From 638803c497e60b0b8bef38154c9ff0cedeb66b6d Mon Sep 17 00:00:00 2001 From: hjhan Date: Wed, 1 Jul 2026 18:17:47 +0800 Subject: [PATCH] =?UTF-8?q?refactor(swap):=20=E9=98=B6=E6=AE=B51c=20CalcSw?= =?UTF-8?q?apInterests=E8=99=9A=E6=96=B9=E6=B3=95=E6=8E=A5=E7=BC=9D(testab?= =?UTF-8?q?le=E8=BF=81=E7=A7=BB)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 加1个protected virtual虚方法: - CalcSwapInterests: 计算利息腿利息明细(原new SwapDealService(this).GetInterests) 参数与GetInterests完全一致,保证行为不变 将3个分支方法里的'new SwapDealService(this).GetInterests'替换为 调用CalcSwapInterests虚方法: - SaveAutoEodInterestPosition(自动互换分支) - SaveAutoEodWithCloseInterestPosition(平仓分支) - SaveEodInterestPositionCopy(普通日分支) 测试子类override CalcSwapInterests,用StubSwapDealService (已有89个测试验证)内存算利息,即可测全部4个分支。 验证: 93个测试全通过(T0/T1=89 + DealInterests=4),无回归。 --- .../SwapModule/SwapEodPositionService.cs | 27 ++++++++++++++++--- 1 file changed, 24 insertions(+), 3 deletions(-) diff --git a/YLErpDAL/Modules/SwapModule/SwapEodPositionService.cs b/YLErpDAL/Modules/SwapModule/SwapEodPositionService.cs index 230f99d3..e54156b8 100644 --- a/YLErpDAL/Modules/SwapModule/SwapEodPositionService.cs +++ b/YLErpDAL/Modules/SwapModule/SwapEodPositionService.cs @@ -58,6 +58,27 @@ namespace YLErp.Modules.SwapModule return new EodCurrencyRateService(UserInfo).GetCurrencyRate(quoteCurrency, settlementCurrency, valueDate, seekPreday, currencyRateType); } + /// + /// 计算利息腿利息明细(生产: new SwapDealService(this).GetInterests;测试: 用StubSwapDealService内存算) + /// 参数与 SwapDealService.GetInterests 完全一致,保证行为不变。 + /// + protected virtual List CalcSwapInterests( + trade td, trade_extend tradeExtend, + DateTime valueDate, DateTime unwindDate, + List eodPositions, List positions, + decimal posiNotionalValue, decimal posiLongNotionalValue, decimal posiShortNotionalValue, + decimal closePosiNotionalValue, decimal closePrecent, + int eventType, bool tdClose, bool needPrice, + decimal grossPrice, decimal orginPv, + bool add = false, bool settment = true, bool newCalcLast = false, + List closeList = null) + { + return new SwapDealService(this).GetInterests(td, tradeExtend, valueDate, unwindDate, + eodPositions, positions, posiNotionalValue, posiLongNotionalValue, posiShortNotionalValue, + closePosiNotionalValue, closePrecent, eventType, tdClose, needPrice, + grossPrice, orginPv, add, settment, newCalcLast, closeList); + } + #endregion /// @@ -966,7 +987,7 @@ namespace YLErp.Modules.SwapModule { orginPv = eodPayPosition.InterestPrincipalFix; } - var interests = new SwapDealService(this).GetInterests(td, td.trade_extend, valueDate, valueDate, preEodPositions, positions, posiNotionalValue, posiLongNotional, posiShortNational, posiNotionalValue, closePercent, (int)SwapEventTypeEnum.自动互换, false, true, grossPrice, orginPv, true); + var interests = CalcSwapInterests(td, td.trade_extend, valueDate, valueDate, preEodPositions, positions, posiNotionalValue, posiLongNotional, posiShortNational, posiNotionalValue, closePercent, (int)SwapEventTypeEnum.自动互换, false, true, grossPrice, orginPv, true); decimal InterestAmount = interests.Sum(x => x.InterestAmount); decimal TdInterestAmount = interests.Sum(x => x.TdInterestAmount); @@ -1076,7 +1097,7 @@ namespace YLErp.Modules.SwapModule positions.Add(position); List preEodPositions = new List(); preEodPositions.Add(eodPayPosition); - var interests = new SwapDealService(this).GetInterests(td, td.trade_extend, valueDate, valueDate, preEodPositions, positions, posiNotionalValue, posiLongNotional, posiShortNational, closeNational, 1, eventType, false, true, grossPrice, orginPv, true, settment: false, newCalcLast: true); + var interests = CalcSwapInterests(td, td.trade_extend, valueDate, valueDate, preEodPositions, positions, posiNotionalValue, posiLongNotional, posiShortNational, closeNational, 1, eventType, false, true, grossPrice, orginPv, true, settment: false, newCalcLast: true); decimal TdInterestAmount = interests.Sum(x => x.TdInterestAmount); decimal InterestAmount = interests.Sum(x => x.InterestAmount); newEodPayPosition.ValueDate = valueDate; @@ -1234,7 +1255,7 @@ namespace YLErp.Modules.SwapModule { preEodPositions.Add(eodPayPosition); } - var interests = new SwapDealService(this).GetInterests(td, td.trade_extend, valueDate, valueDate, preEodPositions, positions, posiNotionalValue, posiLongNational, posiShortNational, posiNotionalValue, closePercent, 0, false, needPrice, grossPrice, orginPv); + var interests = CalcSwapInterests(td, td.trade_extend, valueDate, valueDate, preEodPositions, positions, posiNotionalValue, posiLongNational, posiShortNational, posiNotionalValue, closePercent, 0, false, needPrice, grossPrice, orginPv); UpdateDbOption(newEodPayPosition); newEodPayPosition.PosiStatus = 0;