|
@@ -1,45 +1,38 @@
|
|
|
package com.persagy.apm.diagnose.indicatorrecord.service.impl;
|
|
|
|
|
|
import com.alibaba.fastjson.JSONObject;
|
|
|
-import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
|
|
-import com.baomidou.mybatisplus.core.metadata.IPage;
|
|
|
-import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
|
|
-import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
|
|
-import com.google.common.base.CaseFormat;
|
|
|
-import com.persagy.apm.common.model.dto.Sort;
|
|
|
+import com.persagy.apm.diagnose.config.ComputePropertiesConfig;
|
|
|
+import com.persagy.apm.diagnose.constant.DiAgnoseConst;
|
|
|
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.service.IProjectIndicatorComputeService;
|
|
|
-import com.persagy.apm.diagnose.indicatorrecord.dao.MonitorIndicatorRecordMapper;
|
|
|
-import com.persagy.apm.diagnose.indicatorrecord.model.ConvertMonitorIndicatorRecordTool;
|
|
|
-import com.persagy.apm.diagnose.indicatorrecord.model.MonitorIndicatorRecord;
|
|
|
import com.persagy.apm.diagnose.indicatorrecord.model.dto.*;
|
|
|
import com.persagy.apm.diagnose.indicatorrecord.service.IMonitorIndicatorRecordService;
|
|
|
import com.persagy.apm.diagnose.service.CenterDataService;
|
|
|
import com.persagy.apm.diagnose.service.EnergyAlarmServiceImpl;
|
|
|
+import com.persagy.apm.diagnose.service.dto.AlarmRuleDTO;
|
|
|
import com.persagy.apm.diagnose.service.dto.CalculateMethodDTO;
|
|
|
import com.persagy.apm.diagnose.service.dto.ProjectDTO;
|
|
|
import com.persagy.apm.diagnose.service.dto.TimeDataDTO;
|
|
|
import com.persagy.apm.diagnose.timerecord.model.CalculateTimeRecord;
|
|
|
import com.persagy.apm.diagnose.timerecord.service.ICalculateTimeRecordService;
|
|
|
import com.persagy.apm.diagnose.utils.*;
|
|
|
-import com.persagy.apm.energyalarmstarter.alarmdata.feign.DmpResult;
|
|
|
-import com.persagy.apm.energyalarmstarter.alarmdata.model.dto.AlarmCondition;
|
|
|
-import com.persagy.apm.energyalarmstarter.alarmdata.model.dto.alarmconfig.QueryAlarmConfigDTO;
|
|
|
-import com.persagy.apm.energyalarmstarter.alarmdata.model.vo.AlarmConfigItem;
|
|
|
import com.persagy.apm.energyalarmstarter.alarmdata.service.AlarmConfigServiceImpl;
|
|
|
import com.persagy.apm.energyalarmstarter.collectdata.websocket.AlarmWebSocketServer;
|
|
|
+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;
|
|
|
import lombok.extern.slf4j.Slf4j;
|
|
|
import org.apache.commons.lang.StringUtils;
|
|
|
import org.springframework.beans.BeanUtils;
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
|
-import org.springframework.beans.factory.annotation.Value;
|
|
|
import org.springframework.scheduling.annotation.Async;
|
|
|
import org.springframework.scheduling.annotation.AsyncResult;
|
|
|
import org.springframework.stereotype.Service;
|
|
|
import org.springframework.util.CollectionUtils;
|
|
|
|
|
|
+import javax.annotation.Resource;
|
|
|
import java.math.BigDecimal;
|
|
|
import java.util.*;
|
|
|
import java.util.concurrent.CountDownLatch;
|
|
@@ -54,8 +47,7 @@ import java.util.stream.Collectors;
|
|
|
*/
|
|
|
@Slf4j
|
|
|
@Service
|
|
|
-public class MonitorIndicatorRecordServiceImpl extends ServiceImpl<MonitorIndicatorRecordMapper, MonitorIndicatorRecord>
|
|
|
- implements IMonitorIndicatorRecordService {
|
|
|
+public class MonitorIndicatorRecordServiceImpl implements IMonitorIndicatorRecordService {
|
|
|
|
|
|
@Autowired
|
|
|
private RedisLock lockUtil;
|
|
@@ -73,6 +65,9 @@ public class MonitorIndicatorRecordServiceImpl extends ServiceImpl<MonitorIndica
|
|
|
@Autowired
|
|
|
private EnergyAlarmServiceImpl energyAlarmService;
|
|
|
|
|
|
+ @Autowired
|
|
|
+ private ComputePropertiesConfig computePropertiesConfig;
|
|
|
+
|
|
|
|
|
|
@Autowired
|
|
|
private CenterDataService centerDataService;
|
|
@@ -81,115 +76,15 @@ public class MonitorIndicatorRecordServiceImpl extends ServiceImpl<MonitorIndica
|
|
|
public final static String alarmSlipt = "_";
|
|
|
|
|
|
|
|
|
- @Value(value = "${energy.eq.run.compute.round.days:1}")
|
|
|
- private Integer roundDays;
|
|
|
-
|
|
|
-
|
|
|
- @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;
|
|
|
|
|
|
|
|
|
- private final static Long ConfigItemKeyTime = 60 * 60 * 1000L;
|
|
|
-
|
|
|
-
|
|
|
@Autowired
|
|
|
private IProjectIndicatorComputeService projectIndicatorComputeService;
|
|
|
|
|
|
- /**
|
|
|
- * 创建监测指标历史记录
|
|
|
- *
|
|
|
- * @return 监测指标历史记录主键
|
|
|
- * @author lixing
|
|
|
- */
|
|
|
- @Override
|
|
|
- public String createMonitorIndicatorRecord(AddMonitorIndicatorRecordDTO addMonitorIndicatorRecordDTO) {
|
|
|
- MonitorIndicatorRecord monitorIndicatorRecord = ConvertMonitorIndicatorRecordTool.INSTANCE.convertAddDto2Entity(addMonitorIndicatorRecordDTO);
|
|
|
- // 设置默认值
|
|
|
- setDefaultValue(monitorIndicatorRecord);
|
|
|
- save(monitorIndicatorRecord);
|
|
|
- return null;
|
|
|
- }
|
|
|
-
|
|
|
- /**
|
|
|
- * 如果某些字段没有赋值,使用默认的值
|
|
|
- *
|
|
|
- * @param monitorIndicatorRecord 监测指标历史记录实体
|
|
|
- * @author lixing
|
|
|
- */
|
|
|
- private void setDefaultValue(MonitorIndicatorRecord monitorIndicatorRecord) {
|
|
|
- // todo 其他默认的属性
|
|
|
+ @Resource(name = "ZillionDao")
|
|
|
+ private CoreDao coredao;
|
|
|
|
|
|
- }
|
|
|
-
|
|
|
- /**
|
|
|
- * 监测指标历史记录详情
|
|
|
- *
|
|
|
- * @param id 主键
|
|
|
- * @return 部门do类
|
|
|
- * @author lixing
|
|
|
- */
|
|
|
- @Override
|
|
|
- public MonitorIndicatorRecord queryMonitorIndicatorRecordDetail(String id) {
|
|
|
- MonitorIndicatorRecord monitorIndicatorRecord = getById(id);
|
|
|
- if (monitorIndicatorRecord == null) {
|
|
|
- throw new IllegalArgumentException("查看MonitorIndicatorRecord详情时发生异常,找不到要查看的记录,id=" + id);
|
|
|
- }
|
|
|
- return monitorIndicatorRecord;
|
|
|
- }
|
|
|
-
|
|
|
- /**
|
|
|
- * 更新监测指标历史记录
|
|
|
- *
|
|
|
- * @author lixing
|
|
|
- */
|
|
|
- @Override
|
|
|
- public void updateMonitorIndicatorRecord(UpdateMonitorIndicatorRecordDTO updateMonitorIndicatorRecordDTO) {
|
|
|
- MonitorIndicatorRecord monitorIndicatorRecord = getById(updateMonitorIndicatorRecordDTO.getId());
|
|
|
- monitorIndicatorRecord = ConvertMonitorIndicatorRecordTool.INSTANCE.convertUpdateDto2Entity(monitorIndicatorRecord, updateMonitorIndicatorRecordDTO);
|
|
|
- updateById(monitorIndicatorRecord);
|
|
|
- }
|
|
|
-
|
|
|
- /**
|
|
|
- * 校验监测指标历史记录是否可删除
|
|
|
- *
|
|
|
- * @param id 监测指标历史记录主键
|
|
|
- * @return 监测指标历史记录do类
|
|
|
- * @author lixing
|
|
|
- */
|
|
|
- public MonitorIndicatorRecord checkDeletable(String id) {
|
|
|
- if (id == null) {
|
|
|
- throw new IllegalArgumentException("删除MonitorIndicatorRecord时发生异常,主键为空");
|
|
|
- }
|
|
|
-
|
|
|
- MonitorIndicatorRecord monitorIndicatorRecord = getById(id);
|
|
|
-
|
|
|
- if (monitorIndicatorRecord == null) {
|
|
|
- throw new IllegalArgumentException("删除MonitorIndicatorRecord时发生异常,找不到要删除的数据,id:" + id);
|
|
|
- }
|
|
|
- return monitorIndicatorRecord;
|
|
|
- }
|
|
|
-
|
|
|
- /**
|
|
|
- * 删除监测指标历史记录
|
|
|
- *
|
|
|
- * @param id 主键
|
|
|
- * @author lixing
|
|
|
- */
|
|
|
- @Override
|
|
|
- public void deleteMonitorIndicatorRecord(String id) {
|
|
|
- // 校验是否可删除
|
|
|
- MonitorIndicatorRecord monitorIndicatorRecord = checkDeletable(id);
|
|
|
- updateById(monitorIndicatorRecord);
|
|
|
- }
|
|
|
|
|
|
/**
|
|
|
* 查询监测指标历史记录
|
|
@@ -198,215 +93,178 @@ public class MonitorIndicatorRecordServiceImpl extends ServiceImpl<MonitorIndica
|
|
|
* @author lixing
|
|
|
*/
|
|
|
@Override
|
|
|
- public List<MonitorIndicatorRecord> queryMonitorIndicatorRecordList(QueryMonitorIndicatorRecordDTO queryMonitorIndicatorRecordDTO) {
|
|
|
- QueryWrapper<MonitorIndicatorRecord> queryWrapper = new QueryWrapper<>();
|
|
|
- // 默认按创建时间倒序排序
|
|
|
- queryWrapper.orderBy(true, false, MonitorIndicatorRecord.PROP_DATE);
|
|
|
-
|
|
|
- if (queryMonitorIndicatorRecordDTO != null) {
|
|
|
-
|
|
|
- // todo 需判断使用like还是eq
|
|
|
- if (StringUtils.isNotEmpty(queryMonitorIndicatorRecordDTO.getObjId())) {
|
|
|
- queryWrapper.like(MonitorIndicatorRecord.PROP_OBJ_ID, queryMonitorIndicatorRecordDTO.getObjId());
|
|
|
- }
|
|
|
-
|
|
|
- // todo 需判断使用like还是eq
|
|
|
- if (StringUtils.isNotEmpty(queryMonitorIndicatorRecordDTO.getMonitorIndicatorId())) {
|
|
|
- queryWrapper.like(MonitorIndicatorRecord.PROP_MONITOR_INDICATOR_ID, queryMonitorIndicatorRecordDTO.getMonitorIndicatorId());
|
|
|
- }
|
|
|
-
|
|
|
- if (queryMonitorIndicatorRecordDTO.getDate() != null) {
|
|
|
- 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);
|
|
|
+ public List<MonitorIndicatorRecord> queryMonitorIndicatorRecordList(QueryMonitorIndicatorRecordDTO queryMonitorIndicatorRecordDTO) throws Exception {
|
|
|
+ MonitorIndicatorRecord query = new MonitorIndicatorRecord();
|
|
|
+ query.setMonitorIndicatorId(queryMonitorIndicatorRecordDTO.getMonitorIndicatorId());
|
|
|
+ query.setProject(queryMonitorIndicatorRecordDTO.getProjectId());
|
|
|
+ query.setObjId(queryMonitorIndicatorRecordDTO.getObjId());
|
|
|
+ query.setSpecialOperation("dataTime", SpecialOperator.$gte, queryMonitorIndicatorRecordDTO.getTimeFrom());
|
|
|
+ query.setSpecialOperation("dataTime", SpecialOperator.$lt, queryMonitorIndicatorRecordDTO.getTimeTo());
|
|
|
+ return coredao.query(query);
|
|
|
}
|
|
|
|
|
|
- /**
|
|
|
- * 分页查询监测指标历史记录
|
|
|
- *
|
|
|
- * @return IPage<MonitorIndicatorRecord>
|
|
|
- * @author lixing
|
|
|
- */
|
|
|
- @Override
|
|
|
- public IPage<MonitorIndicatorRecord> pageQueryMonitorIndicatorRecord(PageQueryMonitorIndicatorRecordDTO pageQueryMonitorIndicatorRecordDTO) {
|
|
|
- QueryWrapper<MonitorIndicatorRecord> queryWrapper = new QueryWrapper<>();
|
|
|
- // 这里认为pageQueryDTO是经过校验的,肯定包含分页信息
|
|
|
- IPage<MonitorIndicatorRecord> pageParam = new Page<>(pageQueryMonitorIndicatorRecordDTO.getPage(), pageQueryMonitorIndicatorRecordDTO.getSize(), true);
|
|
|
- // 排序信息
|
|
|
- if (CollectionUtils.isEmpty(pageQueryMonitorIndicatorRecordDTO.getOrders())) {
|
|
|
- // 默认按创建时间倒序排序
|
|
|
- queryWrapper.orderBy(true, false, MonitorIndicatorRecord.PROP_DATE);
|
|
|
- } else {
|
|
|
- List<Sort> orders = pageQueryMonitorIndicatorRecordDTO.getOrders();
|
|
|
- for (Sort sort : orders) {
|
|
|
- // 将驼峰转换为下划线格式
|
|
|
- sort.setColumn(CaseFormat.LOWER_CAMEL.to(CaseFormat.LOWER_UNDERSCORE, sort.getColumn()));
|
|
|
- queryWrapper.orderBy(true, sort.isAsc(), sort.getColumn());
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
- // todo 需判断使用like还是eq
|
|
|
- if (StringUtils.isNotEmpty(pageQueryMonitorIndicatorRecordDTO.getObjId())) {
|
|
|
- queryWrapper.like(MonitorIndicatorRecord.PROP_OBJ_ID, pageQueryMonitorIndicatorRecordDTO.getObjId());
|
|
|
- }
|
|
|
-
|
|
|
- // todo 需判断使用like还是eq
|
|
|
- if (StringUtils.isNotEmpty(pageQueryMonitorIndicatorRecordDTO.getMonitorIndicatorId())) {
|
|
|
- queryWrapper.like(MonitorIndicatorRecord.PROP_MONITOR_INDICATOR_ID, pageQueryMonitorIndicatorRecordDTO.getMonitorIndicatorId());
|
|
|
- }
|
|
|
-
|
|
|
- if (pageQueryMonitorIndicatorRecordDTO.getDate() != null) {
|
|
|
- queryWrapper.eq(MonitorIndicatorRecord.PROP_DATE, pageQueryMonitorIndicatorRecordDTO.getDate());
|
|
|
- }
|
|
|
-
|
|
|
- // todo 需判断使用like还是eq
|
|
|
- if (StringUtils.isNotEmpty(pageQueryMonitorIndicatorRecordDTO.getValue())) {
|
|
|
- queryWrapper.like(MonitorIndicatorRecord.PROP_VALUE, pageQueryMonitorIndicatorRecordDTO.getValue());
|
|
|
- }
|
|
|
- return getBaseMapper().selectPage(pageParam, queryWrapper);
|
|
|
- }
|
|
|
|
|
|
@Override
|
|
|
@Async("asyncComputeDataExecutor")
|
|
|
public Future<String> computeIndicatorData(ProjectDTO projectDTO, ProjectIndicatorCompute projectIndicatorCompute, CountDownLatch latch) throws Exception {
|
|
|
long time = System.currentTimeMillis() + (20 * 1000);
|
|
|
try {
|
|
|
- if (!lockUtil.lock(projectDTO.getProjectId() + "_compute", String.valueOf(time))) {
|
|
|
+ if (!lockUtil.lock(projectDTO.getProjectId() + DiAgnoseConst.RedisConstants.ComputeProjectLockKey, String.valueOf(time))) {
|
|
|
// 获取不到锁,略过
|
|
|
return new AsyncResult<>("【监测指标数据计算线程】项目:" + projectDTO.getProjectId() + "被占用");
|
|
|
}
|
|
|
|
|
|
long start = System.currentTimeMillis();
|
|
|
- AsyncResult<String> projectDTO1 = computeProjectIndicatorData(projectDTO, projectIndicatorCompute);
|
|
|
- if (projectDTO1 != null) {
|
|
|
- return projectDTO1;
|
|
|
+ AsyncResult<String> errorMsg = computeProjectIndicatorData(projectDTO, projectIndicatorCompute);
|
|
|
+ if (errorMsg != null) {
|
|
|
+ return errorMsg;
|
|
|
}
|
|
|
long end = System.currentTimeMillis();
|
|
|
return new AsyncResult<>("【监测指标数据计算线程】计算项目指标数据用时:" + projectDTO.getProjectId() + ";" + (end - start));
|
|
|
} finally {
|
|
|
// 释放锁
|
|
|
- lockUtil.unlock(projectDTO.getProjectId() + "_compute", String.valueOf(time));
|
|
|
+ lockUtil.unlock(projectDTO.getProjectId() + DiAgnoseConst.RedisConstants.ComputeProjectLockKey, String.valueOf(time));
|
|
|
latch.countDown();
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
+
|
|
|
private AsyncResult<String> computeProjectIndicatorData(ProjectDTO projectDTO, ProjectIndicatorCompute projectIndicatorCompute) throws Exception {
|
|
|
- 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() + "未查询到报警条件");
|
|
|
- }
|
|
|
- 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);
|
|
|
+ {
|
|
|
+ //判断当前计算轮次是否大于缓存中最新计算轮次,如果是,则证明已经被计算过,则略过
|
|
|
+ Object redisComputeRound = redisUtil.hget(DiAgnoseConst.RedisConstants.TargetComputeTime, projectDTO.getProjectId());
|
|
|
+ if (redisComputeRound != null && projectIndicatorCompute != null
|
|
|
+ && projectIndicatorCompute.getComputeRound() < Long.parseLong(redisComputeRound.toString())) {
|
|
|
+ return new AsyncResult<>("【监测指标数据计算线程】当前项目:" + projectDTO.getProjectId() + "被占用");
|
|
|
+ }
|
|
|
+ }
|
|
|
+ //通过报警服务查询报警规则
|
|
|
+ List<AlarmRuleDTO> projectAlarmRules = energyAlarmService.getProjectAlarmRules(projectDTO.getProjectId());
|
|
|
+ if (CollectionUtils.isEmpty(projectAlarmRules)) {
|
|
|
+ return new AsyncResult<>("【监测指标数据计算线程】当前项目:" + projectDTO.getProjectId() + "未设置报警规则");
|
|
|
}
|
|
|
|
|
|
+ Set<String> objIdAndIndicatorId = getObjIdAndInfoCodeFromRules(projectAlarmRules);
|
|
|
+ if (CollectionUtils.isEmpty(objIdAndIndicatorId)) {
|
|
|
+ return new AsyncResult<>("【监测指标数据计算线程】当前项目:" + projectDTO.getProjectId() + "报警规则未关联对象");
|
|
|
+ }
|
|
|
Map<String, Date> objId_indicatorIdAndComputeTIme = getObjId_IndicatorIdAndComputeTIme(projectDTO);
|
|
|
Map<String, CalculateMethodDTO> methodIdAndMethodDTO = energyAlarmService.queryCalculateMethods();
|
|
|
|
|
|
- Map<String, Set<String>> objIdAndInfoCodes = getObjIdAndInfoCodes(configItemList, objIdAndObj);
|
|
|
-
|
|
|
- //根据报警条件查询监测对象
|
|
|
- for (Map.Entry<String, Set<String>> entry : objIdAndInfoCodes.entrySet()) {
|
|
|
- String objId = entry.getKey();
|
|
|
- Set<String> infoCodes = entry.getValue();
|
|
|
- if (CollectionUtils.isEmpty(infoCodes)) {
|
|
|
+ for (String objIdIndicatorId : objIdAndIndicatorId) {
|
|
|
+ int indexOf = objIdIndicatorId.indexOf("_");
|
|
|
+ String objId = objIdIndicatorId.substring(0, indexOf);
|
|
|
+ String indicatorId = objIdIndicatorId.substring(indexOf + 1);
|
|
|
+ String methodId = energyAlarmService.queryObjIndicatorMethodId(projectDTO.getProjectId(), objId, indicatorId);
|
|
|
+ if (StringUtils.isBlank(methodId)) {
|
|
|
+ log.error("【监测指标数据计算线程】:项目监控指标未设置公式:" + projectDTO.getProjectId() + ";" + objId + ";" + indicatorId);
|
|
|
continue;
|
|
|
}
|
|
|
- //获取对象id及指标相应公式id
|
|
|
- Map<String, String> objId_indicatorAndMethodId = getObjId_indicatorAndMethodId(projectDTO, objId, new ArrayList<>(infoCodes));
|
|
|
- if (objId_indicatorAndMethodId.isEmpty()) {
|
|
|
- log.error("【监测指标数据计算线程】:项目监控指标未设置公式:" + projectDTO.getProjectId() + ";" + objId);
|
|
|
+ CalculateMethodDTO calculateMethodDTO = methodIdAndMethodDTO.get(methodId);
|
|
|
+ if (calculateMethodDTO == null) {
|
|
|
+ log.error("【监测指标数据计算线程】:项目监控指标设置公式为null:" + projectDTO.getProjectId() + ";" + objId + ";" + indicatorId);
|
|
|
continue;
|
|
|
}
|
|
|
- //处理监控指标
|
|
|
- for (String infocode : infoCodes) {
|
|
|
- String caculateMethodId = objId_indicatorAndMethodId.get(infocode);
|
|
|
- if (StringUtils.isEmpty(caculateMethodId)) {
|
|
|
- log.error("【监测指标数据计算线程】:监控指标未设置公式:" + infocode);
|
|
|
- continue;
|
|
|
- }
|
|
|
- CalculateMethodDTO calculateMethodDTO = methodIdAndMethodDTO.get(caculateMethodId);
|
|
|
- if (calculateMethodDTO == null) {
|
|
|
- log.error("【监测指标数据计算线程】:监控指标未设置公式为null:" + infocode);
|
|
|
- continue;
|
|
|
- }
|
|
|
-
|
|
|
- Date lastComputeTime = objId_indicatorIdAndComputeTIme.get(infocode);
|
|
|
- if (lastComputeTime == null) {
|
|
|
- lastComputeTime = getDefultStartTime();
|
|
|
- }
|
|
|
- Date computeEndTime = DateUtils.addDays(lastComputeTime, roundDays);
|
|
|
- String indicatorId = getIndicatorIdFromInfocode(infocode);
|
|
|
- String formula = calculateMethodDTO.getFormula();
|
|
|
- JSONObject obj = objIdAndObj.get(objId);
|
|
|
- Date computeTime = computeIndicatorData(projectDTO, obj, lastComputeTime, computeEndTime, indicatorId, formula);
|
|
|
- saveOrUpdateComputeTime(projectDTO.getProjectId(), obj.getString("id"), indicatorId, computeTime);
|
|
|
+ Date lastComputeTime = objId_indicatorIdAndComputeTIme.get(objIdIndicatorId);
|
|
|
+ if (lastComputeTime == null) {
|
|
|
+ lastComputeTime = getDefultStartTime();
|
|
|
}
|
|
|
+ Date computeEndTime = DateUtils.addDays(lastComputeTime, computePropertiesConfig.getRoundDays());
|
|
|
+ String formula = calculateMethodDTO.getFormula();
|
|
|
+ Date computeTime = computeIndicatorData(projectDTO, objId, lastComputeTime, computeEndTime, indicatorId, formula);
|
|
|
+ saveOrUpdateComputeTime(projectDTO.getProjectId(), objId, indicatorId, computeTime);
|
|
|
}
|
|
|
// 更新缓存计算轮次
|
|
|
updateProjectComputeRound(projectDTO.getProjectId(), projectIndicatorCompute);
|
|
|
return null;
|
|
|
}
|
|
|
|
|
|
+ /**
|
|
|
+ * @title getObjIdAndInfoCodeFromRules
|
|
|
+ * @description 通过报警条件获取所有对象及其监控点位,objId_infoCode
|
|
|
+ * @author leifeng
|
|
|
+ * @param: projectAlarmRules
|
|
|
+ * @updateTime 2021/10/26 21:24
|
|
|
+ * @return: java.util.Set<java.lang.String>
|
|
|
+ * @throws
|
|
|
+ */
|
|
|
+ private Set<String> getObjIdAndInfoCodeFromRules(List<AlarmRuleDTO> projectAlarmRules) {
|
|
|
+ Set<String> objIdAndInfoCode = new HashSet<>();
|
|
|
+ for (AlarmRuleDTO projectAlarmRule : projectAlarmRules) {
|
|
|
+ List<String> objIds = projectAlarmRule.getObjIds();
|
|
|
+ if(CollectionUtils.isEmpty(objIds)){
|
|
|
+ continue;
|
|
|
+ }
|
|
|
+ List<String> infoCodes = projectAlarmRule.getInfoCodes();
|
|
|
+ if (CollectionUtils.isEmpty(infoCodes)){
|
|
|
+ continue;
|
|
|
+ }
|
|
|
+ for (String infoCode : infoCodes) {
|
|
|
+ for (String objId : objIds) {
|
|
|
+ objIdAndInfoCode.add(objId + "_" + infoCode);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ return objIdAndInfoCode;
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * @title computeIndicatorData
|
|
|
+ * @description 计算指标数据,返回最后计算时间
|
|
|
+ * @author leifeng
|
|
|
+ * @param: projectDTO
|
|
|
+ * @param: objId
|
|
|
+ * @param: lastComputeTime
|
|
|
+ * @param: computeEndTime
|
|
|
+ * @param: indicatorId
|
|
|
+ * @param: formula
|
|
|
+ * @updateTime 2021/9/25 20:11
|
|
|
+ */
|
|
|
+ private Date computeIndicatorData(ProjectDTO projectDTO, String objId, Date lastComputeTime, Date computeEndTime, String infoCode, String formula) throws Exception {
|
|
|
+ ComputeCalculateDTO computeCalculateDTO = new ComputeCalculateDTO();
|
|
|
+ computeCalculateDTO.setObjId(objId);
|
|
|
+ computeCalculateDTO.setProjectId(projectDTO.getProjectId());
|
|
|
+ computeCalculateDTO.setTargetId(infoCode);
|
|
|
+ Map<String, Double> timeDataMap = TimeDataUtil.getTimeDataMap(lastComputeTime, computeEndTime,
|
|
|
+ EnumTimeType.MIN15);
|
|
|
+
|
|
|
+ Date timeEnd = null;
|
|
|
+ for (Map.Entry<String, Double> entry : timeDataMap.entrySet()) {
|
|
|
+ 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;
|
|
|
+ }
|
|
|
+
|
|
|
+ MonitorIndicatorRecord monitorIndicatorRecord = new MonitorIndicatorRecord();
|
|
|
+ monitorIndicatorRecord.setMonitorIndicatorId(infoCode);
|
|
|
+ monitorIndicatorRecord.setDataTime(dataTime);
|
|
|
+ monitorIndicatorRecord.setObjId(objId);
|
|
|
+ monitorIndicatorRecord.setProject(projectDTO.getProjectId());
|
|
|
+ monitorIndicatorRecord.setDataValue(targetData);
|
|
|
+ saveOrUpdateByPk(monitorIndicatorRecord);
|
|
|
+ }
|
|
|
+ return timeEnd;
|
|
|
+ }
|
|
|
+
|
|
|
private Date getDefultStartTime() throws Exception {
|
|
|
Date lastComputeTime;
|
|
|
- if (StringUtils.isBlank(dStartTime)) {
|
|
|
+ if (StringUtils.isBlank(computePropertiesConfig.getDStartTime())) {
|
|
|
lastComputeTime = new Date();
|
|
|
} else {
|
|
|
- lastComputeTime = DateUtils.str2Date(dStartTime, DateUtils.SDF_SECOND);
|
|
|
+ lastComputeTime = DateUtils.str2Date(computePropertiesConfig.getDStartTime(), 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) {
|
|
@@ -420,16 +278,7 @@ public class MonitorIndicatorRecordServiceImpl extends ServiceImpl<MonitorIndica
|
|
|
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")
|
|
@@ -452,27 +301,29 @@ public class MonitorIndicatorRecordServiceImpl extends ServiceImpl<MonitorIndica
|
|
|
}
|
|
|
|
|
|
@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);
|
|
|
+ public void saveOrUpdateByPk(MonitorIndicatorRecord monitorIndicatorRecord) throws Exception {
|
|
|
+ MonitorIndicatorRecord query = new MonitorIndicatorRecord();
|
|
|
+ query.setProject(monitorIndicatorRecord.getProject());
|
|
|
+ query.setObjId(monitorIndicatorRecord.getObjId());
|
|
|
+ query.setDataTime(monitorIndicatorRecord.getDataTime());
|
|
|
+// query.setSplitTimeType(EnumTimeType.MIN15.getCode());
|
|
|
+ query.setMonitorIndicatorId(monitorIndicatorRecord.getMonitorIndicatorId());
|
|
|
+ List<MonitorIndicatorRecord> queryList = coredao.query(query);
|
|
|
+ if (CollectionUtils.isEmpty(queryList)) {//新增
|
|
|
+ coredao.save(monitorIndicatorRecord);
|
|
|
} else {
|
|
|
- this.update(monitorIndicatorRecord, queryWrapper);
|
|
|
+ MonitorIndicatorRecord update = new MonitorIndicatorRecord();
|
|
|
+ update.setDataValue(monitorIndicatorRecord.getDataValue());
|
|
|
+ coredao.update(query, update);
|
|
|
}
|
|
|
}
|
|
|
|
|
|
@Override
|
|
|
public void cleanAlarmConfig(String projectId) {
|
|
|
if (StringUtils.isBlank(projectId)) {
|
|
|
- redisUtil.del(RedisUtil.PROJECT_ALARM_ITEM);
|
|
|
+ redisUtil.del(DiAgnoseConst.RedisConstants.PROJECT_ALARM_ITEM);
|
|
|
} else {
|
|
|
- redisUtil.hdel(RedisUtil.PROJECT_ALARM_ITEM, projectId);
|
|
|
+ redisUtil.hdel(DiAgnoseConst.RedisConstants.PROJECT_ALARM_ITEM, projectId);
|
|
|
}
|
|
|
}
|
|
|
|
|
@@ -480,44 +331,47 @@ public class MonitorIndicatorRecordServiceImpl extends ServiceImpl<MonitorIndica
|
|
|
public void cleanAlarmConfigSendTime(CleanAlarmConfigDTO cleanAlarmConfigDTO) {
|
|
|
if (StringUtils.isBlank(cleanAlarmConfigDTO.getProjectId())) {
|
|
|
//清除所有
|
|
|
- redisUtil.del(RedisUtil.PROJECT_ITEM_SEND_TIME);
|
|
|
+ redisUtil.del(DiAgnoseConst.RedisConstants.PROJECT_ITEM_SEND_TIME);
|
|
|
} else if (StringUtils.isBlank(cleanAlarmConfigDTO.getAlarmConfigItemId())) {
|
|
|
//清除项目
|
|
|
- redisUtil.del(RedisUtil.PROJECT_ALARM_ITEM + ":" + cleanAlarmConfigDTO.getProjectId());
|
|
|
+ redisUtil.del(DiAgnoseConst.RedisConstants.PROJECT_ALARM_ITEM + ":" + cleanAlarmConfigDTO.getProjectId());
|
|
|
} else {
|
|
|
//清除指定
|
|
|
- redisUtil.hdel(RedisUtil.PROJECT_ALARM_ITEM + ":" + cleanAlarmConfigDTO.getProjectId(), cleanAlarmConfigDTO.getAlarmConfigItemId());
|
|
|
+ redisUtil.hdel(DiAgnoseConst.RedisConstants.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() + "为查询到报警条件");
|
|
|
+ //通过报警服务查询报警规则
|
|
|
+ List<AlarmRuleDTO> projectAlarmRules = energyAlarmService.getProjectAlarmRules(projectDTO.getProjectId());
|
|
|
+ if (CollectionUtils.isEmpty(projectAlarmRules)) {
|
|
|
return;
|
|
|
}
|
|
|
+ //根据报警规则,获取对象id_报警类型及设备监控点位list
|
|
|
+ Map<String, List<String>> objIdAlarmItemCodeAndInfoCodes = getObjIdAlarmItemCodeAndInfoCodes(projectAlarmRules);
|
|
|
+
|
|
|
+ for (Map.Entry<String, List<String>> entry : objIdAlarmItemCodeAndInfoCodes.entrySet()) {
|
|
|
+ String objIdAndAlarmItemCode = entry.getKey();
|
|
|
+
|
|
|
+ int indexOf = objIdAndAlarmItemCode.indexOf("_");
|
|
|
+ String objId = objIdAndAlarmItemCode.substring(0, indexOf);
|
|
|
+
|
|
|
+
|
|
|
+ List<String> infCodeList = entry.getValue();
|
|
|
+
|
|
|
+ //通过redis查询对象该报警类型下的发数截止时间
|
|
|
+ ConfigItemDataSendTimeDTO configItemSendTimeDTO = getConfigItemSendTimeDTO(projectDTO, objIdAndAlarmItemCode);
|
|
|
|
|
|
- for (AlarmConfigItem alarmConfigItem : configItemList) {
|
|
|
- AlarmCondition condition = alarmConfigItem.getCondition();
|
|
|
- if (condition == null) {
|
|
|
- continue;
|
|
|
- }
|
|
|
- List<String> infoCodes = condition.getInfoCode();
|
|
|
- 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, getIndicatorIdListFromInfoCodes(infoCodes), endTime);
|
|
|
+ Date endTime = getSendEndTime(lastSendTime);
|
|
|
+
|
|
|
+ List<MonitorIndicatorRecord> list = getMonitorIndicatorRecordsGtLte(projectDTO.getProjectId(), objId, lastSendTime, infCodeList, endTime);
|
|
|
if (CollectionUtils.isEmpty(list)) {
|
|
|
continue;
|
|
|
}
|
|
|
-
|
|
|
Map<String, List<MonitorIndicatorRecord>> timeKeyAndRecordList = new LinkedHashMap<>();
|
|
|
for (MonitorIndicatorRecord record : list) {
|
|
|
- String timeKey = DateUtils.date2Str(record.getDate(), DateUtils.SDF_SECOND);
|
|
|
+ String timeKey = DateUtils.date2Str(record.getDataTime(), DateUtils.SDF_SECOND);
|
|
|
if (!timeKeyAndRecordList.containsKey(timeKey)) {
|
|
|
timeKeyAndRecordList.put(timeKey, new ArrayList<>());
|
|
|
}
|
|
@@ -525,21 +379,50 @@ public class MonitorIndicatorRecordServiceImpl extends ServiceImpl<MonitorIndica
|
|
|
}
|
|
|
for (Map.Entry<String, List<MonitorIndicatorRecord>> dateListEntry : timeKeyAndRecordList.entrySet()) {
|
|
|
List<MonitorIndicatorRecord> value = dateListEntry.getValue();
|
|
|
- if (CollectionUtils.isEmpty(value) || value.size() != infoCodes.size()) {
|
|
|
+ if (CollectionUtils.isEmpty(value) || value.size() != infCodeList.size()) {
|
|
|
continue;
|
|
|
}
|
|
|
String sentValue = CollectDataUtil.buildSendParam(value);
|
|
|
AlarmWebSocketServer.sendMsgToClients(projectDTO.getProjectId(), CollectDataUtil.buildSendParam(value));
|
|
|
- log.info("指标发送报表服务数据:" + projectDTO.getProjectId() + sentValue);
|
|
|
+ log.info("指标发送报表服务数据:" + projectDTO.getProjectId()+";"+ sentValue);
|
|
|
endTime = DateUtils.str2Date(dateListEntry.getKey(), DateUtils.SDF_SECOND);
|
|
|
}
|
|
|
configItemSendTimeDTO.setLastSendTime(endTime);
|
|
|
- updateRedisConfigItemSendTimeDTO(projectDTO.getProjectId(), configItemSendTimeDTO);
|
|
|
+ configItemSendTimeDTO.setUpdateTime(new Date());
|
|
|
+ updateRedisConfigItemSendTimeDTO(projectDTO.getProjectId(), objIdAndAlarmItemCode, configItemSendTimeDTO);
|
|
|
}
|
|
|
}
|
|
|
|
|
|
- private Date getSendEndTiem(Date lastSendTime) {
|
|
|
- Date date = DateUtils.addHours(lastSendTime, sendDataHour);
|
|
|
+ /**
|
|
|
+ * @title getObjIdAlarmItemCodeAndInfoCodes
|
|
|
+ * @description 获取对象报警类型及监控指标list,key为objId_itemCode
|
|
|
+ * @author leifeng
|
|
|
+ * @param: projectAlarmRules
|
|
|
+ * @updateTime 2021/10/26 21:35
|
|
|
+ * @return: java.util.Map<java.lang.String,java.util.List<java.lang.String>>
|
|
|
+ * @throws
|
|
|
+ */
|
|
|
+ private Map<String, List<String>> getObjIdAlarmItemCodeAndInfoCodes(List<AlarmRuleDTO> projectAlarmRules) {
|
|
|
+ Map<String, List<String>> objIdAlarmItemCodeAndInfoCodes = new HashMap<>();
|
|
|
+ for (AlarmRuleDTO projectAlarmRule : projectAlarmRules) {
|
|
|
+ String alarmItemCode = projectAlarmRule.getAlarmItemCode();
|
|
|
+ List<String> objIds = projectAlarmRule.getObjIds();
|
|
|
+ List<String> infoCodes = projectAlarmRule.getInfoCodes();
|
|
|
+ for (String infoCode : infoCodes) {
|
|
|
+ for (String objId : objIds) {
|
|
|
+ String key = objId + "_" + alarmItemCode;
|
|
|
+ if (!objIdAlarmItemCodeAndInfoCodes.containsKey(key)) {
|
|
|
+ objIdAlarmItemCodeAndInfoCodes.put(key, new ArrayList<String>());
|
|
|
+ }
|
|
|
+ objIdAlarmItemCodeAndInfoCodes.get(key).add(infoCode);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ return objIdAlarmItemCodeAndInfoCodes;
|
|
|
+ }
|
|
|
+
|
|
|
+ private Date getSendEndTime(Date lastSendTime) {
|
|
|
+ Date date = DateUtils.addHours(lastSendTime, computePropertiesConfig.getSendDataHour());
|
|
|
if (date.getTime() > System.currentTimeMillis()) {//大于当前时间
|
|
|
return new Date();
|
|
|
}
|
|
@@ -558,17 +441,19 @@ public class MonitorIndicatorRecordServiceImpl extends ServiceImpl<MonitorIndica
|
|
|
* @updateTime 2021/9/25 20:08
|
|
|
* @return: java.util.List<com.persagy.apm.diagnose.indicatorrecord.model.MonitorIndicatorRecord>
|
|
|
*/
|
|
|
- private List<MonitorIndicatorRecord> getMonitorIndicatorRecordsGtLte(ProjectDTO projectDTO, AlarmConfigItem alarmConfigItem, Date lastSendTime, List<String> infoCodes, Date endTime) {
|
|
|
- QueryWrapper<MonitorIndicatorRecord> queryWrapper = new QueryWrapper<>();
|
|
|
- queryWrapper.eq(MonitorIndicatorRecord.PROJECT_ID, projectDTO.getProjectId());
|
|
|
- queryWrapper.eq(MonitorIndicatorRecord.PROP_OBJ_ID, alarmConfigItem.getObjId());
|
|
|
- queryWrapper.in(MonitorIndicatorRecord.PROP_MONITOR_INDICATOR_ID, infoCodes);
|
|
|
- queryWrapper.gt(MonitorIndicatorRecord.PROP_DATE, lastSendTime);
|
|
|
- queryWrapper.le(MonitorIndicatorRecord.PROP_DATE, endTime);
|
|
|
- queryWrapper.orderByAsc(MonitorIndicatorRecord.PROP_DATE);
|
|
|
- return list(queryWrapper);
|
|
|
+ private List<MonitorIndicatorRecord> getMonitorIndicatorRecordsGtLte(String projectId, String objId, Date lastSendTime, List<String> infoCodes, Date endTime) throws Exception {
|
|
|
+ MonitorIndicatorRecord monitorIndicatorRecord = new MonitorIndicatorRecord();
|
|
|
+ monitorIndicatorRecord.setProject(projectId);
|
|
|
+ monitorIndicatorRecord.setObjId(objId);
|
|
|
+// monitorIndicatorRecord.setSplitTimeType(EnumTimeType.MIN15.getCode());
|
|
|
+ monitorIndicatorRecord.setSpecialOperation("monitorIndicatorId", SpecialOperator.$in, infoCodes);
|
|
|
+ monitorIndicatorRecord.setSpecialOperation("dataTime", SpecialOperator.$gt, lastSendTime);
|
|
|
+ monitorIndicatorRecord.setSpecialOperation("dataTime", SpecialOperator.$lte, endTime);
|
|
|
+
|
|
|
+ return coredao.query(monitorIndicatorRecord);
|
|
|
}
|
|
|
|
|
|
+
|
|
|
/**
|
|
|
* @title getConfigItemSendTimeDTO
|
|
|
* @description redis中查询报警条件上次发数时间, 如果查询为空, 则初始化当前时间
|
|
@@ -578,15 +463,16 @@ public class MonitorIndicatorRecordServiceImpl extends ServiceImpl<MonitorIndica
|
|
|
* @updateTime 2021/9/25 20:03
|
|
|
* @return: com.persagy.apm.diagnose.indicatorrecord.model.dto.ConfigItemDataSendTimeDTO
|
|
|
*/
|
|
|
- private ConfigItemDataSendTimeDTO getConfigItemSendTimeDTO(ProjectDTO projectDTO, AlarmConfigItem alarmConfigItem) throws Exception {
|
|
|
- ConfigItemDataSendTimeDTO sendTimeDTO = (ConfigItemDataSendTimeDTO) redisUtil.get(getRedisSendDataKey(projectDTO.getProjectId(), alarmConfigItem.getId()));
|
|
|
+ private ConfigItemDataSendTimeDTO getConfigItemSendTimeDTO(ProjectDTO projectDTO, String objIdAndAlarmItemCode) throws Exception {
|
|
|
+ ConfigItemDataSendTimeDTO sendTimeDTO = (ConfigItemDataSendTimeDTO) redisUtil.get(getRedisSendDataKey(projectDTO.getProjectId(), objIdAndAlarmItemCode));
|
|
|
if (sendTimeDTO == null) {
|
|
|
- sendTimeDTO = ConfigItemDataSendTimeDTO.builder().objId(alarmConfigItem.getObjId()).configItemid(alarmConfigItem.getId()).lastSendTime(getDefultStartTime()).build();
|
|
|
+ sendTimeDTO = ConfigItemDataSendTimeDTO.builder().lastSendTime(getDefultStartTime()).build();
|
|
|
}
|
|
|
return sendTimeDTO;
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
+ * @throws
|
|
|
* @title getRedisSendDataKey
|
|
|
* @description 获取发数时间redis key
|
|
|
* @author leifeng
|
|
@@ -594,10 +480,9 @@ public class MonitorIndicatorRecordServiceImpl extends ServiceImpl<MonitorIndica
|
|
|
* @param: alarmConfigItemId
|
|
|
* @updateTime 2021/10/14 19:56
|
|
|
* @return: java.lang.String
|
|
|
- * @throws
|
|
|
*/
|
|
|
- private String getRedisSendDataKey(String projectId, String alarmConfigItemId) {
|
|
|
- return RedisUtil.PROJECT_ITEM_SEND_TIME + ":" + projectId + ":" + alarmConfigItemId;
|
|
|
+ private String getRedisSendDataKey(String projectId, String objIdAndAlarmItemCode) {
|
|
|
+ return DiAgnoseConst.RedisConstants.PROJECT_ITEM_SEND_TIME + ":" + projectId + ":" + objIdAndAlarmItemCode;
|
|
|
}
|
|
|
|
|
|
/**
|
|
@@ -608,8 +493,8 @@ public class MonitorIndicatorRecordServiceImpl extends ServiceImpl<MonitorIndica
|
|
|
* @param: sendTimeDTO
|
|
|
* @updateTime 2021/9/25 20:05
|
|
|
*/
|
|
|
- private void updateRedisConfigItemSendTimeDTO(String projectId, ConfigItemDataSendTimeDTO sendTimeDTO) {
|
|
|
- redisUtil.set(getRedisSendDataKey(projectId, sendTimeDTO.getConfigItemid()), sendTimeDTO, SendDataTimeKeyTime);
|
|
|
+ private void updateRedisConfigItemSendTimeDTO(String projectId, String objeIdAndAlarmItemCode, ConfigItemDataSendTimeDTO sendTimeDTO) {
|
|
|
+ redisUtil.set(getRedisSendDataKey(projectId, objeIdAndAlarmItemCode), sendTimeDTO, SendDataTimeKeyTime);
|
|
|
}
|
|
|
|
|
|
/**
|
|
@@ -634,7 +519,7 @@ public class MonitorIndicatorRecordServiceImpl extends ServiceImpl<MonitorIndica
|
|
|
projectIndicatorCompute.setComputeRound(round);
|
|
|
projectIndicatorComputeService.updateById(projectIndicatorCompute);
|
|
|
}
|
|
|
- redisUtil.hset(RedisUtil.TargetComputeTime, projectId, round.toString());
|
|
|
+ redisUtil.hset(DiAgnoseConst.RedisConstants.TargetComputeTime, projectId, round.toString());
|
|
|
}
|
|
|
|
|
|
|
|
@@ -654,59 +539,11 @@ public class MonitorIndicatorRecordServiceImpl extends ServiceImpl<MonitorIndica
|
|
|
}
|
|
|
|
|
|
|
|
|
- /**
|
|
|
- * @title computeIndicatorData
|
|
|
- * @description 计算指标数据
|
|
|
- * @author leifeng
|
|
|
- * @param: projectDTO
|
|
|
- * @param: obj
|
|
|
- * @param: lastComputeTime
|
|
|
- * @param: computeEndTime
|
|
|
- * @param: indicatorId
|
|
|
- * @param: formula
|
|
|
- * @updateTime 2021/9/25 20:11
|
|
|
- */
|
|
|
- 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()) {
|
|
|
- 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;
|
|
|
- }
|
|
|
- MonitorIndicatorRecord monitorIndicatorRecord = new MonitorIndicatorRecord();
|
|
|
- monitorIndicatorRecord.setMonitorIndicatorId(indicatorId);
|
|
|
- monitorIndicatorRecord.setDate(dataTime);
|
|
|
- monitorIndicatorRecord.setObjId(obj.getString("id"));
|
|
|
- monitorIndicatorRecord.setProjectId(projectDTO.getProjectId());
|
|
|
- monitorIndicatorRecord.setValue(targetData);
|
|
|
- saveOrUpdateByPk(monitorIndicatorRecord);
|
|
|
- }
|
|
|
- return timeEnd;
|
|
|
- }
|
|
|
-
|
|
|
- private String getIndicatorIdFromInfocode(String infocode) {
|
|
|
- int indexOf = infocode.indexOf(alarmSlipt);
|
|
|
- return infocode.substring(indexOf + 1);
|
|
|
- }
|
|
|
|
|
|
/**
|
|
|
* @ClassName MonitorIndicatorRecordServiceImpl
|
|
|
* @author leifeng
|
|
|
- * @Description 查询项目下对象指标计算时间
|
|
|
+ * @Description 查询项目下对象指标计算时间,key为objId_indicator
|
|
|
* @createTime 2021/9/24 11:22
|
|
|
*/
|
|
|
private Map<String, Date> getObjId_IndicatorIdAndComputeTIme(ProjectDTO projectDTO) {
|
|
@@ -715,44 +552,25 @@ public class MonitorIndicatorRecordServiceImpl extends ServiceImpl<MonitorIndica
|
|
|
}
|
|
|
|
|
|
|
|
|
- /**
|
|
|
- * @title getAlarmConfigItemList
|
|
|
- * @description 从缓存中获取报警条件, 如果缓存不存在, 则查询报警服务, 报警条件配置
|
|
|
- * @author leifeng
|
|
|
- * @param: projectDTO
|
|
|
- * @updateTime 2021/9/24 11:27
|
|
|
- * @return: java.util.List<com.persagy.apm.energyalarmstarter.alarmdata.model.vo.AlarmConfigItem>
|
|
|
- */
|
|
|
- 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("WD");
|
|
|
- queryAlarmConfigDTO.setCategory(Collections.singletonList("Eqdx"));
|
|
|
- queryAlarmConfigDTO.setOpen(1);
|
|
|
- DmpResult<List<AlarmConfigItem>> configItemResult = alarmConfigService.query(queryAlarmConfigDTO);
|
|
|
- itemList = DmpResultUtil.getData(configItemResult);
|
|
|
- redisUtil.hset(RedisUtil.PROJECT_ALARM_ITEM, projectId, itemList, ConfigItemKeyTime);
|
|
|
- }
|
|
|
- return itemList;
|
|
|
- }
|
|
|
-
|
|
|
|
|
|
private Double computeObjTargetDataByCalculate(ComputeCalculateDTO computeCalculateDTO, String calculateStr)
|
|
|
throws Exception {
|
|
|
List<String> variables = CalculateUtil.getVariablesFromFormula(calculateStr);
|
|
|
Map<String, Double> variableAndData = new HashMap<>(16);
|
|
|
for (String variable : variables) {
|
|
|
- String v = variable.substring(2, variable.length() - 1);// 获取${}中变量
|
|
|
+ // 获取${}中变量
|
|
|
+ String v = variable.substring(2, variable.length() - 1);
|
|
|
// 解析变量
|
|
|
Double data = null;
|
|
|
- if (v.startsWith(CalculateUtil.SUM)) {// 求和
|
|
|
+
|
|
|
+ if (v.startsWith(CalculateUtil.SUM)) {
|
|
|
+ // 求和
|
|
|
v = v.substring(4, v.length() - 1);
|
|
|
computeCalculateDTO.setCalculateVariableDTO(CalculateVariableDTO.buildCalculateVariableDTO(v));
|
|
|
List<Double> dataList = analysisVariable(computeCalculateDTO);
|
|
|
data = getSumDataFromDataList(dataList);
|
|
|
- } else if (v.startsWith(CalculateUtil.MIN)) {// 求最小值
|
|
|
+ } else if (v.startsWith(CalculateUtil.MIN)) {
|
|
|
+ // 求最小值
|
|
|
v = v.substring(4, v.length() - 1);
|
|
|
computeCalculateDTO.setCalculateVariableDTO(CalculateVariableDTO.buildCalculateVariableDTO(v));
|
|
|
List<Double> analysisVariable = analysisVariable(computeCalculateDTO);
|
|
@@ -779,7 +597,7 @@ public class MonitorIndicatorRecordServiceImpl extends ServiceImpl<MonitorIndica
|
|
|
BigDecimal result = new ComputeFormulaUtil(calculateStr).getResult();
|
|
|
if (result == null) {
|
|
|
log.error("【监测指标数据计算线程】:解析公式为空,projectId:" + computeCalculateDTO.getProjectId() + "对象id:"
|
|
|
- + computeCalculateDTO.getObj().getString("id") + ";指标id:" + computeCalculateDTO.getTargetId()
|
|
|
+ + computeCalculateDTO.getObjId() + ";指标id:" + computeCalculateDTO.getTargetId()
|
|
|
+ ";带入公式:" + calculateStr);
|
|
|
return null;
|
|
|
}
|
|
@@ -825,10 +643,10 @@ public class MonitorIndicatorRecordServiceImpl extends ServiceImpl<MonitorIndica
|
|
|
} else {
|
|
|
List<JSONObject> objList = centerDataService.queryObjRelationList(CenterDataUtil.getObjRelationDataDTO(
|
|
|
computeCalculateDTO.getProjectId(), calculateVariableDTO.getComputeObjType(),
|
|
|
- computeCalculateDTO.getObj().getString("id"), null));
|
|
|
+ computeCalculateDTO.getObjId(), null));
|
|
|
if (CollectionUtils.isEmpty(objList)) {
|
|
|
log.error("【指标计算线程】:查询数据中台子对象为空,projectId:" + computeCalculateDTO.getProjectId() + ";objId:"
|
|
|
- + computeCalculateDTO.getObj().getString("id") + ";子对象类型:"
|
|
|
+ + computeCalculateDTO.getObjId() + ";子对象类型:"
|
|
|
+ calculateVariableDTO.getComputeObjType());
|
|
|
return null;
|
|
|
}
|
|
@@ -836,7 +654,7 @@ public class MonitorIndicatorRecordServiceImpl extends ServiceImpl<MonitorIndica
|
|
|
for (JSONObject object : objList) {
|
|
|
ComputeCalculateDTO computeCalculateDTO2 = new ComputeCalculateDTO();
|
|
|
BeanUtils.copyProperties(computeCalculateDTO2, computeCalculateDTO);
|
|
|
- computeCalculateDTO2.setObj(object);
|
|
|
+ computeCalculateDTO2.setObjId(object.getString("id"));
|
|
|
List<Double> queryDataList = computeObjDataByComputeCalculateDTO(computeCalculateDTO2);
|
|
|
list.addAll(queryDataList);
|
|
|
}
|
|
@@ -856,35 +674,41 @@ public class MonitorIndicatorRecordServiceImpl extends ServiceImpl<MonitorIndica
|
|
|
// 查询数据中台信息点数据
|
|
|
if (time.equals(CalculateUtil.invalidTime)) {
|
|
|
// 查询静态信息点
|
|
|
- return getObjStaticDataFromCenterData(computeCalculateDTO.getObj(), computeCode);
|
|
|
+ return getObjStaticDataFromCenterData(computeCalculateDTO.getProjectId(), computeCalculateDTO.getObjId(), computeCode);
|
|
|
} else {
|
|
|
assert startTime != null;
|
|
|
return getServiceDataFromCenterDataService(computeCalculateDTO.getProjectId(),
|
|
|
- computeCalculateDTO.getObj().getString("id"), computeCode, timeType, startTime,
|
|
|
- DateUtils.addHours(startTime, computeAfterHour));
|
|
|
+ computeCalculateDTO.getObjId(), computeCode, timeType, startTime,
|
|
|
+ DateUtils.addHours(startTime, computePropertiesConfig.getComputeAfterHour()));
|
|
|
}
|
|
|
} else {
|
|
|
// 查询指标数据
|
|
|
List<Double> result = new ArrayList<>();
|
|
|
- QueryWrapper<MonitorIndicatorRecord> queryWrapper = new QueryWrapper<>();
|
|
|
- queryWrapper.eq(MonitorIndicatorRecord.PROJECT_ID, computeCalculateDTO.getProjectId());
|
|
|
- queryWrapper.eq(MonitorIndicatorRecord.PROP_OBJ_ID, computeCalculateDTO.getObj().getString("id"));
|
|
|
- queryWrapper.eq(MonitorIndicatorRecord.PROP_MONITOR_INDICATOR_ID, computeCode);
|
|
|
- queryWrapper.eq(MonitorIndicatorRecord.PROP_DATE, startTime);
|
|
|
- List<MonitorIndicatorRecord> list = list(queryWrapper);
|
|
|
+ MonitorIndicatorRecord query = new MonitorIndicatorRecord();
|
|
|
+ query.setProject(computeCalculateDTO.getProjectId());
|
|
|
+ query.setObjId(computeCalculateDTO.getObjId());
|
|
|
+ query.setDataTime(startTime);
|
|
|
+ query.setMonitorIndicatorId(computeCode);
|
|
|
+ List<MonitorIndicatorRecord> list = coredao.query(query);
|
|
|
if (CollectionUtils.isEmpty(list)) {
|
|
|
return result;
|
|
|
}
|
|
|
- result.add(list.get(0).getValue());
|
|
|
+ result.add(list.get(0).getDataValue());
|
|
|
return result;
|
|
|
}
|
|
|
}
|
|
|
|
|
|
- private List<Double> getObjStaticDataFromCenterData(JSONObject obj, String computeCode) {
|
|
|
+ private List<Double> getObjStaticDataFromCenterData(String projectId, String objId, String computeCode) throws Exception {
|
|
|
List<Double> arrayList = new ArrayList<>();
|
|
|
- Double double1 = obj.getDouble(computeCode);
|
|
|
+ List<JSONObject> objectList = centerDataService.queryObjListByObjId(projectId, Arrays.asList(objId));
|
|
|
+ if (CollectionUtils.isEmpty(objectList)) {
|
|
|
+ log.error("【指标数据计算线程】:查询数据中台对象不存在,:objId:" + objId + ";信息点:" + computeCode);
|
|
|
+ arrayList.add(null);
|
|
|
+ return arrayList;
|
|
|
+ }
|
|
|
+ Double double1 = objectList.get(0).getDouble(computeCode);
|
|
|
if (double1 == null) {
|
|
|
- log.error("【指标数据计算线程】:查询数据中台对象静态数据为空,:objId:" + obj.getString("id") + ";信息点:" + computeCode);
|
|
|
+ log.error("【指标数据计算线程】:查询数据中台对象静态数据为空,:objId:" + objId + ";信息点:" + computeCode);
|
|
|
}
|
|
|
arrayList.add(double1);
|
|
|
return arrayList;
|