package com.yanzhu.jh.bigscreen.web.controller;

import com.ruoyi.common.constant.Constants;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.common.core.redis.RedisCache;
import com.yanzhu.jh.project.domain.SmzProjectQuarterlyAssess;
import com.yanzhu.jh.project.service.ISmzProjectQuarterlyAssessService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.Calendar;
import java.util.List;
import java.util.concurrent.TimeUnit;

@RestController
@RequestMapping("/bgscreen/asscess")
public class ProjectQuarterlyAssessController extends BaseController {
    @Autowired
    private ISmzProjectQuarterlyAssessService smzProjectQuarterlyAssessService;

    @Autowired
    private RedisCache redisCache;


    @GetMapping("/currentListByDept")
    public TableDataInfo currentListByDept(Long deptId){
        String key="bgscreen_asscess_currentListByDept"+deptId;
        Object obj=redisCache.getCacheObject(key);
        if(obj!=null){
           return getDataTable((List<?>) obj);
        }
        SmzProjectQuarterlyAssess smzProjectQuarterlyAssess=new SmzProjectQuarterlyAssess();
        smzProjectQuarterlyAssess.setDeptId(deptId);
        Calendar calendar=Calendar.getInstance();
        smzProjectQuarterlyAssess.setYear((long)calendar.get(Calendar.YEAR));
        int month=calendar.get(Calendar.MONTH);
        smzProjectQuarterlyAssess.setQuarterly((long)(month+2)/3);
        List list= smzProjectQuarterlyAssessService.currentListByDept(smzProjectQuarterlyAssess);
        redisCache.setCacheObject(key, list, Constants.BIGSCREEN_QUERY_CACHE, TimeUnit.MINUTES);
        return getDataTable(list);
    }

    /**
     * 根据项目类型查询项目的季度计划
     * @param
     * @return
     */
    @PostMapping("/queryByProjectType")
    public AjaxResult queryByProjectType(@RequestBody SmzProjectQuarterlyAssess where){
        String key="bgscreen_asscess_queryByProjectType_"+where.getId()+"_"+where.getYear()+"_"+where.getQuarterly();
        Object obj=redisCache.getCacheObject(key);
        if(obj!=null){
            return AjaxResult.success(obj);
        }

        List list=smzProjectQuarterlyAssessService.queryByProjectType(where);
        redisCache.setCacheObject(key, list, Constants.BIGSCREEN_QUERY_CACHE, TimeUnit.MINUTES);
        return AjaxResult.success(list);

    }


}
