Browse Source

渠道号。。。单品绑定逻辑

zhaoxian 4 years ago
parent
commit
b08be85b21

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

@@ -1,8 +1,11 @@
 package cn.com.ctop.kuaishou.modules.channel.mapper;
 
+import cn.com.ctop.kuaishou.modules.channel.entity.KuaishouChannelItems;
 import cn.com.ctop.kuaishou.modules.channel.entity.KuaishouChannelItemsRel;
 import com.baomidou.mybatisplus.core.mapper.BaseMapper;
 
+import java.util.List;
+
 /**
  * 渠道号和单品关系表
  *
@@ -12,4 +15,5 @@ import com.baomidou.mybatisplus.core.mapper.BaseMapper;
  */
 public interface KuaishouChannelItemsRelMapper extends BaseMapper<KuaishouChannelItemsRel> {
 
+    List<KuaishouChannelItems> queryItems(Long channelId);
 }

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

@@ -2,4 +2,10 @@
 <!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.KuaishouChannelItemsRelMapper">
 
+    <select id="queryItems" resultType="cn.com.ctop.kuaishou.modules.channel.entity.KuaishouChannelItems">
+        SELECT t2.item_name, t2.project_id, t2.project_name, t2.state, keyword
+        FROM ctop_kuaishou_channel_items_rel t1
+                 LEFT JOIN ctop_kuaishou_channel_items t2 ON t1.item_id = t2.id
+        WHERE t1.channel_id = #{channelId}
+    </select>
 </mapper>

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

@@ -1,8 +1,11 @@
 package cn.com.ctop.kuaishou.modules.channel.service;
 
+import cn.com.ctop.kuaishou.modules.channel.entity.KuaishouChannelItems;
 import cn.com.ctop.kuaishou.modules.channel.entity.KuaishouChannelItemsRel;
 import com.baomidou.mybatisplus.extension.service.IService;
 
+import java.util.List;
+
 /**
  * 渠道号和单品关系表
  *
@@ -12,4 +15,5 @@ import com.baomidou.mybatisplus.extension.service.IService;
  */
 public interface IKuaishouChannelItemsRelService extends IService<KuaishouChannelItemsRel> {
 
+    List<KuaishouChannelItems> queryItems(Long channelId);
 }

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

@@ -1,11 +1,15 @@
 package cn.com.ctop.kuaishou.modules.channel.service.impl;
 
+import cn.com.ctop.kuaishou.modules.channel.entity.KuaishouChannelItems;
 import cn.com.ctop.kuaishou.modules.channel.entity.KuaishouChannelItemsRel;
 import cn.com.ctop.kuaishou.modules.channel.mapper.KuaishouChannelItemsRelMapper;
 import cn.com.ctop.kuaishou.modules.channel.service.IKuaishouChannelItemsRelService;
 import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
+import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.stereotype.Service;
 
