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

import com.ruoyi.common.constant.Constants;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.core.redis.RedisCache;
import com.yanzhu.jh.project.domain.SurProjectSchedule;
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 {

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

    /**
     * 按项目类型查询形象进度数据
     * @param type
     * @return
     */
    @GetMapping("/selectByProjectType")
    public AjaxResult selectByProjectType(Long type){
        String key="bgscreen_schedule_selectByProjectType_"+type;
        Object obj=redisCache.getCacheObject(key);
        if(obj!=null){
            return AjaxResult.success(obj);
        }
        List<SurProjectSchedule> list=isurProjectScheduleService.selectByProjectType(type);
        redisCache.setCacheObject(key, list, Constants.BIGSCREEN_QUERY_CACHE, TimeUnit.MINUTES);
        return AjaxResult.success(list);
    }
}
