From ea2f583c6d1c4166222bcb4839c662c4f5553714 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=BC=A0=E5=90=8D=E9=94=90?= <1565842059@qq.com> Date: Thu, 27 Aug 2026 19:01:29 +0800 Subject: [PATCH] =?UTF-8?q?fix(swap):=20=E8=A7=A3=E5=86=B3=E6=97=A5?= =?UTF-8?q?=E6=9C=9F=E5=88=B7=E6=96=B0=E5=90=8E=E9=83=A8=E5=88=86=E5=B9=B3?= =?UTF-8?q?=E4=BB=93=E6=95=B0=E9=87=8F=E8=AE=A1=E7=AE=97=E9=97=AE=E9=A2=98?= =?UTF-8?q?-=E5=85=AC=E5=8F=B8=E8=A1=8C=E4=B8=BA?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - 在日期刷新基线方法中添加平仓数量重新计算逻辑 - 确保非全平仓情况下按原比例重新计算平仓数量 - 添加单元测试验证部分平仓数量按原比例重算功能 - 修复了日期刷新后平仓比例与实际平仓数量不匹配的bug --- .../ClosePercentProductContractTest.cs | 28 +++++++++++++++++++ .../Scripts/app/swaptrade/unwindSwapTrade.js | 2 ++ 2 files changed, 30 insertions(+) diff --git a/UnitTestProject/Modules/SwapModule/ClosePercentProductContractTest.cs b/UnitTestProject/Modules/SwapModule/ClosePercentProductContractTest.cs index ad44bead..7c3d5722 100644 --- a/UnitTestProject/Modules/SwapModule/ClosePercentProductContractTest.cs +++ b/UnitTestProject/Modules/SwapModule/ClosePercentProductContractTest.cs @@ -353,5 +353,33 @@ namespace YLErp.Modules.SwapModule Console.WriteLine($"⚠ 退化场景:A={closePercentA} == B={convertedB}(首次平仓,无法暴露双重转换bug)"); Console.WriteLine($"✅ 非退化场景见 CPC_005/007:A=0.325 ≠ B=0.50(多次部分平仓后才能暴露)"); } + + [TestMethod] + public void CPC_011_日期刷新基线后_部分平仓数量必须按原比例重算() + { + var directory = new DirectoryInfo(AppContext.BaseDirectory); + string source = null; + while (directory != null && source == null) + { + var path = Path.Combine(directory.FullName, "YLErpWeb", "wwwroot", "Scripts", "app", "swaptrade", "unwindSwapTrade.js"); + if (File.Exists(path)) + { + source = File.ReadAllText(path); + } + directory = directory.Parent; + } + + Assert.IsNotNull(source, "未找到 unwindSwapTrade.js"); + var refreshStart = source.IndexOf("refreshUnwindBaseline() {//", StringComparison.Ordinal); + var refreshEnd = source.IndexOf("getInterestList() {//", refreshStart, StringComparison.Ordinal); + var refreshMethod = source.Substring(refreshStart, refreshEnd - refreshStart); + var oriClosePercentIndex = refreshMethod.IndexOf("thisObj.oriClosePercent =", StringComparison.Ordinal); + var recalcCloseQtyIndex = refreshMethod.IndexOf( + "thisObj.deal.CloseQty = thisObj.calcCloseQtyByPercent(thisObj.deal.ClosePercent);", + StringComparison.Ordinal); + + Assert.IsTrue(recalcCloseQtyIndex > oriClosePercentIndex, + "日期刷新并更新最多可平比例后,部分平仓数量必须按保留的平仓比例重新计算。"); + } } } diff --git a/YLErpWeb/wwwroot/Scripts/app/swaptrade/unwindSwapTrade.js b/YLErpWeb/wwwroot/Scripts/app/swaptrade/unwindSwapTrade.js index 5b2050ef..52153c5a 100644 --- a/YLErpWeb/wwwroot/Scripts/app/swaptrade/unwindSwapTrade.js +++ b/YLErpWeb/wwwroot/Scripts/app/swaptrade/unwindSwapTrade.js @@ -524,6 +524,8 @@ const vue = new Vue({ // 如果是全平,更新平仓比例 if (thisObj.deal.CloseMethod == 1) { thisObj.deal.ClosePercent = thisObj.oriClosePercent; + } else { + thisObj.deal.CloseQty = thisObj.calcCloseQtyByPercent(thisObj.deal.ClosePercent); } // 强制 Vue 更新界面