mirror of
https://gitee.com/hhyykk/ipms-sjy.git
synced 2025-08-12 01:01:53 +08:00
多模块重构 7:pay 模块的重构完成
This commit is contained in:
@@ -1,6 +1,7 @@
|
||||
package cn.iocoder.yudao.module.pay.service.merchant;
|
||||
|
||||
import cn.hutool.core.util.RandomUtil;
|
||||
import cn.iocoder.yudao.framework.pay.core.client.PayClientFactory;
|
||||
import cn.iocoder.yudao.module.pay.controller.admin.merchant.vo.app.PayAppCreateReqVO;
|
||||
import cn.iocoder.yudao.module.pay.controller.admin.merchant.vo.app.PayAppExportReqVO;
|
||||
import cn.iocoder.yudao.module.pay.controller.admin.merchant.vo.app.PayAppPageReqVO;
|
||||
@@ -30,11 +31,6 @@ import static cn.iocoder.yudao.framework.test.core.util.RandomUtils.randomPojo;
|
||||
import static cn.iocoder.yudao.module.pay.enums.ErrorCodeConstants.*;
|
||||
import static org.junit.jupiter.api.Assertions.*;
|
||||
|
||||
/**
|
||||
* {@link PayAppServiceImpl} 的单元测试类
|
||||
*
|
||||
* @author 芋艿
|
||||
*/
|
||||
@Import(PayAppServiceImpl.class)
|
||||
public class PayAppServiceTest extends BaseDbUnitTest {
|
||||
|
||||
|
@@ -2,6 +2,7 @@ package cn.iocoder.yudao.module.pay.service.merchant;
|
||||
|
||||
import cn.iocoder.yudao.framework.common.enums.CommonStatusEnum;
|
||||
import cn.iocoder.yudao.framework.common.pojo.PageResult;
|
||||
import cn.iocoder.yudao.framework.pay.core.client.PayClientFactory;
|
||||
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;
|
||||
@@ -14,9 +15,11 @@ import cn.iocoder.yudao.module.pay.dal.mysql.merchant.PayChannelMapper;
|
||||
import cn.iocoder.yudao.module.pay.test.BaseDbUnitTest;
|
||||
import com.alibaba.fastjson.JSON;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.springframework.boot.test.mock.mockito.MockBean;
|
||||
import org.springframework.context.annotation.Import;
|
||||
|
||||
import javax.annotation.Resource;
|
||||
import javax.validation.Validator;
|
||||
import java.util.List;
|
||||
|
||||
import static cn.iocoder.yudao.framework.common.util.date.DateUtils.buildTime;
|
||||
@@ -37,6 +40,11 @@ public class PayChannelServiceTest extends BaseDbUnitTest {
|
||||
@Resource
|
||||
private PayChannelMapper channelMapper;
|
||||
|
||||
@MockBean
|
||||
private PayClientFactory payClientFactory;
|
||||
@MockBean
|
||||
private Validator validator;
|
||||
|
||||
@Test
|
||||
public void testCreateWechatVersion2Channel_success() {
|
||||
// 准备参数
|
||||
|
@@ -4,6 +4,8 @@ import cn.hutool.core.date.DateUtil;
|
||||
import cn.hutool.core.util.RandomUtil;
|
||||
import cn.iocoder.yudao.framework.common.pojo.PageResult;
|
||||
import cn.iocoder.yudao.framework.common.util.date.DateUtils;
|
||||
import cn.iocoder.yudao.framework.pay.config.PayProperties;
|
||||
import cn.iocoder.yudao.framework.pay.core.client.PayClientFactory;
|
||||
import cn.iocoder.yudao.framework.pay.core.enums.PayChannelEnum;
|
||||
import cn.iocoder.yudao.module.pay.controller.admin.order.vo.PayOrderExportReqVO;
|
||||
import cn.iocoder.yudao.module.pay.controller.admin.order.vo.PayOrderPageReqVO;
|
||||
@@ -12,8 +14,12 @@ import cn.iocoder.yudao.module.pay.dal.mysql.order.PayOrderMapper;
|
||||
import cn.iocoder.yudao.module.pay.enums.order.PayOrderNotifyStatusEnum;
|
||||
import cn.iocoder.yudao.module.pay.enums.order.PayOrderStatusEnum;
|
||||
import cn.iocoder.yudao.module.pay.enums.refund.PayRefundTypeEnum;
|
||||
import cn.iocoder.yudao.module.pay.service.merchant.PayAppService;
|
||||
import cn.iocoder.yudao.module.pay.service.merchant.PayChannelService;
|
||||
import cn.iocoder.yudao.module.pay.service.notify.PayNotifyService;
|
||||
import cn.iocoder.yudao.module.pay.test.BaseDbUnitTest;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.springframework.boot.test.mock.mockito.MockBean;
|
||||
import org.springframework.context.annotation.Import;
|
||||
|
||||
import javax.annotation.Resource;
|
||||
@@ -30,7 +36,7 @@ import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||
*
|
||||
* @author 芋艿
|
||||
*/
|
||||
@Import(PayOrderServiceImpl.class)
|
||||
@Import({PayOrderServiceImpl.class})
|
||||
public class PayOrderServiceTest extends BaseDbUnitTest {
|
||||
|
||||
@Resource
|
||||
@@ -39,6 +45,17 @@ public class PayOrderServiceTest extends BaseDbUnitTest {
|
||||
@Resource
|
||||
private PayOrderMapper orderMapper;
|
||||
|
||||
@MockBean
|
||||
private PayClientFactory payClientFactory;
|
||||
@MockBean
|
||||
private PayProperties properties;
|
||||
@MockBean
|
||||
private PayAppService appService;
|
||||
@MockBean
|
||||
private PayChannelService channelService;
|
||||
@MockBean
|
||||
private PayNotifyService notifyService;
|
||||
|
||||
public String generateNo() {
|
||||
return DateUtil.format(new Date(), "yyyyMMddHHmmss") + RandomUtil.randomInt(100000, 999999);
|
||||
}
|
||||
|
@@ -2,6 +2,7 @@ package cn.iocoder.yudao.module.pay.service.refund;
|
||||
|
||||
import cn.iocoder.yudao.framework.common.pojo.PageResult;
|
||||
import cn.iocoder.yudao.framework.common.util.date.DateUtils;
|
||||
import cn.iocoder.yudao.framework.pay.core.client.PayClientFactory;
|
||||
import cn.iocoder.yudao.framework.pay.core.enums.PayChannelEnum;
|
||||
import cn.iocoder.yudao.module.pay.controller.admin.refund.vo.PayRefundExportReqVO;
|
||||
import cn.iocoder.yudao.module.pay.controller.admin.refund.vo.PayRefundPageReqVO;
|
||||
@@ -10,8 +11,14 @@ import cn.iocoder.yudao.module.pay.dal.mysql.refund.PayRefundMapper;
|
||||
import cn.iocoder.yudao.module.pay.enums.order.PayOrderNotifyStatusEnum;
|
||||
import cn.iocoder.yudao.module.pay.enums.refund.PayRefundStatusEnum;
|
||||
import cn.iocoder.yudao.module.pay.enums.refund.PayRefundTypeEnum;
|
||||
import cn.iocoder.yudao.module.pay.service.merchant.PayAppService;
|
||||
import cn.iocoder.yudao.module.pay.service.merchant.PayChannelService;
|
||||
import cn.iocoder.yudao.module.pay.service.notify.PayNotifyService;
|
||||
import cn.iocoder.yudao.module.pay.service.order.PayOrderExtensionService;
|
||||
import cn.iocoder.yudao.module.pay.service.order.PayOrderService;
|
||||
import cn.iocoder.yudao.module.pay.test.BaseDbUnitTest;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.springframework.boot.test.mock.mockito.MockBean;
|
||||
import org.springframework.context.annotation.Import;
|
||||
|
||||
import javax.annotation.Resource;
|
||||
@@ -22,12 +29,6 @@ import static cn.iocoder.yudao.framework.test.core.util.AssertUtils.assertPojoEq
|
||||
import static cn.iocoder.yudao.framework.test.core.util.RandomUtils.randomPojo;
|
||||
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||
|
||||
|
||||
/**
|
||||
* {@link PayRefundServiceImpl} 的单元测试类
|
||||
*
|
||||
* @author aquan
|
||||
*/
|
||||
@Import(PayRefundServiceImpl.class)
|
||||
public class PayRefundServiceTest extends BaseDbUnitTest {
|
||||
|
||||
@@ -37,6 +38,18 @@ public class PayRefundServiceTest extends BaseDbUnitTest {
|
||||
@Resource
|
||||
private PayRefundMapper refundMapper;
|
||||
|
||||
@MockBean
|
||||
private PayClientFactory payClientFactory;
|
||||
@MockBean
|
||||
private PayOrderService orderService;
|
||||
@MockBean
|
||||
private PayOrderExtensionService orderExtensionService;
|
||||
@MockBean
|
||||
private PayAppService appService;
|
||||
@MockBean
|
||||
private PayChannelService channelService;
|
||||
@MockBean
|
||||
private PayNotifyService notifyService;
|
||||
|
||||
@Test
|
||||
public void testGetRefundPage() {
|
||||
|
@@ -0,0 +1,54 @@
|
||||
spring:
|
||||
main:
|
||||
lazy-initialization: true # 开启懒加载,加快速度
|
||||
banner-mode: off # 单元测试,禁用 Banner
|
||||
|
||||
--- #################### 数据库相关配置 ####################
|
||||
|
||||
spring:
|
||||
# 数据源配置项
|
||||
datasource:
|
||||
name: ruoyi-vue-pro
|
||||
url: jdbc:h2:mem:testdb;MODE=MYSQL;DATABASE_TO_UPPER=false; # MODE 使用 MySQL 模式;DATABASE_TO_UPPER 配置表和字段使用小写
|
||||
driver-class-name: org.h2.Driver
|
||||
username: sa
|
||||
password:
|
||||
schema: classpath:sql/create_tables.sql # MySQL 转 H2 的语句,使用 https://www.jooq.org/translate/ 工具
|
||||
druid:
|
||||
async-init: true # 单元测试,异步初始化 Druid 连接池,提升启动速度
|
||||
initial-size: 1 # 单元测试,配置为 1,提升启动速度
|
||||
|
||||
# Redis 配置。Redisson 默认的配置足够使用,一般不需要进行调优
|
||||
redis:
|
||||
host: 127.0.0.1 # 地址
|
||||
port: 16379 # 端口(单元测试,使用 16379 端口)
|
||||
database: 0 # 数据库索引
|
||||
|
||||
mybatis:
|
||||
lazy-initialization: true # 单元测试,设置 MyBatis Mapper 延迟加载,加速每个单元测试
|
||||
|
||||
--- #################### 定时任务相关配置 ####################
|
||||
|
||||
--- #################### 配置中心相关配置 ####################
|
||||
|
||||
--- #################### 服务保障相关配置 ####################
|
||||
|
||||
# Lock4j 配置项(单元测试,禁用 Lock4j)
|
||||
|
||||
# Resilience4j 配置项
|
||||
|
||||
--- #################### 监控相关配置 ####################
|
||||
|
||||
--- #################### 芋道相关配置 ####################
|
||||
|
||||
# 芋道配置项,设置当前项目所有自定义的配置
|
||||
yudao:
|
||||
info:
|
||||
base-package: cn.iocoder.yudao.module.member.dal.mysql
|
||||
base-package2: cn.iocoder.yudao.module
|
||||
core-service:
|
||||
base-package: cn.iocoder.yudao.module.member.dal.mysql # TODO 芋艿:要清理掉
|
||||
captcha:
|
||||
timeout: 5m
|
||||
width: 160
|
||||
height: 60
|
@@ -0,0 +1,4 @@
|
||||
<configuration>
|
||||
<!-- 引用 Spring Boot 的 logback 基础配置 -->
|
||||
<include resource="org/springframework/boot/logging/logback/defaults.xml" />
|
||||
</configuration>
|
@@ -0,0 +1,5 @@
|
||||
DELETE FROM pay_merchant;
|
||||
DELETE FROM pay_app;
|
||||
DELETE FROM pay_channel;
|
||||
DELETE FROM pay_order;
|
||||
DELETE FROM pay_refund;
|
@@ -0,0 +1,115 @@
|
||||
CREATE TABLE IF NOT EXISTS "pay_merchant"
|
||||
(
|
||||
"id" number NOT NULL GENERATED BY DEFAULT AS IDENTITY,
|
||||
"no" varchar(32) NOT NULL,
|
||||
"name" varchar(64) NOT NULL,
|
||||
"short_name" varchar(64) NOT NULL,
|
||||
"status" tinyint NOT NULL,
|
||||
"remark" varchar(255) DEFAULT NULL,
|
||||
"creator" varchar(64) DEFAULT '',
|
||||
"create_time" datetime NOT NULL DEFAULT CURRENT_TIMESTAMP,
|
||||
"updater" varchar(64) DEFAULT '',
|
||||
"update_time" datetime NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
|
||||
"deleted" bit(1) NOT NULL DEFAULT FALSE,
|
||||
PRIMARY KEY ("id")
|
||||
) COMMENT '支付商户信息';
|
||||
|
||||
CREATE TABLE IF NOT EXISTS "pay_app" (
|
||||
"id" number NOT NULL GENERATED BY DEFAULT AS IDENTITY,
|
||||
"name" varchar(64) NOT NULL,
|
||||
"status" tinyint NOT NULL,
|
||||
"remark" varchar(255) DEFAULT NULL,
|
||||
`pay_notify_url` varchar(1024) NOT NULL,
|
||||
`refund_notify_url` varchar(1024) NOT NULL,
|
||||
`merchant_id` bigint(20) NOT NULL,
|
||||
"creator" varchar(64) DEFAULT '',
|
||||
"create_time" datetime NOT NULL DEFAULT CURRENT_TIMESTAMP,
|
||||
"updater" varchar(64) DEFAULT '',
|
||||
"update_time" datetime NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
|
||||
"deleted" bit(1) NOT NULL DEFAULT FALSE,
|
||||
PRIMARY KEY ("id")
|
||||
) COMMENT = '支付应用信息';
|
||||
|
||||
CREATE TABLE IF NOT EXISTS "pay_channel" (
|
||||
"id" number NOT NULL GENERATED BY DEFAULT AS IDENTITY,
|
||||
"code" varchar(32) NOT NULL,
|
||||
"status" tinyint(4) NOT NULL,
|
||||
"remark" varchar(255) DEFAULT NULL,
|
||||
"fee_rate" double NOT NULL DEFAULT 0,
|
||||
"merchant_id" bigint(20) NOT NULL,
|
||||
"app_id" bigint(20) NOT NULL,
|
||||
"config" varchar(10240) NOT NULL,
|
||||
"creator" varchar(64) NULL DEFAULT '',
|
||||
"create_time" datetime NOT NULL DEFAULT CURRENT_TIMESTAMP,
|
||||
"updater" varchar(64) NULL DEFAULT '',
|
||||
"update_time" datetime NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
|
||||
"deleted" bit(1) NOT NULL DEFAULT FALSE,
|
||||
PRIMARY KEY ("id")
|
||||
) COMMENT = '支付渠道';
|
||||
|
||||
CREATE TABLE IF NOT EXISTS `pay_order` (
|
||||
"id" number NOT NULL GENERATED BY DEFAULT AS IDENTITY,
|
||||
`merchant_id` bigint(20) NOT NULL,
|
||||
`app_id` bigint(20) NOT NULL,
|
||||
`channel_id` bigint(20) DEFAULT NULL,
|
||||
`channel_code` varchar(32) DEFAULT NULL,
|
||||
`merchant_order_id` varchar(64) NOT NULL,
|
||||
`subject` varchar(32) NOT NULL,
|
||||
`body` varchar(128) NOT NULL,
|
||||
`notify_url` varchar(1024) NOT NULL,
|
||||
`notify_status` tinyint(4) NOT NULL,
|
||||
`amount` bigint(20) NOT NULL,
|
||||
`channel_fee_rate` double DEFAULT 0,
|
||||
`channel_fee_amount` bigint(20) DEFAULT 0,
|
||||
`status` tinyint(4) NOT NULL,
|
||||
`user_ip` varchar(50) NOT NULL,
|
||||
`expire_time` datetime(0) NOT NULL DEFAULT CURRENT_TIMESTAMP,
|
||||
`success_time` datetime(0) DEFAULT CURRENT_TIMESTAMP,
|
||||
`notify_time` datetime(0) DEFAULT CURRENT_TIMESTAMP,
|
||||
`success_extension_id` bigint(20) DEFAULT NULL COMMENT '支付成功的订单拓展单编号',
|
||||
`refund_status` tinyint(4) NOT NULL,
|
||||
`refund_times` tinyint(4) NOT NULL,
|
||||
`refund_amount` bigint(20) NOT NULL,
|
||||
`channel_user_id` varchar(255) DEFAULT NULL,
|
||||
`channel_order_no` varchar(64) DEFAULT NULL,
|
||||
`creator` varchar(64) DEFAULT '',
|
||||
`create_time` datetime(0) NOT NULL DEFAULT CURRENT_TIMESTAMP,
|
||||
`updater` varchar(64) DEFAULT '',
|
||||
`update_time` datetime(0) NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
|
||||
`deleted` bit(1) NOT NULL DEFAULT FALSE,
|
||||
PRIMARY KEY ("id")
|
||||
) COMMENT = '支付订单';
|
||||
|
||||
CREATE TABLE IF NOT EXISTS `pay_refund` (
|
||||
"id" number NOT NULL GENERATED BY DEFAULT AS IDENTITY,
|
||||
`merchant_id` bigint(20) NOT NULL,
|
||||
`app_id` bigint(20) NOT NULL,
|
||||
`channel_id` bigint(20) NOT NULL,
|
||||
`channel_code` varchar(32) NOT NULL,
|
||||
`order_id` bigint(20) NOT NULL,
|
||||
`trade_no` varchar(64) NOT NULL,
|
||||
`merchant_order_id` varchar(64) NOT NULL,
|
||||
`merchant_refund_no` varchar(64) NOT NULL,
|
||||
`notify_url` varchar(1024) NOT NULL,
|
||||
`notify_status` tinyint(4) NOT NULL,
|
||||
`status` tinyint(4) NOT NULL,
|
||||
`type` tinyint(4) NOT NULL,
|
||||
`pay_amount` bigint(20) NOT NULL,
|
||||
`refund_amount` bigint(20) NOT NULL,
|
||||
`reason` varchar(256) NOT NULL,
|
||||
`user_ip` varchar(50) NULL DEFAULT NULL,
|
||||
`channel_order_no` varchar(64) NOT NULL,
|
||||
`channel_refund_no` varchar(64) NULL DEFAULT NULL,
|
||||
`channel_error_code` varchar(128) NULL DEFAULT NULL,
|
||||
`channel_error_msg` varchar(256) NULL DEFAULT NULL,
|
||||
`channel_extras` varchar(1024) NULL DEFAULT NULL,
|
||||
`expire_time` datetime(0) NULL DEFAULT NULL,
|
||||
`success_time` datetime(0) NULL DEFAULT NULL,
|
||||
`notify_time` datetime(0) NULL DEFAULT NULL,
|
||||
`creator` varchar(64) NULL DEFAULT '',
|
||||
`create_time` datetime(0) NOT NULL DEFAULT CURRENT_TIMESTAMP,
|
||||
`updater` varchar(64) NULL DEFAULT '',
|
||||
`update_time` datetime(0) NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
|
||||
`deleted` bit(1) NOT NULL DEFAULT FALSE,
|
||||
PRIMARY KEY ("id")
|
||||
) COMMENT = '退款订单';
|
Reference in New Issue
Block a user