Parcourir la source

安全指数代码提交

jingyuanchao il y a 2 ans
Parent
commit
5425b2f57b

+ 6 - 0
soc-common/soc-common-core/src/main/java/com/xunmei/common/core/constant/Constants.java

@@ -140,4 +140,10 @@ public class Constants {
      * web端登录
      */
     public static final String LOGIN_TYPE_1 = "1";
+
+    /**
+     * 数字常量
+     */
+    public static final Integer ONE = 1;
+    public static final Integer TWO = 2;
 }

+ 82 - 37
soc-modules/soc-modules-core/src/main/java/com/xunmei/core/safetyindex/service/impl/CoreSafetyExceptionDataServiceImpl.java

@@ -8,6 +8,7 @@ import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
 import com.baomidou.mybatisplus.core.toolkit.IdWorker;
 import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
 import com.xunmei.common.core.constant.CacheConstants;
+import com.xunmei.common.core.constant.Constants;
 import com.xunmei.common.core.domain.safetyindex.domain.CoreSafetyDeductData;
 import com.xunmei.common.core.domain.safetyindex.domain.CoreSafetyExceptionData;
 import com.xunmei.common.core.domain.safetyindex.domain.CoreSafetySourceData;
@@ -21,7 +22,6 @@ import com.xunmei.core.safetyindex.service.ICoreSafetyDeductDataService;
 import com.xunmei.core.safetyindex.service.ICoreSafetyExceptionDataService;
 import com.xunmei.core.safetyindex.service.ICoreSafetyIndexCalculateRuleService;
 import com.xunmei.core.safetyindex.service.ICoreSafetySourceDataService;
-import com.xunmei.system.api.RemoteOrgService;
 import com.xunmei.system.api.vo.SysOrgVO;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.stereotype.Service;
@@ -42,20 +42,25 @@ import java.util.stream.Collectors;
  */
 @Service
 public class CoreSafetyExceptionDataServiceImpl extends ServiceImpl<CoreSafetyExceptionDataMapper, CoreSafetyExceptionData> implements ICoreSafetyExceptionDataService {
+    public static final String RESUMPTION_DICT_CODE = "1004";
+    public static final String QUESTION_DICT_CODE = "1005";
+    public static final String MONITORING_DICT_CODE = "1006";
     public static final String CORE_RESUMPTION = "core_resumption";
     public static final String CORE_QUESTION = "core_question";
     public static final String CORE_MONITORING_RETRIEVAL_TASK = "core_monitoring_retrieval_task";
+    public static final String BEFORE_POINT_CODE = "10040201";
+    public static final String MIDDLE_POINT_CODE = "10040203";
+    public static final String AFTER_POINT_CODE = "10040202";
+    public static final String UN_CONFIRM_POINT_CODE = "10050101";
+    public static final String UN_RECTIFY_POINT_CODE = "10050101";
     @Autowired
     private CoreSafetyExceptionDataMapper coreSafetyExceptionDataMapper;
     @Autowired
-    private RemoteOrgService orgService;
-    @Autowired
     private ResumptionService resumptionService;
     @Autowired
     private IQuestionService questionService;
     @Autowired
     private ICoreMonitoringRetrievalTaskService monitoringRetrievalTaskService;
-
     @Autowired
     private ICoreSafetyIndexCalculateRuleService ruleService;
     @Autowired
@@ -79,9 +84,6 @@ public class CoreSafetyExceptionDataServiceImpl extends ServiceImpl<CoreSafetyEx
 
     }
 
-    public static final String RESUMPTION_DICT_CODE = "1004";
-    public static final String QUESTION_DICT_CODE = "1005";
-    public static final String MONITORING_DICT_CODE = "1006";
 
     @Override
     @Transactional(rollbackFor = Exception.class)
@@ -108,29 +110,86 @@ public class CoreSafetyExceptionDataServiceImpl extends ServiceImpl<CoreSafetyEx
         //删除已有的计算数据
         deleteOldData(year, month);
 
-
+        List<SysOrgVO> orgList = RedisUtils.getCacheList(CacheConstants.ORG_CACHE_LIST_KEY);
         //计算安保履职
