浏览代码

Merge branch 'master' of http://git.tjyourong.com.cn/ctop/adsp-cloud

yumeng 3 年之前
父节点
当前提交
6acd0e37b0

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

@@ -140,7 +140,7 @@ public class AiKuaishouCreateCreativeController {
                 throw new Exception("视频数量不能为空");
             }
             kuaishouProgramCreativeAutoService.submit(() -> {
-                createCreativeService.autoCreateProgramCreative(strategy, 1, videoCnt);
+                createCreativeService.ProgramCreative(strategy, 1, videoCnt);
 
             });
             returnJson.put("code", 0);
@@ -181,7 +181,7 @@ public class AiKuaishouCreateCreativeController {
             }
             if (strategy.getHistoryTop() == 0) {
                 kuaishouProgramTopCreativeAutoService.submit(() -> {
-                    createCreativeService.autoCreateProgramCreative(strategy, 2, videoCnt);
+                    createCreativeService.ProgramCreative(strategy, 2, videoCnt);
                 });
             } else {
                 log.info("历史高质量暂停搭建,accountId:{}", strategy.getAccountId());

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

@@ -13,6 +13,7 @@ public interface IAiKuaishouCreateCreativeService {
 
     void customCreativeLimit(AiKuaishouAdvertiserStrategy strategy);
 
+    void ProgramCreative(AiKuaishouAdvertiserStrategy strategy, Integer createType, Long videoCnt);
     // 组创建是否超限
     Boolean getUnitOverrun(Long accountId);
 }

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

@@ -738,6 +738,7 @@ 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);
@@ -767,15 +768,20 @@ public class AiKuaishouCreateCreativeServiceImpl implements IAiKuaishouCreateCre
                 customUnitCnt = 2000L / imageCnt;
             }
         }
-
-        Long unitNum = customUnitCnt * hour / 20;
-        log.info("{}当前时间内需要创建组总数:{}", strategy.getAccountId(), unitNum);
+        String date = DateUtils.formatDate(new Date());
         //查询当前账户创建自定义类型组数量
-        int unitCreateCnt = groupService.queryToDayBuiltCount(strategy.getAccountId(), 4);
+        Integer unitCreateCnt = queryUnitCnt(strategy.getAccountId() + date + "_old_custom_cnt");
+        Long unitNum = 0L;
+        if (!Check.isNull(unitCreateCnt)) {
+            unitNum = customUnitCnt - unitCreateCnt;
+        }
+        unitNum = unitNum * hour / 20;
+        log.info("{}当前时间内需要创建组总数:{}", strategy.getAccountId(), unitNum);
+
+//        int unitCreateCnt = groupService.queryToDayBuiltCount(strategy.getAccountId(), 4);
         log.info("{}截止目前创建组总数:{}", strategy.getAccountId(), unitCreateCnt);
