Explorar el Código

项目自动投放策略,广告组序号优化

zhaoxian hace 3 años
padre
commit
3beba3f10b

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

@@ -350,6 +350,9 @@ public class AiKuaishouProjectCreateCreativeServiceImpl implements IAiKuaishouPr
                         unitLevelOperationRecord.setCreateType(2);//项目创建
                         Integer unitCode = -1;
                         String msg = unitParams.getString("errorMsg");
+                        String nowDate = DateUtils.formatDate(new Date(), "yy-MMdd");
+                        String redisKey = strategy.getAccountId() + "_" + newCampaignId + nowDate;
+                        Integer redisValue = (Integer) redisUtil.get(redisKey);
                         if (Check.isNull(msg)) {
                             Map<String, Object> unitCreateResult = kuaishouInterfaceService.adUnitCreate(token.getAccessToken(), token.getAccountId(), unitParams, 1);
                             unitCode = (Integer) unitCreateResult.get("code");
@@ -363,15 +366,16 @@ public class AiKuaishouProjectCreateCreativeServiceImpl implements IAiKuaishouPr
                                 videoCnt--;
                                 JSONObject creativeParams = creativeParams(token, unitId, videoItem, strategy);
                                 createCreativeByImage(cutFrameList, token, creativeParams, newCampaignId, unitId, videoItem, strategy.getImageCnt(), strategy, strategyUuid, null);
-
                             }
                             if (unitCode != 0) {
                                 unitLevelOperationRecordService.saveOrUpdate(unitLevelOperationRecord);
+                                redisUtil.set(redisKey, redisValue - 1, 100000L);
                             }
                         } else {
                             unitLevelOperationRecord.setStatus(unitCode);
                             unitLevelOperationRecord.setMessage(msg);
                             unitLevelOperationRecordService.saveOrUpdate(unitLevelOperationRecord);
+                            redisUtil.set(redisKey, redisValue - 1, 100000L);
                         }
                         if (videoCnt <= 0) {
                             return videoCnt;
@@ -379,10 +383,12 @@ public class AiKuaishouProjectCreateCreativeServiceImpl implements IAiKuaishouPr
                     }
                 }
             }
-        } catch (BeansException e) {
+        } catch (
+                BeansException e) {
             log.error("创建自定义创意异常", e);
             insertAccountOperationRecord(strategy, "创建自定义创意异常", operationType, 0);
         }
+
         insertAccountOperationRecord(strategy, "success", operationType, 1);
         return videoCnt;
     }
@@ -491,6 +497,8 @@ public class AiKuaishouProjectCreateCreativeServiceImpl implements IAiKuaishouPr
                         unitLevelOperationRecord.setCreateType(2);//项目创建
                         Integer unitCode = -1;
                         String errorMsg = unitParams.getString("errorMsg");
+                        String redisKey = strategy.getAccountId() + "_" + newCampaignId + DateUtils.formatDate(new Date(), "yy-MMdd");
+                        Integer redisValue = (Integer) redisUtil.get(redisKey);
                         if (Check.isNull(errorMsg)) {
                             log.info("创建广告组入参:{}", unitParams);
                             Map<String, Object> unitCreateResult = kuaishouInterfaceService.adUnitCreate(token.getAccessToken(), token.getAccountId(), unitParams, 1);
@@ -508,11 +516,13 @@ public class AiKuaishouProjectCreateCreativeServiceImpl implements IAiKuaishouPr
                             if (unitCode != 0) {
                                 log.error("组创建失败=>accountId:{};message:{}", accountId, errorMsg);
                                 unitLevelOperationRecordService.saveOrUpdate(unitLevelOperationRecord);
+                                redisUtil.set(redisKey, redisValue - 1, 100000L);
                             }
                         } else {
                             unitLevelOperationRecord.setStatus(unitCode);
                             unitLevelOperationRecord.setMessage(errorMsg);
                             unitLevelOperationRecordService.saveOrUpdate(unitLevelOperationRecord);
+                            redisUtil.set(redisKey, redisValue - 1, 100000L);
                         }
                     }
                 }
@@ -1469,6 +1479,7 @@ public class AiKuaishouProjectCreateCreativeServiceImpl implements IAiKuaishouPr
                 } else {
                     count = (Integer) redisValue + 1;
                     redisUtil.set(redisKey, count, 100000L);
+
                 }
             }
             wildcard = wildcard + "-" + count;