Explorar o código

Merge remote-tracking branch 'origin/master'

syh %!s(int64=4) %!d(string=hai) anos
pai
achega
866ad43cc4

+ 1 - 0
jeecg-boot-module-system/src/main/java/org/jeecg/config/ShiroConfig.java

@@ -184,6 +184,7 @@ public class ShiroConfig {
         filterChainDefinitionMap.put("/kuaishou/material/*", "anon");
         filterChainDefinitionMap.put("/kuaishou/create/*", "anon");
         filterChainDefinitionMap.put("/template/kuaiShouBatchCampaignTemplate/*", "anon");
+        filterChainDefinitionMap.put("/batch/kuaiShouGroupTemplate/*", "anon");
 
         // 添加自己的过滤器并且取名为jwt
         Map<String, Filter> filterMap = new HashMap<>(1);

+ 7 - 10
module-alarm/src/main/java/cn/com/ctop/alarm/modules/constant/MatchLogic.java

@@ -68,16 +68,13 @@ public class MatchLogic {
                         return value.equals(thresholds.get(0));
                     } else if ("not_equal".equals(condition)) {
                         return !value.equals(thresholds.get(0));
-                    }
-                    for (String thro : thresholds) {
-                        if ("contain".equals(condition)) {
-                            if (value.contains(thro)) {
-                                return true;
-                            }
-                        } else if ("no_contain".equals(condition)) {
-                            if (!value.contains(thro)) {
-                                return true;
-                            }
+                    } else if ("contain".equals(condition)) {
+                        if (thresholds.toString().contains(value)) {
+                            return true;
+                        }
+                    } else if ("no_contain".equals(condition)) {
+                        if (!thresholds.toString().contains(value)) {
+                            return true;
                         }
                     }
                 } else {

+ 22 - 1
module-job-kuaishou/src/main/java/cn/com/ctop/job/kuaishou/handler/KuaishouCreateUnitJob.java

@@ -1,10 +1,17 @@
 package cn.com.ctop.job.kuaishou.handler;
 
+import cn.com.ctop.common.module.utils.Check;
+import cn.com.ctop.common.module.utils.HttpUtils2;
 import cn.com.ctop.kuaishou.modules.batch.service.IKuaiShouGroupTemplateService;
+import com.xxl.job.core.context.XxlJobHelper;
 import com.xxl.job.core.handler.annotation.XxlJob;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.stereotype.Component;
 
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+
 @Component
 public class KuaishouCreateUnitJob {
 
@@ -14,6 +21,20 @@ public class KuaishouCreateUnitJob {
 
     @XxlJob("kuaihouCreateUnit")
     public void execute() {
-        groupTemplateService.createUnit();
+
+        List<Long> idList = groupTemplateService.getIdList();
+        if (Check.isNull(idList)) {
+            XxlJobHelper.log("批量2.0暂时没有未创建的组");
+            return;
+        }
+        String url = "http://api.tjyourong.com.cn/jeecg-boot/batch/kuaiShouGroupTemplate/createUnit";
+        for (int i = 0; i < idList.size(); i++) {
+            Long id = idList.get(i);
+            Map<String, Object> requestMap = new HashMap<>();
+            requestMap.put("id", id);
+            HttpUtils2.httpGet(url, requestMap, null);
+        }
+
+
     }
 }

+ 9 - 3
module-kuaishou/src/main/java/cn/com/ctop/kuaishou/modules/batch/controller/KuaiShouGroupTemplateController.java

@@ -35,6 +35,8 @@ import java.net.URLDecoder;
 import java.util.Arrays;
 import java.util.List;
 import java.util.Map;
+import java.util.concurrent.ExecutorService;
+import java.util.concurrent.Executors;
 
 /**
  * 创建组模板
@@ -50,7 +52,7 @@ import java.util.Map;
 public class KuaiShouGroupTemplateController {
     @Autowired
     private IKuaiShouGroupTemplateService kuaiShouGroupTemplateService;
-
+    static ExecutorService executorService = Executors.newFixedThreadPool(10);
 
     /**
      * 批量创建广告组
@@ -78,11 +80,15 @@ public class KuaiShouGroupTemplateController {
 
     }
 
+
     @GetMapping(value = "/createUnit")
-    public Result<JSONObject> createUnit() {
+    public Result<JSONObject> createUnit(Long id) {
         Result<JSONObject> result = new Result<>();
         try {
-            kuaiShouGroupTemplateService.createUnit();
+            KuaiShouGroupTemplate template = kuaiShouGroupTemplateService.getById(id);
+            if (!Check.isNull(template)) {
+                executorService.submit(() -> kuaiShouGroupTemplateService.createUnit(template));
+            }
             result.setSuccess(true);
         } catch (Exception e) {
             e.printStackTrace();

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

@@ -25,4 +25,6 @@ public interface KuaiShouGroupTemplateMapper extends BaseMapper<KuaiShouGroupTem
     JSONObject getUrlByPhotoId(@Param("photoId") Long photoId);
 
     JSONObject getImageJsonByMd5(String md5);
+
+    List<Long> getIdList();
 }

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

@@ -48,4 +48,11 @@
      limit 1
     </select>
 
+    <select id="getIdList" resultType="java.lang.Long">
+    select id  from ctop_kuaishou_group_template
+    where  task_status = 0
+    order by create_time desc
+    limit 70
+    </select>
+
 </mapper>

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

@@ -4,6 +4,8 @@ import cn.com.ctop.kuaishou.modules.batch.entity.KuaiShouGroupTemplate;
 import com.alibaba.fastjson.JSONObject;
 import com.baomidou.mybatisplus.extension.service.IService;
 
+import java.util.List;
+
 /**
  * @Description: 创建组模板
  * @Author: jeecg-boot
@@ -14,7 +16,7 @@ public interface IKuaiShouGroupTemplateService extends IService<KuaiShouGroupTem
 
     JSONObject submitUnitTask(JSONObject requestJson) throws Exception;
 
-    void createUnit();
+    void createUnit(KuaiShouGroupTemplate template);
 
     /**
      * 获取api创建数
@@ -35,4 +37,11 @@ public interface IKuaiShouGroupTemplateService extends IService<KuaiShouGroupTem
     void createCreative(String accessToken, Long unitId, KuaiShouGroupTemplate template);
 
     JSONObject getUnionJson(Long templateId);
+
+    /**
+     * 获取待创建2.0Id列表
+     *
+     * @return
+     */
+    List<Long> getIdList();
 }

+ 133 - 141
module-kuaishou/src/main/java/cn/com/ctop/kuaishou/modules/batch/service/impl/KuaiShouGroupTemplateServiceImpl.java

@@ -275,153 +275,140 @@ public class KuaiShouGroupTemplateServiceImpl extends ServiceImpl<KuaiShouGroupT
      * 创建组
      */
     @Override
-    public void createUnit() {
-        QueryWrapper<KuaiShouGroupTemplate> queryWrapper = new QueryWrapper<>();
-        queryWrapper.eq("task_status", 0);
-        queryWrapper.orderByAsc("create_time");
-        queryWrapper.last("limit 45");
-        List<KuaiShouGroupTemplate> list = this.list(queryWrapper);
-        if (Check.isNull(list)) {
-            log.error("暂未未创建的组");
+    public void createUnit(KuaiShouGroupTemplate template) {
+        Long accountId = template.getAccountId();
+        CtopOauthToken token = tokenService.getTokenByAccountId(accountId);
+        KuaiShouGroupTemplate updateTemplate = new KuaiShouGroupTemplate();
+        if (Check.isNull(token)) {
+            updateTemplate.setTaskStatus(3);
+            updateTemplate.setReviewDetail("未获取到授权信息");
+            updateTemplate.setCreativeStatus(3);
+            updateTemplate.setCreativeReviewDetail("未获取到授权信息");
+            updateById(updateTemplate);
             return;
         }
-        for (KuaiShouGroupTemplate template : list) {
-            executorService.submit(new Runnable() {
-                @Override
-                public void run() {
 
-                    Long accountId = template.getAccountId();
-                    CtopOauthToken token = tokenService.getTokenByAccountId(accountId);
-                    if (Check.isNull(token)) {
-                        return;
-                    }
-                    KuaiShouGroupTemplate updateTemplate = new KuaiShouGroupTemplate();
-                    updateTemplate.setId(template.getId());
-                    updateTemplate.setTaskStatus(1);
-                    updateById(updateTemplate);   // 修改状态为创建中
-                    JSONObject createUnitJson = new JSONObject();
-
-                    JSONArray sceneIdArr = JSONArray.parseArray(template.getSceneId());
-                    if (Check.isNull(sceneIdArr)) {
-                        updateTemplate.setTaskStatus(3);
-                        updateTemplate.setReviewDetail("scene_id不能为空");
-                        updateTemplate.setCreativeStatus(3);
-                        updateTemplate.setCreativeReviewDetail("组创建失败");
-                        updateById(updateTemplate);
-                        return;
-                    }
-                    createUnitJson.put("scene_id", sceneIdArr); //资源位置
-                    Integer sceneId = (Integer) sceneIdArr.get(0);
-                    if (sceneId != 5) {
-                        if (!Check.isNull(template.getTemplateId())) {
-                            createUnitJson.put("template_id", template.getTemplateId());
-                        }
-                    } else {
-                        if (!Check.isNull(template.getTemplateId())) {
-                            JSONObject unionJson = getUnionJson(template.getTemplateId());
-                            if (unionJson.getInteger("code") != 0) {
-                                updateTemplate.setTaskStatus(3);
-                                updateTemplate.setReviewDetail(unionJson.getString("message"));
-                                updateTemplate.setCreativeStatus(3);
-                                updateTemplate.setCreativeReviewDetail("组创建失败");
-                                updateById(updateTemplate);
-                                return;
-                            } else {
-                                createUnitJson.put("target", unionJson.getJSONObject("target"));
-                            }
-                        }
-                    }
-                    createUnitJson.put("campaign_id", template.getCampaignId());
-                    createUnitJson.put("unit_name", template.getUnitName());
-                    if (!Check.isNull(template.getBidType())) {
-                        createUnitJson.put("bid_type", template.getBidType()); // 优化目标类型
-                    }
-                    if (!Check.isNull(template.getUseAppMarket())) {
-                        createUnitJson.put("use_app_market", template.getUseAppMarket()); //优先从系统应用商店下载
-                    }
-                    if (!Check.isNull(template.getAppStore())) {
-                        createUnitJson.put("app_store", JSONArray.parseArray(template.getAppStore())); //应用商店列表
-                    }
-                    if (!Check.isNull(template.getBid())) {
-                        createUnitJson.put("bid", template.getBid()); //出价
-                    }
-                    if (!Check.isNull(template.getCpaBid())) {
-                        createUnitJson.put("cpa_bid", template.getCpaBid()); //出价
-                    }
-                    if (!Check.isNull(template.getOcpxActionType())) {
-                        createUnitJson.put("ocpx_action_type", template.getOcpxActionType()); //优化目标
-                    }
-                    if (!Check.isNull(template.getDeepConversionType())) {
-                        createUnitJson.put("deep_conversion_type", template.getDeepConversionType()); //深度转化目标
-                    }
-                    if (!Check.isNull(template.getDeepConversionBid())) {
-                        createUnitJson.put("deep_conversion_bid", template.getDeepConversionBid()); //深度转化目标出价
-                    }
-                    if (!Check.isNull(template.getUnitType())) {
-                        createUnitJson.put("unit_type", template.getUnitType()); //创意制作方式
-                    }
-                    if (!Check.isNull(template.getBeginTime())) {
-                        createUnitJson.put("begin_time", template.getBeginTime()); //投放开始时间
-                    }
-                    if (!Check.isNull(template.getEndTime())) {
-                        createUnitJson.put("end_time", template.getEndTime()); //投放结束时间
-                    }
-                    if (!Check.isNull(template.getScheduleTime())) {
-                        createUnitJson.put("schedule_time", template.getScheduleTime()); //投放时间段
-                    }
-                    if (!Check.isNull(template.getDayBudget())) {
-                        createUnitJson.put("day_budget", template.getDayBudget()); //单日预算金额
-                    }
-                    if (!Check.isNull(template.getConvertId())) {
-                        createUnitJson.put("convert_id", template.getConvertId()); //转化目标ID
-                    }
-                    if (!Check.isNull(template.getUrlType())) {
-                        createUnitJson.put("url_type", template.getUrlType()); //url类型
-                    }
-                    if (!Check.isNull(template.getUrl())) {
-                        createUnitJson.put("url", template.getUrl()); // 投放链接
-                    }
-                    if (!Check.isNull(template.getAppId())) {
-                        createUnitJson.put("app_id", template.getAppId()); // 应用ID
-                    }
-                    if (!Check.isNull(template.getShowMode())) {
-                        createUnitJson.put("show_mode", template.getShowMode()); // 创意展现方式
-                    }
-                    if (!Check.isNull(template.getSpeed())) {
-                        createUnitJson.put("speed", template.getSpeed()); // 投放方式
-                    }
-                    Map<String, Object> groupMap = iKuaishouInterfaceService.adUnitCreate(token.getAccessToken(), accountId, createUnitJson, 1);
-                    updateTemplate = new KuaiShouGroupTemplate();
-                    updateTemplate.setId(template.getId());
-                    Integer code = (Integer) groupMap.get("code");
-                    if (code == 0) {
-                        updateTemplate.setTaskStatus(2);
-                        Long unit = (Long) groupMap.get("unitId");
-                        updateTemplate.setUnitId((unit));
-                        Thread thread = new Thread() {
-                            @Override
-                            public void run() {
-                                createCreative(token.getAccessToken(), unit, template);
-                            }
-                        };
-                        thread.start();
-                    } else {
-                        updateTemplate.setTaskStatus(3);
-                        updateTemplate.setReviewDetail((String) groupMap.get("message"));
-                        updateTemplate.setCreativeStatus(3);
-                        updateTemplate.setCreativeReviewDetail("组创建失败");
-                    }
+        updateTemplate.setId(template.getId());
+        updateTemplate.setTaskStatus(1);
+        updateById(updateTemplate);   // 修改状态为创建中
+        JSONObject createUnitJson = new JSONObject();
+
+        JSONArray sceneIdArr = JSONArray.parseArray(template.getSceneId());
+        if (Check.isNull(sceneIdArr)) {
+            updateTemplate.setTaskStatus(3);
+            updateTemplate.setReviewDetail("scene_id不能为空");
+            updateTemplate.setCreativeStatus(3);
+            updateTemplate.setCreativeReviewDetail("组创建失败");
+            updateById(updateTemplate);
+            return;
+        }
+        createUnitJson.put("scene_id", sceneIdArr); //资源位置
+        Integer sceneId = (Integer) sceneIdArr.get(0);
+        if (sceneId != 5) {
+            if (!Check.isNull(template.getTemplateId())) {
+                createUnitJson.put("template_id", template.getTemplateId());
+            }
+        } else {
+            if (!Check.isNull(template.getTemplateId())) {
+                JSONObject unionJson = getUnionJson(template.getTemplateId());
+                if (unionJson.getInteger("code") != 0) {
+                    updateTemplate.setTaskStatus(3);
+                    updateTemplate.setReviewDetail(unionJson.getString("message"));
+                    updateTemplate.setCreativeStatus(3);
+                    updateTemplate.setCreativeReviewDetail("组创建失败");
                     updateById(updateTemplate);
-                    try {
-                        Thread.sleep(2 * 1000);
-                    } catch (InterruptedException e) {
-                        e.printStackTrace();
-                    }
-
+                    return;
+                } else {
+                    createUnitJson.put("target", unionJson.getJSONObject("target"));
                 }
-            });
+            }
+        }
+        createUnitJson.put("campaign_id", template.getCampaignId());
+        createUnitJson.put("unit_name", template.getUnitName());
+        if (!Check.isNull(template.getBidType())) {
+            createUnitJson.put("bid_type", template.getBidType()); // 优化目标类型
+        }
+        if (!Check.isNull(template.getUseAppMarket())) {
+            createUnitJson.put("use_app_market", template.getUseAppMarket()); //优先从系统应用商店下载
+        }
+        if (!Check.isNull(template.getAppStore())) {
+            createUnitJson.put("app_store", JSONArray.parseArray(template.getAppStore())); //应用商店列表
+        }
+        if (!Check.isNull(template.getBid())) {
+            createUnitJson.put("bid", template.getBid()); //出价
+        }
+        if (!Check.isNull(template.getCpaBid())) {
+            createUnitJson.put("cpa_bid", template.getCpaBid()); //出价
+        }
+        if (!Check.isNull(template.getOcpxActionType())) {
+            createUnitJson.put("ocpx_action_type", template.getOcpxActionType()); //优化目标
+        }
+        if (!Check.isNull(template.getDeepConversionType())) {
+            createUnitJson.put("deep_conversion_type", template.getDeepConversionType()); //深度转化目标
+        }
+        if (!Check.isNull(template.getDeepConversionBid())) {
+            createUnitJson.put("deep_conversion_bid", template.getDeepConversionBid()); //深度转化目标出价
+        }
+        if (!Check.isNull(template.getUnitType())) {
+            createUnitJson.put("unit_type", template.getUnitType()); //创意制作方式
+        }
+        if (!Check.isNull(template.getBeginTime())) {
+            createUnitJson.put("begin_time", template.getBeginTime()); //投放开始时间
+        }
+        if (!Check.isNull(template.getEndTime())) {
+            createUnitJson.put("end_time", template.getEndTime()); //投放结束时间
+        }
+        if (!Check.isNull(template.getScheduleTime())) {
+            createUnitJson.put("schedule_time", template.getScheduleTime()); //投放时间段
+        }
+        if (!Check.isNull(template.getDayBudget())) {
+            createUnitJson.put("day_budget", template.getDayBudget()); //单日预算金额
+        }
+        if (!Check.isNull(template.getConvertId())) {
+            createUnitJson.put("convert_id", template.getConvertId()); //转化目标ID
+        }
+        if (!Check.isNull(template.getUrlType())) {
+            createUnitJson.put("url_type", template.getUrlType()); //url类型
+        }
+        if (!Check.isNull(template.getUrl())) {
+            createUnitJson.put("url", template.getUrl()); // 投放链接
+        }
+        if (!Check.isNull(template.getAppId())) {
+            createUnitJson.put("app_id", template.getAppId()); // 应用ID
+        }
+        if (!Check.isNull(template.getShowMode())) {
+            createUnitJson.put("show_mode", template.getShowMode()); // 创意展现方式
+        }
+        if (!Check.isNull(template.getSpeed())) {
+            createUnitJson.put("speed", template.getSpeed()); // 投放方式
+        }
+        Map<String, Object> groupMap = iKuaishouInterfaceService.adUnitCreate(token.getAccessToken(), accountId, createUnitJson, 1);
+        updateTemplate = new KuaiShouGroupTemplate();
+        updateTemplate.setId(template.getId());
+        Integer code = (Integer) groupMap.get("code");
+        if (code == 0) {
+            updateTemplate.setTaskStatus(2);
+            Long unit = (Long) groupMap.get("unitId");
+            updateTemplate.setUnitId((unit));
+            Thread thread = new Thread() {
+                @Override
+                public void run() {
+                    createCreative(token.getAccessToken(), unit, template);
+                }
+            };
+            thread.start();
+        } else {
+            updateTemplate.setTaskStatus(3);
+            updateTemplate.setReviewDetail((String) groupMap.get("message"));
+            updateTemplate.setCreativeStatus(3);
+            updateTemplate.setCreativeReviewDetail("组创建失败");
+        }
+        updateById(updateTemplate);
+        try {
+            Thread.sleep(2 * 1000);
+        } catch (InterruptedException e) {
+            e.printStackTrace();
         }
-
     }
 
 
@@ -513,6 +500,11 @@ public class KuaiShouGroupTemplateServiceImpl extends ServiceImpl<KuaiShouGroupT
         return returnJson;
     }
 
+    @Override
+    public List<Long> getIdList() {
+        return groupTemplateMapper.getIdList();
+    }
+
     /**
      * 获取当天api创建创意数
      *