From d556eae5569ad2faedd74e82f8973dd5c61ccf0d Mon Sep 17 00:00:00 2001 From: chen quan <18975233382@163.com> Date: Wed, 29 Dec 2021 19:47:59 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BC=98=E5=8C=96=20=E6=94=AF=E4=BB=98?= =?UTF-8?q?=E9=85=8D=E7=BD=AE=E6=A0=A1=E9=AA=8C=E6=96=B9=E5=BC=8F=EF=BC=8C?= =?UTF-8?q?=E4=BC=98=E5=8C=96=E4=B8=9A=E5=8A=A1=E5=B1=82=E5=BC=82=E5=B8=B8?= =?UTF-8?q?=E6=8A=9B=E5=87=BA=E7=B1=BB=E5=9E=8B=EF=BC=8C=E4=BC=98=E5=8C=96?= =?UTF-8?q?=E6=94=AF=E4=BB=98=E5=BA=94=E7=94=A8=E6=B8=B2=E6=9F=93=E9=80=BB?= =?UTF-8?q?=E8=BE=91=EF=BC=8C=E6=B7=BB=E5=8A=A0=E5=88=A0=E9=99=A4=E6=94=AF?= =?UTF-8?q?=E4=BB=98=E5=95=86=E6=88=B7=20=E6=94=AF=E4=BB=98=E5=BA=94?= =?UTF-8?q?=E7=94=A8=E7=9A=84=E6=A0=A1=E9=AA=8C=EF=BC=8C=E9=80=80=E6=AC=BE?= =?UTF-8?q?=E8=AE=A2=E5=8D=95=E5=8E=BB=E9=99=A4reqNo=E5=AD=97=E6=AE=B5?= =?UTF-8?q?=EF=BC=8C=E6=94=AF=E4=BB=98=E8=AE=A2=E5=8D=95=E5=8E=BB=E9=99=A4?= =?UTF-8?q?=20channelExtras=20=E5=8F=82=E6=95=B0=E5=B1=95=E7=A4=BA?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../pay/controller/app/PayAppController.java | 38 ++---- .../app/vo/PayAppPageItemRespVO.java | 42 ++----- .../merchant/PayMerchantController.java | 2 +- .../merchant/vo/PayMerchantExcelVO.java | 9 +- .../order/vo/order/PayOrderDetailsRespVO.java | 3 - .../order/vo/refund/vo/PayRefundBaseVO.java | 4 - .../order/vo/refund/vo/PayRefundExcelVO.java | 3 - .../vo/refund/vo/PayRefundExportReqVO.java | 3 - .../vo/refund/vo/PayRefundPageReqVO.java | 3 - .../pay/convert/order/PayOrderConvert.java | 6 - .../pay/convert/refund/PayRefundConvert.java | 1 - .../pay/dal/mysql/app/PayAppMapper.java | 14 ++- .../dal/mysql/channel/PayChannelMapper.java | 5 +- .../pay/dal/mysql/order/PayOrderMapper.java | 14 +++ .../pay/dal/mysql/order/PayRefundMapper.java | 16 ++- .../service/app/impl/PayAppServiceImpl.java | 34 ++++- .../channel/impl/PayChannelServiceImpl.java | 20 +-- .../service/merchant/PayMerchantService.java | 2 +- .../merchant/impl/PayMerchantServiceImpl.java | 58 +++++---- .../src/main/resources/application.yaml | 2 - .../service/refund/PayRefundServiceTest.java | 6 - yudao-admin-ui/src/api/pay/merchant.js | 2 +- yudao-admin-ui/src/utils/dict.js | 6 - .../pay/app/components/aliPayChannelForm.vue | 8 +- .../pay/app/components/wechatChannelForm.vue | 8 +- yudao-admin-ui/src/views/pay/app/index.vue | 118 +++++++++--------- .../src/views/pay/merchant/index.vue | 4 +- yudao-admin-ui/src/views/pay/order/index.vue | 4 - yudao-admin-ui/src/views/pay/refund/index.vue | 26 ++-- .../pay/enums/PayErrorCodeCoreConstants.java | 2 + .../pay/core/client/PayClientConfig.java | 23 +++- .../impl/alipay/AlipayPayClientConfig.java | 18 +-- .../client/impl/wx/WXPayClientConfig.java | 16 +-- .../pay/core/enums/PayChannelEnum.java | 47 +++---- 34 files changed, 267 insertions(+), 300 deletions(-) diff --git a/yudao-admin-server/src/main/java/cn/iocoder/yudao/adminserver/modules/pay/controller/app/PayAppController.java b/yudao-admin-server/src/main/java/cn/iocoder/yudao/adminserver/modules/pay/controller/app/PayAppController.java index e902eff35..0384e340b 100644 --- a/yudao-admin-server/src/main/java/cn/iocoder/yudao/adminserver/modules/pay/controller/app/PayAppController.java +++ b/yudao-admin-server/src/main/java/cn/iocoder/yudao/adminserver/modules/pay/controller/app/PayAppController.java @@ -1,7 +1,6 @@ package cn.iocoder.yudao.adminserver.modules.pay.controller.app; import cn.hutool.core.collection.CollUtil; -import cn.hutool.core.util.StrUtil; import cn.iocoder.yudao.adminserver.modules.pay.controller.app.vo.*; import cn.iocoder.yudao.adminserver.modules.pay.convert.app.PayAppConvert; import cn.iocoder.yudao.adminserver.modules.pay.service.app.PayAppService; @@ -10,12 +9,12 @@ import cn.iocoder.yudao.adminserver.modules.pay.service.merchant.PayMerchantServ import cn.iocoder.yudao.coreservice.modules.pay.dal.dataobject.merchant.PayAppDO; import cn.iocoder.yudao.coreservice.modules.pay.dal.dataobject.merchant.PayChannelDO; import cn.iocoder.yudao.coreservice.modules.pay.dal.dataobject.merchant.PayMerchantDO; -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.excel.core.util.ExcelUtils; import cn.iocoder.yudao.framework.operatelog.core.annotations.OperateLog; +import cn.iocoder.yudao.framework.pay.core.enums.PayChannelEnum; import io.swagger.annotations.Api; import io.swagger.annotations.ApiImplicitParam; import io.swagger.annotations.ApiOperation; @@ -28,20 +27,11 @@ import javax.annotation.Resource; import javax.servlet.http.HttpServletResponse; import javax.validation.Valid; import java.io.IOException; -import java.lang.reflect.InvocationTargetException; -import java.util.ArrayList; -import java.util.Collection; -import java.util.List; -import java.util.Map; +import java.util.*; import static cn.iocoder.yudao.framework.common.pojo.CommonResult.success; import static cn.iocoder.yudao.framework.operatelog.core.enums.OperateTypeEnum.EXPORT; -/** - * 支付应用信息 controller 组件 - * - * @author aquan - */ // TODO @aquan:一般 controller 上就不写注释了,因为有 swagger 注解,不然就重复啦 @Slf4j @Api(tags = "支付应用信息") @RestController @@ -119,6 +109,7 @@ public class PayAppController { // 得到所有的应用编号,查出所有的通道 Collection payAppIds = CollectionUtils.convertList(pageResult.getList(), PayAppDO::getId); List channels = channelService.getChannelListByAppIds(payAppIds); + Iterator iterator = channels.iterator(); // 得到所有的商户信息 Collection merchantIds = CollectionUtils.convertList(pageResult.getList(), PayAppDO::getMerchantId); @@ -132,22 +123,15 @@ public class PayAppController { // 写入商户的数据 respVO.setPayMerchant(PayAppConvert.INSTANCE.convert(deptMap.get(app.getMerchantId()))); // 写入支付渠道信息的数据 - // TODO @aquan:VO 里返回的 payChannel,是不是用一个 Set 集合就好了,里面是渠道的枚举值 - PayAppPageItemRespVO.PayChannel payChannel = new PayAppPageItemRespVO.PayChannel(); - channels.forEach(c -> { - if (c.getAppId().equals(app.getId())) { - // 获取 set 方法 - String methodName = StrUtil.toCamelCase("set_" + c.getCode()); - try { - // 根据 set 方法将值写入 - payChannel.getClass().getMethod(methodName, Integer.class) - .invoke(payChannel, CommonStatusEnum.ENABLE.getStatus()); - } catch (IllegalAccessException | NoSuchMethodException | InvocationTargetException e) { - log.error("[getAppPage]调用方法[{}]设置参数[{}]异常", c.getCode(), methodName); - } + Set channelCodes = new HashSet<>(PayChannelEnum.values().length); + while (iterator.hasNext()) { + PayChannelDO channelDO = iterator.next(); + if (channelDO.getAppId().equals(app.getId())) { + channelCodes.add(channelDO.getCode()); + iterator.remove(); } - }); - respVO.setPayChannel(payChannel); + } + respVO.setChannelCodes(channelCodes); appList.add(respVO); }); diff --git a/yudao-admin-server/src/main/java/cn/iocoder/yudao/adminserver/modules/pay/controller/app/vo/PayAppPageItemRespVO.java b/yudao-admin-server/src/main/java/cn/iocoder/yudao/adminserver/modules/pay/controller/app/vo/PayAppPageItemRespVO.java index 742ee62e3..6d8144afe 100644 --- a/yudao-admin-server/src/main/java/cn/iocoder/yudao/adminserver/modules/pay/controller/app/vo/PayAppPageItemRespVO.java +++ b/yudao-admin-server/src/main/java/cn/iocoder/yudao/adminserver/modules/pay/controller/app/vo/PayAppPageItemRespVO.java @@ -1,6 +1,5 @@ package cn.iocoder.yudao.adminserver.modules.pay.controller.app.vo; -import cn.iocoder.yudao.framework.common.enums.CommonStatusEnum; import io.swagger.annotations.ApiModel; import io.swagger.annotations.ApiModelProperty; import lombok.Data; @@ -8,7 +7,13 @@ import lombok.EqualsAndHashCode; import lombok.ToString; import java.util.Date; +import java.util.Set; +/** + * 支付应用信息分页查询 Response VO + * + * @author aquan + */ @ApiModel(value = "支付应用信息分页查询 Response VO", description = "相比于支付信息,还会多出应用渠道的开关信息") @Data @EqualsAndHashCode(callSuper = true) @@ -38,39 +43,8 @@ public class PayAppPageItemRespVO extends PayAppBaseVO { } - /** - * 支付渠道 - */ - private PayChannel payChannel; + @ApiModelProperty(value = "渠道编码集合", required = true, example = "alipay_pc,alipay_wap...") + private Set channelCodes; - /** - * 支付渠道开通情况 - * 1默认为未开通当前支付渠道,0为已开通支付渠道 - */ - @Data - @ApiModel("支付渠道") - public static class PayChannel { - - @ApiModelProperty(value = "微信 JSAPI 支付", required = true, example = "1") - private Integer wxPub = CommonStatusEnum.DISABLE.getStatus(); - - @ApiModelProperty(value = "微信小程序支付", required = true, example = "1") - private Integer wxLite = CommonStatusEnum.DISABLE.getStatus(); - - @ApiModelProperty(value = "微信 App 支付", required = true, example = "1") - private Integer wxApp = CommonStatusEnum.DISABLE.getStatus(); - - @ApiModelProperty(value = "支付宝 PC 网站支付", required = true, example = "1") - private Integer alipayPc = CommonStatusEnum.DISABLE.getStatus(); - - @ApiModelProperty(value = "支付宝 Wap 网站支付", required = true, example = "1") - private Integer alipayWap = CommonStatusEnum.DISABLE.getStatus(); - - @ApiModelProperty(value = "支付宝App 支付", required = true, example = "1") - private Integer alipayApp = CommonStatusEnum.DISABLE.getStatus(); - - @ApiModelProperty(value = "支付宝扫码支付", required = true, example = "1") - private Integer alipayQr = CommonStatusEnum.DISABLE.getStatus(); - } } diff --git a/yudao-admin-server/src/main/java/cn/iocoder/yudao/adminserver/modules/pay/controller/merchant/PayMerchantController.java b/yudao-admin-server/src/main/java/cn/iocoder/yudao/adminserver/modules/pay/controller/merchant/PayMerchantController.java index 54f8056c8..b581e99ff 100644 --- a/yudao-admin-server/src/main/java/cn/iocoder/yudao/adminserver/modules/pay/controller/merchant/PayMerchantController.java +++ b/yudao-admin-server/src/main/java/cn/iocoder/yudao/adminserver/modules/pay/controller/merchant/PayMerchantController.java @@ -75,7 +75,7 @@ public class PayMerchantController { return success(PayMerchantConvert.INSTANCE.convert(merchant)); } - @GetMapping("/list-name") // TODO @aquan:/list-name =》/list-by-name + @GetMapping("/list-by-name") @ApiOperation("根据商户名称获得支付商户信息列表") @ApiImplicitParam(name = "name", value = "商户名称", example = "芋道", dataTypeClass = Long.class) @PreAuthorize("@ss.hasPermission('pay:merchant:query')") diff --git a/yudao-admin-server/src/main/java/cn/iocoder/yudao/adminserver/modules/pay/controller/merchant/vo/PayMerchantExcelVO.java b/yudao-admin-server/src/main/java/cn/iocoder/yudao/adminserver/modules/pay/controller/merchant/vo/PayMerchantExcelVO.java index 80c206c2d..cb229fb11 100644 --- a/yudao-admin-server/src/main/java/cn/iocoder/yudao/adminserver/modules/pay/controller/merchant/vo/PayMerchantExcelVO.java +++ b/yudao-admin-server/src/main/java/cn/iocoder/yudao/adminserver/modules/pay/controller/merchant/vo/PayMerchantExcelVO.java @@ -2,11 +2,10 @@ package cn.iocoder.yudao.adminserver.modules.pay.controller.merchant.vo; import cn.iocoder.yudao.framework.excel.core.annotations.DictFormat; import cn.iocoder.yudao.framework.excel.core.convert.DictConvert; -import lombok.*; -import java.util.*; -import io.swagger.annotations.*; - import com.alibaba.excel.annotation.ExcelProperty; +import lombok.Data; + +import java.util.Date; /** * 支付商户信息 Excel VO @@ -29,7 +28,7 @@ public class PayMerchantExcelVO { private String shortName; @ExcelProperty(value = "开启状态",converter = DictConvert.class) - @DictFormat("pay_merchant_status") + @DictFormat("sys_common_status") private Integer status; @ExcelProperty("备注") diff --git a/yudao-admin-server/src/main/java/cn/iocoder/yudao/adminserver/modules/pay/controller/order/vo/order/PayOrderDetailsRespVO.java b/yudao-admin-server/src/main/java/cn/iocoder/yudao/adminserver/modules/pay/controller/order/vo/order/PayOrderDetailsRespVO.java index 8db4c1dd3..d85a9bcb1 100644 --- a/yudao-admin-server/src/main/java/cn/iocoder/yudao/adminserver/modules/pay/controller/order/vo/order/PayOrderDetailsRespVO.java +++ b/yudao-admin-server/src/main/java/cn/iocoder/yudao/adminserver/modules/pay/controller/order/vo/order/PayOrderDetailsRespVO.java @@ -46,9 +46,6 @@ public class PayOrderDetailsRespVO extends PayOrderBaseVO { @ApiModelProperty(value = "支付订单号") private String no; - @ApiModelProperty(value = "支付渠道的额外参数") - private String channelExtras; - @ApiModelProperty(value = "支付异步通知的内容") private String channelNotifyData; } diff --git a/yudao-admin-server/src/main/java/cn/iocoder/yudao/adminserver/modules/pay/controller/order/vo/refund/vo/PayRefundBaseVO.java b/yudao-admin-server/src/main/java/cn/iocoder/yudao/adminserver/modules/pay/controller/order/vo/refund/vo/PayRefundBaseVO.java index 87d75d597..c8421b035 100755 --- a/yudao-admin-server/src/main/java/cn/iocoder/yudao/adminserver/modules/pay/controller/order/vo/refund/vo/PayRefundBaseVO.java +++ b/yudao-admin-server/src/main/java/cn/iocoder/yudao/adminserver/modules/pay/controller/order/vo/refund/vo/PayRefundBaseVO.java @@ -16,10 +16,6 @@ import static cn.iocoder.yudao.framework.common.util.date.DateUtils.FORMAT_YEAR_ @Data public class PayRefundBaseVO { - @ApiModelProperty(value = "退款单请求号", required = true) - @NotNull(message = "退款单请求号不能为空") - private String reqNo; - @ApiModelProperty(value = "商户编号", required = true) @NotNull(message = "商户编号不能为空") private Long merchantId; diff --git a/yudao-admin-server/src/main/java/cn/iocoder/yudao/adminserver/modules/pay/controller/order/vo/refund/vo/PayRefundExcelVO.java b/yudao-admin-server/src/main/java/cn/iocoder/yudao/adminserver/modules/pay/controller/order/vo/refund/vo/PayRefundExcelVO.java index edc394a1a..be90f1a61 100755 --- a/yudao-admin-server/src/main/java/cn/iocoder/yudao/adminserver/modules/pay/controller/order/vo/refund/vo/PayRefundExcelVO.java +++ b/yudao-admin-server/src/main/java/cn/iocoder/yudao/adminserver/modules/pay/controller/order/vo/refund/vo/PayRefundExcelVO.java @@ -22,9 +22,6 @@ public class PayRefundExcelVO { @ExcelProperty("商品名称") private String subject; - @ExcelProperty("退款单请求号") - private String reqNo; - @ExcelProperty(value = "商户名称") private String merchantName; diff --git a/yudao-admin-server/src/main/java/cn/iocoder/yudao/adminserver/modules/pay/controller/order/vo/refund/vo/PayRefundExportReqVO.java b/yudao-admin-server/src/main/java/cn/iocoder/yudao/adminserver/modules/pay/controller/order/vo/refund/vo/PayRefundExportReqVO.java index 4e8cc6f6b..5a0e9c4e0 100755 --- a/yudao-admin-server/src/main/java/cn/iocoder/yudao/adminserver/modules/pay/controller/order/vo/refund/vo/PayRefundExportReqVO.java +++ b/yudao-admin-server/src/main/java/cn/iocoder/yudao/adminserver/modules/pay/controller/order/vo/refund/vo/PayRefundExportReqVO.java @@ -13,9 +13,6 @@ import static cn.iocoder.yudao.framework.common.util.date.DateUtils.FORMAT_YEAR_ @Data public class PayRefundExportReqVO { - @ApiModelProperty(value = "退款单请求号") - private String reqNo; - @ApiModelProperty(value = "商户编号") private Long merchantId; diff --git a/yudao-admin-server/src/main/java/cn/iocoder/yudao/adminserver/modules/pay/controller/order/vo/refund/vo/PayRefundPageReqVO.java b/yudao-admin-server/src/main/java/cn/iocoder/yudao/adminserver/modules/pay/controller/order/vo/refund/vo/PayRefundPageReqVO.java index eddfddfee..103a7a27c 100755 --- a/yudao-admin-server/src/main/java/cn/iocoder/yudao/adminserver/modules/pay/controller/order/vo/refund/vo/PayRefundPageReqVO.java +++ b/yudao-admin-server/src/main/java/cn/iocoder/yudao/adminserver/modules/pay/controller/order/vo/refund/vo/PayRefundPageReqVO.java @@ -18,9 +18,6 @@ import static cn.iocoder.yudao.framework.common.util.date.DateUtils.FORMAT_YEAR_ @ToString(callSuper = true) public class PayRefundPageReqVO extends PageParam { - @ApiModelProperty(value = "退款单请求号") - private String reqNo; - @ApiModelProperty(value = "商户编号") private Long merchantId; diff --git a/yudao-admin-server/src/main/java/cn/iocoder/yudao/adminserver/modules/pay/convert/order/PayOrderConvert.java b/yudao-admin-server/src/main/java/cn/iocoder/yudao/adminserver/modules/pay/convert/order/PayOrderConvert.java index 7af6201a5..308298ac6 100755 --- a/yudao-admin-server/src/main/java/cn/iocoder/yudao/adminserver/modules/pay/convert/order/PayOrderConvert.java +++ b/yudao-admin-server/src/main/java/cn/iocoder/yudao/adminserver/modules/pay/convert/order/PayOrderConvert.java @@ -8,8 +8,6 @@ import cn.iocoder.yudao.coreservice.modules.pay.dal.dataobject.order.PayOrderDO; import cn.iocoder.yudao.coreservice.modules.pay.dal.dataobject.order.PayOrderExtensionDO; import cn.iocoder.yudao.framework.common.pojo.PageResult; import org.mapstruct.Mapper; -import org.mapstruct.Mapping; -import org.mapstruct.Mappings; import org.mapstruct.factory.Mappers; import java.math.BigDecimal; @@ -44,10 +42,6 @@ public interface PayOrderConvert { * @param bean 订单扩展DO * @return 详细订单扩展 RespVO */ - @Mappings({ - @Mapping(target = "channelExtras" - , expression = "java(bean.getChannelExtras() != null ? bean.getChannelExtras().toString():null)") - }) PayOrderDetailsRespVO.PayOrderExtension orderDetailExtensionConvert(PayOrderExtensionDO bean); List convertList(List list); diff --git a/yudao-admin-server/src/main/java/cn/iocoder/yudao/adminserver/modules/pay/convert/refund/PayRefundConvert.java b/yudao-admin-server/src/main/java/cn/iocoder/yudao/adminserver/modules/pay/convert/refund/PayRefundConvert.java index fe4d2a44d..8f5ee66d3 100755 --- a/yudao-admin-server/src/main/java/cn/iocoder/yudao/adminserver/modules/pay/convert/refund/PayRefundConvert.java +++ b/yudao-admin-server/src/main/java/cn/iocoder/yudao/adminserver/modules/pay/convert/refund/PayRefundConvert.java @@ -62,7 +62,6 @@ public interface PayRefundConvert { PayRefundExcelVO payRefundExcelVO = new PayRefundExcelVO(); payRefundExcelVO.setId(bean.getId()); - payRefundExcelVO.setReqNo(bean.getReqNo()); payRefundExcelVO.setTradeNo(bean.getTradeNo()); payRefundExcelVO.setMerchantOrderId(bean.getMerchantOrderId()); payRefundExcelVO.setMerchantRefundNo(bean.getMerchantRefundNo()); diff --git a/yudao-admin-server/src/main/java/cn/iocoder/yudao/adminserver/modules/pay/dal/mysql/app/PayAppMapper.java b/yudao-admin-server/src/main/java/cn/iocoder/yudao/adminserver/modules/pay/dal/mysql/app/PayAppMapper.java index c73490f35..c6e3b38e9 100644 --- a/yudao-admin-server/src/main/java/cn/iocoder/yudao/adminserver/modules/pay/dal/mysql/app/PayAppMapper.java +++ b/yudao-admin-server/src/main/java/cn/iocoder/yudao/adminserver/modules/pay/dal/mysql/app/PayAppMapper.java @@ -60,12 +60,24 @@ public interface PayAppMapper extends BaseMapperX { /** * 根据 商户 ID 查询支付应用信息 + * * @param merchantId 商户 ID * @return 支付应用信息列表 */ - default List getListByMerchantId(String merchantId){ + default List getListByMerchantId(String merchantId) { return selectList(new LambdaQueryWrapper() .select(PayAppDO::getId, PayAppDO::getName) .eq(PayAppDO::getMerchantId, merchantId)); } + + /** + * 根据商户号统计存在的支付应用数量 + * + * @param merchantId 商户 ID + * @return 支付应用数量 + */ + default Long selectCount(Long merchantId) { + return selectCount(new LambdaQueryWrapper().eq(PayAppDO::getMerchantId, merchantId)); + } + } diff --git a/yudao-admin-server/src/main/java/cn/iocoder/yudao/adminserver/modules/pay/dal/mysql/channel/PayChannelMapper.java b/yudao-admin-server/src/main/java/cn/iocoder/yudao/adminserver/modules/pay/dal/mysql/channel/PayChannelMapper.java index f02cf53a7..54a4829a9 100644 --- a/yudao-admin-server/src/main/java/cn/iocoder/yudao/adminserver/modules/pay/dal/mysql/channel/PayChannelMapper.java +++ b/yudao-admin-server/src/main/java/cn/iocoder/yudao/adminserver/modules/pay/dal/mysql/channel/PayChannelMapper.java @@ -55,8 +55,7 @@ public interface PayChannelMapper extends BaseMapperX { * @param code 通道编码 * @return 数量 */ - // TODO @aquan:Mapper 的操作,和 db 保持一致 - default Integer getChannelCountByConditions(Long merchantId, Long appid, String code) { + default Integer selectCount(Long merchantId, Long appid, String code) { return this.selectCount(new QueryWrapper().lambda() .eq(PayChannelDO::getMerchantId, merchantId) .eq(PayChannelDO::getAppId, appid) @@ -71,7 +70,7 @@ public interface PayChannelMapper extends BaseMapperX { * @param code 通道编码 * @return 数量 */ - default PayChannelDO getChannelByConditions(Long merchantId, Long appid, String code) { + default PayChannelDO selectOne(Long merchantId, Long appid, String code) { return this.selectOne((new QueryWrapper().lambda() .eq(PayChannelDO::getMerchantId, merchantId) .eq(PayChannelDO::getAppId, appid) diff --git a/yudao-admin-server/src/main/java/cn/iocoder/yudao/adminserver/modules/pay/dal/mysql/order/PayOrderMapper.java b/yudao-admin-server/src/main/java/cn/iocoder/yudao/adminserver/modules/pay/dal/mysql/order/PayOrderMapper.java index 39fc71287..1fb9e870a 100755 --- a/yudao-admin-server/src/main/java/cn/iocoder/yudao/adminserver/modules/pay/dal/mysql/order/PayOrderMapper.java +++ b/yudao-admin-server/src/main/java/cn/iocoder/yudao/adminserver/modules/pay/dal/mysql/order/PayOrderMapper.java @@ -62,4 +62,18 @@ public interface PayOrderMapper extends BaseMapperX { .in(PayOrderDO::getId, idList)); } + /** + * 查询符合的订单数量 + * + * @param appId 应用编号 + * @param status 订单状态 + * @return 条数 + */ + default Long selectCount(Long appId, Integer status) { + + return selectCount(new LambdaQueryWrapper() + .eq(PayOrderDO::getAppId, appId) + .in(PayOrderDO::getStatus, status)); + } + } diff --git a/yudao-admin-server/src/main/java/cn/iocoder/yudao/adminserver/modules/pay/dal/mysql/order/PayRefundMapper.java b/yudao-admin-server/src/main/java/cn/iocoder/yudao/adminserver/modules/pay/dal/mysql/order/PayRefundMapper.java index c5f9c632b..2fd3f2299 100755 --- a/yudao-admin-server/src/main/java/cn/iocoder/yudao/adminserver/modules/pay/dal/mysql/order/PayRefundMapper.java +++ b/yudao-admin-server/src/main/java/cn/iocoder/yudao/adminserver/modules/pay/dal/mysql/order/PayRefundMapper.java @@ -6,6 +6,7 @@ import cn.iocoder.yudao.coreservice.modules.pay.dal.dataobject.order.PayRefundDO import cn.iocoder.yudao.framework.common.pojo.PageResult; import cn.iocoder.yudao.framework.mybatis.core.mapper.BaseMapperX; import cn.iocoder.yudao.framework.mybatis.core.query.QueryWrapperX; +import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; import org.apache.ibatis.annotations.Mapper; import java.util.List; @@ -20,7 +21,6 @@ public interface PayRefundMapper extends BaseMapperX { default PageResult selectPage(PayRefundPageReqVO reqVO) { return selectPage(reqVO, new QueryWrapperX() - .likeIfPresent("req_no", reqVO.getReqNo()) .eqIfPresent("merchant_id", reqVO.getMerchantId()) .eqIfPresent("app_id", reqVO.getAppId()) .eqIfPresent("channel_code", reqVO.getChannelCode()) @@ -37,7 +37,6 @@ public interface PayRefundMapper extends BaseMapperX { .eqIfPresent("merchant_id", reqVO.getMerchantId()) .eqIfPresent("app_id", reqVO.getAppId()) .eqIfPresent("channel_code", reqVO.getChannelCode()) - .likeIfPresent("req_no", reqVO.getReqNo()) .likeIfPresent("merchant_refund_no", reqVO.getMerchantRefundNo()) .eqIfPresent("type", reqVO.getType()) .eqIfPresent("status", reqVO.getStatus()) @@ -46,4 +45,17 @@ public interface PayRefundMapper extends BaseMapperX { .orderByDesc("id")); } + /** + * 查询符合的订单数量 + * + * @param appId 应用编号 + * @param status 订单状态 + * @return 条数 + */ + default Long selectCount(Long appId, Integer status) { + + return selectCount(new LambdaQueryWrapper() + .eq(PayRefundDO::getAppId, appId) + .eq(PayRefundDO::getStatus, status)); + } } diff --git a/yudao-admin-server/src/main/java/cn/iocoder/yudao/adminserver/modules/pay/service/app/impl/PayAppServiceImpl.java b/yudao-admin-server/src/main/java/cn/iocoder/yudao/adminserver/modules/pay/service/app/impl/PayAppServiceImpl.java index 4945a82b5..17b3e04e0 100644 --- a/yudao-admin-server/src/main/java/cn/iocoder/yudao/adminserver/modules/pay/service/app/impl/PayAppServiceImpl.java +++ b/yudao-admin-server/src/main/java/cn/iocoder/yudao/adminserver/modules/pay/service/app/impl/PayAppServiceImpl.java @@ -9,9 +9,13 @@ import cn.iocoder.yudao.adminserver.modules.pay.controller.app.vo.PayAppUpdateRe import cn.iocoder.yudao.adminserver.modules.pay.convert.app.PayAppConvert; import cn.iocoder.yudao.adminserver.modules.pay.dal.mysql.app.PayAppMapper; import cn.iocoder.yudao.adminserver.modules.pay.dal.mysql.merchant.PayMerchantMapper; +import cn.iocoder.yudao.adminserver.modules.pay.dal.mysql.order.PayOrderMapper; +import cn.iocoder.yudao.adminserver.modules.pay.dal.mysql.order.PayRefundMapper; import cn.iocoder.yudao.adminserver.modules.pay.service.app.PayAppService; import cn.iocoder.yudao.coreservice.modules.pay.dal.dataobject.merchant.PayAppDO; import cn.iocoder.yudao.coreservice.modules.pay.dal.dataobject.merchant.PayMerchantDO; +import cn.iocoder.yudao.coreservice.modules.pay.enums.order.PayOrderStatusEnum; +import cn.iocoder.yudao.coreservice.modules.pay.enums.order.PayRefundStatusEnum; import cn.iocoder.yudao.framework.common.enums.CommonStatusEnum; import cn.iocoder.yudao.framework.common.pojo.PageResult; import com.google.common.annotations.VisibleForTesting; @@ -21,7 +25,7 @@ import org.springframework.validation.annotation.Validated; import javax.annotation.Resource; import java.util.*; -import static cn.iocoder.yudao.coreservice.modules.pay.enums.PayErrorCodeCoreConstants.PAY_APP_NOT_FOUND; +import static cn.iocoder.yudao.coreservice.modules.pay.enums.PayErrorCodeCoreConstants.*; import static cn.iocoder.yudao.framework.common.exception.util.ServiceExceptionUtil.exception; import static cn.iocoder.yudao.framework.common.util.collection.CollectionUtils.convertSet; @@ -36,9 +40,17 @@ public class PayAppServiceImpl implements PayAppService { @Resource private PayAppMapper appMapper; + @Resource private PayMerchantMapper merchantMapper; + @Resource + private PayOrderMapper orderMapper; + + @Resource + private PayRefundMapper refundMapper; + + @Override public Long createApp(PayAppCreateReqVO createReqVO) { // 插入 @@ -61,7 +73,8 @@ public class PayAppServiceImpl implements PayAppService { public void deleteApp(Long id) { // 校验存在 this.validateAppExists(id); - // TODO aquan:校验是否存在进行中的支付单、退款单,如果是,则不允许删除。 + this.validateOrderTransactionExist(id); + // 删除 appMapper.deleteById(id); } @@ -157,4 +170,21 @@ public class PayAppServiceImpl implements PayAppService { } } + /** + * 验证是否存在交易中或者退款中等处理中状态的订单 + * + * @param appId 应用 ID + */ + private void validateOrderTransactionExist(Long appId) { + // 查看交易订单 + if (orderMapper.selectCount(appId, PayOrderStatusEnum.WAITING.getStatus()) > 0) { + throw exception(PAY_APP_EXIST_TRANSACTION_ORDER_CANT_DELETE); + } + // 查看退款订单 + if (refundMapper.selectCount(appId, PayRefundStatusEnum.CREATE.getStatus()) > 0) { + throw exception(PAY_APP_EXIST_TRANSACTION_ORDER_CANT_DELETE); + } + + } + } diff --git a/yudao-admin-server/src/main/java/cn/iocoder/yudao/adminserver/modules/pay/service/channel/impl/PayChannelServiceImpl.java b/yudao-admin-server/src/main/java/cn/iocoder/yudao/adminserver/modules/pay/service/channel/impl/PayChannelServiceImpl.java index 7f96b34f5..6ba21f8c3 100644 --- a/yudao-admin-server/src/main/java/cn/iocoder/yudao/adminserver/modules/pay/service/channel/impl/PayChannelServiceImpl.java +++ b/yudao-admin-server/src/main/java/cn/iocoder/yudao/adminserver/modules/pay/service/channel/impl/PayChannelServiceImpl.java @@ -1,5 +1,6 @@ package cn.iocoder.yudao.adminserver.modules.pay.service.channel.impl; +import cn.hutool.core.util.ObjectUtil; import cn.hutool.json.JSONUtil; import cn.iocoder.yudao.adminserver.modules.pay.controller.channel.vo.PayChannelCreateReqVO; import cn.iocoder.yudao.adminserver.modules.pay.controller.channel.vo.PayChannelExportReqVO; @@ -14,7 +15,6 @@ import cn.iocoder.yudao.framework.pay.core.client.PayClientConfig; import cn.iocoder.yudao.framework.pay.core.enums.PayChannelEnum; import lombok.extern.slf4j.Slf4j; import org.springframework.stereotype.Service; -import org.springframework.util.Assert; import org.springframework.validation.annotation.Validated; import javax.annotation.Resource; @@ -46,8 +46,9 @@ public class PayChannelServiceImpl implements PayChannelService { public Long createChannel(PayChannelCreateReqVO reqVO) { // 断言是否有重复的 PayChannelDO channelDO = this.getChannelByConditions(reqVO.getMerchantId(), reqVO.getAppId(), reqVO.getCode()); - // TODO @aquan:这里会抛出系统异常,不会抛出 ServiceException - Assert.isNull(channelDO, CHANNEL_EXIST_SAME_CHANNEL_ERROR.getMsg()); + if (ObjectUtil.isNotNull(channelDO)) { + throw exception(CHANNEL_EXIST_SAME_CHANNEL_ERROR); + } // 新增渠道 PayChannelDO channel = PayChannelConvert.INSTANCE.convert(reqVO); @@ -122,7 +123,7 @@ public class PayChannelServiceImpl implements PayChannelService { */ @Override public Integer getChannelCountByConditions(Long merchantId, Long appid, String code) { - return this.channelMapper.getChannelCountByConditions(merchantId, appid, code); + return this.channelMapper.selectCount(merchantId, appid, code); } /** @@ -135,7 +136,7 @@ public class PayChannelServiceImpl implements PayChannelService { */ @Override public PayChannelDO getChannelByConditions(Long merchantId, Long appid, String code) { - return this.channelMapper.getChannelByConditions(merchantId, appid, code); + return this.channelMapper.selectOne(merchantId, appid, code); } /** @@ -146,11 +147,14 @@ public class PayChannelServiceImpl implements PayChannelService { */ private void settingConfigAndCheckParam(PayChannelDO channel, String configStr) { // 得到这个渠道是微信的还是支付宝的 - Class payClass = PayChannelEnum.findByCodeGetClass(channel.getCode()); - Assert.notNull(payClass, CHANNEL_NOT_EXISTS.getMsg()); + Class payClass = PayChannelEnum.getByCode(channel.getCode()).getConfigClass(); + if (ObjectUtil.isNull(payClass)) { + throw exception(CHANNEL_NOT_EXISTS); + } PayClientConfig config = JSONUtil.toBean(configStr, payClass); + // 验证参数 - config.verifyParam(validator); + config.validate(validator); channel.setConfig(config); } diff --git a/yudao-admin-server/src/main/java/cn/iocoder/yudao/adminserver/modules/pay/service/merchant/PayMerchantService.java b/yudao-admin-server/src/main/java/cn/iocoder/yudao/adminserver/modules/pay/service/merchant/PayMerchantService.java index 9b082ffa1..b8e74dd75 100644 --- a/yudao-admin-server/src/main/java/cn/iocoder/yudao/adminserver/modules/pay/service/merchant/PayMerchantService.java +++ b/yudao-admin-server/src/main/java/cn/iocoder/yudao/adminserver/modules/pay/service/merchant/PayMerchantService.java @@ -16,7 +16,7 @@ import java.util.Map; /** * 支付商户信息 Service 接口 * - * @author 芋艿 TODO @aquan:作者是你哈 + * @author aquan */ public interface PayMerchantService { diff --git a/yudao-admin-server/src/main/java/cn/iocoder/yudao/adminserver/modules/pay/service/merchant/impl/PayMerchantServiceImpl.java b/yudao-admin-server/src/main/java/cn/iocoder/yudao/adminserver/modules/pay/service/merchant/impl/PayMerchantServiceImpl.java index 9f2085854..b80132a1f 100644 --- a/yudao-admin-server/src/main/java/cn/iocoder/yudao/adminserver/modules/pay/service/merchant/impl/PayMerchantServiceImpl.java +++ b/yudao-admin-server/src/main/java/cn/iocoder/yudao/adminserver/modules/pay/service/merchant/impl/PayMerchantServiceImpl.java @@ -1,11 +1,13 @@ package cn.iocoder.yudao.adminserver.modules.pay.service.merchant.impl; import cn.hutool.core.date.DateUtil; +import cn.hutool.core.util.ObjectUtil; import cn.iocoder.yudao.adminserver.modules.pay.controller.merchant.vo.PayMerchantCreateReqVO; import cn.iocoder.yudao.adminserver.modules.pay.controller.merchant.vo.PayMerchantExportReqVO; import cn.iocoder.yudao.adminserver.modules.pay.controller.merchant.vo.PayMerchantPageReqVO; import cn.iocoder.yudao.adminserver.modules.pay.controller.merchant.vo.PayMerchantUpdateReqVO; import cn.iocoder.yudao.adminserver.modules.pay.convert.merchant.PayMerchantConvert; +import cn.iocoder.yudao.adminserver.modules.pay.dal.mysql.app.PayAppMapper; import cn.iocoder.yudao.adminserver.modules.pay.dal.mysql.merchant.PayMerchantMapper; import cn.iocoder.yudao.adminserver.modules.pay.service.merchant.PayMerchantService; import cn.iocoder.yudao.coreservice.modules.pay.dal.dataobject.merchant.PayMerchantDO; @@ -19,6 +21,7 @@ import java.time.LocalDateTime; import java.util.Collection; import java.util.List; +import static cn.iocoder.yudao.coreservice.modules.pay.enums.PayErrorCodeCoreConstants.PAY_MERCHANT_EXIST_APP_CANT_DELETE; import static cn.iocoder.yudao.coreservice.modules.pay.enums.PayErrorCodeCoreConstants.PAY_MERCHANT_NOT_EXISTS; import static cn.iocoder.yudao.framework.common.exception.util.ServiceExceptionUtil.exception; @@ -34,6 +37,9 @@ public class PayMerchantServiceImpl implements PayMerchantService { @Resource private PayMerchantMapper merchantMapper; + @Resource + private PayAppMapper appMapper; + @Override public Long createMerchant(PayMerchantCreateReqVO createReqVO) { // 插入 @@ -55,19 +61,13 @@ public class PayMerchantServiceImpl implements PayMerchantService { @Override public void deleteMerchant(Long id) { - // 校验存在 + // 校验 this.validateMerchantExists(id); - // TODO @aquan:需要校验 PayApp 是否都在。如果在的情况下,不允许删除 + this.validateAppExists(id); // 删除 merchantMapper.deleteById(id); } - private void validateMerchantExists(Long id) { - if (merchantMapper.selectById(id) == null) { - throw exception(PAY_MERCHANT_NOT_EXISTS); - } - } - @Override public PayMerchantDO getMerchant(Long id) { return merchantMapper.selectById(id); @@ -88,13 +88,6 @@ public class PayMerchantServiceImpl implements PayMerchantService { return merchantMapper.selectList(exportReqVO); } - // TODO @aquan:接口上已经有注释,这里不用在有啦 - /** - * 修改商户状态 - * - * @param id 商户编号 - * @param status 状态 - */ @Override public void updateMerchantStatus(Long id, Integer status) { // 校验商户存在 @@ -106,21 +99,11 @@ public class PayMerchantServiceImpl implements PayMerchantService { merchantMapper.updateById(merchant); } - /** - * 根据商户名称模糊查询商户集合 - * - * @param merchantName 商户名称 - * @return 商户集合 - */ @Override public List getMerchantListByName(String merchantName) { return this.merchantMapper.getMerchantListByName(merchantName); } - /** - * 检查商户是否存在 - * @param id 商户编号 - */ @VisibleForTesting public void checkMerchantExists(Long id) { if (id == null) { @@ -132,6 +115,27 @@ public class PayMerchantServiceImpl implements PayMerchantService { } } + /** + * 校验商户是否存在 + * + * @param id 商户 ID + */ + private void validateMerchantExists(Long id) { + if (ObjectUtil.isNull(merchantMapper.selectById(id))) { + throw exception(PAY_MERCHANT_NOT_EXISTS); + } + } + + /** + * 校验商户是否还存在支付应用 + * + * @param id 商户ID + */ + private void validateAppExists(Long id) { + if (appMapper.selectCount(id) > 0) { + throw exception(PAY_MERCHANT_EXIST_APP_CANT_DELETE); + } + } // TODO @芋艿:后续增加下合适的算法 /** @@ -139,8 +143,8 @@ public class PayMerchantServiceImpl implements PayMerchantService { * * @return 商户号 */ - private String generateMerchantNo(){ - return "M" + DateUtil.format(LocalDateTime.now(),"yyyyMMddHHmmssSSS"); + private String generateMerchantNo() { + return "M" + DateUtil.format(LocalDateTime.now(), "yyyyMMddHHmmssSSS"); } } diff --git a/yudao-admin-server/src/main/resources/application.yaml b/yudao-admin-server/src/main/resources/application.yaml index 7d54df9ca..8770c06bd 100644 --- a/yudao-admin-server/src/main/resources/application.yaml +++ b/yudao-admin-server/src/main/resources/application.yaml @@ -75,6 +75,4 @@ yudao: - cn.iocoder.yudao.adminserver.modules.system.enums.SysErrorCodeConstants tenant: # 多租户相关配置项 tables: # 配置需要开启多租户的表;如果实体已经继承 TenantBaseDO 类,则无需重复配置 - pay: - payReturnUrl: http://127.0.0.1 # TODO @aquan:这个变量,配置到 dev 或者 local 里,不同环境有差别哈 debug: false diff --git a/yudao-admin-server/src/test/java/cn/iocoder/yudao/adminserver/modules/pay/service/refund/PayRefundServiceTest.java b/yudao-admin-server/src/test/java/cn/iocoder/yudao/adminserver/modules/pay/service/refund/PayRefundServiceTest.java index d60c6fc59..2741144e2 100755 --- a/yudao-admin-server/src/test/java/cn/iocoder/yudao/adminserver/modules/pay/service/refund/PayRefundServiceTest.java +++ b/yudao-admin-server/src/test/java/cn/iocoder/yudao/adminserver/modules/pay/service/refund/PayRefundServiceTest.java @@ -72,8 +72,6 @@ public class PayRefundServiceTest extends BaseDbUnitTest { o.setUpdateTime(DateUtils.buildTime(2021, 1, 1, 10, 10, 35)); }); refundMapper.insert(dbRefund); - // 测试 reqNo 不匹配 - refundMapper.insert(cloneIgnoreId(dbRefund, o -> o.setReqNo("RF1111112"))); // 测试 merchantId 不匹配 refundMapper.insert(cloneIgnoreId(dbRefund, o -> o.setMerchantId(2L))); // 测试 appId 不匹配 @@ -94,7 +92,6 @@ public class PayRefundServiceTest extends BaseDbUnitTest { o.setCreateTime(DateUtils.buildTime(2022, 1, 1, 10, 10, 10)))); // 准备参数 PayRefundPageReqVO reqVO = new PayRefundPageReqVO(); - reqVO.setReqNo("RF0000001"); reqVO.setMerchantId(1L); reqVO.setAppId(1L); reqVO.setChannelCode(PayChannelEnum.WX_PUB.getCode()); @@ -147,8 +144,6 @@ public class PayRefundServiceTest extends BaseDbUnitTest { o.setUpdateTime(DateUtils.buildTime(2021, 1, 1, 10, 10, 35)); }); refundMapper.insert(dbRefund); - // 测试 reqNo 不匹配 - refundMapper.insert(cloneIgnoreId(dbRefund, o -> o.setReqNo("RF1111112"))); // 测试 merchantId 不匹配 refundMapper.insert(cloneIgnoreId(dbRefund, o -> o.setMerchantId(2L))); // 测试 appId 不匹配 @@ -170,7 +165,6 @@ public class PayRefundServiceTest extends BaseDbUnitTest { // 准备参数 PayRefundExportReqVO reqVO = new PayRefundExportReqVO(); - reqVO.setReqNo("RF0000001"); reqVO.setMerchantId(1L); reqVO.setAppId(1L); reqVO.setChannelCode(PayChannelEnum.WX_PUB.getCode()); diff --git a/yudao-admin-ui/src/api/pay/merchant.js b/yudao-admin-ui/src/api/pay/merchant.js index 1c6d7e20a..51b604ee2 100644 --- a/yudao-admin-ui/src/api/pay/merchant.js +++ b/yudao-admin-ui/src/api/pay/merchant.js @@ -49,7 +49,7 @@ export function getMerchant(id) { // 根据商户名称搜索商户列表 export function getMerchantListByName(name) { return request({ - url: '/pay/merchant/list-name', + url: '/pay/merchant/list-by-name', params:{ name:name }, diff --git a/yudao-admin-ui/src/utils/dict.js b/yudao-admin-ui/src/utils/dict.js index dae5d4916..2589fbb39 100644 --- a/yudao-admin-ui/src/utils/dict.js +++ b/yudao-admin-ui/src/utils/dict.js @@ -34,12 +34,6 @@ export const DICT_TYPE = { OA_LEAVE_STATUS: 'oa_leave_status', OA_LEAVE_TYPE: 'oa_leave_type', - // 商户状态 - PAY_MERCHANT_STATUS: 'pay_merchant_status', // TODO @aquan:一般使用 COMMON_RESULT 即可。保持数值一致,以后加更多状态的时候,在单独数据字典 - // 应用状态 - PAY_APP_STATUS: 'pay_app_status', - // 渠道状态 - PAY_CHANNEL_STATUS: 'pay_channel_status', // 微信渠道版本 PAY_CHANNEL_WECHAT_VERSION:'pay_channel_wechat_version', // 支付渠道支付宝算法类型 diff --git a/yudao-admin-ui/src/views/pay/app/components/aliPayChannelForm.vue b/yudao-admin-ui/src/views/pay/app/components/aliPayChannelForm.vue index 29587aba3..58d40e768 100644 --- a/yudao-admin-ui/src/views/pay/app/components/aliPayChannelForm.vue +++ b/yudao-admin-ui/src/views/pay/app/components/aliPayChannelForm.vue @@ -1,6 +1,6 @@