Browse Source

快手自动创建

yumeng 4 years ago
parent
commit
507db8d638

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

@@ -194,6 +194,7 @@ public class ShiroConfig {
         filterChainDefinitionMap.put("/explore/*", "anon");
         filterChainDefinitionMap.put("/ai/batchUpdate/*", "anon");
         filterChainDefinitionMap.put("/ctop/kuaishou/videoReport/*", "anon");
+        filterChainDefinitionMap.put("/ai/create/*", "anon");
         //filterChainDefinitionMap.put("/overView/*", "anon");
 
         // 添加自己的过滤器并且取名为jwt

+ 85 - 23
module-job-kuaishou/src/main/java/cn/com/ctop/job/kuaishou/handler/KuaishouAiCreativeJob.java

@@ -1,34 +1,34 @@
 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.ai.entity.AiKuaishouAdvertiserStrategy;
 import cn.com.ctop.kuaishou.modules.ai.service.IAiKuaishouAdvertiserStrategyService;
 import cn.com.ctop.kuaishou.modules.ai.service.IAiKuaishouCreateCreativeService;
+import com.alibaba.fastjson.JSONObject;
 import com.xxl.job.core.handler.annotation.XxlJob;
+import lombok.extern.slf4j.Slf4j;
 import org.jeecg.common.util.DateUtils;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.stereotype.Component;
 
 import java.text.ParseException;
+import java.util.HashMap;
 import java.util.List;
-import java.util.concurrent.ExecutorService;
-import java.util.concurrent.Executors;
+import java.util.Map;
 
 /**
  * @author syh
  * 自动投放定时任务
  */
 @Component
+@Slf4j
 public class KuaishouAiCreativeJob {
     @Autowired
     private IAiKuaishouAdvertiserStrategyService strategyService;
     @Autowired
     private IAiKuaishouCreateCreativeService createCreativeService;
 
-    static ExecutorService customCreativeAutoExecutorService = Executors.newFixedThreadPool(5);
-    static ExecutorService customCreativeSupplementExecutorService = Executors.newFixedThreadPool(5);
-    static ExecutorService programCreativeAutoExecutorService = Executors.newFixedThreadPool(5);
-    static ExecutorService programCreativeTopExecutorService = Executors.newFixedThreadPool(5);
-
     /**
      * 自定义上新创意
      */
@@ -38,11 +38,27 @@ public class KuaishouAiCreativeJob {
         if (null == strategies || strategies.isEmpty()) {
             return;
         }
-        strategies.forEach(strategy -> customCreativeAutoExecutorService.submit(() -> {
+        String url = "http://api.tjyourong.com.cn/jeecg-boot/ai/create/customCreativeLimit";
+        for (AiKuaishouAdvertiserStrategy strategy : strategies) {
             if (null != strategy.getOpenProgramCreate() && strategy.getOpenProgramCreate() != 1) {
-                createCreativeService.customCreativeLimit(strategy);
+                Map<String, Object> requestMap = new HashMap<>();
+                requestMap.put("id", strategy.getId());
+                String result = HttpUtils2.httpGet(url, requestMap, null);
+                JSONObject jsonObject = JSONObject.parseObject(result);
+                if (!Check.isNull(jsonObject)) {
+                    Integer code = jsonObject.getInteger("code");
+                    if (code == 0) {
+                        log.info("快手自动上新异步执行中,accountId:{}", strategy.getAccountId());
+                    } else {
+                        log.error("快手自动上新异执行失败,accountId:{}", strategy.getAccountId());
+                    }
+                } else {
+                    log.error("快手自动上新返回结果为空,accountId:{}", strategy.getAccountId());
+                }
             }
-        }));
+        }
+
+
     }
 
     /**
@@ -55,16 +71,27 @@ public class KuaishouAiCreativeJob {
             return;
         }
         try {
+            String url = "http://api.tjyourong.com.cn/jeecg-boot/ai/create/customCreativeSupplement";
             int hour = DateUtils.getNowHour();
-            strategies.forEach(strategy -> customCreativeSupplementExecutorService.submit(() -> {
-                if (null != strategy.getOpenProgramCreate() && strategy.getOpenProgramCreate() != 1) {
-                    try {
-                        createCreativeService.customCreativeSupplement(strategy, hour);
-                    } catch (ParseException e) {
-                        e.printStackTrace();
+            for (AiKuaishouAdvertiserStrategy strategy : strategies) {
+                Map<String, Object> requestMap = new HashMap<>();
+                requestMap.put("id", strategy.getId());
+                requestMap.put("hour", hour);
+                String result = HttpUtils2.httpGet(url, requestMap, null);
+                JSONObject jsonObject = JSONObject.parseObject(result);
+                if (!Check.isNull(jsonObject)) {
+                    Integer code = jsonObject.getInteger("code");
+                    if (code == 0) {
+                        log.info("快手创意补充异步执行中,accountId:{}", strategy.getAccountId());
+                    } else {
+                        log.error("快手创意补充异步执行失败,accountId:{}", strategy.getAccountId());
                     }
+                } else {
+                    log.error("快手创意补充返回结果为空,accountId:{}", strategy.getAccountId());
                 }
-            }));
+            }
+
+
         } catch (ParseException e) {
             e.printStackTrace();
         }
@@ -79,12 +106,31 @@ public class KuaishouAiCreativeJob {
         if (null == strategies || strategies.isEmpty()) {
             return;
         }
-        strategies.forEach(strategy -> programCreativeAutoExecutorService.submit(() -> {
+        String url = "http://api.tjyourong.com.cn/jeecg-boot/ai/create/kuaishouProgramCreativeAuto";
+        for (AiKuaishouAdvertiserStrategy strategy : strategies) {
             if (null != strategy.getOpenProgramCreate() && strategy.getOpenProgramCreate() != 0) {
                 long videoCnt = strategy.getProgramUnitCnt() * 5 / 2;
-                createCreativeService.autoCreateProgramCreative(strategy, 1, videoCnt);
+                Map<String, Object> requestMap = new HashMap<>();
+                requestMap.put("id", strategy.getId());
+                requestMap.put("videoCnt", videoCnt);
+                String result = HttpUtils2.httpGet(url, requestMap, null);
+                JSONObject jsonObject = JSONObject.parseObject(result);
+                if (!Check.isNull(jsonObject)) {
+                    Integer code = jsonObject.getInteger("code");
+                    if (code == 0) {
+                        log.info("快手上新程序化创意补充异步执行中,accountId:{}", strategy.getAccountId());
+                    } else {
+                        log.error("快手上新程序化异步执行失败,accountId:{}", strategy.getAccountId());
+                    }
+                } else {
+                    log.error("快手上新程序化充返回结果为空,accountId:{}", strategy.getAccountId());
+                }
+
+
             }
-        }));
+        }
+
+
     }
 
     /**
@@ -96,11 +142,27 @@ public class KuaishouAiCreativeJob {
         if (null == strategies || strategies.isEmpty()) {
             return;
         }
-        strategies.forEach(strategy -> programCreativeTopExecutorService.submit(() -> {
+        String url = "http://api.tjyourong.com.cn/jeecg-boot/ai/create/autoCreateProgramHistoryTopCreative";
+        for (AiKuaishouAdvertiserStrategy strategy : strategies) {
             if (null != strategy.getOpenProgramCreate() && strategy.getOpenProgramCreate() != 0) {
                 long videoCnt = strategy.getProgramUnitCnt() * 5 / 2;
-                createCreativeService.autoCreateProgramCreative(strategy, 2, videoCnt);
+                Map<String, Object> requestMap = new HashMap<>();
+                requestMap.put("id", strategy.getId());
+                requestMap.put("videoCnt", videoCnt);
+                String result = HttpUtils2.httpGet(url, requestMap, null);
+                JSONObject jsonObject = JSONObject.parseObject(result);
+                if (!Check.isNull(jsonObject)) {
+                    Integer code = jsonObject.getInteger("code");
+                    if (code == 0) {
+                        log.info("快手历史高质量程序化创意补充异步执行中,accountId:{}", strategy.getAccountId());
+                    } else {
+                        log.error("快手历史高质量程序化异步执行失败,accountId:{}", strategy.getAccountId());
+                    }
+                } else {
+                    log.error("快手历史高质量程序化充返回结果为空,accountId:{}", strategy.getAccountId());
+                }
             }
-        }));
+        }
+
     }
 }

+ 170 - 0
module-kuaishou/src/main/java/cn/com/ctop/kuaishou/modules/ai/controller/AiKuaishouCreateCreativeController.java

@@ -0,0 +1,170 @@
+package cn.com.ctop.kuaishou.modules.ai.controller;
+
+import cn.com.ctop.common.module.utils.Check;
+import cn.com.ctop.kuaishou.modules.ai.entity.AiKuaishouAdvertiserStrategy;
+import cn.com.ctop.kuaishou.modules.ai.service.IAiKuaishouAdvertiserStrategyService;
+import cn.com.ctop.kuaishou.modules.ai.service.IAiKuaishouCreateCreativeService;
+import com.alibaba.fastjson.JSONObject;
+import io.swagger.annotations.Api;
+import lombok.extern.slf4j.Slf4j;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.web.bind.annotation.GetMapping;
+import org.springframework.web.bind.annotation.RequestMapping;
+
+import java.text.ParseException;
+import java.util.concurrent.ExecutorService;
+import java.util.concurrent.Executors;
+
+@Slf4j
+@Api(tags = "快手-自动投放")
+@RequestMapping("/ai/create")
+public class AiKuaishouCreateCreativeController {
+    @Autowired
+    private IAiKuaishouCreateCreativeService createCreativeService;
+    @Autowired
+    private IAiKuaishouAdvertiserStrategyService strategyService;
+    static ExecutorService executorService = Executors.newFixedThreadPool(2);
+    static ExecutorService kuaishouCustomCreativeSupplementExecutorService = Executors.newFixedThreadPool(2);
+    static ExecutorService kuaishouProgramCreativeAutoService = Executors.newFixedThreadPool(2);
+    static ExecutorService kuaishouProgramTopCreativeAutoService = Executors.newFixedThreadPool(2);
+
+
+    /**
+     * 自动上新
+     *
+     * @param id
+     * @return
+     */
+    @GetMapping(value = "/customCreativeLimit")
+    public JSONObject customCreativeLimit(String id) {
+        JSONObject returnJson = new JSONObject();
+        try {
+            if (Check.isNull(id)) {
+                throw new Exception("主键id不能为空");
+            }
+            AiKuaishouAdvertiserStrategy strategy = strategyService.getById(id);
+            if (Check.isNull(strategy)) {
+                throw new Exception("根据id获取详细信息为空");
+            }
+            executorService.submit(() ->
+                    createCreativeService.customCreativeLimit(strategy)
+            );
+            returnJson.put("code", 0);
+            returnJson.put("message", "异步创建中");
+        } catch (Exception e) {
+            returnJson.put("code", -1);
+            returnJson.put("message", e.getMessage());
+        }
+        return returnJson;
+
+    }
+
+    /**
+     * 自定义创意补充
+     *
+     * @param id
+     * @param hour
+     * @return
+     */
+    @GetMapping(value = "/kuaishouCustomCreativeSupplement")
+    public JSONObject kuaishouCustomCreativeSupplement(String id, Integer hour) {
+        JSONObject returnJson = new JSONObject();
+        try {
+            if (Check.isNull(id)) {
+                throw new Exception("主键id不能为空");
+            }
+            AiKuaishouAdvertiserStrategy strategy = strategyService.getById(id);
+            if (Check.isNull(strategy)) {
+                throw new Exception("根据id获取详细信息为空");
+            }
+            if (Check.isNull(hour)) {
+                throw new Exception("小时数据为空");
+            }
+            kuaishouCustomCreativeSupplementExecutorService.submit(() -> {
+                try {
+                    createCreativeService.customCreativeSupplement(strategy, hour);
+                } catch (ParseException e) {
+                    e.printStackTrace();
+                }
+            });
+            returnJson.put("code", 0);
+            returnJson.put("message", "异步创建中");
+        } catch (Exception e) {
+            returnJson.put("code", -1);
+            returnJson.put("message", e.getMessage());
+        }
+        return returnJson;
+
+    }
+
+    /**
+     * 程序化上新素材
+     *
+     * @param id
+     * @param videoCnt
+     * @return
+     */
+    @GetMapping(value = "/kuaishouProgramCreativeAuto")
+    public JSONObject kuaishouCustomCreativeSupplement(String id, Long videoCnt) {
+        JSONObject returnJson = new JSONObject();
+        try {
+            if (Check.isNull(id)) {
+                throw new Exception("主键id不能为空");
+            }
+            AiKuaishouAdvertiserStrategy strategy = strategyService.getById(id);
+            if (Check.isNull(strategy)) {
+                throw new Exception("根据id获取详细信息为空");
+            }
+            if (Check.isNull(videoCnt)) {
+                throw new Exception("视频数量不能为空");
+            }
+            kuaishouProgramCreativeAutoService.submit(() -> {
+                createCreativeService.autoCreateProgramCreative(strategy, 1, videoCnt);
+
+            });
+            returnJson.put("code", 0);
+            returnJson.put("message", "异步创建中");
+        } catch (Exception e) {
+            returnJson.put("code", -1);
+            returnJson.put("message", e.getMessage());
+        }
+        return returnJson;
+
+    }
+
+    /**
+     * 程序化历史高质量
+     *
+     * @param id
+     * @param videoCnt
+     * @return
+     */
+    @GetMapping(value = "/autoCreateProgramHistoryTopCreative")
+    public JSONObject autoCreateProgramHistoryTopCreative(String id, Long videoCnt) {
+        JSONObject returnJson = new JSONObject();
+        try {
+            if (Check.isNull(id)) {
+                throw new Exception("主键id不能为空");
+            }
+            AiKuaishouAdvertiserStrategy strategy = strategyService.getById(id);
+            if (Check.isNull(strategy)) {
+                throw new Exception("根据id获取详细信息为空");
+            }
+            if (Check.isNull(videoCnt)) {
+                throw new Exception("视频数量不能为空");
+            }
+            kuaishouProgramTopCreativeAutoService.submit(() -> {
+                createCreativeService.autoCreateProgramCreative(strategy, 2, videoCnt);
+            });
+            returnJson.put("code", 0);
+            returnJson.put("message", "异步创建中");
+        } catch (Exception e) {
+            returnJson.put("code", -1);
+            returnJson.put("message", e.getMessage());
+        }
+        return returnJson;
+
+    }
+
+
+}

+ 3 - 2
module-kuaishou/src/main/java/cn/com/ctop/kuaishou/modules/ai/service/impl/AiKuaishouCreateCreativeServiceImpl.java

@@ -89,7 +89,7 @@ public class AiKuaishouCreateCreativeServiceImpl implements IAiKuaishouCreateCre
         if (null != singleAppid && singleAppid == 0) {
             //多应用
             String appidString = strategy.getAppIdArray();
-            JSONArray appIdArray = JSON.parseArray(appidString);
+            JSONArray appIdArray = JSONArray.parseArray(appidString);
             if (null != appIdArray && !appIdArray.isEmpty()) {
                 for (int i = 0; i < appIdArray.size(); i++) {
                     String replaceString = KuaishouCreativeMatTypeEnum.getNameByType(strategy.getUnitType().toString() + createType.toString());
@@ -185,7 +185,7 @@ public class AiKuaishouCreateCreativeServiceImpl implements IAiKuaishouCreateCre
                 unitCnt++;
                 String timestamp = DateUtils.formatDate(new Date(), "yyyyMMddHHmmss");
                 String unitName = getName(strategy.getGroupName(), strategy, createType, null, timestamp, unitCnt);
-                Long appId = JSON.parseArray(strategy.getAppIdArray()).getLong(0);
+                Long appId = JSONArray.parseArray(strategy.getAppIdArray()).getLong(0);
                 JSONObject unitParams = createUnitParams(token, newCampaignId, strategy, unitName, appId);
                 Map<String, Object> unitCreateResult = kuaishouInterfaceService.adUnitCreate(token.getAccessToken(), token.getAccountId(), unitParams, 1);
                 Integer unitCode = (Integer) unitCreateResult.get("code");
@@ -217,6 +217,7 @@ public class AiKuaishouCreateCreativeServiceImpl implements IAiKuaishouCreateCre
         return videoCnt;
     }
 
+
     /**
      * 创建程序化创意
      *