From bf2bffc884f00fd2ed2f16667ab6b91328012b8a Mon Sep 17 00:00:00 2001
From: 陶杰 <1378534974@qq.com>
Date: 星期二, 01 十月 2024 11:37:34 +0800
Subject: [PATCH] 1.订单商品评论 2.订单报表sql优化

---
 src/main/java/com/mzl/flower/service/payment/OrderService.java |   40 ++++++++++++++++++++++++++++++++++++----
 1 files changed, 36 insertions(+), 4 deletions(-)

diff --git a/src/main/java/com/mzl/flower/service/payment/OrderService.java b/src/main/java/com/mzl/flower/service/payment/OrderService.java
index e1aebd0..47f3acb 100644
--- a/src/main/java/com/mzl/flower/service/payment/OrderService.java
+++ b/src/main/java/com/mzl/flower/service/payment/OrderService.java
@@ -12,8 +12,10 @@
 import com.mzl.flower.config.security.SecurityUtils;
 import com.mzl.flower.constant.Constants;
 import com.mzl.flower.dto.PriceDTO;
+import com.mzl.flower.dto.request.comment.QueryFlowerCommentDTO;
 import com.mzl.flower.dto.request.menber.MemberGrowthRecordDTO;
 import com.mzl.flower.dto.request.payment.*;
+import com.mzl.flower.dto.response.comment.FlowerCommentVO;
 import com.mzl.flower.dto.response.coupon.CouponRecordVO;
 import com.mzl.flower.dto.response.flower.FlowerCartListDTO;
 import com.mzl.flower.dto.response.flower.FlowerCartListWrapDTO;
@@ -43,6 +45,7 @@
 import com.mzl.flower.mapper.system.UserWechatMapper;
 import com.mzl.flower.mapper.warehouse.WarehouseLocationMapper;
 import com.mzl.flower.service.BaseService;
+import com.mzl.flower.service.comment.FlowerCommentService;
 import com.mzl.flower.service.coupon.CouponRecordService;
 import com.mzl.flower.service.flower.FlowerService;
 import com.mzl.flower.service.menber.MemberGrowthRecordService;
@@ -164,6 +167,9 @@
     @Autowired
     private CouponRecordService couponRecordService;
 
+    @Autowired
+    private FlowerCommentService flowerCommentService;
+
 
     public void changeFlower2Cart(CartSaveDTO dto) {
         String userId = SecurityUtils.getUserId();
@@ -196,7 +202,7 @@
                 Integer completeNumToday=getFlowerCompleteNumToday(userId,c.getFlowerId());
                 Integer tmp=completeNumToday+c.getNum();
                 if(null!=tmp && null!=flowerDetail.getLimited()
-                      &&  tmp.compareTo(flowerDetail.getLimited())>0){
+                        &&  tmp.compareTo(flowerDetail.getLimited())>0){
                     throw new ValidationException("当天的订单的花数量加上购物车的数量不能超过限售数量!");
                 }
 
@@ -208,7 +214,7 @@
 
                 // 限购  1.首先查看购物车中的数量是否已经超过限售数量
                 if(null!=c.getNum() && null!=flowerDetail.getLimited()
-                      && c.getNum().compareTo(flowerDetail.getLimited())>0){
+                        && c.getNum().compareTo(flowerDetail.getLimited())>0){
                     throw new ValidationException("数量不能超过限售数量!");
                 }
 
@@ -216,7 +222,7 @@
                 Integer completeNumToday=getFlowerCompleteNumToday(userId,c.getFlowerId());
                 Integer tmp=completeNumToday+c.getNum();
                 if(null!=tmp && null!=flowerDetail.getLimited()
-                       && tmp.compareTo(flowerDetail.getLimited())>0){
+                        && tmp.compareTo(flowerDetail.getLimited())>0){
                     throw new ValidationException("当天的订单的花数量加上购物车的数量不能超过限售数量!");
                 }
 
@@ -1135,6 +1141,7 @@
                 new QueryWrapper<OrderItem>().eq("order_id", id));
 
         Map<Long, String> stationMap = prepareStationMap();
+        Map<String, FlowerCommentVO> commentMap=prepareCommentMap(id);
 
         List<OrderItemListDTO> result = new ArrayList<>();
         for (OrderItem oi : ls) {
@@ -1143,10 +1150,35 @@
 
             dto.setStationName(stationMap.get(oi.getStationId()));
 
+            // 评论
+            final FlowerCommentVO flowerCommentVO = commentMap.get(oi.getId());
+            copyCommentInfo(dto,flowerCommentVO);
+
             result.add(dto);
         }
 
         return result;
+    }
+
+    private Map<String, FlowerCommentVO> prepareCommentMap(String orderId) {
+        QueryFlowerCommentDTO queryFlowerCommentDTO = new QueryFlowerCommentDTO();
+        queryFlowerCommentDTO.setOrderId(orderId);
+        final List<FlowerCommentVO> list = flowerCommentService.getList(queryFlowerCommentDTO);
+        if (list == null || list.isEmpty()) {
+            return Collections.emptyMap();
+        }
+        // 将 List 转换为 Map,其中 key 为 FlowerCommentVO 的 id
+        return list.stream().collect(Collectors.toMap(FlowerCommentVO::getOrderItemId, item -> item));
+    }
+
+
+    private void copyCommentInfo(OrderItemListDTO dto,FlowerCommentVO flowerCommentVO){
+        if(null != dto && null!=flowerCommentVO){
+            dto.setCommentGrade(flowerCommentVO.getCommentGrade());
+            dto.setComment(flowerCommentVO.getComment());
+            dto.setCommentImages(flowerCommentVO.getCommentImages());
+            dto.setAnonymityFalg(flowerCommentVO.getAnonymityFalg());
+        }
     }
 
     public List<Order> autoReceive() {
@@ -1678,7 +1710,7 @@
                     // 新增
                     cartMapper.updateById(cart);
                 }else{
-                   // 更新
+                    // 更新
                     cartMapper.insert(cart);
                 }
             }

--
Gitblit v1.9.3