Browse Source

Merge remote-tracking branch 'origin/master'

# Conflicts:
#	jeecg-boot-module-system/src/main/java/org/jeecg/modules/ads/service/impl/AiStrategyServiceImpl.java
syh 4 năm trước cách đây
mục cha
commit
10cf60bfea
18 tập tin đã thay đổi với 375 bổ sung162 xóa
  1. 124 38
      jeecg-boot-module-system/src/main/java/org/jeecg/modules/ads/service/impl/AiStrategyServiceImpl.java
  2. 3 0
      module-alarm/src/main/java/cn/com/ctop/alarm/modules/entity/RuleIndicator.java
  3. 2 0
      module-alarm/src/main/java/cn/com/ctop/alarm/modules/service/impl/RuleTemplateServiceImpl.java
  4. 19 0
      module-common/src/main/java/cn/com/ctop/common/module/entity/RuleDataTargetKuaishou.java
  5. 1 1
      module-job-kuaishou/src/main/java/cn/com/ctop/job/kuaishou/handler/KuaishouCampaignCopyDateJob.java
  6. 17 12
      module-kuaishou/src/main/java/cn/com/ctop/kuaishou/modules/batch/controller/KuaishouCampaignCopyDataController.java
  7. 5 0
      module-kuaishou/src/main/java/cn/com/ctop/kuaishou/modules/batch/mapper/KuaiShouVideoGetMapper.java
  8. 24 0
      module-kuaishou/src/main/java/cn/com/ctop/kuaishou/modules/batch/mapper/xml/KuaiShouVideoGetMapper.xml
  9. 10 0
      module-kuaishou/src/main/java/cn/com/ctop/kuaishou/modules/batch/service/IKuaiShouVideoGetService.java
  10. 1 1
      module-kuaishou/src/main/java/cn/com/ctop/kuaishou/modules/batch/service/IKuaishouCampaignCopyDataService.java
  11. 0 4
      module-kuaishou/src/main/java/cn/com/ctop/kuaishou/modules/batch/service/impl/BatchServiceImpl.java
  12. 15 0
      module-kuaishou/src/main/java/cn/com/ctop/kuaishou/modules/batch/service/impl/KuaiShouVideoGetServiceImpl.java
  13. 69 67
      module-kuaishou/src/main/java/cn/com/ctop/kuaishou/modules/batch/service/impl/KuaishouCampaignCopyDataServiceImpl.java
  14. 8 1
      module-kuaishou/src/main/java/cn/com/ctop/kuaishou/modules/report/entity/KuaishouAudienceReportDailyAccount.java
  15. 1 1
      module-kuaishou/src/main/java/cn/com/ctop/kuaishou/modules/report/mapper/KuaishouAudienceReportDailyAccountMapper.java
  16. 41 23
      module-kuaishou/src/main/java/cn/com/ctop/kuaishou/modules/report/mapper/xml/KuaishouAudienceReportDailyAccountMapper.xml
  17. 3 3
      module-kuaishou/src/main/java/cn/com/ctop/kuaishou/modules/report/service/impl/KuaishouAudienceReportDailyAccountServiceImpl.java
  18. 32 11
      module-kuaishou/src/main/java/cn/com/ctop/kuaishou/modules/report/service/impl/RuleKuaiShouPlanServiceImpl.java

+ 124 - 38
jeecg-boot-module-system/src/main/java/org/jeecg/modules/ads/service/impl/AiStrategyServiceImpl.java

@@ -9,6 +9,7 @@ import cn.com.ctop.common.module.service.IMaterialImageInfoService;
 import cn.com.ctop.kuaishou.modules.batch.entity.KuaiShouImageGet;
 import cn.com.ctop.kuaishou.modules.batch.entity.KuaiShouImageGet;
 import cn.com.ctop.kuaishou.modules.batch.entity.KuaiShouVideoGet;
 import cn.com.ctop.kuaishou.modules.batch.entity.KuaiShouVideoGet;
 import cn.com.ctop.kuaishou.modules.batch.entity.KuaishouStrategy;
 import cn.com.ctop.kuaishou.modules.batch.entity.KuaishouStrategy;
+import cn.com.ctop.kuaishou.modules.batch.mapper.KuaiShouVideoGetMapper;
 import cn.com.ctop.kuaishou.modules.batch.service.IKuaiShouImageGetService;
 import cn.com.ctop.kuaishou.modules.batch.service.IKuaiShouImageGetService;
 import cn.com.ctop.kuaishou.modules.batch.service.IKuaiShouMaterialUploadService;
 import cn.com.ctop.kuaishou.modules.batch.service.IKuaiShouMaterialUploadService;
 import cn.com.ctop.kuaishou.modules.batch.service.IKuaiShouVideoGetService;
 import cn.com.ctop.kuaishou.modules.batch.service.IKuaiShouVideoGetService;
