mirror of
				https://gitee.com/hhyykk/ipms-sjy.git
				synced 2025-11-01 02:38:43 +08:00 
			
		
		
		
	code review 支付的逻辑
This commit is contained in:
		| @@ -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 = '支付渠道'; | ||||
|  | ||||
|   | ||||
		Reference in New Issue
	
	Block a user
	 YunaiV
					YunaiV