xdd 1 tuần trước cách đây
mục cha
commit
f9200175e2

+ 12 - 1
fs-service-system/src/main/java/com/fs/live/mapper/LiveOrderItemMapper.java

@@ -1,10 +1,12 @@
 package com.fs.live.mapper;
 
 import java.util.List;
+import java.util.Map;
 
 import com.fs.live.domain.LiveOrderItem;
 import com.fs.live.vo.LiveOrderItemListUVO;
 import com.fs.live.vo.LiveOrderItemVo;
+import org.apache.ibatis.annotations.MapKey;
 import org.apache.ibatis.annotations.Param;
 import org.apache.ibatis.annotations.Select;
 import org.apache.ibatis.annotations.Update;
@@ -67,7 +69,16 @@ public interface LiveOrderItemMapper {
     @Select("select loi.*,fsp.bar_code from live_order_item loi left join fs_store_product fsp on loi.product_id =fsp.product_id   where loi.order_id = #{orderId}")
     List<LiveOrderItem> selectLiveOrderItemByOrderId(Long orderId);
 
-    List<LiveOrderItemVo> selectLiveOrderItemByOrderIds(@Param("orderIds") List<Long> orderIds);
+    @MapKey("orderId")
+    @Select("select a.item_id, a.order_id, a.order_code, a.cart_id, a.goods_id, a.product_id,a. product_attr_value_id, a.json_info, a.num, a.is_after_sales, a.is_prescribe, a.store_id, a.is_gift\n" +
+            "        , b.product_name, b.image as img_url, b.price, b.ot_price, b.sales, b.product_info as product_introduce\n" +
+            "        from live_order_item a\n" +
+            "        left join fs_store_product b on a.product_id = b.product_id\n" +
+            "        where order_id in\n" +
+            "        <foreach item=\"orderId\" collection=\"orderIds\" open=\"(\" separator=\",\" close=\")\">\n" +
+            "            #{orderId}\n" +
+            "        </foreach>")
+    Map<Long,List<LiveOrderItemVo>> selectLiveOrderItemByOrderIds(@Param("orderIds") List<Long> orderIds);
 
     int insertBatchList(@Param("liveOrderItemList") List<LiveOrderItem> liveOrderItemList);
 

+ 48 - 32
fs-service-system/src/main/java/com/fs/live/service/impl/LiveOrderServiceImpl.java

@@ -9,6 +9,7 @@ import java.time.ZoneId;
 import java.time.format.DateTimeFormatter;
 import java.time.temporal.ChronoUnit;
 import java.util.*;
+import java.util.concurrent.CompletableFuture;
 import java.util.concurrent.TimeUnit;
 import java.util.stream.Collectors;
 
@@ -747,42 +748,57 @@ public class LiveOrderServiceImpl implements ILiveOrderService {
         if(CollectionUtils.isEmpty(allOrderIds)) {
             return Collections.emptyList();
         }
-        Map<Long, FsStoreDelivers> byOrderIdWithTypeBatch = fsStoreDeliversMapper
-                .findByOrderIdWithTypeBatch(allOrderIds, 1);
-
-        Map<Long,LiveAfterSales> liveAfterSalesMap = liveAfterSalesMapper.findByOrderIds(allOrderIds);
-
-        for (LiveOrderListVo order : liveOrders) {
-            FsStoreDelivers delivers = byOrderIdWithTypeBatch.get(order.getOrderId());
+        try{
+            CompletableFuture<Map<Long, FsStoreDelivers>> deliversFuture = CompletableFuture.supplyAsync(() ->
+                    fsStoreDeliversMapper.findByOrderIdWithTypeBatch(allOrderIds, 1));
+            CompletableFuture<Map<Long, LiveAfterSales>> afterSalesFuture = CompletableFuture.supplyAsync(() ->
+                    liveAfterSalesMapper.findByOrderIds(allOrderIds));
+            CompletableFuture<Map<Long, List<LiveOrderItemVo>>> orderItemsFuture = CompletableFuture.supplyAsync(() ->
+                    liveOrderItemMapper.selectLiveOrderItemByOrderIds(allOrderIds));
+
+            CompletableFuture.allOf(deliversFuture, afterSalesFuture, orderItemsFuture).join();
+            Map<Long, FsStoreDelivers> byOrderIdWithTypeBatch = deliversFuture.get();
+            Map<Long, LiveAfterSales> liveAfterSalesMap = afterSalesFuture.get();
+            Map<Long, List<LiveOrderItemVo>> liveOrderItemMaps = orderItemsFuture.get();
+
+            for (LiveOrderListVo order : liveOrders) {
+                FsStoreDelivers delivers = byOrderIdWithTypeBatch.get(order.getOrderId());
+
+                if(ObjectUtil.isNotNull(delivers)) {
+                    order.setDeliveryCode(delivers.getDeliverSn());
+                    order.setDeliveryName(delivers.getDeliverName());
+                    order.setDeliverySn(delivers.getDeliverId());
+                    order.setDeliveryStatus(delivers.getStatus());
+                    order.setDeliveryType(String.valueOf(delivers.getStateEx()));
+                }else {
+                    order.setDeliveryCode(null);
+                    order.setDeliveryName(null);
+                    order.setDeliverySn(null);
+                    order.setDeliveryStatus(null);
+                    order.setDeliveryType(null);
+                }
+                if(ObjectUtil.isNotNull(liveAfterSalesMap)){
+                    LiveAfterSales liveAfterSales = liveAfterSalesMap.get(order.getOrderId());
+                    if(ObjectUtil.isNotNull(liveAfterSales)) {
+                        order.setAfterSaleId(liveAfterSales.getId());
+                    }
+                }
 
-            if(ObjectUtil.isNotNull(delivers)) {
-                order.setDeliveryCode(delivers.getDeliverSn());
-                order.setDeliveryName(delivers.getDeliverName());
-                order.setDeliverySn(delivers.getDeliverId());
-                order.setDeliveryStatus(delivers.getStatus());
-                order.setDeliveryType(String.valueOf(delivers.getStateEx()));
-            }else {
-                order.setDeliveryCode(null);
-                order.setDeliveryName(null);
-                order.setDeliverySn(null);
-                order.setDeliveryStatus(null);
-                order.setDeliveryType(null);
-            }
-            if(ObjectUtil.isNotNull(liveAfterSalesMap)){
-                LiveAfterSales liveAfterSales = liveAfterSalesMap.get(order.getOrderId());
-                if(ObjectUtil.isNotNull(liveAfterSales)) {
-                    order.setAfterSaleId(liveAfterSales.getId());
+                if(ObjectUtil.isNotNull(liveOrderItemMaps)){
+                    Long orderId = order.getOrderId();
+                    List<LiveOrderItemVo> liveOrderItemVos = liveOrderItemMaps.get(orderId);
+                    if(CollectionUtils.isNotEmpty(liveOrderItemVos)) {
+                        order.setOrderItemList(liveOrderItemVos);
+                    }
                 }
             }
+            if (liveOrders.isEmpty()) {
+                return liveOrders;
+            }
+        }catch (Exception e){
+            log.error("查询订单详情失败", e);
+            throw new RuntimeException("查询订单详情失败");
         }
-        if (liveOrders.isEmpty()) {
-            return liveOrders;
-        }
-        List<LiveOrderItemVo> liveOrderItems = liveOrderItemMapper.selectLiveOrderItemByOrderIds(allOrderIds);
-
-        liveOrders.forEach(item -> {
-            item.setOrderItemList(liveOrderItems.stream().filter(liveOrderItem -> liveOrderItem.getOrderId().equals(item.getOrderId())).collect(Collectors.toList()));
-        });
         return liveOrders;
     }
 

+ 1 - 10
fs-service-system/src/main/resources/mapper/live/LiveOrderItemMapper.xml

@@ -42,16 +42,7 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
         </where>
     </select>
 
-    <select id="selectLiveOrderItemByOrderIds" parameterType="java.util.List" resultType="com.fs.live.vo.LiveOrderItemVo">
-        select a.item_id, a.order_id, a.order_code, a.cart_id, a.goods_id, a.product_id,a. product_attr_value_id, a.json_info, a.num, a.is_after_sales, a.is_prescribe, a.store_id, a.is_gift
-        , b.product_name, b.image as img_url, b.price, b.ot_price, b.sales, b.product_info as product_introduce
-        from live_order_item a
-        left join fs_store_product b on a.product_id = b.product_id
-        where order_id in
-        <foreach item="orderId" collection="orderIds" open="(" separator="," close=")">
-            #{orderId}
-        </foreach>
-    </select>
+
 
     <select id="selectCheckedByUserId" parameterType="java.util.List" resultType="com.fs.live.vo.LiveOrderItemVo">
         select a.item_id, a.order_id, a.order_code, a.cart_id, a.goods_id, a.product_id,a. product_attr_value_id, a.json_info, a.num, a.is_after_sales, a.is_prescribe, a.store_id, a.is_gift

+ 32 - 0
fs-user-app/src/main/java/com/fs/app/controller/LiveOrderController.java

@@ -2,6 +2,7 @@ package com.fs.app.controller;
 
 import cn.hutool.core.util.ObjectUtil;
 import cn.hutool.core.util.StrUtil;
+import com.alibaba.fastjson.JSON;
 import com.fs.app.annotation.Login;
 import com.fs.app.utils.JwtUtils;
 import com.fs.common.annotation.Log;
@@ -33,6 +34,7 @@ import com.fs.store.service.IFsExpressService;
 import com.github.pagehelper.PageHelper;
 import com.github.pagehelper.PageInfo;
 import io.swagger.annotations.ApiOperation;
+import lombok.extern.slf4j.Slf4j;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.security.access.prepost.PreAuthorize;
 import org.springframework.validation.annotation.Validated;
@@ -51,6 +53,7 @@ import static com.fs.live.service.impl.LiveServiceImpl.to16Hex;
  * @author fs
  * @date 2025-07-08
  */
+@Slf4j
 @RestController
 @RequestMapping("/app/live/liveOrder")
 public class LiveOrderController extends AppBaseController
@@ -69,6 +72,8 @@ public class LiveOrderController extends AppBaseController
     @ApiOperation("物流查询多运单号")
     @PostMapping("/getExpressMulti")
     public R getExpressMulti( @Validated @RequestBody FsStoreOrderExpressParam param){
+        log.info("物流查询多运单号 请求参数: {}", JSON.toJSONString(param));
+
         LiveOrder order=liveOrderService.selectLiveOrderByOrderId(String.valueOf(param.getOrderId()));
         if (ObjectUtil.isNull(order)) {
             throw new CustomException("订单不存在");
@@ -83,6 +88,8 @@ public class LiveOrderController extends AppBaseController
     @ApiOperation("物流查询")
     @PostMapping("/getExpress")
     public R getExpress( @Validated @RequestBody FsStoreOrderExpressParam param){
+        log.info("物流查询 参数: {}", JSON.toJSONString(param));
+
         LiveOrder order=liveOrderService.selectLiveOrderByOrderId(String.valueOf(param.getOrderId()));
         if (ObjectUtil.isNull(order)) {
             throw new CustomException("订单不存在");
@@ -102,6 +109,8 @@ public class LiveOrderController extends AppBaseController
     @GetMapping("/list")
     public R list(LiveOrder liveOrder)
     {
+        log.info("查询订单列表 参数: {}", JSON.toJSONString(liveOrder));
+
         PageHelper.startPage(Integer.parseInt(ServletUtils.getParameter("pageNum")) ,Integer.parseInt(ServletUtils.getParameter("pageSize")) );
         try {
             liveOrder.setUserId(getUserId());
@@ -121,6 +130,8 @@ public class LiveOrderController extends AppBaseController
     @GetMapping("/export")
     public AjaxResult export(LiveOrder liveOrder)
     {
+        log.info("订单导出 参数: {}", JSON.toJSONString(liveOrder));
+
         List<LiveOrder> list = liveOrderService.selectLiveOrderList(liveOrder);
         ExcelUtil<LiveOrder> util = new ExcelUtil<LiveOrder>(LiveOrder.class);
         return util.exportExcel(list, "订单数据");
@@ -133,12 +144,16 @@ public class LiveOrderController extends AppBaseController
     @GetMapping(value = "/info/{orderId}")
     public AjaxResult getInfo(@PathVariable("orderId") String orderId)
     {
+        log.info("获取订单详细信息 参数: {}",orderId);
+
         return AjaxResult.success(liveOrderService.selectLiveOrderByOrderId(orderId));
     }
 
     @ApiOperation("确认订单")
     @PostMapping("/confirm")
     public R confirm(@Validated @RequestBody LiveOrderConfirmParam param, HttpServletRequest request){
+        log.info("确认订单 参数: {}", JSON.toJSONString(param));
+
         param.setUserId(Long.parseLong(getUserId()));
         return liveOrderService.confirmOrder(param);
     }
@@ -149,6 +164,8 @@ public class LiveOrderController extends AppBaseController
     @RepeatSubmit
     public R buy(@RequestBody LiveOrder liveOrder)
     {
+        log.info("购物车购买 参数: {}", JSON.toJSONString(liveOrder));
+
         liveOrder.setUserId(getUserId());
         return liveOrderService.buy(liveOrder);
     }
@@ -162,6 +179,8 @@ public class LiveOrderController extends AppBaseController
     @RepeatSubmit
     public R add(@RequestBody LiveOrder liveOrder)
     {
+        log.info("新增订单: {}", JSON.toJSONString(liveOrder));
+
         liveOrder.setUserId(getUserId());
         return liveOrderService.createLiveOrder(liveOrder);
     }
@@ -170,6 +189,7 @@ public class LiveOrderController extends AppBaseController
     @ApiOperation("计算订单金额")
     @PostMapping("/computed")
     public R computed(@Validated @RequestBody LiveOrderComputedParam param){
+        log.info("计算订单金额 {}",JSON.toJSONString(param));
 
         LiveOrderComputeDTO dto=liveOrderService.computedOrder(Long.parseLong(getUserId()),param);
         return R.ok().put("data",dto);
@@ -195,6 +215,7 @@ public class LiveOrderController extends AppBaseController
     @Deprecated
     public R getExpress(@PathVariable("id") Long id)
     {
+        log.info("查看物流状态 {}",id);
 
         LiveOrder order=liveOrderService.selectLiveOrderByOrderId(String.valueOf(id));
         ExpressInfoDTO expressInfoDTO=null;
@@ -218,6 +239,8 @@ public class LiveOrderController extends AppBaseController
     @PostMapping(value = "/pay")
     public void pay(LiveOrder liveOrder)
     {
+        log.info("支付订单 参数: {}",liveOrder);
+
        liveOrderService.handlePay(liveOrder);
     }
 
@@ -244,6 +267,8 @@ public class LiveOrderController extends AppBaseController
     @Log(title = "退款", businessType = BusinessType.UPDATE)
     @PostMapping("/refundOrderMoney")
     public synchronized R refundOrderMoney(@Validated @RequestBody LiveOrderRefundParam param, HttpServletRequest request) {
+        log.info("退款 {}",JSON.toJSONString(param));
+
         return liveOrderService.refundOrderMoney(param.getOrderId());
     }
 
@@ -255,6 +280,8 @@ public class LiveOrderController extends AppBaseController
     @RepeatSubmit
     public R cancelConfirm(@PathVariable String orderId,@PathVariable String type)
     {
+        log.info("订单确认 参数 orderId: {} type: {}", orderId, type);
+
         LiveOrder byId = liveOrderService.getById(orderId);
         List<Map<String, String>> allCodeDescMap = null;
         if (type.equals("0"))
@@ -268,6 +295,7 @@ public class LiveOrderController extends AppBaseController
     @GetMapping(value = "/liveOrderUser/{liveId}")
     public R liveOrderUser(@PathVariable  String liveId)
     {
+        log.info("正在购买的用户 参数: {}",liveId);
         return liveOrderService.liveOrderUser(liveId);
     }
 
@@ -275,6 +303,8 @@ public class LiveOrderController extends AppBaseController
     @ApiOperation("取消订单")
     @PostMapping("/cancelOrder")
     public R cancelOrder(@Validated @RequestBody LiveOrderCancelParam param, HttpServletRequest request){
+        log.info("取消订单 参数: {}",JSON.toJSONString(param));
+
         LiveOrder order=liveOrderService.selectLiveOrderByOrderId(String.valueOf(param.getOrderId()));
         if (ObjectUtil.isNull(order)) {
             throw new CustomException("订单不存在");
@@ -287,6 +317,8 @@ public class LiveOrderController extends AppBaseController
     @ApiOperation("完成订单")
     @PostMapping("/finishOrder")
     public R finishOrder(@Validated @RequestBody LiveOrderCancelParam param, HttpServletRequest request){
+        log.info("完成订单 参数: {}",JSON.toJSONString(param));
+
         return liveOrderService.finishOrder(param.getOrderId());
     }
     @ApiOperation("完成订单")