From b1cb0d6fe00a736a68f265aa129bc605b11bc986 Mon Sep 17 00:00:00 2001
From: 16639036659 <577530412@qq.com>
Date: 星期四, 25 四月 2024 15:03:42 +0800
Subject: [PATCH] 饼图添加整改与未整改数据的统计结果

---
 src/main/java/com/ruoyi/doublePrevention/service/impl/SPIDataCountServiceImpl.java |  145 +++++++++++++++++++++++++++++++++++++++++++++---
 1 files changed, 136 insertions(+), 9 deletions(-)

diff --git a/src/main/java/com/ruoyi/doublePrevention/service/impl/SPIDataCountServiceImpl.java b/src/main/java/com/ruoyi/doublePrevention/service/impl/SPIDataCountServiceImpl.java
index 5531f62..0160f18 100644
--- a/src/main/java/com/ruoyi/doublePrevention/service/impl/SPIDataCountServiceImpl.java
+++ b/src/main/java/com/ruoyi/doublePrevention/service/impl/SPIDataCountServiceImpl.java
@@ -1,24 +1,27 @@
 package com.ruoyi.doublePrevention.service.impl;
 
 import com.ruoyi.doublePrevention.entity.DoublePreventDept;
+import com.ruoyi.doublePrevention.entity.SPI.*;
 import com.ruoyi.doublePrevention.entity.dto.DataCountDangerLevelRectifiedRespDO;
 import com.ruoyi.doublePrevention.entity.dto.DataCountDangerLevelRespDO;
 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;
 import com.ruoyi.doublePrevention.service.baseService.PreventRiskDangerInfoService;
 import com.ruoyi.doublePrevention.service.baseService.TrHiddenDangerCheckPointService;
 import com.ruoyi.doublePrevention.vo.ResultVO;
-import io.swagger.models.auth.In;
 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;
 
+import java.time.LocalDateTime;
 import java.util.Calendar;
 import java.util.Date;
 import java.util.List;
@@ -26,6 +29,9 @@
 @Service("SPIDataCountService")
 public class SPIDataCountServiceImpl implements SPIDataCountService {
 
+
+    @Autowired
+    private RedisTemplate redisTemplate;
 
     @Autowired
     private DoublePreventionDeptService doublePreventionDeptService;
@@ -66,26 +72,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);
+
             //    月-统计时间段内所有、死亡、重伤、轻伤的隐患数量
-            resultCountByTime = preventRiskDangerInfoService.listDangerResultCountByTime(params.getStartTime(), params.getEndTime(), depIds);
+            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());
+
 
             //    月-统计时间段内一般、重大的隐患数量
-            levelCountByTime = checkPointService.listDangerLevelCountByTime(params.getStartTime(), params.getEndTime(), depIds);
+            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());
 
             //    月-统计时间段内一般已整改、重大已整改的隐患数量
-            levelRectifiedCountByTime = checkPointService.listDangerLevelRectifiedCountByTime(params.getStartTime(), params.getEndTime(), depIds);
+            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);
             //    年-统计时间段内所有、死亡、重伤、轻伤的隐患数量
-            resultCountByTime = preventRiskDangerInfoService.listDangerResultCountByTime(params.getStartTime(), params.getEndTime(), depIds);
+            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());
+
 
             //    年-统计时间段内一般、重大的隐患数量
-            levelCountByTime = checkPointService.listDangerLevelCountByTime(params.getStartTime(), params.getEndTime(), depIds);
+            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());
+
 
             //    年-统计时间段内一般已整改、重大已整改的隐患数量
-            levelRectifiedCountByTime = checkPointService.listDangerLevelRectifiedCountByTime(params.getStartTime(), params.getEndTime(), depIds);
+            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");
@@ -100,6 +157,78 @@
         spiDataCountRespDTO.setDep(depInfoByDepId.getDeptName());
         parameterVerificationResult.setData(spiDataCountRespDTO);
         return parameterVerificationResult;
+    }
+
+    @Override
+    public ResultVO<SPIDataRespDTO> getSPIData(SPIDataReqBO spiDataReqBO) {
+
+        ResultVO resultVO = new ResultVO<>();
+        resultVO.setCode("200");
+        resultVO.setMsg("查询成功");
+
+        String key = "006a4740-8f2d-4fdc-a25b-a7413a37a2ba";
+
+        if (ObjectUtils.isEmpty(spiDataReqBO.getKey())){
+            resultVO.setCode("400");
+            resultVO.setMsg("key不能为空");
+            return resultVO;
+        }
+        if (!spiDataReqBO.getKey().equals(key)){
+            resultVO.setCode("400");
+            resultVO.setMsg("key不正确");
+            return resultVO;
+        }
+        if (ObjectUtils.isEmpty(spiDataReqBO.getStartTime())){
+            spiDataReqBO.setStartTime(new Date(123, 3,1));
+        }
+        if (ObjectUtils.isEmpty(spiDataReqBO.getEndTime())){
+            spiDataReqBO.setEndTime(new Date());
+        }
+
+        List<TroubleData> spiData = checkPointService.getSPIData(spiDataReqBO);
+
+        SPIDataRespDTO spiDataRespDTO = new SPIDataRespDTO();
+        spiDataRespDTO.setTroubleDataList(spiData);
+
+        resultVO.setData(spiDataRespDTO);
+
+        return resultVO;
+    }
+
+    @Override
+    public ResultVO<TroubleLevel> getSPIDataForPieChart(SPIDataReqBO spiDataReqBO) {
+
+        ResultVO resultVO = new ResultVO<>();
+        resultVO.setCode("200");
+        resultVO.setMsg("查询成功");
+
+        String key = "006a4740-8f2d-4fdc-a25b-a7413a37a2ba";
+
+        if (ObjectUtils.isEmpty(spiDataReqBO.getKey())){
+            resultVO.setCode("400");
+            resultVO.setMsg("key不能为空");
+            return resultVO;
+        }
+        if (!spiDataReqBO.getKey().equals(key)){
+            resultVO.setCode("400");
+            resultVO.setMsg("key不正确");
+            return resultVO;
+        }
+
+        SPIDataForPieChartRespDTO spiDataForPieChartRespDTO = new SPIDataForPieChartRespDTO();
+
+        if (ObjectUtils.isEmpty(spiDataReqBO.getYear())){
+
+            spiDataReqBO.setYear("2024");
+            TroubleLevel troubleLevel = checkPointService.getTroubleLevel(spiDataReqBO);
+            resultVO.setData(troubleLevel);
+            return resultVO;
+        }
+
+        TroubleLevel troubleLevel = checkPointService.getTroubleLevel(spiDataReqBO);
+        resultVO.setData(troubleLevel);
+
+        return resultVO;
     }
 
 
@@ -195,6 +324,4 @@
         params.setEndTime(endTime);
         return params;
     }
-
-
 }

--
Gitblit v1.9.2