浏览代码

自动投放 计划创建失败、多应用程序化素材时间段、多应用创意名称修改

yum 4 年之前
父节点
当前提交
b28f2f6ca7

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

@@ -149,7 +149,7 @@ public class AiKuaishouCreateCreativeServiceImpl implements IAiKuaishouCreateCre
                         unitLevelOperationRecordService.saveOrUpdate(unitLevelOperationRecord);
                         videoCnt--;
                         JSONObject creativeParams = creativeParams(token, unitId, videoItem, strategy);
-                        createCreativeByImage(cutFrameList, token, creativeParams, newCampaignId, unitId, videoItem, strategy.getImageCnt(), strategy, strategyUuid);
+                        createCreativeByImage(cutFrameList, token, creativeParams, newCampaignId, unitId, videoItem, strategy.getImageCnt(), strategy, strategyUuid, appInfo.getAppVersion());
                         if (videoCnt <= 0) {
                             return videoCnt;
                         }
@@ -208,7 +208,7 @@ public class AiKuaishouCreateCreativeServiceImpl implements IAiKuaishouCreateCre
                 unitLevelOperationRecordService.saveOrUpdate(unitLevelOperationRecord);
                 videoCnt--;
                 JSONObject creativeParams = creativeParams(token, unitId, videoItem, strategy);
-                createCreativeByImage(cutFrameList, token, creativeParams, newCampaignId, unitId, videoItem, strategy.getImageCnt(), strategy, strategyUuid);
+                createCreativeByImage(cutFrameList, token, creativeParams, newCampaignId, unitId, videoItem, strategy.getImageCnt(), strategy, strategyUuid, null);
                 if (videoCnt <= 0) {
                     return 0L;
                 }
@@ -235,14 +235,24 @@ public class AiKuaishouCreateCreativeServiceImpl implements IAiKuaishouCreateCre
         }
         //1:获取视频信息
         kuaishouInterfaceService.getVideoList(token, DateUtils.date2Str(), DateUtils.date2Str());
-        Long timeStart = KuaishouCreativeMatTypeEnum.getStartTimeByType(strategy.getUnitType().toString() + createType.toString());
-        Long timeEnd = KuaishouCreativeMatTypeEnum.getEndTimeByType(strategy.getUnitType().toString() + createType.toString());
+        //2:判定账户是否单一应用
+        Long timeStart = null;
+        Long timeEnd = null;
+
+        Integer singleAppid = strategy.getSingleAppid();
+        if (null != singleAppid && singleAppid == 0) {
+            timeStart = -7 * 60 * 24L;
+            timeEnd = -5L;
+        } else {
+            timeStart = KuaishouCreativeMatTypeEnum.getStartTimeByType(strategy.getUnitType().toString() + createType.toString());
+            timeEnd = KuaishouCreativeMatTypeEnum.getEndTimeByType(strategy.getUnitType().toString() + createType.toString());
+        }
+
         Long now = System.currentTimeMillis();
         String startTime = DateUtils.formatDateTime(now + timeStart * 60 * 1000L);
         String endTime = DateUtils.formatDateTime(now + timeEnd * 60 * 1000L);
 
-        //2:判定账户是否单一应用
-        Integer singleAppid = strategy.getSingleAppid();
+
         if (null != singleAppid && singleAppid == 0) {
             //多应用
             String appidString = strategy.getAppIdArray();
@@ -300,7 +310,7 @@ public class AiKuaishouCreateCreativeServiceImpl implements IAiKuaishouCreateCre
                         Long unitId = (Long) unitCreateResult.get("unitId");
                         unitLevelOperationRecord.setUnitId(unitId);
                         unitLevelOperationRecordService.saveOrUpdate(unitLevelOperationRecord);
-                        JSONObject creativeParams = programCreativeParams(token, unitId, splitVideos.get(j - 1), strategy, j);
+                        JSONObject creativeParams = programCreativeParams(token, unitId, splitVideos.get(j - 1), strategy, j, appInfo.getAppVersion());
                         createProgramCreative(token, creativeParams, strategy);
                     }
                 }
