双重预防项目-国泰新华二开定制版
huangzhen
2022-10-13 81a6a662b5db806e0824f311a89993d853db9371
src/main/java/com/ruoyi/doublePrevention/service/impl/SPIDataCountServiceImpl.java
@@ -6,6 +6,7 @@
import com.ruoyi.doublePrevention.entity.dto.DataCountDangerResultRespDO;
import com.ruoyi.doublePrevention.entity.dto.req.SPIDataCountReqDTO;
import com.ruoyi.doublePrevention.entity.dto.resp.SPIDataCountRespDTO;
import com.ruoyi.doublePrevention.enums.CountContentEnum;
import com.ruoyi.doublePrevention.repository.param.DataCountStartAndEndTimeParams;
import com.ruoyi.doublePrevention.service.SPIDataCountService;
import com.ruoyi.doublePrevention.service.baseService.DoublePreventionDeptService;
@@ -16,6 +17,7 @@
import org.apache.commons.lang3.ObjectUtils;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.stereotype.Service;
import org.springframework.util.CollectionUtils;
@@ -26,6 +28,9 @@
@Service("SPIDataCountService")
public class SPIDataCountServiceImpl implements SPIDataCountService {
    @Autowired
    private RedisTemplate redisTemplate;
    @Autowired
    private DoublePreventionDeptService doublePreventionDeptService;
@@ -66,26 +71,77 @@
        DataCountDangerLevelRespDO levelCountByTime = null;
        DataCountDangerLevelRectifiedRespDO levelRectifiedCountByTime = null;
        String SPIDataCountKey = "SPI_PREVENT_RISK_";
        //判断month是否null
        Calendar calendar = Calendar.getInstance();
        int currentYear = calendar.get(Calendar.YEAR);
        int currentMonth = calendar.get(Calendar.MONTH) + 1;
        int currentDay = calendar.get(Calendar.DATE);
        if (month == null){
            if (currentYear != year){
                SPIDataCountKey = SPIDataCountKey + year+"_"+"【1-12】_"+depId;
            }else {
                SPIDataCountKey = SPIDataCountKey + year + "_" + "【1-" + currentMonth + "/" + currentDay + "】_" + depId;
            }
        }else {
            if (currentYear != year){
                SPIDataCountKey = SPIDataCountKey + year+"_"+month+"_"+depId;
            }else {
                SPIDataCountKey = SPIDataCountKey + year + "_" + currentMonth +"_【1-" + currentDay + "】_" + depId;
            }
        }
        if (ObjectUtils.isNotEmpty(month) && ObjectUtils.isNotEmpty(year)){
            DataCountStartAndEndTimeParams params = timeInterval(month, year);
            //    月-统计时间段内所有、死亡、重伤、轻伤的隐患数量
            if (!redisTemplate.opsForHash().hasKey(SPIDataCountKey,CountContentEnum.RESULT_COUNT.name())){
            resultCountByTime = preventRiskDangerInfoService.listDangerResultCountByTime(params.getStartTime(), params.getEndTime(), depIds);
                redisTemplate.opsForHash().put(SPIDataCountKey,CountContentEnum.RESULT_COUNT.name(),resultCountByTime);
            }
            resultCountByTime = (DataCountDangerResultRespDO)redisTemplate.opsForHash().get(SPIDataCountKey,CountContentEnum.RESULT_COUNT.name());
            //    月-统计时间段内一般、重大的隐患数量
            if (!redisTemplate.opsForHash().hasKey(SPIDataCountKey,CountContentEnum.LEVEL_COUNT.name())){
            levelCountByTime = checkPointService.listDangerLevelCountByTime(params.getStartTime(), params.getEndTime(), depIds);
                redisTemplate.opsForHash().put(SPIDataCountKey,CountContentEnum.LEVEL_COUNT.name(),levelCountByTime);
            }
            levelCountByTime = (DataCountDangerLevelRespDO)redisTemplate.opsForHash().get(SPIDataCountKey,CountContentEnum.LEVEL_COUNT.name());
            //    月-统计时间段内一般已整改、重大已整改的隐患数量
            if (!redisTemplate.opsForHash().hasKey(SPIDataCountKey,CountContentEnum.LEVEL_RECTIFIED_COUNT.name())){
            levelRectifiedCountByTime = checkPointService.listDangerLevelRectifiedCountByTime(params.getStartTime(), params.getEndTime(), depIds);
                redisTemplate.opsForHash().put(SPIDataCountKey,CountContentEnum.LEVEL_RECTIFIED_COUNT.name(),levelRectifiedCountByTime);
            }
            levelRectifiedCountByTime = (DataCountDangerLevelRectifiedRespDO)redisTemplate.opsForHash().get(SPIDataCountKey,CountContentEnum.LEVEL_RECTIFIED_COUNT.name());
        }else {
            DataCountStartAndEndTimeParams params = timeInterval(null, year);
            //    年-统计时间段内所有、死亡、重伤、轻伤的隐患数量
            if (!redisTemplate.opsForHash().hasKey(SPIDataCountKey,CountContentEnum.RESULT_COUNT.name())){
            resultCountByTime = preventRiskDangerInfoService.listDangerResultCountByTime(params.getStartTime(), params.getEndTime(), depIds);
                redisTemplate.opsForHash().put(SPIDataCountKey,CountContentEnum.RESULT_COUNT.name(),resultCountByTime);
            }
            resultCountByTime = (DataCountDangerResultRespDO)redisTemplate.opsForHash().get(SPIDataCountKey,CountContentEnum.RESULT_COUNT.name());
            //    年-统计时间段内一般、重大的隐患数量
            if (!redisTemplate.opsForHash().hasKey(SPIDataCountKey,CountContentEnum.LEVEL_COUNT.name())){
            levelCountByTime = checkPointService.listDangerLevelCountByTime(params.getStartTime(), params.getEndTime(), depIds);
                redisTemplate.opsForHash().put(SPIDataCountKey,CountContentEnum.LEVEL_COUNT.name(),levelCountByTime);
            }
            levelCountByTime = (DataCountDangerLevelRespDO)redisTemplate.opsForHash().get(SPIDataCountKey,CountContentEnum.LEVEL_COUNT.name());
            //    年-统计时间段内一般已整改、重大已整改的隐患数量
            if (!redisTemplate.opsForHash().hasKey(SPIDataCountKey,CountContentEnum.LEVEL_RECTIFIED_COUNT.name())){
            levelRectifiedCountByTime = checkPointService.listDangerLevelRectifiedCountByTime(params.getStartTime(), params.getEndTime(), depIds);
                redisTemplate.opsForHash().put(SPIDataCountKey,CountContentEnum.LEVEL_RECTIFIED_COUNT.name(),levelRectifiedCountByTime);
            }
            levelRectifiedCountByTime = (DataCountDangerLevelRectifiedRespDO)redisTemplate.opsForHash().get(SPIDataCountKey,CountContentEnum.LEVEL_RECTIFIED_COUNT.name());
        }
        if (resultCountByTime == null || levelCountByTime == null || levelRectifiedCountByTime == null){
            parameterVerificationResult.setCode("400");
@@ -195,6 +251,4 @@
        params.setEndTime(endTime);
        return params;
    }
}