Parcourir la source

Merge remote-tracking branch 'origin/master'

# Conflicts:
#	jeecg-boot-module-system/src/test/java/org/jeecg/SampleTest.java
syh il y a 4 ans
Parent
commit
106675615b
76 fichiers modifiés avec 4611 ajouts et 1072 suppressions
  1. 5 3
      jeecg-boot-module-system/src/main/java/org/jeecg/modules/ctop/controller/TestController.java
  2. 658 654
      jeecg-boot-module-system/src/main/java/org/jeecg/modules/system/service/impl/SysBaseApiImpl.java
  3. 3 3
      jeecg-boot-module-system/src/main/resources/application-dev.yml
  4. 8 10
      module-alarm/src/main/java/cn/com/ctop/alarm/modules/controller/AlarmEventRuleController.java
  5. 25 0
      module-alarm/src/main/java/cn/com/ctop/alarm/modules/controller/AlarmEventSendController.java
  6. 2 2
      module-alarm/src/main/java/cn/com/ctop/alarm/modules/controller/AlarmMetricValueController.java
  7. 231 0
      module-alarm/src/main/java/cn/com/ctop/alarm/modules/controller/AlarmRuleCampaignRelController.java
  8. 24 14
      module-alarm/src/main/java/cn/com/ctop/alarm/modules/entity/AlarmEventRule.java
  9. 2 0
      module-alarm/src/main/java/cn/com/ctop/alarm/modules/entity/AlarmEventSend.java
  10. 8 6
      module-alarm/src/main/java/cn/com/ctop/alarm/modules/entity/AlarmMetricValue.java
  11. 80 0
      module-alarm/src/main/java/cn/com/ctop/alarm/modules/entity/AlarmRuleCampaignRel.java
  12. 44 0
      module-alarm/src/main/java/cn/com/ctop/alarm/modules/enums/StatusEnum.java
  13. 2 2
      module-alarm/src/main/java/cn/com/ctop/alarm/modules/mapper/AlarmEventMetricMapper.java
  14. 1 1
      module-alarm/src/main/java/cn/com/ctop/alarm/modules/mapper/AlarmEventRuleMapper.java
  15. 1 0
      module-alarm/src/main/java/cn/com/ctop/alarm/modules/mapper/AlarmMetricValueMapper.java
  16. 20 0
      module-alarm/src/main/java/cn/com/ctop/alarm/modules/mapper/AlarmRuleCampaignRelMapper.java
  17. 12 1
      module-alarm/src/main/java/cn/com/ctop/alarm/modules/mapper/xml/AlarmEventRuleMapper.xml
  18. 8 1
      module-alarm/src/main/java/cn/com/ctop/alarm/modules/mapper/xml/AlarmMetricValueMapper.xml
  19. 18 0
      module-alarm/src/main/java/cn/com/ctop/alarm/modules/mapper/xml/AlarmRuleCampaignRelMapper.xml
  20. 5 6
      module-alarm/src/main/java/cn/com/ctop/alarm/modules/service/IAlarmEventRuleService.java
  21. 5 1
      module-alarm/src/main/java/cn/com/ctop/alarm/modules/service/IAlarmEventSendService.java
  22. 14 0
      module-alarm/src/main/java/cn/com/ctop/alarm/modules/service/IAlarmRuleCampaignRelService.java
  23. 192 279
      module-alarm/src/main/java/cn/com/ctop/alarm/modules/service/impl/AlarmEventRuleServiceImpl.java
  24. 454 2
      module-alarm/src/main/java/cn/com/ctop/alarm/modules/service/impl/AlarmEventSendServiceImpl.java
  25. 4 1
      module-alarm/src/main/java/cn/com/ctop/alarm/modules/service/impl/AlarmMetricValueServiceImpl.java
  26. 19 0
      module-alarm/src/main/java/cn/com/ctop/alarm/modules/service/impl/AlarmRuleCampaignRelServiceImpl.java
  27. 248 0
      module-common/src/main/java/cn/com/ctop/common/module/controller/WarningOperationLogController.java
  28. 2 1
      module-common/src/main/java/cn/com/ctop/common/module/entity/Project.java
  29. 3 0
      module-common/src/main/java/cn/com/ctop/common/module/entity/UserAllocation.java
  30. 75 0
      module-common/src/main/java/cn/com/ctop/common/module/entity/WarningOperationLog.java
  31. 3 0
      module-common/src/main/java/cn/com/ctop/common/module/mapper/ProjectMapper.java
  32. 2 0
      module-common/src/main/java/cn/com/ctop/common/module/mapper/UserAllocationMapper.java
  33. 15 0
      module-common/src/main/java/cn/com/ctop/common/module/mapper/WarningOperationLogMapper.java
  34. 11 0
      module-common/src/main/java/cn/com/ctop/common/module/mapper/xml/ProjectMapper.xml
  35. 6 0
      module-common/src/main/java/cn/com/ctop/common/module/mapper/xml/UserAllocationMapper.xml
  36. 5 0
      module-common/src/main/java/cn/com/ctop/common/module/mapper/xml/WarningOperationLogMapper.xml
  37. 23 0
      module-common/src/main/java/cn/com/ctop/common/module/service/IMessageTemplate.java
  38. 14 0
      module-common/src/main/java/cn/com/ctop/common/module/service/IWarningOperationLogService.java
  39. 39 0
      module-common/src/main/java/cn/com/ctop/common/module/service/impl/MessageTemplateImpl.java
  40. 19 0
      module-common/src/main/java/cn/com/ctop/common/module/service/impl/WarningOperationLogServiceImpl.java
  41. 49 0
      module-common/src/main/java/cn/com/ctop/common/module/utils/KuaishouInterfaceConstant.java
  42. 3 3
      module-job-kuaishou/src/main/java/cn/com/ctop/job/kuaishou/handler/KuaiShouAlarmRuleHourlyCheckJob.java
  43. 3 3
      module-job-kuaishou/src/main/java/cn/com/ctop/job/kuaishou/handler/KuaiShouAlarmRuleMinuteCheckJob.java
  44. 317 0
      module-kuaishou/src/main/java/cn/com/ctop/kuaishou/modules/batch/controller/KuaishouTemplateController.java
  45. 248 0
      module-kuaishou/src/main/java/cn/com/ctop/kuaishou/modules/batch/controller/KuaishouTemplateTargetController.java
  46. 4 0
      module-kuaishou/src/main/java/cn/com/ctop/kuaishou/modules/batch/entity/KuaiShouGroup.java
  47. 68 0
      module-kuaishou/src/main/java/cn/com/ctop/kuaishou/modules/batch/entity/KuaishouTemplate.java
  48. 212 0
      module-kuaishou/src/main/java/cn/com/ctop/kuaishou/modules/batch/entity/KuaishouTemplateTarget.java
  49. 2 0
      module-kuaishou/src/main/java/cn/com/ctop/kuaishou/modules/batch/mapper/KuaiShouCampaignMapper.java
  50. 3 0
      module-kuaishou/src/main/java/cn/com/ctop/kuaishou/modules/batch/mapper/KuaiShouGroupMapper.java
  51. 15 0
      module-kuaishou/src/main/java/cn/com/ctop/kuaishou/modules/batch/mapper/KuaishouTemplateMapper.java
  52. 15 0
      module-kuaishou/src/main/java/cn/com/ctop/kuaishou/modules/batch/mapper/KuaishouTemplateTargetMapper.java
  53. 8 0
      module-kuaishou/src/main/java/cn/com/ctop/kuaishou/modules/batch/mapper/xml/KuaiShouCampaignMapper.xml
  54. 13 0
      module-kuaishou/src/main/java/cn/com/ctop/kuaishou/modules/batch/mapper/xml/KuaiShouGroupMapper.xml
  55. 5 0
      module-kuaishou/src/main/java/cn/com/ctop/kuaishou/modules/batch/mapper/xml/KuaishouTemplateMapper.xml
  56. 5 0
      module-kuaishou/src/main/java/cn/com/ctop/kuaishou/modules/batch/mapper/xml/KuaishouTemplateTargetMapper.xml
  57. 1 0
      module-kuaishou/src/main/java/cn/com/ctop/kuaishou/modules/batch/service/IKuaiShouCampaignCreateService.java
  58. 89 0
      module-kuaishou/src/main/java/cn/com/ctop/kuaishou/modules/batch/service/IKuaishouPopulationService.java
  59. 21 0
      module-kuaishou/src/main/java/cn/com/ctop/kuaishou/modules/batch/service/IKuaishouTemplateService.java
  60. 14 0
      module-kuaishou/src/main/java/cn/com/ctop/kuaishou/modules/batch/service/IKuaishouTemplateTargetService.java
  61. 31 0
      module-kuaishou/src/main/java/cn/com/ctop/kuaishou/modules/batch/service/IWarningOperationService.java
  62. 67 7
      module-kuaishou/src/main/java/cn/com/ctop/kuaishou/modules/batch/service/impl/KuaiShouGroupServiceImpl.java
  63. 68 11
      module-kuaishou/src/main/java/cn/com/ctop/kuaishou/modules/batch/service/impl/KuaishouInterfaceServiceImpl.java
  64. 311 0
      module-kuaishou/src/main/java/cn/com/ctop/kuaishou/modules/batch/service/impl/KuaishouPopulationServiceImpl.java
  65. 447 0
      module-kuaishou/src/main/java/cn/com/ctop/kuaishou/modules/batch/service/impl/KuaishouTemplateServiceImpl.java
  66. 19 0
      module-kuaishou/src/main/java/cn/com/ctop/kuaishou/modules/batch/service/impl/KuaishouTemplateTargetServiceImpl.java
  67. 116 0
      module-kuaishou/src/main/java/cn/com/ctop/kuaishou/modules/batch/service/impl/WarningOperationServiceImpl.java
  68. 0 24
      module-kuaishou/src/main/java/cn/com/ctop/kuaishou/modules/report/controller/KuaishouCostGroupController.java
  69. 1 9
      module-kuaishou/src/main/java/cn/com/ctop/kuaishou/modules/report/entity/KuaishouCostGroup.java
  70. 4 2
      module-kuaishou/src/main/java/cn/com/ctop/kuaishou/modules/report/mapper/KuaishouCostGroupMapper.java
  71. 55 19
      module-kuaishou/src/main/java/cn/com/ctop/kuaishou/modules/report/mapper/xml/KuaishouCostGroupMapper.xml
  72. 30 7
      module-kuaishou/src/main/java/cn/com/ctop/kuaishou/modules/report/service/impl/KuaishouCostGroupServiceImpl.java
  73. 9 0
      module-kuaishou/src/main/java/cn/com/ctop/kuaishou/modules/report/service/impl/KuaishouZombieCreativeServiceImpl.java
  74. 4 0
      module-toutiao/src/main/java/cn/com/ctop/toutiao/modules/material/service/IByteDanceAdvertiserDataService.java
  75. 43 0
      module-toutiao/src/main/java/cn/com/ctop/toutiao/modules/material/service/impl/ByteDanceAdvertiserDataServiceImpl.java
  76. 1 0
      module-toutiao/src/main/java/cn/com/ctop/toutiao/modules/report/mapper/xml/BytedanceVideoReportMapper.xml

+ 5 - 3
jeecg-boot-module-system/src/main/java/org/jeecg/modules/ctop/controller/TestController.java

