Jelajahi Sumber

修改湿球温度计算逻辑

miaolijing 3 tahun lalu
induk
melakukan
48deddc40a

+ 8 - 62
src/main/java/com/persagy/apm/diagnose/maintenance/service/impl/ProjectDataRecordServiceImpl.java

@@ -29,9 +29,7 @@ import com.persagy.apm.energyalarmstarter.alarmdata.model.dto.alarmrecord.AddAla
 import com.persagy.apm.energyalarmstarter.alarmdata.model.dto.alarmrecord.BatchUpdateAlarmRecordDTO;
 import com.persagy.apm.energyalarmstarter.alarmdata.model.dto.alarmrecord.QueryAlarmRecordDTO;
 import com.persagy.apm.energyalarmstarter.alarmdata.model.dto.alarmrecord.UpdateAlarmRecordDTO;
-import com.persagy.apm.energyalarmstarter.alarmdata.model.vo.AlarmConfigItem;
 import com.persagy.apm.energyalarmstarter.alarmdata.model.vo.AlarmRecordItem;
-import com.persagy.apm.energyalarmstarter.alarmdata.service.AlarmConfigServiceImpl;
 import com.persagy.apm.energyalarmstarter.alarmdata.service.AlarmRecordServiceImpl;
 import com.persagy.apm.energyalarmstarter.collectdata.websocket.AlarmWebSocketServer;
 import com.persagy.framework.ems.data.core.enumeration.SpecialOperator;
