zhaoxian 3 rokov pred
rodič
commit
1e76844138

+ 3 - 6
jeecg-boot-module-system/src/main/java/cn/com/ctop/kuaishou/modules/ai/controller/AiKuaishouCreateCreativeController.java

@@ -25,9 +25,9 @@ public class AiKuaishouCreateCreativeController {
     private IAiKuaishouCreateCreativeService createCreativeService;
     @Autowired
     private IAiKuaishouAdvertiserStrategyService strategyService;
-    static ExecutorService executorService = Executors.newFixedThreadPool(5);
+
     static ExecutorService kuaishouCustomCreativeSupplementExecutorService = Executors.newFixedThreadPool(3);
-    static ExecutorService kuaishouProgramCreativeAutoService = Executors.newFixedThreadPool(3);
+    static ExecutorService kuaishouProgramCreativeAutoService = Executors.newFixedThreadPool(2);
     static ExecutorService kuaishouProgramTopCreativeAutoService = Executors.newFixedThreadPool(3);
 
 
@@ -53,10 +53,7 @@ public class AiKuaishouCreateCreativeController {
                 log.error("组创建超限,accountId:{}", strategy.getAccountId());
                 throw new Exception("今日组创建已超限");
             }
-
-            executorService.submit(() ->
-                    createCreativeService.customCreativeLimit(strategy)
-            );
+            createCreativeService.customCreativeLimit(strategy);
             returnJson.put("code", 0);
             returnJson.put("message", "异步创建中");
         } catch (Exception e) {

+ 1 - 1
jeecg-boot-module-system/src/main/java/cn/com/ctop/kuaishou/modules/ai/service/IAiKuaishouCreateCreativeService.java

@@ -5,7 +5,7 @@ import cn.com.ctop.kuaishou.modules.ai.entity.AiKuaishouAdvertiserStrategy;
 import java.text.ParseException;
 
 public interface IAiKuaishouCreateCreativeService {
-    Long autoCreateCreative(AiKuaishouAdvertiserStrategy strategy, Integer createType, Long videoCnt);
+    Long autoCreateCreative(AiKuaishouAdvertiserStrategy strategy, Integer createType, Long videoCnt,String startTime,String endTime);
 
     void autoCreateProgramCreative(AiKuaishouAdvertiserStrategy strategy, Integer createType, Long videoCnt);
 

+ 41 - 49
jeecg-boot-module-system/src/main/java/cn/com/ctop/kuaishou/modules/ai/service/impl/AiKuaishouCreateCreativeServiceImpl.java

@@ -8,35 +8,14 @@ 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.ai.entity.AiKuaiShouAppInfo;
-import cn.com.ctop.kuaishou.modules.ai.entity.AiKuaishouAdvertiserStrategy;
-import cn.com.ctop.kuaishou.modules.ai.entity.AiKuaishouCampaignLevelOperationRecord;
-import cn.com.ctop.kuaishou.modules.ai.entity.AiKuaishouCreativeLevelOperationRecord;
-import cn.com.ctop.kuaishou.modules.ai.entity.AiKuaishouUnitLevelOperationRecord;
-import cn.com.ctop.kuaishou.modules.ai.entity.KuaiShouAppMultipleBids;
-import cn.com.ctop.kuaishou.modules.ai.entity.KuaishouAccountCreativeOverrunInfo;
+import cn.com.ctop.kuaishou.modules.ai.entity.*;
 import cn.com.ctop.kuaishou.modules.ai.enums.KuaishouCreativeAdsenceTypeEnum;
 import cn.com.ctop.kuaishou.modules.ai.enums.KuaishouCreativeMatTypeEnum;
-import cn.com.ctop.kuaishou.modules.ai.service.IAiKuaiShouAppInfoService;
-import cn.com.ctop.kuaishou.modules.ai.service.IAiKuaishouCampaignLevelOperationRecordService;
-import cn.com.ctop.kuaishou.modules.ai.service.IAiKuaishouCreateCreativeService;
-import cn.com.ctop.kuaishou.modules.ai.service.IAiKuaishouCreativeLevelOperationRecordService;
-import cn.com.ctop.kuaishou.modules.ai.service.IAiKuaishouUnitLevelOperationRecordService;
-import cn.com.ctop.kuaishou.modules.ai.service.IKuaiShouAppMultipleBidsService;
-import cn.com.ctop.kuaishou.modules.ai.service.IKuaishouAccountCreativeOverrunInfoService;
-import cn.com.ctop.kuaishou.modules.ai.service.IKuaishouLandpagePackageService;
+import cn.com.ctop.kuaishou.modules.ai.service.*;
 import cn.com.ctop.kuaishou.modules.batch.entity.KuaiShouAppList;
 import cn.com.ctop.kuaishou.modules.batch.entity.KuaiShouImageGet;
 import cn.com.ctop.kuaishou.modules.batch.entity.KuaiShouVideoGet;
-import cn.com.ctop.kuaishou.modules.batch.service.IKuaiShouAppListService;
-import cn.com.ctop.kuaishou.modules.batch.service.IKuaiShouCampaignService;
-import cn.com.ctop.kuaishou.modules.batch.service.IKuaiShouGroupService;
-import cn.com.ctop.kuaishou.modules.batch.service.IKuaiShouGroupTemplateService;
-import cn.com.ctop.kuaishou.modules.batch.service.IKuaiShouImageGetService;
-import cn.com.ctop.kuaishou.modules.batch.service.IKuaiShouMaterialUploadService;
-import cn.com.ctop.kuaishou.modules.batch.service.IKuaiShouUpdateService;
-import cn.com.ctop.kuaishou.modules.batch.service.IKuaiShouVideoGetService;
-import cn.com.ctop.kuaishou.modules.batch.service.IKuaishouInterfaceService;
+import cn.com.ctop.kuaishou.modules.batch.service.*;
 import cn.com.ctop.kuaishou.modules.channel.entity.KuaishouChannel;
 import cn.com.ctop.kuaishou.modules.channel.entity.KuaishouChannelItems;
 import cn.com.ctop.kuaishou.modules.channel.service.IKuaishouChannelService;
@@ -54,14 +33,9 @@ import org.springframework.stereotype.Service;
 
 import java.math.BigDecimal;
 import java.text.ParseException;
-import java.util.ArrayList;
-import java.util.Collections;
-import java.util.Date;
-import java.util.HashMap;
-import java.util.List;
-import java.util.Map;
-import java.util.Random;
-import java.util.UUID;
+import java.util.*;
+import java.util.concurrent.ExecutorService;
+import java.util.concurrent.Executors;
 
 @Slf4j
 @Service
@@ -108,7 +82,7 @@ public class AiKuaishouCreateCreativeServiceImpl implements IAiKuaishouCreateCre
      * @param videoCnt   视频数量
      */
     @Override
-    public Long autoCreateCreative(AiKuaishouAdvertiserStrategy strategy, Integer createType, Long videoCnt) {
+    public Long autoCreateCreative(AiKuaishouAdvertiserStrategy strategy, Integer createType, Long videoCnt, String startTime, String endTime) {
         String strategyUuid = UUID.randomUUID().toString();
         strategy.setUnitType(4);
         Long accountId = strategy.getAccountId();
@@ -119,11 +93,7 @@ public class AiKuaishouCreateCreativeServiceImpl implements IAiKuaishouCreateCre
         }
         //1:获取视频信息
         kuaishouInterfaceService.getVideoList(token, DateUtils.date2Str(), DateUtils.date2Str());
-        Long timeStart = KuaishouCreativeMatTypeEnum.getStartTimeByType(strategy.getUnitType().toString() + createType.toString());
-        Long timeEnd = KuaishouCreativeMatTypeEnum.getEndTimeByType(strategy.getUnitType().toString() + createType.toString());
-        Long now = System.currentTimeMillis();
-        String startTime = DateUtils.formatDateTime(now + timeStart * 60 * 1000L);
-        String endTime = DateUtils.formatDateTime(now + timeEnd * 60 * 1000L);
+
 
         //2:判定账户是否单一应用
         Integer singleAppid = strategy.getSingleAppid();
@@ -193,7 +163,6 @@ public class AiKuaishouCreateCreativeServiceImpl implements IAiKuaishouCreateCre
                                 unitLevelOperationRecordService.saveOrUpdate(unitLevelOperationRecord);
                                 continue;
                             }
-                            createUnitCnt(strategy.getAccountId() + DateUtils.date2Str() + "_old_custom_cnt");
                             Long unitId = (Long) unitCreateResult.get("unitId");
                             unitLevelOperationRecord.setUnitId(unitId);
                             unitLevelOperationRecordService.saveOrUpdate(unitLevelOperationRecord);
@@ -274,7 +243,6 @@ public class AiKuaishouCreateCreativeServiceImpl implements IAiKuaishouCreateCre
                             unitLevelOperationRecordService.saveOrUpdate(unitLevelOperationRecord);
                             continue;
                         }
-                        createUnitCnt(strategy.getAccountId() + DateUtils.date2Str() + "_old_custom_cnt");
                         Long unitId = (Long) unitCreateResult.get("unitId");
                         unitLevelOperationRecord.setUnitId(unitId);
                         unitLevelOperationRecordService.saveOrUpdate(unitLevelOperationRecord);
@@ -412,7 +380,6 @@ public class AiKuaishouCreateCreativeServiceImpl implements IAiKuaishouCreateCre
                         unitLevelOperationRecordService.saveOrUpdate(unitLevelOperationRecord);
                         continue;
                     }
