Selaa lähdekoodia

自动投放添加试玩

zhaoxian 2 vuotta sitten
vanhempi
commit
66fb4b3a00

+ 5 - 0
jeecg-boot-module-system/src/main/java/cn/com/ctop/common/module/utils/KuaishouInterfaceConstant.java

@@ -372,4 +372,9 @@ public class KuaishouInterfaceConstant {
      */
     public static final String AD_UNIT_EXPLORE_SUPPORT = "/rest/openapi/v1/ad_unit/explore/support";
 
+     /**
+     * 获取试玩列表
+     */
+    public static final String PLAYABLE_LIST = "/rest/openapi/gw/dsp/v1/playable/list";
+
 }

+ 5 - 1
jeecg-boot-module-system/src/main/java/cn/com/ctop/kuaishou/modules/ai/controller/AiKuaishouAccountAutoStrategyController.java

@@ -120,7 +120,7 @@ public class AiKuaishouAccountAutoStrategyController {
             aiKuaishouAccountAutoStrategy.setUserIds(userIds);
         } else if (CtopRoleCodeConstant.COMMON_ROLE_CODE_ADMIN.equals(roleCode)) {
             aiKuaishouAccountAutoStrategy.setUserIds(null);
-        }else {
+        } else {
             userIds.add(userId);
             aiKuaishouAccountAutoStrategy.setUserIds(userIds);
         }
@@ -249,6 +249,10 @@ public class AiKuaishouAccountAutoStrategyController {
                     aiKuaishouAccountAutoStrategy.setAppId(appId);
                 }
             }
