From 46316c140029b2ea8b951973c9a9b98eaa442368 Mon Sep 17 00:00:00 2001 From: tengyufan <1532636164@qq.com> Date: Wed, 5 Aug 2026 18:26:15 +0800 Subject: [PATCH] =?UTF-8?q?fix:=20=E6=81=A2=E5=A4=8D=E4=BA=92=E6=8D=A2?= =?UTF-8?q?=E5=B9=B3=E4=BB=93=E4=BA=A4=E6=98=93=E8=B4=B9=E7=94=A8=E6=8C=89?= =?UTF-8?q?=E5=9F=BA=E7=A1=80=E8=B4=B9=E7=8E=87=E8=AE=A1=E7=AE=97?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../SwapModule/InitUnwindTradingFeeTest.cs | 16 ++++++-------- .../Modules/SwapModule/SwapDealService.cs | 22 +++++++++---------- YLErpWeb/fe-tests/unwindSwapTrade.test.js | 15 ++++++++----- .../Scripts/app/swaptrade/unwindSwapTrade.js | 10 +-------- 4 files changed, 28 insertions(+), 35 deletions(-) diff --git a/UnitTestProject/Modules/SwapModule/InitUnwindTradingFeeTest.cs b/UnitTestProject/Modules/SwapModule/InitUnwindTradingFeeTest.cs index 0b9f7b37..8ebfb199 100644 --- a/UnitTestProject/Modules/SwapModule/InitUnwindTradingFeeTest.cs +++ b/UnitTestProject/Modules/SwapModule/InitUnwindTradingFeeTest.cs @@ -111,27 +111,25 @@ namespace YLErp.Modules.SwapModule } [TestMethod] - public void PartialCloseTradingFeeAndPendingFeeUseTheSameRoundedOriginalFeeAllocation() + public void ManuallyAdjustedPendingFeeDoesNotOverrideBaseRateCloseFee() { var oriPosition = new swap_position { - PosiFeeType = 0, - PosiTradingFeeUnit = 1.1234m, - PosiTradingFeePending = 113.46m + PosiFeeType = 1, + PosiTradingFeeUnit = 0.123456m, + PosiTradingFeePending = 1235.56m }; var unwindData = new UnwindData { - NotionalValue = 10098m, - CloseNotionalValue = 4039.2m, NotionalQty = 10000m, - CloseQty = 4000m + CloseQty = 10000m }; var tradingFee = InvokeCalcInitTradingFee(oriPosition, unwindData); var pendingFee = InvokeCalcInitTradingFeePending(oriPosition, new swap_position(), unwindData); - Assert.AreEqual(45.38m, tradingFee); - Assert.AreEqual(45.38m, pendingFee); + Assert.AreEqual(1234.56m, tradingFee); + Assert.AreEqual(1235.56m, pendingFee); } [TestMethod] diff --git a/YLErpDAL/Modules/SwapModule/SwapDealService.cs b/YLErpDAL/Modules/SwapModule/SwapDealService.cs index 05d0a372..4248ae87 100644 --- a/YLErpDAL/Modules/SwapModule/SwapDealService.cs +++ b/YLErpDAL/Modules/SwapModule/SwapDealService.cs @@ -324,19 +324,12 @@ namespace YLErp.Modules.SwapModule return 0; } - if (oriPosition.PosiTradingFeeUnit == 0) + if (oriPosition.PosiFeeType == 1) { - return 0; + return Math.Round(oriPosition.PosiTradingFeeUnit * unwindData.CloseQty, ConsGlobal.MoneyRound, MidpointRounding.AwayFromZero); } - var closeBase = oriPosition.PosiFeeType == 1 ? unwindData.CloseQty : unwindData.CloseNotionalValue; - var originalBase = oriPosition.PosiFeeType == 1 ? unwindData.NotionalQty : unwindData.NotionalValue; - if (originalBase <= 0) - { - return 0; - } - - return Math.Round(oriPosition.PosiTradingFeePending * closeBase / originalBase, ConsGlobal.MoneyRound, MidpointRounding.AwayFromZero); + return Math.Round(oriPosition.PosiTradingFeeUnit / 100m * unwindData.CloseNotionalValue, ConsGlobal.MoneyRound, MidpointRounding.AwayFromZero); } private static decimal CalcInitTradingFeePending(swap_position oriPosition, swap_position position, UnwindData unwindData) @@ -346,7 +339,14 @@ namespace YLErp.Modules.SwapModule return position?.PosiTradingFeePending ?? 0; } - return CalcInitTradingFee(oriPosition, unwindData); + var closeBase = oriPosition.PosiFeeType == 1 ? unwindData.CloseQty : unwindData.CloseNotionalValue; + var originalBase = oriPosition.PosiFeeType == 1 ? unwindData.NotionalQty : unwindData.NotionalValue; + if (originalBase <= 0) + { + return position?.PosiTradingFeePending ?? 0; + } + + return Math.Round(oriPosition.PosiTradingFeePending * closeBase / originalBase, ConsGlobal.MoneyRound, MidpointRounding.AwayFromZero); } /// /// 校验上日是否收盘 diff --git a/YLErpWeb/fe-tests/unwindSwapTrade.test.js b/YLErpWeb/fe-tests/unwindSwapTrade.test.js index 53c8197d..eb87bc0d 100644 --- a/YLErpWeb/fe-tests/unwindSwapTrade.test.js +++ b/YLErpWeb/fe-tests/unwindSwapTrade.test.js @@ -43,6 +43,9 @@ function loadUnwindHelpers() { vueDatePicker() { return {}; }, vueNumberInput() { return {}; } }, + swapPricePrecision: { + createVueInputComponent() { return {}; } + }, tradeHelper: { IsBond() { return false; } }, main: { post() { @@ -112,14 +115,14 @@ describe('base-rate pending trading fee', () => { expectClose(result, 450.00); }); - test('partial close fee and pending fee both use the rounded opening fee allocation', () => { - const tradingFee = swapPosiFeeCalc.calcAllocatedTradingFee( - 113.46, consPosiFeeType.Percent, 1.1234, 4039.2, 4000, 10098, 10000); + test('a manually adjusted pending fee does not override the base-rate close fee', () => { + const tradingFee = swapPosiFeeCalc.calcTradingFee( + consPosiFeeType.Unit, 0.123456, 0, 10000); const pendingFee = swapPosiFeeCalc.calcTradingFeePending( - 113.46, consPosiFeeType.Percent, 1.1234, 4039.2, 4000, 10098, 10000, 0.4); + 1235.56, consPosiFeeType.Unit, 0.123456, 0, 10000, 0, 10000, 1); - expectClose(tradingFee, 45.38); - expectClose(pendingFee, 45.38); + expectClose(tradingFee, 1234.56); + expectClose(pendingFee, 1235.56); }); test('without a configured base rate, the legacy close-percent calculation remains', () => { diff --git a/YLErpWeb/wwwroot/Scripts/app/swaptrade/unwindSwapTrade.js b/YLErpWeb/wwwroot/Scripts/app/swaptrade/unwindSwapTrade.js index 27e031a7..4e30c411 100644 --- a/YLErpWeb/wwwroot/Scripts/app/swaptrade/unwindSwapTrade.js +++ b/YLErpWeb/wwwroot/Scripts/app/swaptrade/unwindSwapTrade.js @@ -213,15 +213,7 @@ const vue = new Vue({ this.deal.ClosePercent); }, refreshTradingFeeByUnit() { - const allocatedFee = swapPosiFeeCalc.calcAllocatedTradingFee( - this.floatPosition.BeforeCloseFee, - this.floatPosition.PosiFeeType, - this.floatPosition.PosiTradingFeeUnit, - this.deal.CloseNotionalValue, - this.deal.CloseQty, - this.deal.NotionalValue, - this.deal.NotionalQty); - this.floatPosition.TradingFee = allocatedFee !== null ? allocatedFee : swapPosiFeeCalc.calcTradingFee( + this.floatPosition.TradingFee = swapPosiFeeCalc.calcTradingFee( this.floatPosition.PosiFeeType, this.floatPosition.PosiTradingFeeUnit, this.deal.CloseNotionalValue,