Prechádzať zdrojové kódy

快手自动投放账户程序化创意创建

syh 4 rokov pred
rodič
commit
68142fb7c3

+ 2 - 4
module-common/src/main/java/cn/com/ctop/common/module/service/impl/MaterialTagInfoServiceImpl.java

@@ -11,15 +11,13 @@ import cn.com.ctop.common.module.utils.ResultMapUtils;
 import cn.com.ctop.common.module.utils.StatusCode;
 import com.alibaba.fastjson.JSONArray;
 import com.alibaba.fastjson.JSONObject;
-import com.baomidou.mybatisplus.core.conditions.Wrapper;
 import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
-import com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper;
 import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
 import org.jeecg.common.system.vo.LoginUser;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.stereotype.Service;
 
-import java.util.Date;
+import javax.annotation.Resource;
 import java.util.HashMap;
 import java.util.List;
 import java.util.Map;
@@ -36,7 +34,7 @@ public class MaterialTagInfoServiceImpl extends ServiceImpl<MaterialTagInfoMappe
     private IMaterialInfoService materialInfoService;
     @Autowired
     private ITagInfoService tagInfoService;
-    @Autowired
+    @Resource
     private MaterialTagInfoMapper materialTagInfoMapper;
     @Override
     public Map<String, Object> mark(JSONObject data, LoginUser user) {

+ 0 - 1
module-kuaishou/src/main/java/cn/com/ctop/kuaishou/modules/ai/controller/KuaiShouMaterialControer.java

@@ -215,7 +215,6 @@ public class KuaiShouMaterialControer {
      */
     @PostMapping(value = "/getHistoryTopVideoList")
     public JSONObject getHistoryTopVideoList(@RequestBody JSONObject requestJson) {
-        //   log.info("获取历史Top素材入参:{}", requestJson);
         JSONObject returnJson = new JSONObject();
         try {
             if (Check.isNull(requestJson)) {

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

@@ -201,6 +201,12 @@ public class AiKuaishouAdvertiserStrategy {
 	 */
 	private String appIdArray;
 	private Integer openProgramCreate;
+
+	private Long campaignDayBudget;
+	private String campaignDayBudgetSchedule;
+	private Long unitDayBudget;
+	private String unitDayBudgetSchedule;
+
 	@TableField(exist = false)
 	private String authName;
 }

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

@@ -1,9 +1,10 @@
 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);
+    void autoCreateCreative(AiKuaishouAdvertiserStrategy strategy, Integer createType, JSONObject params);
 
-    void autoCreateProgramCreative(AiKuaishouAdvertiserStrategy strategy);
+    void autoCreateProgramCreative(AiKuaishouAdvertiserStrategy strategy,Integer createType,JSONObject params);
 }

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

@@ -4,9 +4,10 @@ import cn.com.ctop.kuaishou.modules.ai.entity.AiCreativeLimit;
 import cn.com.ctop.kuaishou.modules.ai.mapper.AiCreativeLimitMapper;
 import cn.com.ctop.kuaishou.modules.ai.service.IAiCreativeLimitService;
 import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
-import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.stereotype.Service;
 
+import javax.annotation.Resource;
+
 /**
  * 关联数超限
  *
@@ -16,7 +17,7 @@ import org.springframework.stereotype.Service;
  */
 @Service
 public class AiCreativeLimitServiceImpl extends ServiceImpl<AiCreativeLimitMapper, AiCreativeLimit> implements IAiCreativeLimitService {
-    @Autowired
+    @Resource
     private AiCreativeLimitMapper creativeLimitMapper;
 
     @Override

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

@@ -52,67 +52,84 @@ public class AiKuaishouCreateCreativeServiceImpl implements IAiKuaishouCreateCre
     @Autowired
     private IAiKuaiShouAppInfoService appInfoService;
 
+    String getReplaceStringByCreateType(AiKuaishouAdvertiserStrategy strategy, Integer createType) {
+        String replaceString;
+        if (createType == 2) {
+            replaceString = "历史高质量";
+        } else if (createType == 3) {
+            replaceString = "素材上新";
+        } else {
+            replaceString = "素材上新";
+        }
+        if (strategy.getUnitType() == 7) {
+            replaceString = "程序化" + replaceString;
+        }
+        return replaceString;
+    }
 
     /**
      * 创建自定义创意
-     * @param strategy
+     *
+     * @param strategy   账户配置信息
+     * @param createType 创意创建类型 1:素材上新 2:历史高质量 3:历史遗漏素材
+     * @param params     需要拼装的参数
      */
     @Override
-    public void autoCreateCreative(AiKuaishouAdvertiserStrategy strategy){
+    public void autoCreateCreative(AiKuaishouAdvertiserStrategy strategy, Integer createType, JSONObject params) {
         strategy.setUnitType(4);
-        String replaceString = "素材上新";
+        String replaceString = getReplaceStringByCreateType(strategy, createType);
         Long accountId = strategy.getAccountId();
         CtopOauthToken token = tokenService.getOauthTokenByAccountId(accountId.toString());
-        if(null == token){
-            log.info("token获取失败=>accountId:{}",accountId);
+        if (null == token) {
+            log.info("token获取失败=>accountId:{}", accountId);
             return;
         }
         //1:获取视频信息
-        kuaishouInterfaceService.getVideoList(token, DateUtils.date2Str(),DateUtils.date2Str());
+        kuaishouInterfaceService.getVideoList(token, DateUtils.date2Str(), DateUtils.date2Str());
         int timeStart = -10;
         int timeEnd = -5;
         Long now = System.currentTimeMillis();
-        String startTime = DateUtils.formatDate(new Date(now + timeStart*60*1000),"yyyy-MM-dd HH:mm:ss");
-        String endTime = DateUtils.formatDate(new Date(now + timeEnd*60*1000),"yyyy-MM-dd HH:mm:ss");
+        String startTime = DateUtils.formatDate(new Date(now + timeStart * 60 * 1000), "yyyy-MM-dd HH:mm:ss");
+        String endTime = DateUtils.formatDate(new Date(now + timeEnd * 60 * 1000), "yyyy-MM-dd HH:mm:ss");
 
         //2:判定账户是否单一应用
         Integer singleAppid = strategy.getSingleAppid();
-        if(null!=singleAppid&&singleAppid==0){
+        if (null != singleAppid && singleAppid == 0) {
             //非单一应用
             String appidString = strategy.getAppIdArray();
             JSONArray appIdArray = JSONArray.parseArray(appidString);
-            if(null!=appIdArray&&!appIdArray.isEmpty()){
-                for(int i=0;i<appIdArray.size();i++){
-                    AiKuaiShouAppInfo appInfo = appInfoService.getByParams(strategy.getAccountId(),appIdArray.getLong(i));
-                    if(null == appInfo){
-                        log.info("账户:{},appid({}) 数据不存在",accountId, appIdArray.getLong(i));
+            if (null != appIdArray && !appIdArray.isEmpty()) {
+                for (int i = 0; i < appIdArray.size(); i++) {
+                    AiKuaiShouAppInfo appInfo = appInfoService.getByParams(strategy.getAccountId(), appIdArray.getLong(i));
+                    if (null == appInfo) {
+                        log.info("账户:{},appid({}) 数据不存在", accountId, appIdArray.getLong(i));
                         continue;
                     }
-                    if(null!=strategy.getGeneralTrack()&&strategy.getGeneralTrack() == 0){
+                    if (null != strategy.getGeneralTrack() && strategy.getGeneralTrack() == 0) {
                         strategy.setClickTrackUrl(appInfo.getTrackUrl());
                         strategy.setImpressionUrl(appInfo.getTrackUrl());
                     }
-                    replaceString = appInfo.getAppVersion()+replaceString;
-                    //1:查询通用素材
-                    List<KuaiShouVideoGet> allVideos = getVideosByParams(strategy,startTime,endTime,appInfo);
-                    if(null == allVideos||allVideos.isEmpty()){
+                    replaceString = appInfo.getAppVersion() + replaceString;
+                    //1:查询素材
+                    List<KuaiShouVideoGet> allVideos = getVideosByParams(strategy, startTime, endTime, appInfo, createType);
+                    if (null == allVideos || allVideos.isEmpty()) {
                         return;
                     }
-                    Long newCampaignId = getCampaignId(strategy,token,replaceString,"ALL_CAMPAIGN");
+                    Long newCampaignId = getCampaignId(strategy, token, replaceString, "ALL_CAMPAIGN");
 
                     //开始创建组+创意
-                    String timestamp = DateUtils.formatDate(new Date(),"yyyyMMddHHmmss");
-                    String unitNamePrefix = strategy.getGroupName().replace("自定义",replaceString)+ timestamp;
+                    String timestamp = DateUtils.formatDate(new Date(), "yyyyMMddHHmmss");
+                    String unitNamePrefix = strategy.getGroupName().replace("自定义", replaceString) + timestamp;
                     int unitCnt = 0;
-                    for(KuaiShouVideoGet videoItem: allVideos) {
+                    for (KuaiShouVideoGet videoItem : allVideos) {
                         KuaishouAccountCreativeOverrunInfo overrunInfo = overrunInfoService.getByParams(accountId, DateUtils.formatDate(new Date()));
                         if (null != overrunInfo) {
-                            log.info("该账户创意创建已超限=>accountId:{}",accountId);
+                            log.info("该账户创意创建已超限=>accountId:{}", accountId);
                             return;
                         }
                         unitCnt++;
                         String unitName = unitNamePrefix + "-" + unitCnt;
-                        JSONObject unitParams = createUnitParams(token, newCampaignId, strategy, unitName,appInfo.getAppId());
+                        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");
@@ -133,23 +150,23 @@ public class AiKuaishouCreateCreativeServiceImpl implements IAiKuaishouCreateCre
                     }
                 }
             }
-        }else{
+        } else {
             //单一应用
-            List<KuaiShouVideoGet> newVideos = videoGetService.getNewVideoBetweenTime(accountId,startTime,endTime,strategy.getChannelType(),null,null);
-            if (null == newVideos ||newVideos.isEmpty()){
-                log.info("账户:{},{} 到 {} 这段时间没有上新素材",accountId, startTime, endTime);
+            List<KuaiShouVideoGet> newVideos = videoGetService.getNewVideoBetweenTime(accountId, startTime, endTime, strategy.getChannelType(), null, null);
+            if (null == newVideos || newVideos.isEmpty()) {
+                log.info("账户:{},{} 到 {} 这段时间没有上新素材", accountId, startTime, endTime);
                 return;
             }
-            Long newCampaignId = getCampaignId(strategy,token,replaceString,"TODAY");
-            if(null== newCampaignId){
+            Long newCampaignId = getCampaignId(strategy, token, replaceString, "TODAY");
+            if (null == newCampaignId) {
                 return;
             }
 
             //3、在“上新”计划中新增广告组,一个素材搭配n张封面,组成一个广告组
-            String timestamp = DateUtils.formatDate(new Date(),"yyyyMMddHHmmss");
-            String unitNamePrefix = strategy.getGroupName().replace("自定义",replaceString)+ timestamp;
+            String timestamp = DateUtils.formatDate(new Date(), "yyyyMMddHHmmss");
+            String unitNamePrefix = strategy.getGroupName().replace("自定义", replaceString) + timestamp;
             int unitCnt = 0;
-            for(KuaiShouVideoGet videoItem: newVideos) {
+            for (KuaiShouVideoGet videoItem : newVideos) {
                 KuaishouAccountCreativeOverrunInfo overrunInfo = overrunInfoService.getByParams(accountId, DateUtils.formatDate(new Date()));
                 if (null != overrunInfo) {
                     return;
@@ -157,7 +174,7 @@ public class AiKuaishouCreateCreativeServiceImpl implements IAiKuaishouCreateCre
                 unitCnt++;
                 String unitName = unitNamePrefix + "-" + unitCnt;
                 Long appId = JSONArray.parseArray(strategy.getAppIdArray()).getLong(0);
-                JSONObject unitParams = createUnitParams(token, newCampaignId, strategy, unitName,appId);
+                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");
@@ -181,56 +198,58 @@ public class AiKuaishouCreateCreativeServiceImpl implements IAiKuaishouCreateCre
 
     /**
      * 创建程序化创意
+     *
      * @param strategy
      */
     @Override
-    public void autoCreateProgramCreative(AiKuaishouAdvertiserStrategy strategy){
+    public void autoCreateProgramCreative(AiKuaishouAdvertiserStrategy strategy, Integer createType, JSONObject params) {
         strategy.setUnitType(7);
-        String replaceString = "程序化自动上新";
+        String replaceString = getReplaceStringByCreateType(strategy, createType);
+        ;
         Long accountId = strategy.getAccountId();
         CtopOauthToken token = tokenService.getOauthTokenByAccountId(accountId.toString());
-        if(null == token){
-            log.info("token获取失败=>accountId:{}",accountId);
+        if (null == token) {
+            log.info("token获取失败=>accountId:{}", accountId);
             return;
         }
         //1:获取视频信息
-        kuaishouInterfaceService.getVideoList(token, DateUtils.date2Str(),DateUtils.date2Str());
+        kuaishouInterfaceService.getVideoList(token, DateUtils.date2Str(), DateUtils.date2Str());
         int timeStart = -10;
         int timeEnd = -5;
         Long now = System.currentTimeMillis();
-        String startTime = DateUtils.formatDate(new Date(now + timeStart*60*1000),"yyyy-MM-dd HH:mm:ss");
-        String endTime = DateUtils.formatDate(new Date(now + timeEnd*60*1000),"yyyy-MM-dd HH:mm:ss");
+        String startTime = DateUtils.formatDate(new Date(now + timeStart * 60 * 1000), "yyyy-MM-dd HH:mm:ss");
+        String endTime = DateUtils.formatDate(new Date(now + timeEnd * 60 * 1000), "yyyy-MM-dd HH:mm:ss");
 
         //2:判定账户是否单一应用
         Integer singleAppid = strategy.getSingleAppid();
-        if(null!=singleAppid&&singleAppid==0){
+        if (null != singleAppid && singleAppid == 0) {
             //非单一应用
             String appidString = strategy.getAppIdArray();
             JSONArray appIdArray = JSONArray.parseArray(appidString);
-            if(null!=appIdArray&&!appIdArray.isEmpty()){
-                for(int i=0;i<appIdArray.size();i++){
-                    AiKuaiShouAppInfo appInfo = appInfoService.getByParams(strategy.getAccountId(),appIdArray.getLong(i));
-                    if(null == appInfo){
-                        log.info("账户:{},appid({}) 数据不存在",accountId, appIdArray.getLong(i));
+            if (null != appIdArray && !appIdArray.isEmpty()) {
+                for (int i = 0; i < appIdArray.size(); i++) {
+                    AiKuaiShouAppInfo appInfo = appInfoService.getByParams(strategy.getAccountId(), appIdArray.getLong(i));
+                    if (null == appInfo) {
+                        log.info("账户:{},appid({}) 数据不存在", accountId, appIdArray.getLong(i));
                         continue;
                     }
                     //判定是否通用监测链接
-                    if(null!=strategy.getGeneralTrack()&&strategy.getGeneralTrack() == 0){
+                    if (null != strategy.getGeneralTrack() && strategy.getGeneralTrack() == 0) {
                         strategy.setClickTrackUrl(appInfo.getTrackUrl());
                         strategy.setImpressionUrl(appInfo.getTrackUrl());
                     }
-                    replaceString = appInfo.getAppVersion()+replaceString;
+                    replaceString = appInfo.getAppVersion() + replaceString;
                     //1:查询可用素材
-                    List<KuaiShouVideoGet> allVideos = getVideosByParams(strategy,startTime,endTime,appInfo);
-                    if(null == allVideos){
+                    List<KuaiShouVideoGet> allVideos = getVideosByParams(strategy, startTime, endTime, appInfo, createType);
+                    if (null == allVideos) {
                         return;
                     }
-                    Long newCampaignId = getCampaignId(strategy,token,replaceString,"ALL_CAMPAIGN");
+                    Long newCampaignId = getCampaignId(strategy, token, replaceString, "ALL_CAMPAIGN");
                     //创建组
-                    String timestamp = DateUtils.formatDate(new Date(),"yyyyMMddHHmmss");
-                    String unitNamePrefix = strategy.getGroupName().replace("自定义",replaceString)+ timestamp;
+                    String timestamp = DateUtils.formatDate(new Date(), "yyyyMMddHHmmss");
+                    String unitNamePrefix = strategy.getGroupName().replace("自定义", replaceString) + timestamp;
                     String unitName = unitNamePrefix + "-" + timestamp;
-                    JSONObject unitParams = createUnitParams(token, newCampaignId, strategy, unitName,appInfo.getAppId());
+                    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");
@@ -240,37 +259,37 @@ public class AiKuaishouCreateCreativeServiceImpl implements IAiKuaishouCreateCre
                     }
                     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++) {
+                    List<List<KuaiShouVideoGet>> splitVideos = new ListUtils<KuaiShouVideoGet>().split(allVideos, allVideos.size() / 5);
+                    for (int j = 1; j < splitVideos.size() + 1; j++) {
                         KuaishouAccountCreativeOverrunInfo overrunInfo = overrunInfoService.getByParams(accountId, DateUtils.formatDate(new Date()));
                         if (null != overrunInfo) {
-                            log.info("该账户创意创建已超限=>accountId:{}",accountId);
+                            log.info("该账户创意创建已超限=>accountId:{}", accountId);
                             return;
                         }
 
-                        JSONObject creativeParams = programCreativeParams(token, unitId, splitVideos.get(j-1), strategy,j);
+                        JSONObject creativeParams = programCreativeParams(token, unitId, splitVideos.get(j - 1), strategy, j);
                         createProgramCreative(token, creativeParams);
                     }
                 }
             }
-        }else{
+        } 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> newVideos = videoGetService.getNewVideoBetweenTime(accountId, startTime, endTime, strategy.getChannelType(), null, 150);
+            if (null == newVideos || newVideos.isEmpty()) {
+                log.info("账户:{},{} 到 {} 这段时间没有上新素材", accountId, startTime, endTime);
                 return;
             }
 
-            Long newCampaignId = getCampaignId(strategy,token,replaceString,"TODAY");
-            if(null== newCampaignId){
+            Long newCampaignId = getCampaignId(strategy, token, replaceString, "TODAY");
+            if (null == newCampaignId) {
                 return;
             }
 
             //3、在“上新”计划中新增广告组,一个素材搭配n张封面,组成一个广告组
-            String timestamp = DateUtils.formatDate(new Date(),"yyyyMMddHHmmss");
-            String unitNamePrefix = strategy.getGroupName().replace("自定义",replaceString)+ timestamp;
+            String timestamp = DateUtils.formatDate(new Date(), "yyyyMMddHHmmss");
+            String unitNamePrefix = strategy.getGroupName().replace("自定义", replaceString) + timestamp;
             int unitCnt = 0;
-            for(KuaiShouVideoGet videoItem: newVideos) {
+            for (KuaiShouVideoGet videoItem : newVideos) {
                 KuaishouAccountCreativeOverrunInfo overrunInfo = overrunInfoService.getByParams(accountId, DateUtils.formatDate(new Date()));
                 if (null != overrunInfo) {
                     return;
@@ -278,7 +297,7 @@ public class AiKuaishouCreateCreativeServiceImpl implements IAiKuaishouCreateCre
                 unitCnt++;
                 String unitName = unitNamePrefix + "-" + unitCnt;
                 Long appId = JSONArray.parseArray(strategy.getAppIdArray()).getLong(0);
-                JSONObject unitParams = createUnitParams(token, newCampaignId, strategy, unitName,appId);
+                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");
@@ -314,7 +333,7 @@ public class AiKuaishouCreateCreativeServiceImpl implements IAiKuaishouCreateCre
         }
         Integer code = resultJson.getInteger("code");
         String message = resultJson.getString("message");
-        if (null==code||code!=0) {
+        if (null == code || code != 0) {
             log.error("创建程序化创意失败,accountId:{},返回结果:{},入参:{}", token.getAccountId(), message, creativeParams);
             return;
         }
@@ -322,37 +341,37 @@ public class AiKuaishouCreateCreativeServiceImpl implements IAiKuaishouCreateCre
         return;
     }
 
-    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) {
         JSONObject programJson = new JSONObject();
         programJson.put("advertiser_id", token.getAccountId());
         programJson.put("unit_id", unitId);
-        programJson.put("package_name", "程序化创意"+creativeCnt);
+        programJson.put("package_name", "程序化创意" + creativeCnt);
         JSONArray horizontalPhotoIds = new JSONArray();
         JSONArray verticalPhotoIds = new JSONArray();
         JSONArray coverImageTokens = new JSONArray();
-        for(KuaiShouVideoGet videoGet:list){
+        for (KuaiShouVideoGet videoGet : list) {
             List<MaterialCutFrame> cutFrameList = materialCutFrameService.getListByVideoSignature(videoGet.getSignature());
-            if (null!=cutFrameList&&!cutFrameList.isEmpty()){
+            if (null != cutFrameList && !cutFrameList.isEmpty()) {
                 MaterialCutFrame cutFrame = cutFrameList.get(0);
-                String imageToken = getImageToken(cutFrame.getUrl(),cutFrame.getSignature(), token.getAccountId(), token.getAccessToken());
+                String imageToken = getImageToken(cutFrame.getUrl(), cutFrame.getSignature(), token.getAccountId(), token.getAccessToken());
                 if (!Check.isNull(imageToken)) {
                     coverImageTokens.add(imageToken);
                 }
             }
-            if(videoGet.getMaterialType() == 2){
+            if (videoGet.getMaterialType() == 2) {
                 horizontalPhotoIds.add(videoGet.getPhotoId());
             }
-            if(videoGet.getMaterialType() == 1){
+            if (videoGet.getMaterialType() == 1) {
                 verticalPhotoIds.add(videoGet.getPhotoId());
             }
         }
-        if(!horizontalPhotoIds.isEmpty()){
+        if (!horizontalPhotoIds.isEmpty()) {
             programJson.put("horizontal_photo_ids", horizontalPhotoIds);
         }
-        if(!verticalPhotoIds.isEmpty()){
+        if (!verticalPhotoIds.isEmpty()) {
             programJson.put("vertical_photo_ids", verticalPhotoIds);
         }
-        if(coverImageTokens.size()>=5){
+        if (coverImageTokens.size() >= 5) {
             coverImageTokens.remove(0);
         }
         if (!Check.isNull(strategy.getSiteId())) {
@@ -385,41 +404,74 @@ public class AiKuaishouCreateCreativeServiceImpl implements IAiKuaishouCreateCre
         return programJson;
     }
 
-    private List<KuaiShouVideoGet> getVideosByParams(AiKuaishouAdvertiserStrategy strategy,String startTime,String endTime,AiKuaiShouAppInfo appInfo) {
-        List<KuaiShouVideoGet> generalVideos = videoGetService.getNewVideoBetweenTime(strategy.getAccountId(),startTime,endTime,strategy.getChannelType(),null,null);
+    private List<KuaiShouVideoGet> getNewVideoListByParams(AiKuaishouAdvertiserStrategy strategy, String startTime, String endTime, AiKuaiShouAppInfo appInfo) {
+        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()){
-            log.info("账户:{},appId({}){}到{}这段时间没有上新素材",strategy.getAccountId(),appInfo.getAppId(),startTime, endTime);
+        List<KuaiShouVideoGet> customVideos = videoGetService.getNewVideoBetweenTime(strategy.getAccountId(), startTime, endTime, strategy.getChannelType(), appInfo.getAppVersion(), null);
+        if (null == generalVideos || generalVideos.isEmpty() || null == customVideos || customVideos.isEmpty()) {
+            log.info("账户:{},appId({}){}到{}这段时间没有上新素材", strategy.getAccountId(), appInfo.getAppId(), startTime, endTime);
             return null;
         }
-
         //合并
-        if(null == generalVideos||generalVideos.isEmpty()){
+        if (null == generalVideos || generalVideos.isEmpty()) {
             return customVideos;
-        }else if(null == customVideos||customVideos.isEmpty()){
+        } else if (null == customVideos || customVideos.isEmpty()) {
             return generalVideos;
-        }else {
+        } else {
             generalVideos.addAll(customVideos);
             return generalVideos;
         }
     }
 
-    private Long getCampaignId(AiKuaishouAdvertiserStrategy strategy,CtopOauthToken token,String replaceString,String checkType) {
+    private List<KuaiShouVideoGet> getRelateZeroVideoList(AiKuaishouAdvertiserStrategy strategy, String startTime, String endTime, AiKuaiShouAppInfo appInfo) {
+        Integer channelType = null;
+        if (null != strategy.getChannelType() && strategy.getChannelType() != 2) {
+            channelType = strategy.getChannelType();
+        }
+        return videoGetService.getZeroVideoByParams(strategy.getAccountId(), startTime, endTime, 100, appInfo.getAppVersion(), channelType);
+    }
+
+    private List<KuaiShouVideoGet> getHistoryTopVideoListByParams(AiKuaishouAdvertiserStrategy strategy, String startTime, String endTime, AiKuaiShouAppInfo appInfo) {
+        Integer channelType = null;
+        if (null != strategy.getChannelType() && strategy.getChannelType() != 2) {
+            channelType = strategy.getChannelType();
+        }
+        return videoGetService.getHistoryTopVideoByParams(strategy.getAccountId(), startTime, endTime, 100, appInfo.getAppVersion(), channelType);
+    }
+
+    /**
+     * 创建自定义创意
+     *
+     * @param strategy   账户配置信息
+     * @param createType 创意创建类型 1:素材上新 2:历史高质量 3:历史遗漏素材
+     * @param startTime  开始时间
+     * @param endTime    结束时间
+     */
+    private List<KuaiShouVideoGet> getVideosByParams(AiKuaishouAdvertiserStrategy strategy, String startTime, String endTime, AiKuaiShouAppInfo appInfo, Integer createType) {
+        if (createType == 1) {
+            return getNewVideoListByParams(strategy, startTime, endTime, appInfo);
+        } else if (createType == 2) {
+            return getHistoryTopVideoListByParams(strategy, startTime, endTime, appInfo);
+        } else {
+            return getRelateZeroVideoList(strategy, startTime, endTime, appInfo);
+        }
+    }
+
+    private Long getCampaignId(AiKuaishouAdvertiserStrategy strategy, CtopOauthToken token, String replaceString, String checkType) {
         JSONArray campaignList = null;
         Date campaignDate = new Date();
         String timestamp = "";
-        if(null!=checkType&&checkType.equals("ALL_CAMPAIGN")){
-            campaignList = kuaishouInterfaceService.getCampaignList(token, null, null,1);
-        }else{
-            timestamp = DateUtils.formatDate(campaignDate,"yyyyMMddHHmmss");
-            campaignList = kuaishouInterfaceService.getCampaignList(token, new Date(), new Date(),1);
+        if (null != checkType && checkType.equals("ALL_CAMPAIGN")) {
+            campaignList = kuaishouInterfaceService.getCampaignList(token, null, null, 1);
+        } else {
+            timestamp = DateUtils.formatDate(campaignDate, "yyyyMMddHHmmss");
+            campaignList = kuaishouInterfaceService.getCampaignList(token, new Date(), new Date(), 1);
         }
         Long newCampaignId = 0L;
-        if (null!=campaignList&&campaignList.size()>0){
-            for(int i = 0;i<campaignList.size();i++){
+        if (null != campaignList && campaignList.size() > 0) {
+            for (int i = 0; i < campaignList.size(); i++) {
                 JSONObject jsonObject = campaignList.getJSONObject(i);
-                if (jsonObject.getString("campaign_name").contains(replaceString)){
+                if (jsonObject.getString("campaign_name").contains(replaceString)) {
                     newCampaignId = jsonObject.getLong("campaign_id");
                     return newCampaignId;
                 }
@@ -427,18 +479,18 @@ public class AiKuaishouCreateCreativeServiceImpl implements IAiKuaishouCreateCre
         }
         // 不存在“上新”计划,则创建一个计划
         JSONObject campaignParams = new JSONObject();
-        campaignParams.put("advertiser_id",token.getAccountId());
-        String campaignName = strategy.getCampaignName().replace("自定义",replaceString)+timestamp;
-        campaignParams.put("campaign_name",campaignName);
-        campaignParams.put("type",strategy.getCampaignType());
+        campaignParams.put("advertiser_id", token.getAccountId());
+        String campaignName = strategy.getCampaignName().replace("自定义", replaceString) + timestamp;
+        campaignParams.put("campaign_name", campaignName);
+        campaignParams.put("type", strategy.getCampaignType());
         //TODO 目前设定为不限
-        campaignParams.put("day_budget",0L);
+        campaignParams.put("day_budget", 0L);
         Map<String, Object> campaignCreateResult = kuaishouInterfaceService.campaignCreate(token.getAccessToken(), token.getAccountId(), campaignParams);
         Integer code = (Integer) campaignCreateResult.get("code");
         String message = (String) campaignCreateResult.get("message");
-        if(code != 0 ){
+        if (code != 0) {
             //TODO 写入日志信息表
-            log.info("计划创建失败=>message:{}",message);
+            log.info("计划创建失败=>message:{}", message);
             return null;
         }
         newCampaignId = (Long) campaignCreateResult.get("campaignId");
@@ -446,39 +498,39 @@ public class AiKuaishouCreateCreativeServiceImpl implements IAiKuaishouCreateCre
     }
 
 
-    private JSONObject createUnitParams(CtopOauthToken token, Long campaignId,  AiKuaishouAdvertiserStrategy strategy,
-                                        String unitName,Long appId) {
+    private JSONObject createUnitParams(CtopOauthToken token, Long campaignId, AiKuaishouAdvertiserStrategy strategy,
+                                        String unitName, Long appId) {
         // 拼装创建组的入参 json
         JSONObject unitParams = new JSONObject();
         Integer unitType = strategy.getUnitType();
         //创意制作方式
-        unitParams.put("unit_type",unitType);
-        unitParams.put("advertiser_id",token.getAccountId());
-        unitParams.put("campaign_id",campaignId);
+        unitParams.put("unit_type", unitType);
+        unitParams.put("advertiser_id", token.getAccountId());
+        unitParams.put("campaign_id", campaignId);
         unitParams.put("unit_name", unitName);
         //出价类型
-        unitParams.put("bid_type",strategy.getBidType());
+        unitParams.put("bid_type", strategy.getBidType());
         // 优先从系统应用商店下载
-        if(null!=strategy.getUseAppMarket()){
-            unitParams.put("use_app_market",strategy.getUseAppMarket());
+        if (null != strategy.getUseAppMarket()) {
+            unitParams.put("use_app_market", strategy.getUseAppMarket());
         }
         //应用商店列表
-        if(null!=strategy.getAppStore()&&!"".equals(strategy.getAppStore())){
-            unitParams.put("app_store",JSONArray.parseArray(strategy.getAppStore()));
+        if (null != strategy.getAppStore() && !"".equals(strategy.getAppStore())) {
+            unitParams.put("app_store", JSONArray.parseArray(strategy.getAppStore()));
         }
-        unitParams.put("ocpx_action_type",strategy.getOcpxActionType());
+        unitParams.put("ocpx_action_type", strategy.getOcpxActionType());
 
 
         // 在本策略中,都是 OCPM 的出价方式
         //出价
-        if (null!=strategy.getBid()&&strategy.getBid()!=0) {
+        if (null != strategy.getBid() && strategy.getBid() != 0) {
             unitParams.put("bid", strategy.getBid());
         }
-        if (null!=strategy.getCpaBid()&&strategy.getCpaBid()!=0) {
+        if (null != strategy.getCpaBid() && strategy.getCpaBid() != 0) {
             unitParams.put("cpa_bid", strategy.getCpaBid());
         }
         //优先低成本
-        if (null!=strategy.getSmartBid()&&strategy.getSmartBid()!=0) {
+        if (null != strategy.getSmartBid() && strategy.getSmartBid() != 0) {
             unitParams.put("smart_bid", strategy.getSmartBid());
         }
         //优化目标
@@ -500,7 +552,7 @@ public class AiKuaishouCreateCreativeServiceImpl implements IAiKuaishouCreateCre
         //资源位置
         Integer sceneId = null;
         String scenceIdString = strategy.getSceneId();
-        if (null!=scenceIdString&&!scenceIdString.trim().equals(scenceIdString)&&Check.isNull(JSONArray.parseArray(scenceIdString))) {
+        if (null != scenceIdString && !scenceIdString.trim().equals(scenceIdString) && Check.isNull(JSONArray.parseArray(scenceIdString))) {
             sceneId = JSONArray.parseArray(strategy.getSceneId()).getInteger(0);
             unitParams.put("scene_id", JSONArray.parseArray(strategy.getSceneId()));
         }
@@ -601,77 +653,76 @@ public class AiKuaishouCreateCreativeServiceImpl implements IAiKuaishouCreateCre
             if (sceneId != 5) {
                 unitParams.put("template_id", strategy.getTemplateId()); //定向模板id
             } else { // 联盟广告位 需要根据模板id 获取定向数据
-                JSONObject unionJson = groupTemplateService.getUnionJson(Long.parseLong(strategy.getTemplateId()+""));
+                JSONObject unionJson = groupTemplateService.getUnionJson(Long.parseLong(strategy.getTemplateId() + ""));
                 Integer code = unionJson.getInteger("code");
                 if (code == 0) {
                     JSONObject target = unionJson.getJSONObject("target");
                     unitParams.put("target", target);
                 } else {
-                    log.info("组创建异常=》accountId({})联盟广告位定向模板错误",strategy.getAccountId());
+                    log.info("组创建异常=》accountId({})联盟广告位定向模板错误", strategy.getAccountId());
                     return null;
                 }
             }
         } else {
-            JSONObject target = getTarget(sceneId,strategy);
+            JSONObject target = getTarget(sceneId, strategy);
             // 定向数据
             unitParams.put("target", target);
         }
 
 
-
         // 设置定向内容
         JSONObject targetJsonObject = new JSONObject();
-        if(null!=strategy.getRegion()&&!"".equals(strategy.getRegion())){
-            targetJsonObject.put("region",JSONArray.parseArray(strategy.getRegion()));
+        if (null != strategy.getRegion() && !"".equals(strategy.getRegion())) {
+            targetJsonObject.put("region", JSONArray.parseArray(strategy.getRegion()));
         }
-        if(null!=strategy.getAgesRange()&&!"".equals(strategy.getAgesRange())){
-            targetJsonObject.put("ages_range",JSONArray.parseArray(strategy.getAgesRange()));
+        if (null != strategy.getAgesRange() && !"".equals(strategy.getAgesRange())) {
+            targetJsonObject.put("ages_range", JSONArray.parseArray(strategy.getAgesRange()));
         }
-        if(null!=strategy.getGender()){
-            targetJsonObject.put("gender",strategy.getGender());
+        if (null != strategy.getGender()) {
+            targetJsonObject.put("gender", strategy.getGender());
         }
-        if(null!=strategy.getPlatformOs()){
-            targetJsonObject.put("platform_os",strategy.getPlatformOs());
+        if (null != strategy.getPlatformOs()) {
+            targetJsonObject.put("platform_os", strategy.getPlatformOs());
         }
-        if(null!=strategy.getAndroidOsv()){
-            targetJsonObject.put("android_osv",strategy.getAndroidOsv());
+        if (null != strategy.getAndroidOsv()) {
+            targetJsonObject.put("android_osv", strategy.getAndroidOsv());
         }
-        if(null!=strategy.getIosOsv()){
-            targetJsonObject.put("ios_osv",strategy.getIosOsv());
+        if (null != strategy.getIosOsv()) {
+            targetJsonObject.put("ios_osv", strategy.getIosOsv());
         }
-        if(null!=strategy.getDeviceBrand()&&!"".equals(strategy.getDeviceBrand())&&!"[]".equals(strategy.getDeviceBrand())){
-            targetJsonObject.put("device_brand",JSONArray.parseArray(strategy.getDeviceBrand()));
+        if (null != strategy.getDeviceBrand() && !"".equals(strategy.getDeviceBrand()) && !"[]".equals(strategy.getDeviceBrand())) {
+            targetJsonObject.put("device_brand", JSONArray.parseArray(strategy.getDeviceBrand()));
         }
-        if(null!=strategy.getDevicePrice()&&!"".equals(strategy.getDevicePrice())&&!"[]".equals(strategy.getDevicePrice())){
-            targetJsonObject.put("device_price",JSONArray.parseArray(strategy.getDevicePrice()));
+        if (null != strategy.getDevicePrice() && !"".equals(strategy.getDevicePrice()) && !"[]".equals(strategy.getDevicePrice())) {
+            targetJsonObject.put("device_price", JSONArray.parseArray(strategy.getDevicePrice()));
         }
-        if(null!=strategy.getPopulation()&&!"".equals(strategy.getPopulation())){
+        if (null != strategy.getPopulation() && !"".equals(strategy.getPopulation())) {
             JSONArray population = JSONArray.parseArray(strategy.getPopulation());
-            targetJsonObject.put("population",population);
+            targetJsonObject.put("population", population);
         }
-        if(null!=strategy.getFilterConvertedLevel()&&strategy.getFilterConvertedLevel()!=0){
-            targetJsonObject.put("filter_converted_level",strategy.getFilterConvertedLevel());
+        if (null != strategy.getFilterConvertedLevel() && strategy.getFilterConvertedLevel() != 0) {
+            targetJsonObject.put("filter_converted_level", strategy.getFilterConvertedLevel());
         }
-        if(null!=strategy.getExcludePopulation()&&!"".equals(strategy.getExcludePopulation())){
+        if (null != strategy.getExcludePopulation() && !"".equals(strategy.getExcludePopulation())) {
             JSONArray excludePopulation = JSONArray.parseArray(strategy.getExcludePopulation());
-            targetJsonObject.put("exclude_population",excludePopulation);
+            targetJsonObject.put("exclude_population", excludePopulation);
         }
         //是否开启智能扩量
-        if(null!=strategy.getIsOpen()&&strategy.getIsOpen().equals(1)){
+        if (null != strategy.getIsOpen() && strategy.getIsOpen().equals(1)) {
             JSONObject intelliExtend = new JSONObject();
-            intelliExtend.put("is_open",1);
-            if(null!=strategy.getNoAgeBreak()&&strategy.getNoAgeBreak().equals(1)){
-                intelliExtend.put("no_age_break",1);
+            intelliExtend.put("is_open", 1);
+            if (null != strategy.getNoAgeBreak() && strategy.getNoAgeBreak().equals(1)) {
+                intelliExtend.put("no_age_break", 1);
             }
-            if(null!=strategy.getNoGenderBreak()&&strategy.getNoGenderBreak().equals(1)){
-                intelliExtend.put("no_gender_break",1);
+            if (null != strategy.getNoGenderBreak() && strategy.getNoGenderBreak().equals(1)) {
+                intelliExtend.put("no_gender_break", 1);
             }
-            if(null!=strategy.getNoAreaBreak()&&strategy.getNoAreaBreak().equals(1)){
-                intelliExtend.put("no_area_break",1);
+            if (null != strategy.getNoAreaBreak() && strategy.getNoAreaBreak().equals(1)) {
+                intelliExtend.put("no_area_break", 1);
             }
-            targetJsonObject.put("intelli_extend",intelliExtend);
+            targetJsonObject.put("intelli_extend", intelliExtend);
         }
-        unitParams.put("target",targetJsonObject);
+        unitParams.put("target", targetJsonObject);
         return unitParams;
     }
 
@@ -682,24 +733,24 @@ public class AiKuaishouCreateCreativeServiceImpl implements IAiKuaishouCreateCre
      * @param strategy
      * @return
      */
-    private JSONObject getTarget(Integer sceneId,AiKuaishouAdvertiserStrategy strategy) {
+    private JSONObject getTarget(Integer sceneId, AiKuaishouAdvertiserStrategy strategy) {
         JSONObject target = new JSONObject();
         // 地域
         String regionString = strategy.getRegion();
-        if (null!=regionString&&!"".equals(regionString.trim())) {
+        if (null != regionString && !"".equals(regionString.trim())) {
             target.put("region", JSONArray.parseArray(regionString));
         }
         String districtIdString = strategy.getDistrictIds();
         // 商圈定向
-        if (null!=districtIdString&&!"".equals(districtIdString.trim())) {
+        if (null != districtIdString && !"".equals(districtIdString.trim())) {
             target.put("district_ids", JSONArray.parseArray(districtIdString));
         }
         // 用户类型
-        if (null!=strategy.getUserType()) {
+        if (null != strategy.getUserType()) {
             target.put("user_type", strategy.getUserType());
         }
         //自定义年龄段
-        if (null!=strategy.getAgeMin() || null!=strategy.getAgeMax()) {
+        if (null != strategy.getAgeMin() || null != strategy.getAgeMax()) {
             JSONObject age = new JSONObject();
             age.put("min", strategy.getAgeMin());
             age.put("max", strategy.getAgeMax());
@@ -707,66 +758,66 @@ public class AiKuaishouCreateCreativeServiceImpl implements IAiKuaishouCreateCre
         }
         // 固定年龄段
         String ageRangeString = strategy.getAgesRange();
-        if (null!=ageRangeString&&!"".equals(ageRangeString.trim())) {
+        if (null != ageRangeString && !"".equals(ageRangeString.trim())) {
             target.put("ages_range", JSONArray.parseArray(ageRangeString));
         }
         // 性别
-        if (null!=strategy.getGender()) {
+        if (null != strategy.getGender()) {
             target.put("gender", strategy.getGender());
         }
         // 操作系统
-        if (null!=strategy.getPlatformOs()) {
+        if (null != strategy.getPlatformOs()) {
             target.put("platform_os", strategy.getPlatformOs());
         }
         // Android版本
-        if (null!=strategy.getAndroidOsv()) {
+        if (null != strategy.getAndroidOsv()) {
             target.put("android_osv", strategy.getAndroidOsv());
         }
         // Android版本
-        if (null!=strategy.getIosOsv()) {
+        if (null != strategy.getIosOsv()) {
             target.put("ios_osv", strategy.getIosOsv());
         }
         // 网络环境
-        if (null!=strategy.getNetwork()) {
-            target.put("network",strategy.getNetwork());
+        if (null != strategy.getNetwork()) {
+            target.put("network", strategy.getNetwork());
         }
         // 设备品牌
         String deviceBrandString = strategy.getDeviceBrand();
-        if (null != deviceBrandString&&!"".equals(deviceBrandString.trim())) {
+        if (null != deviceBrandString && !"".equals(deviceBrandString.trim())) {
             target.put("device_brand", JSONArray.parseArray(deviceBrandString));
         }
         // 设备价格
         String devicePriceString = strategy.getDevicePrice();
-        if (null != devicePriceString&&!"".equals(devicePriceString.trim())) {
+        if (null != devicePriceString && !"".equals(devicePriceString.trim())) {
             target.put("device_price", JSONArray.parseArray(devicePriceString));
         }
         if (sceneId != 5) {
             // 商业兴趣类型
-            if (null!=strategy.getBusinessInterestType()) {
+            if (null != strategy.getBusinessInterestType()) {
                 target.put("business_interest_type", strategy.getBusinessInterestType());
             }
             // 商业兴趣
             String businessInterestString = strategy.getBusinessInterest();
-            if (null != businessInterestString&&!"".equals(businessInterestString.trim())) {
+            if (null != businessInterestString && !"".equals(businessInterestString.trim())) {
                 target.put("business_interest", JSONArray.parseArray(businessInterestString));
             }
             // 网红粉丝
             String fansStarString = strategy.getFansStar();
-            if (null != fansStarString&&!"".equals(fansStarString.trim())) {
+            if (null != fansStarString && !"".equals(fansStarString.trim())) {
                 target.put("fans_star", JSONArray.parseArray(fansStarString));
             }
             // 兴趣视频用户
             String interestVideoString = strategy.getInterestVideo();
-            if (null != interestVideoString&&!"".equals(interestVideoString.trim())) {
+            if (null != interestVideoString && !"".equals(interestVideoString.trim())) {
                 target.put("interest_video", JSONArray.parseArray(interestVideoString));
             }
             // 过滤已转化人群
-            if (null!=strategy.getFilterConvertedLevel()) {
+            if (null != strategy.getFilterConvertedLevel()) {
                 target.put("filter_converted_level", strategy.getFilterConvertedLevel());
             }
 
             // 开启智能扩量
-            if (null!=strategy.getIsOpen()&&strategy.getIsOpen() == 1) {
+            if (null != strategy.getIsOpen() && strategy.getIsOpen() == 1) {
                 JSONObject intelli_extend = new JSONObject();
                 intelli_extend.put("is_open", strategy.getIsOpen());
                 //  不可突破年龄
@@ -787,31 +838,31 @@ public class AiKuaishouCreateCreativeServiceImpl implements IAiKuaishouCreateCre
         }
         // APP行为-按分类
         String appInterestString = strategy.getAppInterest();
-        if (null != appInterestString&&!"".equals(appInterestString.trim())) {
+        if (null != appInterestString && !"".equals(appInterestString.trim())) {
             target.put("app_interest", JSONArray.parseArray(appInterestString));
         }
         // APP行为-按APP名称
         String appIdsString = strategy.getAppIds();
-        if (null != appIdsString&&!"".equals(appIdsString.trim())) {
+        if (null != appIdsString && !"".equals(appIdsString.trim())) {
             target.put("app_ids", JSONArray.parseArray(appIdsString));
         }
 
         // 人群包定向
         String populationString = strategy.getPopulation();
-        if (null != populationString&&!"".equals(populationString.trim())) {
+        if (null != populationString && !"".equals(populationString.trim())) {
             target.put("population", JSONArray.parseArray(populationString));
         }
         // 人群包排除
         String excludePopulationString = strategy.getExcludePopulation();
-        if (null != excludePopulationString&&!"".equals(excludePopulationString.trim())) {
+        if (null != excludePopulationString && !"".equals(excludePopulationString.trim())) {
             target.put("exclude_population", JSONArray.parseArray(excludePopulationString));
         }
         // 付费人群包id
         String paidAudienceString = strategy.getPaidAudience();
-        if (null != paidAudienceString&&!"".equals(paidAudienceString.trim())) {
+        if (null != paidAudienceString && !"".equals(paidAudienceString.trim())) {
             target.put("paid_audience", JSONArray.parseArray(paidAudienceString));
         }
-        if (Check.isNull(strategy.getBehaviorInterest())){
+        if (Check.isNull(strategy.getBehaviorInterest())) {
             // TODO 只是单独结构体 后续需要优化
             target.put("behavior_interest", JSONObject.parseObject(strategy.getBehaviorInterest()));
         }
@@ -821,17 +872,17 @@ public class AiKuaishouCreateCreativeServiceImpl implements IAiKuaishouCreateCre
 
     private void createCreativeByImage(List<MaterialCutFrame> cutFrameList, CtopOauthToken token, JSONObject creativeParams,
                                        Long campaignId, Long unitId, KuaiShouVideoGet videoItem,
-                                       int imageNumber){
-        int creativeCnt  = 1;
+                                       int imageNumber) {
+        int creativeCnt = 1;
 
-        if ((null!=cutFrameList&&!cutFrameList.isEmpty())){
+        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, creativeCnt,videoItem);
-                creativeCnt ++;
+                String imageToken = getImageToken(imageUrl, imageCode, token.getAccountId(), token.getAccessToken());
+                creativeParams.put("image_token", imageToken);
+                createCreative(token, creativeParams, campaignId, unitId, creativeCnt, videoItem);
+                creativeCnt++;
                 if (creativeCnt > imageNumber) {
                     break;
                 }
@@ -839,25 +890,25 @@ public class AiKuaishouCreateCreativeServiceImpl implements IAiKuaishouCreateCre
         }
     }
 
-    private String getImageToken(String imageUrl, String imageCode, Long accountId,String token){
+    private String getImageToken(String imageUrl, String imageCode, Long accountId, String token) {
         // 根据imageUrl 和 imageCode,获取 imageToken (创建创意用)
-        KuaiShouImageGet imageGet = imageGetService.getOneByParams(null,imageCode);
-        if ((null == imageGet) || ("".equals(imageGet.getImageToken()))){
+        KuaiShouImageGet imageGet = imageGetService.getOneByParams(null, imageCode);
+        if ((null == imageGet) || ("".equals(imageGet.getImageToken()))) {
             // 如果取不到image_token
             // 则调用上传url的方法 kuauiShouImageUpload(url, signature, accountId, oauthToken.getAccessToken());
-            return materialUploadService.kuauiShouImageUpload(imageUrl,imageCode,accountId,token);
+            return materialUploadService.kuauiShouImageUpload(imageUrl, imageCode, accountId, token);
         }
         return imageGet.getImageToken();
     }
 
-    private JSONObject creativeParams(CtopOauthToken token,Long unitId,KuaiShouVideoGet videoItem,AiKuaishouAdvertiserStrategy strategy){
+    private JSONObject creativeParams(CtopOauthToken token, Long unitId, KuaiShouVideoGet videoItem, AiKuaishouAdvertiserStrategy strategy) {
         JSONObject creativeParams = new JSONObject();
-        creativeParams.put("advertiser_id",token.getAccountId());
-        creativeParams.put("unit_id",unitId);
-        creativeParams.put("photo_id",videoItem.getPhotoId());
-        creativeParams.put("creative_material_type",videoItem.getMaterialType());
-        creativeParams.put("action_bar_text",strategy.getActionBarText());
-        creativeParams.put("description",strategy.getDescription());
+        creativeParams.put("advertiser_id", token.getAccountId());
+        creativeParams.put("unit_id", unitId);
+        creativeParams.put("photo_id", videoItem.getPhotoId());
+        creativeParams.put("creative_material_type", videoItem.getMaterialType());
+        creativeParams.put("action_bar_text", strategy.getActionBarText());
+        creativeParams.put("description", strategy.getDescription());
         // 封面广告语标题
         if (!Check.isNull(strategy.getStickerTitle())) {
             creativeParams.put("sticker_title", strategy.getStickerTitle());
@@ -871,45 +922,45 @@ public class AiKuaishouCreateCreativeServiceImpl implements IAiKuaishouCreateCre
             creativeParams.put("expose_tag", strategy.getExposeTag());
         }
         // 广告标签2期
-        if (null!=strategy.getNewExposeTag()&&!"".equals(strategy.getNewExposeTag())) {
+        if (null != strategy.getNewExposeTag() && !"".equals(strategy.getNewExposeTag())) {
             creativeParams.put("new_expose_tag", JSONArray.parseArray(strategy.getNewExposeTag()));
         }
         // 安卓下载中间页ID
-        if(null!=strategy.getSiteId()){
-            creativeParams.put("site_id",strategy.getSiteId());
+        if (null != strategy.getSiteId()) {
+            creativeParams.put("site_id", strategy.getSiteId());
         }
-        if(null != strategy.getClickTrackUrl()&&!"".equals(strategy.getClickTrackUrl())){
-            creativeParams.put("click_track_url",strategy.getClickTrackUrl());
+        if (null != strategy.getClickTrackUrl() && !"".equals(strategy.getClickTrackUrl())) {
+            creativeParams.put("click_track_url", strategy.getClickTrackUrl());
         }
-        if(null != strategy.getImpressionUrl()&&!"".equals(strategy.getImpressionUrl())){
-            creativeParams.put("impression_url",strategy.getImpressionUrl());
+        if (null != strategy.getImpressionUrl() && !"".equals(strategy.getImpressionUrl())) {
+            creativeParams.put("impression_url", strategy.getImpressionUrl());
         }
         // 第三方有效播放监测链接
         if (!Check.isNull(strategy.getAdPhotoPlayedT3sUrl())) {
             creativeParams.put("ad_photo_played_t3s_url", strategy.getAdPhotoPlayedT3sUrl());
         }
-        if(null != strategy.getActionbarClickUrl()&&!"".equals(strategy.getActionbarClickUrl())){
-            creativeParams.put("actionbar_click_url",strategy.getActionbarClickUrl());
+        if (null != strategy.getActionbarClickUrl() && !"".equals(strategy.getActionbarClickUrl())) {
+            creativeParams.put("actionbar_click_url", strategy.getActionbarClickUrl());
         }
-        if(null!=strategy.getCreativeCategory()){
-            creativeParams.put("creative_category",strategy.getCreativeCategory());
+        if (null != strategy.getCreativeCategory()) {
+            creativeParams.put("creative_category", strategy.getCreativeCategory());
         }
-        if(null!=strategy.getCreativeTag()&&!"".equals(strategy.getCreativeTag())){
-            creativeParams.put("creative_tag",JSONArray.parseArray(strategy.getCreativeTag()));
+        if (null != strategy.getCreativeTag() && !"".equals(strategy.getCreativeTag())) {
+            creativeParams.put("creative_tag", JSONArray.parseArray(strategy.getCreativeTag()));
         }
         return creativeParams;
     }
 
 
-    private void createCreative(CtopOauthToken token,JSONObject creativeParams,Long campaignId,Long unitId,
-                                int creativeCnt,KuaiShouVideoGet videoGet){
-        creativeParams.put("creative_name","自定义创意_"+creativeCnt);
+    private void createCreative(CtopOauthToken token, JSONObject creativeParams, Long campaignId, Long unitId,
+                                int creativeCnt, KuaiShouVideoGet videoGet) {
+        creativeParams.put("creative_name", "自定义创意_" + creativeCnt);
         Map<String, Object> creativeCreateResult = kuaishouInterfaceService.creativeCreate
-                (token.getAccessToken(), token.getAccountId(), creativeParams,1);
+                (token.getAccessToken(), token.getAccountId(), creativeParams, 1);
         Integer creativeCode = (Integer) creativeCreateResult.get("code");
         String creativeMessage = (String) creativeCreateResult.get("message");
-        if(creativeCode != 0 ){
-            log.info("创意创建失败=>message:{}",creativeMessage);
+        if (creativeCode != 0) {
+            log.info("创意创建失败=>message:{}", creativeMessage);
             return;
         }
         Long creativeId = (Long) creativeCreateResult.get("creativeId");

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

@@ -40,4 +40,8 @@ public interface KuaiShouVideoGetMapper extends BaseMapper<KuaiShouVideoGet> {
     Integer getEffectiveCountByAccountId(Long accountId);
 
     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> 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);
 }

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

@@ -201,6 +201,36 @@
         AND t2.effect_day_num &lt;= 7
 
     </select>
+    <select id="getZeroVideoByParams" resultType="cn.com.ctop.kuaishou.modules.batch.entity.KuaiShouVideoGet">
+        select
+        video.*
+        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
+        <if test="accountId!=null">
+            and video.account_id = #{accountId}
+        </if>
+        <if test="startTime!=null">
+            and video.stat_date &gt;= #{startTime}
+        </if>
+        <if test="endTime!=null">
+            and video.stat_date &lt;= #{endTime}
+        </if>
+        <if test="channelType != null and channelType != '' ">
+            and video.channel_type = #{channelType}
+        </if>
+        <if test="appVersion != null and appVersion != '' ">
+            and photo_name like concat(#{appVersion},'%')
+        </if>
+        and video.status = 0
+        group by video.signature
+        order by video.stat_date desc
+        <if test="videoCnt!=null">
+            limit #{videoCnt}
+        </if>
+    </select>
+
     <select id="getHotMoneyCountByAccountId" resultType="java.lang.Integer">
         SELECT
         count(1)
@@ -220,4 +250,37 @@
         t2.faddish_date is not null
         and faddish_day_num &lt;=14
     </select>
+    <select id="getHistoryTopVideoByParams"
+            resultType="cn.com.ctop.kuaishou.modules.batch.entity.KuaiShouVideoGet">
+        select
+            video.*
+        from
+            ctop_kuaishou_report_daily_material report
+        left join (select * from ctop_kuaishou_video_get
+                where
+                    status = 0
+                and signature is not null
+        <if test="accountId!=null">
+                 and account_id = #{accountId}
+        </if>
+        <if test="channelType!=null">
+            and channel_type = #{channelType}
+        </if>
+        <if test="startTime!=null">
+            and stat_date &gt;= #{startTime}
+        </if>
+        <if test="endTime!=null">
+            and stat_date &lt;= #{endTime}
+        </if>
+        group by signature) video
+                  on video.signature = report.signature
+        left join (SELECT id, photo_id from ctop_ai_creative_limit WHERE account_id = #{accountId}) t2
+            on video.photo_id = t2.photo_id
+            where video.id is not null
+            group by video.signature
+        order by sum(report.charge) desc
+        <if test="videoCnt!=null">
+            limit #{videoCnt}
+        </if>
+    </select>
 </mapper>

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

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

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

@@ -275,4 +275,14 @@ public class KuaiShouVideoGetServiceImpl extends ServiceImpl<KuaiShouVideoGetMap
     public Integer getHotMoneyCountByAccountId(Long accountId) {
         return videoGetMapper.getHotMoneyCountByAccountId(accountId);
     }
+
+    @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);
+    }
+
+    @Override
+    public List<KuaiShouVideoGet> getHistoryTopVideoByParams(Long accountId, String startTime, String endTime, Integer videoCnt, String appVersion, Integer channelType) {
+        return videoGetMapper.getHistoryTopVideoByParams(accountId,startTime,endTime,videoCnt,appVersion,channelType);
+    }
 }