Commit f0fcf4798ebef2bc1d03f291e583a8379084dd6e

Authored by YunaiV
1 parent 6069a387

code review 支付的逻辑

yudao-admin-server/src/main/java/cn/iocoder/yudao/adminserver/modules/pay/dal/mysql/merchant/PayMerchantMapper.java
1 1 package cn.iocoder.yudao.adminserver.modules.pay.dal.mysql.merchant;
2 2  
3   -import java.util.*;
4   -
  3 +import cn.iocoder.yudao.adminserver.modules.pay.controller.merchant.vo.PayMerchantExportReqVO;
  4 +import cn.iocoder.yudao.adminserver.modules.pay.controller.merchant.vo.PayMerchantPageReqVO;
5 5 import cn.iocoder.yudao.coreservice.modules.pay.dal.dataobject.merchant.PayMerchantDO;
6 6 import cn.iocoder.yudao.framework.common.pojo.PageResult;
7   -import cn.iocoder.yudao.framework.mybatis.core.query.QueryWrapperX;
8 7 import cn.iocoder.yudao.framework.mybatis.core.mapper.BaseMapperX;
  8 +import cn.iocoder.yudao.framework.mybatis.core.query.QueryWrapperX;
9 9 import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
10 10 import org.apache.ibatis.annotations.Mapper;
11   -import cn.iocoder.yudao.adminserver.modules.pay.controller.merchant.vo.*;
  11 +
  12 +import java.util.List;
12 13  
13 14 /**
14 15 * 支付商户信息 Mapper
... ... @@ -47,6 +48,7 @@ public interface PayMerchantMapper extends BaseMapperX<PayMerchantDO> {
47 48 * @return 商户集合
48 49 */
49 50 default List<PayMerchantDO> getMerchantListByName(String merchantName) {
  51 + // TODO @aquan:全模糊匹配,暂时不考虑索引的事;另外,可以直接 new Lambada 的 QueryWrapper 实现类呀
50 52 return this.selectList(new QueryWrapper<PayMerchantDO>()
51 53 .lambda().likeRight(PayMerchantDO::getName, merchantName));
52 54 }
... ...
yudao-admin-server/src/main/java/cn/iocoder/yudao/adminserver/modules/pay/service/channel/impl/PayChannelServiceImpl.java
1 1 package cn.iocoder.yudao.adminserver.modules.pay.service.channel.impl;
2 2  
3   -import cn.hutool.core.io.IoUtil;
4   -import cn.hutool.core.util.StrUtil;
5   -import cn.iocoder.yudao.adminserver.modules.pay.controller.channel.vo.*;
  3 +import cn.iocoder.yudao.adminserver.modules.pay.controller.channel.vo.PayChannelCreateReqVO;
  4 +import cn.iocoder.yudao.adminserver.modules.pay.controller.channel.vo.PayChannelExportReqVO;
  5 +import cn.iocoder.yudao.adminserver.modules.pay.controller.channel.vo.PayChannelPageReqVO;
  6 +import cn.iocoder.yudao.adminserver.modules.pay.controller.channel.vo.PayChannelUpdateReqVO;
