Browse Source

修复v1.1.0相关导出bug

zhangxin 3 tuần trước cách đây
mục cha
commit
97db53f581

+ 5 - 0
yami-shop-bean/src/main/java/com/yami/shop/bean/param/BackendOrderParam.java

@@ -77,6 +77,11 @@ public class BackendOrderParam {
      */
     private Integer refundStatus;
 
+    /**
+     * 订单退款状态参考refundStatus(配送类型 1:快递 2:自提 3:及时配送)
+     */
+    private String dvyType;
+
     /**
      * 企业ID列表
      */

+ 5 - 0
yami-shop-bean/src/main/java/com/yami/shop/bean/param/OrderRefundStaisticsParam.java

@@ -59,6 +59,11 @@ public class OrderRefundStaisticsParam {
     @ApiModelProperty("退款单状态 10:待审核 20:处理中 30:驳回退款 40:撤销退款 60:待退货(一审同意) 65:待确认收货(二审待审核) 70:退款完成")
     private Integer returnMoneySts;
 
+    /**
+     * 订单退款状态参考refundStatus(配送类型 1:快递 2:自提 3:及时配送)
+     */
+    private String dvyType;
+
     /**
      * 企业ID列表
      */

+ 8 - 1
yami-shop-platform/src/main/java/com/yami/shop/platform/controller/ChannelController.java

@@ -5,6 +5,7 @@ package com.yami.shop.platform.controller;
 import com.baomidou.mybatisplus.core.metadata.IPage;
 import com.yami.shop.bean.model.Channel;
 import com.yami.shop.bean.vo.ChannelVO;
+import com.yami.shop.common.config.Constant;
 import com.yami.shop.common.util.PageParam;
 import com.yami.shop.common.util.R;
 import com.yami.shop.security.platform.util.SecurityUtils;
@@ -103,7 +104,13 @@ public class ChannelController {
     @ApiOperation(value = "查询全部")
     public R<List<Channel>> listByUserId() {
         Long userId = SecurityUtils.getSysUser().getUserId();
-        List<Channel> channels = sysUserService.findByUserId(userId);
+        List<Channel> channels = null;
+        if(userId == Constant.SUPER_ADMIN_ID){
+            channels = channelService.list();
+        }else {
+            channels = sysUserService.findByUserId(userId);
+        }
+
         return R.SUCCESS(channels);
     }
 }

+ 2 - 2
yami-shop-platform/src/main/java/com/yami/shop/platform/controller/OrderController.java

@@ -84,8 +84,8 @@ public class OrderController {
 
     @GetMapping("/deliverListStatusNum")
     @ApiOperation("后管端-快递订单列表-订单状态数量")
-    public R<Map<String, Integer>> deliverListStatusNum() {
-        return R.SUCCESS(orderService.deliverListStatusNum());
+    public R<Map<String, Integer>> deliverListStatusNum(BackendOrderParam orderParam) {
+        return R.SUCCESS(orderService.deliverListStatusNum(orderParam));
     }
 
     /**

+ 1 - 1
yami-shop-service/src/main/java/com/yami/shop/dao/OrderMapper.java

@@ -128,7 +128,7 @@ public interface OrderMapper extends BaseMapper<Order> {
 
     void updateByToPaySuccessDelivery(@Param("orderNumbers") List<String> orderNumbers, @Param("payType") Integer payType);
 
-    Integer statusCount(@Param("status") List<Integer> status);
+    Integer statusCount(@Param("status") List<Integer> status, @Param("orderParam")BackendOrderParam orderParam);
 
     /**
      * 统计订单数量

+ 1 - 1
yami-shop-service/src/main/java/com/yami/shop/service/OrderService.java

@@ -158,7 +158,7 @@ public interface OrderService extends IService<Order> {
      */
     OrderRefundAmountDTO computeOrderRefundAmount(String orderNumber, List<OrderRefundAmountParam> suk);
 
-    Map<String,Integer> deliverListStatusNum();
+    Map<String,Integer> deliverListStatusNum(BackendOrderParam orderParam);
 
     /**
      * 订单统计数据

+ 23 - 10
yami-shop-service/src/main/java/com/yami/shop/service/impl/OrderServiceImpl.java

@@ -63,6 +63,8 @@ import org.apache.commons.lang3.ObjectUtils;
 import org.apache.commons.lang3.StringUtils;
 import org.apache.poi.ss.usermodel.*;
 import org.apache.poi.ss.util.CellRangeAddress;
+import org.apache.poi.xssf.streaming.SXSSFSheet;
+import org.apache.poi.xssf.streaming.SXSSFWorkbook;
 import org.apache.poi.xssf.usermodel.XSSFWorkbook;
 import org.springframework.beans.BeanUtils;
 import org.springframework.cache.annotation.CacheEvict;
@@ -349,6 +351,7 @@ public class OrderServiceImpl extends ServiceImpl<OrderMapper, Order> implements
 
     @Override
     public IPage<Order> deliverList(PageParam<Order> page, BackendOrderParam orderParam) {
+
         List<Order> orderList = orderMapper.deliverList(new PageAdapter(page), orderParam);
         if (!orderList.isEmpty()) {
             orderList.forEach(c -> {
@@ -1325,14 +1328,14 @@ public class OrderServiceImpl extends ServiceImpl<OrderMapper, Order> implements
     }
 
     @Override
-    public Map<String, Integer> deliverListStatusNum() {
+    public Map<String, Integer> deliverListStatusNum(BackendOrderParam orderParam) {
         Map<String, Integer> map = new LinkedTreeMap<>();
-        map.put("all", orderMapper.statusCount(Lists.newArrayList(0, 1, 20, 30, 40, 50, 60, 70, 80)));
-        map.put("paddingPay", orderMapper.statusCount(Lists.newArrayList(0)));
-        map.put("paddingShipped", orderMapper.statusCount(Lists.newArrayList(1)));
-        map.put("paddingReceived", orderMapper.statusCount(Lists.newArrayList(20, 30, 40, 70)));
-        map.put("completed", orderMapper.statusCount(Lists.newArrayList(80)));
-        map.put("cancel", orderMapper.statusCount(Lists.newArrayList(60,50)));
+        map.put("all", orderMapper.statusCount(Lists.newArrayList(0, 1, 20, 30, 40, 50, 60, 70, 80),orderParam));
+        map.put("paddingPay", orderMapper.statusCount(Lists.newArrayList(0),orderParam));
+        map.put("paddingShipped", orderMapper.statusCount(Lists.newArrayList(1),orderParam));
+        map.put("paddingReceived", orderMapper.statusCount(Lists.newArrayList(20, 30, 40, 70),orderParam));
+        map.put("completed", orderMapper.statusCount(Lists.newArrayList(80),orderParam));
+        map.put("cancel", orderMapper.statusCount(Lists.newArrayList(60,50),orderParam));
         return map;
     }
 
@@ -1391,7 +1394,7 @@ public class OrderServiceImpl extends ServiceImpl<OrderMapper, Order> implements
         // 设置响应头
         ExportUtils.setupResponse(response, fileName);
 
-        try (Workbook workbook = new XSSFWorkbook()) {
+        try (SXSSFWorkbook workbook = new SXSSFWorkbook(100)) {
             // 创建Sheet
             Sheet sheet = workbook.createSheet("正常订单");
 
@@ -1424,8 +1427,8 @@ public class OrderServiceImpl extends ServiceImpl<OrderMapper, Order> implements
 
             // 写入响应流
             workbook.write(response.getOutputStream());
-            response.getOutputStream().flush();
-
+//            response.getOutputStream().flush();
+            workbook.dispose(); // 清理临时文件
             log.info("订单导出成功,文件:{},记录数:{}", fileName, orderList.size());
 
         } catch (Exception e) {
@@ -1474,7 +1477,17 @@ public class OrderServiceImpl extends ServiceImpl<OrderMapper, Order> implements
             ExportUtils.createCell(sheet,row, 0,order.getOrderItems().size(),rowNum, indexNum, dataStyle);
             fillOrderRowData(sheet,rowNum,row, order, dataStyle, numberStyle, dateStyle);
             rowNum+=order.getOrderItems().size()-1;
+            // 每100行手动刷新一次
+            if ((indexNum+1) % 100 == 0) {
+                try {
+                    ((SXSSFSheet) sheet).flushRows(100);
+                } catch (IOException e) {
+                    log.error("订单导出失败", e);
+                    throw new RuntimeException("导出失败:" + e.getMessage());
+                }
+            }
             indexNum++;
+
         }
 
     }

+ 79 - 7
yami-shop-service/src/main/resources/mapper/OrderMapper.xml

@@ -488,12 +488,15 @@
             <if test="orderParam.orderNumber != null and orderParam.orderNumber != ''">
                 and a.order_number = #{orderParam.orderNumber}
             </if>
-            <if test="orderParam.channelIdList != null and orderParam.channelIdList != ''">
+            <if test="orderParam.channelIdList != null and !orderParam.channelIdList.isEmpty()">
                 and a.channel_id  in
                 <foreach collection="orderParam.channelIdList" item="channelId" open="(" close=")" separator=",">
                     #{channelId}
                 </foreach>
             </if>
+            <if test="orderParam.dvyType != null and orderParam.dvyType != ''">
+                and a.dvy_type = #{orderParam.dvyType}
+            </if>
             <if test="orderParam.shopId != null">
                 and a.shop_id = #{orderParam.shopId}
             </if>
@@ -512,7 +515,6 @@
             <if test="orderParam.userMobile != null">
                 and b.mobile LIKE concat("%",#{orderParam.userMobile},"%")
             </if>
-
             <if test="orderParam.orderStatus != null and orderParam.orderStatus != ''">
                 <if test="orderParam.orderStatus == 'all'">
                     AND a.hb_order_status in (0, 1,20,30,40,50,60,70,80)
@@ -548,6 +550,15 @@
             <if test="orderParam.orderNumber != null and orderParam.orderNumber != ''">
                 and a.order_number = #{orderParam.orderNumber}
             </if>
+            <if test="orderParam.channelIdList != null and !orderParam.channelIdList.isEmpty()">
+                and a.channel_id  in
+                <foreach collection="orderParam.channelIdList" item="channelId" open="(" close=")" separator=",">
+                    #{channelId}
+                </foreach>
+            </if>
+            <if test="orderParam.dvyType != null and orderParam.dvyType != ''">
+                and a.dvy_type = #{orderParam.dvyType}
+            </if>
             <if test="orderParam.shopId != null">
                 and a.shop_id = #{orderParam.shopId}
             </if>
@@ -995,10 +1006,68 @@
     </select>
 
     <select id="statusCount" resultType="integer">
-        SELECT count(1) FROM `tz_order` WHERE hb_order_status in
-        <foreach collection="status" item="status" separator="," open="(" close=")">
-            #{status}
-        </foreach>
+        SELECT count(a.order_id) FROM `tz_order` a
+        LEFT JOIN tz_user_addr_order b on a.addr_order_id=b.addr_order_id
+        LEFT JOIN tz_shop_detail c on a.shop_id=c.shop_id
+        <where>
+            hb_order_status in
+            <foreach collection="status" item="status" separator="," open="(" close=")">
+                #{status}
+            </foreach>
+            <if test="orderParam.orderNumber != null and orderParam.orderNumber != ''">
+                and a.order_number = #{orderParam.orderNumber}
+            </if>
+            <if test="orderParam.channelIdList != null and !orderParam.channelIdList.isEmpty()">
+                and a.channel_id  in
+                <foreach collection="orderParam.channelIdList" item="channelId" open="(" close=")" separator=",">
+                    #{channelId}
+                </foreach>
+            </if>
+            <if test="orderParam.dvyType != null and orderParam.dvyType != ''">
+                and a.dvy_type = #{orderParam.dvyType}
+            </if>
+            <if test="orderParam.shopId != null">
+                and a.shop_id = #{orderParam.shopId}
+            </if>
+            <if test="orderParam.startTime != null">
+                and a.create_time &gt; #{orderParam.startTime}
+            </if>
+            <if test="orderParam.endTime != null">
+                and a.create_time &lt; #{orderParam.endTime}
+            </if>
+            <if test="orderParam.refundStatus != null and orderParam.refundStatus != 0">
+                and a.refund_status = #{orderParam.refundStatus}
+            </if>
+            <if test="orderParam.receiver != null">
+                and b.receiver LIKE concat("%",#{orderParam.receiver},"%")
+            </if>
+            <if test="orderParam.userMobile != null">
+                and b.mobile LIKE concat("%",#{orderParam.userMobile},"%")
+            </if>
+
+            <if test="orderParam.orderStatus != null and orderParam.orderStatus != ''">
+                <if test="orderParam.orderStatus == 'all'">
+                    AND a.hb_order_status in (0, 1,20,30,40,50,60,70,80)
+                </if>
+                <if test="orderParam.orderStatus == 'paddingPay'">
+                    AND a.hb_order_status in (0)
+                </if>
+
+                <if test="orderParam.orderStatus == 'paddingShipped'">
+                    AND a.hb_order_status in (1)
+                </if>
+
+                <if test="orderParam.orderStatus == 'paddingReceived'">
+                    AND a.hb_order_status in (20,30,40,70)
+                </if>
+                <if test="orderParam.orderStatus == 'completed'">
+                    AND a.hb_order_status in (80)
+                </if>
+                <if test="orderParam.orderStatus == 'cancel'">
+                    AND a.hb_order_status in (50,60)
+                </if>
+            </if>
+        </where>
     </select>
     <select id="selectOrderCount" resultType="com.yami.shop.bean.param.OrderCountParam">
         SELECT
@@ -1104,12 +1173,15 @@
             <if test="orderParam.orderNumber != null and orderParam.orderNumber != ''">
                 and a.order_number = #{orderParam.orderNumber}
             </if>
-            <if test="orderParam.channelIdList != null and orderParam.channelIdList != ''">
+            <if test="orderParam.channelIdList != null and !orderParam.channelIdList.isEmpty()">
                 and a.channel_id  in
                 <foreach collection="orderParam.channelIdList" item="channelId" open="(" close=")" separator=",">
                     #{channelId}
                 </foreach>
             </if>
+            <if test="orderParam.dvyType != null and orderParam.dvyType != ''">
+                and a.dvy_type = #{orderParam.dvyType}
+            </if>
             <if test="orderParam.shopId != null">
                 and a.shop_id = #{orderParam.shopId}
             </if>

+ 33 - 17
yami-shop-service/src/main/resources/mapper/OrderRefundMapper.xml

@@ -439,35 +439,45 @@
 
     <select id="orderRefundCount" resultType="com.yami.shop.bean.param.OrderRefundCountParam">
         SELECT
-        COUNT(return_money_sts) AS allCount,
-        COUNT(CASE WHEN return_money_sts = 10 THEN 1 END) AS sellerApplyCount,
-        COUNT(CASE WHEN return_money_sts = 30 THEN 1 END) AS sellerRejectCount,
-        COUNT(CASE WHEN return_money_sts = 40 THEN 1 END) AS withdrawApplyCount,
-        COUNT(CASE WHEN return_money_sts = 60 THEN 1 END) AS sellerAcceptCount,
-        COUNT(CASE WHEN return_money_sts = 65 THEN 1 END) AS buyerDeliveryCount,
-        COUNT(CASE WHEN return_money_sts = 70 THEN 1 END) AS refundCompleteCount
-        FROM tz_order_refund
+        COUNT(re.return_money_sts) AS allCount,
+        COUNT(CASE WHEN re.return_money_sts = 10 THEN 1 END) AS sellerApplyCount,
+        COUNT(CASE WHEN re.return_money_sts = 30 THEN 1 END) AS sellerRejectCount,
+        COUNT(CASE WHEN re.return_money_sts = 40 THEN 1 END) AS withdrawApplyCount,
+        COUNT(CASE WHEN re.return_money_sts = 60 THEN 1 END) AS sellerAcceptCount,
+        COUNT(CASE WHEN re.return_money_sts = 65 THEN 1 END) AS buyerDeliveryCount,
+        COUNT(CASE WHEN re.return_money_sts = 70 THEN 1 END) AS refundCompleteCount
+        FROM tz_order_refund re
+        left join tz_order o on refund.order_id = o.order_id
         <where>
             <if test="orderRefund.orderNumber != null">
-                and order_number = #{orderRefund.orderNumber}
+                and re.order_number = #{orderRefund.orderNumber}
+            </if>
+            <if test="orderRefund.channelIdList != null and  !orderRefund.channelIdList.isEmpty()">
+                and o.channel_id  in
+                <foreach collection="orderRefund.channelIdList" item="channelId" open="(" close=")" separator=",">
+                    #{channelId}
+                </foreach>
+            </if>
+            <if test="orderRefund.dvyType != null and orderRefund.dvyType != ''">
+                and o.dvy_type = #{orderParam.dvyType}
             </if>
             <if test="orderRefund.refundSn != null">
-                and refund_sn = #{orderRefund.refundSn}
+                and re.refund_sn = #{orderRefund.refundSn}
             </if>
             <if test="orderRefund.buyerMobile != null">
-                and buyer_mobile = #{orderRefund.buyerMobile}
+                and re.buyer_mobile = #{orderRefund.buyerMobile}
             </if>
             <if test="orderRefund.applyType != null">
-                and apply_type = #{orderRefund.applyType}
+                and re.apply_type = #{orderRefund.applyType}
             </if>
             <if test="orderRefund.returnMoneySts != null and orderRefund.returnMoneySts != 0">
-                and return_money_sts = #{orderRefund.returnMoneySts}
+                and re.return_money_sts = #{orderRefund.returnMoneySts}
             </if>
             <if test="orderRefund.startTime != null">
-                AND create_time &gt;= #{orderRefund.startTime}
+                AND re.create_time &gt;= #{orderRefund.startTime}
             </if>
             <if test="orderRefund.endTime != null">
-                AND create_time &lt;= #{orderRefund.endTime}
+                AND re.create_time &lt;= #{orderRefund.endTime}
             </if>
         </where>
 
@@ -482,12 +492,15 @@
             <if test="orderRefund.orderNumber != null">
                 and refund.order_number = #{orderRefund.orderNumber}
             </if>
-            <if test="orderRefund.channelIdList != null and orderRefund.channelIdList != ''">
+            <if test="orderRefund.channelIdList != null and  !orderRefund.channelIdList.isEmpty()">
                 and o.channel_id  in
                 <foreach collection="orderRefund.channelIdList" item="channelId" open="(" close=")" separator=",">
                     #{channelId}
                 </foreach>
             </if>
+            <if test="orderRefund.dvyType != null and orderRefund.dvyType != ''">
+                and o.dvy_type = #{orderParam.dvyType}
+            </if>
             <if test="orderRefund.refundSn != null">
                 and refund.refund_sn = #{orderRefund.refundSn}
             </if>
@@ -541,12 +554,15 @@
             <if test="orderRefund.orderNumber != null">
                 and refund.order_number = #{orderRefund.orderNumber}
             </if>
-            <if test="orderRefund.channelIdList != null and orderRefund.channelIdList != ''">
+            <if test="orderRefund.channelIdList != null and !orderRefund.channelIdList.isEmpty()">
                 and o.channel_id  in
                 <foreach collection="orderRefund.channelIdList" item="channelId" open="(" close=")" separator=",">
                     #{channelId}
                 </foreach>
             </if>
+            <if test="orderRefund.dvyType != null and orderRefund.dvyType != ''">
+                and o.dvy_type = #{orderParam.dvyType}
+            </if>
             <if test="orderRefund.refundSn != null">
                 and refund.refund_sn = #{orderRefund.refundSn}
             </if>

+ 2 - 2
yami-shop-service/src/main/resources/mapper/UserMapper.xml

@@ -137,7 +137,7 @@
         FROM tz_user a
         <where>
             a.channel_id in (SELECT id FROM tz_channel)
-            <if test="po.channelIdList != null and po.channelIdList != ''">
+            <if test="po.channelIdList != null and !po.channelIdList.isEmpty()">
                 and a.channel_id  in
                 <foreach collection="po.channelIdList" item="channelId" open="(" close=")" separator=",">
                     #{channelId}
@@ -229,7 +229,7 @@
         FROM tz_user a
         <where>
             a.channel_id in (SELECT id FROM tz_channel)
-            <if test="po.channelIdList != null and po.channelIdList != ''">
+            <if test="po.channelIdList != null and !po.channelIdList.isEmpty()">
                 and a.channel_id  in
                 <foreach collection="po.channelIdList" item="channelId" open="(" close=")" separator=",">
                     #{channelId}

+ 3 - 1
yami-shop-sys/src/main/java/com/yami/shop/sys/dao/SysUserChannelMapper.java

@@ -31,7 +31,7 @@ public interface SysUserChannelMapper extends BaseMapper<SysUserChannel> {
 	 * 根据用户id删除用户与角色关系
 	 * @param userId
 	 */
-	void deleteByUserId(Long userId);
+	void deleteByUserId(@Param("userId") Long userId);
 
 	/**
 	 * 根据用户id 批量添加用户角色关系
@@ -39,4 +39,6 @@ public interface SysUserChannelMapper extends BaseMapper<SysUserChannel> {
 	 * @param channelIdList
 	 */
 	void insertUserAndUserChannel(@Param("userId") Long userId, @Param("channelIdList") List<Long> channelIdList);
+
+	List<Long> listChannelByUserId(@Param("userId") Long userId);
 }

+ 5 - 0
yami-shop-sys/src/main/java/com/yami/shop/sys/service/impl/SysUserServiceImpl.java

@@ -156,6 +156,11 @@ public class SysUserServiceImpl extends ServiceImpl<SysUserMapper, SysUser> impl
             // 通过关联表查询用户对应的部门信息
             user.setDepts(deptService.listDeptsByUserId(userId));
         }
+        //获取用户所属企业
+        if (user != null) {
+            // 通过关联表查询用户对应的部门信息
+            user.setChannelIdList(sysUserChannelMapper.listChannelByUserId(userId));
+        }
         return user;
     }
 

+ 6 - 2
yami-shop-sys/src/main/resources/mapper/SysUserChannelMapper.xml

@@ -13,8 +13,12 @@
 	<delete id="deleteByUserId">
 		delete from tz_sys_user_channel where user_id = #{userId}
 	</delete>
-	
-	<insert id="insertUserAndUserChannel">
+    <select id="listChannelByUserId" resultType="java.lang.Long">
+		select channel_id from tz_sys_user_channel where user_id = #{userId}
+
+	</select>
+
+    <insert id="insertUserAndUserChannel">
 	  	insert into tz_sys_user_channel (user_id,channel_id) values
 	  	<foreach collection="channelIdList" item="channelId" separator=",">
 	  		(#{userId},#{channelId})