-        calculateResumptionData(resumptionIndexList, resumptionExceptionDataList, year, month);
+        calculateResumptionData(resumptionIndexList, resumptionExceptionDataList, year, month, orgList);
 
         //计算问题整改
-        calculateQuestionData(questionIndexList, questionExceptionDataList, year, month);
+        calculateQuestionData(questionIndexList, questionExceptionDataList, year, month, orgList);
+
+        //计算监控调阅
+        calculateMonitoringData(monitoringIndexList, monitoringExceptionDataList, year, month, orgList);
+
+
+    }
+
+    private void calculateMonitoringData(List<SafeIndexRuleCountVo> monitoringIndexList, List<CoreSafetyExceptionData> dataList, int year, int month, List<SysOrgVO> orgList) {
+        //将数据按机构分组
+        Map<Long, List<CoreSafetyExceptionData>> monitoringExceptionDataList = dataList.stream().collect(Collectors.groupingBy(CoreSafetyExceptionData::getOrgId));
 
 
     }
 
-    private void calculateQuestionData(List<SafeIndexRuleCountVo> questionIndexList, List<CoreSafetyExceptionData> dataList, int year, int month) {
+    private void calculateQuestionData(List<SafeIndexRuleCountVo> questionIndexList, List<CoreSafetyExceptionData> dataList, int year, int month, List<SysOrgVO> orgList) {
+        //将数据按机构分组
+        Map<Long, List<CoreSafetyExceptionData>> questionExceptionDataList = dataList.stream().collect(Collectors.groupingBy(CoreSafetyExceptionData::getOrgId));
+        //未在规定时间内确认
+        List<SafeIndexRuleCountVo> unConfirmIndexList = questionIndexList.stream()
+                .filter(r -> ObjectUtil.equal(UN_CONFIRM_POINT_CODE, r.getPointCode()))
+                .filter(r -> r.getCalculateType().equals(Constants.ONE))
+                .collect(Collectors.toList());
+        //已确认但未在规定时间内完成整改
+        List<SafeIndexRuleCountVo> unRectifyIndexList = questionIndexList.stream()
+                .filter(r -> ObjectUtil.equal(UN_RECTIFY_POINT_CODE, r.getPointCode()))
+                .filter(r -> r.getCalculateType().equals(Constants.ONE))
+                .collect(Collectors.toList());
+        for (Long orgId : questionExceptionDataList.keySet()) {
+            orgList.stream().filter(o -> ObjectUtil.equal(o.getId(), orgId)).findFirst().ifPresent(org -> {
+                //获取机构的指标配置
+                List<SafeIndexRuleCountVo> orgResumptionIndexList = questionIndexList.stream().filter(r -> ObjectUtil.equal(r.getOrgType(), org.getType())).collect(Collectors.toList());
+                if (orgResumptionIndexList.isEmpty()) {
+                    return;
+                }
+                List<CoreSafetyExceptionData> safetyExceptionData = questionExceptionDataList.get(orgId);
+                //未确认的数据
+                long unConfirmDataCount = safetyExceptionData.stream().filter(data -> ObjectUtil.equal(data.getExtraField2(), 2)).count();
+                //未整改的数据
+                long unRectifyDataCount = safetyExceptionData.stream().filter(data -> ObjectUtil.notEqual(data.getExtraField2(), 2)).count();
+                List<CoreSafetySourceData> sourceDataList = new ArrayList<>();
+                //计算未确认的累计数
+                extracted(unConfirmIndexList, year, month, orgId, (int) unConfirmDataCount, sourceDataList);
+                //计算已确认未整改的累计数
+                extracted(unRectifyIndexList, year, month, orgId, (int) unRectifyDataCount, sourceDataList);
+
+            });
+        }
+
 
     }
 
-    private void calculateResumptionData(List<SafeIndexRuleCountVo> resumptionIndexList, List<CoreSafetyExceptionData> resumptionExceptionDataList, int year, int month) {
+    private void extracted(List<SafeIndexRuleCountVo> questionIndexList, int year, int month, Long orgId, int dataSize, List<CoreSafetySourceData> sourceDataList) {
+        SafeIndexRuleCountVo indexConfigCountVo = questionIndexList.get(0);
+        double deductScore = dataSize * indexConfigCountVo.getItemValue();
+        //计算未确认的数据累计数
+        if (dataSize != 0) {
+            CoreSafetySourceData safeSourceData = doNewSafetySourceData(indexConfigCountVo, orgId, deductScore, year, month, dataSize);
+            sourceDataList.add(safeSourceData);
+        }
+    }
+
+    private void calculateResumptionData(List<SafeIndexRuleCountVo> resumptionIndexList, List<CoreSafetyExceptionData> resumptionExceptionDataList, int year, int month, List<SysOrgVO> orgList) {
         //扩展字段1:计划id  扩展字段2:计划执行时刻 (2,3,4 营业前中后)
         //将数据按机构分组
         Map<Long, List<CoreSafetyExceptionData>> safetyExceptionDataMapList = resumptionExceptionDataList.stream().collect(Collectors.groupingBy(CoreSafetyExceptionData::getOrgId));
-
-        List<SysOrgVO> orgList = RedisUtils.getCacheList(CacheConstants.ORG_CACHE_LIST_KEY);
+        //营业前
+        List<SafeIndexRuleCountVo> resumptionBeforeUndoIndexList = getResumptionUndoIndexList(BEFORE_POINT_CODE, resumptionIndexList);
+        //营业中
+        List<SafeIndexRuleCountVo> resumptionMiddleIndexList = getResumptionUndoIndexList(MIDDLE_POINT_CODE, resumptionIndexList);
+        //营业后
+        List<SafeIndexRuleCountVo> resumptionAfterUndoIndexList = getResumptionUndoIndexList(AFTER_POINT_CODE, resumptionIndexList);
 
         for (Long orgId : safetyExceptionDataMapList.keySet()) {
-            orgList.parallelStream().filter(o -> ObjectUtil.equal(o.getId(), orgId)).findFirst().ifPresent(org -> {
+            orgList.stream().filter(o -> ObjectUtil.equal(o.getId(), orgId)).findFirst().ifPresent(org -> {
                 //获取机构的指标配置
                 List<SafeIndexRuleCountVo> orgResumptionIndexList = resumptionIndexList.stream().filter(r -> ObjectUtil.equal(r.getOrgType(), org.getType())).collect(Collectors.toList());
                 if (orgResumptionIndexList.isEmpty()) {
@@ -141,39 +200,20 @@ public class CoreSafetyExceptionDataServiceImpl extends ServiceImpl<CoreSafetyEx
                 //构建执行时刻的map,用于存储每个时刻的异常数据
                 Map<Integer, List<CoreSafetyExceptionData>> execTimeMap = buildExecTimeMap(resumptionExceptionDataListByOrg);
 
-
-                //营业前
-                List<SafeIndexRuleCountVo> resumptionBeforeUndoIndexList = resumptionIndexList.stream()
-                        .filter(r -> ObjectUtil.equal("10040201", r.getPointCode()))
-                        .filter(r -> r.getCalculateType() == 1)
-                        .collect(Collectors.toList());
                 if (ObjectUtil.isNotEmpty(resumptionBeforeUndoIndexList)) {
                     List<CoreSafetySourceData> sourceDataList = calculateContinuousCumulativeCount(resumptionBeforeUndoIndexList, execTimeMap.get(2), orgId, year, month);
                     saveSourceData(sourceDataList, resumptionBeforeUndoIndexList.get(0));
                 }
 
-                //营业中
-                List<SafeIndexRuleCountVo> resumptionMiddleIndexList = resumptionIndexList.stream()
-                        .filter(r -> ObjectUtil.equal("10040203", r.getPointCode()))
-                        .filter(r -> r.getCalculateType() == 1)
-                        .collect(Collectors.toList());
                 if (ObjectUtil.isNotEmpty(resumptionMiddleIndexList)) {
                     List<CoreSafetySourceData> sourceDataList = calculateContinuousCumulativeCount(resumptionMiddleIndexList, execTimeMap.get(4), orgId, year, month);
                     saveSourceData(sourceDataList, resumptionMiddleIndexList.get(0));
                 }
 
-
-                //营业后
-                List<SafeIndexRuleCountVo> resumptionAfterUndoIndexList = resumptionIndexList.stream()
-                        .filter(r -> ObjectUtil.equal("10040202", r.getPointCode()))
-                        .filter(r -> r.getCalculateType() == 1)
-                        .collect(Collectors.toList());
                 if (ObjectUtil.isNotEmpty(resumptionAfterUndoIndexList)) {
                     List<CoreSafetySourceData> sourceDataList = calculateContinuousCumulativeCount(resumptionAfterUndoIndexList, execTimeMap.get(4), orgId, year, month);
                     saveSourceData(sourceDataList, resumptionAfterUndoIndexList.get(0));
                 }
-
-
             });
         }
     }
@@ -261,8 +301,6 @@ public class CoreSafetyExceptionDataServiceImpl extends ServiceImpl<CoreSafetyEx
 
         return sourceDataList;
     }
-//传入一个已做好升序排序的数组,数组中的每个元素都是yyyy-MM-dd格式的时间,判断相邻元素是否是连续的时间,把所有的连续天数分组出来,放在一个map中,key为连续天数,value为连续天数的集合,最终返回一个List<Map<Integer,List<String>>这样的数据
-// 例如:传入参数:["2022-01-01", "2022-01-02", "2022-01-03", "2022-01-04", "2022-01-06", "2022-01-07", "2022-01-08", "2022-01-09", "2022-01-11"],应该返回一个List<Map<Integer,List<String>>,数组中有两个map:一个map,其中一个key为4,value为["2022-01-01", "2022-01-02", "2022-01-03", "2022-01-04"],另一个map,其中一个key也为4,value为["2022-01-06", "2022-01-07", "2022-01-08", "2022-01-09"],其中"2022-01-11" 这个元素应该被丢弃,因为它不与其他任何元素是相邻时间
 
     public static List<Map<Integer, List<String>>> groupContinuousDays(List<String> days) {
         List<Map<Integer, List<String>>> result = new ArrayList<>();
@@ -293,6 +331,13 @@ public class CoreSafetyExceptionDataServiceImpl extends ServiceImpl<CoreSafetyEx
         return result;
     }
 
+    private List<SafeIndexRuleCountVo> getResumptionUndoIndexList(String pointCode, List<SafeIndexRuleCountVo> resumptionIndexList) {
+        return resumptionIndexList.stream()
+                .filter(r -> ObjectUtil.equal(pointCode, r.getPointCode()))
+                .filter(r -> r.getCalculateType() == 1)
+                .collect(Collectors.toList());
+    }
+
    /* public static void main(String[] args) {
         String[] dates = {"2022-01-01", "2022-01-02", "2022-01-03", "2022-01-04", "2022-01-06", "2022-01-07", "2022-01-08", "2022-01-09", "2022-01-11"};
         List<Map<Integer, List<String>>> result = groupContinuousDays(dates);
@@ -372,7 +417,7 @@ public class CoreSafetyExceptionDataServiceImpl extends ServiceImpl<CoreSafetyEx
     private void doQuestionExceptionData(DateTime time) {
         //未确认和已确认但未整改的
         //扩展字段1:来源任务id
-        //扩展字段2:任务来源 1:履职,2:安全检查
+        //扩展字段2:confirm_status 整改状态 0:未确认,2:已确认
         List<CoreSafetyExceptionData> resumptionExceptionList = questionService.selectQuestionExceptionData(time);
         this.saveBatch(resumptionExceptionList);
     }

+ 1 - 1
soc-modules/soc-modules-core/src/main/resources/mapper/question/QuestionMapper.xml

@@ -207,7 +207,7 @@
 
     <select id="selectQuestionExceptionData"
             resultType="com.xunmei.common.core.domain.safetyindex.domain.CoreSafetyExceptionData">
-        SELECT a.id as dataId, a.org_id as orgId, a.src_task_id as extraField1, a.src_type as extraField2, a.submit_time as dataTime,'core_question' as dataSource,now() as createTime
+        SELECT a.id as dataId, a.org_id as orgId, a.src_task_id as extraField1, a.confirm_status as extraField2, a.submit_time as dataTime,'core_question' as dataSource,now() as createTime
         FROM core_question a where reform_deadline <![CDATA[<]]> #{time} and (confirm_status=0 or (confirm_status=2 and reform_status=10))
     </select>
 </mapper>