From 5ea8ef80312e8c1d3365abe7106622d676def195 Mon Sep 17 00:00:00 2001
From: huangzhen <867127663@qq.com>
Date: 星期五, 30 九月 2022 16:41:09 +0800
Subject: [PATCH] Merge remote-tracking branch 'origin/master'

---
 src/main/java/com/ruoyi/doublePrevention/service/impl/SPIDataCountServiceImpl.java |  200 ++++++++++++++++++++++++++++++++++++++++++++++++++
 1 files changed, 200 insertions(+), 0 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
new file mode 100644
index 0000000..5531f62
--- /dev/null
+++ b/src/main/java/com/ruoyi/doublePrevention/service/impl/SPIDataCountServiceImpl.java
@@ -0,0 +1,200 @@
+package com.ruoyi.doublePrevention.service.impl;
+
+import com.ruoyi.doublePrevention.entity.DoublePreventDept;
+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.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.stereotype.Service;
+import org.springframework.util.CollectionUtils;
+
+import java.util.Calendar;
+import java.util.Date;
+import java.util.List;
+
+@Service("SPIDataCountService")
+public class SPIDataCountServiceImpl implements SPIDataCountService {
+
+
+    @Autowired
+    private DoublePreventionDeptService doublePreventionDeptService;
+
+    @Autowired
+    private PreventRiskDangerInfoService preventRiskDangerInfoService;
+
+    @Autowired
+    private TrHiddenDangerCheckPointService checkPointService;
+
+
+    /**
+     * 数据统计-隐患数据统计-根据月或者年
+     */
+    @Override
+    public ResultVO<SPIDataCountRespDTO> listDangerResultCountByMonthOrYear(SPIDataCountReqDTO spiDataCountReqDTO) {
+        ResultVO<SPIDataCountRespDTO> parameterVerificationResult = parameterVerification(spiDataCountReqDTO);
+        if ("400".equals(parameterVerificationResult.getCode())){
+            return parameterVerificationResult;
+        }
+        Integer month = spiDataCountReqDTO.getMonth();
+        Integer year = spiDataCountReqDTO.getYear();
+
+        Long depId = spiDataCountReqDTO.getDepId();
+        //获取部门信息
+        DoublePreventDept depInfoByDepId = doublePreventionDeptService.getDepInfoByDepId(depId);
+        //获取部门及所有子部门信息
+        //祖级列表
+        String ancestors = depInfoByDepId.getAncestors();
+        ancestors = ancestors + ",";
+        List<Long> depIds = doublePreventionDeptService.listDepAndSubDepIds(ancestors);
+        depIds.add(depId);
+        if (CollectionUtils.isEmpty(depIds)){
+            throw new RuntimeException("部门不存在");
+        }
+
+        DataCountDangerResultRespDO resultCountByTime = null;
+        DataCountDangerLevelRespDO levelCountByTime = null;
+        DataCountDangerLevelRectifiedRespDO levelRectifiedCountByTime = null;
+
+        if (ObjectUtils.isNotEmpty(month) && ObjectUtils.isNotEmpty(year)){
+            DataCountStartAndEndTimeParams params = timeInterval(month, year);
+            //    月-统计时间段内所有、死亡、重伤、轻伤的隐患数量
+            resultCountByTime = preventRiskDangerInfoService.listDangerResultCountByTime(params.getStartTime(), params.getEndTime(), depIds);
+
+            //    月-统计时间段内一般、重大的隐患数量
+            levelCountByTime = checkPointService.listDangerLevelCountByTime(params.getStartTime(), params.getEndTime(), depIds);
+
+            //    月-统计时间段内一般已整改、重大已整改的隐患数量
+            levelRectifiedCountByTime = checkPointService.listDangerLevelRectifiedCountByTime(params.getStartTime(), params.getEndTime(), depIds);
+        }else {
+            DataCountStartAndEndTimeParams params = timeInterval(null, year);
+            //    年-统计时间段内所有、死亡、重伤、轻伤的隐患数量
+            resultCountByTime = preventRiskDangerInfoService.listDangerResultCountByTime(params.getStartTime(), params.getEndTime(), depIds);
+
+            //    年-统计时间段内一般、重大的隐患数量
+            levelCountByTime = checkPointService.listDangerLevelCountByTime(params.getStartTime(), params.getEndTime(), depIds);
+
+            //    年-统计时间段内一般已整改、重大已整改的隐患数量
+            levelRectifiedCountByTime = checkPointService.listDangerLevelRectifiedCountByTime(params.getStartTime(), params.getEndTime(), depIds);
+        }
+        if (resultCountByTime == null || levelCountByTime == null || levelRectifiedCountByTime == null){
+            parameterVerificationResult.setCode("400");
+            parameterVerificationResult.setMsg("数据统计异常");
+            return parameterVerificationResult;
+        }
+        SPIDataCountRespDTO spiDataCountRespDTO = new SPIDataCountRespDTO();
+        BeanUtils.copyProperties(resultCountByTime,spiDataCountRespDTO);
+        BeanUtils.copyProperties(levelCountByTime,spiDataCountRespDTO);
+        BeanUtils.copyProperties(levelRectifiedCountByTime,spiDataCountRespDTO);
+        BeanUtils.copyProperties(spiDataCountReqDTO,spiDataCountRespDTO);
+        spiDataCountRespDTO.setDep(depInfoByDepId.getDeptName());
+        parameterVerificationResult.setData(spiDataCountRespDTO);
+        return parameterVerificationResult;
+    }
+
+
+    /**
+     * @description 参数校验
+     */
+    private ResultVO<SPIDataCountRespDTO> parameterVerification(SPIDataCountReqDTO spiDataCountReqDTO){
+        ResultVO resultVO = new ResultVO<>();
+        resultVO.setCode("200");
+        resultVO.setMsg("查询成功");
+        if (ObjectUtils.isEmpty(spiDataCountReqDTO)){
+            resultVO.setCode("400");
+            resultVO.setMsg("参数为空,查询失败");
+            return resultVO;
+        }
+
+        if (ObjectUtils.isEmpty(spiDataCountReqDTO.getMonth())){
+            if (ObjectUtils.isEmpty(spiDataCountReqDTO.getYear())){
+                resultVO.setCode("400");
+                resultVO.setMsg("查询年份不能为空");
+                return resultVO;
+            }
+        }else {
+            if (ObjectUtils.isEmpty(spiDataCountReqDTO.getYear())){
+                resultVO.setCode("400");
+                resultVO.setMsg("查询年份不能为空");
+                return resultVO;
+            }
+        }
+
+        if (ObjectUtils.isNotEmpty(spiDataCountReqDTO.getDepId())){
+            DoublePreventDept depInfoByDepId = doublePreventionDeptService.getDepInfoByDepId(spiDataCountReqDTO.getDepId());
+            if (depInfoByDepId == null){
+                resultVO.setCode("400");
+                resultVO.setMsg("查询的部门不存在");
+                return resultVO;
+            }
+        }
+        return resultVO;
+    }
+
+
+
+    /**
+     * 数据统计-统计时间处理:根据传参判断是否为统计月还是统计年,月份为空表明是统计年 月份不为空表明是统计月
+     */
+    private DataCountStartAndEndTimeParams timeInterval(Integer month, Integer year){
+
+        //确定结束时间
+        Calendar calendar = Calendar.getInstance();
+        int nowYear = calendar.get(Calendar.YEAR);
+        Date startTime = null;
+        Date endTime = null;
+        if (month == null){
+            //说明统计的是当前年份
+            if (nowYear == year){
+                endTime =calendar.getTime();
+
+                calendar.clear();
+                calendar.set(Calendar.YEAR,nowYear);
+                startTime = calendar.getTime();
+
+            }else {
+                calendar.clear();
+                calendar.set(Calendar.YEAR,year);
+                startTime = calendar.getTime();
+
+                calendar.set(Calendar.YEAR,year+1);
+                calendar.set(Calendar.DAY_OF_YEAR,-1);
+                calendar.set(Calendar.SECOND,59);
+                calendar.set(Calendar.MINUTE,59);
+                calendar.set(Calendar.HOUR_OF_DAY,23);
+                endTime = calendar.getTime();
+
+            }
+        //统计的是指定月份
+        }else{
+            calendar.set(year, month - 1, 1);
+            calendar.set(Calendar.SECOND,0);
+            calendar.set(Calendar.MINUTE,0);
+            calendar.set(Calendar.HOUR_OF_DAY,0);
+            startTime = calendar.getTime();
+
+            calendar.set(Calendar.DATE,calendar.getActualMaximum(Calendar.DATE)); //指定月份的最后一天
+            calendar.set(Calendar.SECOND,59);
+            calendar.set(Calendar.MINUTE,59);
+            calendar.set(Calendar.HOUR_OF_DAY,23);
+            endTime = calendar.getTime();
+
+        }
+        DataCountStartAndEndTimeParams params = new DataCountStartAndEndTimeParams();
+        params.setStartTime(startTime);
+        params.setEndTime(endTime);
+        return params;
+    }
+
+
+}

--
Gitblit v1.9.2