瀏覽代碼

事件触发告警006

qiangxuan 7 月之前
父節點
當前提交
bb1a39697e

+ 5 - 5
jeecg-module-gather/src/main/java/org/jeecg/modules/fpgJob/LeanEventTriggerWarnTask.java

@@ -51,7 +51,7 @@ public class LeanEventTriggerWarnTask {
     @Autowired
     ILeanEventWarnInfoService leanEventWarnInfoService;
 
-//    @Scheduled(cron = "0 */3 * * * *")
+    @Scheduled(cron = "0 */1 * * * *")
     public void leanEventTriggerWarnHandle(){
         LambdaQueryWrapper<FpgGatherData> queryWrapper = new LambdaQueryWrapper<>();
         queryWrapper.eq(FpgGatherData::getEventWarnState, "0").isNotNull(FpgGatherData::getDeviceInformationId).orderByDesc(FpgGatherData::getCreateTime);
@@ -63,10 +63,10 @@ public class LeanEventTriggerWarnTask {
             });
         }
         // 逻辑删除已校验完精益事件告警的采集数据,事件告警使用状态0:使用中1:使用结束
-//        List<FpgGatherData> updateFpgGatherDataList = fpgGatherDataList.stream().map(s -> s.setEventWarnState("1")).collect(Collectors.toList());
-//        if (oConvertUtils.listIsNotEmpty(updateFpgGatherDataList)){
-//            fpgGatherDataService.updateBatchById(updateFpgGatherDataList);
-//        }
+        List<FpgGatherData> updateFpgGatherDataList = fpgGatherDataList.stream().map(s -> s.setEventWarnState("1")).collect(Collectors.toList());
+        if (oConvertUtils.listIsNotEmpty(updateFpgGatherDataList)){
+            fpgGatherDataService.updateBatchById(updateFpgGatherDataList);
+        }
     }
 
 

+ 35 - 22
jeecg-module-gather/src/main/java/org/jeecg/modules/leanEventWarn/service/impl/LeanEventWarnInfoServiceImpl.java

@@ -1,6 +1,8 @@
 package org.jeecg.modules.leanEventWarn.service.impl;
+import cn.hutool.core.date.LocalDateTimeUtil;
 import org.jeecg.modules.events.entity.LeanEventsHost;
 import org.jeecg.modules.gatherData.entity.FpgStatiscsModelData;
+import org.jeecg.modules.gatherData.entity.FpgStatiscsModelMongodb;
 import org.jeecg.modules.leanEventWarn.entity.LeanEventWarnInfo;
 import org.jeecg.modules.leanEventWarn.entity.LeanEventsHostConfig;
 import org.jeecg.modules.leanEventWarn.mapper.LeanEventWarnInfoMapper;
@@ -30,6 +32,7 @@ import java.time.LocalDateTime;
 import java.time.ZoneId;
 import java.time.format.DateTimeFormatter;
 import java.util.ArrayList;
+import java.util.Calendar;
 import java.util.Date;
 import java.util.List;
 import java.util.stream.Collectors;
@@ -266,14 +269,14 @@ public class LeanEventWarnInfoServiceImpl extends ServiceImpl<LeanEventWarnInfoM
             }
         });
         // 根据类型、采集点ID、设备ID、区域ID、峰平谷配置时间范围查询mongoDB
