Pārlūkot izejas kodu

Merge branch 'V2.0.1' into test

zhaoxian 3 gadi atpakaļ
vecāks
revīzija
4df40bd84b

+ 0 - 1
jeecg-boot-module-system/src/main/java/cn/com/ctop/kuaishou/modules/channel/entity/KuaishouChannelCreateStrategy.java

@@ -189,7 +189,6 @@ public class KuaishouChannelCreateStrategy {
     /**
      * 创建类型,1新增,2,选择
      */
-    @TableField(exist = false)
     private String appCreateType;
 
     /**

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

@@ -14,7 +14,5 @@ import com.baomidou.mybatisplus.core.mapper.BaseMapper;
  */
 public interface KuaishouChannelCreateStrategyMapper extends BaseMapper<KuaishouChannelCreateStrategy> {
 
-    List<KuaishouChannelCreateStrategy> queryChannelStrategyByAccountId(@Param("accountId") Long accountId);
-
-    List<KuaishouChannelCreateStrategy> queryChannelStrategyByProjectId(@Param("accountId") Long accountId);
+    List<Long> queryAllIdByAccountId(@Param("accountId")  Long accountId);
 }

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

@@ -40,9 +40,9 @@ public interface KuaishouChannelMapper extends BaseMapper<KuaishouChannel> {
 
     List<KuaishouChannel> queryByAccountIdLevel(@Param("accountId") Long accountId, @Param("usageLevel") String usageLevel);
 
-    List<Integer> queryUsedLevel(@Param("strategys") List<KuaishouChannelCreateStrategy> strategys);
+    List<Integer> queryUsedLevel(@Param("strategys") List<Long> strategys);
 
-    List<KuaishouChannel> queryChannelByUsageTimes(@Param("usageTimes") Integer usageTimes, @Param("usageLevel") String usageLevel, @Param("strategys") List<KuaishouChannelCreateStrategy> strategys, @Param("appName") String appName);
+    List<KuaishouChannel> queryChannelByUsageTimes(@Param("usageTimes") Integer usageTimes, @Param("usageLevel") String usageLevel, @Param("strategys") List<Long> strategys, @Param("appName") String appName);
 
     List<JSONObject> queryItemsListByAccountId(@Param("accountId") Long accountId, @Param("appName") String appName);
 

+ 11 - 19
jeecg-boot-module-system/src/main/java/cn/com/ctop/kuaishou/modules/channel/mapper/xml/KuaishouChannelCreateStrategyMapper.xml

@@ -2,24 +2,16 @@
 <!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
 <mapper namespace="cn.com.ctop.kuaishou.modules.channel.mapper.KuaishouChannelCreateStrategyMapper">
 
-    <select id="queryChannelStrategyByAccountId" resultType="cn.com.ctop.kuaishou.modules.channel.entity.KuaishouChannelCreateStrategy">
-        SELECT
-            *
-        FROM
-            ctop_kuaishou_channel_create_strategy
-        WHERE
-            account_id =#{accountId}
-        ORDER BY
-            create_time
-    </select>
-    <select id="queryChannelStrategyByProjectId" resultType="cn.com.ctop.kuaishou.modules.channel.entity.KuaishouChannelCreateStrategy">
-        SELECT
-            *
-        FROM
-            ctop_kuaishou_channel_create_strategy
-        WHERE
-                project_id = ( SELECT project_id FROM ctop_user_allocation WHERE account_id = #{accountId} )
-        ORDER BY
-            create_time
+    <select id="queryAllIdByAccountId" resultType="java.lang.Long">
+        SELECT *
+        FROM (SELECT id
+              FROM ctop_kuaishou_channel_create_strategy
+              WHERE account_id = #{accountId}
+              UNION ALL
+              SELECT id
+              FROM ctop_kuaishou_channel_create_strategy
+              WHERE project_id = (SELECT project_id FROM ctop_user_allocation WHERE account_id = #{accountId})) t
+        GROUP BY t.id
     </select>
+
 </mapper>

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

@@ -200,15 +200,17 @@
                  open="(" close=")">
             #{item.id}
         </foreach>
-        AND t1.state = 1
-        AND t1.channel_state = 1
-        AND app_id in (
-            SELECT app_id FROM ctop_kuaishou_channel_app_info where app_name = #{appName}
-        )
-        AND t1.usage_times = #{usageTimes}
-        and t1.usage_level = #{usageLevel}
-        GROUP BY  t1.channel_code
-        ORDER BY t1.create_time,t1.channel_number
+            AND t1.state = 1
+            AND t1.channel_state = 1
+        <if test="usageTimes > 1">
+            AND is_cycle = 1
+          </if>
+            AND app_id in (
+                SELECT app_id FROM ctop_kuaishou_channel_app_info where app_name = #{appName}
+            )
+            AND t1.usage_times = #{usageTimes}
+            and t1.usage_level = #{usageLevel}
+            ORDER BY t1.create_time,t1.channel_number
     </select>
 
 

+ 1 - 3
jeecg-boot-module-system/src/main/java/cn/com/ctop/kuaishou/modules/channel/service/IKuaishouChannelCreateStrategyService.java

@@ -14,7 +14,5 @@ import java.util.List;
  */
 public interface IKuaishouChannelCreateStrategyService extends IService<KuaishouChannelCreateStrategy> {
 
-    List<KuaishouChannelCreateStrategy> queryChannelStrategyByAccountId(Long accountId);
-
-    List<KuaishouChannelCreateStrategy> queryChannelStrategyByProjectId(Long accountId);
+    List<Long> queryAllIdByAccountId(Long accountId);
 }

+ 2 - 7
jeecg-boot-module-system/src/main/java/cn/com/ctop/kuaishou/modules/channel/service/impl/KuaishouChannelCreateStrategyServiceImpl.java

@@ -24,12 +24,7 @@ public class KuaishouChannelCreateStrategyServiceImpl extends ServiceImpl<Kuaish
     private KuaishouChannelCreateStrategyMapper createStrategyMapper;
 
     @Override
-    public List<KuaishouChannelCreateStrategy> queryChannelStrategyByAccountId(Long accountId) {
-        return createStrategyMapper.queryChannelStrategyByAccountId(accountId);
-    }
-
-    @Override
-    public List<KuaishouChannelCreateStrategy> queryChannelStrategyByProjectId(Long accountId) {
-        return createStrategyMapper.queryChannelStrategyByProjectId(accountId);
+    public List<Long> queryAllIdByAccountId(Long accountId) {
+        return createStrategyMapper.queryAllIdByAccountId(accountId);
     }
 }

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

@@ -382,38 +382,31 @@ public class KuaishouChannelServiceImpl extends ServiceImpl<KuaishouChannelMappe
      * 账户级批量创建渠道号
      */
     private void addMoreChannel(KuaishouChannelCreateStrategy strategy, Integer numberMin, Integer numberMax) {
-        //获取token
-        CtopOauthToken token = tokenService.getTokenByAccountId(strategy.getAccountId());
-        Thread thread = new Thread() {
-            @Override
-            public void run() {
-                try {
-                    List<KuaiShouAppList> oldAppList = null;
-                    if (Check.isNull(strategy.getAppId())) {
-                        //使用范围是账户时,查询旧app来做匹配
-                        kuaishouInterfaceService.getAppList(token.getAccountId(), token.getAccessToken());
-                        oldAppList = kuaiShouAppListService.getAppListByAccountId(token.getAccountId());
-                    }
-                    if (!Check.isNull(strategy.getUrl()) && strategy.getUrl().contains(CHANNEL_STR)) {
-                        for (int i = numberMin; i <= numberMax; i++) {
-                            KuaishouChannelCreateStrategy replaceData = replaceWildcard(strategy, i);
-                            createApp(replaceData, token, oldAppList);
-                            createChannel(replaceData, i);
-                        }
-                    } else {
-                        createApp(strategy, token, oldAppList);
-                        for (int i = numberMin; i <= numberMax; i++) {
-                            KuaishouChannelCreateStrategy replaceData = replaceWildcard(strategy, i);
-                            createChannel(replaceData, i);
-                        }
-                    }
-                } catch (Exception e) {
-                    e.printStackTrace();
+        try {
+            //获取token
+            CtopOauthToken token = tokenService.getTokenByAccountId(strategy.getAccountId());
+            List<KuaiShouAppList> oldAppList = null;
+            if (Check.isNull(strategy.getAppId())) {
+                //使用范围是账户时,查询旧app来做匹配
+                kuaishouInterfaceService.getAppList(token.getAccountId(), token.getAccessToken());
+                oldAppList = kuaiShouAppListService.getAppListByAccountId(token.getAccountId());
+            }
+            if (!Check.isNull(strategy.getUrl()) && strategy.getUrl().contains(CHANNEL_STR)) {
+                for (int i = numberMin; i <= numberMax; i++) {
+                    KuaishouChannelCreateStrategy replaceData = replaceWildcard(strategy, i);
+                    createApp(replaceData, token, oldAppList);
+                    createChannel(replaceData, i);
+                }
+            } else {
+                createApp(strategy, token, oldAppList);
+                for (int i = numberMin; i <= numberMax; i++) {
+                    KuaishouChannelCreateStrategy replaceData = replaceWildcard(strategy, i);
+                    createChannel(replaceData, i);
                 }
             }
-        };
-        thread.start();
-
+        } catch (Exception e) {
+            e.printStackTrace();
+        }
     }
 
     /**
@@ -446,27 +439,21 @@ public class KuaishouChannelServiceImpl extends ServiceImpl<KuaishouChannelMappe
      * 创建单个渠道号
      */
     private void addSingleChannel(KuaishouChannelCreateStrategy strategy) {
-        Integer i = Integer.valueOf(strategy.getNumberValue());
-        CtopOauthToken token = tokenService.getTokenByAccountId(strategy.getAccountId());
-        Thread thread = new Thread() {
-            @Override
-            public void run() {
-                try {
-                    List<KuaiShouAppList> oldAppList = null;
-                    if (Check.isNull(strategy.getAppId())) {
-                        //使用范围是账户时,查询旧app来做匹配
-                        kuaishouInterfaceService.getAppList(token.getAccountId(), token.getAccessToken());
-                        oldAppList = kuaiShouAppListService.getAppListByAccountId(token.getAccountId());
-                    }
-                    KuaishouChannelCreateStrategy replaceData = replaceWildcard(strategy, i);
-                    createApp(replaceData, token, oldAppList);
-                    createChannel(replaceData, i);
-                } catch (Exception e) {
-                    e.printStackTrace();
-                }
+        try {
+            Integer i = Integer.valueOf(strategy.getNumberValue());
+            List<KuaiShouAppList> oldAppList = null;
+            CtopOauthToken token = tokenService.getTokenByAccountId(strategy.getAccountId());
+            if (Check.isNull(strategy.getAppId())) {
+                //使用范围是账户时,查询旧app来做匹配
+                kuaishouInterfaceService.getAppList(token.getAccountId(), token.getAccessToken());
+                oldAppList = kuaiShouAppListService.getAppListByAccountId(token.getAccountId());
             }
-        };
-        thread.start();
+            KuaishouChannelCreateStrategy replaceData = replaceWildcard(strategy, i);
+            createApp(replaceData, token, oldAppList);
+            createChannel(replaceData, i);
+        } catch (Exception e) {
+            e.printStackTrace();
+        }
     }
 
     /**
@@ -962,48 +949,34 @@ public class KuaishouChannelServiceImpl extends ServiceImpl<KuaishouChannelMappe
 
     @Override
     public Result<Object> queryChannel(Long accountId, String level, String appName, String photoName) throws Exception {
-        //查询账户策略
-        List<KuaishouChannelCreateStrategy> strategys = channelCreateStrategyService.queryChannelStrategyByAccountId(accountId);
-        if (Check.isNull(strategys) || strategys.isEmpty()) {
-            //查询账户所在项目策略
-            strategys = channelCreateStrategyService.queryChannelStrategyByProjectId(accountId);
-            if (Check.isNull(strategys) || strategys.isEmpty()) {
-                return Result.error("渠道号获取失败,该账户没有创建过渠道号");
-            }
+        //查询账户所有策略
+        List<Long> strategyIds = channelCreateStrategyService.queryAllIdByAccountId(accountId);
+        if (Check.isNull(strategyIds) || strategyIds.isEmpty()) {
+            return Result.error("渠道号获取失败,该账户没有创建过渠道号");
         }
-        //所有策略下的 使用范围,使用层级,是否循环等字段 保持一致
-        KuaishouChannelCreateStrategy createStrategy = strategys.get(0);
-        Integer usageRange = createStrategy.getUsageRange();
-        String usageLevel = createStrategy.getUsageLevel();
-        if ("plan".equals(level) && "group".equals(usageLevel)) {
-            return Result.error("您只创建了广告组层级的渠道号,通过广告计划查询不到渠道号");
+        List<Integer> usageTimesTypes = channelMapper.queryUsedLevel(strategyIds);
+        if (Check.isNull(usageTimesTypes)) {
+            return Result.error("渠道号已无效");
         }
-        if (usageRange == 1) {
-            /**============================账户范围============================*/
-            if ("account".equals(usageLevel)) {
-                //---------------------账户层级---------------------
-                return doAccountRangeAccountLevel(accountId, strategys, appName);
-            } else if ("plan".equals(usageLevel) && usageLevel.equals(level)) {
-                //---------------------计划层级---------------------
-                return doPlanLevel(accountId, strategys, appName, 0);
-            } else if ("group".equals(usageLevel)) {
-                //---------------------组层级-----------------------
-                return doGroupLevel(accountId, strategys, appName, 0, photoName);
+        for (Integer usageTimes : usageTimesTypes) {
+            //获取可用渠道号,筛查出一个返回给前端
+            List<KuaishouChannel> list = channelMapper.queryChannelByUsageTimes(usageTimes, level, strategyIds, appName);
+            if (Check.isNull(list)) {
+                continue;
             }
-        } else {
-            /**============================项目范围============================*/
-            if ("account".equals(usageLevel)) {
-                //---------------------账户层级---------------------
-                return doAccountRangeAccountLevel(accountId, strategys, appName);
-            } else if ("plan".equals(usageLevel) && usageLevel.equals(level)) {
-                //---------------------计划层级---------------------
-                return doPlanLevel(accountId, strategys, appName, 0);
-            } else if ("group".equals(usageLevel)) {
-                //---------------------组层级---------------------
-                return doGroupLevel(accountId, strategys, appName, 0, photoName);
+            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 Result.ok(channel);
             }
         }
-        return Result.error("未查到渠道号");
+        return Result.error("查询失败");
     }
 
     @Override
@@ -1188,8 +1161,7 @@ public class KuaishouChannelServiceImpl extends ServiceImpl<KuaishouChannelMappe
         }
     }
 
-    private Result<Object> doAccountRangeAccountLevel(Long
-                                                              accountId, List<KuaishouChannelCreateStrategy> strategys, String appName) throws Exception {
+    private Result<Object> getRealAccountChannel(Long accountId, List<KuaishouChannelCreateStrategy> strategys, String appName) throws Exception {
         List<KuaishouChannel> channelList = channelMapper.queryByAccountIdLevel(accountId, "account");
         if (!Check.isNull(channelList)) {
             for (KuaishouChannel channel : channelList) {
@@ -1222,125 +1194,6 @@ public class KuaishouChannelServiceImpl extends ServiceImpl<KuaishouChannelMappe
         return Result.error("未查询到渠道号");
     }
 
-    //通过账户范围计划层级查询
-    private Result<Object> doPlanLevel(Long accountId, List<KuaishouChannelCreateStrategy> strategys, String appName, int count) throws
-            Exception {
-        List<Integer> usageTimesTypes = channelMapper.queryUsedLevel(strategys);
-        if (Check.isNull(usageTimesTypes)) {
-            return Result.error("渠道号已无效");
-        }
-        for (Integer usageTimes : usageTimesTypes) {
-            //获取可用渠道号,筛查出一个返回给前端
-            List<KuaishouChannel> list = channelMapper.queryChannelByUsageTimes(usageTimes, "plan", strategys,appName);
-            if (Check.isNull(list)) {
-                continue;
-            }
-            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);
-                    }
-                    // 获取绑定应用的渠道号
-                    KuaishouChannelRel channelRel = channelRelService.queryByAccountChannelCode(channel.getChannelCode(), accountId, appName);
-                    if (Check.isNull(channelRel)) {
-                        continue;
-                    }
-                    if (Check.isNull(channelRel.getAppId())) {
-                        //创建APP
-                        createNewApp(channel, accountId, 1);
-                        if (Check.isNull(channel.getAppId())) {
-                            continue;
-                        } else {
-                            channelRel.setAppId(channel.getAppId());
-                            channelRelService.saveOrUpdate(channelRel);
-                            this.saveOrUpdate(channel);
-                            return Result.ok(channel);
-                        }
-                    } else {
-                        this.saveOrUpdate(channel);
-                        channel.setAppId(channelRel.getAppId());
-                        return Result.ok(channel);
-                    }
-
-            }
-        }
-        if (count == 0) {
-            return doPlanLevel(accountId, strategys, appName, 1);
-        }
-        return Result.ok("未查询到渠道号");
-    }
-
-    //通过项目范围广告组层级查询
-    private Result<Object> doGroupLevel(Long accountId, List<KuaishouChannelCreateStrategy> strategys, String
-            appName, int count, String photoName) throws Exception {
-        List<Integer> haveCycleTimesList = channelMapper.queryUsedLevel(strategys);
-        if (Check.isNull(haveCycleTimesList)) {
-            return Result.error("渠道号已无效");
-        }
-        for (Integer haveCycleTimes : haveCycleTimesList) {
-            List<KuaishouChannel> list = channelMapper.queryChannelByUsageTimes(haveCycleTimes, "group", strategys,appName);
-            if (Check.isNull(list)) {
-                continue;
-            }
-            for (KuaishouChannel channel : list) {
-//                Integer cycleTimes = channel.getCycleTimes();//可循环次数
-                Integer usageTimes = channel.getUsageTimes();//使用次数
-                //优先判断已经循环的次数 大于 使用次数
-                if (haveCycleTimes > usageTimes) {
-                    if (!Check.isNull(channel.getIsHaveItem()) && channel.getIsHaveItem() == 1) {
-                        //有单品
-                        List<KuaishouChannelItems> itemsList = channelItemsRelService.queryItems(channel.getId());
-                        if (Check.isNull(itemsList) || itemsList.isEmpty()) {
-                            continue;
-                        }
-                        //素材名字和单品关键字做匹配
-                        String keyword = itemsList.get(0).getKeyword();
-                        if (!photoName.contains(keyword)) {
-                            continue;
-                        }
-                    }
-                    // 符合条件,获取该渠道号
-                    KuaishouChannelRel channelRel = channelRelService.queryByAccountChannelCode(channel.getChannelCode(), accountId, appName);
-                    if (Check.isNull(channelRel)) {
-                        continue;
-                    }
-                    if (Check.isNull(channelRel.getAppId())) {
-                        //创建APP
-                        createNewApp(channel, accountId, 1);
-                        if (Check.isNull(channel.getAppId())) {
-                            continue;
-                        } else {
-                            channelRel.setAppId(channel.getAppId());
-                            channelRelService.saveOrUpdate(channelRel);
-                            this.saveOrUpdate(channel);
-                            return Result.ok(channel);
-                        }
-                    } else {
-                        this.saveOrUpdate(channel);
-                        channel.setAppId(channelRel.getAppId());
-                        return Result.ok(channel);
-                    }
-                } else {
-                    //判断可循环次数 大于 已经循环的次数
-//                    if (cycleTimes > haveCycleTimes) {
-//                        //已循环次数+1
-//                        channel.setHaveCycleTimes(haveCycleTimes + 1);
-//                        this.saveOrUpdate(channel);
-//                    }
-                    continue;
-                }
-            }
-        }
-        if (count == 0) {
-            return doGroupLevel(accountId, strategys, appName, 1, photoName);
-        }
-        return Result.ok("未查询到渠道号");
-    }
-
     private void createNewApp(KuaishouChannel channel, Long accountId, int count) throws Exception {
         CtopOauthToken token = tokenService.getTokenByAccountId(accountId);
         String accessToken = null;