yumeng 4 éve
szülő
commit
9ef561a0b0

+ 17 - 9
module-alarm/src/main/java/cn/com/ctop/alarm/modules/controller/RuleAccountTemplateController.java

@@ -4,6 +4,7 @@ import cn.com.ctop.alarm.modules.entity.RuleAccountTemplate;
 import cn.com.ctop.alarm.modules.service.IRuleAccountTemplateService;
 import cn.com.ctop.common.module.annotation.AutoLog;
 import com.alibaba.fastjson.JSON;
+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 +20,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;
@@ -81,6 +74,21 @@ public class RuleAccountTemplateController {
         return result;
     }
 
+
+    @GetMapping(value = "/getRelationAccountById")
+    public Result<JSONObject> getRelationAccountById(Long id) {
+        Result<JSONObject> result = new Result<>();
+        JSONObject returnJson = new JSONObject();
+        QueryWrapper<RuleAccountTemplate> accountTemplateQueryWrapper = new QueryWrapper<>();
+        accountTemplateQueryWrapper.eq("template_id", id);
+        List<RuleAccountTemplate> list = ruleAccountTemplateService.list(accountTemplateQueryWrapper);
+        returnJson.put("relationCount", list.size());
+        result.setSuccess(true);
+        result.setResult(returnJson);
+        return result;
+    }
+
+
     /**
      * 添加
      *

+ 10 - 9
module-alarm/src/main/java/cn/com/ctop/alarm/modules/controller/RuleBaseController.java

@@ -1,6 +1,7 @@
 package cn.com.ctop.alarm.modules.controller;
 
 import cn.com.ctop.alarm.modules.entity.RuleBase;
+import cn.com.ctop.alarm.modules.service.IRuleAccountThresholdService;
 import cn.com.ctop.alarm.modules.service.IRuleBaseService;
 import cn.com.ctop.common.module.annotation.AutoLog;
 import com.alibaba.fastjson.JSON;
@@ -19,15 +20,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 +31,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 +49,8 @@ import java.util.Map;
 public class RuleBaseController {
     @Autowired
     private IRuleBaseService ruleBaseService;
+    @Autowired
+    private IRuleAccountThresholdService ruleAccountThresholdService;
 
     /**
      * 分页列表查询
@@ -138,6 +134,11 @@ public class RuleBaseController {
     public Result<?> delete(@RequestParam(name = "id", required = true) String id) {
         try {
             ruleBaseService.removeById(id);
+            Map<String, Object> deleteMap = new HashMap<>();
+            deleteMap.put("rule_id", id);
+            ruleAccountThresholdService.removeByMap(deleteMap);
+
+
         } catch (Exception e) {
             log.error("删除失败", e.getMessage());
             return Result.error("删除失败!");

+ 5 - 5
module-alarm/src/main/java/cn/com/ctop/alarm/modules/controller/RuleConditionController.java

@@ -60,16 +60,16 @@ public class RuleConditionController {
     @AutoLog(value = "规则运算符配置表-分页列表查询")
     @ApiOperation(value = "规则运算符配置表-分页列表查询", notes = "规则运算符配置表-分页列表查询")
     @GetMapping(value = "/list")
-    public Result<IPage<RuleCondition>> queryPageList(RuleCondition ruleCondition,
+    public Result<List<RuleCondition>> queryPageList(RuleCondition ruleCondition,
                                                       @RequestParam(name = "pageNo", defaultValue = "1") Integer pageNo,
                                                       @RequestParam(name = "pageSize", defaultValue = "10") Integer pageSize,
                                                       HttpServletRequest req) {
-        Result<IPage<RuleCondition>> result = new Result<>();
+        Result<List<RuleCondition>> result = new Result<>();
         QueryWrapper<RuleCondition> queryWrapper = QueryGenerator.initQueryWrapper(ruleCondition, req.getParameterMap());
-        Page<RuleCondition> page = new Page<RuleCondition>(pageNo, pageSize);
-        IPage<RuleCondition> pageList = ruleConditionService.page(page, queryWrapper);
+
+        List<RuleCondition> list = ruleConditionService.list(queryWrapper);
         result.setSuccess(true);
-        result.setResult(pageList);
+        result.setResult(list);
         return result;
     }
 

+ 53 - 10
module-alarm/src/main/java/cn/com/ctop/alarm/modules/controller/RuleGroupController.java

@@ -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("删除失败!");

+ 41 - 2
module-alarm/src/main/java/cn/com/ctop/alarm/modules/controller/RuleTemplateController.java

@@ -1,10 +1,12 @@
 package cn.com.ctop.alarm.modules.controller;
 
+import cn.com.ctop.alarm.modules.entity.RuleGroup;
 import cn.com.ctop.alarm.modules.entity.RuleTemplate;
-import cn.com.ctop.alarm.modules.service.IRuleTemplateService;
+import cn.com.ctop.alarm.modules.service.*;
 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;
@@ -32,6 +34,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;
 
@@ -49,6 +52,15 @@ import java.util.Map;
 public class RuleTemplateController {
     @Autowired
     private IRuleTemplateService ruleTemplateService;
+    @Autowired
+    private IRuleGroupService ruleGroupService;
+    @Autowired
+    private IRuleBaseService ruleBaseService;
+    @Autowired
+    private IRuleAccountThresholdService ruleAccountThresholdService;
+    @Autowired
+    private IRuleAccountTemplateService accountTemplateService;
+
 
     /**
      * 分页列表查询
@@ -158,12 +170,39 @@ public class RuleTemplateController {
      * @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 {
-            ruleTemplateService.removeById(id);
+            RuleTemplate ruleTemplate = ruleTemplateService.getById(id);
+            if (!Check.isNull(ruleTemplate)) {
+                QueryWrapper<RuleGroup> groupQueryWrapper = new QueryWrapper<>();
+                groupQueryWrapper.eq("template_id", id);
+                List<RuleGroup> groupList = ruleGroupService.list(groupQueryWrapper);
+                if (!Check.isNull(groupList)) {
+                    for (RuleGroup group : groupList) {
+                        JSONArray ruleIds = JSONArray.parseArray(group.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(group.getId());
+                    }
+                }
+
+                Map<String, Object> deleteMap = new HashMap<>();
+                deleteMap.put("template_id", id);
+                accountTemplateService.removeByMap(deleteMap);
+                ruleTemplateService.removeById(id);
+            }
+
+
         } catch (Exception e) {
             log.error("删除失败", e.getMessage());
             return Result.error("删除失败!");

+ 3 - 0
module-alarm/src/main/java/cn/com/ctop/alarm/modules/entity/RuleBase.java

@@ -32,6 +32,9 @@ public class RuleBase {
     @TableId(type = IdType.AUTO)
     @ApiModelProperty(value = "id")
     private Long id;
+
+    private Long groupId;
+
     /**
      * 规则名称
      */

