|
@@ -1,9 +1,14 @@
|
|
|
package cn.com.ctop.alarm.modules.controller;
|
|
|
|
|
|
import cn.com.ctop.alarm.modules.entity.RuleGroup;
|
|
|
+import cn.com.ctop.alarm.modules.service.IRuleAccountThresholdService;
|
|
|
+import cn.com.ctop.alarm.modules.service.IRuleBaseService;
|
|
|
import cn.com.ctop.alarm.modules.service.IRuleGroupService;
|
|
|
import cn.com.ctop.common.module.annotation.AutoLog;
|
|
|
+import cn.com.ctop.common.module.utils.Check;
|
|
|
import com.alibaba.fastjson.JSON;
|
|
|
+import com.alibaba.fastjson.JSONArray;
|
|
|
+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;
|
|
@@ -19,15 +24,7 @@ import org.jeecgframework.poi.excel.entity.ExportParams;
|
|
|
import org.jeecgframework.poi.excel.entity.ImportParams;
|
|
|
import org.jeecgframework.poi.excel.view.JeecgEntityExcelView;
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
|
-import org.springframework.web.bind.annotation.DeleteMapping;
|
|
|
-import org.springframework.web.bind.annotation.GetMapping;
|
|
|
-import org.springframework.web.bind.annotation.PostMapping;
|
|
|
-import org.springframework.web.bind.annotation.PutMapping;
|
|
|
-import org.springframework.web.bind.annotation.RequestBody;
|
|
|
-import org.springframework.web.bind.annotation.RequestMapping;
|
|
|
-import org.springframework.web.bind.annotation.RequestMethod;
|
|
|
-import org.springframework.web.bind.annotation.RequestParam;
|
|
|
-import org.springframework.web.bind.annotation.RestController;
|
|
|
+import org.springframework.web.bind.annotation.*;
|
|
|
import org.springframework.web.multipart.MultipartFile;
|
|
|
import org.springframework.web.multipart.MultipartHttpServletRequest;
|
|
|
import org.springframework.web.servlet.ModelAndView;
|
|
@@ -38,6 +35,7 @@ import java.io.IOException;
|
|
|
import java.io.UnsupportedEncodingException;
|
|
|
import java.net.URLDecoder;
|
|
|
import java.util.Arrays;
|
|
|
+import java.util.HashMap;
|
|
|
import java.util.List;
|
|
|
import java.util.Map;
|
|
|
|
|
@@ -55,6 +53,38 @@ import java.util.Map;
|
|
|
public class RuleGroupController {
|
|
|
@Autowired
|
|
|
private IRuleGroupService ruleGroupService;
|
|
|
+ @Autowired
|
|
|
+ private IRuleBaseService ruleBaseService;
|
|
|
+ @Autowired
|
|
|
+ private IRuleAccountThresholdService ruleAccountThresholdService;
|
|
|
+
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 创建规则组
|
|
|
+ *
|
|
|
+ * @param requestJson
|
|
|
+ * @return
|
|
|
+ */
|
|
|
+
|
|
|
+ @PostMapping(value = "/createRuleGroup")
|
|
|
+ public Result createRuleGroup(@RequestBody JSONObject requestJson) {
|
|
|
+ Result result = new Result<>();
|
|
|
+ try {
|
|
|
+ if (Check.isNull(requestJson)) {
|
|
|
+ throw new Exception("请输出需要创建的参数");
|
|
|
+ }
|
|
|
+
|
|
|
+ JSONObject returnJson = ruleGroupService.createRuleGroup(requestJson);
|
|
|
+
|
|
|
+
|
|
|
+ result.success("添加成功!");
|
|
|
+ } catch (Exception e) {
|
|
|
+ log.error(e.getMessage(), e);
|
|
|
+ result.error500("操作失败");
|
|
|
+ }
|
|
|
+ return result;
|
|
|
+ }
|
|
|
+
|
|
|
|
|
|
/**
|
|
|
* 分页列表查询
|
|
@@ -132,12 +162,25 @@ public class RuleGroupController {
|
|
|
* @param id
|
|
|
* @return
|
|
|
*/
|
|
|
+
|
|
|
+
|
|
|
@AutoLog(value = "规则组-通过id删除")
|
|
|
@ApiOperation(value = "规则组-通过id删除", notes = "规则组-通过id删除")
|
|
|
@DeleteMapping(value = "/delete")
|
|
|
public Result<?> delete(@RequestParam(name = "id", required = true) String id) {
|
|
|
try {
|
|
|
- ruleGroupService.removeById(id);
|
|
|
+ RuleGroup ruleGroup = ruleGroupService.getById(id);
|
|
|
+ if (!Check.isNull(ruleGroup)) {
|
|
|
+ JSONArray ruleIds = JSONArray.parseArray(ruleGroup.getRuleIds());
|
|
|
+ for (int i = 0; i < ruleIds.size(); i++) {
|
|
|
+ Long ruleId = ruleIds.getLong(i);
|
|
|
+ ruleBaseService.removeById(ruleId);
|
|
|
+ Map<String, Object> deleteMap = new HashMap<>();
|
|
|
+ deleteMap.put("rule_id", ruleId);
|
|
|
+ ruleAccountThresholdService.removeByMap(deleteMap);
|
|
|
+ }
|
|
|
+ ruleGroupService.removeById(id);
|
|
|
+ }
|
|
|
} catch (Exception e) {
|
|
|
log.error("删除失败", e.getMessage());
|
|
|
return Result.error("删除失败!");
|