-                    createUnitCnt(strategy.getAccountId() + DateUtils.date2Str() + "_old_custom_cnt");
                     Long unitId = (Long) unitCreateResult.get("unitId");
                     unitLevelOperationRecord.setUnitId(unitId);
                     unitLevelOperationRecordService.saveOrUpdate(unitLevelOperationRecord);
@@ -425,7 +392,7 @@ public class AiKuaishouCreateCreativeServiceImpl implements IAiKuaishouCreateCre
                     if (videoCnt <= 0) {
                         return 0L;
                     }
-
+                    Thread.sleep(500L);
                 }
             } catch (Exception e) {
                 e.printStackTrace();
@@ -550,7 +517,6 @@ public class AiKuaishouCreateCreativeServiceImpl implements IAiKuaishouCreateCre
                                 unitLevelOperationRecordService.saveOrUpdate(unitLevelOperationRecord);
                                 continue;
                             }
-                            createUnitCnt(strategy.getAccountId() + DateUtils.date2Str() + "_old_program_cnt");
                             Long unitId = (Long) unitCreateResult.get("unitId");
                             unitLevelOperationRecord.setUnitId(unitId);
                             unitLevelOperationRecordService.saveOrUpdate(unitLevelOperationRecord);
@@ -630,7 +596,6 @@ public class AiKuaishouCreateCreativeServiceImpl implements IAiKuaishouCreateCre
                                 unitLevelOperationRecordService.saveOrUpdate(unitLevelOperationRecord);
                                 continue;
                             }
