refactor(context): 将 MerchantContextLoader 迁入 common.context

与 PaymentContext/Filter/TradeActor 同属线程身份装载层,移除空 assist 包。
This commit is contained in:
DaxPay Dev
2026-07-14 11:56:53 +08:00
parent a243a510aa
commit a23a10abd7
21 changed files with 28 additions and 30 deletions

View File

@@ -2,7 +2,7 @@ package cn.daxpay.open.channel.adapay.controller.callback;
import cn.daxpay.open.channel.adapay.service.callback.AdapayPayCallbackService;
import cn.daxpay.open.channel.adapay.service.callback.AdapayRefundCallbackService;
import cn.daxpay.open.payment.common.assist.MerchantContextLoader;
import cn.daxpay.open.payment.common.context.MerchantContextLoader;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import jakarta.servlet.http.HttpServletRequest;

View File

@@ -1,7 +1,7 @@
package cn.daxpay.open.channel.alipay.controller.callback;
import cn.daxpay.open.channel.alipay.service.callback.AlipayCallbackService;
import cn.daxpay.open.payment.common.assist.MerchantContextLoader;
import cn.daxpay.open.payment.common.context.MerchantContextLoader;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import jakarta.servlet.http.HttpServletRequest;

View File

@@ -2,7 +2,7 @@ package cn.daxpay.open.channel.dougong.controller.callback;
import cn.daxpay.open.channel.dougong.service.callback.DougongPayCallbackService;
import cn.daxpay.open.channel.dougong.service.callback.DougongRefundCallbackService;
import cn.daxpay.open.payment.common.assist.MerchantContextLoader;
import cn.daxpay.open.payment.common.context.MerchantContextLoader;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import jakarta.servlet.http.HttpServletRequest;

View File

@@ -2,7 +2,7 @@ package cn.daxpay.open.channel.douyin.controller.callback;
import cn.daxpay.open.channel.douyin.service.callback.DouyinPayCallbackService;
import cn.daxpay.open.channel.douyin.service.callback.DouyinRefundCallbackService;
import cn.daxpay.open.payment.common.assist.MerchantContextLoader;
import cn.daxpay.open.payment.common.context.MerchantContextLoader;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import jakarta.servlet.http.HttpServletRequest;

View File

@@ -2,7 +2,7 @@ package cn.daxpay.open.channel.fuyou.controller.callback;
import cn.daxpay.open.channel.fuyou.service.callback.FuyouPayCallbackService;
import cn.daxpay.open.channel.fuyou.service.callback.FuyouRefundCallbackService;
import cn.daxpay.open.payment.common.assist.MerchantContextLoader;
import cn.daxpay.open.payment.common.context.MerchantContextLoader;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import lombok.RequiredArgsConstructor;

View File

@@ -2,7 +2,7 @@ package cn.daxpay.open.channel.hkrt.controller.callback;
import cn.daxpay.open.channel.hkrt.service.callback.HkrtPayCallbackService;
import cn.daxpay.open.channel.hkrt.service.callback.HkrtRefundCallbackService;
import cn.daxpay.open.payment.common.assist.MerchantContextLoader;
import cn.daxpay.open.payment.common.context.MerchantContextLoader;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import jakarta.servlet.http.HttpServletRequest;

View File

@@ -2,7 +2,7 @@ package cn.daxpay.open.channel.hmpay.controller.callback;
import cn.daxpay.open.channel.hmpay.service.callback.HmpayPayCallbackService;
import cn.daxpay.open.channel.hmpay.service.callback.HmpayRefundCallbackService;
import cn.daxpay.open.payment.common.assist.MerchantContextLoader;
import cn.daxpay.open.payment.common.context.MerchantContextLoader;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import jakarta.servlet.http.HttpServletRequest;

View File

