Kaynağa Gözat

Merge remote-tracking branch 'origin/master_ai' into test

syh 4 yıl önce
ebeveyn
işleme
8287c76951

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

@@ -9,21 +9,23 @@ import cn.com.ctop.common.module.vo.ResFileDTO;
 import cn.com.ctop.crawler.modules.core.entity.CrawlerDouyinMusicTask;
 import cn.com.ctop.crawler.modules.core.service.CrawlerDouyinMusicTaskService;
 import cn.com.ctop.crawler.modules.douyin.service.DouyinMusicService;
+import cn.com.ctop.kuaishou.modules.ai.entity.AiKuaishouAdvertiserStrategy;
+import cn.com.ctop.kuaishou.modules.ai.service.IAiKuaishouAdvertiserStrategyService;
+import cn.com.ctop.kuaishou.modules.ai.service.IAiKuaishouCreateCreativeService;
 import cn.com.ctop.kuaishou.modules.batch.entity.KuaishouTemplate;
 import cn.com.ctop.kuaishou.modules.batch.service.*;
 import cn.com.ctop.kuaishou.modules.graphql.service.IKuaishouWebInterfaceService;
 import cn.com.ctop.kuaishou.modules.material.entity.KuaishouAccessToken;
 import cn.com.ctop.kuaishou.modules.material.entity.KuaishouResultToken;
-import cn.com.ctop.kuaishou.modules.report.service.*;
+import cn.com.ctop.kuaishou.modules.report.service.IKuaiShouDailyAgentService;
+import cn.com.ctop.kuaishou.modules.report.service.IKuaishouAudienceReportDailyService;
 import cn.com.ctop.toutiao.modules.link.service.IETLReportBytedanceVideoService;
 import cn.com.ctop.toutiao.modules.material.service.IByteDanceAdvertiserDataService;
 import cn.com.ctop.toutiao.modules.material.service.IBytedanceEffectVideoInfoService;
-import cn.com.ctop.toutiao.modules.report.mapper.BytedanceReportMaterialDailyMapper;
 import cn.com.ctop.toutiao.modules.report.service.*;
 import com.alibaba.fastjson.JSONArray;
 import com.alibaba.fastjson.JSONObject;
 import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
-import com.xxl.job.core.context.XxlJobHelper;
 import lombok.extern.slf4j.Slf4j;
 import org.apache.commons.lang3.StringUtils;
 import org.apache.ibatis.annotations.Param;
@@ -31,12 +33,7 @@ import org.jeecg.common.api.vo.Result;
 import org.jeecg.common.util.DateUtils;
 import org.quartz.JobExecutionException;
 import org.springframework.beans.factory.annotation.Autowired;
-import org.springframework.web.bind.annotation.GetMapping;
-import org.springframework.web.bind.annotation.PostMapping;
-import org.springframework.web.bind.annotation.RequestBody;
-import org.springframework.web.bind.annotation.RequestMapping;
-import org.springframework.web.bind.annotation.RequestParam;
-import org.springframework.web.bind.annotation.RestController;
+import org.springframework.web.bind.annotation.*;
 
 import javax.annotation.Resource;
 import java.io.IOException;