@@ -349,7 +359,7 @@ public class AiKuaishouCreateCreativeServiceImpl implements IAiKuaishouCreateCre
                 Long unitId = (Long) unitCreateResult.get("unitId");
                 unitLevelOperationRecord.setUnitId(unitId);
                 unitLevelOperationRecordService.saveOrUpdate(unitLevelOperationRecord);
-                JSONObject creativeParams = programCreativeParams(token, unitId, splitVideos.get(j - 1), strategy, j);
+                JSONObject creativeParams = programCreativeParams(token, unitId, splitVideos.get(j - 1), strategy, j, null);
                 createProgramCreative(token, creativeParams, strategy);
             }
         }
@@ -436,11 +446,21 @@ public class AiKuaishouCreateCreativeServiceImpl implements IAiKuaishouCreateCre
         log.info("创建程序化创意成功");
     }
 
-    private JSONObject programCreativeParams(CtopOauthToken token, Long unitId, List<KuaiShouVideoGet> list, AiKuaishouAdvertiserStrategy strategy, Integer creativeCnt) {
+    private JSONObject programCreativeParams(CtopOauthToken token, Long unitId, List<KuaiShouVideoGet> list, AiKuaishouAdvertiserStrategy strategy, Integer creativeCnt, String appVersion) {
         JSONObject programJson = new JSONObject();
         programJson.put("advertiser_id", token.getAccountId());
         programJson.put("unit_id", unitId);
-        programJson.put("package_name", "程序化创意" + creativeCnt);
+        if (strategy.getSingleAppid() != null && strategy.getSingleAppid() == 0) {  // 多应用情况下 创意名称已app-versionMI命名
+            if (!Check.isNull(appVersion)) {
+                programJson.put("package_name", appVersion);
+            } else {
+                programJson.put("package_name", "程序化创意" + creativeCnt);
+            }
+
+        } else {
+            programJson.put("package_name", "程序化创意" + creativeCnt);
+        }
+
         JSONArray horizontalPhotoIds = new JSONArray();
         JSONArray verticalPhotoIds = new JSONArray();
         JSONArray coverImageTokens = new JSONArray();
@@ -571,6 +591,9 @@ public class AiKuaishouCreateCreativeServiceImpl implements IAiKuaishouCreateCre
      * @param startTime  开始时间
      * @param endTime    结束时间
      */
+    @Autowired
+    private IKuaiShouCampaignService campaignService;
+
     private List<KuaiShouVideoGet> getVideosByParams(AiKuaishouAdvertiserStrategy strategy, String startTime, String endTime, AiKuaiShouAppInfo appInfo, Integer createType, Long videoCnt) {
         if (createType == 1) {
             return getNewVideoListByParams(strategy, startTime, endTime, appInfo);
@@ -584,23 +607,34 @@ public class AiKuaishouCreateCreativeServiceImpl implements IAiKuaishouCreateCre
     }
 
     private Long getCampaignId(AiKuaishouAdvertiserStrategy strategy, CtopOauthToken token, String replaceString, String checkType, Integer createType, AiKuaiShouAppInfo appInfo, String uuid) {
-        JSONArray campaignList;
-        String timestamp = null;
-        if ("ALL_CAMPAIGN".equals(checkType)) {
+        //  JSONArray campaignList;
+        String timestamp = DateUtils.formatDate(new Date(), "yyyyMMddHHmmss");
+        /*if ("ALL_CAMPAIGN".equals(checkType)) {
             campaignList = kuaishouInterfaceService.getCampaignList(token, null, null, 1);
         } else {
             timestamp = DateUtils.formatDate(new Date(), "yyyyMMddHHmmss");
             campaignList = kuaishouInterfaceService.getCampaignList(token, new Date(), new Date(), 1);
-        }
+        }*/
 
-        if (null != campaignList && !campaignList.isEmpty()) {
+       /* if (!Check.isNull(campaignList)){
             for (int i = 0; i < campaignList.size(); i++) {
                 JSONObject jsonObject = campaignList.getJSONObject(i);
                 if (jsonObject.getString("campaign_name").contains(replaceString)) {
                     return jsonObject.getLong("campaign_id");
                 }
             }
+        }*/
+        Long campaignId = null;
+        if ("ALL_CAMPAIGN".equals(checkType)) {
+            campaignId = campaignService.getCampaignIdByAccountAndName(strategy.getAccountId(), replaceString);
+        } else if ("TODAY".equals(checkType)) {
+            String nowDate = DateUtils.getNowDate("yyyy-MM-dd") + " 00:00:01";
+            campaignId = campaignService.getCampaignIdByAccountAndNameAndDate(strategy.getAccountId(), replaceString, nowDate);
+        }
+        if (!Check.isNull(campaignId)) {
+            return campaignId;
         }
+
         // 不存在“上新”计划,则创建一个计划
         JSONObject campaignParams = new JSONObject();
         campaignParams.put("advertiser_id", token.getAccountId());
@@ -622,7 +656,7 @@ public class AiKuaishouCreateCreativeServiceImpl implements IAiKuaishouCreateCre
             aiKuaishouCampaignLevelOperationRecordService.saveOrUpdate(record);
             return null;
         }
-        Long campaignId = (Long) campaignCreateResult.get("campaignId");
+        campaignId = (Long) campaignCreateResult.get("campaignId");
         record.setCampaignId(campaignId);
         aiKuaishouCampaignLevelOperationRecordService.saveOrUpdate(record);
         return campaignId;
@@ -1008,14 +1042,14 @@ public class AiKuaishouCreateCreativeServiceImpl implements IAiKuaishouCreateCre
 
     private void createCreativeByImage(List<MaterialCutFrame> cutFrameList, CtopOauthToken token, JSONObject creativeParams,
                                        Long campaignId, Long unitId, KuaiShouVideoGet videoItem,
-                                       int imageNumber, AiKuaishouAdvertiserStrategy strategy, String uuid) {
+                                       int imageNumber, AiKuaishouAdvertiserStrategy strategy, String uuid, String appVersion) {
         if ((null != cutFrameList && !cutFrameList.isEmpty())) {
             for (int i = 0; i < cutFrameList.size(); i++) {
                 String imageCode = cutFrameList.get(i).getSignature();
                 String imageUrl = cutFrameList.get(i).getUrl();
                 String imageToken = getImageToken(imageUrl, imageCode, token.getAccountId(), token.getAccessToken());
                 creativeParams.put("image_token", imageToken);
-                createCreative(token, creativeParams, campaignId, unitId, i + 1, videoItem, strategy, uuid);
+                createCreative(token, creativeParams, campaignId, unitId, i + 1, videoItem, strategy, uuid, appVersion);
                 imageNumber--;
                 if (imageNumber <= 0) {
                     break;
@@ -1089,8 +1123,13 @@ public class AiKuaishouCreateCreativeServiceImpl implements IAiKuaishouCreateCre
 
 
     private void createCreative(CtopOauthToken token, JSONObject creativeParams, Long campaignId, Long unitId,
-                                int creativeCnt, KuaiShouVideoGet videoGet, AiKuaishouAdvertiserStrategy strategy, String uuid) {
-        String creativeName = "自定义创意_" + creativeCnt;
+                                int creativeCnt, KuaiShouVideoGet videoGet, AiKuaishouAdvertiserStrategy strategy, String uuid, String appVersion) {
+        String creativeName = null;
+        if (!Check.isNull(appVersion)) {
+            creativeName = appVersion + "_" + creativeCnt;
+        } else {
+            creativeName = "自定义创意_" + creativeCnt;
+        }
         creativeParams.put("creative_name", creativeName);
         Map<String, Object> creativeCreateResult = kuaishouInterfaceService.creativeCreate(token.getAccessToken(), token.getAccountId(), creativeParams, 1);
         Integer creativeCode = (Integer) creativeCreateResult.get("code");

+ 4 - 0
module-kuaishou/src/main/java/cn/com/ctop/kuaishou/modules/batch/mapper/KuaiShouCampaignMapper.java

@@ -21,4 +21,8 @@ public interface KuaiShouCampaignMapper extends BaseMapper<KuaiShouCampaign> {
     List<Long> queryCampaignIdByAccountId(Long accountId);
 
     Integer getNewDataByAccountIdAndDate(@Param("accountId") Long accountId, @Param("statDate") String statDate);
+
+    Long getCampaignIdByAccountAndName(@Param("accountId") Long accountId, @Param("name") String replaceString);
+
+    Long getCampaignIdByAccountAndNameAndDate(@Param("accountId") Long accountId, @Param("name") String replaceString, @Param("nowDate") String nowDate);
 }

+ 16 - 0
module-kuaishou/src/main/java/cn/com/ctop/kuaishou/modules/batch/mapper/xml/KuaiShouCampaignMapper.xml

@@ -54,4 +54,20 @@
      where account_id = #{accountId}
      and DATE_FORMAT(put_create_time,'%Y-%m-%d') = #{statDate}
     </select>
+    <select id="getCampaignIdByAccountAndName" resultType="java.lang.Long">
+        select campaign_id  from  ctop_kuaishou_campaign where  account_id = #{accountId}
+        and campaign_name like CONCAT('%',CONCAT(#{name},'%'))
+        order by put_create_time DESC
+        limit 1
+
+
+    </select>
+    <select id="getCampaignIdByAccountAndNameAndDate" resultType="java.lang.Long">
+          select campaign_id  from  ctop_kuaishou_campaign where  account_id = #{accountId}
+        and campaign_name like CONCAT('%',CONCAT(#{name},'%'))
+        and put_create_time &gt;= #{nowDate}
+        order by put_create_time DESC
+        limit 1
+
+    </select>
 </mapper>

+ 4 - 0
module-kuaishou/src/main/java/cn/com/ctop/kuaishou/modules/batch/service/IKuaiShouCampaignService.java

@@ -23,4 +23,8 @@ public interface IKuaiShouCampaignService extends IService<KuaiShouCampaign> {
     KuaiShouCampaign getCampaignByAccountAndCampaign(Long accountId, Long campaignId);
 
     Integer getNewDataByAccountIdAndDate(Long accountId, String statDate);
+
+    Long getCampaignIdByAccountAndName(Long accountId, String replaceString);
+
+    Long getCampaignIdByAccountAndNameAndDate(Long accountId, String replaceString, String nowDate);
 }

+ 10 - 0
module-kuaishou/src/main/java/cn/com/ctop/kuaishou/modules/batch/service/impl/KuaiShouCampaignServiceImpl.java

@@ -81,4 +81,14 @@ public class KuaiShouCampaignServiceImpl extends ServiceImpl<KuaiShouCampaignMap
         return campaignMapper.getNewDataByAccountIdAndDate(accountId, statDate);
     }
 
+    @Override
+    public Long getCampaignIdByAccountAndName(Long accountId, String replaceString) {
+        return campaignMapper.getCampaignIdByAccountAndName(accountId, replaceString);
+    }
+
+    @Override
+    public Long getCampaignIdByAccountAndNameAndDate(Long accountId, String replaceString, String nowDate) {
+        return campaignMapper.getCampaignIdByAccountAndNameAndDate(accountId, replaceString, nowDate);
+    }
+
 }

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

@@ -1023,7 +1023,7 @@ public class KuaishouInterfaceServiceImpl implements IKuaishouInterfaceService {
             param.put("end_date", DateUtils.formatDate(endDate));
         }
         param.put("page", page);
-        param.put("page_size", 200);
+        param.put("page_size", 2000);
 
         String result = HttpUtils.kuaiShouhttpPostRequest(url, param.toJSONString(), headers);
         JSONObject resultJson = JSONObject.parseObject(result);