Kaynağa Gözat

Merge branch 'test'

zhaoxian 3 yıl önce
ebeveyn
işleme
2f55b32a4f

+ 61 - 29
jeecg-boot-module-system/src/main/java/cn/com/ctop/kuaishou/modules/ai/service/impl/AiKuaishouAccountAutoDoServiceImpl.java

@@ -187,6 +187,7 @@ public class AiKuaishouAccountAutoDoServiceImpl implements IAiKuaishouAccountAut
             unitNum = unitNum - customUnitCnt;
         }
         if (unitNum <= 0) {
+            log.info("今日创建已达标");
             return;
         }
         log.info("----- (自定义)账户:{},已建组数:{};剩余待建组数:{}", strategy.getAccountId(), customUnitCnt, unitNum);
@@ -270,8 +271,9 @@ public class AiKuaishouAccountAutoDoServiceImpl implements IAiKuaishouAccountAut
             KuaishouChannel usedchannel = null;
             try {
                 KuaishouChannel channel = null;
-                Integer useChannel = Check.isNull(strategy.getUseChannel()) ? 0 : strategy.getUseChannel();//0不使用,1使用
-                if (useChannel == 1) {
+                //0不使用,1使用
+                Integer useChannel = Check.isNull(strategy.getUseChannel()) ? 0 : strategy.getUseChannel();
+                if (useChannel == 1 && !"group".equals(level)) {
                     /*获取渠道号*/
                     channel = getChannel(level, accountId, appName);
                     if (Check.isNull(channel)) {
@@ -283,6 +285,8 @@ public class AiKuaishouAccountAutoDoServiceImpl implements IAiKuaishouAccountAut
                 if (null == newCampaignId) {
                     return videoCnt;
                 }
+                //赋值本次执行可创建数
+                videoCnt = strategy.getToBeBuiltCnt();
                 log.info("---------获取计划成功,计划id:{}", newCampaignId);
                 // 1 :使用渠道号
                 if (useChannel == 1) {
@@ -298,6 +302,7 @@ public class AiKuaishouAccountAutoDoServiceImpl implements IAiKuaishouAccountAut
                                 log.error("****** 获取已创建的计划所使用的渠道号失败");
                                 return videoCnt;
                             }
+                            log.info("------因计划层级,更新为已创建的计划所使用的渠道号:{}", usedchannel.getChannelCode());
                         } else {
                             usedchannel = channel;
                         }
@@ -414,14 +419,14 @@ public class AiKuaishouAccountAutoDoServiceImpl implements IAiKuaishouAccountAut
     }
 
     /**
-     * 更新广告组数
+     * 更新广告组编号
      */
     private void updateVideoStatus(String key) {
         Integer unitCnt = (Integer) redisUtil.get(key);
         if (Check.isNull(unitCnt)) {
             redisUtil.set(key, 1, 100000L);
         } else {
-            redisUtil.set(key, unitCnt + 1, 100000L);
+            redisUtil.set(key, unitCnt - 1, 100000L);
         }
     }
 
@@ -476,6 +481,8 @@ public class AiKuaishouAccountAutoDoServiceImpl implements IAiKuaishouAccountAut
                 if (campaignId == null) {
                     continue;
                 }
+                //赋值本次执行可创建数
+                videoCnt = strategy.getToBeBuiltCnt();
                 /*根据匹配逻辑,定向包和素材进行匹配,获取匹配后的素材*/
                 getTargetsAndVideos(strategy, allVideos, videoKey, appId, campaignId, appInfo.getAppVersion(), 0);
             }
@@ -575,6 +582,7 @@ public class AiKuaishouAccountAutoDoServiceImpl implements IAiKuaishouAccountAut
             unitNum = unitNum - programUnitCnt;
         }
         if (unitNum == 0) {
+            log.info("今日创建已达标");
             return;
         }
         log.info("----- (程序化)账户:{},已建组数:{};剩余待建组数:{}", strategy.getAccountId(), programUnitCnt, unitNum);
@@ -671,6 +679,8 @@ public class AiKuaishouAccountAutoDoServiceImpl implements IAiKuaishouAccountAut
                 if (null == newCampaignId) {
                     return videoCnt;
                 }
