|
@@ -6,10 +6,7 @@ import com.alibaba.fastjson.JSONArray;
|
|
|
import com.alibaba.fastjson.JSONObject;
|
|
|
import com.persagy.apm.diagnose.config.ComputePropertiesConfig;
|
|
|
import com.persagy.apm.diagnose.config.RabbitConfig;
|
|
|
-import com.persagy.apm.diagnose.constant.AlarmConstants;
|
|
|
-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.constant.*;
|
|
|
import com.persagy.apm.diagnose.indicatorcompute.model.ProjectIndicatorCompute;
|
|
|
import com.persagy.apm.diagnose.indicatorcompute.service.IProjectIndicatorComputeService;
|
|
|
import com.persagy.apm.diagnose.indicatorrecord.model.dto.*;
|
|
@@ -26,6 +23,7 @@ import com.persagy.apm.diagnose.utils.*;
|
|
|
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.IndicatorComputeLog;
|
|
|
import com.persagy.framework.ems.data.pojo.hbase.MonitorIndicatorRecord;
|
|
|
import lombok.extern.slf4j.Slf4j;
|
|
|
import org.apache.commons.lang.StringUtils;
|
|
@@ -119,7 +117,6 @@ public class MonitorIndicatorRecordServiceImpl implements IMonitorIndicatorRecor
|
|
|
// 获取不到锁,略过
|
|
|
return new AsyncResult<>("【监测指标数据计算线程】项目:" + projectDTO.getProjectId() + "被占用");
|
|
|
}
|
|
|
-
|
|
|
long start = System.currentTimeMillis();
|
|
|
AsyncResult<String> errorMsg = computeProjectIndicatorData(projectDTO, projectIndicatorCompute);
|
|
|
if (errorMsg != null) {
|
|
@@ -138,7 +135,6 @@ public class MonitorIndicatorRecordServiceImpl implements IMonitorIndicatorRecor
|
|
|
|
|
|
private AsyncResult<String> computeProjectIndicatorData(ProjectDTO projectDTO, ProjectIndicatorCompute projectIndicatorCompute) throws Exception {
|
|
|
// log.info(Thread.currentThread().getName() + "开始计算[{}]的设备运行诊断监测指标", projectDTO.getProjectId());
|
|
|
-
|
|
|
//判断当前计算轮次是否大于缓存中最新计算轮次,如果是,则证明已经被计算过,则略过
|
|
|
if (checkProjectIsCalcd(projectDTO.getProjectId(), projectIndicatorCompute)) {
|
|
|
return new AsyncResult<>("【监测指标数据计算线程】当前项目:" + projectDTO.getProjectId() + "被占用");
|
|
@@ -147,7 +143,6 @@ public class MonitorIndicatorRecordServiceImpl implements IMonitorIndicatorRecor
|
|
|
//通过报警服务查询报警规则
|
|
|
// 查询设备运行诊断的报警类型
|
|
|
List<String> eqdxAlarmItemCodeList = energyAlarmService.queryEqdxAlarmItemCodes();
|
|
|
-
|
|
|
if (CollectionUtils.isEmpty(eqdxAlarmItemCodeList)) {
|
|
|
return new AsyncResult<>("【监测指标数据计算线程】未查询到设备运行诊断的报警类型");
|
|
|
}
|
|
@@ -155,51 +150,65 @@ public class MonitorIndicatorRecordServiceImpl implements IMonitorIndicatorRecor
|
|
|
if (CollectionUtils.isEmpty(projectAlarmRules)) {
|
|
|
return new AsyncResult<>("【监测指标数据计算线程】当前项目:" + projectDTO.getProjectId() + "未设置报警规则");
|
|
|
}
|
|
|
-
|
|
|
+ //通过项目报警条件,获取项目下对象id及监控点位id
|
|
|
Set<String> objIdAndIndicatorId = getObjIdAndInfoCodeFromRules(projectAlarmRules);
|
|
|
- // log.debug(Thread.currentThread().getName() + "共有{}个监测指标需要计算", objIdAndIndicatorId.size());
|
|
|
if (CollectionUtils.isEmpty(objIdAndIndicatorId)) {
|
|
|
return new AsyncResult<>("【监测指标数据计算线程】当前项目:" + projectDTO.getProjectId() + "报警规则未关联对象");
|
|
|
}
|
|
|
+
|
|
|
Map<String, Date> objId_indicatorIdAndComputeTIme = getObjId_IndicatorIdAndComputeTIme(projectDTO);
|
|
|
Map<String, CalculateMethodDTO> methodIdAndMethodDTO = energyAlarmService.queryCalculateMethods();
|
|
|
|
|
|
for (String objIdIndicatorId : objIdAndIndicatorId) {
|
|
|
- computeObjIndicatorData(projectDTO, objId_indicatorIdAndComputeTIme.get(objIdIndicatorId), methodIdAndMethodDTO, objIdIndicatorId);
|
|
|
+ Date lastComputeTime = objId_indicatorIdAndComputeTIme.get(objIdIndicatorId);
|
|
|
+ if (lastComputeTime == null) {
|
|
|
+ lastComputeTime = getDefultStartTime();
|
|
|
+ }
|
|
|
+ try {
|
|
|
+ computeObjIndicatorData(projectDTO,lastComputeTime ,methodIdAndMethodDTO, objIdIndicatorId);
|
|
|
+ }catch (Exception e){
|
|
|
+ IndicatorComputeLog save = new IndicatorComputeLog();
|
|
|
+ save.setLogInfo(e.getMessage());
|
|
|
+ save.setProject(projectDTO.getProjectId());
|
|
|
+ int indexOf = objIdIndicatorId.indexOf("_");
|
|
|
+ String objId = objIdIndicatorId.substring(0, indexOf);
|
|
|
+ String indicatorId = objIdIndicatorId.substring(indexOf + 1);
|
|
|
+ save.setCode(indicatorId);
|
|
|
+ save.setObjId(objId);
|
|
|
+ save.setLogType(EnumComputeLogType.ComputeType.getCode());
|
|
|
+ save.setDataTime(lastComputeTime);
|
|
|
+ save.setComputeRound(projectIndicatorCompute.getComputeRound());
|
|
|
+ save.setLogInfo(CommonUtils.getExceptionStackTrace(e));
|
|
|
+ save.setLogTime(new Date());
|
|
|
+ coredao.save(save);
|
|
|
+ }
|
|
|
}
|
|
|
// 更新缓存计算轮次
|
|
|
updateProjectComputeRound(projectDTO.getProjectId(), projectIndicatorCompute);
|
|
|
return null;
|
|
|
}
|
|
|
|
|
|
+
|
|
|
private void computeObjIndicatorData(ProjectDTO projectDTO, Date lastComputeTime, Map<String, CalculateMethodDTO> methodIdAndMethodDTO, String objIdIndicatorId) throws Exception {
|
|
|
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);
|
|
|
- return;
|
|
|
+// log.error("【监测指标数据计算线程】:项目监控指标未设置公式:" + projectDTO.getProjectId() + ";" + objId + ";" + indicatorId);
|
|
|
+ throw new Exception("【监测指标数据计算线程】:项目监控指标未设置公式:" + projectDTO.getProjectId() + ";" + objId + ";" + indicatorId);
|
|
|
}
|
|
|
CalculateMethodDTO calculateMethodDTO = methodIdAndMethodDTO.get(methodId);
|
|
|
if (calculateMethodDTO == null) {
|
|
|
- log.error("【监测指标数据计算线程】:项目监控指标设置公式为null:" + projectDTO.getProjectId() + ";" + objId + ";" + indicatorId);
|
|
|
- return;
|
|
|
- }
|
|
|
- if (lastComputeTime == null) {
|
|
|
- lastComputeTime = getDefultStartTime();
|
|
|
+ throw new Exception("【监测指标数据计算线程】:项目监控指标设置公式为null:" + projectDTO.getProjectId() + ";" + objId + ";" + indicatorId);
|
|
|
}
|
|
|
+
|
|
|
Date computeEndTime = DateUtils.addDays(lastComputeTime, computePropertiesConfig.getRoundDays());
|
|
|
String formula = calculateMethodDTO.getFormula();
|
|
|
if (StringUtils.isBlank(formula)) {
|
|
|
- log.error("【监测指标数据计算线程】:项目监控指标设置公式为null:" + projectDTO.getProjectId() + ";" + objId + ";" + indicatorId);
|
|
|
- return;
|
|
|
- }
|
|
|
- Date computeTime = computeIndicatorData(projectDTO, objId, lastComputeTime, computeEndTime, indicatorId, formula);
|
|
|
- if (computeTime == null) {
|
|
|
- return;
|
|
|
+ throw new Exception("【监测指标数据计算线程】:项目监控指标设置公式为null:" + projectDTO.getProjectId() + ";" + objId + ";" + indicatorId);
|
|
|
}
|
|
|
- saveOrUpdateComputeTime(projectDTO.getProjectId(), objId, indicatorId, computeTime);
|
|
|
+ computeIndicatorData(projectDTO, objId, lastComputeTime, computeEndTime, indicatorId, formula);
|
|
|
}
|
|
|
|
|
|
/**
|
|
@@ -251,7 +260,7 @@ public class MonitorIndicatorRecordServiceImpl implements IMonitorIndicatorRecor
|
|
|
* @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 {
|
|
|
+ private void 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());
|
|
@@ -259,20 +268,18 @@ public class MonitorIndicatorRecordServiceImpl implements IMonitorIndicatorRecor
|
|
|
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);
|
|
@@ -280,8 +287,9 @@ public class MonitorIndicatorRecordServiceImpl implements IMonitorIndicatorRecor
|
|
|
monitorIndicatorRecord.setProject(projectDTO.getProjectId());
|
|
|
monitorIndicatorRecord.setDataValue(targetData);
|
|
|
saveOrUpdateByPk(monitorIndicatorRecord);
|
|
|
+ saveOrUpdateComputeTime(projectDTO.getProjectId(), objId, infoCode, dataTime);
|
|
|
}
|
|
|
- return timeEnd;
|
|
|
+
|
|
|
}
|
|
|
|
|
|
private Date getDefultStartTime() throws Exception {
|
|
@@ -297,7 +305,6 @@ public class MonitorIndicatorRecordServiceImpl implements IMonitorIndicatorRecor
|
|
|
|
|
|
|
|
|
private void saveOrUpdateComputeTime(String projectId, String objId, String indicatorId, Date computeTime) {
|
|
|
-
|
|
|
CalculateTimeRecord update = new CalculateTimeRecord();
|
|
|
update.setMonitorIndicatorId(indicatorId);
|
|
|
update.setObjId(objId);
|
|
@@ -440,7 +447,6 @@ public class MonitorIndicatorRecordServiceImpl implements IMonitorIndicatorRecor
|
|
|
if (CollectionUtils.isEmpty(objIdAlarmItemCodeAndInfoCodes) || objIdAlarmItemCodeAndInfoCodes.size() == 0) {
|
|
|
return;
|
|
|
}
|
|
|
- // log.error("获取到的设备与监测点位映射关系:" + objIdAlarmItemCodeAndInfoCodes);
|
|
|
for (Map.Entry<String, List<String>> entry : objIdAlarmItemCodeAndInfoCodes.entrySet()) {
|
|
|
String objIdAndAlarmItemCode = entry.getKey();
|
|
|
int indexOf = objIdAndAlarmItemCode.indexOf("_");
|
|
@@ -448,7 +454,6 @@ public class MonitorIndicatorRecordServiceImpl implements IMonitorIndicatorRecor
|
|
|
String alarmItemCode = objIdAndAlarmItemCode.substring(indexOf + 1);
|
|
|
String lockKey = AlarmConstants.alarmDataLockPrefix + objId + "-" + alarmItemCode;
|
|
|
Object isLock = redisUtil.get(lockKey);
|
|
|
- // log.error("是否获取到锁:" + isLock);
|
|
|
if (null != isLock) {
|
|
|
continue;
|
|
|
}
|
|
@@ -481,7 +486,6 @@ public class MonitorIndicatorRecordServiceImpl implements IMonitorIndicatorRecor
|
|
|
if (sendTimeKeyAndDataList.size() == 0) {
|
|
|
continue;
|
|
|
}
|
|
|
-
|
|
|
JSONArray sendArray = CollectDataUtil.batchBuildSendJsonParam(sendTimeKeyAndDataList, alarmItemCode);
|
|
|
|
|
|
try {
|
|
@@ -492,11 +496,21 @@ public class MonitorIndicatorRecordServiceImpl implements IMonitorIndicatorRecor
|
|
|
updateRedisConfigItemSendTimeDTO(projectDTO.getProjectId(), objIdAndAlarmItemCode, configItemSendTimeDTO);
|
|
|
// 发数
|
|
|
rabbitConfig.sendMsg(sendArray);
|
|
|
+
|
|
|
+ IndicatorComputeLog save = new IndicatorComputeLog();
|
|
|
+ save.setProject(projectDTO.getProjectId());
|
|
|
+ save.setCode(alarmItemCode);
|
|
|
+ save.setObjId(objId);
|
|
|
+ save.setLogType(EnumComputeLogType.SendDataType.getCode());
|
|
|
+ save.setDataTime(endTime);
|
|
|
+ save.setLogInfo(sendArray.toJSONString());
|
|
|
+ save.setLogTime(new Date());
|
|
|
+ coredao.save(save);
|
|
|
} catch (Exception e) {
|
|
|
e.printStackTrace();
|
|
|
log.error("指标发送报表服务报错:" + projectDTO.getProjectId() + ";" + CommonUtils.getExceptionStackTrace(e));
|
|
|
}
|
|
|
- log.error("指标发送报表服务数据:" + projectDTO.getProjectId() + ";" + sendArray);
|
|
|
+// log.error("指标发送报表服务数据:" + projectDTO.getProjectId() + ";" + sendArray);
|
|
|
}
|
|
|
}
|
|
|
|
|
@@ -693,6 +707,7 @@ public class MonitorIndicatorRecordServiceImpl implements IMonitorIndicatorRecor
|
|
|
|
|
|
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) {
|
|
@@ -734,10 +749,9 @@ public class MonitorIndicatorRecordServiceImpl implements IMonitorIndicatorRecor
|
|
|
}
|
|
|
BigDecimal result = new ComputeFormulaUtil(calculateStr).getResult();
|
|
|
if (result == null) {
|
|
|
- log.error("【监测指标数据计算线程】:解析公式为空,projectId:" + computeCalculateDTO.getProjectId() + "对象id:"
|
|
|
+ throw new Exception("【监测指标数据计算线程】:解析公式为空,projectId:" + computeCalculateDTO.getProjectId() + "对象id:"
|
|
|
+ computeCalculateDTO.getObjId() + ";指标id:" + computeCalculateDTO.getTargetId()
|
|
|
+ ";带入公式:" + calculateStr);
|
|
|
- return null;
|
|
|
}
|
|
|
return result.doubleValue();
|
|
|
}
|
|
@@ -783,10 +797,9 @@ public class MonitorIndicatorRecordServiceImpl implements IMonitorIndicatorRecor
|
|
|
computeCalculateDTO.getProjectId(), calculateVariableDTO.getComputeObjType(),
|
|
|
computeCalculateDTO.getObjId(), null));
|
|
|
if (CollectionUtils.isEmpty(objList)) {
|
|
|
- log.error("【指标计算线程】:查询数据中台子对象为空,projectId:" + computeCalculateDTO.getProjectId() + ";objId:"
|
|
|
+ throw new Exception("【指标计算线程】:查询数据中台子对象为空,projectId:" + computeCalculateDTO.getProjectId() + ";objId:"
|
|
|
+ computeCalculateDTO.getObjId() + ";子对象类型:"
|
|
|
+ calculateVariableDTO.getComputeObjType());
|
|
|
- return null;
|
|
|
}
|
|
|
List<Double> list = new ArrayList<>();
|
|
|
for (JSONObject object : objList) {
|
|
@@ -840,13 +853,11 @@ public class MonitorIndicatorRecordServiceImpl implements IMonitorIndicatorRecor
|
|
|
List<Double> arrayList = new ArrayList<>();
|
|
|
List<JSONObject> objectList = centerDataService.queryObjListByObjId(projectId, Collections.singletonList(objId));
|
|
|
if (CollectionUtils.isEmpty(objectList)) {
|
|
|
- log.error("【指标数据计算线程】:查询数据中台对象不存在,:objId:" + objId + ";信息点:" + computeCode);
|
|
|
- arrayList.add(null);
|
|
|
- return arrayList;
|
|
|
+ throw new Exception("【指标数据计算线程】:查询数据中台对象不存在,:objId:" + objId + ";信息点:" + computeCode);
|
|
|
}
|
|
|
Double double1 = objectList.get(0).getDouble(computeCode);
|
|
|
if (double1 == null) {
|
|
|
- log.error("【指标数据计算线程】:查询数据中台对象静态数据为空,:objId:" + objId + ";信息点:" + computeCode);
|
|
|
+ throw new Exception("【指标数据计算线程】:查询数据中台对象静态数据为空,:objId:" + objId + ";信息点:" + computeCode);
|
|
|
}
|
|
|
arrayList.add(double1);
|
|
|
return arrayList;
|
|
@@ -862,7 +873,7 @@ public class MonitorIndicatorRecordServiceImpl implements IMonitorIndicatorRecor
|
|
|
result.add(dataList.get(0).getData());
|
|
|
}
|
|
|
if (CollectionUtils.isEmpty(result)) {
|
|
|
- log.error("【指标计算线程】:查询数据中台对象历史数据为空,projectId:" + projectId + ";objId:" + objId + ";信息点:" + computeCode
|
|
|
+ throw new Exception("【指标计算线程】:查询数据中台对象历史数据为空,projectId:" + projectId + ";objId:" + objId + ";信息点:" + computeCode
|
|
|
+ ";时间:" + DateUtils.date2Str(startTime, DateUtils.SDF_SECOND) + "_"
|
|
|
+ DateUtils.date2Str(startTime2, DateUtils.SDF_SECOND));
|
|
|
}
|