订单:

1、简化交易订单的逻辑
This commit is contained in:
YunaiV 2023-08-18 19:28:36 +08:00
parent f217ba0807
commit fe07e223e4
3 changed files with 13 additions and 91 deletions

View File

@ -5,8 +5,6 @@ import cn.iocoder.yudao.framework.common.pojo.CommonResult;
import cn.iocoder.yudao.framework.common.pojo.PageResult;
import cn.iocoder.yudao.module.member.api.user.MemberUserApi;
import cn.iocoder.yudao.module.member.api.user.dto.MemberUserRespDTO;
import cn.iocoder.yudao.module.product.api.property.ProductPropertyValueApi;
import cn.iocoder.yudao.module.product.api.property.dto.ProductPropertyValueDetailRespDTO;
import cn.iocoder.yudao.module.trade.controller.admin.order.vo.TradeOrderDeliveryReqVO;
import cn.iocoder.yudao.module.trade.controller.admin.order.vo.TradeOrderDetailRespVO;
import cn.iocoder.yudao.module.trade.controller.admin.order.vo.TradeOrderPageItemRespVO;
@ -44,8 +42,6 @@ public class TradeOrderController {
@Resource
private TradeOrderQueryService tradeOrderQueryService;
@Resource
private ProductPropertyValueApi productPropertyValueApi;
@Resource
private MemberUserApi memberUserApi;
@ -64,11 +60,8 @@ public class TradeOrderController {
// 查询订单项
List<TradeOrderItemDO> orderItems = tradeOrderQueryService.getOrderItemListByOrderId(
convertSet(pageResult.getList(), TradeOrderDO::getId));
// 查询商品属性
List<ProductPropertyValueDetailRespDTO> propertyValueDetails = productPropertyValueApi
.getPropertyValueDetailList(TradeOrderConvert.INSTANCE.convertPropertyValueIds(orderItems));
// 最终组合
return success(TradeOrderConvert.INSTANCE.convertPage(pageResult, orderItems, propertyValueDetails, userMap));
return success(TradeOrderConvert.INSTANCE.convertPage(pageResult, orderItems, userMap));
}
@GetMapping("/get-detail")
@ -80,13 +73,10 @@ public class TradeOrderController {
TradeOrderDO order = tradeOrderQueryService.getOrder(id);
// 查询订单项
List<TradeOrderItemDO> orderItems = tradeOrderQueryService.getOrderItemListByOrderId(id);
// 查询商品属性
List<ProductPropertyValueDetailRespDTO> propertyValueDetails = productPropertyValueApi
.getPropertyValueDetailList(TradeOrderConvert.INSTANCE.convertPropertyValueIds(orderItems));
// 查询会员
// 拼接数据
MemberUserRespDTO user = memberUserApi.getUser(order.getUserId());
// 最终组合
return success(TradeOrderConvert.INSTANCE.convert(order, orderItems, propertyValueDetails, user));
return success(TradeOrderConvert.INSTANCE.convert(order, orderItems, user));
}
@PostMapping("/delivery")

View File

@ -118,11 +118,8 @@ public class AppTradeOrderController {
// 查询订单项
List<TradeOrderItemDO> orderItems = tradeOrderQueryService.getOrderItemListByOrderId(
convertSet(pageResult.getList(), TradeOrderDO::getId));
// 查询商品属性
List<ProductPropertyValueDetailRespDTO> propertyValueDetails = productPropertyValueApi
.getPropertyValueDetailList(TradeOrderConvert.INSTANCE.convertPropertyValueIds(orderItems));
// 最终组合
return success(TradeOrderConvert.INSTANCE.convertPage02(pageResult, orderItems, propertyValueDetails));
return success(TradeOrderConvert.INSTANCE.convertPage02(pageResult, orderItems));
}
@GetMapping("/get-count")

View File

@ -14,7 +14,6 @@ import cn.iocoder.yudao.module.product.api.comment.dto.ProductCommentCreateReqDT
import cn.iocoder.yudao.module.product.api.property.dto.ProductPropertyValueDetailRespDTO;
import cn.iocoder.yudao.module.product.api.sku.dto.ProductSkuUpdateStockReqDTO;
import cn.iocoder.yudao.module.promotion.api.combination.dto.CombinationRecordCreateReqDTO;
import cn.iocoder.yudao.module.promotion.api.price.dto.PriceCalculateReqDTO;
import cn.iocoder.yudao.module.trade.api.order.dto.TradeOrderRespDTO;
import cn.iocoder.yudao.module.trade.controller.admin.base.member.user.MemberUserRespVO;
import cn.iocoder.yudao.module.trade.controller.admin.base.product.property.ProductPropertyValueDetailRespVO;
@ -84,9 +83,6 @@ public interface TradeOrderConvert {
TradeOrderItemDO convert(TradePriceCalculateRespBO.OrderItem item);
@Mapping(source = "userId", target = "userId")
PriceCalculateReqDTO convert(AppTradeOrderCreateReqVO createReqVO, Long userId);
@Mappings({
@Mapping(source = "skuId", target = "id"),
@Mapping(source = "count", target = "incrCount"),
@ -123,38 +119,18 @@ public interface TradeOrderConvert {
}
// TODO 芋艿可简化
default PageResult<TradeOrderPageItemRespVO> convertPage(PageResult<TradeOrderDO> pageResult, List<TradeOrderItemDO> orderItems,
List<ProductPropertyValueDetailRespDTO> propertyValueDetails,
Map<Long, MemberUserRespDTO> memberUserRespDTOMap) {
default PageResult<TradeOrderPageItemRespVO> convertPage(PageResult<TradeOrderDO> pageResult,
List<TradeOrderItemDO> orderItems,
Map<Long, MemberUserRespDTO> memberUserMap) {
Map<Long, List<TradeOrderItemDO>> orderItemMap = convertMultiMap(orderItems, TradeOrderItemDO::getOrderId);
Map<Long, ProductPropertyValueDetailRespDTO> propertyValueDetailMap = convertMap(propertyValueDetails, ProductPropertyValueDetailRespDTO::getValueId);
// 转化 List
List<TradeOrderPageItemRespVO> orderVOs = CollectionUtils.convertList(pageResult.getList(), order -> {
List<TradeOrderItemDO> xOrderItems = orderItemMap.get(order.getId());
TradeOrderPageItemRespVO orderVO = convert(order, xOrderItems);
if (CollUtil.isNotEmpty(xOrderItems)) {
// 处理商品属性
for (int i = 0; i < xOrderItems.size(); i++) {
List<TradeOrderItemDO.Property> properties = xOrderItems.get(i).getProperties();
if (CollUtil.isEmpty(properties)) {
continue;
}
TradeOrderPageItemRespVO.Item item = orderVO.getItems().get(i);
item.setProperties(new ArrayList<>(properties.size()));
// 遍历每个 properties设置到 TradeOrderPageItemRespVO.Item
properties.forEach(property -> {
ProductPropertyValueDetailRespDTO propertyValueDetail = propertyValueDetailMap.get(property.getValueId());
if (propertyValueDetail == null) {
return;
}
item.getProperties().add(convert(propertyValueDetail));
});
}
}
// 处理收货地址
orderVO.setReceiverAreaName(AreaUtils.format(order.getReceiverAreaId()));
// 增加用户昵称
orderVO.setUser(memberUserRespDTOMap.get(orderVO.getUserId()));
orderVO.setUser(memberUserMap.get(orderVO.getUserId()));
return orderVO;
});
return new PageResult<>(orderVOs, pageResult.getTotal());
@ -164,28 +140,9 @@ public interface TradeOrderConvert {
ProductPropertyValueDetailRespVO convert(ProductPropertyValueDetailRespDTO bean);
// TODO 芋艿可简化
default TradeOrderDetailRespVO convert(TradeOrderDO order, List<TradeOrderItemDO> orderItems,
List<ProductPropertyValueDetailRespDTO> propertyValueDetails, MemberUserRespDTO user) {
MemberUserRespDTO user) {
TradeOrderDetailRespVO orderVO = convert2(order, orderItems);
// 处理商品属性
Map<Long, ProductPropertyValueDetailRespDTO> propertyValueDetailMap = convertMap(propertyValueDetails, ProductPropertyValueDetailRespDTO::getValueId);
for (int i = 0; i < orderItems.size(); i++) {
List<TradeOrderItemDO.Property> properties = orderItems.get(i).getProperties();
if (CollUtil.isEmpty(properties)) {
continue;
}
TradeOrderDetailRespVO.Item item = orderVO.getItems().get(i);
item.setProperties(new ArrayList<>(properties.size()));
// 遍历每个 properties设置到 TradeOrderPageItemRespVO.Item
properties.forEach(property -> {
ProductPropertyValueDetailRespDTO propertyValueDetail = propertyValueDetailMap.get(property.getValueId());
if (propertyValueDetail == null) {
return;
}
item.getProperties().add(convert(propertyValueDetail));
});
}
// 处理收货地址
orderVO.setReceiverAreaName(AreaUtils.format(order.getReceiverAreaId()));
// 处理用户信息
@ -197,35 +154,13 @@ public interface TradeOrderConvert {
MemberUserRespVO convert(MemberUserRespDTO bean);
// TODO 芋艿可简化
default PageResult<AppTradeOrderPageItemRespVO> convertPage02(PageResult<TradeOrderDO> pageResult, List<TradeOrderItemDO> orderItems,
List<ProductPropertyValueDetailRespDTO> propertyValueDetails) {
default PageResult<AppTradeOrderPageItemRespVO> convertPage02(PageResult<TradeOrderDO> pageResult,
List<TradeOrderItemDO> orderItems) {
Map<Long, List<TradeOrderItemDO>> orderItemMap = convertMultiMap(orderItems, TradeOrderItemDO::getOrderId);
Map<Long, ProductPropertyValueDetailRespDTO> propertyValueDetailMap = convertMap(propertyValueDetails, ProductPropertyValueDetailRespDTO::getValueId);
// 转化 List
List<AppTradeOrderPageItemRespVO> orderVOs = CollectionUtils.convertList(pageResult.getList(), order -> {
List<TradeOrderItemDO> xOrderItems = orderItemMap.get(order.getId());
AppTradeOrderPageItemRespVO orderVO = convert02(order, xOrderItems);
if (CollUtil.isNotEmpty(xOrderItems)) {
// 处理商品属性
for (int i = 0; i < xOrderItems.size(); i++) {
List<TradeOrderItemDO.Property> properties = xOrderItems.get(i).getProperties();
if (CollUtil.isEmpty(properties)) {
continue;
}
AppTradeOrderItemRespVO item = orderVO.getItems().get(i);
item.setProperties(new ArrayList<>(properties.size()));
// 遍历每个 properties设置到 TradeOrderPageItemRespVO.Item
properties.forEach(property -> {
ProductPropertyValueDetailRespDTO propertyValueDetail = propertyValueDetailMap.get(property.getValueId());
if (propertyValueDetail == null) {
return;
}
item.getProperties().add(convert02(propertyValueDetail));
});
}
}
return orderVO;
return convert02(order, xOrderItems);
});
return new PageResult<>(orderVOs, pageResult.getTotal());
}