소스 검색

Merge branch 'V2.0.1'

zhaoxian 4 년 전
부모
커밋
ec981f5332

+ 204 - 185
jeecg-boot-module-system/src/main/java/cn/com/ctop/kuaishou/modules/ai/service/impl/AiKuaishouCreateCreativeServiceImpl.java

@@ -288,6 +288,7 @@ public class AiKuaishouCreateCreativeServiceImpl implements IAiKuaishouCreateCre
                 }
             }
         } else {
+
             //单一应用
             String replaceString = KuaishouCreativeMatTypeEnum.getNameByType(strategy.getUnitType().toString() + createType.toString());
             Long appId = null;
@@ -302,12 +303,15 @@ public class AiKuaishouCreateCreativeServiceImpl implements IAiKuaishouCreateCre
                     appName = appInfo.getAppName();
                 }
             }
+            KuaishouChannel channel = null;
+            KuaishouChannel usedchannel = null;
+            Long newCampaignId = null;
             //渠道号应用层级,account-账户,plan-计划,group-组
             String level = strategy.getUsageLevel();
             Integer useChannel = strategy.getUseChannel();//0不使用,1使用
-            KuaishouChannel channel = null;
-            if (!Check.isNull(useChannel) && useChannel == 1 && ("account".equals(level) || "plan".equals(level))) {
-                try {
+            useChannel = Check.isNull(useChannel) ? 0 : 1;
+            try {
+                if (!Check.isNull(useChannel) && useChannel == 1 && ("account".equals(level) || "plan".equals(level))) {
                     Result<Object> result = channelService.queryChannel(accountId, level, appName, null);
                     Integer code = result.getCode();
                     if (code == 200) {
@@ -322,113 +326,120 @@ public class AiKuaishouCreateCreativeServiceImpl implements IAiKuaishouCreateCre
                         log.error("通过账户(" + accountId + ")未获取到渠道号!!!");
                         return videoCnt;
                     }
-                } catch (Exception e) {
-                    e.printStackTrace();
                 }
-            }
-            Long newCampaignId = getCampaignId(strategy, token, replaceString, "TODAY", createType, appId, strategyUuid, channel);
-            if (null == newCampaignId) {
-                return videoCnt;
-            }
-            KuaishouChannel usedchannel = null;
-            if (useChannel == 1) {
-                strategy.setMaterialKeyword(null);
-                if (!"group".equals(level)) {
-                    usedchannel = channelService.queryUsedChannel(accountId, newCampaignId, level);
-                    if (Check.isNull(usedchannel)) {
-                        if ("account".equals(level)) {
-                            usedchannel = channel;
-                        } else {
-                            return videoCnt;
+                newCampaignId = getCampaignId(strategy, token, replaceString, "TODAY", createType, appId, strategyUuid, channel);
+                if (null == newCampaignId) {
+                    channelService.callBackUpdateChannelRel(level, channel.getChannelCode(), accountId, newCampaignId, null, 0);
+                    return videoCnt;
+                }
+
+                if (useChannel == 1) {
+                    strategy.setMaterialKeyword(null);
+                    if (!"group".equals(level)) {
+                        usedchannel = channelService.queryUsedChannel(accountId, newCampaignId, level);
+                        if (Check.isNull(usedchannel)) {
+                            if ("account".equals(level)) {
+                                usedchannel = channel;
+                            } else {
+                                channelService.callBackUpdateChannelRel(level, channel.getChannelCode(), accountId, newCampaignId, null, 0);
+                                return videoCnt;
+                            }
+                        }
+                        List<KuaishouChannelItems> items = usedchannel.getItems();
+                        if (!Check.isNull(items) && !items.isEmpty()) {
+                            strategy.setMaterialKeyword(items.get(0).getKeyword());
                         }
-                    }
-                    List<KuaishouChannelItems> items = usedchannel.getItems();
-                    if (!Check.isNull(items) && !items.isEmpty()) {
-                        strategy.setMaterialKeyword(items.get(0).getKeyword());
                     }
                 }
-            }
-            List<KuaiShouVideoGet> newVideos = getVideosByParams(strategy, startTime, endTime, null, createType, videoCnt);
-            if (null == newVideos || newVideos.isEmpty()) {
-                log.info("账户:{},{} 到 {} 未获取到相应素材({})", accountId, startTime, endTime, replaceString);
-                return videoCnt;
-            }
-            //3、在“上新”计划中新增广告组,一个素材搭配n张封面,组成一个广告组
-            for (KuaiShouVideoGet videoItem : newVideos) {
-                Boolean unitOverrun = getUnitOverrun(accountId);
-                if (unitOverrun) {
-                    log.error("组创建超限,accountId:{}", accountId);
-                    return 0L;
+                List<KuaiShouVideoGet> newVideos = getVideosByParams(strategy, startTime, endTime, null, createType, videoCnt);
+                if (null == newVideos || newVideos.isEmpty()) {
+                    log.info("账户:{},{} 到 {} 未获取到相应素材({})", accountId, startTime, endTime, replaceString);
+                    return videoCnt;
                 }
+                //3、在“上新”计划中新增广告组,一个素材搭配n张封面,组成一个广告组
+                for (KuaiShouVideoGet videoItem : newVideos) {
+                    Boolean unitOverrun = getUnitOverrun(accountId);
+                    if (unitOverrun) {
+                        log.error("组创建超限,accountId:{}", accountId);
+                        return 0L;
+                    }
 
-                KuaishouAccountCreativeOverrunInfo overrunInfo = overrunInfoService.getByParams(accountId, DateUtils.formatDate(new Date()));
-                if (null != overrunInfo) {
-                    return 0L;
-                }
-                // 每个组,搭配5个创意
-                List<MaterialCutFrame> cutFrameList = materialCutFrameService.getListByVideoSignature(videoItem.getSignature());
-                if ((null == cutFrameList || cutFrameList.isEmpty())) {
-                    log.info("未获取到视频封面=>videoSignature:{}", videoItem.getSignature());
-                    continue;
-                }
-                //获取组级渠道号
-                if (!Check.isNull(useChannel) && useChannel == 1 && "group".equals(level)) {
-                    try {
-                        Result<Object> result = channelService.queryChannel(accountId, level, appName, videoItem.getPhotoName());
-                        Integer code = result.getCode();
-                        if (code == 200) {
-                            usedchannel = (KuaishouChannel) result.getResult();
-                            if (Check.isNull(usedchannel)) {
-                                log.info("(组级)账户:{}素材名称({}),{}",accountId,videoItem.getPhotoName(), result.getMessage());
-                                continue;
+                    KuaishouAccountCreativeOverrunInfo overrunInfo = overrunInfoService.getByParams(accountId, DateUtils.formatDate(new Date()));
+                    if (null != overrunInfo) {
+                        return 0L;
+                    }
+                    // 每个组,搭配5个创意
+                    List<MaterialCutFrame> cutFrameList = materialCutFrameService.getListByVideoSignature(videoItem.getSignature());
+                    if ((null == cutFrameList || cutFrameList.isEmpty())) {
+                        log.info("未获取到视频封面=>videoSignature:{}", videoItem.getSignature());
+                        continue;
+                    }
+                    //获取组级渠道号
+                    if (!Check.isNull(useChannel) && useChannel == 1 && "group".equals(level)) {
+                        try {
+                            Result<Object> result = channelService.queryChannel(accountId, level, appName, videoItem.getPhotoName());
+                            Integer code = result.getCode();
+                            if (code == 200) {
+                                usedchannel = (KuaishouChannel) result.getResult();
+                                if (Check.isNull(usedchannel)) {
+                                    log.info("(组级)账户:{}素材名称({}),{}", accountId, videoItem.getPhotoName(), result.getMessage());
+                                    continue;
+                                } else {
+                                    log.info("(组级)获取到渠道号:{}", usedchannel.getChannelCode());
+                                }
                             } else {
-                                log.info("(组级)获取到渠道号:{}", usedchannel.getChannelCode());
+                                log.error("(组级)账户:{}素材名称({}),未获取到渠道号!!!", accountId, videoItem.getPhotoName());
+                                continue;
                             }
-                        } else {
-                            log.error("(组级)账户:{}素材名称({}),未获取到渠道号!!!",accountId,videoItem.getPhotoName());
-                            continue;
+                        } catch (Exception e) {
+                            e.printStackTrace();
                         }
-                    } catch (Exception e) {
-                        e.printStackTrace();
                     }
-                }
-                String unitName = getName(strategy.getGroupName(), strategy, createType, videoItem.getPhotoName(), "unit", newCampaignId, appId, usedchannel);
-                JSONObject unitParams = createUnitParams(token, newCampaignId, strategy, unitName, appId, usedchannel);
-                log.info("创建广告组入参:{}", unitParams);
-                Map<String, Object> unitCreateResult = kuaishouInterfaceService.adUnitCreate(token.getAccessToken(), token.getAccountId(), unitParams, 1);
-                Integer unitCode = (Integer) unitCreateResult.get("code");
-                String unitMessage = (String) unitCreateResult.get("message");
-                AiKuaishouUnitLevelOperationRecord unitLevelOperationRecord = new AiKuaishouUnitLevelOperationRecord();
-                BeanUtils.copyProperties(strategy, unitLevelOperationRecord);
-                unitLevelOperationRecord.setGroupName(unitName);
-                unitLevelOperationRecord.setCampaignId(newCampaignId);
-                unitLevelOperationRecord.setCpaBid(unitParams.getInteger("cpa_bid"));
-                unitLevelOperationRecord.setBid(unitParams.getInteger("bid"));
-                unitLevelOperationRecord.setDeepConversionBid(unitParams.getInteger("deep_conversion_bid"));
-                unitLevelOperationRecord.setCreateTime(new Date());
-                unitLevelOperationRecord.setStatus(unitCode);
-                unitLevelOperationRecord.setMessage(unitMessage);
-                unitLevelOperationRecord.setCampaignId(newCampaignId);
-                unitLevelOperationRecord.setAiStrategyUuid(strategyUuid);
-                if (unitCode != 0) {
-                    log.info("组创建失败=>accountId:{};message:{}", accountId, unitMessage);
+                    String unitName = getName(strategy.getGroupName(), strategy, createType, videoItem.getPhotoName(), "unit", newCampaignId, appId, usedchannel);
+                    JSONObject unitParams = createUnitParams(token, newCampaignId, strategy, unitName, appId, usedchannel);
+                    log.info("创建广告组入参:{}", unitParams);
+                    Map<String, Object> unitCreateResult = kuaishouInterfaceService.adUnitCreate(token.getAccessToken(), token.getAccountId(), unitParams, 1);
+                    Integer unitCode = (Integer) unitCreateResult.get("code");
+                    String unitMessage = (String) unitCreateResult.get("message");
+                    AiKuaishouUnitLevelOperationRecord unitLevelOperationRecord = new AiKuaishouUnitLevelOperationRecord();
+                    BeanUtils.copyProperties(strategy, unitLevelOperationRecord);
+                    unitLevelOperationRecord.setGroupName(unitName);
+                    unitLevelOperationRecord.setCampaignId(newCampaignId);
+                    unitLevelOperationRecord.setCpaBid(unitParams.getInteger("cpa_bid"));
+                    unitLevelOperationRecord.setBid(unitParams.getInteger("bid"));
+                    unitLevelOperationRecord.setDeepConversionBid(unitParams.getInteger("deep_conversion_bid"));
+                    unitLevelOperationRecord.setCreateTime(new Date());
+                    unitLevelOperationRecord.setStatus(unitCode);
+                    unitLevelOperationRecord.setMessage(unitMessage);
+                    unitLevelOperationRecord.setCampaignId(newCampaignId);
+                    unitLevelOperationRecord.setAiStrategyUuid(strategyUuid);
+                    if (unitCode != 0) {
+                        log.info("组创建失败=>accountId:{};message:{}", accountId, unitMessage);
+                        unitLevelOperationRecordService.saveOrUpdate(unitLevelOperationRecord);
+                        if (!Check.isNull(usedchannel)) {
+                            channelService.callBackUpdateChannelRel(level, usedchannel.getChannelCode(), accountId, newCampaignId, null, 0);
+                        }
+                        continue;
+                    }
+                    Long unitId = (Long) unitCreateResult.get("unitId");
+                    unitLevelOperationRecord.setUnitId(unitId);
                     unitLevelOperationRecordService.saveOrUpdate(unitLevelOperationRecord);
+                    videoCnt--;
                     if (!Check.isNull(usedchannel)) {
-                        channelService.callBackUpdateChannelRel(level, usedchannel.getChannelCode(), accountId, newCampaignId, null, 0);
+                        channelService.callBackUpdateChannelRel(level, usedchannel.getChannelCode(), accountId, newCampaignId, unitId, 1);
                     }
-                    continue;
+                    JSONObject creativeParams = creativeParams(token, unitId, videoItem, strategy, usedchannel);//TODO 添加素材
+                    createCreativeByImage(cutFrameList, token, creativeParams, newCampaignId, unitId, videoItem, strategy.getImageCnt(), strategy, strategyUuid, null);
+                    if (videoCnt <= 0) {
+                        return 0L;
+                    }
+
                 }
-                Long unitId = (Long) unitCreateResult.get("unitId");
-                unitLevelOperationRecord.setUnitId(unitId);
-                unitLevelOperationRecordService.saveOrUpdate(unitLevelOperationRecord);
-                videoCnt--;
+            } catch (Exception e) {
+                e.printStackTrace();
+                log.error("创建自定义广告组异常", e);
                 if (!Check.isNull(usedchannel)) {
-                    channelService.callBackUpdateChannelRel(level, usedchannel.getChannelCode(), accountId, newCampaignId, unitId, 1);
-                }
-                JSONObject creativeParams = creativeParams(token, unitId, videoItem, strategy, usedchannel);//TODO 添加素材
-                createCreativeByImage(cutFrameList, token, creativeParams, newCampaignId, unitId, videoItem, strategy.getImageCnt(), strategy, strategyUuid, null);
-                if (videoCnt <= 0) {
-                    return 0L;
+                    channelService.callBackUpdateChannelRel(level, usedchannel.getChannelCode(), accountId, newCampaignId, null, 0);
                 }
             }
         }
@@ -661,9 +672,12 @@ public class AiKuaishouCreateCreativeServiceImpl implements IAiKuaishouCreateCre
             //渠道号应用层级,account-账户,plan-计划,group-组
             String level = strategy.getUsageLevel();
             Integer useChannel = strategy.getUseChannel();//0不使用,1使用
+            useChannel = Check.isNull(useChannel) ? 0 : 1;
             KuaishouChannel channel = null;
-            if (!Check.isNull(useChannel) && useChannel == 1 && ("account".equals(level) || "plan".equals(level))) {
-                try {
+            KuaishouChannel usedchannel = null;
+            Long newCampaignId = null;
+            try {
+                if (!Check.isNull(useChannel) && useChannel == 1 && ("account".equals(level) || "plan".equals(level))) {
                     Result<Object> result = channelService.queryChannel(accountId, level, appName, null);
                     Integer code = result.getCode();
                     if (code == 200) {
@@ -678,114 +692,119 @@ public class AiKuaishouCreateCreativeServiceImpl implements IAiKuaishouCreateCre
                         log.error("通过账户(" + accountId + ")未获取到渠道号!!!");
                         return;
                     }
-                } catch (Exception e) {
-                    e.printStackTrace();
                 }
-            }
-            Long newCampaignId = getCampaignId(strategy, token, replaceString, "TODAY", createType, appId, strategyUuid, channel);
-            if (null == newCampaignId) {
-                return;
-            }
-            KuaishouChannel usedchannel = null;
-            if (useChannel == 1) {
-                strategy.setMaterialKeyword(null);
-                if (!"group".equals(level)) {
-                    usedchannel = channelService.queryUsedChannel(accountId, newCampaignId, level);
-                    if (Check.isNull(usedchannel)) {
-                        if ("account".equals(level)) {
-                            usedchannel = channel;
-                        } else {
-                            return;
+                newCampaignId = getCampaignId(strategy, token, replaceString, "TODAY", createType, appId, strategyUuid, channel);
+                if (null == newCampaignId) {
+                    channelService.callBackUpdateChannelRel(level, channel.getChannelCode(), accountId, newCampaignId, null, 0);
+                    return;
+                }
+                if (useChannel == 1) {
+                    strategy.setMaterialKeyword(null);
+                    if (!"group".equals(level)) {
+                        usedchannel = channelService.queryUsedChannel(accountId, newCampaignId, level);
+                        if (Check.isNull(usedchannel)) {
+                            if ("account".equals(level)) {
+                                usedchannel = channel;
+                            } else {
+                                channelService.callBackUpdateChannelRel(level, channel.getChannelCode(), accountId, newCampaignId, null, 0);
+                                return;
+                            }
+                        }
+                        List<KuaishouChannelItems> items = usedchannel.getItems();
+                        if (!Check.isNull(items) && !items.isEmpty()) {
+                            strategy.setMaterialKeyword(items.get(0).getKeyword());
                         }
-                    }
-                    List<KuaishouChannelItems> items = usedchannel.getItems();
-                    if (!Check.isNull(items) && !items.isEmpty()) {
-                        strategy.setMaterialKeyword(items.get(0).getKeyword());
                     }
                 }
-            }
-            List<KuaiShouVideoGet> allVideos = getVideosByParams(strategy, startTime, endTime, null, createType, videoCnt);
-            if (null == allVideos) {
-                return;
-            }
-            //创意
-            List<List<KuaiShouVideoGet>> splitVideos = Lists.partition(allVideos, 5);
-            for (int j = 1; j < splitVideos.size() + 1; j++) {
-                Boolean unitOverrun = getUnitOverrun(accountId);
-                if (unitOverrun) {
-                    log.error("组创建超限,accountId:{}", accountId);
+                List<KuaiShouVideoGet> allVideos = getVideosByParams(strategy, startTime, endTime, null, createType, videoCnt);
+                if (null == allVideos) {
                     return;
                 }
-
-                Object redisObj = redisUtil.get(key);
-                if (!Check.isNull(redisObj)) {
-                    Integer value = (Integer) redisObj;
-                    if (value == 1) {
-                        log.error("程序化创意创建超限,accountId:{}", strategy.getAccountId());
+                //创意
+                List<List<KuaiShouVideoGet>> splitVideos = Lists.partition(allVideos, 5);
+                for (int j = 1; j < splitVideos.size() + 1; j++) {
+                    Boolean unitOverrun = getUnitOverrun(accountId);
+                    if (unitOverrun) {
+                        log.error("组创建超限,accountId:{}", accountId);
                         return;
                     }
-                }
-                //获取组级渠道号
-                if (!Check.isNull(useChannel) && useChannel == 1 && "group".equals(level)) {
-                    try {
-                        KuaiShouVideoGet videoGet = splitVideos.get(1).get(0);
-                        if (Check.isNull(videoGet)) {
+
+                    Object redisObj = redisUtil.get(key);
+                    if (!Check.isNull(redisObj)) {
+                        Integer value = (Integer) redisObj;
+                        if (value == 1) {
+                            log.error("程序化创意创建超限,accountId:{}", strategy.getAccountId());
                             return;
                         }
-                        Result<Object> result = channelService.queryChannel(accountId, level, appName, videoGet.getPhotoName());
-                        Integer code = result.getCode();
-                        if (code == 200) {
-                            usedchannel = (KuaishouChannel) result.getResult();
-                            if (Check.isNull(usedchannel)) {
-                                log.info("(组级)账户:{}素材名称({}),{}",accountId,videoGet.getPhotoName(), result.getMessage());
-                                continue;
+                    }
+                    //获取组级渠道号
+                    if (!Check.isNull(useChannel) && useChannel == 1 && "group".equals(level)) {
+                        try {
+                            KuaiShouVideoGet videoGet = splitVideos.get(1).get(0);
+                            if (Check.isNull(videoGet)) {
+                                return;
+                            }
+                            Result<Object> result = channelService.queryChannel(accountId, level, appName, videoGet.getPhotoName());
+                            Integer code = result.getCode();
+                            if (code == 200) {
+                                usedchannel = (KuaishouChannel) result.getResult();
+                                if (Check.isNull(usedchannel)) {
+                                    log.info("(组级)账户:{}素材名称({}),{}", accountId, videoGet.getPhotoName(), result.getMessage());
+                                    continue;
+                                } else {
+                                    log.info("(组级)获取到渠道号:{}", usedchannel.getChannelCode());
+                                }
                             } else {
-                                log.info("(组级)获取到渠道号:{}", usedchannel.getChannelCode());
+                                log.error("(组级)账户:{}素材名称({}),未获取到渠道号!!!", accountId, videoGet.getPhotoName());
+                                continue;
                             }
-                        } else {
-                            log.error("(组级)账户:{}素材名称({}),未获取到渠道号!!!",accountId,videoGet.getPhotoName());
-                            continue;
+                        } catch (Exception e) {
+                            e.printStackTrace();
                         }
-                    } catch (Exception e) {
-                        e.printStackTrace();
                     }
-                }
 
-                //创建组
-                String unitName = getName(strategy.getGroupName(), strategy, createType, null, "unit", newCampaignId, appId, usedchannel);
-                JSONObject unitParams = createUnitParams(token, newCampaignId, strategy, unitName, appId, usedchannel);
-                log.info("创建广告组入参:{}", unitParams);
-                Map<String, Object> unitCreateResult = kuaishouInterfaceService.adUnitCreate(token.getAccessToken(), token.getAccountId(), unitParams, 1);
-                Integer unitCode = (Integer) unitCreateResult.get("code");
-                String unitMessage = (String) unitCreateResult.get("message");
-                AiKuaishouUnitLevelOperationRecord unitLevelOperationRecord = new AiKuaishouUnitLevelOperationRecord();
-                BeanUtils.copyProperties(strategy, unitLevelOperationRecord);
-                unitLevelOperationRecord.setGroupName(unitName);
-                unitLevelOperationRecord.setCampaignId(newCampaignId);
-                unitLevelOperationRecord.setCpaBid(unitParams.getInteger("cpa_bid"));
-                unitLevelOperationRecord.setBid(unitParams.getInteger("bid"));
-                unitLevelOperationRecord.setDeepConversionBid(unitParams.getInteger("deep_conversion_bid"));
-                unitLevelOperationRecord.setCreateTime(new Date());
-                unitLevelOperationRecord.setStatus(unitCode);
-                unitLevelOperationRecord.setMessage(unitMessage);
-                unitLevelOperationRecord.setCampaignId(newCampaignId);
-                unitLevelOperationRecord.setAiStrategyUuid(strategyUuid);
-                if (unitCode != 0) {
-                    log.info("组创建失败=>accountId:{};message:{}", accountId, unitMessage);
+                    //创建组
+                    String unitName = getName(strategy.getGroupName(), strategy, createType, null, "unit", newCampaignId, appId, usedchannel);
+                    JSONObject unitParams = createUnitParams(token, newCampaignId, strategy, unitName, appId, usedchannel);
+                    log.info("创建广告组入参:{}", unitParams);
+                    Map<String, Object> unitCreateResult = kuaishouInterfaceService.adUnitCreate(token.getAccessToken(), token.getAccountId(), unitParams, 1);
+                    Integer unitCode = (Integer) unitCreateResult.get("code");
+                    String unitMessage = (String) unitCreateResult.get("message");
+                    AiKuaishouUnitLevelOperationRecord unitLevelOperationRecord = new AiKuaishouUnitLevelOperationRecord();
+                    BeanUtils.copyProperties(strategy, unitLevelOperationRecord);
+                    unitLevelOperationRecord.setGroupName(unitName);
+                    unitLevelOperationRecord.setCampaignId(newCampaignId);
+                    unitLevelOperationRecord.setCpaBid(unitParams.getInteger("cpa_bid"));
+                    unitLevelOperationRecord.setBid(unitParams.getInteger("bid"));
+                    unitLevelOperationRecord.setDeepConversionBid(unitParams.getInteger("deep_conversion_bid"));
+                    unitLevelOperationRecord.setCreateTime(new Date());
+                    unitLevelOperationRecord.setStatus(unitCode);
+                    unitLevelOperationRecord.setMessage(unitMessage);
+                    unitLevelOperationRecord.setCampaignId(newCampaignId);
+                    unitLevelOperationRecord.setAiStrategyUuid(strategyUuid);
+                    if (unitCode != 0) {
+                        log.info("组创建失败=>accountId:{};message:{}", accountId, unitMessage);
+                        unitLevelOperationRecordService.saveOrUpdate(unitLevelOperationRecord);
+                        if (!Check.isNull(usedchannel)) {
+                            channelService.callBackUpdateChannelRel(level, usedchannel.getChannelCode(), accountId, newCampaignId, null, 0);
+                        }
+                        return;
+                    }
+                    Long unitId = (Long) unitCreateResult.get("unitId");
+                    unitLevelOperationRecord.setUnitId(unitId);
                     unitLevelOperationRecordService.saveOrUpdate(unitLevelOperationRecord);
                     if (!Check.isNull(usedchannel)) {
-                        channelService.callBackUpdateChannelRel(level, usedchannel.getChannelCode(), accountId, newCampaignId, null, 0);
+                        channelService.callBackUpdateChannelRel(level, usedchannel.getChannelCode(), accountId, newCampaignId, unitId, 1);
                     }
-                    return;
+                    JSONObject creativeParams = programCreativeParams(token, unitId, splitVideos.get(j - 1), strategy, j, null, usedchannel);
+                    createProgramCreative(token, creativeParams, strategy);
                 }
-                Long unitId = (Long) unitCreateResult.get("unitId");
-                unitLevelOperationRecord.setUnitId(unitId);
-                unitLevelOperationRecordService.saveOrUpdate(unitLevelOperationRecord);
-                if (!Check.isNull(channel)) {
-                    channelService.callBackUpdateChannelRel(level, channel.getChannelCode(), accountId, newCampaignId, unitId, 1);
+            } catch (Exception e) {
+                e.printStackTrace();
+                log.error("创建程序化广告组异常", e);
+                if (!Check.isNull(usedchannel)) {
+                    channelService.callBackUpdateChannelRel(level, usedchannel.getChannelCode(), accountId, newCampaignId, null, 0);
                 }
-                JSONObject creativeParams = programCreativeParams(token, unitId, splitVideos.get(j - 1), strategy, j, null, usedchannel);
-                createProgramCreative(token, creativeParams, strategy);
             }
         }
 

+ 5 - 15
jeecg-boot-module-system/src/main/java/cn/com/ctop/kuaishou/modules/channel/service/impl/KuaishouChannelItemsServiceImpl.java

@@ -3,7 +3,6 @@ package cn.com.ctop.kuaishou.modules.channel.service.impl;
 import cn.com.ctop.common.module.mapper.ProjectMapper;
 import cn.com.ctop.common.module.utils.Check;
 import cn.com.ctop.common.module.utils.ExportExcelUtils;
-import cn.com.ctop.kuaishou.modules.ai.entity.KuaishouAppPackage;
 import cn.com.ctop.kuaishou.modules.channel.entity.KuaishouChannelItems;
 import cn.com.ctop.kuaishou.modules.channel.entity.KuaishouChannelItemsRel;
 import cn.com.ctop.kuaishou.modules.channel.mapper.KuaishouChannelItemsMapper;
@@ -14,10 +13,7 @@ import com.alibaba.fastjson.JSONObject;
 import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
 import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
 import com.github.pagehelper.PageInfo;
-import org.apache.poi.hssf.usermodel.HSSFCell;
-import org.apache.poi.hssf.usermodel.HSSFDateUtil;
 import org.apache.poi.hssf.usermodel.HSSFWorkbook;
-import org.apache.poi.ss.usermodel.Cell;
 import org.apache.poi.ss.usermodel.Row;
 import org.apache.poi.ss.usermodel.Sheet;
 import org.apache.poi.ss.usermodel.Workbook;
@@ -26,16 +22,11 @@ import org.apache.shiro.SecurityUtils;
 import org.jeecg.common.api.vo.Result;
 import org.jeecg.common.system.vo.LoginUser;
 import org.jeecg.common.util.DateUtils;
-import org.jeecg.common.util.MD5Util;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.stereotype.Service;
 import org.springframework.web.multipart.MultipartFile;
 
-import java.io.IOException;
-import java.text.DecimalFormat;
-import java.text.SimpleDateFormat;
 import java.util.ArrayList;
-import java.util.Date;
 import java.util.List;
 
 /**
@@ -108,15 +99,14 @@ public class KuaishouChannelItemsServiceImpl extends ServiceImpl<KuaishouChannel
                 continue;
             }
             QueryWrapper<KuaishouChannelItemsRel> queryWrapper = new QueryWrapper<>();
-            queryWrapper.eq("channel_id", object.getLong("channelId"));
-            queryWrapper.eq("item_id", object.getLong("id")).last("limit 1");
+            queryWrapper.eq("channel_id", object.getLong("channelId")).last("limit 1");
             KuaishouChannelItemsRel one = channelItemsRelService.getOne(queryWrapper);
             if (Check.isNull(one)) {
-                KuaishouChannelItemsRel rel = new KuaishouChannelItemsRel();
-                rel.setItemId(object.getLong("id"));
-                rel.setChannelId(object.getLong("channelId"));
-                channelItemsRelService.save(rel);
+                one = new KuaishouChannelItemsRel();
             }
+            one.setItemId(object.getLong("id"));
+            one.setChannelId(object.getLong("channelId"));
+            channelItemsRelService.saveOrUpdate(one);
         }
         return Result.ok("绑定成功");
     }

+ 94 - 73
jeecg-boot-module-system/src/main/java/cn/com/ctop/kuaishou/modules/channel/service/impl/KuaishouChannelServiceImpl.java

@@ -54,12 +54,10 @@ import org.springframework.stereotype.Service;
 import org.springframework.web.multipart.MultipartFile;
 
 import java.util.ArrayList;
+import java.util.Date;
 import java.util.HashMap;
 import java.util.List;
-import java.util.Locale;
 import java.util.Map;
-import java.util.concurrent.ExecutorService;
-import java.util.concurrent.Executors;
 
 /**
  * 渠道号信息表
@@ -123,8 +121,6 @@ public class KuaishouChannelServiceImpl extends ServiceImpl<KuaishouChannelMappe
     private static final String NUMBER_STR = "{{编号}}";
     private static final String CHANNEL = "_channel_FLAG";
 
-    static ExecutorService executorService = Executors.newFixedThreadPool(5);
-
 
     @Override
     public Result<Object> channelManagementHome(Long productId, Long projectId, Long accountId, String userId) {
@@ -329,41 +325,47 @@ public class KuaishouChannelServiceImpl extends ServiceImpl<KuaishouChannelMappe
                     }
                 } else {
                     /**-----------------项目维度:使用层级是计划、组-----------------*/
-                    accountList.forEach(accountId -> executorService.submit(() -> {
-                        //获取token
-                        CtopOauthToken token = tokenService.getTokenByAccountId(accountId);
-                        //获取应用图片token
-                        JSONObject tokenJson = appInfoService.uploadAppIconImage(strategy.getAppIconUrl(), token.getAccountId(), token.getAccessToken());
-                        if (!Check.isNull(tokenJson) && tokenJson.getInteger("code") != 0) {
-                            log.error("通过账户ID(" + token.getAccountId() + ")获取图片Token失败,返回信息:" + tokenJson.getString("message"));
-                        }
-                        //使用范围是账户时,查询旧app来做匹配
-                        kuaishouInterfaceService.getAppList(accountId, token.getAccessToken());
-                        List<KuaiShouAppList> oldAppList = kuaiShouAppListService.getAppListByAccountId(accountId);
-                        strategy.setImageToken(tokenJson.getString("imageToken"));
-                        strategy.setAccountId(accountId);
-                        if (url.contains(CHANNEL_STR)) {
-                            for (int i = numberMin; i <= numberMax; i++) {
-                                try {
-                                    KuaishouChannelCreateStrategy replaceData = replaceWildcard(strategy, i);
-                                    createApp(replaceData, token, oldAppList);
-                                    createChannel(replaceData, i, 1);
-                                } catch (Exception e) {
-                                    e.printStackTrace();
+                    Thread thread = new Thread() {
+                        @Override
+                        public void run() {
+                            for (Long accountId : accountList) {
+                                //获取token
+                                CtopOauthToken token = tokenService.getTokenByAccountId(accountId);
+                                //获取应用图片token
+                                JSONObject tokenJson = appInfoService.uploadAppIconImage(strategy.getAppIconUrl(), token.getAccountId(), token.getAccessToken());
+                                if (!Check.isNull(tokenJson) && tokenJson.getInteger("code") != 0) {
+                                    log.error("通过账户ID(" + token.getAccountId() + ")获取图片Token失败,返回信息:" + tokenJson.getString("message"));
                                 }
-                            }
-                        } else {
-                            try {
-                                createApp(strategy, token, oldAppList);
-                                for (int i = numberMin; i <= numberMax; i++) {
-                                    KuaishouChannelCreateStrategy replaceData = replaceWildcard(strategy, i);
-                                    createChannel(replaceData, i, 1);
+                                //使用范围是账户时,查询旧app来做匹配
+                                kuaishouInterfaceService.getAppList(accountId, token.getAccessToken());
+                                List<KuaiShouAppList> oldAppList = kuaiShouAppListService.getAppListByAccountId(accountId);
+                                strategy.setImageToken(tokenJson.getString("imageToken"));
+                                strategy.setAccountId(accountId);
+                                if (url.contains(CHANNEL_STR)) {
+                                    for (int i = numberMin; i <= numberMax; i++) {
+                                        try {
+                                            KuaishouChannelCreateStrategy replaceData = replaceWildcard(strategy, i);
+                                            createApp(replaceData, token, oldAppList);
+                                            createChannel(replaceData, i, 1);
+                                        } catch (Exception e) {
+                                            e.printStackTrace();
+                                        }
+                                    }
+                                } else {
+                                    try {
+                                        createApp(strategy, token, oldAppList);
+                                        for (int i = numberMin; i <= numberMax; i++) {
+                                            KuaishouChannelCreateStrategy replaceData = replaceWildcard(strategy, i);
+                                            createChannel(replaceData, i, 1);
+                                        }
+                                    } catch (Exception e) {
+                                        e.printStackTrace();
+                                    }
                                 }
-                            } catch (Exception e) {
-                                e.printStackTrace();
                             }
                         }
-                    }));
+                    };
+                    thread.start();
                 }
             } else {
                 /**==========================范围是 账户==========================*/
@@ -379,25 +381,38 @@ public class KuaishouChannelServiceImpl extends ServiceImpl<KuaishouChannelMappe
                 List<KuaiShouAppList> oldAppList = kuaiShouAppListService.getAppListByAccountId(token.getAccountId());
                 strategy.setImageToken(tokenJson.getString("imageToken"));
                 if (url.contains(CHANNEL_STR)) {
-                    ilist.forEach(i -> executorService.submit(() -> {
-                        try {
-                            KuaishouChannelCreateStrategy replaceData = replaceWildcard(strategy, i);
-                            createApp(replaceData, token, oldAppList);
-                            createChannel(replaceData, i, 1);
-                        } catch (Exception e) {
-                            e.printStackTrace();
+                    Thread thread = new Thread() {
+                        @Override
+                        public void run() {
+                            try {
+                                for (int i = numberMin; i <= numberMax; i++) {
+                                    KuaishouChannelCreateStrategy replaceData = replaceWildcard(strategy, i);
+                                    createApp(replaceData, token, oldAppList);
+                                    createChannel(replaceData, i, 1);
+                                }
+
+                            } catch (Exception e) {
+                                e.printStackTrace();
+                            }
                         }
-                    }));
+                    };
+                    thread.start();
                 } else {
                     createApp(strategy, token, oldAppList);
-                    ilist.forEach(i -> executorService.submit(() -> {
-                        try {
-                            KuaishouChannelCreateStrategy replaceData = replaceWildcard(strategy, i);
-                            createChannel(replaceData, i, 1);
-                        } catch (Exception e) {
-                            e.printStackTrace();
+                    Thread thread = new Thread() {
+                        @Override
+                        public void run() {
+                            try {
+                                for (int i = numberMin; i <= numberMax; i++) {
+                                    KuaishouChannelCreateStrategy replaceData = replaceWildcard(strategy, i);
+                                    createChannel(replaceData, i, 1);
+                                }
+                            } catch (Exception e) {
+                                e.printStackTrace();
+                            }
                         }
-                    }));
+                    };
+                    thread.start();
                 }
             }
         } catch (Exception e) {
@@ -913,26 +928,32 @@ public class KuaishouChannelServiceImpl extends ServiceImpl<KuaishouChannelMappe
                         }
                     } else {
                         /**-----------------项目维度:使用层级是计划、组-----------------*/
-                        accountList.forEach(accountId -> executorService.submit(() -> {
-                            //获取token
-                            CtopOauthToken token = tokenService.getTokenByAccountId(accountId);
-                            //获取应用图片token
-                            JSONObject tokenJson = appInfoService.uploadAppIconImage(strategy.getAppIconUrl(), token.getAccountId(), token.getAccessToken());
-                            if (!Check.isNull(tokenJson) && tokenJson.getInteger("code") != 0) {
-                                log.error("通过账户ID(" + token.getAccountId() + ")获取图片Token失败,返回信息:" + tokenJson.getString("message"));
-                            }
-                            //使用范围是账户时,查询旧app来做匹配
-                            kuaishouInterfaceService.getAppList(token.getAccountId(), token.getAccessToken());
-                            List<KuaiShouAppList> oldAppList = kuaiShouAppListService.getAppListByAccountId(accountId);
-                            strategy.setImageToken(tokenJson.getString("imageToken"));
-                            strategy.setAccountId(accountId);
-                            try {
-                                createApp(strategy, token, oldAppList);
-                                createChannel(strategy, 0, 1);
-                            } catch (Exception e) {
-                                e.printStackTrace();
+                        Thread thread = new Thread() {
+                            @Override
+                            public void run() {
+                                for (Long accountId : accountList) {
+                                    //获取token
+                                    CtopOauthToken token = tokenService.getTokenByAccountId(accountId);
+                                    //获取应用图片token
+                                    JSONObject tokenJson = appInfoService.uploadAppIconImage(strategy.getAppIconUrl(), token.getAccountId(), token.getAccessToken());
+                                    if (!Check.isNull(tokenJson) && tokenJson.getInteger("code") != 0) {
+                                        log.error("通过账户ID(" + token.getAccountId() + ")获取图片Token失败,返回信息:" + tokenJson.getString("message"));
+                                    }
+                                    //使用范围是账户时,查询旧app来做匹配
+                                    kuaishouInterfaceService.getAppList(token.getAccountId(), token.getAccessToken());
+                                    List<KuaiShouAppList> oldAppList = kuaiShouAppListService.getAppListByAccountId(accountId);
+                                    strategy.setImageToken(tokenJson.getString("imageToken"));
+                                    strategy.setAccountId(accountId);
+                                    try {
+                                        createApp(strategy, token, oldAppList);
+                                        createChannel(strategy, 0, 1);
+                                    } catch (Exception e) {
+                                        e.printStackTrace();
+                                    }
+                                }
                             }
-                        }));
+                        };
+                        thread.start();
                     }
                 } else {
                     /**==========================范围是 账户==========================*/
@@ -1035,8 +1056,9 @@ public class KuaishouChannelServiceImpl extends ServiceImpl<KuaishouChannelMappe
             queryWrapper.eq("channel_code", channelCode).last("limit 1");
             KuaishouChannel one = this.getOne(queryWrapper);
             if (!Check.isNull(one)) {
+                one.setUpdateTime(new Date());
+                one.setChannelLock(1);
                 if (0 == state) {
-                    one.setChannelLock(1);
                     this.saveOrUpdate(one);
                 } else {
                     QueryWrapper<KuaishouChannelRel> relqueryWrapper = new QueryWrapper<>();
@@ -1049,16 +1071,15 @@ public class KuaishouChannelServiceImpl extends ServiceImpl<KuaishouChannelMappe
                         }
                         rel.setCampaignId(planId);
                         rel.setUnitId(groupId);
+                        rel.setUpdateTime(new Date());
                         channelRelService.save(rel);
                         if ("plan".equals(level)) {
                             Integer usageTimes = channelRelService.queryUsePlanCount(accountId, channelCode);
                             one.setUsageTimes(usageTimes);
-                            one.setChannelLock(1);
                             this.saveOrUpdate(one);
                         } else if ("group".equals(level)) {
                             Integer usageTimes = channelRelService.queryUseGroupCount(accountId, channelCode);
                             one.setUsageTimes(usageTimes);
-                            one.setChannelLock(1);
                             this.saveOrUpdate(one);
                         }
                     }