|  | @@ -949,36 +949,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("渠道号获取失败,该账户没有创建过渠道号");
 | 
	
		
			
				|  |  | +        KuaishouChannel one = channelMapper.getChannelEntity(accountId);
 | 
	
		
			
				|  |  | +        if (Check.isNull(one)) {
 | 
	
		
			
				|  |  | +            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);
 | 
	
		
			
				|  |  | -            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 +1044,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 +1064,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) {
 |