From a159a983a2da801b654c84f74f34645e073902fd Mon Sep 17 00:00:00 2001 From: YunaiV Date: Tue, 15 Aug 2023 21:19:13 +0800 Subject: [PATCH] =?UTF-8?q?=E8=AE=A2=E5=8D=95=EF=BC=9A=201.=20=E6=8B=86?= =?UTF-8?q?=E5=88=86=E8=AF=BB=E5=86=99=20OrderService=EF=BC=8C=E9=81=BF?= =?UTF-8?q?=E5=85=8D=E5=8D=95=20Service=20=E9=80=BB=E8=BE=91=E8=BF=87?= =?UTF-8?q?=E9=87=8D=E3=80=82?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../trade/api/order/TradeOrderApiImpl.java | 6 +- .../admin/order/TradeOrderController.java | 17 +- .../app/order/AppTradeOrderController.java | 34 ++-- .../dal/mysql/order/TradeOrderItemMapper.java | 3 +- .../aftersale/TradeAfterSaleServiceImpl.java | 23 ++- .../service/order/TradeOrderQueryService.java | 91 +++++++++ .../order/TradeOrderQueryServiceImpl.java | 93 ++++++++- .../service/order/TradeOrderService.java | 190 ------------------ .../order/TradeOrderUpdateService.java | 85 ++++++++ ....java => TradeOrderUpdateServiceImpl.java} | 106 +--------- .../aftersale/TradeAfterSaleServiceTest.java | 4 +- ....java => TradeOrderUpdateServiceTest.java} | 16 +- 12 files changed, 333 insertions(+), 335 deletions(-) delete mode 100644 yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/service/order/TradeOrderService.java create mode 100644 yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/service/order/TradeOrderUpdateService.java rename yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/service/order/{TradeOrderServiceImpl.java => TradeOrderUpdateServiceImpl.java} (87%) rename yudao-module-mall/yudao-module-trade-biz/src/test/java/cn/iocoder/yudao/module/trade/service/order/{TradeOrderServiceTest.java => TradeOrderUpdateServiceTest.java} (96%) diff --git a/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/api/order/TradeOrderApiImpl.java b/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/api/order/TradeOrderApiImpl.java index 1909f71ca..7895386cf 100644 --- a/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/api/order/TradeOrderApiImpl.java +++ b/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/api/order/TradeOrderApiImpl.java @@ -1,7 +1,7 @@ package cn.iocoder.yudao.module.trade.api.order; import cn.iocoder.yudao.module.trade.dal.dataobject.order.TradeOrderItemDO; -import cn.iocoder.yudao.module.trade.service.order.TradeOrderService; +import cn.iocoder.yudao.module.trade.service.order.TradeOrderQueryService; import org.springframework.stereotype.Service; import org.springframework.validation.annotation.Validated; @@ -20,12 +20,12 @@ import static cn.iocoder.yudao.module.trade.enums.ErrorCodeConstants.ORDER_ITEM_ public class TradeOrderApiImpl implements TradeOrderApi { @Resource - private TradeOrderService tradeOrderService; + private TradeOrderQueryService tradeOrderQueryService; @Override public Long validateOrder(Long userId, Long orderItemId) { // 校验订单项,订单项存在订单就存在 - TradeOrderItemDO item = tradeOrderService.getOrderItem(userId, orderItemId); + TradeOrderItemDO item = tradeOrderQueryService.getOrderItem(userId, orderItemId); if (item == null) { throw exception(ORDER_ITEM_NOT_FOUND); } diff --git a/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/controller/admin/order/TradeOrderController.java b/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/controller/admin/order/TradeOrderController.java index 6dc8f2b7b..786be10d7 100644 --- a/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/controller/admin/order/TradeOrderController.java +++ b/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/controller/admin/order/TradeOrderController.java @@ -14,7 +14,8 @@ import cn.iocoder.yudao.module.trade.controller.admin.order.vo.TradeOrderPageReq import cn.iocoder.yudao.module.trade.convert.order.TradeOrderConvert; import cn.iocoder.yudao.module.trade.dal.dataobject.order.TradeOrderDO; import cn.iocoder.yudao.module.trade.dal.dataobject.order.TradeOrderItemDO; -import cn.iocoder.yudao.module.trade.service.order.TradeOrderService; +import cn.iocoder.yudao.module.trade.service.order.TradeOrderQueryService; +import cn.iocoder.yudao.module.trade.service.order.TradeOrderUpdateService; import io.swagger.v3.oas.annotations.Operation; import io.swagger.v3.oas.annotations.Parameter; import io.swagger.v3.oas.annotations.tags.Tag; @@ -39,7 +40,9 @@ import static cn.iocoder.yudao.framework.security.core.util.SecurityFrameworkUti public class TradeOrderController { @Resource - private TradeOrderService tradeOrderService; + private TradeOrderUpdateService tradeOrderUpdateService; + @Resource + private TradeOrderQueryService tradeOrderQueryService; @Resource private ProductPropertyValueApi productPropertyValueApi; @@ -51,7 +54,7 @@ public class TradeOrderController { @PreAuthorize("@ss.hasPermission('trade:order:query')") public CommonResult> getOrderPage(TradeOrderPageReqVO reqVO) { // 查询订单 - PageResult pageResult = tradeOrderService.getOrderPage(reqVO); + PageResult pageResult = tradeOrderQueryService.getOrderPage(reqVO); if (CollUtil.isEmpty(pageResult.getList())) { return success(PageResult.empty()); } @@ -59,7 +62,7 @@ public class TradeOrderController { // 查询用户信息 Map userMap = memberUserApi.getUserMap(convertSet(pageResult.getList(), TradeOrderDO::getUserId));; // 查询订单项 - List orderItems = tradeOrderService.getOrderItemListByOrderId( + List orderItems = tradeOrderQueryService.getOrderItemListByOrderId( convertSet(pageResult.getList(), TradeOrderDO::getId)); // 查询商品属性 List propertyValueDetails = productPropertyValueApi @@ -74,9 +77,9 @@ public class TradeOrderController { @PreAuthorize("@ss.hasPermission('trade:order:query')") public CommonResult getOrderDetail(@RequestParam("id") Long id) { // 查询订单 - TradeOrderDO order = tradeOrderService.getOrder(id); + TradeOrderDO order = tradeOrderQueryService.getOrder(id); // 查询订单项 - List orderItems = tradeOrderService.getOrderItemListByOrderId(id); + List orderItems = tradeOrderQueryService.getOrderItemListByOrderId(id); // 查询商品属性 List propertyValueDetails = productPropertyValueApi .getPropertyValueDetailList(TradeOrderConvert.INSTANCE.convertPropertyValueIds(orderItems)); @@ -90,7 +93,7 @@ public class TradeOrderController { @Operation(summary = "发货订单") @PreAuthorize("@ss.hasPermission('trade:order:delivery')") public CommonResult deliveryOrder(@RequestBody TradeOrderDeliveryReqVO deliveryReqVO) { - tradeOrderService.deliveryOrder(getLoginUserId(), deliveryReqVO); + tradeOrderUpdateService.deliveryOrder(getLoginUserId(), deliveryReqVO); return success(true); } diff --git a/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/controller/app/order/AppTradeOrderController.java b/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/controller/app/order/AppTradeOrderController.java index 2de3527b0..6456db122 100644 --- a/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/controller/app/order/AppTradeOrderController.java +++ b/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/controller/app/order/AppTradeOrderController.java @@ -17,7 +17,7 @@ import cn.iocoder.yudao.module.trade.enums.order.TradeOrderStatusEnum; import cn.iocoder.yudao.module.trade.framework.order.config.TradeOrderProperties; import cn.iocoder.yudao.module.trade.service.delivery.DeliveryExpressService; import cn.iocoder.yudao.module.trade.service.order.TradeOrderQueryService; -import cn.iocoder.yudao.module.trade.service.order.TradeOrderService; +import cn.iocoder.yudao.module.trade.service.order.TradeOrderUpdateService; import com.google.common.collect.Maps; import io.swagger.v3.oas.annotations.Operation; import io.swagger.v3.oas.annotations.Parameter; @@ -44,7 +44,7 @@ import static cn.iocoder.yudao.framework.security.core.util.SecurityFrameworkUti public class AppTradeOrderController { @Resource - private TradeOrderService tradeOrderService; + private TradeOrderUpdateService tradeOrderUpdateService; @Resource private TradeOrderQueryService tradeOrderQueryService; @Resource @@ -60,21 +60,21 @@ public class AppTradeOrderController { @Operation(summary = "获得订单结算信息") @PreAuthenticated public CommonResult settlementOrder(@Valid AppTradeOrderSettlementReqVO settlementReqVO) { - return success(tradeOrderService.settlementOrder(getLoginUserId(), settlementReqVO)); + return success(tradeOrderUpdateService.settlementOrder(getLoginUserId(), settlementReqVO)); } @PostMapping("/create") @Operation(summary = "创建订单") @PreAuthenticated public CommonResult createOrder(@RequestBody AppTradeOrderCreateReqVO createReqVO) { - TradeOrderDO order = tradeOrderService.createOrder(getLoginUserId(), getClientIP(), createReqVO); + TradeOrderDO order = tradeOrderUpdateService.createOrder(getLoginUserId(), getClientIP(), createReqVO); return success(new AppTradeOrderCreateRespVO().setId(order.getId()).setPayOrderId(order.getPayOrderId())); } @PostMapping("/update-paid") @Operation(summary = "更新订单为已支付") // 由 pay-module 支付服务,进行回调,可见 PayNotifyJob public CommonResult updateOrderPaid(@RequestBody PayOrderNotifyReqDTO notifyReqDTO) { - tradeOrderService.updateOrderPaid(Long.valueOf(notifyReqDTO.getMerchantOrderId()), + tradeOrderUpdateService.updateOrderPaid(Long.valueOf(notifyReqDTO.getMerchantOrderId()), notifyReqDTO.getPayOrderId()); return success(true); } @@ -84,13 +84,13 @@ public class AppTradeOrderController { @Parameter(name = "id", description = "交易订单编号") public CommonResult getOrder(@RequestParam("id") Long id) { // 查询订单 - TradeOrderDO order = tradeOrderService.getOrder(getLoginUserId(), id); + TradeOrderDO order = tradeOrderQueryService.getOrder(getLoginUserId(), id); if (order == null) { return success(null); } // 查询订单项 - List orderItems = tradeOrderService.getOrderItemListByOrderId(order.getId()); + List orderItems = tradeOrderQueryService.getOrderItemListByOrderId(order.getId()); // 查询商品属性 List propertyValueDetails = productPropertyValueApi .getPropertyValueDetailList(TradeOrderConvert.INSTANCE.convertPropertyValueIds(orderItems)); @@ -114,9 +114,9 @@ public class AppTradeOrderController { @Operation(summary = "获得交易订单分页") public CommonResult> getOrderPage(AppTradeOrderPageReqVO reqVO) { // 查询订单 - PageResult pageResult = tradeOrderService.getOrderPage(getLoginUserId(), reqVO); + PageResult pageResult = tradeOrderQueryService.getOrderPage(getLoginUserId(), reqVO); // 查询订单项 - List orderItems = tradeOrderService.getOrderItemListByOrderId( + List orderItems = tradeOrderQueryService.getOrderItemListByOrderId( convertSet(pageResult.getList(), TradeOrderDO::getId)); // 查询商品属性 List propertyValueDetails = productPropertyValueApi @@ -130,18 +130,18 @@ public class AppTradeOrderController { public CommonResult> getOrderCount() { Map orderCount = Maps.newLinkedHashMapWithExpectedSize(5); // 全部 - orderCount.put("allCount", tradeOrderService.getOrderCount(getLoginUserId(), null, null)); + orderCount.put("allCount", tradeOrderQueryService.getOrderCount(getLoginUserId(), null, null)); // 待付款(未支付) - orderCount.put("unpaidCount", tradeOrderService.getOrderCount(getLoginUserId(), + orderCount.put("unpaidCount", tradeOrderQueryService.getOrderCount(getLoginUserId(), TradeOrderStatusEnum.UNPAID.getStatus(), null)); // 待发货 - orderCount.put("undeliveredCount", tradeOrderService.getOrderCount(getLoginUserId(), + orderCount.put("undeliveredCount", tradeOrderQueryService.getOrderCount(getLoginUserId(), TradeOrderStatusEnum.UNDELIVERED.getStatus(), null)); // 待收货 - orderCount.put("deliveredCount", tradeOrderService.getOrderCount(getLoginUserId(), + orderCount.put("deliveredCount", tradeOrderQueryService.getOrderCount(getLoginUserId(), TradeOrderStatusEnum.DELIVERED.getStatus(), null)); // 待评价 - orderCount.put("uncommentedCount", tradeOrderService.getOrderCount(getLoginUserId(), + orderCount.put("uncommentedCount", tradeOrderQueryService.getOrderCount(getLoginUserId(), TradeOrderStatusEnum.COMPLETED.getStatus(), false)); return success(orderCount); } @@ -150,7 +150,7 @@ public class AppTradeOrderController { @Operation(summary = "确认交易订单收货") @Parameter(name = "id", description = "交易订单编号") public CommonResult takeOrder(@RequestParam("id") Long id) { - tradeOrderService.receiveOrder(getLoginUserId(), id); + tradeOrderUpdateService.receiveOrder(getLoginUserId(), id); return success(true); } @@ -176,14 +176,14 @@ public class AppTradeOrderController { @Operation(summary = "获得交易订单项") @Parameter(name = "id", description = "交易订单项编号") public CommonResult getOrderItem(@RequestParam("id") Long id) { - TradeOrderItemDO item = tradeOrderService.getOrderItem(getLoginUserId(), id); + TradeOrderItemDO item = tradeOrderQueryService.getOrderItem(getLoginUserId(), id); return success(TradeOrderConvert.INSTANCE.convert03(item)); } @PostMapping("/item/create-comment") @Operation(summary = "创建交易订单项的评价") public CommonResult createOrderItemComment(@RequestBody AppTradeOrderItemCommentCreateReqVO createReqVO) { - return success(tradeOrderService.createOrderItemComment(createReqVO)); + return success(tradeOrderUpdateService.createOrderItemComment(getLoginUserId(), createReqVO)); } } diff --git a/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/dal/mysql/order/TradeOrderItemMapper.java b/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/dal/mysql/order/TradeOrderItemMapper.java index 553bd5697..ee8b8b1a5 100644 --- a/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/dal/mysql/order/TradeOrderItemMapper.java +++ b/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/dal/mysql/order/TradeOrderItemMapper.java @@ -31,9 +31,10 @@ public interface TradeOrderItemMapper extends BaseMapperX { .eq(TradeOrderItemDO::getSkuId, skuIds)); } - default TradeOrderItemDO selectOrderItemByIdAndUserId(Long orderItemId, Long loginUserId) { + default TradeOrderItemDO selectByIdAndUserId(Long orderItemId, Long loginUserId) { return selectOne(new LambdaQueryWrapperX() .eq(TradeOrderItemDO::getId, orderItemId) .eq(TradeOrderItemDO::getUserId, loginUserId)); } + } diff --git a/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/service/aftersale/TradeAfterSaleServiceImpl.java b/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/service/aftersale/TradeAfterSaleServiceImpl.java index ab94fb7a2..f7c93d56c 100644 --- a/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/service/aftersale/TradeAfterSaleServiceImpl.java +++ b/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/service/aftersale/TradeAfterSaleServiceImpl.java @@ -27,7 +27,8 @@ import cn.iocoder.yudao.module.trade.enums.order.TradeOrderStatusEnum; import cn.iocoder.yudao.module.trade.framework.aftersalelog.core.dto.TradeAfterSaleLogCreateReqDTO; import cn.iocoder.yudao.module.trade.framework.aftersalelog.core.service.AfterSaleLogService; import cn.iocoder.yudao.module.trade.framework.order.config.TradeOrderProperties; -import cn.iocoder.yudao.module.trade.service.order.TradeOrderService; +import cn.iocoder.yudao.module.trade.service.order.TradeOrderQueryService; +import cn.iocoder.yudao.module.trade.service.order.TradeOrderUpdateService; import lombok.extern.slf4j.Slf4j; import org.springframework.scheduling.annotation.Async; import org.springframework.stereotype.Service; @@ -54,7 +55,9 @@ import static cn.iocoder.yudao.module.trade.enums.ErrorCodeConstants.*; public class TradeAfterSaleServiceImpl implements TradeAfterSaleService, AfterSaleLogService { @Resource - private TradeOrderService tradeOrderService; + private TradeOrderUpdateService tradeOrderUpdateService; + @Resource + private TradeOrderQueryService tradeOrderQueryService; @Resource private TradeAfterSaleMapper tradeAfterSaleMapper; @@ -92,7 +95,7 @@ public class TradeAfterSaleServiceImpl implements TradeAfterSaleService, AfterSa */ private TradeOrderItemDO validateOrderItemApplicable(Long userId, AppTradeAfterSaleCreateReqVO createReqVO) { // 校验订单项存在 - TradeOrderItemDO orderItem = tradeOrderService.getOrderItem(userId, createReqVO.getOrderItemId()); + TradeOrderItemDO orderItem = tradeOrderQueryService.getOrderItem(userId, createReqVO.getOrderItemId()); if (orderItem == null) { throw exception(ORDER_ITEM_NOT_FOUND); } @@ -108,7 +111,7 @@ public class TradeAfterSaleServiceImpl implements TradeAfterSaleService, AfterSa } // 校验订单存在 - TradeOrderDO order = tradeOrderService.getOrder(userId, orderItem.getOrderId()); + TradeOrderDO order = tradeOrderQueryService.getOrder(userId, orderItem.getOrderId()); if (order == null) { throw exception(ORDER_NOT_FOUND); } @@ -136,7 +139,7 @@ public class TradeAfterSaleServiceImpl implements TradeAfterSaleService, AfterSa afterSale.setNo(RandomUtil.randomString(10)); // TODO 芋艿:优化 no 生成逻辑 afterSale.setStatus(TradeAfterSaleStatusEnum.APPLY.getStatus()); // 标记是售中还是售后 - TradeOrderDO order = tradeOrderService.getOrder(orderItem.getUserId(), orderItem.getOrderId()); + TradeOrderDO order = tradeOrderQueryService.getOrder(orderItem.getUserId(), orderItem.getOrderId()); afterSale.setOrderNo(order.getNo()); // 记录 orderNo 订单流水,方便后续检索 afterSale.setType(TradeOrderStatusEnum.isCompleted(order.getStatus()) ? TradeAfterSaleTypeEnum.AFTER_SALE.getType() : TradeAfterSaleTypeEnum.IN_SALE.getType()); @@ -144,7 +147,7 @@ public class TradeAfterSaleServiceImpl implements TradeAfterSaleService, AfterSa tradeAfterSaleMapper.insert(afterSale); // 更新交易订单项的售后状态 - tradeOrderService.updateOrderItemAfterSaleStatus(orderItem.getId(), + tradeOrderUpdateService.updateOrderItemAfterSaleStatus(orderItem.getId(), TradeOrderItemAfterSaleStatusEnum.NONE.getStatus(), TradeOrderItemAfterSaleStatusEnum.APPLY.getStatus(), null); @@ -196,7 +199,7 @@ public class TradeAfterSaleServiceImpl implements TradeAfterSaleService, AfterSa // TODO 发送售后消息 // 更新交易订单项的售后状态为【未申请】 - tradeOrderService.updateOrderItemAfterSaleStatus(afterSale.getOrderItemId(), + tradeOrderUpdateService.updateOrderItemAfterSaleStatus(afterSale.getOrderItemId(), TradeOrderItemAfterSaleStatusEnum.APPLY.getStatus(), TradeOrderItemAfterSaleStatusEnum.NONE.getStatus(), null); } @@ -291,7 +294,7 @@ public class TradeAfterSaleServiceImpl implements TradeAfterSaleService, AfterSa // TODO 发送售后消息 // 更新交易订单项的售后状态为【未申请】 - tradeOrderService.updateOrderItemAfterSaleStatus(afterSale.getOrderItemId(), + tradeOrderUpdateService.updateOrderItemAfterSaleStatus(afterSale.getOrderItemId(), TradeOrderItemAfterSaleStatusEnum.APPLY.getStatus(), TradeOrderItemAfterSaleStatusEnum.NONE.getStatus(), null); } @@ -339,7 +342,7 @@ public class TradeAfterSaleServiceImpl implements TradeAfterSaleService, AfterSa // TODO 发送售后消息 // 更新交易订单项的售后状态为【已完成】 - tradeOrderService.updateOrderItemAfterSaleStatus(afterSale.getOrderItemId(), + tradeOrderUpdateService.updateOrderItemAfterSaleStatus(afterSale.getOrderItemId(), TradeOrderItemAfterSaleStatusEnum.APPLY.getStatus(), TradeOrderItemAfterSaleStatusEnum.SUCCESS.getStatus(), afterSale.getRefundPrice()); } @@ -381,7 +384,7 @@ public class TradeAfterSaleServiceImpl implements TradeAfterSaleService, AfterSa // TODO 发送售后消息 // 更新交易订单项的售后状态为【未申请】 - tradeOrderService.updateOrderItemAfterSaleStatus(afterSale.getOrderItemId(), + tradeOrderUpdateService.updateOrderItemAfterSaleStatus(afterSale.getOrderItemId(), TradeOrderItemAfterSaleStatusEnum.APPLY.getStatus(), TradeOrderItemAfterSaleStatusEnum.NONE.getStatus(), null); } diff --git a/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/service/order/TradeOrderQueryService.java b/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/service/order/TradeOrderQueryService.java index 8ef513cb8..0c03802a3 100644 --- a/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/service/order/TradeOrderQueryService.java +++ b/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/service/order/TradeOrderQueryService.java @@ -1,9 +1,17 @@ package cn.iocoder.yudao.module.trade.service.order; +import cn.iocoder.yudao.framework.common.pojo.PageResult; +import cn.iocoder.yudao.module.trade.controller.admin.order.vo.TradeOrderPageReqVO; +import cn.iocoder.yudao.module.trade.controller.app.order.vo.AppTradeOrderPageReqVO; +import cn.iocoder.yudao.module.trade.dal.dataobject.order.TradeOrderDO; +import cn.iocoder.yudao.module.trade.dal.dataobject.order.TradeOrderItemDO; import cn.iocoder.yudao.module.trade.framework.delivery.core.client.dto.ExpressTrackRespDTO; +import java.util.Collection; import java.util.List; +import static java.util.Collections.singleton; + /** * 交易订单【读】 Service 接口 * @@ -11,6 +19,52 @@ import java.util.List; */ public interface TradeOrderQueryService { + // =================== Order =================== + + /** + * 获得指定编号的交易订单 + * + * @param id 交易订单编号 + * @return 交易订单 + */ + TradeOrderDO getOrder(Long id); + + /** + * 获得指定用户,指定的交易订单 + * + * @param userId 用户编号 + * @param id 交易订单编号 + * @return 交易订单 + */ + TradeOrderDO getOrder(Long userId, Long id); + + /** + * 【管理员】获得交易订单分页 + * + * @param reqVO 分页请求 + * @return 交易订单 + */ + PageResult getOrderPage(TradeOrderPageReqVO reqVO); + + /** + * 【会员】获得交易订单分页 + * + * @param userId 用户编号 + * @param reqVO 分页请求 + * @return 交易订单 + */ + PageResult getOrderPage(Long userId, AppTradeOrderPageReqVO reqVO); + + /** + * 【会员】获得交易订单数量 + * + * @param userId 用户编号 + * @param status 订单状态。如果为空,则不进行筛选 + * @param commonStatus 评价状态。如果为空,则不进行筛选 + * @return 订单数量 + */ + Long getOrderCount(Long userId, Integer status, Boolean commonStatus); + /** * 获得订单的物流轨迹 * @@ -20,4 +74,41 @@ public interface TradeOrderQueryService { */ List getExpressTrackList(Long id, Long userId); + // =================== Order Item =================== + + /** + * 获得指定用户,指定的交易订单项 + * + * @param userId 用户编号 + * @param itemId 交易订单项编号 + * @return 交易订单项 + */ + TradeOrderItemDO getOrderItem(Long userId, Long itemId); + + /** + * 根据交易订单项编号数组,查询交易订单项 + * + * @param ids 交易订单项编号数组 + * @return 交易订单项数组 + */ + List getOrderItemList(Collection ids); + + /** + * 根据交易订单编号,查询交易订单项 + * + * @param orderId 交易订单编号 + * @return 交易订单项数组 + */ + default List getOrderItemListByOrderId(Long orderId) { + return getOrderItemListByOrderId(singleton(orderId)); + } + + /** + * 根据交易订单编号数组,查询交易订单项 + * + * @param orderIds 交易订单编号数组 + * @return 交易订单项数组 + */ + List getOrderItemListByOrderId(Collection orderIds); + } diff --git a/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/service/order/TradeOrderQueryServiceImpl.java b/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/service/order/TradeOrderQueryServiceImpl.java index 20dc074b2..9fb238465 100644 --- a/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/service/order/TradeOrderQueryServiceImpl.java +++ b/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/service/order/TradeOrderQueryServiceImpl.java @@ -1,7 +1,17 @@ package cn.iocoder.yudao.module.trade.service.order; +import cn.hutool.core.collection.CollUtil; +import cn.hutool.core.util.ObjectUtil; +import cn.hutool.core.util.StrUtil; +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.trade.controller.admin.order.vo.TradeOrderPageReqVO; +import cn.iocoder.yudao.module.trade.controller.app.order.vo.AppTradeOrderPageReqVO; import cn.iocoder.yudao.module.trade.dal.dataobject.delivery.DeliveryExpressDO; import cn.iocoder.yudao.module.trade.dal.dataobject.order.TradeOrderDO; +import cn.iocoder.yudao.module.trade.dal.dataobject.order.TradeOrderItemDO; +import cn.iocoder.yudao.module.trade.dal.mysql.order.TradeOrderItemMapper; import cn.iocoder.yudao.module.trade.dal.mysql.order.TradeOrderMapper; import cn.iocoder.yudao.module.trade.framework.delivery.core.client.ExpressClientFactory; import cn.iocoder.yudao.module.trade.framework.delivery.core.client.dto.ExpressTrackQueryReqDTO; @@ -10,10 +20,10 @@ import cn.iocoder.yudao.module.trade.service.delivery.DeliveryExpressService; import org.springframework.stereotype.Service; import javax.annotation.Resource; -import java.util.Collections; -import java.util.List; +import java.util.*; import static cn.iocoder.yudao.framework.common.exception.util.ServiceExceptionUtil.exception; +import static cn.iocoder.yudao.framework.common.util.collection.CollectionUtils.convertSet; import static cn.iocoder.yudao.module.trade.enums.ErrorCodeConstants.EXPRESS_NOT_EXISTS; import static cn.iocoder.yudao.module.trade.enums.ErrorCodeConstants.ORDER_NOT_FOUND; @@ -30,10 +40,64 @@ public class TradeOrderQueryServiceImpl implements TradeOrderQueryService { @Resource private TradeOrderMapper tradeOrderMapper; + @Resource + private TradeOrderItemMapper tradeOrderItemMapper; @Resource private DeliveryExpressService deliveryExpressService; + @Resource + private MemberUserApi memberUserApi; + + // =================== Order =================== + + @Override + public TradeOrderDO getOrder(Long id) { + return tradeOrderMapper.selectById(id); + } + + @Override + public TradeOrderDO getOrder(Long userId, Long id) { + TradeOrderDO order = tradeOrderMapper.selectById(id); + if (order != null + && ObjectUtil.notEqual(order.getUserId(), userId)) { + return null; + } + return order; + } + + @Override + public PageResult getOrderPage(TradeOrderPageReqVO reqVO) { + // 获得 userId 相关的查询 + Set userIds = new HashSet<>(); + if (StrUtil.isNotEmpty(reqVO.getUserMobile())) { + MemberUserRespDTO user = memberUserApi.getUserByMobile(reqVO.getUserMobile()); + if (user == null) { // 没查询到用户,说明肯定也没他的订单 + return new PageResult<>(); + } + userIds.add(user.getId()); + } + if (StrUtil.isNotEmpty(reqVO.getUserNickname())) { + List users = memberUserApi.getUserListByNickname(reqVO.getUserNickname()); + if (CollUtil.isEmpty(users)) { // 没查询到用户,说明肯定也没他的订单 + return new PageResult<>(); + } + userIds.addAll(convertSet(users, MemberUserRespDTO::getId)); + } + // 分页查询 + return tradeOrderMapper.selectPage(reqVO, userIds); + } + + @Override + public PageResult getOrderPage(Long userId, AppTradeOrderPageReqVO reqVO) { + return tradeOrderMapper.selectPage(reqVO, userId); + } + + @Override + public Long getOrderCount(Long userId, Integer status, Boolean commentStatus) { + return tradeOrderMapper.selectCountByUserIdAndStatus(userId, status, commentStatus); + } + @Override public List getExpressTrackList(Long id, Long userId) { // 查询订单 @@ -57,4 +121,29 @@ public class TradeOrderQueryServiceImpl implements TradeOrderQueryService { .setPhone(order.getReceiverMobile())); } + // =================== Order Item =================== + + @Override + public TradeOrderItemDO getOrderItem(Long userId, Long itemId) { + TradeOrderItemDO orderItem = tradeOrderItemMapper.selectById(itemId); + if (orderItem != null + && ObjectUtil.notEqual(orderItem.getUserId(), userId)) { + return null; + } + return orderItem; + } + + @Override + public List getOrderItemList(Collection ids) { + return tradeOrderItemMapper.selectBatchIds(ids); + } + + @Override + public List getOrderItemListByOrderId(Collection orderIds) { + if (CollUtil.isEmpty(orderIds)) { + return Collections.emptyList(); + } + return tradeOrderItemMapper.selectListByOrderId(orderIds); + } + } diff --git a/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/service/order/TradeOrderService.java b/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/service/order/TradeOrderService.java deleted file mode 100644 index c61ca8a33..000000000 --- a/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/service/order/TradeOrderService.java +++ /dev/null @@ -1,190 +0,0 @@ -package cn.iocoder.yudao.module.trade.service.order; - -import cn.iocoder.yudao.framework.common.pojo.PageResult; -import cn.iocoder.yudao.module.trade.controller.admin.order.vo.TradeOrderDeliveryReqVO; -import cn.iocoder.yudao.module.trade.controller.admin.order.vo.TradeOrderPageReqVO; -import cn.iocoder.yudao.module.trade.controller.app.order.vo.AppTradeOrderCreateReqVO; -import cn.iocoder.yudao.module.trade.controller.app.order.vo.AppTradeOrderPageReqVO; -import cn.iocoder.yudao.module.trade.controller.app.order.vo.AppTradeOrderSettlementReqVO; -import cn.iocoder.yudao.module.trade.controller.app.order.vo.AppTradeOrderSettlementRespVO; -import cn.iocoder.yudao.module.trade.controller.app.order.vo.item.AppTradeOrderItemCommentCreateReqVO; -import cn.iocoder.yudao.module.trade.dal.dataobject.order.TradeOrderDO; -import cn.iocoder.yudao.module.trade.dal.dataobject.order.TradeOrderItemDO; - -import java.util.Collection; -import java.util.List; - -import static java.util.Collections.singleton; - -/** - * 交易订单 Service 接口 - * - * @author LeeYan9 - * @since 2022-08-26 - */ -public interface TradeOrderService { - - // =================== Order =================== - - /** - * 获得订单结算信息 - * - * @param userId 登录用户 - * @param settlementReqVO 订单结算请求 - * @return 订单结算结果 - */ - AppTradeOrderSettlementRespVO settlementOrder(Long userId, AppTradeOrderSettlementReqVO settlementReqVO); - - /** - * 【会员】创建交易订单 - * - * @param userId 登录用户 - * @param userIp 用户 IP 地址 - * @param createReqVO 创建交易订单请求模型 - * @return 交易订单的 - */ - TradeOrderDO createOrder(Long userId, String userIp, AppTradeOrderCreateReqVO createReqVO); - - /** - * 更新交易订单已支付 - * - * @param id 交易订单编号 - * @param payOrderId 支付订单编号 - */ - void updateOrderPaid(Long id, Long payOrderId); - - /** - * 【管理员】发货交易订单 - * - * @param userId 管理员编号 - * @param deliveryReqVO 发货请求 - */ - void deliveryOrder(Long userId, TradeOrderDeliveryReqVO deliveryReqVO); - - /** - * 【会员】收货交易订单 - * - * @param userId 用户编号 - * @param id 订单编号 - */ - void receiveOrder(Long userId, Long id); - - /** - * 获得指定编号的交易订单 - * - * @param id 交易订单编号 - * @return 交易订单 - */ - TradeOrderDO getOrder(Long id); - - /** - * 获得指定用户,指定的交易订单 - * - * @param userId 用户编号 - * @param id 交易订单编号 - * @return 交易订单 - */ - TradeOrderDO getOrder(Long userId, Long id); - - /** - * 【管理员】获得交易订单分页 - * - * @param reqVO 分页请求 - * @return 交易订单 - */ - PageResult getOrderPage(TradeOrderPageReqVO reqVO); - - /** - * 【会员】获得交易订单分页 - * - * @param userId 用户编号 - * @param reqVO 分页请求 - * @return 交易订单 - */ - PageResult getOrderPage(Long userId, AppTradeOrderPageReqVO reqVO); - - /** - * 【会员】获得交易订单数量 - * - * @param userId 用户编号 - * @param status 订单状态。如果为空,则不进行筛选 - * @param commonStatus 评价状态。如果为空,则不进行筛选 - * @return 订单数量 - */ - Long getOrderCount(Long userId, Integer status, Boolean commonStatus); - - // =================== Order Item =================== - - /** - * 获得指定用户,指定的交易订单项 - * - * @param userId 用户编号 - * @param itemId 交易订单项编号 - * @return 交易订单项 - */ - TradeOrderItemDO getOrderItem(Long userId, Long itemId); - - /** - * 更新交易订单项的售后状态 - * - * @param id 交易订单项编号 - * @param oldAfterSaleStatus 当前售后状态;如果不符,更新后会抛出异常 - * @param newAfterSaleStatus 目标售后状态 - * @param refundPrice 退款金额;当订单项退款成功时,必须传递该值 - */ - void updateOrderItemAfterSaleStatus(Long id, Integer oldAfterSaleStatus, - Integer newAfterSaleStatus, Integer refundPrice); - - /** - * 根据交易订单项编号数组,查询交易订单项 - * - * @param ids 交易订单项编号数组 - * @return 交易订单项数组 - */ - List getOrderItemList(Collection ids); - - /** - * 根据交易订单编号,查询交易订单项 - * - * @param orderId 交易订单编号 - * @return 交易订单项数组 - */ - default List getOrderItemListByOrderId(Long orderId) { - return getOrderItemListByOrderId(singleton(orderId)); - } - - /** - * 根据交易订单编号数组,查询交易订单项 - * - * @param orderIds 交易订单编号数组 - * @return 交易订单项数组 - */ - List getOrderItemListByOrderId(Collection orderIds); - - /** - * 得到订单项通过 订单项 id 和用户 id - * - * @param orderItemId 订单项 id - * @param loginUserId 登录用户 id - * @return 得到订单项 - */ - TradeOrderItemDO getOrderItemByIdAndUserId(Long orderItemId, Long loginUserId); - - /** - * 得到订单通过 id 和 用户 id - * - * @param orderId 订单 id - * @param loginUserId 登录用户 id - * @return 得到订单 - */ - TradeOrderDO getOrderByIdAndUserId(Long orderId, Long loginUserId); - - /** - * 创建订单项的评论 - * - * @param createReqVO 创建请求 - * @return 得到评价 id - */ - Long createOrderItemComment(AppTradeOrderItemCommentCreateReqVO createReqVO); - -} diff --git a/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/service/order/TradeOrderUpdateService.java b/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/service/order/TradeOrderUpdateService.java new file mode 100644 index 000000000..92183efb3 --- /dev/null +++ b/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/service/order/TradeOrderUpdateService.java @@ -0,0 +1,85 @@ +package cn.iocoder.yudao.module.trade.service.order; + +import cn.iocoder.yudao.module.trade.controller.admin.order.vo.TradeOrderDeliveryReqVO; +import cn.iocoder.yudao.module.trade.controller.app.order.vo.AppTradeOrderCreateReqVO; +import cn.iocoder.yudao.module.trade.controller.app.order.vo.AppTradeOrderSettlementReqVO; +import cn.iocoder.yudao.module.trade.controller.app.order.vo.AppTradeOrderSettlementRespVO; +import cn.iocoder.yudao.module.trade.controller.app.order.vo.item.AppTradeOrderItemCommentCreateReqVO; +import cn.iocoder.yudao.module.trade.dal.dataobject.order.TradeOrderDO; + +/** + * 交易订单【写】Service 接口 + * + * @author LeeYan9 + * @since 2022-08-26 + */ +public interface TradeOrderUpdateService { + + // =================== Order =================== + + /** + * 获得订单结算信息 + * + * @param userId 登录用户 + * @param settlementReqVO 订单结算请求 + * @return 订单结算结果 + */ + AppTradeOrderSettlementRespVO settlementOrder(Long userId, AppTradeOrderSettlementReqVO settlementReqVO); + + /** + * 【会员】创建交易订单 + * + * @param userId 登录用户 + * @param userIp 用户 IP 地址 + * @param createReqVO 创建交易订单请求模型 + * @return 交易订单的 + */ + TradeOrderDO createOrder(Long userId, String userIp, AppTradeOrderCreateReqVO createReqVO); + + /** + * 更新交易订单已支付 + * + * @param id 交易订单编号 + * @param payOrderId 支付订单编号 + */ + void updateOrderPaid(Long id, Long payOrderId); + + /** + * 【管理员】发货交易订单 + * + * @param userId 管理员编号 + * @param deliveryReqVO 发货请求 + */ + void deliveryOrder(Long userId, TradeOrderDeliveryReqVO deliveryReqVO); + + /** + * 【会员】收货交易订单 + * + * @param userId 用户编号 + * @param id 订单编号 + */ + void receiveOrder(Long userId, Long id); + + // =================== Order Item =================== + + /** + * 更新交易订单项的售后状态 + * + * @param id 交易订单项编号 + * @param oldAfterSaleStatus 当前售后状态;如果不符,更新后会抛出异常 + * @param newAfterSaleStatus 目标售后状态 + * @param refundPrice 退款金额;当订单项退款成功时,必须传递该值 + */ + void updateOrderItemAfterSaleStatus(Long id, Integer oldAfterSaleStatus, + Integer newAfterSaleStatus, Integer refundPrice); + + /** + * 创建订单项的评论 + * + * @param userId 用户编号 + * @param createReqVO 创建请求 + * @return 得到评价 id + */ + Long createOrderItemComment(Long userId, AppTradeOrderItemCommentCreateReqVO createReqVO); + +} diff --git a/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/service/order/TradeOrderServiceImpl.java b/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/service/order/TradeOrderUpdateServiceImpl.java similarity index 87% rename from yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/service/order/TradeOrderServiceImpl.java rename to yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/service/order/TradeOrderUpdateServiceImpl.java index 377e7a92f..5137c3ce4 100644 --- a/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/service/order/TradeOrderServiceImpl.java +++ b/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/service/order/TradeOrderUpdateServiceImpl.java @@ -8,7 +8,6 @@ import cn.hutool.core.util.StrUtil; import cn.iocoder.yudao.framework.common.core.KeyValue; import cn.iocoder.yudao.framework.common.enums.CommonStatusEnum; import cn.iocoder.yudao.framework.common.enums.TerminalEnum; -import cn.iocoder.yudao.framework.common.pojo.PageResult; import cn.iocoder.yudao.framework.common.util.collection.CollectionUtils; import cn.iocoder.yudao.framework.common.util.json.JsonUtils; import cn.iocoder.yudao.module.member.api.address.AddressApi; @@ -31,9 +30,7 @@ import cn.iocoder.yudao.module.promotion.api.coupon.CouponApi; import cn.iocoder.yudao.module.promotion.api.coupon.dto.CouponUseReqDTO; import cn.iocoder.yudao.module.promotion.enums.combination.CombinationRecordStatusEnum; import cn.iocoder.yudao.module.trade.controller.admin.order.vo.TradeOrderDeliveryReqVO; -import cn.iocoder.yudao.module.trade.controller.admin.order.vo.TradeOrderPageReqVO; import cn.iocoder.yudao.module.trade.controller.app.order.vo.AppTradeOrderCreateReqVO; -import cn.iocoder.yudao.module.trade.controller.app.order.vo.AppTradeOrderPageReqVO; import cn.iocoder.yudao.module.trade.controller.app.order.vo.AppTradeOrderSettlementReqVO; import cn.iocoder.yudao.module.trade.controller.app.order.vo.AppTradeOrderSettlementRespVO; import cn.iocoder.yudao.module.trade.controller.app.order.vo.item.AppTradeOrderItemCommentCreateReqVO; @@ -61,23 +58,23 @@ import org.springframework.transaction.annotation.Transactional; import javax.annotation.Resource; import java.time.LocalDateTime; -import java.util.*; +import java.util.List; +import java.util.Objects; import static cn.iocoder.yudao.framework.common.exception.util.ServiceExceptionUtil.exception; import static cn.iocoder.yudao.framework.common.util.collection.CollectionUtils.*; -import static cn.iocoder.yudao.framework.security.core.util.SecurityFrameworkUtils.getLoginUserId; import static cn.iocoder.yudao.module.pay.enums.ErrorCodeConstants.ORDER_NOT_FOUND; import static cn.iocoder.yudao.module.trade.enums.ErrorCodeConstants.*; /** - * 交易订单 Service 实现类 + * 交易订单【写】Service 实现类 * * @author LeeYan9 * @since 2022-08-26 */ @Service @Slf4j -public class TradeOrderServiceImpl implements TradeOrderService { +public class TradeOrderUpdateServiceImpl implements TradeOrderUpdateService { @Resource private TradeOrderMapper tradeOrderMapper; @@ -514,65 +511,8 @@ public class TradeOrderServiceImpl implements TradeOrderService { return order; } - @Override - public TradeOrderDO getOrder(Long id) { - return tradeOrderMapper.selectById(id); - } - - @Override - public TradeOrderDO getOrder(Long userId, Long id) { - TradeOrderDO order = tradeOrderMapper.selectById(id); - if (order != null - && ObjectUtil.notEqual(order.getUserId(), userId)) { - return null; - } - return order; - } - - @Override - public PageResult getOrderPage(TradeOrderPageReqVO reqVO) { - // 获得 userId 相关的查询 - Set userIds = new HashSet<>(); - if (StrUtil.isNotEmpty(reqVO.getUserMobile())) { - MemberUserRespDTO user = memberUserApi.getUserByMobile(reqVO.getUserMobile()); - if (user == null) { // 没查询到用户,说明肯定也没他的订单 - return new PageResult<>(); - } - userIds.add(user.getId()); - } - if (StrUtil.isNotEmpty(reqVO.getUserNickname())) { - List users = memberUserApi.getUserListByNickname(reqVO.getUserNickname()); - if (CollUtil.isEmpty(users)) { // 没查询到用户,说明肯定也没他的订单 - return new PageResult<>(); - } - userIds.addAll(convertSet(users, MemberUserRespDTO::getId)); - } - // 分页查询 - return tradeOrderMapper.selectPage(reqVO, userIds); - } - - @Override - public PageResult getOrderPage(Long userId, AppTradeOrderPageReqVO reqVO) { - return tradeOrderMapper.selectPage(reqVO, userId); - } - - @Override - public Long getOrderCount(Long userId, Integer status, Boolean commentStatus) { - return tradeOrderMapper.selectCountByUserIdAndStatus(userId, status, commentStatus); - } - // =================== Order Item =================== - @Override - public TradeOrderItemDO getOrderItem(Long userId, Long itemId) { - TradeOrderItemDO orderItem = tradeOrderItemMapper.selectById(itemId); - if (orderItem != null - && ObjectUtil.notEqual(orderItem.getUserId(), userId)) { - return null; - } - return orderItem; - } - @Override public void updateOrderItemAfterSaleStatus(Long id, Integer oldAfterSaleStatus, Integer newAfterSaleStatus, Integer refundPrice) { // 如果退款成功,则 refundPrice 非空 @@ -610,40 +550,16 @@ public class TradeOrderServiceImpl implements TradeOrderService { // TODO 芋艿:未来如果有分佣,需要更新相关分佣订单为已失效 } - @Override - public List getOrderItemList(Collection ids) { - return tradeOrderItemMapper.selectBatchIds(ids); - } - - @Override - public List getOrderItemListByOrderId(Collection orderIds) { - if (CollUtil.isEmpty(orderIds)) { - return Collections.emptyList(); - } - return tradeOrderItemMapper.selectListByOrderId(orderIds); - } - - @Override - public TradeOrderItemDO getOrderItemByIdAndUserId(Long orderItemId, Long loginUserId) { - return tradeOrderItemMapper.selectOrderItemByIdAndUserId(orderItemId, loginUserId); - } - - @Override - public TradeOrderDO getOrderByIdAndUserId(Long orderId, Long loginUserId) { - return tradeOrderMapper.selectOrderByIdAndUserId(orderId, loginUserId); - } - @Override @Transactional(rollbackFor = Exception.class) - public Long createOrderItemComment(AppTradeOrderItemCommentCreateReqVO createReqVO) { - Long loginUserId = getLoginUserId(); + public Long createOrderItemComment(Long userId, AppTradeOrderItemCommentCreateReqVO createReqVO) { // 先通过订单项 ID,查询订单项是否存在 - TradeOrderItemDO orderItem = getOrderItemByIdAndUserId(createReqVO.getOrderItemId(), loginUserId); + TradeOrderItemDO orderItem = tradeOrderItemMapper.selectByIdAndUserId(createReqVO.getOrderItemId(), userId); if (orderItem == null) { throw exception(ORDER_ITEM_NOT_FOUND); } // 校验订单相关状态 - TradeOrderDO order = getOrderByIdAndUserId(orderItem.getOrderId(), loginUserId); + TradeOrderDO order = tradeOrderMapper.selectOrderByIdAndUserId(orderItem.getOrderId(), userId); if (order == null) { throw exception(ORDER_NOT_FOUND); } @@ -654,14 +570,14 @@ public class TradeOrderServiceImpl implements TradeOrderService { throw exception(ORDER_COMMENT_STATUS_NOT_FALSE); } - // 创建评价 + // 1. 创建评价 ProductCommentCreateReqDTO productCommentCreateReqDTO = TradeOrderConvert.INSTANCE.convert04(createReqVO, orderItem); Long comment = productCommentApi.createComment(productCommentCreateReqDTO); - // 更新订单项评价状态 + + // 2. 更新订单项评价状态 tradeOrderItemMapper.updateById(new TradeOrderItemDO().setId(orderItem.getId()).setCommentStatus(Boolean.TRUE)); - List orderItems = getOrderItemListByOrderId(CollUtil.newArrayList(order.getId())); + List orderItems = tradeOrderItemMapper.selectListByOrderId(order.getId()); if (!anyMatch(orderItems, item -> Objects.equals(item.getCommentStatus(), Boolean.FALSE))) { - // 对于 order 来说,就是评论完,把 order 更新完合理的 status 等字段。 tradeOrderMapper.updateById(new TradeOrderDO().setId(order.getId()).setCommentStatus(Boolean.TRUE)); } return comment; diff --git a/yudao-module-mall/yudao-module-trade-biz/src/test/java/cn/iocoder/yudao/module/trade/service/aftersale/TradeAfterSaleServiceTest.java b/yudao-module-mall/yudao-module-trade-biz/src/test/java/cn/iocoder/yudao/module/trade/service/aftersale/TradeAfterSaleServiceTest.java index 68efd67a7..c1224d228 100644 --- a/yudao-module-mall/yudao-module-trade-biz/src/test/java/cn/iocoder/yudao/module/trade/service/aftersale/TradeAfterSaleServiceTest.java +++ b/yudao-module-mall/yudao-module-trade-biz/src/test/java/cn/iocoder/yudao/module/trade/service/aftersale/TradeAfterSaleServiceTest.java @@ -18,7 +18,7 @@ import cn.iocoder.yudao.module.trade.enums.aftersale.TradeAfterSaleWayEnum; import cn.iocoder.yudao.module.trade.enums.order.TradeOrderItemAfterSaleStatusEnum; import cn.iocoder.yudao.module.trade.enums.order.TradeOrderStatusEnum; import cn.iocoder.yudao.module.trade.framework.order.config.TradeOrderProperties; -import cn.iocoder.yudao.module.trade.service.order.TradeOrderService; +import cn.iocoder.yudao.module.trade.service.order.TradeOrderUpdateService; import org.junit.jupiter.api.Test; import org.springframework.boot.test.mock.mockito.MockBean; import org.springframework.context.annotation.Import; @@ -52,7 +52,7 @@ public class TradeAfterSaleServiceTest extends BaseDbUnitTest { private TradeAfterSaleLogMapper tradeAfterSaleLogMapper; @MockBean - private TradeOrderService tradeOrderService; + private TradeOrderUpdateService tradeOrderService; @MockBean private PayRefundApi payRefundApi; diff --git a/yudao-module-mall/yudao-module-trade-biz/src/test/java/cn/iocoder/yudao/module/trade/service/order/TradeOrderServiceTest.java b/yudao-module-mall/yudao-module-trade-biz/src/test/java/cn/iocoder/yudao/module/trade/service/order/TradeOrderUpdateServiceTest.java similarity index 96% rename from yudao-module-mall/yudao-module-trade-biz/src/test/java/cn/iocoder/yudao/module/trade/service/order/TradeOrderServiceTest.java rename to yudao-module-mall/yudao-module-trade-biz/src/test/java/cn/iocoder/yudao/module/trade/service/order/TradeOrderUpdateServiceTest.java index f9dc071dd..313d1874e 100644 --- a/yudao-module-mall/yudao-module-trade-biz/src/test/java/cn/iocoder/yudao/module/trade/service/order/TradeOrderServiceTest.java +++ b/yudao-module-mall/yudao-module-trade-biz/src/test/java/cn/iocoder/yudao/module/trade/service/order/TradeOrderUpdateServiceTest.java @@ -48,16 +48,16 @@ import static org.mockito.Mockito.verify; import static org.mockito.Mockito.when; /** - * {@link TradeOrderServiceImpl} 的单元测试类 + * {@link TradeOrderUpdateServiceImpl} 的单元测试类 * * @author LeeYan9 * @since 2022-09-07 */ -@Import({TradeOrderServiceImpl.class, TradeOrderConfig.class}) -public class TradeOrderServiceTest extends BaseDbUnitTest { +@Import({TradeOrderUpdateServiceImpl.class, TradeOrderConfig.class}) +public class TradeOrderUpdateServiceTest extends BaseDbUnitTest { @Resource - private TradeOrderServiceImpl tradeOrderService; + private TradeOrderUpdateServiceImpl tradeOrderUpdateService; @Resource private TradeOrderMapper tradeOrderMapper; @@ -150,7 +150,7 @@ public class TradeOrderServiceTest extends BaseDbUnitTest { }))).thenReturn(1000L); // 调用方法 - TradeOrderDO order = tradeOrderService.createOrder(userId, userIp, reqVO); + TradeOrderDO order = tradeOrderUpdateService.createOrder(userId, userIp, reqVO); // 断言 TradeOrderDO 订单 List tradeOrderDOs = tradeOrderMapper.selectList(); assertEquals(tradeOrderDOs.size(), 1); @@ -259,7 +259,7 @@ public class TradeOrderServiceTest extends BaseDbUnitTest { .setMerchantOrderId("1")).setPrice(100)); // 调用 - tradeOrderService.updateOrderPaid(id, payOrderId); + tradeOrderUpdateService.updateOrderPaid(id, payOrderId); // 断言 TradeOrderDO dbOrder = tradeOrderMapper.selectById(id); assertEquals(dbOrder.getStatus(), TradeOrderStatusEnum.UNDELIVERED.getStatus()); @@ -282,7 +282,7 @@ public class TradeOrderServiceTest extends BaseDbUnitTest { // mock 方法(支付单) // 调用 - tradeOrderService.deliveryOrder(randomLongId(), deliveryReqVO); + tradeOrderUpdateService.deliveryOrder(randomLongId(), deliveryReqVO); // 断言 TradeOrderDO dbOrder = tradeOrderMapper.selectById(1L); assertEquals(dbOrder.getStatus(), TradeOrderStatusEnum.DELIVERED.getStatus()); @@ -304,7 +304,7 @@ public class TradeOrderServiceTest extends BaseDbUnitTest { // mock 方法(支付单) // 调用 - tradeOrderService.receiveOrder(userId, id); + tradeOrderUpdateService.receiveOrder(userId, id); // 断言 TradeOrderDO dbOrder = tradeOrderMapper.selectById(1L); assertEquals(dbOrder.getStatus(), TradeOrderStatusEnum.COMPLETED.getStatus());