-        List<FpgStatiscsModelData> fpgStatiscsModelDataList = queryByTimeRanges(mongoTemplate, timeRanges, fpgGatherData.getDevicePointId(), fpgGatherData.getDeviceInformationId(), fpgGatherData.getDeviceRegionId());
+        List<FpgStatiscsModelMongodb> fpgStatiscsModelDataList = queryByTimeRanges(mongoTemplate, timeRanges, fpgGatherData.getDevicePointId(), fpgGatherData.getDeviceInformationId(), fpgGatherData.getDeviceRegionId());
         if (!oConvertUtils.listIsNotEmpty(fpgStatiscsModelDataList) ){
             return;
         }
         // 判断MongoDB中的累加运行时长是否大于 LeanEventsHostConfig中的尖峰平谷运行限制时长
         int runTimeLimit = Integer.parseInt(leanEventsHostConfig.getRunTime());
         if("tops".equals(leanEventsHost.getDeviceInformationId())){
-            BigDecimal topsIngTimeSum = fpgStatiscsModelDataList.stream().map(FpgStatiscsModelData::getTopsIngTime)
+            BigDecimal topsIngTimeSum = fpgStatiscsModelDataList.stream().map(FpgStatiscsModelMongodb::getTopsIngTime)
                     .reduce(BigDecimal.ZERO, BigDecimal::add).divide(new BigDecimal(60), 0, RoundingMode.CEILING);
             if (topsIngTimeSum.intValue() > runTimeLimit){
                 // 尖——累加运行时长超过限制时长,触发告警
@@ -284,7 +287,7 @@ public class LeanEventWarnInfoServiceImpl extends ServiceImpl<LeanEventWarnInfoM
                 saveOrUpdateLeanEventWarnInfo(fpgGatherData, leanEventWarnInfo);
             }
         }else if ("peaks".equals(leanEventsHost.getDeviceInformationId())){
-            BigDecimal peaksIngTimeSum = fpgStatiscsModelDataList.stream().map(FpgStatiscsModelData::getPeaksIngTime)
+            BigDecimal peaksIngTimeSum = fpgStatiscsModelDataList.stream().map(FpgStatiscsModelMongodb::getPeaksIngTime)
                     .reduce(BigDecimal.ZERO, BigDecimal::add).divide(new BigDecimal(60), 0, RoundingMode.CEILING);
             if (peaksIngTimeSum.intValue() > runTimeLimit){
                 // 峰——累加运行时长超过限制时长,触发告警
@@ -295,7 +298,7 @@ public class LeanEventWarnInfoServiceImpl extends ServiceImpl<LeanEventWarnInfoM
                 saveOrUpdateLeanEventWarnInfo(fpgGatherData, leanEventWarnInfo);
             }
         }else if ("flat".equals(leanEventsHost.getDeviceInformationId())){
-            BigDecimal flatIngTimeSum = fpgStatiscsModelDataList.stream().map(FpgStatiscsModelData::getFlatIngTime)
+            BigDecimal flatIngTimeSum = fpgStatiscsModelDataList.stream().map(FpgStatiscsModelMongodb::getFlatIngTime)
                     .reduce(BigDecimal.ZERO, BigDecimal::add).divide(new BigDecimal(60), 0, RoundingMode.CEILING);
             if (flatIngTimeSum.intValue() > runTimeLimit){
                 // 平——累加运行时长超过限制时长,触发告警
@@ -306,7 +309,7 @@ public class LeanEventWarnInfoServiceImpl extends ServiceImpl<LeanEventWarnInfoM
                 saveOrUpdateLeanEventWarnInfo(fpgGatherData, leanEventWarnInfo);
             }
         } else if ("valleys".equals(leanEventsHost.getDeviceInformationId())) {
-            BigDecimal valleysIngTimeSum = fpgStatiscsModelDataList.stream().map(FpgStatiscsModelData::getValleysIngTime)
+            BigDecimal valleysIngTimeSum = fpgStatiscsModelDataList.stream().map(FpgStatiscsModelMongodb::getValleysIngTime)
                     .reduce(BigDecimal.ZERO, BigDecimal::add).divide(new BigDecimal(60), 0, RoundingMode.CEILING);
             if (valleysIngTimeSum.intValue() > runTimeLimit){
                 // 谷——累加运行时长超过限制时长,触发告警
@@ -330,7 +333,7 @@ public class LeanEventWarnInfoServiceImpl extends ServiceImpl<LeanEventWarnInfoM
         // 根据辅设备ID、事件ID、限制类型,获取精益时间配置关联信息
         LambdaQueryWrapper<LeanEventsHostConfig> queryWrapper = new LambdaQueryWrapper<>();
         queryWrapper.eq(LeanEventsHostConfig::getDeviceInformationListId, fpgGatherData.getDeviceInformationId())
-                .eq(LeanEventsHostConfig::getEventsId, leanEventsHost.getEventsId()).eq(LeanEventsHostConfig::getLimitType, "0");
+                .eq(LeanEventsHostConfig::getEventsId, leanEventsHost.getEventsId()).eq(LeanEventsHostConfig::getLimitType, "1");
         LeanEventsHostConfig leanEventsHostConfig = leanEventsHostConfigService.list(queryWrapper).stream().findFirst().orElse(null);
         if (leanEventsHostConfig == null){
             return;
@@ -349,49 +352,49 @@ public class LeanEventWarnInfoServiceImpl extends ServiceImpl<LeanEventWarnInfoM
             }
         });
         // 根据类型、采集点ID、设备ID、区域ID、峰平谷配置时间范围查询mongoDB