+import java.util.List;
+
 /**
  * 渠道号和单品关系表
  *
@@ -16,4 +20,11 @@ import org.springframework.stereotype.Service;
 @Service
 public class KuaishouChannelItemsRelServiceImpl extends ServiceImpl<KuaishouChannelItemsRelMapper, KuaishouChannelItemsRel> implements IKuaishouChannelItemsRelService {
 
+    @Autowired
+    KuaishouChannelItemsRelMapper channelItemsRelMapper;
+
+    @Override
+    public List<KuaishouChannelItems> queryItems(Long channelId) {
+        return channelItemsRelMapper.queryItems(channelId);
+    }
 }

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

@@ -5,7 +5,9 @@ import cn.com.ctop.common.module.utils.Check;
 import cn.com.ctop.common.module.utils.ExportExcelUtils;
 import cn.com.ctop.kuaishou.modules.ai.entity.KuaishouAppPackage;
 import cn.com.ctop.kuaishou.modules.channel.entity.KuaishouChannelItems;
+import cn.com.ctop.kuaishou.modules.channel.entity.KuaishouChannelItemsRel;
 import cn.com.ctop.kuaishou.modules.channel.mapper.KuaishouChannelItemsMapper;
+import cn.com.ctop.kuaishou.modules.channel.service.IKuaishouChannelItemsRelService;
 import cn.com.ctop.kuaishou.modules.channel.service.IKuaishouChannelItemsService;
 import com.alibaba.fastjson.JSONArray;
 import com.alibaba.fastjson.JSONObject;
@@ -51,6 +53,8 @@ public class KuaishouChannelItemsServiceImpl extends ServiceImpl<KuaishouChannel
     @Autowired
     private ProjectMapper projectMapper;
 
+    @Autowired
+    private IKuaishouChannelItemsRelService channelItemsRelService;
 
     @Override
     public Result<Object> queryChannelItemList(KuaishouChannelItems kuaishouChannelItems) {
@@ -99,10 +103,10 @@ 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);
-            KuaishouChannelItems item = new KuaishouChannelItems();
-            item.setId(object.getLong("id"));
-            item.setChannelCode(object.getString("channelCode"));
-            this.updateById(item);
+            KuaishouChannelItemsRel rel = new KuaishouChannelItemsRel();
+            rel.setItemId(object.getLong("id"));
+            rel.setChannelId(object.getLong("channelId"));
+            channelItemsRelService.save(rel);
         }
         return Result.ok("绑定成功");
     }
@@ -158,7 +162,7 @@ public class KuaishouChannelItemsServiceImpl extends ServiceImpl<KuaishouChannel
 
     @Override
     public List<KuaishouChannelItems> queryItemsByChannelCode(Long projectId, String channelCode) {
-        return channelItemsMapper.queryItemsByChannelCode(projectId,  channelCode);
+        return channelItemsMapper.queryItemsByChannelCode(projectId, channelCode);
     }
 
 

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

@@ -126,7 +126,7 @@ public class KuaishouChannelServiceImpl extends ServiceImpl<KuaishouChannelMappe
         PageHelper.startPage(pageNo, pageSize, false);
         List<KuaishouChannel> kuaishouChannels = channelMapper.channelNumberDetails(kuaishouChannel);
         for (KuaishouChannel channel : kuaishouChannels) {
-            List<KuaishouChannelItems> list = channelItemsService.queryItemsByChannelCode(channel.getProjectId(), channel.getChannelCode());
+            List<KuaishouChannelItems> list = channelItemsRelService.queryItems(channel.getId());
             channel.setItems(list);
         }
         PageInfo pageInfo = new PageInfo(kuaishouChannels);
@@ -858,10 +858,10 @@ public class KuaishouChannelServiceImpl extends ServiceImpl<KuaishouChannelMappe
 
         } else {
             /**============================项目范围============================*/
-            if ("account".equals(usageLevel)) {
-                //---------------------账户层级---------------------
-                return doProjectRangeAccountLevel(accountId, strategys);
-            } else if ("plan".equals(usageLevel) && usageLevel.equals(level)) {
+                if ("account".equals(usageLevel)) {
+                    //---------------------账户层级---------------------
+                    return doProjectRangeAccountLevel(accountId, strategys);
+                } else if ("plan".equals(usageLevel) && usageLevel.equals(level)) {
                 //---------------------计划层级---------------------
                 return doProjectRangePlanLevel(accountId, strategys);
             } else if ("group".equals(usageLevel)) {
@@ -874,6 +874,54 @@ public class KuaishouChannelServiceImpl extends ServiceImpl<KuaishouChannelMappe
 
     //通过账户范围计划层级查询
     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;
+                                }
+                            }
+                        }
+                    } else {
+
+                    }
+                }
+            if (flag) {
+                break;
+            }
+        }
+
+
         return Result.ok();
     }
 
@@ -889,7 +937,7 @@ public class KuaishouChannelServiceImpl extends ServiceImpl<KuaishouChannelMappe
         if (!Check.isNull(channelList)) {
             KuaishouChannel channel = channelList.get(0);
             KuaishouChannelRel channelRel = channelRelService.queryByAccountChannelCode(channel.getChannelCode(), channel.getAccountId());
-            if (Check.isNull(channelRel)) {
+            if (Check.isNull(channelRel)) {/////
                 return Result.error("未查询到渠道号");
             }
             if (Check.isNull(channelRel.getAppId())) {