ソースを参照

修复 redis获取数据转换对象失败问题

miaolijing 3 年 前
コミット
18d4ca60f9

+ 7 - 2
src/main/java/com/persagy/apm/diagnose/indicatorrecord/service/impl/MonitorIndicatorRecordServiceImpl.java

@@ -1,5 +1,7 @@
 package com.persagy.apm.diagnose.indicatorrecord.service.impl;
 
+import cn.hutool.json.JSONUtil;
+import com.alibaba.fastjson.JSON;
 import com.alibaba.fastjson.JSONArray;
 import com.alibaba.fastjson.JSONObject;
 import com.persagy.apm.diagnose.config.ComputePropertiesConfig;
@@ -502,8 +504,11 @@ public class MonitorIndicatorRecordServiceImpl implements IMonitorIndicatorRecor
      * @return: com.persagy.apm.diagnose.indicatorrecord.model.dto.ConfigItemDataSendTimeDTO
      */
     private ConfigItemDataSendTimeDTO getConfigItemSendTimeDTO(ProjectDTO projectDTO, String objIdAndAlarmItemCode) throws Exception {
-        ConfigItemDataSendTimeDTO sendTimeDTO = (ConfigItemDataSendTimeDTO) redisUtil.get(getRedisSendDataKey(projectDTO.getProjectId(), objIdAndAlarmItemCode));
-        if (sendTimeDTO == null) {
+        ConfigItemDataSendTimeDTO sendTimeDTO = null;
+        Object obj = redisUtil.get(getRedisSendDataKey(projectDTO.getProjectId(),objIdAndAlarmItemCode));
+        if (null != obj){
+            sendTimeDTO =  JSONUtil.toBean(JSON.toJSONString(obj), ConfigItemDataSendTimeDTO.class);
+        }else{
             sendTimeDTO = ConfigItemDataSendTimeDTO.builder().lastSendTime(getDefultStartTime()).build();
         }
         return sendTimeDTO;

+ 10 - 4
src/main/java/com/persagy/apm/diagnose/maintenance/service/impl/ProjectDataRecordServiceImpl.java

@@ -1,5 +1,6 @@
 package com.persagy.apm.diagnose.maintenance.service.impl;
 
+import cn.hutool.json.JSONUtil;
 import com.alibaba.fastjson.JSON;
 import com.alibaba.fastjson.JSONArray;
 import com.alibaba.fastjson.JSONObject;
@@ -134,8 +135,10 @@ public class ProjectDataRecordServiceImpl implements IProjectDataRecordService {
                 return new AsyncResult<>("【监测维保数据推送线程】:项目:" + projectId + "被占用");
             }
 
+            getConfigItemSendTimeDTO("Pj1101060001","Eq11010600010b63c95c53e342c193d280357f491d9e_Eqdx002");
+
             long start = System.currentTimeMillis();
-            sendProjectMaintenanceData(todayDate, projectId);
+//            sendProjectMaintenanceData(todayDate, projectId);
             long end = System.currentTimeMillis();
             return new AsyncResult<>("【监测维保数据推送线程】推送项目维保数据用时:" + projectId + ";" + (end - start));
         } finally {
@@ -371,8 +374,11 @@ public class ProjectDataRecordServiceImpl implements IProjectDataRecordService {
     }
 
     private ConfigItemDataSendTimeDTO getConfigItemSendTimeDTO(String projectId, String objIdAndAlarmItemCode) throws Exception {
-        ConfigItemDataSendTimeDTO sendTimeDTO = (ConfigItemDataSendTimeDTO) redisUtil.get(getRedisSendDataKey(projectId, objIdAndAlarmItemCode));
-        if (sendTimeDTO == null) {
+        ConfigItemDataSendTimeDTO sendTimeDTO = null;
+        Object obj = redisUtil.get(getRedisSendDataKey(projectId,objIdAndAlarmItemCode));
+        if (null != obj){
+            sendTimeDTO =  JSONUtil.toBean(JSON.toJSONString(obj), ConfigItemDataSendTimeDTO.class);
+        }else{
             sendTimeDTO = ConfigItemDataSendTimeDTO.builder().lastSendTime(getDefultStartTime()).build();
         }
         return sendTimeDTO;
@@ -1105,7 +1111,7 @@ public class ProjectDataRecordServiceImpl implements IProjectDataRecordService {
                         Double hVal = getHVal(dto.getTemperature(), dto.getHumidity());
                         //根据允许范围推出Tw值
                         Double Tw = getTw(dto.getTemperature(), hVal, TwdTemp_Limit);
-                        log.info("项目编号为:" + projectDTO.getProjectId() + "日期为:" + dto.getHourTime() + "温度:" + dto.getTemperature() + "湿度:" + dto.getHumidity() + "湿球温度:" + Tw);
+//                        log.info("项目编号为:" + projectDTO.getProjectId() + "日期为:" + dto.getHourTime() + "温度:" + dto.getTemperature() + "湿度:" + dto.getHumidity() + "湿球温度:" + Tw);
                         //小时时间
                         Date hour = dto.getHourTime();
                         Date nextHour = com.persagy.apm.diagnose.utils.DateUtils.addHours(hour, 1);

+ 1 - 1
src/main/java/com/persagy/apm/diagnose/service/MaintenanceDataService.java

@@ -79,7 +79,7 @@ public class MaintenanceDataService {
             try {
                 log.info(future.get());
             } catch (Exception e) {
-                log.error("发送指标数据错误:" + CommonUtils.getExceptionStackTrace(e));
+                log.error("发送维保数据错误:" + CommonUtils.getExceptionStackTrace(e));
             }
         });
     }