Преглед на файлове

渠道号。。。兼容账户维度自动投放

zhaoxian преди 4 години
родител
ревизия
5818626b4a

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

@@ -8,19 +8,43 @@ import cn.com.ctop.common.module.utils.Check;
 import cn.com.ctop.common.module.utils.HttpUtils;
 import cn.com.ctop.common.module.utils.KuaishouInterfaceConstant;
 import cn.com.ctop.common.module.utils.PropertiesUtils;
-import cn.com.ctop.kuaishou.modules.ai.entity.*;
+import cn.com.ctop.kuaishou.modules.ai.entity.AiKuaiShouAppInfo;
+import cn.com.ctop.kuaishou.modules.ai.entity.AiKuaishouAdvertiserStrategy;
+import cn.com.ctop.kuaishou.modules.ai.entity.AiKuaishouCampaignLevelOperationRecord;
+import cn.com.ctop.kuaishou.modules.ai.entity.AiKuaishouCreativeLevelOperationRecord;
+import cn.com.ctop.kuaishou.modules.ai.entity.AiKuaishouUnitLevelOperationRecord;
+import cn.com.ctop.kuaishou.modules.ai.entity.KuaiShouAppMultipleBids;
+import cn.com.ctop.kuaishou.modules.ai.entity.KuaishouAccountCreativeOverrunInfo;
 import cn.com.ctop.kuaishou.modules.ai.enums.KuaishouCreativeAdsenceTypeEnum;
 import cn.com.ctop.kuaishou.modules.ai.enums.KuaishouCreativeMatTypeEnum;
-import cn.com.ctop.kuaishou.modules.ai.service.*;
+import cn.com.ctop.kuaishou.modules.ai.service.IAiKuaiShouAppInfoService;
+import cn.com.ctop.kuaishou.modules.ai.service.IAiKuaishouCampaignLevelOperationRecordService;
+import cn.com.ctop.kuaishou.modules.ai.service.IAiKuaishouCreateCreativeService;
+import cn.com.ctop.kuaishou.modules.ai.service.IAiKuaishouCreativeLevelOperationRecordService;
+import cn.com.ctop.kuaishou.modules.ai.service.IAiKuaishouUnitLevelOperationRecordService;
+import cn.com.ctop.kuaishou.modules.ai.service.IKuaiShouAppMultipleBidsService;
+import cn.com.ctop.kuaishou.modules.ai.service.IKuaishouAccountCreativeOverrunInfoService;
+import cn.com.ctop.kuaishou.modules.ai.service.IKuaishouLandpagePackageService;
 import cn.com.ctop.kuaishou.modules.batch.entity.KuaiShouAppList;
 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.service.*;
+import cn.com.ctop.kuaishou.modules.batch.service.IKuaiShouAppListService;
+import cn.com.ctop.kuaishou.modules.batch.service.IKuaiShouCampaignService;
+import cn.com.ctop.kuaishou.modules.batch.service.IKuaiShouGroupService;
+import cn.com.ctop.kuaishou.modules.batch.service.IKuaiShouGroupTemplateService;
+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.IKuaiShouUpdateService;
+import cn.com.ctop.kuaishou.modules.batch.service.IKuaiShouVideoGetService;
+import cn.com.ctop.kuaishou.modules.batch.service.IKuaishouInterfaceService;
+import cn.com.ctop.kuaishou.modules.channel.entity.KuaishouChannel;
+import cn.com.ctop.kuaishou.modules.channel.service.IKuaishouChannelService;
 import com.alibaba.fastjson.JSON;
 import com.alibaba.fastjson.JSONArray;
 import com.alibaba.fastjson.JSONObject;
 import com.google.common.collect.Lists;
 import lombok.extern.slf4j.Slf4j;
+import org.jeecg.common.api.vo.Result;
 import org.jeecg.common.util.DateUtils;
 import org.jeecg.common.util.RedisUtil;
 import org.springframework.beans.BeanUtils;
@@ -29,7 +53,14 @@ import org.springframework.stereotype.Service;
 
 import java.math.BigDecimal;
 import java.text.ParseException;
-import java.util.*;
+import java.util.ArrayList;
+import java.util.Collections;
+import java.util.Date;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+import java.util.Random;
+import java.util.UUID;
 
 @Slf4j
 @Service
@@ -64,6 +95,8 @@ public class AiKuaishouCreateCreativeServiceImpl implements IAiKuaishouCreateCre
     private IKuaishouLandpagePackageService landpagePackageService;
     @Autowired
     private IKuaiShouAppMultipleBidsService kuaiShouAppMultipleBidsService;
