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.redis.RedisCache;
import com.ruoyi.common.utils.SecurityUtils;
import com.yanzhu.jh.project.domain.SurProjectSchedule;
import com.yanzhu.jh.project.domain.vo.SurProjectScheduleWhere;
import com.yanzhu.jh.project.service.ISurProjectScheduleService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

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

@RestController
@RequestMapping("/bgscreen/schedule")
public class ProjectScheduleController extends BaseController {

    @Autowired
    private ISurProjectScheduleService isurProjectScheduleService;
    @Autowired
    private RedisCache redisCache;
    @GetMapping("/projectConstructionProgress")
    public AjaxResult getProjectConstructionProgress(Long projectId){
        SurProjectSchedule surProjectSchedule= isurProjectScheduleService.getProjectConstructionProgress(projectId);
        return AjaxResult.success(surProjectSchedule);
    }

    @GetMapping("/constructionProgressByDept")
    public AjaxResult getConstructionProgressByDept(Long deptId){
        SurProjectSchedule where=new SurProjectSchedule();
        if(deptId==null || deptId<=0){
            if (SecurityUtils.isUserB()) {
                where.setPrjIds(getProjectIds());
            }
        }else{
            where.setDeptId(deptId);
        }
        List<SurProjectSchedule> list=isurProjectScheduleService.getConstructionProgressByDept(where);
        return AjaxResult.success(list);
    }
    /**
     * 按项目类型查询形象进度数据
     * @param type
     * @return
     */
    @GetMapping("/selectByProjectType")
    public AjaxResult selectByProjectType(Long type,Long deptId){
        String key="bgscreen_schedule_selectByProjectType_"+type+"_"+deptId;
        Object obj=redisCache.getCacheObject(key);
        if(obj!=null){
            return AjaxResult.success(obj);
        }
        SurProjectScheduleWhere where =new SurProjectScheduleWhere();
        where.setPrjType(type);
        where.setDeptId(deptId);
        if(deptId==null || deptId<=0){
            if (SecurityUtils.isUserB()) {
                where.setPrjIds(getProjectIds());
            }
        }
        List<SurProjectSchedule> list=isurProjectScheduleService.selectByProjectType(where);
        redisCache.setCacheObject(key, list, Constants.BIGSCREEN_QUERY_CACHE, TimeUnit.MINUTES);
        return AjaxResult.success(list);
    }
}