+                //赋值本次执行可创建数
+                videoCnt = strategy.getToBeBuiltCnt();
                 log.info("---------获取计划成功,计划id:{}", newCampaignId);
 
                 if (!Check.isNull(channel)) {
@@ -893,6 +903,8 @@ public class AiKuaishouAccountAutoDoServiceImpl implements IAiKuaishouAccountAut
                 if (campaignId == null) {
                     continue;
                 }
+                //赋值本次执行可创建数
+                videoCnt = strategy.getToBeBuiltCnt();
                 /*根据匹配逻辑,定向包和素材进行匹配,获取匹配后的素材*/
                 getProTargetsAndVideos(strategy, proVideos, programKey, 0, appId, campaignId, appInfo.getAppVersion());
             }
@@ -975,6 +987,7 @@ public class AiKuaishouAccountAutoDoServiceImpl implements IAiKuaishouAccountAut
         Long accountId = strategy.getAccountId();
         KuaishouChannel channel = null;
         /*获取组级渠道号*/
+         /*
         channel = getChannel("group", accountId, appName);
         if (Check.isNull(channel)) {
             log.error("****** 获取组级渠道号失败");
@@ -985,6 +998,7 @@ public class AiKuaishouAccountAutoDoServiceImpl implements IAiKuaishouAccountAut
         if (!Check.isNull(items) && !items.isEmpty()) {
             strategy.setMaterialKeyword(items.get(0).getKeyword());
         }
+        */
 
         //待建素材集 redis key值
         String date = DateUtils.formatDate(new Date());
@@ -1004,7 +1018,14 @@ public class AiKuaishouAccountAutoDoServiceImpl implements IAiKuaishouAccountAut
 
         //记录创建成功的素材,待最后执行删除redis
         List<AiKuaishouAccountAutoVideo> successVideoList = new ArrayList<>();
+        Integer unitCode = null;
+        String unitMessage = null;
         for (AiKuaishouAccountAutoVideo videoItem : targetsAndVideos) {
+            channel = getChannel("group", accountId, appName);
+            if (Check.isNull(channel)) {
+                log.error("****** 获取组级渠道号失败");
+                return videoCnt;
+            }
             boolean unitOverrun = getUnitOverrun(accountId);
             if (unitOverrun) {
                 log.error("****** 账户({})创建广告组超限", accountId);
@@ -1018,8 +1039,7 @@ public class AiKuaishouAccountAutoDoServiceImpl implements IAiKuaishouAccountAut
                 return 0;
             }
 
-            Integer unitCode = null;
-            String unitMessage = null;
+
             String unitName = getName(strategy.getGroupName(), strategy, videoType, videoItem.getPhotoName(), "unit", newCampaignId, videoItem.getAutoTargetId(), appId, channel);
             Result<Object> result = createUnitParams(token, newCampaignId, strategy, unitName, appId, channel, videoItem.getAutoTargetId());
             if (result.getCode() != CommonConstant.SC_OK_200) {
@@ -1066,7 +1086,7 @@ public class AiKuaishouAccountAutoDoServiceImpl implements IAiKuaishouAccountAut
             }
         }
         removeRedisVideos(successVideoList, videoKey);