@@ -96,43 +93,23 @@ public class TestController {
     private IKuaiShouHistoryReportTaskService kuaiShouHistoryReportTaskService;
 
     static ExecutorService executorService = Executors.newFixedThreadPool(15);
-    static ExecutorService videoService = Executors.newFixedThreadPool(5);
     static ExecutorService suzhaoService = Executors.newFixedThreadPool(5);
     @Autowired
     private IKuaiShouDailyAgentService dailyAgentService;
     @Autowired
     private IKuaishouTemplateService templateService;
     @Autowired
-    private IBytedanceAccountReportTaskRecordService reportTaskRecordService;
-    @Resource
-    private BytedanceReportMaterialDailyMapper bytedanceReportMaterialDailyMapper;
-    @Autowired
     private ICtopOauthTokenService ctopOauthTokenService;
-
     @Autowired
     private IBindAccountAuthService bindAccountAuthService;
     @Resource
     private UserAllocationMapper allocationMapper;
     @Autowired
     private IBytedanceReportService bytedanceReportService;
-
     @Autowired
     private IUserAllocationService allocationService;
     @Autowired
-    private IEtlKuaiShouNewlyService kuaiShouNewlyService;
-    static ExecutorService materialExecutorService = Executors.newFixedThreadPool(8);
-
-    @Autowired
     private ICtopOauthTokenService tokenService;
-    @Autowired
-    private IEtlKuaiShouGroupDailyReportService etlKuaiShouGroupDailyReportService;
-    @Autowired
-    private IEtlKuaiShouAccountMaterialOverviewService accountMaterialOverviewService;
-
-    @Autowired
-    private IEtlKuaiShouNewlyService newlyService;
-    @Autowired
-    private IKuaishouReportDailyGroupService reportDailyGroupService;
 
 
     @GetMapping("/cleanNewlyData")
@@ -298,11 +275,6 @@ public class TestController {
         } catch (InterruptedException e) {
             e.printStackTrace();
         }
-//        bytedanceReportMaterialDailyMapper.updateImageReportCode();
-//        bytedanceReportMaterialDailyMapper.updateImageReportProjectId();
-//        bytedanceReportMaterialDailyMapper.updateImageReportProjectName();
-//        bytedanceReportMaterialDailyMapper.updateImageReportPlaneId();
-//        bytedanceReportMaterialDailyMapper.updateImageReportPlaneName();
         Map<String, Object> result = new HashMap<>();
         ResultMapUtils.setResultMap(new HashMap<>(), StatusCode.COMMON_SUCCESS);
         return result;
@@ -546,7 +518,6 @@ public class TestController {
 
             QueryWrapper<UserAllocation> userAllocationQueryWrapper = new QueryWrapper<>();
             userAllocationQueryWrapper.eq("project_id", projectId);
-            // userAllocationQueryWrapper.eq("account_status", 0);
             List<UserAllocation> list = userAllocationService.list(userAllocationQueryWrapper);
             if (!Check.isNull(list)) {
                 for (UserAllocation allocation : list) {
@@ -1277,4 +1248,35 @@ public class TestController {
         }));
         return Result.ok("success");
     }
+
+    @Autowired
+    private IAiKuaishouAdvertiserStrategyService strategyService;
+    @Autowired
+    private IAiKuaishouCreateCreativeService createCreativeService;
+
+    @GetMapping("testCreateCreative")
+    public Map<String,Object>testCreateCreative(Long accountId,Integer createType){
+        Map<String,Object>result = new HashMap<>();
+        AiKuaishouAdvertiserStrategy strategy = strategyService.getByAccountId(accountId);
+        if(strategy == null){
+            ResultMapUtils.setResultMap(result,StatusCode.COMMON_PARAM_ERROR);
+            return result;
+        }
+        createCreativeService.autoCreateCreative(strategy,createType,150);
+        ResultMapUtils.setResultMap(result,StatusCode.COMMON_SUCCESS);
+        return result;
+    }
+
+    @GetMapping("testProgramCreative")
+    public Map<String,Object>testProgramCreative(Long accountId,Integer createType){
+        Map<String,Object>result = new HashMap<>();
+        AiKuaishouAdvertiserStrategy strategy = strategyService.getByAccountId(accountId);
+        if(strategy == null){
+            ResultMapUtils.setResultMap(result,StatusCode.COMMON_PARAM_ERROR);
+            return result;
+        }
+        createCreativeService.autoCreateProgramCreative(strategy, createType,150);
+        ResultMapUtils.setResultMap(result,StatusCode.COMMON_SUCCESS);
+        return result;
+    }
 }

+ 1 - 1
jeecg-boot-module-system/src/main/resources/application-wps.yml

@@ -101,7 +101,7 @@ spring:
 #          password: hcst@2021
 #          driver-class-name: com.mysql.jdbc.Driver
         master:
-          url: jdbc:mysql://139.186.151.174:3306/jeecg-boot?characterEncoding=UTF-8&useUnicode=true
+          url: jdbc:mysql://139.186.165.84:3306/jeecg-boot?characterEncoding=UTF-8&useUnicode=true
           username: hcst
           password: hcst@2020
           driver-class-name: com.mysql.jdbc.Driver

+ 117 - 0
module-job-kuaishou/src/main/java/cn/com/ctop/job/kuaishou/handler/KuaishouAiCreativeJob.java

