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.SurProjectPlan;
import com.yanzhu.jh.project.service.ISurProjectPlanService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
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/projectPlan")
public class ProjectPlanController {

    @Autowired
    ISurProjectPlanService surProjectPlanService;
    @Autowired
    private RedisCache redisCache;
    @GetMapping("/listAll/{type}")
    public AjaxResult listAll(@PathVariable("type") Long type){
        String key="bgscreen_projectPlan_listAll_"+type;
        Object obj=redisCache.getCacheObject(key);
        if(obj!=null){
            return AjaxResult.success(obj);
        }

        SurProjectPlan where=new SurProjectPlan();
        where.setPlanType(type);
        where.setIsDel(0l);
        List<SurProjectPlan> list = surProjectPlanService.selectSurProjectPlanList(where);
        redisCache.setCacheObject(key, list, Constants.BIGSCREEN_QUERY_CACHE, TimeUnit.MINUTES);
        return AjaxResult.success(list);
    }

    @GetMapping("/listAllTop3")
    public AjaxResult listAllTop3(){
        String key="bgscreen_projectPlan_listAll_";
        Object obj=redisCache.getCacheObject(key);
        if(obj!=null){
            return AjaxResult.success(obj);
        }

        List<SurProjectPlan> list = surProjectPlanService.selectSurProjectPlanListTop3();
        redisCache.setCacheObject(key, list, Constants.BIGSCREEN_QUERY_CACHE, TimeUnit.MINUTES);
        return AjaxResult.success(list);
    }
}