-        if (videoCnt > 0) {
+        if (videoCnt > 0 && unitCode == 0) {
             return addCustomByGroupChannel(strategy, appName, videoType, token, newCampaignId, appId, videoCnt, strategyUuid);
         }
         return videoCnt;
@@ -1079,7 +1099,7 @@ public class AiKuaishouAccountAutoDoServiceImpl implements IAiKuaishouAccountAut
     private Integer addProgramByGroupChannel(AiKuaishouAccountAutoStrategy strategy, String appName, Integer videoType, CtopOauthToken token, Long newCampaignId, Long appId, Integer videoCnt, String uuid) throws Exception {
         Long accountId = strategy.getAccountId();
         /*获取组级渠道号*/
-        KuaishouChannel channel = getChannel("group", accountId, appName);
+        /*KuaishouChannel channel = getChannel("group", accountId, appName);
         if (Check.isNull(channel)) {
             log.error("****** 获取组级渠道号失败");
             return videoCnt;
@@ -1089,6 +1109,7 @@ public class AiKuaishouAccountAutoDoServiceImpl implements IAiKuaishouAccountAut
         if (!Check.isNull(items) && !items.isEmpty()) {
             strategy.setMaterialKeyword(items.get(0).getKeyword());
         }
+        */
         String date = DateUtils.formatDate(new Date());
 
         //程序化创建创意超限标识,redis key值
@@ -1103,21 +1124,25 @@ public class AiKuaishouAccountAutoDoServiceImpl implements IAiKuaishouAccountAut
             log.error("****** {}账户({})通过组级渠道号关键词{},未获取到素材(程序化)", date, accountId, strategy.getMaterialKeyword());
         } else {
             if (allVideos.size() >= 3) {
-                List<List<AiKuaishouAccountAutoVideo>> splitVideos = Lists.partition(allVideos, 10);
-                int size = splitVideos.size() - 1;
+                List<List<AiKuaishouAccountAutoVideo>> splitVideos = Lists.newArrayList(Lists.partition(allVideos, 10));
+                List<List<AiKuaishouAccountAutoVideo>> newVideos = new ArrayList<>();
+                for (List<AiKuaishouAccountAutoVideo> splitVideo : splitVideos) {
+                    newVideos.add(Lists.newArrayList(splitVideo));
+                }
+                int size = newVideos.size() - 1;
                 if (size > 0) {
                     //判断最后一个集合小于3
-                    List<AiKuaishouAccountAutoVideo> lastVideos = splitVideos.get(size);
+                    List<AiKuaishouAccountAutoVideo> lastVideos = newVideos.get(size);
                     if (lastVideos.size() < 3) {
                         //小于3 则去除
                         for (int i = 0; i < size; i++) {
-                            proVideos.add(splitVideos.get(i));
+                            proVideos.add(newVideos.get(i));
                         }
                     } else {
-                        proVideos = splitVideos;
+                        proVideos = newVideos;
                     }
                 } else {
-                    proVideos = splitVideos;
+                    proVideos = newVideos;
                 }
             }
         }
@@ -1130,6 +1155,8 @@ public class AiKuaishouAccountAutoDoServiceImpl implements IAiKuaishouAccountAut
 
         //记录创建成功的素材,待最后执行删除redis
         List<List<AiKuaishouAccountAutoVideo>> successVideoList = new ArrayList<>();
+        Integer unitCode = null;
+        String unitMessage = null;
         for (List<AiKuaishouAccountAutoVideo> videos : targetsAndVideos) {
             boolean unitOverrun = getUnitOverrun(accountId);
             if (unitOverrun) {
@@ -1137,6 +1164,12 @@ public class AiKuaishouAccountAutoDoServiceImpl implements IAiKuaishouAccountAut
                 removeProRedisVideos(successVideoList, videoKey);
                 return 0;
             }
+            /*获取组级渠道号*/
+            KuaishouChannel channel = getChannel("group", accountId, appName);
+            if (Check.isNull(channel)) {
+                log.error("****** 获取组级渠道号失败");
+                return videoCnt;
+            }
 
             Object redisObj = redisUtil.get(programKey);
             if (!Check.isNull(redisObj)) {
@@ -1148,8 +1181,7 @@ public class AiKuaishouAccountAutoDoServiceImpl implements IAiKuaishouAccountAut
                 }
             }
 
-            Integer unitCode = null;
-            String unitMessage = null;
+
             String unitName = getName(strategy.getGroupName(), strategy, videoType, null, "unit", newCampaignId, appId, videos.get(0).getAutoTargetId(), channel);
             Result<Object> result = createUnitParams(token, newCampaignId, strategy, unitName, appId, channel, videos.get(0).getAutoTargetId());
             if (result.getCode() != CommonConstant.SC_OK_200) {
@@ -1197,7 +1229,7 @@ public class AiKuaishouAccountAutoDoServiceImpl implements IAiKuaishouAccountAut
         }
         //删除已使用的素材
         removeProRedisVideos(successVideoList, videoKey);
-        if (videoCnt > 0) {
+        if (videoCnt > 0 && unitCode == 0) {
             return addProgramByGroupChannel(strategy, appName, videoType, token, newCampaignId, appId, videoCnt, uuid);
         }
         return videoCnt;
@@ -1511,18 +1543,16 @@ public class AiKuaishouAccountAutoDoServiceImpl implements IAiKuaishouAccountAut
         KuaishouChannel channel = null;
         try {
             channel = null;
-            if (("account".equals(level) || "plan".equals(level))) {
-                Result<Object> result = channelService.queryChannel(accountId, level, appName, null);
-                if (result.getCode() == 200) {
-                    channel = (KuaishouChannel) result.getResult();
-                    if (Check.isNull(channel)) {
-                        log.error("****** 账户({})未获取到渠道号,{}", accountId, result.getMessage());
-                    } else {
-                        log.info("------获取渠道号:{}", channel.getChannelCode());
-                    }
+            Result<Object> result = channelService.queryChannel(accountId, level, appName, null);
+            if (result.getCode() == 200) {
+                channel = (KuaishouChannel) result.getResult();
+                if (Check.isNull(channel)) {
+                    log.error("****** 账户({})未获取到渠道号,{}", accountId, result.getMessage());
                 } else {
-                    log.error("******  账户({})根据应用名:{},未查询渠道号!{}", accountId, appName, result.getMessage());
+                    log.info("------获取渠道号:{}", channel.getChannelCode());
                 }
+            } else {
+                log.error("******  账户({})根据应用名:{},未查询渠道号!{}", accountId, appName, result.getMessage());
             }
         } catch (Exception e) {
             e.printStackTrace();
@@ -1592,8 +1622,8 @@ public class AiKuaishouAccountAutoDoServiceImpl implements IAiKuaishouAccountAut
             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(channel) && !Check.isNull(channel.getClickTrackUrl())) {
+                programJson.put("click_url", channel.getClickTrackUrl());
             }
 
             //第三方 ActionBar 点击监控链接
@@ -1776,6 +1806,8 @@ public class AiKuaishouAccountAutoDoServiceImpl implements IAiKuaishouAccountAut
             //判断是否扔可创建计划
             if (planCnt > datas.size()) {
                 return createCampaign(strategy, token, videoType, uuid, channel);
+            }else{
+                log.info("当日创建量已达标");
             }
         } else {
             return createCampaign(strategy, token, videoType, uuid, channel);

+ 1 - 0
jeecg-boot-module-system/src/main/java/cn/com/ctop/kuaishou/modules/batch/service/impl/KuaishouInterfaceServiceImpl.java

@@ -3379,6 +3379,7 @@ public class KuaishouInterfaceServiceImpl implements IKuaishouInterfaceService {
                             appList.setImageToken(dataJson.getString("image_token"));
                             appList.setPackageName(dataJson.getString("package_name"));
                             appList.setReturnTime(DateUtils.timeStamp2Date(dataJson.getTimestamp("update_time")));
+                            appList.setAppPrivacyUrl(dataJson.getString("app_privacy_url"));
                             addList.add(appList);
                         }
                     }

+ 8 - 1
jeecg-boot-module-system/src/main/java/cn/com/ctop/kuaishou/modules/channel/mapper/KuaishouChannelMapper.java

@@ -1,7 +1,6 @@
 package cn.com.ctop.kuaishou.modules.channel.mapper;
 
 import cn.com.ctop.kuaishou.modules.channel.entity.KuaishouChannel;
-import cn.com.ctop.kuaishou.modules.channel.entity.KuaishouChannelCreateStrategy;
 import com.alibaba.fastjson.JSONArray;
 import com.alibaba.fastjson.JSONObject;
 import com.baomidou.mybatisplus.core.mapper.BaseMapper;
@@ -51,4 +50,12 @@ public interface KuaishouChannelMapper extends BaseMapper<KuaishouChannel> {
     List<JSONObject> queryChannelList(@Param("accountId") Long accountId, @Param("appName") String appName);
 
     List<KuaishouChannel> queryChannelListByAccount(@Param("accountId") Long accountId);
+
+    List<KuaishouChannel> getAccountLevelRepeatChannel(@Param("accountId") Long accountId, @Param("appName") String appName);
+
+    List<KuaishouChannel> getAccountLevelNoRepeatChannel(@Param("accountId") Long accountId, @Param("appName") String appName);
+
+    KuaishouChannel getChannelEntity(@Param("accountId") Long accountId);
+
+    List<KuaishouChannel> queryNoAccountLevelNoRepeatChannel(@Param("usageLevel") String usageLevel, @Param("accountId") Long accountId, @Param("appName") String appName);
 }

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

@@ -131,6 +131,7 @@
         FROM `ctop_kuaishou_channel`
         WHERE account_id = #{accountId}
           AND state = 1
+          AND channel_state = 1
           AND id > #{usedId}
           AND usage_range = #{usageRange}
         ORDER BY channel_code, channel_number limit 10
@@ -146,6 +147,7 @@
         FROM `ctop_kuaishou_channel`
         WHERE account_id = #{accountId}
         AND state = 1
+        AND channel_state = 1
         <if test="isHaveItem != null">
             and is_have_item = #{isHaveItem}
         </if>
@@ -205,14 +207,109 @@
         <if test="usageTimes > 1">
             AND is_cycle = 1
           </if>
+        <if test="appName != null">
             AND app_id in (
                 SELECT DISTINCT app_id FROM ctop_kuaishou_channel_app_info where app_name = #{appName}  and app_id is not null
             )
+        </if>
             AND t1.usage_times = #{usageTimes}
             and t1.usage_level = #{usageLevel}
             ORDER BY t1.create_time,t1.channel_number
     </select>
 
+    <select id="getAccountLevelRepeatChannel" resultType="cn.com.ctop.kuaishou.modules.channel.entity.KuaishouChannel">
+        SELECT t1.id,
+               t1.channel_code,
+               t1.usage_level,
+               t1.usage_range,
+               t1.usage_times,
+               t1.is_have_item,
+               t1.channel_name,
+               t1.click_track_url,
+               t1.actionbar_click_url,
+               t1.schema_uri
+        FROM `ctop_kuaishou_channel` t1
+        LEFT JOIN ctop_kuaishou_channel_rel t2 ON t1.account_id = t2.account_id AND t1.channel_code = t2.channel_code
+        WHERE
+            t1.account_id = #{accountId}
+          AND t1.state = 1
+          AND t1.channel_state = 1
+          AND t1.app_id is not null
+          and t1.usage_level = 'account'
+        <if test="appName != null">
+            AND t1.app_id in (
+            SELECT DISTINCT app_id FROM ctop_kuaishou_channel_app_info where app_name = #{appName}  and app_id is not null
+            )
+        </if>
+        GROUP BY t1.channel_code
+        ORDER BY t1.create_time,t1.channel_number
+            LIMIT 100
+    </select>
+
+    <select id="getAccountLevelNoRepeatChannel" resultType="cn.com.ctop.kuaishou.modules.channel.entity.KuaishouChannel">
+        SELECT t1.id,
+               t1.channel_code,
+               t1.usage_level,
+               t1.usage_range,
+               t1.usage_times,
+               t1.is_have_item,
+               t1.channel_name,
+               t1.click_track_url,
+               t1.actionbar_click_url,
+               t1.schema_uri
+        FROM `ctop_kuaishou_channel` t1
+        WHERE
+            t1.account_id = #{accountId}
+          AND t1.state = 1
+          AND t1.channel_state = 1
+          AND app_id is not null
+          AND t1.channel_code not in (
+            SELECT channel_code FROM ctop_kuaishou_channel_rel WHERE account_id = #{accountId}  AND unit_id is not null
+        )
+        <if test="appName != null">
+            AND t1.app_id in (
+            SELECT DISTINCT app_id FROM ctop_kuaishou_channel_app_info WHERE app_name = #{appName}  AND app_id is not null
+            )
+        </if>
+        ORDER BY t1.create_time,t1.channel_number
+            LIMIT 100
+    </select>
+
+    <select id="queryNoAccountLevelNoRepeatChannel" resultType="cn.com.ctop.kuaishou.modules.channel.entity.KuaishouChannel">
+        SELECT t1.id,
+               t1.channel_code,
+               t1.usage_level,
+               t1.usage_range,
+               t1.usage_times,
+               t1.is_have_item,
+               t1.channel_name,
+               t1.click_track_url,
+               t1.actionbar_click_url,
+               t1.schema_uri
+        FROM `ctop_kuaishou_channel` t1
+        WHERE  t1.account_id = #{accountId}
+          AND t1.state = 1
+          AND t1.channel_state = 1
+          AND app_id is not null
+        <if test="appName != null">
+            AND t1.app_id in (
+            SELECT DISTINCT app_id FROM ctop_kuaishou_channel_app_info where app_name = #{appName}  and app_id is not null
+            )
+        </if>
+          AND t1.usage_times = 0
+          and t1.usage_level = #{usageLevel}
+        ORDER BY t1.create_time,t1.channel_number
+            LIMIT 100
+    </select>
+
+    <select id="getChannelEntity" resultType="cn.com.ctop.kuaishou.modules.channel.entity.KuaishouChannel">
+        SELECT *
+        FROM `ctop_kuaishou_channel`
+        WHERE account_id = #{accountId}
+          AND state = 1
+          AND channel_state = 1 LIMIT 1
+    </select>
+
     <select id="queryUsedLevel" resultType="java.lang.Integer">
         SELECT usage_times
         FROM `ctop_kuaishou_channel`
@@ -222,6 +319,7 @@
             #{item}
         </foreach>
         AND state = 1
+        AND channel_state = 1
         group by usage_times
     </select>
 
@@ -245,17 +343,18 @@
   <select id="queryChannelList" resultType="com.alibaba.fastjson.JSONObject">
       SELECT
           t1.id,
-          channel_code,
-          channel_name,
+          channel_code as 'channelCode',
+          channel_name as 'channelName',
           t1.url,
-          schema_uri,
-          click_track_url,
-          actionbar_click_url
+          schema_uri as 'schemaUri',
+          click_track_url as 'clickTrackUrl',
+          actionbar_click_url as 'actionbarClickUrl'
       FROM
           ctop_kuaishou_channel t1
               LEFT JOIN ctop_kuaishou_channel_app_info t2 ON t1.app_id = t2.app_id
       WHERE
           t1.state = 1
+        AND t1.channel_state = 1
         AND t1.account_id = #{accountId}
         AND t2.app_name = #{appName}
 
@@ -284,6 +383,7 @@
         WHERE t2.account_id = #{accountId}
           AND t2.usage_level = #{level}
           AND t2.state = 1
+          AND t2.channel_state = 1
           AND t1.campaign_id = #{campaignId} LIMIT 1
     </select>
 

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

@@ -168,16 +168,9 @@ public class KuaishouChannelServiceImpl extends ServiceImpl<KuaishouChannelMappe
      * 校验渠道号是否重复
      */
     private boolean checkChannelCode(KuaishouChannelCreateStrategy strategy) {
-        String numberValue = strategy.getNumberValue();
-        Integer min = null;
-        Integer max = null;
-        if (numberValue.contains("-")) {
-            String[] split = numberValue.split("-");
-            min = Integer.valueOf(split[0]);
-            max = Integer.valueOf(split[1]);
-            strategy.setNumberMin(min);
-            strategy.setNumberMax(max);
-        }
+        String numberValue = strategy.getNumberValue().trim();
+        Integer min = strategy.getNumberMin();
+        Integer max = strategy.getNumberMax();
 
         QueryWrapper<KuaishouChannelCreateStrategy> queryWrapper = new QueryWrapper<>();
         queryWrapper.eq("product_id", strategy.getProductId());
@@ -243,6 +236,15 @@ public class KuaishouChannelServiceImpl extends ServiceImpl<KuaishouChannelMappe
             queryWrapper.eq("account_id", strategy.getAccountId());
         }
         queryWrapper.eq("project_id", strategy.getProjectId());
+        Integer numberMin = 0;
+        Integer numberMax = 0;
+        if (strategy.getNumberValue().contains("-")) {
+            String[] split = strategy.getNumberValue().split("-");
+            numberMin = Integer.valueOf(split[0]);
+            numberMax = Integer.valueOf(split[1]);
+            strategy.setNumberMin(numberMin);
+            strategy.setNumberMax(numberMax);
+        }
         //查询是否已经创建过策略,若已创建则某些字段必须一致,比如是否循环、使用层级
         KuaishouChannelCreateStrategy one = channelCreateStrategyService.getOne(queryWrapper.last("limit 1"));
         if (!Check.isNull(one)) {
@@ -279,8 +281,6 @@ public class KuaishouChannelServiceImpl extends ServiceImpl<KuaishouChannelMappe
             if (!strategy.getNumberValue().contains("-")) {
                 return customizedCreate(strategy);
             }
-            Integer numberMin = strategy.getNumberMin();
-            Integer numberMax = strategy.getNumberMax();
             Integer usageRange = strategy.getUsageRange();
             if (usageRange == 2) {
                 /*==========================范围是 项目==========================*/
@@ -511,6 +511,18 @@ public class KuaishouChannelServiceImpl extends ServiceImpl<KuaishouChannelMappe
                     updateApp(strategy, app, token);
                 }
             }
+        }else{
+            KuaiShouAppList appInfo = kuaiShouAppListService.getAppInfo(strategy.getAccountId(), strategy.getAppId());
+            KuaishouChannelAppInfo channelAppInfo = new KuaishouChannelAppInfo();
+            BeanUtils.copyProperties(appInfo, channelAppInfo);
+            channelAppInfo.setState(1);
+            channelAppInfo.setUrl((String) appInfo.getUrl());
+            channelAppInfo.setUseSdk(0);
+            channelAppInfo.setAppIconUrl((String) appInfo.getAppIconUrl());
+            channelAppInfo.setId(null);
+            channelAppInfo.setType("check");
+            channelAppInfo.setRemark("选择原有App");
+            channelAppInfoService.save(channelAppInfo);
         }
     }
 
@@ -906,6 +918,14 @@ public class KuaishouChannelServiceImpl extends ServiceImpl<KuaishouChannelMappe
                 }
                 strategy.setCreateType(createType);
 
