Browse Source

Merge remote-tracking branch 'origin/test' into test

songyh 4 years ago
parent
commit
358a6aa44c

+ 59 - 37
jeecg-boot-bytedance/src/main/java/org/jeecg/modules/bytedance/advertise/service/impl/AiBytedanceAdvertiserStrategyServiceImpl.java

@@ -145,22 +145,32 @@ public class AiBytedanceAdvertiserStrategyServiceImpl extends ServiceImpl<AiByte
                 if(null == adId){
                     continue;
                 }
-                adDplinkInfo.setAdId(adId);
-                adDplinkInfo.setAccountId(strategy.getAccountId());
-                adDplinkInfo.setStatus(1);
-                adDplinkInfo.setStrategyId(strategy.getId());
-                adDplinkInfoService.save(adDplinkInfo);
+
                 //3:创建创意
                 JSONObject creativeParams = getCreativeParams(strategy,adId,video,token);
                 log.info("账户id:{};创意创建参数:{}",strategy.getAccountId(),creativeParams);
                 JSONObject creativeObject =  marketingService.creativeCreate(token,adId,creativeParams);
                 if(null!=creativeObject.getInteger("code")&&creativeObject.getInteger("code")!=0){
+                    List<Long> adIds = new ArrayList<>();
+                    adIds.add(adId);
+                    Result resultDeletePlan = marketingService.updPlanStatus(token,adIds,"delete");
+                    if (!resultDeletePlan.isSuccess()){
+                        log.info("广告计划删除失败:message==>{}",resultDeletePlan.getMessage());
+                    }
+
                     String message = creativeObject.getString("message");
                     Integer code = creativeObject.getInteger("code");
                     //创建创意失败
                     log.info("账户id:{};创意创建失败:code==>{};message==>{}",strategy.getAccountId(),code,message);
                     continue;
                 }
+
+                adDplinkInfo.setAdId(adId);
+                adDplinkInfo.setAccountId(strategy.getAccountId());
+                adDplinkInfo.setStatus(1);
+                adDplinkInfo.setStrategyId(strategy.getId());
+                adDplinkInfoService.save(adDplinkInfo);
+
                 BytedanceAiVideoCreativeLog creativeLog = new BytedanceAiVideoCreativeLog(strategy,adId,campaignId,video);
                 videoCreativeLogService.saveOrUpdate(creativeLog);
                 videoCnt --;
@@ -207,23 +217,30 @@ public class AiBytedanceAdvertiserStrategyServiceImpl extends ServiceImpl<AiByte
                 if(null == adId){
                     continue;
                 }
-                adDplinkInfo.setAdId(adId);
-                adDplinkInfo.setAccountId(strategy.getAccountId());
-                adDplinkInfo.setStatus(1);
-                adDplinkInfo.setStrategyId(strategy.getId());
-                adDplinkInfoService.save(adDplinkInfo);
                 //3:创建创意
                 JSONObject creativeParams = getCreativeParams(strategy,adId,video,token);
                 log.info("创意创建参数:{}",creativeParams);
                 JSONObject creativeObject =  marketingService.creativeCreate(token,adId,creativeParams);
                 log.info("创意创建返回数据:{}",creativeObject);
                 if(null!=creativeObject.getInteger("code")&&creativeObject.getInteger("code")!=0){
+                    List<Long> adIds = new ArrayList<>();
+                    adIds.add(adId);
+                    Result resultDeletePlan = marketingService.updPlanStatus(token,adIds,"delete");
+                    if (!resultDeletePlan.isSuccess()){
+                        log.info("广告计划删除失败:message==>{}",resultDeletePlan.getMessage());
+                    }
                     String message = creativeObject.getString("message");
                     Integer code = creativeObject.getInteger("code");
                     //创建创意失败
                     log.info("账户id:{};创意创建失败:code==>{};message==>{}",strategy.getAccountId(),code,message);
                     continue;
                 }
+
+                adDplinkInfo.setAdId(adId);
+                adDplinkInfo.setAccountId(strategy.getAccountId());
+                adDplinkInfo.setStatus(1);
+                adDplinkInfo.setStrategyId(strategy.getId());
+                adDplinkInfoService.save(adDplinkInfo);
                 BytedanceAiVideoCreativeLog creativeLog = new BytedanceAiVideoCreativeLog(strategy,adId,campaignId,video);
                 videoCreativeLogService.saveOrUpdate(creativeLog);
                 videoCnt --;
@@ -732,6 +749,7 @@ public class AiBytedanceAdvertiserStrategyServiceImpl extends ServiceImpl<AiByte
                 params.put("exclude_flow_package",excludeFlowPackage);
             }
         }