@@ -708,7 +708,7 @@ public class TestController {
             List<CtopOauthToken> ctopOauthTokens = oauthTokenMapper.selectList(tokenQueryWrapper);
             List<CtopOauthToken> ctopOauthTokens = oauthTokenMapper.selectList(tokenQueryWrapper);
             if (!Check.isNull(ctopOauthTokens)) {
             if (!Check.isNull(ctopOauthTokens)) {
                 for (CtopOauthToken token : ctopOauthTokens) {
                 for (CtopOauthToken token : ctopOauthTokens) {
-                    historyReportTaskService.createTask(token.getAccountId(), token.getAccessToken(), startDate, endDateStr, CtopAdConstant.KUAISHOU_LOAD_JOB_TYPE_HISTORY);
+                    historyReportTaskService.createTask(token.getAccountId(), token.getAccessToken(), "2020-09-01", "2020-10-01", CtopAdConstant.KUAISHOU_LOAD_JOB_TYPE_HISTORY);
                 }
                 }
 
 
             }
             }
@@ -868,9 +868,11 @@ public class TestController {
         oauthTokenQueryWrapper.last("limit 1");
         oauthTokenQueryWrapper.last("limit 1");
         CtopOauthToken token = oauthTokenMapper.selectOne(oauthTokenQueryWrapper);
         CtopOauthToken token = oauthTokenMapper.selectOne(oauthTokenQueryWrapper);
         try {
         try {
-            kuaishouInterfaceService.getCampaignList(token, null, null);
+            // kuaishouInterfaceService.getCampaignList(token, null, null);
             //1:获取全量广告组数据
             //1:获取全量广告组数据
-            kuaishouInterfaceService.getGroupList(token, null, null);
+            SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd");
+            Date parse = simpleDateFormat.parse("2020-11-11");
+            kuaishouInterfaceService.getGroupList(token, parse, parse);
         } catch (Exception e) {
         } catch (Exception e) {
             e.printStackTrace();
             e.printStackTrace();
         }
         }

Fichier diff supprimé car celui-ci est trop grand
+ 658 - 654
jeecg-boot-module-system/src/main/java/org/jeecg/modules/system/service/impl/SysBaseApiImpl.java


+ 3 - 3
jeecg-boot-module-system/src/main/resources/application-dev.yml

@@ -135,9 +135,9 @@ spring:
         connectionProperties: druid.stat.mergeSql\=true;druid.stat.slowSqlMillis\=5000
         connectionProperties: druid.stat.mergeSql\=true;druid.stat.slowSqlMillis\=5000
       datasource:
       datasource:
         master:
         master:
-          url: jdbc:mysql://139.186.31.213:3306/jeecg-boot?characterEncoding=UTF-8&useUnicode=true
-          username: hcst
-          password: hcst2020
+          url: jdbc:mysql://127.0.0.1:3306/jeecg-boot?characterEncoding=UTF-8&useUnicode=true
+          username: root
+          password: root
           driver-class-name: com.mysql.jdbc.Driver
           driver-class-name: com.mysql.jdbc.Driver
           # 多数据源配置
           # 多数据源配置
           #multi-datasource1:
           #multi-datasource1:

+ 8 - 10
module-alarm/src/main/java/cn/com/ctop/alarm/modules/controller/AlarmEventRuleController.java

@@ -113,11 +113,10 @@ public class AlarmEventRuleController {
     @AutoLog(value = "预警事件规则表-添加")
     @AutoLog(value = "预警事件规则表-添加")
     @ApiOperation(value = "预警事件规则表-添加", notes = "预警事件规则表-添加")
     @ApiOperation(value = "预警事件规则表-添加", notes = "预警事件规则表-添加")
     @PostMapping(value = "/add")
     @PostMapping(value = "/add")
-    public Result<AlarmEventRule> addAlarmEventRule(@RequestBody JSONObject obj) {
-        Result<AlarmEventRule> result = new Result<>();
+    public Result<Object> addAlarmEventRule(@RequestBody JSONObject obj) {
+        Result<Object> result = new Result<>();
         try {
         try {
-            alarmEventRuleService.addAlarmEventRule(obj);
-            result.success("添加成功!");
+            result = alarmEventRuleService.addAlarmEventRule(obj);
         } catch (Exception e) {
         } catch (Exception e) {
             log.error(e.getMessage(), e);
             log.error(e.getMessage(), e);
             result.error500("操作失败");
             result.error500("操作失败");
@@ -134,11 +133,10 @@ public class AlarmEventRuleController {
     @AutoLog(value = "预警事件规则表-编辑")
     @AutoLog(value = "预警事件规则表-编辑")
     @ApiOperation(value = "预警事件规则表-编辑", notes = "预警事件规则表-编辑")
     @ApiOperation(value = "预警事件规则表-编辑", notes = "预警事件规则表-编辑")
     @PostMapping(value = "/edit")
     @PostMapping(value = "/edit")
-    public Result<AlarmEventRule> editAlarmEventRule(@RequestBody JSONObject obj) {
-        Result<AlarmEventRule> result = new Result<>();
+    public Result<Object> editAlarmEventRule(@RequestBody JSONObject obj) {
+        Result<Object> result = new Result<>();
         try {
         try {
-            alarmEventRuleService.editAlarmEventRule(obj);
-            result.success("修改成功!");
+            result = alarmEventRuleService.editAlarmEventRule(obj);
         } catch (Exception e) {
         } catch (Exception e) {
             log.error(e.getMessage(), e);
             log.error(e.getMessage(), e);
             result.error500("操作失败");
             result.error500("操作失败");
@@ -155,7 +153,7 @@ public class AlarmEventRuleController {
     @AutoLog(value = "预警事件规则表-通过id删除")
     @AutoLog(value = "预警事件规则表-通过id删除")
     @ApiOperation(value = "预警事件规则表-通过id删除", notes = "预警事件规则表-通过id删除")
     @ApiOperation(value = "预警事件规则表-通过id删除", notes = "预警事件规则表-通过id删除")
     @GetMapping(value = "/delete")
     @GetMapping(value = "/delete")
-    public Result<?> delete(String id) {
+    public Result<?> delete(Long id) {
         try {
         try {
             alarmEventRuleService.deleteById(id);
             alarmEventRuleService.deleteById(id);
         } catch (Exception e) {
         } catch (Exception e) {
@@ -194,7 +192,7 @@ public class AlarmEventRuleController {
     @AutoLog(value = "预警事件规则表-通过id查询")
     @AutoLog(value = "预警事件规则表-通过id查询")
     @ApiOperation(value = "预警事件规则表-通过id查询", notes = "预警事件规则表-通过id查询")
     @ApiOperation(value = "预警事件规则表-通过id查询", notes = "预警事件规则表-通过id查询")
     @GetMapping(value = "/queryById")
     @GetMapping(value = "/queryById")
-    public Result<AlarmEventRule> queryById(@RequestParam(name = "id", required = true) String id) {
+    public Result<AlarmEventRule> queryById(@RequestParam(name = "id", required = true) Long id) {
         Result<AlarmEventRule> result = new Result<>();
         Result<AlarmEventRule> result = new Result<>();
         AlarmEventRule alarmEventRule = alarmEventRuleService.selectById(id);
         AlarmEventRule alarmEventRule = alarmEventRuleService.selectById(id);
         if (alarmEventRule == null) {
         if (alarmEventRule == null) {

+ 25 - 0
module-alarm/src/main/java/cn/com/ctop/alarm/modules/controller/AlarmEventSendController.java

@@ -102,6 +102,31 @@ public class AlarmEventSendController {
         return result;
         return result;
     }
     }
 
 
+    @GetMapping(value = "/matchAlarmRules")
+    public Result<?> matchAlarmRules(String type) {
+        Result<AlarmEventSend> result = new Result<>();
+        try {
+            alarmEventSendService.matchAlarmRules(type);
+            result.success("操作成功!");
+        } catch (Exception e) {
+            log.error(e.getMessage(), e);
+            result.error500("操作失败");
+        }
+        return result;
+    }
+
+    @GetMapping(value = "/rechangeValue")
+    public Result<?> rechangeValue(String type) {
+        Result<AlarmEventSend> result = new Result<>();
+        try {
+            alarmEventSendService.getAlarmValue(type);
+            result.success("操作成功!");
+        } catch (Exception e) {
+            log.error(e.getMessage(), e);
+            result.error500("操作失败");
+        }
+        return result;
+    }
     /**
     /**
      * 编辑
      * 编辑
      *
      *

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

@@ -80,8 +80,8 @@ public class AlarmMetricValueController {
         return result;
         return result;
     }
     }
 
 
-    @AutoLog(value = "指标字段记录表-分页列表查询")
-    @ApiOperation(value = "指标字段记录表-分页列表查询", notes = "指标字段记录表-分页列表查询")
+    @AutoLog(value = "指标字段记录表")
+    @ApiOperation(value = "指标字段记录表-分页列表查询", notes = "指标字段记录表")
     @GetMapping(value = "/queryParentChildList")
     @GetMapping(value = "/queryParentChildList")
     public Result<Object> queryParentChildList(AlarmMetricValue alarmMetricValue, HttpServletRequest req) {
     public Result<Object> queryParentChildList(AlarmMetricValue alarmMetricValue, HttpServletRequest req) {
         Result<Object> result = null;
         Result<Object> result = null;

+ 231 - 0
module-alarm/src/main/java/cn/com/ctop/alarm/modules/controller/AlarmRuleCampaignRelController.java

@@ -0,0 +1,231 @@
+package cn.com.ctop.alarm.modules.controller;
+
+import cn.com.ctop.alarm.modules.entity.AlarmRuleCampaignRel;
+import cn.com.ctop.alarm.modules.service.IAlarmRuleCampaignRelService;
+import cn.com.ctop.common.module.annotation.AutoLog;
+import com.alibaba.fastjson.JSON;
+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;
+import org.jeecg.common.api.vo.Result;
+import org.jeecg.common.system.query.QueryGenerator;
+import org.jeecg.common.util.oConvertUtils;
+import org.jeecgframework.poi.excel.ExcelImportUtil;
+import org.jeecgframework.poi.excel.def.NormalExcelConstants;
+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.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.multipart.MultipartFile;
+import org.springframework.web.multipart.MultipartHttpServletRequest;
+import org.springframework.web.servlet.ModelAndView;
+
+import javax.servlet.http.HttpServletRequest;
+import javax.servlet.http.HttpServletResponse;
+import java.io.IOException;
+import java.io.UnsupportedEncodingException;
+import java.net.URLDecoder;
+import java.util.Arrays;
+import java.util.List;
+import java.util.Map;
+
+/**
+ * 规则和计划、组关系表
+ *
+ * @author jeecg-boot
+ * @version V1.0
+ * @date 2020-11-09
+ */
+@Slf4j
+@Api(tags = "规则和计划、组关系表")
+@RestController
+@RequestMapping("/alarm.modules/alarmRuleCampaignRel")
+public class AlarmRuleCampaignRelController {
+    @Autowired
+    private IAlarmRuleCampaignRelService alarmRuleCampaignRelService;
+
+    /**
+     * 分页列表查询
+     *
+     * @param alarmRuleCampaignRel
+     * @param pageNo
+     * @param pageSize
+     * @param req
+     * @return
+     */
+    @AutoLog(value = "规则和计划、组关系表-分页列表查询")
+    @ApiOperation(value = "规则和计划、组关系表-分页列表查询", notes = "规则和计划、组关系表-分页列表查询")
+    @GetMapping(value = "/list")
+    public Result<IPage<AlarmRuleCampaignRel>> queryPageList(AlarmRuleCampaignRel alarmRuleCampaignRel,
+                                                             @RequestParam(name = "pageNo", defaultValue = "1") Integer pageNo,
+                                                             @RequestParam(name = "pageSize", defaultValue = "10") Integer pageSize,
+                                                             HttpServletRequest req) {
+        Result<IPage<AlarmRuleCampaignRel>> result = new Result<>();
+        QueryWrapper<AlarmRuleCampaignRel> queryWrapper = QueryGenerator.initQueryWrapper(alarmRuleCampaignRel, req.getParameterMap());
+        Page<AlarmRuleCampaignRel> page = new Page<AlarmRuleCampaignRel>(pageNo, pageSize);
+        IPage<AlarmRuleCampaignRel> pageList = alarmRuleCampaignRelService.page(page, queryWrapper);
+        result.setSuccess(true);
+        result.setResult(pageList);
+        return result;
+    }
+
+    /**
+     * 添加
+     *
+     * @param alarmRuleCampaignRel
+     * @return
+     */
+    @AutoLog(value = "规则和计划、组关系表-添加")
+    @ApiOperation(value = "规则和计划、组关系表-添加", notes = "规则和计划、组关系表-添加")
+    @PostMapping(value = "/add")
+    public Result<AlarmRuleCampaignRel> add(@RequestBody AlarmRuleCampaignRel alarmRuleCampaignRel) {
+        Result<AlarmRuleCampaignRel> result = new Result<>();
+        try {
+            alarmRuleCampaignRelService.save(alarmRuleCampaignRel);
+            result.success("添加成功!");
+        } catch (Exception e) {
+            log.error(e.getMessage(), e);
+            result.error500("操作失败");
+        }
+        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 {
+            alarmRuleCampaignRelService.removeById(id);
+        } catch (Exception e) {
+            log.error("删除失败", e.getMessage());
+            return Result.error("删除失败!");
+        }
+        return Result.ok("删除成功!");
+    }
+
+    /**
+     * 批量删除
+     *
+     * @param ids
+     * @return
+     */
+    @AutoLog(value = "规则和计划、组关系表-批量删除")
+    @ApiOperation(value = "规则和计划、组关系表-批量删除", notes = "规则和计划、组关系表-批量删除")
+    @DeleteMapping(value = "/deleteBatch")
+    public Result<AlarmRuleCampaignRel> deleteBatch(@RequestParam(name = "ids", required = true) String ids) {
+        Result<AlarmRuleCampaignRel> result = new Result<>();
+        if (ids == null || "".equals(ids.trim())) {
+            result.error500("参数不识别!");
+        } else {
+            this.alarmRuleCampaignRelService.removeByIds(Arrays.asList(ids.split(",")));
+            result.success("删除成功!");
+        }
+        return result;
+    }
+
+    /**
+     * 通过id查询
+     *
+     * @param id
+     * @return
+     */
+    @AutoLog(value = "规则和计划、组关系表-通过id查询")
+    @ApiOperation(value = "规则和计划、组关系表-通过id查询", notes = "规则和计划、组关系表-通过id查询")
+    @GetMapping(value = "/queryById")
+    public Result<AlarmRuleCampaignRel> queryById(@RequestParam(name = "id", required = true) String id) {
+        Result<AlarmRuleCampaignRel> result = new Result<>();
+        AlarmRuleCampaignRel alarmRuleCampaignRel = alarmRuleCampaignRelService.getById(id);
+        if (alarmRuleCampaignRel == null) {
+            result.error500("未找到对应实体");
+        } else {
+            result.setResult(alarmRuleCampaignRel);
+            result.setSuccess(true);
+        }
+        return result;
+    }
+
+    /**
+     * 导出excel
+     *
+     * @param request
+     * @param response
+     */
+    @RequestMapping(value = "/exportXls")
+    public ModelAndView exportXls(HttpServletRequest request, HttpServletResponse response) {
+        // Step.1 组装查询条件
+        QueryWrapper<AlarmRuleCampaignRel> queryWrapper = null;
+        try {
+            String paramsStr = request.getParameter("paramsStr");
+            if (oConvertUtils.isNotEmpty(paramsStr)) {
+                String deString = URLDecoder.decode(paramsStr, "UTF-8");
+                AlarmRuleCampaignRel alarmRuleCampaignRel = JSON.parseObject(deString, AlarmRuleCampaignRel.class);
+                queryWrapper = QueryGenerator.initQueryWrapper(alarmRuleCampaignRel, request.getParameterMap());
+            }
+        } catch (UnsupportedEncodingException e) {
+            e.printStackTrace();
+        }
+
+        //Step.2 AutoPoi 导出Excel
+        ModelAndView mv = new ModelAndView(new JeecgEntityExcelView());
+        List<AlarmRuleCampaignRel> pageList = alarmRuleCampaignRelService.list(queryWrapper);
+        //导出文件名称
+        mv.addObject(NormalExcelConstants.FILE_NAME, "规则和计划、组关系表列表");
+        mv.addObject(NormalExcelConstants.CLASS, AlarmRuleCampaignRel.class);
+        mv.addObject(NormalExcelConstants.PARAMS, new ExportParams("规则和计划、组关系表列表数据", "导出人:Jeecg", "导出信息"));
+        mv.addObject(NormalExcelConstants.DATA_LIST, pageList);
+        return mv;
+    }
+
+    /**
+     * 通过excel导入数据
+     *
+     * @param request
+     * @param response
+     * @return
+     */
+    @RequestMapping(value = "/importExcel", method = RequestMethod.POST)
+    public Result<?> importExcel(HttpServletRequest request, HttpServletResponse response) {
+        MultipartHttpServletRequest multipartRequest = (MultipartHttpServletRequest) request;
+        Map<String, MultipartFile> fileMap = multipartRequest.getFileMap();
+        for (Map.Entry<String, MultipartFile> entity : fileMap.entrySet()) {
+            MultipartFile file = entity.getValue();
+            ImportParams params = new ImportParams();
+            params.setTitleRows(2);
+            params.setHeadRows(1);
+            params.setNeedSave(true);
+            try {
+                List<AlarmRuleCampaignRel> listAlarmRuleCampaignRels = ExcelImportUtil.importExcel(file.getInputStream(), AlarmRuleCampaignRel.class, params);
+                alarmRuleCampaignRelService.saveBatch(listAlarmRuleCampaignRels);
+                return Result.ok("文件导入成功!数据行数:" + listAlarmRuleCampaignRels.size());
+            } catch (Exception e) {
+                log.error(e.getMessage(), e);
+                return Result.error("文件导入失败:" + e.getMessage());
+            } finally {
+                try {
+                    file.getInputStream().close();
+                } catch (IOException e) {
+                    e.printStackTrace();
+                }
+            }
+        }
+        return Result.ok("文件导入失败!");
+    }
+
+}

+ 24 - 14
module-alarm/src/main/java/cn/com/ctop/alarm/modules/entity/AlarmEventRule.java

@@ -29,7 +29,6 @@ import java.util.List;
 @Accessors(chain = true)
 @Accessors(chain = true)
 @ApiModel(value = "ctop_alarm_event_rule对象", description = "预警事件规则表")
 @ApiModel(value = "ctop_alarm_event_rule对象", description = "预警事件规则表")
 public class AlarmEventRule {
 public class AlarmEventRule {
-
     /**
     /**
      * 规则id
      * 规则id
      */
      */
@@ -42,12 +41,9 @@ public class AlarmEventRule {
     @Excel(name = "账户编号", width = 15)
     @Excel(name = "账户编号", width = 15)
     @ApiModelProperty(value = "账户编号")
     @ApiModelProperty(value = "账户编号")
     private Long accountId;
     private Long accountId;
-    /**
-     * 组编号
-     */
-    @Excel(name = "组编号", width = 15)
-    @ApiModelProperty(value = "组编号")
-    private Long unitId;
+
+    private Long campaignId;
+
     /**
     /**
      * 规则名称
      * 规则名称
      */
      */
@@ -78,6 +74,14 @@ public class AlarmEventRule {
     @Excel(name = "规则状态", width = 15)
     @Excel(name = "规则状态", width = 15)
     @ApiModelProperty(value = "规则状态")
     @ApiModelProperty(value = "规则状态")
     private String eventRuleStatus;
     private String eventRuleStatus;
+
+    private String appStatus;
+
+    private String createrId;
+
+    private String metricValueCode;
+
+    private String metricValueName;
     /**
     /**
      * createTime
      * createTime
      */
      */
@@ -96,11 +100,6 @@ public class AlarmEventRule {
     private Date updateTime;
     private Date updateTime;
 
 
     @TableField(exist = false)
     @TableField(exist = false)
-    private List<AlarmEventMetric> alarmEventMetrics;
-
-    private String createrId;
-
-    @TableField(exist = false)
     private String createrName;
     private String createrName;
 
 
     @TableField(exist = false)
     @TableField(exist = false)
@@ -118,8 +117,19 @@ public class AlarmEventRule {
     @TableField(exist = false)
     @TableField(exist = false)
     private String alarmCondition;
     private String alarmCondition;
 
 
-    private String metricValueCode;
+    @TableField(exist = false)
+    private String campaignName;
 
 
-    private String metricValueName;
+    @TableField(exist = false)
+    private Long unitId;
+
+    @TableField(exist = false)
+    private String unitName;
+
+    @TableField(exist = false)
+    private List<AlarmRuleCampaignRel> rel;
+
+    @TableField(exist = false)
+    private List<AlarmEventMetric> alarmEventMetrics;
 
 
 }
 }

+ 2 - 0
module-alarm/src/main/java/cn/com/ctop/alarm/modules/entity/AlarmEventSend.java

@@ -34,6 +34,8 @@ public class AlarmEventSend {
     @TableId(type = IdType.AUTO)
     @TableId(type = IdType.AUTO)
     @ApiModelProperty(value = "主键id")
     @ApiModelProperty(value = "主键id")
     private Long alarmSendId;
     private Long alarmSendId;
+
+    private String userId;
     /**
     /**
      * 规则id
      * 规则id
      */
      */

+ 8 - 6
module-alarm/src/main/java/cn/com/ctop/alarm/modules/entity/AlarmMetricValue.java

@@ -54,12 +54,14 @@ public class AlarmMetricValue {
     @Excel(name = "指标值编码", width = 15)
     @Excel(name = "指标值编码", width = 15)
     @ApiModelProperty(value = "指标值编码")
     @ApiModelProperty(value = "指标值编码")
     private String metricValueCode;
     private String metricValueCode;
-    /**
-     * metricValueType
-     */
-    @Excel(name = "metricValueType", width = 15)
-    @ApiModelProperty(value = "metricValueType")
-    private String metricValueType;
+    //数据级别;1账户计划组可见,2账户计划可见,3账户可见
+    private String metricValueLevel;
+
+    private String msgValueType;
+
+    private String msgValueUnit;
+
+    private String msgTemplate;
     /**
     /**
      * createTime
      * createTime
      */
      */

+ 80 - 0
module-alarm/src/main/java/cn/com/ctop/alarm/modules/entity/AlarmRuleCampaignRel.java

@@ -0,0 +1,80 @@
+package cn.com.ctop.alarm.modules.entity;
+
+import com.baomidou.mybatisplus.annotation.TableField;
+import com.baomidou.mybatisplus.annotation.TableName;
+import com.fasterxml.jackson.annotation.JsonFormat;
+import io.swagger.annotations.ApiModel;
+import io.swagger.annotations.ApiModelProperty;
+import lombok.Data;
+import lombok.EqualsAndHashCode;
+import lombok.experimental.Accessors;
+import org.jeecgframework.poi.excel.annotation.Excel;
+import org.springframework.format.annotation.DateTimeFormat;
+
+import java.util.Date;
+
+/**
+ * 规则和计划、组关系表
+ *alarm_rule_campaign_rel
+ * @author jeecg-boot
+ * @version V1.0
+ * @date 2020-11-09
+ */
+@Data
+@TableName("ctop_alarm_rule_campaign_rel")
+@EqualsAndHashCode(callSuper = false)
+@Accessors(chain = true)
+@ApiModel(value = "ctop_alarm_rule_campaign_rel对象", description = "规则和计划、组关系表")
+public class AlarmRuleCampaignRel {
+
+    /**
+     * 规则id
+     */
+    @Excel(name = "规则id", width = 15)
+    @ApiModelProperty(value = "规则id")
+    private Long eventRuleId;
+    /**
+     * 账户id
+     */
+    @Excel(name = "账户id", width = 15)
+    @ApiModelProperty(value = "账户id")
+    private Long accountId;
+    /**
+     * 计划id
+     */
+    @Excel(name = "计划id", width = 15)
+    @ApiModelProperty(value = "计划id")
+    private Long campaignId;
+    @TableField(exist = false)
+    private String campaignName;
+    /**
+     * 组id
+     */
+    @Excel(name = "组id", width = 15)
+    @ApiModelProperty(value = "组id")
+    private Long unitId;
+    @TableField(exist = false)
+    private String unitName;
+    /**
+     * 规则级别 account-账户级;unit-组级;campaign-计划级
+     */
+    @Excel(name = "规则级别 ACCOUNT-账户级;UNIT-组级;CAMPAIGN-计划级", width = 15)
+    @ApiModelProperty(value = "规则级别 account-账户级;unit-组级;campaign-计划级")
+    private String eventRuleLevel;
+    /**
+     * createTime
+     */
+    @Excel(name = "createTime", width = 20, format = "yyyy-MM-dd HH:mm:ss")
+    @JsonFormat(timezone = "GMT+8", pattern = "yyyy-MM-dd HH:mm:ss")
+    @DateTimeFormat(pattern = "yyyy-MM-dd HH:mm:ss")
+    @ApiModelProperty(value = "createTime")
+    private Date createTime;
+    /**
+     * updateTime
+     */
+    @Excel(name = "updateTime", width = 20, format = "yyyy-MM-dd HH:mm:ss")
+    @JsonFormat(timezone = "GMT+8", pattern = "yyyy-MM-dd HH:mm:ss")
+    @DateTimeFormat(pattern = "yyyy-MM-dd HH:mm:ss")
+    @ApiModelProperty(value = "updateTime")
+    private Date updateTime;
+}

+ 44 - 0
module-alarm/src/main/java/cn/com/ctop/alarm/modules/enums/StatusEnum.java

@@ -0,0 +1,44 @@
+package cn.com.ctop.alarm.modules.enums;
+
+import lombok.Data;
+
+public enum StatusEnum {
+    STATUSM1("-1", "不限"),
+    STATUS1("1", "已暂停"),
+    STATUS3("3", "超预算"),
+    STATUS4("4", "有效"),
+    STATUS5("5", "已删除"),
+    STATUS6("6", "余额不足"),
+    STATUS11("11", "审核中"),
+    STATUS12("12", "审核未通过"),
+    STATUS14("14", "已结束"),
+    STATUS15("15", "已暂停"),
+    STATUS17("17", "组超预算"),
+    STATUS19("19", "未达投放时间"),
+    STATUS20("20", "有效");
+
+    private String name;
+    private String code;
+
+    private StatusEnum(String code, String name) {
+        this.name = name;
+        this.code = code;
+    }
+
+    public static StatusEnum getEnumByCode(String code) {
+        for (StatusEnum em : StatusEnum.values()) {
+            if (em.code.equals(code)) {
+                return em;
+            }
+        }
+        return null;
+    }
+
+    public String getName() {
+        return name;
+    }
+
+    public String getCode() {
+        return code;
+    }
+}

+ 2 - 2
module-alarm/src/main/java/cn/com/ctop/alarm/modules/mapper/AlarmEventMetricMapper.java

@@ -14,7 +14,7 @@ import java.util.List;
  */
  */
 public interface AlarmEventMetricMapper extends BaseMapper<AlarmEventMetric> {
 public interface AlarmEventMetricMapper extends BaseMapper<AlarmEventMetric> {
 
 
-    List<AlarmEventMetric> selectByEventRuleId(String id);
+    List<AlarmEventMetric> selectByEventRuleId(Long id);
 
 
-    void deleteByRuleId(String id);
+    void deleteByRuleId(Long id);
 }
 }

+ 1 - 1
module-alarm/src/main/java/cn/com/ctop/alarm/modules/mapper/AlarmEventRuleMapper.java

@@ -16,7 +16,7 @@ public interface AlarmEventRuleMapper extends BaseMapper<AlarmEventRule> {
 
 
     List<AlarmEventRule> selectListPage(AlarmEventRule alarmEventRule);
     List<AlarmEventRule> selectListPage(AlarmEventRule alarmEventRule);
 
 
-    AlarmEventRule queryById(String id);
+    AlarmEventRule queryById(Long id);
 
 
     List<AlarmEventRule> queryRunningRecordPage(AlarmEventRule alarmEventRule);
     List<AlarmEventRule> queryRunningRecordPage(AlarmEventRule alarmEventRule);
 }
 }

+ 1 - 0
module-alarm/src/main/java/cn/com/ctop/alarm/modules/mapper/AlarmMetricValueMapper.java

@@ -14,4 +14,5 @@ import com.baomidou.mybatisplus.core.mapper.BaseMapper;
  */
  */
 public interface AlarmMetricValueMapper extends BaseMapper<AlarmMetricValue> {
 public interface AlarmMetricValueMapper extends BaseMapper<AlarmMetricValue> {
 
 
+    List<AlarmMetricValue> queryListByLevel(AlarmMetricValue alarmMetricValue);
 }
 }

+ 20 - 0
module-alarm/src/main/java/cn/com/ctop/alarm/modules/mapper/AlarmRuleCampaignRelMapper.java

@@ -0,0 +1,20 @@
+package cn.com.ctop.alarm.modules.mapper;
+
+import java.util.List;
+
+import org.apache.ibatis.annotations.Param;
+import cn.com.ctop.alarm.modules.entity.AlarmRuleCampaignRel;
+import com.baomidou.mybatisplus.core.mapper.BaseMapper;
+
+/**
+ * 规则和计划、组关系表
+ * @author: jeecg-boot
+ * @date:   2020-11-09
+ * @cersion: V1.0
+ */
+public interface AlarmRuleCampaignRelMapper extends BaseMapper<AlarmRuleCampaignRel> {
+
+    void deleteByRuleId(Long id);
+
+    List<AlarmRuleCampaignRel> selectByRuleId(Long id);
+}

+ 12 - 1
module-alarm/src/main/java/cn/com/ctop/alarm/modules/mapper/xml/AlarmEventRuleMapper.xml

@@ -16,6 +16,15 @@
             <if test="checkFrequency != null and checkFrequency !='' ">
             <if test="checkFrequency != null and checkFrequency !='' ">
                 AND t1.check_frequency = #{checkFrequency}
                 AND t1.check_frequency = #{checkFrequency}
             </if>
             </if>
+            <if test="unitId != null and unitId !='' ">
+                AND t1.event_rule_id != #{unitId}
+            </if>
+            <if test="accountId != null and accountId !='' ">
+                AND t1.account_id = #{accountId}
+            </if>
+            <if test="eventRuleName != null and eventRuleName !='' ">
+                AND t1.event_rule_name = #{eventRuleName}
+            </if>
         </where>
         </where>
         order by t1.create_time desc
         order by t1.create_time desc
     </select>
     </select>
@@ -40,7 +49,9 @@
         ORDER BY t2.create_time DESC
         ORDER BY t2.create_time DESC
     </select>
     </select>
     <select id="queryById" resultType="cn.com.ctop.alarm.modules.entity.AlarmEventRule">
     <select id="queryById" resultType="cn.com.ctop.alarm.modules.entity.AlarmEventRule">
-       SELECT DISTINCT t1.*,t3.realname AS 'createrName',t2.user_id,t2.user_name,t2.auth_name AS accountName FROM
+       SELECT DISTINCT t1.*,
+       t3.realname AS 'createrName',t2.user_id,t2.user_name,t2.auth_name AS accountName
+       FROM
         ctop_alarm_event_rule t1
         ctop_alarm_event_rule t1
         LEFT JOIN ctop_user_allocation t2 ON t1.account_id = t2.account_id
         LEFT JOIN ctop_user_allocation t2 ON t1.account_id = t2.account_id
          LEFT JOIN sys_user t3 ON t1.creater_id = t3.id
          LEFT JOIN sys_user t3 ON t1.creater_id = t3.id

+ 8 - 1
module-alarm/src/main/java/cn/com/ctop/alarm/modules/mapper/xml/AlarmMetricValueMapper.xml

@@ -1,5 +1,12 @@
 <?xml version="1.0" encoding="UTF-8"?>
 <?xml version="1.0" encoding="UTF-8"?>
 <!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
 <!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.AlarmMetricValueMapper">
 <mapper namespace="cn.com.ctop.alarm.modules.mapper.AlarmMetricValueMapper">
-
+    <select id="queryListByLevel" parameterType="cn.com.ctop.alarm.modules.entity.AlarmMetricValue"
+            resultType="cn.com.ctop.alarm.modules.entity.AlarmMetricValue">
+        SELECT
+        *
+        FROM
+        ctop_alarm_metric_value t1
+        WHERE metric_value_level LIKE CONCAT("%",#{metricValueLevel},"%")
+    </select>
 </mapper>
 </mapper>

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

@@ -0,0 +1,18 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!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.AlarmRuleCampaignRelMapper">
+
+    <delete id="deleteByRuleId">
+        delete from ctop_alarm_rule_campaign_rel
+        where event_rule_id = #{id}
+    </delete>
+
+    <select id="selectByRuleId" resultType="cn.com.ctop.alarm.modules.entity.AlarmRuleCampaignRel">
+       SELECT t1.*,t2.unit_name AS unitName,t3.campaign_name AS campaignName
+       FROM
+        ctop_alarm_rule_campaign_rel t1
+        LEFT JOIN ctop_kuaishou_group t2 ON t1.unit_id =  t2.unit_id
+		LEFT JOIN ctop_kuaishou_campaign t3 ON t1.campaign_id = t3.campaign_id
+        WHERE event_rule_id = #{id}
+    </select>
+</mapper>

+ 5 - 6
module-alarm/src/main/java/cn/com/ctop/alarm/modules/service/IAlarmEventRuleService.java

@@ -4,6 +4,7 @@ import cn.com.ctop.alarm.modules.entity.AlarmEventRule;
 import com.alibaba.fastjson.JSONObject;
 import com.alibaba.fastjson.JSONObject;
 import com.baomidou.mybatisplus.extension.service.IService;
 import com.baomidou.mybatisplus.extension.service.IService;
 import com.github.pagehelper.PageInfo;
 import com.github.pagehelper.PageInfo;
+import org.jeecg.common.api.vo.Result;
 
 
 /**
 /**
  * @Description: 预警事件规则表
  * @Description: 预警事件规则表
@@ -13,17 +14,15 @@ import com.github.pagehelper.PageInfo;
  */
  */
 public interface IAlarmEventRuleService extends IService<AlarmEventRule> {
 public interface IAlarmEventRuleService extends IService<AlarmEventRule> {
 
 
-    void addAlarmEventRule(JSONObject obj);
+    Result<Object> addAlarmEventRule(JSONObject obj);
 
 
-    void editAlarmEventRule(JSONObject obj);
+    Result<Object> editAlarmEventRule(JSONObject obj);
 
 
-    AlarmEventRule selectById(String id);
-
-    void matchAlarmRules(String checkType);
+    AlarmEventRule selectById(Long id);
 
 
     PageInfo<AlarmEventRule> selectListPage(AlarmEventRule alarmEventRule);
     PageInfo<AlarmEventRule> selectListPage(AlarmEventRule alarmEventRule);
 
 
-    void deleteById(String id);
+    void deleteById(Long id);
 
 
     PageInfo<AlarmEventRule> queryRunningRecordPage(AlarmEventRule alarmEventRule);
     PageInfo<AlarmEventRule> queryRunningRecordPage(AlarmEventRule alarmEventRule);
 }
 }

+ 5 - 1
module-alarm/src/main/java/cn/com/ctop/alarm/modules/service/IAlarmEventSendService.java

@@ -1,14 +1,18 @@
 package cn.com.ctop.alarm.modules.service;
 package cn.com.ctop.alarm.modules.service;
 
 
 import cn.com.ctop.alarm.modules.entity.AlarmEventSend;
 import cn.com.ctop.alarm.modules.entity.AlarmEventSend;
+import com.alibaba.fastjson.JSONObject;
 import com.baomidou.mybatisplus.extension.service.IService;
 import com.baomidou.mybatisplus.extension.service.IService;
 
 
 /**
 /**
  * @Description: 预警事件发送表
  * @Description: 预警事件发送表
  * @Author: jeecg-boot
  * @Author: jeecg-boot
- * @Date:   2020-10-29
+ * @Date: 2020-10-29
  * @Version: V1.0
  * @Version: V1.0
  */
  */
 public interface IAlarmEventSendService extends IService<AlarmEventSend> {
 public interface IAlarmEventSendService extends IService<AlarmEventSend> {
 
 
+    void matchAlarmRules(String checkType);
+
+    JSONObject getAlarmValue(String type);
 }
 }

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

@@ -0,0 +1,14 @@
+package cn.com.ctop.alarm.modules.service;
+
+import cn.com.ctop.alarm.modules.entity.AlarmRuleCampaignRel;
+import com.baomidou.mybatisplus.extension.service.IService;
+
+/**
+ * @Description: 规则和计划、组关系表
+ * @Author: jeecg-boot
+ * @Date: 2020-11-09
+ * @Version: V1.0
+ */
+public interface IAlarmRuleCampaignRelService extends IService<AlarmRuleCampaignRel> {
+
+}

+ 192 - 279
module-alarm/src/main/java/cn/com/ctop/alarm/modules/service/impl/AlarmEventRuleServiceImpl.java

@@ -2,14 +2,15 @@ package cn.com.ctop.alarm.modules.service.impl;
 
 
 import cn.com.ctop.alarm.modules.entity.AlarmEventMetric;
 import cn.com.ctop.alarm.modules.entity.AlarmEventMetric;
 import cn.com.ctop.alarm.modules.entity.AlarmEventRule;
 import cn.com.ctop.alarm.modules.entity.AlarmEventRule;
-import cn.com.ctop.alarm.modules.entity.AlarmEventSend;
+import cn.com.ctop.alarm.modules.entity.AlarmRuleCampaignRel;
 import cn.com.ctop.alarm.modules.mapper.AlarmEventMetricMapper;
 import cn.com.ctop.alarm.modules.mapper.AlarmEventMetricMapper;
 import cn.com.ctop.alarm.modules.mapper.AlarmEventRuleMapper;
 import cn.com.ctop.alarm.modules.mapper.AlarmEventRuleMapper;
-import cn.com.ctop.alarm.modules.mapper.AlarmEventSendMapper;
+import cn.com.ctop.alarm.modules.mapper.AlarmRuleCampaignRelMapper;
 import cn.com.ctop.alarm.modules.service.IAlarmEventRuleService;
 import cn.com.ctop.alarm.modules.service.IAlarmEventRuleService;
-import cn.com.ctop.common.module.service.IMessageTemplate;
-import cn.com.ctop.common.module.service.ISendMessageService;
 import cn.com.ctop.common.module.utils.Check;
 import cn.com.ctop.common.module.utils.Check;
+import cn.com.ctop.kuaishou.modules.batch.entity.KuaiShouGroup;
+import cn.com.ctop.kuaishou.modules.batch.mapper.KuaiShouCampaignMapper;
+import cn.com.ctop.kuaishou.modules.batch.mapper.KuaiShouGroupMapper;
 import com.alibaba.fastjson.JSONArray;
 import com.alibaba.fastjson.JSONArray;
 import com.alibaba.fastjson.JSONObject;
 import com.alibaba.fastjson.JSONObject;
 import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
 import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
@@ -17,15 +18,15 @@ import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
 import com.github.pagehelper.PageInfo;
 import com.github.pagehelper.PageInfo;
 import com.xxl.job.core.enums.NoEn;
 import com.xxl.job.core.enums.NoEn;
 import org.apache.shiro.SecurityUtils;
 import org.apache.shiro.SecurityUtils;
+import org.jeecg.common.api.vo.Result;
 import org.jeecg.common.system.vo.LoginUser;
 import org.jeecg.common.system.vo.LoginUser;
-import org.jeecg.common.util.db.DataSourceCachePool;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.beans.factory.annotation.Autowired;
-import org.springframework.data.redis.core.HashOperations;
 import org.springframework.stereotype.Service;
 import org.springframework.stereotype.Service;
 
 
 import javax.transaction.Transactional;
 import javax.transaction.Transactional;
-import java.math.BigDecimal;
+import java.util.HashMap;
 import java.util.List;
 import java.util.List;
+import java.util.Map;
 
 
 /**
 /**
  * 预警事件规则表
  * 预警事件规则表
@@ -47,13 +48,13 @@ public class AlarmEventRuleServiceImpl extends ServiceImpl<AlarmEventRuleMapper,
     private AlarmEventMetricMapper alarmEventMetricMapper;
     private AlarmEventMetricMapper alarmEventMetricMapper;
 
 
     @Autowired
     @Autowired
-    private AlarmEventSendMapper alarmEventSendMapper;
+    private AlarmRuleCampaignRelMapper alarmRuleCampaignRelMapper;
 
 
     @Autowired
     @Autowired
-    private IMessageTemplate messageTemplate;
+    private KuaiShouCampaignMapper kuaiShouCampaignMapper;
 
 
     @Autowired
     @Autowired
-    private ISendMessageService sendMessageService;
+    private KuaiShouGroupMapper kuaiShouGroupMapper;
 
 
     @Override
     @Override
     public PageInfo<AlarmEventRule> selectListPage(AlarmEventRule alarmEventRule) {
     public PageInfo<AlarmEventRule> selectListPage(AlarmEventRule alarmEventRule) {
@@ -61,9 +62,10 @@ public class AlarmEventRuleServiceImpl extends ServiceImpl<AlarmEventRuleMapper,
     }
     }
 
 
     @Override
     @Override
-    public void deleteById(String id) {
+    public void deleteById(Long id) {
         alarmEventRuleMapper.deleteById(id);
         alarmEventRuleMapper.deleteById(id);
         alarmEventMetricMapper.deleteByRuleId(id);
         alarmEventMetricMapper.deleteByRuleId(id);
+        alarmRuleCampaignRelMapper.deleteByRuleId(id);
     }
     }
 
 
     @Override
     @Override
@@ -72,51 +74,164 @@ public class AlarmEventRuleServiceImpl extends ServiceImpl<AlarmEventRuleMapper,
     }
     }
 
 
     @Override
     @Override
-    public void addAlarmEventRule(JSONObject obj) {
-        AlarmEventRule rule = new AlarmEventRule();
-        rule.setAccountId(obj.getLong("accountId"));
-        rule.setUnitId(obj.getLong("unitId"));
-        rule.setEventRuleName(obj.getString("eventRuleName"));
-        rule.setEventRuleLevel(obj.getString("eventRuleLevel"));
-        rule.setCheckFrequency(obj.getString("checkFrequency"));
-        rule.setProcessMethod(obj.getString("processMethod"));
-        rule.setEventRuleStatus(NoEn.NO1.valueStr());
-        rule.setMetricValueCode(obj.getString("metricValueCode"));
-        rule.setMetricValueName(obj.getString("metricValueName"));
-        rule.setCreaterId(obj.getString("createrId"));
+    public Result<Object> addAlarmEventRule(JSONObject obj) {
+        Map<String, Object> map = new HashMap<>();
+        map.put("account_id", obj.getLong("accountId"));
+        map.put("event_rule_name", obj.getString("eventRuleName"));
+        if (!Check.isNull(alarmEventRuleMapper.selectByMap(map))) {
+            return Result.error(1, "添加失败,重复的规则名,请重新输入");
+        }
 
 
-        LoginUser sysUser = (LoginUser) SecurityUtils.getSubject().getPrincipal();
-        if (!Check.isNull(sysUser)) {
-            rule.setCreaterId(sysUser.getId());
+        //1。新增rule表
+        AlarmEventRule rule = new AlarmEventRule();
+        reSetRuleEntity(rule, obj);
+        JSONArray metrics = obj.getJSONArray("alarmEventMetric");
+        if (Check.isNull(metrics)) {
+            return Result.error(1, "请选择具体规则指标");
         }
         }
+        rule.setEventRuleStatus(NoEn.NO1.valueStr());//默认新增为激活状态
         alarmEventRuleMapper.insert(rule);
         alarmEventRuleMapper.insert(rule);
-        JSONArray metrics = obj.getJSONArray("alarmEventMetric");
+        //2。新增metric表
+        AlarmEventMetric metric = null;
         for (int i = 0; i < metrics.size(); i++) {
         for (int i = 0; i < metrics.size(); i++) {
-            JSONObject mo = metrics.getJSONObject(i);
-            AlarmEventMetric metric = new AlarmEventMetric();
-            metric.setEventRuleId(rule.getEventRuleId());
-            metric.setMetricValueCode(mo.getString("metricValueCode"));
-            metric.setJudgeType(mo.getString("judgeType"));
-            metric.setJudgeMethod(mo.getString("judgeMethod"));
-            metric.setThreshold(mo.getString("threshold"));
-            metric.setMinThreshold(mo.getString("minThreshold"));
-            metric.setDataRange(mo.getString("dataRange"));
-            metric.setMetricValueCode(mo.getString("metricValueCode"));
-            metric.setMetricValueName(mo.getString("metricValueName"));
+            metric = new AlarmEventMetric();
+            reSetMetricEntity(metric, metrics.getJSONObject(i), rule.getEventRuleId());
             alarmEventMetricMapper.insert(metric);
             alarmEventMetricMapper.insert(metric);
         }
         }
+        //2。新增rel表
+        //通过指定选择应用
+        JSONArray rels = obj.getJSONArray("rel");
+        if (!Check.isNull(rels)) {
+            addRelByIds(rels, rule);
+        }
+        return new Result<>().success("添加成功!");
     }
     }
 
 
     @Override
     @Override
-    public void editAlarmEventRule(JSONObject obj) {
+    public Result<Object> editAlarmEventRule(JSONObject obj) {
+        AlarmEventRule alarmEventRule = new AlarmEventRule();
+        alarmEventRule.setUnitId(obj.getLong("eventRuleId"));
+        alarmEventRule.setAccountId(obj.getLong("accountId"));
+        alarmEventRule.setEventRuleName(obj.getString("eventRuleName"));
+        if (!Check.isNull(alarmEventRuleMapper.selectListPage(alarmEventRule))) {
+            return Result.error(1, "修改失败,重复的规则名,请重新输入");
+        }
+        //1.更改rule表
         AlarmEventRule rule = new AlarmEventRule();
         AlarmEventRule rule = new AlarmEventRule();
+        reSetRuleEntity(rule, obj);
+        QueryWrapper<AlarmEventRule> ruleWrapper = new QueryWrapper<>();
+        ruleWrapper.eq("event_rule_id", obj.getLong("eventRuleId"));
+        alarmEventRuleMapper.update(rule, ruleWrapper);
+        rule.setEventRuleId(obj.getLong("eventRuleId"));
+        //2.更改metric表
+        JSONArray metrics = obj.getJSONArray("alarmEventMetric");
+        if (Check.isNull(metrics)) {
+            return Result.error(1, "请选择具体规则指标");
+        }
+        AlarmEventMetric metric = null;
+        QueryWrapper<AlarmEventMetric> metricWrapper = null;
+        for (int i = 0; i < metrics.size(); i++) {
+            JSONObject mo = metrics.getJSONObject(i);
+            metric = new AlarmEventMetric();
+            reSetMetricEntity(metric, mo, rule.getEventRuleId());
+            metricWrapper = new QueryWrapper<>();
+            metricWrapper.eq("event_metric_id", mo.getLong("eventMetricId"));
+            metricWrapper.eq("event_rule_id", obj.getLong("eventRuleId"));
+            alarmEventMetricMapper.update(metric, metricWrapper);
+        }
+        //3.更改rel表
+        //通过指定,传参ids绑定应用
+        JSONArray rels = obj.getJSONArray("rel");
+        if (!Check.isNull(rels)) {
+            alarmRuleCampaignRelMapper.deleteByRuleId(rule.getEventRuleId());
+            addRelByIds(rels, rule);
+        }
+        return new Result<>().success("修改成功!");
+    }
+
+    @Override
+    public AlarmEventRule selectById(Long id) {
+        AlarmEventRule alarmEventRule = alarmEventRuleMapper.queryById(id);
+        if (Check.isNull(alarmEventRule)) {
+            return null;
+        }
+        alarmEventRule.setAlarmEventMetrics(alarmEventMetricMapper.selectByEventRuleId(id));
+        if (("CAMPAIGN".equals(alarmEventRule.getEventRuleLevel()) || "UNIT".equals(alarmEventRule.getEventRuleLevel())) && !NoEn.NO1.valueStr().equals(alarmEventRule.getAppStatus())) {
+            alarmEventRule.setRel(alarmRuleCampaignRelMapper.selectByRuleId(id));
+        }
+        return alarmEventRule;
+    }
+
+    //通过状态+level绑定应用
+    private void addRelByStatus(AlarmEventRule rule, Long campaignId) {
+        if ("CAMPAIGN".equals(rule.getEventRuleLevel())) {
+            List<Long> ids = kuaiShouCampaignMapper.queryIdsByPutStatus(rule.getAccountId(), NoEn.NO1.valueStr());
+            if (Check.isNull(ids)) {
+                return;
+            }
+            for (Long id : ids) {
+                AlarmRuleCampaignRel relEntity = new AlarmRuleCampaignRel();
+                relEntity.setEventRuleId(rule.getEventRuleId());
+                relEntity.setAccountId(rule.getAccountId());
+                relEntity.setEventRuleLevel(rule.getEventRuleLevel());
+                relEntity.setCampaignId(id);
+                alarmRuleCampaignRelMapper.insert(relEntity);
+            }
+        }
+        if ("UNIT".equals(rule.getEventRuleLevel())) {
+            Map<String, Object> map = new HashMap<>();
+            map.put("put_status", NoEn.NO1.valueStr());
+            map.put("account_id", rule.getAccountId());
+            if (Check.isNull(campaignId)) {
+                map.put("campaign_id", campaignId);
+            }
+            List<KuaiShouGroup> kuaiShouGroups = kuaiShouGroupMapper.selectByMap(map);
+            if (Check.isNull(kuaiShouGroups)) {
+                return;
+            }
+            for (KuaiShouGroup kuaiShouGroup : kuaiShouGroups) {
+                AlarmRuleCampaignRel relEntity = new AlarmRuleCampaignRel();
+                relEntity.setEventRuleId(rule.getEventRuleId());
+                relEntity.setAccountId(rule.getAccountId());
+                relEntity.setEventRuleLevel(rule.getEventRuleLevel());
+                relEntity.setCampaignId(kuaiShouGroup.getCampaignId());
+                relEntity.setUnitId(kuaiShouGroup.getUnitId());
+                alarmRuleCampaignRelMapper.insert(relEntity);
+            }
+        }
+    }
+
+    //通过指定,传参IDS绑定应用
+    private void addRelByIds(JSONArray rels, AlarmEventRule rule) {
+        for (int k = 0; k < rels.size(); k++) {
+            AlarmRuleCampaignRel relEntity = new AlarmRuleCampaignRel();
+            JSONObject rel = rels.getJSONObject(k);
+            relEntity.setEventRuleId(rule.getEventRuleId());
+            relEntity.setAccountId(rule.getAccountId());
+            relEntity.setEventRuleLevel(rule.getEventRuleLevel());
+            relEntity.setCampaignId(rel.getLong("campaignId"));
+            relEntity.setUnitId(rel.getLong("unitId"));
+            alarmRuleCampaignRelMapper.insert(relEntity);
+        }
+    }
+
+    /**
+     * 规则实体类封装
+     * Message template
+     *
+     * @param
+     * @return void
+     * @throws
+     * @author ZHAOXA
+     */
+    private void reSetRuleEntity(AlarmEventRule rule, JSONObject obj) {
         Long accountId = obj.getLong("accountId");
         Long accountId = obj.getLong("accountId");
         if (!Check.isNull(accountId)) {
         if (!Check.isNull(accountId)) {
             rule.setAccountId(accountId);
             rule.setAccountId(accountId);
         }
         }
-        Long unitId = obj.getLong("unitId");
-        if (!Check.isNull(unitId)) {
-            rule.setUnitId(unitId);
+        Long campaignId = obj.getLong("campaignId");
+        if (!Check.isNull(campaignId)) {
+            rule.setCampaignId(campaignId);
         }
         }
         String eventRuleName = obj.getString("eventRuleName");
         String eventRuleName = obj.getString("eventRuleName");
         if (!Check.isNull(eventRuleName)) {
         if (!Check.isNull(eventRuleName)) {
@@ -136,266 +251,64 @@ public class AlarmEventRuleServiceImpl extends ServiceImpl<AlarmEventRuleMapper,
         }
         }
         String metricValueName = obj.getString("metricValueName");
         String metricValueName = obj.getString("metricValueName");
         if (!Check.isNull(metricValueName)) {
         if (!Check.isNull(metricValueName)) {
-            rule.setMetricValueCode(metricValueName);
+            rule.setMetricValueName(metricValueName);
         }
         }
         String processMethod = obj.getString("processMethod");
         String processMethod = obj.getString("processMethod");
         if (!Check.isNull(processMethod)) {
         if (!Check.isNull(processMethod)) {
             rule.setProcessMethod(processMethod);
             rule.setProcessMethod(processMethod);
-
         }
         }
         String eventRuleStatus = obj.getString("eventRuleStatus");
         String eventRuleStatus = obj.getString("eventRuleStatus");
         if (!Check.isNull(eventRuleStatus)) {
         if (!Check.isNull(eventRuleStatus)) {
             rule.setEventRuleStatus(eventRuleStatus);
             rule.setEventRuleStatus(eventRuleStatus);
         }
         }
+        rule.setCreaterId(obj.getString("createrId"));
         LoginUser sysUser = (LoginUser) SecurityUtils.getSubject().getPrincipal();
         LoginUser sysUser = (LoginUser) SecurityUtils.getSubject().getPrincipal();
         if (!Check.isNull(sysUser)) {
         if (!Check.isNull(sysUser)) {
             rule.setCreaterId(sysUser.getId());
             rule.setCreaterId(sysUser.getId());
         }
         }
-        QueryWrapper<AlarmEventRule> ruleWrapper = new QueryWrapper<>();
-        ruleWrapper.eq("event_rule_id", obj.getLong("eventRuleId"));
-        alarmEventRuleMapper.update(rule, ruleWrapper);
-        JSONArray metrics = obj.getJSONArray("alarmEventMetric");
-        if (Check.isNull(metrics)) {
-            return;
-        }
-        for (int i = 0; i < metrics.size(); i++) {
-            JSONObject mo = metrics.getJSONObject(i);
-            AlarmEventMetric metric = new AlarmEventMetric();
-            Long eventRuleId = rule.getEventRuleId();
-            if (!Check.isNull(eventRuleId)) {
-                metric.setEventRuleId(eventRuleId);
-            }
-            String valueCode = mo.getString("metricValueCode");
-            if (!Check.isNull(valueCode)) {
-                metric.setMetricValueCode(valueCode);
-            }
-            String valueName = mo.getString("metricValueName");
-            if (!Check.isNull(valueName)) {
-                metric.setMetricValueName(valueName);
-            }
-            String judgeType = mo.getString("judgeType");
-            if (!Check.isNull(judgeType)) {
-                metric.setJudgeType(judgeType);
-            }
-            String judgeMethod = mo.getString("judgeMethod");
-            if (!Check.isNull(judgeMethod)) {
-                metric.setJudgeMethod(judgeMethod);
-            }
-            String threshold = mo.getString("threshold");
-            if (!Check.isNull(threshold)) {
-                metric.setThreshold(threshold);
-            }
-            String minThreshold = mo.getString("minThreshold");
-            if (!Check.isNull(minThreshold)) {
-                metric.setMinThreshold(minThreshold);
-            }
-            String dataRange = mo.getString("dataRange");
-            if (!Check.isNull(dataRange)) {
-                metric.setDataRange(dataRange);
-            }
-            QueryWrapper<AlarmEventMetric> metricWrapper = new QueryWrapper<>();
-            metricWrapper.eq("event_metric_id", mo.getLong("eventMetricId"));
-            metricWrapper.eq("event_rule_id", obj.getLong("eventRuleId"));
-            alarmEventMetricMapper.update(metric, metricWrapper);
-        }
-    }
-
-    @Override
-    public AlarmEventRule selectById(String id) {
-        AlarmEventRule alarmEventRule = alarmEventRuleMapper.queryById(id);
-        List<AlarmEventMetric> alarmEventMetricList = alarmEventMetricMapper.selectByEventRuleId(id);
-        return alarmEventRule.setAlarmEventMetrics(alarmEventMetricList);
-    }
-
-    @Override
-    public void matchAlarmRules(String checkType) {
-        List<AlarmEventRule> allRules = getAllAlarmRules(checkType);
-        List<JSONObject> accountCosts = getCostInfo("account");
-        if (Check.isNull(allRules) || Check.isNull(accountCosts)) {
-            return;
-        }
-        for (JSONObject cost : accountCosts) {
-            for (AlarmEventRule rule : allRules) {
-                if (cost.getLong("accountId") - rule.getAccountId() == 0) {
-                    matchRules(rule, cost);
-                }
-            }
-        }
-    }
-
-    private void matchRules(AlarmEventRule rule, JSONObject cost) {
-        String rulesMetric = rule.getMetricValueCode();
-        //目标成本
-        BigDecimal value = cost.getBigDecimal(rulesMetric);
-        if (Check.isNull(value)) {
-            log.warn("规则中指标不匹配");
-            return;
-        }
-        //总消耗
-        BigDecimal totalCost = cost.getBigDecimal("totalCost");
-        List<AlarmEventMetric> metrics = rule.getAlarmEventMetrics();
-        if (Check.isNull(metrics)) {
-            return;
-        }
-        boolean flag = true;
-        StringBuffer depletionStr = new StringBuffer();
-        StringBuffer valueStr = new StringBuffer();
-        StringBuffer roiStr = new StringBuffer();
-        if (metrics.size() > 1) {
-            depletionStr.append("消耗");
-            valueStr.append("并且成本");
-            roiStr.append("并且ROI");
-        } else {
-            valueStr.append(metrics.get(0).getMetricValueName());
-        }
-        for (AlarmEventMetric metric : metrics) {
-            if (flag) {
-                //阈值
-                BigDecimal threshold = new BigDecimal(metric.getThreshold());
-                String judgeMethod = metric.getJudgeMethod();
-                String metricValue = metric.getMetricValueCode();
-                String sub = metricValue.substring(metricValue.lastIndexOf("_") + 1);
-                //大于等于
-                if ("GT_EQ".equals(judgeMethod)) {
-                    //判断阈值类型(cost-成本;depletion-消耗;roi)
-                    if ("depletion".equals(sub)) {
-                        flag = totalCost.compareTo(threshold) >= 0;
-                        depletionStr.append("高于").append("账户设置的消耗值:").append(threshold).append("元");
-                        continue;
-                    } else if ("roi".equals(sub)) {
-                        roiStr.append("高于").append("账户设置的ROI:").append(threshold.multiply(new BigDecimal(100)).setScale(2)).append("%");
-                        flag = value.compareTo(threshold) >= 0;
-                        continue;
-                    } else {
-                        valueStr.append("高于").append("账户设置的成本价格:").append(threshold).append("元");
-                        flag = value.compareTo(threshold) >= 0;
-                        continue;
-                    }
-                    //小于等于
-                } else if ("LT_EQ".equals(judgeMethod)) {
-                    if ("depletion".equals(sub)) {
-                        depletionStr.append("低于").append("账户设置的消耗值:").append(threshold).append("元");
-                        flag = totalCost.compareTo(threshold) <= 0;
-                        continue;
-                    } else if ("roi".equals(sub)) {
-                        roiStr.append("低于").append("账户设置的ROI:").append(threshold.multiply(new BigDecimal(100)).setScale(2)).append("%");
-                        flag = value.compareTo(threshold) <= 0;
-                        continue;
-                    } else {
-                        valueStr.append("低于").append("账户设置的成本价格:").append(threshold).append("元");
-                        flag = value.compareTo(threshold) <= 0;
-                        continue;
-                    }
-                    //介于
-                } else if ("BETWEEN".equals(judgeMethod)) {
-                    BigDecimal minThreshold = new BigDecimal(metric.getMinThreshold());
-                    if ("depletion".equals(sub)) {
-                        flag = (totalCost.compareTo(threshold) > 0) || (totalCost.compareTo(minThreshold) < 0);
-                        if (totalCost.compareTo(threshold) > 0) {
-                            depletionStr.append("高于");
-                        }
-                        if (totalCost.compareTo(minThreshold) < 0) {
-                            depletionStr.append("低于");
-                        }
-                        depletionStr.append("账户设置的消耗区间:").append(minThreshold).append("元-").append(threshold).append("元");
-                        continue;
-                    } else if ("roi".equals(sub)) {
-                        flag = (value.compareTo(threshold) > 0) || (value.compareTo(minThreshold) < 0);
-                        if (value.compareTo(threshold) > 0) {
-                            roiStr.append("高于");
-                        }
-                        if (value.compareTo(minThreshold) < 0) {
-                            roiStr.append("低于");
-                        }
-                        roiStr.append("账户设置的").append(rule.getMetricValueName()).append("区间:").append(minThreshold.multiply(new BigDecimal(100)).setScale(2)).append("%-").append(threshold.multiply(new BigDecimal(100)).setScale(2)).append("%");
-                        continue;
-                    } else {
-                        flag = (value.compareTo(threshold) > 0) || (value.compareTo(minThreshold) < 0);
-                        if (value.compareTo(threshold) > 0) {
-                            valueStr.append("高于");
-                        }
-                        if (value.compareTo(minThreshold) < 0) {
-                            valueStr.append("低于");
-                        }
-                        valueStr.append("账户设置的成本区间:").append(minThreshold).append("元-").append(threshold).append("元");
-                        continue;
-                    }
-                } else {
-                    log.warn("缺失判断条件");
-                }
-            } else {
-                break;
-            }
+        if (!Check.isNull(obj.getString("appStatus")) && Check.isNull(obj.getJSONArray("rel"))) {
+            rule.setAppStatus(obj.getString("appStatus"));
         }
         }
-        //规则满足,产生预警
-        if (flag) {
-            cost.put("accountName", rule.getAccountName());
-            cost.put("name", rule.getMetricValueName());
-            if (metrics.size() > 1) {
-                if (rule.getMetricValueCode().toLowerCase().contains("roi")) {
-                    cost.put("depletion", depletionStr.append("<br/>").append(roiStr).toString());
-                } else {
-                    cost.put("depletion", depletionStr.append("<br/>").append(valueStr).toString());
-                }
-            } else {
-                cost.put("depletion", valueStr.toString());
-            }
-            String msg = null;
-            if ("SEND".equals(rule.getProcessMethod())) {
-                cost.put("end", "请您及时查看并调整!");
-                msg = messageTemplate.getAlarmCostMessage(cost);
-            } else {
-                cost.put("end", "现已被关停,请您及时查看并调整!");
-                msg = messageTemplate.getAlarmCostMessage(cost);
-            }
-            if (!Check.isNull(msg)) {
-                sendMessageService.sendMessage(rule.getUserId(), msg);
-
-                AlarmEventSend send = new AlarmEventSend();
-                send.setAlarmDetail(msg);
-                send.setAlarmStatus(NoEn.NO1.valueStr());
-                send.setMetricValueCode(rule.getMetricValueCode());
-                send.setEventRuleId(rule.getEventRuleId());
-                send.setAlarmCondition(rule.getMetricValueName() + "预警:" + cost.getString("depletion"));
-                alarmEventSendMapper.insert(send);
-            }
-        }
-    }
-
-    /**
-     * 获取成本数据。
-     *
-     * @param code : unit 组级数据,account 账户级数据
-     * @return java.util.List<cn.com.ctop.kuaishou.modules.report.entity.KuaishouCostGroup>
-     * @throws
-     * @author ZHAOXA
-     */
-    private List<JSONObject> getCostInfo(String code) {
-        HashOperations<String, Object, Object> hahs = DataSourceCachePool.getRedisTemplate().opsForHash();
-        return (List<JSONObject>) hahs.get("KS_COST", code);
     }
     }
 
 
     /**
     /**
-     * 获取告警规则集合
+     * 填充规则详细实体类
      *
      *
      * @param
      * @param
-     * @return java.util.List<cn.com.ctop.alarm.modules.entity.AlarmEventRules>
+     * @return void
      * @throws
      * @throws
      * @author ZHAOXA
      * @author ZHAOXA
      */
      */
-    private List<AlarmEventRule> getAllAlarmRules(String checkType) {
-        AlarmEventRule alarmEventRule = new AlarmEventRule();
-        alarmEventRule.setEventRuleStatus(NoEn.NO1.valueStr());
-        alarmEventRule.setCheckFrequency(checkType);
-        List<AlarmEventRule> ruleList = alarmEventRuleMapper.selectListPage(alarmEventRule);
-        if (!Check.isNull(ruleList)) {
-            for (AlarmEventRule rule : ruleList) {
-                QueryWrapper<AlarmEventMetric> metricWrapper = new QueryWrapper<>();
-                metricWrapper.eq("event_rule_id", rule.getEventRuleId());
-                rule.setAlarmEventMetrics(alarmEventMetricMapper.selectList(metricWrapper));
-            }
+    private void reSetMetricEntity(AlarmEventMetric metric, JSONObject mo, Long ruleId) {
+        metric.setEventRuleId(ruleId);
+        String valueCode = mo.getString("metricValueCode");
+        if (!Check.isNull(valueCode)) {
+            metric.setMetricValueCode(valueCode);
+        }
+        String valueName = mo.getString("metricValueName");
+        if (!Check.isNull(valueName)) {
+            metric.setMetricValueName(valueName);
+        }
+        String judgeType = mo.getString("judgeType");
+        if (!Check.isNull(judgeType)) {
+            metric.setJudgeType(judgeType);
+        }
+        String judgeMethod = mo.getString("judgeMethod");
+        if (!Check.isNull(judgeMethod)) {
+            metric.setJudgeMethod(judgeMethod);
+        }
+        String threshold = mo.getString("threshold");
+        if (!Check.isNull(threshold)) {
+            metric.setThreshold(threshold);
+        }
+        String minThreshold = mo.getString("minThreshold");
+        if (!Check.isNull(minThreshold)) {
+            metric.setMinThreshold(minThreshold);
+        }
+        String dataRange = mo.getString("dataRange");
+        if (!Check.isNull(dataRange)) {
+            metric.setDataRange(dataRange);
         }
         }
-        return ruleList;
     }
     }
 
 
 }
 }

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

@@ -1,19 +1,471 @@
 package cn.com.ctop.alarm.modules.service.impl;
 package cn.com.ctop.alarm.modules.service.impl;
 
 
+import cn.com.ctop.alarm.modules.entity.AlarmEventMetric;
+import cn.com.ctop.alarm.modules.entity.AlarmEventRule;
 import cn.com.ctop.alarm.modules.entity.AlarmEventSend;
 import cn.com.ctop.alarm.modules.entity.AlarmEventSend;
+import cn.com.ctop.alarm.modules.entity.AlarmMetricValue;
+import cn.com.ctop.alarm.modules.entity.AlarmRuleCampaignRel;
+import cn.com.ctop.alarm.modules.enums.StatusEnum;
+import cn.com.ctop.alarm.modules.mapper.AlarmEventMetricMapper;
+import cn.com.ctop.alarm.modules.mapper.AlarmEventRuleMapper;
 import cn.com.ctop.alarm.modules.mapper.AlarmEventSendMapper;
 import cn.com.ctop.alarm.modules.mapper.AlarmEventSendMapper;
+import cn.com.ctop.alarm.modules.mapper.AlarmMetricValueMapper;
+import cn.com.ctop.alarm.modules.mapper.AlarmRuleCampaignRelMapper;
 import cn.com.ctop.alarm.modules.service.IAlarmEventSendService;
 import cn.com.ctop.alarm.modules.service.IAlarmEventSendService;
+import cn.com.ctop.common.module.entity.CtopOauthToken;
+import cn.com.ctop.common.module.service.ICtopOauthTokenService;
+import cn.com.ctop.common.module.service.IMessageTemplate;
+import cn.com.ctop.common.module.service.ISendMessageService;
+import cn.com.ctop.common.module.utils.Check;
+import cn.com.ctop.kuaishou.modules.batch.entity.KuaiShouCampaign;
+import cn.com.ctop.kuaishou.modules.batch.entity.KuaiShouGroup;
+import cn.com.ctop.kuaishou.modules.batch.mapper.KuaiShouCampaignMapper;
+import cn.com.ctop.kuaishou.modules.batch.mapper.KuaiShouGroupMapper;
+import cn.com.ctop.kuaishou.modules.batch.service.IKuaiShouUpdateService;
+import com.alibaba.fastjson.JSONObject;
+import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
+import com.xxl.job.core.enums.NoEn;
+import lombok.extern.slf4j.Slf4j;
+import org.jeecg.common.util.db.DataSourceCachePool;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.data.redis.core.HashOperations;
 import org.springframework.stereotype.Service;
 import org.springframework.stereotype.Service;
 
 
-import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
+import java.math.BigDecimal;
+import java.util.ArrayList;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
 
 
 /**
 /**
  * 预警事件发送表
  * 预警事件发送表
+ *
  * @author jeecg-boot
  * @author jeecg-boot
- * @date   2020-10-29
  * @version V1.0
  * @version V1.0
+ * @date 2020-10-29
  */
  */
+@Slf4j
 @Service
 @Service
 public class AlarmEventSendServiceImpl extends ServiceImpl<AlarmEventSendMapper, AlarmEventSend> implements IAlarmEventSendService {
 public class AlarmEventSendServiceImpl extends ServiceImpl<AlarmEventSendMapper, AlarmEventSend> implements IAlarmEventSendService {
 
 
+    @Autowired
+    private AlarmEventRuleMapper alarmEventRuleMapper;
+
+    @Autowired
+    private AlarmEventMetricMapper alarmEventMetricMapper;
+
+    @Autowired
+    private AlarmRuleCampaignRelMapper alarmRuleCampaignRelMapper;
+
+    @Autowired
+    private AlarmMetricValueMapper alarmMetricValueMapper;
+
+    @Autowired
+    private AlarmEventSendMapper alarmEventSendMapper;
+
+    @Autowired
+    private IMessageTemplate messageTemplate;
+
+    @Autowired
+    private ISendMessageService sendMessageService;
+
+    @Autowired
+    private KuaiShouCampaignMapper kuaiShouCampaignMapper;
+
+    @Autowired
+    private IKuaiShouUpdateService kuaiShouUpdateService;
+
+    @Autowired
+    private ICtopOauthTokenService oauthTokenService;
+
+    @Autowired
+    private KuaiShouGroupMapper kuaiShouGroupMapper;
+
+    private static JSONObject alarmValue;
+
+    /**
+     * value数据存储到内存
+     *
+     * @param
+     * @return com.alibaba.fastjson.JSONObject
+     * @throws
+     * @author ZHAOXA
+     */
+    @Override
+    public JSONObject getAlarmValue(String type) {
+        if (NoEn.NO1.valueStr().equals(type)) {
+            alarmValue = null;
+        }
+        if (Check.isNull(alarmValue)) {
+            alarmValue = new JSONObject();
+            List<AlarmMetricValue> valueList = alarmMetricValueMapper.selectList(null);
+            if (!Check.isNull(valueList)) {
+                for (AlarmMetricValue value : valueList) {
+                    alarmValue.put(value.getMetricValueCode(), value);
+                }
+            }
+            return alarmValue;
+        }
+        return alarmValue;
+    }
+
+    @Override
+    public void matchAlarmRules(String checkType) {
+        log.info("------匹配规则start----------");
+        long startTime = System.currentTimeMillis();
+        List<AlarmEventRule> allRules = getAllAlarmRules(checkType);
+        List<JSONObject> accountCosts = getCostInfo("ACCOUNT");
+        List<JSONObject> campaignCosts = getCostInfo("CAMPAIGN");
+        List<JSONObject> unitCosts = getCostInfo("UNIT");
+        if (Check.isNull(allRules)) {
+            return;
+        }
+        //判断账户级
+        for (AlarmEventRule rule : allRules) {
+            for (JSONObject accountCost : accountCosts) {
+                if ("ACCOUNT".equals(rule.getEventRuleLevel()) && accountCost.getLong("accountId") - rule.getAccountId() == 0) {
+                    matchRules(rule, accountCost, "ACCOUNT");
+                }
+            }
+            //判断计划级
+            for (JSONObject campaignCost : campaignCosts) {
+                if ("CAMPAIGN".equals(rule.getEventRuleLevel()) && campaignCost.getLong("accountId") - rule.getAccountId() == 0) {
+                    List<AlarmRuleCampaignRel> rel = rule.getRel();
+                    if (!Check.isNull(rel)) {
+                        for (AlarmRuleCampaignRel campaignRel : rel) {
+                            if (campaignRel.getCampaignId() - campaignCost.getLong("campaignId") == 0) {
+                                rule.setCampaignId(campaignRel.getCampaignId());
+                                rule.setCampaignName(campaignRel.getCampaignName());
+                                matchRules(rule, campaignCost, "CAMPAIGN");
+                            }
+                        }
+                    }
+                }
+            }
+            //判断组级
+            for (JSONObject unitCost : unitCosts) {
+                if ("UNIT".equals(rule.getEventRuleLevel()) && unitCost.getLong("accountId") - rule.getAccountId() == 0) {
+                    List<AlarmRuleCampaignRel> rel = rule.getRel();
+                    if (!Check.isNull(rel)) {
+                        for (AlarmRuleCampaignRel unitRel : rel) {
+                            if (unitRel.getUnitId() - unitCost.getLong("unitId") == 0) {
+                                rule.setCampaignId(unitRel.getCampaignId());
+                                rule.setCampaignName(unitRel.getCampaignName());
+                                rule.setUnitId(unitRel.getUnitId());
+                                rule.setUnitName(unitRel.getUnitName());
+                                matchRules(rule, unitCost, "UNIT");
+                            }
+                        }
+                    }
+                }
+            }
+        }
+        long endTime = System.currentTimeMillis();
+        log.info("---end---匹配规则用时:{} ms", endTime - startTime);
+    }
+
+    /**
+     * 匹配规则
+     *
+     * @param
+     * @return void
+     * @throws
+     * @author ZHAOXA
+     */
+    private void matchRules(AlarmEventRule rule, JSONObject cost, String level) {
+        try {
+            //目标值
+            String goal = cost.getString(rule.getMetricValueCode());
+            if (Check.isNull(goal)) {
+                log.warn("规则中指标不匹配");
+                return;
+            }
+            //总消耗
+            BigDecimal totalCost = cost.getBigDecimal("totalCost");
+            BigDecimal value = new BigDecimal(goal);
+            List<AlarmEventMetric> metrics = rule.getAlarmEventMetrics();
+            if (Check.isNull(metrics)) {
+                return;
+            }
+            //value配置数据
+            JSONObject alarmValue = getAlarmValue(NoEn.NO0.valueStr());
+            boolean flag = true;
+            StringBuffer _depletion = new StringBuffer();
+            StringBuffer _roi = new StringBuffer();
+            StringBuffer _value = new StringBuffer();
+            for (AlarmEventMetric metric : metrics) {
+                if (flag) {
+                    //阈值
+                    BigDecimal threshold = new BigDecimal(metric.getThreshold());
+                    String judgeMethod = metric.getJudgeMethod();
+                    String metricValue = metric.getMetricValueCode();
+                    JSONObject valObj = alarmValue.getJSONObject(metricValue);
+                    //模板
+                    String msgTemplate = valObj.getString("msgTemplate");
+                    //单位 元、%
+                    String msgValueUnit = valObj.getString("msgValueUnit");
+                    //阈值类型 1-字符串,2-数字(BigDecimal),3-百分数',
+                    String showValue = getThreshold(valObj.getString("msgValueType"), threshold, msgValueUnit);
+                    String judgment = "低于";
+                    //大于等于
+                    if ("GT_EQ".equals(judgeMethod)) {
+                        judgment = "高于";
+                        //判断阈值类型(cost-成本;depletion-消耗;roi)
+                        if (metricValue.contains("_depletion")) {
+                            flag = totalCost.compareTo(threshold) >= 0;
+                            getMsgTemplate(_depletion, msgTemplate, judgment, "消耗值", showValue);
+                        } else if (metricValue.contains("_roi")) {
+                            flag = value.compareTo(threshold) >= 0;
+                            getMsgTemplate(_roi, msgTemplate, judgment, "ROI", showValue);
+                        } else {
+                            flag = value.compareTo(threshold) >= 0;
+                            getMsgTemplate(_value, msgTemplate, judgment, "阈值", showValue);
+                        }
+                        //小于等于
+                    } else if ("LT_EQ".equals(judgeMethod)) {
+                        if (metricValue.contains("_depletion")) {
+                            flag = totalCost.compareTo(threshold) <= 0;
+                            getMsgTemplate(_depletion, msgTemplate, judgment, "消耗值", showValue);
+                        } else if (metricValue.contains("_roi")) {
+                            flag = value.compareTo(threshold) <= 0;
+                            getMsgTemplate(_roi, msgTemplate, judgment, "ROI", showValue);
+                        } else {
+                            flag = value.compareTo(threshold) <= 0;
+                            getMsgTemplate(_value, msgTemplate, judgment, "阈值", showValue);
+                        }
+                        //介于
+                    } else if ("BETWEEN".equals(judgeMethod)) {
+                        BigDecimal minThreshold = new BigDecimal(metric.getMinThreshold());
+                        String minshowValue = getThreshold(valObj.getString("msgValueType"), minThreshold, msgValueUnit);
+                        if (metricValue.contains("_depletion")) {
+                            flag = (totalCost.compareTo(threshold) > 0) || (totalCost.compareTo(minThreshold) < 0);
+                            if (totalCost.compareTo(threshold) > 0) {
+                                judgment = "高于";
+                            }
+                            getMsgTemplate(_depletion, msgTemplate, judgment, "消耗区间", minshowValue.concat("-").concat(showValue));
+                        } else if (metricValue.contains("_roi")) {
+                            flag = (value.compareTo(threshold) > 0) || (value.compareTo(minThreshold) < 0);
+                            if (value.compareTo(threshold) > 0) {
+                                judgment = "高于";
+                            }
+                            getMsgTemplate(_roi, msgTemplate, judgment, "ROI区间", minshowValue.concat("-").concat(showValue));
+                            continue;
+                        } else {
+                            flag = (value.compareTo(threshold) > 0) || (value.compareTo(minThreshold) < 0);
+                            if (value.compareTo(threshold) > 0) {
+                                judgment = "高于";
+                            }
+                            getMsgTemplate(_value, msgTemplate, judgment, "阈值区间", minshowValue.concat("-").concat(showValue));
+                        }
+                        //等于
+                    } else if ("EQ".equals(judgeMethod)) {
+                        judgment = "等于";
+                        flag = value.compareTo(threshold) == 0;
+                        String name = StatusEnum.getEnumByCode(threshold.toString()).getName();
+                        getMsgTemplate(_value, msgTemplate, judgment, "阈值", name);
+                    } else {
+                        log.warn("缺失判断条件");
+                        break;
+                    }
+                } else {
+                    break;
+                }
+            }
+            //规则满足,产生预警
+            if (flag) {
+                String detail = getDetail(_depletion, _roi, _value);
+                String msg = getMsg(level, detail, cost, rule);
+                if (!Check.isNull(msg)) {
+                    sendMessageService.sendMessage(rule.getUserId(), msg);
+                    AlarmEventSend send = new AlarmEventSend();
+                    send.setAlarmDetail(msg);
+                    send.setAlarmStatus(NoEn.NO1.valueStr());
+                    send.setMetricValueCode(rule.getMetricValueCode());
+                    send.setEventRuleId(rule.getEventRuleId());
+                    send.setAlarmCondition(rule.getMetricValueName().concat("预警:").concat(detail.replace("<br/>", ";")));
+                    send.setUserId(rule.getUserId());
+                    alarmEventSendMapper.insert(send);
+                }
+            }
+        } catch (Exception e) {
+            log.error("匹配规则异常", e);
+        }
+    }
+
+    private boolean shutDown(AlarmEventRule rule, String level) {
+        CtopOauthToken token = oauthTokenService.getTokenByAccountId(rule.getAccountId());
+        Map<String, Object> updateMap = new HashMap<>();
+        if (!Check.isNull(token)) {
+            if ("CAMPAIGN".equals(level)) {
+                updateMap = kuaiShouUpdateService.updateCampaignStatus(token.getAccessToken(), rule.getAccountId(), rule.getCampaignId(), NoEn.NO2.valueInt(), rule.getUserId());
+                log.info("---------规则关停快手计划:{}", rule.getCampaignId());
+            } else if ("UNIT".equals(level)) {
+                updateMap = kuaiShouUpdateService.updateUnitStatus(token.getAccessToken(), rule.getAccountId(), rule.getUnitId(), NoEn.NO2.valueInt(), rule.getUserId());
+                log.info("---------规则关停快手组:{}", rule.getUnitId());
+            }
+        }
+        return (boolean) updateMap.get("success");
+    }
+
+    /**
+     * 判断模板中阈值展示格式(含单位)
+     * 例如:100.0元、55.53%
+     */
+    private String getThreshold(String msgValueType, BigDecimal value, String msgValueUnit) {
+        //1-字符串,2-数字(BigDecimal),3-百分数
+        if ("3".equals(msgValueType)) {
+            return value.multiply(new BigDecimal(100)).setScale(2).toString().concat(msgValueUnit);
+        }
+        return value.toString().concat(msgValueUnit);
+    }
+
+    /**
+     * 匹配消息模板
+     */
+    private void getMsgTemplate(StringBuffer buf, String msgTemplate, String jud, String name, String value) {
+        buf.append(msgTemplate.replace("{judgment}", jud).replace("{name}", name).replace("{value}", value));
+    }
+
+    /**
+     * 组合消息内容
+     */
+    private String getDetail(StringBuffer _depletion, StringBuffer _roi, StringBuffer _value) {
+        StringBuffer detail = new StringBuffer();
+        if (_depletion.length() > 0) {
+            detail.append(_depletion);
+            if (_roi.length() > 0) {
+                detail.append("并且").append(_roi);
+                if (_value.length() > 0) {
+                    detail.append("并且").append(_value);
+                }
+            } else {
+                if (_value.length() > 0) {
+                    detail.append("并且").append(_value);
+                }
+            }
+        } else {
+            if (_roi.length() > 0) {
+                detail.append(_roi);
+                if (_value.length() > 0) {
+                    detail.append("并且").append(_value);
+                }
+            } else {
+                if (_value.length() > 0) {
+                    detail.append(_value);
+                }
+            }
+        }
+        return detail.toString();
+    }
+
+    /**
+     * 整理发送的消息
+     */
+    private String getMsg(String level, String detail, JSONObject cost, AlarmEventRule rule) {
+        StringBuffer header = new StringBuffer();
+        header.append(rule.getMetricValueName()).append("预警").append("<br/>").
+                append("您的账户:").append(cost.getString("accountId")).append(",授权名称为:").append(rule.getAccountName()).append("<br/>");
+        if ("ACCOUNT".equals(level)) {
+            header.append(detail);
+        } else if ("CAMPAIGN".equals(level)) {
+            header.append("计划ID:").append(rule.getCampaignId()).append(",计划名称为:").append(rule.getCampaignName()).append("<br/>").append(detail);
+        } else {
+            header.append("计划ID:").append(rule.getCampaignId()).append(",计划名称为:").append(rule.getCampaignName()).append("<br/>")
+                    .append("组ID:").append(rule.getUnitId()).append(",组名称为:").append(rule.getUnitName()).append("<br/>").append(detail);
+        }
+        String msg = null;
+        if ("PAUSE".equals(rule.getProcessMethod())) {
+            header.append("现已被关停,请您及时查看并调整!");
+            if (shutDown(rule, level)) {
+                msg = header.toString();
+            }
+        } else {
+            header.append("请您及时查看并调整!");
+            msg = header.toString();
+        }
+        return msg;
+    }
+
+
+    /**
+     * 获取成本数据。
+     *
+     * @param code : unit 组级数据,account 账户级数据
+     * @return java.util.List<cn.com.ctop.kuaishou.modules.report.entity.KuaishouCostGroup>
+     * @throws
+     * @author ZHAOXA
+     */
+    private List<JSONObject> getCostInfo(String code) {
+        HashOperations<String, Object, Object> hahs = DataSourceCachePool.getRedisTemplate().opsForHash();
+        return (List<JSONObject>) hahs.get("KS_COST", code);
+    }
+
+    /**
+     * 获取告警规则集合
+     *
+     * @param
+     * @return java.util.List<cn.com.ctop.alarm.modules.entity.AlarmEventRules>
+     * @throws
+     * @author ZHAOXA
+     */
+    private List<AlarmEventRule> getAllAlarmRules(String checkType) {
+        AlarmEventRule alarmEventRule = new AlarmEventRule();
+        alarmEventRule.setEventRuleStatus(NoEn.NO1.valueStr());
+        alarmEventRule.setCheckFrequency(checkType);
+        List<AlarmEventRule> ruleList = alarmEventRuleMapper.selectListPage(alarmEventRule);
+        if (!Check.isNull(ruleList)) {
+            for (AlarmEventRule rule : ruleList) {
+                rule.setAlarmEventMetrics(alarmEventMetricMapper.selectByEventRuleId(rule.getEventRuleId()));
+                if (!"ACCOUNT".equals(rule.getEventRuleLevel())) {
+                    if (NoEn.NO1.valueStr().equals(rule.getAppStatus())) {
+                        rule.setRel(getRel(rule));
+                    } else {
+                        rule.setRel(alarmRuleCampaignRelMapper.selectByRuleId(rule.getEventRuleId()));
+                    }
+                }
+            }
+        }
+        return ruleList;
+    }
+
+    private List<AlarmRuleCampaignRel> getRel(AlarmEventRule rule) {
+        List<AlarmRuleCampaignRel> relList = new ArrayList<>();
+        AlarmRuleCampaignRel rel = null;
+        if ("CAMPAIGN".equals(rule.getEventRuleLevel())) {
+            Map<String, Object> map = new HashMap<>();
+            map.put("put_status", NoEn.NO1.valueStr());
+            map.put("account_id", rule.getAccountId());
+            List<KuaiShouCampaign> kuaiShouCampaigns = kuaiShouCampaignMapper.selectByMap(map);
+            if (!Check.isNull(kuaiShouCampaigns)) {
+                for (KuaiShouCampaign campaign : kuaiShouCampaigns) {
+                    rel = new AlarmRuleCampaignRel();
+                    rel.setCampaignId(campaign.getCampaignId());
+                    rel.setCampaignName(campaign.getCampaignName());
+                    rel.setEventRuleLevel("CAMPAIGN");
+                    relList.add(rel);
+                }
+            }
+        }
+        if ("UNIT".equals(rule.getEventRuleLevel())) {
+            Map<String, Object> map = new HashMap<>();
+            map.put("putStatus", NoEn.NO1.valueStr());
+            map.put("accountId", rule.getAccountId());
+            if (Check.isNull(rule.getCampaignId())) {
+                map.put("campaignId", rule.getCampaignId());
+            }
+            List<KuaiShouGroup> kuaiShouGroups = kuaiShouGroupMapper.queryByMap(map);
+            if (!Check.isNull(kuaiShouGroups)) {
+                for (KuaiShouGroup kuaiShouGroup : kuaiShouGroups) {
+                    rel = new AlarmRuleCampaignRel();
+                    rel.setCampaignId(kuaiShouGroup.getCampaignId());
+                    rel.setCampaignName(kuaiShouGroup.getCampaignName());
+                    rel.setEventRuleLevel("CAMPAIGN");
+                    rel.setUnitId(kuaiShouGroup.getUnitId());
+                    rel.setUnitName(kuaiShouGroup.getUnitName());
+                    relList.add(rel);
+                }
+            }
+        }
+        return relList;
+    }
 }
 }

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

@@ -3,7 +3,9 @@ package cn.com.ctop.alarm.modules.service.impl;
 import cn.com.ctop.alarm.modules.entity.AlarmMetricValue;
 import cn.com.ctop.alarm.modules.entity.AlarmMetricValue;
 import cn.com.ctop.alarm.modules.mapper.AlarmMetricValueMapper;
 import cn.com.ctop.alarm.modules.mapper.AlarmMetricValueMapper;
 import cn.com.ctop.alarm.modules.service.IAlarmMetricValueService;
 import cn.com.ctop.alarm.modules.service.IAlarmMetricValueService;
+import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
 import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
 import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
+import lombok.extern.slf4j.Slf4j;
 import org.jeecg.common.api.vo.Result;
 import org.jeecg.common.api.vo.Result;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.stereotype.Service;
 import org.springframework.stereotype.Service;
@@ -21,6 +23,7 @@ import java.util.Map;
  * @version V1.0
  * @version V1.0
  * @date 2020-10-29
  * @date 2020-10-29
  */
  */
+@Slf4j
 @Service
 @Service
 public class AlarmMetricValueServiceImpl extends ServiceImpl<AlarmMetricValueMapper, AlarmMetricValue> implements IAlarmMetricValueService {
 public class AlarmMetricValueServiceImpl extends ServiceImpl<AlarmMetricValueMapper, AlarmMetricValue> implements IAlarmMetricValueService {
 
 
@@ -30,7 +33,7 @@ public class AlarmMetricValueServiceImpl extends ServiceImpl<AlarmMetricValueMap
     @Override
     @Override
     public Result<Object> queryParentChildList(AlarmMetricValue alarmMetricValue) {
     public Result<Object> queryParentChildList(AlarmMetricValue alarmMetricValue) {
         Result<Object> result = new Result<>();
         Result<Object> result = new Result<>();
-        List<AlarmMetricValue> list = alarmMetricValueMapper.selectList(null);
+        List<AlarmMetricValue> list = alarmMetricValueMapper.queryListByLevel(alarmMetricValue);
         List<AlarmMetricValue> resultList = new ArrayList<>();
         List<AlarmMetricValue> resultList = new ArrayList<>();
         Map<Integer, List<AlarmMetricValue>> map = new HashMap<>();
         Map<Integer, List<AlarmMetricValue>> map = new HashMap<>();
         List<Integer> parents = new ArrayList<>();
         List<Integer> parents = new ArrayList<>();

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

@@ -0,0 +1,19 @@
+package cn.com.ctop.alarm.modules.service.impl;
+
+import cn.com.ctop.alarm.modules.entity.AlarmRuleCampaignRel;
+import cn.com.ctop.alarm.modules.mapper.AlarmRuleCampaignRelMapper;
+import cn.com.ctop.alarm.modules.service.IAlarmRuleCampaignRelService;
+import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
+import org.springframework.stereotype.Service;
+
+/**
+ * 规则和计划、组关系表
+ *
+ * @author jeecg-boot
+ * @version V1.0
+ * @date 2020-11-09
+ */
+@Service
+public class AlarmRuleCampaignRelServiceImpl extends ServiceImpl<AlarmRuleCampaignRelMapper, AlarmRuleCampaignRel> implements IAlarmRuleCampaignRelService {
+
+}

+ 248 - 0
module-common/src/main/java/cn/com/ctop/common/module/controller/WarningOperationLogController.java

@@ -0,0 +1,248 @@
+package cn.com.ctop.common.module.controller;
+
+import cn.com.ctop.common.module.annotation.AutoLog;
+import cn.com.ctop.common.module.entity.WarningOperationLog;
+import cn.com.ctop.common.module.service.IWarningOperationLogService;
+import com.alibaba.fastjson.JSON;
+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;
+import org.jeecg.common.api.vo.Result;
+import org.jeecg.common.system.query.QueryGenerator;
+import org.jeecg.common.util.oConvertUtils;
+import org.jeecgframework.poi.excel.ExcelImportUtil;
+import org.jeecgframework.poi.excel.def.NormalExcelConstants;
+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.*;
+import org.springframework.web.multipart.MultipartFile;
+import org.springframework.web.multipart.MultipartHttpServletRequest;
+import org.springframework.web.servlet.ModelAndView;
+
+import javax.servlet.http.HttpServletRequest;
+import javax.servlet.http.HttpServletResponse;
+import java.io.IOException;
+import java.io.UnsupportedEncodingException;
+import java.net.URLDecoder;
+import java.util.Arrays;
+import java.util.List;
+import java.util.Map;
+
+/**
+ * 预警操作记录
+ *
+ * @author jeecg-boot
+ * @version V1.0
+ * @date 2020-11-11
+ */
+@Slf4j
+@Api(tags = "预警操作记录")
+@RestController
+@RequestMapping("/wa/warningOperationLog")
+public class WarningOperationLogController {
+    @Autowired
+    private IWarningOperationLogService warningOperationLogService;
+
+    /**
+     * 分页列表查询
+     *
+     * @param warningOperationLog
+     * @param pageNo
+     * @param pageSize
+     * @param req
+     * @return
+     */
+    @AutoLog(value = "预警操作记录-分页列表查询")
+    @ApiOperation(value = "预警操作记录-分页列表查询", notes = "预警操作记录-分页列表查询")
+    @GetMapping(value = "/list")
+    public Result<IPage<WarningOperationLog>> queryPageList(WarningOperationLog warningOperationLog,
+                                                            @RequestParam(name = "pageNo", defaultValue = "1") Integer pageNo,
+                                                            @RequestParam(name = "pageSize", defaultValue = "10") Integer pageSize,
+                                                            HttpServletRequest req) {
+        Result<IPage<WarningOperationLog>> result = new Result<>();
+        QueryWrapper<WarningOperationLog> queryWrapper = QueryGenerator.initQueryWrapper(warningOperationLog, req.getParameterMap());
+        Page<WarningOperationLog> page = new Page<WarningOperationLog>(pageNo, pageSize);
+        IPage<WarningOperationLog> pageList = warningOperationLogService.page(page, queryWrapper);
+        result.setSuccess(true);
+        result.setResult(pageList);
+        return result;
+    }
+
+    /**
+     * 添加
+     *
+     * @param warningOperationLog
+     * @return
+     */
+    @AutoLog(value = "预警操作记录-添加")
+    @ApiOperation(value = "预警操作记录-添加", notes = "预警操作记录-添加")
+    @PostMapping(value = "/add")
+    public Result<WarningOperationLog> add(@RequestBody WarningOperationLog warningOperationLog) {
+        Result<WarningOperationLog> result = new Result<>();
+        try {
+            warningOperationLogService.save(warningOperationLog);
+            result.success("添加成功!");
+        } catch (Exception e) {
+            log.error(e.getMessage(), e);
+            result.error500("操作失败");
+        }
+        return result;
+    }
+
+    /**
+     * 编辑
+     *
+     * @param warningOperationLog
+     * @return
+     */
+    @AutoLog(value = "预警操作记录-编辑")
+    @ApiOperation(value = "预警操作记录-编辑", notes = "预警操作记录-编辑")
+    @PutMapping(value = "/edit")
+    public Result<WarningOperationLog> edit(@RequestBody WarningOperationLog warningOperationLog) {
+        Result<WarningOperationLog> result = new Result<WarningOperationLog>();
+        WarningOperationLog warningOperationLogEntity = warningOperationLogService.getById(warningOperationLog.getId());
+        if (warningOperationLogEntity == null) {
+            result.error500("未找到对应实体");
+        } else {
+            boolean ok = warningOperationLogService.updateById(warningOperationLog);
+            if (ok) {
+                result.success("修改成功!");
+            }
+        }
+
+        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 {
+            warningOperationLogService.removeById(id);
+        } catch (Exception e) {
+            log.error("删除失败", e.getMessage());
+            return Result.error("删除失败!");
+        }
+        return Result.ok("删除成功!");
+    }
+
+    /**
+     * 批量删除
+     *
+     * @param ids
+     * @return
+     */
+    @AutoLog(value = "预警操作记录-批量删除")
+    @ApiOperation(value = "预警操作记录-批量删除", notes = "预警操作记录-批量删除")
+    @DeleteMapping(value = "/deleteBatch")
+    public Result<WarningOperationLog> deleteBatch(@RequestParam(name = "ids", required = true) String ids) {
+        Result<WarningOperationLog> result = new Result<>();
+        if (ids == null || "".equals(ids.trim())) {
+            result.error500("参数不识别!");
+        } else {
+            this.warningOperationLogService.removeByIds(Arrays.asList(ids.split(",")));
+            result.success("删除成功!");
+        }
+        return result;
+    }
+
+    /**
+     * 通过id查询
+     *
+     * @param id
+     * @return
+     */
+    @AutoLog(value = "预警操作记录-通过id查询")
+    @ApiOperation(value = "预警操作记录-通过id查询", notes = "预警操作记录-通过id查询")
+    @GetMapping(value = "/queryById")
+    public Result<WarningOperationLog> queryById(@RequestParam(name = "id", required = true) String id) {
+        Result<WarningOperationLog> result = new Result<>();
+        WarningOperationLog warningOperationLog = warningOperationLogService.getById(id);
+        if (warningOperationLog == null) {
+            result.error500("未找到对应实体");
+        } else {
+            result.setResult(warningOperationLog);
+            result.setSuccess(true);
+        }
+        return result;
+    }
+
+    /**
+     * 导出excel
+     *
+     * @param request
+     * @param response
+     */
+    @RequestMapping(value = "/exportXls")
+    public ModelAndView exportXls(HttpServletRequest request, HttpServletResponse response) {
+        // Step.1 组装查询条件
+        QueryWrapper<WarningOperationLog> queryWrapper = null;
+        try {
+            String paramsStr = request.getParameter("paramsStr");
+            if (oConvertUtils.isNotEmpty(paramsStr)) {
+                String deString = URLDecoder.decode(paramsStr, "UTF-8");
+                WarningOperationLog warningOperationLog = JSON.parseObject(deString, WarningOperationLog.class);
+                queryWrapper = QueryGenerator.initQueryWrapper(warningOperationLog, request.getParameterMap());
+            }
+        } catch (UnsupportedEncodingException e) {
+            e.printStackTrace();
+        }
+
+        //Step.2 AutoPoi 导出Excel
+        ModelAndView mv = new ModelAndView(new JeecgEntityExcelView());
+        List<WarningOperationLog> pageList = warningOperationLogService.list(queryWrapper);
+        //导出文件名称
+        mv.addObject(NormalExcelConstants.FILE_NAME, "预警操作记录列表");
+        mv.addObject(NormalExcelConstants.CLASS, WarningOperationLog.class);
+        mv.addObject(NormalExcelConstants.PARAMS, new ExportParams("预警操作记录列表数据", "导出人:Jeecg", "导出信息"));
+        mv.addObject(NormalExcelConstants.DATA_LIST, pageList);
+        return mv;
+    }
+
+    /**
+     * 通过excel导入数据
+     *
+     * @param request
+     * @param response
+     * @return
+     */
+    @RequestMapping(value = "/importExcel", method = RequestMethod.POST)
+    public Result<?> importExcel(HttpServletRequest request, HttpServletResponse response) {
+        MultipartHttpServletRequest multipartRequest = (MultipartHttpServletRequest) request;
+        Map<String, MultipartFile> fileMap = multipartRequest.getFileMap();
+        for (Map.Entry<String, MultipartFile> entity : fileMap.entrySet()) {
+            MultipartFile file = entity.getValue();
+            ImportParams params = new ImportParams();
+            params.setTitleRows(2);
+            params.setHeadRows(1);
+            params.setNeedSave(true);
+            try {
+                List<WarningOperationLog> listWarningOperationLogs = ExcelImportUtil.importExcel(file.getInputStream(), WarningOperationLog.class, params);
+                warningOperationLogService.saveBatch(listWarningOperationLogs);
+                return Result.ok("文件导入成功!数据行数:" + listWarningOperationLogs.size());
+            } catch (Exception e) {
+                log.error(e.getMessage(), e);
+                return Result.error("文件导入失败:" + e.getMessage());
+            } finally {
+                try {
+                    file.getInputStream().close();
+                } catch (IOException e) {
+                    e.printStackTrace();
+                }
+            }
+        }
+        return Result.ok("文件导入失败!");
+    }
+
+}

+ 2 - 1
module-common/src/main/java/cn/com/ctop/common/module/entity/Project.java

@@ -127,7 +127,8 @@ public class Project {
 
 
     @TableField(exist = false)
     @TableField(exist = false)
     private Integer needExamine;
     private Integer needExamine;
-
+    private String bidType;
+    private String ocpxActionType;
 
 
    /* @TableField(exist = false)
    /* @TableField(exist = false)
     private String responsibleName; // 运营负责人
     private String responsibleName; // 运营负责人

+ 3 - 0
module-common/src/main/java/cn/com/ctop/common/module/entity/UserAllocation.java

@@ -126,6 +126,9 @@ public class UserAllocation implements Serializable {
     @ApiModelProperty(value = "平台类型 1 头条 2快手")
     @ApiModelProperty(value = "平台类型 1 头条 2快手")
     private String mediaId;
     private String mediaId;
 
 
+
+
+
    /* @TableField(exist = false)
    /* @TableField(exist = false)
     private String advertiserName;
     private String advertiserName;
 
 

+ 75 - 0
module-common/src/main/java/cn/com/ctop/common/module/entity/WarningOperationLog.java

@@ -0,0 +1,75 @@
+package cn.com.ctop.common.module.entity;
+
+import com.baomidou.mybatisplus.annotation.IdType;
+import com.baomidou.mybatisplus.annotation.TableId;
+import com.baomidou.mybatisplus.annotation.TableName;
+import io.swagger.annotations.ApiModel;
+import io.swagger.annotations.ApiModelProperty;
+import lombok.Data;
+import lombok.EqualsAndHashCode;
+import lombok.experimental.Accessors;
+import org.jeecgframework.poi.excel.annotation.Excel;
+
+import java.util.Date;
+
+/**
+ * 预警操作记录
+ *
+ * @author jeecg-boot
+ * @version V1.0
+ * @date 2020-11-11
+ */
+@Data
+@TableName("ctop_warning_operation_log")
+@EqualsAndHashCode(callSuper = false)
+@Accessors(chain = true)
+@ApiModel(value = "ctop_warning_operation_log对象", description = "预警操作记录")
+public class WarningOperationLog {
+
+    /**
+     * id
+     */
+    @TableId(type = IdType.AUTO)
+    @ApiModelProperty(value = "id")
+    private Long id;
+    /**
+     * 账户ID
+     */
+    @Excel(name = "账户ID", width = 15)
+    @ApiModelProperty(value = "账户ID")
+    private Long accountId;
+    /**
+     * 账户ID
+     */
+    @Excel(name = "账户ID", width = 15)
+    @ApiModelProperty(value = "账户ID")
+    private Long unitId;
+    /**
+     * 发送人
+     */
+    @Excel(name = "发送人", width = 15)
+    @ApiModelProperty(value = "发送人")
+    private String userId;
+    /**
+     * 标题
+     */
+    @Excel(name = "标题", width = 15)
+    @ApiModelProperty(value = "标题")
+    private String subject;
+    /**
+     * 预警类型 1 出价方式  2 出价过高
+     */
+    @Excel(name = "预警类型 1 出价方式  2 出价过高 ", width = 15)
+    @ApiModelProperty(value = "预警类型 1 出价方式  2 出价过高 ")
+    private Integer warningType;
+    /**
+     * 创建时间
+     */
+    @ApiModelProperty(value = "创建时间")
+    private Date createTime;
+    /**
+     * 修改时间
+     */
+    @ApiModelProperty(value = "修改时间")
+    private Date updateTime;
+}

+ 3 - 0
module-common/src/main/java/cn/com/ctop/common/module/mapper/ProjectMapper.java

@@ -1,6 +1,7 @@
 package cn.com.ctop.common.module.mapper;
 package cn.com.ctop.common.module.mapper;
 
 
 import cn.com.ctop.common.module.entity.Project;
 import cn.com.ctop.common.module.entity.Project;
+import com.alibaba.fastjson.JSONObject;
 import com.baomidou.mybatisplus.core.mapper.BaseMapper;
 import com.baomidou.mybatisplus.core.mapper.BaseMapper;
 import org.apache.ibatis.annotations.Param;
 import org.apache.ibatis.annotations.Param;
 
 
@@ -14,4 +15,6 @@ import org.apache.ibatis.annotations.Param;
 public interface ProjectMapper extends BaseMapper<Project> {
 public interface ProjectMapper extends BaseMapper<Project> {
 
 
     String getNameByAccountId(@Param("accountId") Long accountId);
     String getNameByAccountId(@Param("accountId") Long accountId);
+
+    JSONObject getWarningInfoByProjectId(@Param("projectId") Long projectId);
 }
 }

+ 2 - 0
module-common/src/main/java/cn/com/ctop/common/module/mapper/UserAllocationMapper.java

@@ -25,4 +25,6 @@ public interface UserAllocationMapper extends BaseMapper<UserAllocation> {
     List<JSONObject> getUserIdListByProjectId(@Param("projectId") Long projectId);
     List<JSONObject> getUserIdListByProjectId(@Param("projectId") Long projectId);
 
 
     List<JSONObject> getAccountIdListByUserId(@Param("userId") Long userId);
     List<JSONObject> getAccountIdListByUserId(@Param("userId") Long userId);
+
+    Long getProjectIdByAccountId(@Param("accountId") Long accountId);
 }
 }

+ 15 - 0
module-common/src/main/java/cn/com/ctop/common/module/mapper/WarningOperationLogMapper.java

@@ -0,0 +1,15 @@
+package cn.com.ctop.common.module.mapper;
+
+import cn.com.ctop.common.module.entity.WarningOperationLog;
+import com.baomidou.mybatisplus.core.mapper.BaseMapper;
+
+/**
+ * 预警操作记录
+ *
+ * @author: jeecg-boot
+ * @date: 2020-11-11
+ * @cersion: V1.0
+ */
+public interface WarningOperationLogMapper extends BaseMapper<WarningOperationLog> {
+
+}

+ 11 - 0
module-common/src/main/java/cn/com/ctop/common/module/mapper/xml/ProjectMapper.xml

@@ -10,4 +10,15 @@
      )
      )
     </select>
     </select>
 
 
+    <select id="getWarningInfoByProjectId" resultType="com.alibaba.fastjson.JSONObject">
+     select
+     id projectId,
+     project_name projectName,
+     max_bid maxBid,
+     bid_type bidType,
+     ocpx_action_type ocpxActionType
+     from ctop_project
+     where id = #{projectId}
+    </select>
+
 </mapper>
 </mapper>

+ 6 - 0
module-common/src/main/java/cn/com/ctop/common/module/mapper/xml/UserAllocationMapper.xml

@@ -63,5 +63,11 @@
     AND t1.account_status = 0
     AND t1.account_status = 0
     </select>
     </select>
 
 
+    <select id="getProjectIdByAccountId" resultType="java.lang.Long">
+    select  project_id  from  ctop_user_allocation
+    where account_id = #{accountId}
+    limit 1
+    </select>
+
 
 
 </mapper>
 </mapper>

+ 5 - 0
module-common/src/main/java/cn/com/ctop/common/module/mapper/xml/WarningOperationLogMapper.xml

@@ -0,0 +1,5 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
+<mapper namespace="cn.com.ctop.common.module.mapper.WarningOperationLogMapper">
+
+</mapper>

+ 23 - 0
module-common/src/main/java/cn/com/ctop/common/module/service/IMessageTemplate.java

@@ -58,4 +58,27 @@ public interface IMessageTemplate {
      */
      */
     String getAlarmCostMessage(JSONObject cost);
     String getAlarmCostMessage(JSONObject cost);
 
 
+    /**
+     * 快手 组出价方式错误消息模板
+     *
+     * @param projectName
+     * @param advertiserId
+     * @param unitId
+     * @param unit_name
+     * @return
+     */
+
+    String getKuaiShouBidTypeMessage(String projectName, Long advertiserId, Long unitId, String unit_name);
+
+
+    /**
+     * 快手 组出价过高消息模板
+     *
+     * @param projectName
+     * @param advertiserId
+     * @param unitId
+     * @param unit_name
+     * @return
+     */
+    String getKuaiShouBidMessage(String projectName, Long advertiserId, Long unitId, String unit_name);
 }
 }

+ 14 - 0
module-common/src/main/java/cn/com/ctop/common/module/service/IWarningOperationLogService.java

@@ -0,0 +1,14 @@
+package cn.com.ctop.common.module.service;
+
+import cn.com.ctop.common.module.entity.WarningOperationLog;
+import com.baomidou.mybatisplus.extension.service.IService;
+
+/**
+ * @Description: 预警操作记录
+ * @Author: jeecg-boot
+ * @Date: 2020-11-11
+ * @Version: V1.0
+ */
+public interface IWarningOperationLogService extends IService<WarningOperationLog> {
+
+}

+ 39 - 0
module-common/src/main/java/cn/com/ctop/common/module/service/impl/MessageTemplateImpl.java

@@ -5,6 +5,9 @@ import cn.com.ctop.common.module.utils.Check;
 import com.alibaba.fastjson.JSONObject;
 import com.alibaba.fastjson.JSONObject;
 import org.springframework.stereotype.Service;
 import org.springframework.stereotype.Service;
 
 
+import java.util.Arrays;
+import java.util.List;
+
 @Service
 @Service
 public class MessageTemplateImpl implements IMessageTemplate {
 public class MessageTemplateImpl implements IMessageTemplate {
 
 
@@ -156,4 +159,40 @@ public class MessageTemplateImpl implements IMessageTemplate {
                 .append(obj.getString("end"));
                 .append(obj.getString("end"));
         return text.toString();
         return text.toString();
     }
     }
+
+
+    /**
+     * @param projectName
+     * @param advertiserId
+     * @param unitId
+     * @param unit_name
+     * @return
+     */
+
+    @Override
+    public String getKuaiShouBidTypeMessage(String projectName, Long advertiserId, Long unitId, String unit_name) {
+        StringBuilder text = new StringBuilder();
+        text.append("出价方式错误预警").append("<br/>")
+                .append("您的项目:").append(projectName + ",").append("<br/>")
+                .append("下的账户:").append(advertiserId + ",").append("<br/>")
+                .append("广告组id为:").append(unitId).append("<br/>")
+                .append("广告组名称为:").append(unit_name).append("<br/>")
+                .append("出价方式设置错误。").append("<br/>")
+                .append("系统已执行暂停此组操作,请您及时查看!");
+        return text.toString();
+    }
+
+    @Override
+    public String getKuaiShouBidMessage(String projectName, Long advertiserId, Long unitId, String unit_name) {
+        StringBuilder text = new StringBuilder();
+        text.append("出价过高预警").append("<br/>")
+                .append("您的项目:").append(projectName + ",").append("<br/>")
+                .append("下的账户:").append(advertiserId + ",").append("<br/>")
+                .append("广告组id为:").append(unitId).append("<br/>")
+                .append("广告组名称为:").append(unit_name).append("<br/>")
+                .append("出价设置过高。").append("<br/>")
+                .append("系统已执行暂停此组操作,请您及时查看!");
+        return text.toString();
+    }
+
 }
 }

+ 19 - 0
module-common/src/main/java/cn/com/ctop/common/module/service/impl/WarningOperationLogServiceImpl.java

@@ -0,0 +1,19 @@
+package cn.com.ctop.common.module.service.impl;
+
+import cn.com.ctop.common.module.entity.WarningOperationLog;
+import cn.com.ctop.common.module.mapper.WarningOperationLogMapper;
+import cn.com.ctop.common.module.service.IWarningOperationLogService;
+import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
+import org.springframework.stereotype.Service;
+
+/**
+ * 预警操作记录
+ *
+ * @author jeecg-boot
+ * @version V1.0
+ * @date 2020-11-11
+ */
+@Service
+public class WarningOperationLogServiceImpl extends ServiceImpl<WarningOperationLogMapper, WarningOperationLog> implements IWarningOperationLogService {
+
+}

+ 49 - 0
module-common/src/main/java/cn/com/ctop/common/module/utils/KuaishouInterfaceConstant.java

@@ -76,6 +76,14 @@ public class KuaishouInterfaceConstant {
      */
      */
     public static final String IMAGE_GET = "/rest/openapi/v1/file/ad/image/get";
     public static final String IMAGE_GET = "/rest/openapi/v1/file/ad/image/get";
     /**
     /**
+     * 获取慕模列表
+     */
+    public static final String TEMPLATE_LIST = "/rest/openapi/v1/target/template/list";
+    /**
+     * 创建定向模板
+     */
+    public static final String TEMPLATE_CREATE = "/rest/openapi/v1/target/template/create";
+    /**
      * 获取地域信息
      * 获取地域信息
      */
      */
     public static final String REGION_LIST = "/rest/openapi/v1/region/list";
     public static final String REGION_LIST = "/rest/openapi/v1/region/list";
@@ -113,11 +121,52 @@ public class KuaishouInterfaceConstant {
     public static final String DAILY_FLOWS = "/rest/openapi/v1/advertiser/fund/daily_flows";
     public static final String DAILY_FLOWS = "/rest/openapi/v1/advertiser/fund/daily_flows";
 
 
     /**
     /**
+     * 上传人群接口
+     */
+    public static final String POPULATION_UPLOAD = "/rest/openapi/v1/dmp/population/upload";
+    /**
      * 获取人群包接口
      * 获取人群包接口
      */
      */
     public static final String POPULATION_LIST = "/rest/openapi/v1/dmp/population/list";
     public static final String POPULATION_LIST = "/rest/openapi/v1/dmp/population/list";
 
 
     /**
     /**
+     * 删除人群包接口
+     */
+    public static final String POPULATION_DELETE = "/rest/openapi/v1/dmp/population/delete";
+
+    /**
+     * 推送人群包接口
+     */
+    public static final String POPULATION_PUSH = "/rest/openapi/v1/dmp/population/push";
+
+    /**
+     * 跨账户人群包推送接口
+     */
+    public static final String POPULATION_PUSH_ACCOUNTS = "/rest/openapi/v1/dmp/population/accounts/push";
+
+    /**
+     * 游戏精选标签创建
+     * 获取游戏精选标签所有接口类型
+     */
+    public static final String POPULATION_GAME_TAG_LIST = "https://ad.e.kuaishou.com/rest/openapi/v1/dmp/population/paid/game_select_type/list";
+
+    /**
+     * 游戏精选标签人群包
+     * 游戏精选标签创建
+     */
+    public static final String POPULATION_GAME_TAG_CREATE = "/rest/openapi/v1/dmp/population/paid/game_select_tag/create";
+
+    /**
+     * DMP更新人群包接口
+     */
+    public static final String POPULATION_UPDATE = "/rest/openapi/v1/dmp/population/update";
+
+    /**
+     * 获取人群预估数量
+     */
+    public static final String POPULATION_PREDICTION = "/rest/openapi/v1/tool/audience/prediction";
+
+    /**
      * 获取可选的应用定向
      * 获取可选的应用定向
      */
      */
     public static final String APP_SEARCH = "/rest/openapi/v1/tool/app/search";
     public static final String APP_SEARCH = "/rest/openapi/v1/tool/app/search";

+ 3 - 3
module-job-kuaishou/src/main/java/cn/com/ctop/job/kuaishou/handler/KuaiShouAlarmRuleHourlyCheckJob.java

@@ -1,6 +1,6 @@
 package cn.com.ctop.job.kuaishou.handler;
 package cn.com.ctop.job.kuaishou.handler;
 
 
-import cn.com.ctop.alarm.modules.service.IAlarmEventRuleService;
+import cn.com.ctop.alarm.modules.service.IAlarmEventSendService;
 import com.xxl.job.core.biz.model.ReturnT;
 import com.xxl.job.core.biz.model.ReturnT;
 import com.xxl.job.core.handler.annotation.XxlJob;
 import com.xxl.job.core.handler.annotation.XxlJob;
 import org.quartz.JobExecutionException;
 import org.quartz.JobExecutionException;
@@ -10,7 +10,7 @@ import org.springframework.stereotype.Component;
 @Component
 @Component
 public class KuaiShouAlarmRuleHourlyCheckJob {
 public class KuaiShouAlarmRuleHourlyCheckJob {
     @Autowired
     @Autowired
-    private IAlarmEventRuleService alarmEventRuleService;
+    private IAlarmEventSendService alarmEventSendService;
 
 
     /**
     /**
      * 定时获取成本数据
      * 定时获取成本数据
@@ -20,7 +20,7 @@ public class KuaiShouAlarmRuleHourlyCheckJob {
     @XxlJob("kuaiShouAlarmRuleHourlyCheckJob")
     @XxlJob("kuaiShouAlarmRuleHourlyCheckJob")
     public ReturnT<String> execute(String param) throws Exception {
     public ReturnT<String> execute(String param) throws Exception {
         //检查频率 HOUR - 每小时;HALF_HOUR-每半小时
         //检查频率 HOUR - 每小时;HALF_HOUR-每半小时
-        alarmEventRuleService.matchAlarmRules("HOUR");
+        alarmEventSendService.matchAlarmRules("HOUR");
         return ReturnT.SUCCESS;
         return ReturnT.SUCCESS;
     }
     }
 }
 }

+ 3 - 3
module-job-kuaishou/src/main/java/cn/com/ctop/job/kuaishou/handler/KuaiShouAlarmRuleMinuteCheckJob.java

@@ -1,6 +1,6 @@
 package cn.com.ctop.job.kuaishou.handler;
 package cn.com.ctop.job.kuaishou.handler;
 
 
-import cn.com.ctop.alarm.modules.service.IAlarmEventRuleService;
+import cn.com.ctop.alarm.modules.service.IAlarmEventSendService;
 import com.xxl.job.core.biz.model.ReturnT;
 import com.xxl.job.core.biz.model.ReturnT;
 import com.xxl.job.core.handler.annotation.XxlJob;
 import com.xxl.job.core.handler.annotation.XxlJob;
 import org.quartz.JobExecutionException;
 import org.quartz.JobExecutionException;
@@ -10,7 +10,7 @@ import org.springframework.stereotype.Component;
 @Component
 @Component
 public class KuaiShouAlarmRuleMinuteCheckJob {
 public class KuaiShouAlarmRuleMinuteCheckJob {
     @Autowired
     @Autowired
-    private IAlarmEventRuleService alarmEventRuleService;
+    private IAlarmEventSendService alarmEventSendService;
 
 
     /**
     /**
      * 定时获取成本数据
      * 定时获取成本数据
@@ -20,7 +20,7 @@ public class KuaiShouAlarmRuleMinuteCheckJob {
     @XxlJob("kuaiShouAlarmRuleMinuteCheckJob")
     @XxlJob("kuaiShouAlarmRuleMinuteCheckJob")
     public ReturnT<String> execute(String param) throws Exception {
     public ReturnT<String> execute(String param) throws Exception {
         //检查频率 HOUR - 每小时;HALF_HOUR-每半小时
         //检查频率 HOUR - 每小时;HALF_HOUR-每半小时
-        alarmEventRuleService.matchAlarmRules("HALF_HOUR");
+        alarmEventSendService.matchAlarmRules("HALF_HOUR");
         return ReturnT.SUCCESS;
         return ReturnT.SUCCESS;
     }
     }
 }
 }

+ 317 - 0
module-kuaishou/src/main/java/cn/com/ctop/kuaishou/modules/batch/controller/KuaishouTemplateController.java

@@ -0,0 +1,317 @@
+package cn.com.ctop.kuaishou.modules.batch.controller;
+
+import cn.com.ctop.common.module.annotation.AutoLog;
+import cn.com.ctop.common.module.entity.CtopOauthToken;
+import cn.com.ctop.common.module.service.ICtopOauthTokenService;
+import cn.com.ctop.common.module.utils.Check;
+import cn.com.ctop.kuaishou.modules.batch.entity.KuaishouTemplate;
+import cn.com.ctop.kuaishou.modules.batch.service.IKuaishouTemplateService;
+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;
+import org.jeecg.common.api.vo.Result;
+import org.jeecg.common.system.query.QueryGenerator;
+import org.jeecg.common.util.oConvertUtils;
+import org.jeecgframework.poi.excel.ExcelImportUtil;
+import org.jeecgframework.poi.excel.def.NormalExcelConstants;
+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.*;
+import org.springframework.web.multipart.MultipartFile;
+import org.springframework.web.multipart.MultipartHttpServletRequest;
+import org.springframework.web.servlet.ModelAndView;
+
+import javax.servlet.http.HttpServletRequest;
+import javax.servlet.http.HttpServletResponse;
+import java.io.IOException;
+import java.io.UnsupportedEncodingException;
+import java.net.URLDecoder;
+import java.util.Arrays;
+import java.util.List;
+import java.util.Map;
+
+/**
+ * 快手-定向模板
+ *
+ * @author jeecg-boot
+ * @version V1.0
+ * @date 2020-11-09
+ */
+@Slf4j
+@Api(tags = "快手-定向模板")
+@RestController
+@RequestMapping("/batch/kuaishouTemplate")
+public class KuaishouTemplateController {
+    @Autowired
+    private IKuaishouTemplateService kuaishouTemplateService;
+
+    @Autowired
+    private ICtopOauthTokenService oauthTokenService;
+
+    /**
+     * 分页列表查询
+     *
+     * @param kuaishouTemplate
+     * @param pageNo
+     * @param pageSize
+     * @param req
+     * @return
+     */
+    @AutoLog(value = "快手-定向模板-分页列表查询")
+    @ApiOperation(value = "快手-定向模板-分页列表查询", notes = "快手-定向模板-分页列表查询")
+    @GetMapping(value = "/list")
+    public Result<IPage<KuaishouTemplate>> queryPageList(KuaishouTemplate kuaishouTemplate,
+                                                         @RequestParam(name = "pageNo", defaultValue = "1") Integer pageNo,
+                                                         @RequestParam(name = "pageSize", defaultValue = "10") Integer pageSize,
+                                                         HttpServletRequest req) {
+        Result<IPage<KuaishouTemplate>> result = new Result<>();
+        QueryWrapper<KuaishouTemplate> queryWrapper = QueryGenerator.initQueryWrapper(kuaishouTemplate, req.getParameterMap());
+        Page<KuaishouTemplate> page = new Page<KuaishouTemplate>(pageNo, pageSize);
+        IPage<KuaishouTemplate> pageList = kuaishouTemplateService.page(page, queryWrapper);
+        result.setSuccess(true);
+        result.setResult(pageList);
+        return result;
+    }
+
+
+    /**
+     * 根据账户获取定向模板列表
+     *
+     * @param accountId
+     * @return
+     */
+    @GetMapping(value = "/getTemplateByAccountId")
+    public Result<Boolean> queryPageList(Long accountId) {
+
+        Result<Boolean> result = new Result<>();
+        try {
+            if (Check.isNull(accountId)) {
+                throw new Exception("请选择账户id");
+            }
+
+            CtopOauthToken oauthToken = oauthTokenService.getTokenByAccountId(accountId);
+            if (Check.isNull(oauthToken)) {
+                throw new Exception("未获取到账户信息");
+            }
+
+            kuaishouTemplateService.getTemplateByAccountId(accountId, oauthToken.getAccessToken(), 1);
+            result.setSuccess(true);
+        } catch (Exception e) {
+            e.printStackTrace();
+            result.setSuccess(false);
+            result.setMessage(e.getMessage());
+        }
+        return result;
+    }
+
+
+    /**
+     * 创建定向模板
+     *
+     * @param
+     * @return
+     */
+    @GetMapping(value = "/createTemplate")
+    public Result<Boolean> createTemplate(@RequestBody JSONObject requestJson) {
+        Result<Boolean> result = new Result<>();
+        try {
+
+            Long accountId = requestJson.getLong("accountId");
+            if (Check.isNull(accountId)) {
+                throw new Exception("请选择账户id");
+            }
+            CtopOauthToken oauthToken = oauthTokenService.getTokenByAccountId(accountId);
+            if (Check.isNull(oauthToken)) {
+                throw new Exception("未获取到账户信息");
+            }
+            JSONObject returnJson = kuaishouTemplateService.createTemplate(accountId, oauthToken.getAccessToken(), requestJson);
+            result.setSuccess(true);
+        } catch (Exception e) {
+            e.printStackTrace();
+            result.setSuccess(false);
+            result.setMessage(e.getMessage());
+        }
+        return result;
+    }
+
+
+    /**
+     * 添加
+     *
+     * @param kuaishouTemplate
+     * @return
+     */
+    @AutoLog(value = "快手-定向模板-添加")
+    @ApiOperation(value = "快手-定向模板-添加", notes = "快手-定向模板-添加")
+    @PostMapping(value = "/add")
+    public Result<KuaishouTemplate> add(@RequestBody KuaishouTemplate kuaishouTemplate) {
+        Result<KuaishouTemplate> result = new Result<>();
+        try {
+            kuaishouTemplateService.save(kuaishouTemplate);
+            result.success("添加成功!");
+        } catch (Exception e) {
+            log.error(e.getMessage(), e);
+            result.error500("操作失败");
+        }
+        return result;
+    }
+
+    /**
+     * 编辑
+     *
+     * @param kuaishouTemplate
+     * @return
+     */
+    @AutoLog(value = "快手-定向模板-编辑")
+    @ApiOperation(value = "快手-定向模板-编辑", notes = "快手-定向模板-编辑")
+    @PutMapping(value = "/edit")
+    public Result<KuaishouTemplate> edit(@RequestBody KuaishouTemplate kuaishouTemplate) {
+        Result<KuaishouTemplate> result = new Result<KuaishouTemplate>();
+        KuaishouTemplate kuaishouTemplateEntity = kuaishouTemplateService.getById(kuaishouTemplate.getId());
+        if (kuaishouTemplateEntity == null) {
+            result.error500("未找到对应实体");
+        } else {
+            boolean ok = kuaishouTemplateService.updateById(kuaishouTemplate);
+            if (ok) {
+                result.success("修改成功!");
+            }
+        }
+
+        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 {
+            kuaishouTemplateService.removeById(id);
+        } catch (Exception e) {
+            log.error("删除失败", e.getMessage());
+            return Result.error("删除失败!");
+        }
+        return Result.ok("删除成功!");
+    }
+
+    /**
+     * 批量删除
+     *
+     * @param ids
+     * @return
+     */
+    @AutoLog(value = "快手-定向模板-批量删除")
+    @ApiOperation(value = "快手-定向模板-批量删除", notes = "快手-定向模板-批量删除")
+    @DeleteMapping(value = "/deleteBatch")
+    public Result<KuaishouTemplate> deleteBatch(@RequestParam(name = "ids", required = true) String ids) {
+        Result<KuaishouTemplate> result = new Result<>();
+        if (ids == null || "".equals(ids.trim())) {
+            result.error500("参数不识别!");
+        } else {
+            this.kuaishouTemplateService.removeByIds(Arrays.asList(ids.split(",")));
+            result.success("删除成功!");
+        }
+        return result;
+    }
+
+    /**
+     * 通过id查询
+     *
+     * @param id
+     * @return
+     */
+    @AutoLog(value = "快手-定向模板-通过id查询")
+    @ApiOperation(value = "快手-定向模板-通过id查询", notes = "快手-定向模板-通过id查询")
+    @GetMapping(value = "/queryById")
+    public Result<KuaishouTemplate> queryById(@RequestParam(name = "id", required = true) String id) {
+        Result<KuaishouTemplate> result = new Result<>();
+        KuaishouTemplate kuaishouTemplate = kuaishouTemplateService.getById(id);
+        if (kuaishouTemplate == null) {
+            result.error500("未找到对应实体");
+        } else {
+            result.setResult(kuaishouTemplate);
+            result.setSuccess(true);
+        }
+        return result;
+    }
+
+    /**
+     * 导出excel
+     *
+     * @param request
+     * @param response
+     */
+    @RequestMapping(value = "/exportXls")
+    public ModelAndView exportXls(HttpServletRequest request, HttpServletResponse response) {
+        // Step.1 组装查询条件
+        QueryWrapper<KuaishouTemplate> queryWrapper = null;
+        try {
+            String paramsStr = request.getParameter("paramsStr");
+            if (oConvertUtils.isNotEmpty(paramsStr)) {
+                String deString = URLDecoder.decode(paramsStr, "UTF-8");
+                KuaishouTemplate kuaishouTemplate = JSON.parseObject(deString, KuaishouTemplate.class);
+                queryWrapper = QueryGenerator.initQueryWrapper(kuaishouTemplate, request.getParameterMap());
+            }
+        } catch (UnsupportedEncodingException e) {
+            e.printStackTrace();
+        }
+
+        //Step.2 AutoPoi 导出Excel
+        ModelAndView mv = new ModelAndView(new JeecgEntityExcelView());
+        List<KuaishouTemplate> pageList = kuaishouTemplateService.list(queryWrapper);
+        //导出文件名称
+        mv.addObject(NormalExcelConstants.FILE_NAME, "快手-定向模板列表");
+        mv.addObject(NormalExcelConstants.CLASS, KuaishouTemplate.class);
+        mv.addObject(NormalExcelConstants.PARAMS, new ExportParams("快手-定向模板列表数据", "导出人:Jeecg", "导出信息"));
+        mv.addObject(NormalExcelConstants.DATA_LIST, pageList);
+        return mv;
+    }
+
+    /**
+     * 通过excel导入数据
+     *
+     * @param request
+     * @param response
+     * @return
+     */
+    @RequestMapping(value = "/importExcel", method = RequestMethod.POST)
+    public Result<?> importExcel(HttpServletRequest request, HttpServletResponse response) {
+        MultipartHttpServletRequest multipartRequest = (MultipartHttpServletRequest) request;
+        Map<String, MultipartFile> fileMap = multipartRequest.getFileMap();
+        for (Map.Entry<String, MultipartFile> entity : fileMap.entrySet()) {
+            MultipartFile file = entity.getValue();
+            ImportParams params = new ImportParams();
+            params.setTitleRows(2);
+            params.setHeadRows(1);
+            params.setNeedSave(true);
+            try {
+                List<KuaishouTemplate> listKuaishouTemplates = ExcelImportUtil.importExcel(file.getInputStream(), KuaishouTemplate.class, params);
+                kuaishouTemplateService.saveBatch(listKuaishouTemplates);
+                return Result.ok("文件导入成功!数据行数:" + listKuaishouTemplates.size());
+            } catch (Exception e) {
+                log.error(e.getMessage(), e);
+                return Result.error("文件导入失败:" + e.getMessage());
+            } finally {
+                try {
+                    file.getInputStream().close();
+                } catch (IOException e) {
+                    e.printStackTrace();
+                }
+            }
+        }
+        return Result.ok("文件导入失败!");
+    }
+
+}

+ 248 - 0
module-kuaishou/src/main/java/cn/com/ctop/kuaishou/modules/batch/controller/KuaishouTemplateTargetController.java

@@ -0,0 +1,248 @@
+package cn.com.ctop.kuaishou.modules.batch.controller;
+
+import cn.com.ctop.common.module.annotation.AutoLog;
+import cn.com.ctop.kuaishou.modules.batch.entity.KuaishouTemplateTarget;
+import cn.com.ctop.kuaishou.modules.batch.service.IKuaishouTemplateTargetService;
+import com.alibaba.fastjson.JSON;
+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;
+import org.jeecg.common.api.vo.Result;
+import org.jeecg.common.system.query.QueryGenerator;
+import org.jeecg.common.util.oConvertUtils;
+import org.jeecgframework.poi.excel.ExcelImportUtil;
+import org.jeecgframework.poi.excel.def.NormalExcelConstants;
+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.*;
+import org.springframework.web.multipart.MultipartFile;
+import org.springframework.web.multipart.MultipartHttpServletRequest;
+import org.springframework.web.servlet.ModelAndView;
+
+import javax.servlet.http.HttpServletRequest;
+import javax.servlet.http.HttpServletResponse;
+import java.io.IOException;
+import java.io.UnsupportedEncodingException;
+import java.net.URLDecoder;
+import java.util.Arrays;
+import java.util.List;
+import java.util.Map;
+
+/**
+ * 快手-定向模板-详情
+ *
+ * @author jeecg-boot
+ * @version V1.0
+ * @date 2020-11-09
+ */
+@Slf4j
+@Api(tags = "快手-定向模板-详情")
+@RestController
+@RequestMapping("/batch/kuaishouTemplateTarget")
+public class KuaishouTemplateTargetController {
+    @Autowired
+    private IKuaishouTemplateTargetService kuaishouTemplateTargetService;
+
+    /**
+     * 分页列表查询
+     *
+     * @param kuaishouTemplateTarget
+     * @param pageNo
+     * @param pageSize
+     * @param req
+     * @return
+     */
+    @AutoLog(value = "快手-定向模板-详情-分页列表查询")
+    @ApiOperation(value = "快手-定向模板-详情-分页列表查询", notes = "快手-定向模板-详情-分页列表查询")
+    @GetMapping(value = "/list")
+    public Result<IPage<KuaishouTemplateTarget>> queryPageList(KuaishouTemplateTarget kuaishouTemplateTarget,
+                                                               @RequestParam(name = "pageNo", defaultValue = "1") Integer pageNo,
+                                                               @RequestParam(name = "pageSize", defaultValue = "10") Integer pageSize,
+                                                               HttpServletRequest req) {
+        Result<IPage<KuaishouTemplateTarget>> result = new Result<>();
+        QueryWrapper<KuaishouTemplateTarget> queryWrapper = QueryGenerator.initQueryWrapper(kuaishouTemplateTarget, req.getParameterMap());
+        Page<KuaishouTemplateTarget> page = new Page<KuaishouTemplateTarget>(pageNo, pageSize);
+        IPage<KuaishouTemplateTarget> pageList = kuaishouTemplateTargetService.page(page, queryWrapper);
+        result.setSuccess(true);
+        result.setResult(pageList);
+        return result;
+    }
+
+    /**
+     * 添加
+     *
+     * @param kuaishouTemplateTarget
+     * @return
+     */
+    @AutoLog(value = "快手-定向模板-详情-添加")
+    @ApiOperation(value = "快手-定向模板-详情-添加", notes = "快手-定向模板-详情-添加")
+    @PostMapping(value = "/add")
+    public Result<KuaishouTemplateTarget> add(@RequestBody KuaishouTemplateTarget kuaishouTemplateTarget) {
+        Result<KuaishouTemplateTarget> result = new Result<>();
+        try {
+            kuaishouTemplateTargetService.save(kuaishouTemplateTarget);
+            result.success("添加成功!");
+        } catch (Exception e) {
+            log.error(e.getMessage(), e);
+            result.error500("操作失败");
+        }
+        return result;
+    }
+
+    /**
+     * 编辑
+     *
+     * @param kuaishouTemplateTarget
+     * @return
+     */
+    @AutoLog(value = "快手-定向模板-详情-编辑")
+    @ApiOperation(value = "快手-定向模板-详情-编辑", notes = "快手-定向模板-详情-编辑")
+    @PutMapping(value = "/edit")
+    public Result<KuaishouTemplateTarget> edit(@RequestBody KuaishouTemplateTarget kuaishouTemplateTarget) {
+        Result<KuaishouTemplateTarget> result = new Result<KuaishouTemplateTarget>();
+        KuaishouTemplateTarget kuaishouTemplateTargetEntity = kuaishouTemplateTargetService.getById(kuaishouTemplateTarget.getId());
+        if (kuaishouTemplateTargetEntity == null) {
+            result.error500("未找到对应实体");
+        } else {
+            boolean ok = kuaishouTemplateTargetService.updateById(kuaishouTemplateTarget);
+            if (ok) {
+                result.success("修改成功!");
+            }
+        }
+
+        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 {
+            kuaishouTemplateTargetService.removeById(id);
+        } catch (Exception e) {
+            log.error("删除失败", e.getMessage());
+            return Result.error("删除失败!");
+        }
+        return Result.ok("删除成功!");
+    }
+
+    /**
+     * 批量删除
+     *
+     * @param ids
+     * @return
+     */
+    @AutoLog(value = "快手-定向模板-详情-批量删除")
+    @ApiOperation(value = "快手-定向模板-详情-批量删除", notes = "快手-定向模板-详情-批量删除")
+    @DeleteMapping(value = "/deleteBatch")
+    public Result<KuaishouTemplateTarget> deleteBatch(@RequestParam(name = "ids", required = true) String ids) {
+        Result<KuaishouTemplateTarget> result = new Result<>();
+        if (ids == null || "".equals(ids.trim())) {
+            result.error500("参数不识别!");
+        } else {
+            this.kuaishouTemplateTargetService.removeByIds(Arrays.asList(ids.split(",")));
+            result.success("删除成功!");
+        }
+        return result;
+    }
+
+    /**
+     * 通过id查询
+     *
+     * @param id
+     * @return
+     */
+    @AutoLog(value = "快手-定向模板-详情-通过id查询")
+    @ApiOperation(value = "快手-定向模板-详情-通过id查询", notes = "快手-定向模板-详情-通过id查询")
+    @GetMapping(value = "/queryById")
+    public Result<KuaishouTemplateTarget> queryById(@RequestParam(name = "id", required = true) String id) {
+        Result<KuaishouTemplateTarget> result = new Result<>();
+        KuaishouTemplateTarget kuaishouTemplateTarget = kuaishouTemplateTargetService.getById(id);
+        if (kuaishouTemplateTarget == null) {
+            result.error500("未找到对应实体");
+        } else {
+            result.setResult(kuaishouTemplateTarget);
+            result.setSuccess(true);
+        }
+        return result;
+    }
+
+    /**
+     * 导出excel
+     *
+     * @param request
+     * @param response
+     */
+    @RequestMapping(value = "/exportXls")
+    public ModelAndView exportXls(HttpServletRequest request, HttpServletResponse response) {
+        // Step.1 组装查询条件
+        QueryWrapper<KuaishouTemplateTarget> queryWrapper = null;
+        try {
+            String paramsStr = request.getParameter("paramsStr");
+            if (oConvertUtils.isNotEmpty(paramsStr)) {
+                String deString = URLDecoder.decode(paramsStr, "UTF-8");
+                KuaishouTemplateTarget kuaishouTemplateTarget = JSON.parseObject(deString, KuaishouTemplateTarget.class);
+                queryWrapper = QueryGenerator.initQueryWrapper(kuaishouTemplateTarget, request.getParameterMap());
+            }
+        } catch (UnsupportedEncodingException e) {
+            e.printStackTrace();
+        }
+
+        //Step.2 AutoPoi 导出Excel
+        ModelAndView mv = new ModelAndView(new JeecgEntityExcelView());
+        List<KuaishouTemplateTarget> pageList = kuaishouTemplateTargetService.list(queryWrapper);
+        //导出文件名称
+        mv.addObject(NormalExcelConstants.FILE_NAME, "快手-定向模板-详情列表");
+        mv.addObject(NormalExcelConstants.CLASS, KuaishouTemplateTarget.class);
+        mv.addObject(NormalExcelConstants.PARAMS, new ExportParams("快手-定向模板-详情列表数据", "导出人:Jeecg", "导出信息"));
+        mv.addObject(NormalExcelConstants.DATA_LIST, pageList);
+        return mv;
+    }
+
+    /**
+     * 通过excel导入数据
+     *
+     * @param request
+     * @param response
+     * @return
+     */
+    @RequestMapping(value = "/importExcel", method = RequestMethod.POST)
+    public Result<?> importExcel(HttpServletRequest request, HttpServletResponse response) {
+        MultipartHttpServletRequest multipartRequest = (MultipartHttpServletRequest) request;
+        Map<String, MultipartFile> fileMap = multipartRequest.getFileMap();
+        for (Map.Entry<String, MultipartFile> entity : fileMap.entrySet()) {
+            MultipartFile file = entity.getValue();
+            ImportParams params = new ImportParams();
+            params.setTitleRows(2);
+            params.setHeadRows(1);
+            params.setNeedSave(true);
+            try {
+                List<KuaishouTemplateTarget> listKuaishouTemplateTargets = ExcelImportUtil.importExcel(file.getInputStream(), KuaishouTemplateTarget.class, params);
+                kuaishouTemplateTargetService.saveBatch(listKuaishouTemplateTargets);
+                return Result.ok("文件导入成功!数据行数:" + listKuaishouTemplateTargets.size());
+            } catch (Exception e) {
+                log.error(e.getMessage(), e);
+                return Result.error("文件导入失败:" + e.getMessage());
+            } finally {
+                try {
+                    file.getInputStream().close();
+                } catch (IOException e) {
+                    e.printStackTrace();
+                }
+            }
+        }
+        return Result.ok("文件导入失败!");
+    }
+
+}

+ 4 - 0
module-kuaishou/src/main/java/cn/com/ctop/kuaishou/modules/batch/entity/KuaiShouGroup.java

@@ -1,5 +1,6 @@
 package cn.com.ctop.kuaishou.modules.batch.entity;
 package cn.com.ctop.kuaishou.modules.batch.entity;
 
 
+import com.baomidou.mybatisplus.annotation.TableField;
 import com.baomidou.mybatisplus.annotation.TableId;
 import com.baomidou.mybatisplus.annotation.TableId;
 import com.baomidou.mybatisplus.annotation.TableName;
 import com.baomidou.mybatisplus.annotation.TableName;
 import com.fasterxml.jackson.annotation.JsonFormat;
 import com.fasterxml.jackson.annotation.JsonFormat;
@@ -44,6 +45,9 @@ public class KuaiShouGroup {
     @Excel(name = "广告活动ID", width = 15)
     @Excel(name = "广告活动ID", width = 15)
     @ApiModelProperty(value = "广告活动ID")
     @ApiModelProperty(value = "广告活动ID")
     private Long campaignId;
     private Long campaignId;
+
+    @TableField(exist = false)
+    private String campaignName;
     /**
     /**
      * 广告组ID
      * 广告组ID
      */
      */

+ 68 - 0
module-kuaishou/src/main/java/cn/com/ctop/kuaishou/modules/batch/entity/KuaishouTemplate.java

@@ -0,0 +1,68 @@
+package cn.com.ctop.kuaishou.modules.batch.entity;
+
+import com.baomidou.mybatisplus.annotation.TableName;
+import io.swagger.annotations.ApiModel;
+import io.swagger.annotations.ApiModelProperty;
+import lombok.Data;
+import lombok.EqualsAndHashCode;
+import lombok.experimental.Accessors;
+import org.jeecgframework.poi.excel.annotation.Excel;
+
+import java.util.Date;
+
+/**
+ * 快手-定向模板
+ *
+ * @author jeecg-boot
+ * @version V1.0
+ * @date 2020-11-09
+ */
+@Data
+@TableName("ctop_kuaishou_template")
+@EqualsAndHashCode(callSuper = false)
+@Accessors(chain = true)
+@ApiModel(value = "ctop_kuaishou_template对象", description = "快手-定向模板")
+public class KuaishouTemplate {
+
+    /**
+     * id
+     */
+    @ApiModelProperty(value = "id")
+    private String id;
+    /**
+     * 账户ID
+     */
+    @Excel(name = "账户ID", width = 15)
+    @ApiModelProperty(value = "账户ID")
+    private Long accountId;
+    /**
+     * 定向模板id
+     */
+    @Excel(name = "定向模板id", width = 15)
+    @ApiModelProperty(value = "定向模板id")
+    private Long templateId;
+    /**
+     * 模板名称
+     */
+    @Excel(name = "模板名称", width = 15)
+    @ApiModelProperty(value = "模板名称")
+    private String templateName;
+    /**
+     * 绑定组个数
+     */
+    @Excel(name = "绑定组个数", width = 15)
+    @ApiModelProperty(value = "绑定组个数")
+    private Integer unitCount;
+    /**
+     * 定向模板创建时间
+     */
+    @Excel(name = "定向模板创建时间", width = 15)
+    @ApiModelProperty(value = "定向模板创建时间")
+    private Date createTime;
+    /**
+     * 定向模板修改时间
+     */
+    @Excel(name = "定向模板修改时间", width = 15)
+    @ApiModelProperty(value = "定向模板修改时间")
+    private Date updateTime;
+}

+ 212 - 0
module-kuaishou/src/main/java/cn/com/ctop/kuaishou/modules/batch/entity/KuaishouTemplateTarget.java

@@ -0,0 +1,212 @@
+package cn.com.ctop.kuaishou.modules.batch.entity;
+
+import com.baomidou.mybatisplus.annotation.TableName;
+import io.swagger.annotations.ApiModel;
+import io.swagger.annotations.ApiModelProperty;
+import lombok.Data;
+import lombok.EqualsAndHashCode;
+import lombok.experimental.Accessors;
+import org.jeecgframework.poi.excel.annotation.Excel;
+
+import java.util.Date;
+
+/**
+ * 快手-定向模板-详情
+ *
+ * @author jeecg-boot
+ * @version V1.0
+ * @date 2020-11-09
+ */
+@Data
+@TableName("ctop_kuaishou_template_target")
+@EqualsAndHashCode(callSuper = false)
+@Accessors(chain = true)
+@ApiModel(value = "ctop_kuaishou_template_target对象", description = "快手-定向模板-详情")
+public class KuaishouTemplateTarget {
+
+    /**
+     * id
+     */
+    @ApiModelProperty(value = "id")
+    private String id;
+    /**
+     * 定向模板id
+     */
+    @Excel(name = "定向模板id", width = 15)
+    @ApiModelProperty(value = "定向模板id")
+    private Long templateId;
+    /**
+     * 地域
+     */
+    @Excel(name = "地域", width = 15)
+    @ApiModelProperty(value = "地域")
+    private String region;
+    /**
+     * 商圈定向
+     */
+    @Excel(name = "商圈定向", width = 15)
+    @ApiModelProperty(value = "商圈定向")
+    private String districtIds;
+    /**
+     * 用户类型 0:实时1:常驻 2:不限
+     */
+    @Excel(name = "用户类型 0:实时1:常驻 2:不限 ", width = 15)
+    @ApiModelProperty(value = "用户类型 0:实时1:常驻 2:不限 ")
+    private Integer userType;
+    /**
+     * 可选年龄段 18:18-23岁 24:24-30岁 31:31-40岁 41:41-49岁 50:50-100岁
+     */
+    @Excel(name = "可选年龄段 18:18-23岁 24:24-30岁 31:31-40岁 41:41-49岁 50:50-100岁 ", width = 15)
+    @ApiModelProperty(value = "可选年龄段 18:18-23岁 24:24-30岁 31:31-40岁 41:41-49岁 50:50-100岁 ")
+    private String agesRange;
+    /**
+     * 年龄最小值
+     */
+    @Excel(name = "年龄最小值", width = 15)
+    @ApiModelProperty(value = "年龄最小值")
+    private Integer min;
+    /**
+     * 年龄最大值
+     */
+    @Excel(name = "年龄最大值", width = 15)
+    @ApiModelProperty(value = "年龄最大值")
+    private Integer max;
+    /**
+     * 性别 1:女性, 2:男性,0 表示不限
+     */
+    @Excel(name = "性别 1:女性, 2:男性,0 表示不限", width = 15)
+    @ApiModelProperty(value = "性别 1:女性, 2:男性,0 表示不限")
+    private Integer gender;
+    /**
+     * 定向的 os 版本 应用安装类计划以app_id中的platform_os为准 1:Android,2:iOS,0 表示不限
+     */
+    @Excel(name = "定向的 os 版本 应用安装类计划以app_id中的platform_os为准 1:Android,2:iOS,0 表示不限", width = 15)
+    @ApiModelProperty(value = "定向的 os 版本 应用安装类计划以app_id中的platform_os为准 1:Android,2:iOS,0 表示不限")
+    private Integer platformOs;
+    /**
+     * Android 版本 3:不限,4:4.x+,5:5.x+,6:6.x+,7:7.x+
+     */
+    @Excel(name = "Android 版本 3:不限,4:4.x+,5:5.x+,6:6.x+,7:7.x+", width = 15)
+    @ApiModelProperty(value = "Android 版本 3:不限,4:4.x+,5:5.x+,6:6.x+,7:7.x+")
+    private Integer androidOsv;
+    /**
+     * iOS 版本 6:不限, 7:7.x+, 8:8.x+, 9:9.x+, 10:10.x+
+     */
+    @Excel(name = "iOS 版本 6:不限, 7:7.x+, 8:8.x+, 9:9.x+, 10:10.x+", width = 15)
+    @ApiModelProperty(value = "iOS 版本 6:不限, 7:7.x+, 8:8.x+, 9:9.x+, 10:10.x+")
+    private Integer iosOsv;
+    /**
+     * 网络环境 1:WI-FI,2:移动网络,0:表示不限
+     */
+    @Excel(name = "网络环境 1:WI-FI,2:移动网络,0:表示不限", width = 15)
+    @ApiModelProperty(value = "网络环境 1:WI-FI,2:移动网络,0:表示不限")
+    private Integer network;
+    /**
+     * 过滤已转化人群纬度 0:不限 1:广告组 2:广告计划 3:本账户 4:公司主体 5:APP
+     */
+    @Excel(name = "过滤已转化人群纬度 0:不限 1:广告组 2:广告计划 3:本账户 4:公司主体 5:APP", width = 15)
+    @ApiModelProperty(value = "过滤已转化人群纬度 0:不限 1:广告组 2:广告计划 3:本账户 4:公司主体 5:APP")
+    private Integer filterConvertedLevel;
+    /**
+     * 设备品牌  1:OPPO,2:VIVO, 3:华为,4:小米,5:荣耀,6:三星,7:金立,8:魅族,9:乐视,10:其他,11:苹果(只有 platform_os 为不限时支持此选项);传值为 [] 表示不限;当 platform_os 表示 iOS 的时候,没有设备品牌定向
+     */
+    @Excel(name = "设备品牌  1:OPPO,2:VIVO, 3:华为,4:小米,5:荣耀,6:三星,7:金立,8:魅族,9:乐视,10:其他,11:苹果(只有 platform_os 为不限时支持此选项);传值为 [] 表示不限;当 platform_os 表示 iOS 的时候,没有设备品牌定向", width = 15)
+    @ApiModelProperty(value = "设备品牌  1:OPPO,2:VIVO, 3:华为,4:小米,5:荣耀,6:三星,7:金立,8:魅族,9:乐视,10:其他,11:苹果(只有 platform_os 为不限时支持此选项);传值为 [] 表示不限;当 platform_os 表示 iOS 的时候,没有设备品牌定向")
+    private String deviceBrand;
+    /**
+     * 设备价格 1:1,500元以下,2:1,501~2,000,3:2,001~2,500,4:2,501~3,000,5、3,001~3,500,6:3,501~4,000,7:4,001~4,500,8:4,501~5,000,9:5,001~5,500,10:5,500元以上,传值为 [] 表示不限
+     */
+    @Excel(name = "设备价格 1:1,500元以下,2:1,501~2,000,3:2,001~2,500,4:2,501~3,000,5、3,001~3,500,6:3,501~4,000,7:4,001~4,500,8:4,501~5,000,9:5,001~5,500,10:5,500元以上,传值为 [] 表示不限", width = 15)
+    @ApiModelProperty(value = "设备价格 1:1,500元以下,2:1,501~2,000,3:2,001~2,500,4:2,501~3,000,5、3,001~3,500,6:3,501~4,000,7:4,001~4,500,8:4,501~5,000,9:5,001~5,500,10:5,500元以上,传值为 [] 表示不限")
+    private String devicePrice;
+    /**
+     * 商业兴趣类型 0:默认值 1:智能投放 2:兴趣标签
+     */
+    @Excel(name = "商业兴趣类型 0:默认值 1:智能投放 2:兴趣标签", width = 15)
+    @ApiModelProperty(value = "商业兴趣类型 0:默认值 1:智能投放 2:兴趣标签")
+    private Integer businessInterestType;
+    /**
+     * 商业兴趣
+     */
+    @Excel(name = "商业兴趣", width = 15)
+    @ApiModelProperty(value = "商业兴趣")
+    private String businessInterest;
+    /**
+     * 网红类别
+     */
+    @Excel(name = "网红类别", width = 15)
+    @ApiModelProperty(value = "网红类别")
+    private String fansStar;
+    /**
+     * 兴趣视频
+     */
+    @Excel(name = "兴趣视频", width = 15)
+    @ApiModelProperty(value = "兴趣视频")
+    private String interestVideo;
+    /**
+     * APP行为-按分类
+     */
+    @Excel(name = "APP行为-按分类", width = 15)
+    @ApiModelProperty(value = "APP行为-按分类")
+    private String appInterest;
+    /**
+     * APP行为-按APP名称
+     */
+    @Excel(name = "APP行为-按APP名称", width = 15)
+    @ApiModelProperty(value = "APP行为-按APP名称")
+    private String appIds;
+    /**
+     * 定向人群包
+     */
+    @Excel(name = "定向人群包", width = 15)
+    @ApiModelProperty(value = "定向人群包")
+    private String population;
+    /**
+     * 付费人群包
+     */
+    @Excel(name = "付费人群包", width = 15)
+    @ApiModelProperty(value = "付费人群包")
+    private String paidAudience;
+    /**
+     * 排除人群包
+     */
+    @Excel(name = "排除人群包", width = 15)
+    @ApiModelProperty(value = "排除人群包")
+    private String excludePopulation;
+    /**
+     * 开启智能扩量 默认为0,为1时打开智能扩量,其他数值报错;关闭智能扩量时,以下三个字段必须为0
+     */
+    @Excel(name = "开启智能扩量 默认为0,为1时打开智能扩量,其他数值报错;关闭智能扩量时,以下三个字段必须为0", width = 15)
+    @ApiModelProperty(value = "开启智能扩量 默认为0,为1时打开智能扩量,其他数值报错;关闭智能扩量时,以下三个字段必须为0")
+    private Integer isOpen;
+    /**
+     * 不可突破年龄 默认为0(可突破/无需控制),定向age数据不为空时,可设为1(不可突破)
+     */
+    @Excel(name = "不可突破年龄 默认为0(可突破/无需控制),定向age数据不为空时,可设为1(不可突破)", width = 15)
+    @ApiModelProperty(value = "不可突破年龄 默认为0(可突破/无需控制),定向age数据不为空时,可设为1(不可突破)")
+    private Integer noAgeBreak;
+    /**
+     * 不可突破性别 默认为0(可突破/无需控制),定向gender数据不为空时,可设为1(不可突破
+     */
+    @Excel(name = "不可突破性别 默认为0(可突破/无需控制),定向gender数据不为空时,可设为1(不可突破", width = 15)
+    @ApiModelProperty(value = "不可突破性别 默认为0(可突破/无需控制),定向gender数据不为空时,可设为1(不可突破")
+    private Integer noGenderBreak;
+    /**
+     * 不可突破地域 默认为0(可突破/无需控制),定向region数据不为空时,可设为1(不可突破)
+     */
+    @Excel(name = "不可突破地域 默认为0(可突破/无需控制),定向region数据不为空时,可设为1(不可突破)", width = 15)
+    @ApiModelProperty(value = "不可突破地域 默认为0(可突破/无需控制),定向region数据不为空时,可设为1(不可突破)")
+    private Integer noAreaBreak;
+    /**
+     * 定向模板创建时间
+     */
+    @Excel(name = "定向模板创建时间", width = 15)
+    @ApiModelProperty(value = "定向模板创建时间")
+    private Date createTime;
+    /**
+     * 定向模板修改时间
+     */
+    @Excel(name = "定向模板修改时间", width = 15)
+    @ApiModelProperty(value = "定向模板修改时间")
+    private Date updateTime;
+}

+ 2 - 0
module-kuaishou/src/main/java/cn/com/ctop/kuaishou/modules/batch/mapper/KuaiShouCampaignMapper.java

@@ -15,4 +15,6 @@ import java.util.List;
 public interface KuaiShouCampaignMapper extends BaseMapper<KuaiShouCampaign> {
 public interface KuaiShouCampaignMapper extends BaseMapper<KuaiShouCampaign> {
 
 
     void replaceBatch(@Param(value = "campaigns") List<KuaiShouCampaign> campaigns);
     void replaceBatch(@Param(value = "campaigns") List<KuaiShouCampaign> campaigns);
+
+    List<Long> queryIdsByPutStatus(Long accountId,String putStatus);
 }
 }

+ 3 - 0
module-kuaishou/src/main/java/cn/com/ctop/kuaishou/modules/batch/mapper/KuaiShouGroupMapper.java

@@ -6,6 +6,7 @@ import org.apache.ibatis.annotations.Param;
 
 
 import java.math.BigDecimal;
 import java.math.BigDecimal;
 import java.util.List;
 import java.util.List;
+import java.util.Map;
 
 
 /**
 /**
  * @Description: 广告组信息
  * @Description: 广告组信息
@@ -19,4 +20,6 @@ public interface KuaiShouGroupMapper extends BaseMapper<KuaiShouGroup> {
     List<String> selectWarningGroup(@Param("accountId") Long accountId, @Param("maxBid") Long maxBid);
     List<String> selectWarningGroup(@Param("accountId") Long accountId, @Param("maxBid") Long maxBid);
 
 
     List<String> selectWarningCpaBid(@Param("accountId") Long accountId, @Param("maxBid") BigDecimal maxDeepCapBid);
     List<String> selectWarningCpaBid(@Param("accountId") Long accountId, @Param("maxBid") BigDecimal maxDeepCapBid);
+
+    List<KuaiShouGroup> queryByMap(Map<String, Object> map);
 }
 }

+ 15 - 0
module-kuaishou/src/main/java/cn/com/ctop/kuaishou/modules/batch/mapper/KuaishouTemplateMapper.java

@@ -0,0 +1,15 @@
+package cn.com.ctop.kuaishou.modules.batch.mapper;
+
+import cn.com.ctop.kuaishou.modules.batch.entity.KuaishouTemplate;
+import com.baomidou.mybatisplus.core.mapper.BaseMapper;
+
+/**
+ * 快手-定向模板
+ *
+ * @author: jeecg-boot
+ * @date: 2020-11-09
+ * @cersion: V1.0
+ */
+public interface KuaishouTemplateMapper extends BaseMapper<KuaishouTemplate> {
+
+}

+ 15 - 0
module-kuaishou/src/main/java/cn/com/ctop/kuaishou/modules/batch/mapper/KuaishouTemplateTargetMapper.java

@@ -0,0 +1,15 @@
+package cn.com.ctop.kuaishou.modules.batch.mapper;
+
+import cn.com.ctop.kuaishou.modules.batch.entity.KuaishouTemplateTarget;
+import com.baomidou.mybatisplus.core.mapper.BaseMapper;
+
+/**
+ * 快手-定向模板-详情
+ *
+ * @author: jeecg-boot
+ * @date: 2020-11-09
+ * @cersion: V1.0
+ */
+public interface KuaishouTemplateTargetMapper extends BaseMapper<KuaishouTemplateTarget> {
+
+}

+ 8 - 0
module-kuaishou/src/main/java/cn/com/ctop/kuaishou/modules/batch/mapper/xml/KuaiShouCampaignMapper.xml

@@ -33,4 +33,12 @@
             #{campaign.updateTime})
             #{campaign.updateTime})
         </foreach>
         </foreach>
     </insert>
     </insert>
+
+    <select id="queryIdsByPutStatus" resultType="java.lang.Long">
+        SELECT campaign_id
+        FROM
+        ctop_kuaishou_campaign
+        WHERE account_id = #{accountId}
+        AND put_status = #{putStatus}
+    </select>
 </mapper>
 </mapper>

+ 13 - 0
module-kuaishou/src/main/java/cn/com/ctop/kuaishou/modules/batch/mapper/xml/KuaiShouGroupMapper.xml

@@ -98,5 +98,18 @@
    group by unit_id
    group by unit_id
     </select>
     </select>
 
 
+    <select id="queryByMap" resultType="cn.com.ctop.kuaishou.modules.batch.entity.KuaiShouGroup">
+        SELECT
+        t1.*,t2.campaign_name as campaignName
+        FROM ctop_kuaishou_group t1
+        LEFT JOIN ctop_kuaishou_campaign t2
+        ON t1.campaign_id = t2.campaign_id
+        WHERE t1.account_id = #{accountId}
+        and t1.put_status = #{putStatus}
+        <if test="campaignId != null">
+            t1.campaign_id = #{campaignId}
+        </if>
+    </select>
+
 
 
 </mapper>
 </mapper>

+ 5 - 0
module-kuaishou/src/main/java/cn/com/ctop/kuaishou/modules/batch/mapper/xml/KuaishouTemplateMapper.xml

@@ -0,0 +1,5 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
+<mapper namespace="cn.com.ctop.kuaishou.modules.batch.mapper.KuaishouTemplateMapper">
+
+</mapper>

+ 5 - 0
module-kuaishou/src/main/java/cn/com/ctop/kuaishou/modules/batch/mapper/xml/KuaishouTemplateTargetMapper.xml

@@ -0,0 +1,5 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
+<mapper namespace="cn.com.ctop.kuaishou.modules.batch.mapper.KuaishouTemplateTargetMapper">
+
+</mapper>

+ 1 - 0
module-kuaishou/src/main/java/cn/com/ctop/kuaishou/modules/batch/service/IKuaiShouCampaignCreateService.java

@@ -12,4 +12,5 @@ import com.baomidou.mybatisplus.extension.service.IService;
 public interface IKuaiShouCampaignCreateService extends IService<KuaiShouCampaignCreate> {
 public interface IKuaiShouCampaignCreateService extends IService<KuaiShouCampaignCreate> {
 
 
     KuaiShouCampaignCreate selectCampaignByCampaignId(String campaignId);
     KuaiShouCampaignCreate selectCampaignByCampaignId(String campaignId);
+
 }
 }

+ 89 - 0
module-kuaishou/src/main/java/cn/com/ctop/kuaishou/modules/batch/service/IKuaishouPopulationService.java

@@ -1,8 +1,11 @@
 package cn.com.ctop.kuaishou.modules.batch.service;
 package cn.com.ctop.kuaishou.modules.batch.service;
 
 
 import cn.com.ctop.kuaishou.modules.batch.entity.KuaishouPopulation;
 import cn.com.ctop.kuaishou.modules.batch.entity.KuaishouPopulation;
+import com.alibaba.fastjson.JSONObject;
 import com.baomidou.mybatisplus.extension.service.IService;
 import com.baomidou.mybatisplus.extension.service.IService;
 
 
+import java.io.File;
+
 /**
 /**
  * 人群包列表
  * 人群包列表
  *
  *
@@ -11,5 +14,91 @@ import com.baomidou.mybatisplus.extension.service.IService;
  * @date 2020-05-06
  * @date 2020-05-06
  */
  */
 public interface IKuaishouPopulationService extends IService<KuaishouPopulation> {
 public interface IKuaishouPopulationService extends IService<KuaishouPopulation> {
+    /**
+     * 获取人群包接口
+     *
+     * @param accountId
+     * @param populationId 人群包ID
+     * @param accessToken  token
+     * @param accountId    广告主ID
+     * @return
+     */
+    boolean deletePopulation(Long accountId, String populationId, String accessToken);
+
+    /**
+     * 获取人群包接口
+     *
+     * @param accountId
+     * @param populationName 人群包名称
+     * @param type           1:IMEI 2:IDFA 3:IMEI_MD5 4:IDFA_MD5 5:手机号-MD5 7:OAID
+     * @param accountId      广告主ID
+     * @param file           请求的页码
+     * @param accessToken    token
+     * @return
+     */
+    JSONObject updatePopulation(Long accountId, int type, String populationName, File file, String accessToken);
+
+    /**
+     * 推送人群包接口(单日最多可调用50次推送接口)
+     *
+     * @param accountId
+     * @param populationId 人群包ID (只有status为1或6的人群包可推送,最多支持4个人群包状态同时为“推送中”)
+     * @param accessToken  token
+     * @param accountId    广告主ID
+     * @return
+     */
+    boolean pushPopulation(Long accountId, String populationId, String accessToken);
+
+    /**
+     * 跨账户人群包推送接口
+     *
+     * @param populationId 人群包ID
+     * @param accessToken  token
+     * @param accountId    广告主ID
+     * @param ids          要推送的账户ids
+     * @return
+     */
+    boolean pushAccountsPopulation(Long accountId, String populationId, Long[] ids, String accessToken);
+
+    /**
+     * 游戏精选标签人群包
+     * 获取游戏精选标签所有接口类型
+     *
+     * @param accessToken token
+     * @return
+     */
+    JSONObject selectGameTags(String accessToken);
+
+    /**
+     * 游戏精选标签人群包
+     * 游戏精选标签创建
+     *
+     * @param accessToken token
+     * @param accountId   广告主ID
+     * @return
+     */
+    Long createGameTags(Long accountId, JSONObject obj, String accessToken);
+
+    /**
+     * DMP更新人群包接口
+     *
+     * @param populationId   人群包ID
+     * @param populationType 1:APPEND(增量更新)
+     * @param type           人群数据类型 1:IMEI 2:IDFA 3:IMEI_MD5 4:IDFA_MD5 7:OAID 8:OAID_MD5
+     * @param accessToken    token
+     * @param accountId      广告主ID
+     * @param file           请求的文件,最大支持500MB
+     * @return
+     */
+    JSONObject updatePopulation(Long accountId, Integer type, Long populationId, Integer populationType, File file, String accessToken);
+
+    /**
+     * 获取人群预估数量
+     *
+     * @param accessToken token
+     * @param accountId   广告主ID
+     * @return
+     */
+    Long predictionPopulation(Long accountId, JSONObject obj, String accessToken);
 
 
 }
 }

+ 21 - 0
module-kuaishou/src/main/java/cn/com/ctop/kuaishou/modules/batch/service/IKuaishouTemplateService.java

@@ -0,0 +1,21 @@
+package cn.com.ctop.kuaishou.modules.batch.service;
+
+import cn.com.ctop.kuaishou.modules.batch.entity.KuaishouTemplate;
+import com.alibaba.fastjson.JSONObject;
+import com.baomidou.mybatisplus.extension.service.IService;
+
+/**
+ * @Description: 快手-定向模板
+ * @Author: jeecg-boot
+ * @Date: 2020-11-09
+ * @Version: V1.0
+ */
+public interface IKuaishouTemplateService extends IService<KuaishouTemplate> {
+
+    void getTemplateByAccountId(Long accountId, String accessToken, Integer page);
+
+    JSONObject createTemplate(Long accountId, String accessToken, JSONObject requestJson);
+
+
+    JSONObject updateTemplate(Long accountId, String accessToken, JSONObject requestJson);
+}

+ 14 - 0
module-kuaishou/src/main/java/cn/com/ctop/kuaishou/modules/batch/service/IKuaishouTemplateTargetService.java

@@ -0,0 +1,14 @@
+package cn.com.ctop.kuaishou.modules.batch.service;
+
+import cn.com.ctop.kuaishou.modules.batch.entity.KuaishouTemplateTarget;
+import com.baomidou.mybatisplus.extension.service.IService;
+
+/**
+ * @Description: 快手-定向模板-详情
+ * @Author: jeecg-boot
+ * @Date: 2020-11-09
+ * @Version: V1.0
+ */
+public interface IKuaishouTemplateTargetService extends IService<KuaishouTemplateTarget> {
+
+}

+ 31 - 0
module-kuaishou/src/main/java/cn/com/ctop/kuaishou/modules/batch/service/IWarningOperationService.java

@@ -0,0 +1,31 @@
+package cn.com.ctop.kuaishou.modules.batch.service;
+
+import com.alibaba.fastjson.JSONObject;
+
+public interface IWarningOperationService {
+    JSONObject getBidTypeAndMaxBid(Long accountId);
+
+    /**
+     * 快手 出价方式 预警 && 操作
+     *
+     * @param projectId
+     * @param projectName
+     * @param advertiserId
+     * @param unitId
+     * @param unit_name
+     */
+    void kuaiShouWarningOperation(Long projectId, String projectName, Long advertiserId, Long unitId, String unit_name);
+
+
+    /**
+     * 出价 过高预警 && 操作
+     *
+     * @param projectId
+     * @param projectName
+     * @param advertiserId
+     * @param unitId
+     * @param unit_name
+     */
+
+    void kuaiShouBidWarningOperation(Long projectId, String projectName, Long advertiserId, Long unitId, String unit_name);
+}

+ 67 - 7
module-kuaishou/src/main/java/cn/com/ctop/kuaishou/modules/batch/service/impl/KuaiShouGroupServiceImpl.java

@@ -12,6 +12,7 @@ import cn.com.ctop.kuaishou.modules.batch.mapper.KuaiShouScheduleMapper;
 import cn.com.ctop.kuaishou.modules.batch.service.IKuaiShouCampaignService;
 import cn.com.ctop.kuaishou.modules.batch.service.IKuaiShouCampaignService;
 import cn.com.ctop.kuaishou.modules.batch.service.IKuaiShouCreativeService;
 import cn.com.ctop.kuaishou.modules.batch.service.IKuaiShouCreativeService;
 import cn.com.ctop.kuaishou.modules.batch.service.IKuaiShouGroupService;
 import cn.com.ctop.kuaishou.modules.batch.service.IKuaiShouGroupService;
+import cn.com.ctop.kuaishou.modules.batch.service.IWarningOperationService;
 import com.alibaba.fastjson.JSONArray;
 import com.alibaba.fastjson.JSONArray;
 import com.alibaba.fastjson.JSONObject;
 import com.alibaba.fastjson.JSONObject;
 import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
 import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
@@ -260,8 +261,19 @@ public class KuaiShouGroupServiceImpl extends ServiceImpl<KuaiShouGroupMapper, K
 
 
     }
     }
 
 
+    static ExecutorService executorBidTypeService = Executors.newFixedThreadPool(20);
+    static ExecutorService executorMaxBidService = Executors.newFixedThreadPool(5);
+    @Autowired
+    private IWarningOperationService warningOperationService;
 
 
     private void addGroupV2(Long advertiserId, JSONArray details) {
     private void addGroupV2(Long advertiserId, JSONArray details) {
+
+        JSONObject json = warningOperationService.getBidTypeAndMaxBid(advertiserId);
+        Long maxBid = json.getLong("maxBid");// 最高出价
+        String bidTypeStr = json.getString("bidType"); // 出价方式
+        JSONArray bidTypeArr = JSONArray.parseArray(bidTypeStr);
+        String ocpxActionTypeStr = json.getString("ocpxActionType"); // 优化目标
+        JSONArray bidArr = JSONArray.parseArray(ocpxActionTypeStr);
         if (!Check.isNull(details)) {
         if (!Check.isNull(details)) {
             List<KuaiShouGroup> groups = new ArrayList<>();
             List<KuaiShouGroup> groups = new ArrayList<>();
             List<KuaiShouAppInfo> appInfos = new ArrayList<>();
             List<KuaiShouAppInfo> appInfos = new ArrayList<>();
@@ -270,21 +282,69 @@ public class KuaiShouGroupServiceImpl extends ServiceImpl<KuaiShouGroupMapper, K
             for (int i = 0; i < details.size(); i++) {
             for (int i = 0; i < details.size(); i++) {
                 JSONObject detail = JSONObject.parseObject(details.get(i).toString());
                 JSONObject detail = JSONObject.parseObject(details.get(i).toString());
                 if (!Check.isNull(detail)) {
                 if (!Check.isNull(detail)) {
-                    KuaiShouGroup group = new KuaiShouGroup();
+                    Integer bid_type = detail.getInteger("bid_type");
+                    Long bid = detail.getLong("bid");
+                    Long cpa_bid = detail.getLong("cpa_bid");
+                    Long day_budget = detail.getLong("day_budget");
+                    Integer ocpx_action_type = detail.getInteger("ocpx_action_type");
                     Long unitId = detail.getLong("unit_id");
                     Long unitId = detail.getLong("unit_id");
+                    String unit_name = detail.getString("unit_name");
+                    Integer status = detail.getInteger("status");
+                    Integer put_status = detail.getInteger("put_status");
+                    if (put_status == 1) { // 组状态为 投放中的
+                        if (status != 15) { // 广告组状态为非暂停
+                            Boolean ocpxTrueOrFalse = false;
+                            for (int j = 0; j < bidArr.size(); j++) {
+                                Integer ocpxActionType = (Integer) bidArr.get(j);
+                                if (ocpxActionType.equals(ocpx_action_type)) {
+                                    ocpxTrueOrFalse = true;
+                                    break;
+                                }
+                            }
+                            Boolean bidTypeTrueOrFalse = false;
+                            for (int j = 0; j < bidTypeArr.size(); j++) {
+                                Integer bidType = (Integer) bidTypeArr.get(j);
+                                if (bidType.equals(bid_type)) {
+                                    bidTypeTrueOrFalse = true;
+                                    break;
+                                }
+                            }
+                            if (!bidTypeTrueOrFalse || !ocpxTrueOrFalse) { // 出价方式设置非法
+                                if (day_budget > 500 * 1000 || day_budget == 0) { // 预算大于500 或者不限制预算 需要发送通知 并且进行暂停操作
+                                    executorBidTypeService.submit(new Runnable() {
+                                        @Override
+                                        public void run() {
+                                            warningOperationService.kuaiShouWarningOperation(json.getLong("projectId"), json.getString("projectName"), advertiserId, unitId, unit_name);
+                                        }
+                                    });
+                                }
+                            }
+                            if (bid > maxBid || cpa_bid > maxBid) {
+                                executorMaxBidService.submit(new Runnable() {
+                                    @Override
+                                    public void run() {
+                                        warningOperationService.kuaiShouBidWarningOperation(json.getLong("projectId"), json.getString("projectName"), advertiserId, unitId, unit_name);
+                                    }
+                                });
+                            }
+                        }
+                    }
+
+
+                    KuaiShouGroup group = new KuaiShouGroup();
                     group.setId("" + advertiserId + unitId);
                     group.setId("" + advertiserId + unitId);
                     group.setAccountId(advertiserId);
                     group.setAccountId(advertiserId);
                     group.setCampaignId(detail.getLong("campaign_id"));
                     group.setCampaignId(detail.getLong("campaign_id"));
                     group.setUnitId(unitId);
                     group.setUnitId(unitId);
-                    group.setUnitName(detail.getString("unit_name"));
-                    group.setStatus(detail.getInteger("status"));
-                    group.setPutStatus(detail.getInteger("put_status"));
+                    group.setUnitName(unit_name);
+                    group.setStatus(status);
+                    group.setPutStatus(put_status);
                     group.setCreateChannel(detail.getInteger("create_channel"));
                     group.setCreateChannel(detail.getInteger("create_channel"));
                     group.setReviewDetail(detail.getString("review_detail"));
                     group.setReviewDetail(detail.getString("review_detail"));
-                    group.setBidType(detail.getInteger("bid_type"));
-                    group.setBid(detail.getLong("bid"));
+                    group.setBidType(bid_type);
+                    group.setBid(bid);
                     group.setCpaBid(detail.getLong("cpa_bid"));
                     group.setCpaBid(detail.getLong("cpa_bid"));
-                    group.setOcpxActionType(detail.getInteger("ocpx_action_type"));
+                    group.setOcpxActionType(ocpx_action_type);
                     group.setDeepConversionType(detail.getInteger("deep_conversion_type"));
                     group.setDeepConversionType(detail.getInteger("deep_conversion_type"));
                     group.setDeepConversionBid(detail.getLong("deep_conversion_bid"));
                     group.setDeepConversionBid(detail.getLong("deep_conversion_bid"));
                     group.setDayBudget(detail.getLong("day_budget"));
                     group.setDayBudget(detail.getLong("day_budget"));

+ 68 - 11
module-kuaishou/src/main/java/cn/com/ctop/kuaishou/modules/batch/service/impl/KuaishouInterfaceServiceImpl.java

@@ -138,6 +138,8 @@ public class KuaishouInterfaceServiceImpl implements IKuaishouInterfaceService {
     private IKuaiShouGroupService getKuaiShouGroupService;
     private IKuaiShouGroupService getKuaiShouGroupService;
     @Autowired
     @Autowired
     private IKuaiShouAdvertiserBaseInfoService KuaiShouAdvertiserBaseInfoService;
     private IKuaiShouAdvertiserBaseInfoService KuaiShouAdvertiserBaseInfoService;
+    @Autowired
+    private IWarningOperationService warningOperationService;
 
 
 
 
     @Override
     @Override
@@ -1201,7 +1203,7 @@ public class KuaishouInterfaceServiceImpl implements IKuaishouInterfaceService {
         String url = PropertiesUtils.getConfig("kuaishou_api_url") + KuaishouInterfaceConstant.GROUP_LIST;
         String url = PropertiesUtils.getConfig("kuaishou_api_url") + KuaishouInterfaceConstant.GROUP_LIST;
         JSONObject param = new JSONObject();
         JSONObject param = new JSONObject();
         param.put("advertiser_id", token.getAccountId());
         param.put("advertiser_id", token.getAccountId());
-        param.put("page_size", 200);
+        param.put("page_size", 500);
         param.put("page", page);
         param.put("page", page);
         if (startDate != null && endDate != null) {
         if (startDate != null && endDate != null) {
             param.put("start_date", DateUtils.formatDate(startDate));
             param.put("start_date", DateUtils.formatDate(startDate));
@@ -1230,31 +1232,86 @@ public class KuaishouInterfaceServiceImpl implements IKuaishouInterfaceService {
         getGroupListByPage(token, startDate, endDate, page + 1);
         getGroupListByPage(token, startDate, endDate, page + 1);
     }
     }
 
 
+    static ExecutorService executorBidTypeService = Executors.newFixedThreadPool(20);
+    static ExecutorService executorMaxBidService = Executors.newFixedThreadPool(5);
 
 
     private void addGroup(Long advertiserId, JSONArray details) {
     private void addGroup(Long advertiserId, JSONArray details) {
+        JSONObject json = warningOperationService.getBidTypeAndMaxBid(advertiserId);
+        Long maxBid = json.getLong("maxBid");// 最高出价
+        String bidTypeStr = json.getString("bidType"); // 出价方式
+        JSONArray bidTypeArr = JSONArray.parseArray(bidTypeStr);
+        String ocpxActionTypeStr = json.getString("ocpxActionType"); // 优化目标
+        JSONArray bidArr = JSONArray.parseArray(ocpxActionTypeStr);
         if (!Check.isNull(details)) {
         if (!Check.isNull(details)) {
             List<KuaiShouGroup> groups = new ArrayList<>();
             List<KuaiShouGroup> groups = new ArrayList<>();
             for (int i = 0; i < details.size(); i++) {
             for (int i = 0; i < details.size(); i++) {
                 JSONObject detail = JSONObject.parseObject(details.get(i).toString());
                 JSONObject detail = JSONObject.parseObject(details.get(i).toString());
                 if (!Check.isNull(detail)) {
                 if (!Check.isNull(detail)) {
-                    KuaiShouGroup group = new KuaiShouGroup();
+                    Integer bid_type = detail.getInteger("bid_type");
+                    Long bid = detail.getLong("bid");
+                    Long cpa_bid = detail.getLong("cpa_bid");
+                    Long day_budget = detail.getLong("day_budget");
+                    Integer ocpx_action_type = detail.getInteger("ocpx_action_type");
                     Long unitId = detail.getLong("unit_id");
                     Long unitId = detail.getLong("unit_id");
+                    String unit_name = detail.getString("unit_name");
+                    Integer status = detail.getInteger("status");
+                    Integer put_status = detail.getInteger("put_status");
+                    if (put_status == 1) { // 组状态为 投放中的
+                        if (status != 15) { // 广告组状态为非暂停
+                            Boolean ocpxTrueOrFalse = false;
+                            for (int j = 0; j < bidArr.size(); j++) {
+                                Integer ocpxActionType = (Integer) bidArr.get(j);
+                                if (ocpxActionType.equals(ocpx_action_type)) {
+                                    ocpxTrueOrFalse = true;
+                                    break;
+                                }
+                            }
+                            Boolean bidTypeTrueOrFalse = false;
+                            for (int j = 0; j < bidTypeArr.size(); j++) {
+                                Integer bidType = (Integer) bidTypeArr.get(j);
+                                if (bidType.equals(bid_type)) {
+                                    bidTypeTrueOrFalse = true;
+                                    break;
+                                }
+                            }
+                            if (!bidTypeTrueOrFalse || !ocpxTrueOrFalse) { // 出价方式设置非法
+                                if (day_budget > 500 * 1000 || day_budget == 0) { // 预算大于500 或者不限制预算 需要发送通知 并且进行暂停操作
+                                    executorBidTypeService.submit(new Runnable() {
+                                        @Override
+                                        public void run() {
+                                            warningOperationService.kuaiShouWarningOperation(json.getLong("projectId"), json.getString("projectName"), advertiserId, unitId, unit_name);
+                                        }
+                                    });
+                                }
+                            }
+                            if (bid > maxBid || cpa_bid > maxBid) {
+                                executorMaxBidService.submit(new Runnable() {
+                                    @Override
+                                    public void run() {
+                                        warningOperationService.kuaiShouBidWarningOperation(json.getLong("projectId"), json.getString("projectName"), advertiserId, unitId, unit_name);
+                                    }
+                                });
+                            }
+                        }
+                    }
+
+                    KuaiShouGroup group = new KuaiShouGroup();
                     group.setId("" + advertiserId + unitId);
                     group.setId("" + advertiserId + unitId);
                     group.setAccountId(advertiserId);
                     group.setAccountId(advertiserId);
                     group.setCampaignId(detail.getLong("campaign_id"));
                     group.setCampaignId(detail.getLong("campaign_id"));
                     group.setUnitId(unitId);
                     group.setUnitId(unitId);
-                    group.setUnitName(detail.getString("unit_name"));
-                    group.setStatus(detail.getInteger("status"));
-                    group.setPutStatus(detail.getInteger("put_status"));
+                    group.setUnitName(unit_name);
+                    group.setStatus(status);
+                    group.setPutStatus(put_status);
                     group.setCreateChannel(detail.getInteger("create_channel"));
                     group.setCreateChannel(detail.getInteger("create_channel"));
                     group.setReviewDetail(detail.getString("review_detail"));
                     group.setReviewDetail(detail.getString("review_detail"));
-                    group.setBidType(detail.getInteger("bid_type"));
-                    group.setBid(detail.getLong("bid"));
-                    group.setCpaBid(detail.getLong("cpa_bid"));
-                    group.setOcpxActionType(detail.getInteger("ocpx_action_type"));
+                    group.setBidType(bid_type);
+                    group.setBid(bid);
+                    group.setCpaBid(cpa_bid);
+                    group.setOcpxActionType(ocpx_action_type);
                     group.setDeepConversionType(detail.getInteger("deep_conversion_type"));
                     group.setDeepConversionType(detail.getInteger("deep_conversion_type"));
                     group.setDeepConversionBid(detail.getLong("deep_conversion_bid"));
                     group.setDeepConversionBid(detail.getLong("deep_conversion_bid"));
-                    group.setDayBudget(detail.getLong("day_budget"));
+                    group.setDayBudget(day_budget);
                     group.setSpeed(detail.getInteger("speed"));
                     group.setSpeed(detail.getInteger("speed"));
                     group.setBeginTime(detail.getString("begin_time"));
                     group.setBeginTime(detail.getString("begin_time"));
                     group.setEndTime(detail.getString("end_time"));
                     group.setEndTime(detail.getString("end_time"));
@@ -1312,7 +1369,7 @@ public class KuaishouInterfaceServiceImpl implements IKuaishouInterfaceService {
                 param.put("start_date", DateUtils.formatDate(startDate));
                 param.put("start_date", DateUtils.formatDate(startDate));
                 param.put("end_date", DateUtils.formatDate(endDate));
                 param.put("end_date", DateUtils.formatDate(endDate));
             }
             }
-            param.put("page_size", 200);
+            param.put("page_size", 500);
             param.put("page", page);
             param.put("page", page);
 
 
             String result = HttpUtils.kuaiShouhttpPostRequest(url, param.toJSONString(), headers);
             String result = HttpUtils.kuaiShouhttpPostRequest(url, param.toJSONString(), headers);

+ 311 - 0
module-kuaishou/src/main/java/cn/com/ctop/kuaishou/modules/batch/service/impl/KuaishouPopulationServiceImpl.java

@@ -1,11 +1,21 @@
 package cn.com.ctop.kuaishou.modules.batch.service.impl;
 package cn.com.ctop.kuaishou.modules.batch.service.impl;
 
 
+import cn.com.ctop.common.module.utils.Check;
+import cn.com.ctop.common.module.utils.HttpUtils;
+import cn.com.ctop.common.module.utils.KuaishouInterfaceConstant;
+import cn.com.ctop.common.module.utils.PropertiesUtils;
 import cn.com.ctop.kuaishou.modules.batch.entity.KuaishouPopulation;
 import cn.com.ctop.kuaishou.modules.batch.entity.KuaishouPopulation;
 import cn.com.ctop.kuaishou.modules.batch.mapper.KuaishouPopulationMapper;
 import cn.com.ctop.kuaishou.modules.batch.mapper.KuaishouPopulationMapper;
 import cn.com.ctop.kuaishou.modules.batch.service.IKuaishouPopulationService;
 import cn.com.ctop.kuaishou.modules.batch.service.IKuaishouPopulationService;
+import com.alibaba.fastjson.JSONObject;
 import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
 import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
+import lombok.extern.slf4j.Slf4j;
 import org.springframework.stereotype.Service;
 import org.springframework.stereotype.Service;
 
 
+import java.io.File;
+import java.util.HashMap;
+import java.util.Map;
+
 /**
 /**
  * 人群包列表
  * 人群包列表
  *
  *
@@ -13,7 +23,308 @@ import org.springframework.stereotype.Service;
  * @version V1.0
  * @version V1.0
  * @date 2020-05-06
  * @date 2020-05-06
  */
  */
+@Slf4j
 @Service
 @Service
 public class KuaishouPopulationServiceImpl extends ServiceImpl<KuaishouPopulationMapper, KuaishouPopulation> implements IKuaishouPopulationService {
 public class KuaishouPopulationServiceImpl extends ServiceImpl<KuaishouPopulationMapper, KuaishouPopulation> implements IKuaishouPopulationService {
 
 
+
+    private String urlPath = PropertiesUtils.getConfig("kuaishou_api_url");
+
+    /**
+     * 获取人群包接口
+     *
+     * @param accountId
+     * @param populationId 人群包ID
+     * @param accessToken  token
+     * @param accountId    广告主ID
+     * @return
+     */
+    @Override
+    public boolean deletePopulation(Long accountId, String populationId, String accessToken) {
+        log.info("删除人群包,accountId:{}", accountId);
+        String url = urlPath + KuaishouInterfaceConstant.POPULATION_DELETE;
+        Map<String, String> headers = new HashMap<>();
+        headers.put("Access-Token", accessToken);
+        headers.put("Content-Type", "application/json");
+        JSONObject requestJson = new JSONObject();
+        requestJson.put("advertiser_id", accountId);
+        requestJson.put("orientation_id", populationId);
+        String result = HttpUtils.kuaiShouhttpPostRequest(url, requestJson.toJSONString(), headers);
+        JSONObject resultJson = JSONObject.parseObject(result);
+        if (!Check.isNull(resultJson)) {
+            Integer code = resultJson.getInteger("code");
+            return code == 0;
+        }
+        return false;
+    }
+
+
+    /**
+     * 获取人群包接口
+     *
+     * @param accountId
+     * @param populationName 人群包名称
+     * @param type           1:IMEI 2:IDFA 3:IMEI_MD5 4:IDFA_MD5 5:手机号-MD5 7:OAID
+     * @param accountId      广告主ID
+     * @param file           请求的页码
+     * @param accessToken    token
+     * @return
+     */
+    @Override
+    public JSONObject updatePopulation(Long accountId, int type, String populationName, File file, String accessToken) {
+        log.info("上传人群包,accountId:{}", accountId);
+        String url = urlPath + KuaishouInterfaceConstant.POPULATION_UPLOAD;
+        Map<String, String> headers = new HashMap<>();
+        headers.put("Access-Token", accessToken);
+        headers.put("Content-Type", "application/json");
+        JSONObject requestJson = new JSONObject();
+        requestJson.put("advertiser_id", accountId);
+        requestJson.put("type", type);
+        requestJson.put("orientation_name", populationName);
+        requestJson.put("file", file);
+        String result = HttpUtils.kuaiShouhttpPostRequest(url, requestJson.toJSONString(), headers);
+        JSONObject resultJson = JSONObject.parseObject(result);
+        if (!Check.isNull(resultJson)) {
+            Integer code = resultJson.getInteger("code");
+            if (code == 0) {
+                return resultJson.getJSONObject("data");
+            }
+        }
+        return null;
+    }
+
+    /**
+     * 推送人群包接口(单日最多可调用50次推送接口)
+     *
+     * @param accountId
+     * @param populationId 人群包ID (只有status为1或6的人群包可推送,最多支持4个人群包状态同时为“推送中”)
+     * @param accessToken  token
+     * @param accountId    广告主ID
+     * @return
+     */
+    @Override
+    public boolean pushPopulation(Long accountId, String populationId, String accessToken) {
+        log.info("推送人群包,accountId:{}", accountId);
+        String url = urlPath + KuaishouInterfaceConstant.POPULATION_PUSH;
+        Map<String, String> headers = new HashMap<>();
+        headers.put("Access-Token", accessToken);
+        headers.put("Content-Type", "application/json");
+        JSONObject requestJson = new JSONObject();
+        requestJson.put("advertiser_id", accountId);
+        requestJson.put("orientation_id", populationId);
+        String result = HttpUtils.kuaiShouhttpPostRequest(url, requestJson.toJSONString(), headers);
+        JSONObject resultJson = JSONObject.parseObject(result);
+        if (!Check.isNull(resultJson)) {
+            Integer code = resultJson.getInteger("code");
+            return code == 0;
+        }
+        return false;
+    }
+
+    /**
+     * 跨账户人群包推送接口
+     *
+     * @param populationId 人群包ID
+     * @param accessToken  token
+     * @param accountId    广告主ID
+     * @param ids          要推送的账户ids
+     * @return
+     */
+    @Override
+    public boolean pushAccountsPopulation(Long accountId, String populationId, Long[] ids, String accessToken) {
+        log.info("推送人群包,accountId:{}", accountId);
+        String url = urlPath + KuaishouInterfaceConstant.POPULATION_PUSH_ACCOUNTS;
+        Map<String, String> headers = new HashMap<>();
+        headers.put("Access-Token", accessToken);
+        headers.put("Content-Type", "application/json");
+        JSONObject requestJson = new JSONObject();
+        requestJson.put("advertiser_id", accountId);
+        requestJson.put("orientation_id", populationId);
+        requestJson.put("dest_account_ids", ids);
+        String result = HttpUtils.kuaiShouhttpPostRequest(url, requestJson.toJSONString(), headers);
+        JSONObject resultJson = JSONObject.parseObject(result);
+        if (!Check.isNull(resultJson)) {
+            Integer code = resultJson.getInteger("code");
+            return code == 0;
+        }
+        return false;
+    }
+
+    /**
+     * 游戏精选标签人群包
+     * 获取游戏精选标签所有接口类型
+     *
+     * @param accessToken token
+     * @return
+     */
+    @Override
+    public JSONObject selectGameTags(String accessToken) {
+        String url = urlPath + KuaishouInterfaceConstant.POPULATION_GAME_TAG_LIST;
+        Map<String, String> headers = new HashMap<>();
+        headers.put("Access-Token", accessToken);
+        headers.put("Content-Type", "application/json");
+        String result = HttpUtils.kuaiShouhttpPostRequest(url, null, headers);
+        JSONObject resultJson = JSONObject.parseObject(result);
+        if (!Check.isNull(resultJson)) {
+            Integer code = resultJson.getInteger("code");
+            if (code == 0) {
+                return resultJson.getJSONObject("data");
+            }
+        }
+        return null;
+    }
+
+    /**
+     * 游戏精选标签人群包
+     * 游戏精选标签创建
+     *
+     * @param accessToken token
+     * @param accountId   广告主ID
+     * @return
+     */
+    @Override
+    public Long createGameTags(Long accountId, JSONObject obj, String accessToken) {
+        String url = urlPath + KuaishouInterfaceConstant.POPULATION_GAME_TAG_CREATE;
+        Map<String, String> headers = new HashMap<>();
+        headers.put("Access-Token", accessToken);
+        headers.put("Content-Type", "application/json");
+        JSONObject requestJson = new JSONObject();
+        requestJson.put("advertiser_id", accountId);
+        requestJson.put("orientation_name", obj.getString("populationName"));
+        if (!Check.isNull(obj.getString("gameCategory"))) {
+            requestJson.put("game_category", obj.getString("gameCategory"));
+        }
+        if (!Check.isNull(obj.getString("gameTheme"))) {
+            requestJson.put("game_theme", obj.getString("gameTheme"));
+        }
+        if (!Check.isNull(obj.getString("artStyle"))) {
+            requestJson.put("art_style", obj.getString("artStyle"));
+        }
+        if (!Check.isNull(obj.getString("payWilling"))) {
+            requestJson.put("pay_willing", obj.getString("payWilling"));
+        }
+        if (!Check.isNull(obj.getString("activeLevel"))) {
+            requestJson.put("active_level", obj.getString("activeLevel"));
+        }
+        String result = HttpUtils.kuaiShouhttpPostRequest(url, requestJson.toJSONString(), headers);
+        JSONObject resultJson = JSONObject.parseObject(result);
+        if (!Check.isNull(resultJson)) {
+            Integer code = resultJson.getInteger("code");
+            if (code == 0) {
+                return resultJson.getJSONObject("data").getLong("orientation_id");
+            }
+        }
+        return null;
+    }
+
+    /**
+     * DMP更新人群包接口
+     *
+     * @param populationId   人群包ID
+     * @param populationType 1:APPEND(增量更新)
+     * @param type           人群数据类型 1:IMEI 2:IDFA 3:IMEI_MD5 4:IDFA_MD5 7:OAID 8:OAID_MD5
+     * @param accessToken    token
+     * @param accountId      广告主ID
+     * @param file           请求的文件,最大支持500MB
+     * @return
+     */
+    @Override
+    public JSONObject updatePopulation(Long accountId, Integer type, Long populationId, Integer populationType, File file, String accessToken) {
+        String url = urlPath + KuaishouInterfaceConstant.POPULATION_UPDATE;
+        Map<String, String> headers = new HashMap<>();
+        headers.put("Access-Token", accessToken);
+        headers.put("Content-Type", "application/json");
+        JSONObject requestJson = new JSONObject();
+        requestJson.put("advertiser_id", accountId);
+        requestJson.put("type", type);
+        requestJson.put("orientation_id", populationId);
+        requestJson.put("operation_type", populationType);
+        requestJson.put("file", file);
+        String result = HttpUtils.kuaiShouhttpPostRequest(url, requestJson.toJSONString(), headers);
+        JSONObject resultJson = JSONObject.parseObject(result);
+        if (!Check.isNull(resultJson)) {
+            Integer code = resultJson.getInteger("code");
+            if (code == 0) {
+                return resultJson.getJSONObject("data");
+            }
+        }
+        return null;
+    }
+
+    /**
+     * 获取人群预估数量
+     *
+     * @param accessToken token
+     * @param accountId   广告主ID
+     * @return
+     */
+    @Override
+    public Long predictionPopulation(Long accountId, JSONObject obj, String accessToken) {
+        String url = urlPath + KuaishouInterfaceConstant.POPULATION_PREDICTION;
+        Map<String, String> headers = new HashMap<>();
+        headers.put("Access-Token", accessToken);
+        headers.put("Content-Type", "application/json");
+        JSONObject requestJson = new JSONObject();
+        requestJson.put("advertiser_id", accountId);
+        if (!Check.isNull(obj.getJSONArray("region"))) {
+            requestJson.put("region", obj.getJSONArray("region"));
+        }
+        if (!Check.isNull(obj.getJSONArray("ages_range"))) {
+            requestJson.put("ages_range", obj.getJSONArray("ages_range"));
+        }
+        if (!Check.isNull(obj.getInteger("gender"))) {
+            requestJson.put("gender", obj.getInteger("gender"));
+        }
+        if (!Check.isNull(obj.getInteger("platform_os"))) {
+            requestJson.put("platform_os", obj.getInteger("platform_os"));
+        }
+        if (!Check.isNull(obj.getInteger("android_osv"))) {
+            requestJson.put("android_osv", obj.getInteger("android_osv"));
+        }
+        if (!Check.isNull(obj.getInteger("ios_osv"))) {
+            requestJson.put("ios_osv", obj.getInteger("ios_osv"));
+        }
+        if (!Check.isNull(obj.getInteger("network"))) {
+            requestJson.put("network", obj.getInteger("network"));
+        }
+        if (!Check.isNull(obj.getJSONArray("device_brand"))) {
+            requestJson.put("device_brand", obj.getJSONArray("device_brand"));
+        }
+        if (!Check.isNull(obj.getJSONArray("device_price"))) {
+            requestJson.put("device_price", obj.getJSONArray("device_price"));
+        }
+        if (!Check.isNull(obj.getInteger("business_interest_type"))) {
+            requestJson.put("business_interest_type", obj.getInteger("business_interest_type"));
+        }
+        if (!Check.isNull(obj.getJSONArray("business_interest"))) {
+            requestJson.put("business_interest", obj.getJSONArray("business_interest"));
+        }
+        if (!Check.isNull(obj.getJSONArray("fans_star"))) {
+            requestJson.put("fans_star", obj.getJSONArray("fans_star"));
+        }
+        if (!Check.isNull(obj.getJSONArray("interest_video"))) {
+            requestJson.put("interest_video", obj.getJSONArray("interest_video"));
+        }
+        if (!Check.isNull(obj.getJSONArray("app_interest"))) {
+            requestJson.put("app_interest", obj.getJSONArray("app_interest"));
+        }
+        if (!Check.isNull(obj.getJSONArray("app_ids"))) {
+            requestJson.put("app_ids", obj.getJSONArray("app_ids"));
+        }
+        if (!Check.isNull(obj.getJSONArray("population"))) {
+            requestJson.put("population", obj.getJSONArray("population"));
+        }
+        if (!Check.isNull(obj.getJSONArray("exclude_population"))) {
+            requestJson.put("exclude_population", obj.getJSONArray("exclude_population"));
+        }
+        String result = HttpUtils.kuaiShouhttpPostRequest(url, requestJson.toJSONString(), headers);
+        JSONObject resultJson = JSONObject.parseObject(result);
+        if (!Check.isNull(resultJson)) {
+            Integer code = resultJson.getInteger("code");
+            if (code == 0) {
+                return resultJson.getJSONObject("data").getLong("audience_prediction_num");
+            }
+        }
+        return null;
+    }
 }
 }

+ 447 - 0
module-kuaishou/src/main/java/cn/com/ctop/kuaishou/modules/batch/service/impl/KuaishouTemplateServiceImpl.java

@@ -0,0 +1,447 @@
+package cn.com.ctop.kuaishou.modules.batch.service.impl;
+
+import cn.com.ctop.common.module.utils.Check;
+import cn.com.ctop.common.module.utils.HttpUtils;
+import cn.com.ctop.common.module.utils.KuaishouInterfaceConstant;
+import cn.com.ctop.common.module.utils.PropertiesUtils;
+import cn.com.ctop.kuaishou.modules.batch.entity.KuaishouTemplate;
+import cn.com.ctop.kuaishou.modules.batch.entity.KuaishouTemplateTarget;
+import cn.com.ctop.kuaishou.modules.batch.mapper.KuaishouTemplateMapper;
+import cn.com.ctop.kuaishou.modules.batch.service.IKuaishouTemplateService;
+import cn.com.ctop.kuaishou.modules.batch.service.IKuaishouTemplateTargetService;
+import com.alibaba.fastjson.JSONArray;
+import com.alibaba.fastjson.JSONObject;
+import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
+import lombok.extern.slf4j.Slf4j;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.stereotype.Service;
+
+import java.util.HashMap;
+import java.util.Map;
+
+/**
+ * 快手-定向模板
+ *
+ * @author jeecg-boot
+ * @version V1.0
+ * @date 2020-11-09
+ */
+@Slf4j
+@Service
+public class KuaishouTemplateServiceImpl extends ServiceImpl<KuaishouTemplateMapper, KuaishouTemplate> implements IKuaishouTemplateService {
+    @Autowired
+    private IKuaishouTemplateTargetService templateTargetService;
+
+    @Override
+    public void getTemplateByAccountId(Long accountId, String accessToken, Integer page) {
+        String url = PropertiesUtils.getConfig("kuaishou_api_url") + KuaishouInterfaceConstant.TEMPLATE_LIST;
+        JSONObject param = new JSONObject();
+        param.put("advertiser_id", accountId);
+        param.put("page", page);
+        param.put("page_size", 500);
+        Map<String, String> headers = new HashMap<String, String>();
+        headers.put("Access-Token", accessToken);
+        headers.put("Content-Type", " application/json");
+        String result = HttpUtils.kuaiShouhttpPostRequest(url, param.toJSONString(), headers);
+        JSONObject resultJson = JSONObject.parseObject(result);
+        if (!Check.isNull(resultJson)) {
+            Integer code = resultJson.getInteger("code");
+            if (code == 0) {
+                JSONObject dataJson = resultJson.getJSONObject("data");
+                if (Check.isNull(dataJson)) {
+                    return;
+                }
+                JSONArray details = dataJson.getJSONArray("details");
+                if (Check.isNull(details)) {
+                    return;
+                }
+                for (int i = 0; i < details.size(); i++) {
+                    JSONObject jsonObject = details.getJSONObject(i);
+                    Long templateId = jsonObject.getLong("template_id");
+                    KuaishouTemplate template = new KuaishouTemplate();
+                    template.setId(accountId + "_" + templateId);
+                    template.setAccountId(accountId);
+                    template.setTemplateId(templateId);
+                    template.setTemplateName(jsonObject.getString("template_name"));
+                    template.setUnitCount(jsonObject.getInteger("unit_count"));
+                    template.setCreateTime(jsonObject.getDate("create_time"));
+                    template.setUpdateTime(jsonObject.getDate("updateTime"));
+                    this.saveOrUpdate(template);
+                    JSONObject targetJson = jsonObject.getJSONObject("target");
+                    if (!Check.isNull(targetJson)) {
+                        KuaishouTemplateTarget templateTarget = new KuaishouTemplateTarget();
+                        templateTarget.setId(accountId + "_" + templateId);
+                        templateTarget.setTemplateId(templateId);
+                        if (!Check.isNull(targetJson.getJSONArray("region"))) {
+                            templateTarget.setRegion(targetJson.getJSONArray("region").toJSONString());
+                        }
+                        if (!Check.isNull(targetJson.getJSONArray("district_ids"))) {
+                            templateTarget.setDistrictIds(targetJson.getJSONArray("district_ids").toString());
+                        }
+                        if (!Check.isNull(targetJson.getInteger("user_type"))) {
+                            templateTarget.setUserType(targetJson.getInteger("user_type"));
+                        }
+                        if (!Check.isNull(targetJson.getJSONArray("ages_range"))) {
+                            templateTarget.setAgesRange(targetJson.getJSONArray("ages_range").toJSONString());
+                        }
+                        JSONObject ageJson = targetJson.getJSONObject("age");
+                        if (!Check.isNull(ageJson)) {
+                            templateTarget.setMin(ageJson.getInteger("min"));
+                            templateTarget.setMax(ageJson.getInteger("max"));
+                        }
+                        if (!Check.isNull(targetJson.getInteger("gender"))) {
+                            templateTarget.setGender(targetJson.getInteger("gender"));
+                        }
+                        if (!Check.isNull(targetJson.getInteger("platform_os"))) {
+                            templateTarget.setPlatformOs(targetJson.getInteger("platform_os"));
+                        }
+                        if (!Check.isNull(targetJson.getInteger("android_osv"))) {
+                            templateTarget.setAndroidOsv(targetJson.getInteger("android_osv"));
+                        }
+                        if (!Check.isNull(targetJson.getInteger("ios_osv"))) {
+                            templateTarget.setIosOsv(targetJson.getInteger("ios_osv"));
+                        }
+                        if (!Check.isNull(targetJson.getInteger("network"))) {
+                            templateTarget.setNetwork(targetJson.getInteger("network"));
+                        }
+                        if (!Check.isNull(targetJson.getInteger("filter_converted_level"))) {
+                            templateTarget.setFilterConvertedLevel(targetJson.getInteger("filter_converted_level"));
+                        }
+                        if (!Check.isNull(targetJson.getJSONArray("device_brand"))) {
+                            templateTarget.setDeviceBrand(targetJson.getJSONArray("device_brand").toJSONString());
+                        }
+                        if (!Check.isNull(targetJson.getJSONArray("device_price"))) {
+                            templateTarget.setDevicePrice(targetJson.getJSONArray("device_price").toJSONString());
+                        }
+                        if (!Check.isNull(targetJson.getInteger("business_interest_type"))) {
+                            templateTarget.setBusinessInterestType(targetJson.getInteger("business_interest_type"));
+                        }
+                        if (!Check.isNull(targetJson.getJSONArray("business_interest"))) {
+                            templateTarget.setBusinessInterest(targetJson.getJSONArray("business_interest").toJSONString());
+                        }
+                        if (!Check.isNull(targetJson.getJSONArray("fans_star"))) {
+                            templateTarget.setFansStar(targetJson.getJSONArray("fans_star").toJSONString());
+                        }
+                        if (!Check.isNull(targetJson.getJSONArray("interest_video"))) {
+                            templateTarget.setInterestVideo(targetJson.getJSONArray("interest_video").toJSONString());
+                        }
+                        if (!Check.isNull(targetJson.getJSONArray("app_interest"))) {
+                            templateTarget.setAppInterest(targetJson.getJSONArray("app_interest").toJSONString());
+                        }
+                        if (!Check.isNull(targetJson.getJSONArray("app_ids"))) {
+                            templateTarget.setAppIds(targetJson.getJSONArray("app_ids").toJSONString());
+                        }
+                        if (!Check.isNull(targetJson.getJSONArray("population"))) {
+                            templateTarget.setPopulation(targetJson.getJSONArray("population").toJSONString());
+                        }
+                        if (!Check.isNull(targetJson.getJSONArray("paid_audience"))) {
+                            templateTarget.setPaidAudience(targetJson.getJSONArray("paid_audience").toJSONString());
+                        }
+                        if (!Check.isNull(targetJson.getJSONArray("exclude_population"))) {
+                            templateTarget.setExcludePopulation(targetJson.getJSONArray("exclude_population").toJSONString());
+                        }
+                        JSONObject intelliExtendJson = targetJson.getJSONObject("intelli_extend");
+                        if (!Check.isNull(intelliExtendJson)) {
+                            if (!Check.isNull(intelliExtendJson.getInteger("is_open"))) {
+                                templateTarget.setIsOpen(intelliExtendJson.getInteger("is_open"));
+                            }
+                            if (!Check.isNull(intelliExtendJson.getInteger("no_age_break"))) {
+                                templateTarget.setNoAgeBreak(intelliExtendJson.getInteger("no_age_break"));
+                            }
+                            if (!Check.isNull(intelliExtendJson.getInteger("no_gender_break"))) {
+                                templateTarget.setNoGenderBreak(intelliExtendJson.getInteger("no_gender_break"));
+                            }
+                            if (!Check.isNull(intelliExtendJson.getInteger("no_area_break"))) {
+                                templateTarget.setNoAreaBreak(intelliExtendJson.getInteger("no_area_break"));
+                            }
+                        }
+                        templateTargetService.saveOrUpdate(templateTarget);
+                    }
+
+                }
+
+                getTemplateByAccountId(accountId, accessToken, page + 1);
+            } else {
+                log.error("获取模板信息返回信息错误:accountId:{},返回信息:{}", accountId, resultJson);
+
+
+            }
+
+
+        } else {
+            log.error("获取模板信息返回信息为空:accountId:{}", accountId);
+        }
+
+
+    }
+
+
+    /**
+     * 创建定向模板
+     *
+     * @param accountId
+     * @param accessToken
+     * @param requestJson
+     * @return
+     */
+    @Override
+    public JSONObject createTemplate(Long accountId, String accessToken, JSONObject requestJson) {
+
+
+        try {
+            if (Check.isNull(requestJson.getString("templateName"))) {
+                throw new Exception("定向模板名称为必传项");
+            }
+
+            JSONObject param = new JSONObject();
+            param.put("advertiser_id", accountId);
+            param.put("template_name", requestJson.getString("templateName"));
+            JSONObject targetJson = new JSONObject();
+            if (!Check.isNull(requestJson.getJSONArray("region"))) {
+                targetJson.put("region", requestJson.getJSONArray("region"));
+            }
+            if (!Check.isNull(requestJson.getJSONArray("districtIds"))) {
+                targetJson.put("district_ids", requestJson.getJSONArray("districtIds"));
+            }
+            if (!Check.isNull(requestJson.getInteger("userType"))) {
+                targetJson.put("user_type", requestJson.getInteger("userType"));
+            }
+            if (!Check.isNull(requestJson.getJSONArray("agesRange"))) {
+                targetJson.put("ages_range", requestJson.getJSONArray("agesRange"));
+            }
+
+            JSONObject ageJson = new JSONObject();
+            if (!Check.isNull(requestJson.getInteger("min"))) {
+                ageJson.put("min", requestJson.getInteger("min"));
+            }
+            if (!Check.isNull(requestJson.getInteger("max"))) {
+                ageJson.put("max", requestJson.getInteger("max"));
+            }
+            if (!Check.isNull(ageJson)) {
+                targetJson.put("age", ageJson);
+            }
+
+            if (!Check.isNull(requestJson.getInteger("gender"))) {
+                targetJson.put("gender", requestJson.getInteger("gender"));
+            }
+            if (!Check.isNull(requestJson.getInteger("platformOs"))) {
+                targetJson.put("platform_os", requestJson.getInteger("platformOs"));
+            }
+            if (!Check.isNull(requestJson.getInteger("androidOsv"))) {
+                targetJson.put("android_osv", requestJson.getInteger("androidOsv"));
+            }
+            if (!Check.isNull(requestJson.getInteger("iosOsv"))) {
+                targetJson.put("ios_osv", requestJson.getInteger("iosOsv"));
+            }
+            if (!Check.isNull(requestJson.getInteger("network"))) {
+                targetJson.put("network", requestJson.getInteger("network"));
+            }
+            if (!Check.isNull(requestJson.getInteger("filterConvertedLevel"))) {
+                targetJson.put("filter_converted_level", requestJson.getInteger("filterConvertedLevel"));
+            }
+            if (!Check.isNull(requestJson.getJSONArray("deviceBrand"))) {
+                targetJson.put("device_brand", requestJson.getJSONArray("deviceBrand"));
+            }
+            if (!Check.isNull(requestJson.getJSONArray("devicePrice"))) {
+                targetJson.put("device_price", requestJson.getJSONArray("devicePrice"));
+            }
+            if (!Check.isNull(requestJson.getInteger("businessInterestType"))) {
+                targetJson.put("business_interest_type", requestJson.getInteger("businessInterestType"));
+            }
+            if (!Check.isNull(requestJson.getJSONArray("businessInterest"))) {
+                targetJson.put("business_interest", requestJson.getJSONArray("businessInterest"));
+            }
+            if (!Check.isNull(requestJson.getJSONArray("fansStar"))) {
+                targetJson.put("fans_star", requestJson.getJSONArray("fansStar"));
+            }
+            if (!Check.isNull(requestJson.getJSONArray("interestVideo"))) {
+                targetJson.put("interest_video", requestJson.getJSONArray("interestVideo"));
+            }
+            if (!Check.isNull(requestJson.getJSONArray("appInterest"))) {
+                targetJson.put("app_interest", requestJson.getJSONArray("appInterest"));
+            }
+            if (!Check.isNull(requestJson.getJSONArray("appIds"))) {
+                targetJson.put("app_ids", requestJson.getJSONArray("appIds"));
+            }
+            if (!Check.isNull(requestJson.getJSONArray("population"))) {
+                targetJson.put("population", requestJson.getJSONArray("population"));
+            }
+            if (!Check.isNull(requestJson.getJSONArray("paidAudience"))) {
+                targetJson.put("paid_audience", requestJson.getJSONArray("paidAudience"));
+            }
+            if (!Check.isNull(requestJson.getJSONArray("excludePopulation"))) {
+                targetJson.put("exclude_population", requestJson.getJSONArray("excludePopulation"));
+            }
+            JSONObject intelliExtendJson = new JSONObject();
+
+            if (!Check.isNull(requestJson.getInteger("isOpen"))) {
+                intelliExtendJson.put("is_open", requestJson.getInteger("isOpen"));
+            }
+            if (!Check.isNull(requestJson.getInteger("noAgeBreak"))) {
+                intelliExtendJson.put("no_age_break", requestJson.getInteger("noAgeBreak"));
+            }
+            if (!Check.isNull(requestJson.getInteger("noGenderBreak"))) {
+                intelliExtendJson.put("no_gender_break", requestJson.getInteger("noGenderBreak"));
+            }
+            if (!Check.isNull(requestJson.getInteger("noAreaBreak"))) {
+                intelliExtendJson.put("no_area_break", requestJson.getInteger("noAreaBreak"));
+            }
+            if (!Check.isNull(intelliExtendJson)) {
+                targetJson.put("intelli_extend", intelliExtendJson);
+            }
+            if (!Check.isNull(targetJson)) {
+                param.put("target", targetJson);
+            }
+
+            Map<String, String> headers = new HashMap<String, String>();
+            headers.put("Access-Token", accessToken);
+            headers.put("Content-Type", " application/json");
+
+            String url = PropertiesUtils.getConfig("kuaishou_api_url") + KuaishouInterfaceConstant.TEMPLATE_CREATE;
+            System.err.println(param);
+            String result = HttpUtils.kuaiShouhttpPostRequest(url, param.toJSONString(), headers);
+
+            JSONObject resultJson = JSONObject.parseObject(result);
+            System.err.println(resultJson);
+
+
+        } catch (Exception e) {
+            e.printStackTrace();
+        }
+        return null;
+    }
+
+
+    /**
+     * 修改定向模板
+     *
+     * @param accountId
+     * @param accessToken
+     * @param requestJson
+     * @return
+     */
+    @Override
+    public JSONObject updateTemplate(Long accountId, String accessToken, JSONObject requestJson) {
+        try {
+            if (Check.isNull(requestJson.getString("templateName"))) {
+                throw new Exception("定向模板名称为必传项");
+            }
+
+            JSONObject param = new JSONObject();
+            param.put("advertiser_id", accountId);
+            param.put("template_name", requestJson.getString("templateName"));
+            JSONObject targetJson = new JSONObject();
+            if (!Check.isNull(requestJson.getJSONArray("region"))) {
+                targetJson.put("region", requestJson.getJSONArray("region"));
+            }
+            if (!Check.isNull(requestJson.getJSONArray("districtIds"))) {
+                targetJson.put("district_ids", requestJson.getJSONArray("districtIds"));
+            }
+            if (!Check.isNull(requestJson.getInteger("userType"))) {
+                targetJson.put("user_type", requestJson.getInteger("userType"));
+            }
+            if (!Check.isNull(requestJson.getJSONArray("agesRange"))) {
+                targetJson.put("ages_range", requestJson.getJSONArray("agesRange"));
+            }
+
+            JSONObject ageJson = new JSONObject();
+            if (!Check.isNull(requestJson.getInteger("min"))) {
+                ageJson.put("min", requestJson.getInteger("min"));
+            }
+            if (!Check.isNull(requestJson.getInteger("max"))) {
+                ageJson.put("max", requestJson.getInteger("max"));
+            }
+            if (!Check.isNull(ageJson)) {
+                targetJson.put("age", ageJson);
+            }
+
+            if (!Check.isNull(requestJson.getInteger("gender"))) {
+                targetJson.put("gender", requestJson.getInteger("gender"));
+            }
+            if (!Check.isNull(requestJson.getInteger("platformOs"))) {
+                targetJson.put("platform_os", requestJson.getInteger("platformOs"));
+            }
+            if (!Check.isNull(requestJson.getInteger("androidOsv"))) {
+                targetJson.put("android_osv", requestJson.getInteger("androidOsv"));
+            }
+            if (!Check.isNull(requestJson.getInteger("iosOsv"))) {
+                targetJson.put("ios_osv", requestJson.getInteger("iosOsv"));
+            }
+            if (!Check.isNull(requestJson.getInteger("network"))) {
+                targetJson.put("network", requestJson.getInteger("network"));
+            }
+            if (!Check.isNull(requestJson.getInteger("filterConvertedLevel"))) {
+                targetJson.put("filter_converted_level", requestJson.getInteger("filterConvertedLevel"));
+            }
+            if (!Check.isNull(requestJson.getJSONArray("deviceBrand"))) {
+                targetJson.put("device_brand", requestJson.getJSONArray("deviceBrand"));
+            }
+            if (!Check.isNull(requestJson.getJSONArray("devicePrice"))) {
+                targetJson.put("device_price", requestJson.getJSONArray("devicePrice"));
+            }
+            if (!Check.isNull(requestJson.getInteger("businessInterestType"))) {
+                targetJson.put("business_interest_type", requestJson.getInteger("businessInterestType"));
+            }
+            if (!Check.isNull(requestJson.getJSONArray("businessInterest"))) {
+                targetJson.put("business_interest", requestJson.getJSONArray("businessInterest"));
+            }
+            if (!Check.isNull(requestJson.getJSONArray("fansStar"))) {
+                targetJson.put("fans_star", requestJson.getJSONArray("fansStar"));
+            }
+            if (!Check.isNull(requestJson.getJSONArray("interestVideo"))) {
+                targetJson.put("interest_video", requestJson.getJSONArray("interestVideo"));
+            }
+            if (!Check.isNull(requestJson.getJSONArray("appInterest"))) {
+                targetJson.put("app_interest", requestJson.getJSONArray("appInterest"));
+            }
+            if (!Check.isNull(requestJson.getJSONArray("appIds"))) {
+                targetJson.put("app_ids", requestJson.getJSONArray("appIds"));
+            }
+            if (!Check.isNull(requestJson.getJSONArray("population"))) {
+                targetJson.put("population", requestJson.getJSONArray("population"));
+            }
+            if (!Check.isNull(requestJson.getJSONArray("paidAudience"))) {
+                targetJson.put("paid_audience", requestJson.getJSONArray("paidAudience"));
+            }
+            if (!Check.isNull(requestJson.getJSONArray("excludePopulation"))) {
+                targetJson.put("exclude_population", requestJson.getJSONArray("excludePopulation"));
+            }
+            JSONObject intelliExtendJson = new JSONObject();
+
+            if (!Check.isNull(requestJson.getInteger("isOpen"))) {
+                intelliExtendJson.put("is_open", requestJson.getInteger("isOpen"));
+            }
+            if (!Check.isNull(requestJson.getInteger("noAgeBreak"))) {
+                intelliExtendJson.put("no_age_break", requestJson.getInteger("noAgeBreak"));
+            }
+            if (!Check.isNull(requestJson.getInteger("noGenderBreak"))) {
+                intelliExtendJson.put("no_gender_break", requestJson.getInteger("noGenderBreak"));
+            }
+            if (!Check.isNull(requestJson.getInteger("noAreaBreak"))) {
+                intelliExtendJson.put("no_area_break", requestJson.getInteger("noAreaBreak"));
+            }
+            if (!Check.isNull(intelliExtendJson)) {
+                targetJson.put("intelli_extend", intelliExtendJson);
+            }
+            if (!Check.isNull(targetJson)) {
+                param.put("target", targetJson);
+            }
+
+            Map<String, String> headers = new HashMap<String, String>();
+            headers.put("Access-Token", accessToken);
+            headers.put("Content-Type", " application/json");
+
+            String url = PropertiesUtils.getConfig("kuaishou_api_url") + KuaishouInterfaceConstant.TEMPLATE_CREATE;
+            System.err.println(param);
+            String result = HttpUtils.kuaiShouhttpPostRequest(url, param.toJSONString(), headers);
+
+            JSONObject resultJson = JSONObject.parseObject(result);
+            System.err.println(resultJson);
+
+
+        } catch (Exception e) {
+            e.printStackTrace();
+        }
+        return null;
+    }
+}

+ 19 - 0
module-kuaishou/src/main/java/cn/com/ctop/kuaishou/modules/batch/service/impl/KuaishouTemplateTargetServiceImpl.java

@@ -0,0 +1,19 @@
+package cn.com.ctop.kuaishou.modules.batch.service.impl;
+
+import cn.com.ctop.kuaishou.modules.batch.entity.KuaishouTemplateTarget;
+import cn.com.ctop.kuaishou.modules.batch.mapper.KuaishouTemplateTargetMapper;
+import cn.com.ctop.kuaishou.modules.batch.service.IKuaishouTemplateTargetService;
+import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
+import org.springframework.stereotype.Service;
+
+/**
+ * 快手-定向模板-详情
+ *
+ * @author jeecg-boot
+ * @version V1.0
+ * @date 2020-11-09
+ */
+@Service
+public class KuaishouTemplateTargetServiceImpl extends ServiceImpl<KuaishouTemplateTargetMapper, KuaishouTemplateTarget> implements IKuaishouTemplateTargetService {
+
+}

+ 116 - 0
module-kuaishou/src/main/java/cn/com/ctop/kuaishou/modules/batch/service/impl/WarningOperationServiceImpl.java

@@ -0,0 +1,116 @@
+package cn.com.ctop.kuaishou.modules.batch.service.impl;
+
+import cn.com.ctop.common.module.entity.CtopOauthToken;
+import cn.com.ctop.common.module.entity.WarningOperationLog;
+import cn.com.ctop.common.module.mapper.ProjectMapper;
+import cn.com.ctop.common.module.mapper.UserAllocationMapper;
+import cn.com.ctop.common.module.service.ICtopOauthTokenService;
+import cn.com.ctop.common.module.service.IMessageTemplate;
+import cn.com.ctop.common.module.service.ISendMessageService;
+import cn.com.ctop.common.module.service.IWarningOperationLogService;
+import cn.com.ctop.common.module.utils.Check;
+import cn.com.ctop.kuaishou.modules.batch.service.IKuaiShouUpdateService;
+import cn.com.ctop.kuaishou.modules.batch.service.IWarningOperationService;
+import com.alibaba.fastjson.JSONObject;
+import lombok.extern.slf4j.Slf4j;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.stereotype.Service;
+
+@Slf4j
+@Service
+public class WarningOperationServiceImpl implements IWarningOperationService {
+    @Autowired
+    private ProjectMapper projectMapper;
+    @Autowired
+    private UserAllocationMapper userAllocationMapper;
+    @Autowired
+    private IMessageTemplate messageTemplate;
+    @Autowired
+    private IKuaiShouUpdateService updateService;
+    @Autowired
+    private ISendMessageService sendMessageService;
+    @Autowired
+    private ICtopOauthTokenService oauthTokenService;
+    @Autowired
+    private IWarningOperationLogService warningOperationLogService;
+
+    @Override
+    public JSONObject getBidTypeAndMaxBid(Long accountId) {
+        Long projectId = userAllocationMapper.getProjectIdByAccountId(accountId);
+        if (Check.isNull(projectId)) {
+            log.error("此账户未绑定项目");
+            return null;
+        }
+        JSONObject warningJson = projectMapper.getWarningInfoByProjectId(projectId);
+        return warningJson;
+    }
+
+
+    /**
+     * 快手出价方式预警 && 操作
+     *
+     * @param projectId
+     * @param projectName
+     * @param advertiserId
+     * @param unitId
+     * @param unit_name
+     */
+
+    @Override
+    public void kuaiShouWarningOperation(Long projectId, String projectName, Long advertiserId, Long unitId, String unit_name) {
+
+        String userId = userAllocationMapper.queryUserIdByAccountId(advertiserId);
+        try {
+            String text = messageTemplate.getKuaiShouBidTypeMessage(projectName, advertiserId, unitId, unit_name);
+
+            sendMessageService.sendMessage(userId, text);
+        } catch (Exception e) {
+            e.printStackTrace();
+        }
+        CtopOauthToken token = oauthTokenService.getTokenByAccountId(advertiserId);
+        updateService.updateUnitStatus(token.getAccessToken(), advertiserId, unitId, 2, "admin");
+        WarningOperationLog warningOperationLog = new WarningOperationLog();
+        warningOperationLog.setAccountId(advertiserId);
+        warningOperationLog.setSubject("出价方式预警");
+        warningOperationLog.setUnitId(unitId);
+        warningOperationLog.setUserId(userId);
+        warningOperationLog.setWarningType(1);
+        warningOperationLogService.save(warningOperationLog);
+
+
+    }
+
+
+    /**
+     * 出价 过高预警 && 操作
+     *
+     * @param projectId
+     * @param projectName
+     * @param advertiserId
+     * @param unitId
+     * @param unit_name
+     */
+
+    @Override
+    public void kuaiShouBidWarningOperation(Long projectId, String projectName, Long advertiserId, Long unitId, String unit_name) {
+        String userId = userAllocationMapper.queryUserIdByAccountId(advertiserId);
+        try {
+            String text = messageTemplate.getKuaiShouBidMessage(projectName, advertiserId, unitId, unit_name);
+            sendMessageService.sendMessage(userId, text);
+        } catch (Exception e) {
+            e.printStackTrace();
+        }
+
+        CtopOauthToken token = oauthTokenService.getTokenByAccountId(advertiserId);
+        updateService.updateUnitStatus(token.getAccessToken(), advertiserId, unitId, 2, "admin");
+
+        WarningOperationLog warningOperationLog = new WarningOperationLog();
+        warningOperationLog.setAccountId(advertiserId);
+        warningOperationLog.setSubject("出价过高预警");
+        warningOperationLog.setUnitId(unitId);
+        warningOperationLog.setUserId(userId);
+        warningOperationLog.setWarningType(2);
+        warningOperationLogService.save(warningOperationLog);
+
+    }
+}

+ 0 - 24
module-kuaishou/src/main/java/cn/com/ctop/kuaishou/modules/report/controller/KuaishouCostGroupController.java

@@ -103,30 +103,6 @@ public class KuaishouCostGroupController {
     }
     }
 
 
     /**
     /**
-     * 编辑
-     *
-     * @param kuaishouCostGroup
-     * @return
-     */
-    @AutoLog(value = "快手组级时报统计-编辑")
-    @ApiOperation(value = "快手组级时报统计-编辑", notes = "快手组级时报统计-编辑")
-    @PutMapping(value = "/edit")
-    public Result<KuaishouCostGroup> edit(@RequestBody KuaishouCostGroup kuaishouCostGroup) {
-        Result<KuaishouCostGroup> result = new Result<KuaishouCostGroup>();
-        KuaishouCostGroup kuaishouCostGroupEntity = kuaishouCostGroupService.getById(kuaishouCostGroup.getId());
-        if (kuaishouCostGroupEntity == null) {
-            result.error500("未找到对应实体");
-        } else {
-            boolean ok = kuaishouCostGroupService.updateById(kuaishouCostGroup);
-            if (ok) {
-                result.success("修改成功!");
-            }
-        }
-
-        return result;
-    }
-
-    /**
      * 通过id删除
      * 通过id删除
      *
      *
      * @param id
      * @param id

+ 1 - 9
module-kuaishou/src/main/java/cn/com/ctop/kuaishou/modules/report/entity/KuaishouCostGroup.java

@@ -1,7 +1,5 @@
 package cn.com.ctop.kuaishou.modules.report.entity;
 package cn.com.ctop.kuaishou.modules.report.entity;
 
 
-import com.baomidou.mybatisplus.annotation.IdType;
-import com.baomidou.mybatisplus.annotation.TableId;
 import com.baomidou.mybatisplus.annotation.TableName;
 import com.baomidou.mybatisplus.annotation.TableName;
 import com.fasterxml.jackson.annotation.JsonFormat;
 import com.fasterxml.jackson.annotation.JsonFormat;
 import io.swagger.annotations.ApiModel;
 import io.swagger.annotations.ApiModel;
@@ -15,7 +13,7 @@ import org.springframework.format.annotation.DateTimeFormat;
 import java.util.Date;
 import java.util.Date;
 
 
 /**
 /**
- * 快手组级时报统计
+ * 快手时报统计
  *
  *
  * @author jeecg-boot
  * @author jeecg-boot
  * @version V1.0
  * @version V1.0
@@ -29,12 +27,6 @@ import java.util.Date;
 public class KuaishouCostGroup {
 public class KuaishouCostGroup {
 
 
     /**
     /**
-     * id
-     */
-    @TableId(type = IdType.INPUT)
-    @ApiModelProperty(value = "id")
-    private Long id;
-    /**
      * 账户ID
      * 账户ID
      */
      */
     @Excel(name = "账户ID", width = 15)
     @Excel(name = "账户ID", width = 15)

+ 4 - 2
module-kuaishou/src/main/java/cn/com/ctop/kuaishou/modules/report/mapper/KuaishouCostGroupMapper.java

@@ -15,9 +15,11 @@ import java.util.List;
  */
  */
 public interface KuaishouCostGroupMapper extends BaseMapper<KuaishouCostGroup> {
 public interface KuaishouCostGroupMapper extends BaseMapper<KuaishouCostGroup> {
 
 
+    List<JSONObject> queryAccountCostInfo(String nowDate);
+
+    List<JSONObject> queryCampaignCostInfo(String date);
+
     List<JSONObject> queryGroupCostInfo(String date);
     List<JSONObject> queryGroupCostInfo(String date);
 
 
     int bulkInsert(List<JSONObject> list);
     int bulkInsert(List<JSONObject> list);
-
-    List<JSONObject> queryAccountCostInfo(String nowDate);
 }
 }

+ 55 - 19
module-kuaishou/src/main/java/cn/com/ctop/kuaishou/modules/report/mapper/xml/KuaishouCostGroupMapper.xml

@@ -1,8 +1,11 @@
 <?xml version="1.0" encoding="UTF-8"?>
 <?xml version="1.0" encoding="UTF-8"?>
 <!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
 <!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
 <mapper namespace="cn.com.ctop.kuaishou.modules.report.mapper.KuaishouCostGroupMapper">
 <mapper namespace="cn.com.ctop.kuaishou.modules.report.mapper.KuaishouCostGroupMapper">
-    <select id="queryGroupCostInfo" resultType="com.alibaba.fastjson.JSONObject">
-        SELECT stat_date AS statDate,account_id AS accountId,unit_id AS unitId,ROUND(SUM(charge),3) AS totalCost,
+
+    <select id="queryAccountCostInfo" resultType="com.alibaba.fastjson.JSONObject">
+        SELECT
+        stat_date AS statDate,account_id AS accountId,ROUND(SUM(charge),3) AS totalCost,
+        "account" AS type, sysdate() AS createTime,
         CASE WHEN SUM(bclick) != 0 THEN
         CASE WHEN SUM(bclick) != 0 THEN
         ROUND(SUM(charge)/SUM(bclick),3) ELSE 0 END AS 'actionCost',
         ROUND(SUM(charge)/SUM(bclick),3) ELSE 0 END AS 'actionCost',
         CASE WHEN SUM(activation) != 0 THEN
         CASE WHEN SUM(activation) != 0 THEN
@@ -10,9 +13,9 @@
         CASE WHEN SUM(event_register) != 0 THEN
         CASE WHEN SUM(event_register) != 0 THEN
         ROUND(SUM(charge)/SUM(event_register),3)  ELSE 0 END AS  registerCost,
         ROUND(SUM(charge)/SUM(event_register),3)  ELSE 0 END AS  registerCost,
         CASE WHEN SUM(event_pay) != 0 THEN
         CASE WHEN SUM(event_pay) != 0 THEN
-         ROUND(SUM(charge) / SUM(event_pay), 3) ELSE 0 END AS  payCost,
+        ROUND(SUM(charge) / SUM(event_pay), 3) ELSE 0 END AS  payCost,
         CASE WHEN SUM(form_count) != 0 THEN
         CASE WHEN SUM(form_count) != 0 THEN
-         ROUND(SUM(charge) / SUM(form_count),3) ELSE 0 END AS  formCost,
+        ROUND(SUM(charge) / SUM(form_count),3) ELSE 0 END AS  formCost,
         CASE WHEN SUM(event_jin_jian_app) != 0 THEN
         CASE WHEN SUM(event_jin_jian_app) != 0 THEN
         ROUND(SUM(charge)/SUM(event_jin_jian_app) ,3) ELSE 0 END AS finishedCost,
         ROUND(SUM(charge)/SUM(event_jin_jian_app) ,3) ELSE 0 END AS finishedCost,
         CASE WHEN SUM(event_credit_grant_app) != 0 THEN
         CASE WHEN SUM(event_credit_grant_app) != 0 THEN
@@ -20,15 +23,18 @@
         CASE WHEN SUM(charge) != 0 THEN
         CASE WHEN SUM(charge) != 0 THEN
         ROUND(SUM(event_pay_purchase_amount_first_day)/SUM(charge) ,4) ELSE 0 END AS firstDayRoi,
         ROUND(SUM(event_pay_purchase_amount_first_day)/SUM(charge) ,4) ELSE 0 END AS firstDayRoi,
         CASE WHEN SUM(charge) != 0 THEN
         CASE WHEN SUM(charge) != 0 THEN
-        ROUND(SUM(event_pay_purchase_amount)/SUM(charge) ,4) ELSE 0 END AS roi,
-        "unit" AS type,
-        sysdate() AS createTime
-         FROM ctop_kuaishou_report_hourly_group
+        ROUND(SUM(event_pay_purchase_amount)/SUM(charge) ,4) ELSE 0 END AS roi
+        FROM ctop_kuaishou_report_hourly_account
         WHERE stat_date = #{date}
         WHERE stat_date = #{date}
-        GROUP BY unit_id
+        GROUP BY account_id
     </select>
     </select>
-    <select id="queryAccountCostInfo" resultType="com.alibaba.fastjson.JSONObject">
-        SELECT stat_date AS statDate,account_id AS accountId,ROUND(SUM(charge),3) AS totalCost,
+
+    <select id="queryCampaignCostInfo" resultType="com.alibaba.fastjson.JSONObject">
+       SELECT
+        t1.stat_date AS statDate,t1.account_id AS accountId,
+		t1.campaign_id AS campaignId,IFNULL(t2.status,-1) as campaignStatus,
+		"campaign" AS type, sysdate() AS createTime,
+		ROUND(SUM(charge),3) AS totalCost,
         CASE WHEN SUM(bclick) != 0 THEN
         CASE WHEN SUM(bclick) != 0 THEN
         ROUND(SUM(charge)/SUM(bclick),3) ELSE 0 END AS 'actionCost',
         ROUND(SUM(charge)/SUM(bclick),3) ELSE 0 END AS 'actionCost',
         CASE WHEN SUM(activation) != 0 THEN
         CASE WHEN SUM(activation) != 0 THEN
@@ -36,9 +42,9 @@
         CASE WHEN SUM(event_register) != 0 THEN
         CASE WHEN SUM(event_register) != 0 THEN
         ROUND(SUM(charge)/SUM(event_register),3)  ELSE 0 END AS  registerCost,
         ROUND(SUM(charge)/SUM(event_register),3)  ELSE 0 END AS  registerCost,
         CASE WHEN SUM(event_pay) != 0 THEN
         CASE WHEN SUM(event_pay) != 0 THEN
-         ROUND(SUM(charge) / SUM(event_pay), 3) ELSE 0 END AS  payCost,
+        ROUND(SUM(charge) / SUM(event_pay), 3) ELSE 0 END AS  payCost,
         CASE WHEN SUM(form_count) != 0 THEN
         CASE WHEN SUM(form_count) != 0 THEN
-         ROUND(SUM(charge) / SUM(form_count),3) ELSE 0 END AS  formCost,
+        ROUND(SUM(charge) / SUM(form_count),3) ELSE 0 END AS  formCost,
         CASE WHEN SUM(event_jin_jian_app) != 0 THEN
         CASE WHEN SUM(event_jin_jian_app) != 0 THEN
         ROUND(SUM(charge)/SUM(event_jin_jian_app) ,3) ELSE 0 END AS finishedCost,
         ROUND(SUM(charge)/SUM(event_jin_jian_app) ,3) ELSE 0 END AS finishedCost,
         CASE WHEN SUM(event_credit_grant_app) != 0 THEN
         CASE WHEN SUM(event_credit_grant_app) != 0 THEN
@@ -46,23 +52,53 @@
         CASE WHEN SUM(charge) != 0 THEN
         CASE WHEN SUM(charge) != 0 THEN
         ROUND(SUM(event_pay_purchase_amount_first_day)/SUM(charge) ,4) ELSE 0 END AS firstDayRoi,
         ROUND(SUM(event_pay_purchase_amount_first_day)/SUM(charge) ,4) ELSE 0 END AS firstDayRoi,
         CASE WHEN SUM(charge) != 0 THEN
         CASE WHEN SUM(charge) != 0 THEN
-        ROUND(SUM(event_pay_purchase_amount)/SUM(charge) ,4) ELSE 0 END AS roi,
-        "account" AS type,
-        sysdate() AS createTime
-         FROM ctop_kuaishou_report_hourly_account
+        ROUND(SUM(event_pay_purchase_amount)/SUM(charge) ,4) ELSE 0 END AS roi
+        FROM ctop_kuaishou_report_hourly_campaign t1
+		LEFT JOIN ctop_kuaishou_campaign t2 ON t1.campaign_id = t2.campaign_id
         WHERE stat_date = #{date}
         WHERE stat_date = #{date}
-        GROUP BY account_id
+        GROUP BY t1.campaign_id
+    </select>
+
+    <select id="queryGroupCostInfo" resultType="com.alibaba.fastjson.JSONObject">
+        SELECT
+        stat_date AS statDate,t1.account_id AS accountId,t1.campaign_id AS campaignId,
+        t1.unit_id AS unitId,IFNULL(t2.status,-1) as unitStatus,
+        "unit" AS type, sysdate() AS createTime,
+		ROUND(SUM(charge),3) AS totalCost,
+        CASE WHEN SUM(bclick) != 0 THEN
+        ROUND(SUM(charge)/SUM(bclick),3) ELSE 0 END AS 'actionCost',
+        CASE WHEN SUM(activation) != 0 THEN
+        ROUND(SUM(charge)/SUM(activation),3) ELSE 0 END AS activationCost,
+        CASE WHEN SUM(event_register) != 0 THEN
+        ROUND(SUM(charge)/SUM(event_register),3)  ELSE 0 END AS  registerCost,
+        CASE WHEN SUM(event_pay) != 0 THEN
+        ROUND(SUM(charge) / SUM(event_pay), 3) ELSE 0 END AS  payCost,
+        CASE WHEN SUM(form_count) != 0 THEN
+        ROUND(SUM(charge) / SUM(form_count),3) ELSE 0 END AS  formCost,
+        CASE WHEN SUM(event_jin_jian_app) != 0 THEN
+        ROUND(SUM(charge)/SUM(event_jin_jian_app) ,3) ELSE 0 END AS finishedCost,
+        CASE WHEN SUM(event_credit_grant_app) != 0 THEN
+        ROUND(SUM(charge)/SUM(event_credit_grant_app) ,3)ELSE 0 END AS approvalCost,
+        CASE WHEN SUM(charge) != 0 THEN
+        ROUND(SUM(event_pay_purchase_amount_first_day)/SUM(charge) ,4) ELSE 0 END AS firstDayRoi,
+        CASE WHEN SUM(charge) != 0 THEN
+        ROUND(SUM(event_pay_purchase_amount)/SUM(charge) ,4) ELSE 0 END AS roi
+        FROM ctop_kuaishou_report_hourly_group t1
+		LEFT JOIN ctop_kuaishou_group t2 ON t1.unit_id = t2.unit_id
+        WHERE stat_date = #{date}
+        GROUP BY t1.unit_id
     </select>
     </select>
 
 
     <insert id="bulkInsert" parameterType="com.alibaba.fastjson.JSONObject">
     <insert id="bulkInsert" parameterType="com.alibaba.fastjson.JSONObject">
         insert into ctop_kuaishou_cost_group (
         insert into ctop_kuaishou_cost_group (
-        account_id, unit_id, total_cost, total_balance, type,stat_date, action_cost, activation_cost,
+        account_id, campaign_id,unit_id, total_cost, total_balance, type,stat_date, action_cost, activation_cost,
         register_cost, pay_cost, form_cost,finished_cost,approval_cost,first_day_roi,roi,create_time
         register_cost, pay_cost, form_cost,finished_cost,approval_cost,first_day_roi,roi,create_time
         )
         )
         values
         values
         <foreach collection="list" item="it" separator=",">
         <foreach collection="list" item="it" separator=",">
             (
             (
             #{it.accountId},
             #{it.accountId},
+            #{it.campaignId},
             #{it.unitId},
             #{it.unitId},
             #{it.totalCost},
             #{it.totalCost},
             #{it.totalBalance},
             #{it.totalBalance},

+ 30 - 7
module-kuaishou/src/main/java/cn/com/ctop/kuaishou/modules/report/service/impl/KuaishouCostGroupServiceImpl.java

@@ -10,6 +10,7 @@ import cn.com.ctop.kuaishou.modules.report.mapper.KuaishouReportHourlyGroupMappe
 import cn.com.ctop.kuaishou.modules.report.service.IKuaishouCostGroupService;
 import cn.com.ctop.kuaishou.modules.report.service.IKuaishouCostGroupService;
 import com.alibaba.fastjson.JSONObject;
 import com.alibaba.fastjson.JSONObject;
 import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
 import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
+import lombok.extern.slf4j.Slf4j;
 import org.jeecg.common.util.DateUtils;
 import org.jeecg.common.util.DateUtils;
 import org.jeecg.common.util.db.DataSourceCachePool;
 import org.jeecg.common.util.db.DataSourceCachePool;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.beans.factory.annotation.Autowired;
@@ -27,6 +28,7 @@ import java.util.Map;
  * @version V1.0
  * @version V1.0
  * @date 2020-10-30
  * @date 2020-10-30
  */
  */
+@Slf4j
 @Service
 @Service
 public class KuaishouCostGroupServiceImpl extends ServiceImpl<KuaishouCostGroupMapper, KuaishouCostGroup> implements IKuaishouCostGroupService {
 public class KuaishouCostGroupServiceImpl extends ServiceImpl<KuaishouCostGroupMapper, KuaishouCostGroup> implements IKuaishouCostGroupService {
 
 
@@ -43,27 +45,48 @@ public class KuaishouCostGroupServiceImpl extends ServiceImpl<KuaishouCostGroupM
 
 
     @Override
     @Override
     public void saveInfo() {
     public void saveInfo() {
+        log.info("-----更新数据-start--------");
+        long startTime = System.currentTimeMillis();
         String date = DateUtils.getNowDate(DateUtils.WEB_FORMAT);
         String date = DateUtils.getNowDate(DateUtils.WEB_FORMAT);
         Map<String, Object> deleteMap = new HashMap<>();
         Map<String, Object> deleteMap = new HashMap<>();
         deleteMap.put("stat_date", date);
         deleteMap.put("stat_date", date);
         kuaishouCostGroupMapper.deleteByMap(deleteMap);
         kuaishouCostGroupMapper.deleteByMap(deleteMap);
-        //组级的数据统计
-//        List<JSONObject> grouplist = kuaishouCostGroupMapper.queryGroupCostInfo(date);
-//        if (!Check.isNull(grouplist)) {
-//            kuaishouCostGroupMapper.bulkInsert(grouplist);
-//        }
+        //获取账户级数据
         List<JSONObject> accountList = kuaishouCostGroupMapper.queryAccountCostInfo(date);
         List<JSONObject> accountList = kuaishouCostGroupMapper.queryAccountCostInfo(date);
         if (!Check.isNull(accountList)) {
         if (!Check.isNull(accountList)) {
+            //获取账户余额
             getTotalBalance(accountList);
             getTotalBalance(accountList);
             kuaishouCostGroupMapper.bulkInsert(accountList);
             kuaishouCostGroupMapper.bulkInsert(accountList);
         }
         }
+        //获取计划级数据
+        List<JSONObject> campaignList = kuaishouCostGroupMapper.queryCampaignCostInfo(date);
+        if (!Check.isNull(campaignList)) {
+            kuaishouCostGroupMapper.bulkInsert(campaignList);
+        }
+        //获取组级数据
+        List<JSONObject> grouplist = kuaishouCostGroupMapper.queryGroupCostInfo(date);
+        if (!Check.isNull(grouplist)) {
+            kuaishouCostGroupMapper.bulkInsert(grouplist);
+        }
         Map<String, List<JSONObject>> map = new HashMap<>();
         Map<String, List<JSONObject>> map = new HashMap<>();
-//        map.put("unit", grouplist);
-        map.put("account", accountList);
+        map.put("ACCOUNT", accountList);
+        map.put("CAMPAIGN", campaignList);
+        map.put("UNIT", grouplist);
+
         HashOperations<String, Object, Object> hash = DataSourceCachePool.getRedisTemplate().opsForHash();
         HashOperations<String, Object, Object> hash = DataSourceCachePool.getRedisTemplate().opsForHash();
         hash.putAll("KS_COST", map);
         hash.putAll("KS_COST", map);
+        long endTime = System.currentTimeMillis();
+        log.info("---end---更新数据用时:{} ms", endTime - startTime);
     }
     }
 
 
+    /**
+     * 查询余额
+     *
+     * @param
+     * @return void
+     * @throws
+     * @author ZHAOXA
+     */
     private void getTotalBalance(List<JSONObject> accountList) {
     private void getTotalBalance(List<JSONObject> accountList) {
         for (JSONObject obj : accountList) {
         for (JSONObject obj : accountList) {
             CtopOauthToken oauthToken = oauthTokenService.getTokenByAccountId(obj.getLong("accountId"));
             CtopOauthToken oauthToken = oauthTokenService.getTokenByAccountId(obj.getLong("accountId"));

+ 9 - 0
module-kuaishou/src/main/java/cn/com/ctop/kuaishou/modules/report/service/impl/KuaishouZombieCreativeServiceImpl.java

@@ -21,6 +21,7 @@ import com.alibaba.fastjson.JSONObject;
 import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
 import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
 import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
 import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
 import com.xxl.job.core.enums.NoEn;
 import com.xxl.job.core.enums.NoEn;
+import lombok.extern.slf4j.Slf4j;
 import org.jeecg.common.util.DateUtils;
 import org.jeecg.common.util.DateUtils;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.stereotype.Service;
 import org.springframework.stereotype.Service;
@@ -38,6 +39,7 @@ import java.util.Map;
  * @version V1.0
  * @version V1.0
  * @date 2020-10-14
  * @date 2020-10-14
  */
  */
+@Slf4j
 @Service
 @Service
 public class KuaishouZombieCreativeServiceImpl extends ServiceImpl<KuaishouZombieCreativeMapper, KuaishouZombieCreative> implements IKuaishouZombieCreativeService {
 public class KuaishouZombieCreativeServiceImpl extends ServiceImpl<KuaishouZombieCreativeMapper, KuaishouZombieCreative> implements IKuaishouZombieCreativeService {
     @Autowired
     @Autowired
@@ -76,6 +78,8 @@ public class KuaishouZombieCreativeServiceImpl extends ServiceImpl<KuaishouZombi
 
 
     @Override
     @Override
     public void checkZombieProject() {
     public void checkZombieProject() {
+        log.info("-----------------start---------------");
+        long startTime = System.currentTimeMillis();
         //获取五天前的日期 yyyy-MM-dd
         //获取五天前的日期 yyyy-MM-dd
         String date = DateUtils.getLastDay(DateUtils.formatDate(new Date()), NoEn.NO5.valueInt());
         String date = DateUtils.getLastDay(DateUtils.formatDate(new Date()), NoEn.NO5.valueInt());
         //查询五天内花费都为0的数据集
         //查询五天内花费都为0的数据集
@@ -96,6 +100,8 @@ public class KuaishouZombieCreativeServiceImpl extends ServiceImpl<KuaishouZombi
             List<KuaishouZombieCreative> zombiePlans = new ArrayList<>();
             List<KuaishouZombieCreative> zombiePlans = new ArrayList<>();
             List<JSONObject> zombieList = new ArrayList<>();
             List<JSONObject> zombieList = new ArrayList<>();
             //通过账户和创意ID,筛选出确认的僵尸计划账户
             //通过账户和创意ID,筛选出确认的僵尸计划账户
+            long tims = System.currentTimeMillis();
+            log.info("-----获取数据集---------用时:{} ms", tims - startTime);
             zombieCreatives.forEach(zombie -> {
             zombieCreatives.forEach(zombie -> {
                 list.forEach(obj -> {
                 list.forEach(obj -> {
                     if (zombie.getAccountId() - obj.getInteger("accountId") == 0 && zombie.getCreativeId() - obj.getInteger("creativeId") == 0) {
                     if (zombie.getAccountId() - obj.getInteger("accountId") == 0 && zombie.getCreativeId() - obj.getInteger("creativeId") == 0) {
@@ -131,6 +137,7 @@ public class KuaishouZombieCreativeServiceImpl extends ServiceImpl<KuaishouZombi
                     }
                     }
                 });
                 });
             });
             });
+            log.info("-----筛选逻辑---------用时:{} ms", System.currentTimeMillis() - tims);
             //过滤掉已确认的僵尸数据,剩余活跃的计划
             //过滤掉已确认的僵尸数据,剩余活跃的计划
             zombieCreatives.removeAll(zombiePlans);
             zombieCreatives.removeAll(zombiePlans);
             //更新计划状态为已活跃
             //更新计划状态为已活跃
@@ -147,6 +154,8 @@ public class KuaishouZombieCreativeServiceImpl extends ServiceImpl<KuaishouZombi
         } else {
         } else {
             insertorUpdate(list);
             insertorUpdate(list);
         }
         }
+        long endTime = System.currentTimeMillis();
+        log.info("---end---共用时:{} ms", endTime - startTime);
     }
     }
 
 
     /**
     /**

+ 4 - 0
module-toutiao/src/main/java/cn/com/ctop/toutiao/modules/material/service/IByteDanceAdvertiserDataService.java

@@ -38,4 +38,8 @@ public interface IByteDanceAdvertiserDataService {
     void getImageByPage(CtopOauthToken token, String imageIds, int page);
     void getImageByPage(CtopOauthToken token, String imageIds, int page);
 
 
     JSONArray advertiserList(String token);
     JSONArray advertiserList(String token);
+
+
+    void getBytedancePlanList(String accountId, String accessToken, int pageNum, String createDate, String updateDate);
+
 }
 }

+ 43 - 0
module-toutiao/src/main/java/cn/com/ctop/toutiao/modules/material/service/impl/ByteDanceAdvertiserDataServiceImpl.java

@@ -716,4 +716,47 @@ public class ByteDanceAdvertiserDataServiceImpl implements IByteDanceAdvertiserD
         params.put("page_size", 100);
         params.put("page_size", 100);
         return HttpUtils.bytedanceGetRequest(token.getAccessToken(), url, params);
         return HttpUtils.bytedanceGetRequest(token.getAccessToken(), url, params);
     }
     }
+
+
+    public void getBytedancePlanList(String accountId, String accessToken, int pageNum, String createDate, String updateDate) {
+
+        // 请求地址
+        String url = PropertiesUtils.getValue("bytedance_config", "bytedance_api_url") + PropertiesUtils.getValue("bytedance_config", "bytedance_v2_ad_get");
+        // 请求参数
+        Map<String, Object> filtering = new HashMap<>();
+        if (null != createDate && !"".equals(createDate)) {
+            filtering.put("ad_create_time", createDate);
+        }
+        if (null != updateDate && !"".equals(updateDate)) {
+            filtering.put("ad_modify_time", updateDate);
+        }
+
+        JSONObject param = new JSONObject();
+        param.put("advertiser_id", accountId);
+        param.put("page", pageNum);
+        param.put("page_size", 1000);
+        param.put("filtering", filtering);
+        JSONObject resultObject = HttpUtils.bytedanceGetRequest(accessToken, url, param);
+        Integer code = resultObject.getInteger("code");
+        if (null == code || !code.equals(0)) {
+            log.error("获取广告计划信息接口异常==》accountId:{},message:{}", accountId, resultObject.getString("message"));
+            return;
+        }
+        JSONArray data = resultObject.getJSONObject("data").getJSONArray("list");
+        if (null == data || data.isEmpty()) {
+            return;
+        }
+        for (int i = 0; i < data.size(); i++) {
+            JSONObject dataObject = data.getJSONObject(i);
+            ByteDanceAdvertisePlan advertisePlan = new ByteDanceAdvertisePlan(dataObject, accountId);
+            BigDecimal deepCpabid = dataObject.getBigDecimal("deep_cpabid");
+            if (null != deepCpabid) {
+                advertisePlan.setDeepCpaBid(deepCpabid);
+            }
+            //   advertisePlanService.saveOrUpdate(advertisePlan);
+        }
+        getBytedancePlanList(accountId, accessToken, pageNum + 1, createDate, updateDate);
+    }
+
+
 }
 }

+ 1 - 0
module-toutiao/src/main/java/cn/com/ctop/toutiao/modules/report/mapper/xml/BytedanceVideoReportMapper.xml

@@ -27,6 +27,7 @@
                 #{item}
                 #{item}
             </foreach>
             </foreach>
         </if>
         </if>
+        AND t1.video_url is not null
         GROUP BY t1.signature
         GROUP BY t1.signature
         ) t
         ) t
         WHERE (t.clip LIKE '%${clip}%')
         WHERE (t.clip LIKE '%${clip}%')