+                if (strategy.getNumberValue().contains("-")) {
+                    String[] split = strategy.getNumberValue().split("-");
+                    Integer numberMin = Integer.valueOf(split[0]);
+                    Integer numberMax = Integer.valueOf(split[1]);
+                    strategy.setNumberMin(numberMin);
+                    strategy.setNumberMax(numberMax);
+                }
+
                 QueryWrapper<KuaishouChannelCreateStrategy> queryWrapper = new QueryWrapper<>();
                 queryWrapper.eq("product_id", strategy.getProductId());
                 if (!Check.isNull(strategy.getAccountId())) {
@@ -949,36 +969,81 @@ public class KuaishouChannelServiceImpl extends ServiceImpl<KuaishouChannelMappe
 
     @Override
     public Result<Object> queryChannel(Long accountId, String level, String appName, String photoName) throws Exception {
-        //查询账户所有策略
-        List<Long> strategyIds = channelCreateStrategyService.queryAllIdByAccountId(accountId);
-        if (Check.isNull(strategyIds) || strategyIds.isEmpty()) {
-            return Result.error("渠道号获取失败,该账户没有创建过渠道号");
-        }
-        List<Integer> usageTimesTypes = channelMapper.queryUsedLevel(strategyIds);
-        if (Check.isNull(usageTimesTypes)) {
-            return Result.error("渠道号已无效");
+        KuaishouChannel one = channelMapper.getChannelEntity(accountId);
+        if (Check.isNull(one)) {
+            return Result.error("未查询到渠道号");
         }
-        for (Integer usageTimes : usageTimesTypes) {
-            //获取可用渠道号,筛查出一个返回给前端
-            List<KuaishouChannel> list = channelMapper.queryChannelByUsageTimes(usageTimes, level, strategyIds, appName);
-            if (Check.isNull(list)) {
-                continue;
+        //是否循环重复使用 0:否,1:是
+        Integer isCycle = one.getIsCycle();
+        if (isCycle == 0) {
+            if ("account".equals(level)) {
+                //账户层级   不可循环使用渠道号
+                List<KuaishouChannel> list = channelMapper.getAccountLevelNoRepeatChannel(accountId, appName);
+                KuaishouChannel channel = getValidChannel(list);
+                if (!Check.isNull(channel)) {
+                    return Result.ok(channel);
+                }
+            } else {
+                //获取可用渠道号,筛查出一个返回给前端
+                List<KuaishouChannel> list = channelMapper.queryNoAccountLevelNoRepeatChannel(level, accountId, appName);
+                KuaishouChannel channel = getValidChannel(list);
+                if (!Check.isNull(channel)) {
+                    return Result.ok(channel);
+                }
             }
-            for (KuaishouChannel channel : list) {
-                //1 关联单品,无单品则跳过
-                if (channel.getIsHaveItem() == 1) {
-                    List<KuaishouChannelItems> items = channelItemsRelService.queryItems(channel.getId());
-                    if (Check.isNull(items) || items.isEmpty()) {
-                        continue;
+        } else {
+            //循环使用逻辑
+            if ("account".equals(level)) {
+                //账户层级可循环使用渠道号
+                List<KuaishouChannel> list = channelMapper.getAccountLevelRepeatChannel(accountId,appName);
+                KuaishouChannel channel = getValidChannel(list);
+                if (!Check.isNull(channel)) {
+                    return Result.ok(channel);
+                }
+            } else {
+                //查询账户所有策略
+                List<Long> strategyIds = channelCreateStrategyService.queryAllIdByAccountId(accountId);
+                if (Check.isNull(strategyIds) || strategyIds.isEmpty()) {
+                    return Result.error("渠道号获取失败,该账户没有创建过渠道号");
+                }
+                List<Integer> usageTimesTypes = channelMapper.queryUsedLevel(strategyIds);
+                if (Check.isNull(usageTimesTypes)) {
+                    return Result.error("渠道号已无效");
+                }
+                for (Integer usageTimes : usageTimesTypes) {
+                    //获取可用渠道号,筛查出一个返回给前端
+                    List<KuaishouChannel> list = channelMapper.queryChannelByUsageTimes(usageTimes, level, strategyIds, appName);
+                    KuaishouChannel channel = getValidChannel(list);
+                    if (!Check.isNull(channel)) {
+                        return Result.ok(channel);
                     }
-                    channel.setItems(items);
                 }
-                return Result.ok(channel);
             }
         }
         return Result.error("查询失败");
     }
 
+    /**
+     * 筛选渠道号,给渠道号添加单品
+     */
+    private KuaishouChannel getValidChannel(List<KuaishouChannel> list) {
+        if (Check.isNull(list) || list.isEmpty()) {
+            return null;
+        }
+        for (KuaishouChannel channel : list) {
+            //1 关联单品,无单品则跳过
+            if (channel.getIsHaveItem() == 1) {
+                List<KuaishouChannelItems> items = channelItemsRelService.queryItems(channel.getId());
+                if (Check.isNull(items) || items.isEmpty()) {
+                    continue;
+                }
+                channel.setItems(items);
+            }
+            return channel;
+        }
+        return null;
+    }
+
     @Override
     public Result<Object> queryChannelLevel(JSONObject data) {
         Long accountId = data.getLong("accountId");
@@ -999,8 +1064,7 @@ public class KuaishouChannelServiceImpl extends ServiceImpl<KuaishouChannelMappe
     }
 
     @Override
-    public void callBackUpdateChannelRel(String level, String channelCode, Long accountId, Long planId, Long
-            groupId) {
+    public void callBackUpdateChannelRel(String level, String channelCode, Long accountId, Long planId, Long groupId) {
         try {
             QueryWrapper<KuaishouChannel> queryWrapper = new QueryWrapper<>();
             queryWrapper.eq("account_id", accountId);
@@ -1020,15 +1084,15 @@ public class KuaishouChannelServiceImpl extends ServiceImpl<KuaishouChannelMappe
                     rel.setUnitId(groupId);
                     rel.setUpdateTime(new Date());
                     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);
-                    }
+//                    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) {