+    @Autowired
+    private IKuaishouChannelService channelService;
 
 
     /**
@@ -137,8 +170,8 @@ public class AiKuaishouCreateCreativeServiceImpl implements IAiKuaishouCreateCre
                                 continue;
                             }
                             //开始创建组+创意
-                            String unitName = getName(strategy.getGroupName(), strategy, createType, videoItem.getPhotoName(), "unit", newCampaignId, appInfo.getAppId());
-                            JSONObject unitParams = createUnitParams(token, newCampaignId, strategy, unitName, appInfo.getAppId());
+                            String unitName = getName(strategy.getGroupName(), strategy, createType, videoItem.getPhotoName(), "unit", newCampaignId, appInfo.getAppId(), null);
+                            JSONObject unitParams = createUnitParams(token, newCampaignId, strategy, unitName, appInfo.getAppId(), null);
                             log.info("创建广告组入参:{}", unitParams);
                             Map<String, Object> unitCreateResult = kuaishouInterfaceService.adUnitCreate(token.getAccessToken(), token.getAccountId(), unitParams, 1);
                             Integer unitCode = (Integer) unitCreateResult.get("code");
@@ -164,7 +197,7 @@ public class AiKuaishouCreateCreativeServiceImpl implements IAiKuaishouCreateCre
                             unitLevelOperationRecord.setUnitId(unitId);
                             unitLevelOperationRecordService.saveOrUpdate(unitLevelOperationRecord);
                             videoCnt--;
-                            JSONObject creativeParams = creativeParams(token, unitId, videoItem, strategy);
+                            JSONObject creativeParams = creativeParams(token, unitId, videoItem, strategy, null);
                             createCreativeByImage(cutFrameList, token, creativeParams, newCampaignId, unitId, videoItem, strategy.getImageCnt(), strategy, strategyUuid, appInfo.getAppVersion());
                             if (videoCnt <= 0) {
                                 return videoCnt;
@@ -211,8 +244,8 @@ public class AiKuaishouCreateCreativeServiceImpl implements IAiKuaishouCreateCre
                         }
                         Long newCampaignId = getCampaignId(strategy, token, replaceString, "TODAY", createType, appId, strategyUuid);
                         //开始创建组+创意
-                        String unitName = getName(strategy.getGroupName(), strategy, createType, videoItem.getPhotoName(), "unit", newCampaignId, appId);
-                        JSONObject unitParams = createUnitParams(token, newCampaignId, strategy, unitName, appId);
+                        String unitName = getName(strategy.getGroupName(), strategy, createType, videoItem.getPhotoName(), "unit", newCampaignId, appId, null);
+                        JSONObject unitParams = createUnitParams(token, newCampaignId, strategy, unitName, appId, null);
                         unitParams.remove("cpa_bid");
                         unitParams.put("cpa_bid", multipleBids.getCpaBid());
                         if (!Check.isNull(multipleBids.getDeepConversionBid())) {
@@ -245,7 +278,7 @@ public class AiKuaishouCreateCreativeServiceImpl implements IAiKuaishouCreateCre
                         unitLevelOperationRecord.setUnitId(unitId);
                         unitLevelOperationRecordService.saveOrUpdate(unitLevelOperationRecord);
                         videoCnt--;
-                        JSONObject creativeParams = creativeParams(token, unitId, videoItem, strategy);
+                        JSONObject creativeParams = creativeParams(token, unitId, videoItem, strategy, null);
                         createCreativeByImage(cutFrameList, token, creativeParams, newCampaignId, unitId, videoItem, strategy.getImageCnt(), strategy, strategyUuid, null);
                         if (videoCnt <= 0) {
                             return videoCnt;
@@ -268,6 +301,28 @@ public class AiKuaishouCreateCreativeServiceImpl implements IAiKuaishouCreateCre
                     return videoCnt;
                 }
             }
+            //渠道号应用层级,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 {
+                    Result<Object> result = channelService.queryChannel(accountId, level);
+                    Integer code = result.getCode();
+                    if (code == 200) {
+                        channel = (KuaishouChannel) result.getResult();
+                        if (Check.isNull(channel)) {
+                            log.info("账户:{},{}", accountId, result.getMessage());
+                        } else {
+                            log.info("获取渠道号:{}", channel.getChannelCode());
+                        }
+                    } else {
+                        log.error("通过账户(" + accountId + ")未获取到渠道号!!!");
+                    }
+                } catch (Exception e) {
+                    e.printStackTrace();
+                }
+            }
             Long newCampaignId = getCampaignId(strategy, token, replaceString, "TODAY", createType, appId, strategyUuid);
             if (null == newCampaignId) {
                 return videoCnt;
@@ -291,8 +346,27 @@ public class AiKuaishouCreateCreativeServiceImpl implements IAiKuaishouCreateCre
                     log.info("未获取到视频封面=>videoSignature:{}", videoItem.getSignature());
                     continue;
                 }
-                String unitName = getName(strategy.getGroupName(), strategy, createType, videoItem.getPhotoName(), "unit", newCampaignId, appId);
-                JSONObject unitParams = createUnitParams(token, newCampaignId, strategy, unitName, appId);
+                //获取组级渠道号
+                if (!Check.isNull(useChannel) && useChannel == 1 && "group".equals(level)) {
+                    try {
+                        Result<Object> result = channelService.queryChannel(accountId, level);
+                        Integer code = result.getCode();
+                        if (code == 200) {
+                            channel = (KuaishouChannel) result.getResult();
+                            if (Check.isNull(channel)) {
+                                log.info("账户(组级):{},{}", accountId, result.getMessage());
+                            } else {
+                                log.info("获取到组级渠道号:{}", channel.getChannelCode());
+                            }
+                        } else {
+                            log.error("通过账户(" + accountId + ")未获取到渠道号!!!");
+                        }
+                    } catch (Exception e) {
+                        e.printStackTrace();
+                    }
+                }
+                String unitName = getName(strategy.getGroupName(), strategy, createType, videoItem.getPhotoName(), "unit", newCampaignId, appId, channel);
+                JSONObject unitParams = createUnitParams(token, newCampaignId, strategy, unitName, appId, channel);
                 log.info("创建广告组入参:{}", unitParams);
                 Map<String, Object> unitCreateResult = kuaishouInterfaceService.adUnitCreate(token.getAccessToken(), token.getAccountId(), unitParams, 1);
                 Integer unitCode = (Integer) unitCreateResult.get("code");
@@ -318,7 +392,8 @@ public class AiKuaishouCreateCreativeServiceImpl implements IAiKuaishouCreateCre
                 unitLevelOperationRecord.setUnitId(unitId);
                 unitLevelOperationRecordService.saveOrUpdate(unitLevelOperationRecord);
                 videoCnt--;
-                JSONObject creativeParams = creativeParams(token, unitId, videoItem, strategy);
+                channelService.callBackUpdateChannelRel(level, channel.getChannelCode(), accountId, newCampaignId, unitId);
+                JSONObject creativeParams = creativeParams(token, unitId, videoItem, strategy, channel);//TODO 添加素材
                 createCreativeByImage(cutFrameList, token, creativeParams, newCampaignId, unitId, videoItem, strategy.getImageCnt(), strategy, strategyUuid, null);
                 if (videoCnt <= 0) {
                     return 0L;
@@ -421,8 +496,8 @@ public class AiKuaishouCreateCreativeServiceImpl implements IAiKuaishouCreateCre
                                 }
                             }
                             //创建组
-                            String unitName = getName(strategy.getGroupName(), strategy, createType, null, "unit", newCampaignId, appInfo.getAppId());
-                            JSONObject unitParams = createUnitParams(token, newCampaignId, strategy, unitName, appInfo.getAppId());
+                            String unitName = getName(strategy.getGroupName(), strategy, createType, null, "unit", newCampaignId, appInfo.getAppId(), null);
+                            JSONObject unitParams = createUnitParams(token, newCampaignId, strategy, unitName, appInfo.getAppId(), null);
                             log.info("创建广告组入参:{}", unitParams);
                             Map<String, Object> unitCreateResult = kuaishouInterfaceService.adUnitCreate(token.getAccessToken(), token.getAccountId(), unitParams, 1);
                             Integer unitCode = (Integer) unitCreateResult.get("code");
@@ -447,7 +522,7 @@ public class AiKuaishouCreateCreativeServiceImpl implements IAiKuaishouCreateCre
                             Long unitId = (Long) unitCreateResult.get("unitId");
                             unitLevelOperationRecord.setUnitId(unitId);
                             unitLevelOperationRecordService.saveOrUpdate(unitLevelOperationRecord);
-                            JSONObject creativeParams = programCreativeParams(token, unitId, splitVideos.get(j - 1), strategy, j, appInfo.getAppVersion());
+                            JSONObject creativeParams = programCreativeParams(token, unitId, splitVideos.get(j - 1), strategy, j, appInfo.getAppVersion(), null);
                             createProgramCreative(token, creativeParams, strategy);
                         }
                     }
@@ -493,8 +568,8 @@ public class AiKuaishouCreateCreativeServiceImpl implements IAiKuaishouCreateCre
                             }
                             Long newCampaignId = getCampaignId(strategy, token, replaceString, "TODAY", createType, appId, strategyUuid);
                             //创建组
-                            String unitName = getName(strategy.getGroupName(), strategy, createType, videoGet.getPhotoName(), "unit", newCampaignId, appId);
-                            JSONObject unitParams = createUnitParams(token, newCampaignId, strategy, unitName, appId);
+                            String unitName = getName(strategy.getGroupName(), strategy, createType, videoGet.getPhotoName(), "unit", newCampaignId, appId, null);
+                            JSONObject unitParams = createUnitParams(token, newCampaignId, strategy, unitName, appId, null);
                             unitParams.remove("cpa_bid");
                             unitParams.put("cpa_bid", multipleBids.getCpaBid());
                             if (!Check.isNull(multipleBids.getDeepConversionBid())) {
@@ -527,7 +602,7 @@ public class AiKuaishouCreateCreativeServiceImpl implements IAiKuaishouCreateCre
                             Long unitId = (Long) unitCreateResult.get("unitId");
                             unitLevelOperationRecord.setUnitId(unitId);
                             unitLevelOperationRecordService.saveOrUpdate(unitLevelOperationRecord);
-                            JSONObject creativeParams = programCreativeParams(token, unitId, splitVideos.get(j - 1), strategy, j, null);
+                            JSONObject creativeParams = programCreativeParams(token, unitId, splitVideos.get(j - 1), strategy, j, null, null);
                             createProgramCreative(token, creativeParams, strategy);
                         }
                     }
@@ -554,6 +629,29 @@ public class AiKuaishouCreateCreativeServiceImpl implements IAiKuaishouCreateCre
             if (null == newCampaignId) {
                 return;
             }
+            //渠道号应用层级,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 {
+                    Result<Object> result = channelService.queryChannel(accountId, level);
+                    Integer code = result.getCode();
+                    if (code == 200) {
+                        channel = (KuaishouChannel) result.getResult();
+                        if (Check.isNull(channel)) {
+                            log.info("账户:{},{}", accountId, result.getMessage());
+                        } else {
+                            log.info("获取渠道号:{}", channel.getChannelCode());
+                        }
+                    } else {
+                        log.error("通过账户(" + accountId + ")未获取到渠道号!!!");
+                    }
+                } catch (Exception e) {
+                    e.printStackTrace();
+                }
+            }
+
             //创意
             List<List<KuaiShouVideoGet>> splitVideos = Lists.partition(allVideos, 5);
             for (int j = 1; j < splitVideos.size() + 1; j++) {
@@ -571,9 +669,29 @@ public class AiKuaishouCreateCreativeServiceImpl implements IAiKuaishouCreateCre
                         return;
                     }
                 }
+                //获取组级渠道号
+                if (!Check.isNull(useChannel) && useChannel == 1 && "group".equals(level)) {
+                    try {
+                        Result<Object> result = channelService.queryChannel(accountId, level);
+                        Integer code = result.getCode();
+                        if (code == 200) {
+                            channel = (KuaishouChannel) result.getResult();
+                            if (Check.isNull(channel)) {
+                                log.info("账户(组级):{},{}", accountId, result.getMessage());
+                            } else {
+                                log.info("获取到组级渠道号:{}", channel.getChannelCode());
+                            }
+                        } else {
+                            log.error("通过账户(" + accountId + ")未获取到渠道号!!!");
+                        }
+                    } catch (Exception e) {
+                        e.printStackTrace();
+                    }
+                }
+
                 //创建组
-                String unitName = getName(strategy.getGroupName(), strategy, createType, null, "unit", newCampaignId, appId);
-                JSONObject unitParams = createUnitParams(token, newCampaignId, strategy, unitName, appId);
+                String unitName = getName(strategy.getGroupName(), strategy, createType, null, "unit", newCampaignId, appId, channel);
+                JSONObject unitParams = createUnitParams(token, newCampaignId, strategy, unitName, appId, channel);
                 log.info("创建广告组入参:{}", unitParams);
                 Map<String, Object> unitCreateResult = kuaishouInterfaceService.adUnitCreate(token.getAccessToken(), token.getAccountId(), unitParams, 1);
                 Integer unitCode = (Integer) unitCreateResult.get("code");
@@ -598,7 +716,8 @@ public class AiKuaishouCreateCreativeServiceImpl implements IAiKuaishouCreateCre
                 Long unitId = (Long) unitCreateResult.get("unitId");
                 unitLevelOperationRecord.setUnitId(unitId);
                 unitLevelOperationRecordService.saveOrUpdate(unitLevelOperationRecord);
-                JSONObject creativeParams = programCreativeParams(token, unitId, splitVideos.get(j - 1), strategy, j, null);
+                channelService.callBackUpdateChannelRel(level, channel.getChannelCode(), accountId, newCampaignId, unitId);
+                JSONObject creativeParams = programCreativeParams(token, unitId, splitVideos.get(j - 1), strategy, j, null, channel);
                 createProgramCreative(token, creativeParams, strategy);
             }
         }
@@ -707,7 +826,7 @@ public class AiKuaishouCreateCreativeServiceImpl implements IAiKuaishouCreateCre
         }
     }
 
-    private JSONObject programCreativeParams(CtopOauthToken token, Long unitId, List<KuaiShouVideoGet> list, AiKuaishouAdvertiserStrategy strategy, Integer creativeCnt, String appVersion) {
+    private JSONObject programCreativeParams(CtopOauthToken token, Long unitId, List<KuaiShouVideoGet> list, AiKuaishouAdvertiserStrategy strategy, Integer creativeCnt, String appVersion, KuaishouChannel channel) {
         JSONObject programJson = new JSONObject();
         programJson.put("advertiser_id", token.getAccountId());
         programJson.put("unit_id", unitId);
@@ -749,7 +868,7 @@ public class AiKuaishouCreateCreativeServiceImpl implements IAiKuaishouCreateCre
         programJson.put("cover_image_tokens", coverImageTokens);
 
         if (!Check.isNull(strategy.getSiteId())) {
-            if (!strategy.getSiteId().equals("-1") ) {
+            if (!strategy.getSiteId().equals("-1")) {
                 programJson.put("site_id", strategy.getSiteId());
             }
 
@@ -764,10 +883,15 @@ public class AiKuaishouCreateCreativeServiceImpl implements IAiKuaishouCreateCre
         if (!Check.isNull(strategy.getClickTrackUrl())) {
             programJson.put("click_url", strategy.getClickTrackUrl());
         }
+        if (!Check.isNull(channel) && !Check.isNull(channel.getActionbarClickUrl())) {
+            programJson.put("click_url", channel.getActionbarClickUrl());
+        }
         if (!Check.isNull(strategy.getActionbarClickUrl())) {
             programJson.put("actionbar_click_url", strategy.getActionbarClickUrl());
         }
-
+        if (!Check.isNull(channel) && !Check.isNull(channel.getActionbarClickUrl())) {
+            programJson.put("actionbar_click_url", channel.getActionbarClickUrl());
+        }
         JSONArray captions = getCaptions(strategy.getDescription());
         programJson.put("captions", captions);
         if (!Check.isNull(strategy.getCreativeCategory())) {
@@ -922,7 +1046,7 @@ public class AiKuaishouCreateCreativeServiceImpl implements IAiKuaishouCreateCre
         // 不存在“上新”计划,则创建一个计划
         JSONObject campaignParams = new JSONObject();
         campaignParams.put("advertiser_id", token.getAccountId());
-        String campaignName = getName(strategy.getCampaignName(), strategy, createType, null, "plan", null, appId);
+        String campaignName = getName(strategy.getCampaignName(), strategy, createType, null, "plan", null, appId, null);
         campaignParams.put("campaign_name", campaignName);
         campaignParams.put("type", strategy.getCampaignType());
         if (null != strategy.getCampaignDayBudget() && strategy.getCampaignDayBudget() != 0) {
@@ -953,7 +1077,7 @@ public class AiKuaishouCreateCreativeServiceImpl implements IAiKuaishouCreateCre
     }
 
     private JSONObject createUnitParams(CtopOauthToken token, Long campaignId, AiKuaishouAdvertiserStrategy strategy,
-                                        String unitName, Long appId) {
+                                        String unitName, Long appId, KuaishouChannel channel) {
         // 拼装创建组的入参 json
         JSONObject unitParams = new JSONObject();
         Integer unitType = strategy.getUnitType();
@@ -1019,10 +1143,16 @@ public class AiKuaishouCreateCreativeServiceImpl implements IAiKuaishouCreateCre
             if (!Check.isNull(appId)) {
                 unitParams.put("app_id", appId);
             }
+            if (!Check.isNull(channel) && !Check.isNull(channel.getAppId())) {
+                unitParams.put("app_id", channel.getAppId());
+            }
             // 直达链接
             if (!Check.isNull(strategy.getSchemaUri())) {
                 unitParams.put("schema_uri", strategy.getSchemaUri());
             }
+            if (!Check.isNull(channel) && !Check.isNull(channel.getSchemaUri())) {
+                unitParams.put("schema_uri", channel.getSchemaUri());
+            }
             // 优先从系统应用商店下载
             if (null != strategy.getUseAppMarket()) {
                 unitParams.put("use_app_market", strategy.getUseAppMarket());
@@ -1426,7 +1556,7 @@ public class AiKuaishouCreateCreativeServiceImpl implements IAiKuaishouCreateCre
         return imageGet.getImageToken();
     }
 
-    private JSONObject creativeParams(CtopOauthToken token, Long unitId, KuaiShouVideoGet videoItem, AiKuaishouAdvertiserStrategy strategy) {
+    private JSONObject creativeParams(CtopOauthToken token, Long unitId, KuaiShouVideoGet videoItem, AiKuaishouAdvertiserStrategy strategy, KuaishouChannel channel) {
         JSONObject creativeParams = new JSONObject();
         creativeParams.put("advertiser_id", token.getAccountId());
         creativeParams.put("unit_id", unitId);
@@ -1455,13 +1585,16 @@ public class AiKuaishouCreateCreativeServiceImpl implements IAiKuaishouCreateCre
         }
         // 安卓下载中间页ID
         if (!Check.isNull(strategy.getSiteId())) {
-            if (!strategy.getSiteId().equals("-1") ) {
+            if (!strategy.getSiteId().equals("-1")) {
                 creativeParams.put("site_id", strategy.getSiteId());
             }
         }
         if (null != strategy.getClickTrackUrl() && !"".equals(strategy.getClickTrackUrl())) {
             creativeParams.put("click_track_url", strategy.getClickTrackUrl());
         }
+        if (!Check.isNull(channel) && !Check.isNull(channel.getClickTrackUrl())) {
+            creativeParams.put("click_track_url", channel.getClickTrackUrl());
+        }
         if (null != strategy.getImpressionUrl() && !"".equals(strategy.getImpressionUrl())) {
             creativeParams.put("impression_url", strategy.getImpressionUrl());
         }
@@ -1472,6 +1605,9 @@ public class AiKuaishouCreateCreativeServiceImpl implements IAiKuaishouCreateCre
         if (null != strategy.getActionbarClickUrl() && !"".equals(strategy.getActionbarClickUrl())) {
             creativeParams.put("actionbar_click_url", strategy.getActionbarClickUrl());
         }
+        if (!Check.isNull(channel) && !Check.isNull(channel.getActionbarClickUrl())) {
+            creativeParams.put("actionbar_click_url", channel.getActionbarClickUrl());
+        }
         if (null != strategy.getCreativeCategory()) {
             creativeParams.put("creative_category", strategy.getCreativeCategory());
         }
@@ -1534,7 +1670,15 @@ public class AiKuaishouCreateCreativeServiceImpl implements IAiKuaishouCreateCre
     private IKuaiShouAppListService appListService;
 
 
-    private String getName(String wildcard, AiKuaishouAdvertiserStrategy strategy, Integer createType, String materialName, String type, Long campaignId, Long appId) {
+    private String getName(String wildcard, AiKuaishouAdvertiserStrategy strategy, Integer createType, String materialName, String type, Long campaignId, Long appId, KuaishouChannel channel) {
+        if (!Check.isNull(channel)) {
+            if (wildcard.contains("{{渠道号}}")) {
+                wildcard = wildcard.replace("{{渠道号}}", channel.getChannelCode());
+            }
+            if (wildcard.contains("{{渠道号名称}}")) {
+                wildcard = wildcard.replace("{{渠道号名称}}", channel.getChannelName());
+            }
+        }
         if (wildcard.contains("{{应用名称}}") || wildcard.contains("{{应用标记}}")) {
             KuaiShouAppList getAppInfo = appListService.getAppInfo(strategy.getAccountId(), appId);
             if (!Check.isNull(getAppInfo)) {

+ 3 - 0
jeecg-boot-module-system/src/main/java/cn/com/ctop/kuaishou/modules/channel/mapper/KuaishouChannelRelMapper.java

@@ -15,4 +15,7 @@ public interface KuaishouChannelRelMapper extends BaseMapper<KuaishouChannelRel>
 
     KuaishouChannelRel queryByAccountChannelCode(@Param("channelCode") String channelCode, @Param("accountId") Long accountId);
 
+    Integer queryUsePlanCount(@Param("accountId") Long accountId, @Param("channelCode") String channelCode);
+
+    Integer queryUseGroupCount(@Param("accountId") Long accountId, @Param("channelCode") String channelCode);
 }

+ 13 - 2
jeecg-boot-module-system/src/main/java/cn/com/ctop/kuaishou/modules/channel/mapper/xml/KuaishouChannelMapper.xml

@@ -184,7 +184,14 @@
         SELECT id,
                channel_code,
                usage_level,
-               usage_range
+               usage_range,
+               usage_times,
+               is_have_item,
+               cycle_times,
+               channel_name,
+               click_track_url,
+               actionbar_click_url,
+               schema_uri
         FROM `ctop_kuaishou_channel`
         WHERE account_id = #{accountId}
           and usage_level = #{usageLevel}
@@ -198,7 +205,11 @@
         usage_range,
         usage_times,
         is_have_item,
-        cycle_times
+        cycle_times,
+        channel_name,
+        click_track_url,
+        actionbar_click_url,
+        schema_uri
         FROM `ctop_kuaishou_channel`
         WHERE strategy_id IN
         <foreach collection="strategys" item="item" separator=","

+ 24 - 0
jeecg-boot-module-system/src/main/java/cn/com/ctop/kuaishou/modules/channel/mapper/xml/KuaishouChannelRelMapper.xml

@@ -9,4 +9,28 @@
         WHERE account_id = #{accountId}
           AND channel_code = #{channelCode} limit 1
     </select>
+
+    <select id="queryUsePlanCount" resultType="java.lang.Integer">
+        SELECT IFNULL(SUM(1), 0)
+        FROM (
+                 SELECT 1
+                 FROM ctop_kuaishou_channel_rel
+                 WHERE account_id = #{accountId}
+                   AND channel_code = #{channelCode}
+                   AND app_id is not null
+                   AND campaign_id is not null
+                 GROUP BY campaign_id
+             ) t
+    </select>
+
+    <select id="queryUseGroupCount" resultType="java.lang.Integer">
+        SELECT IFNULL(SUM(1), 0)
+        FROM (SELECT 1
+              FROM ctop_kuaishou_channel_rel
+              WHERE account_id = #{accountId}
+                AND channel_code = #{channelCode}
+                AND app_id IS NOT NULL
+                AND unit_id IS NOT NULL
+              GROUP BY unit_id) t
+    </select>
 </mapper>

+ 4 - 0
jeecg-boot-module-system/src/main/java/cn/com/ctop/kuaishou/modules/channel/service/IKuaishouChannelRelService.java

@@ -13,4 +13,8 @@ import com.baomidou.mybatisplus.extension.service.IService;
 public interface IKuaishouChannelRelService extends IService<KuaishouChannelRel> {
 
     KuaishouChannelRel queryByAccountChannelCode(String channelCode, Long accountId);
+
+    Integer queryUsePlanCount(Long accountId, String channelCode);
+
+    Integer queryUseGroupCount(Long accountId, String channelCode);
 }

+ 5 - 2
jeecg-boot-module-system/src/main/java/cn/com/ctop/kuaishou/modules/channel/service/IKuaishouChannelService.java

@@ -9,13 +9,14 @@ import org.springframework.web.multipart.MultipartFile;
 
 /**
  * 渠道号信息表
+ *
  * @author jeecg-boot
  * 2021-08-30
  * @version V1.0
  */
 public interface IKuaishouChannelService extends IService<KuaishouChannel> {
 
-    Result<Object> channelManagementHome(Long productId, Long projectId, Long accountId,String userId);
+    Result<Object> channelManagementHome(Long productId, Long projectId, Long accountId, String userId);
 
     Result<Object> channelNumberDetails(KuaishouChannel kuaishouCha, Integer pageNo, Integer pageSizennel);
 
@@ -27,9 +28,11 @@ public interface IKuaishouChannelService extends IService<KuaishouChannel> {
 
     Result<Object> systemBatchCreation(JSONObject request);
 
-    Result<Object> customizedCreate(JSONObject request,Integer createType) throws Exception;
+    Result<Object> customizedCreate(JSONObject request, Integer createType) throws Exception;
 
     Result<Object> queryChannel(Long accountId, String usageLevel) throws Exception;
 
     Result<Object> queryChannelLevel(Long accountId);
+
+    void callBackUpdateChannelRel(String level, String channelCode, Long accoountId, Long planId, Long groupId);
 }

+ 10 - 0
jeecg-boot-module-system/src/main/java/cn/com/ctop/kuaishou/modules/channel/service/impl/KuaishouChannelRelServiceImpl.java

@@ -23,4 +23,14 @@ public class KuaishouChannelRelServiceImpl extends ServiceImpl<KuaishouChannelRe
     public KuaishouChannelRel queryByAccountChannelCode(String channelCode, Long accountId) {
         return channelRelMapper.queryByAccountChannelCode(channelCode, accountId);
     }
+
+    @Override
+    public Integer queryUsePlanCount(Long accountId, String channelCode) {
+        return channelRelMapper.queryUsePlanCount(accountId,  channelCode);
+    }
+
+    @Override
+    public Integer queryUseGroupCount(Long accountId, String channelCode) {
+        return channelRelMapper.queryUseGroupCount(accountId,  channelCode);
+    }
 }

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

