feat(payment): 初始化支付模块核心代码
- 添加支付常量类PaymentConstants,定义支付状态、微信、支付宝、银联等相关常量 - 创建微信支付类型常量类WechatPayType,支持JSAPI、NATIVE、H5、APP支付方式 - 新增支付控制器PaymentController,提供创建支付、查询状态、退款等统一接口 - 实现支付回调控制器PaymentNotifyController,处理微信、支付宝、银联异步通知 - 添加支付请求数据传输对象PaymentRequest,支持多种支付方式参数校验 - 定义支付响应、状态更新请求等相关DTO类- 集成Swagger注解,完善接口文档说明- 添加参数校验和异常处理机制,确保支付流程安全可靠
This commit is contained in:
165
java/payment/utils/PaymentTypeCompatibilityUtil.java
Normal file
165
java/payment/utils/PaymentTypeCompatibilityUtil.java
Normal file
@@ -0,0 +1,165 @@
|
||||
package com.gxwebsoft.payment.utils;
|
||||
|
||||
import com.gxwebsoft.payment.enums.PaymentType;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* 支付方式兼容性处理工具类
|
||||
* 处理废弃支付方式到核心支付方式的映射转换
|
||||
*
|
||||
* @author 科技小王子
|
||||
* @since 2025-08-30
|
||||
*/
|
||||
@Slf4j
|
||||
public class PaymentTypeCompatibilityUtil {
|
||||
|
||||
/**
|
||||
* 废弃支付方式到核心支付方式的映射表
|
||||
*/
|
||||
private static final Map<Integer, Integer> DEPRECATED_TO_CORE_MAPPING = new HashMap<>();
|
||||
|
||||
static {
|
||||
// 旧编号到新编号的映射
|
||||
DEPRECATED_TO_CORE_MAPPING.put(3, 2); // 支付宝(旧3) -> 支付宝(新2)
|
||||
DEPRECATED_TO_CORE_MAPPING.put(12, 6); // 免费(旧12) -> 免费(新6)
|
||||
DEPRECATED_TO_CORE_MAPPING.put(15, 7); // 积分支付(旧15) -> 积分支付(新7)
|
||||
DEPRECATED_TO_CORE_MAPPING.put(19, 3); // 银联支付(旧19) -> 银联支付(新3)
|
||||
|
||||
// 会员卡类支付 -> 余额支付
|
||||
DEPRECATED_TO_CORE_MAPPING.put(2, 0); // 会员卡支付 -> 余额支付
|
||||
DEPRECATED_TO_CORE_MAPPING.put(6, 0); // VIP月卡 -> 余额支付
|
||||
DEPRECATED_TO_CORE_MAPPING.put(7, 0); // VIP年卡 -> 余额支付
|
||||
DEPRECATED_TO_CORE_MAPPING.put(8, 0); // VIP次卡 -> 余额支付
|
||||
DEPRECATED_TO_CORE_MAPPING.put(9, 0); // IC月卡 -> 余额支付
|
||||
DEPRECATED_TO_CORE_MAPPING.put(10, 0); // IC年卡 -> 余额支付
|
||||
DEPRECATED_TO_CORE_MAPPING.put(11, 0); // IC次卡 -> 余额支付
|
||||
DEPRECATED_TO_CORE_MAPPING.put(13, 0); // VIP充值卡 -> 余额支付
|
||||
DEPRECATED_TO_CORE_MAPPING.put(14, 0); // IC充值卡 -> 余额支付
|
||||
DEPRECATED_TO_CORE_MAPPING.put(16, 0); // VIP季卡 -> 余额支付
|
||||
DEPRECATED_TO_CORE_MAPPING.put(17, 0); // IC季卡 -> 余额支付
|
||||
|
||||
// 微信Native -> 微信支付
|
||||
DEPRECATED_TO_CORE_MAPPING.put(102, 1); // 微信Native -> 微信支付
|
||||
|
||||
// 代付 -> 微信支付(默认)
|
||||
DEPRECATED_TO_CORE_MAPPING.put(18, 1); // 代付 -> 微信支付
|
||||
}
|
||||
|
||||
/**
|
||||
* 将废弃的支付方式转换为核心支付方式
|
||||
*
|
||||
* @param originalPayType 原始支付方式代码
|
||||
* @return 转换后的核心支付方式代码
|
||||
*/
|
||||
public static Integer convertToCore(Integer originalPayType) {
|
||||
if (originalPayType == null) {
|
||||
return null;
|
||||
}
|
||||
|
||||
// 检查是否为废弃的支付方式
|
||||
if (DEPRECATED_TO_CORE_MAPPING.containsKey(originalPayType)) {
|
||||
Integer corePayType = DEPRECATED_TO_CORE_MAPPING.get(originalPayType);
|
||||
log.warn("检测到废弃的支付方式: {} -> {},建议升级到核心支付方式",
|
||||
originalPayType, corePayType);
|
||||
return corePayType;
|
||||
}
|
||||
|
||||
// 如果是核心支付方式,直接返回
|
||||
return originalPayType;
|
||||
}
|
||||
|
||||
/**
|
||||
* 检查支付方式是否已废弃
|
||||
*
|
||||
* @param payType 支付方式代码
|
||||
* @return true表示已废弃
|
||||
*/
|
||||
public static boolean isDeprecated(Integer payType) {
|
||||
return payType != null && DEPRECATED_TO_CORE_MAPPING.containsKey(payType);
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取支付方式的迁移说明
|
||||
*
|
||||
* @param payType 支付方式代码
|
||||
* @return 迁移说明文本
|
||||
*/
|
||||
public static String getMigrationMessage(Integer payType) {
|
||||
if (payType == null || !isDeprecated(payType)) {
|
||||
return null;
|
||||
}
|
||||
|
||||
PaymentType originalType = PaymentType.getByCode(payType);
|
||||
PaymentType coreType = PaymentType.getByCode(convertToCore(payType));
|
||||
|
||||
if (originalType != null && coreType != null) {
|
||||
return String.format("支付方式 %s(%d) 已废弃,建议使用 %s(%d)",
|
||||
originalType.getName(), payType,
|
||||
coreType.getName(), coreType.getCode());
|
||||
}
|
||||
|
||||
return "该支付方式已废弃,请使用核心支付方式";
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取所有核心支付方式代码
|
||||
*
|
||||
* @return 核心支付方式代码数组
|
||||
*/
|
||||
public static Integer[] getCorePaymentTypeCodes() {
|
||||
return new Integer[]{0, 1, 2, 3, 4, 5, 6, 7};
|
||||
}
|
||||
|
||||
/**
|
||||
* 检查是否为核心支付方式
|
||||
*
|
||||
* @param payType 支付方式代码
|
||||
* @return true表示是核心支付方式
|
||||
*/
|
||||
public static boolean isCorePaymentType(Integer payType) {
|
||||
if (payType == null) {
|
||||
return false;
|
||||
}
|
||||
|
||||
for (Integer coreType : getCorePaymentTypeCodes()) {
|
||||
if (coreType.equals(payType)) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* 生成支付方式迁移报告
|
||||
*
|
||||
* @return 迁移报告文本
|
||||
*/
|
||||
public static String generateMigrationReport() {
|
||||
StringBuilder report = new StringBuilder();
|
||||
report.append("=== 支付方式迁移报告 ===\n");
|
||||
report.append("核心支付方式(8种):\n");
|
||||
|
||||
for (Integer coreType : getCorePaymentTypeCodes()) {
|
||||
PaymentType type = PaymentType.getByCode(coreType);
|
||||
if (type != null) {
|
||||
report.append(String.format(" %d - %s\n", coreType, type.getName()));
|
||||
}
|
||||
}
|
||||
|
||||
report.append("\n废弃支付方式映射:\n");
|
||||
for (Map.Entry<Integer, Integer> entry : DEPRECATED_TO_CORE_MAPPING.entrySet()) {
|
||||
PaymentType originalType = PaymentType.getByCode(entry.getKey());
|
||||
PaymentType coreType = PaymentType.getByCode(entry.getValue());
|
||||
if (originalType != null && coreType != null) {
|
||||
report.append(String.format(" %d(%s) -> %d(%s)\n",
|
||||
entry.getKey(), originalType.getName(),
|
||||
entry.getValue(), coreType.getName()));
|
||||
}
|
||||
}
|
||||
|
||||
return report.toString();
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user