浏览代码

自动投放修改——添加程序化创意创建记录

zhaoxian 3 年之前
父节点
当前提交
da473fcbf3

+ 25 - 0
jeecg-boot-module-system/src/main/java/cn/com/ctop/kuaishou/modules/ai/entity/AiKuaishouProgramCreativeLevelOperationRecord.java

@@ -1,5 +1,6 @@
 package cn.com.ctop.kuaishou.modules.ai.entity;
 
+import com.alibaba.fastjson.JSONObject;
 import com.baomidou.mybatisplus.annotation.IdType;
 import com.baomidou.mybatisplus.annotation.TableId;
 import com.baomidou.mybatisplus.annotation.TableName;
@@ -123,4 +124,28 @@ public class AiKuaishouProgramCreativeLevelOperationRecord {
      * 1:账户自动投放 2:项目自动投放
      */
     private Integer createType;
+
+    public AiKuaishouProgramCreativeLevelOperationRecord(){}
+
+    public AiKuaishouProgramCreativeLevelOperationRecord( JSONObject creativeParams ,Long campaignId, Long unitId, String uuid, String message) {
+        this.aiStrategyUuid = uuid;
+        this.accountId = creativeParams.getLong("advertiser_id");
+        this.campaignId = campaignId;
+        this.unitId = unitId;
+        this.packageName = creativeParams.getString("package_name");
+        this.horizontalPhotoIds = creativeParams.getString("hids");
+        this.verticalPhotoIds = creativeParams.getString("vids");
+        this.siteId = creativeParams.getInteger("site_id");
+        this.stickerStyles = creativeParams.getString("sticker_styles");
+        this.actionBar = creativeParams.getString("action_bar");
+        this.captions = creativeParams.getString("captions");
+        this.clickUrl = creativeParams.getString("click_url");
+        this.actionbarClickUrl = creativeParams.getString("actionbar_click_url");
+        this.creativeCategory = creativeParams.getInteger("creative_category");
+        this.creativeTag = creativeParams.getString("creative_tag");
+        this.createType = 3;
+        this.operationType = 1;
+        this.message = message;
+        this.createTime = new Date();
+    }
 }

+ 31 - 11
jeecg-boot-module-system/src/main/java/cn/com/ctop/kuaishou/modules/ai/service/impl/AiKuaishouAccountAutoDoServiceImpl.java

@@ -13,6 +13,7 @@ import cn.com.ctop.kuaishou.modules.ai.entity.AiKuaishouAccountAutoTarget;
 import cn.com.ctop.kuaishou.modules.ai.entity.AiKuaishouAccountAutoVideo;
 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.AiKuaishouProgramCreativeLevelOperationRecord;
 import cn.com.ctop.kuaishou.modules.ai.entity.AiKuaishouUnitLevelOperationRecord;
 import cn.com.ctop.kuaishou.modules.ai.entity.KuaishouAccountCreativeOverrunInfo;
 import cn.com.ctop.kuaishou.modules.ai.enums.KuaishouAutoTypeEnum;
@@ -23,6 +24,7 @@ import cn.com.ctop.kuaishou.modules.ai.service.IAiKuaishouAccountAutoTargetServi
 import cn.com.ctop.kuaishou.modules.ai.service.IAiKuaishouAccountAutoVideoService;
 import cn.com.ctop.kuaishou.modules.ai.service.IAiKuaishouCampaignLevelOperationRecordService;
 import cn.com.ctop.kuaishou.modules.ai.service.IAiKuaishouCreativeLevelOperationRecordService;
+import cn.com.ctop.kuaishou.modules.ai.service.IAiKuaishouProgramCreativeLevelOperationRecordService;
 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;
@@ -92,6 +94,10 @@ public class AiKuaishouAccountAutoDoServiceImpl implements IAiKuaishouAccountAut
     private IKuaishouAccountCreativeOverrunInfoService overrunInfoService;
     @Autowired
     private IAiKuaishouCampaignLevelOperationRecordService aiKuaishouCampaignLevelOperationRecordService;
+
+    @Autowired
+    private IAiKuaishouProgramCreativeLevelOperationRecordService kuaishouProgramCreativeLevelOperationRecordService;
+
     @Autowired
     private IAiKuaiShouAppInfoService appInfoService;
     @Autowired
@@ -772,9 +778,9 @@ public class AiKuaishouAccountAutoDoServiceImpl implements IAiKuaishouAccountAut
                         continue;
                     }
                     JSONObject unitParams = (JSONObject) result.getResult();
-                    log.info("--------------执行创建程序化广告组,参数:{}", unitParams);
+//                    log.info("--------------执行创建程序化广告组,参数:{}", unitParams);
                     Map<String, Object> unitCreateResult = kuaishouInterfaceService.adUnitCreate(token.getAccessToken(), token.getAccountId(), unitParams, 1);
-                    log.info("--------------创建程序化广告组结果,返回数据:{}", unitCreateResult.toString());
+//                    log.info("--------------创建程序化广告组结果,返回数据:{}", unitCreateResult.toString());
                     unitCode = (Integer) unitCreateResult.get("code");
                     unitMessage = (String) unitCreateResult.get("message");
 
@@ -802,7 +808,7 @@ public class AiKuaishouAccountAutoDoServiceImpl implements IAiKuaishouAccountAut
                     //获取创意参数
                     JSONObject creativeParams = getProgramCreativeParams(token, unitId, videos, strategy, videoCnt, null, usedchannel);
                     //执行创建创意
