From 15bf1a90abd68ac944422cc30d3e0fc8f0c76d83 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E9=A9=AC=E5=86=B0=E5=86=B0?= <437394478@qq.com> Date: Thu, 6 Aug 2026 14:44:30 +0800 Subject: [PATCH] =?UTF-8?q?fix=EF=BC=9A=E6=89=8B=E5=8A=A8=E4=BA=92?= =?UTF-8?q?=E6=8D=A2=E4=B8=8D=E5=86=8D=E4=BA=A7=E7=94=9F=E5=BA=94=E4=BB=98?= =?UTF-8?q?=E9=A2=84=E4=BB=98=E9=87=91=E6=94=AF=E5=87=BA?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../SwapModule/SwapIncomeScenarioTest.cs | 30 +++++++++++++++++++ .../SwapModule/SwapUnwindScenarioTest.cs | 29 ++++++++++++++++++ .../Modules/SwapModule/SwapDealService.cs | 6 +++- 3 files changed, 64 insertions(+), 1 deletion(-) diff --git a/UnitTestProject/Modules/SwapModule/SwapIncomeScenarioTest.cs b/UnitTestProject/Modules/SwapModule/SwapIncomeScenarioTest.cs index 5a1d4308..02aaf36d 100644 --- a/UnitTestProject/Modules/SwapModule/SwapIncomeScenarioTest.cs +++ b/UnitTestProject/Modules/SwapModule/SwapIncomeScenarioTest.cs @@ -63,5 +63,35 @@ namespace YLErp.Modules.SwapModule Assert.AreEqual(ClientCashInCashOut.系统操作_预付金返息, service.ClientCashCalls[1].action); Console.WriteLine($"SI_002: 互换={service.ClientCashCalls[0].amount}, 预付金返息={service.ClientCashCalls[1].amount} ✅"); } + + [TestMethod] + public void SI_003_SwapIncome_含预付金腿_不返还预付金本金() + { + var td = SwapDealTestFactory.CreateTrade(); + td.ExerciseDate = new DateTime(2026, 12, 31); + var service = new TestableSwapDealService(td); + var unwindData = SwapDealTestFactory.CreateUnwindData(swapRealizedPnL: 0m); + unwindData.FlowEvents.Add(new swap_flow_event + { + UnderlyingCode = "UT-FLOAT", + MarkClosePnl = 100m, + PayDirection = 1 + }); + unwindData.FlowEvents.Add(new swap_flow_event + { + InterestMode = (int)InterestModeEnum.初始预付金, + InterestDirection = 1, + InterestPrincipal = 10000m, + InterestClosePnL = 2m + }); + + service.SwapIncome(unwindData); + + Assert.AreEqual(0m, unwindData.SwapMarginAmount, "手动互换不应返还预付金本金"); + Assert.IsFalse(service.ClientCashCalls.Any(x => x.action == ClientCashInCashOut.系统操作_应付预付金), + "手动互换不应生成应付预付金流水"); + Assert.IsTrue(service.ClientCashCalls.Any(x => x.action == ClientCashInCashOut.系统操作_预付金返息), + "手动互换仍应结算预付金返息"); + } } } diff --git a/UnitTestProject/Modules/SwapModule/SwapUnwindScenarioTest.cs b/UnitTestProject/Modules/SwapModule/SwapUnwindScenarioTest.cs index ea9bf5c0..f97b0ba1 100644 --- a/UnitTestProject/Modules/SwapModule/SwapUnwindScenarioTest.cs +++ b/UnitTestProject/Modules/SwapModule/SwapUnwindScenarioTest.cs @@ -166,6 +166,35 @@ namespace YLErp.Modules.SwapModule Console.WriteLine($"UW_005: 反序列化SwapRealizedPnL=8000, 资金流水={service.ClientCashCalls[0].amount}, TradeStatus={td.TradeStatus} ✅"); } + [TestMethod] + public void UW_005A_ApproveSwapTrade_互换审核_不返还预付金本金() + { + var td = SwapDealTestFactory.CreateTrade(); + td.ExerciseDate = new DateTime(2026, 12, 31); + var unwindData = SwapDealTestFactory.CreateUnwindData( + swapRealizedPnL: 100m, swapMarginAmount: -10000m); + var swapEvent = new swap_event + { + id = 2, + SwapTradeId = SwapDealTestFactory.SwapTradeId, + EventType = (int)SwapEventTypeEnum.互换, + Invalid = false, + EventData = JsonConvert.SerializeObject(unwindData) + }; + var service = new TestableSwapDealService(td, + swapEvents: new Dictionary + { + [(int)SwapEventTypeEnum.互换] = swapEvent + }); + + service.ApproveSwapTrade(td, (int)SwapEventTypeEnum.互换); + + Assert.AreEqual(1, service.ClientCashCalls.Count, "互换审批只应生成互换结算流水"); + Assert.AreEqual(ClientCashInCashOut.系统操作_互换, service.ClientCashCalls[0].action); + Assert.IsFalse(service.ClientCashCalls.Any(x => x.action == ClientCashInCashOut.系统操作_应付预付金), + "互换审批不应生成应付预付金流水"); + } + // ================================================================ // 场景6:ApplySwapTrade 提交审核 —— 前置校验与保存事件 // ================================================================ diff --git a/YLErpDAL/Modules/SwapModule/SwapDealService.cs b/YLErpDAL/Modules/SwapModule/SwapDealService.cs index 4248ae87..c708e06d 100644 --- a/YLErpDAL/Modules/SwapModule/SwapDealService.cs +++ b/YLErpDAL/Modules/SwapModule/SwapDealService.cs @@ -85,6 +85,10 @@ namespace YLErp.Modules.SwapModule if (unwindData.FlowEvents.Any(x => !string.IsNullOrEmpty(x.UnderlyingCode))) { CalcCloseAmount(unwindData); + if (eventType == (int)SwapEventTypeEnum.互换) + { + unwindData.SwapMarginAmount = 0; + } return; } @@ -1868,7 +1872,7 @@ namespace YLErp.Modules.SwapModule var flowList = FindFlowEventsByEventId(swapEvent.id); string action = eventType == (int)SwapEventTypeEnum.互换 ? ClientCashInCashOut.系统操作_互换 : ClientCashInCashOut.系统操作_平仓费; int clientCashId = AddClientCash(td, Convert.ToDouble(-swapEvent.unwindData.SwapRealizedPnL), action, swapEvent.unwindData.ValueDate); - if (swapEvent.unwindData.SwapMarginAmount != 0) + if (eventType == (int)SwapEventTypeEnum.平仓 && swapEvent.unwindData.SwapMarginAmount != 0) { AddClientCash(td, Convert.ToDouble(swapEvent.unwindData.SwapMarginAmount), ClientCashInCashOut.系统操作_应付预付金, swapEvent.unwindData.ValueDate); }