浏览代码

修改上新视频获取逻辑bug

syh 4 年之前
父节点
当前提交
9f28767be4

+ 7 - 0
jeecg-boot-base-common/src/main/java/org/jeecg/common/util/DateUtils.java

@@ -115,6 +115,13 @@ public class DateUtils extends PropertyEditorSupport {
         return dsdf.format(parse);
     }
 
+    public static Integer getNowHour() throws ParseException {
+        Calendar cal = Calendar.getInstance();
+        Date date = new Date();
+        cal.setTime(date);
+        return cal.get(Calendar.HOUR_OF_DAY);
+    }
+
     public static Integer getHour(String dateStr) throws ParseException {
         DateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
         Calendar cal = Calendar.getInstance();

+ 2 - 2
jeecg-boot-module-system/src/main/java/org/jeecg/modules/ctop/controller/TestController.java

@@ -1262,7 +1262,7 @@ public class TestController {
             ResultMapUtils.setResultMap(result,StatusCode.COMMON_PARAM_ERROR);
             return result;
         }
-        createCreativeService.autoCreateCreative(strategy,createType,150);
+        createCreativeService.autoCreateCreative(strategy,createType,150L);
         ResultMapUtils.setResultMap(result,StatusCode.COMMON_SUCCESS);
         return result;
     }
@@ -1275,7 +1275,7 @@ public class TestController {
             ResultMapUtils.setResultMap(result,StatusCode.COMMON_PARAM_ERROR);
             return result;
         }
-        createCreativeService.autoCreateProgramCreative(strategy, createType,150);
+        createCreativeService.autoCreateProgramCreative(strategy, createType,150L);
         ResultMapUtils.setResultMap(result,StatusCode.COMMON_SUCCESS);
         return result;
     }

+ 15 - 77
jeecg-boot-module-system/src/test/java/org/jeecg/SampleTest.java

@@ -18,7 +18,6 @@ import cn.com.ctop.oa.modules.service.IWechatUserListService;
 import cn.com.ctop.toutiao.modules.link.service.IETLReportBytedanceVideoService;
 import cn.com.ctop.toutiao.modules.material.service.IByteDanceAdvertiserDataService;
 import cn.com.ctop.toutiao.modules.report.entity.BytedanceAccountReportTaskRecord;
-import cn.com.ctop.toutiao.modules.report.mapper.BytedanceReportMaterialDailyMapper;
 import cn.com.ctop.toutiao.modules.report.service.*;
 import lombok.extern.slf4j.Slf4j;
 import org.jeecg.common.util.DateUtils;
@@ -29,7 +28,6 @@ import org.springframework.boot.test.context.SpringBootTest;
 import org.springframework.test.context.ActiveProfiles;
 import org.springframework.test.context.junit4.SpringRunner;
 
-import javax.annotation.Resource;
 import java.text.ParseException;
 import java.text.SimpleDateFormat;
 import java.util.Date;
@@ -434,11 +432,23 @@ public class SampleTest {
     }
 
     @Autowired
-    private IRuleKuaiShouPlanService ruleKuaiShouPlanService;
-
+    private IBytedanceVideoEtlInfoService bytedanceVideoEtlInfoService;
+    @Autowired
+    IBytedanceVideoReportService bytedanceVideoReportService;
+    @Autowired
+    IETLReportBytedanceVideoService ietlReportBytedanceVideoService;
+    @Autowired
+    IKuaishouReportDailyImageService kuaishouReportDailyImageService;
+    @Autowired
+    IRuleByteDanceAccountService ruleByteDanceAccountService;
+    @Autowired
+    IAiKuaishouNewCreateCampaign aiKuaishouNewCreateCampaign;
+    @Autowired
+    private IKuaishouVideoEtlInfoService kuaishouVideoEtlInfoService;
     @Autowired
     private IBytedanceAccountReportTaskRecordService reportTaskRecordService;
 
