Browse Source

移除logback日志配置文件

lixing 3 years ago
parent
commit
80092c0cf0

+ 41 - 17
src/main/java/com/persagy/apm/diagnose/indicatorrecord/service/impl/MonitorIndicatorRecordServiceImpl.java

@@ -20,6 +20,7 @@ import com.persagy.apm.diagnose.timerecord.service.ICalculateTimeRecordService;
 import com.persagy.apm.diagnose.utils.*;
 import com.persagy.apm.energyalarmstarter.alarmdata.service.AlarmConfigServiceImpl;
 import com.persagy.apm.energyalarmstarter.collectdata.websocket.AlarmWebSocketServer;
+import com.persagy.framework.ems.data.core.enumeration.EMSOrder;
 import com.persagy.framework.ems.data.core.enumeration.SpecialOperator;
 import com.persagy.framework.ems.data.mvc.dao.CoreDao;
 import com.persagy.framework.ems.data.pojo.hbase.MonitorIndicatorRecord;
@@ -76,7 +77,7 @@ public class MonitorIndicatorRecordServiceImpl implements IMonitorIndicatorRecor
     public final static String alarmSlipt = "_";
 
 
-    private final static Long SendDataTimeKeyTime = 24 * 60 * 60 * 1000L;
+//    private final static Long SendDataTimeKeyTime = 24 * 60 * 60 * 1000L;
 
 
     @Autowired
@@ -365,28 +366,22 @@ public class MonitorIndicatorRecordServiceImpl implements IMonitorIndicatorRecor
             Date lastSendTime = configItemSendTimeDTO.getLastSendTime();
             Date endTime = getSendEndTime(lastSendTime);
 
