Forráskód Böngészése

Merge branch 'dev' into 'mp-server-test'

经销商渠道统计数据查询优化

See merge request quanshu/mp-server!337
zhong chunping 3 éve
szülő
commit
fdb8fef814

+ 2 - 1
mp-admin/src/main/java/com/qs/mp/web/controller/api/admin/ChannelMgrController.java

@@ -129,7 +129,7 @@ public class ChannelMgrController extends BaseApiController {
 	 */
 	@PostMapping("/list")
 	@PreAuthorize("@ss.hasPermi('business:channel:list')")
-	public TableDataInfo listChannel(@RequestBody Channel channel) {
+	public TableDataInfo listChannel(@RequestBody ChannelVO channel) {
 		List<ChannelVO> list = new ArrayList<ChannelVO>();
 		startPage();
 		QueryWrapper<Channel> queryWrapper = new QueryWrapper<>();
@@ -140,6 +140,7 @@ public class ChannelMgrController extends BaseApiController {
 		queryWrapper.eq(null != channel && null != channel.getLevel(),"t1.level", channel.getLevel());
 		queryWrapper.likeRight(null != channel && StringUtils.isNotBlank(channel.getMobile()), "t1.mobile", channel.getMobile());
 		queryWrapper.likeRight(null != channel && StringUtils.isNotBlank(channel.getName()), "t1.name", channel.getName());
+		queryWrapper.likeRight(null != channel && StringUtils.isNotBlank(channel.getParentName()), "t2.name", channel.getParentName());
 		queryWrapper.eq(null != channel && null != channel.getProvinceId(), "t1.province_id", channel.getProvinceId());
 		queryWrapper.eq(null != channel && null != channel.getCityId(), "t1.city_id", channel.getCityId());
 		queryWrapper.eq(null != channel && null != channel.getAreaId(), "t1.area_id", channel.getAreaId());

+ 30 - 5
mp-admin/src/main/java/com/qs/mp/web/controller/api/admin/SaleSiteMgrController.java

@@ -7,6 +7,7 @@ import com.qs.mp.admin.domain.vo.TicketCntVO;
 import com.qs.mp.admin.service.ITicketService;
 import com.qs.mp.channel.domain.Channel;
 import com.qs.mp.channel.domain.ChannelOrder;
+import com.qs.mp.channel.domain.ChannelOrderDetail;
 import com.qs.mp.channel.domain.ChannelUserRel;
 import com.qs.mp.channel.domain.param.ChannelParam;
 import com.qs.mp.channel.domain.param.SaleSiteParam;
@@ -97,9 +98,26 @@ public class SaleSiteMgrController extends BaseApiController {
 		queryWrapper.eq(null != channel && null != channel.getAreaId(), "t1.area_id", channel.getAreaId());
 		queryWrapper.orderByDesc("t1.channel_id");
 		list = channelService.selectChannelVoList(queryWrapper);
+		List<Long> channelIds = new ArrayList<Long>();
 		if(null != list && list.size() > 0) {
 			for(ChannelVO channelVO : list) {
-				if(null != channelVO && StringUtils.isNotBlank(channelVO.getChannelNo())) {
+				if(null != channelVO && null != channelVO.getChannelId()
+						&& StringUtils.isNotBlank(channelVO.getChannelNo())) {
+					channelIds.add(channelVO.getChannelId());
+ 				}
+			}
+		}
+		List<TicketCntVO>  cntList = new ArrayList<TicketCntVO>();
+		if(null != channelIds && channelIds.size() > 0) {
+			QueryWrapper<ChannelOrderDetail> ticketCntQueryWrapper = new QueryWrapper<ChannelOrderDetail>();
+			ticketCntQueryWrapper.in("t1.channel_id", channelIds);
+			cntList = ticketService.listTicketCnt(ticketCntQueryWrapper);
+		}
+		
+		if(null != list && list.size() > 0) {
+			for(ChannelVO channelVO : list) {
+				if(null != channelVO && null != channelVO.getChannelId()
+						&& StringUtils.isNotBlank(channelVO.getChannelNo())) {
 					// int siteCnt = channelService.getChannelSiteCnt(channelVO.getChannelNo());
 					LambdaQueryWrapper<ChannelUserRel> userCntQueryWrapper = new LambdaQueryWrapper<ChannelUserRel>();
 					userCntQueryWrapper.eq(ChannelUserRel::getChannelId, channelVO.getChannelId());
@@ -110,10 +128,16 @@ public class SaleSiteMgrController extends BaseApiController {
 					// channelVO.setSysUser(sysUser);
 					channelVO.setParentsName(getParentsName(channelVO.getChannelNo()));
 					// 统计盲票库存, 销量
-					TicketCntVO ticketCnt = ticketService.getTicketCnt(channelVO.getChannelId());
-					channelVO.setOffLineQtyCnt(null != ticketCnt?ticketCnt.getOffLineQtyCnt():0);
-					channelVO.setOffLineSaleCnt(null != ticketCnt?ticketCnt.getOffLineSaleCnt():0);
-					channelVO.setOnLineSaleCnt(null != ticketCnt?ticketCnt.getOnLineSaleCnt():0);
+					if(null != cntList && cntList.size() > 0) {
+						List<TicketCntVO> voList =  cntList.stream().filter(item  -> item.getChannelId().equals(channelVO.getChannelId()))
+				                .collect(Collectors.toList());
+						if(null != voList && voList.size() > 0) {
+							TicketCntVO ticketCnt =  voList.get(0);
+							channelVO.setOffLineQtyCnt(null != ticketCnt?ticketCnt.getOffLineQtyCnt():0);
+							channelVO.setOffLineSaleCnt(null != ticketCnt?ticketCnt.getOffLineSaleCnt():0);
+							channelVO.setOnLineSaleCnt(null != ticketCnt?ticketCnt.getOnLineSaleCnt():0);
+						}
+					}
  				}
 			}
 		}
@@ -326,6 +350,7 @@ public class SaleSiteMgrController extends BaseApiController {
 			userCntQueryWrapper.eq(ChannelUserRel::getChannelId, channelVO.getChannelId());
 			int userCnt = channelUserRelService.count(userCntQueryWrapper);
 			channelVO.setUserCnt(userCnt);
+			channelVO.setParentsName(getParentsName(channelVO.getChannelNo()));
 		}
 	    // 查询经销商销售额、佣金收入、订单数等
 	    ChannelOperDataVO channelOperDataVO = channelService.getChannelTotalOperData(channelVO.getChannelNo());

+ 2 - 0
mp-service/src/main/java/com/qs/mp/admin/domain/vo/TicketCntVO.java

@@ -9,6 +9,8 @@ import lombok.Data;
 @Data
 public class TicketCntVO {
 
+	// 渠道ID
+	Long channelId;
 	// 线下库存(盲票张数)
 	long offLineQtyCnt; // 线下库存(盲票张数)
 	

+ 8 - 0
mp-service/src/main/java/com/qs/mp/admin/mapper/TicketMapper.java

@@ -5,6 +5,7 @@ import com.baomidou.mybatisplus.core.toolkit.Constants;
 import com.qs.mp.admin.domain.Ticket;
 import com.baomidou.mybatisplus.core.mapper.BaseMapper;
 import com.qs.mp.admin.domain.vo.TicketCntVO;
+import com.qs.mp.channel.domain.ChannelOrderDetail;
 
 import java.util.List;
 import org.apache.ibatis.annotations.Param;
@@ -25,4 +26,11 @@ public interface TicketMapper extends BaseMapper<Ticket> {
    * @return
    */
   TicketCntVO getTicketCnt(@Param("channelId") Long channelId);
+  
+  /**
+   * 查询统计数据
+   * @param queryWrapper
+   * @return
+   */
+  List<TicketCntVO> listTicketCnt(@Param(Constants.WRAPPER) Wrapper<ChannelOrderDetail> queryWrapper);
 }

+ 8 - 0
mp-service/src/main/java/com/qs/mp/admin/service/ITicketService.java

@@ -4,6 +4,7 @@ import com.baomidou.mybatisplus.core.conditions.Wrapper;
 import com.qs.mp.admin.domain.Ticket;
 import com.qs.mp.admin.domain.excel.TicketExcel;
 import com.qs.mp.admin.domain.vo.TicketCntVO;
+import com.qs.mp.channel.domain.ChannelOrderDetail;
 import com.baomidou.mybatisplus.extension.service.IService;
 
 import java.util.List;
@@ -49,4 +50,11 @@ public interface ITicketService extends IService<Ticket> {
    * @return
    */
   TicketCntVO getTicketCnt(Long channelId);
+  
+  /**
+   * 查询统计数据
+   * @param queryWrapper
+   * @return
+   */
+  List<TicketCntVO> listTicketCnt(Wrapper<ChannelOrderDetail> queryWrapper);
 }

+ 6 - 1
mp-service/src/main/java/com/qs/mp/admin/service/impl/TicketServiceImpl.java

@@ -7,6 +7,7 @@ import com.qs.mp.admin.domain.excel.TicketExcel;
 import com.qs.mp.admin.domain.vo.TicketCntVO;
 import com.qs.mp.admin.mapper.TicketMapper;
 import com.qs.mp.admin.service.ITicketService;
+import com.qs.mp.channel.domain.ChannelOrderDetail;
 import com.qs.mp.common.exception.ServiceException;
 import com.qs.mp.common.utils.RSAUtil;
 import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
@@ -82,6 +83,10 @@ public class TicketServiceImpl extends ServiceImpl<TicketMapper, Ticket> impleme
 	public TicketCntVO getTicketCnt(Long channelId) {
 		return getBaseMapper().getTicketCnt(channelId);
 	}
-	
+
+	@Override
+	public List<TicketCntVO> listTicketCnt(Wrapper<ChannelOrderDetail> queryWrapper) {
+		return getBaseMapper().listTicketCnt(queryWrapper);
+	}
 	
 }

+ 3 - 0
mp-service/src/main/java/com/qs/mp/channel/service/IChannelOrderService.java

@@ -1,6 +1,8 @@
 package com.qs.mp.channel.service;
 
+import com.qs.mp.admin.domain.vo.TicketCntVO;
 import com.qs.mp.channel.domain.ChannelOrder;
+import com.qs.mp.channel.domain.ChannelOrderDetail;
 
 import java.util.List;
 
@@ -62,4 +64,5 @@ public interface IChannelOrderService extends IService<ChannelOrder> {
 	 * @return
 	 */
 	public List<ChannelOrderVO> selectChannelOrderVoList(Wrapper<ChannelOrder> wrapper);
+	
 }

+ 13 - 0
mp-service/src/main/resources/mapper/admin/TicketMapper.xml

@@ -54,4 +54,17 @@
 		left join mp_ticket_box t3 on t2.box_id = t3.box_id
 		where t1.channel_id = #{channelId};
     </select>
+    
+     <select id="listTicketCnt" resultType="com.qs.mp.admin.domain.vo.TicketCntVO">
+       select
+         t1.channel_id channelId,
+		 SUM( CASE WHEN (t2.`status` != 1 and t3.type = 'online') THEN 1 ELSE 0 END ) AS onLineSaleCnt,
+		 SUM( CASE WHEN (t2.`status` != 1 and t3.type = 'offline') THEN 1 ELSE 0 END ) AS offLineSaleCnt,
+		 SUM( CASE WHEN (t2.`status` = 1 and t3.type = 'offline') THEN 1 ELSE 0 END ) AS offLineQtyCnt
+		from mp_channel_order_detail t1
+		left join mp_ticket t2 on t1.pkg_id = t2.pkg_id
+		left join mp_ticket_box t3 on t2.box_id = t3.box_id
+		${ew.customSqlSegment}
+		GROUP BY t1.channel_id
+    </select>
 </mapper>