+
     @Test
     public void execute() {
         List<UserAllocation> allocations = allocationService.listByMediaId("3", 0);
@@ -458,8 +468,6 @@ public class SampleTest {
         bytedanceReportService.bytedanceMaterialReport(token2, "2020-10-14", "2020-10-14");
     }
 
-    @Resource
-    private BytedanceReportMaterialDailyMapper bytedanceReportMaterialDailyMapper;
 
     private void load12AccountData(CtopOauthToken token) {
         reportService.getAdvertiserReport(token, DateUtils.parseDate("2020-10-01", "yyyy-MM-dd"), DateUtils.parseDate("2020-10-31", "yyyy-MM-dd"), CtopAdConstant.BYTEDANCE_REPORT_TYPE_DAILY);
@@ -474,8 +482,6 @@ public class SampleTest {
         bytedanceReportService.bytedanceMaterialReport(token, "2020-10-20", "2020-10-21");
     }
 
-    @Autowired
-    private IKuaishouVideoEtlInfoService kuaishouVideoEtlInfoService;
 
     @Test
     public void etlKuaishouData() {
@@ -488,8 +494,6 @@ public class SampleTest {
         }
     }
 
-    @Autowired
-    private IBytedanceVideoEtlInfoService bytedanceVideoEtlInfoService;
 
     @Test
     public void loadBytedanceVideo() {
@@ -510,83 +514,17 @@ public class SampleTest {
     }
 
 
-    @Autowired
-    IRuleByteDanceAccountService ruleByteDanceAccountService;
-    @Autowired
-    IAiKuaishouNewCreateCampaign aiKuaishouNewCreateCampaign;
 
     @Test
     public void testLoadBytedanceDataV2() {
-        String accountIds =
-                "1675440464386062," +
-                        "1688606248211533," +
-                        "1669181787105294," +
-                        "1687571097467912," +
-                        "1650079154438157," +
-                        "1680697900744711," +
-                        "1678156679964680," +
-                        "1670727177043982," +
-                        "1676160388944910," +
-                        "1687559760306190," +
-                        "1687382871519240," +
-                        "1680312075164686," +
-                        "1675440465991688," +
-                        "1664657972166663," +
-                        "1688193173408782," +
-                        "1675616147056647," +
-                        "1687308848716814," +
-                        "1686394621234247," +
-                        "1683594409340935," +
-                        "1683676478859341," +
-                        "1686384860112904," +
-                        "1668290872519693," +
-                        "1674063202781191," +
-                        "1685024266033160," +
-                        "1669714891201544," +
-                        "1687758256277512," +
-                        "1675434231118856," +
-                        "1686394621807687," +
-                        "1678411706704903," +
-                        "1686223489547271," +
-                        "1660120711467022," +
-                        "1686833795211278," +
-                        "1680697899143175," +
-                        "1661313994984462," +
-                        "1661313995480077," +
-                        "1636295780727820," +
-                        "1676540490482759," +
-                        "1675342904713223," +
-                        "1686771461984327," +
-                        "1685841129360391," +
-                        "1683676477736973," +
-                        "1661313994470413," +
-                        "1663465141771272," +
-                        "1687758256732174," +
-                        "1686223482927117," +
-                        "1686835166313479," +
-                        "1642648003678215," +
-                        "1639753233213454," +
-                        "1675239584963662," +
-                        "1674634579279885," +
-                        "1650263841162253," +
-                        "1672178052130888";
+        String accountIds = "1675440464386062";
         String[] accountArray = accountIds.split(",");
         for (int i = 0; i < accountArray.length; i++) {
             CtopOauthToken token = tokenService.getTokenByAccountId(Long.parseLong(accountArray[i]));
-
             reportService.getAdvertiserReport(token, DateUtils.parseDate("2021-01-14", "yyyy-MM-dd"), DateUtils.parseDate("2021-01-14", "yyyy-MM-dd"), CtopAdConstant.BYTEDANCE_REPORT_TYPE_DAILY);
         }
     }
 
-    @Autowired
-    IBytedanceVideoReportService bytedanceVideoReportService;
-
-    @Autowired
-    IETLReportBytedanceVideoService ietlReportBytedanceVideoService;
-
-    @Autowired
-    IKuaishouReportDailyImageService kuaishouReportDailyImageService;
-
     @Test
     public void loadKuaiShouImage() {
         List<CtopOauthToken> tokens = oauthTokenService.selectKuaiShouToken();

+ 0 - 51
module-common/src/main/java/cn/com/ctop/common/module/utils/ListUtils.java

@@ -1,51 +0,0 @@
-package cn.com.ctop.common.module.utils;
-
-import java.util.ArrayList;
-import java.util.Arrays;
-import java.util.List;
-
-public class ListUtils<T> {
-    public List<List<T>> split(List<T> sList, int num) {
-        List<List<T>> eList = new ArrayList<List<T>>();
-        List<T> gList;
-        int size = (sList.size()) / num;
-        int size2 = (sList.size()) % num;
-        int j = 0;
-        int xx = 0;
-        for (int i = 0; i < num; i++) {
-            gList = new ArrayList<T>();
-
-            for (j = xx; j < (size + xx); j++) {
-                gList.add(sList.get(j));
-            }
-            xx = j;
-            eList.add(gList);
-        }
-        if (size2 != 0) {
-            gList = new ArrayList<T>();
-            for (int y = 1; y < size2 + 1; y++) {
-                gList.add(sList.get(sList.size() - y));
-            }
-            eList.add(gList);
-        }
-        return eList;
-    }
-
-    public static void main(String[] args) {
-        List<String> ll = new ArrayList<>();
-        ll.add("a");
-        ll.add("b");
-        ll.add("c");
-        ll.add("d");
-        ll.add("e");
-        ll.add("f");
-        ll.add("g");
-
-        //把list平均拆分成2个,若不能平均拆分,多出的一个会单独保存到一个list中。
-        List<List<String>> li = new ListUtils<String>().split(ll, ll.size()/2);
-        for(List<String> l : li){
-            //打印出被拆分后的每个list中的值
-            System.out.println(Arrays.toString(l.toArray()));
-        }
-    }
-}

+ 25 - 3
module-job-kuaishou/src/main/java/cn/com/ctop/job/kuaishou/handler/KuaishouAiCreativeJob.java

@@ -7,6 +7,7 @@ import com.xxl.job.core.handler.annotation.XxlJob;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.stereotype.Component;
 
+import java.text.ParseException;
 import java.util.List;
 
 /**
@@ -36,6 +37,27 @@ public class KuaishouAiCreativeJob {
     }
 
     /**
+     * 补充自定义创意
+     */
+    @XxlJob("kuaishouCustomCreativeSupplement")
+    public void kuaishouCustomCreativeSupplement() {
+        List<AiKuaishouAdvertiserStrategy> strategies = strategyService.getAllEffectStrategy();
+        if(null==strategies||strategies.isEmpty()){
+            return;
+        }
+        strategies.forEach(strategy -> {
+            if(null!=strategy.getOpenProgramCreate()&&strategy.getOpenProgramCreate()!=1){
+                try {
+                    createCreativeService.customCreativeSupplement(strategy);
+                } catch (ParseException e) {
+                    e.printStackTrace();
+                }
+            }
+        });
+    }
+
+
+    /**
      * 自定义高质量创意
      */
     @XxlJob("kuaishouCustomCreativeTop")
@@ -46,7 +68,7 @@ public class KuaishouAiCreativeJob {
         }
         strategies.forEach(strategy -> {
             if(null!=strategy.getOpenProgramCreate()&&strategy.getOpenProgramCreate()!=1){
-                createCreativeService.autoCreateCreative(strategy,2,20);
+                createCreativeService.autoCreateCreative(strategy,2,20L);
             }
         });
     }
@@ -94,7 +116,7 @@ public class KuaishouAiCreativeJob {
         }
         strategies.forEach(strategy -> {
             if(null!=strategy.getOpenProgramCreate()&&strategy.getOpenProgramCreate()!=0){
-                createCreativeService.autoCreateProgramCreative(strategy,1,150);
+                createCreativeService.autoCreateProgramCreative(strategy,1,150L);
             }
         });
     }
@@ -110,7 +132,7 @@ public class KuaishouAiCreativeJob {
         }
         strategies.forEach(strategy -> {
             if(null!=strategy.getOpenProgramCreate()&&strategy.getOpenProgramCreate()!=0){
-                createCreativeService.autoCreateProgramCreative(strategy,2,150);
+                createCreativeService.autoCreateProgramCreative(strategy,2,150L);
             }
         });
     }

+ 2 - 0
module-kuaishou/src/main/java/cn/com/ctop/kuaishou/modules/ai/entity/AiKuaishouAdvertiserStrategy.java

@@ -206,6 +206,8 @@ public class AiKuaishouAdvertiserStrategy {
 	private String campaignDayBudgetSchedule;
 	private Long unitDayBudget;
 	private String unitDayBudgetSchedule;
+	private Long customUnitCnt;
+	private Long programUnitCnt;
 
 	@TableField(exist = false)
 	private String authName;

+ 6 - 2
module-kuaishou/src/main/java/cn/com/ctop/kuaishou/modules/ai/service/IAiKuaishouCreateCreativeService.java

@@ -2,8 +2,12 @@ package cn.com.ctop.kuaishou.modules.ai.service;
 
 import cn.com.ctop.kuaishou.modules.ai.entity.AiKuaishouAdvertiserStrategy;
 
+import java.text.ParseException;
+
 public interface IAiKuaishouCreateCreativeService {
-    void autoCreateCreative(AiKuaishouAdvertiserStrategy strategy, Integer createType, Integer videoCnt);
+    Long autoCreateCreative(AiKuaishouAdvertiserStrategy strategy, Integer createType, Long videoCnt);
+
+    void autoCreateProgramCreative(AiKuaishouAdvertiserStrategy strategy,Integer createType,Long videoCnt);
 
-    void autoCreateProgramCreative(AiKuaishouAdvertiserStrategy strategy,Integer createType,Integer videoCnt);
+    void customCreativeSupplement(AiKuaishouAdvertiserStrategy strategy) throws ParseException;
 }

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

@@ -19,17 +19,21 @@ import cn.com.ctop.kuaishou.modules.batch.service.*;
 import com.alibaba.fastjson.JSON;
 import com.alibaba.fastjson.JSONArray;
 import com.alibaba.fastjson.JSONObject;
+import com.google.common.collect.Lists;
 import lombok.extern.slf4j.Slf4j;
 import org.jeecg.common.util.DateUtils;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.stereotype.Service;
 
+import java.text.ParseException;
 import java.util.*;
 
 @Slf4j
 @Service
 public class AiKuaishouCreateCreativeServiceImpl implements IAiKuaishouCreateCreativeService {
     @Autowired
+    private IKuaiShouGroupService groupService;
+    @Autowired
     private IKuaiShouGroupTemplateService groupTemplateService;
     @Autowired
     private ICtopOauthTokenService tokenService;
@@ -51,17 +55,25 @@ public class AiKuaishouCreateCreativeServiceImpl implements IAiKuaishouCreateCre
     private IAiKuaiShouAppInfoService appInfoService;
 
 
+
     String getReplaceStringByCreateType(AiKuaishouAdvertiserStrategy strategy, Integer createType) {
-        String replaceString = "素材上新";
-        if (createType == 2) {
-            replaceString = "高质量素材";
-        } else if (createType == 3) {
-            replaceString = "素材上新";
-        } else if(createType == 4){
-            replaceString = "历史素材";
-        }
-        if (strategy.getUnitType() == 7) {
-            replaceString = "程序化" + replaceString;
+        String replaceString = "自定义上新";
+        if(strategy.getUnitType() == 7){
+            if (createType == 2) {
+                replaceString = "程序化高质量";
+            } else if (createType == 3) {
+                replaceString = "程序化上新";
+            } else if(createType == 4){
+                replaceString = "程序化素材";
+            }
+        }else{
+            if (createType == 2) {
+                replaceString = "自定义高质量";
+            } else if (createType == 3) {
+                replaceString = "自定义上新";
+            } else if(createType == 4){
+                replaceString = "自定义历史";
+            }
         }
         return replaceString;
     }
@@ -74,14 +86,14 @@ public class AiKuaishouCreateCreativeServiceImpl implements IAiKuaishouCreateCre
      * @param videoCnt
      */
     @Override
-    public void autoCreateCreative(AiKuaishouAdvertiserStrategy strategy, Integer createType, Integer videoCnt) {
+    public Long autoCreateCreative(AiKuaishouAdvertiserStrategy strategy, Integer createType, Long videoCnt) {
         strategy.setUnitType(4);
         String replaceString = getReplaceStringByCreateType(strategy, createType);
         Long accountId = strategy.getAccountId();
         CtopOauthToken token = tokenService.getOauthTokenByAccountId(accountId.toString());
         if (null == token) {
             log.info("token获取失败=>accountId:{}", accountId);
-            return;
+            return videoCnt;
         }
         //1:获取视频信息
         kuaishouInterfaceService.getVideoList(token, DateUtils.date2Str(), DateUtils.date2Str());
@@ -126,10 +138,10 @@ public class AiKuaishouCreateCreativeServiceImpl implements IAiKuaishouCreateCre
                     }
                     replaceString = appInfo.getAppVersion() + replaceString;
                     //1:查询素材
-                    List<KuaiShouVideoGet> allVideos = getVideosByParams(strategy, startTime, endTime, appInfo, createType);
+                    List<KuaiShouVideoGet> allVideos = getVideosByParams(strategy, startTime, endTime, appInfo, createType,videoCnt);
                     if (null == allVideos || allVideos.isEmpty()) {
                         log.info("账户:{},{} 到 {} 未获取到相应素材({})", accountId, startTime, endTime,replaceString);
-                        return;
+                        return videoCnt;
                     }
                     Long newCampaignId = getCampaignId(strategy, token, replaceString, "ALL_CAMPAIGN");
 
@@ -141,7 +153,13 @@ public class AiKuaishouCreateCreativeServiceImpl implements IAiKuaishouCreateCre
                         KuaishouAccountCreativeOverrunInfo overrunInfo = overrunInfoService.getByParams(accountId, DateUtils.formatDate(new Date()));
                         if (null != overrunInfo) {
                             log.info("该账户创意创建已超限=>accountId:{}", accountId);
-                            return;
+                            return 0L;
+                        }
+                        // 获取视频封面数据
+                        List<MaterialCutFrame> cutFrameList = materialCutFrameService.getListByVideoSignature(videoItem.getSignature());
+                        if ((null == cutFrameList || cutFrameList.isEmpty())) {
+                            log.info("未获取到视频封面=>videoSignature:{}", videoItem.getSignature());
+                            continue;
                         }
                         unitCnt++;
                         String unitName = unitNamePrefix + "-" + unitCnt;
@@ -154,28 +172,25 @@ public class AiKuaishouCreateCreativeServiceImpl implements IAiKuaishouCreateCre
                             continue;
                         }
                         Long unitId = (Long) unitCreateResult.get("unitId");
-
-                        // 每个组,搭配n个创意
-                        List<MaterialCutFrame> cutFrameList = materialCutFrameService.getListByVideoSignature(videoItem.getSignature());
-                        if ((null == cutFrameList || cutFrameList.isEmpty())) {
-                            log.info("未获取到视频封面=>videoSignature:{}", videoItem.getSignature());
-                            continue;
-                        }
+                        videoCnt --;
                         JSONObject creativeParams = creativeParams(token, unitId, videoItem, strategy);
                         createCreativeByImage(cutFrameList, token, creativeParams, newCampaignId, unitId, videoItem, strategy.getImageCnt());
+                        if(videoCnt<=0){
+                            return videoCnt;
+                        }
                     }
                 }
             }
         } else {
             //单一应用
-            List<KuaiShouVideoGet> newVideos = getVideosByParams(strategy, startTime, endTime, null, 100);
+            List<KuaiShouVideoGet> newVideos = getVideosByParams(strategy, startTime, endTime, null, createType,videoCnt);
             if (null == newVideos || newVideos.isEmpty()) {
                 log.info("账户:{},{} 到 {} 未获取到相应素材({})", accountId, startTime, endTime,replaceString);
-                return;
+                return videoCnt;
             }
             Long newCampaignId = getCampaignId(strategy, token, replaceString, "TODAY");
             if (null == newCampaignId) {
-                return;
+                return videoCnt;
             }
 
             //3、在“上新”计划中新增广告组,一个素材搭配n张封面,组成一个广告组
@@ -185,7 +200,13 @@ public class AiKuaishouCreateCreativeServiceImpl implements IAiKuaishouCreateCre
             for (KuaiShouVideoGet videoItem : newVideos) {
                 KuaishouAccountCreativeOverrunInfo overrunInfo = overrunInfoService.getByParams(accountId, DateUtils.formatDate(new Date()));
                 if (null != overrunInfo) {
-                    return;
+                    return 0L;
+                }
+                // 每个组,搭配5个创意
+                List<MaterialCutFrame> cutFrameList = materialCutFrameService.getListByVideoSignature(videoItem.getSignature());
+                if ((null == cutFrameList || cutFrameList.isEmpty())) {
+                    log.info("未获取到视频封面=>videoSignature:{}", videoItem.getSignature());
+                    continue;
                 }
                 unitCnt++;
                 String unitName = unitNamePrefix + "-" + unitCnt;
@@ -199,19 +220,16 @@ public class AiKuaishouCreateCreativeServiceImpl implements IAiKuaishouCreateCre
                     continue;
                 }
                 Long unitId = (Long) unitCreateResult.get("unitId");
-
-                // 每个组,搭配5个创意
-                List<MaterialCutFrame> cutFrameList = materialCutFrameService.getListByVideoSignature(videoItem.getSignature());
-                if ((null == cutFrameList || cutFrameList.isEmpty())) {
-                    log.info("未获取到视频封面=>videoSignature:{}", videoItem.getSignature());
-                    continue;
-                }
+                videoCnt -- ;
                 JSONObject creativeParams = creativeParams(token, unitId, videoItem, strategy);
                 createCreativeByImage(cutFrameList, token, creativeParams, newCampaignId, unitId, videoItem, strategy.getImageCnt());
+                if(videoCnt<=0){
+                    return 0L;
+                }
             }
         }