@@ -56,6 +57,9 @@ public class AiStrategyServiceImpl implements IAiStrategyService {
     private IKuaiShouImageGetService imageGetService;
     private IKuaiShouImageGetService imageGetService;
     @Autowired
     @Autowired
     private IKuaiShouMaterialUploadService materialUploadService;
     private IKuaiShouMaterialUploadService materialUploadService;
+    @Autowired
+    private KuaiShouVideoGetMapper videoGetMapper;
+
     /**
     /**
      *
      *
      * @param strategy
      * @param strategy
@@ -69,6 +73,7 @@ public class AiStrategyServiceImpl implements IAiStrategyService {
             log.info("token获取失败=>accountId:{}",strategy.getAccountId());
             log.info("token获取失败=>accountId:{}",strategy.getAccountId());
             return;
             return;
         }
         }
+
         //策略类型
         //策略类型
         String scenes = strategy.getScenes();
         String scenes = strategy.getScenes();
         //根据策略类型获取策略模板信息
         //根据策略类型获取策略模板信息
@@ -77,12 +82,36 @@ public class AiStrategyServiceImpl implements IAiStrategyService {
             log.info("策略模板信息获取失败=>testDirection:{}",scenes);
             log.info("策略模板信息获取失败=>testDirection:{}",scenes);
             return;
             return;
         }
         }
-        //1:获取相应账户下的最新的5条素材信息
-        List<KuaiShouVideoGet> videoGets = videoGetService.getNewVideoByAccountId(accountId,1);
-        if(null == videoGets){
+
+        // 1: 根据模板信息表里的 material_select_method (素材选择方式),得到"跑量视频"和"上新视频"获取方式
+        // {'highQualityMaterial':{'days':7, 'num':5},'newMaterialNum':5}
+        // TODO 更新该账户下的 ctop_kuaishou_video_get 数据
+
+        kuaishouInterfaceService.getVideoList(token,DateUtils.date2Str(),DateUtils.date2Str());
+
+        JSONObject MaterialSelectMethod = JSONObject.parseObject(strategyTemplate.getMaterialSelectMethod());
+        List<KuaiShouVideoGet> newVideos = new ArrayList<KuaiShouVideoGet>();
+        List<KuaiShouVideoGet> highQualityVideos = new ArrayList<KuaiShouVideoGet>();
+
+        if (MaterialSelectMethod.containsKey("newMaterialNum")){
+            int newVideoCnt = (int) MaterialSelectMethod.get("newMaterialNum");
+            newVideos = videoGetService.getNewVideoDescDate(accountId,newVideoCnt);
+        }
+        if(MaterialSelectMethod.containsKey("highQualityMaterial")){
+            int days = MaterialSelectMethod.getJSONObject("highQualityMaterial").getInteger("days");
+            int highQualityVideoCnt = MaterialSelectMethod.getJSONObject("highQualityMaterial").getInteger("num");
+            highQualityVideos = videoGetMapper.getHighQualityVideo(accountId,days,highQualityVideoCnt);
+        }
+
+        // 跑量视频 + 上新视频 合并到一个list, 为单素材搭配组做准备 TODO
+        List<KuaiShouVideoGet> fullVideos = new ArrayList<KuaiShouVideoGet>();
+        fullVideos.addAll(highQualityVideos);
+        fullVideos.addAll(newVideos);
+        if(null == fullVideos){
             log.info("素材获取失败=>accountId:{}",accountId);
             log.info("素材获取失败=>accountId:{}",accountId);
             return;
             return;
         }
         }
+
         String materialFixType = strategyTemplate.getMaterialFixType();
         String materialFixType = strategyTemplate.getMaterialFixType();
         Date campaignDate = new Date();
         Date campaignDate = new Date();
         String timestamp = DateUtils.formatDate(campaignDate,"yyyyMMddHHmmss");
         String timestamp = DateUtils.formatDate(campaignDate,"yyyyMMddHHmmss");
@@ -96,7 +125,7 @@ public class AiStrategyServiceImpl implements IAiStrategyService {
             //7、一个计划,拼装创建计划的入参json
             //7、一个计划,拼装创建计划的入参json
             JSONObject campaignParams = new JSONObject();
             JSONObject campaignParams = new JSONObject();
             campaignParams.put("advertiser_id",token.getAccountId());
             campaignParams.put("advertiser_id",token.getAccountId());
-            String campaignName = "户14-上下滑&信息流" + "-自定义001"+ "剪辑-低价-低价包邮-活动-年龄18岁以上-单出价-"+ timestamp;
+            String campaignName = "户14-上下滑&信息流" + "-自定义001-"+ "剪辑-低价-低价包邮-活动-年龄18岁以上-单出价-"+ timestamp;
             campaignParams.put("campaign_name",campaignName);
             campaignParams.put("campaign_name",campaignName);
             campaignParams.put("type",Integer.parseInt(strategy.getMarketingGoal()));
             campaignParams.put("type",Integer.parseInt(strategy.getMarketingGoal()));
             campaignParams.put("day_budget",0L);
             campaignParams.put("day_budget",0L);
@@ -109,12 +138,12 @@ public class AiStrategyServiceImpl implements IAiStrategyService {
             }
             }
             Long campaignId = (Long) campaignCreateResult.get("campaignId");
             Long campaignId = (Long) campaignCreateResult.get("campaignId");
             int unitCnt = 1;
             int unitCnt = 1;
-            // 8、根据定向和素材,两层循环 创建组和创意
+            // 8、根据素材和出价,两层循环 创建组和创意
             for (Long item:getCapbids) {
             for (Long item:getCapbids) {
                 //判定素材搭配方式
                 //判定素材搭配方式
                 if(null!=materialFixType&&materialFixType.trim().equals("single")){
                 if(null!=materialFixType&&materialFixType.trim().equals("single")){
                     // 选择素材,创建创意
                     // 选择素材,创建创意
-                    for(KuaiShouVideoGet videoItem: videoGets){
+                    for(KuaiShouVideoGet videoItem: fullVideos){
                         //拼装广告组参数
                         //拼装广告组参数
                         unitCnt ++;
                         unitCnt ++;
                         String unitName = campaignName + "-" + unitCnt;
                         String unitName = campaignName + "-" + unitCnt;
@@ -146,41 +175,97 @@ public class AiStrategyServiceImpl implements IAiStrategyService {
                             createCreativeByImage(cutFrameList,orgFrameList,token,creativeParams,campaignId,unitId,strategy,videoItem,15,null);
                             createCreativeByImage(cutFrameList,orgFrameList,token,creativeParams,campaignId,unitId,strategy,videoItem,15,null);
                         }
                         }
                     }
                     }
-                }else{
+                }
+                else{
                     //混搭素材逻辑
                     //混搭素材逻辑
-                    String unitName = campaignName + "-" + unitCnt;
-                    JSONObject unitParams = createUnitParams(token, campaignId, strategy, item, unitName);
-                    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;
+                    //跑量素材
+                    if(highQualityVideos.size() > 0){
+                        // 取模和余数:
+                        int mod = highQualityVideos.size() / 15;
+                        int rem = highQualityVideos.size() % 15;
+                        int innerUnitCnt = 0;
+                        if(mod!=0){
+                            for(int i=0;i<mod;i++){
+                                String unitName = campaignName + "-跑量-" + item + "-" + innerUnitCnt;
+                                JSONObject unitParams = createUnitParams(token, campaignId, strategy, item, unitName);
+                                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");
+                                for(int j=0;j<15;j++){
+                                    JSONObject creativeParams = creativeParams(token,unitId,highQualityVideos.get(i*15+j),unitCnt,strategy);
+                                    createCreative(token,creativeParams,campaignId,unitId,strategy,null,1,highQualityVideos.get(i*15+j));
+                                }
+                                innerUnitCnt++;
+                            }
+
+                        }
+                        if(rem!=0){
+                            String unitName = campaignName + "-跑量-" + item + "-" + innerUnitCnt;
+                            JSONObject unitParams = createUnitParams(token, campaignId, strategy, item, unitName);
+                            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");
+
+                            for(int j=0;j<rem;j++){
+                                JSONObject creativeParams = creativeParams(token,unitId,highQualityVideos.get(mod*15+j),unitCnt,strategy);
+                                createCreative(token,creativeParams,campaignId,unitId,strategy,null,1,highQualityVideos.get(mod*15+j));
+                            }
+                        }
                     }
                     }
-                    Long unitId = (Long) unitCreateResult.get("unitId");
-                    // 选择素材,创建创意
-                    for(KuaiShouVideoGet videoItem: videoGets){
-                        //拼装广告组参数
-                        JSONObject creativeParams = creativeParams(token,unitId,videoItem,unitCnt,strategy);
-                        JSONArray sceneIdJsonArray = JSONArray.parseArray(strategy.getSceneId());
-                        // 如果广告位只包含 上下滑大屏广告(6),则一个素材搭配1张封面,生成1个创意
-                        if (sceneIdJsonArray.contains(6) && sceneIdJsonArray.size() == 1){
-                            //直接创建创意
-                            createCreative(token,creativeParams,campaignId,unitId,strategy,null,1,videoItem);
-                        } else {
-                            // 素材自带的封面 ctop_material_image_info 内部素材的自带封面,素造的没有
-                            // 素材的智能抽帧封面 ctop_material_cut_frame 其中素造的为8张封面,内部的为15张封面
-                            List<MaterialCutFrame> cutFrameList = materialCutFrameService.getListByVideoSignature(videoItem.getSignature());
-                            List<MaterialImageInfo> orgFrameList = materialImageInfoService.getListByVideoSignature(videoItem.getSignature());
-                            // 其他情况下,一个素材搭配15张封面,生成15个创意
-                            if ((null == cutFrameList||cutFrameList.isEmpty())&&(null == orgFrameList|| orgFrameList.isEmpty())){
-                                log.info("未获取到视频封面=>videoSignature:{}",videoItem.getSignature());
+                    // 新上素材混搭
+                    if(newVideos.size() > 0){
+                        // 取模和余数:
+                        int mod = newVideos.size() / 15;
+                        int rem = newVideos.size() % 15;
+                        int innerUnitCnt = 0;
+                        if(mod!=0){
+                            for(int i=0;i<mod;i++){
+                                String unitName = campaignName + "-上新-" + item + "-" + innerUnitCnt;
+                                JSONObject unitParams = createUnitParams(token, campaignId, strategy, item, unitName);
+                                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");
+                                for(int j=0;j<15;j++){
+                                    JSONObject creativeParams = creativeParams(token,unitId,newVideos.get(i*15+j),unitCnt,strategy);
+                                    createCreative(token,creativeParams,campaignId,unitId,strategy,null,1,newVideos.get(i*15+j));
+                                }
+                                innerUnitCnt++;
+                            }
+
+                        }
+                        if(rem!=0){
+                            String unitName = campaignName + "-上新-" + item + "-" + innerUnitCnt;
+                            JSONObject unitParams = createUnitParams(token, campaignId, strategy, item, unitName);
+                            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;
                                 continue;
                             }
                             }
-                            createCreativeByImage(cutFrameList,orgFrameList,token,creativeParams,campaignId,unitId,strategy,videoItem,1,null);
+                            Long unitId = (Long) unitCreateResult.get("unitId");
+
+                            for(int j=0;j<rem;j++){
+                                JSONObject creativeParams = creativeParams(token,unitId,newVideos.get(mod*15+j),unitCnt,strategy);
+                                createCreative(token,creativeParams,campaignId,unitId,strategy,null,1,newVideos.get(mod*15+j));
+                            }
                         }
                         }
                     }
                     }
-                    unitCnt ++;
                 }
                 }
             }
             }
         }else if(scenes.equals(2)){
         }else if(scenes.equals(2)){
@@ -225,7 +310,7 @@ public class AiStrategyServiceImpl implements IAiStrategyService {
                     AiKuaishouStrategyTargetUnion targetUnion = new AiKuaishouStrategyTargetUnion(strategyMiddle.getId(),item.getId(),item.getTargetContent());
                     AiKuaishouStrategyTargetUnion targetUnion = new AiKuaishouStrategyTargetUnion(strategyMiddle.getId(),item.getId(),item.getTargetContent());
                     targetUnionService.save(targetUnion);
                     targetUnionService.save(targetUnion);
                     // 选择素材,创建创意
                     // 选择素材,创建创意
-                    for(KuaiShouVideoGet videoItem: videoGets){
+                    for(KuaiShouVideoGet videoItem: fullVideos){
                         //拼装广告组参数
                         //拼装广告组参数
                         unitCnt++;
                         unitCnt++;
                         String unitName = campaignName + "-" + unitCnt;
                         String unitName = campaignName + "-" + unitCnt;
@@ -552,7 +637,7 @@ public class AiStrategyServiceImpl implements IAiStrategyService {
     }
     }
     private void createCreative(CtopOauthToken token,JSONObject creativeParams,Long campaignId,Long unitId,
     private void createCreative(CtopOauthToken token,JSONObject creativeParams,Long campaignId,Long unitId,
                                 KuaishouStrategy strategy,AiKuaishouStrategyTargetUnion targetUnion,int creativeCnt,KuaiShouVideoGet videoGet){
                                 KuaishouStrategy strategy,AiKuaishouStrategyTargetUnion targetUnion,int creativeCnt,KuaiShouVideoGet videoGet){
-        creativeParams.put("creative_name","自定义创意_竖版视频_"+creativeCnt+System.currentTimeMillis());
+        creativeParams.put("creative_name","自定义创意_竖版视频_"+creativeCnt);
         Map<String, Object> creativeCreateResult = kuaishouInterfaceService.creativeCreate
         Map<String, Object> creativeCreateResult = kuaishouInterfaceService.creativeCreate
                 (token.getAccessToken(), token.getAccountId(), creativeParams,1);
                 (token.getAccessToken(), token.getAccountId(), creativeParams,1);
         Integer creativeCode = (Integer) creativeCreateResult.get("code");
         Integer creativeCode = (Integer) creativeCreateResult.get("code");
@@ -588,7 +673,8 @@ public class AiStrategyServiceImpl implements IAiStrategyService {
         return imageGet.getImageToken();
         return imageGet.getImageToken();
     }
     }
 
 
-    private List<AiKuaishouStrategyTargetBase> splitBasesByDomain(String definitionDomain, List<AiKuaishouStrategyTargetBase> targetBases) {
+    private List<AiKuaishouStrategyTargetBase> splitBasesByDomain(String definitionDomain,
+                                                                  List<AiKuaishouStrategyTargetBase> targetBases) {
         if(null==definitionDomain){
         if(null==definitionDomain){
             return targetBases;
             return targetBases;
         }
         }

+ 3 - 0
module-alarm/src/main/java/cn/com/ctop/alarm/modules/entity/RuleIndicator.java

@@ -75,6 +75,9 @@ public class RuleIndicator {
     @Excel(name = "对应数据字典id", width = 15)
     @Excel(name = "对应数据字典id", width = 15)
     @ApiModelProperty(value = "对应数据字典id")
     @ApiModelProperty(value = "对应数据字典id")
     private String dictId;
     private String dictId;
+
+    private String requestUrl;
+
     /**
     /**
      * 对应数据表名称
      * 对应数据表名称
      */
      */

+ 2 - 0
module-alarm/src/main/java/cn/com/ctop/alarm/modules/service/impl/RuleTemplateServiceImpl.java

@@ -344,6 +344,7 @@ public class RuleTemplateServiceImpl extends ServiceImpl<RuleTemplateMapper, Rul
                         ruleJson.put("dataUnit", ruleIndicator.getDataUnit());
                         ruleJson.put("dataUnit", ruleIndicator.getDataUnit());
                         ruleJson.put("name", ruleIndicator.getName());
                         ruleJson.put("name", ruleIndicator.getName());
                         ruleJson.put("modelType", ruleIndicator.getModelType());
                         ruleJson.put("modelType", ruleIndicator.getModelType());
+                        ruleJson.put("requestUrl", ruleIndicator.getRequestUrl());
                     }
                     }
 
 
                     ruleDetail.add(ruleJson);
                     ruleDetail.add(ruleJson);