+            if (!Check.isNull(aiKuaishouAccountAutoStrategyEntity.getPlayableIds()) && !aiKuaishouAccountAutoStrategyEntity.getPlayableIds().equals(aiKuaishouAccountAutoStrategy.getPlayableIds())) {
+                redisUtil.removeAll(aiKuaishouAccountAutoStrategy.getId() + "-play-");
+            }
+
 
             boolean ok = aiKuaishouAccountAutoStrategyService.updateById(aiKuaishouAccountAutoStrategy);
             if (ok) {

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

@@ -483,6 +483,21 @@ public class AiKuaishouAccountAutoStrategy {
     @Excel(name = "本地定向集", width = 15)
     @ApiModelProperty(value = "本地定向集")
     private String autoTargetArray;
+
+    /**
+     * 试玩 ID集
+     */
+    @Excel(name = "试玩 ID集", width = 15)
+    @ApiModelProperty(value = "试玩 ID集")
+    private String playableIds;
+
+    /**
+     * 试玩按钮文字内容
+     */
+    @Excel(name = "1:立即试玩;2:试玩一下;3:立即体验;4:免装试玩;5:免装体验。启用试玩时:默认“立即试玩”", width = 15)
+    @ApiModelProperty(value = "1:立即试玩;2:试玩一下;3:立即体验;4:免装试玩;5:免装体验。启用试玩时:默认“立即试玩”")
+    private Integer playButton;
+
     /**
      * 素材来源 1-上新素材,2-高质量素材,3-遗漏素材,4-历史打捞
      */

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

@@ -370,6 +370,7 @@ public class AiKuaishouAccountAutoDoServiceImpl implements IAiKuaishouAccountAut
                     }
                     AiKuaishouUnitLevelOperationRecord unitRecord = new AiKuaishouUnitLevelOperationRecord(strategy, unitParams, unitCode, unitMessage, strategyUuid, videoItem.getAutoTargetId(), channelId);
                     if (unitCode != 0) {
+                        rollbackPlayId(unitParams, strategy);
                         log.error("****** 账户({})组创建失败,入参:{},message:{}", accountId, unitParams, unitMessage);
                         String redisKey = strategy.getAccountId() + "_" + newCampaignId + DateUtils.formatDate(new Date(), "yyMMdd");
                         Integer redisCnt = (Integer) redisUtil.get(redisKey);
@@ -1615,15 +1616,15 @@ public class AiKuaishouAccountAutoDoServiceImpl implements IAiKuaishouAccountAut
                 photo.put("cover_image_token", null);// 封面图片 token,通过上传图片接口获得,不传值则直接使用视频的首帧作为封面图片
                 photo.put("creative_material_type", type);//1:竖版视频 2:横版视频
                 photoList.add(photo);
-                if(!Check.isNull(type)&&type==1){
+                if (!Check.isNull(type) && type == 1) {
                     vids.add(photoId);
-                }else{
+                } else {
                     hids.add(photoId);
                 }
             }
             programJson.put("photo_list", photoList);
-            programJson.put("vids",vids);
-            programJson.put("hids",hids);
+            programJson.put("vids", vids);
+            programJson.put("hids", hids);
             //落地页 ID
             if (!Check.isNull(strategy.getSiteId()) && !"-1".equals(strategy.getSiteId())) {
                 programJson.put("site_id", strategy.getSiteId());
@@ -2049,7 +2050,11 @@ public class AiKuaishouAccountAutoDoServiceImpl implements IAiKuaishouAccountAut
             if (!Check.isNull(strategy.getIntentionTarget()) && strategy.getIntentionTarget() != 0) {
                 unitParams.put("intention_target", true);
             }
-
+            //试玩 ID
+            if (!Check.isNull(strategy.getPlayableIds())) {
+                unitParams.put("playable_id", getPlayId(strategy.getPlayableIds(), strategy.getId(), campaignId));
+                unitParams.put("play_button", strategy.getPlayButton());
+            }
             //是否开启自动生成视频
             if (!Check.isNull(strategy.getAutoCreatePhoto())) {
                 unitParams.put("auto_create_photo", strategy.getAutoCreatePhoto());
@@ -2778,4 +2783,86 @@ public class AiKuaishouAccountAutoDoServiceImpl implements IAiKuaishouAccountAut
         int num = (int) (Math.random() * (end - start + 1) + start);
         return num;
     }
+
+    /**
+     * 轮询使用 playableIds 值,playableIds string格式:123,456,789,122
+     */
+    public Long getPlayId(String playableIds, Long strategyId, Long campaignId) {
+        JSONObject obj = JSONObject.parseObject(playableIds);
+        String playIds = obj.getString("ids");
+        String playId = null;
+        Map<String, Object> map = new HashMap<>();
+        String redisKey = strategyId + "-play-" + campaignId + "-" + DateUtils.formatDate(new Date(), "yyMMdd");
+        Map<Object, Object> mget = redisUtil.hmget(redisKey);
+        if (Check.isNullMap(mget)) {
+            String[] ids = playIds.split(",");
+            playId = ids[0];
+            if (ids.length > 1) {
+                String newValues = playIds.replace(playId + ",", "");
+                map.put(String.valueOf(0), newValues);
+            }
+            map.put(String.valueOf(1), playId);
+            redisUtil.hmset(redisKey, map, 100000L);
+        } else {
+            for (Object key : mget.keySet()) {
+                String keyIndex = String.valueOf(key);
+                String values = String.valueOf(mget.get(keyIndex));
+                String[] ids = values.split(",");
+                playId = ids[0];
+                if (ids.length > 1) {
+                    String newValues = values.replace(playId + ",", "");
+                    map.put(keyIndex, newValues);
+                } else {
+                    redisUtil.hdel(redisKey, keyIndex);
+                }
+                int upIndex = Integer.valueOf(keyIndex) + 1;
+                String upValues = String.valueOf(mget.get(String.valueOf(upIndex)));
+                if ("null".equals(upValues)) {
+                    map.put(String.valueOf(upIndex), playId);
+                } else {
+                    map.put(String.valueOf(upIndex), upValues + "," + playId);
+                }
+                break;
+            }
+            redisUtil.hmset(redisKey, map, 100000L);
+        }
+        return Long.valueOf(playId);
+    }
+
+    /**
+     * 回滚 playableIds 值
+     */
+    public void rollbackPlayId(JSONObject unitParams, AiKuaishouAccountAutoStrategy strategy) {
+        Long playableId = unitParams.getLong("playable_id");
+        if (Check.isNull(playableId)) {
+            return;
+        }
+        Map<String, Object> map = new HashMap<>();
+        String redisKey = strategy.getId() + "-play-" + unitParams.getLong("campaign_id") + "-" + DateUtils.formatDate(new Date(), "yyMMdd");
+        Map<Object, Object> mget = redisUtil.hmget(redisKey);
+        if (!Check.isNullMap(mget)) {
+            for (Object key : mget.keySet()) {
+                String keyIndex = String.valueOf(key);
+                String values = String.valueOf(mget.get(keyIndex));
+                if (values.contains(playableId + "")) {
+                    break;
+                }
+                values = playableId + "," + values;
+                map.put(keyIndex, values);
+
+                String upIndex = Integer.valueOf(keyIndex) + 1 + "";
+                String upValues = String.valueOf(mget.get(upIndex));
+                if (!"null".equals(upValues)) {
+                    if (String.valueOf(playableId).equals(upValues)) {
+                        redisUtil.hdel(redisKey, upIndex);
+                    } else {
+                        String newValues = upValues.replace("," + playableId, "");
+                        map.put(upIndex, newValues);
+                    }
+                }
+                break;
+            }
+            redisUtil.hmset(redisKey, map, 100000L);
+        }
+    }
 }

+ 22 - 0
jeecg-boot-module-system/src/main/java/cn/com/ctop/kuaishou/modules/batch/controller/BatchController.java

@@ -2605,4 +2605,26 @@ public class BatchController {
     }
 
 
+    /**
+     * 获取试玩列表
+     *
+     * @param accountId
+     */
+    @GetMapping(value = "/getPlayableList")
+    public Result<Object> getPlayableList(Long accountId) {
+        try {
+            if (Check.isNull(accountId)) {
+                return Result.error("缺少参数!");
+            }
+            CtopOauthToken oauthToken = oauthTokenService.getTokenByAccountId(accountId);
+            if (Check.isNull(oauthToken)) {
+                return Result.error("缺少参数!");
+            }
+            return batchService.getPlayableList(accountId, oauthToken.getAccessToken());
+        } catch (Exception e) {
+            e.printStackTrace();
+        }
+        return Result.error("fail");
+    }
+
 }

+ 3 - 0
jeecg-boot-module-system/src/main/java/cn/com/ctop/kuaishou/modules/batch/service/IBatchService.java

@@ -6,6 +6,7 @@ import cn.com.ctop.kuaishou.modules.batch.entity.KuaiShouCreative;
 import cn.com.ctop.kuaishou.modules.batch.entity.KuaiShouGroup;
 import com.alibaba.fastjson.JSONArray;
 import com.alibaba.fastjson.JSONObject;
+import org.jeecg.common.api.vo.Result;
 
 import java.math.BigDecimal;
 import java.util.Map;
@@ -180,4 +181,6 @@ public interface IBatchService {
      * @return
      */
     JSONObject getCategoryWhite(Long accountId, String accessToken);
+
+    Result<Object> getPlayableList(Long accountId, String accessToken);
 }

+ 38 - 1
jeecg-boot-module-system/src/main/java/cn/com/ctop/kuaishou/modules/batch/service/impl/BatchServiceImpl.java

@@ -2,23 +2,30 @@ package cn.com.ctop.kuaishou.modules.batch.service.impl;
 
 import cn.com.ctop.common.module.entity.CtopOauthToken;
 import cn.com.ctop.common.module.entity.UserAllocation;
+import cn.com.ctop.common.module.enums.MaterialEnum;
 import cn.com.ctop.common.module.mapper.UserAllocationMapper;
 import cn.com.ctop.common.module.service.ICtopOauthTokenService;
+import cn.com.ctop.common.module.utils.BigDecimalUtil;
 import cn.com.ctop.common.module.utils.Check;
 import cn.com.ctop.common.module.utils.HttpUtils;
+import cn.com.ctop.common.module.utils.KuaishouInterfaceConstant;
+import cn.com.ctop.common.module.utils.PropertiesUtils;
 import cn.com.ctop.kuaishou.modules.batch.entity.*;
 import cn.com.ctop.kuaishou.modules.batch.mapper.*;
 import cn.com.ctop.kuaishou.modules.batch.service.*;
+import cn.com.ctop.kuaishou.modules.report.entity.KuaishouReportDailyExplore;
 import com.alibaba.fastjson.JSONArray;
 import com.alibaba.fastjson.JSONObject;
 import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
 import lombok.extern.slf4j.Slf4j;
+import org.jeecg.common.api.vo.Result;
 import org.jeecg.common.util.DateUtils;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.beans.factory.annotation.Value;
 import org.springframework.stereotype.Service;
 
 import java.math.BigDecimal;
+import java.util.ArrayList;
 import java.util.Date;
 import java.util.HashMap;
 import java.util.List;
@@ -65,7 +72,7 @@ public class BatchServiceImpl implements IBatchService {
     public BigDecimal getCost(Long accountId) {
         //BigDecimal dailyCost = batchMapper.getDailyCost(accountId);
         BigDecimal hourlyCost = batchMapper.getHourCost(accountId, DateUtils.formatDate(new Date()));
-    //    BigDecimal totalCost = dailyCost.add(hourlyCost);
+        //    BigDecimal totalCost = dailyCost.add(hourlyCost);
         return hourlyCost;
     }
 
@@ -2161,6 +2168,36 @@ public class BatchServiceImpl implements IBatchService {
         }
         return thirdArr;
     }
+
+
+    @Override
+    public Result<Object> getPlayableList(Long accountId, String accessToken) {
+        try {
+            String url = PropertiesUtils.getConfig("kuaishou_api_url") + KuaishouInterfaceConstant.PLAYABLE_LIST;
+            Map<String, String> header = new HashMap<>();
+            header.put("Access-Token", accessToken);
+            header.put("Content-Type", "application/json");
+            JSONObject params = new JSONObject();
+            params.put("advertiser_id", accountId);
+            params.put("page", 1);
+            params.put("page_size", 2000);
+            String result = HttpUtils.httpPostRequest(url, params, header);
+            JSONObject resultJson = JSONObject.parseObject(result);
+            System.out.println(resultJson.toJSONString());
+            if (!Check.isNull(resultJson)) {
+                Integer code = resultJson.getInteger("code");
+                if (code == 0) {
+                    return Result.ok(resultJson.getJSONObject("data"));
+                } else {
+                    log.info("查询获取试玩列表失败,accountId:{},返回信息:{}", accountId, resultJson);
+                    return Result.error("查询获取试玩列表失败," + resultJson.getString("message"));
+                }
+            }
+        } catch (Exception e) {
+            log.error("查询获取试玩列表失败", e);
+        }
+        return Result.error("查询获取试玩列表失败");
+    }
 }