@@ -0,0 +1,117 @@
+package cn.com.ctop.job.kuaishou.handler;
+
+import cn.com.ctop.kuaishou.modules.ai.entity.AiKuaishouAdvertiserStrategy;
+import cn.com.ctop.kuaishou.modules.ai.service.IAiKuaishouAdvertiserStrategyService;
+import cn.com.ctop.kuaishou.modules.ai.service.IAiKuaishouCreateCreativeService;
+import com.xxl.job.core.handler.annotation.XxlJob;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.stereotype.Component;
+
+import java.util.List;
+
+/**
+ * @author syh
+ * 自动投放定时任务
+ */
+@Component
+public class KuaishouAiCreativeJob {
+    @Autowired
+    private IAiKuaishouAdvertiserStrategyService strategyService;
+    @Autowired
+    private IAiKuaishouCreateCreativeService createCreativeService;
+    /**
+     * 自定义上新创意
+     */
+    @XxlJob("kuaishouCustomCreativeAuto")
+    public void kuaishouCustomCreativeAuto() {
+        List<AiKuaishouAdvertiserStrategy> strategies = strategyService.getAllEffectStrategy();
+        if(null==strategies||strategies.isEmpty()){
+            return;
+        }
+        strategies.forEach(strategy -> {
+            if(null!=strategy.getOpenProgramCreate()&&strategy.getOpenProgramCreate()!=1){
+                createCreativeService.autoCreateCreative(strategy,1,null);
+            }
+        });
+    }
+
+    /**
+     * 自定义高质量创意
+     */
+    @XxlJob("kuaishouCustomCreativeTop")
+    public void kuaishouCustomCreativeTop() {
+        List<AiKuaishouAdvertiserStrategy> strategies = strategyService.getAllEffectStrategy();
+        if(null==strategies||strategies.isEmpty()){
+            return;
+        }
+        strategies.forEach(strategy -> {
+            if(null!=strategy.getOpenProgramCreate()&&strategy.getOpenProgramCreate()!=1){
+                createCreativeService.autoCreateCreative(strategy,2,20);
+            }
+        });
+    }
+
+    /**
+     * 自定义遗漏创意
+     */
+    @XxlJob("kuaishouCustomCreativeMissing")
+    public void kuaishouCustomCreativeMissing() {
+        List<AiKuaishouAdvertiserStrategy> strategies = strategyService.getAllEffectStrategy();
+        if(null==strategies||strategies.isEmpty()){
+            return;
+        }
+        strategies.forEach(strategy -> {
+            if(null!=strategy.getOpenProgramCreate()&&strategy.getOpenProgramCreate()!=1){
+                createCreativeService.autoCreateCreative(strategy,3,null);
+            }
+        });
+    }
+
+    /**
+     * 自定义历史打捞创意
+     */
+    @XxlJob("kuaishouCustomCreativeHistory")
+    public void kuaishouCustomCreativeHistory() {
+        List<AiKuaishouAdvertiserStrategy> strategies = strategyService.getAllEffectStrategy();
+        if(null==strategies||strategies.isEmpty()){
+            return;
+        }
+        strategies.forEach(strategy -> {
+            if(null!=strategy.getOpenProgramCreate()&&strategy.getOpenProgramCreate()!=1){
+                createCreativeService.autoCreateCreative(strategy,4,null);
+            }
+        });
+    }
+
+    /**
+     * 程序化上新创意
+     */
+    @XxlJob("kuaishouProgramCreativeAuto")
+    public void kuaishouProgramCreativeAuto() {
+        List<AiKuaishouAdvertiserStrategy> strategies = strategyService.getAllEffectStrategy();
+        if(null==strategies||strategies.isEmpty()){
+            return;
+        }
+        strategies.forEach(strategy -> {
+            if(null!=strategy.getOpenProgramCreate()&&strategy.getOpenProgramCreate()!=0){
+                createCreativeService.autoCreateProgramCreative(strategy,1,150);
+            }
+        });
+    }
+
+    /**
+     * 程序化上新创意
+     */
+    @XxlJob("kuaishouProgramCreativeTop")
+    public void kuaishouProgramCreativeTop() {
+        List<AiKuaishouAdvertiserStrategy> strategies = strategyService.getAllEffectStrategy();
+        if(null==strategies||strategies.isEmpty()){
+            return;
+        }
+        strategies.forEach(strategy -> {
+            if(null!=strategy.getOpenProgramCreate()&&strategy.getOpenProgramCreate()!=0){
+                createCreativeService.autoCreateProgramCreative(strategy,2,150);
+            }
+        });
+    }
+}

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

@@ -1,10 +1,9 @@
 package cn.com.ctop.kuaishou.modules.ai.service;
 
 import cn.com.ctop.kuaishou.modules.ai.entity.AiKuaishouAdvertiserStrategy;
-import com.alibaba.fastjson.JSONObject;
 
 public interface IAiKuaishouCreateCreativeService {
-    void autoCreateCreative(AiKuaishouAdvertiserStrategy strategy, Integer createType, JSONObject params);
+    void autoCreateCreative(AiKuaishouAdvertiserStrategy strategy, Integer createType, Integer videoCnt);
 
-    void autoCreateProgramCreative(AiKuaishouAdvertiserStrategy strategy,Integer createType,JSONObject params);
+    void autoCreateProgramCreative(AiKuaishouAdvertiserStrategy strategy,Integer createType,Integer videoCnt);
 }

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

