Browse Source

修改企业报告预警逻辑,将多个文件的预警合并到一个事件消息中。

Memory_LG 1 year ago
parent
commit
10d0828697

+ 56 - 4
src/main/java/com/sooka/sponest/data/housingconstruction/handler/TaskHandler.java

@@ -52,9 +52,61 @@ public class TaskHandler {
         List<CenterdataTHousingconstructionEnterprise> enterpriseList = enterpriseService.selectCenterdataTHousingconstructionEnterpriseList(new CenterdataTHousingconstructionEnterprise());
 
         //获取每个企业每种报告的最新记录
-        List<CenterdataTHousingconstructionEnterpriseproductionreport> dataList = reportService.selectCenterdataTHousingconstructionEnterpriseproductionreportList(new CenterdataTHousingconstructionEnterpriseproductionreport());
+        List<CenterdataTHousingconstructionEnterpriseproductionreport> dataList = reportService.getNewReport(new CenterdataTHousingconstructionEnterpriseproductionreport());
 
-        //获取报告类型
+
+        //遍历企业列表,获取企业信息
+        for (CenterdataTHousingconstructionEnterprise enterprise : enterpriseList) {
+            StringBuilder enterpriseStr = new StringBuilder();//事故隐患排查治理制度,安全事故应急救援预案,
+            //遍历字典集合,获取字典类型
+            for (SysDictData sysDictData : reportCacheList) {
+                //设置标识,最终根据标识判断是否序号将当前类型的报告拼接到事件描述中
+                boolean flag = true;
+                //遍历业务结果集
+                for (CenterdataTHousingconstructionEnterpriseproductionreport report : dataList) {
+                    //如果企业id相同                                          并且  文件类型相同
+                    if(report.getEnterpriseId().equals(enterprise.getId())  && report.getReportType().equals(sysDictData.getDictValue())){
+                        //获取文件上传时间 + 阈值30天 与当前时间做比较
+                        //获取数据的上传时间
+                        Date createTime = report.getCreateTime();
+                        // 将 Date 转换为 LocalDateTime
+                        LocalDateTime localDateTime = convertToLocalDateTime(createTime);
+                        // 在 LocalDateTime 上加上 30 天
+                        LocalDateTime increaseBy30Days = localDateTime.plus(30, ChronoUnit.DAYS);
+                        // 获取当前日期和时间
+                        LocalDateTime now = LocalDateTime.now();
+                        //文件上传时间没有超过设定的阈值, 不需要上报
+                        if (increaseBy30Days.isAfter(now)) {
+                            //拼接 事件描述
+                            flag = false;
+                        }
+                        break;
+                    }
+                }
+                if(flag){
+                    enterpriseStr.append(sysDictData.getDictLabel()).append(",");
+                }
+            }
+            if(enterpriseStr.length() > 0){
+                enterpriseStr.deleteCharAt(enterpriseStr.length() -1);
+                enterpriseStr.append(")发生%s, 超过30天未上传, 请及时处理!%s%s");
+                enterpriseStr.insert(0,enterprise.getEnterpriseName() +"的(");
+                //创建事件实体类
+                SensorEventVo sensorEventVo = new SensorEventVo(
+                        enterprise.getLongitude(),
+                        enterprise.getLatitude(),
+                        enterprise.getId(),
+                        enterprise.getEnterpriseName(),
+                        new Date(),
+                        enterprise.getRegisteredAddress()
+                );
+                //发送事件
+                sendEvent.sendEvent(enterpriseStr.toString(), StaticEntity.ENTERPRISE_NAME, "", "", sensorEventVo, StaticEntity.ENTERPRISE_CODE);
+            }
+        }
+
+        //  每个企业每种类型的文件单独上报代码
+        /*//获取报告类型
         reportCacheList.forEach(sysDictData -> {
             //获取企业信息
             enterpriseList.forEach(enterprise -> {
@@ -90,12 +142,12 @@ public class TaskHandler {
                     );
                     //设置基础模板
                     StringBuilder template = new StringBuilder();
-                    template.append(enterprise.getEnterpriseName()).append("的").append(sysDictData.getDictLabel()).append("发生%s,").append("超过30天未上传, 请及时处理!%s%s");
+                    template.append(enterprise.getEnterpriseName()).append("的").append(sysDictData.getDictLabel()).append("发生%s, 超过30天未上传, 请及时处理!%s%s");
                     //发送事件
                     sendEvent.sendEvent(template.toString(), StaticEntity.ENTERPRISE_NAME, "", "", sensorEventVo, StaticEntity.ENTERPRISE_CODE);
                 }
             });
-        });
+        });*/
     }
 
     // 将 Date 转换为 LocalDateTime