@@ -2,7 +2,7 @@ package cn.daxpay.open.channel.lakala.controller.callback;
import cn.daxpay.open.channel.lakala.service.callback.LakalaPayCallbackService;
import cn.daxpay.open.channel.lakala.service.callback.LakalaRefundCallbackService;
import cn.daxpay.open.payment.common.assist.MerchantContextLoader;
import cn.daxpay.open.payment.common.context.MerchantContextLoader;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import jakarta.servlet.http.HttpServletRequest;

View File

@@ -2,7 +2,7 @@ package cn.daxpay.open.channel.leshua.controller.callback;
import cn.daxpay.open.channel.leshua.service.callback.LeshuaPayCallbackService;
import cn.daxpay.open.channel.leshua.service.callback.LeshuaRefundCallbackService;
import cn.daxpay.open.payment.common.assist.MerchantContextLoader;
import cn.daxpay.open.payment.common.context.MerchantContextLoader;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import jakarta.servlet.http.HttpServletRequest;

View File

@@ -2,7 +2,7 @@ package cn.daxpay.open.channel.ums.controller.callback;
import cn.daxpay.open.channel.ums.service.callback.UmsPayCallbackService;
import cn.daxpay.open.channel.ums.service.callback.UmsRefundCallbackService;
import cn.daxpay.open.payment.common.assist.MerchantContextLoader;
import cn.daxpay.open.payment.common.context.MerchantContextLoader;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import jakarta.servlet.http.HttpServletRequest;

View File

@@ -2,7 +2,7 @@ package cn.daxpay.open.channel.vbill.controller.callback;
import cn.daxpay.open.channel.vbill.service.callback.VbillPayCallbackService;
import cn.daxpay.open.channel.vbill.service.callback.VbillRefundCallbackService;
import cn.daxpay.open.payment.common.assist.MerchantContextLoader;
import cn.daxpay.open.payment.common.context.MerchantContextLoader;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import jakarta.servlet.http.HttpServletRequest;

View File

@@ -2,7 +2,7 @@ package cn.daxpay.open.channel.wechat.controller.callback;
import cn.daxpay.open.channel.wechat.service.callback.WechatPayCallbackService;
import cn.daxpay.open.channel.wechat.service.callback.WechatRefundCallbackService;
import cn.daxpay.open.payment.common.assist.MerchantContextLoader;
import cn.daxpay.open.payment.common.context.MerchantContextLoader;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import jakarta.servlet.http.HttpServletRequest;

View File

@@ -2,7 +2,7 @@ package cn.daxpay.open.channel.yeepay.controller.callback;
import cn.daxpay.open.channel.yeepay.service.callback.YeepayPayCallbackService;
import cn.daxpay.open.channel.yeepay.service.callback.YeepayRefundCallbackService;
import cn.daxpay.open.payment.common.assist.MerchantContextLoader;
import cn.daxpay.open.payment.common.context.MerchantContextLoader;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import jakarta.servlet.http.HttpServletRequest;

View File

@@ -1,6 +1,6 @@
package cn.daxpay.open.payment.admin.service.device;
import cn.daxpay.open.payment.common.assist.MerchantContextLoader;
import cn.daxpay.open.payment.common.context.MerchantContextLoader;
import cn.daxpay.open.payment.device.enums.QrCodeAmountTypeEnum;
import cn.daxpay.open.payment.device.enums.QrCodeStatusEnum;
import cn.daxpay.open.payment.device.qrcode.dao.DeviceQrCodeManager;

View File

@@ -2,7 +2,7 @@ package cn.daxpay.open.payment.auth;
import cn.daxpay.open.payment.merchant.dao.channel.ChannelMerchantManager;
import cn.daxpay.open.payment.merchant.entity.channel.ChannelMerchant;
import cn.daxpay.open.payment.common.assist.MerchantContextLoader;
import cn.daxpay.open.payment.common.context.MerchantContextLoader;
import cn.daxpay.open.payment.strategy.PaymentStrategyFactory;
import cn.daxpay.open.payment.strategy.auth.AbsChannelAuthStrategy;
import cn.daxpay.open.payment.unipay.param.assist.AuthCodeParam;

