|
@@ -6,15 +6,16 @@ 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.alarmservice.group.calculatemethod.model.CalculateMethod;
|
|
|
import com.persagy.apm.alarmservice.group.calculatemethod.model.dto.CalculateMethodDTO;
|
|
|
+import com.persagy.apm.alarmservice.group.calculatemethod.service.ICalculateMethodService;
|
|
|
+import com.persagy.apm.alarmservice.group.monitorindicator.model.MonitorIndicator;
|
|
|
+import com.persagy.apm.alarmservice.group.monitorindicator.service.IMonitorIndicatorService;
|
|
|
import com.persagy.apm.alarmservice.project.alarmcondition.dao.AlarmConditionMapper;
|
|
|
import com.persagy.apm.alarmservice.project.alarmcondition.model.AlarmCondition;
|
|
|
import com.persagy.apm.alarmservice.project.alarmcondition.model.ConvertAlarmConditionTool;
|
|
|
import com.persagy.apm.alarmservice.project.alarmcondition.model.Formula;
|
|
|
-import com.persagy.apm.alarmservice.project.alarmcondition.model.dto.AddAlarmConditionDTO;
|
|
|
-import com.persagy.apm.alarmservice.project.alarmcondition.model.dto.PageQueryAlarmConditionDTO;
|
|
|
-import com.persagy.apm.alarmservice.project.alarmcondition.model.dto.QueryAlarmConditionDTO;
|
|
|
-import com.persagy.apm.alarmservice.project.alarmcondition.model.dto.UpdateAlarmConditionDTO;
|
|
|
+import com.persagy.apm.alarmservice.project.alarmcondition.model.dto.*;
|
|
|
import com.persagy.apm.alarmservice.project.alarmcondition.service.IAlarmConditionService;
|
|
|
import com.persagy.apm.common.constant.enums.ValidEnum;
|
|
|
import com.persagy.apm.common.context.poems.PoemsContext;
|
|
@@ -23,6 +24,7 @@ import com.persagy.apm.common.response.CommonResult;
|
|
|
import com.persagy.apm.common.utils.ResultHelper;
|
|
|
import com.persagy.common.enums.ResponseCode;
|
|
|
import org.apache.commons.lang.StringUtils;
|
|
|
+import org.springframework.beans.factory.annotation.Autowired;
|
|
|
import org.springframework.stereotype.Service;
|
|
|
import org.springframework.util.CollectionUtils;
|
|
|
|
|
@@ -39,6 +41,9 @@ import java.util.regex.Pattern;
|
|
|
public class AlarmConditionServiceImpl extends ServiceImpl<AlarmConditionMapper, AlarmCondition>
|
|
|
implements IAlarmConditionService {
|
|
|
|
|
|
+ @Autowired
|
|
|
+ private IMonitorIndicatorService monitorIndicatorService;
|
|
|
+
|
|
|
/**
|
|
|
* 创建报警条件
|
|
|
*
|
|
@@ -50,7 +55,6 @@ public class AlarmConditionServiceImpl extends ServiceImpl<AlarmConditionMapper,
|
|
|
public Map<String, Object> createAlarmCondition(AddAlarmConditionDTO addAlarmConditionDTO) {
|
|
|
AlarmCondition alarmCondition = ConvertAlarmConditionTool.INSTANCE.convertAddDto2Entity(addAlarmConditionDTO);
|
|
|
List<List<CalculateMethodDTO>> frontend = addAlarmConditionDTO.getFrontend();
|
|
|
- Object json = JSON.toJSON(frontend);
|
|
|
alarmCondition.setFrontend(frontend);
|
|
|
//将前端公式转换成后台公式
|
|
|
Map<String, Object> stringMap = frontend2Backend(frontend);
|
|
@@ -59,7 +63,7 @@ public class AlarmConditionServiceImpl extends ServiceImpl<AlarmConditionMapper,
|
|
|
// 设置默认值
|
|
|
setDefaultValue(alarmCondition);
|
|
|
save(alarmCondition);
|
|
|
- stringMap.put("id",alarmCondition.getId());
|
|
|
+ stringMap.put("id", alarmCondition.getId());
|
|
|
return stringMap;
|
|
|
}
|
|
|
|
|
@@ -79,12 +83,12 @@ public class AlarmConditionServiceImpl extends ServiceImpl<AlarmConditionMapper,
|
|
|
StringBuffer displayFormula = new StringBuffer();
|
|
|
displayFormula.append(calculateMethodDTO.getMonitorIndicatorName()).append(calculateMethodDTO.getOperator());
|
|
|
for (Formula formula : formulas) {
|
|
|
- if(formula.getValue()!=null){
|
|
|
+ if (formula.getValue() != null) {
|
|
|
nullString.append(formula.getValue()).append("==NaN").append(" || ");
|
|
|
notNullString.append(formula.getValue()).append("!=NaN").append(" && ");
|
|
|
tempFormula.append(formula.getValue());
|
|
|
infoCodesSet.add(formula.getValue());
|
|
|
- }else{
|
|
|
+ } else {
|
|
|
tempFormula.append(formula.getLabel());
|
|
|
}
|
|
|
displayFormula.append(formula.getLabel());
|
|
@@ -110,9 +114,9 @@ public class AlarmConditionServiceImpl extends ServiceImpl<AlarmConditionMapper,
|
|
|
Map<String, Object> map = new HashMap();
|
|
|
List<String> infoCodesList = new ArrayList<>();
|
|
|
infoCodesList.addAll(infoCodesSet);
|
|
|
- map.put("infoCode",infoCodesList);
|
|
|
- map.put("backend",substring.toString());
|
|
|
- map.put("displayFormula",displayFormulaList);
|
|
|
+ map.put("infoCode", infoCodesList);
|
|
|
+ map.put("backend", substring.toString());
|
|
|
+ map.put("displayFormula", displayFormulaList);
|
|
|
return map;
|
|
|
}
|
|
|
|
|
@@ -297,20 +301,28 @@ public class AlarmConditionServiceImpl extends ServiceImpl<AlarmConditionMapper,
|
|
|
}
|
|
|
|
|
|
@Override
|
|
|
- public CommonResult<Boolean> validate(List<Formula> formulas) {
|
|
|
+ public CommonResult<Boolean> validate(ValidateAlarmConditionDTO validateAlarmConditionDTO) {
|
|
|
+ MonitorIndicator monitorIndicator = monitorIndicatorService.queryMonitorIndicatorDetail(validateAlarmConditionDTO.getFrontend().getMonitorIndicatorId());
|
|
|
+ List<Formula> formulas = validateAlarmConditionDTO.getFrontend().getFormula();
|
|
|
StringBuffer displayFormula = new StringBuffer();
|
|
|
- Set<String> infoCodesList = new HashSet<>();
|
|
|
+ String infoCodes = "";
|
|
|
for (Formula formula : formulas) {
|
|
|
if (formula.getValue() != null) {
|
|
|
String value = formula.getValue();
|
|
|
- infoCodesList.add(value);
|
|
|
+ infoCodes = value;
|
|
|
displayFormula.append(value);
|
|
|
- }else {
|
|
|
+ } else {
|
|
|
displayFormula.append(formula.getLabel());
|
|
|
}
|
|
|
}
|
|
|
- List<String> infoCodes = new ArrayList<>();
|
|
|
- infoCodes.addAll(infoCodesList);
|
|
|
+ MonitorIndicator indicator = monitorIndicatorService.queryMonitorIndicatorDetail(infoCodes);
|
|
|
+ String monitorUnit = monitorIndicator.getUnit();
|
|
|
+ String unit = indicator.getUnit();
|
|
|
+ if (monitorUnit != null && unit != null && !monitorUnit.equals(unit)) {
|
|
|
+ return ResultHelper.failure(ResponseCode.C0134.getCode(), "选择的指标与单位指标不一致");
|
|
|
+ } else if (monitorUnit == null || unit == null) {
|
|
|
+ return ResultHelper.failure(ResponseCode.C0134.getCode(), "公式错误");
|
|
|
+ }
|
|
|
return this.validate(displayFormula.toString(), infoCodes);
|
|
|
}
|
|
|
|
|
@@ -318,10 +330,10 @@ public class AlarmConditionServiceImpl extends ServiceImpl<AlarmConditionMapper,
|
|
|
* 使用正则来校验数学公式
|
|
|
*
|
|
|
* @param expression 数学公式,包含变量
|
|
|
- * @param variables 内置变量集合
|
|
|
+ * @param
|
|
|
* @return
|
|
|
*/
|
|
|
- public static CommonResult validate(String expression, List<String> variables) {
|
|
|
+ public static CommonResult validate(String expression, String variable) {
|
|
|
// if (variables == null || variables.isEmpty()) {
|
|
|
// return ResultHelper.failure(ResponseCode.C0134.getCode(), "内置变量为空");
|
|
|
// }
|
|
@@ -329,10 +341,10 @@ public class AlarmConditionServiceImpl extends ServiceImpl<AlarmConditionMapper,
|
|
|
expression = expression.replaceAll(" ", "");
|
|
|
// 连续运算符处理
|
|
|
if (expression.split("[\\+\\-\\*\\/]{2,}").length > 1) {
|
|
|
- return ResultHelper.failure(ResponseCode.C0134.getCode(), "公式不合法,包含连续运算符");
|
|
|
+ return ResultHelper.failure(ResponseCode.C0134.getCode(), expression + "公式不合法,包含连续运算符");
|
|
|
}
|
|
|
if (org.apache.commons.lang3.StringUtils.contains(expression, "()")) {
|
|
|
- return ResultHelper.failure(ResponseCode.C0134.getCode(), "公式不合法,包含空括号");
|
|
|
+ return ResultHelper.failure(ResponseCode.C0134.getCode(), expression + "公式不合法,包含空括号");
|
|
|
}
|
|
|
// expression = expression.replaceAll("\\)\\(", "\\)*\\(");
|
|
|
// expression = expression.replaceAll("\\(\\-", "\\(0-");
|
|
@@ -343,8 +355,8 @@ public class AlarmConditionServiceImpl extends ServiceImpl<AlarmConditionMapper,
|
|
|
if (org.apache.commons.lang3.StringUtils.isBlank(split) || Pattern.matches("[0-9]+", split)) {
|
|
|
continue;
|
|
|
}
|
|
|
- if (!variables.contains(split)) {
|
|
|
- return ResultHelper.failure(ResponseCode.C0134.getCode(), "公式不合法,包含非法变量或字符");
|
|
|
+ if (!variable.equals(split)) {
|
|
|
+ return ResultHelper.failure(ResponseCode.C0134.getCode(), expression + "公式不合法,包含非法变量或字符");
|
|
|
}
|
|
|
}
|
|
|
// 校验括号
|
|
@@ -355,7 +367,7 @@ public class AlarmConditionServiceImpl extends ServiceImpl<AlarmConditionMapper,
|
|
|
char currChar = expression.charAt(i);
|
|
|
if (i == 0) {
|
|
|
if (Pattern.matches("\\*|\\/", String.valueOf(currChar))) {
|
|
|
- return ResultHelper.failure(ResponseCode.C0134.getCode(), "公式不合法,以错误运算符开头");
|
|
|
+ return ResultHelper.failure(ResponseCode.C0134.getCode(), expression + "公式不合法,以错误运算符开头");
|
|
|
}
|
|
|
if (currChar == '+') {
|
|
|
resultExpression = expression.substring(1);
|
|
@@ -370,24 +382,24 @@ public class AlarmConditionServiceImpl extends ServiceImpl<AlarmConditionMapper,
|
|
|
if (stack.size() > 0) {
|
|
|
stack.pop();
|
|
|
} else {
|
|
|
- return ResultHelper.failure(ResponseCode.C0134.getCode(), "公式不合法,括号不配对");
|
|
|
+ return ResultHelper.failure(ResponseCode.C0134.getCode(), expression + "公式不合法,括号不配对");
|
|
|
}
|
|
|
}
|
|
|
if (preChar != null && preChar == '(' && Pattern.matches("[\\+\\-\\*\\/]+", String.valueOf(currChar))) {
|
|
|
- return ResultHelper.failure(ResponseCode.C0134.getCode(), "公式不合法,左括号后是运算符");
|
|
|
+ return ResultHelper.failure(ResponseCode.C0134.getCode(), expression + "公式不合法,左括号后是运算符");
|
|
|
}
|
|
|
if (preChar != null && preChar == ')' && !Pattern.matches("[\\+\\-\\*\\/]+", String.valueOf(currChar))) {
|
|
|
- return ResultHelper.failure(ResponseCode.C0134.getCode(), "公式不合法,右括号后面不是运算符");
|
|
|
+ return ResultHelper.failure(ResponseCode.C0134.getCode(), expression + "公式不合法,右括号后面不是运算符");
|
|
|
}
|
|
|
if (i == expression.length() - 1) {
|
|
|
if (Pattern.matches("\\+|\\-|\\*|\\/", String.valueOf(currChar))) {
|
|
|
- return ResultHelper.failure(ResponseCode.C0134.getCode(), "公式不合法,以运算符结尾");
|
|
|
+ return ResultHelper.failure(ResponseCode.C0134.getCode(), expression + "公式不合法,以运算符结尾");
|
|
|
}
|
|
|
}
|
|
|
preChar = currChar;
|
|
|
}
|
|
|
if (stack.size() > 0) {
|
|
|
- return ResultHelper.failure(ResponseCode.C0134.getCode(), "公式不合法,括号不配对");
|
|
|
+ return ResultHelper.failure(ResponseCode.C0134.getCode(), expression + "公式不合法,括号不配对");
|
|
|
}
|
|
|
return ResultHelper.success();
|
|
|
}
|