订单:
1、简化交易订单的逻辑
This commit is contained in:
parent
f217ba0807
commit
fe07e223e4
@ -5,8 +5,6 @@ import cn.iocoder.yudao.framework.common.pojo.CommonResult;
|
|||||||
import cn.iocoder.yudao.framework.common.pojo.PageResult;
|
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.MemberUserApi;
|
||||||
import cn.iocoder.yudao.module.member.api.user.dto.MemberUserRespDTO;
|
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.TradeOrderDeliveryReqVO;
|
||||||
import cn.iocoder.yudao.module.trade.controller.admin.order.vo.TradeOrderDetailRespVO;
|
import cn.iocoder.yudao.module.trade.controller.admin.order.vo.TradeOrderDetailRespVO;
|
||||||
import cn.iocoder.yudao.module.trade.controller.admin.order.vo.TradeOrderPageItemRespVO;
|
import cn.iocoder.yudao.module.trade.controller.admin.order.vo.TradeOrderPageItemRespVO;
|
||||||
@ -44,8 +42,6 @@ public class TradeOrderController {
|
|||||||
@Resource
|
@Resource
|
||||||
private TradeOrderQueryService tradeOrderQueryService;
|
private TradeOrderQueryService tradeOrderQueryService;
|
||||||
|
|
||||||
@Resource
|
|
||||||
private ProductPropertyValueApi productPropertyValueApi;
|
|
||||||
@Resource
|
@Resource
|
||||||
private MemberUserApi memberUserApi;
|
private MemberUserApi memberUserApi;
|
||||||
|
|
||||||
@ -64,11 +60,8 @@ public class TradeOrderController {
|
|||||||
// 查询订单项
|
// 查询订单项
|
||||||
List<TradeOrderItemDO> orderItems = tradeOrderQueryService.getOrderItemListByOrderId(
|
List<TradeOrderItemDO> orderItems = tradeOrderQueryService.getOrderItemListByOrderId(
|
||||||
convertSet(pageResult.getList(), TradeOrderDO::getId));
|
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")
|
@GetMapping("/get-detail")
|
||||||
@ -80,13 +73,10 @@ public class TradeOrderController {
|
|||||||
TradeOrderDO order = tradeOrderQueryService.getOrder(id);
|
TradeOrderDO order = tradeOrderQueryService.getOrder(id);
|
||||||
// 查询订单项
|
// 查询订单项
|
||||||
List<TradeOrderItemDO> orderItems = tradeOrderQueryService.getOrderItemListByOrderId(id);
|
List<TradeOrderItemDO> orderItems = tradeOrderQueryService.getOrderItemListByOrderId(id);
|
||||||
// 查询商品属性
|
|
||||||
List<ProductPropertyValueDetailRespDTO> propertyValueDetails = productPropertyValueApi
|
// 拼接数据
|
||||||
.getPropertyValueDetailList(TradeOrderConvert.INSTANCE.convertPropertyValueIds(orderItems));
|
|
||||||
// 查询会员
|
|
||||||
MemberUserRespDTO user = memberUserApi.getUser(order.getUserId());
|
MemberUserRespDTO user = memberUserApi.getUser(order.getUserId());
|
||||||
// 最终组合
|
return success(TradeOrderConvert.INSTANCE.convert(order, orderItems, user));
|
||||||
return success(TradeOrderConvert.INSTANCE.convert(order, orderItems, propertyValueDetails, user));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@PostMapping("/delivery")
|
@PostMapping("/delivery")
|
||||||
|
@ -118,11 +118,8 @@ public class AppTradeOrderController {
|
|||||||
// 查询订单项
|
// 查询订单项
|
||||||
List<TradeOrderItemDO> orderItems = tradeOrderQueryService.getOrderItemListByOrderId(
|
List<TradeOrderItemDO> orderItems = tradeOrderQueryService.getOrderItemListByOrderId(
|
||||||
convertSet(pageResult.getList(), TradeOrderDO::getId));
|
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")
|
@GetMapping("/get-count")
|
||||||
|
@ -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.property.dto.ProductPropertyValueDetailRespDTO;
|
||||||
import cn.iocoder.yudao.module.product.api.sku.dto.ProductSkuUpdateStockReqDTO;
|
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.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.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.member.user.MemberUserRespVO;
|
||||||
import cn.iocoder.yudao.module.trade.controller.admin.base.product.property.ProductPropertyValueDetailRespVO;
|
import cn.iocoder.yudao.module.trade.controller.admin.base.product.property.ProductPropertyValueDetailRespVO;
|
||||||
@ -84,9 +83,6 @@ public interface TradeOrderConvert {
|
|||||||
|
|
||||||
TradeOrderItemDO convert(TradePriceCalculateRespBO.OrderItem item);
|
TradeOrderItemDO convert(TradePriceCalculateRespBO.OrderItem item);
|
||||||
|
|
||||||
@Mapping(source = "userId", target = "userId")
|
|
||||||
PriceCalculateReqDTO convert(AppTradeOrderCreateReqVO createReqVO, Long userId);
|
|
||||||
|
|
||||||
@Mappings({
|
@Mappings({
|
||||||
@Mapping(source = "skuId", target = "id"),
|
@Mapping(source = "skuId", target = "id"),
|
||||||
@Mapping(source = "count", target = "incrCount"),
|
@Mapping(source = "count", target = "incrCount"),
|
||||||
@ -123,38 +119,18 @@ public interface TradeOrderConvert {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// TODO 芋艿:可简化
|
// TODO 芋艿:可简化
|
||||||
default PageResult<TradeOrderPageItemRespVO> convertPage(PageResult<TradeOrderDO> pageResult, List<TradeOrderItemDO> orderItems,
|
default PageResult<TradeOrderPageItemRespVO> convertPage(PageResult<TradeOrderDO> pageResult,
|
||||||
List<ProductPropertyValueDetailRespDTO> propertyValueDetails,
|
List<TradeOrderItemDO> orderItems,
|
||||||
Map<Long, MemberUserRespDTO> memberUserRespDTOMap) {
|
Map<Long, MemberUserRespDTO> memberUserMap) {
|
||||||
Map<Long, List<TradeOrderItemDO>> orderItemMap = convertMultiMap(orderItems, TradeOrderItemDO::getOrderId);
|
Map<Long, List<TradeOrderItemDO>> orderItemMap = convertMultiMap(orderItems, TradeOrderItemDO::getOrderId);
|
||||||
Map<Long, ProductPropertyValueDetailRespDTO> propertyValueDetailMap = convertMap(propertyValueDetails, ProductPropertyValueDetailRespDTO::getValueId);
|
|
||||||
// 转化 List
|
// 转化 List
|
||||||
List<TradeOrderPageItemRespVO> orderVOs = CollectionUtils.convertList(pageResult.getList(), order -> {
|
List<TradeOrderPageItemRespVO> orderVOs = CollectionUtils.convertList(pageResult.getList(), order -> {
|
||||||
List<TradeOrderItemDO> xOrderItems = orderItemMap.get(order.getId());
|
List<TradeOrderItemDO> xOrderItems = orderItemMap.get(order.getId());
|
||||||
TradeOrderPageItemRespVO orderVO = convert(order, xOrderItems);
|
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.setReceiverAreaName(AreaUtils.format(order.getReceiverAreaId()));
|
||||||
// 增加用户昵称
|
// 增加用户昵称
|
||||||
orderVO.setUser(memberUserRespDTOMap.get(orderVO.getUserId()));
|
orderVO.setUser(memberUserMap.get(orderVO.getUserId()));
|
||||||
return orderVO;
|
return orderVO;
|
||||||
});
|
});
|
||||||
return new PageResult<>(orderVOs, pageResult.getTotal());
|
return new PageResult<>(orderVOs, pageResult.getTotal());
|
||||||
@ -164,28 +140,9 @@ public interface TradeOrderConvert {
|
|||||||
|
|
||||||
ProductPropertyValueDetailRespVO convert(ProductPropertyValueDetailRespDTO bean);
|
ProductPropertyValueDetailRespVO convert(ProductPropertyValueDetailRespDTO bean);
|
||||||
|
|
||||||
// TODO 芋艿:可简化
|
|
||||||
default TradeOrderDetailRespVO convert(TradeOrderDO order, List<TradeOrderItemDO> orderItems,
|
default TradeOrderDetailRespVO convert(TradeOrderDO order, List<TradeOrderItemDO> orderItems,
|
||||||
List<ProductPropertyValueDetailRespDTO> propertyValueDetails, MemberUserRespDTO user) {
|
MemberUserRespDTO user) {
|
||||||
TradeOrderDetailRespVO orderVO = convert2(order, orderItems);
|
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()));
|
orderVO.setReceiverAreaName(AreaUtils.format(order.getReceiverAreaId()));
|
||||||
// 处理用户信息
|
// 处理用户信息
|
||||||
@ -197,35 +154,13 @@ public interface TradeOrderConvert {
|
|||||||
|
|
||||||
MemberUserRespVO convert(MemberUserRespDTO bean);
|
MemberUserRespVO convert(MemberUserRespDTO bean);
|
||||||
|
|
||||||
// TODO 芋艿:可简化
|
default PageResult<AppTradeOrderPageItemRespVO> convertPage02(PageResult<TradeOrderDO> pageResult,
|
||||||
default PageResult<AppTradeOrderPageItemRespVO> convertPage02(PageResult<TradeOrderDO> pageResult, List<TradeOrderItemDO> orderItems,
|
List<TradeOrderItemDO> orderItems) {
|
||||||
List<ProductPropertyValueDetailRespDTO> propertyValueDetails) {
|
|
||||||
Map<Long, List<TradeOrderItemDO>> orderItemMap = convertMultiMap(orderItems, TradeOrderItemDO::getOrderId);
|
Map<Long, List<TradeOrderItemDO>> orderItemMap = convertMultiMap(orderItems, TradeOrderItemDO::getOrderId);
|
||||||
Map<Long, ProductPropertyValueDetailRespDTO> propertyValueDetailMap = convertMap(propertyValueDetails, ProductPropertyValueDetailRespDTO::getValueId);
|
|
||||||
// 转化 List
|
// 转化 List
|
||||||
List<AppTradeOrderPageItemRespVO> orderVOs = CollectionUtils.convertList(pageResult.getList(), order -> {
|
List<AppTradeOrderPageItemRespVO> orderVOs = CollectionUtils.convertList(pageResult.getList(), order -> {
|
||||||
List<TradeOrderItemDO> xOrderItems = orderItemMap.get(order.getId());
|
List<TradeOrderItemDO> xOrderItems = orderItemMap.get(order.getId());
|
||||||
AppTradeOrderPageItemRespVO orderVO = convert02(order, xOrderItems);
|
return 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 new PageResult<>(orderVOs, pageResult.getTotal());
|
return new PageResult<>(orderVOs, pageResult.getTotal());
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user