From 32bcf9beb9746d790f5cfbc28b175ed0d507c363 Mon Sep 17 00:00:00 2001 From: hjhan Date: Fri, 3 Jul 2026 09:52:57 +0800 Subject: [PATCH] =?UTF-8?q?refactor(swap):=20FindTrade=20seam=E4=B8=8A?= =?UTF-8?q?=E6=8F=90=E5=9F=BA=E7=B1=BB=E6=B6=88=E9=99=A4=E4=B8=89=E5=AD=90?= =?UTF-8?q?=E7=B1=BB=E9=87=8D=E5=A4=8D?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 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测试全绿,无回归。 --- YLErpDAL/Modules/SwapModule/SwapDealService.cs | 6 +----- .../Modules/SwapModule/SwapEodPositionService.cs | 6 +----- YLErpDAL/Modules/SwapModule/SwapFlowEventService.cs | 3 +-- YLErpDAL/Modules/SwapModule/SwapTradeBaseService.cs | 12 ++++++++++++ 4 files changed, 15 insertions(+), 12 deletions(-) diff --git a/YLErpDAL/Modules/SwapModule/SwapDealService.cs b/YLErpDAL/Modules/SwapModule/SwapDealService.cs index ef772d90..8c557d4b 100644 --- a/YLErpDAL/Modules/SwapModule/SwapDealService.cs +++ b/YLErpDAL/Modules/SwapModule/SwapDealService.cs @@ -24,11 +24,7 @@ namespace YLErp.Modules.SwapModule #region 可测试化接缝(Seams)——override 这些虚方法可在测试中替换 DB/外部调用,生产代码行为不变 - /// 查找交易(生产: DbContext.trade.Find;测试: 返回内存对象) - protected virtual trade FindTrade(int tradeId) - { - return DbContext.trade.Find(tradeId); - } + // FindTrade 已上提到基类 SwapTradeBaseService(三子类实现一致,消除重复) /// 添加资金记录(生产: AddClientCashInCashOut;测试: 计数并记录金额) protected virtual int AddClientCash(trade td, double amount, string action, DateTime valueDate) diff --git a/YLErpDAL/Modules/SwapModule/SwapEodPositionService.cs b/YLErpDAL/Modules/SwapModule/SwapEodPositionService.cs index e5334b3d..9007286c 100644 --- a/YLErpDAL/Modules/SwapModule/SwapEodPositionService.cs +++ b/YLErpDAL/Modules/SwapModule/SwapEodPositionService.cs @@ -79,11 +79,7 @@ namespace YLErp.Modules.SwapModule grossPrice, orginPv, add, settment, newCalcLast, closeList); } - /// 查找交易(生产: DbContext.trade.Find;测试: 内存字典) - protected virtual trade FindTrade(int swapTradeId) - { - return DbContext.trade.Find(swapTradeId); - } + // FindTrade 已上提到基类 SwapTradeBaseService(三子类实现一致,消除重复) /// 查找交易扩展(生产: DbContext.trade_extend;测试: 内存字典) protected virtual trade_extend FindTradeExtend(int tradeId) diff --git a/YLErpDAL/Modules/SwapModule/SwapFlowEventService.cs b/YLErpDAL/Modules/SwapModule/SwapFlowEventService.cs index 4498b0c9..39eb73e4 100644 --- a/YLErpDAL/Modules/SwapModule/SwapFlowEventService.cs +++ b/YLErpDAL/Modules/SwapModule/SwapFlowEventService.cs @@ -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); diff --git a/YLErpDAL/Modules/SwapModule/SwapTradeBaseService.cs b/YLErpDAL/Modules/SwapModule/SwapTradeBaseService.cs index 3373a90b..d1a54850 100644 --- a/YLErpDAL/Modules/SwapModule/SwapTradeBaseService.cs +++ b/YLErpDAL/Modules/SwapModule/SwapTradeBaseService.cs @@ -19,6 +19,18 @@ namespace YLErp.Modules.SwapModule { } + + #region 可测试化接缝(Seams)——子类共用,override 可在测试中替换 DB/外部调用 + + /// 查找交易(生产: DbContext.trade.Find;测试: 返回内存对象)。 + /// SwapDealService/SwapEodPositionService/SwapFlowEventService 三处实现完全一致,上提基类消除重复。 + protected virtual trade FindTrade(int tradeId) + { + return DbContext.trade.Find(tradeId); + } + + #endregion + /// /// 校验标的是否存在 ///