feat(payment): 优化支付方式并确保系统平滑迁移

-将19种复杂支付方式简化为8种核心支付方式
- 更新PaymentType枚举,添加废弃支付方式的兼容处理
- 新增PaymentTypeCompatibilityUtil工具类,用于支付方式迁移
- 更新ShopOrder和ShopOrderParam的支付方式描述
- 修改ShopOrderServiceImpl中的支付处理逻辑
- 添加单元测试,验证支付方式优化后的功能正确性
This commit is contained in:
2025-08-31 01:42:02 +08:00
parent b105936840
commit 61a5178e5a
7 changed files with 630 additions and 61 deletions

View File

@@ -0,0 +1,136 @@
package com.gxwebsoft.payment.enums;
import com.gxwebsoft.payment.utils.PaymentTypeCompatibilityUtil;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.DisplayName;
import static org.junit.jupiter.api.Assertions.*;
/**
* 支付方式枚举测试类
* 验证支付方式优化后的功能正确性
*
* @author 科技小王子
* @since 2025-08-30
*/
@DisplayName("支付方式枚举测试")
class PaymentTypeTest {
@Test
@DisplayName("测试核心支付方式")
void testCorePaymentTypes() {
// 测试8种核心支付方式
assertEquals(PaymentType.BALANCE, PaymentType.getByCode(0));
assertEquals(PaymentType.WECHAT, PaymentType.getByCode(1));
assertEquals(PaymentType.ALIPAY, PaymentType.getByCode(2));
assertEquals(PaymentType.UNION_PAY, PaymentType.getByCode(3));
assertEquals(PaymentType.CASH, PaymentType.getByCode(4));
assertEquals(PaymentType.POS, PaymentType.getByCode(5));
assertEquals(PaymentType.FREE, PaymentType.getByCode(6));
assertEquals(PaymentType.POINTS, PaymentType.getByCode(7));
// 验证核心支付方式标识
assertTrue(PaymentType.BALANCE.isCorePaymentType());
assertTrue(PaymentType.WECHAT.isCorePaymentType());
assertTrue(PaymentType.ALIPAY.isCorePaymentType());
assertTrue(PaymentType.UNION_PAY.isCorePaymentType());
assertTrue(PaymentType.CASH.isCorePaymentType());
assertTrue(PaymentType.POS.isCorePaymentType());
assertTrue(PaymentType.FREE.isCorePaymentType());
assertTrue(PaymentType.POINTS.isCorePaymentType());
}
@Test
@DisplayName("测试废弃支付方式")
void testDeprecatedPaymentTypes() {
// 测试废弃支付方式标识
assertTrue(PaymentType.WECHAT_NATIVE.isDeprecated());
assertTrue(PaymentType.MEMBER_CARD_OLD.isDeprecated());
assertTrue(PaymentType.VIP_MONTHLY.isDeprecated());
// 验证废弃支付方式仍然可以通过代码获取(向后兼容)
assertEquals(PaymentType.WECHAT_NATIVE, PaymentType.getByCode(102));
assertEquals(PaymentType.FREE_OLD, PaymentType.getByCode(12));
assertEquals(PaymentType.POINTS_OLD, PaymentType.getByCode(15));
}
@Test
@DisplayName("测试支付方式分类")
void testPaymentTypeCategories() {
// 测试微信支付类型
assertTrue(PaymentType.WECHAT.isWechatPay());
assertTrue(PaymentType.WECHAT_NATIVE.isWechatPay());
// 测试第三方支付
assertTrue(PaymentType.WECHAT.isThirdPartyPay());
assertTrue(PaymentType.ALIPAY.isThirdPartyPay());
assertTrue(PaymentType.UNION_PAY.isThirdPartyPay());
// 测试在线支付
assertTrue(PaymentType.WECHAT.isOnlinePay());
assertTrue(PaymentType.ALIPAY.isOnlinePay());
assertFalse(PaymentType.CASH.isOnlinePay());
assertFalse(PaymentType.POS.isOnlinePay());
}
@Test
@DisplayName("测试兼容性工具类")
void testCompatibilityUtil() {
// 测试废弃支付方式转换
assertEquals(Integer.valueOf(0), PaymentTypeCompatibilityUtil.convertToCore(2)); // 会员卡 -> 余额
assertEquals(Integer.valueOf(1), PaymentTypeCompatibilityUtil.convertToCore(102)); // 微信Native -> 微信
assertEquals(Integer.valueOf(2), PaymentTypeCompatibilityUtil.convertToCore(3)); // 支付宝编号调整
assertEquals(Integer.valueOf(6), PaymentTypeCompatibilityUtil.convertToCore(12)); // 免费编号调整
assertEquals(Integer.valueOf(7), PaymentTypeCompatibilityUtil.convertToCore(15)); // 积分编号调整
assertEquals(Integer.valueOf(3), PaymentTypeCompatibilityUtil.convertToCore(19)); // 银联编号调整
// 测试核心支付方式不变
assertEquals(Integer.valueOf(0), PaymentTypeCompatibilityUtil.convertToCore(0)); // 余额支付
assertEquals(Integer.valueOf(1), PaymentTypeCompatibilityUtil.convertToCore(1)); // 微信支付
assertEquals(Integer.valueOf(4), PaymentTypeCompatibilityUtil.convertToCore(4)); // 现金支付
assertEquals(Integer.valueOf(5), PaymentTypeCompatibilityUtil.convertToCore(5)); // POS机支付
// 测试废弃检查
assertTrue(PaymentTypeCompatibilityUtil.isDeprecated(102)); // 微信Native
assertTrue(PaymentTypeCompatibilityUtil.isDeprecated(12)); // 免费(旧)
assertTrue(PaymentTypeCompatibilityUtil.isDeprecated(15)); // 积分(旧)
assertFalse(PaymentTypeCompatibilityUtil.isDeprecated(0)); // 余额支付
assertFalse(PaymentTypeCompatibilityUtil.isDeprecated(1)); // 微信支付
// 测试核心支付方式检查
assertTrue(PaymentTypeCompatibilityUtil.isCorePaymentType(0)); // 余额支付
assertTrue(PaymentTypeCompatibilityUtil.isCorePaymentType(1)); // 微信支付
assertTrue(PaymentTypeCompatibilityUtil.isCorePaymentType(2)); // 支付宝支付
assertTrue(PaymentTypeCompatibilityUtil.isCorePaymentType(7)); // 积分支付
assertFalse(PaymentTypeCompatibilityUtil.isCorePaymentType(102)); // 微信Native
assertFalse(PaymentTypeCompatibilityUtil.isCorePaymentType(12)); // 免费(旧)
}
@Test
@DisplayName("测试迁移消息")
void testMigrationMessages() {
// 测试废弃支付方式的迁移消息
String message = PaymentTypeCompatibilityUtil.getMigrationMessage(102);
assertNotNull(message);
assertTrue(message.contains("微信Native"));
assertTrue(message.contains("微信支付"));
// 测试核心支付方式无迁移消息
assertNull(PaymentTypeCompatibilityUtil.getMigrationMessage(0));
assertNull(PaymentTypeCompatibilityUtil.getMigrationMessage(1));
}
@Test
@DisplayName("测试迁移报告生成")
void testMigrationReport() {
String report = PaymentTypeCompatibilityUtil.generateMigrationReport();
assertNotNull(report);
assertTrue(report.contains("核心支付方式"));
assertTrue(report.contains("废弃支付方式映射"));
assertTrue(report.contains("余额支付"));
assertTrue(report.contains("微信支付"));
System.out.println("=== 支付方式迁移报告 ===");
System.out.println(report);
}
}