From 655eefc340bd9225f490c81ce52a242efb6482db Mon Sep 17 00:00:00 2001 From: puhui999 Date: Mon, 28 Aug 2023 09:23:30 +0800 Subject: [PATCH 1/4] =?UTF-8?q?=E8=AE=A2=E5=8D=95=E7=AE=A1=E7=90=86?= =?UTF-8?q?=EF=BC=9A=E5=AE=8C=E5=96=84=E8=AE=A2=E5=8D=95=E7=AE=A1=E7=90=86?= =?UTF-8?q?=E6=8F=90=E5=88=B0=E7=9A=84=E4=B8=80=E4=BA=9B=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../trade/enums/ErrorCodeConstants.java | 1 + .../DeliveryPickUpStoreController.java | 9 +++++++-- .../DeliveryPickUpStoreSimpleRespVO.java | 3 ++- .../admin/order/TradeOrderController.java | 12 ++++-------- .../order/TradeOrderUpdateServiceImpl.java | 19 ++++++++++--------- 5 files changed, 24 insertions(+), 20 deletions(-) diff --git a/yudao-module-mall/yudao-module-trade-api/src/main/java/cn/iocoder/yudao/module/trade/enums/ErrorCodeConstants.java b/yudao-module-mall/yudao-module-trade-api/src/main/java/cn/iocoder/yudao/module/trade/enums/ErrorCodeConstants.java index dc757b05e..3aa0e5dd3 100644 --- a/yudao-module-mall/yudao-module-trade-api/src/main/java/cn/iocoder/yudao/module/trade/enums/ErrorCodeConstants.java +++ b/yudao-module-mall/yudao-module-trade-api/src/main/java/cn/iocoder/yudao/module/trade/enums/ErrorCodeConstants.java @@ -32,6 +32,7 @@ public interface ErrorCodeConstants { ErrorCode ORDER_DELIVERY_FAIL_REFUND_STATUS_NOT_NONE = new ErrorCode(1011000021, "交易订单发货失败,订单已退款或部分退款"); ErrorCode ORDER_DELIVERY_FAIL_COMBINATION_RECORD_STATUS_NOT_SUCCESS = new ErrorCode(1011000022, "交易订单发货失败,拼团未成功"); ErrorCode ORDER_DELIVERY_FAIL_BARGAIN_RECORD_STATUS_NOT_SUCCESS = new ErrorCode(1011000023, "交易订单发货失败,砍价未成功"); + ErrorCode ORDER_DELIVERY_FAIL_DELIVERY_TYPE_NOT_EXPRESS = new ErrorCode(1011000024, "交易订单发货失败,发货类型不是快递"); // ========== After Sale 模块 1011000100 ========== ErrorCode AFTER_SALE_NOT_FOUND = new ErrorCode(1011000100, "售后单不存在"); diff --git a/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/controller/admin/delivery/DeliveryPickUpStoreController.java b/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/controller/admin/delivery/DeliveryPickUpStoreController.java index a8ddec24c..7687ebc64 100644 --- a/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/controller/admin/delivery/DeliveryPickUpStoreController.java +++ b/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/controller/admin/delivery/DeliveryPickUpStoreController.java @@ -3,6 +3,8 @@ package cn.iocoder.yudao.module.trade.controller.admin.delivery; import cn.iocoder.yudao.framework.common.enums.CommonStatusEnum; import cn.iocoder.yudao.framework.common.pojo.CommonResult; import cn.iocoder.yudao.framework.common.pojo.PageResult; +import cn.iocoder.yudao.framework.common.util.collection.CollectionUtils; +import cn.iocoder.yudao.framework.ip.core.utils.AreaUtils; import cn.iocoder.yudao.module.trade.controller.admin.delivery.vo.pickup.*; import cn.iocoder.yudao.module.trade.convert.delivery.DeliveryPickUpStoreConvert; import cn.iocoder.yudao.module.trade.dal.dataobject.delivery.DeliveryPickUpStoreDO; @@ -64,10 +66,13 @@ public class DeliveryPickUpStoreController { } @GetMapping("/list-all-simple") - @Operation(summary = "获取快递公司精简信息列表") + @Operation(summary = "获得自提门店精简信息列表") public CommonResult> getSimpleDeliveryPickUpStoreList() { List list = deliveryPickUpStoreService.getDeliveryPickUpStoreListByStatus(CommonStatusEnum.ENABLE.getStatus()); - return success(DeliveryPickUpStoreConvert.INSTANCE.convertList1(list)); + return success(CollectionUtils.convertList(DeliveryPickUpStoreConvert.INSTANCE.convertList1(list), item -> { + item.setAreaName(AreaUtils.format(item.getAreaId())); + return item; + })); } @GetMapping("/list") diff --git a/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/controller/admin/delivery/vo/pickup/DeliveryPickUpStoreSimpleRespVO.java b/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/controller/admin/delivery/vo/pickup/DeliveryPickUpStoreSimpleRespVO.java index 34c66df4c..c12fc9fc3 100644 --- a/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/controller/admin/delivery/vo/pickup/DeliveryPickUpStoreSimpleRespVO.java +++ b/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/controller/admin/delivery/vo/pickup/DeliveryPickUpStoreSimpleRespVO.java @@ -23,7 +23,8 @@ public class DeliveryPickUpStoreSimpleRespVO { @Schema(description = "区域编号", requiredMode = Schema.RequiredMode.REQUIRED, example = "18733") private Integer areaId; - // TODO @puhui999:要把 areaName 也返回哈 + @Schema(description = "区域名称", requiredMode = Schema.RequiredMode.REQUIRED, example = "xx市") + private String areaName; @Schema(description = "门店详细地址", requiredMode = Schema.RequiredMode.REQUIRED, example = "复旦大学路 188 号") private String detailAddress; 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 8a28e5ddb..57b21bee0 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 @@ -85,8 +85,7 @@ public class TradeOrderController { tradeOrderQueryService.getExpressTrackList(id, getLoginUserId()))); } - // TODO @puhui999:put 请求哈 - @PostMapping("/delivery") + @PutMapping("/delivery") @Operation(summary = "订单发货") @PreAuthorize("@ss.hasPermission('trade:order:update')") public CommonResult deliveryOrder(@RequestBody TradeOrderDeliveryReqVO deliveryReqVO) { @@ -94,8 +93,7 @@ public class TradeOrderController { return success(true); } - // TODO @puhui999:put 请求哈,update-remark; - @PostMapping("/remark") + @PutMapping("/update-remark") @Operation(summary = "订单备注") @PreAuthorize("@ss.hasPermission('trade:order:update')") public CommonResult updateOrderRemark(@RequestBody TradeOrderRemarkReqVO reqVO) { @@ -103,8 +101,7 @@ public class TradeOrderController { return success(true); } - // TODO @puhui999:put 请求哈,update-price; - @PostMapping("/adjust-price") + @PutMapping("/update-price") @Operation(summary = "订单调价") @PreAuthorize("@ss.hasPermission('trade:order:update')") public CommonResult updateOrderPrice(@RequestBody TradeOrderUpdatePriceReqVO reqVO) { @@ -112,8 +109,7 @@ public class TradeOrderController { return success(true); } - // TODO @puhui999:put 请求哈,update-address; - @PostMapping("/adjust-address") + @PutMapping("/update-address") @Operation(summary = "修改订单收货地址") @PreAuthorize("@ss.hasPermission('trade:order:update')") public CommonResult updateOrderAddress(@RequestBody TradeOrderUpdateAddressReqVO reqVO) { diff --git a/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/service/order/TradeOrderUpdateServiceImpl.java b/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/service/order/TradeOrderUpdateServiceImpl.java index dd119a64e..989b8c1d8 100644 --- a/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/service/order/TradeOrderUpdateServiceImpl.java +++ b/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/service/order/TradeOrderUpdateServiceImpl.java @@ -29,10 +29,10 @@ import cn.iocoder.yudao.module.promotion.api.combination.dto.CombinationRecordUp 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.TradeOrderUpdateAddressReqVO; -import cn.iocoder.yudao.module.trade.controller.admin.order.vo.TradeOrderUpdatePriceReqVO; import cn.iocoder.yudao.module.trade.controller.admin.order.vo.TradeOrderDeliveryReqVO; import cn.iocoder.yudao.module.trade.controller.admin.order.vo.TradeOrderRemarkReqVO; +import cn.iocoder.yudao.module.trade.controller.admin.order.vo.TradeOrderUpdateAddressReqVO; +import cn.iocoder.yudao.module.trade.controller.admin.order.vo.TradeOrderUpdatePriceReqVO; 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; @@ -397,7 +397,10 @@ public class TradeOrderUpdateServiceImpl implements TradeOrderUpdateService { // TODO @puhui999:只有选择快递的,才可以发货 // 1.1 校验并获得交易订单(可发货) TradeOrderDO order = validateOrderDeliverable(deliveryReqVO.getId()); - + // 校验 deliveryType 是否为快递,是快递才可以发货 + if (ObjectUtil.notEqual(order.getDeliveryType(), DeliveryTypeEnum.EXPRESS.getMode())) { + throw exception(ORDER_DELIVERY_FAIL_DELIVERY_TYPE_NOT_EXPRESS); + } // TODO @puhui999:下面不修改 deliveryType,直接校验 deliveryType 是否为快递,是快递才可以发货;先做严格的方式哈。 // 判断发货类型 TradeOrderDO updateOrderObj = new TradeOrderDO(); @@ -411,10 +414,10 @@ public class TradeOrderUpdateServiceImpl implements TradeOrderUpdateService { if (deliveryExpress.getStatus().equals(CommonStatusEnum.DISABLE.getStatus())) { throw exception(EXPRESS_STATUS_NOT_ENABLE); } - updateOrderObj.setLogisticsId(deliveryReqVO.getLogisticsId()).setLogisticsNo(deliveryReqVO.getLogisticsNo()).setDeliveryType(DeliveryTypeEnum.EXPRESS.getMode()); + updateOrderObj.setLogisticsId(deliveryReqVO.getLogisticsId()).setLogisticsNo(deliveryReqVO.getLogisticsNo()); } else { // 2.2 无需发货 - updateOrderObj.setLogisticsId(0L).setLogisticsNo("").setDeliveryType(DeliveryTypeEnum.NULL.getMode()); + updateOrderObj.setLogisticsId(0L).setLogisticsNo(""); } // 更新 TradeOrderDO 状态为已发货,等待收货 updateOrderObj.setStatus(TradeOrderStatusEnum.DELIVERED.getStatus()).setDeliveryTime(LocalDateTime.now()); @@ -454,16 +457,14 @@ public class TradeOrderUpdateServiceImpl implements TradeOrderUpdateService { // 订单类型:拼团 if (Objects.equals(TradeOrderTypeEnum.COMBINATION.getType(), order.getType())) { // 校验订单拼团是否成功 - // TODO @puhui999:是不是取反? - if (combinationRecordApi.isCombinationRecordSuccess(order.getUserId(), order.getId())) { + if (!combinationRecordApi.isCombinationRecordSuccess(order.getUserId(), order.getId())) { throw exception(ORDER_DELIVERY_FAIL_COMBINATION_RECORD_STATUS_NOT_SUCCESS); } } // 订单类类型:砍价 if (Objects.equals(TradeOrderTypeEnum.BARGAIN.getType(), order.getType())) { // 校验订单砍价是否成功 - // TODO @puhui999:是不是取反? - if (bargainRecordApi.isBargainRecordSuccess(order.getUserId(), order.getId())) { + if (!bargainRecordApi.isBargainRecordSuccess(order.getUserId(), order.getId())) { throw exception(ORDER_DELIVERY_FAIL_BARGAIN_RECORD_STATUS_NOT_SUCCESS); } } From 0411b3464a2384b6e20304f2f6fa8fbe5eb4e502 Mon Sep 17 00:00:00 2001 From: puhui999 Date: Mon, 28 Aug 2023 17:21:29 +0800 Subject: [PATCH 2/4] =?UTF-8?q?=E8=AE=A2=E5=8D=95=E5=94=AE=E5=90=8E?= =?UTF-8?q?=E9=80=80=E6=AC=BE=EF=BC=9A=E6=B7=BB=E5=8A=A0=E8=8E=B7=E5=8F=96?= =?UTF-8?q?=E5=94=AE=E5=90=8E=E8=AE=A2=E5=8D=95=E8=AF=A6=E6=83=85=E6=8E=A5?= =?UTF-8?q?=E5=8F=A3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../aftersale/TradeAfterSaleController.java | 36 ++++++++++-- .../vo/TradeAfterSaleDetailRespVO.java | 48 +++++++++++++++ .../aftersale/TradeAfterSaleConvert.java | 24 ++++++++ .../core/dto/TradeAfterSaleLogRespDTO.java | 58 +++++++++++++++++++ .../core/service/AfterSaleLogService.java | 11 ++++ .../aftersale/TradeAfterSaleService.java | 8 +++ .../aftersale/TradeAfterSaleServiceImpl.java | 18 ++++++ 7 files changed, 197 insertions(+), 6 deletions(-) create mode 100644 yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/controller/admin/aftersale/vo/TradeAfterSaleDetailRespVO.java create mode 100644 yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/framework/aftersalelog/core/dto/TradeAfterSaleLogRespDTO.java diff --git a/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/controller/admin/aftersale/TradeAfterSaleController.java b/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/controller/admin/aftersale/TradeAfterSaleController.java index c12d2b5c0..56fdc06da 100644 --- a/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/controller/admin/aftersale/TradeAfterSaleController.java +++ b/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/controller/admin/aftersale/TradeAfterSaleController.java @@ -7,13 +7,15 @@ import cn.iocoder.yudao.framework.operatelog.core.annotations.OperateLog; import cn.iocoder.yudao.module.member.api.user.MemberUserApi; import cn.iocoder.yudao.module.member.api.user.dto.MemberUserRespDTO; import cn.iocoder.yudao.module.pay.api.notify.dto.PayRefundNotifyReqDTO; -import cn.iocoder.yudao.module.trade.controller.admin.aftersale.vo.TradeAfterSaleDisagreeReqVO; -import cn.iocoder.yudao.module.trade.controller.admin.aftersale.vo.TradeAfterSalePageReqVO; -import cn.iocoder.yudao.module.trade.controller.admin.aftersale.vo.TradeAfterSaleRefuseReqVO; -import cn.iocoder.yudao.module.trade.controller.admin.aftersale.vo.TradeAfterSaleRespPageItemVO; +import cn.iocoder.yudao.module.trade.controller.admin.aftersale.vo.*; import cn.iocoder.yudao.module.trade.convert.aftersale.TradeAfterSaleConvert; import cn.iocoder.yudao.module.trade.dal.dataobject.aftersale.TradeAfterSaleDO; +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.aftersalelog.core.dto.TradeAfterSaleLogRespDTO; +import cn.iocoder.yudao.module.trade.framework.aftersalelog.core.service.AfterSaleLogService; import cn.iocoder.yudao.module.trade.service.aftersale.TradeAfterSaleService; +import cn.iocoder.yudao.module.trade.service.order.TradeOrderQueryService; import io.swagger.v3.oas.annotations.Operation; import io.swagger.v3.oas.annotations.Parameter; import io.swagger.v3.oas.annotations.tags.Tag; @@ -25,6 +27,7 @@ import org.springframework.web.bind.annotation.*; import javax.annotation.Resource; import javax.annotation.security.PermitAll; import javax.validation.Valid; +import java.util.List; import java.util.Map; import static cn.iocoder.yudao.framework.common.pojo.CommonResult.success; @@ -41,7 +44,10 @@ public class TradeAfterSaleController { @Resource private TradeAfterSaleService afterSaleService; - + @Resource + private TradeOrderQueryService tradeOrderQueryService; + @Resource + private AfterSaleLogService afterSaleLogService; @Resource private MemberUserApi memberUserApi; @@ -61,6 +67,24 @@ public class TradeAfterSaleController { return success(TradeAfterSaleConvert.INSTANCE.convertPage(pageResult, memberUsers)); } + @GetMapping("/get-detail") + @Operation(summary = "获得售后订单详情") + @Parameter(name = "id", description = "售后编号", required = true, example = "1") + @PreAuthorize("@ss.hasPermission('trade:after-sale:query')") + public CommonResult getOrderDetail(@RequestParam("id") Long id) { + // 查询订单 + TradeAfterSaleDO afterSale = afterSaleService.getAfterSale(id); + // 查询订单 + TradeOrderDO order = tradeOrderQueryService.getOrder(afterSale.getOrderId()); + // 查询订单项 + List orderItems = tradeOrderQueryService.getOrderItemListByOrderId(id); + // 拼接数据 + MemberUserRespDTO user = memberUserApi.getUser(afterSale.getUserId()); + // 获取售后日志 + List logs = afterSaleLogService.getLog(afterSale.getId()); + return success(TradeAfterSaleConvert.INSTANCE.convert(afterSale, order, orderItems, user, logs)); + } + @PutMapping("/agree") @Operation(summary = "同意售后") @Parameter(name = "id", description = "售后编号", required = true, example = "1") @@ -88,7 +112,7 @@ public class TradeAfterSaleController { } @PutMapping("/refuse") - @Operation(summary = "确认收货") + @Operation(summary = "拒绝收货") @Parameter(name = "id", description = "售后编号", required = true, example = "1") @PreAuthorize("@ss.hasPermission('trade:after-sale:receive')") public CommonResult refuseAfterSale(TradeAfterSaleRefuseReqVO refuseReqVO) { diff --git a/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/controller/admin/aftersale/vo/TradeAfterSaleDetailRespVO.java b/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/controller/admin/aftersale/vo/TradeAfterSaleDetailRespVO.java new file mode 100644 index 000000000..c6d12a263 --- /dev/null +++ b/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/controller/admin/aftersale/vo/TradeAfterSaleDetailRespVO.java @@ -0,0 +1,48 @@ +package cn.iocoder.yudao.module.trade.controller.admin.aftersale.vo; + +import cn.iocoder.yudao.module.trade.controller.admin.aftersale.vo.log.TradeAfterSaleLogRespVO; +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.order.vo.TradeOrderBaseVO; +import cn.iocoder.yudao.module.trade.controller.admin.order.vo.TradeOrderItemBaseVO; +import io.swagger.v3.oas.annotations.media.Schema; +import lombok.Data; + +import java.util.List; + +@Schema(description = "管理后台 - 售后订单的详情 Response VO") +@Data +public class TradeAfterSaleDetailRespVO extends TradeAfterSaleBaseVO { + + /** + * 订单项列表 + */ + private List items; + + /** + * 订单基本信息 + */ + private TradeOrderBaseVO order; + + /** + * 用户信息 + */ + private MemberUserRespVO user; + + /** + * 售后日志 + */ + private List afterSaleLog; + + @Schema(description = "管理后台 - 交易订单的详情的订单项目") + @Data + public static class Item extends TradeOrderItemBaseVO { + + /** + * 属性数组 + */ + private List properties; + + } + +} diff --git a/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/convert/aftersale/TradeAfterSaleConvert.java b/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/convert/aftersale/TradeAfterSaleConvert.java index 7fa8b328c..eda67d3d0 100644 --- a/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/convert/aftersale/TradeAfterSaleConvert.java +++ b/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/convert/aftersale/TradeAfterSaleConvert.java @@ -4,19 +4,26 @@ import cn.iocoder.yudao.framework.common.pojo.PageResult; import cn.iocoder.yudao.module.member.api.user.dto.MemberUserRespDTO; import cn.iocoder.yudao.module.pay.api.refund.dto.PayRefundCreateReqDTO; import cn.iocoder.yudao.module.product.api.property.dto.ProductPropertyValueDetailRespDTO; +import cn.iocoder.yudao.module.trade.controller.admin.aftersale.vo.TradeAfterSaleDetailRespVO; import cn.iocoder.yudao.module.trade.controller.admin.aftersale.vo.TradeAfterSaleRespPageItemVO; +import cn.iocoder.yudao.module.trade.controller.admin.aftersale.vo.log.TradeAfterSaleLogRespVO; 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.order.vo.TradeOrderBaseVO; import cn.iocoder.yudao.module.trade.controller.app.aftersale.vo.AppTradeAfterSaleCreateReqVO; import cn.iocoder.yudao.module.trade.controller.app.aftersale.vo.AppTradeAfterSaleRespVO; import cn.iocoder.yudao.module.trade.dal.dataobject.aftersale.TradeAfterSaleDO; +import cn.iocoder.yudao.module.trade.dal.dataobject.aftersale.TradeAfterSaleLogDO; +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.aftersalelog.core.dto.TradeAfterSaleLogRespDTO; import cn.iocoder.yudao.module.trade.framework.order.config.TradeOrderProperties; import org.mapstruct.Mapper; import org.mapstruct.Mapping; import org.mapstruct.Mappings; import org.mapstruct.factory.Mappers; +import java.util.List; import java.util.Map; @Mapper @@ -61,4 +68,21 @@ public interface TradeAfterSaleConvert { PageResult convertPage02(PageResult page); + List convertList(List list); + + List convertList1(List list); + + TradeOrderBaseVO convert(TradeOrderDO order); + + TradeAfterSaleDetailRespVO convert(TradeAfterSaleDO afterSale, List orderItems, List logs); + + default TradeAfterSaleDetailRespVO convert(TradeAfterSaleDO afterSale, TradeOrderDO order, List orderItems, + MemberUserRespDTO user, List logs) { + TradeAfterSaleDetailRespVO respVO = convert(afterSale, orderItems, convertList1(logs)); + // 处理用户信息 + respVO.setUser(convert(user)); + // 处理订单信息 + respVO.setOrder(convert(order)); + return respVO; + } } diff --git a/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/framework/aftersalelog/core/dto/TradeAfterSaleLogRespDTO.java b/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/framework/aftersalelog/core/dto/TradeAfterSaleLogRespDTO.java new file mode 100644 index 000000000..8719b65db --- /dev/null +++ b/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/framework/aftersalelog/core/dto/TradeAfterSaleLogRespDTO.java @@ -0,0 +1,58 @@ +package cn.iocoder.yudao.module.trade.framework.aftersalelog.core.dto; + +import io.swagger.v3.oas.annotations.media.Schema; +import lombok.AllArgsConstructor; +import lombok.Data; +import lombok.NoArgsConstructor; + +import javax.validation.constraints.NotNull; +import java.time.LocalDateTime; + +/** + * 贸易售后日志详情 DTO + * + * @author HUIHUI + */ +@Data +@NoArgsConstructor +@AllArgsConstructor +public class TradeAfterSaleLogRespDTO { + + @Schema(description = "编号", requiredMode = Schema.RequiredMode.REQUIRED, example = "20669") + private Long id; + + @Schema(description = "用户编号", requiredMode = Schema.RequiredMode.REQUIRED, example = "22634") + @NotNull(message = "用户编号不能为空") + private Long userId; + + @Schema(description = "用户类型", requiredMode = Schema.RequiredMode.REQUIRED, example = "2") + @NotNull(message = "用户类型不能为空") + private Integer userType; + + @Schema(description = "售后编号", requiredMode = Schema.RequiredMode.REQUIRED, example = "3023") + @NotNull(message = "售后编号不能为空") + private Long afterSaleId; + + @Schema(description = "订单编号", requiredMode = Schema.RequiredMode.REQUIRED, example = "25870") + @NotNull(message = "订单编号不能为空") + private Long orderId; + + @Schema(description = "订单项编号", requiredMode = Schema.RequiredMode.REQUIRED, example = "23154") + @NotNull(message = "订单项编号不能为空") + private Long orderItemId; + + @Schema(description = "售后状态(之前)", example = "2") + private Integer beforeStatus; + + @Schema(description = "售后状态(之后)", requiredMode = Schema.RequiredMode.REQUIRED, example = "1") + @NotNull(message = "售后状态(之后)不能为空") + private Integer afterStatus; + + @Schema(description = "操作明细", requiredMode = Schema.RequiredMode.REQUIRED, example = "维权完成,退款金额:¥37776.00") + @NotNull(message = "操作明细不能为空") + private String content; + + @Schema(description = "创建时间", requiredMode = Schema.RequiredMode.REQUIRED) + private LocalDateTime createTime; + +} diff --git a/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/framework/aftersalelog/core/service/AfterSaleLogService.java b/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/framework/aftersalelog/core/service/AfterSaleLogService.java index ccea309f4..e92643d79 100644 --- a/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/framework/aftersalelog/core/service/AfterSaleLogService.java +++ b/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/framework/aftersalelog/core/service/AfterSaleLogService.java @@ -2,6 +2,9 @@ package cn.iocoder.yudao.module.trade.framework.aftersalelog.core.service; import cn.iocoder.yudao.module.trade.framework.aftersalelog.core.dto.TradeAfterSaleLogCreateReqDTO; +import cn.iocoder.yudao.module.trade.framework.aftersalelog.core.dto.TradeAfterSaleLogRespDTO; + +import java.util.List; /** * 交易售后日志 Service 接口 @@ -20,4 +23,12 @@ public interface AfterSaleLogService { */ void createLog(TradeAfterSaleLogCreateReqDTO logDTO); + /** + * 获取售后日志 + * + * @param afterSaleId 售后 id + * @return 售后日志 + */ + List getLog(Long afterSaleId); + } diff --git a/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/service/aftersale/TradeAfterSaleService.java b/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/service/aftersale/TradeAfterSaleService.java index 09f2c9f3b..a7b2db687 100644 --- a/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/service/aftersale/TradeAfterSaleService.java +++ b/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/service/aftersale/TradeAfterSaleService.java @@ -42,6 +42,14 @@ public interface TradeAfterSaleService { */ TradeAfterSaleDO getAfterSale(Long userId, Long id); + /** + * 【管理员】获得售后单 + * + * @param id 售后编号 + * @return 售后订单 + */ + TradeAfterSaleDO getAfterSale(Long id); + /** * 【会员】创建售后订单 * 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 e5d106342..3769461a1 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 @@ -26,6 +26,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.aftersalelog.core.dto.TradeAfterSaleLogCreateReqDTO; +import cn.iocoder.yudao.module.trade.framework.aftersalelog.core.dto.TradeAfterSaleLogRespDTO; 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.TradeOrderQueryService; @@ -40,6 +41,7 @@ import org.springframework.validation.annotation.Validated; import javax.annotation.Resource; import java.time.LocalDateTime; +import java.util.List; import static cn.iocoder.yudao.framework.common.exception.util.ServiceExceptionUtil.exception; import static cn.iocoder.yudao.framework.common.util.json.JsonUtils.toJsonString; @@ -86,6 +88,15 @@ public class TradeAfterSaleServiceImpl implements TradeAfterSaleService, AfterSa return tradeAfterSaleMapper.selectByIdAndUserId(id, userId); } + @Override + public TradeAfterSaleDO getAfterSale(Long id) { + TradeAfterSaleDO afterSale = tradeAfterSaleMapper.selectById(id); + if (afterSale == null) { + throw exception(AFTER_SALE_NOT_FOUND); + } + return afterSale; + } + @Override @Transactional(rollbackFor = Exception.class) public Long createAfterSale(Long userId, AppTradeAfterSaleCreateReqVO createReqVO) { @@ -439,4 +450,11 @@ public class TradeAfterSaleServiceImpl implements TradeAfterSaleService, AfterSa log.error("[createLog][request({}) 日志记录错误]", toJsonString(logDTO), exception); } } + + @Override + public List getLog(Long afterSaleId) { + // TODO 不熟悉流程先这么滴 + List saleLogDOs = tradeAfterSaleLogMapper.selectList(TradeAfterSaleLogDO::getAfterSaleId, afterSaleId); + return TradeAfterSaleConvert.INSTANCE.convertList(saleLogDOs); + } } From d5fe7708ceb7efb522ffc150a9ae615a2c1e5e36 Mon Sep 17 00:00:00 2001 From: puhui999 Date: Tue, 29 Aug 2023 09:54:14 +0800 Subject: [PATCH 3/4] =?UTF-8?q?=E8=AE=A2=E5=8D=95=E5=94=AE=E5=90=8E?= =?UTF-8?q?=E9=80=80=E6=AC=BE=EF=BC=9A=E6=B7=BB=E5=8A=A0=E8=8E=B7=E5=8F=96?= =?UTF-8?q?=E5=94=AE=E5=90=8E=E8=AE=A2=E5=8D=95=E8=AF=A6=E6=83=85=E6=8E=A5?= =?UTF-8?q?=E5=8F=A3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../admin/aftersale/vo/TradeAfterSaleDetailRespVO.java | 5 +++++ .../trade/convert/aftersale/TradeAfterSaleConvert.java | 1 + 2 files changed, 6 insertions(+) diff --git a/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/controller/admin/aftersale/vo/TradeAfterSaleDetailRespVO.java b/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/controller/admin/aftersale/vo/TradeAfterSaleDetailRespVO.java index c6d12a263..1b3a3d055 100644 --- a/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/controller/admin/aftersale/vo/TradeAfterSaleDetailRespVO.java +++ b/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/controller/admin/aftersale/vo/TradeAfterSaleDetailRespVO.java @@ -8,12 +8,17 @@ import cn.iocoder.yudao.module.trade.controller.admin.order.vo.TradeOrderItemBas import io.swagger.v3.oas.annotations.media.Schema; import lombok.Data; +import javax.validation.constraints.NotNull; import java.util.List; @Schema(description = "管理后台 - 售后订单的详情 Response VO") @Data public class TradeAfterSaleDetailRespVO extends TradeAfterSaleBaseVO { + @Schema(description = "售后编号", requiredMode = Schema.RequiredMode.REQUIRED, example = "1024") + @NotNull(message = "售后编号不能为空") + private Long id; + /** * 订单项列表 */ diff --git a/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/convert/aftersale/TradeAfterSaleConvert.java b/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/convert/aftersale/TradeAfterSaleConvert.java index eda67d3d0..36cefc5ca 100644 --- a/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/convert/aftersale/TradeAfterSaleConvert.java +++ b/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/convert/aftersale/TradeAfterSaleConvert.java @@ -74,6 +74,7 @@ public interface TradeAfterSaleConvert { TradeOrderBaseVO convert(TradeOrderDO order); + @Mapping(target = "id", source = "afterSale.id") TradeAfterSaleDetailRespVO convert(TradeAfterSaleDO afterSale, List orderItems, List logs); default TradeAfterSaleDetailRespVO convert(TradeAfterSaleDO afterSale, TradeOrderDO order, List orderItems, From 716727bfa7ebcfb0f298e0f805f06efd4d54f695 Mon Sep 17 00:00:00 2001 From: jason <2667446@qq.com> Date: Tue, 29 Aug 2023 15:28:24 +0800 Subject: [PATCH 4/4] =?UTF-8?q?=E5=88=9B=E5=BB=BA=20PayClient=20=E8=BF=81?= =?UTF-8?q?=E7=A7=BB=E5=88=B0=20PayChannelService?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../pay/core/client/PayClientFactory.java | 16 +---- .../core/client/impl/AbstractPayClient.java | 2 + .../client/impl/PayClientFactoryImpl.java | 51 ++------------ .../PayClientFactoryImplIntegrationTest.java | 10 +-- .../framework/pay/wallet/WalletPayClient.java | 4 +- .../channel/PayChannelServiceImpl.java | 68 +++++++++++++------ 6 files changed, 65 insertions(+), 86 deletions(-) diff --git a/yudao-framework/yudao-spring-boot-starter-biz-pay/src/main/java/cn/iocoder/yudao/framework/pay/core/client/PayClientFactory.java b/yudao-framework/yudao-spring-boot-starter-biz-pay/src/main/java/cn/iocoder/yudao/framework/pay/core/client/PayClientFactory.java index 03e6bb613..4739deb25 100644 --- a/yudao-framework/yudao-spring-boot-starter-biz-pay/src/main/java/cn/iocoder/yudao/framework/pay/core/client/PayClientFactory.java +++ b/yudao-framework/yudao-spring-boot-starter-biz-pay/src/main/java/cn/iocoder/yudao/framework/pay/core/client/PayClientFactory.java @@ -1,6 +1,6 @@ package cn.iocoder.yudao.framework.pay.core.client; -import cn.iocoder.yudao.framework.pay.core.client.impl.delegate.DelegatePayClient; +import cn.iocoder.yudao.framework.pay.core.client.impl.AbstractPayClient; /** * 支付客户端的工厂接口 @@ -21,18 +21,8 @@ public interface PayClientFactory { * 创建支付客户端 * * @param channelId 渠道编号 - * @param channelCode 渠道编码 - * @param config 支付配置 - */ - void createOrUpdatePayClient(Long channelId, String channelCode, - Config config); - - /** - * 新增或更新代理支付客户端 - * @param channelId 渠道编号 - * @param delegatePayClient 代理支付客户端 + * @param client 支付客户端 * @param 支付配置 */ - void addOrUpdateDelegatePayClient(Long channelId, DelegatePayClient delegatePayClient); - + void addOrUpdatePayClient(Long channelId, AbstractPayClient client); } diff --git a/yudao-framework/yudao-spring-boot-starter-biz-pay/src/main/java/cn/iocoder/yudao/framework/pay/core/client/impl/AbstractPayClient.java b/yudao-framework/yudao-spring-boot-starter-biz-pay/src/main/java/cn/iocoder/yudao/framework/pay/core/client/impl/AbstractPayClient.java index e8f898b2e..d66e64115 100644 --- a/yudao-framework/yudao-spring-boot-starter-biz-pay/src/main/java/cn/iocoder/yudao/framework/pay/core/client/impl/AbstractPayClient.java +++ b/yudao-framework/yudao-spring-boot-starter-biz-pay/src/main/java/cn/iocoder/yudao/framework/pay/core/client/impl/AbstractPayClient.java @@ -9,6 +9,7 @@ import cn.iocoder.yudao.framework.pay.core.client.dto.order.PayOrderUnifiedReqDT import cn.iocoder.yudao.framework.pay.core.client.dto.refund.PayRefundRespDTO; import cn.iocoder.yudao.framework.pay.core.client.dto.refund.PayRefundUnifiedReqDTO; import cn.iocoder.yudao.framework.pay.core.client.exception.PayException; +import lombok.Getter; import lombok.extern.slf4j.Slf4j; import java.util.Map; @@ -35,6 +36,7 @@ public abstract class AbstractPayClient implemen /** * 支付配置 */ + @Getter protected Config config; public AbstractPayClient(Long channelId, String channelCode, Config config) { diff --git a/yudao-framework/yudao-spring-boot-starter-biz-pay/src/main/java/cn/iocoder/yudao/framework/pay/core/client/impl/PayClientFactoryImpl.java b/yudao-framework/yudao-spring-boot-starter-biz-pay/src/main/java/cn/iocoder/yudao/framework/pay/core/client/impl/PayClientFactoryImpl.java index eb11009d7..64114b264 100644 --- a/yudao-framework/yudao-spring-boot-starter-biz-pay/src/main/java/cn/iocoder/yudao/framework/pay/core/client/impl/PayClientFactoryImpl.java +++ b/yudao-framework/yudao-spring-boot-starter-biz-pay/src/main/java/cn/iocoder/yudao/framework/pay/core/client/impl/PayClientFactoryImpl.java @@ -1,15 +1,8 @@ package cn.iocoder.yudao.framework.pay.core.client.impl; -import cn.hutool.core.lang.Assert; import cn.iocoder.yudao.framework.pay.core.client.PayClient; import cn.iocoder.yudao.framework.pay.core.client.PayClientConfig; import cn.iocoder.yudao.framework.pay.core.client.PayClientFactory; -import cn.iocoder.yudao.framework.pay.core.client.impl.alipay.*; -import cn.iocoder.yudao.framework.pay.core.client.impl.delegate.DelegatePayClient; -import cn.iocoder.yudao.framework.pay.core.client.impl.mock.MockPayClient; -import cn.iocoder.yudao.framework.pay.core.client.impl.mock.MockPayClientConfig; -import cn.iocoder.yudao.framework.pay.core.client.impl.weixin.*; -import cn.iocoder.yudao.framework.pay.core.enums.channel.PayChannelEnum; import lombok.extern.slf4j.Slf4j; import java.util.concurrent.ConcurrentHashMap; @@ -40,48 +33,12 @@ public class PayClientFactoryImpl implements PayClientFactory { @Override @SuppressWarnings("unchecked") - public void createOrUpdatePayClient(Long channelId, String channelCode, - Config config) { - AbstractPayClient client = (AbstractPayClient) clients.get(channelId); - if (client == null) { - client = this.createPayClient(channelId, channelCode, config); + public void addOrUpdatePayClient(Long channelId, AbstractPayClient client) { + AbstractPayClient prePayClient = (AbstractPayClient) clients.putIfAbsent(channelId, client); + if (prePayClient == null) { client.init(); - clients.put(client.getId(), client); } else { - client.refresh(config); + prePayClient.refresh(client.getConfig()); } } - - @Override - public void addOrUpdateDelegatePayClient(Long channelId, DelegatePayClient delegatePayClient) { - clients.put(channelId, delegatePayClient); - } - - @SuppressWarnings("unchecked") - private AbstractPayClient createPayClient( - Long channelId, String channelCode, Config config) { - PayChannelEnum channelEnum = PayChannelEnum.getByCode(channelCode); - Assert.notNull(channelEnum, String.format("支付渠道(%s) 为空", channelEnum)); - // 创建客户端 - switch (channelEnum) { - // 微信支付 - case WX_PUB: return (AbstractPayClient) new WxPubPayClient(channelId, (WxPayClientConfig) config); - case WX_LITE: return (AbstractPayClient) new WxLitePayClient(channelId, (WxPayClientConfig) config); - case WX_APP: return (AbstractPayClient) new WxAppPayClient(channelId, (WxPayClientConfig) config); - case WX_BAR: return (AbstractPayClient) new WxBarPayClient(channelId, (WxPayClientConfig) config); - case WX_NATIVE: return (AbstractPayClient) new WxNativePayClient(channelId, (WxPayClientConfig) config); - // 支付宝支付 - case ALIPAY_WAP: return (AbstractPayClient) new AlipayWapPayClient(channelId, (AlipayPayClientConfig) config); - case ALIPAY_QR: return (AbstractPayClient) new AlipayQrPayClient(channelId, (AlipayPayClientConfig) config); - case ALIPAY_APP: return (AbstractPayClient) new AlipayAppPayClient(channelId, (AlipayPayClientConfig) config); - case ALIPAY_PC: return (AbstractPayClient) new AlipayPcPayClient(channelId, (AlipayPayClientConfig) config); - case ALIPAY_BAR: return (AbstractPayClient) new AlipayBarPayClient(channelId, (AlipayPayClientConfig) config); - // 其它支付 - case MOCK: return (AbstractPayClient) new MockPayClient(channelId, (MockPayClientConfig) config); - } - // 创建失败,错误日志 + 抛出异常 - log.error("[createPayClient][配置({}) 找不到合适的客户端实现]", config); - throw new IllegalArgumentException(String.format("配置(%s) 找不到合适的客户端实现", config)); - } - } diff --git a/yudao-framework/yudao-spring-boot-starter-biz-pay/src/test/java/cn/iocoder/yudao/framework/pay/core/client/impl/PayClientFactoryImplIntegrationTest.java b/yudao-framework/yudao-spring-boot-starter-biz-pay/src/test/java/cn/iocoder/yudao/framework/pay/core/client/impl/PayClientFactoryImplIntegrationTest.java index 984256063..c921d09b9 100644 --- a/yudao-framework/yudao-spring-boot-starter-biz-pay/src/test/java/cn/iocoder/yudao/framework/pay/core/client/impl/PayClientFactoryImplIntegrationTest.java +++ b/yudao-framework/yudao-spring-boot-starter-biz-pay/src/test/java/cn/iocoder/yudao/framework/pay/core/client/impl/PayClientFactoryImplIntegrationTest.java @@ -9,7 +9,6 @@ import cn.iocoder.yudao.framework.pay.core.client.impl.alipay.AlipayQrPayClient; import cn.iocoder.yudao.framework.pay.core.client.impl.alipay.AlipayWapPayClient; import cn.iocoder.yudao.framework.pay.core.client.impl.weixin.WxPayClientConfig; import cn.iocoder.yudao.framework.pay.core.client.impl.weixin.WxPubPayClient; -import cn.iocoder.yudao.framework.pay.core.enums.channel.PayChannelEnum; import org.junit.jupiter.api.Disabled; import org.junit.jupiter.api.Test; @@ -41,7 +40,8 @@ public class PayClientFactoryImplIntegrationTest { config.setMchKey("0alL64UDQdlCwiKZ73ib7ypaIjMns06p"); // 创建客户端 Long channelId = RandomUtil.randomLong(); - payClientFactory.createOrUpdatePayClient(channelId, PayChannelEnum.WX_PUB.getCode(), config); + + payClientFactory.addOrUpdatePayClient(channelId, new WxPubPayClient(channelId, config)); PayClient client = payClientFactory.getPayClient(channelId); // 发起支付 PayOrderUnifiedReqDTO reqDTO = buildPayOrderUnifiedReqDTO(); @@ -64,7 +64,7 @@ public class PayClientFactoryImplIntegrationTest { config.setApiV3Key("joerVi8y5DJ3o4ttA0o1uH47Xz1u2Ase"); // 创建客户端 Long channelId = RandomUtil.randomLong(); - payClientFactory.createOrUpdatePayClient(channelId, PayChannelEnum.WX_PUB.getCode(), config); + payClientFactory.addOrUpdatePayClient(channelId, new WxPubPayClient(channelId, config)); PayClient client = payClientFactory.getPayClient(channelId); // 发起支付 PayOrderUnifiedReqDTO reqDTO = buildPayOrderUnifiedReqDTO(); @@ -87,7 +87,7 @@ public class PayClientFactoryImplIntegrationTest { config.setAlipayPublicKey("MIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEAnq90KnF4dTnlzzmxpujbI05OYqi5WxAS6cL0gnZFv2gK51HExF8v/BaP7P979PhFMgWTqmOOI+Dtno5s+yD09XTY1WkshbLk6i4g2Xlr8fyW9ODnkU88RI2w9UdPhQU4cPPwBNlrsYhKkVK2OxwM3kFqjoBBY0CZoZCsSQ3LDH5WeZqPArlsS6xa2zqJBuuoKjMrdpELl3eXSjP8K54eDJCbeetCZNKWLL3DPahTPB7LZikfYmslb0QUvCgGapD0xkS7eVq70NaL1G57MWABs4tbfWgxike4Daj3EfUrzIVspQxj7w8HEj9WozJPgL88kSJSits0pqD3n5r8HSuseQIDAQAB"); // 创建客户端 Long channelId = RandomUtil.randomLong(); - payClientFactory.createOrUpdatePayClient(channelId, PayChannelEnum.ALIPAY_QR.getCode(), config); + payClientFactory.addOrUpdatePayClient(channelId, new AlipayQrPayClient(channelId, config)); PayClient client = payClientFactory.getPayClient(channelId); // 发起支付 PayOrderUnifiedReqDTO reqDTO = buildPayOrderUnifiedReqDTO(); @@ -111,7 +111,7 @@ public class PayClientFactoryImplIntegrationTest { config.setAlipayPublicKey("MIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEAnq90KnF4dTnlzzmxpujbI05OYqi5WxAS6cL0gnZFv2gK51HExF8v/BaP7P979PhFMgWTqmOOI+Dtno5s+yD09XTY1WkshbLk6i4g2Xlr8fyW9ODnkU88RI2w9UdPhQU4cPPwBNlrsYhKkVK2OxwM3kFqjoBBY0CZoZCsSQ3LDH5WeZqPArlsS6xa2zqJBuuoKjMrdpELl3eXSjP8K54eDJCbeetCZNKWLL3DPahTPB7LZikfYmslb0QUvCgGapD0xkS7eVq70NaL1G57MWABs4tbfWgxike4Daj3EfUrzIVspQxj7w8HEj9WozJPgL88kSJSits0pqD3n5r8HSuseQIDAQAB"); // 创建客户端 Long channelId = RandomUtil.randomLong(); - payClientFactory.createOrUpdatePayClient(channelId, PayChannelEnum.ALIPAY_WAP.getCode(), config); + payClientFactory.addOrUpdatePayClient(channelId, new AlipayWapPayClient(channelId, config)); PayClient client = payClientFactory.getPayClient(channelId); // 发起支付 PayOrderUnifiedReqDTO reqDTO = buildPayOrderUnifiedReqDTO(); diff --git a/yudao-module-pay/yudao-module-pay-biz/src/main/java/cn/iocoder/yudao/module/pay/framework/pay/wallet/WalletPayClient.java b/yudao-module-pay/yudao-module-pay-biz/src/main/java/cn/iocoder/yudao/module/pay/framework/pay/wallet/WalletPayClient.java index 20f66bb0f..08cc52654 100644 --- a/yudao-module-pay/yudao-module-pay-biz/src/main/java/cn/iocoder/yudao/module/pay/framework/pay/wallet/WalletPayClient.java +++ b/yudao-module-pay/yudao-module-pay-biz/src/main/java/cn/iocoder/yudao/module/pay/framework/pay/wallet/WalletPayClient.java @@ -5,8 +5,8 @@ import cn.iocoder.yudao.framework.pay.core.client.dto.order.PayOrderRespDTO; import cn.iocoder.yudao.framework.pay.core.client.dto.order.PayOrderUnifiedReqDTO; import cn.iocoder.yudao.framework.pay.core.client.dto.refund.PayRefundRespDTO; import cn.iocoder.yudao.framework.pay.core.client.dto.refund.PayRefundUnifiedReqDTO; +import cn.iocoder.yudao.framework.pay.core.client.impl.AbstractPayClient; import cn.iocoder.yudao.framework.pay.core.client.impl.NonePayClientConfig; -import cn.iocoder.yudao.framework.pay.core.client.impl.delegate.DelegatePayClient; import cn.iocoder.yudao.module.pay.dal.dataobject.wallet.PayWalletTransactionDO; import cn.iocoder.yudao.module.pay.service.wallet.PayWalletService; import lombok.extern.slf4j.Slf4j; @@ -21,7 +21,7 @@ import static cn.iocoder.yudao.framework.common.exception.enums.GlobalErrorCodeC * @author jason */ @Slf4j -public class WalletPayClient extends DelegatePayClient { +public class WalletPayClient extends AbstractPayClient { private PayWalletService payWalletService; diff --git a/yudao-module-pay/yudao-module-pay-biz/src/main/java/cn/iocoder/yudao/module/pay/service/channel/PayChannelServiceImpl.java b/yudao-module-pay/yudao-module-pay-biz/src/main/java/cn/iocoder/yudao/module/pay/service/channel/PayChannelServiceImpl.java index d29ad973f..3504b98cd 100644 --- a/yudao-module-pay/yudao-module-pay-biz/src/main/java/cn/iocoder/yudao/module/pay/service/channel/PayChannelServiceImpl.java +++ b/yudao-module-pay/yudao-module-pay-biz/src/main/java/cn/iocoder/yudao/module/pay/service/channel/PayChannelServiceImpl.java @@ -6,9 +6,14 @@ import cn.hutool.core.util.ObjectUtil; import cn.iocoder.yudao.framework.common.enums.CommonStatusEnum; import cn.iocoder.yudao.framework.common.util.collection.CollectionUtils; import cn.iocoder.yudao.framework.common.util.json.JsonUtils; -import cn.iocoder.yudao.framework.pay.core.client.impl.NonePayClientConfig; import cn.iocoder.yudao.framework.pay.core.client.PayClientConfig; import cn.iocoder.yudao.framework.pay.core.client.PayClientFactory; +import cn.iocoder.yudao.framework.pay.core.client.impl.AbstractPayClient; +import cn.iocoder.yudao.framework.pay.core.client.impl.NonePayClientConfig; +import cn.iocoder.yudao.framework.pay.core.client.impl.alipay.*; +import cn.iocoder.yudao.framework.pay.core.client.impl.mock.MockPayClient; +import cn.iocoder.yudao.framework.pay.core.client.impl.mock.MockPayClientConfig; +import cn.iocoder.yudao.framework.pay.core.client.impl.weixin.*; import cn.iocoder.yudao.framework.pay.core.enums.channel.PayChannelEnum; import cn.iocoder.yudao.framework.tenant.core.util.TenantUtils; import cn.iocoder.yudao.module.pay.controller.admin.channel.vo.PayChannelCreateReqVO; @@ -29,7 +34,6 @@ import javax.annotation.PostConstruct; import javax.annotation.Resource; import javax.validation.Validator; import java.time.LocalDateTime; -import java.util.ArrayList; import java.util.Collection; import java.util.Collections; import java.util.List; @@ -81,29 +85,55 @@ public class PayChannelServiceImpl implements PayChannelService { log.error("[支付模块 yudao-module-pay - 表结构未导入][参考 https://doc.iocoder.cn/pay/build/ 开启]"); } log.info("[initLocalCache][缓存支付渠道,数量为:{}]", channels.size()); - // 钱包 client 需要和其它 client 分开了创建 - List walletChannels = new ArrayList<>(); - // TODO @jason:有点复杂,看看用 PayClientInitializer 能不能简化 - List otherChannels = new ArrayList<>(); - channels.forEach(t -> { - if (PayChannelEnum.WALLET.getCode().equals(t.getCode())) { - walletChannels.add(t); - } else { - otherChannels.add(t); - } - }); // 第二步:构建缓存:创建或更新支付 Client - otherChannels.forEach(payChannel -> payClientFactory.createOrUpdatePayClient(payChannel.getId(), - payChannel.getCode(), payChannel.getConfig())); + channels.forEach(payChannel ->{ + AbstractPayClient payClient = createPayClient(payChannel.getId(), payChannel.getCode(), payChannel.getConfig()); + payClientFactory.addOrUpdatePayClient(payChannel.getId(), payClient); - walletChannels.forEach(payChannel -> { - WalletPayClient walletPayClient = new WalletPayClient(payChannel.getId(), payChannel.getCode(), - (NonePayClientConfig) payChannel.getConfig(), payWalletService); - payClientFactory.addOrUpdateDelegatePayClient(payChannel.getId(), walletPayClient); }); this.channelCache = channels; }); } + @SuppressWarnings("unchecked") + private AbstractPayClient createPayClient( + Long channelId, String channelCode, Config config) { + PayChannelEnum channelEnum = PayChannelEnum.getByCode(channelCode); + Assert.notNull(channelEnum, String.format("支付渠道(%s) 为空", channelEnum)); + // 创建客户端 + switch (channelEnum) { + // 微信支付 + case WX_PUB: + return (AbstractPayClient) new WxPubPayClient(channelId, (WxPayClientConfig) config); + case WX_LITE: + return (AbstractPayClient) new WxLitePayClient(channelId, (WxPayClientConfig) config); + case WX_APP: + return (AbstractPayClient) new WxAppPayClient(channelId, (WxPayClientConfig) config); + case WX_BAR: + return (AbstractPayClient) new WxBarPayClient(channelId, (WxPayClientConfig) config); + case WX_NATIVE: + return (AbstractPayClient) new WxNativePayClient(channelId, (WxPayClientConfig) config); + // 支付宝支付 + case ALIPAY_WAP: + return (AbstractPayClient) new AlipayWapPayClient(channelId, (AlipayPayClientConfig) config); + case ALIPAY_QR: + return (AbstractPayClient) new AlipayQrPayClient(channelId, (AlipayPayClientConfig) config); + case ALIPAY_APP: + return (AbstractPayClient) new AlipayAppPayClient(channelId, (AlipayPayClientConfig) config); + case ALIPAY_PC: + return (AbstractPayClient) new AlipayPcPayClient(channelId, (AlipayPayClientConfig) config); + case ALIPAY_BAR: + return (AbstractPayClient) new AlipayBarPayClient(channelId, (AlipayPayClientConfig) config); + // 其它支付 + case MOCK: + return (AbstractPayClient) new MockPayClient(channelId, (MockPayClientConfig) config); + case WALLET: + return (AbstractPayClient) new WalletPayClient( + channelId, channelCode, (NonePayClientConfig) config, payWalletService); + } + // 创建失败,错误日志 + 抛出异常 + log.error("[createPayClient][配置({}) 找不到合适的客户端实现]", config); + throw new IllegalArgumentException(String.format("配置(%s) 找不到合适的客户端实现", config)); + } /** * 通过定时任务轮询,刷新缓存