Просмотр исходного кода

如果没有数据发送,不更新最新发数时间

lixing 3 лет назад
Родитель
Сommit
b83d2a30d1

+ 25 - 21
src/main/java/com/persagy/apm/diagnose/indicatorrecord/service/impl/MonitorIndicatorRecordServiceImpl.java

@@ -137,7 +137,7 @@ public class MonitorIndicatorRecordServiceImpl implements IMonitorIndicatorRecor
 
 
     private AsyncResult<String> computeProjectIndicatorData(ProjectDTO projectDTO, ProjectIndicatorCompute projectIndicatorCompute) throws Exception {
-//        log.info(Thread.currentThread().getName() + "开始计算[{}]的设备运行诊断监测指标", projectDTO.getProjectId());
+        //        log.info(Thread.currentThread().getName() + "开始计算[{}]的设备运行诊断监测指标", projectDTO.getProjectId());
 
         //判断当前计算轮次是否大于缓存中最新计算轮次,如果是,则证明已经被计算过,则略过
         if (checkProjectIsCalcd(projectDTO.getProjectId(), projectIndicatorCompute)) {
@@ -157,7 +157,7 @@ public class MonitorIndicatorRecordServiceImpl implements IMonitorIndicatorRecor
         }
 
         Set<String> objIdAndIndicatorId = getObjIdAndInfoCodeFromRules(projectAlarmRules);
-//        log.debug(Thread.currentThread().getName() + "共有{}个监测指标需要计算", objIdAndIndicatorId.size());
+        //        log.debug(Thread.currentThread().getName() + "共有{}个监测指标需要计算", objIdAndIndicatorId.size());
         if (CollectionUtils.isEmpty(objIdAndIndicatorId)) {
             return new AsyncResult<>("【监测指标数据计算线程】当前项目:" + projectDTO.getProjectId() + "报警规则未关联对象");
         }
@@ -179,12 +179,12 @@ public class MonitorIndicatorRecordServiceImpl implements IMonitorIndicatorRecor
         String methodId = energyAlarmService.queryObjIndicatorMethodId(projectDTO.getProjectId(), objId, indicatorId);
         if (StringUtils.isBlank(methodId)) {
             log.error("【监测指标数据计算线程】:项目监控指标未设置公式:" + projectDTO.getProjectId() + ";" + objId + ";" + indicatorId);
-                return;
+            return;
         }
         CalculateMethodDTO calculateMethodDTO = methodIdAndMethodDTO.get(methodId);
         if (calculateMethodDTO == null) {
             log.error("【监测指标数据计算线程】:项目监控指标设置公式为null:" + projectDTO.getProjectId() + ";" + objId + ";" + indicatorId);
-                return;
+            return;
         }
         if (lastComputeTime == null) {
             lastComputeTime = getDefultStartTime();
@@ -193,7 +193,7 @@ public class MonitorIndicatorRecordServiceImpl implements IMonitorIndicatorRecor
         String formula = calculateMethodDTO.getFormula();
         if (StringUtils.isBlank(formula)) {
             log.error("【监测指标数据计算线程】:项目监控指标设置公式为null:" + projectDTO.getProjectId() + ";" + objId + ";" + indicatorId);
-                return;
+            return;
         }
         Date computeTime = computeIndicatorData(projectDTO, objId, lastComputeTime, computeEndTime, indicatorId, formula);
         if (computeTime == null) {
@@ -204,7 +204,6 @@ public class MonitorIndicatorRecordServiceImpl implements IMonitorIndicatorRecor
 
     /**
      * 判断项目是否已经被计算
-     *
      */
     private Boolean checkProjectIsCalcd(String projectId, ProjectIndicatorCompute projectIndicatorCompute) {
         Object redisComputeRound = redisUtil.hget(DiAgnoseConst.RedisConstants.TargetComputeTime, projectId);
@@ -381,16 +380,16 @@ public class MonitorIndicatorRecordServiceImpl implements IMonitorIndicatorRecor
 
     @Override
     public void cleanAlarmConfigSendTime(CleanAlarmConfigDTO cleanAlarmConfigDTO) {
-//        if (StringUtils.isBlank(cleanAlarmConfigDTO.getProjectId())) {
-//            //清除所有
-//            redisUtil.del(DiAgnoseConst.RedisConstants.PROJECT_ITEM_SEND_TIME);
-//        } else if (StringUtils.isBlank(cleanAlarmConfigDTO.getAlarmConfigItemId())) {
-//            //清除项目
-//            redisUtil.del(DiAgnoseConst.RedisConstants.PROJECT_ALARM_ITEM + ":" + cleanAlarmConfigDTO.getProjectId());
-//        } else {
-//            //清除指定
-//            redisUtil.hdel(DiAgnoseConst.RedisConstants.PROJECT_ALARM_ITEM + ":" + cleanAlarmConfigDTO.getProjectId(), cleanAlarmConfigDTO.getAlarmConfigItemId());
-//        }
+        //        if (StringUtils.isBlank(cleanAlarmConfigDTO.getProjectId())) {
+        //            //清除所有
+        //            redisUtil.del(DiAgnoseConst.RedisConstants.PROJECT_ITEM_SEND_TIME);
+        //        } else if (StringUtils.isBlank(cleanAlarmConfigDTO.getAlarmConfigItemId())) {
+        //            //清除项目
+        //            redisUtil.del(DiAgnoseConst.RedisConstants.PROJECT_ALARM_ITEM + ":" + cleanAlarmConfigDTO.getProjectId());
+        //        } else {
+        //            //清除指定
+        //            redisUtil.hdel(DiAgnoseConst.RedisConstants.PROJECT_ALARM_ITEM + ":" + cleanAlarmConfigDTO.getProjectId(), cleanAlarmConfigDTO.getAlarmConfigItemId());
+        //        }
         // 清除所有iot数据发送时间
         clearAllIotDataSendTime();
         // 删除报警条件状态缓存
@@ -432,7 +431,7 @@ public class MonitorIndicatorRecordServiceImpl implements IMonitorIndicatorRecor
     private void sendIndicatorDataToAlarmServer(ProjectDTO projectDTO) throws Exception {
         //通过报警服务查询报警规则
         List<AlarmRuleDTO> projectAlarmRules = energyAlarmService.getProjectAlarmRules(projectDTO.getProjectId());
-//        log.error("获取到的项目报警规则:" + projectDTO.getProjectId() + ";" + projectAlarmRules);
+        //        log.error("获取到的项目报警规则:" + projectDTO.getProjectId() + ";" + projectAlarmRules);
         if (CollectionUtils.isEmpty(projectAlarmRules)) {
             return;
         }
@@ -441,7 +440,7 @@ public class MonitorIndicatorRecordServiceImpl implements IMonitorIndicatorRecor
         if (CollectionUtils.isEmpty(objIdAlarmItemCodeAndInfoCodes) || objIdAlarmItemCodeAndInfoCodes.size() == 0) {
             return;
         }
-//        log.error("获取到的设备与监测点位映射关系:" + objIdAlarmItemCodeAndInfoCodes);
+        //        log.error("获取到的设备与监测点位映射关系:" + objIdAlarmItemCodeAndInfoCodes);
         for (Map.Entry<String, List<String>> entry : objIdAlarmItemCodeAndInfoCodes.entrySet()) {
             String objIdAndAlarmItemCode = entry.getKey();
             int indexOf = objIdAndAlarmItemCode.indexOf("_");
@@ -449,7 +448,7 @@ public class MonitorIndicatorRecordServiceImpl implements IMonitorIndicatorRecor
             String alarmItemCode = objIdAndAlarmItemCode.substring(indexOf + 1);
             String lockKey = AlarmConstants.alarmDataLockPrefix + objId + "-" + alarmItemCode;
             Object isLock = redisUtil.get(lockKey);
-//            log.error("是否获取到锁:" + isLock);
+            //            log.error("是否获取到锁:" + isLock);
             if (null != isLock) {
                 continue;
             }
@@ -460,12 +459,12 @@ public class MonitorIndicatorRecordServiceImpl implements IMonitorIndicatorRecor
 
             //通过redis查询对象该报警类型下的发数截止时间
             ConfigItemDataSendTimeDTO configItemSendTimeDTO = getConfigItemSendTimeDTO(projectDTO, objIdAndAlarmItemCode);
-//            log.error("发数截止时间:" + objIdAndAlarmItemCode + "," + configItemSendTimeDTO);
+            //            log.error("发数截止时间:" + objIdAndAlarmItemCode + "," + configItemSendTimeDTO);
             Date lastSendTime = configItemSendTimeDTO.getLastSendTime();
             Date endTime = getSendEndTime(lastSendTime);
 
             Map<String, List<MonitorIndicatorRecord>> timeKeyAndRecordList = getTimekeyAndRecordListGteLt(projectDTO, objId, infCodeList, lastSendTime, endTime);
-//            log.error("本次需要发的数:" + timeKeyAndRecordList);
+            //            log.error("本次需要发的数:" + timeKeyAndRecordList);
             if (timeKeyAndRecordList == null) {
                 continue;
             }
@@ -478,6 +477,11 @@ public class MonitorIndicatorRecordServiceImpl implements IMonitorIndicatorRecor
                 sendTimeKeyAndDataList.put(dateListEntry.getKey(), value);
                 endTime = DateUtils.str2Date(dateListEntry.getKey(), DateUtils.SDFSECOND);
             }
+
+            if (sendTimeKeyAndDataList.size() == 0) {
+                continue;
+            }
+
             JSONArray sendArray = CollectDataUtil.batchBuildSendJsonParam(sendTimeKeyAndDataList, alarmItemCode);
 
             try {