Browse Source

实现接口获取我的下级渠道列表信息,支持翻页

Liugl 3 years ago
parent
commit
c428e4b549

+ 9 - 3
mp-admin/src/main/java/com/qs/mp/web/controller/api/channel/ChannelController.java

@@ -18,6 +18,7 @@ import io.swagger.annotations.Api;
 import io.swagger.annotations.ApiOperation;
 import ma.glasnost.orika.MapperFacade;
 
+import java.util.ArrayList;
 import java.util.Date;
 import java.util.List;
 
@@ -59,8 +60,14 @@ public class ChannelController extends BaseApiController {
 	 */
 	@PostMapping("subchannel/list")
 	public TableDataInfo list(@RequestBody Channel channel) {
-		startPage();
-		List<Channel> list = channelService.list(new LambdaQueryWrapper<Channel>());
+		Long channelId = SecurityUtils.getLoginUser().getChannelId();
+		List<ChannelVO> list = new ArrayList<ChannelVO>();
+		if(null != channelId) {
+			channel.setParentId(channelId);
+			startPage();
+			// List<Channel> list = channelService.list(new LambdaQueryWrapper<Channel>());
+			list = channelService.selectChannelVoList(channel);
+		}
 		return getDataTable(list);
 	}
 
@@ -75,7 +82,6 @@ public class ChannelController extends BaseApiController {
 		if (null == channel || null == channel.getChannelId()) {
 			return error(ErrorCodeEnum.ERROR_CODE_1001);
 		}
-
 		Long channelId = channel.getChannelId();
 		ChannelVO channelVO = new ChannelVO();
 		Channel queryChannel = channelService.getById(channelId);

+ 2 - 0
mp-service/src/main/java/com/qs/mp/channel/domain/vo/ChannelVO.java

@@ -13,4 +13,6 @@ public class ChannelVO extends Channel {
   long userCnt; // 经销用户数
 
   String parentName; // 上级渠道名称
+  
+  ChannelOperDataVO operData;
 }

+ 31 - 0
mp-service/src/main/java/com/qs/mp/channel/mapper/ChannelMapper.java

@@ -1,7 +1,15 @@
 package com.qs.mp.channel.mapper;
 
 import com.qs.mp.channel.domain.Channel;
+import com.qs.mp.channel.domain.vo.ChannelVO;
+
+import java.util.List;
+
+import org.apache.ibatis.annotations.Param;
+
+import com.baomidou.mybatisplus.core.conditions.Wrapper;
 import com.baomidou.mybatisplus.core.mapper.BaseMapper;
+import com.baomidou.mybatisplus.core.toolkit.Constants;
 
 /**
  * @auther quanshu
@@ -10,4 +18,27 @@ import com.baomidou.mybatisplus.core.mapper.BaseMapper;
  */
 public interface ChannelMapper extends BaseMapper<Channel> {
 
+	/**
+	 * 获取我的下级渠道列表信息,支持翻页
+	 * 
+	 * @param channel
+	 * @return
+	 */
+	public List<ChannelVO> selectChannelVoList(@Param(Constants.WRAPPER) Wrapper<Channel> wrapper);
+	
+	/**
+	 * 获取我的经销商列表信息,支持翻页
+	 * 
+	 * @param channel
+	 * @return
+	 */
+	public List<ChannelVO> selectSiteVoList(@Param(Constants.WRAPPER) Wrapper<Channel> wrapper);
+	
+	
+    /**
+     * 查询渠道及其子渠道经销商总数
+     * @param channelNo
+     * @return
+     */
+    int getChannelSiteCnt(@Param("channelNo") String channelNo);
 }

+ 9 - 0
mp-service/src/main/java/com/qs/mp/channel/mapper/ChannelUserRelMapper.java

@@ -1,6 +1,9 @@
 package com.qs.mp.channel.mapper;
 
 import com.qs.mp.channel.domain.ChannelUserRel;
+
+import org.apache.ibatis.annotations.Param;
+
 import com.baomidou.mybatisplus.core.mapper.BaseMapper;
 
 /**
@@ -10,4 +13,10 @@ import com.baomidou.mybatisplus.core.mapper.BaseMapper;
  */
 public interface ChannelUserRelMapper extends BaseMapper<ChannelUserRel> {
 
+    /**
+     * 查询渠道及其子渠道经销商用户数总和
+     * @param channelNo
+     * @return
+     */
+    int getChannelUserCnt(@Param("channelNo") String channelNo);
 }

+ 1 - 9
mp-service/src/main/java/com/qs/mp/channel/service/IChannelService.java

@@ -42,15 +42,7 @@ public interface IChannelService extends IService<Channel> {
 	 * @param channel
 	 * @return
 	 */
-	public List<ChannelVO> selectVoList(Channel channel);
-	
-	/**
-	 * 获取指定渠道信息
-	 * 
-	 * @param channel
-	 * @return
-	 */
-	public ChannelVO getVoById(Long channelId);
+	public List<ChannelVO> selectChannelVoList(Channel channel);
 
 	/**
 	 * 根据用户ID查询渠道

+ 16 - 11
mp-service/src/main/java/com/qs/mp/channel/service/impl/ChannelServiceImpl.java

@@ -1,6 +1,7 @@
 package com.qs.mp.channel.service.impl;
 
 import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
+import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
 import com.qs.mp.channel.domain.Channel;
 import com.qs.mp.channel.domain.vo.ChannelVO;
 import com.qs.mp.channel.mapper.ChannelMapper;
@@ -41,7 +42,11 @@ public class ChannelServiceImpl extends ServiceImpl<ChannelMapper, Channel> impl
 	public void saveChannel(Channel channel) throws Exception {
 		// 1、校验名称是否重复、手机号是否存在(渠道表)
 		
-
+		// 2.校验佣金比例,不能高于其父渠道的佣金比例
+		
+		// 3.插入数据
+		
+		// 4.发送账号创建成功短信
 	}
 	
 
@@ -49,19 +54,19 @@ public class ChannelServiceImpl extends ServiceImpl<ChannelMapper, Channel> impl
 	public void updateChannel(Channel channel) throws Exception {
 		// 1、校验修改子渠道是否为当前用户的子渠道
 		Long channelId = SecurityUtils.getLoginUser().getChannelId();
-
-	}
-
-	@Override
-	public List<ChannelVO> selectVoList(Channel channel) {
-
-		return null;
+		
+		// 2.校验名称是否重复、手机号是否存在(渠道表);
+		
+		// 3.校验佣金比例,不能高于其父渠道的佣金比例,不能低于其子渠道的最大佣金比例
+		
+	    // 4.更新入库
 	}
 
 	@Override
-	public ChannelVO getVoById(Long channelId) {
-		// TODO Auto-generated method stub
-		return null;
+	public List<ChannelVO> selectChannelVoList(Channel channel) {
+		QueryWrapper<Channel> queryWrapper = new QueryWrapper<>();
+		queryWrapper.eq("t1.parent_id", channel.getParentId());
+		return getBaseMapper().selectChannelVoList(queryWrapper);
 	}
 
 	@Override

+ 53 - 0
mp-service/src/main/resources/mapper/channel/ChannelMapper.xml

@@ -31,10 +31,63 @@
         <result column="created_time" property="createdTime" />
         <result column="updated_time" property="updatedTime" />
     </resultMap>
+    
+    <!-- 通用查询VO映射结果 -->
+    <resultMap id="VoResultMap" type="com.qs.mp.channel.domain.vo.ChannelVo">
+        <id column="channel_id" property="channelId" />
+        <result column="channel_no" property="channelNo" />
+        <result column="name" property="name" />
+        <result column="parent_id" property="parentId" />
+        <result column="level" property="level" />
+        <result column="site_type" property="siteType" />
+        <result column="comm_rate" property="commRate" />
+        <result column="province" property="province" />
+        <result column="province_id" property="provinceId" />
+        <result column="city" property="city" />
+        <result column="city_id" property="cityId" />
+        <result column="area" property="area" />
+        <result column="area_id" property="areaId" />
+        <result column="address" property="address" />
+        <result column="contact" property="contact" />
+        <result column="mobile" property="mobile" />
+        <result column="user_id" property="userId" />
+        <result column="money" property="money" />
+        <result column="frozen_money" property="frozenMoney" />
+        <result column="certify_status" property="certifyStatus" />
+        <result column="verify_status" property="verifyStatus" />
+        <result column="biz_license" property="bizLicense" />
+        <result column="door_pic" property="doorPic" />
+        <result column="memo" property="memo" />
+        <result column="created_time" property="createdTime" />
+        <result column="updated_time" property="updatedTime" />
+        <result column="parentName" property="parentName" />
+        <association property="siteCnt" javaType="java.lang.Integer" select="getChannelSiteCnt" column="{channelNo=channelNo}" />
+        <association property="userCnt" javaType="java.lang.Integer" select="com.qs.mp.channel.mapper.ChannelUserRelMapper.getChannelUserCnt" column="{channelNo=channelNo}" /> 
+    </resultMap>
 
     <!-- 通用查询结果列 -->
     <sql id="Base_Column_List">
         channel_id, channel_no, name, parent_id, level, site_type, comm_rate, province, province_id, city, city_id, area, area_id, address, contact, mobile, user_id, money, frozen_money, certify_status, verify_status, biz_license, door_pic, memo, created_time, updated_time
     </sql>
+    
+    <!-- 查询子渠道信息 -->
+    <select id="selectChannelVoList" resultMap="VoResultMap">
+		select t1.* , t2.siteCnt, t3.userCnt, t4.name parentName
+		from mp_channel t1
+		left join (select parent_id, count(*) as siteCnt from mp_channel where `level` = 0 GROUP BY parent_id ) t2 on t1.channel_id = t2.parent_id 
+		left join (select channel_id, count(user_id) as userCnt from mp_channel_user_rel GROUP BY channel_id ) t3 on t1.channel_id = t3.channel_id
+		left join mp_channel t4 on t1.parent_id = t4.channel_id
+		${ew.customSqlSegment}
+		order by a.channel_id desc
+	</select>
+	
+	<!-- 查询渠道及其子渠道经销商用户数总和 -->
+    <select id="getChannelSiteCnt" resultType="integer">
+        select count(t1.channel_id) as siteCnt
+		from mp_channel t1
+		left join mp_channel t2 on t1.parent_id = t2.channel_id
+		where t1.`level`= 0 and t1.certify_status = 'y'
+		and t2.channel_no like concat(#{channelNo}, '%')
+    </select>
 
 </mapper>

+ 10 - 0
mp-service/src/main/resources/mapper/channel/ChannelUserRelMapper.xml

@@ -16,5 +16,15 @@
     <sql id="Base_Column_List">
         id, channel_id, channel_no, user_id, created_time, updated_time
     </sql>
+    
+    <!-- 查询渠道及其子渠道经销商用户数总和 -->
+    <select id="getChannelUserCnt" resultType="integer">
+        select count(t1.user_id) as userCnt 
+		from mp_channel_user_rel t1
+		left join mp_channel t2 on t1.channel_id = t2.channel_id
+		where t2.channel_no like concat(#{channelNo}, '%')
+    </select>
+    
+    
 
 </mapper>