|
@@ -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);
|
|
|
}
|
|
|
|
|
|
/**
|