+        return videoCnt;
     }
-
     private String getUnitNamePrefix(AiKuaishouAdvertiserStrategy strategy,String replaceString,String timestamp){
         String unitNamePrefix = strategy.getGroupName();
         if(!unitNamePrefix.contains("自定义")){
@@ -219,13 +237,14 @@ public class AiKuaishouCreateCreativeServiceImpl implements IAiKuaishouCreateCre
         }
         return unitNamePrefix.replace("自定义", replaceString) + timestamp;
     }
+
     /**
      * 创建程序化创意
      *
      * @param strategy
      */
     @Override
-    public void autoCreateProgramCreative(AiKuaishouAdvertiserStrategy strategy, Integer createType, Integer videoCnt) {
+    public void autoCreateProgramCreative(AiKuaishouAdvertiserStrategy strategy, Integer createType, Long videoCnt) {
         strategy.setUnitType(7);
         String replaceString = getReplaceStringByCreateType(strategy, createType);
         Long accountId = strategy.getAccountId();
@@ -278,7 +297,7 @@ public class AiKuaishouCreateCreativeServiceImpl implements IAiKuaishouCreateCre
                     }
                     replaceString = appInfo.getAppVersion() + replaceString;
                     //1:查询可用素材
-                    List<KuaiShouVideoGet> allVideos = getVideosByParams(strategy, startTime, endTime, appInfo, createType);
+                    List<KuaiShouVideoGet> allVideos = getVideosByParams(strategy, startTime, endTime, appInfo, createType,videoCnt);
                     if (null == allVideos) {
                         return;
                     }
@@ -289,22 +308,23 @@ public class AiKuaishouCreateCreativeServiceImpl implements IAiKuaishouCreateCre
                         return;
                     }
                     Long newCampaignId = getCampaignId(strategy, token, replaceString, "ALL_CAMPAIGN");
