|
@@ -65,14 +65,15 @@ public class AlarmConditionServiceImpl extends ServiceImpl<AlarmConditionMapper,
|
|
|
|
|
|
// 设置默认值
|
|
|
setDefaultValue(alarmCondition);
|
|
|
- save(alarmCondition);
|
|
|
+ saveCondition(alarmCondition);
|
|
|
stringMap.put("id", alarmCondition.getId());
|
|
|
return stringMap;
|
|
|
}
|
|
|
|
|
|
@Override
|
|
|
- public void saveCondition(AlarmCondition alarmCondition){
|
|
|
+ public void saveCondition(AlarmCondition alarmCondition) {
|
|
|
save(alarmCondition);
|
|
|
+ // 发送创建报警条件消息至mq // TODO: 2021/10/25
|
|
|
}
|
|
|
|
|
|
/**
|
|
@@ -83,7 +84,7 @@ public class AlarmConditionServiceImpl extends ServiceImpl<AlarmConditionMapper,
|
|
|
* @version V1.0 2021-09-08 22:30:38
|
|
|
*/
|
|
|
@Override
|
|
|
- public Map<String, Object> swtichAlarmCondition(AddAlarmConditionDTO addAlarmConditionDTO) {
|
|
|
+ public Map<String, Object> switchAlarmCondition(AddAlarmConditionDTO addAlarmConditionDTO) {
|
|
|
AlarmCondition alarmCondition = ConvertAlarmConditionTool.INSTANCE.convertAddDto2Entity(addAlarmConditionDTO);
|
|
|
List<List<CalculateMethodDTO>> frontend = addAlarmConditionDTO.getTriggerFrontend();
|
|
|
alarmCondition.setTriggerFrontend(frontend);
|
|
@@ -93,13 +94,76 @@ public class AlarmConditionServiceImpl extends ServiceImpl<AlarmConditionMapper,
|
|
|
alarmCondition.setInfoCodes((List<String>) stringMap.get("infoCode"));
|
|
|
// 设置默认值
|
|
|
setDefaultValue(alarmCondition);
|
|
|
- stringMap.put("alarmCondition",alarmCondition);
|
|
|
+ stringMap.put("alarmCondition", alarmCondition);
|
|
|
stringMap.put("id", alarmCondition.getId());
|
|
|
return stringMap;
|
|
|
}
|
|
|
|
|
|
@Override
|
|
|
public Map<String, Object> frontend2Backend(List<List<CalculateMethodDTO>> frontend) {
|
|
|
+ // TODO: 2021/10/21 后端条件示例
|
|
|
+ //
|
|
|
+ /* frontend示例 规则1: 新风焓值 ≥ 1;运行状态 = 停止 规则2: 新风焓值 ≥ 新风焓值 + 1
|
|
|
+ [
|
|
|
+ [
|
|
|
+ {
|
|
|
+ "formula": [
|
|
|
+ {
|
|
|
+ "label": "1",
|
|
|
+ "key": "enter3"
|
|
|
+ }
|
|
|
+ ],
|
|
|
+ "tempFormula": "1",
|
|
|
+ "monitorIndicatorName": "新风焓值",
|
|
|
+ "monitorIndicatorId": "ACATAH_FreshAirH",
|
|
|
+ "operator": "≥"
|
|
|
+ },
|
|
|
+ {
|
|
|
+ "formula": [
|
|
|
+ {
|
|
|
+ "label": "停止",
|
|
|
+ "value": "0",
|
|
|
+ "key": "dic"
|
|
|
+ }
|
|
|
+ ],
|
|
|
+ "tempFormula": "0",
|
|
|
+ "monitorIndicatorName": "运行状态",
|
|
|
+ "monitorIndicatorId": "ACATAH_RunStatus",
|
|
|
+ "operator": "="
|
|
|
+ }
|
|
|
+ ],
|
|
|
+ [
|
|
|
+ {
|
|
|
+ "formula": [
|
|
|
+ {
|
|
|
+ "label": "新风焓值",
|
|
|
+ "value": "ACATAH_FreshAirH",
|
|
|
+ "key": "6"
|
|
|
+ },
|
|
|
+ {
|
|
|
+ "key": "8",
|
|
|
+ "label": "+"
|
|
|
+ },
|
|
|
+ {
|
|
|
+ "key": "enter9",
|
|
|
+ "label": "1",
|
|
|
+ "error": true
|
|
|
+ }
|
|
|
+ ],
|
|
|
+ "tempFormula": "ACATAH_FreshAirH",
|
|
|
+ "monitorIndicatorName": "新风焓值",
|
|
|
+ "monitorIndicatorId": "ACATAH_FreshAirH",
|
|
|
+ "operator": "≥",
|
|
|
+ "dictionaries": [],
|
|
|
+ "error": {
|
|
|
+ "monitorIndicatorId": false,
|
|
|
+ "operator": false,
|
|
|
+ "formula": ""
|
|
|
+ }
|
|
|
+ }
|
|
|
+ ]
|
|
|
+ ]
|
|
|
+ */
|
|
|
StringBuffer allNotNull = new StringBuffer();
|
|
|
StringBuffer allNull = new StringBuffer();
|
|
|
Set<String> infoCodesSet = new HashSet<>();
|
|
@@ -108,6 +172,8 @@ public class AlarmConditionServiceImpl extends ServiceImpl<AlarmConditionMapper,
|
|
|
StringBuffer notNullString = new StringBuffer();
|
|
|
StringBuffer nullString = new StringBuffer();
|
|
|
StringBuffer calculateString = new StringBuffer();
|
|
|
+ // 一条规则中包含的公式(中文)
|
|
|
+ List<String> ruleDisplayFormulaList = new ArrayList<>();
|
|
|
for (CalculateMethodDTO calculateMethodDTO : calculateMethodDtoList) {
|
|
|
infoCodesSet.add(calculateMethodDTO.getMonitorIndicatorId());
|
|
|
List<Formula> formulas = calculateMethodDTO.getFormula();
|
|
@@ -115,17 +181,24 @@ public class AlarmConditionServiceImpl extends ServiceImpl<AlarmConditionMapper,
|
|
|
StringBuffer displayFormula = new StringBuffer();
|
|
|
displayFormula.append(calculateMethodDTO.getMonitorIndicatorName()).append(calculateMethodDTO.getOperator());
|
|
|
for (Formula formula : formulas) {
|
|
|
+ displayFormula.append(formula.getLabel());
|
|
|
+ if ("dic".equals(formula.getKey())) {
|
|
|
+ // 如果formula是字典选项
|
|
|
+ tempFormula.append(formula.getValue());
|
|
|
+ continue;
|
|
|
+ }
|
|
|
if (StringUtils.isNotBlank(formula.getValue())) {
|
|
|
+ // 如果formula不是字典选项,且value值不为空,代表formula是个监测指标
|
|
|
nullString.append(formula.getValue()).append("==NaN").append(" || ");
|
|
|
notNullString.append(formula.getValue()).append("!=NaN").append(" && ");
|
|
|
tempFormula.append(formula.getValue());
|
|
|
infoCodesSet.add(formula.getValue());
|
|
|
} else {
|
|
|
+ // formula为数字或操作符
|
|
|
tempFormula.append(replace(formula.getLabel()));
|
|
|
}
|
|
|
- displayFormula.append(formula.getLabel());
|
|
|
}
|
|
|
- displayFormulaList.add(displayFormula.toString());
|
|
|
+ ruleDisplayFormulaList.add(displayFormula.toString());
|
|
|
calculateMethodDTO.setTempFormula(tempFormula.toString());
|
|
|
nullString.append(calculateMethodDTO.getMonitorIndicatorId()).append("==NaN").append(" || ");
|
|
|
notNullString.append(calculateMethodDTO.getMonitorIndicatorId()).append("!=NaN").append(" && ");
|
|
@@ -135,21 +208,21 @@ public class AlarmConditionServiceImpl extends ServiceImpl<AlarmConditionMapper,
|
|
|
.append(calculateMethodDTO.getTempFormula()).append(")")
|
|
|
.append(" && ");
|
|
|
}
|
|
|
+ displayFormulaList.add(String.join(",", ruleDisplayFormulaList));
|
|
|
notNullString.delete(notNullString.length() - 4, notNullString.length()).append(")");
|
|
|
allNotNull.append("(").append(notNullString).append(" || ");
|
|
|
- allNull.append("(").append("(").append(nullString.substring(0, nullString.length() - 4)).append(")").append("?true:").append("(").append(calculateString.substring(0, calculateString.length() - 4)).append(")").append(")").append(" || ");
|
|
|
+ allNull.append("(").append("(").append(nullString.substring(0, nullString.length() - 4)).append(")")
|
|
|
+ .append("?false:").append("(").append(calculateString.substring(0, calculateString.length() - 4)).append(")").append(")").append(" || ");
|
|
|
|
|
|
}
|
|
|
StringBuffer substring = new StringBuffer();
|
|
|
- substring.append("(").append(allNotNull.substring(0, allNotNull.length() - 4)).append(")").append(" && ").append("(").append(allNull.substring(0, allNull.length() - 4)).append(")").toString();
|
|
|
- Map<String, Object> map = new HashMap();
|
|
|
- List<String> infoCodesList = new ArrayList<>();
|
|
|
- infoCodesList.addAll(infoCodesSet);
|
|
|
- List<String> displayFormula = new ArrayList();
|
|
|
- displayFormula.addAll(displayFormulaList);
|
|
|
+ substring.append("(").append(allNotNull.substring(0, allNotNull.length() - 4)).append(")")
|
|
|
+ .append(" && ").append("(").append(allNull.substring(0, allNull.length() - 4)).append(")");
|
|
|
+ Map<String, Object> map = new HashMap<>();
|
|
|
+ List<String> infoCodesList = new ArrayList<>(infoCodesSet);
|
|
|
+ List<String> displayFormula = new ArrayList<>(displayFormulaList);
|
|
|
map.put("infoCode", infoCodesList);
|
|
|
map.put("backend", substring.toString());
|
|
|
- map.put("end", "!" + substring);
|
|
|
map.put("displayFormula", displayFormula);
|
|
|
return map;
|
|
|
}
|
|
@@ -162,15 +235,22 @@ public class AlarmConditionServiceImpl extends ServiceImpl<AlarmConditionMapper,
|
|
|
}
|
|
|
|
|
|
@Override
|
|
|
- public void updateById(Map<String, Object> conditionMap, UpdateAlarmConditionDTO condition) {
|
|
|
+ public void updateAlarmCondition(Map<String, Object> conditionMap, UpdateAlarmConditionDTO condition) {
|
|
|
AlarmCondition alarmCondition = new AlarmCondition();
|
|
|
+ alarmCondition.setInfoCodes((List<String>) conditionMap.get("infoCode"));
|
|
|
alarmCondition.setTriggerFrontend(condition.getFrontend());
|
|
|
- alarmCondition.setAlarmLevel(condition.getAlarmLevel());
|
|
|
alarmCondition.setTriggerBackend((String) conditionMap.get("backend"));
|
|
|
- alarmCondition.setInfoCodes((List<String>) conditionMap.get("infoCode"));
|
|
|
alarmCondition.setTriggerUphold(condition.getTriggerUphold());
|
|
|
+ alarmCondition.setAlarmLevel(condition.getAlarmLevel());
|
|
|
+ alarmCondition.setTriggerRules((List<String>) conditionMap.get("displayFormula"));
|
|
|
+ alarmCondition.setEndBackend("!(" + conditionMap.get("backend") + ")");
|
|
|
alarmCondition.setId(condition.getId());
|
|
|
+ updateAndSendMsg2MQ(alarmCondition);
|
|
|
+ }
|
|
|
+
|
|
|
+ private void updateAndSendMsg2MQ(AlarmCondition alarmCondition) {
|
|
|
updateById(alarmCondition);
|
|
|
+ // 发送消息至MQ // TODO: 2021/10/25
|
|
|
}
|
|
|
|
|
|
/**
|
|
@@ -194,11 +274,12 @@ public class AlarmConditionServiceImpl extends ServiceImpl<AlarmConditionMapper,
|
|
|
*/
|
|
|
@Override
|
|
|
public AlarmCondition queryAlarmConditionDetail(String id) {
|
|
|
- AlarmCondition alarmCondition = getById(id);
|
|
|
- if (alarmCondition == null) {
|
|
|
- throw new IllegalArgumentException("查看AlarmCondition详情时发生异常,找不到要查看的记录,id=" + id);
|
|
|
- }
|
|
|
- return alarmCondition;
|
|
|
+// AlarmCondition alarmCondition = getById(id);
|
|
|
+// if (alarmCondition == null) {
|
|
|
+// throw new IllegalArgumentException("查看AlarmCondition详情时发生异常,找不到要查看的记录,id=" + id);
|
|
|
+// }
|
|
|
+// return alarmCondition;
|
|
|
+ return getById(id);
|
|
|
}
|
|
|
|
|
|
/**
|
|
@@ -220,7 +301,7 @@ public class AlarmConditionServiceImpl extends ServiceImpl<AlarmConditionMapper,
|
|
|
alarmCondition.setTriggerBackend((String) stringMap.get("backend"));
|
|
|
alarmCondition.setInfoCodes((List<String>) stringMap.get("infoCode"));
|
|
|
}
|
|
|
- updateById(alarmCondition);
|
|
|
+ updateAndSendMsg2MQ(alarmCondition);
|
|
|
}
|
|
|
|
|
|
/**
|
|
@@ -396,9 +477,9 @@ public class AlarmConditionServiceImpl extends ServiceImpl<AlarmConditionMapper,
|
|
|
* @return
|
|
|
*/
|
|
|
public CommonResult validate(String expression, String variable) {
|
|
|
-// if (variables == null || variables.isEmpty()) {
|
|
|
-// return ResultHelper.failure(ResponseCode.C0134.getCode(), "内置变量为空");
|
|
|
-// }
|
|
|
+ // if (variables == null || variables.isEmpty()) {
|
|
|
+ // return ResultHelper.failure(ResponseCode.C0134.getCode(), "内置变量为空");
|
|
|
+ // }
|
|
|
// 去空格
|
|
|
expression = expression.replaceAll(" ", "");
|
|
|
// 连续运算符处理
|
|
@@ -408,9 +489,9 @@ public class AlarmConditionServiceImpl extends ServiceImpl<AlarmConditionMapper,
|
|
|
if (org.apache.commons.lang3.StringUtils.contains(expression, "()")) {
|
|
|
return ResultHelper.failure(ResponseCode.C0134.getCode(), "公式不合法");
|
|
|
}
|
|
|
-// expression = expression.replaceAll("\\)\\(", "\\)*\\(");
|
|
|
-// expression = expression.replaceAll("\\(\\-", "\\(0-");
|
|
|
-// expression = expression.replaceAll("\\(\\+", "\\(0+");
|
|
|
+ // expression = expression.replaceAll("\\)\\(", "\\)*\\(");
|
|
|
+ // expression = expression.replaceAll("\\(\\-", "\\(0-");
|
|
|
+ // expression = expression.replaceAll("\\(\\+", "\\(0+");
|
|
|
// 校验变量
|
|
|
String[] splits = expression.split("\\+|\\-|\\*|\\/|\\(|\\)");
|
|
|
for (String split : splits) {
|
|
@@ -465,4 +546,9 @@ public class AlarmConditionServiceImpl extends ServiceImpl<AlarmConditionMapper,
|
|
|
}
|
|
|
return ResultHelper.success();
|
|
|
}
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public List<AlarmCondition> queryAllAlarmConditions() {
|
|
|
+ return queryAlarmConditionList(new QueryAlarmConditionDTO());
|
|
|
+ }
|
|
|
}
|