6 7 import cn.iocoder.yudao.adminserver.modules.pay.convert.channel.PayChannelConvert;
7 8 import cn.iocoder.yudao.adminserver.modules.pay.dal.mysql.channel.PayChannelMapper;
8 9 import cn.iocoder.yudao.adminserver.modules.pay.service.channel.PayChannelService;
9 10 import cn.iocoder.yudao.coreservice.modules.pay.dal.dataobject.merchant.PayChannelDO;
10 11 import cn.iocoder.yudao.framework.common.pojo.PageResult;
11   -import cn.iocoder.yudao.framework.common.util.json.JsonUtils;
12 12 import cn.iocoder.yudao.framework.pay.core.client.impl.alipay.AlipayPayClientConfig;
13 13 import cn.iocoder.yudao.framework.pay.core.client.impl.wx.WXPayClientConfig;
14 14 import cn.iocoder.yudao.framework.pay.core.enums.PayChannelEnum;
15 15 import com.alibaba.fastjson.JSON;
16   -import com.alibaba.fastjson.JSONObject;
17 16 import lombok.extern.slf4j.Slf4j;
18 17 import org.springframework.stereotype.Service;
19 18 import org.springframework.util.Assert;
20 19 import org.springframework.validation.annotation.Validated;
21   -import org.springframework.web.multipart.MultipartFile;
22 20  
23 21 import javax.annotation.Resource;
24 22 import javax.validation.ConstraintViolation;
25 23 import javax.validation.Validation;
26 24 import javax.validation.Validator;
27 25 import javax.validation.ValidatorFactory;
28   -import java.io.IOException;
29 26 import java.util.Collection;
30 27 import java.util.List;
31 28 import java.util.Set;
... ... @@ -49,16 +46,16 @@ public class PayChannelServiceImpl implements PayChannelService {
49 46  
50 47 @Override
51 48 public Long createChannel(PayChannelCreateReqVO reqVO) {
52   -
  49 + // TODO @aquan:感觉获得那一条比较合适。因为是有唯一性的。注释有错别字哈。
53 50 // 判断是否有重复的有责无法新增
54 51 Integer channelCount = this.getChannelCountByConditions(reqVO.getMerchantId(), reqVO.getAppId(), reqVO.getCode());
55 52 if (channelCount > 0) {
56 53 throw exception(CHANNEL_EXIST_SAME_CHANNEL_ERROR);
57 54 }
58 55  
  56 + // 新增渠道
59 57 PayChannelDO channel = PayChannelConvert.INSTANCE.convert(reqVO);
60 58 settingConfigAndCheckParam(channel, reqVO.getConfig());
61   -
62 59 channelMapper.insert(channel);
63 60 return channel.getId();
64 61 }
... ... @@ -170,16 +167,17 @@ public class PayChannelServiceImpl implements PayChannelService {
170 167 * @param configStr 配置
171 168 */
172 169 private void settingConfigAndCheckParam(PayChannelDO channel, String configStr) {
173   -
174 170 // 得到这个渠道是微信的还是支付宝的
175 171 String channelType = PayChannelEnum.verifyWechatOrAliPay(channel.getCode());
176 172 Assert.notNull(channelType, CHANNEL_NOT_EXISTS.getMsg());
177 173  
178 174 // 进行验证
  175 + // TODO @阿全:Spring 可以注入 Validator 哈
179 176 ValidatorFactory validatorFactory = Validation.buildDefaultValidatorFactory();
180 177 Validator validator = validatorFactory.getValidator();
181 178  
182 179 // 微信的验证
  180 + // TODO @aquan:这么实现,可扩性不好。@AssertTrue 注解。
183 181 if (PayChannelEnum.WECHAT.equals(channelType)) {
184 182  
185 183 WXPayClientConfig config = JSON.parseObject(configStr, WXPayClientConfig.class);
... ...
yudao-admin-server/src/main/java/cn/iocoder/yudao/adminserver/modules/pay/service/merchant/impl/PayMerchantServiceImpl.java
... ... @@ -124,7 +124,7 @@ public class PayMerchantServiceImpl implements PayMerchantService {
124 124 */
125 125 @Override
126 126 public List<PayMerchantDO> getMerchantListByNameLimit(String merchantName) {
127   -
  127 + // TODO @aquan:mybatis plus 哈
128 128 LambdaQueryWrapper<PayMerchantDO> queryWrapper = new QueryWrapper<PayMerchantDO>().lambda()
129 129 .select(PayMerchantDO::getId, PayMerchantDO::getName)
130 130 .likeRight(PayMerchantDO::getName, merchantName)
... ...
yudao-admin-server/src/test/java/cn/iocoder/yudao/adminserver/modules/pay/service/channel/PayChannelServiceTest.java
... ... @@ -19,7 +19,6 @@ import org.junit.jupiter.api.Test;
19 19 import org.springframework.context.annotation.Import;
20 20  
21 21 import javax.annotation.Resource;
22   -import javax.validation.Validator;
23 22 import java.util.List;
24 23  
25 24 import static cn.iocoder.yudao.coreservice.modules.pay.enums.PayErrorCodeCoreConstants.CHANNEL_NOT_EXISTS;
... ... @@ -70,7 +69,7 @@ public class PayChannelServiceTest extends BaseDbUnitTest {
70 69  
71 70 @Test
72 71 public void testCreateWechatVersion3Channel_success() {
73   - // 准备参数
  72 + // 准备参数 TODO @aquan:多余的空行去掉哈。例如说 74 行。
74 73  
75 74 WXPayClientConfig v3Config = getV3Config();
76 75 PayChannelCreateReqVO reqVO = randomPojo(PayChannelCreateReqVO.class, o -> {
... ...
yudao-admin-server/src/test/resources/sql/create_tables.sql
... ... @@ -479,7 +479,7 @@ CREATE TABLE IF NOT EXISTS &quot;pay_app&quot; (
479 479 "update_time" datetime NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
480 480 "deleted" bit(1) NOT NULL DEFAULT FALSE,
481 481 PRIMARY KEY ("id")
482   -) COMMENT = '支付应用信息';
  482 +) COMMENT = '支付应用信息';
483 483  
484 484 CREATE TABLE "pay_channel" (
485 485 "id" number NOT NULL GENERATED BY DEFAULT AS IDENTITY,
... ... @@ -496,5 +496,5 @@ CREATE TABLE &quot;pay_channel&quot; (
496 496 "update_time" datetime NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
497 497 "deleted" bit(1) NOT NULL DEFAULT FALSE,
498 498 PRIMARY KEY ("id")
499   -)COMMENT = '支付渠道';
  499 +) COMMENT = '支付渠道';
500 500  
... ...
yudao-core-service/src/main/java/cn/iocoder/yudao/coreservice/modules/pay/enums/PayErrorCodeCoreConstants.java
... ... @@ -27,6 +27,7 @@ public interface PayErrorCodeCoreConstants {
27 27 ErrorCode CHANNEL_WECHAT_VERSION_2_MCH_KEY_IS_NULL = new ErrorCode(1007001006,"微信渠道v2版本中商户密钥不可为空");
28 28 ErrorCode CHANNEL_WECHAT_VERSION_3_PRIVATE_KEY_IS_NULL = new ErrorCode(1007001006,"微信渠道v3版本apiclient_key.pem不可为空");
29 29 ErrorCode CHANNEL_WECHAT_VERSION_3_CERT_KEY_IS_NULL = new ErrorCode(1007001006,"微信渠道v3版本中apiclient_cert.pem不可为空");
  30 +
30 31 /**
31 32 * ========== ORDER 模块 1-007-002-000 ==========
32 33 */
... ... @@ -48,6 +49,8 @@ public interface PayErrorCodeCoreConstants {
48 49 ErrorCode PAY_REFUND_CHN_ORDER_NO_IS_NULL = new ErrorCode(1007006002, "该订单的渠道订单为空");
49 50 ErrorCode PAY_REFUND_POST_HANDLER_NOT_FOUND = new ErrorCode(1007006002, "未找到对应的退款后置处理类");
50 51  
  52 + // TODO @aquan:下面还两个要合并上去哈。另外一般中英文之间要有空格。例如说, 新建一个 order 数据;这样可读性更好。
  53 +
51 54 /**
52 55 * ========== 支付商户信息 1-007-004-000 ==========
53 56 */
... ...
yudao-framework/yudao-spring-boot-starter-biz-pay/src/main/java/cn/iocoder/yudao/framework/pay/core/client/impl/wx/WXPayClientConfig.java
... ... @@ -10,6 +10,8 @@ import java.io.FileNotFoundException;
10 10  
11 11 // TODO 芋艿:参数校验
12 12  
  13 +// TODO @aquan: 不要全文件格式化哈,去掉下 <p> 看着不太友好哈
  14 +
13 15 /**
14 16 * 微信支付的 PayClientConfig 实现类
15 17 * 属性主要来自 {@link com.github.binarywang.wxpay.config.WxPayConfig} 的必要属性
... ... @@ -71,6 +73,7 @@ public class WXPayClientConfig implements PayClientConfig {
71 73 * <p>
72 74 * 注意,可通过 {@link #main(String[])} 读取
73 75 */
  76 + // TODO @aquan:对于只有一个值的时候,直接 groups = V3.class 即可,简洁。例如说,我们在 Spring MVC 注解,url 可以多个,也只写单个,一个道理哈
74 77 @NotBlank(message = "apiclient_key 不能为空", groups = {V3.class})
75 78 private String privateKeyContent;
76 79 /**
... ...