-                    //创建组
-                    String timestamp = DateUtils.formatDate(new Date(), "yyyyMMddHHmmss");
-                    String unitNamePrefix = getUnitNamePrefix(strategy,replaceString,timestamp);
-                    String unitName = unitNamePrefix + "-" + timestamp;
-                    JSONObject unitParams = createUnitParams(token, newCampaignId, strategy, unitName, appInfo.getAppId());
-                    Map<String, Object> unitCreateResult = kuaishouInterfaceService.adUnitCreate(token.getAccessToken(), token.getAccountId(), unitParams, 1);
-                    Integer unitCode = (Integer) unitCreateResult.get("code");
-                    String unitMessage = (String) unitCreateResult.get("message");
-                    if (unitCode != 0) {
-                        log.info("组创建失败=>accountId:{};message:{}", accountId, unitMessage);
-                        continue;
-                    }
-                    Long unitId = (Long) unitCreateResult.get("unitId");
+
                     //创意
-                    List<List<KuaiShouVideoGet>> splitVideos = new ListUtils<KuaiShouVideoGet>().split(allVideos, allVideos.size() / 5);
+                    List<List<KuaiShouVideoGet>> splitVideos = Lists.partition(allVideos,5);
                     for (int j = 1; j < splitVideos.size() + 1; j++) {
+                        //创建组
+                        String timestamp = DateUtils.formatDate(new Date(), "yyyyMMddHHmmss");
+                        String unitNamePrefix = getUnitNamePrefix(strategy,replaceString,timestamp);
+                        String unitName = unitNamePrefix + "-" + timestamp;
+                        JSONObject unitParams = createUnitParams(token, newCampaignId, strategy, unitName, appInfo.getAppId());
+                        Map<String, Object> unitCreateResult = kuaishouInterfaceService.adUnitCreate(token.getAccessToken(), token.getAccountId(), unitParams, 1);
+                        Integer unitCode = (Integer) unitCreateResult.get("code");
+                        String unitMessage = (String) unitCreateResult.get("message");
+                        if (unitCode != 0) {
+                            log.info("组创建失败=>accountId:{};message:{}", accountId, unitMessage);
+                            continue;
+                        }
+                        Long unitId = (Long) unitCreateResult.get("unitId");
                         JSONObject creativeParams = programCreativeParams(token, unitId, splitVideos.get(j - 1), strategy, j);
                         createProgramCreative(token, creativeParams);
                     }
