code review 支付的逻辑

This commit is contained in:
YunaiV 2021-11-21 21:11:07 +08:00
parent 6069a387ea
commit f0fcf4798e
7 changed files with 24 additions and 19 deletions

View File

@ -1,14 +1,15 @@
package cn.iocoder.yudao.adminserver.modules.pay.dal.mysql.merchant; package cn.iocoder.yudao.adminserver.modules.pay.dal.mysql.merchant;
import java.util.*; 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.coreservice.modules.pay.dal.dataobject.merchant.PayMerchantDO; import cn.iocoder.yudao.coreservice.modules.pay.dal.dataobject.merchant.PayMerchantDO;
import cn.iocoder.yudao.framework.common.pojo.PageResult; import cn.iocoder.yudao.framework.common.pojo.PageResult;
import cn.iocoder.yudao.framework.mybatis.core.query.QueryWrapperX;
import cn.iocoder.yudao.framework.mybatis.core.mapper.BaseMapperX; 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.QueryWrapper; import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import org.apache.ibatis.annotations.Mapper; import org.apache.ibatis.annotations.Mapper;
import cn.iocoder.yudao.adminserver.modules.pay.controller.merchant.vo.*;
import java.util.List;
/** /**
* 支付商户信息 Mapper * 支付商户信息 Mapper
@ -47,6 +48,7 @@ public interface PayMerchantMapper extends BaseMapperX<PayMerchantDO> {
* @return 商户集合 * @return 商户集合
*/ */
default List<PayMerchantDO> getMerchantListByName(String merchantName) { default List<PayMerchantDO> getMerchantListByName(String merchantName) {
// TODO @aquan全模糊匹配暂时不考虑索引的事另外可以直接 new Lambada QueryWrapper 实现类呀
return this.selectList(new QueryWrapper<PayMerchantDO>() return this.selectList(new QueryWrapper<PayMerchantDO>()
.lambda().likeRight(PayMerchantDO::getName, merchantName)); .lambda().likeRight(PayMerchantDO::getName, merchantName));
} }

View File

