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

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

@@ -68,6 +68,7 @@ public class AiKuaishouCreateCreativeServiceImpl implements IAiKuaishouCreateCre
      */
      */
     @Override
     @Override
     public Long autoCreateCreative(AiKuaishouAdvertiserStrategy strategy, Integer createType, Long videoCnt) {
     public Long autoCreateCreative(AiKuaishouAdvertiserStrategy strategy, Integer createType, Long videoCnt) {
+        String strategyUuid = UUID.randomUUID().toString();
         strategy.setUnitType(4);
         strategy.setUnitType(4);
         Long accountId = strategy.getAccountId();
         Long accountId = strategy.getAccountId();
         CtopOauthToken token = tokenService.getOauthTokenByAccountId(accountId.toString());
         CtopOauthToken token = tokenService.getOauthTokenByAccountId(accountId.toString());
@@ -108,7 +109,7 @@ public class AiKuaishouCreateCreativeServiceImpl implements IAiKuaishouCreateCre
                         log.info("账户:{},{} 到 {} 未获取到相应素材({})", accountId, startTime, endTime,replaceString);
                         log.info("账户:{},{} 到 {} 未获取到相应素材({})", accountId, startTime, endTime,replaceString);
                         continue;
                         continue;
                     }
                     }
-                    Long newCampaignId = getCampaignId(strategy, token, replaceString, "ALL_CAMPAIGN",createType,appInfo);
+                    Long newCampaignId = getCampaignId(strategy, token, replaceString, "ALL_CAMPAIGN",createType,appInfo,strategyUuid);
                     int unitCnt = 0;
                     int unitCnt = 0;
                     for (KuaiShouVideoGet videoItem : allVideos) {
                     for (KuaiShouVideoGet videoItem : allVideos) {
                         KuaishouAccountCreativeOverrunInfo overrunInfo = overrunInfoService.getByParams(accountId, DateUtils.formatDate(new Date()));
                         KuaishouAccountCreativeOverrunInfo overrunInfo = overrunInfoService.getByParams(accountId, DateUtils.formatDate(new Date()));
@@ -136,6 +137,7 @@ public class AiKuaishouCreateCreativeServiceImpl implements IAiKuaishouCreateCre
                         unitLevelOperationRecord.setCreateTime(new Date());
                         unitLevelOperationRecord.setCreateTime(new Date());
                         unitLevelOperationRecord.setStatus(unitCode);
                         unitLevelOperationRecord.setStatus(unitCode);
                         unitLevelOperationRecord.setMessage(unitMessage);
                         unitLevelOperationRecord.setMessage(unitMessage);
+                        unitLevelOperationRecord.setAiStrategyUuid(strategyUuid);
                         if (unitCode != 0) {
                         if (unitCode != 0) {
                             log.info("组创建失败=>accountId:{};message:{}", accountId, unitMessage);
                             log.info("组创建失败=>accountId:{};message:{}", accountId, unitMessage);
                             unitLevelOperationRecordService.saveOrUpdate(unitLevelOperationRecord);
                             unitLevelOperationRecordService.saveOrUpdate(unitLevelOperationRecord);
@@ -146,7 +148,7 @@ public class AiKuaishouCreateCreativeServiceImpl implements IAiKuaishouCreateCre
                         unitLevelOperationRecordService.saveOrUpdate(unitLevelOperationRecord);
                         unitLevelOperationRecordService.saveOrUpdate(unitLevelOperationRecord);
                         videoCnt --;
                         videoCnt --;
                         JSONObject creativeParams = creativeParams(token, unitId, videoItem, strategy);
                         JSONObject creativeParams = creativeParams(token, unitId, videoItem, strategy);
-                        createCreativeByImage(cutFrameList, token, creativeParams, newCampaignId, unitId, videoItem, strategy.getImageCnt(),strategy);
+                        createCreativeByImage(cutFrameList, token, creativeParams, newCampaignId, unitId, videoItem, strategy.getImageCnt(),strategy,strategyUuid);
                         if(videoCnt<=0){
                         if(videoCnt<=0){
                             return videoCnt;
                             return videoCnt;
                         }
                         }
@@ -161,7 +163,7 @@ public class AiKuaishouCreateCreativeServiceImpl implements IAiKuaishouCreateCre
                 log.info("账户:{},{} 到 {} 未获取到相应素材({})", accountId, startTime, endTime,replaceString);
                 log.info("账户:{},{} 到 {} 未获取到相应素材({})", accountId, startTime, endTime,replaceString);
                 return videoCnt;
                 return videoCnt;
             }
             }
-            Long newCampaignId = getCampaignId(strategy, token, replaceString, "TODAY",createType,null);
+            Long newCampaignId = getCampaignId(strategy, token, replaceString, "TODAY",createType,null,strategyUuid);
             if (null == newCampaignId) {
             if (null == newCampaignId) {
                 return videoCnt;
                 return videoCnt;
             }
             }
@@ -193,6 +195,7 @@ public class AiKuaishouCreateCreativeServiceImpl implements IAiKuaishouCreateCre
                 unitLevelOperationRecord.setCreateTime(new Date());
                 unitLevelOperationRecord.setCreateTime(new Date());
                 unitLevelOperationRecord.setStatus(unitCode);
                 unitLevelOperationRecord.setStatus(unitCode);
                 unitLevelOperationRecord.setMessage(unitMessage);
                 unitLevelOperationRecord.setMessage(unitMessage);
+                unitLevelOperationRecord.setAiStrategyUuid(strategyUuid);
                 if (unitCode != 0) {
                 if (unitCode != 0) {
                     log.info("组创建失败=>accountId:{};message:{}", accountId, unitMessage);
                     log.info("组创建失败=>accountId:{};message:{}", accountId, unitMessage);
                     unitLevelOperationRecordService.saveOrUpdate(unitLevelOperationRecord);
                     unitLevelOperationRecordService.saveOrUpdate(unitLevelOperationRecord);
@@ -203,7 +206,7 @@ public class AiKuaishouCreateCreativeServiceImpl implements IAiKuaishouCreateCre
                 unitLevelOperationRecordService.saveOrUpdate(unitLevelOperationRecord);
                 unitLevelOperationRecordService.saveOrUpdate(unitLevelOperationRecord);
                 videoCnt -- ;
                 videoCnt -- ;
                 JSONObject creativeParams = creativeParams(token, unitId, videoItem, strategy);
                 JSONObject creativeParams = creativeParams(token, unitId, videoItem, strategy);
-                createCreativeByImage(cutFrameList, token, creativeParams, newCampaignId, unitId, videoItem, strategy.getImageCnt(),strategy);
+                createCreativeByImage(cutFrameList, token, creativeParams, newCampaignId, unitId, videoItem, strategy.getImageCnt(),strategy,strategyUuid);
                 if(videoCnt<=0){
                 if(videoCnt<=0){
                     return 0L;
                     return 0L;
                 }
                 }
@@ -219,6 +222,7 @@ public class AiKuaishouCreateCreativeServiceImpl implements IAiKuaishouCreateCre
      */
      */
     @Override
     @Override
     public void autoCreateProgramCreative(AiKuaishouAdvertiserStrategy strategy, Integer createType, Long videoCnt) {
     public void autoCreateProgramCreative(AiKuaishouAdvertiserStrategy strategy, Integer createType, Long videoCnt) {
+        String strategyUuid = UUID.randomUUID().toString();
         strategy.setUnitType(7);
         strategy.setUnitType(7);
         Long accountId = strategy.getAccountId();
         Long accountId = strategy.getAccountId();
         CtopOauthToken token = tokenService.getOauthTokenByAccountId(accountId.toString());
         CtopOauthToken token = tokenService.getOauthTokenByAccountId(accountId.toString());
@@ -265,7 +269,7 @@ public class AiKuaishouCreateCreativeServiceImpl implements IAiKuaishouCreateCre
                         log.info("该账户创意创建已超限=>accountId:{}", accountId);
                         log.info("该账户创意创建已超限=>accountId:{}", accountId);
                         return;
                         return;
                     }
                     }
-                    Long newCampaignId = getCampaignId(strategy, token, replaceString, "ALL_CAMPAIGN",createType,appInfo);
+                    Long newCampaignId = getCampaignId(strategy, token, replaceString, "ALL_CAMPAIGN",createType,appInfo,strategyUuid);
 
 
                     //创建组+创意
                     //创建组+创意
                     List<List<KuaiShouVideoGet>> splitVideos = Lists.partition(allVideos,5);
                     List<List<KuaiShouVideoGet>> splitVideos = Lists.partition(allVideos,5);
@@ -283,6 +287,7 @@ public class AiKuaishouCreateCreativeServiceImpl implements IAiKuaishouCreateCre
                         unitLevelOperationRecord.setCreateTime(new Date());
                         unitLevelOperationRecord.setCreateTime(new Date());
                         unitLevelOperationRecord.setStatus(unitCode);
                         unitLevelOperationRecord.setStatus(unitCode);
                         unitLevelOperationRecord.setMessage(unitMessage);
                         unitLevelOperationRecord.setMessage(unitMessage);
+                        unitLevelOperationRecord.setAiStrategyUuid(strategyUuid);
                         if (unitCode != 0) {
                         if (unitCode != 0) {
                             log.info("组创建失败=>accountId:{};message:{}", accountId, unitMessage);
                             log.info("组创建失败=>accountId:{};message:{}", accountId, unitMessage);
                             unitLevelOperationRecordService.saveOrUpdate(unitLevelOperationRecord);
                             unitLevelOperationRecordService.saveOrUpdate(unitLevelOperationRecord);
@@ -304,7 +309,7 @@ public class AiKuaishouCreateCreativeServiceImpl implements IAiKuaishouCreateCre
                 return;
                 return;
             }
             }
 
 
-            Long newCampaignId = getCampaignId(strategy, token, replaceString, "TODAY",createType,null);
+            Long newCampaignId = getCampaignId(strategy, token, replaceString, "TODAY",createType,null,strategyUuid);
             if (null == newCampaignId) {
             if (null == newCampaignId) {
                 return;
                 return;
             }
             }
@@ -330,6 +335,7 @@ public class AiKuaishouCreateCreativeServiceImpl implements IAiKuaishouCreateCre
                 unitLevelOperationRecord.setCreateTime(new Date());
                 unitLevelOperationRecord.setCreateTime(new Date());
                 unitLevelOperationRecord.setStatus(unitCode);
                 unitLevelOperationRecord.setStatus(unitCode);
                 unitLevelOperationRecord.setMessage(unitMessage);
                 unitLevelOperationRecord.setMessage(unitMessage);
+                unitLevelOperationRecord.setAiStrategyUuid(strategyUuid);
                 if (unitCode != 0) {
                 if (unitCode != 0) {
                     log.info("组创建失败=>accountId:{};message:{}", accountId, unitMessage);
                     log.info("组创建失败=>accountId:{};message:{}", accountId, unitMessage);
                     unitLevelOperationRecordService.saveOrUpdate(unitLevelOperationRecord);
                     unitLevelOperationRecordService.saveOrUpdate(unitLevelOperationRecord);
@@ -529,7 +535,7 @@ public class AiKuaishouCreateCreativeServiceImpl implements IAiKuaishouCreateCre
         }
         }
     }
     }
 
 
-    private Long getCampaignId(AiKuaishouAdvertiserStrategy strategy, CtopOauthToken token, String replaceString, String checkType,Integer createType,AiKuaiShouAppInfo appInfo) {
+    private Long getCampaignId(AiKuaishouAdvertiserStrategy strategy, CtopOauthToken token, String replaceString, String checkType,Integer createType,AiKuaiShouAppInfo appInfo,String uuid) {
         JSONArray campaignList;
         JSONArray campaignList;
         if ("ALL_CAMPAIGN".equals(checkType)) {
         if ("ALL_CAMPAIGN".equals(checkType)) {
             campaignList = kuaishouInterfaceService.getCampaignList(token, null, null, 1);
             campaignList = kuaishouInterfaceService.getCampaignList(token, null, null, 1);
@@ -558,6 +564,7 @@ public class AiKuaishouCreateCreativeServiceImpl implements IAiKuaishouCreateCre
         Integer code = (Integer) campaignCreateResult.get("code");
         Integer code = (Integer) campaignCreateResult.get("code");
         String message = (String) campaignCreateResult.get("message");
         String message = (String) campaignCreateResult.get("message");
         AiKuaishouCampaignLevelOperationRecord record = new AiKuaishouCampaignLevelOperationRecord(strategy,null,code,message);
         AiKuaishouCampaignLevelOperationRecord record = new AiKuaishouCampaignLevelOperationRecord(strategy,null,code,message);
+        record.setCampaignUuid(uuid);
         record.setCampaignName(campaignName);
         record.setCampaignName(campaignName);
         if (code != 0) {
         if (code != 0) {
             log.info("计划创建失败=>message:{}", message);
             log.info("计划创建失败=>message:{}", message);
@@ -949,14 +956,14 @@ public class AiKuaishouCreateCreativeServiceImpl implements IAiKuaishouCreateCre
 
 
     private void createCreativeByImage(List<MaterialCutFrame> cutFrameList, CtopOauthToken token, JSONObject creativeParams,
     private void createCreativeByImage(List<MaterialCutFrame> cutFrameList, CtopOauthToken token, JSONObject creativeParams,
                                        Long campaignId, Long unitId, KuaiShouVideoGet videoItem,
                                        Long campaignId, Long unitId, KuaiShouVideoGet videoItem,
-                                       int imageNumber,AiKuaishouAdvertiserStrategy strategy) {
+                                       int imageNumber,AiKuaishouAdvertiserStrategy strategy,String uuid) {
         if ((null != cutFrameList && !cutFrameList.isEmpty())) {
         if ((null != cutFrameList && !cutFrameList.isEmpty())) {
             for (int i = 0; i < cutFrameList.size(); i++) {
             for (int i = 0; i < cutFrameList.size(); i++) {
                 String imageCode = cutFrameList.get(i).getSignature();
                 String imageCode = cutFrameList.get(i).getSignature();
                 String imageUrl = cutFrameList.get(i).getUrl();
                 String imageUrl = cutFrameList.get(i).getUrl();
                 String imageToken = getImageToken(imageUrl, imageCode, token.getAccountId(), token.getAccessToken());
                 String imageToken = getImageToken(imageUrl, imageCode, token.getAccountId(), token.getAccessToken());
                 creativeParams.put("image_token", imageToken);
                 creativeParams.put("image_token", imageToken);
-                createCreative(token, creativeParams, campaignId, unitId, i+1, videoItem,strategy);
+                createCreative(token, creativeParams, campaignId, unitId, i+1, videoItem,strategy,uuid);
                 imageNumber --;
                 imageNumber --;
                 if (imageNumber<=0) {
                 if (imageNumber<=0) {
                     break;
                     break;
@@ -1030,7 +1037,7 @@ public class AiKuaishouCreateCreativeServiceImpl implements IAiKuaishouCreateCre
 
 
 
 
     private void createCreative(CtopOauthToken token, JSONObject creativeParams, Long campaignId, Long unitId,
     private void createCreative(CtopOauthToken token, JSONObject creativeParams, Long campaignId, Long unitId,
-                                int creativeCnt, KuaiShouVideoGet videoGet,AiKuaishouAdvertiserStrategy strategy) {
+                                int creativeCnt, KuaiShouVideoGet videoGet,AiKuaishouAdvertiserStrategy strategy,String uuid) {
         String creativeName = "自定义创意_"+creativeCnt;
         String creativeName = "自定义创意_"+creativeCnt;
         creativeParams.put("creative_name", creativeName);
         creativeParams.put("creative_name", creativeName);
         Map<String, Object> creativeCreateResult = kuaishouInterfaceService.creativeCreate(token.getAccessToken(), token.getAccountId(), creativeParams, 1);
         Map<String, Object> creativeCreateResult = kuaishouInterfaceService.creativeCreate(token.getAccessToken(), token.getAccountId(), creativeParams, 1);
@@ -1041,6 +1048,7 @@ public class AiKuaishouCreateCreativeServiceImpl implements IAiKuaishouCreateCre
         record.setCreativeName(creativeName);
         record.setCreativeName(creativeName);
         record.setStatus(creativeCode);
         record.setStatus(creativeCode);
         record.setMessage(creativeMessage);
         record.setMessage(creativeMessage);
+        record.setAiStrategyUuid(uuid);
         record.setCreateTime(new Date());
         record.setCreateTime(new Date());
         if (creativeCode != 0) {
         if (creativeCode != 0) {
             creativeLevelOperationRecordService.saveOrUpdate(record);
             creativeLevelOperationRecordService.saveOrUpdate(record);