Commit cea1589e799258d5dc2f6b5e9c08f1c8e49136bc

Authored by YunaiV
1 parent f1424aa6

code review 支付渠道的逻辑

yudao-admin-server/src/main/java/cn/iocoder/yudao/adminserver/modules/pay/controller/channel/vo/PayChannelCreateReqVO.java
... ... @@ -14,10 +14,8 @@ import javax.validation.constraints.NotBlank;
14 14 @ToString(callSuper = true)
15 15 public class PayChannelCreateReqVO extends PayChannelBaseVO {
16 16  
17   -
18   - @ApiModelProperty(value = "通道配置的json字符串")
  17 + @ApiModelProperty(value = "通道配置的 json 字符串")
19 18 @NotBlank(message = "通道配置不能为空")
20 19 private String config;
21 20  
22   -
23 21 }
... ...
yudao-admin-server/src/main/java/cn/iocoder/yudao/adminserver/modules/pay/service/channel/impl/PayChannelServiceImpl.java
... ... @@ -11,11 +11,8 @@ import cn.iocoder.yudao.adminserver.modules.pay.service.channel.PayChannelServic
11 11 import cn.iocoder.yudao.coreservice.modules.pay.dal.dataobject.merchant.PayChannelDO;
12 12 import cn.iocoder.yudao.framework.common.pojo.PageResult;
13 13 import cn.iocoder.yudao.framework.pay.core.client.PayClientConfig;
14   -import cn.iocoder.yudao.framework.pay.core.client.impl.wx.WXPayClientConfig;
15 14 import cn.iocoder.yudao.framework.pay.core.enums.PayChannelEnum;
16 15 import lombok.extern.slf4j.Slf4j;
17   -import org.springframework.beans.factory.annotation.Autowired;
18   -import org.springframework.beans.factory.annotation.Qualifier;
19 16 import org.springframework.stereotype.Service;
20 17 import org.springframework.util.Assert;
21 18 import org.springframework.validation.annotation.Validated;
... ... @@ -25,7 +22,8 @@ import javax.validation.Validator;
25 22 import java.util.Collection;
26 23 import java.util.List;
27 24  
28   -import static cn.iocoder.yudao.coreservice.modules.pay.enums.PayErrorCodeCoreConstants.*;
  25 +import static cn.iocoder.yudao.coreservice.modules.pay.enums.PayErrorCodeCoreConstants.CHANNEL_EXIST_SAME_CHANNEL_ERROR;
  26 +import static cn.iocoder.yudao.coreservice.modules.pay.enums.PayErrorCodeCoreConstants.CHANNEL_NOT_EXISTS;
29 27 import static cn.iocoder.yudao.framework.common.exception.util.ServiceExceptionUtil.exception;
30 28  
31 29 /**
... ... @@ -48,6 +46,7 @@ public class PayChannelServiceImpl implements PayChannelService {
48 46 public Long createChannel(PayChannelCreateReqVO reqVO) {
49 47 // 断言是否有重复的
50 48 PayChannelDO channelDO = this.getChannelByConditions(reqVO.getMerchantId(), reqVO.getAppId(), reqVO.getCode());
  49 + // TODO @aquan:这里会抛出系统异常,不会抛出 ServiceException
51 50 Assert.isNull(channelDO, CHANNEL_EXIST_SAME_CHANNEL_ERROR.getMsg());
52 51  
53 52 // 新增渠道
... ... @@ -154,4 +153,5 @@ public class PayChannelServiceImpl implements PayChannelService {
154 153 config.verifyParam(validator);
155 154 channel.setConfig(config);
156 155 }
  156 +
157 157 }
... ...
yudao-framework/yudao-spring-boot-starter-biz-pay/src/main/java/cn/iocoder/yudao/framework/pay/core/client/impl/wx/WXPayClientConfig.java
1 1 package cn.iocoder.yudao.framework.pay.core.client.impl.wx;
2 2  
3 3 import cn.hutool.core.io.IoUtil;
4   -import cn.hutool.json.JSONObject;
5   -import cn.hutool.json.JSONUtil;
6 4 import cn.iocoder.yudao.framework.pay.core.client.PayClientConfig;
7   -import com.alibaba.fastjson.JSON;
8 5 import lombok.Data;
9   -import org.springframework.beans.factory.annotation.Autowired;
10 6 import org.springframework.util.Assert;
11 7  
12   -import javax.annotation.Resource;
13 8 import javax.validation.ConstraintViolation;
14 9 import javax.validation.Validator;
15   -import javax.validation.constraints.AssertTrue;
16 10 import javax.validation.constraints.NotBlank;
17 11 import java.io.FileInputStream;
18 12 import java.io.FileNotFoundException;
... ... @@ -95,7 +89,6 @@ public class WXPayClientConfig implements PayClientConfig {
95 89 @NotBlank(message = "apiV3 秘钥值 不能为空", groups = V3.class)
96 90 private String apiV3Key;
97 91  
98   -
99 92 /**
100 93 * 分组校验 v2版本
101 94 */
... ... @@ -108,6 +101,7 @@ public class WXPayClientConfig implements PayClientConfig {
108 101 public interface V3 {
109 102 }
110 103  
  104 + // TODO @aquan:1)已经有注释,不用重复注释;2)方法名改成 validate,比较适合 validator;3)断言是否有异常,可以封一个 ConstraintViolationException 异常
111 105 /**
112 106 * 验证配置参数是否正确
113 107 * @param validator 校验对象
... ... @@ -129,5 +123,4 @@ public class WXPayClientConfig implements PayClientConfig {
129 123 System.out.println(IoUtil.readUtf8(new FileInputStream(path)));
130 124 }
131 125  
132   -
133 126 }
... ...
yudao-framework/yudao-spring-boot-starter-biz-pay/src/main/java/cn/iocoder/yudao/framework/pay/core/enums/PayChannelEnum.java
... ... @@ -51,12 +51,14 @@ public enum PayChannelEnum {
51 51 return ArrayUtil.firstMatch(o -> o.getCode().equals(code), values());
52 52 }
53 53  
  54 + // TODO @aquan:加一个 configClass 字段,不用 switch 的方式哈。不然新增一个支付方式,需要改的方法有点多
54 55 /**
55 56 * 根据编码得到支付类
  57 + *
56 58 * @param code 编码
57 59 * @return 支付配置类
58 60 */
59   - public static Class<? extends PayClientConfig> findByCodeGetClass(String code){
  61 + public static Class<? extends PayClientConfig> findByCodeGetClass(String code) {
60 62 switch (PayChannelEnum.getByCode(code)){
61 63 case WX_PUB:
62 64 case WX_LITE:
... ...