Jelajahi Sumber

解决程序化创意空组问题

yumeng 4 tahun lalu
induk
melakukan
341a12af40

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

@@ -263,6 +263,9 @@ public class AiKuaishouCreateCreativeServiceImpl implements IAiKuaishouCreateCre
         String startTime = DateUtils.formatDateTime(now + timeStart * 60 * 1000L);
         String endTime = DateUtils.formatDateTime(now + timeEnd * 60 * 1000L);
 
+        String nowDate = DateUtils.getNowDate("yyyy-MM-dd");
+        String key = token.getAccountId() + "_ProgramCreative" + "_" + nowDate;
+
 
         if (null != singleAppid && singleAppid == 0) {
             //多应用
@@ -298,6 +301,16 @@ public class AiKuaishouCreateCreativeServiceImpl implements IAiKuaishouCreateCre
                     //创建组+创意
                     List<List<KuaiShouVideoGet>> splitVideos = Lists.partition(allVideos, 5);
                     for (int j = 1; j < splitVideos.size() + 1; j++) {
+
+                        Object redisObj = redisUtil.get(key);
+                        if (!Check.isNull(redisObj)) {
+                            Integer value = (Integer) redisObj;
+                            if (value == 1) {
+                                log.error("程序化创意创建超限,accountId:{}", strategy.getAccountId());
+                                return;
+                            }
+                        }
+
                         //创建组
                         String unitName = getName(strategy.getGroupName(), strategy, createType, appInfo, null, "unit", newCampaignId);
                         JSONObject unitParams = createUnitParams(token, newCampaignId, strategy, unitName, appInfo.getAppId());
@@ -340,6 +353,14 @@ public class AiKuaishouCreateCreativeServiceImpl implements IAiKuaishouCreateCre
             //创意
             List<List<KuaiShouVideoGet>> splitVideos = Lists.partition(allVideos, 5);
             for (int j = 1; j < splitVideos.size() + 1; j++) {
+                Object redisObj = redisUtil.get(key);
+                if (!Check.isNull(redisObj)) {
+                    Integer value = (Integer) redisObj;
+                    if (value == 1) {
+                        log.error("程序化创意创建超限,accountId:{}", strategy.getAccountId());
+                        return;
+                    }
+                }
                 //创建组
                 String unitName = getName(strategy.getGroupName(), strategy, createType, null, null, "unit", newCampaignId);
                 String appIdString = strategy.getAppIdArray();
@@ -432,6 +453,8 @@ public class AiKuaishouCreateCreativeServiceImpl implements IAiKuaishouCreateCre
         }
     }
 
+    @Autowired
+    private IKuaiShouUpdateService updateService;
 
     private void createProgramCreative(CtopOauthToken token, JSONObject creativeParams, AiKuaishouAdvertiserStrategy strategy) {
         Map<String, String> headers = new HashMap<>();
@@ -446,12 +469,26 @@ public class AiKuaishouCreateCreativeServiceImpl implements IAiKuaishouCreateCre
             return;
         }
         Integer code = resultJson.getInteger("code");
+
+
         String message = resultJson.getString("message");
-        if (null == code || code != 0) {
-            log.error("创建程序化创意失败,accountId:{},返回结果:{},入参:{}", token.getAccountId(), message, creativeParams);
-            return;
+
+        Long unitId = creativeParams.getLong("unit_id");
+        if (code == 0) {
+            log.info("创建程序化创意成功,accountId:{},unit:{}", token.getAccountId(), unitId);
+
+        } else {
+            log.error("快手创建程序化创意失败,accountId:{},unitId:{},返回信息:{}", token.getAccountId(), unitId, message);
+            if (code == 400001 && "/rest/openapi/v2/creative/advanced/program/create调用已超日限,次日可恢复调用".equals(message)) {
+                String nowDate = DateUtils.getNowDate("yyyy-MM-dd");
+                String key = token.getAccountId() + "_ProgramCreative" + "_" + nowDate;
+                redisUtil.set(key, 1, 100000L);
+                updateService.updateUnitStatus(token.getAccessToken(), token.getAccountId(), unitId, 3, "e9ca23d68d884d4ebb19d07889727dae");
+            }
+
+
         }
-        log.info("创建程序化创意成功");
+
     }
 
     private JSONObject programCreativeParams(CtopOauthToken token, Long unitId, List<KuaiShouVideoGet> list, AiKuaishouAdvertiserStrategy strategy, Integer creativeCnt, String appVersion) {

+ 2 - 1
module-kuaishou/src/main/java/cn/com/ctop/kuaishou/modules/batch/service/impl/KuaiShouUpdateServiceImpl.java

@@ -113,7 +113,6 @@ public class KuaiShouUpdateServiceImpl implements IKuaiShouUpdateService {
     }
 
 
-
     /**
      * 修改广告组预算
      *
@@ -597,6 +596,8 @@ public class KuaiShouUpdateServiceImpl implements IKuaiShouUpdateService {
             Map<String, String> headers = new HashMap<>();
             headers.put("Access-Token", accessToken);
             headers.put("Content-Type", "application/json");
+            System.err.println("修改广告组入参:" + unitJson);
+            System.err.println("修改广告组head:" + headers);
             String result = HttpUtils.kuaiShouhttpPostRequest(url, unitJson.toJSONString(), headers);
             JSONObject resultJson = JSONObject.parseObject(result);
             log.info("修改广告组返回信息:{}", resultJson);