mirror of
https://gitee.com/huangge1199_admin/vue-pro.git
synced 2024-11-26 17:21:53 +08:00
code review 支付的逻辑
This commit is contained in:
parent
6069a387ea
commit
f0fcf4798e
@ -1,14 +1,15 @@
|
||||
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.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.query.QueryWrapperX;
|
||||
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
||||
import org.apache.ibatis.annotations.Mapper;
|
||||
import cn.iocoder.yudao.adminserver.modules.pay.controller.merchant.vo.*;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* 支付商户信息 Mapper
|
||||
@ -47,6 +48,7 @@ public interface PayMerchantMapper extends BaseMapperX<PayMerchantDO> {
|
||||
* @return 商户集合
|
||||
*/
|
||||
default List<PayMerchantDO> getMerchantListByName(String merchantName) {
|
||||
// TODO @aquan:全模糊匹配,暂时不考虑索引的事;另外,可以直接 new Lambada 的 QueryWrapper 实现类呀
|
||||
return this.selectList(new QueryWrapper<PayMerchantDO>()
|
||||
.lambda().likeRight(PayMerchantDO::getName, merchantName));
|
||||
}
|
||||
|
@ -1,31 +1,28 @@
|
||||
package cn.iocoder.yudao.adminserver.modules.pay.service.channel.impl;
|
||||
|
||||
import cn.hutool.core.io.IoUtil;
|
||||
import cn.hutool.core.util.StrUtil;
|
||||
import cn.iocoder.yudao.adminserver.modules.pay.controller.channel.vo.*;
|
||||
import cn.iocoder.yudao.adminserver.modules.pay.controller.channel.vo.PayChannelCreateReqVO;
|
||||
import cn.iocoder.yudao.adminserver.modules.pay.controller.channel.vo.PayChannelExportReqVO;
|
||||
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.dal.mysql.channel.PayChannelMapper;
|
||||
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.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.wx.WXPayClientConfig;
|
||||
import cn.iocoder.yudao.framework.pay.core.enums.PayChannelEnum;
|
||||
import com.alibaba.fastjson.JSON;
|
||||
import com.alibaba.fastjson.JSONObject;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.stereotype.Service;
|
||||
import org.springframework.util.Assert;
|
||||
import org.springframework.validation.annotation.Validated;
|
||||
import org.springframework.web.multipart.MultipartFile;
|
||||
|
||||
import javax.annotation.Resource;
|
||||
import javax.validation.ConstraintViolation;
|
||||
import javax.validation.Validation;
|
||||
import javax.validation.Validator;
|
||||
import javax.validation.ValidatorFactory;
|
||||
import java.io.IOException;
|
||||
import java.util.Collection;
|
||||
import java.util.List;
|
||||
import java.util.Set;
|
||||
@ -49,16 +46,16 @@ public class PayChannelServiceImpl implements PayChannelService {
|
||||
|
||||
@Override
|
||||
public Long createChannel(PayChannelCreateReqVO reqVO) {
|
||||
|
||||
// TODO @aquan:感觉获得那一条比较合适。因为是有唯一性的。注释有错别字哈。
|
||||
// 判断是否有重复的有责无法新增
|
||||
Integer channelCount = this.getChannelCountByConditions(reqVO.getMerchantId(), reqVO.getAppId(), reqVO.getCode());
|
||||
if (channelCount > 0) {
|
||||
throw exception(CHANNEL_EXIST_SAME_CHANNEL_ERROR);
|
||||
}
|
||||
|
||||
// 新增渠道
|
||||
PayChannelDO channel = PayChannelConvert.INSTANCE.convert(reqVO);
|
||||
settingConfigAndCheckParam(channel, reqVO.getConfig());
|
||||
|
||||
channelMapper.insert(channel);
|
||||
return channel.getId();
|
||||
}
|
||||
@ -170,16 +167,17 @@ public class PayChannelServiceImpl implements PayChannelService {
|
||||
* @param configStr 配置
|
||||
*/
|
||||
private void settingConfigAndCheckParam(PayChannelDO channel, String configStr) {
|
||||
|
||||
// 得到这个渠道是微信的还是支付宝的
|
||||
String channelType = PayChannelEnum.verifyWechatOrAliPay(channel.getCode());
|
||||
Assert.notNull(channelType, CHANNEL_NOT_EXISTS.getMsg());
|
||||
|
||||
// 进行验证
|
||||
// TODO @阿全:Spring 可以注入 Validator 哈
|
||||
ValidatorFactory validatorFactory = Validation.buildDefaultValidatorFactory();
|
||||
Validator validator = validatorFactory.getValidator();
|
||||
|
||||
// 微信的验证
|
||||
// TODO @aquan:这么实现,可扩性不好。@AssertTrue 注解。
|
||||
if (PayChannelEnum.WECHAT.equals(channelType)) {
|
||||
|
||||
WXPayClientConfig config = JSON.parseObject(configStr, WXPayClientConfig.class);
|
||||
|
@ -124,7 +124,7 @@ public class PayMerchantServiceImpl implements PayMerchantService {
|
||||
*/
|
||||
@Override
|
||||
public List<PayMerchantDO> getMerchantListByNameLimit(String merchantName) {
|
||||
|
||||
// TODO @aquan:mybatis plus 哈
|
||||
LambdaQueryWrapper<PayMerchantDO> queryWrapper = new QueryWrapper<PayMerchantDO>().lambda()
|
||||
.select(PayMerchantDO::getId, PayMerchantDO::getName)
|
||||
.likeRight(PayMerchantDO::getName, merchantName)
|
||||
|
@ -19,7 +19,6 @@ import org.junit.jupiter.api.Test;
|
||||
import org.springframework.context.annotation.Import;
|
||||
|
||||
import javax.annotation.Resource;
|
||||
import javax.validation.Validator;
|
||||
import java.util.List;
|
||||
|
||||
import static cn.iocoder.yudao.coreservice.modules.pay.enums.PayErrorCodeCoreConstants.CHANNEL_NOT_EXISTS;
|
||||
@ -70,7 +69,7 @@ public class PayChannelServiceTest extends BaseDbUnitTest {
|
||||
|
||||
@Test
|
||||
public void testCreateWechatVersion3Channel_success() {
|
||||
// 准备参数
|
||||
// 准备参数 TODO @aquan:多余的空行去掉哈。例如说 74 行。
|
||||
|
||||
WXPayClientConfig v3Config = getV3Config();
|
||||
PayChannelCreateReqVO reqVO = randomPojo(PayChannelCreateReqVO.class, o -> {
|
||||
|
@ -479,7 +479,7 @@ CREATE TABLE IF NOT EXISTS "pay_app" (
|
||||
"update_time" datetime NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
|
||||
"deleted" bit(1) NOT NULL DEFAULT FALSE,
|
||||
PRIMARY KEY ("id")
|
||||
) COMMENT = '支付应用信息';
|
||||
) COMMENT = '支付应用信息';
|
||||
|
||||
CREATE TABLE "pay_channel" (
|
||||
"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,
|
||||
"deleted" bit(1) NOT NULL DEFAULT FALSE,
|
||||
PRIMARY KEY ("id")
|
||||
)COMMENT = '支付渠道';
|
||||
) COMMENT = '支付渠道';
|
||||
|
||||
|
@ -27,6 +27,7 @@ public interface PayErrorCodeCoreConstants {
|
||||
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_CERT_KEY_IS_NULL = new ErrorCode(1007001006,"微信渠道v3版本中apiclient_cert.pem不可为空");
|
||||
|
||||
/**
|
||||
* ========== 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_POST_HANDLER_NOT_FOUND = new ErrorCode(1007006002, "未找到对应的退款后置处理类");
|
||||
|
||||
// TODO @aquan:下面还两个要合并上去哈。另外一般中英文之间要有空格。例如说, 新建一个 order 数据;这样可读性更好。
|
||||
|
||||
/**
|
||||
* ========== 支付商户信息 1-007-004-000 ==========
|
||||
*/
|
||||
|
@ -10,6 +10,8 @@ import java.io.FileNotFoundException;
|
||||
|
||||
// TODO 芋艿:参数校验
|
||||
|
||||
// TODO @aquan: 不要全文件格式化哈,去掉下 <p> 看着不太友好哈
|
||||
|
||||
/**
|
||||
* 微信支付的 PayClientConfig 实现类
|
||||
* 属性主要来自 {@link com.github.binarywang.wxpay.config.WxPayConfig} 的必要属性
|
||||
@ -71,6 +73,7 @@ public class WXPayClientConfig implements PayClientConfig {
|
||||
* <p>
|
||||
* 注意,可通过 {@link #main(String[])} 读取
|
||||
*/
|
||||
// TODO @aquan:对于只有一个值的时候,直接 groups = V3.class 即可,简洁。例如说,我们在 Spring MVC 注解,url 可以多个,也只写单个,一个道理哈
|
||||
@NotBlank(message = "apiclient_key 不能为空", groups = {V3.class})
|
||||
private String privateKeyContent;
|
||||
/**
|
||||
|
Loading…
Reference in New Issue
Block a user