+
         if(!Check.isNull(strategy.getAdPlatform())){
             String[] platform = strategy.getAdPlatform().split(",");
             if(platform.length>0){
@@ -997,7 +1015,7 @@ public class AiBytedanceAdvertiserStrategyServiceImpl extends ServiceImpl<AiByte
         if(result.contains("{{序号}}")){
             //查询当天已有计划数量
             int i = adDplinkInfoService.getDpLinkInfoCount(strategy.getAccountId());
-            Long num = GetCampaignNum.getCampaignNameNum(strategy.getCampaignCnt(),strategy.getCampaignAdCnt(),i);
+            Long num = GetCampaignNum.getCampaignNameNum(strategy.getCampaignCnt(),strategy.getCampaignAdCnt(), i == 0 ? i+1 : i);
             result = result.replace("{{序号}}",String.valueOf(num));
         }
 
@@ -1412,32 +1430,36 @@ public class AiBytedanceAdvertiserStrategyServiceImpl extends ServiceImpl<AiByte
     private IByteDanceAdvertisePlanService planService;
     @Override
     public void customCreativeSupplement(AiBytedanceAdvertiserStrategy strategy, Integer hour,String openUrl) {
-        Long customUnitCnt = strategy.getCampaignAdCnt()*strategy.getCampaignCnt();
-        Long unitNum = customUnitCnt * hour / 19;
-        log.info("{}当前时间内需要创建计划总数:{}", strategy.getAccountId(), unitNum);
-        //查询当前账户创建自定义类型计划数量
-        int unitCreateCnt = planService.queryToDayBuiltCount(strategy.getAccountId());
-        log.info("{}截止目前创建组总数:{}", strategy.getAccountId(), unitCreateCnt);
-        long remindCnt = unitNum - unitCreateCnt;
-        if (remindCnt >= 1) {
-            log.info("{}计划创建不足,剩余需要创建个数{},使用上新素材创建", strategy.getAccountId(), remindCnt);
-            //优先创建历史遗漏素材
-            remindCnt = this.createCreative(strategy, 1, remindCnt,openUrl);
-        }
-        if (remindCnt >= 1) {
-            log.info("{}计划创建不足,剩余需要创建个数{},使用历史遗漏素材创建", strategy.getAccountId(), remindCnt);
-            //优先创建历史遗漏素材
-            remindCnt = this.createCreative(strategy, 3, remindCnt,openUrl);
-        }
-        if (remindCnt >= 1) {
-            log.info("{}计划创建不足,剩余需要创建个数{},使用高质量素材创建", strategy.getAccountId(), remindCnt);
-            //高质量素材
-            remindCnt = this.createCreative(strategy, 2, remindCnt,openUrl);
-        }
-        if (remindCnt >= 1) {
-            //历史打捞素材
-            log.info("{}计划创建不足,剩余需要创建个数{},使用历史打捞素材创建", strategy.getAccountId(), remindCnt);
-            this.createCreative(strategy, 4, remindCnt,openUrl);
+        try{
+            Long customUnitCnt = strategy.getCampaignAdCnt()*strategy.getCampaignCnt();
+            Long unitNum = customUnitCnt * hour / 19;
+            log.info("{}当前时间内需要创建计划总数:{}", strategy.getAccountId(), unitNum);
+            //查询当前账户创建自定义类型计划数量
+            int unitCreateCnt = planService.queryToDayBuiltCount(strategy.getAccountId());
+            log.info("{}截止目前创建组总数:{}", strategy.getAccountId(), unitCreateCnt);
+            long remindCnt = unitNum - unitCreateCnt;
+            if (remindCnt >= 1) {
+                log.info("{}计划创建不足,剩余需要创建个数{},使用上新素材创建", strategy.getAccountId(), remindCnt);
+                //优先创建历史遗漏素材
+                remindCnt = this.createCreative(strategy, 1, remindCnt,openUrl);
+            }
+            if (remindCnt >= 1) {
+                log.info("{}计划创建不足,剩余需要创建个数{},使用历史遗漏素材创建", strategy.getAccountId(), remindCnt);
+                //优先创建历史遗漏素材
+                remindCnt = this.createCreative(strategy, 3, remindCnt,openUrl);
+            }
+            if (remindCnt >= 1) {
+                log.info("{}计划创建不足,剩余需要创建个数{},使用高质量素材创建", strategy.getAccountId(), remindCnt);
+                //高质量素材
+                remindCnt = this.createCreative(strategy, 2, remindCnt,openUrl);
+            }
+            if (remindCnt >= 1) {
+                //历史打捞素材
+                log.info("{}计划创建不足,剩余需要创建个数{},使用历史打捞素材创建", strategy.getAccountId(), remindCnt);
+                this.createCreative(strategy, 4, remindCnt,openUrl);
+            }
+        }catch (Exception e){
+            log.info(e.getMessage());
         }
     }