refactor(payment): 移除 ChannelMerchantResult.activeEnv 冗余字段

商户 Result 上的 activeEnv 字段语义模糊(来自产品配置的产品级状态,被冗余塞进每个商户
Result),与通道商户环境固化原则冲突:同一产品下沙箱/生产商户并存时,所有商户的
activeEnv 都相同,但实际 sandbox 各异。

- ChannelMerchantResult 删除 activeEnv 字段定义
- ChannelMerchantService.fillEnvStatus 不再查询并填充产品 activeEnv 到商户 Result;
  同步移除 PayProductConfigManager 注入与 PayEnvEnum import (已无引用)
- 商户环境信息统一以固化的 ChannelMerchantResult.sandbox 为唯一来源; 产品当前生效
  环境属产品级状态, 由产品配置接口 (PayProductConfigResult.activeEnv) 单独提供
This commit is contained in:
DaxPay Dev
2026-07-19 23:16:27 +08:00
parent e19574e610
commit d3a8991ba8
2 changed files with 9 additions and 20 deletions

View File

@@ -49,15 +49,11 @@ public class ChannelMerchantResult extends MchBaseResult {
@Schema(description = "是否启用")
private Boolean enable;
/// 是否沙箱环境商户
@Schema(description = "是否沙箱环境商户")
/// 是否沙箱(创建时按当时产品 activeEnv 固化写入, 之后不随产品切换改变)
@Schema(description = "是否沙箱(创建时固化的环境标识)")
private boolean sandbox;
/// 当前生效环境(来自商户 sandbox 字段, 商户只读): prod/sandbox
@Schema(description = "当前生效环境: prod/sandbox")
private String activeEnv;
/// 是否支持沙箱环境(决定前端是否展示环境标签)
/// 是否支持沙箱环境(所属产品的能力标志, 决定前端是否展示环境标签)
@Schema(description = "是否支持沙箱环境")
private Boolean sandboxSupport;

View File

@@ -13,10 +13,8 @@ import cn.daxpay.open.payment.merchant.param.channel.ChannelMerchantQuery;
import cn.daxpay.open.payment.merchant.result.channel.ChannelMerchantResult;
import cn.daxpay.open.payment.masterdata.service.channel.PayChannelService;
import cn.daxpay.open.payment.masterdata.result.channel.PayChannelResult;
import cn.daxpay.open.payment.masterdata.dao.product.PayProductConfigManager;
import cn.daxpay.open.payment.masterdata.dao.product.PayProductManager;
import cn.daxpay.open.payment.masterdata.entity.product.PayProduct;
import cn.daxpay.open.platform.core.enums.pay.config.PayEnvEnum;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;
@@ -38,7 +36,6 @@ public class ChannelMerchantService {
private final TransService transService;
private final PayChannelService payChannelService;
private final PayProductManager payProductManager;
private final PayProductConfigManager payProductConfigManager;
/// 分页
public PageResult<ChannelMerchantResult> page(PageParam pageParam, ChannelMerchantQuery query){
@@ -98,11 +95,14 @@ public class ChannelMerchantService {
return results;
}
/// 批量填充生效环境与沙箱支持标志
/// 批量填充沙箱支持标志
///
/// - sandbox: 直接读实体固化的字段(创建时按当时产品 activeEnv 写入, 之后不再随产品切换改变)
/// - activeEnv: 当前产品生效环境(决定该商户是否参与路由), 来自 pay_md_product_config
/// - sandboxSupport: 该产品是否支持沙箱(决定前端是否显示环境标签), 来自 pay_md_product
///
/// 注意: 不再填充"产品当前 activeEnv"到商户 Result。
/// 商户环境信息以固化的 [ChannelMerchantResult#isSandbox] 为准;
/// 产品当前生效环境属于产品级状态(可通过产品配置接口查询), 不应冗余到商户 Result 上。
private void fillEnvStatus(List<ChannelMerchantResult> results) {
if (results.isEmpty()) {
return;
@@ -120,14 +120,7 @@ public class ChannelMerchantService {
.list()
.stream()
.collect(Collectors.toMap(PayProduct::getCode, p -> Boolean.TRUE.equals(p.getSandbox()), (a, b) -> a));
// 产品当前生效环境(决定路由目标; 不再回写通道商户 sandbox)
Map<String, String> activeEnvMap = payProductConfigManager.mapActiveEnvByProducts(products);
results.forEach(r -> {
String activeEnv = activeEnvMap.getOrDefault(r.getProduct(), PayEnvEnum.PROD.getCode());
r.setActiveEnv(activeEnv);
// sandbox 字段为创建时固化的快照, 直接读实体, 不再用产品 activeEnv 覆盖
r.setSandboxSupport(sandboxMap.getOrDefault(r.getProduct(), false));
});
results.forEach(r -> r.setSandboxSupport(sandboxMap.getOrDefault(r.getProduct(), false)));
}
/// 更新启用状态