@@ -72,7 +70,6 @@ public class ProjectDataRecordServiceImpl implements IProjectDataRecordService {
 
     //报警分类
     public final static String alarmSplit = "_";
-    private final static Long ConfigItemKeyTime = 60 * 60 * 1000L;
     private final static Long SendDataTimeKeyTime = 24 * 60 * 60 * 1000L;
     private final static Double TwdTemp_Limit = 0.1;
 
@@ -102,7 +99,7 @@ public class ProjectDataRecordServiceImpl implements IProjectDataRecordService {
 
     @Override
     @Async("asyncComputeMaintenanceDataExecutor")
-    public Future<String> computeMaintenanceData(Date todayDate,ProjectDTO projectDTO, CountDownLatch latch) throws Exception {
+    public Future<String> computeMaintenanceData(Date todayDate,ProjectDTO projectDTO, CountDownLatch latch) {
         long time = System.currentTimeMillis() + (20 * 1000);
         try {
             if (!lockUtil.lock(projectDTO.getProjectId() + "_computeMaintenance", String.valueOf(time))) {
@@ -146,7 +143,7 @@ public class ProjectDataRecordServiceImpl implements IProjectDataRecordService {
 
     @Override
     @Async("asyncGoingDestroyEquipExecutor")
-    public Future<String> syncGoingDestroyEquip(String projectId, CountDownLatch latch) throws Exception {
+    public Future<String> syncGoingDestroyEquip(String projectId, CountDownLatch latch) {
         long time = System.currentTimeMillis() + (20 * 1000);
         try {
             if (!lockUtil.lock(projectId + "_syncEquip", String.valueOf(time))) {
@@ -181,11 +178,8 @@ public class ProjectDataRecordServiceImpl implements IProjectDataRecordService {
             List<UpdateAlarmRecordDTO> updateAlarmRecordDTOList = new ArrayList<>();
             if (!CollectionUtils.isEmpty(equipSet)) {
                 for (String equipId : equipSet) {
-                    if (null != alarmRecordItemMap && alarmRecordItemMap.containsKey(equipId)) {
-                        if (null != equipInfoMap && equipInfoMap.containsKey(equipId)) {
-                            //同时存在于 报废记录和报警记录,跳过不处理
-                            continue;
-                        } else {
+                    if (alarmRecordItemMap.containsKey(equipId)) {
+                        if (!equipInfoMap.containsKey(equipId)) {
                             //存在于报警记录和但不在报废记录,将报警状态修改为 已恢复
                             AlarmRecordItem alarmRecordItem = alarmRecordItemMap.get(equipId);
                             if (EnumAlarmState.UN_HANDLE.getCode().equals(alarmRecordItem.getState())) {
@@ -197,9 +191,10 @@ public class ProjectDataRecordServiceImpl implements IProjectDataRecordService {
                                 updateAlarmRecordDTOList.add(updateAlarmRecordDTO);
                             }
                         }
+                        //同时存在于 报废记录和报警记录,跳过不处理
                     } else {
                         //不存在于报警列表  在即将报废列表   新产生报警信息
-                        if (null != equipInfoMap && equipInfoMap.containsKey(equipId)) {
+                        if (equipInfoMap.containsKey(equipId)) {
                             saveAlarmEquipIdList.add(equipId);
                         }
                     }
@@ -353,7 +348,7 @@ public class ProjectDataRecordServiceImpl implements IProjectDataRecordService {
                 for (String objId : objIds) {
                     String key = objId + "_" + alarmItemCode;
                     if (!objIdAlarmItemCodeAndInfoCodes.containsKey(key)) {
-                        objIdAlarmItemCodeAndInfoCodes.put(key, new ArrayList<String>());
+                        objIdAlarmItemCodeAndInfoCodes.put(key, new ArrayList<>());
                     }
                     objIdAlarmItemCodeAndInfoCodes.get(key).add(infoCode);
                 }
@@ -1007,55 +1002,6 @@ public class ProjectDataRecordServiceImpl implements IProjectDataRecordService {
     }
 
     /**
-     * redis中查询报警条件上次发数时间, 如果查询为空, 则初始化当前时间
-     */
-//    private ConfigItemDataSendTimeDTO getConfigItemSendTimeDTO(String projectId, AlarmConfigItem alarmConfigItem, Date defaultDate) {
-//        ConfigItemDataSendTimeDTO sendTimeDTO = (ConfigItemDataSendTimeDTO) redisUtil.hget(RedisUtil.PROJECT_ITEM_SEND_TIME + ":" + projectId, alarmConfigItem.getId());
-////        ConfigItemDataSendTimeDTO sendTimeDTO = null;
-//        if (sendTimeDTO == null) {
-//            sendTimeDTO = ConfigItemDataSendTimeDTO.builder().objId(alarmConfigItem.getObjId()).configItemid(alarmConfigItem.getId()).lastSendTime(defaultDate).build();
-//        }
-//        return sendTimeDTO;
-//    }
-
-    /**
-     * 从缓存中获取报警条件, 如果缓存不存在, 则查询报警服务, 报警条件配置
-     */
-//    private List<AlarmConfigItem> getAlarmConfigItemList(String projectId) throws Exception {
-//        List<AlarmConfigItem> itemList = (List<AlarmConfigItem>) redisUtil.hget(RedisUtil.PROJECT_ALARM_ITEM, projectId);
-//        if (CollectionUtils.isEmpty(itemList)) {
-//            QueryAlarmConfigDTO queryAlarmConfigDTO = new QueryAlarmConfigDTO();
-//            queryAlarmConfigDTO.setProjectId(projectId);
-//            queryAlarmConfigDTO.setGroupCode(systemCode);
-//            queryAlarmConfigDTO.setCategory(Collections.singletonList(EnumAlarmCategory.EQWB.getCode()));
-//            queryAlarmConfigDTO.setOpen(1);
-//            DmpResult<List<AlarmConfigItem>> configItemResult = alarmConfigService.query(queryAlarmConfigDTO);
-//            itemList = DmpResultUtil.getData(configItemResult);
-//            redisUtil.hset(RedisUtil.PROJECT_ALARM_ITEM, projectId, itemList, ConfigItemKeyTime);
-//        } else {
-//            List<AlarmConfigItem> newItemList = new ArrayList<>();
-//            itemList.forEach(alarmConfigItem -> {
-//                if (alarmConfigItem.getCategory().equals(EnumAlarmCategory.EQWB.getCode())) {
-//                    newItemList.add(alarmConfigItem);
-//                }
-//            });
-//            if (CollectionUtils.isEmpty(newItemList)) {
-//                QueryAlarmConfigDTO queryAlarmConfigDTO = new QueryAlarmConfigDTO();
-//                queryAlarmConfigDTO.setProjectId(projectId);
-//                queryAlarmConfigDTO.setGroupCode(systemCode);
-//                queryAlarmConfigDTO.setCategory(Collections.singletonList(EnumAlarmCategory.EQWB.getCode()));
-//                queryAlarmConfigDTO.setOpen(1);
-//                DmpResult<List<AlarmConfigItem>> configItemResult = alarmConfigService.query(queryAlarmConfigDTO);
-//                itemList = DmpResultUtil.getData(configItemResult);
-//                redisUtil.hset(RedisUtil.PROJECT_ALARM_ITEM, projectId, itemList, ConfigItemKeyTime);
-//            } else {
-//                itemList = newItemList;
-//            }
-//        }
-//        return itemList;
-//    }
-
-    /**
      * 获取报警记录
      */
     private Map<String, AlarmRecordItem> getAlarmRecordItemMap(String projectId) throws Exception {
@@ -1068,7 +1014,7 @@ public class ProjectDataRecordServiceImpl implements IProjectDataRecordService {
         DmpResult<List<AlarmRecordItem>> configItemResultList = alarmRecordService.query(queryAlarmRecordDTO);
         List<AlarmRecordItem> alarmRecordItemList = DmpResultUtil.getData(configItemResultList);
         if (!CollectionUtils.isEmpty(alarmRecordItemList)){
-            alarmRecordItemList.stream().collect(Collectors.toMap(AlarmRecordItem::getObjId, Function.identity(), (a, b) -> b));
+            return alarmRecordItemList.stream().collect(Collectors.toMap(AlarmRecordItem::getObjId, Function.identity(), (a, b) -> b));
         }
         return new HashMap<>();
     }

+ 9 - 1
src/main/java/com/persagy/apm/diagnose/utils/TwdTempUtil.java

@@ -14,6 +14,7 @@ public class TwdTempUtil {
             Double hVal = getHVal(Td,Hr);
             //根据允许范围推出Tw值
             Double newTw = getTw(Td,hVal,limit);
+            System.out.println(newTw);
         } catch (Exception e) {
             e.printStackTrace();
         }
@@ -27,6 +28,7 @@ public class TwdTempUtil {
         Double num = 0.0;
         Boolean isOk = false;
         Boolean isTrueVal = false;
+        Integer zNum = 0,jNum = 0;
         while (!isOk){
             //湿空气焓值
             Double hwVal = getHwVal(Tw);
@@ -38,8 +40,10 @@ public class TwdTempUtil {
                 isTrueVal = true;
             }else if (hc > 0){//hw 小于 h  增加湿球温度数据值
                 Tw = Tw + 0.25;
+                zNum++;
             }else if (hc < 0){//hw 大于 h  减小湿球温度数据值
                 Tw = Tw - 0.25;
+                jNum++;
             }
             num++;
             if (num > 20){
@@ -49,7 +53,11 @@ public class TwdTempUtil {
         if (isTrueVal){
             return Tw;
         }else {
-            return getTw(Td,hVal,limit+0.5);
+            if (zNum > 0 && jNum > 0){
+                return Tw;
+            }else{
+                return getTw(Td,hVal,limit+0.5);
+            }
         }
     }