Procházet zdrojové kódy

Merge branch 'refs/heads/master' into xiaolu

肖路 před 1 měsícem
rodič
revize
b970e692a2

+ 2 - 0
ruoyi-modules/ruoyi-customer/src/main/java/org/dromara/customer/domain/SupplyArea.java

@@ -52,6 +52,8 @@ public class SupplyArea extends TenantEntity {
 
     private Long parentId;
 
+    private String parentCode;
+
     /**
      * 区域层级(1省/直辖市 2市 3区县 4街道/镇)
      */

+ 2 - 0
ruoyi-modules/ruoyi-customer/src/main/java/org/dromara/customer/domain/bo/SupplyAreaBo.java

@@ -49,6 +49,8 @@ public class SupplyAreaBo extends BaseEntity {
 
     private Long parentId;
 
+    private String parentCode;
+
     /**
      * 区域层级(1省/直辖市 2市 3区县 4街道/镇)
      */

+ 2 - 0
ruoyi-modules/ruoyi-customer/src/main/java/org/dromara/customer/domain/vo/SupplyAreaVo.java

@@ -67,6 +67,8 @@ public class SupplyAreaVo implements Serializable {
     @ExcelDictFormat(readConverterExp = "如=省级编码对应市级的上级编码,顶级区域为0")
     private Long parentId;
 
+    private String parentCode;
+
     /**
      * 区域层级(1省/直辖市 2市 3区县 4街道/镇)
      */

+ 5 - 0
ruoyi-modules/ruoyi-order/src/main/java/org/dromara/order/domain/OrderMain.java

@@ -290,4 +290,9 @@ public class OrderMain extends TenantEntity {
      */
     private String assigneeType;
 
+    /**
+     * 评价状态:0-待评价,1-待追评,2-已评价
+     */
+    private Integer evaluationStatus;
+
 }

+ 5 - 0
ruoyi-modules/ruoyi-order/src/main/java/org/dromara/order/domain/bo/OrderMainBo.java

@@ -295,6 +295,11 @@ public class OrderMainBo extends BaseEntity {
      */
     private String orderStatuses;
 
+    /**
+     * 评价状态:0-待评价,1-待追评,2-已评价
+     */
+    private Integer evaluationStatus;
+
     List<OrderProductBo> orderProductBos;
 
 

+ 5 - 0
ruoyi-modules/ruoyi-order/src/main/java/org/dromara/order/domain/vo/OrderMainVo.java

@@ -407,5 +407,10 @@ public class OrderMainVo implements Serializable {
     //包裹数量
     private Long packageNum;
 
+    /**
+     * 评价状态:0-待评价,1-待追评,2-已评价
+     */
+    private Integer evaluationStatus;
+
 
 }

+ 48 - 24
ruoyi-modules/ruoyi-order/src/main/java/org/dromara/order/service/impl/OrderEvaluationHeaderServiceImpl.java

@@ -1,5 +1,7 @@
 package org.dromara.order.service.impl;
 
+import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper;
+import com.baomidou.mybatisplus.core.metadata.IPage;
 import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
 import org.dromara.common.core.exception.ServiceException;
 import org.dromara.common.core.utils.MapstructUtils;
@@ -12,11 +14,14 @@ import com.baomidou.mybatisplus.core.toolkit.Wrappers;
 import lombok.RequiredArgsConstructor;
 import lombok.extern.slf4j.Slf4j;
 import org.dromara.order.domain.OrderEvaluationItem;
+import org.dromara.order.domain.OrderMain;
+import org.dromara.order.domain.OrderProduct;
 import org.dromara.order.domain.bo.OrderEvaluationItemBo;
 import org.dromara.order.domain.vo.OrderEvaluationItemVo;
 import org.dromara.order.domain.vo.OrderEvaluationListVo;
 import org.dromara.order.domain.vo.OrderProductBriefVo;
 import org.dromara.order.mapper.OrderEvaluationItemMapper;
+import org.dromara.order.mapper.OrderMainMapper;
 import org.dromara.order.mapper.OrderProductMapper;
 import org.springframework.beans.BeanUtils;
 import org.springframework.stereotype.Service;
@@ -41,6 +46,8 @@ import java.util.stream.Collectors;
 @Service
 public class OrderEvaluationHeaderServiceImpl extends ServiceImpl<OrderEvaluationHeaderMapper, OrderEvaluationHeader> implements IOrderEvaluationHeaderService {
 
+    private final OrderMainMapper orderMainMapper;
+
     private final OrderEvaluationHeaderMapper baseMapper;
 
     private final OrderEvaluationItemMapper itemMapper;
@@ -130,43 +137,48 @@ public class OrderEvaluationHeaderServiceImpl extends ServiceImpl<OrderEvaluatio
 
     @Override
     public TableDataInfo<OrderEvaluationListVo> getEvaluationOrderList(Long customerId, String evaluationStatus, PageQuery pageQuery) {
-        // 1. 创建分页对象
-        Page<OrderEvaluationListVo> page = new Page<>(pageQuery.getPageNum(), pageQuery.getPageSize());
-
-        // 2. 调用 Mapper
-        // ⚠️ 重点检查这里:参数顺序必须是 (page, customerId, evaluationStatus)
-        // 如果你之前传成了 (page, pageQuery, evaluationStatus) 或者其他组合,就会报这个错!
-        Page<OrderEvaluationListVo> resultPage = baseMapper.selectEvaluationOrderListPage(
-            page,
-            customerId,
-            evaluationStatus // 确保这里传的是 String 类型的 "0", "1", "2" 或 null,而不是对象
-        );
 
-        List<OrderEvaluationListVo> orders = resultPage.getRecords();
+        if (evaluationStatus != null && "2".equals(evaluationStatus)) {
+            evaluationStatus = "1";
+        }
+        // 1. 分页查询主订单(含评价状态)
+        IPage<OrderEvaluationListVo> page = orderMainMapper.selectEvaluationMainListPage(pageQuery.build(), customerId, evaluationStatus);
+        List<OrderEvaluationListVo> orders = page.getRecords();
 
         if (!orders.isEmpty()) {
-            // 3. 提取当前页所有订单 ID
+            // 2. 批量查商品(仅当前页的订单ID)
             List<Long> orderIds = orders.stream()
                 .map(OrderEvaluationListVo::getOrderId)
                 .collect(Collectors.toList());
 
-            // 4. 批量查询这些订单下的商品列表
+            List<OrderProduct> products = orderProductMapper.selectByOrderIds(orderIds);
 
-            List<OrderProductBriefVo> allProducts = orderProductMapper.selectBriefListByOrderIds(orderIds);
+            // 3. 按 orderId 分组
+            Map<Long, List<OrderProduct>> productMap = products.stream()
+                .collect(Collectors.groupingBy(OrderProduct::getOrderId));
 
-            // 5. 按 orderId 分组商品 (Key: orderId, Value: List<Product>)
-            Map<Long, List<OrderProductBriefVo>> productMap = allProducts.stream()
-                .collect(Collectors.groupingBy(OrderProductBriefVo::getOrderId));
-
-            // 6. 将商品列表组装到对应订单的 productList 字段
+            // 4. 转换并赋值
             for (OrderEvaluationListVo order : orders) {
-                List<OrderProductBriefVo> productList = productMap.getOrDefault(order.getOrderId(), Collections.emptyList());
-                order.setProductList(productList);
+                List<OrderProduct> list = productMap.get(order.getOrderId());
+                if (list != null) {
+                    List<OrderProductBriefVo> briefs = list.stream().map(p -> {
+                        OrderProductBriefVo b = new OrderProductBriefVo();
+                        b.setProductName(p.getProductName());
+                        b.setQuantity(p.getOrderQuantity());
+                        b.setUnitPrice(p.getOrderPrice());
+                        b.setSubtotal(p.getSubtotal());
+                        b.setProductImage(p.getProductImage());
+                        return b;
+                    }).collect(Collectors.toList());
+                    order.setProductList(briefs);
+                } else {
+                    order.setProductList(Collections.emptyList());
+                }
             }
         }
 
-        // 7. 构建返回结果
-        return TableDataInfo.build(resultPage);
+        // 5. 构造分页返回对象
+        return TableDataInfo.build(page);
     }
 
     /**
@@ -259,6 +271,18 @@ public class OrderEvaluationHeaderServiceImpl extends ServiceImpl<OrderEvaluatio
                 throw new ServiceException("评价明细保存失败");
             }
         }
+        // 更新 order_main 表的评价状态为:1 (待追评)
+        LambdaUpdateWrapper<OrderMain> updateWrapper = new LambdaUpdateWrapper<>();
+        updateWrapper.eq(OrderMain::getId, bo.getOrderId())
+            .eq(OrderMain::getEvaluationStatus, 0) // 可
+            .set(OrderMain::getEvaluationStatus, 1); // 1 = 待追评
+
+        int updateCount = orderMainMapper.update(null, updateWrapper);
+        if (updateCount == 0) {
+            // 如果更新行数为 0,可能是订单ID不对,或者状态已经被别人改了
+            log.warn("首次评价后更新订单状态失败,orderId: {}, 可能状态已变更", bo.getOrderId());
+            throw new ServiceException("同步更新订单状态失败");
+        }
 
         bo.setId(evaluationId);
         return true;

+ 4 - 24
ruoyi-modules/ruoyi-order/src/main/resources/mapper/order/OrderMainMapper.xml

@@ -22,36 +22,16 @@
         o.order_time AS orderTime,
         o.total_amount AS totalAmount,
         o.order_status as orderStatus,
-        CASE
-        WHEN oe.max_type IS NULL THEN '0'
-        WHEN oe.max_type = 1 THEN '1'
-        WHEN oe.max_type = 2 THEN '2'
-        ELSE '0'
-        END AS evaluationStatus
+        o.evaluation_status AS evaluationStatus -- 直接查字段
         FROM order_main o
-        LEFT JOIN (
-        SELECT order_id, MAX(evaluation_type) AS max_type
-        FROM order_evaluation_header --
-        WHERE del_flag = '0'
-        GROUP BY order_id
-        ) oe ON o.id = oe.order_id
         WHERE
         o.customer_id = #{customerId}
         AND o.order_status = '5'
         AND o.del_flag = '0'
 
-        <choose>
-            <when test="evaluationStatus != null and evaluationStatus == '0'">
-                AND oe.max_type IS NULL
-            </when>
-            <when test="evaluationStatus != null and evaluationStatus == '1'">
-                AND oe.max_type = 1
-            </when>
-            <when test="evaluationStatus != null and evaluationStatus == '2'">
-                AND oe.max_type = 2
-            </when>
-            <!-- 如果 evaluationStatus 为空或为其他值,则不过滤评价状态,返回所有 -->
-        </choose>
+        <if test="evaluationStatus != null and evaluationStatus != ''">
+            AND o.evaluation_status = #{evaluationStatus}
+        </if>
 
         ORDER BY o.order_time DESC
     </select>