@@ -386,12 +386,12 @@ public class KuaishouChannelServiceImpl extends ServiceImpl<KuaishouChannelMappe
             String newFileUrl = kuaishouAppPackageService.getDownloadPath(appIconUrl);
             if (Check.isNull(newFileUrl)) {
                 log.error("下载图片失败,原路径:" + appIconUrl);
-                obj.put("message","下载图片失败,原路径:" + appIconUrl);
+                obj.put("message", "下载图片失败,原路径:" + appIconUrl);
                 return obj;
             }
             if (Check.isNull(token)) {
                 log.error("根据图片路径获取md5,获取token失败");
-                obj.put("message","根据图片路径获取md5,获取token失败");
+                obj.put("message", "根据图片路径获取md5,获取token失败");
                 return obj;
             }
             String md5 = null;
@@ -402,7 +402,7 @@ public class KuaishouChannelServiceImpl extends ServiceImpl<KuaishouChannelMappe
             }
             if (Check.isNull(md5)) {
                 log.error("获取MD5签名失败,路径:" + newFileUrl);
-                obj.put("message","获取MD5签名失败,路径:" + newFileUrl);
+                obj.put("message", "获取MD5签名失败,路径:" + newFileUrl);
                 return obj;
             }
             //获取图片MD5
@@ -930,6 +930,42 @@ public class KuaishouChannelServiceImpl extends ServiceImpl<KuaishouChannelMappe
         return Result.ok(request);
     }
 