@@ -490,6 +491,7 @@ public class RuleTemplateServiceImpl extends ServiceImpl<RuleTemplateMapper, Rul
                         ruleJson.put("dataUnit", ruleIndicator.getDataUnit());
                         ruleJson.put("dataUnit", ruleIndicator.getDataUnit());
                         ruleJson.put("name", ruleIndicator.getName());
                         ruleJson.put("name", ruleIndicator.getName());
                         ruleJson.put("modelType", ruleIndicator.getModelType());
                         ruleJson.put("modelType", ruleIndicator.getModelType());
+                        ruleJson.put("requestUrl", ruleIndicator.getRequestUrl());
                     }
                     }
 
 
                     ruleDetail.add(ruleJson);
                     ruleDetail.add(ruleJson);

+ 19 - 0
module-common/src/main/java/cn/com/ctop/common/module/entity/RuleDataTargetKuaishou.java

@@ -39,4 +39,23 @@ public class RuleDataTargetKuaishou {
 	private String scheduleTime;
 	private String scheduleTime;
 
 
 	private Integer status;
 	private Integer status;
+
+	/**应用商店*/
+	private String appStore;
+
+	/**定向人群包*/
+	private String population;
+
+	/**排除人群包*/
+	private String excludePopulation;
+
+	/**年龄范围*/
+	private String agesRange;
+
+	/**商业兴趣*/
+	private String businessInterest;
+
+	/**网络环境*/
+	private Integer network;
+
 }
 }

+ 1 - 1
module-job-kuaishou/src/main/java/cn/com/ctop/job/kuaishou/handler/KuaishouCampaignCopyDateJob.java

@@ -20,6 +20,6 @@ public class KuaishouCampaignCopyDateJob {
 
 
     @XxlJob("kuaishouCampaignCopyDateJob")
     @XxlJob("kuaishouCampaignCopyDateJob")
     public void execute() throws Exception {
     public void execute() throws Exception {
-        kuaishouCampaignCopyDataService.batchCopyCampaign();
+        kuaishouCampaignCopyDataService.batchCopyCampaign(null);
     }
     }
 }
 }

+ 17 - 12
module-kuaishou/src/main/java/cn/com/ctop/kuaishou/modules/batch/controller/KuaishouCampaignCopyDataController.java

@@ -23,15 +23,7 @@ import org.jeecgframework.poi.excel.entity.ExportParams;
 import org.jeecgframework.poi.excel.entity.ImportParams;
 import org.jeecgframework.poi.excel.entity.ImportParams;
 import org.jeecgframework.poi.excel.view.JeecgEntityExcelView;
 import org.jeecgframework.poi.excel.view.JeecgEntityExcelView;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.beans.factory.annotation.Autowired;
-import org.springframework.web.bind.annotation.DeleteMapping;
-import org.springframework.web.bind.annotation.GetMapping;
-import org.springframework.web.bind.annotation.PostMapping;
-import org.springframework.web.bind.annotation.PutMapping;
-import org.springframework.web.bind.annotation.RequestBody;
-import org.springframework.web.bind.annotation.RequestMapping;
-import org.springframework.web.bind.annotation.RequestMethod;
-import org.springframework.web.bind.annotation.RequestParam;
-import org.springframework.web.bind.annotation.RestController;
+import org.springframework.web.bind.annotation.*;
 import org.springframework.web.multipart.MultipartFile;
 import org.springframework.web.multipart.MultipartFile;
 import org.springframework.web.multipart.MultipartHttpServletRequest;
 import org.springframework.web.multipart.MultipartHttpServletRequest;
 import org.springframework.web.servlet.ModelAndView;
 import org.springframework.web.servlet.ModelAndView;
@@ -44,6 +36,8 @@ import java.net.URLDecoder;
 import java.util.Arrays;
 import java.util.Arrays;
 import java.util.List;
 import java.util.List;
 import java.util.Map;
 import java.util.Map;
