|
|
|
@ -1,5 +1,6 @@
|
|
|
|
|
package com.xydl.cac.controller;
|
|
|
|
|
|
|
|
|
|
import com.xydl.cac.comparator.Comparator;
|
|
|
|
|
import com.xydl.cac.comparator.FloatCompare;
|
|
|
|
|
import com.xydl.cac.comparator.IntCompare;
|
|
|
|
|
import com.xydl.cac.entity.WarnRule;
|
|
|
|
@ -49,13 +50,18 @@ public class WarnRuleController extends BasicController {
|
|
|
|
|
@GetMapping("listOperator")
|
|
|
|
|
@ApiOperation("查询比较符")
|
|
|
|
|
public Response<Map<String, String>> listOperator(String name) throws Exception {
|
|
|
|
|
Map<String, String> result = new HashMap<>();
|
|
|
|
|
Comparator comparator = this.getComparator(name);
|
|
|
|
|
return Response.success(comparator.supportedOperator());
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private Comparator getComparator(String name) throws BusinessException {
|
|
|
|
|
if (FloatCompare.equalsIgnoreCase(name)) {
|
|
|
|
|
result = floatCompare.supportedOperator();
|
|
|
|
|
return floatCompare;
|
|
|
|
|
} else if (IntCompare.equalsIgnoreCase(name)) {
|
|
|
|
|
result = intCompare.supportedOperator();
|
|
|
|
|
return intCompare;
|
|
|
|
|
} else {
|
|
|
|
|
throw new BusinessException("未找到该比较器");
|
|
|
|
|
}
|
|
|
|
|
return Response.success(result);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@GetMapping("listAll")
|
|
|
|
@ -68,6 +74,8 @@ public class WarnRuleController extends BasicController {
|
|
|
|
|
@PostMapping("add")
|
|
|
|
|
@ApiOperation("新增")
|
|
|
|
|
public Response<WarnRule> add(@Validated @RequestBody WarnRule item) throws Exception {
|
|
|
|
|
Comparator comparator = this.getComparator(item.getComparator());
|
|
|
|
|
comparator.valid(item.getOperator(), item.getThreshold());
|
|
|
|
|
WarnRule result = service.add(item);
|
|
|
|
|
return Response.success(result);
|
|
|
|
|
}
|
|
|
|
@ -78,6 +86,8 @@ public class WarnRuleController extends BasicController {
|
|
|
|
|
if (item.getId() == null) {
|
|
|
|
|
throw new BusinessException("ID不能为空!");
|
|
|
|
|
}
|
|
|
|
|
Comparator comparator = this.getComparator(item.getComparator());
|
|
|
|
|
comparator.valid(item.getOperator(), item.getThreshold());
|
|
|
|
|
service.update(item);
|
|
|
|
|
return Response.success("OK");
|
|
|
|
|
}
|
|
|
|
|