+    @Override
+    public void callBackUpdateChannelRel(String level, String channelCode, Long accountId, Long planId, Long groupId) {
+        try {
+            QueryWrapper<KuaishouChannel> queryWrapper = new QueryWrapper<>();
+            queryWrapper.eq("account_id", accountId);
+            queryWrapper.eq("channel_code", channelCode).last("limit 1");
+            KuaishouChannel one = this.getOne(queryWrapper);
+            if (!Check.isNull(one)) {
+                QueryWrapper<KuaishouChannelRel> relqueryWrapper = new QueryWrapper<>();
+                relqueryWrapper.eq("account_id", accountId);
+                relqueryWrapper.eq("channel_code", channelCode).orderByAsc("create_time").last("limit 1");
+                KuaishouChannelRel rel = channelRelService.getOne(relqueryWrapper);
+                if (!Check.isNull(rel)) {
+                    if (!Check.isNull(rel.getCampaignId())) {
+                        rel.setId(null);
+                    }
+                    rel.setCampaignId(planId);
+                    rel.setUnitId(groupId);
+                    channelRelService.save(rel);
+                    if ("plan".equals(level)) {
+                        Integer usageTimes = channelRelService.queryUsePlanCount(accountId, channelCode);
+                        one.setUsageTimes(usageTimes);
+                        this.saveOrUpdate(one);
+                    } else if ("group".equals(level)) {
+                        Integer usageTimes = channelRelService.queryUseGroupCount(accountId, channelCode);
+                        one.setUsageTimes(usageTimes);
+                        this.saveOrUpdate(one);
+                    }
+                }
+            }
+        } catch (Exception e) {
+            e.printStackTrace();
+            log.error("渠道号回调异常", e);
+        }
+    }
+
     private Result<Object> doAccountRangeAccountLevel(Long accountId, List<KuaishouChannelCreateStrategy> strategys) throws Exception {
         List<KuaishouChannel> channelList = channelMapper.queryByAccountIdLevel(accountId, "account");
         if (!Check.isNull(channelList)) {
@@ -945,10 +981,11 @@ public class KuaishouChannelServiceImpl extends ServiceImpl<KuaishouChannelMappe
                     } else {
                         channelRel.setAppId(channel.getAppId());
                         channelRelService.saveOrUpdate(channelRel);
-                        return Result.ok(channelRel);
+                        return Result.ok(channel);
                     }
                 } else {
-                    return Result.ok(channelRel);
+                    channel.setAppId(channelRel.getAppId());
+                    return Result.ok(channel);
                 }
             }
         }
