refactor(swap): FindTrade seam上提基类消除三子类重复

SwapDealService/SwapEodPositionService/SwapFlowEventService 三处 FindTrade(int)
签名和实现完全一致(DbContext.trade.Find),上提到 SwapTradeBaseService 基类。

核对确认可安全上提的只有 FindTrade(三者逐字一致):
- FindTradeExtend 不可上提: SwapEodPositionService 用 FirstOrDefault,
  SwapFlowEventService 用 First(找不到抛异常),语义不同。
- FindPositions 不可上提: SwapEodPositionService 含 IsInitial 持仓,
  SwapFlowEventService 排除 IsInitial + AsNoTracking,语义不同。

测试 stub override FindTrade 跨基类层级正常工作,C# virtual 多态不受影响。
SwapModule 171测试全绿,无回归。
This commit is contained in:
hjhan
2026-07-03 09:52:57 +08:00
parent b501e21904
commit 32bcf9beb9
4 changed files with 15 additions and 12 deletions
@@ -24,11 +24,7 @@ namespace YLErp.Modules.SwapModule
#region Seamsoverride DB/
/// <summary>查找交易(生产: DbContext.trade.Find;测试: 返回内存对象)</summary>
protected virtual trade FindTrade(int tradeId)
{
return DbContext.trade.Find(tradeId);
}
// FindTrade 已上提到基类 SwapTradeBaseService(三子类实现一致,消除重复)
/// <summary>添加资金记录(生产: AddClientCashInCashOut;测试: 计数并记录金额)</summary>
protected virtual int AddClientCash(trade td, double amount, string action, DateTime valueDate)
@@ -79,11 +79,7 @@ namespace YLErp.Modules.SwapModule
grossPrice, orginPv, add, settment, newCalcLast, closeList);
}
/// <summary>查找交易(生产: DbContext.trade.Find;测试: 内存字典)</summary>
protected virtual trade FindTrade(int swapTradeId)
{
return DbContext.trade.Find(swapTradeId);
}
// FindTrade 已上提到基类 SwapTradeBaseService(三子类实现一致,消除重复)
/// <summary>查找交易扩展(生产: DbContext.trade_extend;测试: 内存字典)</summary>
protected virtual trade_extend FindTradeExtend(int tradeId)
@@ -33,8 +33,7 @@ namespace YLErp.Modules.SwapModule
#region Seams refactor-swap-event-testable override DB/
protected virtual trade FindTrade(int swapTradeId)
=> DbContext.trade.Find(swapTradeId);
// FindTrade 已上提到基类 SwapTradeBaseService(三子类实现一致,消除重复)
protected virtual trade_extend FindTradeExtend(int swapTradeId)
=> DbContext.trade_extend.First(x => x.TradeId == swapTradeId);
@@ -19,6 +19,18 @@ namespace YLErp.Modules.SwapModule
{
}
#region Seamsoverride DB/
/// <summary>查找交易(生产: DbContext.trade.Find;测试: 返回内存对象)。
/// SwapDealService/SwapEodPositionService/SwapFlowEventService 三处实现完全一致,上提基类消除重复。</summary>
protected virtual trade FindTrade(int tradeId)
{
return DbContext.trade.Find(tradeId);
}
#endregion
/// <summary>
/// 校验标的是否存在
/// </summary>