-        List<FpgStatiscsModelData> fpgStatiscsModelDataList = queryByTimeRanges(mongoTemplate, timeRanges, fpgGatherData.getDevicePointId(), fpgGatherData.getDeviceInformationId(), fpgGatherData.getDeviceRegionId());
+        List<FpgStatiscsModelMongodb> fpgStatiscsModelDataList = queryByTimeRanges(mongoTemplate, timeRanges, fpgGatherData.getDevicePointId(), fpgGatherData.getDeviceInformationId(), fpgGatherData.getDeviceRegionId());
         if (!oConvertUtils.listIsNotEmpty(fpgStatiscsModelDataList) ){
             return;
         }
         // 判断MongoDB中的累加运行时长是否大于 LeanEventsHostConfig中的尖峰平谷运行限制时长
-        int runTimeLimit = Integer.parseInt(leanEventsHostConfig.getRunTime());
+        int powerLimit = Integer.parseInt(leanEventsHostConfig.getPowerLimit());
         if("tops".equals(leanEventsHost.getDeviceInformationId())){
-            BigDecimal topsPowerLimitSum = fpgStatiscsModelDataList.stream().map(FpgStatiscsModelData::getTopsPower)
+            BigDecimal topsPowerLimitSum = fpgStatiscsModelDataList.stream().map(FpgStatiscsModelMongodb::getTopsPower)
                     .reduce(BigDecimal.ZERO, BigDecimal::add).divide(new BigDecimal(60), 0, RoundingMode.CEILING);
-            if (topsPowerLimitSum.intValue() > runTimeLimit){
+            if (topsPowerLimitSum.intValue() > powerLimit){
                 // 尖——累加累计功率超过功率限制,触发告警
-                leanEventWarnInfo.setDeviceWarnInfo("事件类型为FPG_ING_TIME,尖累计功率超过功率限制,触发告警!");
+                leanEventWarnInfo.setDeviceWarnInfo("事件类型为FPG_POWER_LIMIT,尖累计功率超过功率限制,触发告警!");
                 leanEventWarnInfo.setWarnType("1");
                 leanEventWarnInfo.setDeviceWarnLevel("0");
                 // 更新或者新增逻辑处理
                 saveOrUpdateLeanEventWarnInfo(fpgGatherData, leanEventWarnInfo);
             }
         }else if ("peaks".equals(leanEventsHost.getDeviceInformationId())){
-            BigDecimal peaksPowerLimitSum = fpgStatiscsModelDataList.stream().map(FpgStatiscsModelData::getPeaksPower)
+            BigDecimal peaksPowerLimitSum = fpgStatiscsModelDataList.stream().map(FpgStatiscsModelMongodb::getPeaksPower)
                     .reduce(BigDecimal.ZERO, BigDecimal::add).divide(new BigDecimal(60), 0, RoundingMode.CEILING);
-            if (peaksPowerLimitSum.intValue() > runTimeLimit){
+            if (peaksPowerLimitSum.intValue() > powerLimit){
                 // 峰——累加累计功率超过功率限制,触发告警
-                leanEventWarnInfo.setDeviceWarnInfo("事件类型为FPG_ING_TIME,峰累计功率超过功率限制,触发告警!");
+                leanEventWarnInfo.setDeviceWarnInfo("事件类型为FPG_POWER_LIMIT,峰累计功率超过功率限制,触发告警!");
                 leanEventWarnInfo.setWarnType("1");
                 leanEventWarnInfo.setDeviceWarnLevel("0");
                 // 更新或者新增逻辑处理
                 saveOrUpdateLeanEventWarnInfo(fpgGatherData, leanEventWarnInfo);
             }
         }else if ("flat".equals(leanEventsHost.getDeviceInformationId())){
-            BigDecimal flatPowerLimitSum = fpgStatiscsModelDataList.stream().map(FpgStatiscsModelData::getFlatPower)
+            BigDecimal flatPowerLimitSum = fpgStatiscsModelDataList.stream().map(FpgStatiscsModelMongodb::getFlatPower)
                     .reduce(BigDecimal.ZERO, BigDecimal::add).divide(new BigDecimal(60), 0, RoundingMode.CEILING);
-            if (flatPowerLimitSum.intValue() > runTimeLimit){
+            if (flatPowerLimitSum.intValue() > powerLimit){
                 // 平——累加累计功率超过功率限制,触发告警
-                leanEventWarnInfo.setDeviceWarnInfo("事件类型为FPG_ING_TIME,平累计功率超过功率限制,触发告警!");
+                leanEventWarnInfo.setDeviceWarnInfo("事件类型为FPG_POWER_LIMIT,平累计功率超过功率限制,触发告警!");
                 leanEventWarnInfo.setWarnType("1");
                 leanEventWarnInfo.setDeviceWarnLevel("0");
                 // 更新或者新增逻辑处理
                 saveOrUpdateLeanEventWarnInfo(fpgGatherData, leanEventWarnInfo);
             }
         } else if ("valleys".equals(leanEventsHost.getDeviceInformationId())) {
-            BigDecimal valleysPowerLimitSum = fpgStatiscsModelDataList.stream().map(FpgStatiscsModelData::getValleysPower)
+            BigDecimal valleysPowerLimitSum = fpgStatiscsModelDataList.stream().map(FpgStatiscsModelMongodb::getValleysPower)
                     .reduce(BigDecimal.ZERO, BigDecimal::add).divide(new BigDecimal(60), 0, RoundingMode.CEILING);
-            if (valleysPowerLimitSum.intValue() > runTimeLimit){
+            if (valleysPowerLimitSum.intValue() > powerLimit){
                 // 谷——累加累计功率超过功率限制,触发告警
                 leanEventWarnInfo.setDeviceWarnInfo("事件类型为FPG_POWER_LIMIT,谷累计功率超过功率限制,触发精益事件告警!");
                 leanEventWarnInfo.setWarnType("1");
@@ -411,7 +414,7 @@ public class LeanEventWarnInfoServiceImpl extends ServiceImpl<LeanEventWarnInfoM
      * @param deviceRegionId
      * @return
      */
-    public List<FpgStatiscsModelData> queryByTimeRanges(MongoTemplate mongoTemplate, List<Date[]> timeRanges, String devicePointId, String deviceInformationId, String deviceRegionId) {
+    public List<FpgStatiscsModelMongodb> queryByTimeRanges(MongoTemplate mongoTemplate, List<Date[]> timeRanges, String devicePointId, String deviceInformationId, String deviceRegionId) {
         Query query = new Query();
         query.addCriteria(Criteria.where("devicePointId").is(devicePointId));
         query.addCriteria(Criteria.where("deviceInformationId").is(deviceInformationId));
@@ -419,11 +422,21 @@ public class LeanEventWarnInfoServiceImpl extends ServiceImpl<LeanEventWarnInfoM
         // 使用Criteria添加多个时间范围条件
         for (int i = 0; i < timeRanges.size(); i++) {
             Date startTime = timeRanges.get(i)[0];
+            // 加8小时
+            Calendar calendar1 = Calendar.getInstance();
+            calendar1.setTime(startTime);
+            calendar1.add(Calendar.HOUR, 8);
+            Date specifiedTimePlus8HoursStartTime = calendar1.getTime();
             Date endTime = timeRanges.get(i)[1];
-            query.addCriteria(Criteria.where("createTime").gte(startTime).lt(endTime));
+            Calendar calendar2 = Calendar.getInstance();
+            calendar2.setTime(endTime);
+            calendar2.add(Calendar.HOUR, 8);
+            Date specifiedTimePlus8HoursStartEndTime = calendar2.getTime();
+            query.addCriteria(Criteria.where("createTime").gte(specifiedTimePlus8HoursStartTime).lt(specifiedTimePlus8HoursStartEndTime));
         }
         // 执行查询
-        return mongoTemplate.find(query, FpgStatiscsModelData.class);
+        List<FpgStatiscsModelMongodb> fpgStatiscsModelDataList = mongoTemplate.find(query, FpgStatiscsModelMongodb.class, "leanmodel_run_power_minute");
+        return fpgStatiscsModelDataList;
     }
 
     /**