@@ -956,7 +993,8 @@ public class KuaishouChannelServiceImpl extends ServiceImpl<KuaishouChannelMappe
     }
 
     //通过账户范围计划层级查询
-    private Result<Object> doAccountRangePlanLevel(Long accountId, List<KuaishouChannelCreateStrategy> strategys) throws Exception {
+    private Result<Object> doAccountRangePlanLevel(Long accountId, List<KuaishouChannelCreateStrategy> strategys) throws
+            Exception {
         List<Integer> haveCycleTimesList = channelMapper.queryUsedLevel(strategys);
         if (Check.isNull(haveCycleTimesList)) {
             return Result.error("渠道号已无效");
@@ -982,10 +1020,11 @@ public class KuaishouChannelServiceImpl extends ServiceImpl<KuaishouChannelMappe
                         } else {
                             channelRel.setAppId(channel.getAppId());
                             channelRelService.saveOrUpdate(channelRel);
-                            return Result.ok(channelRel);
+                            return Result.ok(channel);
                         }
                     } else {
-                        return Result.ok(channelRel);
+                        channel.setAppId(channelRel.getAppId());
+                        return Result.ok(channel);
                     }
                 } else {
                     //判断可循环次数 大于 已经循环的次数
@@ -1002,7 +1041,8 @@ public class KuaishouChannelServiceImpl extends ServiceImpl<KuaishouChannelMappe
     }
 
     //通过账户范围广告组层级查询