-                    boolean flag = createProgramCreatives(token, creativeParams, strategy, 1);
+                    boolean flag = createProgramCreatives(token, creativeParams, strategy, newCampaignId, uuid, 1);
                     if (flag) {
                         //创意成功,则素材置为不可用,添加素材使用记录
                         updateVideoUsed(videoType, videos, "program", null);
@@ -967,7 +973,7 @@ public class AiKuaishouAccountAutoDoServiceImpl implements IAiKuaishouAccountAut
                 //获取创意参数
                 JSONObject creativeParams = getProgramCreativeParams(token, unitId, videos, strategy, videoCnt, videos.get(0).getAppVersion(), null);
                 //执行创建创意
-                createProgramCreatives(token, creativeParams, strategy, 1);
+//                createProgramCreatives(token, creativeParams, strategy, 1);
                 if (videoCnt <= 0) {
                     removeProRedisVideos(successVideoList, videoKey);
                     return 0;
@@ -1216,7 +1222,7 @@ public class AiKuaishouAccountAutoDoServiceImpl implements IAiKuaishouAccountAut
             //获取创意参数
             JSONObject creativeParams = getProgramCreativeParams(token, unitId, videos, strategy, videoCnt, null, channel);
             //执行创建创意
-            boolean flag = createProgramCreatives(token, creativeParams, strategy, 1);
+            boolean flag = createProgramCreatives(token, creativeParams, strategy, newCampaignId, uuid, 1);
             if (flag) {
                 successVideoList.add(videos);
                 //创意成功,则素材置为不可用,添加素材使用记录
@@ -1595,15 +1601,25 @@ public class AiKuaishouAccountAutoDoServiceImpl implements IAiKuaishouAccountAut
 
             //素材列表
             JSONArray photoList = new JSONArray();
+            List<String> vids = new ArrayList<>();//竖版视频ID
+            List<String> hids = new ArrayList<>();//横版视频ID
             for (AiKuaishouAccountAutoVideo video : videos) {
+                Integer type = video.getMaterialType();
+                String photoId = video.getPhotoId();
                 JSONObject photo = new JSONObject();
-                photo.put("photo_id", video.getPhotoId());//视频 ID
+                photo.put("photo_id", photoId);//视频 ID
                 photo.put("cover_image_token", null);// 封面图片 token,通过上传图片接口获得,不传值则直接使用视频的首帧作为封面图片
-                photo.put("creative_material_type", video.getMaterialType());//1:竖版视频 2:横版视频
+                photo.put("creative_material_type", type);//1:竖版视频 2:横版视频
                 photoList.add(photo);
+                if(!Check.isNull(type)&&type==1){
+                    vids.add(photoId);
+                }else{
+                    hids.add(photoId);
+                }
             }
             programJson.put("photo_list", photoList);
-
+            programJson.put("vids",vids);
+            programJson.put("hids",hids);
             //落地页 ID
             if (!Check.isNull(strategy.getSiteId()) && !"-1".equals(strategy.getSiteId())) {
                 programJson.put("site_id", strategy.getSiteId());
@@ -1673,7 +1689,7 @@ public class AiKuaishouAccountAutoDoServiceImpl implements IAiKuaishouAccountAut
     /**
      * 执行创建程序化创意
      */
-    private boolean createProgramCreatives(CtopOauthToken token, JSONObject creativeParams, AiKuaishouAccountAutoStrategy strategy, int count) {
+    private boolean createProgramCreatives(CtopOauthToken token, JSONObject creativeParams, AiKuaishouAccountAutoStrategy strategy, Long campaignId, String uuid, int count) {
         try {
             Map<String, String> headers = new HashMap<>();
             headers.put("Content-Type", "application/json");
@@ -1689,21 +1705,25 @@ public class AiKuaishouAccountAutoDoServiceImpl implements IAiKuaishouAccountAut
             Integer code = resultJson.getInteger("code");
             String message = resultJson.getString("message");
             Long unitId = creativeParams.getLong("unit_id");
+            AiKuaishouProgramCreativeLevelOperationRecord record = new AiKuaishouProgramCreativeLevelOperationRecord(creativeParams, campaignId, unitId, uuid, message);
             if (code == 0) {
                 createLandPageAndUnit(creativeParams, resultJson.getJSONObject("data"));
+                record.setStatus(0);
+                kuaishouProgramCreativeLevelOperationRecordService.saveOrUpdate(record);
             } else {
                 log.error("快手创建程序化创意失败,accountId:{},unitId:{},返回信息:{},入参:{}", token.getAccountId(), unitId, message, creativeParams.toJSONString());
                 if ("系统错误".equals(message) && count <= 3) {
                     log.info("第{}次重新创建程序化创意", count);
                     //系统错误,则重新执行
-                    return createProgramCreatives(token, creativeParams, strategy, count + 1);
+                    return createProgramCreatives(token, creativeParams, strategy, campaignId, uuid, count + 1);
                 } else if (code == 400001 && "/rest/openapi/v2/creative/advanced/program/create调用已超日限,次日可恢复调用".equals(message)) {
                     String statDate = DateUtils.formatDate(new Date());
                     String programKey = token.getAccountId() + "_pcreativecount_" + statDate;
                     redisUtil.set(programKey, 1, 100000L);
                     updateService.updateUnitStatus(token.getAccessToken(), token.getAccountId(), unitId, 3, "e9ca23d68d884d4ebb19d07889727dae");
                 }
-
+                record.setStatus(-1);
+                kuaishouProgramCreativeLevelOperationRecordService.saveOrUpdate(record);
                 return false;
             }
         } catch (Exception e) {