-        long remindCnt = unitNum - unitCreateCnt;
-        if (remindCnt >= 1) {
-            log.info("{}组创建不足,剩余需要创建个数{},使用历史遗漏素材创建", strategy.getAccountId(), remindCnt);
+        if (unitNum >= 1) {
+            log.info("{}组创建不足,剩余需要创建个数{},使用历史遗漏素材创建", strategy.getAccountId(), unitNum);
             //优先创建历史遗漏素材
 
             Long timeStart = KuaishouCreativeMatTypeEnum.getStartTimeByType(strategy.getUnitType().toString() + 3);
@@ -783,27 +789,50 @@ public class AiKuaishouCreateCreativeServiceImpl implements IAiKuaishouCreateCre
             Long now = System.currentTimeMillis();
             String startTime = DateUtils.formatDateTime(now + timeStart * 60 * 1000L);
             String endTime = DateUtils.formatDateTime(now + timeEnd * 60 * 1000L);
-            remindCnt = this.autoCreateCreative(strategy, 3, remindCnt, startTime, endTime);
+            unitNum = this.autoCreateCreative(strategy, 3, unitNum, startTime, endTime);
         }
-        if (remindCnt >= 1) {
-            log.info("{}组创建不足,剩余需要创建个数{},使用高质量素材创建", strategy.getAccountId(), remindCnt);
+        if (unitNum >= 1) {
+            log.info("{}组创建不足,剩余需要创建个数{},使用高质量素材创建", strategy.getAccountId(), 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);
-            remindCnt = this.autoCreateCreative(strategy, 2, remindCnt, startTime, endTime);
+            unitNum = this.autoCreateCreative(strategy, 2, unitNum, startTime, endTime);
         }
-        if (remindCnt >= 1) {
+        if (unitNum >= 1) {
             //历史打捞素材
-            log.info("{}组创建不足,剩余需要创建个数{},使用历史打捞素材创建", strategy.getAccountId(), remindCnt);
+            log.info("{}组创建不足,剩余需要创建个数{},使用历史打捞素材创建", strategy.getAccountId(), 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, remindCnt, startTime, endTime);
+            this.autoCreateCreative(strategy, 4, unitNum, startTime, endTime);
+        }
+    }
+
+    /**
+     * 自定义key格式:【accountId + date+"_old_custom_cnt"】
+     * 程序化key格式:【accountId + date+"_old_program_cnt"】
+     * 查询当日创建广告组数量
+     */
+    private Integer queryUnitCnt(String key) {
+        return (Integer) redisUtil.get(key);
+    }
+
+    /**
+     * 自定义key格式:【accountId + date+"_old_custom_cnt"】
+     * 程序化key格式:【accountId + date+"_old_program_cnt"】
+     * 缓存当日创建广告组数量
+     */
+    private void createUnitCnt(String key) {
+        Integer unitCnt = (Integer) redisUtil.get(key);
+        if (Check.isNull(unitCnt)) {
+            redisUtil.set(key, 1, 100000L);
+        } else {
+            redisUtil.set(key, unitCnt + 1, 100000L);
         }
     }
 
@@ -811,6 +840,7 @@ public class AiKuaishouCreateCreativeServiceImpl implements IAiKuaishouCreateCre
 
     @Override
     public void customCreativeLimit(AiKuaishouAdvertiserStrategy strategy) {
+        String date = DateUtils.formatDate(new Date());
         Long unitNum = strategy.getCustomUnitCnt();
         if (Check.isNull(unitNum)) {
             Integer imageCnt = strategy.getImageCnt();
@@ -822,10 +852,15 @@ public class AiKuaishouCreateCreativeServiceImpl implements IAiKuaishouCreateCre
         }
         log.info("{}当天可创建组总数:{}", strategy.getAccountId(), unitNum);
         //查询当前账户创建自定义类型组数量
-        int unitCreateCnt = groupService.queryToDayBuiltCount(strategy.getAccountId(), 4);
+        Integer unitCreateCnt = queryUnitCnt(strategy.getAccountId() + date + "_old_custom_cnt");
+        if (!Check.isNull(unitCreateCnt)) {
+            unitNum = unitNum - unitCreateCnt;
+        }
+
+//        int unitCreateCnt = groupService.queryToDayBuiltCount(strategy.getAccountId(), 4);
         log.info("{}截止目前创建组总数:{}", strategy.getAccountId(), unitCreateCnt);
         long remindCnt = unitNum - unitCreateCnt;
-        if (remindCnt >= 1) {
+        if (unitNum >= 1) {
             log.info("{}组创建不足,剩余需要创建个数{},开始上新素材创建", strategy.getAccountId(), remindCnt);
             Long timeStart = KuaishouCreativeMatTypeEnum.getStartTimeByType(strategy.getUnitType().toString() + 1);
             Long timeEnd = KuaishouCreativeMatTypeEnum.getEndTimeByType(strategy.getUnitType().toString() + 1);
@@ -835,13 +870,32 @@ public class AiKuaishouCreateCreativeServiceImpl implements IAiKuaishouCreateCre
             executorService.submit(() ->
                     autoCreateCreative(strategy, 1, remindCnt, startTime, endTime)
             );
-
         }
     }
 
     @Autowired
     private IKuaiShouUpdateService updateService;
 
+
+    @Override
+    public void ProgramCreative(AiKuaishouAdvertiserStrategy strategy, Integer createType, Long videoCnt) {
+        Long programUnitCnt = strategy.getProgramUnitCnt();
+        if (Check.isNull(programUnitCnt)) {
+            return;
+        }
+        String date = DateUtils.formatDate(new Date());
+        //查询当前账户创建自定义类型组数量
+        Integer unitCreateCnt = queryUnitCnt(strategy.getAccountId() + date + "_old_program_cnt");
+        Long unitNum = 0L;
+        if (!Check.isNull(unitCreateCnt)) {
+            unitNum = programUnitCnt - unitCreateCnt;
+        }
+        log.info("{}截止目前创建程序化组总数:{}", strategy.getAccountId(), unitCreateCnt);
+        if (unitNum >= 1) {
+            this.autoCreateProgramCreative(strategy, createType, videoCnt);
+        }
+    }
+
     private void createProgramCreative(CtopOauthToken token, JSONObject creativeParams, AiKuaishouAdvertiserStrategy strategy) {
         Map<String, String> headers = new HashMap<>();
         headers.put("Content-Type", "application/json");