refactor(payment): 移除 MerchantAccessPort 接口

调用方直接依赖 MerchantAccessQueryService,去掉多余端口抽象。
This commit is contained in:
DaxPay Dev
2026-07-14 12:52:12 +08:00
parent 1bbb801118
commit abf731b290
6 changed files with 12 additions and 43 deletions

View File

@@ -1,25 +0,0 @@
package cn.daxpay.open.payment.common.access;
/// # 商户接入信息查询端口(运行态 Access
///
/// 定义在 common供装载器 / 验签 / 登录检查等横切能力依赖,
/// 避免 common 直接依赖 merchant DAO 实现。
/// 实现见 `merchant.service.access.MerchantAccessQueryService`。
///
/// 引导类读路径统一走 `*NotTenant``initMch` 之后的业务读(如公钥)走租户内查询。
public interface MerchantAccessPort {
/// 根据商户号查询商户接入信息(引导用,忽略租户)
MerchantAccessInfo getMerchantByMchNo(String mchNo);
/// 根据商户号查询默认应用(引导用,忽略租户)
MchAppInfoAccessInfo getDefaultAppByMchNo(String mchNo);
/// 根据应用号查询应用(引导用,忽略租户)
MchAppInfoAccessInfo getAppByAppId(String appId);
/// 根据商户号查询商户公钥
///
/// 调用方须已完成 `initMch`(或回调控制器已 `bindMchNoForCallback`),走**租户内**查询。
String findMerchantPublicKey(String mchNo);
}

View File