+ 1 - 1
module-alarm/src/main/java/cn/com/ctop/alarm/modules/entity/RuleCondition.java

@@ -43,7 +43,7 @@ public class RuleCondition {
      */
     @Excel(name = "运算符", width = 15)
     @ApiModelProperty(value = "运算符")
-    private String condition;
+    private String ruleCondition;
     /**
      * 数据类型
      */

+ 1 - 0
module-alarm/src/main/java/cn/com/ctop/alarm/modules/entity/RuleGroup.java

@@ -34,6 +34,7 @@ public class RuleGroup {
     @TableId(type = IdType.AUTO)
     @ApiModelProperty(value = "id")
     private Long id;
+    private Long templateId;
     /**
      * 规则id列表
      */

+ 2 - 0
module-alarm/src/main/java/cn/com/ctop/alarm/modules/service/IRuleGroupService.java

@@ -1,6 +1,7 @@
 package cn.com.ctop.alarm.modules.service;
 
 import cn.com.ctop.alarm.modules.entity.RuleGroup;
+import com.alibaba.fastjson.JSONObject;
 import com.baomidou.mybatisplus.extension.service.IService;
 
 /**
@@ -13,4 +14,5 @@ public interface IRuleGroupService extends IService<RuleGroup> {
 
     void checkRules();
 
+    JSONObject createRuleGroup(JSONObject requestJson);
 }

+ 12 - 0
module-alarm/src/main/java/cn/com/ctop/alarm/modules/service/impl/RuleGroupServiceImpl.java

@@ -117,4 +117,16 @@ public class RuleGroupServiceImpl extends ServiceImpl<RuleGroupMapper, RuleGroup
         return null;
     }
 
+    /**
+     * 创建规则集
+     *
+     * @param requestJson
+     * @return
+     */
+    @Override
+    public com.alibaba.fastjson.JSONObject createRuleGroup(com.alibaba.fastjson.JSONObject requestJson) {
+        return null;
+    }
+
+
 }

+ 26 - 1
module-alarm/src/main/java/cn/com/ctop/alarm/modules/service/impl/RuleTemplateServiceImpl.java

@@ -101,6 +101,17 @@ public class RuleTemplateServiceImpl extends ServiceImpl<RuleTemplateMapper, Rul
                         ruleGroup.setRemark(ruleGroupJson.getString("remark"));
                         boolean save = ruleGroupService.save(ruleGroup);
                         if (save) {
+                            String ruleIdsArrStr = ruleGroup.getRuleIds();
+                            JSONArray array = JSONArray.parseArray(ruleIdsArrStr);
+                            if (!Check.isNull(array)) {
+                                for (int j = 0; j < array.size(); j++) {
+                                    Long ruleId = array.getLong(j);
+                                    RuleBase updateBase = new RuleBase();
+                                    updateBase.setId(ruleId);
+                                    updateBase.setGroupId(ruleGroup.getId());
+                                    ruleBaseService.updateById(updateBase);
+                                }
+                            }
                             groupIds.add(ruleGroup.getId());
 
                         }
@@ -108,7 +119,21 @@ public class RuleTemplateServiceImpl extends ServiceImpl<RuleTemplateMapper, Rul
                 }
             }
             template.setGroupIds(groupIds.toJSONString());
-            this.save(template);
+            boolean save = this.save(template);
+            if (save) {
+                String groupIdsArrStr = template.getGroupIds();
+                JSONArray groupIdsArr = JSONArray.parseArray(groupIdsArrStr);
+                if (!Check.isNull(groupIdsArr)) {
+                    for (int i = 0; i < groupIdsArr.size(); i++) {
+                        Long groupId = groupIdsArr.getLong(i);
+                        RuleGroup updateRuleGroup = new RuleGroup();
+                        updateRuleGroup.setId(groupId);
+                        updateRuleGroup.setTemplateId(template.getId());
+                        ruleGroupService.updateById(updateRuleGroup);
+                    }
+
+                }
+            }
             returnJson.put("code", 0);
             returnJson.put("message", "创建成功");