+import java.util.concurrent.ExecutorService;
+import java.util.concurrent.Executors;
 
 
 /**
 /**
  * 待复制广告计划数据
  * 待复制广告计划数据
@@ -88,9 +82,11 @@ public class KuaishouCampaignCopyDataController {
     /**
     /**
      * 添加
      * 添加
      *
      *
-     * @param kuaishouCampaignCopyData
+     * @param
      * @return
      * @return
      */
      */
+    static ExecutorService executorService = Executors.newFixedThreadPool(5);
+
     @AutoLog(value = "待复制广告计划数据-添加")
     @AutoLog(value = "待复制广告计划数据-添加")
     @ApiOperation(value = "待复制广告计划数据-添加", notes = "待复制广告计划数据-添加")
     @ApiOperation(value = "待复制广告计划数据-添加", notes = "待复制广告计划数据-添加")
     @PostMapping(value = "/add")
     @PostMapping(value = "/add")
@@ -104,8 +100,17 @@ public class KuaishouCampaignCopyDataController {
                     kuaishouCampaignCopyData.setCreaterId(sysUser.getId());
                     kuaishouCampaignCopyData.setCreaterId(sysUser.getId());
                 }
                 }
             }
             }
-            kuaishouCampaignCopyDataService.save(kuaishouCampaignCopyData);
-            result.success("添加成功!");
+            boolean save = kuaishouCampaignCopyDataService.save(kuaishouCampaignCopyData);
+            if (save) {
+                executorService.submit(new Runnable() {
+                    @Override
+                    public void run() {
+                        log.info("批量复制计划开始,accountId:{},老计划id:{},新计划id:{}", kuaishouCampaignCopyData.getAccountId(), kuaishouCampaignCopyData.getOldCampaignId(), kuaishouCampaignCopyData.getNewCampaignId());
+                        kuaishouCampaignCopyDataService.batchCopyCampaign(kuaishouCampaignCopyData);
+                    }
+                });
+            }
+            result.success("提交成功,异步创建中");
         } catch (Exception e) {
         } catch (Exception e) {
             log.error(e.getMessage(), e);
             log.error(e.getMessage(), e);
             result.error500("操作失败");
             result.error500("操作失败");

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

@@ -19,4 +19,9 @@ public interface KuaiShouVideoGetMapper extends BaseMapper<KuaiShouVideoGet> {
     void replaceBatch(@Param(value = "videos") List<KuaiShouVideoGet> videoGets);
     void replaceBatch(@Param(value = "videos") List<KuaiShouVideoGet> videoGets);
 
 
     List<KuaiShouVideoGetVo> getVideoList(Map<String, Object> requestMap);
     List<KuaiShouVideoGetVo> getVideoList(Map<String, Object> requestMap);
+
+    List<KuaiShouVideoGet> getHighQualityVideo(long accountId,int days,int num);
+
+
+
 }
 }

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

