소스 검색

调整创建逻辑

yumeng 4 년 전
부모
커밋
fcc1a1f52f

+ 30 - 18
module-alarm/src/main/java/cn/com/ctop/alarm/modules/controller/RuleAccountTemplateController.java

@@ -3,6 +3,7 @@ package cn.com.ctop.alarm.modules.controller;
 import cn.com.ctop.alarm.modules.entity.RuleAccountTemplate;
 import cn.com.ctop.alarm.modules.entity.RuleTemplate;
 import cn.com.ctop.alarm.modules.service.IRuleAccountTemplateService;
+import cn.com.ctop.alarm.modules.service.IRuleAccountThresholdService;
 import cn.com.ctop.alarm.modules.service.IRuleTemplateService;
 import cn.com.ctop.common.module.annotation.AutoLog;
 import cn.com.ctop.common.module.utils.Check;
@@ -34,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;
 
@@ -53,6 +55,8 @@ public class RuleAccountTemplateController {
     private IRuleAccountTemplateService ruleAccountTemplateService;
     @Autowired
     private IRuleTemplateService templateService;
+    @Autowired
+    private IRuleAccountThresholdService accountThresholdService;
 
     @GetMapping(value = "/checkAccountTemplate")
     public Result<JSONObject> checkAccountTemplate(Long accountId) {
@@ -109,6 +113,32 @@ public class RuleAccountTemplateController {
 
 
     /**
+     * 通过id删除
+     *
+     * @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 {
+            RuleAccountTemplate accountTemplate = ruleAccountTemplateService.getById(id);
+            if (!Check.isNull(accountTemplate)) {
+                Map<String, Object> deleteMap = new HashMap<>();
+                deleteMap.put("account_id", accountTemplate.getAccountId());
+                accountThresholdService.removeByMap(deleteMap);
+                ruleAccountTemplateService.removeById(id);
+            }
+        } catch (Exception e) {
+            log.error("删除失败", e.getMessage());
+            return Result.error("删除失败!");
+        }
+        return Result.ok("删除成功!");
+    }
+
+
+    /**
      * 分页列表查询
      *
      * @param ruleAccountTemplate
@@ -193,24 +223,6 @@ public class RuleAccountTemplateController {
         return result;
     }
 
-    /**
-     * 通过id删除
-     *
-     * @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 {
-            ruleAccountTemplateService.removeById(id);
-        } catch (Exception e) {
-            log.error("删除失败", e.getMessage());
-            return Result.error("删除失败!");
-        }
-        return Result.ok("删除成功!");
-    }
 
     /**
      * 批量删除

+ 2 - 1
module-alarm/src/main/java/cn/com/ctop/alarm/modules/controller/RuleGroupController.java

@@ -119,7 +119,8 @@ public class RuleGroupController {
                     JSONArray groupIds = JSONArray.parseArray(ruleTemplate.getGroupIds());
                     Iterator<Object> o = groupIds.iterator();
                     while (o.hasNext()) {
-                        Long groupId = (Long) o.next();
+                        System.err.println(o.next());
+                        String groupId = String.valueOf(o.next());
                         if (groupId.equals(id)) {
                             o.remove();
                         }

+ 3 - 0
module-alarm/src/main/java/cn/com/ctop/alarm/modules/controller/RuleTemplateController.java

@@ -211,6 +211,9 @@ public class RuleTemplateController {
                 if (!Check.isNull(groupList)) {
                     for (RuleGroup group : groupList) {
                         JSONArray ruleIds = JSONArray.parseArray(group.getRuleIds());
+                        if (Check.isNull(ruleIds)) {
+                            continue;
+                        }
                         for (int i = 0; i < ruleIds.size(); i++) {
                             Long ruleId = ruleIds.getLong(i);
                             ruleBaseService.removeById(ruleId);

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

@@ -44,6 +44,7 @@ public class RuleAccountTemplate {
     @Excel(name = "模板id", width = 15)
     @ApiModelProperty(value = "模板id")
     private Long templateId;
+
     /**
      * createTime
      */

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

@@ -56,6 +56,7 @@ public class RuleIndicator {
     @Excel(name = "数据类型", width = 15)
     @ApiModelProperty(value = "数据类型")
     private String dataType;
+    private String modelType;
     /**
      * 数据单位
      */

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

@@ -63,10 +63,7 @@ public class RuleAccountTemplateServiceImpl extends ServiceImpl<RuleAccountTempl
         if (insert == 0) {
             throw new Exception("推送失败,请联系相关技术人员");
         }
-
-
         JSONObject returnJson = new JSONObject();
-
         Integer groupCount = 0;
         for (int i = 0; i < groupIds.size(); i++) {
             Long groupId = groupIds.getLong(i);

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

@@ -1,18 +1,8 @@
 package cn.com.ctop.alarm.modules.service.impl;
 
 import cn.com.ctop.alarm.modules.constant.MatchLogic;
-import cn.com.ctop.alarm.modules.entity.RuleAccountTemplate;
-import cn.com.ctop.alarm.modules.entity.RuleAccountThreshold;
-import cn.com.ctop.alarm.modules.entity.RuleBase;
-import cn.com.ctop.alarm.modules.entity.RuleGroup;
-import cn.com.ctop.alarm.modules.entity.RuleIndicator;
-import cn.com.ctop.alarm.modules.entity.RuleTemplate;
-import cn.com.ctop.alarm.modules.mapper.RuleAccountTemplateMapper;
-import cn.com.ctop.alarm.modules.mapper.RuleAccountThresholdMapper;
-import cn.com.ctop.alarm.modules.mapper.RuleBaseMapper;
-import cn.com.ctop.alarm.modules.mapper.RuleGroupMapper;
-import cn.com.ctop.alarm.modules.mapper.RuleIndicatorMapper;
-import cn.com.ctop.alarm.modules.mapper.RuleTemplateMapper;
+import cn.com.ctop.alarm.modules.entity.*;
+import cn.com.ctop.alarm.modules.mapper.*;
 import cn.com.ctop.alarm.modules.service.IRuleAccountTemplateService;
 import cn.com.ctop.alarm.modules.service.IRuleGroupService;
 import cn.com.ctop.common.module.service.ISendMessageService;
@@ -254,7 +244,7 @@ public class RuleGroupServiceImpl extends ServiceImpl<RuleGroupMapper, RuleGroup
     public JSONObject createRuleGroup(com.alibaba.fastjson.JSONObject requestJson) {
         JSONObject returnJson = new JSONObject();
         try {
-            String templateId = requestJson.getString("templateId");
+            Long templateId = requestJson.getLong("templateId");
             if (Check.isNull(templateId)) {
                 throw new Exception("请选择需要创建的规则模板id");
             }
@@ -292,10 +282,17 @@ public class RuleGroupServiceImpl extends ServiceImpl<RuleGroupMapper, RuleGroup
                         if (!Check.isNull(accountList)) {
                             for (RuleAccountTemplate accountTemplate : accountList) {
                                 Long accountId = accountTemplate.getAccountId();
+                                QueryWrapper<RuleAccountThreshold> thresholdQueryWrapper = new QueryWrapper<>();
+                                thresholdQueryWrapper.eq("account_id", accountId);
+                                thresholdQueryWrapper.eq("rule_id", ruleBase.getId());
+                                thresholdQueryWrapper.last("limit 1");
+                                RuleAccountThreshold accountThreshold = ruleAccountThresholdMapper.selectOne(thresholdQueryWrapper);
+                                if (!Check.isNull(accountThreshold)) {
+                                    continue;
+                                }
                                 RuleAccountThreshold threshold = new RuleAccountThreshold();
                                 threshold.setAccountId(accountId);
                                 threshold.setRuleId(ruleBase.getId());
-                                // threshold.setThreshoId(ruleDetailJson.getString("threshold"));
                                 ruleAccountThresholdMapper.insert(threshold);  // 默认将新建的规则同步到已应用的账户下
                             }
                         }
@@ -305,11 +302,21 @@ public class RuleGroupServiceImpl extends ServiceImpl<RuleGroupMapper, RuleGroup
                 RuleGroup ruleGroup = new RuleGroup();
                 ruleGroup.setRuleIds(ruleIds.toJSONString());
                 ruleGroup.setRuleType(groupJson.getString("ruleType"));
+                ruleGroup.setTemplateId(templateId);
                 ruleGroup.setRuleRelationship(groupJson.getString("ruleRelationship"));
                 ruleGroup.setGroupName(groupJson.getString("groupName"));
                 ruleGroup.setRemark(groupJson.getString("remark"));
                 boolean save = ruleGroupService.save(ruleGroup); // 新增规则组
                 if (save) {
+
+                    for (int j = 0; j < ruleIds.size(); j++) {
+                        Long ruleId = ruleIds.getLong(j);
+                        RuleBase updateRuleBase = new RuleBase();
+                        updateRuleBase.setId(ruleId);
+                        updateRuleBase.setGroupId(ruleGroup.getId());
+                        ruleBaseMapper.updateById(updateRuleBase);
+                    }
+
                     JSONArray groupIds = JSONArray.parseArray(template.getGroupIds());
                     groupIds.add(ruleGroup.getId());
                     template.setGroupIds(groupIds.toJSONString());

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

@@ -50,7 +50,6 @@ public class RuleTemplateServiceImpl extends ServiceImpl<RuleTemplateMapper, Rul
      */
     @Override
     public JSONObject createTemplate(JSONObject requestJson) {
-        System.err.println(requestJson);
         JSONObject returnJson = new JSONObject();
         try {
             Integer mediaType = requestJson.getInteger("mediaType");
@@ -228,6 +227,7 @@ public class RuleTemplateServiceImpl extends ServiceImpl<RuleTemplateMapper, Rul
                     ruleJson.put("dictId", ruleIndicator.getDictId());
                     ruleJson.put("dataUnit", ruleIndicator.getDataUnit());
                     ruleJson.put("name", ruleIndicator.getName());
+                    ruleJson.put("modelType", ruleIndicator.getModelType());
                 }
 
                 ruleDetail.add(ruleJson);