yumeng 4 yıl önce
ebeveyn
işleme
ee1a53e967

+ 23 - 29
module-alarm/src/main/java/cn/com/ctop/alarm/modules/controller/RuleIndicatorController.java

@@ -3,10 +3,10 @@ package cn.com.ctop.alarm.modules.controller;
 import cn.com.ctop.alarm.modules.entity.RuleIndicator;
 import cn.com.ctop.alarm.modules.service.IRuleIndicatorService;
 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;
 import io.swagger.annotations.Api;
 import io.swagger.annotations.ApiOperation;
 import lombok.extern.slf4j.Slf4j;
@@ -19,15 +19,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,28 +48,30 @@ public class RuleIndicatorController {
     @Autowired
     private IRuleIndicatorService ruleIndicatorService;
 
-    /**
-     * 分页列表查询
-     *
-     * @param ruleIndicator
-     * @param pageNo
-     * @param pageSize
-     * @param req
-     * @return
-     */
+
     @AutoLog(value = "规则指标信息-分页列表查询")
     @ApiOperation(value = "规则指标信息-分页列表查询", notes = "规则指标信息-分页列表查询")
     @GetMapping(value = "/list")
-    public Result<IPage<RuleIndicator>> queryPageList(RuleIndicator ruleIndicator,
-                                                      @RequestParam(name = "pageNo", defaultValue = "1") Integer pageNo,
-                                                      @RequestParam(name = "pageSize", defaultValue = "10") Integer pageSize,
-                                                      HttpServletRequest req) {
-        Result<IPage<RuleIndicator>> result = new Result<>();
-        QueryWrapper<RuleIndicator> queryWrapper = QueryGenerator.initQueryWrapper(ruleIndicator, req.getParameterMap());
-        Page<RuleIndicator> page = new Page<RuleIndicator>(pageNo, pageSize);
-        IPage<RuleIndicator> pageList = ruleIndicatorService.page(page, queryWrapper);
+    public Result<JSONObject> queryPageList(RuleIndicator ruleIndicator) {
+        Result<JSONObject> result = new Result<>();
+        Integer mediaType = ruleIndicator.getMediaType();
+        QueryWrapper<RuleIndicator> queryWrapper = new QueryWrapper();
+        queryWrapper.eq("media_type", mediaType);
+        queryWrapper.groupBy("dimension");
+        List<RuleIndicator> list = ruleIndicatorService.list(queryWrapper);
+        JSONObject dataJson = new JSONObject();
+        for (RuleIndicator indicator : list) {
+            String dimension = indicator.getDimension();
+            QueryWrapper<RuleIndicator> queryWrapperData = new QueryWrapper();
+            queryWrapperData.eq("media_type", mediaType);
+            queryWrapperData.eq("dimension", dimension);
+            List<RuleIndicator> dataList = ruleIndicatorService.list(queryWrapperData);
+            if (!Check.isNull(dataList)) {
+                dataJson.put(dimension, dataList);
+            }
+        }
         result.setSuccess(true);
-        result.setResult(pageList);
+        result.setResult(dataJson);
         return result;
     }
 

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

@@ -3,7 +3,9 @@ package cn.com.ctop.alarm.modules.controller;
 import cn.com.ctop.alarm.modules.entity.RuleTemplate;
 import cn.com.ctop.alarm.modules.service.IRuleTemplateService;
 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;
@@ -81,6 +75,38 @@ public class RuleTemplateController {
         return result;
     }
 
+
+    /**
+     * 添加
+     *
+     * @param requestJson
+     * @return
+     */
+    @AutoLog(value = "创建规则模板")
+
+    @PostMapping(value = "/creativeTemplate")
+    public Result add(@RequestBody JSONObject requestJson) {
+        Result result = new Result<>();
+        try {
+            if (Check.isNull(requestJson)) {
+                throw new Exception("请传入模板入参");
+            }
+            JSONObject returnJson = ruleTemplateService.creativeTemplate(requestJson);
+            if (returnJson.getInteger("code") == 0) {
+                result.setSuccess(true);
+                result.setMessage(returnJson.getString("message"));
+            } else {
+                result.setSuccess(false);
+                result.setMessage(returnJson.getString("message"));
+            }
+        } catch (Exception e) {
+            result.setSuccess(false);
+            result.setMessage(e.getMessage());
+        }
+        return result;
+    }
+
+
     /**
      * 添加
      *

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

@@ -49,7 +49,7 @@ public class RuleBase {
      */
     @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

@@ -38,6 +38,7 @@ public class RuleGroup {
     @Excel(name = "规则id列表", width = 15)
     @ApiModelProperty(value = "规则id列表")
     private String ruleIds;
+    private String groupName;
     /**
      * 规则类型 group为组合规则 base 为单条规则
      */

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

@@ -37,7 +37,7 @@ public class RuleIndicator {
      */
     @Excel(name = "1:头条2:快手", width = 15)
     @ApiModelProperty(value = "1:头条2:快手")
-    private Long mediaType;
+    private Integer mediaType;
     /**
      * 指标名称
      */

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

@@ -37,7 +37,7 @@ public class RuleTemplate {
      */
     @Excel(name = "1:头条2:快手", width = 15)
     @ApiModelProperty(value = "1:头条2:快手")
-    private Long mediaType;
+    private Integer mediaType;
     /**
      * 模板名称
      */

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

@@ -1,6 +1,7 @@
 package cn.com.ctop.alarm.modules.service;
 
 import cn.com.ctop.alarm.modules.entity.RuleTemplate;
+import com.alibaba.fastjson.JSONObject;
 import com.baomidou.mybatisplus.extension.service.IService;
 
 /**
@@ -11,4 +12,5 @@ import com.baomidou.mybatisplus.extension.service.IService;
  */
 public interface IRuleTemplateService extends IService<RuleTemplate> {
 
+    JSONObject creativeTemplate(JSONObject requestJson);
 }

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

@@ -1,19 +1,124 @@
 package cn.com.ctop.alarm.modules.service.impl;
 
+import cn.com.ctop.alarm.modules.entity.RuleBase;
+import cn.com.ctop.alarm.modules.entity.RuleGroup;
 import cn.com.ctop.alarm.modules.entity.RuleTemplate;
+import cn.com.ctop.alarm.modules.mapper.RuleBaseMapper;
 import cn.com.ctop.alarm.modules.mapper.RuleTemplateMapper;
+import cn.com.ctop.alarm.modules.service.IRuleBaseService;
+import cn.com.ctop.alarm.modules.service.IRuleGroupService;
 import cn.com.ctop.alarm.modules.service.IRuleTemplateService;
-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 RuleTemplateServiceImpl extends ServiceImpl<RuleTemplateMapper, RuleTemplate> implements IRuleTemplateService {
+    @Autowired
+    private IRuleBaseService ruleBaseService;
+
+    @Autowired
+    private RuleBaseMapper ruleBaseMapper;
+
+    @Autowired
+    private IRuleGroupService ruleGroupService;
+
+    /**
+     * 创建规则模板
+     *
+     * @param requestJson
+     * @return
+     */
+    @Override
+    public JSONObject creativeTemplate(JSONObject requestJson) {
+        System.err.println(requestJson);
+        JSONObject returnJson = new JSONObject();
+        try {
+            Integer mediaType = requestJson.getInteger("mediaType");
+            if (Check.isNull(mediaType)) {
+                throw new Exception("请传入媒体类型");
+            }
+            String templateName = requestJson.getString("templateName");
+            if (Check.isNull(templateName)) {
+                throw new Exception("请传入模板名称");
+            }
+            QueryWrapper<RuleTemplate> queryQueryWrapper = new QueryWrapper<>();
+            queryQueryWrapper.eq("media_type", mediaType);
+            queryQueryWrapper.eq("template_name", templateName);
+            RuleTemplate ruleTemplate = this.getOne(queryQueryWrapper);
+            if (!Check.isNull(ruleTemplate)) {
+                throw new Exception("同媒体下模板名称不能相同");
+            }
+            RuleTemplate template = new RuleTemplate();
+            template.setMediaType(mediaType);
+            template.setTemplateName(templateName);
+
+            JSONArray groupIds = new JSONArray();
+
+            JSONArray ruleList = requestJson.getJSONArray("ruleList"); // 模板规则详情
+            if (Check.isNull(ruleList)) {
+                throw new Exception("模板具体规则不能为空");
+            }
+            for (int i = 0; i < ruleList.size(); i++) {
+                JSONObject ruleGroupJson = ruleList.getJSONObject(i);
+                if (!Check.isNull(ruleGroupJson)) {
+                    JSONArray ruleDetailArr = ruleGroupJson.getJSONArray("ruleDetail");
+                    if (!Check.isNull(ruleDetailArr)) {
+                        JSONArray ruleIds = new JSONArray();
+                        for (int j = 0; j < ruleDetailArr.size(); j++) {
+                            JSONObject ruleDetailJson = ruleDetailArr.getJSONObject(j);
+                            if (!Check.isNull(ruleDetailJson)) {
+                                RuleBase ruleBase = new RuleBase();
+                                ruleBase.setRuleName(ruleDetailJson.getString("ruleName"));
+                                ruleBase.setIndicatorCode(ruleDetailJson.getString("indicatorCode"));
+                                ruleBase.setRuleCondition(ruleDetailJson.getString("ruleCondition"));
+                                ruleBase.setThreshold(ruleDetailJson.getString("threshold"));
+                                ruleBase.setVariableType(ruleDetailJson.getInteger("variableType"));
+                                ruleBase.setRuleDimension(ruleDetailJson.getString("ruleDimension"));
+                                int insert = ruleBaseMapper.insert(ruleBase);
+                                if (insert > 0) {
+                                    ruleIds.add(ruleBase.getId());
+                                }
+                            }
+                        }
+
+                        RuleGroup ruleGroup = new RuleGroup();
+                        ruleGroup.setRuleIds(ruleIds.toJSONString());
+                        ruleGroup.setRuleType(ruleGroupJson.getString("ruleType"));
+                        ruleGroup.setRuleRelationship(ruleGroupJson.getString("ruleRelationship"));
+                        ruleGroup.setGroupName(ruleGroupJson.getString("groupName"));
+                        ruleGroup.setExplain(ruleGroupJson.getString("explain"));
+                        boolean save = ruleGroupService.save(ruleGroup);
+                        if (save) {
+                            groupIds.add(ruleGroup.getId());
+
+                        }
+                    }
+                }
+            }
+            template.setGroupIds(groupIds.toJSONString());
+            this.save(template);
+            returnJson.put("code", 0);
+            returnJson.put("message", "创建成功");
+
+
+        } catch (Exception e) {
+            e.printStackTrace();
+            returnJson.put("code", -1);
+            returnJson.put("message", e.getMessage());
+        }
 
+        return returnJson;
+    }
 }