-    private Result<Object> doAccountRangeGroupLevel(Long accountId, List<KuaishouChannelCreateStrategy> strategys) throws Exception {
+    private Result<Object> doAccountRangeGroupLevel(Long
+                                                            accountId, List<KuaishouChannelCreateStrategy> strategys) throws Exception {
         List<Integer> haveCycleTimesList = channelMapper.queryUsedLevel(strategys);
         if (Check.isNull(haveCycleTimesList)) {
             return Result.error("渠道号已无效");
@@ -1028,10 +1068,11 @@ public class KuaishouChannelServiceImpl extends ServiceImpl<KuaishouChannelMappe
                         } else {
                             channelRel.setAppId(channel.getAppId());
                             channelRelService.saveOrUpdate(channelRel);
-                            return Result.ok(channelRel);
+                            return Result.ok(channel);
                         }
                     } else {
-                        return Result.ok(channelRel);
+                        channel.setAppId(channelRel.getAppId());
+                        return Result.ok(channel);
                     }
                 } else {
                     //判断可循环次数 大于 已经循环的次数
@@ -1048,7 +1089,8 @@ public class KuaishouChannelServiceImpl extends ServiceImpl<KuaishouChannelMappe
     }
 
     //通过项目范围账户层级查询
-    private Result<Object> doProjectRangePlanLevel(Long accountId, List<KuaishouChannelCreateStrategy> strategys) throws Exception {
+    private Result<Object> doProjectRangePlanLevel(Long accountId, List<KuaishouChannelCreateStrategy> strategys) throws
+            Exception {
         List<Integer> haveCycleTimesList = channelMapper.queryUsedLevel(strategys);
         if (Check.isNull(haveCycleTimesList)) {
             return Result.error("渠道号已无效");
@@ -1074,10 +1116,11 @@ public class KuaishouChannelServiceImpl extends ServiceImpl<KuaishouChannelMappe
                         } else {
                             channelRel.setAppId(channel.getAppId());
                             channelRelService.saveOrUpdate(channelRel);
-                            return Result.ok(channelRel);
+                            return Result.ok(channel);
                         }
                     } else {
-                        return Result.ok(channelRel);
+                        channel.setAppId(channelRel.getAppId());
+                        return Result.ok(channel);
                     }
                 } else {
                     //判断可循环次数 大于 已经循环的次数
@@ -1094,7 +1137,8 @@ public class KuaishouChannelServiceImpl extends ServiceImpl<KuaishouChannelMappe
     }
 
     //通过项目范围广告组层级查询
-    private Result<Object> doProjectRangeGroupLevel(Long accountId, List<KuaishouChannelCreateStrategy> strategys) throws Exception {
+    private Result<Object> doProjectRangeGroupLevel(Long
+                                                            accountId, List<KuaishouChannelCreateStrategy> strategys) throws Exception {
         List<Integer> haveCycleTimesList = channelMapper.queryUsedLevel(strategys);
         if (Check.isNull(haveCycleTimesList)) {
             return Result.error("渠道号已无效");
@@ -1120,10 +1164,11 @@ public class KuaishouChannelServiceImpl extends ServiceImpl<KuaishouChannelMappe
                         } else {
                             channelRel.setAppId(channel.getAppId());
                             channelRelService.saveOrUpdate(channelRel);
-                            return Result.ok(channelRel);
+                            return Result.ok(channel);
                         }
                     } else {
-                        return Result.ok(channelRel);
+                        channel.setAppId(channelRel.getAppId());
+                        return Result.ok(channel);
                     }
                 } else {
                     //判断可循环次数 大于 已经循环的次数