-            List<MonitorIndicatorRecord> list = getMonitorIndicatorRecordsGtLte(projectDTO.getProjectId(), objId, lastSendTime, infCodeList, endTime);
-            if (CollectionUtils.isEmpty(list)) {
+            Map<String, List<MonitorIndicatorRecord>> timeKeyAndRecordList = getTimekeyAndRecordListGteLt(projectDTO, objId, infCodeList, lastSendTime, endTime);
+            if (timeKeyAndRecordList == null) {
                 continue;
             }
-            Map<String, List<MonitorIndicatorRecord>> timeKeyAndRecordList = new LinkedHashMap<>();
-            for (MonitorIndicatorRecord record : list) {
-                String timeKey = DateUtils.date2Str(record.getDataTime(), DateUtils.SDF_SECOND);
-                if (!timeKeyAndRecordList.containsKey(timeKey)) {
-                    timeKeyAndRecordList.put(timeKey, new ArrayList<>());
-                }
-                timeKeyAndRecordList.get(timeKey).add(record);
-            }
+           Map<String, List<MonitorIndicatorRecord>> sendTimeKeyAndDataList = new LinkedHashMap<>();
             for (Map.Entry<String, List<MonitorIndicatorRecord>> dateListEntry : timeKeyAndRecordList.entrySet()) {
                 List<MonitorIndicatorRecord> value = dateListEntry.getValue();
                 if (CollectionUtils.isEmpty(value) || value.size() != infCodeList.size()) {
                     continue;
                 }
-                String sentValue = CollectDataUtil.buildSendParam(value,alarmItemCode);
-                AlarmWebSocketServer.sendMsgToClients(projectDTO.getProjectId(), CollectDataUtil.buildSendParam(value,alarmItemCode));
-                log.info("指标发送报表服务数据:" + projectDTO.getProjectId()+";"+ sentValue);
-                endTime = DateUtils.str2Date(dateListEntry.getKey(), DateUtils.SDF_SECOND);
+                sendTimeKeyAndDataList.put(dateListEntry.getKey(),value);
+                endTime = DateUtils.str2Date(dateListEntry.getKey(), DateUtils.SDFSECOND);
             }
+            String sentValue = CollectDataUtil.batchBuildSendParam(sendTimeKeyAndDataList,alarmItemCode);
+            AlarmWebSocketServer.sendMsgToClients(projectDTO.getProjectId(), sentValue);
+            log.error("指标发送报表服务数据:" + projectDTO.getProjectId()+";"+ sentValue);
             configItemSendTimeDTO.setLastSendTime(endTime);
             configItemSendTimeDTO.setUpdateTime(new Date());
             updateRedisConfigItemSendTimeDTO(projectDTO.getProjectId(), objIdAndAlarmItemCode, configItemSendTimeDTO);
@@ -394,6 +389,35 @@ public class MonitorIndicatorRecordServiceImpl implements IMonitorIndicatorRecor
     }
 
     /**
+     * @title getTimekeyAndRecordListGteLt
+     * @description 查询该时间段的需要发送的指标数据,key为时间字符串
+     * @author leifeng
+     * @param: projectDTO
+     * @param: objId
+     * @param: infCodeList
+     * @param: lastSendTime
+     * @param: endTime
+     * @updateTime 2021/11/5 10:59
+     * @return: java.util.Map<java.lang.String,java.util.List<com.persagy.framework.ems.data.pojo.hbase.MonitorIndicatorRecord>>
+     * @throws
+     */
+    private Map<String, List<MonitorIndicatorRecord>> getTimekeyAndRecordListGteLt(ProjectDTO projectDTO, String objId, List<String> infCodeList, Date lastSendTime, Date endTime) throws Exception {
+        List<MonitorIndicatorRecord> list = getMonitorIndicatorRecordsGtLte(projectDTO.getProjectId(), objId, lastSendTime, infCodeList, endTime);
+        if (CollectionUtils.isEmpty(list)) {
+            return null;
+        }
+        Map<String, List<MonitorIndicatorRecord>> timeKeyAndRecordList = new LinkedHashMap<>();
+        for (MonitorIndicatorRecord record : list) {
+            String timeKey = DateUtils.date2Str(record.getDataTime(), DateUtils.SDFSECOND);
+            if (!timeKeyAndRecordList.containsKey(timeKey)) {
+                timeKeyAndRecordList.put(timeKey, new ArrayList<>());
+            }
+            timeKeyAndRecordList.get(timeKey).add(record);
+        }
+        return timeKeyAndRecordList;
+    }
+
+    /**
      * @title getObjIdAlarmItemCodeAndInfoCodes
      * @description 获取对象报警类型及监控指标list,key为objId_itemCode
      * @author leifeng
@@ -449,7 +473,7 @@ public class MonitorIndicatorRecordServiceImpl implements IMonitorIndicatorRecor
         monitorIndicatorRecord.setSpecialOperation("monitorIndicatorId", SpecialOperator.$in, infoCodes);
         monitorIndicatorRecord.setSpecialOperation("dataTime", SpecialOperator.$gt, lastSendTime);
         monitorIndicatorRecord.setSpecialOperation("dataTime", SpecialOperator.$lte, endTime);
-
+        monitorIndicatorRecord.setSort("dataTime", EMSOrder.Asc);
         return coredao.query(monitorIndicatorRecord);
     }
 
@@ -494,7 +518,7 @@ public class MonitorIndicatorRecordServiceImpl implements IMonitorIndicatorRecor
      * @updateTime 2021/9/25 20:05
      */
     private void updateRedisConfigItemSendTimeDTO(String projectId, String objeIdAndAlarmItemCode, ConfigItemDataSendTimeDTO sendTimeDTO) {
-        redisUtil.set(getRedisSendDataKey(projectId, objeIdAndAlarmItemCode), sendTimeDTO, SendDataTimeKeyTime);
+        redisUtil.set(getRedisSendDataKey(projectId, objeIdAndAlarmItemCode), sendTimeDTO);
     }
 
     /**

+ 2 - 2
src/main/java/com/persagy/apm/diagnose/service/ComputeIndicatorDataService.java

@@ -66,7 +66,7 @@ public class ComputeIndicatorDataService {
         latch.await();
         futureList.forEach(future -> {
             try {
-                log.info(future.get());
+                log.error(future.get());
             } catch (Exception e) {
                 log.error("计算项目指标数据错误:" + CommonUtils.getExceptionStackTrace(e));
             }
@@ -92,7 +92,7 @@ public class ComputeIndicatorDataService {
         latch.await();
         futureList.forEach(future -> {
             try {
-                log.info(future.get());
+                log.error(future.get());
             } catch (Exception e) {
                 log.error("发送指标数据错误:" + CommonUtils.getExceptionStackTrace(e));
             }

+ 2 - 2
src/main/java/com/persagy/apm/diagnose/service/schedule/ComputeIndicatorData.java

@@ -27,8 +27,8 @@ public class ComputeIndicatorData {
     	    //指标计算未开启
     	    return;
 		}
-        log.info("【监测指标数据计算线程】计算指标数据开始.........");
+        log.error("【监测指标数据计算线程】计算指标数据开始.........");
         computeIndicatorDataService.computeIndicatorData();
-        log.info("【监测指标数据计算线程】计算指标数据结束.........");
+        log.error("【监测指标数据计算线程】计算指标数据结束.........");
     }
 }

+ 2 - 1
src/main/java/com/persagy/apm/diagnose/service/schedule/SendIndicatorData.java

@@ -27,7 +27,8 @@ public class SendIndicatorData {
     	    //指标计算未开启
     	    return;
 		}
-        log.info("【发送监测指标数据线程】:发送指标数据开始.......");
+        log.error("【发送监测指标数据线程】:发送指标数据开始.......");
         computeIndicatorDataService.sendIndicatorData();
+        log.error("【发送监测指标数据线程】:发送指标数据结束.......");
     }
 }

+ 5 - 6
src/main/java/com/persagy/apm/diagnose/utils/AlarmResultUtil.java

@@ -3,11 +3,6 @@ package com.persagy.apm.diagnose.utils;
 import com.alibaba.fastjson.JSONArray;
 import com.alibaba.fastjson.JSONObject;
 import com.persagy.apm.diagnose.feign.AlarmResult;
-import com.persagy.apm.diagnose.service.dto.CalculateMethodDTO;
-import com.persagy.apm.diagnose.service.dto.MonitorIndicatorConfigDTO;
-import com.persagy.apm.energyalarmstarter.alarmdata.feign.DmpResult;
-import com.persagy.common.utils.StringUtil;
-
 import java.util.ArrayList;
 import java.util.List;
 
@@ -25,7 +20,11 @@ public class AlarmResultUtil {
         if (content == null || content.isEmpty()) {
             return new ArrayList<T>();
         }
-        JSONArray records = (JSONArray) content.getOrDefault("records", new JSONArray());
+//        JSONArray records = (JSONArray) content.getOrDefault("records", new JSONArray());
+        JSONArray records = content.getJSONArray("records");
+        if (records == null || records.isEmpty()) {
+            return new ArrayList<T>();
+        }
         return records.toJavaList(clazz);
     }
 }

+ 32 - 1
src/main/java/com/persagy/apm/diagnose/utils/CollectDataUtil.java

@@ -4,6 +4,7 @@ import com.persagy.framework.ems.data.pojo.hbase.MonitorIndicatorRecord;
 import org.springframework.util.CollectionUtils;
 
 import java.util.List;
+import java.util.Map;
 
 
 /**
@@ -15,7 +16,7 @@ import java.util.List;
  */
 public class CollectDataUtil {
 
-    public static String buildSendParam(List<MonitorIndicatorRecord> recordList,String alarmItemCode) throws Exception {
+    public static String buildSendParam(List<MonitorIndicatorRecord> recordList, String alarmItemCode) throws Exception {
 
         if (CollectionUtils.isEmpty(recordList)) {
             return null;
@@ -48,4 +49,34 @@ public class CollectDataUtil {
     }
 
 
+    public static String batchBuildSendParam(Map<String, List<MonitorIndicatorRecord>> sendTimeKeyAndDataList, String alarmItemCode) {
+        StringBuilder stringBuilder = new StringBuilder();
+
+        for (Map.Entry<String, List<MonitorIndicatorRecord>> entry : sendTimeKeyAndDataList.entrySet()) {
+            String date = entry.getKey();
+            stringBuilder.append(date).append(";");
+            List<MonitorIndicatorRecord> list = entry.getValue();
+            MonitorIndicatorRecord record1 = list.get(0);
+            stringBuilder.append(alarmItemCode).append(";");
+            stringBuilder.append(record1.getObjId()).append(";");
+            for (int i = 0; i < list.size(); i++) {
+                stringBuilder.append(list.get(i).getMonitorIndicatorId());
+                if (i == (list.size() - 1)) {
+                    stringBuilder.append(";");
+                } else {
+                    stringBuilder.append(",");
+                }
+            }
+            for (int i = 0; i < list.size(); i++) {
+                stringBuilder.append(list.get(i).getDataValue());
+                if (i == (list.size() - 1)) {
+                    stringBuilder.append(";");
+                } else {
+                    stringBuilder.append(",");
+                }
+            }
+        }
+        return stringBuilder.toString();
+
+    }
 }