-                            createUnitCnt(strategy.getAccountId() + DateUtils.date2Str() + "_old_program_cnt");
                             Long unitId = (Long) unitCreateResult.get("unitId");
                             unitLevelOperationRecord.setUnitId(unitId);
                             unitLevelOperationRecordService.saveOrUpdate(unitLevelOperationRecord);
@@ -781,6 +746,7 @@ public class AiKuaishouCreateCreativeServiceImpl implements IAiKuaishouCreateCre
                     }
                     JSONObject creativeParams = programCreativeParams(token, unitId, splitVideos.get(j - 1), strategy, j, null, usedchannel);
                     createProgramCreative(token, creativeParams, strategy);
+                    Thread.sleep(500L);
                 }
             } catch (Exception e) {
                 e.printStackTrace();
@@ -816,17 +782,33 @@ public class AiKuaishouCreateCreativeServiceImpl implements IAiKuaishouCreateCre
         if (unitNum >= 1) {
             log.info("{}组创建不足,剩余需要创建个数{},使用历史遗漏素材创建", strategy.getAccountId(), unitNum);
             //优先创建历史遗漏素材
-            unitNum = this.autoCreateCreative(strategy, 3, unitNum);
+
+            Long timeStart = KuaishouCreativeMatTypeEnum.getStartTimeByType(strategy.getUnitType().toString() + 3);
+            Long timeEnd = KuaishouCreativeMatTypeEnum.getEndTimeByType(strategy.getUnitType().toString() + 3);
+            Long now = System.currentTimeMillis();
+            String startTime = DateUtils.formatDateTime(now + timeStart * 60 * 1000L);
+            String endTime = DateUtils.formatDateTime(now + timeEnd * 60 * 1000L);
+            unitNum = this.autoCreateCreative(strategy, 3, unitNum, startTime, endTime);
         }
         if (unitNum >= 1) {
             log.info("{}组创建不足,剩余需要创建个数{},使用高质量素材创建", strategy.getAccountId(), unitNum);
             //高质量素材
-            unitNum = this.autoCreateCreative(strategy, 2, unitNum);
+            Long timeStart = KuaishouCreativeMatTypeEnum.getStartTimeByType(strategy.getUnitType().toString() + 2);
+            Long timeEnd = KuaishouCreativeMatTypeEnum.getEndTimeByType(strategy.getUnitType().toString() + 2);
+            Long now = System.currentTimeMillis();
+            String startTime = DateUtils.formatDateTime(now + timeStart * 60 * 1000L);
+            String endTime = DateUtils.formatDateTime(now + timeEnd * 60 * 1000L);
+            unitNum = this.autoCreateCreative(strategy, 2, unitNum, startTime, endTime);
         }
         if (unitNum >= 1) {
             //历史打捞素材
             log.info("{}组创建不足,剩余需要创建个数{},使用历史打捞素材创建", strategy.getAccountId(), unitNum);
-            this.autoCreateCreative(strategy, 4, unitNum);
+            Long timeStart = KuaishouCreativeMatTypeEnum.getStartTimeByType(strategy.getUnitType().toString() + 4);
+            Long timeEnd = KuaishouCreativeMatTypeEnum.getEndTimeByType(strategy.getUnitType().toString() + 4);
+            Long now = System.currentTimeMillis();
+            String startTime = DateUtils.formatDateTime(now + timeStart * 60 * 1000L);
+            String endTime = DateUtils.formatDateTime(now + timeEnd * 60 * 1000L);
+            this.autoCreateCreative(strategy, 4, unitNum, startTime, endTime);
         }
     }
 
