소스 검색

渠道号。。。获取已使用渠道号列表

zhaoxian 4 년 전
부모
커밋
f6a245bec2

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

@@ -1,6 +1,7 @@
 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;
@@ -38,4 +39,8 @@ public interface KuaishouChannelMapper extends BaseMapper<KuaishouChannel> {
     Integer queryUsedChannelNumber(@Param("strategyId") Long strategyId);
 
     List<KuaishouChannel> queryByAccountIdLevel(@Param("accountId") Long accountId, @Param("usageLevel") String usageLevel);
+
+    List<Integer> queryUsedLevel(@Param("strategys") List<KuaishouChannelCreateStrategy> strategys);
+
+    List<KuaishouChannel> queryChannelByHaveCycleTimes(@Param("haveCycleTimes") Integer haveCycleTimes, @Param("usageLevel") String usageLevel, @Param("strategys") List<KuaishouChannelCreateStrategy> strategys);
 }

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

@@ -68,32 +68,32 @@
                 AND create_type = #{createType}
             </if>
             <if test="channelName != null">
-                AND LOCATE(#{channelName},t1.channel_name)
+                AND LOCATE(#{channelName},channel_name)
             </if>
             <if test="channelCode != null">
-                AND LOCATE(#{channelCode},t1.channel_code)
+                AND LOCATE(#{channelCode},channel_code)
             </if>
         </where>
     </select>
 
     <select id="channelNumberDetails" resultType="cn.com.ctop.kuaishou.modules.channel.entity.KuaishouChannel">
-        SELECT t1.*
-        FROM ctop_kuaishou_channel t1
+        SELECT *
+        FROM ctop_kuaishou_channel
         <where>
             <if test="accountId != null">
-                AND t1.account_id = #{accountId}
+                AND account_id = #{accountId}
             </if>
             <if test="projectId != null">
-                AND t1.project_id = #{projectId}
+                AND project_id = #{projectId}
             </if>
             <if test="createType != null">
                 AND create_type = #{createType}
             </if>
             <if test="channelName != null">
-                AND LOCATE(#{channelName},t1.channel_name)
+                AND LOCATE(#{channelName},channel_name)
             </if>
             <if test="channelCode != null">
-                AND LOCATE(#{channelCode},t1.channel_code)
+                AND LOCATE(#{channelCode},channel_code)
             </if>
         </where>
     </select>
@@ -108,14 +108,11 @@
     <select id="channelNumberUsageDetailsList" resultType="com.alibaba.fastjson.JSONObject">
         SELECT IFNULL((SELECT MAX(tt.create_time)
                        FROM ctop_kuaishou_creative tt
-                       WHERE tt.unit_id = t3.unit_id),'-') as 'createTime',
-               CASE t1.usage_range WHEN 1 THEN '账户' WHEN 2 THEN '项目' ELSE '' END as 'usageRange',
-               IFNULL(t3.channel_code, '') as 'channelCode', IFNULL(t1.project_name, '') as 'projectName',
-               IFNULL(t2.auth_name, '') as 'authName', IFNULL(t3.account_id, '') as 'accountId',
-               IFNULL(t3.campaign_id, '') as 'campaignId',
-               IFNULL(t3.unit_id, '') as 'unitId'
+                       WHERE tt.unit_id = t3.unit_id),
+                      '-') as 'createTime', CASE t1.usage_range WHEN 1 THEN '账户' WHEN 2 THEN '项目' ELSE '' END as 'usageRange', IFNULL(t3.channel_code, '') as 'channelCode', IFNULL(t1.project_name, '') as 'projectName', IFNULL(t2.auth_name, '') as 'authName', IFNULL(t3.account_id, '') as 'accountId', IFNULL(t3.campaign_id, '') as 'campaignId', IFNULL(t3.unit_id, '') as 'unitId'
         FROM ctop_kuaishou_channel_rel t3
-                 INNER JOIN  ctop_kuaishou_channel t1 ON t1.account_id = t3.account_id AND t1.channel_code = t3.channel_code
+                 INNER JOIN ctop_kuaishou_channel t1
+                            ON t1.account_id = t3.account_id AND t1.channel_code = t3.channel_code
                  LEFT JOIN ctop_user_allocation t2 ON t1.account_id = t2.account_id
         WHERE t3.account_id = #{accountId}
           AND t3.channel_code = #{channelCode}
@@ -183,7 +180,42 @@
                usage_range
         FROM `ctop_kuaishou_channel`
         WHERE account_id = #{accountId}
+          and usage_level = #{usageLevel}
+          AND state = 1
+    </select>
+
+    <select id="queryChannelByHaveCycleTimes" resultType="cn.com.ctop.kuaishou.modules.channel.entity.KuaishouChannel">
+        SELECT id,
+        channel_code,
+        usage_level,
+        usage_range,
+        usage_times,
+        is_have_item,
+        cycle_times
+        FROM `ctop_kuaishou_channel`
+        WHERE strategy_id IN
+        <foreach collection="strategys" item="item" separator=","
+                 open="(" close=")">
+            #{item.id}
+        </foreach>
+        AND have_cycle_times = #{haveCycleTimes}
+        AND state = 1
         and usage_level = #{usageLevel}
+        ORDER BY usage_times,
+        limit 20
+    </select>
+
+
+    <select id="queryUsedLevel" resultType="java.lang.Integer">
+        SELECT have_cycle_times
+        FROM `ctop_kuaishou_channel`
+        where strategy_id in
+        <foreach collection="strategys" item="item" separator=","
+                 open="(" close=")">
+            #{item.id}
+        </foreach>
+        AND state = 1
+        group by have_cycle_times
     </select>
 
 </mapper>

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

@@ -3,7 +3,7 @@
 <mapper namespace="cn.com.ctop.kuaishou.modules.channel.mapper.KuaishouChannelRelMapper">
 
     <select id="queryByAccountChannelCode"
-            resultType="cn.com.ctop.kuaishou.modules.channel.entity.KuaishouChannelCreateStrategy">
+            resultType="cn.com.ctop.kuaishou.modules.channel.entity.KuaishouChannelRel">
         SELECT *
         FROM ctop_kuaishou_channel_rel
         WHERE account_id = #{accountId}

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

@@ -103,6 +103,9 @@ public class KuaishouChannelItemsServiceImpl extends ServiceImpl<KuaishouChannel
     public Result<Object> channelBindingItem(JSONArray request) {
         for (int i = 0; i < request.size(); i++) {
             JSONObject object = request.getJSONObject(i);
+            if (Check.isNull(object.getLong("id")) || Check.isNull(object.getLong("channelId"))) {
+                continue;
+            }
             KuaishouChannelItemsRel rel = new KuaishouChannelItemsRel();
             rel.setItemId(object.getLong("id"));
             rel.setChannelId(object.getLong("channelId"));

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

@@ -300,7 +300,7 @@ public class KuaishouChannelServiceImpl extends ServiceImpl<KuaishouChannelMappe
                         try {
                             KuaishouChannelCreateStrategy replaceData = replaceWildcard(strategy, i);
                             createApp(replaceData, null, null);
-                            createChannel(replaceData, i, 0);
+                            createChannel(replaceData, i, 1);
                         } catch (Exception e) {
                             e.printStackTrace();
                         }
@@ -319,7 +319,7 @@ public class KuaishouChannelServiceImpl extends ServiceImpl<KuaishouChannelMappe
                     try {
                         KuaishouChannelCreateStrategy replaceData = replaceWildcard(strategy, i);
                         createApp(replaceData, token, oldAppList);
-                        createChannel(replaceData, i, 0);
+                        createChannel(replaceData, i, 1);
                     } catch (Exception e) {
                         e.printStackTrace();
                     }
@@ -816,7 +816,7 @@ public class KuaishouChannelServiceImpl extends ServiceImpl<KuaishouChannelMappe
                     strategy.setImageToken(tokenJson.getString("imageToken"));
                     try {
                         createApp(strategy, token, oldAppList);
-                        createChannel(strategy, 0, 0);
+                        createChannel(strategy, 0, 1);
                     } catch (Exception e) {
                         e.printStackTrace();
                     }
@@ -849,7 +849,10 @@ public class KuaishouChannelServiceImpl extends ServiceImpl<KuaishouChannelMappe
         }
         if (usageRange == 1) {
             /**============================账户范围============================*/
-            if ("plan".equals(usageLevel) && usageLevel.equals(level)) {
+            if ("account".equals(usageLevel)) {
+                //---------------------账户层级---------------------
+                return doAccountRangeAccountLevel(accountId, strategys);
+            } else if ("plan".equals(usageLevel) && usageLevel.equals(level)) {
                 //---------------------计划层级---------------------
                 return doAccountRangePlanLevel(accountId, strategys);
             } else if ("group".equals(usageLevel)) {
@@ -861,7 +864,7 @@ public class KuaishouChannelServiceImpl extends ServiceImpl<KuaishouChannelMappe
             /**============================项目范围============================*/
             if ("account".equals(usageLevel)) {
                 //---------------------账户层级---------------------
-                return doProjectRangeAccountLevel(accountId, strategys);
+                return doAccountRangePlanLevel(accountId, strategys);
             } else if ("plan".equals(usageLevel) && usageLevel.equals(level)) {
                 //---------------------计划层级---------------------
                 return doProjectRangePlanLevel(accountId, strategys);
@@ -873,103 +876,271 @@ public class KuaishouChannelServiceImpl extends ServiceImpl<KuaishouChannelMappe
         return Result.error("未查到渠道号");
     }
 
+    private Result<Object> doAccountRangeAccountLevel(Long accountId, List<KuaishouChannelCreateStrategy> strategys) throws Exception {
+        List<KuaishouChannel> channelList = channelMapper.queryByAccountIdLevel(accountId, "account");
+        if (!Check.isNull(channelList)) {
+            for (KuaishouChannel channel : channelList) {
+                KuaishouChannelRel channelRel = channelRelService.queryByAccountChannelCode(channel.getChannelCode(), accountId);
+                if (Check.isNull(channelRel)) {
+                    continue;
+                }
+                if (Check.isNull(channelRel.getAppId())) {
+                    createNewApp(channel, accountId, 1);
+                    if (Check.isNull(channel.getAppId())) {
+                        continue;
+                    } else {
+                        channelRel.setAppId(channel.getAppId());
+                        channelRelService.saveOrUpdate(channelRel);
+                        return Result.ok(channelRel);
+                    }
+                } else {
+                    return Result.ok(channelRel);
+                }
+            }
+        }
+        return Result.error("未查询到渠道号");
+    }
+
     //通过账户范围计划层级查询
-    private Result<Object> doAccountRangePlanLevel(Long accountId, List<KuaishouChannelCreateStrategy> strategys) {
-        for (KuaishouChannelCreateStrategy strategy : strategys) {
-            boolean flag = false;
-            Integer cycleTimes = strategy.getCycleTimes();//可循环次数
-            if (strategy.getCreateType() == 1) {
-                /**---------------------组、计划  批量 创建逻辑--------------------------*/
-                Integer numberMin = strategy.getNumberMin();
-                Integer numberMax = strategy.getNumberMax(); //编号最大值
-                //查询所有该策略下创建的渠道号
-                List<KuaishouChannel> builtChannel = channelMapper.queryMaxChannelNumber(strategy.getId());
-                if (!Check.isNull(builtChannel)) {
-                    for (KuaishouChannel maxChannel : builtChannel) {
-                        Integer haveCycleTimes = maxChannel.getHaveCycleTimes();//已用次数
-                        Long channelNumber = maxChannel.getChannelNumber();//已建最大编码
-                        //判断可循环次数>已循环次数
-                        if (cycleTimes >= haveCycleTimes) {
-                            //判断已建的编码,是否最大值,是,就跳过
-                            if (channelNumber >= numberMax) {
-                                continue;
-                            } else {
-                                //本次可用编码
-                                int number = channelNumber.intValue() + 1;
-                                //查询到计划或者组级未被分配给账户的渠道号
-                                //获取token
-                                CtopOauthToken token = tokenService.getTokenByAccountId(accountId);
-                                //获取应用图片token
-                                JSONObject tokenJson = getAccountImgToken(strategy.getAppIconUrl(), token);
-                                strategy.setImageToken(tokenJson.getString("imageToken"));
-                                //使用范围是账户时,查询旧app来做匹配
-                                List<KuaiShouAppList> oldAppList = kuaiShouAppListService.getAppListByAccountId(accountId);
-                                strategy.setAccountId(accountId);
-                                KuaishouChannelCreateStrategy replaceData = replaceWildcard(strategy, number);
-//                                    createApp(strategy, token, oldAppList);
-//                                    createChannel(strategy, number, 1);
-                                flag = true;
-                                break;
-                            }
+    private Result<Object> doAccountRangePlanLevel(Long accountId, List<KuaishouChannelCreateStrategy> strategys) throws Exception {
+        List<Integer> haveCycleTimesList = channelMapper.queryUsedLevel(strategys);
+        if (Check.isNull(haveCycleTimesList)) {
+            return Result.error("渠道号已无效");
+        }
+        for (Integer haveCycleTimes : haveCycleTimesList) {
+            //获取20个可用渠道号,筛查出一个返回给前端
+            List<KuaishouChannel> list = channelMapper.queryChannelByHaveCycleTimes(haveCycleTimes, "plan", strategys);
+            if (Check.isNull(list)) {
+                continue;
+            }
+            for (KuaishouChannel channel : list) {
+                Integer cycleTimes = channel.getCycleTimes();//可循环次数
+                Integer usageTimes = channel.getUsageTimes();//使用次数
+                //优先判断已经循环的次数 大于 使用次数
+                if (haveCycleTimes > usageTimes) {
+                    // 符合条件,获取该渠道号
+                    KuaishouChannelRel channelRel = channelRelService.queryByAccountChannelCode(channel.getChannelCode(), accountId);
+                    if (Check.isNull(channelRel.getAppId())) {
+                        //创建APP
+                        createNewApp(channel, accountId, 1);
+                        if (Check.isNull(channel.getAppId())) {
+                            continue;
+                        } else {
+                            channelRel.setAppId(channel.getAppId());
+                            channelRelService.saveOrUpdate(channelRel);
+                            return Result.ok(channelRel);
                         }
+                    } else {
+                        return Result.ok(channelRel);
                     }
                 } else {
-
+                    //判断可循环次数 大于 已经循环的次数
+                    if (cycleTimes > haveCycleTimes) {
+                        //已循环次数+1
+                        channel.setHaveCycleTimes(haveCycleTimes + 1);
+                        this.saveOrUpdate(channel);
+                    }
+                    continue;
                 }
             }
-            if (flag) {
-                break;
-            }
         }
-
-
-        return Result.ok();
+        return Result.ok("未查询到渠道号");
     }
 
     //通过账户范围广告组层级查询
-    private Result<Object> doAccountRangeGroupLevel(Long accountId, List<KuaishouChannelCreateStrategy> strategys) {
-        return Result.ok();
+    private Result<Object> doAccountRangeGroupLevel(Long accountId, List<KuaishouChannelCreateStrategy> strategys) throws Exception {
+        List<Integer> haveCycleTimesList = channelMapper.queryUsedLevel(strategys);
+        if (Check.isNull(haveCycleTimesList)) {
+            return Result.error("渠道号已无效");
+        }
+        for (Integer haveCycleTimes : haveCycleTimesList) {
+            //获取20个可用渠道号,筛查出一个返回给前端
+            List<KuaishouChannel> list = channelMapper.queryChannelByHaveCycleTimes(haveCycleTimes, "group", strategys);
+            if (Check.isNull(list)) {
+                continue;
+            }
+            for (KuaishouChannel channel : list) {
+                Integer cycleTimes = channel.getCycleTimes();//可循环次数
+                Integer usageTimes = channel.getUsageTimes();//使用次数
+                //优先判断已经循环的次数 大于 使用次数
+                if (haveCycleTimes > usageTimes) {
+                    // 符合条件,获取该渠道号
+                    KuaishouChannelRel channelRel = channelRelService.queryByAccountChannelCode(channel.getChannelCode(), accountId);
+                    if (Check.isNull(channelRel.getAppId())) {
+                        //创建APP
+                        createNewApp(channel, accountId, 1);
+                        if (Check.isNull(channel.getAppId())) {
+                            continue;
+                        } else {
+                            channelRel.setAppId(channel.getAppId());
+                            channelRelService.saveOrUpdate(channelRel);
+                            return Result.ok(channelRel);
+                        }
+                    } else {
+                        return Result.ok(channelRel);
+                    }
+                } else {
+                    //判断可循环次数 大于 已经循环的次数
+                    if (cycleTimes > haveCycleTimes) {
+                        //已循环次数+1
+                        channel.setHaveCycleTimes(haveCycleTimes + 1);
+                        this.saveOrUpdate(channel);
+                    }
+                    continue;
+                }
+            }
+        }
+        return Result.ok("未查询到渠道号");
     }
 
     //通过项目范围账户层级查询
-    private Result<Object> doProjectRangeAccountLevel(Long accountId, List<KuaishouChannelCreateStrategy> strategys) throws Exception {
-        JSONObject request = new JSONObject();
-        List<KuaishouChannel> channelList = channelMapper.queryByAccountIdLevel(accountId, "account");
-        if (!Check.isNull(channelList)) {
-            KuaishouChannel channel = channelList.get(0);
-            KuaishouChannelRel channelRel = channelRelService.queryByAccountChannelCode(channel.getChannelCode(), channel.getAccountId());
-            if (Check.isNull(channelRel)) {/////
-                return Result.error("未查询到渠道号");
+    private Result<Object> doProjectRangePlanLevel(Long accountId, List<KuaishouChannelCreateStrategy> strategys) throws Exception {
+        List<Integer> haveCycleTimesList = channelMapper.queryUsedLevel(strategys);
+        if (Check.isNull(haveCycleTimesList)) {
+            return Result.error("渠道号已无效");
+        }
+        for (Integer haveCycleTimes : haveCycleTimesList) {
+            //获取20个可用渠道号,筛查出一个返回给前端
+            List<KuaishouChannel> list = channelMapper.queryChannelByHaveCycleTimes(haveCycleTimes, "plan", strategys);
+            if (Check.isNull(list)) {
+                continue;
             }
-            if (Check.isNull(channelRel.getAppId())) {
-                createNewApp(channel, accountId, 1);
-                if (Check.isNull(channel.getAppId())) {
-                    return Result.error("账户创建应用失败,渠道号不可用");
+            for (KuaishouChannel channel : list) {
+                Integer cycleTimes = channel.getCycleTimes();//可循环次数
+                Integer usageTimes = channel.getUsageTimes();//使用次数
+                //优先判断已经循环的次数 大于 使用次数
+                if (haveCycleTimes > usageTimes) {
+                    // 符合条件,获取该渠道号
+                    KuaishouChannelRel channelRel = channelRelService.queryByAccountChannelCode(channel.getChannelCode(), accountId);
+                    if (Check.isNull(channelRel.getAppId())) {
+                        //创建APP
+                        createNewApp(channel, accountId, 1);
+                        if (Check.isNull(channel.getAppId())) {
+                            continue;
+                        } else {
+                            channelRel.setAppId(channel.getAppId());
+                            channelRelService.saveOrUpdate(channelRel);
+                            return Result.ok(channelRel);
+                        }
+                    } else {
+                        return Result.ok(channelRel);
+                    }
                 } else {
-                    channelRel.setAppId(channel.getAppId());
-                    channelRelService.saveOrUpdate(channelRel);
-                    request.put("channelCode", channelRel.getChannelCode());
-                    request.put("appId", channelRel.getAppId());
-                    return Result.ok(request);
+                    //判断可循环次数 大于 已经循环的次数
+                    if (cycleTimes > haveCycleTimes) {
+                        //已循环次数+1
+                        channel.setHaveCycleTimes(haveCycleTimes + 1);
+                        this.saveOrUpdate(channel);
+                    }
+                    continue;
                 }
-            } else {
-                request.put("channelCode", channelRel.getChannelCode());
-                request.put("appId", channelRel.getAppId());
-                return Result.ok(request);
             }
-        } else {
-            return Result.error("未查询到渠道号");
         }
+        return Result.ok("未查询到渠道号");
     }
 
-    //通过项目范围账户层级查询
-    private Result<Object> doProjectRangePlanLevel(Long accountId, List<KuaishouChannelCreateStrategy> strategys) {
-        return Result.ok();
+    //通过项目范围广告组层级查询
+    private Result<Object> doProjectRangeGroupLevel(Long accountId, List<KuaishouChannelCreateStrategy> strategys) throws Exception {
+        List<Integer> haveCycleTimesList = channelMapper.queryUsedLevel(strategys);
+        if (Check.isNull(haveCycleTimesList)) {
+            return Result.error("渠道号已无效");
+        }
+        for (Integer haveCycleTimes : haveCycleTimesList) {
+            //获取20个可用渠道号,筛查出一个返回给前端
+            List<KuaishouChannel> list = channelMapper.queryChannelByHaveCycleTimes(haveCycleTimes, "group", strategys);
+            if (Check.isNull(list)) {
+                continue;
+            }
+            for (KuaishouChannel channel : list) {
+                Integer cycleTimes = channel.getCycleTimes();//可循环次数
+                Integer usageTimes = channel.getUsageTimes();//使用次数
+                //优先判断已经循环的次数 大于 使用次数
+                if (haveCycleTimes > usageTimes) {
+                    // 符合条件,获取该渠道号
+                    KuaishouChannelRel channelRel = channelRelService.queryByAccountChannelCode(channel.getChannelCode(), accountId);
+                    if (Check.isNull(channelRel.getAppId())) {
+                        //创建APP
+                        createNewApp(channel, accountId, 1);
+                        if (Check.isNull(channel.getAppId())) {
+                            continue;
+                        } else {
+                            channelRel.setAppId(channel.getAppId());
+                            channelRelService.saveOrUpdate(channelRel);
+                            return Result.ok(channelRel);
+                        }
+                    } else {
+                        return Result.ok(channelRel);
+                    }
+                } else {
+                    //判断可循环次数 大于 已经循环的次数
+                    if (cycleTimes > haveCycleTimes) {
+                        //已循环次数+1
+                        channel.setHaveCycleTimes(haveCycleTimes + 1);
+                        this.saveOrUpdate(channel);
+                    }
+                    continue;
+                }
+            }
+        }
+        return Result.ok("未查询到渠道号");
     }
 
-    //通过项目范围广告组层级查询
-    private Result<Object> doProjectRangeGroupLevel(Long accountId, List<KuaishouChannelCreateStrategy> strategys) {
-        return Result.ok();
+    private void createNewApp(KuaishouChannel channel, Long accountId, int count) throws Exception {
+        CtopOauthToken token = tokenService.getTokenByAccountId(accountId);
+        String accessToken = null;
+        if (!Check.isNull(token)) {
+            accessToken = token.getAccessToken();
+        }
+        if (Check.isNull(channel.getChannelAppInfoId())) {
+            return;
+        }
+        KuaishouChannelAppInfo one = channelAppInfoService.getById(channel.getChannelAppInfoId());
+        JSONObject tokenJson = getAccountImgToken(one.getAppIconUrl(), token);
+        String imageToken = tokenJson.getString("imageToken");
+        JSONObject requestJson = new JSONObject();
+        requestJson.put("advertiser_id", accountId);
+        requestJson.put("app_version", one.getAppVersion());
+        requestJson.put("app_name", one.getAppName());
+        requestJson.put("image_token", imageToken);
+        requestJson.put("package_name", one.getPackageName());
+        requestJson.put("platform", 1);//Android应用下载
+        requestJson.put("url", one.getUrl());
+        requestJson.put("use_sdk", 0);
+        requestJson.put("app_privacy_url", one.getAppPrivacyUrl());
+        String url = PropertiesUtils.getConfig("kuaishou_api_url") + KuaishouInterfaceConstant.APP_CREATE;
+        Map<String, String> headerMap = new HashMap<>();
+        headerMap.put("Content-Type", "multipart/form-data");
+        headerMap.put("Access-Token", accessToken);
+        String request = materialUploadService.exceptInfoForRestTemplate(url, requestJson, headerMap);
+        JSONObject resultJson = JSONObject.parseObject(request);
+        if (!Check.isNull(resultJson)) {
+            Integer code = resultJson.getInteger("code");
+            if (code == 0) {
+                JSONObject data = resultJson.getJSONObject("data");
+                Long appId = data.getLong("app_id");
+                one.setState(1);//成功
+                one.setRemark("创建" + count + "次,succsee");
+                one.setAppId(appId);
+                channelAppInfoService.saveOrUpdate(one);
+                channel.setAppId(appId);
+            } else {
+                String message = resultJson.getString("message");
+                one.setRemark("创建" + count + "次," + message);
+                channelAppInfoService.saveOrUpdate(one);
+                if (message.contains("token")) {
+                    //token失效直接跳过
+                    return;
+                }
+                if (count == 3) {
+                    //渠道号关联的应用创建3次未成功,该渠道号状态置为无效
+                    channel.setState(0);
+                    this.saveOrUpdate(channel);
+                }
+            }
+        }
+        if (Check.isNull(one.getAppId()) && count < 4) {
+            createNewApp(channel, accountId, count + 1);
+        }
     }
 
 
@@ -993,7 +1164,6 @@ public class KuaishouChannelServiceImpl extends ServiceImpl<KuaishouChannelMappe
             isCycle = createStrategy.getIsCycle();
             //若有渠道号策略,则必须创建渠道号,除非渠道号已经建满(是否循环,循环次数决定)
             //判断是否已创建过渠道号,若未创建,则进行创建
-            newAccountId(accountId, strategys, usageLevel);
         } else {
             usageRange = channel.getUsageRange();
             usageLevel = channel.getUsageLevel();
@@ -1027,50 +1197,6 @@ public class KuaishouChannelServiceImpl extends ServiceImpl<KuaishouChannelMappe
         return null;
     }
 
-    private void createNewApp(KuaishouChannel channel, Long accountId, int count) throws Exception {
-        CtopOauthToken token = tokenService.getTokenByAccountId(accountId);
-        String accessToken = null;
-        if (!Check.isNull(token)) {
-            accessToken = token.getAccessToken();
-        }
-        KuaishouChannelAppInfo one = channelAppInfoService.getById(channel.getChannelAppInfoId());
-        JSONObject tokenJson = getAccountImgToken(one.getAppIconUrl(), token);
-        String imageToken = tokenJson.getString("imageToken");
-        JSONObject requestJson = new JSONObject();
-        requestJson.put("advertiser_id", channel.getAccountId());
-        requestJson.put("app_version", one.getAppVersion());
-        requestJson.put("app_name", one.getAppName());
-        requestJson.put("image_token", imageToken);
-        requestJson.put("package_name", one.getPackageName());
-        requestJson.put("platform", 1);//Android应用下载
-        requestJson.put("url", one.getUrl());
-        requestJson.put("use_sdk", 0);
-        requestJson.put("app_privacy_url", one.getAppPrivacyUrl());
-        String url = PropertiesUtils.getConfig("kuaishou_api_url") + KuaishouInterfaceConstant.APP_CREATE;
-        Map<String, String> headerMap = new HashMap<>();
-        headerMap.put("Content-Type", "multipart/form-data");
-        headerMap.put("Access-Token", accessToken);
-        String request = materialUploadService.exceptInfoForRestTemplate(url, requestJson, headerMap);
-        JSONObject resultJson = JSONObject.parseObject(request);
-        if (!Check.isNull(resultJson)) {
-            Integer code = resultJson.getInteger("code");
-            if (code == 0) {
-                JSONObject data = resultJson.getJSONObject("data");
-                Long appId = data.getLong("app_id");
-                one.setState(1);//成功
-                one.setRemark("应用创建成功");
-                one.setAppId(appId);
-                channelAppInfoService.saveOrUpdate(one);
-                channel.setAppId(appId);
-                this.saveOrUpdate(channel);
-            }
-        }
-        if (Check.isNull(one.getAppId()) && count < 4) {
-            createNewApp(channel, accountId, count + 1);
-        }
-    }
-
-
     /**
      * 1、通过账户id查询渠道号,查到则返回
      */
@@ -1112,131 +1238,4 @@ public class KuaishouChannelServiceImpl extends ServiceImpl<KuaishouChannelMappe
         return count;
     }
 
-
-    private void newAccountId(Long accountId, List<KuaishouChannelCreateStrategy> strategys, String usageLevel) throws Exception {
-        for (KuaishouChannelCreateStrategy strategy : strategys) {
-            boolean flag = false;
-            Integer cycleTimes = strategy.getCycleTimes();//可循环次数
-            if ("account".equals(usageLevel)) {
-                if (strategy.getCreateType() == 1) {
-                    Integer numberMin = strategy.getNumberMin();
-                    Integer numberMax = strategy.getNumberMax(); //编号最大值
-                    //查询所有该策略下创建的渠道号
-                    List<KuaishouChannel> builtChannel = channelMapper.queryMaxChannelNumber(strategy.getId());
-                    if (!Check.isNull(builtChannel)) {
-                        for (KuaishouChannel maxChannel : builtChannel) {
-                            Integer haveCycleTimes = maxChannel.getHaveCycleTimes();//已用次数
-                            Long channelNumber = maxChannel.getChannelNumber();//已建最大编码
-                            //判断可循环次数>已循环次数
-                            if (cycleTimes >= haveCycleTimes) {
-                                //判断已建的编码,是否最大值,是,就跳过
-                                if (channelNumber >= numberMax) {
-                                    continue;
-                                } else {
-                                    //获取token
-                                    CtopOauthToken token = tokenService.getTokenByAccountId(accountId);
-                                    //获取应用图片token
-                                    JSONObject tokenJson = getAccountImgToken(strategy.getAppIconUrl(), token);
-                                    strategy.setImageToken(tokenJson.getString("imageToken"));
-                                    //使用范围是账户时,查询旧app来做匹配
-                                    List<KuaiShouAppList> oldAppList = kuaiShouAppListService.getAppListByAccountId(accountId);
-                                    strategy.setAccountId(accountId);
-                                    KuaishouChannelCreateStrategy replaceData = replaceWildcard(strategy, channelNumber.intValue() + 1);
-                                    createApp(strategy, token, oldAppList);
-                                    createChannel(strategy, channelNumber.intValue() + 1, 1);
-                                    if (!"account".equals(usageLevel)) {
-
-                                    }
-                                    flag = true;
-                                    break;
-                                }
-                            }
-                        }
-                    } else {
-                        /**通过策略没有查询到则取最小值重新创建*/
-                        //获取token
-                        CtopOauthToken token = tokenService.getTokenByAccountId(accountId);
-                        //获取应用图片token
-                        JSONObject tokenJson = getAccountImgToken(strategy.getAppIconUrl(), token);
-                        strategy.setImageToken(tokenJson.getString("imageToken"));
-                        //使用范围是账户时,查询旧app来做匹配
-                        List<KuaiShouAppList> oldAppList = kuaiShouAppListService.getAppListByAccountId(accountId);
-                        strategy.setAccountId(accountId);
-                        KuaishouChannelCreateStrategy replaceData = replaceWildcard(strategy, numberMin);
-                        createApp(strategy, token, oldAppList);
-                        createChannel(strategy, numberMin, 1);//自定义,excel创建的排序都为0
-                        flag = true;
-                        break;
-                    }
-                } else {
-                    /**---------------------创建方式是 excel和自定义--------------------------*/
-                    //查询已用次数
-                    Integer usedCount = channelMapper.queryUsedChannelNumber(strategy.getId());
-                    if (usedCount >= cycleTimes) {
-                        continue;
-                    }
-                    //获取token
-                    CtopOauthToken token = tokenService.getTokenByAccountId(accountId);
-                    //获取应用图片token
-                    JSONObject tokenJson = getAccountImgToken(strategy.getAppIconUrl(), token);
-                    //使用范围是账户时,查询旧app来做匹配
-                    List<KuaiShouAppList> oldAppList = kuaiShouAppListService.getAppListByAccountId(accountId);
-                    strategy.setImageToken(tokenJson.getString("imageToken"));
-                    strategy.setAccountId(accountId);
-                    createApp(strategy, token, oldAppList);
-                    createChannel(strategy, 1, 1);
-                }
-            } else {
-                /**---------------------组、计划逻辑--------------------------*/
-                if (strategy.getCreateType() == 1) {
-                    /**---------------------组、计划  批量 创建逻辑--------------------------*/
-                    Integer numberMin = strategy.getNumberMin();
-                    Integer numberMax = strategy.getNumberMax(); //编号最大值
-                    //查询所有该策略下创建的渠道号
-                    List<KuaishouChannel> builtChannel = channelMapper.queryMaxChannelNumber(strategy.getId());
-                    if (!Check.isNull(builtChannel)) {
-                        for (KuaishouChannel maxChannel : builtChannel) {
-                            Integer haveCycleTimes = maxChannel.getHaveCycleTimes();//已用次数
-                            Long channelNumber = maxChannel.getChannelNumber();//已建最大编码
-                            //判断可循环次数>已循环次数
-                            if (cycleTimes >= haveCycleTimes) {
-                                //判断已建的编码,是否最大值,是,就跳过
-                                if (channelNumber >= numberMax) {
-                                    continue;
-                                } else {
-                                    //本次可用编码
-                                    int number = channelNumber.intValue() + 1;
-                                    //查询到计划或者组级未被分配给账户的渠道号
-                                    //获取token
-                                    CtopOauthToken token = tokenService.getTokenByAccountId(accountId);
-                                    //获取应用图片token
-                                    JSONObject tokenJson = getAccountImgToken(strategy.getAppIconUrl(), token);
-                                    strategy.setImageToken(tokenJson.getString("imageToken"));
-                                    //使用范围是账户时,查询旧app来做匹配
-                                    List<KuaiShouAppList> oldAppList = kuaiShouAppListService.getAppListByAccountId(accountId);
-                                    strategy.setAccountId(accountId);
-                                    KuaishouChannelCreateStrategy replaceData = replaceWildcard(strategy, number);
-                                    createApp(strategy, token, oldAppList);
-                                    createChannel(strategy, number, 1);
-                                    flag = true;
-                                    break;
-                                }
-                            }
-                        }
-                    } else {
-
-                    }
-
-                } else {
-                    /**---------------------组、计划  Excel、自定义 创建逻辑--------------------------*/
-
-
-                }
-            }
-            if (flag) {
-                break;
-            }
-        }
-
-    }
 }