@@ -8,7 +8,7 @@ import cn.daxpay.open.platform.capability.auth.entity.AuthInfoResult;
import cn.daxpay.open.platform.capability.auth.entity.LoginAuthContext;
import cn.daxpay.open.platform.capability.auth.exception.LoginFailureException;
import cn.daxpay.open.platform.core.code.CommonCode;
import cn.daxpay.open.payment.common.access.MerchantAccessPort;
import cn.daxpay.open.payment.merchant.service.access.MerchantAccessQueryService;
import cn.daxpay.open.payment.merchant.service.user.MerchantUserService;
import cn.hutool.core.util.StrUtil;
import lombok.RequiredArgsConstructor;
@@ -27,7 +27,7 @@ import java.util.Optional;
@RequiredArgsConstructor
public class DaxUserInfoStatusCheck implements UserInfoStatusCheck {
private final MerchantUserService merchantUserService;
private final MerchantAccessPort merchantAccessPort;
private final MerchantAccessQueryService merchantAccessQueryService;
private final ClientCodeService clientCodeService;
/// 检查用户是否拥有当前终端的权限
@@ -43,7 +43,7 @@ public class DaxUserInfoStatusCheck implements UserInfoStatusCheck {
String merchantNo = Optional.ofNullable(merchantUserService.findMchNoByUserId(userId))
// 登录: 您没有商户端的登录权限
.orElseThrow(() -> new LoginFailureException(CommonCode.FAIL_CODE, "error.payment.login.noMerchantPerm"));
var merchant = Optional.ofNullable(merchantAccessPort.getMerchantByMchNo(merchantNo))
var merchant = Optional.ofNullable(merchantAccessQueryService.getMerchantByMchNo(merchantNo))
// 登录: 您没有商户端的登录权限
.orElseThrow(() -> new LoginFailureException(CommonCode.FAIL_CODE, "error.payment.login.noMerchantPerm"));
if (Objects.equals(merchant.getStatus(), MerchantStatusEnum.DISABLED.getCode())) {

View File

@@ -2,7 +2,6 @@ package cn.daxpay.open.payment.merchant.service.access;
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.dao.appinfo.MchAppInfoManager;
import cn.daxpay.open.payment.merchant.dao.config.MerchantCredentialManager;
import cn.daxpay.open.payment.merchant.dao.info.MerchantInfoManager;
@@ -14,14 +13,13 @@ import org.springframework.stereotype.Service;
/// # 商户接入信息查询服务(运行态 Access
///
/// [MerchantAccessPort] 在 merchant 侧的实现:持有 DAO返回精简 Access DTO。
/// 持有 DAO返回精简 Access DTO,供装载器 / 验签 / 登录检查等横切能力使用
/// 引导类读路径统一走 `*NotTenant``initMch` 之后的业务读(如公钥验签)走租户内查询。
///
/// 配置态 CRUD 请使用各业务 Service勿在此扩展管理端能力。
/// 横切调用方应依赖 [MerchantAccessPort],勿直接依赖本实现类。
@Service
@RequiredArgsConstructor
public class MerchantAccessQueryService implements MerchantAccessPort {
public class MerchantAccessQueryService {
private final MerchantInfoManager merchantInfoManager;
private final MchAppInfoManager mchAppInfoManager;
@@ -29,7 +27,6 @@ public class MerchantAccessQueryService implements MerchantAccessPort {
private final MerchantCredentialManager merchantCredentialManager;
/// 根据商户号查询商户接入信息(引导用,忽略租户)
@Override
public MerchantAccessInfo getMerchantByMchNo(String mchNo) {
return merchantInfoManager.findByMchNoNotTenant(mchNo)
.map(this::toMerchantAccessInfo)
@@ -37,7 +34,6 @@ public class MerchantAccessQueryService implements MerchantAccessPort {
}
/// 根据商户号查询默认应用(引导用,忽略租户)
@Override
public MchAppInfoAccessInfo getDefaultAppByMchNo(String mchNo) {
return mchAppInfoManager.findDefaultByMchNoNotTenant(mchNo)
.map(this::toMchAppInfoAccessInfo)
@@ -45,7 +41,6 @@ public class MerchantAccessQueryService implements MerchantAccessPort {
}
/// 根据应用号查询应用(引导用,忽略租户)
@Override
public MchAppInfoAccessInfo getAppByAppId(String appId) {
return mchAppInfoManager.findByAppIdNotTenant(appId)
.map(this::toMchAppInfoAccessInfo)
@@ -55,7 +50,6 @@ public class MerchantAccessQueryService implements MerchantAccessPort {
/// 根据商户号查询商户公钥
///
/// 调用方须已完成 `initMch`(或回调控制器已 `bindMchNoForCallback`),走**租户内**查询。
@Override
public String findMerchantPublicKey(String mchNo) {
return merchantCredentialManager.findByMchNo(mchNo)
.map(MerchantCredential::getPublicKey)

View File

@@ -17,7 +17,7 @@ import org.springframework.stereotype.Service;
/// # 商户API配置服务配置态
///
/// 管理端/商户端凭证查询与更新。须在已有租户上下文(登录 Filter / 运营端 ignoreTable下调用。
/// 网关验签取公钥请走 [cn.daxpay.open.payment.common.access.MerchantAccessPort]。
/// 网关验签取公钥请走 [cn.daxpay.open.payment.merchant.service.access.MerchantAccessQueryService]。
@Slf4j
@Service
@RequiredArgsConstructor

View File

@@ -7,7 +7,7 @@ import cn.daxpay.open.platform.core.exception.business.VerifySignFailedException
import cn.daxpay.open.payment.common.result.DaxResult;
import cn.daxpay.open.payment.common.context.PaymentContext;
import cn.daxpay.open.payment.common.util.PaySignUtil;
import cn.daxpay.open.payment.common.access.MerchantAccessPort;
import cn.daxpay.open.payment.merchant.service.access.MerchantAccessQueryService;
import cn.daxpay.open.payment.unipay.param.PaymentCommonParam;
import cn.hutool.core.util.StrUtil;
import lombok.RequiredArgsConstructor;
@@ -25,13 +25,13 @@ import org.springframework.stereotype.Service;
public class PaymentSignService {
private final PlatformConfigProperties platformConfigProperties;
private final MerchantAccessPort merchantAccessPort;
private final MerchantAccessQueryService merchantAccessQueryService;
private final PaymentContext paymentContext;
/// 入参签名校验:使用线程上下文中的商户号查询商户公钥进行验签
public void signVerify(PaymentCommonParam param) {
// 获取商户公钥
String publicKey = merchantAccessPort.findMerchantPublicKey(paymentContext.getMchNo());
String publicKey = merchantAccessQueryService.findMerchantPublicKey(paymentContext.getMchNo());
// 签名和公钥校验
if (StrUtil.isBlank(publicKey)) {
// 商户公钥为空

View File

@@ -5,7 +5,7 @@ import cn.daxpay.open.payment.device.qrcode.dao.DeviceQrCodeManager;
import cn.daxpay.open.payment.device.qrcode.entity.DeviceQrCode;
import cn.daxpay.open.payment.unipay.client.result.CodePayInfoResult;
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.daxpay.open.platform.core.exception.DataNotExistException;
import cn.daxpay.open.platform.core.exception.operation.OperationFailException;
import cn.daxpay.open.platform.core.code.CommonCode;
@@ -24,7 +24,7 @@ import org.springframework.stereotype.Service;
public class CodePayAssistService {
private final DeviceQrCodeManager deviceQrCodeManager;
private final MerchantAccessPort merchantAccessPort;
private final MerchantAccessQueryService merchantAccessQueryService;
/// 根据码牌编码查询支付信息(公开接口, 脱敏返回)
///
@@ -42,7 +42,7 @@ public class CodePayAssistService {
throw new OperationFailException(CommonCode.FAIL_CODE, "error.device.qrcode.notAssigned");
}
// 查商户并校验存在(启用校验留待二期支付链路 NormalPayService 统一处理)
MerchantAccessInfo merchant = merchantAccessPort.getMerchantByMchNo(entity.getMchNo());
MerchantAccessInfo merchant = merchantAccessQueryService.getMerchantByMchNo(entity.getMchNo());
if (merchant == null) {
// 码牌: 商户不存在
throw new DataNotExistException("error.device.qrcode.mchNotFound");