@@ -312,7 +332,7 @@ public class AiKuaishouCreateCreativeServiceImpl implements IAiKuaishouCreateCre
             }
         } else {
             //单一应用
-            List<KuaiShouVideoGet> allVideos = getVideosByParams(strategy, startTime, endTime, null, createType);
+            List<KuaiShouVideoGet> allVideos = getVideosByParams(strategy, startTime, endTime, null, createType,videoCnt);
             if (null == allVideos) {
                 return;
             }
@@ -321,33 +341,50 @@ public class AiKuaishouCreateCreativeServiceImpl implements IAiKuaishouCreateCre
             if (null == newCampaignId) {
                 return;
             }
-            //创建组
-            String timestamp = DateUtils.formatDate(new Date(), "yyyyMMddHHmmss");
-            String unitNamePrefix = getUnitNamePrefix(strategy,replaceString,timestamp);
-            String unitName = unitNamePrefix + "-" + timestamp;
-            String appIdString = strategy.getAppIdArray();
-            Long appId = null;
-            if(!Check.isNull(appIdString)&&!Check.isNull(JSON.parseArray(appIdString))){
-                appId = JSON.parseArray(appIdString).getLong(0);
-            }
-            JSONObject unitParams = createUnitParams(token, newCampaignId, strategy, unitName, appId);
-            Map<String, Object> unitCreateResult = kuaishouInterfaceService.adUnitCreate(token.getAccessToken(), token.getAccountId(), unitParams, 1);
-            Integer unitCode = (Integer) unitCreateResult.get("code");
-            String unitMessage = (String) unitCreateResult.get("message");
-            if (unitCode != 0) {
-                log.info("组创建失败=>accountId:{};message:{}", accountId, unitMessage);
-                return;
-            }
-            Long unitId = (Long) unitCreateResult.get("unitId");
+
             //创意
-            List<List<KuaiShouVideoGet>> splitVideos = new ListUtils<KuaiShouVideoGet>().split(allVideos, allVideos.size() / 5);
+            List<List<KuaiShouVideoGet>> splitVideos = Lists.partition(allVideos,5);
             for (int j = 1; j < splitVideos.size() + 1; j++) {
+                //创建组
+                String timestamp = DateUtils.formatDate(new Date(), "yyyyMMddHHmmss");
+                String unitNamePrefix = getUnitNamePrefix(strategy,replaceString,timestamp);
+                String unitName = unitNamePrefix + "-" + timestamp;
+                String appIdString = strategy.getAppIdArray();
+                Long appId = null;
+                if(!Check.isNull(appIdString)&&!Check.isNull(JSON.parseArray(appIdString))){
+                    appId = JSON.parseArray(appIdString).getLong(0);
+                }
+                JSONObject unitParams = createUnitParams(token, newCampaignId, strategy, unitName, appId);
+                Map<String, Object> unitCreateResult = kuaishouInterfaceService.adUnitCreate(token.getAccessToken(), token.getAccountId(), unitParams, 1);
+                Integer unitCode = (Integer) unitCreateResult.get("code");
+                String unitMessage = (String) unitCreateResult.get("message");
+                if (unitCode != 0) {
+                    log.info("组创建失败=>accountId:{};message:{}", accountId, unitMessage);
+                    return;
+                }
+                Long unitId = (Long) unitCreateResult.get("unitId");
                 JSONObject creativeParams = programCreativeParams(token, unitId, splitVideos.get(j - 1), strategy, j);
                 createProgramCreative(token, creativeParams);
             }
         }
     }
 