@@ -59,4 +59,28 @@
 
 
 
 
 
 
+    <select id="getHighQualityVideo" parameterType="java.util.Map"
+            resultType="cn.com.ctop.kuaishou.modules.batch.entity.KuaiShouVideoGet">
+        select * from ctop_kuaishou_video_get
+        where account_id = #{accountId}
+        and signature in
+        (
+        select
+            daily_material.signature
+        from
+        ctop_kuaishou_report_daily_material daily_material
+        inner join
+        ctop_user_allocation allocation
+        on daily_material.account_id = allocation.account_id
+        where  allocation.project_id in (select project_id from ctop_user_allocation where account_id = #{accountId})
+        and  to_days(now()) - to_days(daily_material.stat_date) &lt;= #{days}
+        and daily_material.signature is not null
+        GROUP BY daily_material.signature
+        order by sum(daily_material.charge) desc
+        limit #{num}
+        )
+    </select>
+
+
+
 </mapper>
 </mapper>

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

@@ -2,6 +2,7 @@ package cn.com.ctop.kuaishou.modules.batch.service;
 
 
 import cn.com.ctop.kuaishou.modules.batch.entity.KuaiShouVideoGet;
 import cn.com.ctop.kuaishou.modules.batch.entity.KuaiShouVideoGet;
 import cn.com.ctop.kuaishou.modules.batch.entity.vo.KuaiShouVideoGetVo;
 import cn.com.ctop.kuaishou.modules.batch.entity.vo.KuaiShouVideoGetVo;
+import cn.com.ctop.kuaishou.modules.batch.mapper.KuaiShouVideoGetMapper;
 import com.baomidou.mybatisplus.extension.service.IService;
 import com.baomidou.mybatisplus.extension.service.IService;
 
 
 import java.util.List;
 import java.util.List;
@@ -13,6 +14,9 @@ import java.util.Map;
  * @Date: 2019-07-25
  * @Date: 2019-07-25
  * @Version: V1.0
  * @Version: V1.0
  */
  */
+
+
+
 public interface IKuaiShouVideoGetService extends IService<KuaiShouVideoGet> {
 public interface IKuaiShouVideoGetService extends IService<KuaiShouVideoGet> {
     void replaceBatch(List<KuaiShouVideoGet> videoGets);
     void replaceBatch(List<KuaiShouVideoGet> videoGets);
 
 
@@ -21,4 +25,10 @@ public interface IKuaiShouVideoGetService extends IService<KuaiShouVideoGet> {
     List<KuaiShouVideoGetVo> getVideoList(Map<String, Object> stringObjectMap);
     List<KuaiShouVideoGetVo> getVideoList(Map<String, Object> stringObjectMap);
 
 
     List<KuaiShouVideoGet> getNewVideoByAccountId(Long accountId,Integer videoAiStatus);
     List<KuaiShouVideoGet> getNewVideoByAccountId(Long accountId,Integer videoAiStatus);
+
+    List<KuaiShouVideoGet> getNewVideoDescDate(Long accountId,Integer newVideoCnt);
+
+
+
+
 }
 }

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

@@ -11,5 +11,5 @@ import com.baomidou.mybatisplus.extension.service.IService;
  */
  */
 public interface IKuaishouCampaignCopyDataService extends IService<KuaishouCampaignCopyData> {
 public interface IKuaishouCampaignCopyDataService extends IService<KuaishouCampaignCopyData> {
 
 
-    void batchCopyCampaign();
+    void batchCopyCampaign(KuaishouCampaignCopyData campaignCopyData);
 }
 }

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

@@ -765,20 +765,17 @@ public class BatchServiceImpl implements IBatchService {
         try {
         try {
             JSONObject unitJson = new JSONObject();
             JSONObject unitJson = new JSONObject();
             unitJson.put("campaign_id", copyToCampaignId);
             unitJson.put("campaign_id", copyToCampaignId);
-
             // 资源位置
             // 资源位置
             JSONArray scene_id = JSONArray.parseArray(group.getSceneId());
             JSONArray scene_id = JSONArray.parseArray(group.getSceneId());
             if (!Check.isNull(scene_id)) {
             if (!Check.isNull(scene_id)) {
                 unitJson.put("scene_id", scene_id);
                 unitJson.put("scene_id", scene_id);
             }
             }
-
             Integer sceneId = valueOf(scene_id.get(0).toString());
             Integer sceneId = valueOf(scene_id.get(0).toString());
             // 资源创作方式
             // 资源创作方式
             if (!Check.isNull(group.getUnitType())) {
             if (!Check.isNull(group.getUnitType())) {
                 if (!Check.isNull(group.getUnitType())) {
                 if (!Check.isNull(group.getUnitType())) {
                     unitJson.put("unit_type", group.getUnitType());
                     unitJson.put("unit_type", group.getUnitType());
                 }
                 }
-
                 //投放开始时间
                 //投放开始时间
                 if (!Check.isNull(group.getBeginTime())) {
                 if (!Check.isNull(group.getBeginTime())) {
                     String nowDate = DateUtils.getNowDate("yyyy-MM-dd");
                     String nowDate = DateUtils.getNowDate("yyyy-MM-dd");
@@ -1044,7 +1041,6 @@ public class BatchServiceImpl implements IBatchService {
     @Override
     @Override
     public void copyCreative(Long accountId, Long unitId, Long copyUnitId, JSONObject otherJson) throws Exception {
     public void copyCreative(Long accountId, Long unitId, Long copyUnitId, JSONObject otherJson) throws Exception {
         // 查询当前复制组下的所有非程序化创意
         // 查询当前复制组下的所有非程序化创意
-
         QueryWrapper<KuaiShouCreative> queryWrapper = new QueryWrapper<>();
         QueryWrapper<KuaiShouCreative> queryWrapper = new QueryWrapper<>();
         queryWrapper.eq("account_id", accountId);
         queryWrapper.eq("account_id", accountId);
         queryWrapper.eq("unit_id", copyUnitId);
         queryWrapper.eq("unit_id", copyUnitId);

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

@@ -133,4 +133,19 @@ public class KuaiShouVideoGetServiceImpl extends ServiceImpl<KuaiShouVideoGetMap
         queryWrapper.orderByDesc("stat_date");
         queryWrapper.orderByDesc("stat_date");
         return this.list(queryWrapper);
         return this.list(queryWrapper);
     }
     }
+
+
+    @Override
+    public List<KuaiShouVideoGet>getNewVideoDescDate(Long accountId,Integer newVideoCnt){
+        QueryWrapper<KuaiShouVideoGet>queryWrapper = new QueryWrapper<>();
+        if(null!=accountId&&accountId!=0){
+            queryWrapper.eq("account_id",accountId);
+        }
+        if(null!=newVideoCnt && newVideoCnt>0){
+            queryWrapper.orderByDesc("stat_date");
+            queryWrapper.last("limit " + newVideoCnt);
+        }
+        return this.list(queryWrapper);
+    }
+
 }
 }

+ 69 - 67
module-kuaishou/src/main/java/cn/com/ctop/kuaishou/modules/batch/service/impl/KuaishouCampaignCopyDataServiceImpl.java

@@ -8,24 +8,20 @@ import cn.com.ctop.common.module.utils.Check;
 import cn.com.ctop.kuaishou.modules.batch.entity.KuaiShouGroup;
 import cn.com.ctop.kuaishou.modules.batch.entity.KuaiShouGroup;
 import cn.com.ctop.kuaishou.modules.batch.entity.KuaishouCampaignCopyData;
 import cn.com.ctop.kuaishou.modules.batch.entity.KuaishouCampaignCopyData;
 import cn.com.ctop.kuaishou.modules.batch.mapper.KuaishouCampaignCopyDataMapper;
 import cn.com.ctop.kuaishou.modules.batch.mapper.KuaishouCampaignCopyDataMapper;
-import cn.com.ctop.kuaishou.modules.batch.service.IBatchService;
-import cn.com.ctop.kuaishou.modules.batch.service.IKuaiShouCreativeService;
-import cn.com.ctop.kuaishou.modules.batch.service.IKuaiShouGroupService;
-import cn.com.ctop.kuaishou.modules.batch.service.IKuaiShouGroupTargetService;
-import cn.com.ctop.kuaishou.modules.batch.service.IKuaishouCampaignCopyDataService;
-import cn.com.ctop.kuaishou.modules.batch.service.IKuaishouInterfaceService;
+import cn.com.ctop.kuaishou.modules.batch.service.*;
 import com.alibaba.fastjson.JSONArray;
 import com.alibaba.fastjson.JSONArray;
 import com.alibaba.fastjson.JSONObject;
 import com.alibaba.fastjson.JSONObject;
 import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
 import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
 import com.xxl.job.core.enums.NoEn;
 import com.xxl.job.core.enums.NoEn;
+import lombok.extern.slf4j.Slf4j;
 import org.jeecg.common.util.DateUtils;
 import org.jeecg.common.util.DateUtils;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.stereotype.Service;
 import org.springframework.stereotype.Service;
 
 
-import java.util.Date;
-import java.util.HashMap;
 import java.util.List;
 import java.util.List;
 import java.util.Map;
 import java.util.Map;
+import java.util.concurrent.ExecutorService;
+import java.util.concurrent.Executors;
 
 
 import static java.lang.Integer.valueOf;
 import static java.lang.Integer.valueOf;
 
 
@@ -37,10 +33,8 @@ import static java.lang.Integer.valueOf;
  * @date 2020-12-22
  * @date 2020-12-22
  */
  */
 @Service
 @Service
+@Slf4j
 public class KuaishouCampaignCopyDataServiceImpl extends ServiceImpl<KuaishouCampaignCopyDataMapper, KuaishouCampaignCopyData> implements IKuaishouCampaignCopyDataService {
 public class KuaishouCampaignCopyDataServiceImpl extends ServiceImpl<KuaishouCampaignCopyDataMapper, KuaishouCampaignCopyData> implements IKuaishouCampaignCopyDataService {
-
-    @Autowired
-    private KuaishouCampaignCopyDataMapper kuaishouCampaignCopyDataMapper;
     @Autowired
     @Autowired
     private IBatchService batchService;
     private IBatchService batchService;
     @Autowired
     @Autowired
@@ -57,6 +51,9 @@ public class KuaishouCampaignCopyDataServiceImpl extends ServiceImpl<KuaishouCam
     private ISendMessageService sendMessageService;
     private ISendMessageService sendMessageService;
     @Autowired
     @Autowired
     private IMessageTemplate messageTemplate;
     private IMessageTemplate messageTemplate;
+    @Autowired
+    private IKuaiShouGroupTemplateService groupTemplateService;
+    static ExecutorService executorService = Executors.newFixedThreadPool(15);
 
 
     /**
     /**
      * 批量复制计划
      * 批量复制计划
@@ -67,32 +64,28 @@ public class KuaishouCampaignCopyDataServiceImpl extends ServiceImpl<KuaishouCam
      * @author ZHAOXA
      * @author ZHAOXA
      */
      */
     @Override
     @Override
-    public void batchCopyCampaign() {
-        Map<String, Object> map = new HashMap<>();
-        //'状态:1待复制,2成功,3失败'
-        map.put("state", NoEn.NO1.valueInt());
-        List<KuaishouCampaignCopyData> kuaishouCampaignCopyData = kuaishouCampaignCopyDataMapper.selectByMap(map);
-        for (KuaishouCampaignCopyData copyData : kuaishouCampaignCopyData) {
-            try {
-                CtopOauthToken token = tokenService.getTokenByAccountId(copyData.getAccountId());
-                //执行删除被复制的计划组+创意
-                delOldCampaigns(copyData.getAccountId(), copyData.getOldCampaignId());
-                //获取当前最新广告计划组、创意数据并入库
-                JSONObject data = getNewCampaigns(token.getAccessToken(), copyData);
-                data.put("copyData", copyData);
-                //根据被复制的组数据和模板、预算和排期数据调用快手创建组接口
-                boolean isSuccess = createCopyUnits(token, data);
-                //更新成功,修改状态并发送通知
-                if (isSuccess) {
-                    sendNotification(copyData.getId(), copyData.getOldCampaignName(), copyData.getCreaterId(), NoEn.NO2.valueStr(), "复制成功");
-                }
-            } catch (Exception e) {
-                log.error("复制广告计划异常", e);
-                //复制过程中失败,更新状态并发送预警
-                sendNotification(copyData.getId(), copyData.getOldCampaignName(), copyData.getCreaterId(), NoEn.NO3.valueStr(), e.getMessage());
-            }
-
+    public void batchCopyCampaign(KuaishouCampaignCopyData copyData) {
+        try {
+            CtopOauthToken token = tokenService.getTokenByAccountId(copyData.getAccountId());
+            if (Check.isNull(token)) {
+                throw new Exception("token未获取");
 
 
+            }
+            //执行删除被复制的计划组+创意
+            delOldCampaigns(copyData.getAccountId(), copyData.getOldCampaignId());
+            //获取当前最新广告计划组、创意数据并入库
+            JSONObject data = getNewCampaigns(token.getAccessToken(), copyData);
+            data.put("copyData", copyData);
+            //根据被复制的组数据和模板、预算和排期数据调用快手创建组接口
+            boolean isSuccess = createCopyUnits(token, data);
+            //更新成功,修改状态并发送通知
+            if (isSuccess) {
+                sendNotification(copyData.getId(), copyData.getOldCampaignName(), copyData.getCreaterId(), NoEn.NO2.valueStr(), "复制成功");
+            }
+        } catch (Exception e) {
+            log.error("复制广告计划异常", e);
+            //复制过程中失败,更新状态并发送预警
+            sendNotification(copyData.getId(), copyData.getOldCampaignName(), copyData.getCreaterId(), NoEn.NO3.valueStr(), e.getMessage());
         }
         }
     }
     }
 
 
@@ -106,6 +99,7 @@ public class KuaishouCampaignCopyDataServiceImpl extends ServiceImpl<KuaishouCam
      */
      */
     private void delOldCampaigns(Long accountId, Long campaignId) throws Exception {
     private void delOldCampaigns(Long accountId, Long campaignId) throws Exception {
         try {
         try {
+            log.info("删除老计划下想关联数据,accountId:{},campaignId:{}", accountId, campaignId);
             //删除组
             //删除组
             kuaiShouGroupService.delAllGroupByCampaignId(accountId, campaignId);
             kuaiShouGroupService.delAllGroupByCampaignId(accountId, campaignId);
             //删除创意
             //删除创意
@@ -126,6 +120,7 @@ public class KuaishouCampaignCopyDataServiceImpl extends ServiceImpl<KuaishouCam
     private JSONObject getNewCampaigns(String accessToken, KuaishouCampaignCopyData copyData) throws Exception {
     private JSONObject getNewCampaigns(String accessToken, KuaishouCampaignCopyData copyData) throws Exception {
         JSONObject data = new JSONObject();
         JSONObject data = new JSONObject();
         try {
         try {
+            log.info("获取计划下最新数据,accountId:{},campaignId:{}", copyData.getAccountId(), copyData.getOldCampaignId());
             Long campaignId = copyData.getOldCampaignId();
             Long campaignId = copyData.getOldCampaignId();
             //根据计划ID查询快手广告组并入库
             //根据计划ID查询快手广告组并入库
             kuaiShouGroupService.getGroupListByPage(accessToken, copyData.getAccountId(), campaignId, 1);
             kuaiShouGroupService.getGroupListByPage(accessToken, copyData.getAccountId(), campaignId, 1);
@@ -138,7 +133,6 @@ public class KuaishouCampaignCopyDataServiceImpl extends ServiceImpl<KuaishouCam
             for (KuaiShouGroup kuaiShouGroup : kuaiShouGroups) {
             for (KuaiShouGroup kuaiShouGroup : kuaiShouGroups) {
                 kuaiShouGroup.setTarget(kuaiShouGroupTargetService.queryTargetInfoByunitId(copyData.getAccountId(), kuaiShouGroup.getUnitId()));
                 kuaiShouGroup.setTarget(kuaiShouGroupTargetService.queryTargetInfoByunitId(copyData.getAccountId(), kuaiShouGroup.getUnitId()));
                 //根据广告组ID查询快手广告创意并入库
                 //根据广告组ID查询快手广告创意并入库
-                kuaiShouGroupService.getCreativeByUnit(accessToken, copyData.getAccountId(), kuaiShouGroup.getUnitId());
             }
             }
             data.put("groups", kuaiShouGroups);
             data.put("groups", kuaiShouGroups);
         } catch (Exception e) {
         } catch (Exception e) {
@@ -158,10 +152,12 @@ public class KuaishouCampaignCopyDataServiceImpl extends ServiceImpl<KuaishouCam
      * @author ZHAOXA
      * @author ZHAOXA
      */
      */
     private boolean createCopyUnits(CtopOauthToken token, JSONObject data) throws Exception {
     private boolean createCopyUnits(CtopOauthToken token, JSONObject data) throws Exception {
+
         int count = 0;
         int count = 0;
         String msg = "";
         String msg = "";
         JSONArray groups = data.getJSONArray("groups");
         JSONArray groups = data.getJSONArray("groups");
         JSONObject copyData = data.getJSONObject("copyData");
         JSONObject copyData = data.getJSONObject("copyData");
+        log.info("开始创建组,accountId:{},campaign_id:{}", token.getAccountId(), copyData.getLong("newCampaignId"));
         for (int i = 0; i < groups.size(); i++) {
         for (int i = 0; i < groups.size(); i++) {
             try {
             try {
                 JSONObject group = groups.getJSONObject(i);
                 JSONObject group = groups.getJSONObject(i);
@@ -169,7 +165,7 @@ public class KuaishouCampaignCopyDataServiceImpl extends ServiceImpl<KuaishouCam
                 unitJson.put("campaign_id", copyData.getLong("newCampaignId"));
                 unitJson.put("campaign_id", copyData.getLong("newCampaignId"));
                 // 资源位置
                 // 资源位置
                 JSONArray scene_id = copyData.getJSONArray("sceneId");
                 JSONArray scene_id = copyData.getJSONArray("sceneId");
-                if (Check.isNull(scene_id) || scene_id.size() == 0) {
+                if (Check.isNull(scene_id)) {
                     scene_id = group.getJSONArray("sceneId");
                     scene_id = group.getJSONArray("sceneId");
                 }
                 }
                 unitJson.put("scene_id", scene_id);
                 unitJson.put("scene_id", scene_id);
@@ -248,9 +244,21 @@ public class KuaishouCampaignCopyDataServiceImpl extends ServiceImpl<KuaishouCam
                     unitJson.put("speed", speed);
                     unitJson.put("speed", speed);
                 }
                 }
 
 
-                String templateId = copyData.getString("templateId");
+                Integer sceneId = valueOf(scene_id.get(0).toString());
+                Long templateId = copyData.getLong("templateId");
                 if (!Check.isNull(templateId)) {
                 if (!Check.isNull(templateId)) {
-                    unitJson.put("template_id", templateId);
+                    if (sceneId != 5) {
+                        unitJson.put("template_id", templateId);
+                    } else {
+                        JSONObject unionJson = groupTemplateService.getUnionJson(templateId);
+                        Integer code = unionJson.getInteger("code");
+                        if (code == 0) {
+                            JSONObject target = unionJson.getJSONObject("target");
+                            unitJson.put("target", target);
+                        } else {
+                            continue;
+                        }
+                    }
                 } else {
                 } else {
                     /*----------------用户定向-----------*/
                     /*----------------用户定向-----------*/
                     JSONObject target = group.getJSONObject("target");
                     JSONObject target = group.getJSONObject("target");
@@ -318,7 +326,7 @@ public class KuaishouCampaignCopyDataServiceImpl extends ServiceImpl<KuaishouCam
                     if (!Check.isNull(target.getJSONArray("thirdPlatformCode"))) {
                     if (!Check.isNull(target.getJSONArray("thirdPlatformCode"))) {
                         targetJson.put("third_platform_code", target.getJSONArray("thirdPlatformCode"));
                         targetJson.put("third_platform_code", target.getJSONArray("thirdPlatformCode"));
                     }
                     }
-                    Integer sceneId = valueOf(scene_id.get(0).toString());
+
                     if (sceneId != 5) {
                     if (sceneId != 5) {
                         //过滤已转化人群纬度
                         //过滤已转化人群纬度
                         if (!Check.isNull(target.getInteger("filterConvertedLevel"))) {
                         if (!Check.isNull(target.getInteger("filterConvertedLevel"))) {
@@ -415,33 +423,14 @@ public class KuaishouCampaignCopyDataServiceImpl extends ServiceImpl<KuaishouCam
 
 
                 //快手广告组名
                 //快手广告组名
                 String unitName = group.getString("unitName");
                 String unitName = group.getString("unitName");
-                if (unitName.contains("CopyFrom")) {
-                    String format = "-".concat(DateUtils.yyyymmddhhmmss.get().format(new Date()));
-                    if (unitName.contains("(update)")) {
-                        int lastIndx = unitName.lastIndexOf("-");
-                        group.put("unit_name", unitName.substring(0, lastIndx).concat(format).concat("(update)"));
-                    } else {
-                        unitJson.put("unit_name", unitName.concat(format).concat("(update)"));
-                    }
-                } else {
-                    unitJson.put("unit_name", "CopyFrom-".concat(unitName));
-                }
+
+                unitJson.put("unit_name", unitName);
                 Map<String, Object> returnUnitMap = kuaishouInterfaceService.adUnitCreate(token.getAccessToken(), token.getAccountId(), unitJson, 1);
                 Map<String, Object> returnUnitMap = kuaishouInterfaceService.adUnitCreate(token.getAccessToken(), token.getAccountId(), unitJson, 1);
                 if (!Check.isNullMap(returnUnitMap)) {
                 if (!Check.isNullMap(returnUnitMap)) {
                     Integer code = (Integer) returnUnitMap.get("code");
                     Integer code = (Integer) returnUnitMap.get("code");
                     if (code == 0) {
                     if (code == 0) {
                         Long unitId = (Long) returnUnitMap.get("unitId");
                         Long unitId = (Long) returnUnitMap.get("unitId");
-                        Thread thread = new Thread() {
-                            @Override
-                            public void run() {
-                                try {
-                                    batchService.copyCreative(token.getAccountId(), unitId, group.getLong("unitId"), null);
-                                } catch (Exception e) {
-                                    log.error("复制创建广告创意异常", e);
-                                }
-                            }
-                        };
-                        thread.start();
+                        createCopyCreatives(token, unitId, group.getLong("unitId"));
                     } else {
                     } else {
                         count++;
                         count++;
                         msg = (String) returnUnitMap.get("message");
                         msg = (String) returnUnitMap.get("message");
@@ -454,8 +443,7 @@ public class KuaishouCampaignCopyDataServiceImpl extends ServiceImpl<KuaishouCam
                 log.error("复制过程调用快手接口异常", e);
                 log.error("复制过程调用快手接口异常", e);
             }
             }
         }
         }
-        //全部失败
-
+        //复制广告组全部成功
         if (count == 0) {
         if (count == 0) {
             return true;
             return true;
         } else {
         } else {
@@ -472,8 +460,22 @@ public class KuaishouCampaignCopyDataServiceImpl extends ServiceImpl<KuaishouCam
      * @throws
      * @throws
      * @author ZHAOXA
      * @author ZHAOXA
      */
      */
-    private void createCopyCreatives(CtopOauthToken token, JSONObject data, KuaishouCampaignCopyData
-            copyData) throws Exception {
+    private void createCopyCreatives(CtopOauthToken token, Long unitId, Long copyUnitId) {
+        executorService.submit(new Runnable() {
+            @Override
+            public void run() {
+                try {
+                    log.info("开始多线程执行创建创意,accountId:{},新组:{},老组:{}", token.getAccountId(), unitId, copyUnitId);
+                    kuaiShouGroupService.getCreativeByUnit(token.getAccessToken(), token.getAccountId(), copyUnitId);
+                    Thread.sleep(200l);
+                    batchService.copyCreative(token.getAccountId(), unitId, copyUnitId, null);
+                } catch (Exception e) {
+                    e.printStackTrace();
+                }
+
+            }
+        });
+
 
 
     }
     }
 
 

+ 8 - 1
module-kuaishou/src/main/java/cn/com/ctop/kuaishou/modules/report/entity/KuaishouAudienceReportDailyAccount.java

@@ -7,6 +7,8 @@ import lombok.Data;
 import lombok.EqualsAndHashCode;
 import lombok.EqualsAndHashCode;
 import lombok.experimental.Accessors;
 import lombok.experimental.Accessors;
 
 
+import java.util.List;
+
 /**
 /**
  * 人群分析报表
  * 人群分析报表
  *
  *
@@ -26,5 +28,10 @@ public class KuaishouAudienceReportDailyAccount extends KuaishouAudienceReportDa
     private java.lang.String audienceType;
     private java.lang.String audienceType;
 
 
     @TableField(exist = false)
     @TableField(exist = false)
-    private java.lang.Integer count;
+    private List<String> busTypes;
+
+    @TableField(exist = false)
+    private List<Long> accountIds;
+
+
 }
 }

+ 1 - 1
module-kuaishou/src/main/java/cn/com/ctop/kuaishou/modules/report/mapper/KuaishouAudienceReportDailyAccountMapper.java

@@ -19,7 +19,7 @@ public interface KuaishouAudienceReportDailyAccountMapper extends BaseMapper<Kua
 
 
     List<JSONObject> queryAllReportForm(KuaishouAudienceReportDailyAccount audienceReport);
     List<JSONObject> queryAllReportForm(KuaishouAudienceReportDailyAccount audienceReport);
 
 
-    int querybusinessTypeCount(KuaishouAudienceReportDailyAccount audienceReport);
+    List<String> querybusinessTypeCount(KuaishouAudienceReportDailyAccount audienceReport);
 
 
     List<JSONObject> querybusinessTypeReportForm(KuaishouAudienceReportDailyAccount audienceReport);
     List<JSONObject> querybusinessTypeReportForm(KuaishouAudienceReportDailyAccount audienceReport);
 }
 }

+ 41 - 23
module-kuaishou/src/main/java/cn/com/ctop/kuaishou/modules/report/mapper/xml/KuaishouAudienceReportDailyAccountMapper.xml

@@ -17,8 +17,11 @@
         IFNULL(ROUND(SUM(event_next_day_stay)/SUM(activation)*100,2),0) as eventNextDayStayRatio
         IFNULL(ROUND(SUM(event_next_day_stay)/SUM(activation)*100,2),0) as eventNextDayStayRatio
         FROM ctop_kuaishou_audience_report_daily_account
         FROM ctop_kuaishou_audience_report_daily_account
         where 1=1
         where 1=1
-        <if test="accountId != null">
-            and account_id = #{accountId}
+        <if test="accountIds != null and accountIds.size() > 0">
+            and account_id in
+            <foreach collection="accountIds" item="item" index="index" open="(" separator="," close=")">
+                #{item}
+            </foreach>
         </if>
         </if>
         <if test="startTime != null">
         <if test="startTime != null">
             AND stat_date &gt;= #{startTime}
             AND stat_date &gt;= #{startTime}
@@ -86,8 +89,11 @@
         IFNULL(ROUND(SUM(bclick)/SUM(aclick)*100,2),0) as actionRatio
         IFNULL(ROUND(SUM(bclick)/SUM(aclick)*100,2),0) as actionRatio
         FROM ctop_kuaishou_audience_report_daily_account
         FROM ctop_kuaishou_audience_report_daily_account
         where 1=1
         where 1=1
-        <if test="accountId != null">
-            and account_id = #{accountId}
+        <if test="accountIds != null and accountIds.size() > 0">
+            and account_id in
+            <foreach collection="accountIds" item="item" index="index" open="(" separator="," close=")">
+                #{item}
+            </foreach>
         </if>
         </if>
         <if test="startTime != null">
         <if test="startTime != null">
             AND stat_date &gt;= #{startTime}
             AND stat_date &gt;= #{startTime}
@@ -135,11 +141,14 @@
         IFNULL(ROUND(SUM(bclick)/SUM(aclick)*100,2),0) as actionRatio
         IFNULL(ROUND(SUM(bclick)/SUM(aclick)*100,2),0) as actionRatio
         FROM ctop_kuaishou_audience_report_daily_account
         FROM ctop_kuaishou_audience_report_daily_account
         where 1=1
         where 1=1
-        <if test="count > 0 ">
+        <if test="busTypes !=null and busTypes.size() == 9 ">
             AND business_interest_tags != '其他'
             AND business_interest_tags != '其他'
         </if>
         </if>
-        <if test="accountId != null">
-            and account_id = #{accountId}
+        <if test="accountIds != null and accountIds.size() > 0">
+            and account_id in
+            <foreach collection="accountIds" item="item" index="index" open="(" separator="," close=")">
+                #{item}
+            </foreach>
         </if>
         </if>
         <if test="startTime != null">
         <if test="startTime != null">
             AND stat_date &gt;= #{startTime}
             AND stat_date &gt;= #{startTime}
@@ -152,7 +161,7 @@
         ORDER BY totalCost desc
         ORDER BY totalCost desc
         limit 9
         limit 9
         )
         )
-        <if test="count > 0 ">
+        <if test="busTypes !=null and busTypes.size() == 9 ">
             union all
             union all
             SELECT
             SELECT
             statDate as statDate,
             statDate as statDate,
@@ -177,8 +186,11 @@
             SUM(bclick) as bclick
             SUM(bclick) as bclick
             FROM ctop_kuaishou_audience_report_daily_account t
             FROM ctop_kuaishou_audience_report_daily_account t
             where 1=1
             where 1=1
-            <if test="accountId != null">
-                and account_id = #{accountId}
+            <if test="accountIds != null and accountIds.size() > 0">
+                and account_id in
+                <foreach collection="accountIds" item="item" index="index" open="(" separator="," close=")">
+                    #{item}
+                </foreach>
             </if>
             </if>
             <if test="startTime != null">
             <if test="startTime != null">
                 AND stat_date &gt;= #{startTime}
                 AND stat_date &gt;= #{startTime}
@@ -187,22 +199,29 @@
                 AND stat_date &lt;= #{endTime}
                 AND stat_date &lt;= #{endTime}
             </if>
             </if>
             AND audience_type = 'businessInterestTags'
             AND audience_type = 'businessInterestTags'
+            AND business_interest_tags not in
+            <foreach collection="busTypes" item="item" index="index" open="(" separator="," close=")">
+                #{item}
+            </foreach>
             GROUP BY business_interest_tags
             GROUP BY business_interest_tags
-            ORDER BY charge
-            limit 0,#{count}
             ) t1
             ) t1
         </if>
         </if>
     </select>
     </select>
 
 
 
 
-    <select id="querybusinessTypeCount" resultType="java.lang.Integer">
-        SELECT count(1) FROM (
+    <select id="querybusinessTypeCount" resultType="java.lang.String">
+        SELECT businessInterestTags FROM (
         SELECT
         SELECT
-        1
+        sum(charge) as totalCost,
+        business_interest_tags as businessInterestTags
         FROM ctop_kuaishou_audience_report_daily_account
         FROM ctop_kuaishou_audience_report_daily_account
-        where 1=1
-        <if test="accountId != null">
-            and account_id = #{accountId}
+        where audience_type = 'businessInterestTags'
+        AND business_interest_tags != '其他'
+        <if test="accountIds != null and accountIds.size() > 0">
+            and account_id in
+            <foreach collection="accountIds" item="item" index="index" open="(" separator="," close=")">
+                #{item}
+            </foreach>
         </if>
         </if>
         <if test="startTime != null">
         <if test="startTime != null">
             AND stat_date &gt;= #{startTime}
             AND stat_date &gt;= #{startTime}
@@ -210,10 +229,9 @@
         <if test="endTime != null">
         <if test="endTime != null">
             AND stat_date &lt;= #{endTime}
             AND stat_date &lt;= #{endTime}
         </if>
         </if>
-        <if test="audienceType == 'businessInterestTags' ">
-            AND audience_type = #{audienceType}
-            GROUP BY business_interest_tags
-        </if>
-        ) as tt
+        GROUP BY business_interest_tags
+        ORDER BY totalCost desc
+        limit 9
+        ) t1
     </select>
     </select>
 </mapper>
 </mapper>

+ 3 - 3
module-kuaishou/src/main/java/cn/com/ctop/kuaishou/modules/report/service/impl/KuaishouAudienceReportDailyAccountServiceImpl.java

@@ -39,7 +39,7 @@ public class KuaishouAudienceReportDailyAccountServiceImpl extends ServiceImpl<K
             pageSize = 10;
             pageSize = 10;
         }
         }
         PageHelper.startPage(pageNo, pageSize);
         PageHelper.startPage(pageNo, pageSize);
-        List<JSONObject>jsonObjects = accountMapper.queryPageLists(audienceReport);
+        List<JSONObject> jsonObjects = accountMapper.queryPageLists(audienceReport);
         return new PageInfo<>(jsonObjects);
         return new PageInfo<>(jsonObjects);
     }
     }
 
 
@@ -75,8 +75,8 @@ public class KuaishouAudienceReportDailyAccountServiceImpl extends ServiceImpl<K
             data.put("client", clients);
             data.put("client", clients);
         }
         }
         audienceReport.setAudienceType("businessInterestTags");
         audienceReport.setAudienceType("businessInterestTags");
-        int count = accountMapper.querybusinessTypeCount(audienceReport);
-        audienceReport.setCount(count - 9);
+        List<String> busTypes = accountMapper.querybusinessTypeCount(audienceReport);
+        audienceReport.setBusTypes(busTypes);
         List<JSONObject> bussiness = accountMapper.querybusinessTypeReportForm(audienceReport);
         List<JSONObject> bussiness = accountMapper.querybusinessTypeReportForm(audienceReport);
         if (!Check.isNull(bussiness)) {
         if (!Check.isNull(bussiness)) {
             data.put("businessInterestTags", bussiness);
             data.put("businessInterestTags", bussiness);

+ 32 - 11
module-kuaishou/src/main/java/cn/com/ctop/kuaishou/modules/report/service/impl/RuleKuaiShouPlanServiceImpl.java

@@ -201,28 +201,49 @@ public class RuleKuaiShouPlanServiceImpl extends ServiceImpl<RuleDatePlanKuaisho
                 target.setPlanId(unitDetail.getLong("campaign_id"));
                 target.setPlanId(unitDetail.getLong("campaign_id"));
                 target.setUnitId(unitDetail.getLong("unit_id"));
                 target.setUnitId(unitDetail.getLong("unit_id"));
                 target.setSceneId(unitDetail.getJSONArray("scene_id")==null?"":unitDetail.getJSONArray("scene_id").toString());
                 target.setSceneId(unitDetail.getJSONArray("scene_id")==null?"":unitDetail.getJSONArray("scene_id").toString());
-
-                JSONArray region = unitDetail.getJSONObject("target").getJSONArray("region");
+                //获取组定向信息
+                JSONObject unitTarget = unitDetail.getJSONObject("target");
+                //地域
+                JSONArray region = unitTarget.getJSONArray("region");
                 target.setRegion(region==null?"":region.toJSONString());
                 target.setRegion(region==null?"":region.toJSONString());
-
+                //性别
                 Integer gender = unitDetail.getJSONObject("target").getInteger("gender");
                 Integer gender = unitDetail.getJSONObject("target").getInteger("gender");
                 target.setGender(gender==null?0:gender);
                 target.setGender(gender==null?0:gender);
-
-                Integer platformOs = unitDetail.getJSONObject("target").getInteger("platform_os");
+                //年龄
+                JSONArray agesRange = unitTarget.getJSONArray("ages_range");
+                target.setAgesRange(agesRange==null?"":agesRange.toJSONString());
+                //操作系统
+                Integer platformOs = unitTarget.getInteger("platform_os");
                 target.setPlatformOs(platformOs==null?0:platformOs);
                 target.setPlatformOs(platformOs==null?0:platformOs);
-
-                JSONArray deviceBrand = unitDetail.getJSONObject("target").getJSONArray("device_brand");
+                //设类类型
+                JSONArray deviceBrand = unitTarget.getJSONArray("device_brand");
                 target.setDeviceBrand(deviceBrand==null?"":deviceBrand.toJSONString());
                 target.setDeviceBrand(deviceBrand==null?"":deviceBrand.toJSONString());
-
-                JSONArray devicePrice = unitDetail.getJSONObject("target").getJSONArray("device_price");
+                //设备价格
+                JSONArray devicePrice = unitTarget.getJSONArray("device_price");
                 target.setDevicePrice(devicePrice==null?"":devicePrice.toJSONString());
                 target.setDevicePrice(devicePrice==null?"":devicePrice.toJSONString());
-
-                Integer filterConvertedLevel = unitDetail.getJSONObject("target").getInteger("filter_converted_level");
+                //过滤已转化人群
+                Integer filterConvertedLevel = unitTarget.getInteger("filter_converted_level");
                 target.setFilterConvertedLevel(filterConvertedLevel);
                 target.setFilterConvertedLevel(filterConvertedLevel);
+                //人群包定向
+                JSONArray population = unitTarget.getJSONArray("population");
+                target.setPopulation(population==null?"":population.toJSONString());
+                //人群包排除
+                JSONArray excludePopulation = unitTarget.getJSONArray("exclude_population");
+                target.setExcludePopulation(excludePopulation==null?"":excludePopulation.toJSONString());
+                //应用商店
+                JSONArray appStore = unitDetail.getJSONArray("app_store");
+                target.setAppStore(appStore==null?"":appStore.toJSONString());
+                //商业兴趣
+                JSONArray businessInterest = unitTarget.getJSONArray("business_interest");
+                target.setBusinessInterest(businessInterest==null?"":businessInterest.toJSONString());
+                //网络环境
+                Integer network = unitTarget.getInteger("network");
+                target.setNetwork(network==null?0:network);
 
 
                 Integer isOpen = unitDetail.getJSONObject("target").getJSONObject("intelli_extend").getInteger("is_open");
                 Integer isOpen = unitDetail.getJSONObject("target").getJSONObject("intelli_extend").getInteger("is_open");
                 target.setIsOpen(isOpen==null?0:isOpen);
                 target.setIsOpen(isOpen==null?0:isOpen);
                 target.setScheduleTime(unitDetail.getString("schedule_time")==null?"":unitDetail.getString("schedule_time"));
                 target.setScheduleTime(unitDetail.getString("schedule_time")==null?"":unitDetail.getString("schedule_time"));
+
                 batch.add(target);
                 batch.add(target);
             }
             }
         });
         });