@ -1,31 +1,28 @@
package cn.iocoder.yudao.adminserver.modules.pay.service.channel.impl; package cn.iocoder.yudao.adminserver.modules.pay.service.channel.impl;
import cn.hutool.core.io.IoUtil; import cn.iocoder.yudao.adminserver.modules.pay.controller.channel.vo.PayChannelCreateReqVO;
import cn.hutool.core.util.StrUtil; import cn.iocoder.yudao.adminserver.modules.pay.controller.channel.vo.PayChannelExportReqVO;
import cn.iocoder.yudao.adminserver.modules.pay.controller.channel.vo.*; import cn.iocoder.yudao.adminserver.modules.pay.controller.channel.vo.PayChannelPageReqVO;
import cn.iocoder.yudao.adminserver.modules.pay.controller.channel.vo.PayChannelUpdateReqVO;
import cn.iocoder.yudao.adminserver.modules.pay.convert.channel.PayChannelConvert; import cn.iocoder.yudao.adminserver.modules.pay.convert.channel.PayChannelConvert;
import cn.iocoder.yudao.adminserver.modules.pay.dal.mysql.channel.PayChannelMapper; import cn.iocoder.yudao.adminserver.modules.pay.dal.mysql.channel.PayChannelMapper;
import cn.iocoder.yudao.adminserver.modules.pay.service.channel.PayChannelService; import cn.iocoder.yudao.adminserver.modules.pay.service.channel.PayChannelService;
import cn.iocoder.yudao.coreservice.modules.pay.dal.dataobject.merchant.PayChannelDO; import cn.iocoder.yudao.coreservice.modules.pay.dal.dataobject.merchant.PayChannelDO;
import cn.iocoder.yudao.framework.common.pojo.PageResult; import cn.iocoder.yudao.framework.common.pojo.PageResult;
import cn.iocoder.yudao.framework.common.util.json.JsonUtils;
import cn.iocoder.yudao.framework.pay.core.client.impl.alipay.AlipayPayClientConfig; import cn.iocoder.yudao.framework.pay.core.client.impl.alipay.AlipayPayClientConfig;
import cn.iocoder.yudao.framework.pay.core.client.impl.wx.WXPayClientConfig; import cn.iocoder.yudao.framework.pay.core.client.impl.wx.WXPayClientConfig;
import cn.iocoder.yudao.framework.pay.core.enums.PayChannelEnum; import cn.iocoder.yudao.framework.pay.core.enums.PayChannelEnum;
import com.alibaba.fastjson.JSON; import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
import lombok.extern.slf4j.Slf4j; import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service; import org.springframework.stereotype.Service;
import org.springframework.util.Assert; import org.springframework.util.Assert;
import org.springframework.validation.annotation.Validated; import org.springframework.validation.annotation.Validated;
import org.springframework.web.multipart.MultipartFile;
import javax.annotation.Resource; import javax.annotation.Resource;
import javax.validation.ConstraintViolation; import javax.validation.ConstraintViolation;
import javax.validation.Validation; import javax.validation.Validation;
import javax.validation.Validator; import javax.validation.Validator;
import javax.validation.ValidatorFactory; import javax.validation.ValidatorFactory;
import java.io.IOException;
import java.util.Collection; import java.util.Collection;
import java.util.List; import java.util.List;
import java.util.Set; import java.util.Set;
@ -49,16 +46,16 @@ public class PayChannelServiceImpl implements PayChannelService {
@Override @Override
public Long createChannel(PayChannelCreateReqVO reqVO) { public Long createChannel(PayChannelCreateReqVO reqVO) {
// TODO @aquan感觉获得那一条比较合适因为是有唯一性的注释有错别字哈
// 判断是否有重复的有责无法新增 // 判断是否有重复的有责无法新增
Integer channelCount = this.getChannelCountByConditions(reqVO.getMerchantId(), reqVO.getAppId(), reqVO.getCode()); Integer channelCount = this.getChannelCountByConditions(reqVO.getMerchantId(), reqVO.getAppId(), reqVO.getCode());
if (channelCount > 0) { if (channelCount > 0) {
throw exception(CHANNEL_EXIST_SAME_CHANNEL_ERROR); throw exception(CHANNEL_EXIST_SAME_CHANNEL_ERROR);
} }
// 新增渠道
PayChannelDO channel = PayChannelConvert.INSTANCE.convert(reqVO); PayChannelDO channel = PayChannelConvert.INSTANCE.convert(reqVO);
settingConfigAndCheckParam(channel, reqVO.getConfig()); settingConfigAndCheckParam(channel, reqVO.getConfig());
channelMapper.insert(channel); channelMapper.insert(channel);
return channel.getId(); return channel.getId();
} }
@ -170,16 +167,17 @@ public class PayChannelServiceImpl implements PayChannelService {
* @param configStr 配置 * @param configStr 配置
*/ */
private void settingConfigAndCheckParam(PayChannelDO channel, String configStr) { private void settingConfigAndCheckParam(PayChannelDO channel, String configStr) {
// 得到这个渠道是微信的还是支付宝的 // 得到这个渠道是微信的还是支付宝的
String channelType = PayChannelEnum.verifyWechatOrAliPay(channel.getCode()); String channelType = PayChannelEnum.verifyWechatOrAliPay(channel.getCode());
Assert.notNull(channelType, CHANNEL_NOT_EXISTS.getMsg()); Assert.notNull(channelType, CHANNEL_NOT_EXISTS.getMsg());
// 进行验证 // 进行验证
// TODO @阿全Spring 可以注入 Validator
ValidatorFactory validatorFactory = Validation.buildDefaultValidatorFactory(); ValidatorFactory validatorFactory = Validation.buildDefaultValidatorFactory();
Validator validator = validatorFactory.getValidator(); Validator validator = validatorFactory.getValidator();
// 微信的验证 // 微信的验证
// TODO @aquan这么实现可扩性不好@AssertTrue 注解
if (PayChannelEnum.WECHAT.equals(channelType)) { if (PayChannelEnum.WECHAT.equals(channelType)) {
WXPayClientConfig config = JSON.parseObject(configStr, WXPayClientConfig.class); WXPayClientConfig config = JSON.parseObject(configStr, WXPayClientConfig.class);

View File

@ -124,7 +124,7 @@ public class PayMerchantServiceImpl implements PayMerchantService {
*/ */
@Override @Override
public List<PayMerchantDO> getMerchantListByNameLimit(String merchantName) { public List<PayMerchantDO> getMerchantListByNameLimit(String merchantName) {
// TODO @aquanmybatis plus
LambdaQueryWrapper<PayMerchantDO> queryWrapper = new QueryWrapper<PayMerchantDO>().lambda() LambdaQueryWrapper<PayMerchantDO> queryWrapper = new QueryWrapper<PayMerchantDO>().lambda()
.select(PayMerchantDO::getId, PayMerchantDO::getName) .select(PayMerchantDO::getId, PayMerchantDO::getName)
.likeRight(PayMerchantDO::getName, merchantName) .likeRight(PayMerchantDO::getName, merchantName)

View File

@ -19,7 +19,6 @@ import org.junit.jupiter.api.Test;
import org.springframework.context.annotation.Import; import org.springframework.context.annotation.Import;
import javax.annotation.Resource; import javax.annotation.Resource;
import javax.validation.Validator;
import java.util.List; import java.util.List;
import static cn.iocoder.yudao.coreservice.modules.pay.enums.PayErrorCodeCoreConstants.CHANNEL_NOT_EXISTS; import static cn.iocoder.yudao.coreservice.modules.pay.enums.PayErrorCodeCoreConstants.CHANNEL_NOT_EXISTS;
@ -70,7 +69,7 @@ public class PayChannelServiceTest extends BaseDbUnitTest {
@Test @Test
public void testCreateWechatVersion3Channel_success() { public void testCreateWechatVersion3Channel_success() {
// 准备参数 // 准备参数 TODO @aquan多余的空行去掉哈例如说 74
WXPayClientConfig v3Config = getV3Config(); WXPayClientConfig v3Config = getV3Config();
PayChannelCreateReqVO reqVO = randomPojo(PayChannelCreateReqVO.class, o -> { PayChannelCreateReqVO reqVO = randomPojo(PayChannelCreateReqVO.class, o -> {

View File

@ -479,7 +479,7 @@ CREATE TABLE IF NOT EXISTS "pay_app" (
"update_time" datetime NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP, "update_time" datetime NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
"deleted" bit(1) NOT NULL DEFAULT FALSE, "deleted" bit(1) NOT NULL DEFAULT FALSE,
PRIMARY KEY ("id") PRIMARY KEY ("id")
) COMMENT = '支付应用信息'; ) COMMENT = '支付应用信息';
CREATE TABLE "pay_channel" ( CREATE TABLE "pay_channel" (
"id" number NOT NULL GENERATED BY DEFAULT AS IDENTITY, "id" number NOT NULL GENERATED BY DEFAULT AS IDENTITY,
@ -496,5 +496,5 @@ CREATE TABLE "pay_channel" (
"update_time" datetime NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP, "update_time" datetime NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
"deleted" bit(1) NOT NULL DEFAULT FALSE, "deleted" bit(1) NOT NULL DEFAULT FALSE,
PRIMARY KEY ("id") PRIMARY KEY ("id")
)COMMENT = '支付渠道'; ) COMMENT = '支付渠道';

View File

@ -27,6 +27,7 @@ public interface PayErrorCodeCoreConstants {
ErrorCode CHANNEL_WECHAT_VERSION_2_MCH_KEY_IS_NULL = new ErrorCode(1007001006,"微信渠道v2版本中商户密钥不可为空"); ErrorCode CHANNEL_WECHAT_VERSION_2_MCH_KEY_IS_NULL = new ErrorCode(1007001006,"微信渠道v2版本中商户密钥不可为空");
ErrorCode CHANNEL_WECHAT_VERSION_3_PRIVATE_KEY_IS_NULL = new ErrorCode(1007001006,"微信渠道v3版本apiclient_key.pem不可为空"); ErrorCode CHANNEL_WECHAT_VERSION_3_PRIVATE_KEY_IS_NULL = new ErrorCode(1007001006,"微信渠道v3版本apiclient_key.pem不可为空");
ErrorCode CHANNEL_WECHAT_VERSION_3_CERT_KEY_IS_NULL = new ErrorCode(1007001006,"微信渠道v3版本中apiclient_cert.pem不可为空"); ErrorCode CHANNEL_WECHAT_VERSION_3_CERT_KEY_IS_NULL = new ErrorCode(1007001006,"微信渠道v3版本中apiclient_cert.pem不可为空");
/** /**
* ========== ORDER 模块 1-007-002-000 ========== * ========== ORDER 模块 1-007-002-000 ==========
*/ */
@ -48,6 +49,8 @@ public interface PayErrorCodeCoreConstants {
ErrorCode PAY_REFUND_CHN_ORDER_NO_IS_NULL = new ErrorCode(1007006002, "该订单的渠道订单为空"); ErrorCode PAY_REFUND_CHN_ORDER_NO_IS_NULL = new ErrorCode(1007006002, "该订单的渠道订单为空");
ErrorCode PAY_REFUND_POST_HANDLER_NOT_FOUND = new ErrorCode(1007006002, "未找到对应的退款后置处理类"); ErrorCode PAY_REFUND_POST_HANDLER_NOT_FOUND = new ErrorCode(1007006002, "未找到对应的退款后置处理类");
// TODO @aquan下面还两个要合并上去哈另外一般中英文之间要有空格例如说 新建一个 order 数据这样可读性更好
/** /**
* ========== 支付商户信息 1-007-004-000 ========== * ========== 支付商户信息 1-007-004-000 ==========
*/ */

View File

@ -10,6 +10,8 @@ import java.io.FileNotFoundException;
// TODO 芋艿参数校验 // TODO 芋艿参数校验
// TODO @aquan: 不要全文件格式化哈去掉下 <p> 看着不太友好哈
/** /**
* 微信支付的 PayClientConfig 实现类 * 微信支付的 PayClientConfig 实现类
* 属性主要来自 {@link com.github.binarywang.wxpay.config.WxPayConfig} 的必要属性 * 属性主要来自 {@link com.github.binarywang.wxpay.config.WxPayConfig} 的必要属性
@ -71,6 +73,7 @@ public class WXPayClientConfig implements PayClientConfig {
* <p> * <p>
* 注意可通过 {@link #main(String[])} 读取 * 注意可通过 {@link #main(String[])} 读取
*/ */
// TODO @aquan对于只有一个值的时候直接 groups = V3.class 即可简洁例如说我们在 Spring MVC 注解url 可以多个也只写单个一个道理哈
@NotBlank(message = "apiclient_key 不能为空", groups = {V3.class}) @NotBlank(message = "apiclient_key 不能为空", groups = {V3.class})
private String privateKeyContent; private String privateKeyContent;
/** /**