yumeng 4 år sedan
förälder
incheckning
92643e45de

+ 65 - 19
module-alarm/src/main/java/cn/com/ctop/alarm/modules/service/impl/RuleAccountThresholdServiceImpl.java

@@ -11,6 +11,10 @@ import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.stereotype.Service;
 
+import java.util.HashMap;
+import java.util.Map;
+import java.util.UUID;
+
 /**
  * 规则关联账户 阈值
  *
@@ -50,19 +54,60 @@ public class RuleAccountThresholdServiceImpl extends ServiceImpl<RuleAccountThre
                 continue;
             }
 
+            Long groupId = groupJson.getLong("groupId");
+            Integer isCopy = groupJson.getInteger("isCopy");
+
+            String batchNo = UUID.randomUUID().toString().replace(" ", "");
+
             for (int j = 0; j < ruleDetail.size(); j++) {
-                JSONObject ruleJson = ruleDetail.getJSONObject(j);
-                Long ruleId = ruleJson.getLong("ruleId");
-                if (Check.isNull(ruleId)) {
-                    continue;
-                }
-                String threshold = ruleJson.getString("threshold");
-                if (Check.isNull(threshold)) {
-                    continue;
-                }
-                RuleAccountThreshold updateThreshold = new RuleAccountThreshold();
-                /*if (threshold.contains("[") && threshold.contains("]")) {
-                  *//*  String replace = threshold.replace("[", "").replace("]", "");
+                if (isCopy == 1) { // 规则组可复制
+                    JSONArray ruleDetailArr = ruleDetail.getJSONArray(i);
+                    if (Check.isNull(ruleDetailArr)) {
+                        continue;
+                    }
+                    Map<String, Object> deleteMap = new HashMap<>();
+                    deleteMap.put("account_id", accountId);
+                    deleteMap.put("group_id", groupId);
+                    ruleAccountThresholdMapper.deleteByMap(deleteMap);
+                    for (int k = 0; k < ruleDetailArr.size(); k++) {
+                        JSONObject ruleJson = ruleDetailArr.getJSONObject(k);
+                        if (Check.isNull(ruleJson)) {
+                            continue;
+                        }
+                        Long ruleId = ruleJson.getLong("ruleId");
+                        if (Check.isNull(ruleId)) {
+                            continue;
+                        }
+                        String threshold = ruleJson.getString("threshold");
+                        if (Check.isNull(threshold)) {
+                            continue;
+                        }
+                        RuleAccountThreshold addRuleAccountThreshold = new RuleAccountThreshold();
+                        addRuleAccountThreshold.setAccountId(accountId);
+                        addRuleAccountThreshold.setGroupId(groupId);
+                        addRuleAccountThreshold.setThreshold(threshold);
+                        addRuleAccountThreshold.setRuleId(ruleId);
+                        addRuleAccountThreshold.setBatchNo(batchNo);
+                        int insert = ruleAccountThresholdMapper.insert(addRuleAccountThreshold);
+                        if (insert > 0) {
+                            updateCount += 1;
+                        }
+                    }
+                } else if (isCopy == 0) {
+
+
+                    JSONObject ruleJson = ruleDetail.getJSONObject(j);
+                    Long ruleId = ruleJson.getLong("ruleId");
+                    if (Check.isNull(ruleId)) {
+                        continue;
+                    }
+                    String threshold = ruleJson.getString("threshold");
+                    if (Check.isNull(threshold)) {
+                        continue;
+                    }
+                    RuleAccountThreshold updateThreshold = new RuleAccountThreshold();
+                    /*if (threshold.contains("[") && threshold.contains("]")) {
+                     *//*  String replace = threshold.replace("[", "").replace("]", "");
                     List<String> strings = Arrays.asList(replace.split(","));
                     JSONArray array = new JSONArray();
                     for (int k = 0; k < strings.size(); k++) {
@@ -74,13 +119,14 @@ public class RuleAccountThresholdServiceImpl extends ServiceImpl<RuleAccountThre
                 } else {
 
                 }*/
-                updateThreshold.setThreshold(threshold);
-                QueryWrapper<RuleAccountThreshold> updateQueryWrapper = new QueryWrapper();
-                updateQueryWrapper.eq("account_id", accountId);
-                updateQueryWrapper.eq("rule_id", ruleId);
-                int update = ruleAccountThresholdMapper.update(updateThreshold, updateQueryWrapper);
-                if (update > 0) {
-                    updateCount += 1;
+                    updateThreshold.setThreshold(threshold);
+                    QueryWrapper<RuleAccountThreshold> updateQueryWrapper = new QueryWrapper();
+                    updateQueryWrapper.eq("account_id", accountId);
+                    updateQueryWrapper.eq("rule_id", ruleId);
+                    int update = ruleAccountThresholdMapper.update(updateThreshold, updateQueryWrapper);
+                    if (update > 0) {
+                        updateCount += 1;
+                    }
                 }
             }
         }

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

@@ -307,17 +307,17 @@ public class RuleTemplateServiceImpl extends ServiceImpl<RuleTemplateMapper, Rul
                 accountThresholdQueryWrapper.eq("rule_id", ruleId);
                 RuleAccountThreshold threshold = accountThresholdService.getOne(accountThresholdQueryWrapper);
                 if (!Check.isNull(threshold)) {
-                    String value = threshold.getThreshoId();
+                    String value = threshold.getThreshold();
                     if (!Check.isNull(value)) {
                         if (value.contains("[") && value.contains("]")) {
                             ruleJson.put("threshold", JSONArray.parseArray(value));
                         } else {
                             ruleJson.put("threshold", value);
                         }
-                    }else{
+                    } else {
                         ruleJson.put("threshold", null);
                     }
-                   // ruleJson.put("threshold", threshold.getThreshoId());
+                    // ruleJson.put("threshold", threshold.getThreshoId());
                 } else {
                     ruleJson.put("threshold", null);
                 }