Explorar el Código

自动投放—— 文案修改

zhaoxian hace 3 años
padre
commit
50b75a9a2e

+ 2 - 1
jeecg-boot-module-system/src/main/java/cn/com/ctop/kuaishou/modules/ai/entity/AiKuaishouCreativeLevelOperationRecord.java

@@ -162,12 +162,13 @@ public class AiKuaishouCreativeLevelOperationRecord {
 
     }
 
-    public AiKuaishouCreativeLevelOperationRecord(AiKuaishouAccountAutoStrategy strategy, Integer creativeCode, JSONObject creativeParams, String creativeMessage, Long unitId, String uuid) {
+    public AiKuaishouCreativeLevelOperationRecord(AiKuaishouAccountAutoStrategy strategy, Integer creativeCode, JSONObject creativeParams, String creativeMessage,Long newCampaignId, Long unitId, String uuid) {
         BeanUtils.copyProperties(strategy, this);
         this.status = creativeCode;
         this.description = creativeParams.getString("description");
         this.photoId = creativeParams.getString("photo_id");
         this.message = creativeMessage;
+        this.campaignId = newCampaignId;
         this.unitId = unitId;
         this.aiStrategyUuid = uuid;
         this.createTime = new Date();

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

@@ -382,7 +382,7 @@ public class AiKuaishouAccountAutoDoServiceImpl implements IAiKuaishouAccountAut
                     //获取创意参数
                     JSONObject creativeParams = getCreativeParams(token, unitId, videoItem, strategy, usedchannel, null);
                     //执行创建创意
-                    boolean flag = createCreative(token, creativeParams, strategy, unitId, strategyUuid);
+                    boolean flag = createCreative(token, creativeParams, strategy, newCampaignId, unitId, strategyUuid);
                     if (flag) {
                         //创意成功,则素材置为不可用,添加素材使用记录
                         updateVideoUsed(videoType, null, "custom", videoItem);
@@ -541,7 +541,7 @@ public class AiKuaishouAccountAutoDoServiceImpl implements IAiKuaishouAccountAut
                 //获取创意参数
                 JSONObject creativeParams = getCreativeParams(token, unitId, videoItem, strategy, null, videoItem.getAppVersion());
                 //执行创建创意
-                createCreative(token, creativeParams, strategy, unitId, strategyUuid);
+                createCreative(token, creativeParams, strategy, campaignId, unitId, strategyUuid);
                 if (videoCnt <= 0) {
                     removeRedisVideos(successVideoList, videoKey);
                     return 0;
@@ -1074,7 +1074,7 @@ public class AiKuaishouAccountAutoDoServiceImpl implements IAiKuaishouAccountAut
             //获取创意参数
             JSONObject creativeParams = getCreativeParams(token, unitId, videoItem, strategy, channel, null);
             //执行创建创意
-            boolean flag = createCreative(token, creativeParams, strategy, unitId, strategyUuid);
+            boolean flag = createCreative(token, creativeParams, strategy, newCampaignId, unitId, strategyUuid);
             if (flag) {
                 //创意成功,则素材置为不可用,添加素材使用记录
                 updateVideoUsed(videoType, null, "custom", videoItem);
@@ -1615,7 +1615,7 @@ public class AiKuaishouAccountAutoDoServiceImpl implements IAiKuaishouAccountAut
 
             //行动号召按钮
             if (!Check.isNull(strategy.getActionBarText())) {
-                programJson.put("action_bar", strategy.getActionBarText());
+                programJson.put("action_bar", getActionBar(strategy.getActionBarText()));
             }
 
             //第三方点击检测链接
@@ -1806,7 +1806,7 @@ public class AiKuaishouAccountAutoDoServiceImpl implements IAiKuaishouAccountAut
             //判断是否扔可创建计划
             if (planCnt > datas.size()) {
                 return createCampaign(strategy, token, videoType, uuid, channel);
-            }else{
+            } else {
                 log.info("当日创建量已达标");
             }
         } else {
@@ -2324,7 +2324,7 @@ public class AiKuaishouAccountAutoDoServiceImpl implements IAiKuaishouAccountAut
                 //素材类型 1:竖版视频 2:横版视频
                 creative.put("creative_material_type", videoItem.getMaterialType());
                 //行动号召按钮文案
-                creative.put("action_bar_text", strategy.getActionBarText());
+                creative.put("action_bar_text", getActionBar(strategy.getActionBarText()));
                 //广告语
                 int index = new Random().nextInt(descList.size());
                 creative.put("description", descList.getString(index));
@@ -2372,7 +2372,7 @@ public class AiKuaishouAccountAutoDoServiceImpl implements IAiKuaishouAccountAut
     /**
      * 执行创建自定义创意
      */
-    private boolean createCreative(CtopOauthToken token, JSONObject creativeParams, AiKuaishouAccountAutoStrategy strategy, Long unitId, String uuid) {
+    private boolean createCreative(CtopOauthToken token, JSONObject creativeParams, AiKuaishouAccountAutoStrategy strategy, Long newCampaignId, Long unitId, String uuid) {
         try {
             Map<String, Object> creativeCreateResult = kuaishouInterfaceService.batchCreativeCreate(token.getAccessToken(), token.getAccountId(), creativeParams, 1, null);
             Integer creativeCode = (Integer) creativeCreateResult.get("code");
@@ -2385,7 +2385,7 @@ public class AiKuaishouAccountAutoDoServiceImpl implements IAiKuaishouAccountAut
             } else if (creativeCode == -1 && creativeMessage.contains("视频不存在")) {
                 updateService.updateUnitStatus(token.getAccessToken(), token.getAccountId(), unitId, 3, "e9ca23d68d884d4ebb19d07889727dae");
             }
-            AiKuaishouCreativeLevelOperationRecord record = new AiKuaishouCreativeLevelOperationRecord(strategy, creativeCode, creativeParams, creativeMessage, unitId, uuid);
+            AiKuaishouCreativeLevelOperationRecord record = new AiKuaishouCreativeLevelOperationRecord(strategy, creativeCode, creativeParams, creativeMessage, newCampaignId, unitId, uuid);
             if (creativeCode == 0) {
                 JSONArray addCreativeIds = (JSONArray) creativeCreateResult.get("ids");
                 for (int i = 0; i < addCreativeIds.size(); i++) {
@@ -2733,4 +2733,18 @@ public class AiKuaishouAccountAutoDoServiceImpl implements IAiKuaishouAccountAut
         }
         return upNewCnt;
     }
+
+    public static String getActionBar(String actionBarText) {
+        if (Check.isNull(actionBarText)) {
+            return null;
+        }
+        String[] split = actionBarText.split(",");
+        int i = getrandom(0, split.length - 1);
+        return split[i];
+    }
+
+    public static int getrandom(int start, int end) {
+        int num = (int) (Math.random() * (end - start + 1) + start);
+        return num;
+    }
 }