@@ -69,11 +69,11 @@ public class AiKuaishouCreateCreativeServiceImpl implements IAiKuaishouCreateCre
      * 创建自定义创意
      *
      * @param strategy   账户配置信息
-     * @param createType 创意创建类型 1:素材上新 2:历史高质量 3:历史遗漏素材
-     * @param params     需要拼装的参数
+     * @param createType 创意创建类型 1:素材上新 2:历史高质量 3:历史遗漏素材 4:历史打捞
+     * @param videoCnt
      */
     @Override
-    public void autoCreateCreative(AiKuaishouAdvertiserStrategy strategy, Integer createType, JSONObject params) {
+    public void autoCreateCreative(AiKuaishouAdvertiserStrategy strategy, Integer createType, Integer videoCnt) {
         strategy.setUnitType(4);
         String replaceString = getReplaceStringByCreateType(strategy, createType);
         Long accountId = strategy.getAccountId();
@@ -84,11 +84,27 @@ public class AiKuaishouCreateCreativeServiceImpl implements IAiKuaishouCreateCre
         }
         //1:获取视频信息
         kuaishouInterfaceService.getVideoList(token, DateUtils.date2Str(), DateUtils.date2Str());
-        int timeStart = -10;
-        int timeEnd = -5;
+        Integer timeStart;
+        Integer timeEnd;
+        if(createType == 1){
+            timeStart = -10;
+            timeEnd = -5;
+        }else if(createType == 2){
+            //历史高质量
+            timeStart = -14*60*24;
+            timeEnd = -1*60*24;
+        }else if(createType == 3){
+            //历史遗漏
+            timeStart = -60*60*24;
+            timeEnd = -1*60*24;
+        }else{
+            //历史打捞
+            timeStart = -60*60*24;
+            timeEnd = -1*60*24;
+        }
         Long now = System.currentTimeMillis();
-        String startTime = DateUtils.formatDate(new Date(now + timeStart * 60 * 1000), DateUtils.NEW_FORMAT);
-        String endTime = DateUtils.formatDate(new Date(now + timeEnd * 60 * 1000), DateUtils.NEW_FORMAT);
+        String startTime = DateUtils.formatDate(now+timeStart*60*1000L);
+        String endTime = DateUtils.formatDate(now + timeEnd * 60 * 1000L);
 
         //2:判定账户是否单一应用
         Integer singleAppid = strategy.getSingleAppid();
@@ -117,7 +133,7 @@ public class AiKuaishouCreateCreativeServiceImpl implements IAiKuaishouCreateCre
 
                     //开始创建组+创意
                     String timestamp = DateUtils.formatDate(new Date(), "yyyyMMddHHmmss");
-                    String unitNamePrefix = strategy.getGroupName().replace("自定义", replaceString) + timestamp;
+                    String unitNamePrefix = getUnitNamePrefix(strategy,replaceString,timestamp);
                     int unitCnt = 0;
                     for (KuaiShouVideoGet videoItem : allVideos) {
                         KuaishouAccountCreativeOverrunInfo overrunInfo = overrunInfoService.getByParams(accountId, DateUtils.formatDate(new Date()));
@@ -150,7 +166,7 @@ public class AiKuaishouCreateCreativeServiceImpl implements IAiKuaishouCreateCre
             }
         } else {
             //单一应用
-            List<KuaiShouVideoGet> newVideos = videoGetService.getNewVideoBetweenTime(accountId, startTime, endTime, strategy.getChannelType(), null, null);
+            List<KuaiShouVideoGet> newVideos = getVideosByParams(strategy, startTime, endTime, null, 100);
             if (null == newVideos || newVideos.isEmpty()) {
                 log.info("账户:{},{} 到 {} 这段时间没有上新素材", accountId, startTime, endTime);
                 return;
@@ -162,7 +178,7 @@ public class AiKuaishouCreateCreativeServiceImpl implements IAiKuaishouCreateCre
 
             //3、在“上新”计划中新增广告组,一个素材搭配n张封面,组成一个广告组
             String timestamp = DateUtils.formatDate(new Date(), "yyyyMMddHHmmss");
-            String unitNamePrefix = strategy.getGroupName().replace("自定义", replaceString) + timestamp;
+            String unitNamePrefix = getUnitNamePrefix(strategy,replaceString,timestamp);
             int unitCnt = 0;
             for (KuaiShouVideoGet videoItem : newVideos) {
                 KuaishouAccountCreativeOverrunInfo overrunInfo = overrunInfoService.getByParams(accountId, DateUtils.formatDate(new Date()));
@@ -194,13 +210,20 @@ public class AiKuaishouCreateCreativeServiceImpl implements IAiKuaishouCreateCre
         }
     }
 
+    private String getUnitNamePrefix(AiKuaishouAdvertiserStrategy strategy,String replaceString,String timestamp){
+        String unitNamePrefix = strategy.getGroupName();
+        if(!unitNamePrefix.contains("自定义")){
+            unitNamePrefix += "-自定义-";
+        }
+        return unitNamePrefix.replace("自定义", replaceString) + timestamp;
+    }
     /**
      * 创建程序化创意
      *
      * @param strategy
      */
     @Override
-    public void autoCreateProgramCreative(AiKuaishouAdvertiserStrategy strategy, Integer createType, JSONObject params) {
+    public void autoCreateProgramCreative(AiKuaishouAdvertiserStrategy strategy, Integer createType, Integer videoCnt) {
         strategy.setUnitType(7);
         String replaceString = getReplaceStringByCreateType(strategy, createType);
         Long accountId = strategy.getAccountId();
@@ -211,11 +234,27 @@ public class AiKuaishouCreateCreativeServiceImpl implements IAiKuaishouCreateCre
         }
         //1:获取视频信息
         kuaishouInterfaceService.getVideoList(token, DateUtils.date2Str(), DateUtils.date2Str());
-        int timeStart = -10;
-        int timeEnd = -5;
+        Integer timeStart;
+        Integer timeEnd;
+        if(createType == 1){
+            timeStart = -10;
+            timeEnd = -5;
+        }else if(createType == 2){
+            //历史高质量
+            timeStart = -14*60*24;
+            timeEnd = -1*60*24;
+        }else if(createType == 3){
+            //历史遗漏
+            timeStart = -60*60*24;
+            timeEnd = -1*60*24;
+        }else{
+            //历史打捞
+            timeStart = -60*60*24;
+            timeEnd = -1*60*24;
+        }
         Long now = System.currentTimeMillis();
-        String startTime = DateUtils.formatDate(new Date(now + timeStart * 60 * 1000), DateUtils.NEW_FORMAT);
-        String endTime = DateUtils.formatDate(new Date(now + timeEnd * 60 * 1000), DateUtils.NEW_FORMAT);
+        String startTime = DateUtils.formatDate(now+timeStart*60*1000L);
+        String endTime = DateUtils.formatDate(now + timeEnd * 60 * 1000L);
 
         //2:判定账户是否单一应用
         Integer singleAppid = strategy.getSingleAppid();
@@ -250,7 +289,7 @@ public class AiKuaishouCreateCreativeServiceImpl implements IAiKuaishouCreateCre
                     Long newCampaignId = getCampaignId(strategy, token, replaceString, "ALL_CAMPAIGN");
                     //创建组
                     String timestamp = DateUtils.formatDate(new Date(), "yyyyMMddHHmmss");
-                    String unitNamePrefix = strategy.getGroupName().replace("自定义", replaceString) + timestamp;
+                    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);
@@ -271,9 +310,8 @@ public class AiKuaishouCreateCreativeServiceImpl implements IAiKuaishouCreateCre
             }
         } else {
             //单一应用
-            List<KuaiShouVideoGet> newVideos = videoGetService.getNewVideoBetweenTime(accountId, startTime, endTime, strategy.getChannelType(), null, 150);
-            if (null == newVideos || newVideos.isEmpty()) {
-                log.info("账户:{},{} 到 {} 这段时间没有上新素材", accountId, startTime, endTime);
+            List<KuaiShouVideoGet> allVideos = getVideosByParams(strategy, startTime, endTime, null, createType);
+            if (null == allVideos) {
                 return;
             }
 
@@ -281,36 +319,29 @@ public class AiKuaishouCreateCreativeServiceImpl implements IAiKuaishouCreateCre
             if (null == newCampaignId) {
                 return;
             }
-
-            //3、在“上新”计划中新增广告组,一个素材搭配n张封面,组成一个广告组
+            //创建组
             String timestamp = DateUtils.formatDate(new Date(), "yyyyMMddHHmmss");
-            String unitNamePrefix = strategy.getGroupName().replace("自定义", replaceString) + timestamp;
-            int unitCnt = 0;
-            for (KuaiShouVideoGet videoItem : newVideos) {
-                KuaishouAccountCreativeOverrunInfo overrunInfo = overrunInfoService.getByParams(accountId, DateUtils.formatDate(new Date()));
-                if (null != overrunInfo) {
-                    return;
-                }
-                unitCnt++;
-                String unitName = unitNamePrefix + "-" + unitCnt;
-                Long appId = JSON.parseArray(strategy.getAppIdArray()).getLong(0);
-                // 每个组,搭配n个创意
-                List<MaterialCutFrame> cutFrameList = materialCutFrameService.getListByVideoSignature(videoItem.getSignature());
-                if ((null == cutFrameList || cutFrameList.isEmpty())) {
-                    log.info("未获取到视频封面=>videoSignature:{}", videoItem.getSignature());
-                    continue;
-                }
-                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);
-                    continue;
-                }
-                Long unitId = (Long) unitCreateResult.get("unitId");
-                JSONObject creativeParams = creativeParams(token, unitId, videoItem, strategy);
-                createCreativeByImage(cutFrameList, token, creativeParams, newCampaignId, unitId, videoItem, strategy.getImageCnt());
+            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);
+            for (int j = 1; j < splitVideos.size() + 1; j++) {
+                JSONObject creativeParams = programCreativeParams(token, unitId, splitVideos.get(j - 1), strategy, j);
+                createProgramCreative(token, creativeParams);
             }
         }
     }
