Commit fe07e223e4403f1797ea5c5f08f73c18d80d0d49
1 parent
f217ba08
订单:
1、简化交易订单的逻辑
Showing
3 changed files
with
13 additions
and
91 deletions
yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/controller/admin/order/TradeOrderController.java
| ... | ... | @@ -5,8 +5,6 @@ import cn.iocoder.yudao.framework.common.pojo.CommonResult; |
| 5 | 5 | import cn.iocoder.yudao.framework.common.pojo.PageResult; |
| 6 | 6 | import cn.iocoder.yudao.module.member.api.user.MemberUserApi; |
| 7 | 7 | import cn.iocoder.yudao.module.member.api.user.dto.MemberUserRespDTO; |
| 8 | -import cn.iocoder.yudao.module.product.api.property.ProductPropertyValueApi; | |
| 9 | -import cn.iocoder.yudao.module.product.api.property.dto.ProductPropertyValueDetailRespDTO; | |
| 10 | 8 | import cn.iocoder.yudao.module.trade.controller.admin.order.vo.TradeOrderDeliveryReqVO; |
| 11 | 9 | import cn.iocoder.yudao.module.trade.controller.admin.order.vo.TradeOrderDetailRespVO; |
| 12 | 10 | import cn.iocoder.yudao.module.trade.controller.admin.order.vo.TradeOrderPageItemRespVO; |
| ... | ... | @@ -45,8 +43,6 @@ public class TradeOrderController { |
| 45 | 43 | private TradeOrderQueryService tradeOrderQueryService; |
| 46 | 44 | |
| 47 | 45 | @Resource |
| 48 | - private ProductPropertyValueApi productPropertyValueApi; | |
| 49 | - @Resource | |
| 50 | 46 | private MemberUserApi memberUserApi; |
| 51 | 47 | |
| 52 | 48 | @GetMapping("/page") |
| ... | ... | @@ -64,11 +60,8 @@ public class TradeOrderController { |
| 64 | 60 | // 查询订单项 |
| 65 | 61 | List<TradeOrderItemDO> orderItems = tradeOrderQueryService.getOrderItemListByOrderId( |
| 66 | 62 | convertSet(pageResult.getList(), TradeOrderDO::getId)); |
| 67 | - // 查询商品属性 | |
| 68 | - List<ProductPropertyValueDetailRespDTO> propertyValueDetails = productPropertyValueApi | |
| 69 | - .getPropertyValueDetailList(TradeOrderConvert.INSTANCE.convertPropertyValueIds(orderItems)); | |
| 70 | 63 | // 最终组合 |
| 71 | - return success(TradeOrderConvert.INSTANCE.convertPage(pageResult, orderItems, propertyValueDetails, userMap)); | |
| 64 | + return success(TradeOrderConvert.INSTANCE.convertPage(pageResult, orderItems, userMap)); | |
| 72 | 65 | } |
| 73 | 66 | |
| 74 | 67 | @GetMapping("/get-detail") |
| ... | ... | @@ -80,13 +73,10 @@ public class TradeOrderController { |
| 80 | 73 | TradeOrderDO order = tradeOrderQueryService.getOrder(id); |
| 81 | 74 | // 查询订单项 |
| 82 | 75 | List<TradeOrderItemDO> orderItems = tradeOrderQueryService.getOrderItemListByOrderId(id); |
| 83 | - // 查询商品属性 | |
| 84 | - List<ProductPropertyValueDetailRespDTO> propertyValueDetails = productPropertyValueApi | |
| 85 | - .getPropertyValueDetailList(TradeOrderConvert.INSTANCE.convertPropertyValueIds(orderItems)); | |
| 86 | - // 查询会员 | |
| 76 | + | |
| 77 | + // 拼接数据 | |
| 87 | 78 | MemberUserRespDTO user = memberUserApi.getUser(order.getUserId()); |
| 88 | - // 最终组合 | |
| 89 | - return success(TradeOrderConvert.INSTANCE.convert(order, orderItems, propertyValueDetails, user)); | |
| 79 | + return success(TradeOrderConvert.INSTANCE.convert(order, orderItems, user)); | |
| 90 | 80 | } |
| 91 | 81 | |
| 92 | 82 | @PostMapping("/delivery") | ... | ... |
yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/controller/app/order/AppTradeOrderController.java
| ... | ... | @@ -118,11 +118,8 @@ public class AppTradeOrderController { |
| 118 | 118 | // 查询订单项 |
| 119 | 119 | List<TradeOrderItemDO> orderItems = tradeOrderQueryService.getOrderItemListByOrderId( |
| 120 | 120 | convertSet(pageResult.getList(), TradeOrderDO::getId)); |
| 121 | - // 查询商品属性 | |
| 122 | - List<ProductPropertyValueDetailRespDTO> propertyValueDetails = productPropertyValueApi | |
| 123 | - .getPropertyValueDetailList(TradeOrderConvert.INSTANCE.convertPropertyValueIds(orderItems)); | |
| 124 | 121 | // 最终组合 |
| 125 | - return success(TradeOrderConvert.INSTANCE.convertPage02(pageResult, orderItems, propertyValueDetails)); | |
| 122 | + return success(TradeOrderConvert.INSTANCE.convertPage02(pageResult, orderItems)); | |
| 126 | 123 | } |
| 127 | 124 | |
| 128 | 125 | @GetMapping("/get-count") | ... | ... |
yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/convert/order/TradeOrderConvert.java
| ... | ... | @@ -14,7 +14,6 @@ import cn.iocoder.yudao.module.product.api.comment.dto.ProductCommentCreateReqDT |
| 14 | 14 | import cn.iocoder.yudao.module.product.api.property.dto.ProductPropertyValueDetailRespDTO; |
| 15 | 15 | import cn.iocoder.yudao.module.product.api.sku.dto.ProductSkuUpdateStockReqDTO; |
| 16 | 16 | import cn.iocoder.yudao.module.promotion.api.combination.dto.CombinationRecordCreateReqDTO; |
| 17 | -import cn.iocoder.yudao.module.promotion.api.price.dto.PriceCalculateReqDTO; | |
| 18 | 17 | import cn.iocoder.yudao.module.trade.api.order.dto.TradeOrderRespDTO; |
| 19 | 18 | import cn.iocoder.yudao.module.trade.controller.admin.base.member.user.MemberUserRespVO; |
| 20 | 19 | import cn.iocoder.yudao.module.trade.controller.admin.base.product.property.ProductPropertyValueDetailRespVO; |
| ... | ... | @@ -84,9 +83,6 @@ public interface TradeOrderConvert { |
| 84 | 83 | |
| 85 | 84 | TradeOrderItemDO convert(TradePriceCalculateRespBO.OrderItem item); |
| 86 | 85 | |
| 87 | - @Mapping(source = "userId", target = "userId") | |
| 88 | - PriceCalculateReqDTO convert(AppTradeOrderCreateReqVO createReqVO, Long userId); | |
| 89 | - | |
| 90 | 86 | @Mappings({ |
| 91 | 87 | @Mapping(source = "skuId", target = "id"), |
| 92 | 88 | @Mapping(source = "count", target = "incrCount"), |
| ... | ... | @@ -123,38 +119,18 @@ public interface TradeOrderConvert { |
| 123 | 119 | } |
| 124 | 120 | |
| 125 | 121 | // TODO 芋艿:可简化 |
| 126 | - default PageResult<TradeOrderPageItemRespVO> convertPage(PageResult<TradeOrderDO> pageResult, List<TradeOrderItemDO> orderItems, | |
| 127 | - List<ProductPropertyValueDetailRespDTO> propertyValueDetails, | |
| 128 | - Map<Long, MemberUserRespDTO> memberUserRespDTOMap) { | |
| 122 | + default PageResult<TradeOrderPageItemRespVO> convertPage(PageResult<TradeOrderDO> pageResult, | |
| 123 | + List<TradeOrderItemDO> orderItems, | |
| 124 | + Map<Long, MemberUserRespDTO> memberUserMap) { | |
| 129 | 125 | Map<Long, List<TradeOrderItemDO>> orderItemMap = convertMultiMap(orderItems, TradeOrderItemDO::getOrderId); |
| 130 | - Map<Long, ProductPropertyValueDetailRespDTO> propertyValueDetailMap = convertMap(propertyValueDetails, ProductPropertyValueDetailRespDTO::getValueId); | |
| 131 | 126 | // 转化 List |
| 132 | 127 | List<TradeOrderPageItemRespVO> orderVOs = CollectionUtils.convertList(pageResult.getList(), order -> { |
| 133 | 128 | List<TradeOrderItemDO> xOrderItems = orderItemMap.get(order.getId()); |
| 134 | 129 | TradeOrderPageItemRespVO orderVO = convert(order, xOrderItems); |
| 135 | - if (CollUtil.isNotEmpty(xOrderItems)) { | |
| 136 | - // 处理商品属性 | |
| 137 | - for (int i = 0; i < xOrderItems.size(); i++) { | |
| 138 | - List<TradeOrderItemDO.Property> properties = xOrderItems.get(i).getProperties(); | |
| 139 | - if (CollUtil.isEmpty(properties)) { | |
| 140 | - continue; | |
| 141 | - } | |
| 142 | - TradeOrderPageItemRespVO.Item item = orderVO.getItems().get(i); | |
| 143 | - item.setProperties(new ArrayList<>(properties.size())); | |
| 144 | - // 遍历每个 properties,设置到 TradeOrderPageItemRespVO.Item 中 | |
| 145 | - properties.forEach(property -> { | |
| 146 | - ProductPropertyValueDetailRespDTO propertyValueDetail = propertyValueDetailMap.get(property.getValueId()); | |
| 147 | - if (propertyValueDetail == null) { | |
| 148 | - return; | |
| 149 | - } | |
| 150 | - item.getProperties().add(convert(propertyValueDetail)); | |
| 151 | - }); | |
| 152 | - } | |
| 153 | - } | |
| 154 | 130 | // 处理收货地址 |
| 155 | 131 | orderVO.setReceiverAreaName(AreaUtils.format(order.getReceiverAreaId())); |
| 156 | 132 | // 增加用户昵称 |
| 157 | - orderVO.setUser(memberUserRespDTOMap.get(orderVO.getUserId())); | |
| 133 | + orderVO.setUser(memberUserMap.get(orderVO.getUserId())); | |
| 158 | 134 | return orderVO; |
| 159 | 135 | }); |
| 160 | 136 | return new PageResult<>(orderVOs, pageResult.getTotal()); |
| ... | ... | @@ -164,28 +140,9 @@ public interface TradeOrderConvert { |
| 164 | 140 | |
| 165 | 141 | ProductPropertyValueDetailRespVO convert(ProductPropertyValueDetailRespDTO bean); |
| 166 | 142 | |
| 167 | - // TODO 芋艿:可简化 | |
| 168 | 143 | default TradeOrderDetailRespVO convert(TradeOrderDO order, List<TradeOrderItemDO> orderItems, |
| 169 | - List<ProductPropertyValueDetailRespDTO> propertyValueDetails, MemberUserRespDTO user) { | |
| 144 | + MemberUserRespDTO user) { | |
| 170 | 145 | TradeOrderDetailRespVO orderVO = convert2(order, orderItems); |
| 171 | - // 处理商品属性 | |
| 172 | - Map<Long, ProductPropertyValueDetailRespDTO> propertyValueDetailMap = convertMap(propertyValueDetails, ProductPropertyValueDetailRespDTO::getValueId); | |
| 173 | - for (int i = 0; i < orderItems.size(); i++) { | |
| 174 | - List<TradeOrderItemDO.Property> properties = orderItems.get(i).getProperties(); | |
| 175 | - if (CollUtil.isEmpty(properties)) { | |
| 176 | - continue; | |
| 177 | - } | |
| 178 | - TradeOrderDetailRespVO.Item item = orderVO.getItems().get(i); | |
| 179 | - item.setProperties(new ArrayList<>(properties.size())); | |
| 180 | - // 遍历每个 properties,设置到 TradeOrderPageItemRespVO.Item 中 | |
| 181 | - properties.forEach(property -> { | |
| 182 | - ProductPropertyValueDetailRespDTO propertyValueDetail = propertyValueDetailMap.get(property.getValueId()); | |
| 183 | - if (propertyValueDetail == null) { | |
| 184 | - return; | |
| 185 | - } | |
| 186 | - item.getProperties().add(convert(propertyValueDetail)); | |
| 187 | - }); | |
| 188 | - } | |
| 189 | 146 | // 处理收货地址 |
| 190 | 147 | orderVO.setReceiverAreaName(AreaUtils.format(order.getReceiverAreaId())); |
| 191 | 148 | // 处理用户信息 |
| ... | ... | @@ -197,35 +154,13 @@ public interface TradeOrderConvert { |
| 197 | 154 | |
| 198 | 155 | MemberUserRespVO convert(MemberUserRespDTO bean); |
| 199 | 156 | |
| 200 | - // TODO 芋艿:可简化 | |
| 201 | - default PageResult<AppTradeOrderPageItemRespVO> convertPage02(PageResult<TradeOrderDO> pageResult, List<TradeOrderItemDO> orderItems, | |
| 202 | - List<ProductPropertyValueDetailRespDTO> propertyValueDetails) { | |
| 157 | + default PageResult<AppTradeOrderPageItemRespVO> convertPage02(PageResult<TradeOrderDO> pageResult, | |
| 158 | + List<TradeOrderItemDO> orderItems) { | |
| 203 | 159 | Map<Long, List<TradeOrderItemDO>> orderItemMap = convertMultiMap(orderItems, TradeOrderItemDO::getOrderId); |
| 204 | - Map<Long, ProductPropertyValueDetailRespDTO> propertyValueDetailMap = convertMap(propertyValueDetails, ProductPropertyValueDetailRespDTO::getValueId); | |
| 205 | 160 | // 转化 List |
| 206 | 161 | List<AppTradeOrderPageItemRespVO> orderVOs = CollectionUtils.convertList(pageResult.getList(), order -> { |
| 207 | 162 | List<TradeOrderItemDO> xOrderItems = orderItemMap.get(order.getId()); |
| 208 | - AppTradeOrderPageItemRespVO orderVO = convert02(order, xOrderItems); | |
| 209 | - if (CollUtil.isNotEmpty(xOrderItems)) { | |
| 210 | - // 处理商品属性 | |
| 211 | - for (int i = 0; i < xOrderItems.size(); i++) { | |
| 212 | - List<TradeOrderItemDO.Property> properties = xOrderItems.get(i).getProperties(); | |
| 213 | - if (CollUtil.isEmpty(properties)) { | |
| 214 | - continue; | |
| 215 | - } | |
| 216 | - AppTradeOrderItemRespVO item = orderVO.getItems().get(i); | |
| 217 | - item.setProperties(new ArrayList<>(properties.size())); | |
| 218 | - // 遍历每个 properties,设置到 TradeOrderPageItemRespVO.Item 中 | |
| 219 | - properties.forEach(property -> { | |
| 220 | - ProductPropertyValueDetailRespDTO propertyValueDetail = propertyValueDetailMap.get(property.getValueId()); | |
| 221 | - if (propertyValueDetail == null) { | |
| 222 | - return; | |
| 223 | - } | |
| 224 | - item.getProperties().add(convert02(propertyValueDetail)); | |
| 225 | - }); | |
| 226 | - } | |
| 227 | - } | |
| 228 | - return orderVO; | |
| 163 | + return convert02(order, xOrderItems); | |
| 229 | 164 | }); |
| 230 | 165 | return new PageResult<>(orderVOs, pageResult.getTotal()); |
| 231 | 166 | } | ... | ... |