+    @Override
+    public void customCreativeSupplement(AiKuaishouAdvertiserStrategy strategy) throws ParseException {
+        //获取当前小时数 ,计算截止当前应当创建的组数量
+        Integer hour = DateUtils.getNowHour();
+        Long unitNum = strategy.getCustomUnitCnt()/20*hour;
+        //查询当前账户创建自定义类型组数量
+        int unitCreateCnt = groupService.queryToDayBuiltCount(strategy.getAccountId());
+        long remindCnt = unitNum-unitCreateCnt;
+        if(remindCnt>=1){
+            //优先创建历史遗漏素材
+            remindCnt = this.autoCreateCreative(strategy,3,remindCnt);
+        }
+
+
+    }
+
     private void createProgramCreative(CtopOauthToken token, JSONObject creativeParams) {
         Map<String, String> headers = new HashMap<>();
         headers.put("Content-Type", "application/json");
@@ -450,7 +487,7 @@ public class AiKuaishouCreateCreativeServiceImpl implements IAiKuaishouCreateCre
         }
     }
 
-    private List<KuaiShouVideoGet> getRelateZeroVideoList(AiKuaishouAdvertiserStrategy strategy, String startTime, String endTime, AiKuaiShouAppInfo appInfo,Integer relativeCnt) {
+    private List<KuaiShouVideoGet> getRelateZeroVideoList(AiKuaishouAdvertiserStrategy strategy, String startTime, String endTime, AiKuaiShouAppInfo appInfo,Integer relativeCnt,Long videoCnt) {
         Integer channelType = null;
         if (null != strategy.getChannelType() && strategy.getChannelType() != 2) {
             channelType = strategy.getChannelType();
@@ -459,10 +496,10 @@ public class AiKuaishouCreateCreativeServiceImpl implements IAiKuaishouCreateCre
         if(null!=appInfo&&null!=appInfo.getAppVersion()){
             appVersion = appInfo.getAppVersion();
         }
-        return videoGetService.getZeroVideoByParams(strategy.getAccountId(), startTime, endTime, 100, appVersion, channelType,relativeCnt);
+        return videoGetService.getZeroVideoByParams(strategy.getAccountId(), startTime, endTime, videoCnt, appVersion, channelType,relativeCnt);
     }
 
-    private List<KuaiShouVideoGet> getHistoryTopVideoListByParams(AiKuaishouAdvertiserStrategy strategy, String startTime, String endTime, AiKuaiShouAppInfo appInfo) {
+    private List<KuaiShouVideoGet> getHistoryTopVideoListByParams(AiKuaishouAdvertiserStrategy strategy, String startTime, String endTime, AiKuaiShouAppInfo appInfo,Long videoCnt) {
         Integer channelType = null;
         if (null != strategy.getChannelType() && strategy.getChannelType() != 2) {
             channelType = strategy.getChannelType();
@@ -471,7 +508,7 @@ public class AiKuaishouCreateCreativeServiceImpl implements IAiKuaishouCreateCre
         if(null!=appInfo&&null!=appInfo.getAppVersion()){
             appVersion = appInfo.getAppVersion();
         }
-        return videoGetService.getHistoryTopVideoByParams(strategy.getAccountId(), startTime, endTime, 100, appVersion, channelType);
+        return videoGetService.getHistoryTopVideoByParams(strategy.getAccountId(), startTime, endTime, videoCnt, appVersion, channelType);
     }
 
     /**
@@ -482,15 +519,15 @@ public class AiKuaishouCreateCreativeServiceImpl implements IAiKuaishouCreateCre
      * @param startTime  开始时间
      * @param endTime    结束时间
      */
-    private List<KuaiShouVideoGet> getVideosByParams(AiKuaishouAdvertiserStrategy strategy, String startTime, String endTime, AiKuaiShouAppInfo appInfo, Integer createType) {
+    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);
         } else if (createType == 2) {
-            return getHistoryTopVideoListByParams(strategy, startTime, endTime, appInfo);
+            return getHistoryTopVideoListByParams(strategy, startTime, endTime, appInfo,videoCnt);
         } else if(createType==3){
-            return getRelateZeroVideoList(strategy, startTime, endTime, appInfo,0);
+            return getRelateZeroVideoList(strategy, startTime, endTime, appInfo,0,videoCnt);
         }else{
-            return getRelateZeroVideoList(strategy, startTime, endTime, appInfo,20);
+            return getRelateZeroVideoList(strategy, startTime, endTime, appInfo,20,videoCnt);
         }
     }
 

+ 2 - 2
module-kuaishou/src/main/java/cn/com/ctop/kuaishou/modules/batch/mapper/KuaiShouVideoGetMapper.java

@@ -41,7 +41,7 @@ public interface KuaiShouVideoGetMapper extends BaseMapper<KuaiShouVideoGet> {
 
     Integer getHotMoneyCountByAccountId(Long accountId);
 
-    List<KuaiShouVideoGet> getZeroVideoByParams(@Param("accountId")Long accountId, @Param("startTime")String startTime, @Param("endTime")String endTime, @Param("videoCnt")Integer videoCnt,@Param("appVersion")String appVersion,@Param("channelType")Integer channelType,@Param("relativeCnt")Integer relativeCnt);
+    List<KuaiShouVideoGet> getZeroVideoByParams(@Param("accountId")Long accountId, @Param("startTime")String startTime, @Param("endTime")String endTime, @Param("videoCnt")Long videoCnt,@Param("appVersion")String appVersion,@Param("channelType")Integer channelType,@Param("relativeCnt")Integer relativeCnt);
 
-    List<KuaiShouVideoGet> getHistoryTopVideoByParams(@Param("accountId")Long accountId, @Param("startTime")String startTime, @Param("endTime")String endTime, @Param("videoCnt")Integer videoCnt,@Param("appVersion")String appVersion,@Param("channelType")Integer channelType);
+    List<KuaiShouVideoGet> getHistoryTopVideoByParams(@Param("accountId")Long accountId, @Param("startTime")String startTime, @Param("endTime")String endTime, @Param("videoCnt")Long videoCnt,@Param("appVersion")String appVersion,@Param("channelType")Integer channelType);
 }

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

@@ -49,7 +49,7 @@ public interface IKuaiShouVideoGetService extends IService<KuaiShouVideoGet> {
 
     Integer getHotMoneyCountByAccountId(Long accountId);
 
-    List<KuaiShouVideoGet> getZeroVideoByParams(Long accountId, String startTime, String endTime, Integer videoCnt,String appVersion,Integer channelType,Integer relativeCnt);
+    List<KuaiShouVideoGet> getZeroVideoByParams(Long accountId, String startTime, String endTime, Long videoCnt,String appVersion,Integer channelType,Integer relativeCnt);
 
-    List<KuaiShouVideoGet> getHistoryTopVideoByParams(Long accountId, String startTime, String endTime, Integer videoCnt, String appVersion, Integer channelType);
+    List<KuaiShouVideoGet> getHistoryTopVideoByParams(Long accountId, String startTime, String endTime, Long videoCnt, String appVersion, Integer channelType);
 }

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

@@ -276,12 +276,12 @@ public class KuaiShouVideoGetServiceImpl extends ServiceImpl<KuaiShouVideoGetMap
     }
 
     @Override
-    public List<KuaiShouVideoGet> getZeroVideoByParams(Long accountId, String startTime, String endTime, Integer videoCnt,String appVersion,Integer channelType,Integer relativeCnt) {
+    public List<KuaiShouVideoGet> getZeroVideoByParams(Long accountId, String startTime, String endTime, Long videoCnt,String appVersion,Integer channelType,Integer relativeCnt) {
         return videoGetMapper.getZeroVideoByParams(accountId,startTime,endTime,videoCnt,appVersion,channelType,relativeCnt);
     }
 
     @Override
-    public List<KuaiShouVideoGet> getHistoryTopVideoByParams(Long accountId, String startTime, String endTime, Integer videoCnt, String appVersion, Integer channelType) {
+    public List<KuaiShouVideoGet> getHistoryTopVideoByParams(Long accountId, String startTime, String endTime, Long videoCnt, String appVersion, Integer channelType) {
         return videoGetMapper.getHistoryTopVideoByParams(accountId,startTime,endTime,videoCnt,appVersion,channelType);
     }
 }