+ 3 - 0
src/main/java/com/sooka/sponest/data/housingconstruction/mapper/CenterdataTHousingconstructionEnterpriseproductionreportMapper.java

@@ -59,4 +59,7 @@ public interface CenterdataTHousingconstructionEnterpriseproductionreportMapper
      * @return 结果
      */
     public int deleteCenterdataTHousingconstructionEnterpriseproductionreportByIds(String[] ids);
+
+
+    List<CenterdataTHousingconstructionEnterpriseproductionreport> getNewReport(CenterdataTHousingconstructionEnterpriseproductionreport centerdataTHousingconstructionEnterpriseproductionreport);
 }

+ 6 - 0
src/main/java/com/sooka/sponest/data/housingconstruction/service/ICenterdataTHousingconstructionEnterpriseproductionreportService.java

@@ -60,4 +60,10 @@ public interface ICenterdataTHousingconstructionEnterpriseproductionreportServic
      */
     public int deleteCenterdataTHousingconstructionEnterpriseproductionreportById(String id);
 
+    /**
+     * 获取每个企业每种类型的报告最新一条数据
+     * @param centerdataTHousingconstructionEnterpriseproductionreport
+     * @return
+     */
+    List<CenterdataTHousingconstructionEnterpriseproductionreport> getNewReport(CenterdataTHousingconstructionEnterpriseproductionreport centerdataTHousingconstructionEnterpriseproductionreport);
 }

+ 5 - 0
src/main/java/com/sooka/sponest/data/housingconstruction/service/impl/CenterdataTHousingconstructionEnterpriseproductionreportServiceImpl.java

@@ -110,4 +110,9 @@ public class CenterdataTHousingconstructionEnterpriseproductionreportServiceImpl
         attachService.delAttachByBusId(id);
         return centerdataTHousingconstructionEnterpriseproductionreportMapper.deleteCenterdataTHousingconstructionEnterpriseproductionreportById(id);
     }
+
+    @Override
+    public List<CenterdataTHousingconstructionEnterpriseproductionreport> getNewReport(CenterdataTHousingconstructionEnterpriseproductionreport centerdataTHousingconstructionEnterpriseproductionreport) {
+        return centerdataTHousingconstructionEnterpriseproductionreportMapper.getNewReport(centerdataTHousingconstructionEnterpriseproductionreport);
+    }
 }

+ 11 - 0
src/main/resources/mapper/housingconstruction/CenterdataTHousingconstructionEnterpriseproductionreportMapper.xml

@@ -98,4 +98,15 @@
             #{id}
         </foreach>
     </delete>
+
+    <select id="getNewReport" parameterType="CenterdataTHousingconstructionEnterpriseproductionreport" resultMap="CenterdataTHousingconstructionEnterpriseproductionreportResult">
+        SELECT * FROM centerdata_t_housingconstruction_enterpriseproductionreport AS t1
+        WHERE report_type like 'enterprise_production_report%' AND
+            create_time = (
+                SELECT MAX(create_time)
+                FROM centerdata_t_housingconstruction_enterpriseproductionreport AS t2
+                WHERE t1.enterprise_id = t2.enterprise_id
+                  AND t1.report_type = t2.report_type
+            ) ORDER BY enterprise_name, report_type
+    </select>
 </mapper>