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.SurProjectCheckDetection;
import com.yanzhu.jh.project.service.ISurProjectCheckDetectionService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
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/checkDetection")
public class ProjectCheckDetectionController {
    @Autowired
    ISurProjectCheckDetectionService checkDetectionService;
    @Autowired
    private RedisCache redisCache;

    /**
     * 按送检类型分类汇总
     * @param where checkType送检类型 deptId部门编号  projectId项目编号
     * @return
     */
    @PostMapping("groupByCheckType")
    public AjaxResult groupByCheckType(@RequestBody SurProjectCheckDetection where){
        String key="bgscreen_checkDetection_groupMeasureInfo_"+where.getCheckType()+"_"+where.getDeptId()+"_"+where.getProjectId();
        Object obj=redisCache.getCacheObject(key);
        if(obj!=null){
            return AjaxResult.success(obj);
        }
        List<SurProjectCheckDetection> list=checkDetectionService.groupByCheckType(where);
        redisCache.setCacheObject(key, list, Constants.BIGSCREEN_QUERY_CACHE, TimeUnit.MINUTES);
        return AjaxResult.success(list);
    }
}
