yumeng преди 4 години
родител
ревизия
0518bca7f0

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

@@ -70,12 +70,12 @@ public class RuleAccountTemplateController {
     /**
      * 查询账户下关联的模板
      *
-     * @param page
+     * @param pageNo
      * @param pageSize
      * @return
      */
     @GetMapping(value = "/getTemplateApplied")
-    public Result<PageInfo<TemplateAppliedVo>> getTemplateApplied(int page, int pageSize, Long accountId, String projectName, String userName) {
+    public Result<PageInfo<TemplateAppliedVo>> getTemplateApplied(int pageNo, int pageSize, Long accountId, String projectName, String userName) {
         Result<PageInfo<TemplateAppliedVo>> result = new Result<>();
         try {
             LoginUser sysUser = (LoginUser) SecurityUtils.getSubject().getPrincipal();
@@ -94,7 +94,7 @@ public class RuleAccountTemplateController {
             if (!Check.isNull(userName)) {
                 requestMap.put("userName", userName);
             }
-            PageHelper.startPage(page, pageSize);
+            PageHelper.startPage(pageNo, pageSize);
             List<TemplateAppliedVo> list = ruleAccountTemplateService.getTemplateApplied(requestMap);
 
             PageInfo<TemplateAppliedVo> pageInfo = new PageInfo<>(list);

+ 23 - 9
module-alarm/src/main/java/cn/com/ctop/alarm/modules/controller/RuleAccountThresholdController.java

@@ -3,7 +3,9 @@ package cn.com.ctop.alarm.modules.controller;
 import cn.com.ctop.alarm.modules.entity.RuleAccountThreshold;
 import cn.com.ctop.alarm.modules.service.IRuleAccountThresholdService;
 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.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 +21,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;
@@ -56,6 +50,26 @@ public class RuleAccountThresholdController {
     @Autowired
     private IRuleAccountThresholdService ruleAccountThresholdService;
 
+
+    @PostMapping(value = "/fillThreshold")
+    public Result<JSONObject> fillThreshold(@RequestBody JSONObject requestJson) {
+        Result<JSONObject> result = new Result<>();
+        try {
+            if (Check.isNull(requestJson)) {
+                throw new Exception("入参为空");
+            }
+            JSONObject returnJson = ruleAccountThresholdService.fillThreshold(requestJson);
+            result.setSuccess(true);
+            result.setResult(returnJson);
+        } catch (Exception e) {
+            e.printStackTrace();
+            result.setSuccess(false);
+            result.setMessage(e.getMessage());
+        }
+        return result;
+    }
+
+
     /**
      * 分页列表查询
      *

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

@@ -128,7 +128,12 @@ public class RuleTemplateController {
                                                      @RequestParam(name = "pageSize", defaultValue = "10") Integer pageSize,
                                                      HttpServletRequest req) {
         Result<IPage<RuleTemplate>> result = new Result<>();
+        String templateName = ruleTemplate.getTemplateName();
+        ruleTemplate.setTemplateName(null);
         QueryWrapper<RuleTemplate> queryWrapper = QueryGenerator.initQueryWrapper(ruleTemplate, req.getParameterMap());
+        if (!Check.isNull(templateName)) {
+            queryWrapper.like("template_name", templateName);
+        }
         Page<RuleTemplate> page = new Page<RuleTemplate>(pageNo, pageSize);
         IPage<RuleTemplate> pageList = ruleTemplateService.page(page, queryWrapper);
         result.setSuccess(true);

+ 5 - 4
module-alarm/src/main/java/cn/com/ctop/alarm/modules/mapper/xml/RuleAccountTemplateMapper.xml

@@ -4,8 +4,9 @@
 
     <select id="getTemplateApplied" parameterType="Map"
             resultType="cn.com.ctop.alarm.modules.entity.vo.TemplateAppliedVo">
-        t1.account_id accountId,SELECT
-        t2.auth_name autnName,
+        select
+        t1.account_id accountId,
+        t2.auth_name authName,
         t1.template_id templateId,
         (
         SELECT
@@ -14,7 +15,7 @@
         ctop_rule_template
         WHERE
         id = t1.template_id
-        ) templateName,
+        ) as templateName,
         t3.id projectId,
         t3.project_name projectName,
         t2.user_id userId,
@@ -23,7 +24,7 @@
         ctop_rule_account_template t1
         LEFT JOIN ctop_user_allocation t2 ON t1.account_id = t2.account_id
         LEFT JOIN ctop_project t3 ON t2.project_id = t3.id
-        left sys_user t4 on t2.user_id = t4.id
+        left join sys_user t4 on t2.user_id = t4.id
         where 1 = 1
         <if test="params.userId !=null and params.userId !='' ">
             and t2.user_id = #{params.userId}

+ 9 - 1
module-alarm/src/main/java/cn/com/ctop/alarm/modules/service/IRuleAccountThresholdService.java

@@ -1,14 +1,22 @@
 package cn.com.ctop.alarm.modules.service;
 
 import cn.com.ctop.alarm.modules.entity.RuleAccountThreshold;
+import com.alibaba.fastjson.JSONObject;
 import com.baomidou.mybatisplus.extension.service.IService;
 
 /**
  * @Description: 规则关联账户 阈值
  * @Author: jeecg-boot
- * @Date:   2020-11-15
+ * @Date: 2020-11-15
  * @Version: V1.0
  */
 public interface IRuleAccountThresholdService extends IService<RuleAccountThreshold> {
 
+    /**
+     * 阈值填充
+     *
+     * @param requestJson
+     * @return
+     */
+    JSONObject fillThreshold(JSONObject requestJson) throws Exception;
 }

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

@@ -3,17 +3,91 @@ package cn.com.ctop.alarm.modules.service.impl;
 import cn.com.ctop.alarm.modules.entity.RuleAccountThreshold;
 import cn.com.ctop.alarm.modules.mapper.RuleAccountThresholdMapper;
 import cn.com.ctop.alarm.modules.service.IRuleAccountThresholdService;
-import org.springframework.stereotype.Service;
-
+import cn.com.ctop.common.module.utils.Check;
+import com.alibaba.fastjson.JSONArray;
+import com.alibaba.fastjson.JSONObject;
+import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
 import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.stereotype.Service;
 
 /**
  * 规则关联账户 阈值
+ *
  * @author jeecg-boot
- * @date   2020-11-15
  * @version V1.0
+ * @date 2020-11-15
  */
 @Service
 public class RuleAccountThresholdServiceImpl extends ServiceImpl<RuleAccountThresholdMapper, RuleAccountThreshold> implements IRuleAccountThresholdService {
+    @Autowired
+    private RuleAccountThresholdMapper ruleAccountThresholdMapper;
+
+    /**
+     * 填充阈值
+     *
+     * @param requestJson
+     * @return
+     */
+    @Override
+    public JSONObject fillThreshold(JSONObject requestJson) throws Exception {
+        Long accountId = requestJson.getLong("accountId");
+        if (Check.isNull(accountId)) {
+            throw new Exception("请传入账户id");
+        }
+        JSONArray ruleList = requestJson.getJSONArray("ruleList");
+        if (Check.isNull(ruleList)) {
+            throw new Exception("请输入具体的规则字段");
+        }
+        Integer updateCount = 0;
+        for (int i = 0; i < ruleList.size(); i++) {
+            JSONObject groupJson = ruleList.getJSONObject(i);
+            if (Check.isNull(groupJson)) {
+                continue;
+            }
+            JSONArray ruleDetail = groupJson.getJSONArray("ruleDetail");
+            if (Check.isNull(ruleDetail)) {
+                continue;
+            }
+
+            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("]", "");
+                    List<String> strings = Arrays.asList(replace.split(","));
+                    JSONArray array = new JSONArray();
+                    for (int k = 0; k < strings.size(); k++) {
+                        array.add(strings.get(i))
+                         JSONArray.parseArray(strings);
+                    }*//*
+
+                    updateThreshold.setThreshoId(JSONArray.parseArray(threshold).toJSONString());
+                } else {
+
+                }*/
+                updateThreshold.setThreshoId(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;
+                }
+            }
+        }
 
+        JSONObject returnJson = new JSONObject();
+        returnJson.put("code", 0);
+        returnJson.put("updateCount", updateCount);
+        return returnJson;
+    }
 }

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

@@ -255,7 +255,7 @@ public class RuleTemplateServiceImpl extends ServiceImpl<RuleTemplateMapper, Rul
     public JSONObject queryDetailByAccountIdAndTemplateId(Long accountId, Long templateId) throws Exception {
         JSONObject returnJson = new JSONObject();
         RuleTemplate template = ruleTemplateMapper.selectById(templateId);
-        if (Check.isNull(ruleTemplateMapper)) {
+        if (Check.isNull(template)) {
             throw new Exception("获取模板基本信息为空");
         }
 
@@ -307,8 +307,21 @@ public class RuleTemplateServiceImpl extends ServiceImpl<RuleTemplateMapper, Rul
                 accountThresholdQueryWrapper.eq("rule_id", ruleId);
                 RuleAccountThreshold threshold = accountThresholdService.getOne(accountThresholdQueryWrapper);
                 if (!Check.isNull(threshold)) {
-                    ruleJson.put("threshold", threshold.getThreshoId());
+                    String value = threshold.getThreshoId();
+                    if (!Check.isNull(value)) {
+                        if (value.contains("[") && value.contains("]")) {
+                            ruleJson.put("threshold", JSONArray.parseArray(value));
+                        } else {
+                            ruleJson.put("threshold", value);
+                        }
+                    }else{
+                        ruleJson.put("threshold", null);
+                    }
+                   // ruleJson.put("threshold", threshold.getThreshoId());
+                } else {
+                    ruleJson.put("threshold", null);
                 }
+
                 ruleJson.put("ruleDimension", ruleBase.getRuleDimension());
                 ruleJson.put("variableType", ruleBase.getVariableType());
                 ruleJson.put("isUnlimited", ruleBase.getIsUnlimited());
@@ -337,4 +350,5 @@ public class RuleTemplateServiceImpl extends ServiceImpl<RuleTemplateMapper, Rul
         returnJson.put("ruleList", ruleList);
         return returnJson;
     }
+
 }