@@ -853,6 +835,8 @@ public class AiKuaishouCreateCreativeServiceImpl implements IAiKuaishouCreateCre
         }
     }
 
+    static ExecutorService executorService = Executors.newFixedThreadPool(3);
+
     @Override
     public void customCreativeLimit(AiKuaishouAdvertiserStrategy strategy) {
         String date = DateUtils.formatDate(new Date());
@@ -874,9 +858,17 @@ public class AiKuaishouCreateCreativeServiceImpl implements IAiKuaishouCreateCre
 
 //        int unitCreateCnt = groupService.queryToDayBuiltCount(strategy.getAccountId(), 4);
         log.info("{}截止目前创建组总数:{}", strategy.getAccountId(), unitCreateCnt);
+        long remindCnt = unitNum - unitCreateCnt;
         if (unitNum >= 1) {
-            log.info("{}组创建不足,剩余需要创建个数{},开始上新素材创建", strategy.getAccountId(), unitNum);
-            this.autoCreateCreative(strategy, 1, unitNum);
+            log.info("{}组创建不足,剩余需要创建个数{},开始上新素材创建", strategy.getAccountId(), remindCnt);
+            Long timeStart = KuaishouCreativeMatTypeEnum.getStartTimeByType(strategy.getUnitType().toString() + 1);
+            Long timeEnd = KuaishouCreativeMatTypeEnum.getEndTimeByType(strategy.getUnitType().toString() + 1);
+            Long now = System.currentTimeMillis();
+            String startTime = DateUtils.formatDateTime(now + timeStart * 60 * 1000L);
+            String endTime = DateUtils.formatDateTime(now + timeEnd * 60 * 1000L);
+            executorService.submit(() ->
+                    autoCreateCreative(strategy, 1, remindCnt, startTime, endTime)
+            );
         }
     }
 

+ 2 - 2
jeecg-boot-module-system/src/main/java/cn/com/ctop/kuaishou/modules/batch/service/impl/KuaishouInterfaceServiceImpl.java

@@ -1005,7 +1005,7 @@ public class KuaishouInterfaceServiceImpl implements IKuaishouInterfaceService {
                         returnMap.put("unitId", unitId);
                         returnMap.put("success", true);
                         //添加广告组和定向模板、人群包绑定关系
-                        Thread thread2 = new Thread() {
+                  /*      Thread thread2 = new Thread() {
                             @Override
                             public void run() {
                                 try {
@@ -1032,7 +1032,7 @@ public class KuaishouInterfaceServiceImpl implements IKuaishouInterfaceService {
                                 }
                             }
                         };
-                        thread2.start();
+                        thread2.start();*/
                     }
 
                 } else {