View File

@@ -1,4 +1,4 @@
package cn.daxpay.open.payment.common.assist;
package cn.daxpay.open.payment.common.context;
import cn.daxpay.open.platform.core.code.CommonCode;
import cn.daxpay.open.platform.core.code.CommonErrorCode;
@@ -8,10 +8,8 @@ import cn.daxpay.open.platform.core.enums.merchant.MerchantStatusEnum;
import cn.daxpay.open.platform.core.exception.BizInfoException;
import cn.daxpay.open.platform.core.exception.config.ConfigNotEnableException;
import cn.daxpay.open.platform.iam.service.client.ClientCodeService;
import cn.daxpay.open.payment.common.context.PaymentContext;
import cn.daxpay.open.payment.common.access.MchAppInfoAccessInfo;
import cn.daxpay.open.payment.common.access.MerchantAccessInfo;
import cn.daxpay.open.payment.common.access.MerchantAccessPort;
import cn.daxpay.open.payment.merchant.service.access.MerchantAccessQueryService;
import cn.hutool.core.util.StrUtil;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
@@ -30,7 +28,7 @@ import java.util.Optional;
/// - `resolveApp`:应用解析(推导默认/校验启用),仅需要应用归属时调
///
/// **商户端**特判忽略入参 mchNo强制用登录上下文已装载的商户号防越权自报
/// 引导阶段通过 [MerchantAccessPort] `*NotTenant` 读路径
/// 引导阶段通过 [MerchantAccessQueryService] `*NotTenant` 读路径
/// **initMch 成功之后**业务链路应走正常租户过滤勿再散落类级 `@IgnoreTenant`
/// appId 不进线程上下文详见 `_doc/design/mch-no-tenant-isolation.md`
@Slf4j
@@ -39,7 +37,7 @@ import java.util.Optional;
public class MerchantContextLoader {
private final ClientCodeService clientCodeService;
private final MerchantAccessPort merchantAccessPort;
private final MerchantAccessQueryService merchantAccessQueryService;
private final PaymentContext paymentContext;
/// 通道回调身份装载:仅将 path 上的 mchNo 写入上下文,不查库不校验商户启用
@@ -60,7 +58,7 @@ public class MerchantContextLoader {
if (Objects.equals(clientCodeService.getClientCode(), ClientEnum.MERCHANT.getCode())) {
mchNo = paymentContext.getMchNo();
}
var merchant = Optional.ofNullable(merchantAccessPort.getMerchantByMchNo(mchNo))
var merchant = Optional.ofNullable(merchantAccessQueryService.getMerchantByMchNo(mchNo))
// 未找到指定的商户配置
.orElseThrow(() -> new ConfigNotEnableException("error.payment.merchant.specifiedMchConfigNotFound"));
// 商户状态校验
@@ -77,11 +75,11 @@ public class MerchantContextLoader {
MchAppInfoAccessInfo mchApp;
if (StrUtil.isBlank(appId)) {
// appId 为空,取商户默认应用
mchApp = Optional.ofNullable(merchantAccessPort.getDefaultAppByMchNo(mchNo))
mchApp = Optional.ofNullable(merchantAccessQueryService.getDefaultAppByMchNo(mchNo))
// 未找到商户默认应用配置
.orElseThrow(() -> new ConfigNotEnableException("error.payment.merchant.defaultAppConfigNotFound"));
} else {
mchApp = Optional.ofNullable(merchantAccessPort.getAppByAppId(appId))
mchApp = Optional.ofNullable(merchantAccessQueryService.getAppByAppId(appId))
// 未找到指定的应用配置
.orElseThrow(() -> new ConfigNotEnableException("error.payment.merchant.specifiedAppConfigNotFound"));
}
@@ -101,7 +99,7 @@ public class MerchantContextLoader {
/// 按应用号反推商户身份并初始化(应用号已知商户号未知的场景,如渠道配置/通道认证)
/// 商户端会校验应用归属当前登录商户
public void initMchByApp(String appId) {
var mchApp = Optional.ofNullable(merchantAccessPort.getAppByAppId(appId))
var mchApp = Optional.ofNullable(merchantAccessQueryService.getAppByAppId(appId))
// 未找到指定的应用配置
.orElseThrow(() -> new ConfigNotEnableException("error.payment.merchant.specifiedAppConfigNotFound"));
// 应用状态校验

View File

@@ -5,7 +5,7 @@ import cn.daxpay.open.platform.core.exception.BizInfoException;
import cn.daxpay.open.platform.core.exception.PayFailureException;
import cn.daxpay.open.platform.common.spring.util.WebServletUtil;
import cn.daxpay.open.payment.trade.enums.PayFundStatusEnum;
import cn.daxpay.open.payment.common.assist.MerchantContextLoader;
import cn.daxpay.open.payment.common.context.MerchantContextLoader;
import cn.daxpay.open.payment.strategy.PaymentStrategyFactory;
import cn.daxpay.open.payment.trade.runtime.bo.PayTradeResultBo;
import cn.daxpay.open.payment.trade.order.dao.PayTradeManager;

View File

@@ -6,7 +6,7 @@ import cn.daxpay.open.platform.core.code.CommonErrorCode;
import cn.daxpay.open.platform.core.util.ValidationUtil;
import cn.daxpay.open.payment.unipay.param.MerchantPaymentCommonParam;
import cn.daxpay.open.payment.common.result.DaxResult;
import cn.daxpay.open.payment.common.assist.MerchantContextLoader;
import cn.daxpay.open.payment.common.context.MerchantContextLoader;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.aspectj.lang.ProceedingJoinPoint;

View File

@@ -1,6 +1,6 @@
package cn.daxpay.open.payment.unipay.gateway.service;
import cn.daxpay.open.payment.common.assist.MerchantContextLoader;
import cn.daxpay.open.payment.common.context.MerchantContextLoader;
import cn.daxpay.open.payment.trade.enums.PayTradeTypeEnum;
import cn.daxpay.open.payment.trade.order.dao.GatewayPayOrderManager;
import cn.daxpay.open.payment.trade.order.dao.PayTradeManager;

View File

@@ -2,7 +2,7 @@ package cn.daxpay.open.payment.unipay.gateway.service;
import cn.daxpay.open.payment.trade.enums.GatewayOrderStatusEnum;
import cn.daxpay.open.payment.trade.enums.GatewayPayTypeEnum;
import cn.daxpay.open.payment.common.assist.MerchantContextLoader;
import cn.daxpay.open.payment.common.context.MerchantContextLoader;
import cn.daxpay.open.payment.trade.order.dao.GatewayPayOrderManager;
import cn.daxpay.open.payment.trade.order.entity.GatewayPayOrder;
import cn.daxpay.open.payment.trade.runtime.service.pay.PayAssistService;

View File

@@ -3,7 +3,7 @@ package cn.daxpay.open.payment.unipay.gateway.service;
import cn.daxpay.open.payment.trade.enums.GatewayOrderStatusEnum;
import cn.daxpay.open.payment.trade.enums.PayFundStatusEnum;
import cn.daxpay.open.payment.trade.enums.PayTradeTypeEnum;
import cn.daxpay.open.payment.common.assist.MerchantContextLoader;
import cn.daxpay.open.payment.common.context.MerchantContextLoader;
import cn.daxpay.open.payment.route.service.runtime.PayRouteService;
import cn.daxpay.open.payment.strategy.PaymentStrategyFactory;
import cn.daxpay.open.payment.strategy.pay.AbsNormalPayStrategy;