@@ -346,7 +377,7 @@ public class AiKuaishouCreateCreativeServiceImpl implements IAiKuaishouCreateCre
         JSONArray coverImageTokens = new JSONArray();
         for (KuaiShouVideoGet videoGet : list) {
             List<MaterialCutFrame> cutFrameList = materialCutFrameService.getListByVideoSignature(videoGet.getSignature());
-            if (Check.isNull(cutFrameList)) {
+            if (!Check.isNull(cutFrameList)) {
                 MaterialCutFrame cutFrame = cutFrameList.get(0);
                 String imageToken = getImageToken(cutFrame.getUrl(), cutFrame.getSignature(), token.getAccountId(), token.getAccessToken());
                 if (!Check.isNull(imageToken)) {
@@ -365,6 +396,8 @@ public class AiKuaishouCreateCreativeServiceImpl implements IAiKuaishouCreateCre
         if (coverImageTokens.size() >= 5) {
             coverImageTokens.remove(0);
         }
+        programJson.put("cover_image_tokens", coverImageTokens);
+
         if (!Check.isNull(strategy.getSiteId())) {
             programJson.put("site_id", strategy.getSiteId());
         }
@@ -381,6 +414,9 @@ public class AiKuaishouCreateCreativeServiceImpl implements IAiKuaishouCreateCre
         if (!Check.isNull(strategy.getActionbarClickUrl())) {
             programJson.put("actionbar_click_url", strategy.getActionbarClickUrl());
         }
+        JSONArray captions = new JSONArray();
+        captions.add(strategy.getDescription());
+        programJson.put("captions",captions);
         if (!Check.isNull(strategy.getCreativeCategory())) {
             programJson.put("creative_category", strategy.getCreativeCategory());
             programJson.put("creative_tag", JSON.parseArray(strategy.getCreativeTag()));
@@ -392,7 +428,7 @@ public class AiKuaishouCreateCreativeServiceImpl implements IAiKuaishouCreateCre
         List<KuaiShouVideoGet> generalVideos = videoGetService.getNewVideoBetweenTime(strategy.getAccountId(), startTime, endTime, strategy.getChannelType(), null, null);
         //2:查询特定素材
         List<KuaiShouVideoGet> customVideos = videoGetService.getNewVideoBetweenTime(strategy.getAccountId(), startTime, endTime, strategy.getChannelType(), appInfo.getAppVersion(), null);
-        if ((null == generalVideos || generalVideos.isEmpty()) &&(null == customVideos || customVideos.isEmpty())) {
+        if (Check.isNull(generalVideos) && Check.isNull(customVideos)) {
             log.info("账户:{},appId({}){}到{}这段时间没有上新素材", strategy.getAccountId(), appInfo.getAppId(), startTime, endTime);
             return new ArrayList<>();
         }
@@ -407,12 +443,16 @@ public class AiKuaishouCreateCreativeServiceImpl implements IAiKuaishouCreateCre
         }
     }
 
-    private List<KuaiShouVideoGet> getRelateZeroVideoList(AiKuaishouAdvertiserStrategy strategy, String startTime, String endTime, AiKuaiShouAppInfo appInfo) {
+    private List<KuaiShouVideoGet> getRelateZeroVideoList(AiKuaishouAdvertiserStrategy strategy, String startTime, String endTime, AiKuaiShouAppInfo appInfo,Integer relativeCnt) {
         Integer channelType = null;
         if (null != strategy.getChannelType() && strategy.getChannelType() != 2) {
             channelType = strategy.getChannelType();
         }
-        return videoGetService.getZeroVideoByParams(strategy.getAccountId(), startTime, endTime, 100, appInfo.getAppVersion(), channelType);
+        String appVersion  = null;
+        if(null!=appInfo&&null!=appInfo.getAppVersion()){
+            appVersion = appInfo.getAppVersion();
+        }
+        return videoGetService.getZeroVideoByParams(strategy.getAccountId(), startTime, endTime, 100, appVersion, channelType,relativeCnt);
     }
 
     private List<KuaiShouVideoGet> getHistoryTopVideoListByParams(AiKuaishouAdvertiserStrategy strategy, String startTime, String endTime, AiKuaiShouAppInfo appInfo) {
@@ -420,14 +460,18 @@ public class AiKuaishouCreateCreativeServiceImpl implements IAiKuaishouCreateCre
         if (null != strategy.getChannelType() && strategy.getChannelType() != 2) {
             channelType = strategy.getChannelType();
         }
-        return videoGetService.getHistoryTopVideoByParams(strategy.getAccountId(), startTime, endTime, 100, appInfo.getAppVersion(), channelType);
+        String appVersion  = null;
+        if(null!=appInfo&&null!=appInfo.getAppVersion()){
+            appVersion = appInfo.getAppVersion();
+        }
+        return videoGetService.getHistoryTopVideoByParams(strategy.getAccountId(), startTime, endTime, 100, appVersion, channelType);
     }
 
     /**
      * 创建自定义创意
      *
      * @param strategy   账户配置信息
-     * @param createType 创意创建类型 1:素材上新 2:历史高质量 3:历史遗漏素材
+     * @param createType 创意创建类型 1:素材上新 2:历史高质量 3:历史遗漏素材 4:历史素材打捞
      * @param startTime  开始时间
      * @param endTime    结束时间
      */
@@ -436,8 +480,10 @@ public class AiKuaishouCreateCreativeServiceImpl implements IAiKuaishouCreateCre
             return getNewVideoListByParams(strategy, startTime, endTime, appInfo);
         } else if (createType == 2) {
             return getHistoryTopVideoListByParams(strategy, startTime, endTime, appInfo);
-        } else {
-            return getRelateZeroVideoList(strategy, startTime, endTime, appInfo);
+        } else if(createType==3){
+            return getRelateZeroVideoList(strategy, startTime, endTime, appInfo,0);
+        }else{
+            return getRelateZeroVideoList(strategy, startTime, endTime, appInfo,20);
         }
     }
 
@@ -463,7 +509,11 @@ public class AiKuaishouCreateCreativeServiceImpl implements IAiKuaishouCreateCre
         // 不存在“上新”计划,则创建一个计划
         JSONObject campaignParams = new JSONObject();
         campaignParams.put("advertiser_id", token.getAccountId());
-        String campaignName = strategy.getCampaignName().replace("自定义", replaceString) + timestamp;
+        String campaignName = strategy.getCampaignName();
+        if(!campaignName.contains("自定义")){
+            campaignName+= "-自定义-";
+        }
+        campaignName =campaignName.replace("自定义", replaceString) + timestamp;
         campaignParams.put("campaign_name", campaignName);
         campaignParams.put("type", strategy.getCampaignType());
         //TODO 目前设定为不限
@@ -501,6 +551,8 @@ public class AiKuaishouCreateCreativeServiceImpl implements IAiKuaishouCreateCre
         //组单日预算
         if(null!=strategy.getUnitDayBudget()&&strategy.getUnitDayBudget()!=0){
             unitParams.put("day_budget",strategy.getUnitDayBudget());
+        }else{
+            unitParams.put("day_budget",0);
         }
         //应用商店列表
         if (null != strategy.getAppStore() && !"".equals(strategy.getAppStore())) {
@@ -538,7 +590,7 @@ public class AiKuaishouCreateCreativeServiceImpl implements IAiKuaishouCreateCre
         //资源位置
         Integer sceneId = null;
         String scenceIdString = strategy.getSceneId();
-        if (!Check.isNull(scenceIdString) && Check.isNull(JSON.parseArray(scenceIdString))) {
+        if (!Check.isNull(scenceIdString) && !Check.isNull(JSON.parseArray(scenceIdString))) {
             sceneId = JSON.parseArray(strategy.getSceneId()).getInteger(0);
             unitParams.put("scene_id", JSON.parseArray(strategy.getSceneId()));
         }
@@ -546,6 +598,8 @@ public class AiKuaishouCreateCreativeServiceImpl implements IAiKuaishouCreateCre
         //投放开始时间
         if (!Check.isNull(strategy.getBeginTime())) {
             unitParams.put("begin_time", strategy.getBeginTime());
+        }else {
+            unitParams.put("begin_time",DateUtils.formatDate());
         }
         //投放结束时间
         if (!Check.isNull(strategy.getEndTime())) {

+ 1 - 1
module-kuaishou/src/main/java/cn/com/ctop/kuaishou/modules/batch/controller/KuaishouBatchCampaignPreviewController.java

@@ -120,7 +120,7 @@ public class KuaishouBatchCampaignPreviewController {
     /**
      * 添加
      *
-     * @param kuaishouBatchCampaignPreview
+     * @param data
      * @return
      */
     @AutoLog(value = "添加预览数据")

+ 1 - 1
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);
+    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> 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);
 }

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

@@ -207,7 +207,11 @@
         from
         ctop_kuaishou_video_get video left join ctop_kuaishou_video_relate_creatives creative on video.photo_id = creative.photo_id and video.account_id = creative.account_id
         where
-        creative.creative_count =0
+              1=1
+        <if test="relativeCnt!=null">
+           and creative.creative_count &lt;= #{relativeCnt}
+        </if>
+
         <if test="accountId!=null">
             and video.account_id = #{accountId}
         </if>

+ 1 - 1
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);
+    List<KuaiShouVideoGet> getZeroVideoByParams(Long accountId, String startTime, String endTime, Integer videoCnt,String appVersion,Integer channelType,Integer relativeCnt);
 
     List<KuaiShouVideoGet> getHistoryTopVideoByParams(Long accountId, String startTime, String endTime, Integer videoCnt, String appVersion, Integer channelType);
 }

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

@@ -548,8 +548,6 @@ public class KuaiShouUpdateServiceImpl implements IKuaiShouUpdateService {
             Map<String, String> headers = new HashMap<>();
             headers.put("Access-Token", accessToken);
             headers.put("Content-Type", "application/json");
-
-
             String result = HttpUtils.kuaiShouhttpPostRequest(url, requestJson.toJSONString(), headers);
             JSONObject resultJson = JSONObject.parseObject(result);
             if (!Check.isNull(resultJson)) {
@@ -579,8 +577,6 @@ public class KuaiShouUpdateServiceImpl implements IKuaiShouUpdateService {
             returnJson.put("code", -1);
             returnJson.put("message", e.getMessage());
         }
-
-
         return returnJson;
     }
 
@@ -615,7 +611,6 @@ public class KuaiShouUpdateServiceImpl implements IKuaiShouUpdateService {
                         } catch (InterruptedException e) {
                             e.printStackTrace();
                         }
-
                         returnJson.put("code", 0);
                     } else {
                         returnJson.put("code", -1);

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

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

+ 5 - 6
module-kuaishou/src/main/java/cn/com/ctop/kuaishou/modules/batch/service/impl/KuaishouBatchCampaignPreviewServiceImpl.java

@@ -25,6 +25,7 @@ import org.jeecg.common.util.DateUtils;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.stereotype.Service;
 
+import javax.annotation.Resource;
 import java.util.ArrayList;
 import java.util.HashMap;
 import java.util.List;
@@ -41,19 +42,17 @@ import java.util.regex.Pattern;
  */
 @Service
 public class KuaishouBatchCampaignPreviewServiceImpl extends ServiceImpl<KuaishouBatchCampaignPreviewMapper, KuaishouBatchCampaignPreview> implements IKuaishouBatchCampaignPreviewService {
-
-
-    @Autowired
+    @Resource
     KuaishouBatchCampaignPreviewMapper campaignPreviewMapper;
-    @Autowired
+    @Resource
     KuaishouBatchGroupPreviewMapper groupPreviewMapper;
-    @Autowired
+    @Resource
     KuaishouBatchCreativePreviewMapper creativePreviewMapper;
     @Autowired
     private IKuaishouTemplateService kuaishouTemplateService;
     @Autowired
     private IKuaiShouAppListService kuaiShouAppListService;
-    @Autowired
+    @Resource
     private KuaiShouCampaignMapper kuaiShouCampaignMapper;
 
     @Override