Commit ec76c1ae6ecb068a213ce635ce8af50bf5e670c7
1 parent
3395a3d8
fix:【MALL】修复 addBrokerage 创建分销记录时,每个订单项,生成分销记录
Showing
5 changed files
with
26 additions
and
8 deletions
yudao-module-mall/yudao-module-product-api/src/main/java/cn/iocoder/yudao/module/product/api/sku/ProductSkuApi.java
| ... | ... | @@ -5,6 +5,9 @@ import cn.iocoder.yudao.module.product.api.sku.dto.ProductSkuUpdateStockReqDTO; |
| 5 | 5 | |
| 6 | 6 | import java.util.Collection; |
| 7 | 7 | import java.util.List; |
| 8 | +import java.util.Map; | |
| 9 | + | |
| 10 | +import static cn.iocoder.yudao.framework.common.util.collection.CollectionUtils.convertMap; | |
| 8 | 11 | |
| 9 | 12 | /** |
| 10 | 13 | * 商品 SKU API 接口 |
| ... | ... | @@ -31,6 +34,16 @@ public interface ProductSkuApi { |
| 31 | 34 | List<ProductSkuRespDTO> getSkuList(Collection<Long> ids); |
| 32 | 35 | |
| 33 | 36 | /** |
| 37 | + * 批量查询 SKU MAP | |
| 38 | + * | |
| 39 | + * @param ids SKU 编号列表 | |
| 40 | + * @return SKU MAP | |
| 41 | + */ | |
| 42 | + default Map<Long, ProductSkuRespDTO> getSkuMap(Collection<Long> ids) { | |
| 43 | + return convertMap(getSkuList(ids), ProductSkuRespDTO::getId); | |
| 44 | + } | |
| 45 | + | |
| 46 | + /** | |
| 34 | 47 | * 批量查询 SKU 数组 |
| 35 | 48 | * |
| 36 | 49 | * @param spuIds SPU 编号列表 | ... | ... |
yudao-module-mall/yudao-module-product-api/src/main/java/cn/iocoder/yudao/module/product/api/spu/ProductSpuApi.java
| ... | ... | @@ -30,7 +30,7 @@ public interface ProductSpuApi { |
| 30 | 30 | * @param ids SPU 编号列表 |
| 31 | 31 | * @return SPU MAP |
| 32 | 32 | */ |
| 33 | - default Map<Long, ProductSpuRespDTO> getSpusMap(Collection<Long> ids) { | |
| 33 | + default Map<Long, ProductSpuRespDTO> getSpuMap(Collection<Long> ids) { | |
| 34 | 34 | return convertMap(getSpuList(ids), ProductSpuRespDTO::getId); |
| 35 | 35 | } |
| 36 | 36 | ... | ... |
yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/controller/admin/point/PointActivityController.java
| ... | ... | @@ -124,7 +124,7 @@ public class PointActivityController { |
| 124 | 124 | List<PointProductDO> products = pointActivityService.getPointProductListByActivityIds( |
| 125 | 125 | convertSet(activityList, PointActivityDO::getId)); |
| 126 | 126 | Map<Long, List<PointProductDO>> productsMap = convertMultiMap(products, PointProductDO::getActivityId); |
| 127 | - Map<Long, ProductSpuRespDTO> spuMap = productSpuApi.getSpusMap( | |
| 127 | + Map<Long, ProductSpuRespDTO> spuMap = productSpuApi.getSpuMap( | |
| 128 | 128 | convertSet(activityList, PointActivityDO::getSpuId)); |
| 129 | 129 | List<PointActivityRespVO> result = BeanUtils.toBean(activityList, PointActivityRespVO.class); |
| 130 | 130 | result.forEach(activity -> { | ... | ... |
yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/controller/app/point/AppPointActivityController.java
| ... | ... | @@ -104,7 +104,7 @@ public class AppPointActivityController { |
| 104 | 104 | List<PointProductDO> products = pointActivityService.getPointProductListByActivityIds( |
| 105 | 105 | convertSet(activityList, PointActivityDO::getId)); |
| 106 | 106 | Map<Long, List<PointProductDO>> productsMap = convertMultiMap(products, PointProductDO::getActivityId); |
| 107 | - Map<Long, ProductSpuRespDTO> spuMap = productSpuApi.getSpusMap( | |
| 107 | + Map<Long, ProductSpuRespDTO> spuMap = productSpuApi.getSpuMap( | |
| 108 | 108 | convertSet(activityList, PointActivityDO::getSpuId)); |
| 109 | 109 | List<AppPointActivityRespVO> result = BeanUtils.toBean(activityList, AppPointActivityRespVO.class); |
| 110 | 110 | result.forEach(activity -> { | ... | ... |
yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/service/order/handler/TradeBrokerageOrderHandler.java
| ... | ... | @@ -20,6 +20,7 @@ import org.springframework.stereotype.Component; |
| 20 | 20 | |
| 21 | 21 | import jakarta.annotation.Resource; |
| 22 | 22 | import java.util.List; |
| 23 | +import java.util.Map; | |
| 23 | 24 | |
| 24 | 25 | import static cn.iocoder.yudao.framework.common.util.collection.CollectionUtils.convertList; |
| 25 | 26 | |
| ... | ... | @@ -101,13 +102,17 @@ public class TradeBrokerageOrderHandler implements TradeOrderHandler { |
| 101 | 102 | protected void addBrokerage(Long userId, List<TradeOrderItemDO> orderItems) { |
| 102 | 103 | MemberUserRespDTO user = memberUserApi.getUser(userId); |
| 103 | 104 | Assert.notNull(user); |
| 104 | - ProductSpuRespDTO spu = productSpuApi.getSpu(orderItems.get(0).getSpuId()); | |
| 105 | - Assert.notNull(spu); | |
| 106 | - ProductSkuRespDTO sku = productSkuApi.getSku(orderItems.get(0).getSkuId()); | |
| 105 | + Map<Long, ProductSpuRespDTO> spusMap = productSpuApi.getSpuMap(convertList(orderItems, TradeOrderItemDO::getSpuId)); | |
| 106 | + Map<Long, ProductSkuRespDTO> skusMap = productSkuApi.getSkuMap(convertList(orderItems, TradeOrderItemDO::getSkuId)); | |
| 107 | 107 | |
| 108 | 108 | // 每一个订单项,都会去生成分销记录 |
| 109 | - List<BrokerageAddReqBO> addList = convertList(orderItems, | |
| 110 | - item -> TradeOrderConvert.INSTANCE.convert(user, item, spu, sku)); | |
| 109 | + List<BrokerageAddReqBO> addList = convertList(orderItems, item -> { | |
| 110 | + ProductSpuRespDTO spu = spusMap.get(item.getSpuId()); | |
| 111 | + Assert.notNull(spu); | |
| 112 | + ProductSkuRespDTO sku = skusMap.get(item.getSkuId()); | |
| 113 | + Assert.notNull(sku); | |
| 114 | + return TradeOrderConvert.INSTANCE.convert(user, item, spu, sku); | |
| 115 | + }); | |
| 111 | 116 | brokerageRecordService.addBrokerage(userId, BrokerageRecordBizTypeEnum.ORDER, addList); |
| 112 | 117 | } |
| 113 | 118 | ... | ... |