From 886a4d3ab18229234ffc7e035ddce863eb0ed75d Mon Sep 17 00:00:00 2001 From: hjhan Date: Thu, 2 Jul 2026 08:34:49 +0800 Subject: [PATCH] =?UTF-8?q?refactor(swap):=20ComposePage=E8=A1=A5=E5=85=85?= =?UTF-8?q?=E6=8E=A5=E7=BC=9D-AddClientCash/SaveEodSwapRecord/ClearSwapPos?= =?UTF-8?q?itionsForCompose?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit ComposePage内部还有3处DB依赖需要接缝: - AddClientCashInCashOut(cs:804平仓资金记录) → AddClientCash虚方法 - SaveEodSwap(cs:862框架合约汇总) → SaveEodSwapRecord虚方法 - ClearSwapPositions(cs:729清理旧事件) → ClearSwapPositionsForCompose虚方法 测试时override这3个虚方法可避免连库。 验证: 100个测试全通过。 --- .../SwapModule/SwapEodPositionService.cs | 24 ++++++++++++++++--- 1 file changed, 21 insertions(+), 3 deletions(-) diff --git a/YLErpDAL/Modules/SwapModule/SwapEodPositionService.cs b/YLErpDAL/Modules/SwapModule/SwapEodPositionService.cs index 1d685a0c..406ab09a 100644 --- a/YLErpDAL/Modules/SwapModule/SwapEodPositionService.cs +++ b/YLErpDAL/Modules/SwapModule/SwapEodPositionService.cs @@ -135,6 +135,24 @@ namespace YLErp.Modules.SwapModule } } + /// 添加资金记录(生产: AddClientCashInCashOut;测试: 收集到计数器) + protected virtual int AddClientCash(trade td, double amount, string action, DateTime valueDate) + { + return AddClientCashInCashOut(td, amount, action, valueDate); + } + + /// 保存框架合约日终汇总(生产: SaveEodSwap私有方法;测试: 收集到列表) + protected virtual void SaveEodSwapRecord(trade td, DateTime settleDate, DateTime preSettleDate) + { + SaveEodSwap(td, settleDate, preSettleDate); + } + + /// 清理旧持仓事件(生产: ClearSwapPositions;测试: 空操作) + protected virtual void ClearSwapPositionsForCompose(trade td, DateTime tradeDate, List eventTypes) + { + ClearSwapPositions(td, tradeDate, eventTypes, false); + } + #endregion /// @@ -708,7 +726,7 @@ namespace YLErp.Modules.SwapModule var preSettleDate = GetPreValueDate(tradeDate);//上一交易日期 List eventTyps = new List() { (int)SwapEventTypeEnum.平仓, (int)SwapEventTypeEnum.互换, (int)SwapEventTypeEnum.自动互换 }; List removeEventTyps = new List() { (int)SwapEventTypeEnum.平仓, (int)SwapEventTypeEnum.互换, (int)SwapEventTypeEnum.自动互换 }; - ClearSwapPositions(td, tradeDate, removeEventTyps, false); + ClearSwapPositionsForCompose(td, tradeDate, removeEventTyps); td.trade_extend = FindTradeExtend(swapTradeId); var allEodPositions = FindEodSwapPositions(swapTradeId, preSettleDate); var eodPositions = allEodPositions.Where(x => x.ValueDate == preSettleDate).ToList();//上一日终持仓信息 @@ -789,7 +807,7 @@ namespace YLErp.Modules.SwapModule //记录资金记录 if (amount != 0) { - int clientCashId = AddClientCashInCashOut(td, Convert.ToDouble(x.MarkClosePnl), ClientCashInCashOut.系统操作_平仓费, x.UnwindDate.Value); + int clientCashId = AddClientCash(td, Convert.ToDouble(x.MarkClosePnl), ClientCashInCashOut.系统操作_平仓费, x.UnwindDate.Value); x.ClientCashId = clientCashId; } payQty = payQty - x.Quantity; @@ -847,7 +865,7 @@ namespace YLErp.Modules.SwapModule unwindData.CloseNotionalValue = tdCloseNotionalValue; swapEvent.EventData = JsonHelper.Serialize(unwindData); SaveAllChanges(); - SaveEodSwap(td, tradeDate, preSettleDate); + SaveEodSwapRecord(td, tradeDate, preSettleDate); SaveAllChanges(); trans?.Commit(); }