Browse Source

预警规则匹配逻辑——发送数据

zhaoxian 4 years ago
parent
commit
c394dea550

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

@@ -2,21 +2,27 @@ 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.entity.vo.TemplateAppliedVo;
 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.service.ISysRoleExtService;
 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;
+import com.github.pagehelper.PageHelper;
+import com.github.pagehelper.PageInfo;
 import io.swagger.annotations.Api;
 import io.swagger.annotations.ApiOperation;
 import lombok.extern.slf4j.Slf4j;
+import org.apache.shiro.SecurityUtils;
 import org.jeecg.common.api.vo.Result;
 import org.jeecg.common.system.query.QueryGenerator;
+import org.jeecg.common.system.vo.LoginUser;
 import org.jeecg.common.util.oConvertUtils;
 import org.jeecgframework.poi.excel.ExcelImportUtil;
 import org.jeecgframework.poi.excel.def.NormalExcelConstants;
@@ -58,6 +64,51 @@ public class RuleAccountTemplateController {
     @Autowired
     private IRuleAccountThresholdService accountThresholdService;
 
+    @Autowired
+    private ISysRoleExtService sysRoleService;
+
+    /**
+     * 查询账户下关联的模板
+     *
+     * @param page
+     * @param pageSize
+     * @return
+     */
+    @GetMapping(value = "/getTemplateApplied")
+    public Result<PageInfo<TemplateAppliedVo>> getTemplateApplied(int page, int pageSize, Long accountId, String projectName, String userName) {
+        Result<PageInfo<TemplateAppliedVo>> result = new Result<>();
+        try {
+            LoginUser sysUser = (LoginUser) SecurityUtils.getSubject().getPrincipal();
+            String roleCode = sysRoleService.getRoleCodeByUserId(sysUser.getId());
+            Map<String, Object> requestMap = new JSONObject();
+            if (!"admin".equals(roleCode)) {
+                requestMap.put("userId", sysUser.getId());
+            }
+            if (!Check.isNull(accountId)) {
+                requestMap.put("accountId", accountId);
+            }
+
+            if (!Check.isNull(projectName)) {
+                requestMap.put("projectName", projectName);
+            }
+            if (!Check.isNull(userName)) {
+                requestMap.put("userName", userName);
+            }
+            PageHelper.startPage(page, pageSize);
+            List<TemplateAppliedVo> list = ruleAccountTemplateService.getTemplateApplied(requestMap);
+
+            PageInfo<TemplateAppliedVo> pageInfo = new PageInfo<>(list);
+            result.setSuccess(true);
+            result.setResult(pageInfo);
+        } catch (Exception e) {
+            e.printStackTrace();
+            result.setSuccess(false);
+            result.setMessage(e.getMessage());
+        }
+        return result;
+    }
+
+
     @GetMapping(value = "/checkAccountTemplate")
     public Result<JSONObject> checkAccountTemplate(Long accountId) {
         Result<JSONObject> result = new Result<>();

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

@@ -94,7 +94,7 @@ public class RuleTemplateController {
      * @return
      */
 
-    @GetMapping(value = "/queryDetailById")
+    @GetMapping(value = "/queryDetailByAccountIdAndTemplateId")
     public Result<JSONObject> queryDetailByAccountIdAndTemplateId(Long accountId, Long templateId) {
         Result<JSONObject> result = new Result<>();
         try {

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

@@ -68,6 +68,7 @@ public class RuleBase {
 
     private Integer variableType;// 变量类型
     private Integer judgeFormat;// 判断类型
+    private Boolean isUnlimited;//  是否支持不限  true 是 false 否
 
     /**
      * createTime

+ 90 - 0
module-alarm/src/main/java/cn/com/ctop/alarm/modules/entity/vo/TemplateAppliedVo.java

@@ -0,0 +1,90 @@
+package cn.com.ctop.alarm.modules.entity.vo;
+
+public class TemplateAppliedVo {
+    private Long accountId;
+    private String authName;
+    private Long templateId;
+    private String templateName;
+    private Long projectId;
+    private String projectName;
+    private String userId;
+    private String userName;
+
+    public Long getAccountId() {
+        return accountId;
+    }
+
+    public void setAccountId(Long accountId) {
+        this.accountId = accountId;
+    }
+
+    public String getAuthName() {
+        return authName;
+    }
+
+    public void setAuthName(String authName) {
+        this.authName = authName;
+    }
+
+    public Long getTemplateId() {
+        return templateId;
+    }
+
+    public void setTemplateId(Long templateId) {
+        this.templateId = templateId;
+    }
+
+    public String getTemplateName() {
+        return templateName;
+    }
+
+    public void setTemplateName(String templateName) {
+        this.templateName = templateName;
+    }
+
+    public Long getProjectId() {
+        return projectId;
+    }
+
+    public void setProjectId(Long projectId) {
+        this.projectId = projectId;
+    }
+
+    public String getProjectName() {
+        return projectName;
+    }
+
+    public void setProjectName(String projectName) {
+        this.projectName = projectName;
+    }
+
+    public String getUserId() {
+        return userId;
+    }
+
+    public void setUserId(String userId) {
+        this.userId = userId;
+    }
+
+    public String getUserName() {
+        return userName;
+    }
+
+    public void setUserName(String userName) {
+        this.userName = userName;
+    }
+
+    @Override
+    public String toString() {
+        return "TemplateAppliedVo{" +
+                "accountId=" + accountId +
+                ", authName='" + authName + '\'' +
+                ", templateId=" + templateId +
+                ", templateName='" + templateName + '\'' +
+                ", projectId=" + projectId +
+                ", projectName='" + projectName + '\'' +
+                ", userId='" + userId + '\'' +
+                ", userName='" + userName + '\'' +
+                '}';
+    }
+}

+ 3 - 0
module-alarm/src/main/java/cn/com/ctop/alarm/modules/mapper/RuleAccountTemplateMapper.java

@@ -1,7 +1,9 @@
 package cn.com.ctop.alarm.modules.mapper;
 
 import java.util.List;
+import java.util.Map;
 
+import cn.com.ctop.alarm.modules.entity.vo.TemplateAppliedVo;
 import org.apache.ibatis.annotations.Param;
 import cn.com.ctop.alarm.modules.entity.RuleAccountTemplate;
 import com.baomidou.mybatisplus.core.mapper.BaseMapper;
@@ -14,4 +16,5 @@ import com.baomidou.mybatisplus.core.mapper.BaseMapper;
  */
 public interface RuleAccountTemplateMapper extends BaseMapper<RuleAccountTemplate> {
 
+    List<TemplateAppliedVo> getTemplateApplied(@Param("params") Map<String, Object> requestMap);
 }

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

@@ -2,4 +2,46 @@
 <!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
 <mapper namespace="cn.com.ctop.alarm.modules.mapper.RuleAccountTemplateMapper">
 
+    <select id="getTemplateApplied" parameterType="Map"
+            resultType="cn.com.ctop.alarm.modules.entity.vo.TemplateAppliedVo">
+        t1.account_id accountId,SELECT
+        t2.auth_name autnName,
+        t1.template_id templateId,
+        (
+        SELECT
+        template_name
+        FROM
+        ctop_rule_template
+        WHERE
+        id = t1.template_id
+        ) templateName,
+        t3.id projectId,
+        t3.project_name projectName,
+        t2.user_id userId,
+        t4.realname userName
+        FROM
+        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
+        where 1 = 1
+        <if test="params.userId !=null and params.userId !='' ">
+            and t2.user_id = #{params.userId}
+        </if>
+
+        <if test="params.accountId !=null and params.accountId !='' ">
+            and t2.account_id = #{params.accountId}
+        </if>
+
+        <if test="params.accountId !=null and params.accountId !='' ">
+            and t2.account_id = #{params.accountId}
+        </if>
+        <if test="params.projectName !=null and params.projectName !='' ">
+            and t3.project_name like concat(concat('%',#{params.projectName}),'%')
+        </if>
+        <if test="params.userName !=null and params.userName !='' ">
+            and t4.realname like concat(concat('%',#{params.userName}),'%')
+        </if>
+    </select>
+
 </mapper>

+ 7 - 0
module-alarm/src/main/java/cn/com/ctop/alarm/modules/service/IRuleAccountTemplateService.java

@@ -1,9 +1,13 @@
 package cn.com.ctop.alarm.modules.service;
 
 import cn.com.ctop.alarm.modules.entity.RuleAccountTemplate;
+import cn.com.ctop.alarm.modules.entity.vo.TemplateAppliedVo;
 import com.alibaba.fastjson.JSONObject;
 import com.baomidou.mybatisplus.extension.service.IService;
 
+import java.util.List;
+import java.util.Map;
+
 /**
  * @Description: 规则模板
  * @Author: jeecg-boot
@@ -14,4 +18,7 @@ public interface IRuleAccountTemplateService extends IService<RuleAccountTemplat
 
     // 推送模板到账户下
     JSONObject pushTemplateToAccount(Long accountId, Long templateId) throws Exception;
+
+    // 查询 名下账户 应用的模板
+    List<TemplateAppliedVo> getTemplateApplied(Map<String, Object> requestMap);
 }

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

@@ -1,6 +1,7 @@
 package cn.com.ctop.alarm.modules.service.impl;
 
 import cn.com.ctop.alarm.modules.entity.*;
+import cn.com.ctop.alarm.modules.entity.vo.TemplateAppliedVo;
 import cn.com.ctop.alarm.modules.mapper.RuleAccountTemplateMapper;
 import cn.com.ctop.alarm.modules.service.*;
 import cn.com.ctop.common.module.utils.Check;
@@ -11,6 +12,7 @@ import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.stereotype.Service;
 
 import java.util.HashMap;
+import java.util.List;
 import java.util.Map;
 
 /**
@@ -92,4 +94,16 @@ public class RuleAccountTemplateServiceImpl extends ServiceImpl<RuleAccountTempl
         returnJson.put("groupCount", groupCount);
         return returnJson;
     }
+
+
+    /**
+     * 查询 账户下 应用的模板
+     *
+     * @param requestMap
+     * @return
+     */
+    @Override
+    public List<TemplateAppliedVo> getTemplateApplied(Map<String, Object> requestMap) {
+        return ruleAccountTemplateMapper.getTemplateApplied(requestMap);
+    }
 }

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

@@ -1,6 +1,9 @@
 package cn.com.ctop.alarm.modules.service.impl;
 
 import cn.com.ctop.alarm.modules.constant.MatchLogic;
+import cn.com.ctop.alarm.modules.entity.*;
+import cn.com.ctop.alarm.modules.mapper.*;
+import cn.com.ctop.alarm.modules.entity.AlarmEventRule;
 import cn.com.ctop.alarm.modules.entity.RuleAccountTemplate;
 import cn.com.ctop.alarm.modules.entity.RuleAccountThreshold;
 import cn.com.ctop.alarm.modules.entity.RuleBase;
@@ -105,7 +108,6 @@ public class RuleGroupServiceImpl extends ServiceImpl<RuleGroupMapper, RuleGroup
      *
      * @param ruleGroups   规则集
      * @param thresholdObj 规则id阈值
-     * @param matchData    匹配数据
      * @param indicators   指标码
      * @return void
      * @throws
@@ -407,6 +409,7 @@ public class RuleGroupServiceImpl extends ServiceImpl<RuleGroupMapper, RuleGroup
                     ruleBase.setVariableType(ruleDetailJson.getInteger("variableType"));
                     ruleBase.setRuleDimension(ruleDetailJson.getString("ruleDimension"));
                     ruleBase.setJudgeFormat(ruleDetailJson.getInteger("judgeFormat"));
+                    ruleBase.setIsUnlimited(ruleDetailJson.getBoolean("isUnlimited"));
                     int insert = ruleBaseMapper.insert(ruleBase);  // 添加基础规则
                     if (insert > 0) {
                         if (!Check.isNull(accountList)) {

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

@@ -91,7 +91,7 @@ public class RuleTemplateServiceImpl extends ServiceImpl<RuleTemplateMapper, Rul
                                 ruleBase.setVariableType(ruleDetailJson.getInteger("variableType"));
                                 ruleBase.setRuleDimension(ruleDetailJson.getString("ruleDimension"));
                                 ruleBase.setJudgeFormat(ruleDetailJson.getInteger("judgeFormat"));
-
+                                ruleBase.setIsUnlimited(ruleDetailJson.getBoolean("isUnlimited"));
                                 int insert = ruleBaseMapper.insert(ruleBase);
                                 if (insert > 0) {
                                     ruleIds.add(ruleBase.getId());
@@ -216,6 +216,7 @@ public class RuleTemplateServiceImpl extends ServiceImpl<RuleTemplateMapper, Rul
                 ruleJson.put("threshold", ruleBase.getThreshold());
                 ruleJson.put("ruleDimension", ruleBase.getRuleDimension());
                 ruleJson.put("variableType", ruleBase.getVariableType());
+                ruleJson.put("isUnlimited", ruleBase.getIsUnlimited());
                 /**
                  * 查询指标对应信息
                  */
@@ -310,6 +311,7 @@ public class RuleTemplateServiceImpl extends ServiceImpl<RuleTemplateMapper, Rul
                 }
                 ruleJson.put("ruleDimension", ruleBase.getRuleDimension());
                 ruleJson.put("variableType", ruleBase.getVariableType());
+                ruleJson.put("isUnlimited", ruleBase.getIsUnlimited());
                 /**
                  * 查询指标对应信息
                  */