|
@@ -10,8 +10,6 @@ import com.persagy.apm.common.model.dto.Sort;
|
|
|
import com.persagy.apm.diagnose.constant.EnumDataTimeType;
|
|
|
import com.persagy.apm.diagnose.constant.EnumTimeType;
|
|
|
import com.persagy.apm.diagnose.indicatorcompute.model.ProjectIndicatorCompute;
|
|
|
-import com.persagy.apm.diagnose.indicatorcompute.model.dto.AddProjectIndicatorComputeDTO;
|
|
|
-import com.persagy.apm.diagnose.indicatorcompute.model.dto.UpdateProjectIndicatorComputeDTO;
|
|
|
import com.persagy.apm.diagnose.indicatorcompute.service.IProjectIndicatorComputeService;
|
|
|
import com.persagy.apm.diagnose.indicatorrecord.dao.MonitorIndicatorRecordMapper;
|
|
|
import com.persagy.apm.diagnose.indicatorrecord.model.ConvertMonitorIndicatorRecordTool;
|
|
@@ -21,7 +19,6 @@ import com.persagy.apm.diagnose.indicatorrecord.service.IMonitorIndicatorRecordS
|
|
|
import com.persagy.apm.diagnose.service.CenterDataService;
|
|
|
import com.persagy.apm.diagnose.service.EnergyAlarmServiceImpl;
|
|
|
import com.persagy.apm.diagnose.service.dto.CalculateMethodDTO;
|
|
|
-import com.persagy.apm.diagnose.service.dto.MonitorIndicatorConfigDTO;
|
|
|
import com.persagy.apm.diagnose.service.dto.ProjectDTO;
|
|
|
import com.persagy.apm.diagnose.service.dto.TimeDataDTO;
|
|
|
import com.persagy.apm.diagnose.timerecord.model.CalculateTimeRecord;
|
|
@@ -81,6 +78,9 @@ public class MonitorIndicatorRecordServiceImpl extends ServiceImpl<MonitorIndica
|
|
|
private CenterDataService centerDataService;
|
|
|
|
|
|
|
|
|
+ public final static String alarmSlipt = "_";
|
|
|
+
|
|
|
+
|
|
|
@Value(value = "${energy.eq.run.compute.round.days:1}")
|
|
|
private Integer roundDays;
|
|
|
|
|
@@ -88,6 +88,13 @@ public class MonitorIndicatorRecordServiceImpl extends ServiceImpl<MonitorIndica
|
|
|
@Value(value = "${energy.eq.run.send.hour:1}")
|
|
|
private Integer sendDataHour;
|
|
|
|
|
|
+
|
|
|
+ @Value(value = "${energy.eq.run.compute.after.hour:1}")
|
|
|
+ private Integer computeAfterHour;
|
|
|
+
|
|
|
+ @Value(value = "${energy.eq.run.compute.start.time:null}")
|
|
|
+ private String dStartTime;
|
|
|
+
|
|
|
private final static Long SendDataTimeKeyTime = 24 * 60 * 60 * 1000L;
|
|
|
|
|
|
|
|
@@ -168,7 +175,6 @@ public class MonitorIndicatorRecordServiceImpl extends ServiceImpl<MonitorIndica
|
|
|
if (monitorIndicatorRecord == null) {
|
|
|
throw new IllegalArgumentException("删除MonitorIndicatorRecord时发生异常,找不到要删除的数据,id:" + id);
|
|
|
}
|
|
|
-
|
|
|
return monitorIndicatorRecord;
|
|
|
}
|
|
|
|
|
@@ -213,13 +219,21 @@ public class MonitorIndicatorRecordServiceImpl extends ServiceImpl<MonitorIndica
|
|
|
queryWrapper.eq(MonitorIndicatorRecord.PROP_DATE, queryMonitorIndicatorRecordDTO.getDate());
|
|
|
}
|
|
|
|
|
|
+ if (queryMonitorIndicatorRecordDTO.getTimeFrom() != null) {
|
|
|
+
|
|
|
+ queryWrapper.ge(MonitorIndicatorRecord.PROP_DATE, queryMonitorIndicatorRecordDTO.getTimeFrom());
|
|
|
+ }
|
|
|
+
|
|
|
+ if (queryMonitorIndicatorRecordDTO.getTimeTo() != null) {
|
|
|
+ queryWrapper.lt(MonitorIndicatorRecord.PROP_DATE, queryMonitorIndicatorRecordDTO.getTimeTo());
|
|
|
+ }
|
|
|
+
|
|
|
// todo 需判断使用like还是eq
|
|
|
if (StringUtils.isNotEmpty(queryMonitorIndicatorRecordDTO.getValue())) {
|
|
|
queryWrapper.like(MonitorIndicatorRecord.PROP_VALUE, queryMonitorIndicatorRecordDTO.getValue());
|
|
|
}
|
|
|
|
|
|
}
|
|
|
-
|
|
|
return list(queryWrapper);
|
|
|
}
|
|
|
|
|
@@ -272,77 +286,70 @@ public class MonitorIndicatorRecordServiceImpl extends ServiceImpl<MonitorIndica
|
|
|
@Async("asyncComputeDataExecutor")
|
|
|
public Future<String> computeIndicatorData(ProjectDTO projectDTO, ProjectIndicatorCompute projectIndicatorCompute, CountDownLatch latch) throws Exception {
|
|
|
long time = System.currentTimeMillis() + (20 * 1000);
|
|
|
- if (!lockUtil.lock(projectDTO.getProjectId(), String.valueOf(time))) {
|
|
|
- // 获取不到锁,略过
|
|
|
- return new AsyncResult<>("【监测指标数据计算线程】项目:" + projectDTO.getProjectId() + "被占用");
|
|
|
- }
|
|
|
- try{
|
|
|
+ try {
|
|
|
+ if (!lockUtil.lock(projectDTO.getProjectId() + "_compute", String.valueOf(time))) {
|
|
|
+ // 获取不到锁,略过
|
|
|
+ return new AsyncResult<>("【监测指标数据计算线程】项目:" + projectDTO.getProjectId() + "被占用");
|
|
|
+ }
|
|
|
+
|
|
|
long start = System.currentTimeMillis();
|
|
|
AsyncResult<String> projectDTO1 = computeProjectIndicatorData(projectDTO, projectIndicatorCompute);
|
|
|
if (projectDTO1 != null) {
|
|
|
return projectDTO1;
|
|
|
}
|
|
|
- // 释放锁
|
|
|
long end = System.currentTimeMillis();
|
|
|
return new AsyncResult<>("【监测指标数据计算线程】计算项目指标数据用时:" + projectDTO.getProjectId() + ";" + (end - start));
|
|
|
- }catch (Exception e){
|
|
|
- throw(e);
|
|
|
- }finally {
|
|
|
- lockUtil.unlock(projectDTO.getProjectId(), String.valueOf(time));
|
|
|
+ } finally {
|
|
|
+ // 释放锁
|
|
|
+ lockUtil.unlock(projectDTO.getProjectId() + "_compute", String.valueOf(time));
|
|
|
latch.countDown();
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
private AsyncResult<String> computeProjectIndicatorData(ProjectDTO projectDTO, ProjectIndicatorCompute projectIndicatorCompute) throws Exception {
|
|
|
- Object hget = redisUtil.hget(RedisUtil.TargetComputeTime, projectDTO.getProjectId());
|
|
|
- if (hget != null && projectIndicatorCompute != null
|
|
|
- && projectIndicatorCompute.getComputeRound() < Long.parseLong(hget.toString())) {
|
|
|
+ Object redisComputeRound = redisUtil.hget(RedisUtil.TargetComputeTime, projectDTO.getProjectId());
|
|
|
+ if (redisComputeRound != null && projectIndicatorCompute != null
|
|
|
+ && projectIndicatorCompute.getComputeRound() < Long.parseLong(redisComputeRound.toString())) {
|
|
|
return new AsyncResult<>("【监测指标数据计算线程】当前项目:" + projectDTO.getProjectId() + "被占用");
|
|
|
}
|
|
|
//通过报警服务查询报警配置
|
|
|
List<AlarmConfigItem> configItemList = getAlarmConfigItemList(projectDTO.getProjectId());
|
|
|
if (CollectionUtils.isEmpty(configItemList)) {
|
|
|
- return new AsyncResult<>("【监测指标数据计算线程】当前项目:" + projectDTO.getProjectId() + "为查询到报警条件");
|
|
|
+ return new AsyncResult<>("【监测指标数据计算线程】当前项目:" + projectDTO.getProjectId() + "未查询到报警条件");
|
|
|
}
|
|
|
Set<String> objIdSet = configItemList.stream().map(AlarmConfigItem::getObjId).collect(Collectors.toSet());
|
|
|
-
|
|
|
List<JSONObject> objectList = centerDataService.queryObjListByObjId(projectDTO.getProjectId(), new ArrayList<>(objIdSet));
|
|
|
if (CollectionUtils.isEmpty(objectList)) {
|
|
|
return new AsyncResult<>("【监测指标数据计算线程】当前项目:" + projectDTO.getProjectId() + "查询项目下无设备对象");
|
|
|
}
|
|
|
+
|
|
|
Map<String, JSONObject> objIdAndObj = new HashMap<>();
|
|
|
for (JSONObject obj : objectList) {
|
|
|
objIdAndObj.put(obj.getString("id"), obj);
|
|
|
}
|
|
|
|
|
|
Map<String, Date> objId_indicatorIdAndComputeTIme = getObjId_IndicatorIdAndComputeTIme(projectDTO);
|
|
|
-
|
|
|
Map<String, CalculateMethodDTO> methodIdAndMethodDTO = energyAlarmService.queryCalculateMethods();
|
|
|
|
|
|
- Map<String, String> objId_IndicatorAndCaculateMethodId = getObjId_IndicatorAndCaculateMethodIdMap(projectDTO);
|
|
|
-
|
|
|
+ Map<String, Set<String>> objIdAndInfoCodes = getObjIdAndInfoCodes(configItemList, objIdAndObj);
|
|
|
|
|
|
//根据报警条件查询监测对象
|
|
|
- for (AlarmConfigItem configItem : configItemList) {
|
|
|
- String objId = configItem.getObjId();
|
|
|
- AlarmCondition condition = configItem.getCondition();
|
|
|
- List<String> infoCodeList = condition.getInfoCode();
|
|
|
- if (CollectionUtils.isEmpty(infoCodeList)) {
|
|
|
+ for (Map.Entry<String, Set<String>> entry : objIdAndInfoCodes.entrySet()) {
|
|
|
+ String objId = entry.getKey();
|
|
|
+ Set<String> infoCodes = entry.getValue();
|
|
|
+ if (CollectionUtils.isEmpty(infoCodes)) {
|
|
|
continue;
|
|
|
}
|
|
|
- JSONObject obj = objIdAndObj.get(objId);
|
|
|
- if (obj == null) {
|
|
|
+ //获取对象id及指标相应公式id
|
|
|
+ Map<String, String> objId_indicatorAndMethodId = getObjId_indicatorAndMethodId(projectDTO, objId, new ArrayList<>(infoCodes));
|
|
|
+ if (objId_indicatorAndMethodId.isEmpty()) {
|
|
|
+ log.error("【监测指标数据计算线程】:项目监控指标未设置公式:" + projectDTO.getProjectId() + ";" + objId);
|
|
|
continue;
|
|
|
}
|
|
|
//处理监控指标
|
|
|
- for (String infocode : infoCodeList) {
|
|
|
- if (!objId_IndicatorAndCaculateMethodId.containsKey(infocode)) {
|
|
|
- //监控指标未设置公式
|
|
|
- log.error("【监测指标数据计算线程】:监控指标未设置公式:" + infocode);
|
|
|
- continue;
|
|
|
- }
|
|
|
- String caculateMethodId = objId_IndicatorAndCaculateMethodId.get(infocode);
|
|
|
+ for (String infocode : infoCodes) {
|
|
|
+ String caculateMethodId = objId_indicatorAndMethodId.get(infocode);
|
|
|
if (StringUtils.isEmpty(caculateMethodId)) {
|
|
|
log.error("【监测指标数据计算线程】:监控指标未设置公式:" + infocode);
|
|
|
continue;
|
|
@@ -354,14 +361,15 @@ public class MonitorIndicatorRecordServiceImpl extends ServiceImpl<MonitorIndica
|
|
|
}
|
|
|
|
|
|
Date lastComputeTime = objId_indicatorIdAndComputeTIme.get(infocode);
|
|
|
- if(lastComputeTime==null){
|
|
|
- lastComputeTime=DateUtils.str2Date("2021-09-02 00:00:00",DateUtils.SDF_SECOND);
|
|
|
+ if (lastComputeTime == null) {
|
|
|
+ lastComputeTime = getDefultStartTime();
|
|
|
}
|
|
|
Date computeEndTime = DateUtils.addDays(lastComputeTime, roundDays);
|
|
|
-
|
|
|
String indicatorId = getIndicatorIdFromInfocode(infocode);
|
|
|
String formula = calculateMethodDTO.getFormula();
|
|
|
- computeIndicatorData(projectDTO, obj, lastComputeTime, computeEndTime, indicatorId, formula);
|
|
|
+ JSONObject obj = objIdAndObj.get(objId);
|
|
|
+ Date computeTime = computeIndicatorData(projectDTO, obj, lastComputeTime, computeEndTime, indicatorId, formula);
|
|
|
+ saveOrUpdateComputeTime(projectDTO.getProjectId(), obj.getString("id"), indicatorId, computeTime);
|
|
|
}
|
|
|
}
|
|
|
// 更新缓存计算轮次
|
|
@@ -369,37 +377,129 @@ public class MonitorIndicatorRecordServiceImpl extends ServiceImpl<MonitorIndica
|
|
|
return null;
|
|
|
}
|
|
|
|
|
|
+ private Date getDefultStartTime() throws Exception {
|
|
|
+ Date lastComputeTime;
|
|
|
+ if (StringUtils.isBlank(dStartTime)) {
|
|
|
+ lastComputeTime = new Date();
|
|
|
+ } else {
|
|
|
+ lastComputeTime = DateUtils.str2Date(dStartTime, DateUtils.SDF_SECOND);
|
|
|
+ }
|
|
|
+ return lastComputeTime;
|
|
|
+ }
|
|
|
+
|
|
|
+ private Map<String, Set<String>> getObjIdAndInfoCodes(List<AlarmConfigItem> configItemList, Map<String, JSONObject> objIdAndObj) {
|
|
|
+ Map<String, Set<String>> objIdAndInfoCodes = new HashMap<>();
|
|
|
+ for (AlarmConfigItem alarmConfigItem : configItemList) {
|
|
|
+ String objId = alarmConfigItem.getObjId();
|
|
|
+ AlarmCondition condition = alarmConfigItem.getCondition();
|
|
|
+ List<String> infoCodeList = condition.getInfoCode();
|
|
|
+ if (CollectionUtils.isEmpty(infoCodeList)) {
|
|
|
+ continue;
|
|
|
+ }
|
|
|
+ JSONObject obj = objIdAndObj.get(objId);
|
|
|
+ if (obj == null) {
|
|
|
+ continue;
|
|
|
+ }
|
|
|
+ if (!objIdAndInfoCodes.containsKey(objId)) {
|
|
|
+ objIdAndInfoCodes.put(objId, new HashSet<>());
|
|
|
+ }
|
|
|
+ objIdAndInfoCodes.get(objId).addAll(infoCodeList);
|
|
|
+ }
|
|
|
+ return objIdAndInfoCodes;
|
|
|
+ }
|
|
|
+
|
|
|
+ private void saveOrUpdateComputeTime(String projectId, String objId, String indicatorId, Date computeTime) {
|
|
|
+ if (computeTime == null) {
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ CalculateTimeRecord update = new CalculateTimeRecord();
|
|
|
+ update.setMonitorIndicatorId(indicatorId);
|
|
|
+ update.setObjId(objId);
|
|
|
+ update.setProjectId(projectId);
|
|
|
+ update.setCalculateLastTime(computeTime);
|
|
|
+ calculateTimeRecordService.saveOrUpdateByPk(update);
|
|
|
+ }
|
|
|
+
|
|
|
+ private Map<String, String> getObjId_indicatorAndMethodId(ProjectDTO projectDTO, String objId, List<String> infoCodeList) throws Exception {
|
|
|
+ List<String> indicatorList = getIndicatorIdListFromInfoCodes(infoCodeList);
|
|
|
+ return energyAlarmService.queryObjId_indicatorAndMethodId(projectDTO.getProjectId(), objId, indicatorList);
|
|
|
+ }
|
|
|
+
|
|
|
+ private List<String> getIndicatorIdListFromInfoCodes(List<String> infoCodeList) {
|
|
|
+ List<String> indicatorList = new ArrayList<>();
|
|
|
+ infoCodeList.forEach(infoCode -> indicatorList.add(getIndicatorIdFromInfocode(infoCode)));
|
|
|
+ return indicatorList;
|
|
|
+ }
|
|
|
+
|
|
|
@Override
|
|
|
@Async("asyncSendDataExecutor")
|
|
|
public Future<String> sendIndicatorData(ProjectDTO projectDTO, CountDownLatch latch) throws Exception {
|
|
|
long time = System.currentTimeMillis() + (20 * 1000);
|
|
|
- if (!lockUtil.lock(projectDTO.getProjectId() + "_sendData", String.valueOf(time))) {
|
|
|
- // 获取不到锁,略过
|
|
|
- return new AsyncResult<>("发送指标数据:项目:" + projectDTO.getProjectId() + "被占用");
|
|
|
- }
|
|
|
- try{
|
|
|
+ try {
|
|
|
+ if (!lockUtil.lock(projectDTO.getProjectId() + "_sendData", String.valueOf(time))) {
|
|
|
+ // 获取不到锁,略过
|
|
|
+ return new AsyncResult<>("【监测指标数据计算线程】:项目:" + projectDTO.getProjectId() + "被占用");
|
|
|
+ }
|
|
|
+
|
|
|
long start = System.currentTimeMillis();
|
|
|
sendIndicatorDataToAlarmServer(projectDTO);
|
|
|
long end = System.currentTimeMillis();
|
|
|
- return new AsyncResult<>("【监测指标数据计算线程】计算项目指标数据用时:" + projectDTO.getProjectId() + ";" + (end - start));
|
|
|
- }catch (Exception e){
|
|
|
- throw(e);
|
|
|
- }finally {
|
|
|
+ return new AsyncResult<>("【监测指标数据发送线程】发送项目指标数据用时:" + projectDTO.getProjectId() + ";" + (end - start));
|
|
|
+ } finally {
|
|
|
lockUtil.unlock(projectDTO.getProjectId() + "_sendData", String.valueOf(time));
|
|
|
latch.countDown();
|
|
|
}
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public void saveOrUpdateByPk(MonitorIndicatorRecord monitorIndicatorRecord) {
|
|
|
+ QueryWrapper<MonitorIndicatorRecord> queryWrapper = new QueryWrapper<>();
|
|
|
+ queryWrapper.eq(MonitorIndicatorRecord.PROJECT_ID, monitorIndicatorRecord.getProjectId());
|
|
|
+ queryWrapper.eq(MonitorIndicatorRecord.PROP_OBJ_ID, monitorIndicatorRecord.getObjId());
|
|
|
+ queryWrapper.eq(MonitorIndicatorRecord.PROP_MONITOR_INDICATOR_ID, monitorIndicatorRecord.getMonitorIndicatorId());
|
|
|
+ queryWrapper.eq(MonitorIndicatorRecord.PROP_DATE, monitorIndicatorRecord.getDate());
|
|
|
+ int count = this.count(queryWrapper);
|
|
|
+ if (count == 0) {
|
|
|
+ //新建
|
|
|
+ this.save(monitorIndicatorRecord);
|
|
|
+ } else {
|
|
|
+ this.update(monitorIndicatorRecord, queryWrapper);
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public void cleanAlarmConfig(String projectId) {
|
|
|
+ if (StringUtils.isBlank(projectId)) {
|
|
|
+ redisUtil.del(RedisUtil.PROJECT_ALARM_ITEM);
|
|
|
+ } else {
|
|
|
+ redisUtil.hdel(RedisUtil.PROJECT_ALARM_ITEM, projectId);
|
|
|
+ }
|
|
|
|
|
|
}
|
|
|
|
|
|
+ @Override
|
|
|
+ public void cleanAlarmConfigSendTime(CleanAlarmConfigDTO cleanAlarmConfigDTO) {
|
|
|
+ if (StringUtils.isBlank(cleanAlarmConfigDTO.getProjectId())) {
|
|
|
+ //清除所有
|
|
|
+ redisUtil.del(RedisUtil.PROJECT_ITEM_SEND_TIME);
|
|
|
+ } else if (StringUtils.isBlank(cleanAlarmConfigDTO.getAlarmConfigItemId())) {
|
|
|
+ //清除项目
|
|
|
+ redisUtil.del(RedisUtil.PROJECT_ALARM_ITEM + ":" + cleanAlarmConfigDTO.getProjectId());
|
|
|
+ } else {
|
|
|
+ //清除指定
|
|
|
+ redisUtil.hdel(RedisUtil.PROJECT_ALARM_ITEM + ":" + cleanAlarmConfigDTO.getProjectId(), cleanAlarmConfigDTO.getAlarmConfigItemId());
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
private void sendIndicatorDataToAlarmServer(ProjectDTO projectDTO) throws Exception {
|
|
|
//通过报警服务查询报警配置
|
|
|
List<AlarmConfigItem> configItemList = getAlarmConfigItemList(projectDTO.getProjectId());
|
|
|
if (CollectionUtils.isEmpty(configItemList)) {
|
|
|
log.error("【发送监测指标数据线程】当前项目:" + projectDTO.getProjectId() + "为查询到报警条件");
|
|
|
+ return;
|
|
|
}
|
|
|
+
|
|
|
for (AlarmConfigItem alarmConfigItem : configItemList) {
|
|
|
- ConfigItemDataSendTimeDTO configItemSendTimeDTO = getConfigItemSendTimeDTO(projectDTO, alarmConfigItem);
|
|
|
- Date lastSendTime = configItemSendTimeDTO.getLastSendTime();
|
|
|
AlarmCondition condition = alarmConfigItem.getCondition();
|
|
|
if (condition == null) {
|
|
|
continue;
|
|
@@ -408,19 +508,30 @@ public class MonitorIndicatorRecordServiceImpl extends ServiceImpl<MonitorIndica
|
|
|
if (CollectionUtils.isEmpty(infoCodes)) {
|
|
|
continue;
|
|
|
}
|
|
|
+ ConfigItemDataSendTimeDTO configItemSendTimeDTO = getConfigItemSendTimeDTO(projectDTO, alarmConfigItem);
|
|
|
+ Date lastSendTime = configItemSendTimeDTO.getLastSendTime();
|
|
|
Date endTime = getSendEndTiem(lastSendTime);
|
|
|
- List<MonitorIndicatorRecord> list = getMonitorIndicatorRecordsGtLte(projectDTO, alarmConfigItem, lastSendTime, infoCodes, endTime);
|
|
|
+ List<MonitorIndicatorRecord> list = getMonitorIndicatorRecordsGtLte(projectDTO, alarmConfigItem, lastSendTime, getIndicatorIdListFromInfoCodes(infoCodes), endTime);
|
|
|
if (CollectionUtils.isEmpty(list)) {
|
|
|
continue;
|
|
|
}
|
|
|
|
|
|
- Map<Date, List<MonitorIndicatorRecord>> timeAndIndicatorDataList = list.stream().collect(Collectors.groupingBy(MonitorIndicatorRecord::getDate, Collectors.toList()));
|
|
|
- for (Map.Entry<Date, List<MonitorIndicatorRecord>> dateListEntry : timeAndIndicatorDataList.entrySet()) {
|
|
|
+
|
|
|
+ Map<String, List<MonitorIndicatorRecord>> timeKeyAndRecordList = new LinkedHashMap<>();
|
|
|
+ for (MonitorIndicatorRecord record : list) {
|
|
|
+ String timeKey = DateUtils.date2Str(record.getDate(), DateUtils.SDF_SECOND);
|
|
|
+ if (!timeKeyAndRecordList.containsKey(timeKey)) {
|
|
|
+ timeKeyAndRecordList.put(timeKey, new ArrayList<>());
|
|
|
+ }
|
|
|
+ timeKeyAndRecordList.get(timeKey).add(record);
|
|
|
+ }
|
|
|
+ for (Map.Entry<String, List<MonitorIndicatorRecord>> dateListEntry : timeKeyAndRecordList.entrySet()) {
|
|
|
List<MonitorIndicatorRecord> value = dateListEntry.getValue();
|
|
|
if (CollectionUtils.isEmpty(value) || value.size() != infoCodes.size()) {
|
|
|
continue;
|
|
|
}
|
|
|
AlarmWebSocketServer.sendMsgToClients(projectDTO.getProjectId(), CollectDataUtil.buildSendParam(value));
|
|
|
+ endTime = DateUtils.str2Date(dateListEntry.getKey(), DateUtils.SDF_SECOND);
|
|
|
}
|
|
|
configItemSendTimeDTO.setLastSendTime(endTime);
|
|
|
updateRedisConfigItemSendTimeDTO(projectDTO.getProjectId(), configItemSendTimeDTO);
|
|
@@ -452,8 +563,8 @@ public class MonitorIndicatorRecordServiceImpl extends ServiceImpl<MonitorIndica
|
|
|
queryWrapper.eq(MonitorIndicatorRecord.PROJECT_ID, projectDTO.getProjectId());
|
|
|
queryWrapper.eq(MonitorIndicatorRecord.PROP_OBJ_ID, alarmConfigItem.getObjId());
|
|
|
queryWrapper.in(MonitorIndicatorRecord.PROP_MONITOR_INDICATOR_ID, infoCodes);
|
|
|
- queryWrapper.ge(MonitorIndicatorRecord.PROP_DATE, lastSendTime);
|
|
|
- queryWrapper.lt(true, MonitorIndicatorRecord.PROP_DATE, endTime);
|
|
|
+ queryWrapper.gt(MonitorIndicatorRecord.PROP_DATE, lastSendTime);
|
|
|
+ queryWrapper.le(MonitorIndicatorRecord.PROP_DATE, endTime);
|
|
|
queryWrapper.orderByAsc(MonitorIndicatorRecord.PROP_DATE);
|
|
|
return list(queryWrapper);
|
|
|
}
|
|
@@ -470,9 +581,7 @@ public class MonitorIndicatorRecordServiceImpl extends ServiceImpl<MonitorIndica
|
|
|
private ConfigItemDataSendTimeDTO getConfigItemSendTimeDTO(ProjectDTO projectDTO, AlarmConfigItem alarmConfigItem) throws Exception {
|
|
|
ConfigItemDataSendTimeDTO sendTimeDTO = (ConfigItemDataSendTimeDTO) redisUtil.hget(RedisUtil.PROJECT_ITEM_SEND_TIME + ":" + projectDTO.getProjectId(), alarmConfigItem.getId());
|
|
|
if (sendTimeDTO == null) {
|
|
|
- //第一次发送
|
|
|
-// sendTimeDTO = ConfigItemDataSendTimeDTO.builder().objId(alarmConfigItem.getObjId()).configItemid(alarmConfigItem.getId()).lastSendTime(DateUtils.getStartTimeOfDay(new Date())).build();
|
|
|
- sendTimeDTO = ConfigItemDataSendTimeDTO.builder().objId(alarmConfigItem.getObjId()).configItemid(alarmConfigItem.getId()).lastSendTime(DateUtils.str2Date("2021-09-02 00:00:00",DateUtils.SDF_SECOND)).build();
|
|
|
+ sendTimeDTO = ConfigItemDataSendTimeDTO.builder().objId(alarmConfigItem.getObjId()).configItemid(alarmConfigItem.getId()).lastSendTime(getDefultStartTime()).build();
|
|
|
}
|
|
|
return sendTimeDTO;
|
|
|
}
|
|
@@ -499,18 +608,17 @@ public class MonitorIndicatorRecordServiceImpl extends ServiceImpl<MonitorIndica
|
|
|
*/
|
|
|
private void updateProjectComputeRound(String projectId, ProjectIndicatorCompute projectCompute) {
|
|
|
Integer round = 1;
|
|
|
+ ProjectIndicatorCompute projectIndicatorCompute = new ProjectIndicatorCompute();
|
|
|
+ projectIndicatorCompute.setProjectId(projectId);
|
|
|
+
|
|
|
+ projectIndicatorCompute.setComputeTime(new Date());
|
|
|
if (projectCompute == null) {
|
|
|
- AddProjectIndicatorComputeDTO addProjectIndicatorComputeDTO = new AddProjectIndicatorComputeDTO();
|
|
|
- addProjectIndicatorComputeDTO.setProjectId(projectId);
|
|
|
- addProjectIndicatorComputeDTO.setComputeRound(1);
|
|
|
- addProjectIndicatorComputeDTO.setComputeTime(new Date());
|
|
|
- projectIndicatorComputeService.createProjectIndicatorCompute(addProjectIndicatorComputeDTO);
|
|
|
+ projectIndicatorCompute.setComputeRound(round);
|
|
|
+ projectIndicatorComputeService.save(projectIndicatorCompute);
|
|
|
} else {
|
|
|
- UpdateProjectIndicatorComputeDTO updateProjectIndicatorComputeDTO = new UpdateProjectIndicatorComputeDTO();
|
|
|
- updateProjectIndicatorComputeDTO.setComputeRound(round = getComputeRound(projectCompute.getComputeRound()));
|
|
|
- updateProjectIndicatorComputeDTO.setProjectId(projectCompute.getProjectId());
|
|
|
- updateProjectIndicatorComputeDTO.setComputeTime(new Date());
|
|
|
- projectIndicatorComputeService.updateProjectIndicatorCompute(updateProjectIndicatorComputeDTO);
|
|
|
+ round = getComputeRound(projectCompute.getComputeRound());
|
|
|
+ projectIndicatorCompute.setComputeRound(round);
|
|
|
+ projectIndicatorComputeService.updateById(projectIndicatorCompute);
|
|
|
}
|
|
|
redisUtil.hset(RedisUtil.TargetComputeTime, projectId, round.toString());
|
|
|
}
|
|
@@ -544,20 +652,23 @@ public class MonitorIndicatorRecordServiceImpl extends ServiceImpl<MonitorIndica
|
|
|
* @param: formula
|
|
|
* @updateTime 2021/9/25 20:11
|
|
|
*/
|
|
|
- private void computeIndicatorData(ProjectDTO projectDTO, JSONObject obj, Date lastComputeTime, Date computeEndTime, String indicatorId, String formula) throws Exception {
|
|
|
+ private Date computeIndicatorData(ProjectDTO projectDTO, JSONObject obj, Date lastComputeTime, Date computeEndTime, String indicatorId, String formula) throws Exception {
|
|
|
ComputeCalculateDTO computeCalculateDTO = new ComputeCalculateDTO();
|
|
|
computeCalculateDTO.setObj(obj);
|
|
|
computeCalculateDTO.setProjectId(projectDTO.getProjectId());
|
|
|
computeCalculateDTO.setTargetId(indicatorId);
|
|
|
Map<String, Double> timeDataMap = TimeDataUtil.getTimeDataMap(lastComputeTime, computeEndTime,
|
|
|
EnumTimeType.MIN15);
|
|
|
+
|
|
|
+ Date timeEnd = null;
|
|
|
for (Map.Entry<String, Double> entry : timeDataMap.entrySet()) {
|
|
|
- Double targetData;
|
|
|
Date dataTime = DateUtils.str2Date(entry.getKey(), DateUtils.SDF_SECOND);
|
|
|
+ timeEnd = dataTime;
|
|
|
if (dataTime.getTime() > System.currentTimeMillis()) {
|
|
|
break;
|
|
|
}
|
|
|
computeCalculateDTO.setDataTime(dataTime);
|
|
|
+ Double targetData;
|
|
|
targetData = computeObjTargetDataByCalculate(computeCalculateDTO, formula);
|
|
|
if (targetData == null) {
|
|
|
break;
|
|
@@ -567,13 +678,15 @@ public class MonitorIndicatorRecordServiceImpl extends ServiceImpl<MonitorIndica
|
|
|
monitorIndicatorRecord.setDate(dataTime);
|
|
|
monitorIndicatorRecord.setObjId(obj.getString("id"));
|
|
|
monitorIndicatorRecord.setProjectId(projectDTO.getProjectId());
|
|
|
- saveOrUpdate(monitorIndicatorRecord);
|
|
|
+ monitorIndicatorRecord.setValue(targetData);
|
|
|
+ saveOrUpdateByPk(monitorIndicatorRecord);
|
|
|
}
|
|
|
+ return timeEnd;
|
|
|
}
|
|
|
|
|
|
private String getIndicatorIdFromInfocode(String infocode) {
|
|
|
- int lastIndex = infocode.lastIndexOf("_");
|
|
|
- return infocode.substring(lastIndex);
|
|
|
+ int indexOf = infocode.indexOf(alarmSlipt);
|
|
|
+ return infocode.substring(indexOf + 1);
|
|
|
}
|
|
|
|
|
|
/**
|
|
@@ -584,21 +697,9 @@ public class MonitorIndicatorRecordServiceImpl extends ServiceImpl<MonitorIndica
|
|
|
*/
|
|
|
private Map<String, Date> getObjId_IndicatorIdAndComputeTIme(ProjectDTO projectDTO) {
|
|
|
List<CalculateTimeRecord> calculateTimeRecords = calculateTimeRecordService.queryTimeRecordListByProjectId(projectDTO.getProjectId());
|
|
|
- return calculateTimeRecords.stream().collect(Collectors.toMap(a -> a.getObjId() + "_" + a.getMonitorIndicatorId(), CalculateTimeRecord::getCalculateLastTime));
|
|
|
+ return calculateTimeRecords.stream().collect(Collectors.toMap(a -> a.getObjId() + alarmSlipt + a.getMonitorIndicatorId(), CalculateTimeRecord::getCalculateLastTime));
|
|
|
}
|
|
|
|
|
|
- /**
|
|
|
- * @title getObjId_IndicatorAndCaculateMethodIdMap
|
|
|
- * @description 查询对象id与指标id的计算公式关系, key为objId_indicatorId, value为计算公式id
|
|
|
- * @author leifeng
|
|
|
- * @param: projectDTO
|
|
|
- * @updateTime 2021/9/24 11:26
|
|
|
- * @return: java.util.Map<java.lang.String, java.lang.String>
|
|
|
- */
|
|
|
- private Map<String, String> getObjId_IndicatorAndCaculateMethodIdMap(ProjectDTO projectDTO) throws Exception {
|
|
|
- List<MonitorIndicatorConfigDTO> monitorIndicatorConfigDTOS = energyAlarmService.queryMonitorIndicatorConfigDTOList(projectDTO.getProjectId());
|
|
|
- return monitorIndicatorConfigDTOS.stream().collect(Collectors.toMap(a -> a.getObjId() + "_" + a.getMonitorIndicatorId(), MonitorIndicatorConfigDTO::getCaculateMethodId));
|
|
|
- }
|
|
|
|
|
|
/**
|
|
|
* @title getAlarmConfigItemList
|
|
@@ -746,7 +847,7 @@ public class MonitorIndicatorRecordServiceImpl extends ServiceImpl<MonitorIndica
|
|
|
assert startTime != null;
|
|
|
return getServiceDataFromCenterDataService(computeCalculateDTO.getProjectId(),
|
|
|
computeCalculateDTO.getObj().getString("id"), computeCode, timeType, startTime,
|
|
|
- DateUtils.addMinutes(startTime, 1));
|
|
|
+ DateUtils.addHours(startTime, computeAfterHour));
|
|
|
}
|
|
|
} else {
|
|
|
// 查询指标数据
|
|
@@ -781,9 +882,7 @@ public class MonitorIndicatorRecordServiceImpl extends ServiceImpl<MonitorIndica
|
|
|
startTime2, EnumDataTimeType.getEnumDataTimeType(timeType));
|
|
|
List<Double> result = new ArrayList<>();
|
|
|
if (!CollectionUtils.isEmpty(dataList)) {
|
|
|
- for (TimeDataDTO data : dataList) {
|
|
|
- result.add(data.getData());
|
|
|
- }
|
|
|
+ result.add(dataList.get(0).getData());
|
|
|
}
|
|
|
if (CollectionUtils.isEmpty(result)) {
|
|
|
log.error("【指标计算线程】:查询数据中台对象历史数据为空,projectId:" + projectId + ";objId:" + objId + ";信息点:" + computeCode
|