|
|
@@ -1,30 +1,34 @@
|
|
|
package org.dromara.order.service.impl;
|
|
|
|
|
|
+import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
|
|
+import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper;
|
|
|
+import com.baomidou.mybatisplus.core.metadata.IPage;
|
|
|
+import com.baomidou.mybatisplus.core.toolkit.Wrappers;
|
|
|
+import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
|
|
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
|
|
+import lombok.RequiredArgsConstructor;
|
|
|
+import lombok.extern.slf4j.Slf4j;
|
|
|
import org.dromara.common.core.exception.ServiceException;
|
|
|
import org.dromara.common.core.utils.MapstructUtils;
|
|
|
import org.dromara.common.core.utils.StringUtils;
|
|
|
-import org.dromara.common.mybatis.core.page.TableDataInfo;
|
|
|
import org.dromara.common.mybatis.core.page.PageQuery;
|
|
|
-import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
|
|
-import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
|
|
-import com.baomidou.mybatisplus.core.toolkit.Wrappers;
|
|
|
-import lombok.RequiredArgsConstructor;
|
|
|
-import lombok.extern.slf4j.Slf4j;
|
|
|
+import org.dromara.common.mybatis.core.page.TableDataInfo;
|
|
|
+import org.dromara.order.domain.OrderEvaluationHeader;
|
|
|
import org.dromara.order.domain.OrderEvaluationItem;
|
|
|
+import org.dromara.order.domain.OrderMain;
|
|
|
+import org.dromara.order.domain.OrderProduct;
|
|
|
+import org.dromara.order.domain.bo.OrderEvaluationHeaderBo;
|
|
|
import org.dromara.order.domain.bo.OrderEvaluationItemBo;
|
|
|
+import org.dromara.order.domain.vo.OrderEvaluationHeaderVo;
|
|
|
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.OrderEvaluationHeaderMapper;
|
|
|
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;
|
|
|
-import org.dromara.order.domain.bo.OrderEvaluationHeaderBo;
|
|
|
-import org.dromara.order.domain.vo.OrderEvaluationHeaderVo;
|
|
|
-import org.dromara.order.domain.OrderEvaluationHeader;
|
|
|
-import org.dromara.order.mapper.OrderEvaluationHeaderMapper;
|
|
|
import org.dromara.order.service.IOrderEvaluationHeaderService;
|
|
|
+import org.springframework.stereotype.Service;
|
|
|
import org.springframework.transaction.annotation.Transactional;
|
|
|
|
|
|
import java.util.*;
|
|
|
@@ -41,6 +45,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 +136,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 +270,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;
|