From 828dc237ab4bf6edb413be457c23a3d7b760eb89 Mon Sep 17 00:00:00 2001 From: hjhan Date: Thu, 20 Aug 2026 16:21:46 +0800 Subject: [PATCH 01/16] =?UTF-8?q?fix(swap):=20EQD-6977=20trace=E5=88=A9?= =?UTF-8?q?=E7=8E=87=E6=9D=A5=E6=BA=90=E6=A0=87=E7=AD=BE=E7=BA=A0=E5=81=8F?= =?UTF-8?q?=E2=80=94=E2=80=94=E5=9B=BA=E5=AE=9A=E8=85=BF=E4=B8=8D=E5=8F=96?= =?UTF-8?q?=E4=BB=B7=E6=97=B6=E4=B8=8D=E5=86=8D=E8=AF=AF=E6=A0=87=E5=AE=9A?= =?UTF-8?q?=E7=9B=98=E5=8F=96=E4=BB=B7(UAT=20tradeId=3D2450=E5=8F=8D?= =?UTF-8?q?=E9=A6=88)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../SwapModule/Penalty/PenaltyInterestFeeMerger.cs | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/YLErpDAL/Modules/SwapModule/Penalty/PenaltyInterestFeeMerger.cs b/YLErpDAL/Modules/SwapModule/Penalty/PenaltyInterestFeeMerger.cs index 7ca04a77..a6b2256b 100644 --- a/YLErpDAL/Modules/SwapModule/Penalty/PenaltyInterestFeeMerger.cs +++ b/YLErpDAL/Modules/SwapModule/Penalty/PenaltyInterestFeeMerger.cs @@ -78,9 +78,13 @@ public static class PenaltyInterestFeeMerger frozenRate = PenaltyLegRateResolver.ResolveFrozenRate( position, getSpread(position), preEod?.FloatRate, unwindDate, d => tryGetFixing(d, position.FloatRateUnderlyingCode)); - rateSource = preEod != null - ? $"preEod.FloatRate@{preEod.ValueDate:yyyy-MM-dd}" - : "定盘取价(unwindDate-1区间)"; + // 来源标签须反映实际路径:固定腿不取价(利差即冻结利率);浮动腿才有快照/取价之分 + if (string.IsNullOrEmpty(position.FloatRateUnderlyingCode)) + rateSource = "固定腿利差(不取价)"; + else if (preEod != null) + rateSource = $"preEod.FloatRate@{preEod.ValueDate:yyyy-MM-dd}"; + else + rateSource = "定盘取价(unwindDate-1区间)"; } catch (Exception ex) { From 71683083ef1d01e922a6d92fd763d3b822d0d23f Mon Sep 17 00:00:00 2001 From: hjhan Date: Thu, 20 Aug 2026 17:29:10 +0800 Subject: [PATCH 02/16] =?UTF-8?q?feat(swap):=20EQD-6953=20=E5=B9=B3?= =?UTF-8?q?=E4=BB=93=E6=9C=9F=E6=9C=AB=E7=BB=93=E7=AE=97=E6=94=B6=E7=9B=8A?= =?UTF-8?q?=E7=8E=87=E5=AD=97=E6=AE=B5=E8=BD=BD=E4=BD=93+=E7=BB=93?= =?UTF-8?q?=E7=AE=97=E7=A1=AE=E8=AE=A4=E4=B9=A6Excel=E5=AF=BC=E5=87=BA?= =?UTF-8?q?=E2=80=94=E2=80=94[NotMapped]ExitYtm=E9=9A=8FUnwindData?= =?UTF-8?q?=E8=BF=9Bswap=5Fevent.EventData(=E9=9B=B6=E8=A1=A8=E7=BB=93?= =?UTF-8?q?=E6=9E=84=E5=8F=98=E6=9B=B4)=EF=BC=9B=E7=94=9F=E6=88=90?= =?UTF-8?q?=E5=99=A8=E4=BB=8E=E6=B5=AE=E5=8A=A8=E8=85=BF=E5=9B=9E=E8=AF=BB?= =?UTF-8?q?=E5=AF=BC=E5=87=BA=E5=9B=BA=E5=AE=9A4=E4=BD=8D=E4=B8=8D?= =?UTF-8?q?=E5=8E=BB=E9=9B=B6(0.0000)=EF=BC=9B=E6=A8=A1=E6=9D=BFnodma=5F01?= =?UTF-8?q?.xlsx=E6=96=B0=E5=A2=9ES=E5=88=97=EF=BC=9B=E5=91=BD=E5=90=8D?= =?UTF-8?q?=E9=81=B5=E3=80=8A=E4=BA=92=E6=8D=A2=E4=BB=B7=E6=A0=BC=E5=AD=97?= =?UTF-8?q?=E6=AE=B5=E5=91=BD=E5=90=8D=E8=A7=84=E8=8C=83=E5=86=B3=E7=AD=96?= =?UTF-8?q?=E6=96=87=E6=A1=A3=E3=80=8B=E5=B9=B3=E4=BB=93=3DExit(=E9=9D=9EE?= =?UTF-8?q?nd/Close/Final)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../YLErp.Core/DBModels/SwapFlowEvent.cs | 13 +++++++++++++ .../YLErp.Core/Models/SwapEndConfirmModel.cs | 6 ++++++ .../settlement_template/nodma_01.xlsx | Bin 10445 -> 6130 bytes .../TradeSettleBillGenerator.cs | 7 +++++++ 4 files changed, 26 insertions(+) diff --git a/Framework/YLErp.Core/DBModels/SwapFlowEvent.cs b/Framework/YLErp.Core/DBModels/SwapFlowEvent.cs index b635b672..7b61672f 100644 --- a/Framework/YLErp.Core/DBModels/SwapFlowEvent.cs +++ b/Framework/YLErp.Core/DBModels/SwapFlowEvent.cs @@ -400,5 +400,18 @@ namespace YLErp.DBModels [NotMapped] public decimal? InitYtm { get; set; } + /// + /// 期末标的结算收益率(EQD-6953 平仓)。普通债券类收益互换平仓时由债券计算器按 + /// 期末标的交割全价反算(估值日=平仓日 ValueDate),允许手工覆盖。 + /// 命名遵循《互换价格字段命名规范决策文档》时点维度:平仓/了结用 Exit(勿用 End/Close/Final)。 + /// [NotMapped]:不落 swap_flow_event 表列;仅随 UnwindData 序列化进 swap_event.EventData JSON, + /// 由平仓待复核回显(GetSwapEvent)与结算确认书 Excel(TradeSettleBillGenerator) 消费。 + /// ⚠️ 存储口径为【展示态百分数】(如 6.3721 表示 6.3721%),与同页期末交割全价(展示态)一致, + /// 区别于录入页 trade.InitYtm 的存储态小数(0.063721)——两者载体不同、互不干扰,勿"顺手统一"。 + /// 精度:确认书导出固定 4 位小数不去零(ToString("0.0000"));本字段保留 4 位(四舍五入)。 + /// + [NotMapped] + public decimal? ExitYtm { get; set; } + } } diff --git a/Framework/YLErp.Core/Models/SwapEndConfirmModel.cs b/Framework/YLErp.Core/Models/SwapEndConfirmModel.cs index b796debe..55ddcf9e 100644 --- a/Framework/YLErp.Core/Models/SwapEndConfirmModel.cs +++ b/Framework/YLErp.Core/Models/SwapEndConfirmModel.cs @@ -45,5 +45,11 @@ namespace YLErp.Models public string DividendIn { get; set; } public string Quantity { get; set; } + + /// + /// 期末标的结算收益率(EQD-6953)。普通债券类收益互换平仓收益率,展示态百分数, + /// 固定 4 位小数不去零("0.0000");非债券/历史无值时为空串。 + /// + public string ExitYtm { get; set; } } } diff --git a/Plugins/YLErp.Plugins.GuoLian/App_Docs/settlement_template/nodma_01.xlsx b/Plugins/YLErp.Plugins.GuoLian/App_Docs/settlement_template/nodma_01.xlsx index 2cf6a553190a988bc29368ba950ad764186abc5b..0415cc61533f2eda60684484d8bb2899bc0992c7 100644 GIT binary patch literal 6130 zcmZ`-1yocEw;p1oJEf(hB&0#QyCkJysDT+722@Z&dI0H=c0dW~bdW}r5Rjoux?4(7 z;Engb|9LO#e`nS?XPvdqx99Bq_TGj%IJndR001B09z$)T{z*?W74tNJImt1nGt|it z27TxwrOFo85M>?G!cok#PPh*n1)(8FN z3~a+|qBH!L3M&zE2~1c3fE6|XK=Dr%oS-n!Zymaml=QoV$<->2L3y#sQE3+Lw80kj zl$5E8I|8oL>L02>jOee=X>McPB2^sHMDt1t*x780 z#qJwcWiEWzfeWw9$li(MgAuWkNSC^NKhuk4<~}5?i(NZx;m1~<;e1HG0Yq24aJnIG zdUSpEhRE!YYh&P4l}9XyL_-q9=g~-5)Umk!{`i}RH#0SX7CIq2QmcXOrd*bxGK?e0XqyI90~P{qr^FqwK?wr+YG~9_TI+QXhbp~8OaVTqCk@h{$dKhl>WP?Qe`pN^;ad!QZVBTD`yu!X^?i4bVRq-`+9yD|!CvVGYEg0)@v?+eKD5bq z?je}waNw*Ju8LM-6l!`}jZRfl?Of+fWnNFF9zC^C%$0uv^WQ(*Y_ZedpI2x(OWvES zdQYrXJk#?1vcIhj6?1w1V}_2bwPrc|MbPQ8>rmju1!(WJ()PB-5Q~EU`9aLO!o8~Y zM^ePT-zlQ270nL`WbCUm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H>Oh(tkJb_qmjx4dj3$^-ohO zzXE^l&i@6S1=q&E^y+^F|GmBW7Zd=PMED*2|1>*)wexGw>n}@CNdNaE{?P&Z)yl6L z^6a3FK{VV$KA@FCkBgIc>gZ~SN^3pJ1di*v6g$U>Z$IWZ1 H-#+~h&#u-S diff --git a/Plugins/YLErp.Plugins.GuoLian/DocumentGenerator/TradeSettleBillGenerator.cs b/Plugins/YLErp.Plugins.GuoLian/DocumentGenerator/TradeSettleBillGenerator.cs index 7523323b..e78f361b 100644 --- a/Plugins/YLErp.Plugins.GuoLian/DocumentGenerator/TradeSettleBillGenerator.cs +++ b/Plugins/YLErp.Plugins.GuoLian/DocumentGenerator/TradeSettleBillGenerator.cs @@ -67,6 +67,9 @@ namespace YLErp.Plugins.GuoLian.DocumentGenerator decimal interestRate = unwindFlowEvents.Where(x => ConsTrade.InterestModels.Contains(x.InterestMode)).Sum(s => s.InterestRate); row.InterestRate = interestRate.ToString("0.00%"); var PosiNotionalValue = flowEventGroup.Quantity * flowEventGroup.ContractSize * posi.PosiGrossPrice; + // EQD-6953 期末标的结算收益率:平仓簿记时随 UnwindData 存进 swap_event.EventData, + // 此处从浮动腿(PositionType>0)回读。存储态=展示态百分数(6.3721),导出固定 4 位不去零。 + decimal? exitYtm = null; if (flowEventGroup.EventId.HasValue) { var swapEvent = Context.GetEvent(flowEventGroup.EventId.Value); @@ -74,8 +77,12 @@ namespace YLErp.Plugins.GuoLian.DocumentGenerator { swapEvent.unwindData = JsonHelper.Deserialize(swapEvent.EventData); PosiNotionalValue = swapEvent.unwindData.CloseNotionalValue; + exitYtm = swapEvent.unwindData.FlowEvents? + .FirstOrDefault(f => f.PositionType > 0)? + .ExitYtm; } } + row.ExitYtm = exitYtm?.ToString("0.0000") ?? string.Empty; row.Quantity = flowEventGroup.Quantity.ToString("0.00"); row.PosiNotionalValue = PosiNotionalValue.ToString("0.00"); From 45d4bc1d26cc78fa9ba00ff516b16b8038daf73d Mon Sep 17 00:00:00 2001 From: hjhan Date: Thu, 20 Aug 2026 17:34:52 +0800 Subject: [PATCH 03/16] =?UTF-8?q?feat(web):=20EQD-6953=20=E5=B9=B3?= =?UTF-8?q?=E4=BB=93=E9=A1=B5DP=E2=86=94YD=E4=BA=92=E7=AE=97=E7=BA=AF?= =?UTF-8?q?=E5=87=BD=E6=95=B0=E5=BA=93unwindBondCalc.js+17=E4=B8=AAjest?= =?UTF-8?q?=E5=8D=95=E6=B5=8B=E2=80=94=E2=80=94=E5=86=BB=E7=BB=93=E4=B8=89?= =?UTF-8?q?=E6=9D=A1=E6=98=93=E9=94=99=E7=BA=A6=E5=AE=9A:=E5=8F=91?= =?UTF-8?q?=E8=AE=A1=E7=AE=97=E5=99=A8=E5=B1=95=E7=A4=BA=E6=80=81=E7=9B=B4?= =?UTF-8?q?=E4=BC=A0=E4=B8=8D=C3=97100/ExitYtm=E5=9B=9B=E4=BD=8D=E5=9B=9B?= =?UTF-8?q?=E8=88=8D=E4=BA=94=E5=85=A5AwayFromZero(=E7=A1=AE=E8=AE=A4?= =?UTF-8?q?=E4=B9=A6=E5=AF=BC=E5=87=BA=E5=9B=BA=E5=AE=9A4=E4=BD=8D?= =?UTF-8?q?=E4=B8=8D=E5=8E=BB=E9=9B=B6)/=E5=A4=B1=E8=B4=A5=E5=8F=AA?= =?UTF-8?q?=E6=B8=85=E5=AF=B9=E6=96=B9=E5=AD=97=E6=AE=B5;=E4=BF=AE?= =?UTF-8?q?=E5=A4=8DroundExitYtm(null)=E4=BC=9A=E8=A2=AB=E5=8F=96=E6=95=B4?= =?UTF-8?q?=E6=88=900=E8=A6=86=E7=9B=96=E6=89=8B=E8=BE=93=E7=9A=84?= =?UTF-8?q?=E9=9A=90=E6=82=A3(=E5=8D=95=E6=B5=8B=E6=8B=A6=E6=88=AA);jest?= =?UTF-8?q?=E8=A6=86=E7=9B=96=E7=8E=87=E6=B8=85=E5=8D=95=E7=BA=B3=E5=85=A5?= =?UTF-8?q?=E6=96=B0=E6=96=87=E4=BB=B6;=E7=BA=AF=E6=96=B0=E5=A2=9E?= =?UTF-8?q?=E9=9B=B6=E6=8E=A5=E7=BA=BF,=E4=B8=8D=E5=BD=B1=E5=93=8D?= =?UTF-8?q?=E7=94=9F=E4=BA=A7?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- YLErpWeb/fe-tests/jest.config.js | 1 + YLErpWeb/fe-tests/unwindBondCalc.test.js | 136 ++++++++++++++++++ .../Scripts/app/swaptrade/unwindBondCalc.js | 128 +++++++++++++++++ 3 files changed, 265 insertions(+) create mode 100644 YLErpWeb/fe-tests/unwindBondCalc.test.js create mode 100644 YLErpWeb/wwwroot/Scripts/app/swaptrade/unwindBondCalc.js diff --git a/YLErpWeb/fe-tests/jest.config.js b/YLErpWeb/fe-tests/jest.config.js index d60ebdc6..b06bd582 100644 --- a/YLErpWeb/fe-tests/jest.config.js +++ b/YLErpWeb/fe-tests/jest.config.js @@ -25,6 +25,7 @@ module.exports = { // 覆盖率配置(--coverage 时生效) collectCoverageFrom: [ '../wwwroot/Scripts/app/swaptrade/swapCalc.js', + '../wwwroot/Scripts/app/swaptrade/unwindBondCalc.js', '../wwwroot/Scripts/fast/fastVue.base.js', // 逐步加入更多文件 ], diff --git a/YLErpWeb/fe-tests/unwindBondCalc.test.js b/YLErpWeb/fe-tests/unwindBondCalc.test.js new file mode 100644 index 00000000..792617bd --- /dev/null +++ b/YLErpWeb/fe-tests/unwindBondCalc.test.js @@ -0,0 +1,136 @@ +/** + * unwindBondCalc.test.js — 平仓页 DP↔YD 两字段互算纯函数(EQD-6953) + * ============================================================================ + * 冻结三条与录入页不同、极易被"顺手统一"改坏的约定: + * 1. 发计算器的价格是【展示态直传】,不 ×100(录入页是存储态 ×100); + * 2. ExitYtm 保留 4 位、四舍五入(AwayFromZero)——结算确认书导出固定 4 位不去零, + * 界面精度不得低于导出要求; + * 3. 失败只清【对方】字段(平仓页无净价列,仅 DP/YD 两字段)。 + * + * 运行:cd YLErpWeb/fe-tests && npx jest unwindBondCalc + */ +const UnwindBondCalc = require('../wwwroot/Scripts/app/swaptrade/unwindBondCalc.js'); + +const CALC = { cleanPrice: 98.5, dirtyPrice: 99.5, ytm: 6.3721 }; + +describe('getCalcRequest:展示态直传,不做录入页的 ×100 换算', () => { + test('DP 回车:price 原样 99.5(若误加 ×100 会变成 9950),priceType=DP,估值日=平仓日', () => { + const req = UnwindBondCalc.getCalcRequest('240004.IB', 99.5, 'DP', '2026-08-20'); + expect(req.price).toBe(99.5); + expect(req.priceType).toBe('DP'); + expect(req.targetDate).toBe('2026-08-20'); + expect(req.underlyingCode).toBe('240004.IB'); + expect(req.source).toBe('unwind'); + }); + + test('YD 回车:收益率展示态直传(6.3721 而非 0.063721)', () => { + const req = UnwindBondCalc.getCalcRequest('240004.IB', 6.3721, 'YD', '2026-08-20'); + expect(req.price).toBe(6.3721); + expect(req.priceType).toBe('YD'); + }); + + test('估值日为空时 targetDate 为 null(兜底,调用方应先校验)', () => { + const req = UnwindBondCalc.getCalcRequest('240004.IB', 99.5, 'DP', null); + expect(req.targetDate).toBeNull(); + }); +}); + +describe('roundExitYtm:4 位小数、四舍五入(远离零)', () => { + test('第 5 位进位', () => { + expect(UnwindBondCalc.roundExitYtm(6.37215)).toBe(6.3722); + }); + test('第 5 位舍去', () => { + expect(UnwindBondCalc.roundExitYtm(6.37214)).toBe(6.3721); + }); + test('负收益率同样远离零(负利率债)', () => { + expect(UnwindBondCalc.roundExitYtm(-0.00005)).toBe(-0.0001); + expect(UnwindBondCalc.roundExitYtm(-1.23445)).toBe(-1.2345); + }); +}); + +describe('applyCalcResult:源字段保持、仅回写对方字段', () => { + test('DP 为源:TradingAmountAvg 保持手输值,ExitYtm 被反算覆盖(4位)', () => { + const state = { TradingAmountAvg: 100.123456, ExitYtm: null }; + UnwindBondCalc.applyCalcResult(state, { ytm: 6.37215 }, 'DP'); + expect(state.TradingAmountAvg).toBe(100.123456); // 源:保持 + expect(state.ExitYtm).toBe(6.3722); // 对方:反算+4位取整 + }); + + test('YD 为源:ExitYtm 保持手输值,TradingAmountAvg 被反算覆盖(展示态直写)', () => { + const state = { TradingAmountAvg: null, ExitYtm: 6.3721 }; + UnwindBondCalc.applyCalcResult(state, { dirtyPrice: 99.5023 }, 'YD'); + expect(state.ExitYtm).toBe(6.3721); // 源:保持 + expect(state.TradingAmountAvg).toBe(99.5023); // 对方:直写(不 ÷100) + }); + + test('计算器未返回对方值时不覆盖(保留手工输入)', () => { + const state = { TradingAmountAvg: 100.5, ExitYtm: 6.3 }; + UnwindBondCalc.applyCalcResult(state, { ytm: null }, 'DP'); + expect(state.ExitYtm).toBe(6.3); + UnwindBondCalc.applyCalcResult(state, { dirtyPrice: undefined }, 'YD'); + expect(state.TradingAmountAvg).toBe(100.5); + }); + + test('回写值与现值相同(<1e-9)时不写,避免光标跳动', () => { + const state = { TradingAmountAvg: 100, ExitYtm: 6.3721 }; + UnwindBondCalc.applyCalcResult(state, { ytm: 6.3721 }, 'DP'); + expect(state.ExitYtm).toBe(6.3721); + }); +}); + +describe('applyCalcFailure:保留源字段、只清对方字段、标识全清', () => { + test('DP 为源失败:ExitYtm 清空、全价保留', () => { + const state = { TradingAmountAvg: 100.5, ExitYtm: 6.3, bondDriverType: 'DP', bondAuto: { DP: true, YD: false } }; + UnwindBondCalc.applyCalcFailure(state, 'DP'); + expect(state.TradingAmountAvg).toBe(100.5); + expect(state.ExitYtm).toBeNull(); + expect(state.bondDriverType).toBeNull(); + expect(state.bondAuto).toEqual({ DP: false, YD: false }); + expect(state.bondRev).toEqual({ DP: false, YD: false }); + }); + + test('YD 为源失败:TradingAmountAvg 清空、收益率保留', () => { + const state = { TradingAmountAvg: 100.5, ExitYtm: 6.3, bondDriverType: 'YD' }; + UnwindBondCalc.applyCalcFailure(state, 'YD'); + expect(state.ExitYtm).toBe(6.3); + expect(state.TradingAmountAvg).toBeNull(); + }); +}); + +describe('标识状态机(交互约定2/3,对齐录入页)', () => { + test('成功:源字段标源、对方标 AUTO、REV 清空', () => { + const state = { TradingAmountAvg: 100.5, ExitYtm: null }; + UnwindBondCalc.applyCalcSuccess(state, 'DP'); + expect(state.bondDriverType).toBe('DP'); + expect(state.bondAuto).toEqual({ DP: false, YD: true }); + expect(state.bondRev).toEqual({ DP: false, YD: false }); + }); + + test('手动编辑未回车:清 源/AUTO、本字段累计 REV、不清对方 REV', () => { + const state = { TradingAmountAvg: 100.5, ExitYtm: 6.3, bondRev: { DP: true, YD: false } }; + UnwindBondCalc.applyManualEdit(state, 'YD'); + expect(state.bondDriverType).toBeNull(); + expect(state.bondAuto).toEqual({ DP: false, YD: false }); + expect(state.bondRev).toEqual({ DP: true, YD: true }); // 累计:DP 的 REV 保留 + }); + + test('bondRev 缺失时自动初始化', () => { + const state = {}; + UnwindBondCalc.applyManualEdit(state, 'DP'); + expect(state.bondRev).toEqual({ DP: true, YD: false }); + }); +}); + +describe('FIELDS 映射与 hasValue 守卫', () => { + test('字段映射', () => { + expect(UnwindBondCalc.FIELDS).toEqual({ DP: 'TradingAmountAvg', YD: 'ExitYtm' }); + }); + test('hasValue:空串/null/undefined/NaN 为 false,0 为 true', () => { + expect(UnwindBondCalc.hasValue('')).toBe(false); + expect(UnwindBondCalc.hasValue(null)).toBe(false); + expect(UnwindBondCalc.hasValue(undefined)).toBe(false); + expect(UnwindBondCalc.hasValue(NaN)).toBe(false); + expect(UnwindBondCalc.hasValue(0)).toBe(true); + expect(UnwindBondCalc.hasValue('6.37')).toBe(true); + }); +}); diff --git a/YLErpWeb/wwwroot/Scripts/app/swaptrade/unwindBondCalc.js b/YLErpWeb/wwwroot/Scripts/app/swaptrade/unwindBondCalc.js new file mode 100644 index 00000000..dc533376 --- /dev/null +++ b/YLErpWeb/wwwroot/Scripts/app/swaptrade/unwindBondCalc.js @@ -0,0 +1,128 @@ +/** + * unwindBondCalc.js — 平仓页 期末标的交割全价 ↔ 期末标的结算收益率(ExitYtm) 两字段互算(EQD-6953) + * ============================================================================ + * 与录入页(swapTradeEdit.js + swapCalc.js 债券三字段互算)的关键差异,【勿"顺手统一"】: + * 1. 单位状态:录入页三字段(CP/DP/YD)存【存储态小数】(0.995),发计算器前 ×100、回写 ÷100 + * (bondPriceToCalc/bondCalcPriceToStorage);平仓页 TradingAmountAvg 在 initDeal 已转 + * 【展示态百分数】(99.5),ExitYtm 亦定义为展示态(6.3721)——发计算器不换算、回写不换算。 + * 提交时的存储态转换仍由既有 getStorageDeliveryPrice()/dataFormat() 负责。 + * 2. 字段集:只有 DP(TradingAmountAvg)/YD(ExitYtm) 两个字段(平仓页无净价列), + * 失败只清对方字段(录入页 applyBondCalcFailure 清另外两个,字段名也不同,故不复用)。 + * 3. 估值日:用平仓日 deal.ValueDate(结算语义);录入页用互换起始日 StartDate。 + * 4. 精度:ExitYtm 保留 4 位小数、四舍五入(AwayFromZero)——结算确认书导出要求 + * 固定 4 位不去零(ToString("0.0000")),界面精度不得低于该要求。 + * + * 浏览器:挂 window.UnwindBondCalc(需在 swapCalc.js 之后、unwindSwapTrade.js 之前加载)。 + * Node:module.exports(UMD),供 fe-tests/unwindBondCalc.test.js 使用。 + * 命名遵《互换价格字段命名规范决策文档》:平仓/了结时点 = Exit(非 End/Close/Final)。 + */ +(function (root, factory) { + if (typeof module === 'object' && module.exports) { + module.exports = factory(require('./swapCalc.js')); + } else { + root.UnwindBondCalc = factory(root.SwapCalc); + } +})(typeof self !== 'undefined' ? self : this, function (SwapCalc) { + 'use strict'; + + // driver(回车的"源"字段) → 平仓页浮动腿(floatPosition)字段名 + var FIELDS = { DP: 'TradingAmountAvg', YD: 'ExitYtm' }; + + function hasValue(v) { + return v !== null && v !== undefined && v !== '' && !isNaN(v); + } + + /** + * 构造 /Bond/CalcBond 请求体。 + * ⚠️ price 必须传【展示态百分数】直传(99.5),不做录入页那种 ×100—— + * 平仓页模型里两个字段本就是展示态。此约定由 fe-tests 冻结,防止后人误加换算。 + * source='unwind':BondController 记进日志,便于区分录入页/平仓页来源定位问题。 + */ + function getCalcRequest(underlyingCode, price, driver, valueDate) { + return { + underlyingCode: underlyingCode, + price: Number(price), + priceType: driver, + targetDate: valueDate || null, + source: 'unwind' + }; + } + + /** + * ExitYtm 统一取整:4 位、四舍五入(远离零),对齐后端 decimal ToString("0.0000")。 + * 非数值(null/undefined/NaN)返回 null——供 write 跳过,绝不能把 null 取整成 0 回写 + * (否则计算器未返回 ytm 时会清掉用户手工输入)。 + */ + function roundExitYtm(value) { + if (value === null || value === undefined || isNaN(value)) return null; + return SwapCalc.roundHalfAwayFromZero(value, 4); + } + + /** + * 计算成功回写(交互约定1+2):源字段保持用户手输值,仅回写对方字段(展示态直写)。 + * - driver='DP'(全价回车)→ 回写 ExitYtm = ytm 取整 4 位;计算器未返回 ytm 则不覆盖。 + * - driver='YD'(收益率回车)→ 回写 TradingAmountAvg = dirtyPrice;未返回则不覆盖。 + * ⚠️ 调用方回写 TradingAmountAvg 后须显式重算平仓盈亏(calcFloatClosePnl)。 + * 纯函数,jest 可直接测。 + */ + function applyCalcResult(state, calc, driver) { + function write(field, value) { + if (value === undefined || value === null) return; // 计算器未返回则不覆盖 + var cur = state[field]; + if (typeof cur === 'number' && Math.abs(cur - value) < 1e-9) return; // 无变化不写 + state[field] = value; + } + if (driver === 'DP') { + write('ExitYtm', roundExitYtm(calc && calc.ytm)); + } else if (driver === 'YD') { + write('TradingAmountAvg', calc && calc.dirtyPrice); + } + return state; + } + + /** + * 计算失败落地(交互约定2):保留源字段值(用户可就地改),清对方字段、清全部标识。 + * 与录入页差异:只清"对方"一个字段(录入页清另外两个)。 + */ + function applyCalcFailure(state, driver) { + var other = driver === 'DP' ? 'YD' : 'DP'; + state[FIELDS[other]] = null; + state.bondDriverType = null; + state.bondAuto = { DP: false, YD: false }; + state.bondRev = { DP: false, YD: false }; + return state; + } + + /** 计算成功后的标识(交互约定2):源字段标"源",对方标"AUTO"。 */ + function applyCalcSuccess(state, driver) { + state.bondDriverType = driver; + state.bondAuto = { DP: driver !== 'DP', YD: driver !== 'YD' }; + state.bondRev = { DP: false, YD: false }; + return state; + } + + /** + * 编辑未回车(失焦/按键)的标识(交互约定3):清 源/AUTO,仅本字段累计标"REV", + * 不联动对方字段(允许计算有问题时手工覆盖 ExitYtm)。同录入页:累计 REV 不互清。 + */ + function applyManualEdit(state, type) { + state.bondDriverType = null; + state.bondAuto = { DP: false, YD: false }; + if (!state.bondRev || typeof state.bondRev !== 'object') { + state.bondRev = { DP: false, YD: false }; + } + if (type) state.bondRev[type] = true; + return state; + } + + return { + FIELDS: FIELDS, + hasValue: hasValue, + getCalcRequest: getCalcRequest, + roundExitYtm: roundExitYtm, + applyCalcResult: applyCalcResult, + applyCalcFailure: applyCalcFailure, + applyCalcSuccess: applyCalcSuccess, + applyManualEdit: applyManualEdit + }; +}); From 4bd528f966e1458c6506290f06ba787ecf7f188e Mon Sep 17 00:00:00 2001 From: hjhan Date: Thu, 20 Aug 2026 17:38:43 +0800 Subject: [PATCH 04/16] =?UTF-8?q?feat(web):=20EQD-6953=20=E5=B9=B3?= =?UTF-8?q?=E4=BB=93=E9=A1=B5=E6=8E=A5=E5=85=A5=E6=9C=9F=E6=9C=AB=E7=BB=93?= =?UTF-8?q?=E7=AE=97=E6=94=B6=E7=9B=8A=E7=8E=87=E4=BA=92=E7=AE=97=E2=80=94?= =?UTF-8?q?=E2=80=94SwapUnwind=E6=B5=AE=E5=8A=A8=E7=AB=AF=E6=96=B0?= =?UTF-8?q?=E5=A2=9E=E5=88=97(=E4=BB=85=E6=99=AE=E9=80=9A=E5=80=BA?= =?UTF-8?q?=E5=88=B8=E7=B1=BB=E6=94=B6=E7=9B=8A=E4=BA=92=E6=8D=A2,?= =?UTF-8?q?=E6=8E=A7=E4=BB=B6/=E4=BA=8B=E4=BB=B6/=E6=BA=90AUTO=20REV?= =?UTF-8?q?=E6=A0=87=E8=AF=86=E4=B8=8E=E5=BD=95=E5=85=A5=E9=A1=B5=E5=90=8C?= =?UTF-8?q?=E6=AC=BEvue-swap-price-input)=EF=BC=9BDP=E5=9B=9E=E8=BD=A6?= =?UTF-8?q?=E2=86=92=E7=AE=97ExitYtm(4=E4=BD=8D)=E3=80=81YD=E5=9B=9E?= =?UTF-8?q?=E8=BD=A6=E2=86=92=E5=8F=8D=E7=AE=97=E4=BA=A4=E5=89=B2=E5=85=A8?= =?UTF-8?q?=E4=BB=B7=E5=B9=B6=E9=87=8D=E7=AE=97=E5=B9=B3=E4=BB=93=E7=9B=88?= =?UTF-8?q?=E4=BA=8F=E3=80=81=E6=89=8B=E5=A1=AB=E6=9C=AA=E5=9B=9E=E8=BD=A6?= =?UTF-8?q?=3DREV=E5=8F=AF=E8=A6=86=E7=9B=96=EF=BC=9B=E4=BC=B0=E5=80=BC?= =?UTF-8?q?=E6=97=A5=3D=E5=B9=B3=E4=BB=93=E6=97=A5,=E6=94=B9=E6=97=A5?= =?UTF-8?q?=E6=9C=9F=E6=B8=85=E9=99=88=E6=97=A7=E5=80=BC=EF=BC=9B=E9=98=B2?= =?UTF-8?q?=E5=BE=A1:applyCalcFailure=E9=9D=9E=E6=B3=95driver=E5=8F=AA?= =?UTF-8?q?=E6=B8=85=E6=A0=87=E8=AF=86=E9=98=B2=E8=AF=AF=E6=B8=85=E4=BA=A4?= =?UTF-8?q?=E5=89=B2=E5=85=A8=E4=BB=B7(=E8=A1=A5=E5=9B=9E=E5=BD=92?= =?UTF-8?q?=E6=B5=8B=E8=AF=95)=EF=BC=9BclosePercentInterestRefresh?= =?UTF-8?q?=E6=B2=99=E7=AE=B1=E8=A1=A5UnwindBondCalc=20mock=E5=AF=B9?= =?UTF-8?q?=E9=BD=90=E9=A1=B5=E9=9D=A2=E8=84=9A=E6=9C=AC=E5=BA=8F;209/209?= =?UTF-8?q?=E9=80=9A=E8=BF=87?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- YLErpWeb/Views/SwapTrade2/SwapUnwind.cshtml | 11 +- .../closePercentInterestRefresh.test.js | 7 + YLErpWeb/fe-tests/unwindBondCalc.test.js | 9 ++ .../Scripts/app/swaptrade/unwindBondCalc.js | 8 +- .../Scripts/app/swaptrade/unwindSwapTrade.js | 125 +++++++++++++++++- 5 files changed, 156 insertions(+), 4 deletions(-) diff --git a/YLErpWeb/Views/SwapTrade2/SwapUnwind.cshtml b/YLErpWeb/Views/SwapTrade2/SwapUnwind.cshtml index 04dd36f2..c1fdaf8d 100644 --- a/YLErpWeb/Views/SwapTrade2/SwapUnwind.cshtml +++ b/YLErpWeb/Views/SwapTrade2/SwapUnwind.cshtml @@ -26,6 +26,7 @@ + }
@@ -197,6 +198,8 @@ 期初标的价格 期末标的交割全价% 期末标的价格 + @* EQD-6953 期末标的结算收益率:仅普通债券类收益互换显示,期末交割全价回车反算,可手填覆盖 *@ + 期末标的结算收益率% 数量 交易费用(平仓) 交易费用(待结算) @@ -223,11 +226,17 @@ {{priceFormat(floatPosition.PosiGrossPrice)}} - + + AUTOREV + @* EQD-6953 期末标的结算收益率:回车以它为源反算交割全价(联动盈亏);手填未回车=REV人工输入 *@ + + + AUTOREV + {{formatQuantity(deal.CloseQty)}} diff --git a/YLErpWeb/fe-tests/closePercentInterestRefresh.test.js b/YLErpWeb/fe-tests/closePercentInterestRefresh.test.js index eeeb4310..2fb4a7eb 100644 --- a/YLErpWeb/fe-tests/closePercentInterestRefresh.test.js +++ b/YLErpWeb/fe-tests/closePercentInterestRefresh.test.js @@ -148,6 +148,13 @@ function loadVueApp(model, mockPost) { return Number(Number(positionQty) * (Number(closePercent) / ori).toFixed(6)); } }, + // EQD-6953:平仓页现于 unwindSwapTrade.js 之前加载 unwindBondCalc.js(见 SwapUnwind.cshtml), + // dataFormat 提交取整会引用其守卫;此处给同款行为的最小 mock(真实实现由 unwindBondCalc.test.js 覆盖) + UnwindBondCalc: { + hasValue(v) { return v !== null && v !== undefined && v !== '' && !isNaN(v); }, + roundExitYtm(v) { return v; }, + applyManualEdit(s) { return s; } + }, _: { round(value, precision) { return Number(Number(value || 0).toFixed(precision || 0)); diff --git a/YLErpWeb/fe-tests/unwindBondCalc.test.js b/YLErpWeb/fe-tests/unwindBondCalc.test.js index 792617bd..2937f9a2 100644 --- a/YLErpWeb/fe-tests/unwindBondCalc.test.js +++ b/YLErpWeb/fe-tests/unwindBondCalc.test.js @@ -95,6 +95,15 @@ describe('applyCalcFailure:保留源字段、只清对方字段、标识全清 expect(state.ExitYtm).toBe(6.3); expect(state.TradingAmountAvg).toBeNull(); }); + + test('driver 非法(null):仅清标识、不动任何数值(setValueDate 清陈旧标识场景的防误清守卫)', () => { + const state = { TradingAmountAvg: 100.5, ExitYtm: 6.3, bondDriverType: 'DP', bondAuto: { DP: false, YD: true } }; + UnwindBondCalc.applyCalcFailure(state, null); + expect(state.TradingAmountAvg).toBe(100.5); // 绝不能被清 + expect(state.ExitYtm).toBe(6.3); + expect(state.bondDriverType).toBeNull(); + expect(state.bondAuto).toEqual({ DP: false, YD: false }); + }); }); describe('标识状态机(交互约定2/3,对齐录入页)', () => { diff --git a/YLErpWeb/wwwroot/Scripts/app/swaptrade/unwindBondCalc.js b/YLErpWeb/wwwroot/Scripts/app/swaptrade/unwindBondCalc.js index dc533376..4c52f009 100644 --- a/YLErpWeb/wwwroot/Scripts/app/swaptrade/unwindBondCalc.js +++ b/YLErpWeb/wwwroot/Scripts/app/swaptrade/unwindBondCalc.js @@ -83,10 +83,14 @@ /** * 计算失败落地(交互约定2):保留源字段值(用户可就地改),清对方字段、清全部标识。 * 与录入页差异:只清"对方"一个字段(录入页清另外两个)。 + * driver 非法(null/未知)时仅清标识、不动任何数值——防调用方误清源字段 + * (如 setValueDate 只想清陈旧标识时误传 null,会把 TradingAmountAvg 清掉)。 */ function applyCalcFailure(state, driver) { - var other = driver === 'DP' ? 'YD' : 'DP'; - state[FIELDS[other]] = null; + if (driver === 'DP' || driver === 'YD') { + var other = driver === 'DP' ? 'YD' : 'DP'; + state[FIELDS[other]] = null; + } state.bondDriverType = null; state.bondAuto = { DP: false, YD: false }; state.bondRev = { DP: false, YD: false }; diff --git a/YLErpWeb/wwwroot/Scripts/app/swaptrade/unwindSwapTrade.js b/YLErpWeb/wwwroot/Scripts/app/swaptrade/unwindSwapTrade.js index 1f70d833..764e9623 100644 --- a/YLErpWeb/wwwroot/Scripts/app/swaptrade/unwindSwapTrade.js +++ b/YLErpWeb/wwwroot/Scripts/app/swaptrade/unwindSwapTrade.js @@ -11,6 +11,9 @@ const formatSwapQuantity = value => swapPricePrecision.normalizeCommon('quantity const inputFormatMarginRate = Object.freeze({ precision: otcformat.trading.marginRateP.precision, append: '%' }); const inputFormatMarginRateNoPercent = Object.freeze({ precision: otcformat.trading.umpriceP.precision, append: '', percent: true }); const inputFormatSwapDeliveryPrice = Object.freeze({ precision: 9, append: '', negative: true }); +// EQD-6953 期末标的结算收益率(ExitYtm):展示态百分数(如 6.3721),trimTailZeros:false 不去零; +// 精度由 getInputFormat('yield') 规则给 4 位——不得低于结算确认书导出的固定 4 位(0.0000)。 +const inputFormatUnwindExitYtm = Object.freeze({ append: '', negative: true, trimTailZeros: false }); const consPosiFeeType = Object.freeze({ Percent: 0, Unit: 1 }); const swapPosiFeeCalc = { normalizeFeeType(feeType) { @@ -61,6 +64,8 @@ const vue = new Vue({ marginList: [], initPosiNetPrice: 0, multiplier: 1, + // EQD-6953 簿记模板=普通债券类收益互换 时启用 期末交割全价↔结算收益率(ExitYtm) 互算 + isBondTRS: false, // 平仓比例展示/输入均为"占期初(original)"语义(A):默认与每次重开都基于原始名义本金。 // oriClosePercent = 剩余名义本金/期初名义本金 = 最多可平比例(不能平超过剩余持仓)。 oriClosePercent: 1, @@ -73,10 +78,15 @@ const vue = new Vue({ }, minStartDate() { return this.deal.StartDate; + }, + // EQD-6953:簿记模板为普通债券类收益互换 且 浮动腿标的为债券 时,才展示 源/AUTO/REV 标识并允许互算 + isBondUnwindLeg() { + return this.isBondTRS && !!this.floatPosition && this.IsBond(this.floatPosition.UnderlyingInstrumentType); } }, created() { - this.multiplier = this.deal.StructureType == '普通债券类收益互换' ? 100 : 1; + this.isBondTRS = this.deal.StructureType == '普通债券类收益互换'; + this.multiplier = this.isBondTRS ? 100 : 1; this.initDeal(); this.setValueDate(this.deal.ValueDate); }, @@ -151,6 +161,10 @@ const vue = new Vue({ this.floatPosition.TradingAmountAvg, this.floatPosition.UnderlyingInstrumentType, 'grossPrice'); + // EQD-6953 期末结算收益率:提交前统一 4 位四舍五入(幂等;空/非数保持原样不覆盖) + if (UnwindBondCalc.hasValue(this.floatPosition.ExitYtm)) { + this.floatPosition.ExitYtm = UnwindBondCalc.roundExitYtm(this.floatPosition.ExitYtm); + } this.floatPosition.TradingFee = formatSwapAmount(this.floatPosition.TradingFee); this.floatPosition.TradingFeePending = formatSwapAmount(this.floatPosition.TradingFeePending); this.floatPosition.DividendIn = formatSwapAmount(this.floatPosition.DividendIn); @@ -174,6 +188,14 @@ const vue = new Vue({ this.deal.UnwindDate = e; this.floatPosition.UnwindDate = e; } + // EQD-6953 估值日(平仓日)变了,已算出的期末结算收益率随之失效:清值+清标识,待用户重新回车计算 + // (applyManualEdit(null) 只清 源/AUTO/REV 不动任何数值;勿用 applyCalcFailure(null)—— + // 它对 null driver 会误清 TradingAmountAvg) + if (this.isBondUnwindLeg && this.floatPosition.ExitYtm != null) { + this.floatPosition.ExitYtm = null; + UnwindBondCalc.applyManualEdit(this.floatPosition, null); + this.syncUnwindBondFlags(); + } if (!isUseApproval) { this.getInterestList(); //this.refreshUnderlyingPrice(); @@ -299,6 +321,107 @@ const vue = new Vue({ thisObj.calcFloatClosePnl(); }); }, + //================================================================================== + // EQD-6953 期末标的交割全价 ↔ 期末标的结算收益率(ExitYtm) 互算 + // 交互对齐录入页(swapTradeEdit.js):回车=以该字段为源调 /Bond/CalcBond 反算对方; + // 失败=保留源字段、清对方、标识全清;手填未回车=REV 不联动(允许计算有问题时手工覆盖)。 + // 关键差异见 unwindBondCalc.js 头注:平仓页两字段均为展示态(不 ×100/÷100),估值日=平仓日 ValueDate。 + //================================================================================== + getYieldInputFormat() { + return swapPricePrecision.getInputFormat( + this.floatPosition && this.floatPosition.UnderlyingInstrumentType, + 'yield', + inputFormatUnwindExitYtm); + }, + //期末交割全价的 input(失焦/回车都会触发):保持既有盈亏联动;债券腿按交互约定3标 REV。 + onEndDeliveryPriceInput() { + this.changeUnderlyingPrice(); + if (this.isBondUnwindLeg) { + UnwindBondCalc.applyManualEdit(this.floatPosition, 'DP'); + this.syncUnwindBondFlags(); + } + }, + //收益率字段编辑(失焦/回车触发,组件内部回车时 enter 随后修正标识):约定3 标 REV 不联动。 + onEndBondPriceEdit(type) { + if (!this.isBondUnwindLeg) return; + UnwindBondCalc.applyManualEdit(this.floatPosition, type); + this.syncUnwindBondFlags(); + }, + //按键实时标 REV(组件 input 事件只在失焦/回车触发,逐键输入期间靠 keydown 清 源/AUTO)。 + //回车/修饰键/导航键/功能键不改标识(SwapCalc.isBondPriceValueKey 白名单)。 + onEndBondPriceKeydown(type, event) { + if (!this.isBondUnwindLeg) return; + if (!SwapCalc.isBondPriceValueKey(event)) return; + UnwindBondCalc.applyManualEdit(this.floatPosition, type); + this.syncUnwindBondFlags(); + }, + //回车=以该字段为源调计算器反算对方字段。 + onEndBondPriceEnter(type) { // type: 'DP'期末交割全价 / 'YD'期末结算收益率 + if (!this.isBondUnwindLeg) return; + if (!this.floatPosition.UnderlyingCode) { main.message("请先选择债券标的"); return; } + var price = type === 'DP' ? this.floatPosition.TradingAmountAvg : this.floatPosition.ExitYtm; + if (!UnwindBondCalc.hasValue(price)) return; // 空/非数:不触发计算器 + this.calcUnwindBond(type); + }, + //以 driver(回车字段)为源调 /Bond/CalcBond。成败路由见 base/main.js __post:业务错误走 reject, + //失败落地必须在 .fail(录入页曾把失败处理只写 .done 导致静默失效,勿重蹈)。 + calcUnwindBond(driver) { + if (!this.isBondUnwindLeg) return; + var fp = this.floatPosition; + fp.bondDriverType = driver; // 先定源,回写时 applyCalcResult 会跳过该字段 + var price = driver === 'DP' ? fp.TradingAmountAvg : fp.ExitYtm; + if (!UnwindBondCalc.hasValue(price)) { + UnwindBondCalc.applyCalcFailure(fp, driver); + this.syncUnwindBondFlags(); + return; + } + if (!this.deal.ValueDate) { + main.message("请先填写平仓日期(作为债券计算器估值日)"); + UnwindBondCalc.applyCalcFailure(fp, driver); + this.syncUnwindBondFlags(); + return; + } + var req = UnwindBondCalc.getCalcRequest(fp.UnderlyingCode, price, driver, this.deal.ValueDate); + otcDebug.log('[unwindBondCalc] enter driver=' + driver + ' req=' + JSON.stringify(req)); + var self = this; + main.post('/Bond/CalcBond', req, { alertFn: main.message }).done(function (resp) { + if (!resp || !resp.obj) { // 网络错误/响应异常:框架已提示,按约定2清对方字段+标识 + UnwindBondCalc.applyCalcFailure(fp, driver); + self.syncUnwindBondFlags(); + return; + } + var err = SwapCalc.getBondCalcErrorMessage(resp.obj); + if (err) { // 业务错误(债券不存在/信息不全/参数非法/值域离谱):toast 去重提示,不回写 + if (SwapCalc.shouldShowBondErr(fp, err)) main.message(err); + UnwindBondCalc.applyCalcFailure(fp, driver); + self.syncUnwindBondFlags(); + otcDebug.log('[unwindBondCalc] calc-error driver=' + driver + ' msg=' + err); + return; + } + fp._lastBondErr = null; + UnwindBondCalc.applyCalcResult(fp, resp.obj, driver); + UnwindBondCalc.applyCalcSuccess(fp, driver); + self.syncUnwindBondFlags(); + // YD 为源时 TradingAmountAvg 被反算回填,直接赋值不触发 input 事件,须显式重算盈亏 + if (driver === 'YD') self.calcFloatClosePnl(); + otcDebug.log('[unwindBondCalc] success driver=' + driver + + ' ExitYtm=' + fp.ExitYtm + ' TradingAmountAvg=' + fp.TradingAmountAvg + + ' auto=' + JSON.stringify(fp.bondAuto)); + }).fail(function () { + UnwindBondCalc.applyCalcFailure(fp, driver); + self.syncUnwindBondFlags(); + otcDebug.log('[unwindBondCalc] post-fail/reject driver=' + driver); + }); + }, + //确保 bondDriverType/bondAuto/bondRev 的变更触发 Vue 2 响应式更新(同录入页 syncBondFlags: + //这些属性不在后端模型里,$set + 全新对象引用 + $forceUpdate 兜底,缺一视图不刷新)。 + syncUnwindBondFlags() { + var fp = this.floatPosition; + this.$set(fp, 'bondDriverType', fp.bondDriverType === undefined ? null : fp.bondDriverType); + this.$set(fp, 'bondAuto', { DP: !!(fp.bondAuto && fp.bondAuto.DP), YD: !!(fp.bondAuto && fp.bondAuto.YD) }); + this.$set(fp, 'bondRev', { DP: !!(fp.bondRev && fp.bondRev.DP), YD: !!(fp.bondRev && fp.bondRev.YD) }); + this.$forceUpdate(); + }, calcFloatClosePnl() {//计算浮动端平仓盈亏 var thisObj = this; let floatRatio = thisObj.floatPosition.PayDirection == 1 ? 1 : -1; From fb9cf9eadd16eda40315cb0f5dfba20c743ffbc4 Mon Sep 17 00:00:00 2001 From: hjhan Date: Thu, 20 Aug 2026 17:41:41 +0800 Subject: [PATCH 05/16] =?UTF-8?q?feat(web):=20EQD-6953=20BondController?= =?UTF-8?q?=E8=AE=A1=E7=AE=97=E5=99=A8=E8=B0=83=E7=94=A8=E8=A1=A5source?= =?UTF-8?q?=E5=9C=BA=E6=99=AF=E6=97=A5=E5=BF=97=E2=80=94=E2=80=94=E5=B9=B3?= =?UTF-8?q?=E4=BB=93=E9=A1=B5=E8=AF=B7=E6=B1=82=E5=B8=A6source=3Dunwind(?= =?UTF-8?q?=E5=8F=AF=E9=80=89=E5=8F=82=E6=95=B0=E5=90=91=E5=90=8E=E5=85=BC?= =?UTF-8?q?=E5=AE=B9,=E5=BD=95=E5=85=A5=E9=A1=B5=E4=B8=8D=E4=BC=A0)?= =?UTF-8?q?=EF=BC=9BBondCalcHepler=E6=9C=AC=E5=B0=B1=E8=AE=B0=E5=BD=95?= =?UTF-8?q?=E5=AE=8C=E6=95=B4=E5=8F=82=E6=95=B0/=E7=BB=93=E6=9E=9C/?= =?UTF-8?q?=E5=A4=B1=E8=B4=A5=E5=8E=9F=E5=9B=A0,=E8=A1=A5=E5=9C=BA?= =?UTF-8?q?=E6=99=AF=E7=BB=B4=E5=BA=A6=E5=8D=B3=E5=8F=AF=E5=8C=BA=E5=88=86?= =?UTF-8?q?=E5=85=A5=E5=8F=A3=E5=AE=9A=E4=BD=8D=E6=98=AF=E5=8F=82=E6=95=B0?= =?UTF-8?q?=E8=BF=98=E6=98=AF=E5=88=AB=E7=9A=84=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- YLErpWeb/Controllers/BondController.cs | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/YLErpWeb/Controllers/BondController.cs b/YLErpWeb/Controllers/BondController.cs index 36ef4f85..9a367b76 100644 --- a/YLErpWeb/Controllers/BondController.cs +++ b/YLErpWeb/Controllers/BondController.cs @@ -7,8 +7,12 @@ namespace YLErp.Web.Controllers { [AllowAnonymous] - public JsonResult CalcBond(string underlyingCode, decimal price, string priceType, string targetDate = null) + public JsonResult CalcBond(string underlyingCode, decimal price, string priceType, string targetDate = null, string source = null) { + // EQD-6953:source 标记调用场景(unwind=平仓页;录入页不传)。BondCalcHepler 已记录 + // 完整请求参数与成败结果,此处仅补场景维度,定位问题时先按 source 区分入口再看参数。 + LogFactory.GetLogger("BondController").Info( + $"CalcBond source={source ?? "(未标记)"} underlyingCode={underlyingCode} price={price} priceType={priceType} targetDate={targetDate ?? "(空→代理默认T+1)"}"); string errorMsg; var obj = BondCalcHepler.BondCalc(underlyingCode, price, priceType, out errorMsg, targetDate); if (obj == null) From a5a78eab100a02dde5615ed3cd9dcb4d82be8330 Mon Sep 17 00:00:00 2001 From: hjhan Date: Thu, 20 Aug 2026 18:14:40 +0800 Subject: [PATCH 06/16] =?UTF-8?q?feat(swap):=20EQD-5320=20=E7=BB=93?= =?UTF-8?q?=E7=AE=97=E7=A1=AE=E8=AE=A4=E4=B9=A6=E9=82=AE=E4=BB=B6=E9=93=BE?= =?UTF-8?q?=E8=B7=AF=E8=A1=A5=E5=AE=9A=E4=BD=8D=E6=97=A5=E5=BF=97=E2=80=94?= =?UTF-8?q?=E2=80=94=E8=B5=84=E9=87=91=E6=8F=90=E7=A4=BA/=E7=BB=93?= =?UTF-8?q?=E6=B8=85=E7=A1=AE=E8=AE=A4/=E7=94=9F=E6=88=90=E4=B8=89?= =?UTF-8?q?=E6=9D=A1=E9=93=BE=E8=B7=AF=E6=AD=A4=E5=89=8D=E5=87=A0=E4=B9=8E?= =?UTF-8?q?=E6=97=A0=E6=97=A5=E5=BF=97=E4=B8=94=E5=AD=98=E5=9C=A8=E9=9D=99?= =?UTF-8?q?=E9=BB=98=E5=A4=B1=E8=B4=A5:=E2=91=A0SendConfirmEamil=E6=9F=A5?= =?UTF-8?q?=E4=B8=8D=E5=88=B0=E5=90=88=E5=90=8C=E5=8E=9Freturn=E7=A9=BA?= =?UTF-8?q?=E4=B8=B2(=E5=89=8D=E7=AB=AF=E5=BD=93=E5=B7=B2=E5=8F=91?= =?UTF-8?q?=E9=80=81)=E6=94=B9Error=E6=97=A5=E5=BF=97+=E6=98=8E=E7=A1=AE?= =?UTF-8?q?=E8=BF=94=E5=9B=9E=E5=8F=91=E9=80=81=E5=A4=B1=E8=B4=A5=E5=8E=9F?= =?UTF-8?q?=E5=9B=A0;=E2=91=A1CheckConfirmDoc/CheckSettlementDoc=E6=8A=9B?= =?UTF-8?q?=E9=94=99=E5=89=8D=E8=A1=A5=E6=89=93=E5=BA=93=E5=86=85trade=5Fc?= =?UTF-8?q?ontract=5Fr=E8=A1=8C=E7=8A=B6=E6=80=81(=E6=97=A0=E8=A1=8C=3D?= =?UTF-8?q?=E4=BB=8E=E6=9C=AA=E7=94=9F=E6=88=90/IsValid=3Dfalse=3D?= =?UTF-8?q?=E9=87=8D=E7=94=9F=E6=88=90=E4=BD=9C=E5=BA=9F/doc=E7=BC=BA?= =?UTF-8?q?=E5=A4=B1);=E2=91=A2DealNoDmaEmail=E4=B8=8E=E7=94=9F=E6=88=90?= =?UTF-8?q?=E6=9C=8D=E5=8A=A1=E4=B8=A4=E5=A4=84=E5=AE=A2=E6=88=B7+?= =?UTF-8?q?=E6=97=A5=E6=9C=9F=E6=89=A9=E5=BC=A0=E6=9F=A5=E8=AF=A2=E8=A1=A5?= =?UTF-8?q?Info=E6=97=A5=E5=BF=97=E5=AF=B9=E9=BD=90=E5=8B=BE=E9=80=89vs?= =?UTF-8?q?=E5=AE=9E=E9=99=85=E5=A4=84=E7=90=86;=E2=91=A3GetFileName?= =?UTF-8?q?=E7=89=A9=E7=90=86=E6=96=87=E4=BB=B6=E7=BC=BA=E5=A4=B1=E5=8E=9F?= =?UTF-8?q?=E9=9D=99=E9=BB=98null=E6=94=B9Error;=E2=91=A4=E7=94=9F?= =?UTF-8?q?=E6=88=90=E5=99=A8=E6=9C=AA=E7=94=9F=E6=88=90=E4=BA=A4=E6=98=93?= =?UTF-8?q?=E7=A1=AE=E8=AE=A4=E4=B9=A6=E6=8A=A5=E9=94=99=E8=A1=A5=E4=BA=8B?= =?UTF-8?q?=E4=BB=B6id/=E5=AE=A2=E6=88=B7/=E5=B9=B3=E4=BB=93=E6=97=A5?= =?UTF-8?q?=E4=BE=BF=E4=BA=8E=E5=85=B3=E8=81=94=E6=89=A9=E5=BC=A0=E6=97=A5?= =?UTF-8?q?=E5=BF=97;IYcLogger=E6=97=A0Warn=E7=BB=9F=E4=B8=80=E7=94=A8Erro?= =?UTF-8?q?r?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../TradeSettleBillGenerator.cs | 4 +- .../SwapModule/SwapEndConfirmService.cs | 10 +++- .../SwapModule/SwapEventEmailService.cs | 46 ++++++++++++++++++- .../SwapSettlementBillGenerateService.cs | 6 +++ 4 files changed, 63 insertions(+), 3 deletions(-) diff --git a/Plugins/YLErp.Plugins.GuoLian/DocumentGenerator/TradeSettleBillGenerator.cs b/Plugins/YLErp.Plugins.GuoLian/DocumentGenerator/TradeSettleBillGenerator.cs index e78f361b..adbb66b5 100644 --- a/Plugins/YLErp.Plugins.GuoLian/DocumentGenerator/TradeSettleBillGenerator.cs +++ b/Plugins/YLErp.Plugins.GuoLian/DocumentGenerator/TradeSettleBillGenerator.cs @@ -48,7 +48,9 @@ namespace YLErp.Plugins.GuoLian.DocumentGenerator var confirmNo = Context.Gettrade_contract_r(tradeId, ContractTypeEnum.Trade); if (string.IsNullOrEmpty(confirmNo)) { - throw new ServiceException($"{trade.TradeNumber}未生成交易确认书"); + // 定位要点:带上事件id便于与 SwapSettlementBillGenerateService 的"生成范围扩张日志"对齐—— + // 报错交易常是扩张拉入的同客户同日平仓,并非用户勾选的那笔。 + throw new ServiceException($"{trade.TradeNumber}未生成交易确认书(平仓事件id={flowEventGroup.id}, tradeId={tradeId}, 客户={client.Name}, 平仓日={flowEventGroup.UnwindDate?.ToString("yyyy-MM-dd")});请先为该笔交易生成交易确认书后重试"); } row.TradeNumber = confirmNo; row.ClientName = client.Name; diff --git a/YLErpDAL/Modules/SwapModule/SwapEndConfirmService.cs b/YLErpDAL/Modules/SwapModule/SwapEndConfirmService.cs index c8786ab1..05c0ec86 100644 --- a/YLErpDAL/Modules/SwapModule/SwapEndConfirmService.cs +++ b/YLErpDAL/Modules/SwapModule/SwapEndConfirmService.cs @@ -175,7 +175,15 @@ namespace YLErp.Modules.SwapModule var tradeContract = DbContext.trade_contract_r.Where(x => x.IsValid && x.TradeId == tradeId && x.Type == ContractTypeEnum.Trade).FirstOrDefault(); if (tradeContract == null) { - return ""; + // 定位要点:此处历史上静默 return "",前端当"已发送"但实际未发任何邮件。 + // 打出 warn 并把失败原因透传给前端,便于区分"没生成过交易确认书"与"被重生成作废(IsValid=false)"。 + var rows = DbContext.trade_contract_r.Where(x => x.TradeId == tradeId).Select(x => new { x.Type, x.IsValid, x.ContractCode }).ToList(); + var detail = rows.Any() + ? string.Join(";", rows.Select(r => $"Type={r.Type},IsValid={r.IsValid},Code={r.ContractCode}")) + : "trade_contract_r 无任何行"; + LogFactory.GetLogger("SwapEndConfirm").Error( + $"发送交易确认书邮件中止: tradeId={tradeId} 无有效交易确认书(需 IsValid=true 且 Type={ContractTypeEnum.Trade}); 库内实际行: {detail}"); + return "发送失败:未找到有效交易确认书,请先生成后再发送"; } tradeContract.send_email_result = "发送中"; DbContext.SaveChanges(); diff --git a/YLErpDAL/Modules/SwapModule/SwapEventEmailService.cs b/YLErpDAL/Modules/SwapModule/SwapEventEmailService.cs index a6bad2cc..f6a8e720 100644 --- a/YLErpDAL/Modules/SwapModule/SwapEventEmailService.cs +++ b/YLErpDAL/Modules/SwapModule/SwapEventEmailService.cs @@ -164,6 +164,12 @@ namespace YLErp.Modules.SwapModule && f.UnwindDate == valueDate && f.PayDirection > 0 && eventTypes.Contains(f.EventType) && f.DataState == (int)SwapFlowDateStateEnum.完成 select f; var flowEventList = flowQuery.ToList(); + // 定位要点:发送范围按【客户+日期】整组扩张——用户勾选 A 事件,同客户同日的 B/C 事件会被一并拉入, + // 后续校验报错常是被拉入的事件缺确认书(用户以为"刚生成了还报错")。此日志把勾选与扩张结果对齐打出来。 + LogFactory.GetLogger("SwapEventEmail").Info( + $"资金提示邮件-发送范围: 用户勾选事件[{string.Join(",", EventEmailEmails.Select(s => s.event_id))}] " + + $"客户[{string.Join(",", clientIds.Distinct())}] 日期[{valueDate:yyyy-MM-dd}] " + + $"扩张后实际处理事件[{string.Join(",", flowEventList.Select(f => $"{f.id}:{f.SwapTradeNo}:" + (f.EventType == (int)SwapFlowEventTypeEnum.开仓 ? "开仓" : f.EventType == (int)SwapFlowEventTypeEnum.平仓 ? "平仓" : "T" + f.EventType)))}]"); var docs = new List(); var openFlowEventList = flowEventList.Where(x => x.EventType == (int)SwapFlowEventTypeEnum.开仓).ToList(); var closeFlowEventList = flowEventList.Where(x => x.EventType == (int)SwapFlowEventTypeEnum.平仓).ToList(); @@ -216,6 +222,22 @@ namespace YLErp.Modules.SwapModule } if (tradeNumbers.Any()) { + // 定位要点:报错只带交易编号不够定位。补打每笔缺失交易的 trade_contract_r 实际行状态 + //(无行=从未生成 / IsValid=false=被重生成作废 / document 行缺失=确认书文档被清理),命中哪种一眼可辨。 + var missTradeIds = flowEvents.Where(w => tradeNumbers.Contains(w.SwapTradeNo)).Select(s => s.SwapTradeId).Distinct().ToList(); + var missRows = DbContext.trade_contract_r.Where(x => missTradeIds.Contains(x.TradeId)).ToList(); + var missCodes = missRows.Select(r => r.ContractCode).Distinct().ToList(); + var docCodes = DbContext.trade_contract_document.Where(d => missCodes.Contains(d.Code)).Select(d => d.Code).Distinct().ToList(); + var detail = string.Join(";", missTradeIds.Select(tid => + { + var tradeNo = flowEvents.First(f => f.SwapTradeId == tid).SwapTradeNo; + var rows = missRows.Where(x => x.TradeId == tid).ToList(); + if (!rows.Any()) return $"{tradeNo}: trade_contract_r 无任何行(从未生成交易确认书)"; + return $"{tradeNo}: " + string.Join(",", rows.Select(r => + $"[Type={r.Type},IsValid={r.IsValid},Code={r.ContractCode},doc存在={(docCodes.Contains(r.ContractCode) ? "是" : "否")}]")); + })); + LogFactory.GetLogger("SwapEventEmail").Error( + $"交易确认书校验失败: 交易编号[{string.Join(",", tradeNumbers.Distinct())}]找不到有效交易确认书; 库内明细: {detail}"); throw new Exception($"交易编号为{string.Join(",", tradeNumbers.Distinct())}找不到有效的交易确认书附件,请检查或生成后再发送邮件"); } return list; @@ -265,6 +287,24 @@ namespace YLErp.Modules.SwapModule } if (tradeNumbers.Any()) { + // 定位要点:结算确认书按 SwapFlowEventId 精确匹配。补打每笔缺失平仓事件的合同行状态—— + // 常见原因是生成时的扩张查询覆盖了本事件但用户实际生成的是另一批,或重生成后 IsValid 被作废。 + var missEventIds = flowEvents.Where(w => tradeNumbers.Contains(w.SwapTradeNo)).Select(s => s.id).Distinct().ToList(); + var missRows = DbContext.trade_contract_r.Where(x => missEventIds.Contains(x.SwapFlowEventId ?? 0)).ToList(); + var missTradeIds = flowEvents.Where(w => tradeNumbers.Contains(w.SwapTradeNo)).Select(s => s.SwapTradeId).Distinct().ToList(); + var tradeTypeRows = DbContext.trade_contract_r.Where(x => missTradeIds.Contains(x.TradeId) && x.Type == ContractTypeEnum.Clearing).ToList(); + var detail = string.Join(";", flowEvents.Where(w => tradeNumbers.Contains(w.SwapTradeNo)).GroupBy(g => g.SwapTradeNo).Select(g => + { + var rows = missRows.Where(x => x.SwapFlowEventId == g.First().id).ToList(); + var byTrade = tradeTypeRows.Where(x => x.TradeId == g.First().SwapTradeId).ToList(); + return $"{g.Key}(事件{g.First().id}): " + (rows.Any() + ? string.Join(",", rows.Select(r => $"[Type={r.Type},IsValid={r.IsValid},Code={r.ContractCode}]")) + : $"按事件无行; 按交易的Clearing行=" + (byTrade.Any() + ? string.Join(",", byTrade.Select(r => $"[SwapFlowEventId={r.SwapFlowEventId},IsValid={r.IsValid},Code={r.ContractCode}]")) + : "无")); + })); + LogFactory.GetLogger("SwapEventEmail").Error( + $"结算确认书校验失败: 交易编号[{string.Join(",", tradeNumbers.Distinct())}]找不到有效结算确认书(SwapFlowEventId匹配); 库内明细: {detail}"); throw new Exception($"交易编号为{string.Join(",", tradeNumbers.Distinct())}找不到有效的结算确认书附件,请检查或生成后再发送邮件"); } return list; @@ -764,7 +804,11 @@ namespace YLErp.Modules.SwapModule if (System.IO.File.Exists(fName)) { return fName; } else - { return null; } + { + // 定位要点:物理文件缺失历史上静默返回 null(附件列表混入 null,发送结果不可预期),补 warn 便于发现"库里行在、盘上文件丢"。 + LogFactory.GetLogger("SwapEventEmail").Error($"邮件附件物理文件缺失: trade_contract_document.Paths={baseName} 映射后={fName} 不存在"); + return null; + } } } } diff --git a/YLErpDAL/Modules/TradeModule/DocGenerateModule/SwapSettlementBillGenerateService.cs b/YLErpDAL/Modules/TradeModule/DocGenerateModule/SwapSettlementBillGenerateService.cs index 2a66f0a8..26b32983 100644 --- a/YLErpDAL/Modules/TradeModule/DocGenerateModule/SwapSettlementBillGenerateService.cs +++ b/YLErpDAL/Modules/TradeModule/DocGenerateModule/SwapSettlementBillGenerateService.cs @@ -53,6 +53,12 @@ namespace YLErp.Modules.TradeModule.DocGenerateModule var allFlowEvents = DbContext.swap_flow_event.Where(x => eventIds.Contains(x.EventId)).ToList(); var tradeContracts = DbContext.trade_contract_r.Where(x=> tradeIds.Contains(x.TradeId)&&x.Type== ContractTypeEnum.Clearing&&x.IsValid).ToList(); flowEvents = newFlowEvents.ToList(); + // 定位要点:生成范围按【客户+平仓日】扩张——传入的是用户勾选的 flowEventIds, + // 实际生成会包含同客户同日全部平仓流水(PositionType>0)。若某笔交易未生成过交易确认书, + // TradeSettleBillGenerator 会整批抛"XX未生成交易确认书",此日志用于对齐"勾选了什么 vs 实际生成什么"。 + LogFactory.GetLogger("GenerateSingleV2").Info( + $"生成结算确认书-生成范围: 传入flowEventIds[{string.Join(",", flowEventIds)}] " + + $"扩张后待生成[{string.Join(",", flowEvents.Select(f => $"{f.id}:{f.SwapTradeNo}"))}]"); //---------------------------------- // 交易确认书数据 //---------------------------------- From 3728d45cc40d8863b93068239d46312a299dca85 Mon Sep 17 00:00:00 2001 From: hjhan Date: Fri, 21 Aug 2026 07:09:51 +0800 Subject: [PATCH 07/16] =?UTF-8?q?test(web):=20swapPricePrecisionHelper?= =?UTF-8?q?=E8=A1=A519=E4=BE=8B=E7=89=B9=E5=BE=81=E6=B5=8B=E8=AF=95?= =?UTF-8?q?=E5=86=BB=E7=BB=93=E5=AD=97=E7=AC=A6=E4=B8=B2=E7=B2=BE=E7=A1=AE?= =?UTF-8?q?=E5=8D=81=E8=BF=9B=E5=88=B6=E6=A0=B8=E5=BF=83=E2=80=94=E2=80=94?= =?UTF-8?q?shiftDecimal/roundDecimal/multiplyDecimal/getRule/roundForSubmi?= =?UTF-8?q?t/format=E5=85=A8golden=E5=80=BC=E6=96=AD=E8=A8=80(0.1=C3=970.2?= =?UTF-8?q?=E7=B2=BE=E7=A1=AE0.02=E3=80=811.005=E2=86=921.01=E7=BB=95?= =?UTF-8?q?=E5=BC=80=E6=B5=AE=E7=82=B9=E9=99=B7=E9=98=B1=E3=80=81roundDeci?= =?UTF-8?q?mal=E7=BB=9D=E5=AF=B9=E5=80=BC=E5=9B=9B=E8=88=8D=E4=BA=94?= =?UTF-8?q?=E5=85=A5=E4=B8=8EExitYtm=E7=BA=A6=E5=AE=9A=E5=90=8C=E5=90=91?= =?UTF-8?q?=E3=80=81=E4=B9=98=E6=B3=95=E4=BF=9D=E7=95=99=E5=B0=8F=E6=95=B0?= =?UTF-8?q?=E6=A0=87=E5=BA=A61.5=C3=972=3D3.0=E3=80=81Bond=E5=AD=97?= =?UTF-8?q?=E6=AE=B5=E6=8B=BC=E9=94=99=E2=86=92null=E5=9B=9E=E8=90=BDumpri?= =?UTF-8?q?ce=E8=80=8CStock=E5=9B=9E=E8=90=BD=E5=93=81=E7=A7=8D=E7=BA=A7?= =?UTF-8?q?=E7=9A=84=E4=B8=8D=E5=AF=B9=E7=A7=B0=E5=86=BB=E7=BB=93)?= =?UTF-8?q?=EF=BC=9Brequire=E7=9B=B4=E8=BF=9E=E5=8A=A0=E8=BD=BD=E6=9B=BF?= =?UTF-8?q?=E4=BB=A3readFileSync=E6=B2=99=E7=AE=B1(=E5=8F=AF=E8=A2=AB?= =?UTF-8?q?=E6=8F=92=E6=A1=A9)=EF=BC=9B=E8=A6=86=E7=9B=96=E7=8E=87?= =?UTF-8?q?=E6=B8=85=E5=8D=95=E7=BA=B3=E5=85=A5=E8=AF=A5=E6=96=87=E4=BB=B6?= =?UTF-8?q?=EF=BC=9B=E5=AE=9E=E9=94=A4=E6=B3=A8=E9=87=8A:=E6=BA=90?= =?UTF-8?q?=E7=A0=81=E5=9C=A8rootDir=E5=A4=96=E8=87=B4babel(=E6=97=A0trans?= =?UTF-8?q?former)=E4=B8=8Ev8(=E9=80=83=E9=80=B8=E8=B7=AF=E5=BE=84?= =?UTF-8?q?=E6=97=A0=E6=B3=95=E5=BD=92=E5=9B=A0,=E5=90=ABroots/=E7=BB=9D?= =?UTF-8?q?=E5=AF=B9=E8=B7=AF=E5=BE=84=E5=8F=98=E4=BD=93=E5=AE=9E=E6=B5=8B?= =?UTF-8?q?jest29.7)=E4=B8=A4=E6=8F=90=E4=BE=9B=E5=99=A8=E8=A6=86=E7=9B=96?= =?UTF-8?q?=E7=8E=87=E6=81=920=E4=B8=94=E9=97=A8=E6=A7=9B=E4=B8=8D?= =?UTF-8?q?=E8=A7=A6=E5=8F=91,=E7=9C=9F=E4=BF=AE=E9=9C=80=E9=87=8D?= =?UTF-8?q?=E6=9E=84rootDir=E5=8F=A6=E8=A1=8C=E7=AB=8B=E9=A1=B9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- YLErpWeb/fe-tests/jest.config.js | 4 + .../fe-tests/swapPricePrecisionHelper.test.js | 178 ++++++++++++++++++ 2 files changed, 182 insertions(+) create mode 100644 YLErpWeb/fe-tests/swapPricePrecisionHelper.test.js diff --git a/YLErpWeb/fe-tests/jest.config.js b/YLErpWeb/fe-tests/jest.config.js index b06bd582..f6877998 100644 --- a/YLErpWeb/fe-tests/jest.config.js +++ b/YLErpWeb/fe-tests/jest.config.js @@ -23,9 +23,13 @@ module.exports = { moduleDirectories: ['node_modules', '../wwwroot/Scripts'], // 覆盖率配置(--coverage 时生效) + // 已知问题:源码在 rootDir(fe-tests) 之外,babel 提供器因 transform:{} 无插桩器、 + // v8 提供器对 rootDir 逃逸路径无法归因(jest 29.7 实测,含 roots/绝对路径变体), + // 覆盖率表恒为 0 且门槛不触发。清单仍保留以固化意图,真实修复需重构 rootDir。 collectCoverageFrom: [ '../wwwroot/Scripts/app/swaptrade/swapCalc.js', '../wwwroot/Scripts/app/swaptrade/unwindBondCalc.js', + '../wwwroot/Scripts/app/swaptrade/swapPricePrecisionHelper.js', '../wwwroot/Scripts/fast/fastVue.base.js', // 逐步加入更多文件 ], diff --git a/YLErpWeb/fe-tests/swapPricePrecisionHelper.test.js b/YLErpWeb/fe-tests/swapPricePrecisionHelper.test.js new file mode 100644 index 00000000..d30ae970 --- /dev/null +++ b/YLErpWeb/fe-tests/swapPricePrecisionHelper.test.js @@ -0,0 +1,178 @@ +/** + * swapPricePrecisionHelper.test.js — 字符串精确十进制核心的特征测试 + * ============================================================================ + * 目的:swapPricePrecisionHelper.js 的组件事件(swapPriceInput.component.test.js)与 + * 配置接线(swapPrecisionConfig.test.js)已有测试,但【字符串精确十进制核心】 + * (shiftDecimal / roundDecimal / multiplyDecimal / getRule / format / + * roundForSubmit) 一直只有间接覆盖。精度即资损,这里用 golden 值冻结现状: + * 1. 全部走字符串数位运算,绕开 IEEE754 浮点陷阱(0.1*0.2、1.005.toFixed); + * 2. roundDecimal 是【绝对值上四舍五入】= AwayFromZero,与 unwindBondCalc + * 的 ExitYtm 约定同向; + * 3. roundDecimal 不补零(1.2 → '1.2'),补零是 formatCommon/formatFixed 的职责; + * 4. roundDecimal 对非法输入/负精度【原样返回不归一】,调用方别拿它当校验器; + * 5. getRule 的覆盖优先级:先查 defaults 有无该品种(没有直接 null),再看 + * main.swapPricePrecision 覆盖,覆盖非法则回落 defaults。 + * + * 做法:直接 require 源文件(jest v8 覆盖率据此插桩,readFileSync+new Function + * 的沙箱加载会让覆盖率统计看不见);配置覆盖用 global.main.swapPricePrecision + * 注入——模块内 global 绑定到 globalThis,与本测试文件的 global 同源, + * beforeEach/afterEach 清理防串扰。 + * + * 运行:cd YLErpWeb/fe-tests && npx jest swapPricePrecisionHelper + */ +const helper = require('../wwwroot/Scripts/app/swaptrade/swapPricePrecisionHelper.js'); + +function withConfig(config, extras) { + if (config !== undefined) global.main = { swapPricePrecision: config }; + if (extras && extras.otcformat) global.otcformat = extras.otcformat; +} + +beforeEach(() => { delete global.main; delete global.otcformat; }); +afterEach(() => { delete global.main; delete global.otcformat; }); + +describe('shiftDecimal:纯数位平移,不经浮点', () => { + + test('右移补零 / 左移进小数', () => { + expect(helper.shiftDecimal('1.5', 1)).toBe('15'); + expect(helper.shiftDecimal('1.5', -1)).toBe('0.15'); + expect(helper.shiftDecimal('12.34', -3)).toBe('0.01234'); + expect(helper.shiftDecimal('0.001', -2)).toBe('0.00001'); + expect(helper.shiftDecimal('5', 2)).toBe('500'); + }); + + test('保留符号;places=0 或非整数只做归一化', () => { + expect(helper.shiftDecimal('-1.5', 1)).toBe('-15'); + expect(helper.shiftDecimal('1.50', 0)).toBe('1.50'); // 不动尾巴零 + expect(helper.shiftDecimal('1.50', 1.5)).toBe('1.50'); + }); + + test('归一化先行:首尾零/符号/科学计数法', () => { + expect(helper.shiftDecimal('007.50', 0)).toBe('7.50'); + expect(helper.shiftDecimal('+7', 0)).toBe('7'); + expect(helper.shiftDecimal('-0.000', 0)).toBe('0.000'); // 负零坍缩为无符号 + expect(helper.shiftDecimal('1e-7', 0)).toBe('0.0000001'); + expect(helper.shiftDecimal('1.23e5', 0)).toBe('123000'); + }); + + test('非法输入返回 null,空白串返回空串', () => { + expect(helper.shiftDecimal('abc', 2)).toBeNull(); + expect(helper.shiftDecimal('1.2.3', 2)).toBeNull(); + expect(helper.shiftDecimal('', 2)).toBe(''); + }); +}); + +describe('roundDecimal:绝对值四舍五入(AwayFromZero),字符串路径无浮点陷阱', () => { + + test('经典浮点陷阱对照:1.005 与 0.1×0.2 场景字符串路径给正确答案', () => { + expect(Number(1.005).toFixed(2)).toBe('1.00'); // 浮点路径错(冻结对照) + expect(helper.roundDecimal('1.005', 2)).toBe('1.01'); + expect(helper.roundDecimal('2.345', 2)).toBe('2.35'); + expect(helper.roundDecimal('2.344', 2)).toBe('2.34'); + }); + + test('负数远离零(与 ExitYtm 约定同向)', () => { + expect(helper.roundDecimal('-2.345', 2)).toBe('-2.35'); + expect(helper.roundDecimal('-2.5', 0)).toBe('-3'); + expect(helper.roundDecimal('-0.00005', 4)).toBe('-0.0001'); + }); + + test('进位链:跨数量级与跨整数位', () => { + expect(helper.roundDecimal('9.99', 1)).toBe('10.0'); + expect(helper.roundDecimal('9.99', 0)).toBe('10'); + expect(helper.roundDecimal('99.999', 2)).toBe('100.00'); + expect(helper.roundDecimal('0.00005', 4)).toBe('0.0001'); + }); + + test('不补零也不主动去零:位数不足原样返回,已有位数保留尾巴零', () => { + expect(helper.roundDecimal('1.2', 4)).toBe('1.2'); // 不足4位不补零(补零是 formatCommon 的职责) + expect(helper.roundDecimal('3.10000', 4)).toBe('3.1000'); // 已到4位:只取整不去零(去零是 format 的职责) + }); + + test('防御姿态:负精度/非法输入原样返回,不做校验', () => { + expect(helper.roundDecimal('2.345', -1)).toBe('2.345'); + expect(helper.roundDecimal('2.345', 1.5)).toBe('2.345'); + expect(helper.roundDecimal('abc', 2)).toBe('abc'); + }); +}); + +describe('multiplyDecimal:字符串精确乘法', () => { + + test('0.1×0.2 精确为 0.02(浮点给 0.020000000000000004)', () => { + expect(helper.multiplyDecimal('0.1', '0.2')).toBe('0.02'); + expect(helper.multiplyDecimal('0.1', '0.1')).toBe('0.01'); + expect(helper.multiplyDecimal('1.1', '1.1')).toBe('1.21'); + }); + + test('符号组合;保留小数标度(1.5×2=3.0 而非 3)', () => { + expect(helper.multiplyDecimal('1.5', '2')).toBe('3.0'); + expect(helper.multiplyDecimal('-1.5', '2')).toBe('-3.0'); + expect(helper.multiplyDecimal('-1.5', '-2')).toBe('3.0'); + expect(helper.multiplyDecimal('-0.03', '-0.02')).toBe('0.0006'); + }); + + test('大整数精确(超出 Number.MAX_SAFE_INTEGER)', () => { + expect(helper.multiplyDecimal('123456789', '987654321')).toBe('121932631112635269'); + }); + + test('非法输入 null;空串按 0 处理', () => { + expect(helper.multiplyDecimal('abc', '1')).toBeNull(); + expect(helper.multiplyDecimal('', '1')).toBe('0'); + }); +}); + +describe('getRule / getInputFormat / roundForSubmit:字段规则解析与覆盖优先级', () => { + test('defaults 字段级规则:债券三字段 vs 股票兜底', () => { + expect(helper.getRule('Bond', 'yield')).toEqual({ integerDigits: 2, precision: 4 }); + expect(helper.getRule('Bond', 'grossPrice')).toEqual({ integerDigits: 6, precision: 9 }); + // 债券顶层没有 integerDigits/precision:字段拼错 → null(后续走 umprice 兜底), + // 而 Stock 顶层有 → 字段拼错回落品种级规则。这个不对称冻结于此。 + expect(helper.getRule('Bond', 'unknownField')).toBeNull(); + expect(helper.getRule('Stock', 'anything')).toEqual({ integerDigits: 7, precision: 2 }); + expect(helper.getRule('NoSuchType', 'yield')).toBeNull(); + }); + + test('main.swapPricePrecision 覆盖优先于 defaults,非法覆盖回落 defaults', () => { + withConfig({ Bond: { yield: { integerDigits: 3, precision: 5 } } }); + expect(helper.getRule('Bond', 'yield')).toEqual({ integerDigits: 3, precision: 5 }); + + withConfig({ Bond: { yield: { integerDigits: 0 } } }); + const bad = helper; + expect(bad.getRule('Bond', 'yield')).toEqual({ integerDigits: 2, precision: 4 }); + + // defaults 里没有的品种,配置了也不认:覆盖只允许白名单内微调 + withConfig({ BrandNewType: { yield: { integerDigits: 3, precision: 5 } } }); + const unknown = helper; + expect(unknown.getRule('BrandNewType', 'yield')).toBeNull(); + }); + + test('getInputFormat 合并 options', () => { + expect(helper.getInputFormat('Bond', 'yield', { negative: true })) + .toEqual({ negative: true, integerDigits: 2, precision: 4 }); + expect(helper.getInputFormat('NoSuchType', 'yield', { negative: true })) + .toEqual({ negative: true }); + }); + + test('roundForSubmit:按规则精度+offset 取整;空值/无规则原样返回', () => { + expect(helper.roundForSubmit('3.14159265', 'Bond', 'yield')).toBe('3.1416'); + expect(helper.roundForSubmit('3.14159265', 'Bond', 'yield', 2)).toBe('3.141593'); + expect(helper.roundForSubmit('', 'Bond', 'yield')).toBe(''); + expect(helper.roundForSubmit('1.2', 'NoSuchType', 'yield')).toBe('1.2'); + expect(helper.roundForSubmit('3.14159265', 'Bond', 'yield', 2.5)).toBe('3.1416'); // 非整数offset忽略 + }); +}); + +describe('format:字段级展示态(取整+去尾巴零)', () => { + test('按字段规则取整并去尾零', () => { + expect(helper.format('3.14159', 'Bond', 'yield')).toBe('3.1416'); + expect(helper.format('3.10000', 'Bond', 'yield')).toBe('3.1'); + expect(helper.format('99.5', 'Stock', 'whatever')).toBe('99.5'); + expect(helper.format('', 'Bond', 'yield')).toBe(''); + }); + + test('无规则时回落 otcformat.trading.umprice', () => { + withConfig(undefined, { + otcformat: { trading: { umprice: function (v) { return 'UM:' + v; } } } + }); + expect(helper.format('1.23', 'NoSuchType', 'yield')).toBe('UM:1.23'); + }); +}); From 8b66875098d21ef5728305d904c52b766c2827f2 Mon Sep 17 00:00:00 2001 From: hjhan Date: Fri, 21 Aug 2026 07:09:57 +0800 Subject: [PATCH 08/16] =?UTF-8?q?test(swap):=20EQD-6977=20=E7=BD=9A?= =?UTF-8?q?=E6=81=AF=E5=85=9C=E5=BA=95=E8=A1=A5share<1=E6=81=92=E7=AD=89?= =?UTF-8?q?=E5=BC=8F=E7=94=A8=E4=BE=8B=E2=80=94=E2=80=9450%=E5=B9=B3?= =?UTF-8?q?=E4=BB=93+=E6=97=A0preEod=E5=9C=BA=E6=99=AF=E9=92=89merger?= =?UTF-8?q?=E5=A4=8D=E5=88=BBGetInterests=E6=9C=AC=E9=87=91=E5=8F=A3?= =?UTF-8?q?=E5=BE=84=E7=9A=84=E6=8E=A5=E7=BC=9D(=E6=A0=87=E7=9A=84?= =?UTF-8?q?=E6=9C=9F=E5=88=9D=E5=85=A8=E4=BB=B7CalcNotional=3DposiNotional?= =?UTF-8?q?=C3=97closePercent=20vs=20=E9=87=8D=E6=94=BE=E5=9F=BA=E6=95=B0?= =?UTF-8?q?=E6=8C=89closePosiNotionalValue=E7=BC=A9=E6=94=BE)=EF=BC=9B?= =?UTF-8?q?=E7=8E=B0=E6=9C=89=E7=94=A8=E4=BE=8B=E5=85=A8closePercent=3D1m?= =?UTF-8?q?=EF=BC=8C=E4=B8=A4=E5=A4=84=E5=8F=A3=E5=BE=84=E8=8B=A5=E6=9C=89?= =?UTF-8?q?=E5=81=8F=E5=B7=AE=E5=9C=A8share=3D1=E4=B8=8B=E4=B8=8D=E5=8F=AF?= =?UTF-8?q?=E8=A7=81=E3=80=81share<1=E6=97=B6=E2=91=A0=E6=B7=B7=E5=85=A5?= =?UTF-8?q?=E6=9C=AC=E9=87=91=E5=B7=AE=EF=BC=9B=E5=8F=98=E5=BC=82=E9=AA=8C?= =?UTF-8?q?=E8=AF=81=EF=BC=9ACalcNotional=E4=B8=B4=E6=97=B6=E5=BF=BD?= =?UTF-8?q?=E7=95=A5closePercent=E5=94=AF=E6=AD=A4=E7=94=A8=E4=BE=8B?= =?UTF-8?q?=E7=BA=A2(1=E8=B4=A57=E8=BF=87)=E8=AF=81=E6=98=8E=E9=89=B4?= =?UTF-8?q?=E5=88=AB=E5=8A=9B=EF=BC=9BRunFee=E5=8A=A0closePercent=E5=8F=82?= =?UTF-8?q?=E6=95=B0=E9=BB=98=E8=AE=A41m=E5=AD=98=E9=87=8F=E8=B0=83?= =?UTF-8?q?=E7=94=A8=E9=9B=B6=E5=BD=B1=E5=93=8D?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Penalty/PenaltyBoundaryMatrixTest.cs | 33 +++++++++++++++++-- 1 file changed, 30 insertions(+), 3 deletions(-) diff --git a/UnitTestProject/Modules/SwapModule/Penalty/PenaltyBoundaryMatrixTest.cs b/UnitTestProject/Modules/SwapModule/Penalty/PenaltyBoundaryMatrixTest.cs index 6ebb8bf0..bf3dd846 100644 --- a/UnitTestProject/Modules/SwapModule/Penalty/PenaltyBoundaryMatrixTest.cs +++ b/UnitTestProject/Modules/SwapModule/Penalty/PenaltyBoundaryMatrixTest.cs @@ -11,7 +11,9 @@ namespace UnitTestProject.Modules.SwapModule.Penalty /// ② 重置日前一日平仓(② 几乎整段、窗口首段 0 天); /// ③ 到期日恰为重置日(末段 [到期,到期] 1 天); /// ④ 锚点偏离(td.StartDate=7/31 但腿 PosiStartDate=8/3 的延期/存续腿——重置网格整体不同); - /// ⑤ 起息日当天平仓(无 preEod)。 + /// ⑤ 起息日当天平仓(无 preEod); + /// ⑥ 部分平仓 share<1 + 无 preEod 兜底——钉 merger 复刻 GetInterests 本金口径的接缝 + /// (现有用例全部 closePercent=1m,重放基数与复刻本金的口径偏差在 share=1 下不可见)。 /// /// 一致性前提(与现实世界对齐):冻结利率 = 当前重置区间(含 unwind-1 的区间)的在役利率, /// 即"历史末段利率 = 冻结利率";历史各段定盘不同(体现真实 FR007 利率历史)。 @@ -67,7 +69,7 @@ namespace UnitTestProject.Modules.SwapModule.Penalty private static decimal RunFee(trade td, swap_position p, decimal settledAmount, eod_swap_position? preEod, DateTime unwind, bool settled, decimal spread, - decimal interestPrincipal = 0m, bool maturityCalcLast = true) + decimal interestPrincipal = 0m, bool maturityCalcLast = true, decimal closePercent = 1m) { var e = new swap_flow_event { @@ -78,7 +80,8 @@ namespace UnitTestProject.Modules.SwapModule.Penalty PenaltyInterestFeeMerger.Merge( td, new List { p }, new List { e }, unwind, AnnualDays, settled, maturityCalcLast: maturityCalcLast, - posiNotionalValue: Notional, closePosiNotionalValue: Notional, closePercent: 1m, + posiNotionalValue: Notional, closePosiNotionalValue: Notional * closePercent, + closePercent: closePercent, getSpread: _ => spread, getPreEod: _ => preEod, tryGetFixing: (d, c) => spread); return e.InterestFee; } @@ -192,6 +195,30 @@ namespace UnitTestProject.Modules.SwapModule.Penalty "无preEod+已有重置:兜底取事件基数后 ① 精确,全期=实结+罚息(修复前差≈3.17元)"); } + [TestMethod] + public void 部分平仓无preEod兜底_share对齐本金口径_恒等式成立() + { + // 接缝守卫:merger 的 closePrincipal 走 CalcNotional 复刻 GetInterests 口径 + // (标的期初全价 = posiNotional×closePercent),而重放基数由调用方以 + // closePosiNotionalValue 缩放——两处口径若有偏差,share=1 时不可见、 + // share<1 时 ① 里会混入本金差。本用例以 50% 平仓钉死该对齐。 + var start = new DateTime(2026, 8, 5); var unwind = new DateTime(2026, 8, 20); var maturity = new DateTime(2026, 9, 30); + var hist = new decimal[] { 0.0216m, 0.0144m }; // 8/5 段 2.16% / 8/19 段 1.44%(=冻结),14 天重置 + var share = 0.5m; + var closedNotional = Notional * share; + // 被平份额的实结与重放基数:复利对 notional 线性,直接按半额本金重放 + var elapsed = AccrueOnGrid(start, unwind, AccrualBoundary.StartOnly, hist, notional: closedNotional, period: 14); + var replayFinalBasis = closedNotional + AccrueOnGrid(start, new DateTime(2026, 8, 18), AccrualBoundary.Both, hist, notional: closedNotional, period: 14); + + var fee = RunFee(CreateTrade(start, maturity), CompoundLeg(start, maturity, hist[^1], periodDays: 14), elapsed, + preEod: null, unwind: unwind, settled: false, spread: hist[^1], + interestPrincipal: replayFinalBasis, maturityCalcLast: false, closePercent: share); + + var full = AccrueOnGrid(start, maturity, AccrualBoundary.StartOnly, hist, notional: closedNotional, period: 14); + Assert.AreEqual((double)full, (double)(elapsed + fee), 0.01, + "部分平仓+无preEod:兜底①按被平份额缩放精确,全期(被平份额)=实结+罚息(口径漂移时此式必挂)"); + } + [TestMethod] public void 起息日当天平仓_无preEod_恒等式成立() { From 6e76f1c10d1a7823696a8ba176ea2354ab7b6c57 Mon Sep 17 00:00:00 2001 From: hjhan Date: Fri, 21 Aug 2026 07:10:04 +0800 Subject: [PATCH 09/16] =?UTF-8?q?fix(swap):=20EQD-6977=20=E6=97=A0preEod?= =?UTF-8?q?=E5=85=9C=E5=BA=95=E2=91=A0=3D0=E4=B8=94=E8=B4=A6=E9=BE=84?= =?UTF-8?q?=E8=B6=85=E9=87=8D=E7=BD=AE=E5=91=A8=E6=9C=9F=E8=A1=A5=E9=80=80?= =?UTF-8?q?=E5=8C=96=E5=91=8A=E8=AD=A6trace=E2=80=94=E2=80=94interestWindo?= =?UTF-8?q?wEmpty(=E5=BD=93=E6=97=A5=E5=B7=B2=E7=BB=93=E6=81=AF)=E6=97=A9?= =?UTF-8?q?=E9=80=80=E4=B8=8D=E9=87=8D=E6=94=BE=E8=A6=86=E7=9B=96=E7=A7=8D?= =?UTF-8?q?=E5=AD=90=E5=80=BC=E6=97=B6=E2=91=A0=E9=9D=99=E9=BB=980(?= =?UTF-8?q?=E9=87=8D=E7=BD=AE=E6=97=A5=E5=88=86=E6=94=AF=E6=9C=AC=E6=9C=89?= =?UTF-8?q?=E5=90=8C=E7=B1=BB=E5=91=8A=E8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F-8?q?=E5=85=88=E8=A1=8C3=E4=BE=8Btrace=E9=92=89=E5=AD=90:=E9=80=80?= =?UTF-8?q?=E5=8C=96=E5=BF=85=E5=91=8A=E8=AD=A6(=E5=85=88=E7=BA=A2)/?= =?UTF-8?q?=E5=85=9C=E5=BA=95>0=E4=B8=8D=E5=91=8A=E8=AD=A6/=E7=9C=9F?= =?UTF-8?q?=E9=A6=96=E6=97=A5=E4=B8=8D=E5=91=8A=E8=AD=A6=EF=BC=9B=E7=BD=9A?= =?UTF-8?q?=E6=81=AF=E5=9F=9F27=E4=BE=8B+GetInterests=E5=85=A5=E5=8F=A3?= =?UTF-8?q?=E8=AF=AD=E4=B9=899=E4=BE=8B=E5=85=A8=E7=BB=BF?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Penalty/PenaltyInterestFeeMergerTest.cs | 45 +++++++++- .../Penalty/PenaltyInterestFeeMerger.cs | 86 ++++++++++++------- 2 files changed, 96 insertions(+), 35 deletions(-) diff --git a/UnitTestProject/Modules/SwapModule/Penalty/PenaltyInterestFeeMergerTest.cs b/UnitTestProject/Modules/SwapModule/Penalty/PenaltyInterestFeeMergerTest.cs index 2186bfdc..5df336c4 100644 --- a/UnitTestProject/Modules/SwapModule/Penalty/PenaltyInterestFeeMergerTest.cs +++ b/UnitTestProject/Modules/SwapModule/Penalty/PenaltyInterestFeeMergerTest.cs @@ -50,7 +50,8 @@ namespace UnitTestProject.Modules.SwapModule.Penalty private static void RunMerge( swap_position p, swap_flow_event normalEvent, eod_swap_position? preEod, - Func? getSpread = null, Func? tryGetFixing = null) + Func? getSpread = null, Func? tryGetFixing = null, + AccrualTrace? trace = null) { getSpread ??= _ => Rate; tryGetFixing ??= (d, code) => Rate; @@ -61,7 +62,8 @@ namespace UnitTestProject.Modules.SwapModule.Penalty posiNotionalValue: Notional, closePosiNotionalValue: Notional, closePercent: 1m, getSpread: getSpread, getPreEod: _ => preEod, - tryGetFixing: tryGetFixing); + tryGetFixing: tryGetFixing, + trace: trace); } /// 复利重放 [StartDate, endDate],重置段=每 7 天;分段利率由 rates 决定(rates.Count=1 时为常率)。 @@ -152,6 +154,45 @@ namespace UnitTestProject.Modules.SwapModule.Penalty Assert.IsTrue(e.InterestFee > 0m, "无 preEod(首日平仓等)仍可计算罚息"); } + [TestMethod] + public void 无preEod复利段中兜底为零且账龄超重置周期_留退化告警trace() + { + // 场景:无日终快照 + 复利 + 段中平仓,事件 InterestPrincipal 仍是种子值(=平仓本金)→兜底①=0。 + // 账龄 25 天 ≥ 7 天重置周期:复利每周期并本理应①>0,①=0 属退化—— + // 典型成因=interestWindowEmpty(当日已结息)早退未重放覆盖种子、或日终归档缺失。 + var e = NormalEvent(settledAmount: 50_000m); + e.InterestPrincipal = Notional; // GetInterests 种子值:interestWindowEmpty 早退路径不会用重放基数覆盖它 + var trace = new AccrualTrace(); + RunMerge(Leg(InterestTypeEnum.复利), e, preEod: null, trace: trace); + + StringAssert.Contains(trace.ToString(), "无preEod兜底①=0", + "①=0 且账龄超周期必须留告警,供事后核对日终归档/计息窗口根因"); + } + + [TestMethod] + public void 无preEod兜底为正_不留退化告警() + { + var e = NormalEvent(settledAmount: 50_000m); + e.InterestPrincipal = Notional + 100_000m; // 重放末次并本金后基数 → ①=100000 正常路径 + var trace = new AccrualTrace(); + RunMerge(Leg(InterestTypeEnum.复利), e, preEod: null, trace: trace); + + Assert.IsFalse(trace.ToString().Contains("兜底①=0"), "①>0 是正常兜底路径,不得告警"); + } + + [TestMethod] + public void 无preEod真首日兜底为零_不留退化告警() + { + var p = Leg(InterestTypeEnum.复利); + p.PosiStartDate = UnwindDate; // 起息日当天平仓:账龄 0 < 重置周期,①=0 是设计内约定(类头注) + var e = NormalEvent(settledAmount: 50_000m); + e.InterestPrincipal = Notional; + var trace = new AccrualTrace(); + RunMerge(p, e, preEod: null, trace: trace); + + Assert.IsFalse(trace.ToString().Contains("兜底①=0"), "真首日 ①=0 合法,不得告警"); + } + [TestMethod] public void 冻结利率解析失败_跳过该腿不阻断() { diff --git a/YLErpDAL/Modules/SwapModule/Penalty/PenaltyInterestFeeMerger.cs b/YLErpDAL/Modules/SwapModule/Penalty/PenaltyInterestFeeMerger.cs index a6b2256b..91ab256f 100644 --- a/YLErpDAL/Modules/SwapModule/Penalty/PenaltyInterestFeeMerger.cs +++ b/YLErpDAL/Modules/SwapModule/Penalty/PenaltyInterestFeeMerger.cs @@ -93,39 +93,9 @@ public static class PenaltyInterestFeeMerger } // 复利承接:实际滚动基数中已并入部分(①)+ 段内实际已计利息(②)。单利无并本金语义恒 0。 - // ① 的取值依赖平仓日是否为重置日、有无日终快照(数据契约): - // 段中平仓 + 有快照:TdInterestPrincipal 即当前段滚动基数(=本金+①),直接作差; - // 段中平仓 + 无快照:兜底取 normalEvent.InterestPrincipal——复利重放(CalcDailyCompoundInterest) - // 会把它写为末次并本金后的基数(=被平份额本金+①),同样是实际值而非推导值; - // 重置日当天平仓:快照基数仍是【上一段】的(今日并入尚未发生),须改取 - // preEod.InterestIncomeSum(昨日全部待实现利息 = 今日并入新段基数的那部分)。 - decimal capitalized = 0m, carryIn = 0m; - if (isCompound) - { - var periodDays = position.interest_rest_days ?? 1; - var unwindOnResetDay = SwapDealService.IsResetDay(unwindDate, position.PosiStartDate, periodDays); - if (unwindOnResetDay) - { - capitalized = (preEod?.InterestIncomeSum ?? 0m) * share; - if (preEod == null && (unwindDate - position.PosiStartDate).Days >= periodDays) - trace?.Note($"PENALTY|p{position.id} 注意 无preEod且平仓日=重置日:①退化0(此前重置并入额缺失,请核对日终归档完整性)"); - } - else if (preEod != null) - { - capitalized = Math.Max(0m, preEod.TdInterestPrincipal * share - closePrincipal); - } - else - { - capitalized = Math.Max(0m, normalEvent.InterestPrincipal - closePrincipal); - } - // ① 不得超过实结金额(数据异常时钳制并留痕,避免负②进入计息) - if (capitalized > Math.Max(0m, normalEvent.InterestAmount)) - { - trace?.Note($"PENALTY|p{position.id} 注意 承接①钳制:推导 {capitalized:F4} > 实结 {normalEvent.InterestAmount:F4}(快照/事件数据异常,请核对 preEod.TdInterestPrincipal/InterestIncomeSum)"); - capitalized = Math.Max(0m, normalEvent.InterestAmount); - } - carryIn = normalEvent.InterestAmount - capitalized; - } + var (capitalized, carryIn) = isCompound + ? ResolveCompoundCarry(position, normalEvent, preEod, closePrincipal, share, unwindDate, trace) + : (0m, 0m); var policy = AccrualPolicy.BuildEod(position, annualDays, isCompound); // 锚点 = PosiStartDate:与正常计息重放(CalcDailyCompoundInterest 的分段网格)一致,延期腿勿用 td.StartDate @@ -149,4 +119,54 @@ public static class PenaltyInterestFeeMerger $"罚息={penalty:F2} → InterestFee {feeBefore:F2}→{normalEvent.InterestFee:F2} PnL含罚息={normalEvent.InterestClosePnL:F2}"); } } + + /// + /// 复利承接量:① 实际滚动基数中已并入部分 + ② 最近重置日后实际已计利息(= 实结 − ①)。 + /// + /// ① 的取值依赖平仓日是否为重置日、有无日终快照(数据契约): + /// 段中平仓 + 有快照:TdInterestPrincipal 即当前段滚动基数(=本金+①),直接作差; + /// 段中平仓 + 无快照:兜底取 normalEvent.InterestPrincipal——复利重放(CalcDailyCompoundInterest) + /// 会把它写为末次并本金后的基数(=被平份额本金+①),同样是实际值而非推导值; + /// 重置日当天平仓:快照基数仍是【上一段】的(今日并入尚未发生),须改取 + /// preEod.InterestIncomeSum(昨日全部待实现利息 = 今日并入新段基数的那部分)。 + /// + private static (decimal Capitalized, decimal CarryIn) ResolveCompoundCarry( + swap_position position, swap_flow_event normalEvent, eod_swap_position? preEod, + decimal closePrincipal, decimal share, DateTime unwindDate, AccrualTrace? trace) + { + var periodDays = position.interest_rest_days ?? 1; + var unwindOnResetDay = SwapDealService.IsResetDay(unwindDate, position.PosiStartDate, periodDays); + + var capitalized = 0m; + if (unwindOnResetDay) + { + capitalized = (preEod?.InterestIncomeSum ?? 0m) * share; + if (preEod == null && (unwindDate - position.PosiStartDate).Days >= periodDays) + trace?.Note($"PENALTY|p{position.id} 注意 无preEod且平仓日=重置日:①退化0(此前重置并入额缺失,请核对日终归档完整性)"); + } + else if (preEod != null) + { + capitalized = Math.Max(0m, preEod.TdInterestPrincipal * share - closePrincipal); + } + else + { + capitalized = Math.Max(0m, normalEvent.InterestPrincipal - closePrincipal); + // 兜底①=0 但账龄已过重置周期:复利每周期并本,理应 ①>0——多为 interestWindowEmpty + // (当日已结息)早退未重放覆盖种子值、或日终归档缺失。留痕含两侧基数与账龄,供直接定位根因。 + var ageDays = (unwindDate - position.PosiStartDate).Days; + if (capitalized == 0m && ageDays >= periodDays) + trace?.Note( + $"PENALTY|p{position.id} 注意 无preEod兜底①=0但账龄{ageDays}天≥重置周期{periodDays}天:" + + $"事件基数{normalEvent.InterestPrincipal:F2}=平仓本金{closePrincipal:F2}(疑似interestWindowEmpty种子未重放/日终归档缺失," + + $"请核对swap_flow_event.InterestPrincipal重放回写与eod_swap_position归档)"); + } + + // ① 不得超过实结金额(数据异常时钳制并留痕,避免负②进入计息) + if (capitalized > Math.Max(0m, normalEvent.InterestAmount)) + { + trace?.Note($"PENALTY|p{position.id} 注意 承接①钳制:推导 {capitalized:F4} > 实结 {normalEvent.InterestAmount:F4}(快照/事件数据异常,请核对 preEod.TdInterestPrincipal/InterestIncomeSum)"); + capitalized = Math.Max(0m, normalEvent.InterestAmount); + } + return (capitalized, normalEvent.InterestAmount - capitalized); + } } From e8d0a764422d0b8e39707169f3719e80a8a972f7 Mon Sep 17 00:00:00 2001 From: hjhan Date: Fri, 21 Aug 2026 07:17:20 +0800 Subject: [PATCH 10/16] =?UTF-8?q?refactor(web):=20=E5=B9=B3=E4=BB=93?= =?UTF-8?q?=E9=A1=B5=E6=94=B6=E4=BB=98=E6=96=B9=E5=90=91=E7=AC=A6=E5=8F=B7?= =?UTF-8?q?=E6=98=BE=E5=BC=8F=E5=8C=96unwindLegSign.js+4=E4=BE=8B=E5=8D=95?= =?UTF-8?q?=E6=B5=8B=E2=80=94=E2=80=94=E8=A3=B8=E4=B8=89=E5=85=83(x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AF=81=E9=87=91=E4=B8=A4?= =?UTF-8?q?=E8=85=BF=E9=80=9A=E7=94=A8(changeInterestAmount=E6=A8=A1?= =?UTF-8?q?=E6=9D=BF=E5=AF=B9=E4=B8=A4=E7=B1=BB=E8=A1=8C=E9=83=BD=E7=BB=91?= =?UTF-8?q?=E5=AE=9A,=E5=B7=B2=E6=A0=B8=E5=AE=9E)=EF=BC=9B=E5=8F=A6?= =?UTF-8?q?=E5=88=A0=E6=AD=BB=E4=BB=A3=E7=A0=81:this.ratio/this.shortRatio?= =?UTF-8?q?=E6=95=B0=E6=8D=AE=E5=B1=9E=E6=80=A7+=E8=B5=8B=E5=80=BC?= =?UTF-8?q?=E5=85=A8=E5=BA=93=E6=97=A0=E8=AF=BB=E5=8F=96(=E6=A8=A1?= =?UTF-8?q?=E6=9D=BF=E4=BA=A6=E6=97=A0=E7=BB=91=E5=AE=9A)=E5=8F=8A?= =?UTF-8?q?=E6=B3=A8=E9=87=8A=E6=8E=89=E7=9A=84=E5=8E=86=E5=8F=B2=E4=B8=89?= =?UTF-8?q?=E5=85=83=EF=BC=9BSwapUnwind.cshtml=E8=A1=A5script=E6=A0=87?= =?UTF-8?q?=E7=AD=BE,=E4=B8=A4=E4=B8=AA=E6=89=A7=E8=A1=8C=E5=9E=8B?= =?UTF-8?q?=E6=B5=8B=E8=AF=95=E6=B2=99=E7=AE=B1=E5=96=82=E7=9C=9F=E5=AE=9E?= =?UTF-8?q?=E6=A8=A1=E5=9D=97=EF=BC=9B=E8=A1=8C=E4=B8=BA=E7=AD=89=E4=BB=B7?= =?UTF-8?q?(Number=3D=3D=3D1=E4=B8=8E=3D=3D1=E5=AF=B9=E5=AE=9E=E9=99=85?= =?UTF-8?q?=E5=85=A5=E5=8F=82=E7=AD=89=E4=BB=B7=E5=B7=B2=E9=AA=8C=E8=AF=81?= =?UTF-8?q?),=E5=85=A8=E5=A5=97315=E4=BE=8B=E7=BB=BF?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- YLErpWeb/Views/SwapTrade2/SwapUnwind.cshtml | 1 + .../closePercentInterestRefresh.test.js | 2 + YLErpWeb/fe-tests/unwindLegSign.test.js | 47 +++++++++++++++++++ YLErpWeb/fe-tests/unwindSwapTrade.test.js | 2 + .../Scripts/app/swaptrade/unwindLegSign.js | 45 ++++++++++++++++++ .../Scripts/app/swaptrade/unwindSwapTrade.js | 18 +++---- 6 files changed, 104 insertions(+), 11 deletions(-) create mode 100644 YLErpWeb/fe-tests/unwindLegSign.test.js create mode 100644 YLErpWeb/wwwroot/Scripts/app/swaptrade/unwindLegSign.js diff --git a/YLErpWeb/Views/SwapTrade2/SwapUnwind.cshtml b/YLErpWeb/Views/SwapTrade2/SwapUnwind.cshtml index c1fdaf8d..353c255e 100644 --- a/YLErpWeb/Views/SwapTrade2/SwapUnwind.cshtml +++ b/YLErpWeb/Views/SwapTrade2/SwapUnwind.cshtml @@ -27,6 +27,7 @@ + }
diff --git a/YLErpWeb/fe-tests/closePercentInterestRefresh.test.js b/YLErpWeb/fe-tests/closePercentInterestRefresh.test.js index 2fb4a7eb..5d31102f 100644 --- a/YLErpWeb/fe-tests/closePercentInterestRefresh.test.js +++ b/YLErpWeb/fe-tests/closePercentInterestRefresh.test.js @@ -155,6 +155,8 @@ function loadVueApp(model, mockPost) { roundExitYtm(v) { return v; }, applyManualEdit(s) { return s; } }, + // 收付方向符号:纯函数零依赖,直接喂真实模块(映射冻结由 unwindLegSign.test.js 覆盖) + UnwindLegSign: require('../wwwroot/Scripts/app/swaptrade/unwindLegSign.js'), _: { round(value, precision) { return Number(Number(value || 0).toFixed(precision || 0)); diff --git a/YLErpWeb/fe-tests/unwindLegSign.test.js b/YLErpWeb/fe-tests/unwindLegSign.test.js new file mode 100644 index 00000000..3258511c --- /dev/null +++ b/YLErpWeb/fe-tests/unwindLegSign.test.js @@ -0,0 +1,47 @@ +/** + * unwindLegSign.test.js — 平仓页收付方向符号映射(隐式约定显式化) + * ============================================================================ + * 冻结的领域事实(2026-08-21 业务确认): + * 利息腿(融资成本)与保证金腿(返息/返还本金)方向【必须相反】—— + * 利息是买方持有标的向交易商融资的成本(买方付出去的钱); + * 保证金是客户自己交的抵押金,返息/返还是把客户自己的钱退回来。 + * 两者对同一 InterestDirection 枚举符号互为镜像,这是业务事实而非笔误, + * 任何人"顺手统一"这两个符号都会翻转保证金返还方向(资损级 bug)。 + * + * 另冻结:PayDirection==1 → +1、PositionType==1(多头) → +1 的浮动端/多空符号。 + * + * 运行:cd YLErpWeb/fe-tests && npx jest unwindLegSign + */ +const UnwindLegSign = require('../wwwroot/Scripts/app/swaptrade/unwindLegSign.js'); + +describe('收付方向符号:各枚举映射', () => { + test('利息盈亏(利息腿/保证金腿通用):收取(1)→+1,支付(其他)→-1', () => { + expect(UnwindLegSign.interestPnlSign(1)).toBe(1); + expect(UnwindLegSign.interestPnlSign(0)).toBe(-1); + expect(UnwindLegSign.interestPnlSign(null)).toBe(-1); + }); + + test('保证金腿返还本金:与利息腿同枚举反号(返的是客户自己的钱)', () => { + expect(UnwindLegSign.marginRebatePrincipalSign(1)).toBe(-1); + expect(UnwindLegSign.marginRebatePrincipalSign(0)).toBe(1); + expect(UnwindLegSign.marginRebatePrincipalSign(null)).toBe(1); + }); + + test('浮动端收付:PayDirection==1(收取)→+1;多空:PositionType==1(多头)→+1', () => { + expect(UnwindLegSign.payDirectionSign(1)).toBe(1); + expect(UnwindLegSign.payDirectionSign(0)).toBe(-1); + expect(UnwindLegSign.positionTypeSign(1)).toBe(1); + expect(UnwindLegSign.positionTypeSign(0)).toBe(-1); + }); +}); + +describe('不变量:利息腿与保证金腿符号互为镜像(业务事实,禁止统一)', () => { + test('同一 InterestDirection 下两符号之和恒为 0', () => { + [1, 0, null, undefined, 2].forEach(dir => { + expect( + UnwindLegSign.interestPnlSign(dir) + + UnwindLegSign.marginRebatePrincipalSign(dir) + ).toBe(0); + }); + }); +}); diff --git a/YLErpWeb/fe-tests/unwindSwapTrade.test.js b/YLErpWeb/fe-tests/unwindSwapTrade.test.js index f0774f96..488a0c3b 100644 --- a/YLErpWeb/fe-tests/unwindSwapTrade.test.js +++ b/YLErpWeb/fe-tests/unwindSwapTrade.test.js @@ -66,6 +66,8 @@ function loadUnwindHelpers() { roundHalfAwayFromZero(value) { return value; }, calcCloseQtyByOriginalPercent() { return 0; } }, + // 收付方向符号:纯函数零依赖,直接喂真实模块(映射冻结由 unwindLegSign.test.js 覆盖) + UnwindLegSign: require('../wwwroot/Scripts/app/swaptrade/unwindLegSign.js'), _: { round(value, precision) { return Number(Number(value || 0).toFixed(precision || 0)); diff --git a/YLErpWeb/wwwroot/Scripts/app/swaptrade/unwindLegSign.js b/YLErpWeb/wwwroot/Scripts/app/swaptrade/unwindLegSign.js new file mode 100644 index 00000000..a07d62cd --- /dev/null +++ b/YLErpWeb/wwwroot/Scripts/app/swaptrade/unwindLegSign.js @@ -0,0 +1,45 @@ +/** + * unwindLegSign.js — 平仓页收付方向符号(纯函数) + * ============================================================================ + * 把散落在 unwindSwapTrade.js 各计算式里的裸三元(xxx==1 ? ±1 : ∓1)显式化为命名函数。 + * 【为什么必须显式化】利息盈亏与保证金返还本金对同一 InterestDirection 枚举符号相反—— + * 这是业务事实而非笔误,任何"顺手统一"都会翻转保证金返还方向(资损级 bug): + * 利息盈亏(利息腿/保证金腿通用,changeInterestAmount 对两类行都生效): + * 收益互换中买方为持有标的向交易商融资,利息=融资成本(买方付出去的钱), + * InterestDirection==1(收取) → 盈亏记 +1; + * 保证金返还本金:保证金是客户自己交的抵押金,返息/返还本金是把客户自己的钱退回来, + * 本金流方向与利息(成本)相反 → 同枚举符号取镜像 -1。 + * + * 其余两个符号:PayDirection==1(浮动端收取) → +1;PositionType==1(多头) → +1。 + * + * 加载:浏览器 script 标签(先于 unwindSwapTrade.js);Node:module.exports 供 jest。 + */ +var UnwindLegSign = (function () { + 'use strict'; + + // Number()===1 与页面原 ==1 对 '1'/true/数字等实际入参等价,且对 null/undefined 同样落到 -1 分支 + function interestPnlSign(interestDirection) { + return Number(interestDirection) === 1 ? 1 : -1; + } + + function marginRebatePrincipalSign(interestDirection) { + return Number(interestDirection) === 1 ? -1 : 1; + } + + function payDirectionSign(payDirection) { + return Number(payDirection) === 1 ? 1 : -1; + } + + function positionTypeSign(positionType) { + return Number(positionType) === 1 ? 1 : -1; + } + + return Object.freeze({ + interestPnlSign: interestPnlSign, + marginRebatePrincipalSign: marginRebatePrincipalSign, + payDirectionSign: payDirectionSign, + positionTypeSign: positionTypeSign + }); +}()); + +if (typeof module === 'object' && module.exports) module.exports = UnwindLegSign; diff --git a/YLErpWeb/wwwroot/Scripts/app/swaptrade/unwindSwapTrade.js b/YLErpWeb/wwwroot/Scripts/app/swaptrade/unwindSwapTrade.js index 764e9623..40b5da7c 100644 --- a/YLErpWeb/wwwroot/Scripts/app/swaptrade/unwindSwapTrade.js +++ b/YLErpWeb/wwwroot/Scripts/app/swaptrade/unwindSwapTrade.js @@ -69,8 +69,6 @@ const vue = new Vue({ // 平仓比例展示/输入均为"占期初(original)"语义(A):默认与每次重开都基于原始名义本金。 // oriClosePercent = 剩余名义本金/期初名义本金 = 最多可平比例(不能平超过剩余持仓)。 oriClosePercent: 1, - ratio: 1, - shortRatio: 1, }, computed: { maxUnwindDate() { @@ -125,8 +123,6 @@ const vue = new Vue({ this.marginList = model.FlowEvents.filter((item) => { return item.InterestMode == 5 || item.InterestMode == 6; }); - this.ratio = this.floatPosition.PayDirection == 1 ? -1 : 1; - this.shortRatio = this.floatPosition.PositionType == 1 ? 1 : -1; this.TradeStartDate = model.TradeStartDate; // 最多可平比例(占期初口径) = 剩余名义本金 / 期初名义本金;分母为 0 时兜底为 1 this.oriClosePercent = (this.deal.NotionalValue && this.deal.PosiNotionalValue) @@ -424,8 +420,8 @@ const vue = new Vue({ }, calcFloatClosePnl() {//计算浮动端平仓盈亏 var thisObj = this; - let floatRatio = thisObj.floatPosition.PayDirection == 1 ? 1 : -1; - let longRatio = thisObj.floatPosition.PositionType == 1 ? 1 : -1; + let floatRatio = UnwindLegSign.payDirectionSign(thisObj.floatPosition.PayDirection); + let longRatio = UnwindLegSign.positionTypeSign(thisObj.floatPosition.PositionType); let TradingFee = thisObj.floatPosition.TradingFee == "" ? 0 : parseFloat(thisObj.floatPosition.TradingFee); let TradingFeePending = thisObj.floatPosition.TradingFeePending == "" ? 0 : parseFloat(thisObj.floatPosition.TradingFeePending); let deliveryPrice = thisObj.getStorageDeliveryPrice(); @@ -440,7 +436,7 @@ const vue = new Vue({ this.calcFloatClosePnl(); }, changeInterestAmount(item) {//修改利息金额 - let interestRatio = item.InterestDirection == 1 ? 1 : -1; + let interestRatio = UnwindLegSign.interestPnlSign(item.InterestDirection); item.InterestClosePnL = formatSwapAmount(parseFloat(item.InterestAmount) * interestRatio + parseFloat(item.InterestFee) * interestRatio); this.calcCloseAmount(); }, @@ -450,8 +446,8 @@ const vue = new Vue({ // this.calcCloseAmount(); //}, calcCloseAmount() {//计算平仓总额=浮动收取+利息收取-浮动支付-利息支付 - let floatRatio = this.floatPosition.PayDirection == 1 ? 1 : -1; - let ratio = this.floatPosition.PositionType == 1 ? 1 : -1; + let floatRatio = UnwindLegSign.payDirectionSign(this.floatPosition.PayDirection); + let ratio = UnwindLegSign.positionTypeSign(this.floatPosition.PositionType); let thisObj = this; let pnl = parseFloat(this.floatPosition.FloatPnlSum); let TradingFee = thisObj.floatPosition.TradingFee == "" ? 0 : parseFloat(thisObj.floatPosition.TradingFee); @@ -468,14 +464,14 @@ const vue = new Vue({ thisObj.floatPosition.TradingAmountFeeAvg = deliveryPrice + (TradingFee / thisObj.deal.CloseQty) * ratio; } this.interestList.forEach(x => { - /*let interestRatio = x.InterestDirection == 1 ? 1 : -1;*/ let interestAmount = parseFloat(x.InterestClosePnL); thisObj.deal.SwapCloseAmount = parseFloat(thisObj.deal.SwapCloseAmount) + interestAmount; thisObj.deal.SwapRealizedPnL = parseFloat(thisObj.deal.SwapRealizedPnL) + interestAmount; }); this.marginList.forEach(x => { let interestAmount = parseFloat(x.InterestClosePnL); - let interestRatio = x.InterestDirection == 1 ? -1 : 1; + // 保证金返还本金符号与利息盈亏同枚举反号(见 unwindLegSign.js 头注——业务事实勿统一) + let interestRatio = UnwindLegSign.marginRebatePrincipalSign(x.InterestDirection); thisObj.deal.SwapCloseAmount = parseFloat(thisObj.deal.SwapCloseAmount) + interestAmount; thisObj.deal.SwapMarginRebatePnl = parseFloat(thisObj.deal.SwapMarginRebatePnl) + interestAmount; thisObj.deal.SwapRealizedPnL = parseFloat(thisObj.deal.SwapRealizedPnL) + interestAmount; From 771bd6798b74e41c490924e04695f76f5df64aca Mon Sep 17 00:00:00 2001 From: hjhan Date: Fri, 21 Aug 2026 08:38:42 +0800 Subject: [PATCH 11/16] =?UTF-8?q?feat(swap):=20EQD-6977=20=E7=BD=9A?= =?UTF-8?q?=E6=81=AF=E6=89=BF=E6=8E=A5=E2=91=A0=E4=B8=89=E5=88=86=E6=94=AF?= =?UTF-8?q?=E8=A1=A5=E5=85=A8=E7=A8=8B=E6=8E=A8=E5=AF=BCtrace=E2=80=94?= =?UTF-8?q?=E2=80=94=E6=AE=B5=E4=B8=AD=E5=B9=B3=E4=BB=93+=E6=9C=89?= =?UTF-8?q?=E5=BF=AB=E7=85=A7=E4=B8=BB=E8=B7=AF=E5=BE=84=E6=AD=A4=E5=89=8D?= =?UTF-8?q?=E9=9B=B6=E7=95=99=E7=97=95(=E7=94=A8=E6=88=B7=E5=8F=8D?= =?UTF-8?q?=E9=A6=88=E5=AE=9A=E4=BD=8D=E9=9A=BE)=EF=BC=8C=E7=8E=B0?= =?UTF-8?q?=E6=89=93=E5=87=BA=E5=BF=AB=E7=85=A7=E6=97=A5=E6=9C=9F/TdIntere?= =?UTF-8?q?stPrincipal/share/=E5=B9=B3=E4=BB=93=E6=9C=AC=E9=87=91/?= =?UTF-8?q?=E5=8E=9F=E5=A7=8B=E5=B7=AE/=E9=92=B30=E7=BB=93=E6=9E=9C?= =?UTF-8?q?=EF=BC=8C=E5=8E=9F=E5=A7=8B=E5=B7=AE=E4=B8=BA=E8=B4=9F=E9=A2=9D?= =?UTF-8?q?=E5=A4=96=E6=8F=90=E7=A4=BA=E7=96=91=E5=8F=A3=E5=BE=84=E4=B8=8D?= =?UTF-8?q?=E4=B8=80=E8=87=B4=EF=BC=9B=E9=87=8D=E7=BD=AE=E6=97=A5+?= =?UTF-8?q?=E6=9C=89=E5=BF=AB=E7=85=A7=E8=A1=A5InterestIncomeSum=C3=97shar?= =?UTF-8?q?e=E6=8E=A8=E5=AF=BC=EF=BC=9B=E6=97=A0=E5=BF=AB=E7=85=A7?= =?UTF-8?q?=E5=85=9C=E5=BA=95=E8=A1=A5=E4=BA=8B=E4=BB=B6=E5=9F=BA=E6=95=B0?= =?UTF-8?q?-=E5=B9=B3=E4=BB=93=E6=9C=AC=E9=87=91=E6=8E=A8=E5=AF=BC?= =?UTF-8?q?=EF=BC=9B=E2=91=A0=E5=BC=82=E5=B8=B8=E5=87=AD=E5=8D=95=E8=A1=8C?= =?UTF-8?q?=E6=97=A5=E5=BF=97=E5=8D=B3=E5=8F=AF=E5=8C=BA=E5=88=86=E5=BF=AB?= =?UTF-8?q?=E7=85=A7=E5=9F=BA=E6=95=B0/=E4=BB=BD=E9=A2=9D/=E5=B9=B3?= =?UTF-8?q?=E4=BB=93=E6=9C=AC=E9=87=91=E4=B8=89=E5=9B=A0=EF=BC=9B27?= =?UTF-8?q?=E4=B8=AA=E7=BD=9A=E6=81=AF=E5=8D=95=E6=B5=8B=E5=85=A8=E8=BF=87?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Penalty/PenaltyInterestFeeMerger.cs | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) diff --git a/YLErpDAL/Modules/SwapModule/Penalty/PenaltyInterestFeeMerger.cs b/YLErpDAL/Modules/SwapModule/Penalty/PenaltyInterestFeeMerger.cs index 91ab256f..aa0b4ce0 100644 --- a/YLErpDAL/Modules/SwapModule/Penalty/PenaltyInterestFeeMerger.cs +++ b/YLErpDAL/Modules/SwapModule/Penalty/PenaltyInterestFeeMerger.cs @@ -141,16 +141,29 @@ public static class PenaltyInterestFeeMerger if (unwindOnResetDay) { capitalized = (preEod?.InterestIncomeSum ?? 0m) * share; + if (preEod != null) + trace?.Note( + $"PENALTY|p{position.id} 承接①推导 重置日平仓+有快照:快照{preEod.ValueDate:yyyy-MM-dd} " + + $"昨日待实现利息InterestIncomeSum={preEod.InterestIncomeSum:F4} ×share={share:P4} → ①={capitalized:F4}"); if (preEod == null && (unwindDate - position.PosiStartDate).Days >= periodDays) trace?.Note($"PENALTY|p{position.id} 注意 无preEod且平仓日=重置日:①退化0(此前重置并入额缺失,请核对日终归档完整性)"); } else if (preEod != null) { - capitalized = Math.Max(0m, preEod.TdInterestPrincipal * share - closePrincipal); + // 段中平仓+有快照(复利承接主路径):① = 快照滚动基数×份额 − 平仓本金。全程留推导—— + // ①异常时凭此行即可区分"快照基数错 / share错 / 平仓本金错"三因,不必反推。 + var rawCarry = preEod.TdInterestPrincipal * share - closePrincipal; + capitalized = Math.Max(0m, rawCarry); + trace?.Note( + $"PENALTY|p{position.id} 承接①推导 段中平仓+有快照:快照{preEod.ValueDate:yyyy-MM-dd} " + + $"滚动基数TdInterestPrincipal={preEod.TdInterestPrincipal:F4} ×share={share:P4} −平仓本金{closePrincipal:F4} = {rawCarry:F4} → ①={capitalized:F4}" + + (rawCarry < 0m ? "(原始差为负已钳0:快照滚动基数×份额小于平仓本金,疑部分平仓比例与快照归档口径不一致,请核对eod_swap_position.TdInterestPrincipal)" : "")); } else { capitalized = Math.Max(0m, normalEvent.InterestPrincipal - closePrincipal); + trace?.Note( + $"PENALTY|p{position.id} 承接①推导 段中平仓+无快照兜底:事件基数InterestPrincipal={normalEvent.InterestPrincipal:F4} −平仓本金{closePrincipal:F4} → ①={capitalized:F4}"); // 兜底①=0 但账龄已过重置周期:复利每周期并本,理应 ①>0——多为 interestWindowEmpty // (当日已结息)早退未重放覆盖种子值、或日终归档缺失。留痕含两侧基数与账龄,供直接定位根因。 var ageDays = (unwindDate - position.PosiStartDate).Days; From 9d68e56797005e71dca1a1c6a034d88f7185a88f Mon Sep 17 00:00:00 2001 From: hjhan Date: Fri, 21 Aug 2026 08:41:51 +0800 Subject: [PATCH 12/16] =?UTF-8?q?refactor(swap):=20EQD-6977=20=E7=BD=9A?= =?UTF-8?q?=E6=81=AFtrace=E8=85=BF=E6=A0=87=E8=AF=86p{id}=E6=94=B9?= =?UTF-8?q?=E4=B8=BA=E8=9E=8D=E8=B5=84=E8=85=BF{id}=E2=80=94=E2=80=94?= =?UTF-8?q?=E5=8E=9F=E7=BC=A9=E5=86=99p=E5=8F=AF=E8=AF=BB=E6=80=A7?= =?UTF-8?q?=E5=B7=AE(=E7=94=A8=E6=88=B7=E5=8F=8D=E9=A6=88)=EF=BC=8C?= =?UTF-8?q?=E5=85=A8=E6=96=87=E4=BB=B69=E5=A4=84=E7=BB=9F=E4=B8=80?= =?UTF-8?q?=E5=8D=87=E7=BA=A7=EF=BC=9B=E6=97=A0=E6=B5=8B=E8=AF=95=E6=96=AD?= =?UTF-8?q?=E8=A8=80/=E5=A4=96=E9=83=A8=E6=B6=88=E8=B4=B9=E4=BE=9D?= =?UTF-8?q?=E8=B5=96=E8=AF=A5=E5=AD=97=E7=AC=A6=E4=B8=B2=EF=BC=8C27?= =?UTF-8?q?=E4=B8=AA=E7=BD=9A=E6=81=AF=E5=8D=95=E6=B5=8B=E5=85=A8=E8=BF=87?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Penalty/PenaltyInterestFeeMerger.cs | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/YLErpDAL/Modules/SwapModule/Penalty/PenaltyInterestFeeMerger.cs b/YLErpDAL/Modules/SwapModule/Penalty/PenaltyInterestFeeMerger.cs index aa0b4ce0..54289c5b 100644 --- a/YLErpDAL/Modules/SwapModule/Penalty/PenaltyInterestFeeMerger.cs +++ b/YLErpDAL/Modules/SwapModule/Penalty/PenaltyInterestFeeMerger.cs @@ -52,7 +52,7 @@ public static class PenaltyInterestFeeMerger var normalEvent = interests.FirstOrDefault(x => x.PositionId == position.id); if (normalEvent == null) { - trace?.Note($"PENALTY|p{position.id} 跳过 无正常平仓利息流(意外:融资腿应有对应事件)"); + trace?.Note($"PENALTY|融资腿{position.id} 跳过 无正常平仓利息流(意外:融资腿应有对应事件)"); continue; } @@ -88,7 +88,7 @@ public static class PenaltyInterestFeeMerger } catch (Exception ex) { - trace?.Note($"PENALTY|p{position.id} 跳过 冻结利率解析失败:{ex.Message}"); + trace?.Note($"PENALTY|融资腿{position.id} 跳过 冻结利率解析失败:{ex.Message}"); continue; } @@ -111,7 +111,7 @@ public static class PenaltyInterestFeeMerger normalEvent.InterestClosePnL += penalty * DirectionRatio.ReceivePay(position.InterestDirection); trace?.Note( - $"PENALTY|p{position.id} 完成 mode={mode} {(isCompound ? "复利" : "单利")} " + + $"PENALTY|融资腿{position.id} 完成 mode={mode} {(isCompound ? "复利" : "单利")} " + $"窗口=[{unwindDate:yyyy-MM-dd}→{maturityDate:yyyy-MM-dd}] 平仓日已结={unwindDaySettled} 到期算尾={maturityCalcLast} | " + $"本金 close={closePrincipal:F2} posi={r.PosiPrincipal:F2} share={share:P4} | " + $"冻结利率={frozenRate.AllInRate:P6} 来源={rateSource} | " + @@ -143,10 +143,10 @@ public static class PenaltyInterestFeeMerger capitalized = (preEod?.InterestIncomeSum ?? 0m) * share; if (preEod != null) trace?.Note( - $"PENALTY|p{position.id} 承接①推导 重置日平仓+有快照:快照{preEod.ValueDate:yyyy-MM-dd} " + + $"PENALTY|融资腿{position.id} 承接①推导 重置日平仓+有快照:快照{preEod.ValueDate:yyyy-MM-dd} " + $"昨日待实现利息InterestIncomeSum={preEod.InterestIncomeSum:F4} ×share={share:P4} → ①={capitalized:F4}"); if (preEod == null && (unwindDate - position.PosiStartDate).Days >= periodDays) - trace?.Note($"PENALTY|p{position.id} 注意 无preEod且平仓日=重置日:①退化0(此前重置并入额缺失,请核对日终归档完整性)"); + trace?.Note($"PENALTY|融资腿{position.id} 注意 无preEod且平仓日=重置日:①退化0(此前重置并入额缺失,请核对日终归档完整性)"); } else if (preEod != null) { @@ -155,7 +155,7 @@ public static class PenaltyInterestFeeMerger var rawCarry = preEod.TdInterestPrincipal * share - closePrincipal; capitalized = Math.Max(0m, rawCarry); trace?.Note( - $"PENALTY|p{position.id} 承接①推导 段中平仓+有快照:快照{preEod.ValueDate:yyyy-MM-dd} " + + $"PENALTY|融资腿{position.id} 承接①推导 段中平仓+有快照:快照{preEod.ValueDate:yyyy-MM-dd} " + $"滚动基数TdInterestPrincipal={preEod.TdInterestPrincipal:F4} ×share={share:P4} −平仓本金{closePrincipal:F4} = {rawCarry:F4} → ①={capitalized:F4}" + (rawCarry < 0m ? "(原始差为负已钳0:快照滚动基数×份额小于平仓本金,疑部分平仓比例与快照归档口径不一致,请核对eod_swap_position.TdInterestPrincipal)" : "")); } @@ -163,13 +163,13 @@ public static class PenaltyInterestFeeMerger { capitalized = Math.Max(0m, normalEvent.InterestPrincipal - closePrincipal); trace?.Note( - $"PENALTY|p{position.id} 承接①推导 段中平仓+无快照兜底:事件基数InterestPrincipal={normalEvent.InterestPrincipal:F4} −平仓本金{closePrincipal:F4} → ①={capitalized:F4}"); + $"PENALTY|融资腿{position.id} 承接①推导 段中平仓+无快照兜底:事件基数InterestPrincipal={normalEvent.InterestPrincipal:F4} −平仓本金{closePrincipal:F4} → ①={capitalized:F4}"); // 兜底①=0 但账龄已过重置周期:复利每周期并本,理应 ①>0——多为 interestWindowEmpty // (当日已结息)早退未重放覆盖种子值、或日终归档缺失。留痕含两侧基数与账龄,供直接定位根因。 var ageDays = (unwindDate - position.PosiStartDate).Days; if (capitalized == 0m && ageDays >= periodDays) trace?.Note( - $"PENALTY|p{position.id} 注意 无preEod兜底①=0但账龄{ageDays}天≥重置周期{periodDays}天:" + + $"PENALTY|融资腿{position.id} 注意 无preEod兜底①=0但账龄{ageDays}天≥重置周期{periodDays}天:" + $"事件基数{normalEvent.InterestPrincipal:F2}=平仓本金{closePrincipal:F2}(疑似interestWindowEmpty种子未重放/日终归档缺失," + $"请核对swap_flow_event.InterestPrincipal重放回写与eod_swap_position归档)"); } @@ -177,7 +177,7 @@ public static class PenaltyInterestFeeMerger // ① 不得超过实结金额(数据异常时钳制并留痕,避免负②进入计息) if (capitalized > Math.Max(0m, normalEvent.InterestAmount)) { - trace?.Note($"PENALTY|p{position.id} 注意 承接①钳制:推导 {capitalized:F4} > 实结 {normalEvent.InterestAmount:F4}(快照/事件数据异常,请核对 preEod.TdInterestPrincipal/InterestIncomeSum)"); + trace?.Note($"PENALTY|融资腿{position.id} 注意 承接①钳制:推导 {capitalized:F4} > 实结 {normalEvent.InterestAmount:F4}(快照/事件数据异常,请核对 preEod.TdInterestPrincipal/InterestIncomeSum)"); capitalized = Math.Max(0m, normalEvent.InterestAmount); } return (capitalized, normalEvent.InterestAmount - capitalized); From 640c78b5a96e893c52feef2b5e20d13693879391 Mon Sep 17 00:00:00 2001 From: hjhan Date: Fri, 21 Aug 2026 08:54:47 +0800 Subject: [PATCH 13/16] =?UTF-8?q?refactor(swap):=20EQD-6977=20trace?= =?UTF-8?q?=E5=8F=AF=E8=AF=BB=E6=80=A7=E7=AC=AC=E4=BA=8C=E6=89=B9=EF=BC=9A?= =?UTF-8?q?=E2=91=A0=E2=91=A1=E4=B8=8Ep{id}=E8=AF=AD=E4=B9=89=E5=8C=96?= =?UTF-8?q?=E2=80=94=E2=80=94=E6=89=BF=E6=8E=A5=E2=91=A0=E2=86=92=E5=B7=B2?= =?UTF-8?q?=E5=B9=B6=E5=A4=8D=E5=88=A9=E6=9C=AC=E9=87=91(capitalized)?= =?UTF-8?q?=E3=80=81=E2=91=A1=E2=86=92=E6=AE=B5=E5=86=85=E5=B7=B2=E8=AE=A1?= =?UTF-8?q?=E5=88=A9=E6=81=AF(carryIn)=EF=BC=8C=E6=97=A5=E5=BF=97/?= =?UTF-8?q?=E7=B1=BB=E5=A4=B4=E6=B3=A8/=E6=96=B9=E6=B3=95=E6=B3=A8/?= =?UTF-8?q?=E6=B5=8B=E8=AF=95=E6=96=AD=E8=A8=80=E5=9B=9B=E5=A4=84=E5=90=8C?= =?UTF-8?q?=E6=AD=A5=EF=BC=8C=E8=BF=90=E7=BB=B4=E5=87=AD=E6=97=A5=E5=BF=97?= =?UTF-8?q?=E5=8D=B3=E7=9F=A5=E4=B8=A4=E6=89=BF=E6=8E=A5=E9=87=8F=E5=90=AB?= =?UTF-8?q?=E4=B9=89=EF=BC=9BSwapDealService=C3=9712+SwapEodPositionServic?= =?UTF-8?q?e=C3=971=E7=9A=84p{position.id}=E7=BB=9F=E4=B8=80=E6=94=B9?= =?UTF-8?q?=E8=9E=8D=E8=B5=84=E8=85=BF{position.id}(FIX=20GetFloatRate/Res?= =?UTF-8?q?olve/Segments/EodCloseRefix=E5=85=A8=E7=B3=BB=E5=88=97)?= =?UTF-8?q?=EF=BC=9B=E6=B5=8B=E8=AF=95=E6=96=AD=E8=A8=80=E5=90=8C=E6=AD=A5?= =?UTF-8?q?=E6=9B=B4=E6=96=B0(=E6=AD=A4=E5=89=8D=E6=BC=8F=E6=9F=A5?= =?UTF-8?q?=E5=88=B0=E4=B8=80=E5=A4=84trace=E6=96=AD=E8=A8=80=E5=B7=B2?= =?UTF-8?q?=E4=B8=80=E5=B9=B6=E6=94=B9)=EF=BC=9B27/27=E7=BD=9A=E6=81=AF?= =?UTF-8?q?=E5=8D=95=E6=B5=8B=E9=80=9A=E8=BF=87=EF=BC=8CSwap=E5=85=A8?= =?UTF-8?q?=E5=A5=97644=E4=BE=8B=E4=B8=AD=E4=BB=852=E4=BE=8BDB=E4=BE=9D?= =?UTF-8?q?=E8=B5=96=E5=A4=B1=E8=B4=A5(=E5=B9=B2=E5=87=80=E6=A0=91?= =?UTF-8?q?=E5=A4=8D=E9=AA=8C=E4=B8=BA=E6=97=A2=E6=9C=89=E7=8E=AF=E5=A2=83?= =?UTF-8?q?=E9=97=AE=E9=A2=98)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Penalty/PenaltyInterestFeeMergerTest.cs | 16 +++---- .../Penalty/PenaltyInterestFeeMerger.cs | 44 +++++++++---------- .../Modules/SwapModule/SwapDealService.cs | 24 +++++----- .../SwapModule/SwapEodPositionService.cs | 2 +- 4 files changed, 43 insertions(+), 43 deletions(-) diff --git a/UnitTestProject/Modules/SwapModule/Penalty/PenaltyInterestFeeMergerTest.cs b/UnitTestProject/Modules/SwapModule/Penalty/PenaltyInterestFeeMergerTest.cs index 5df336c4..3a9ede19 100644 --- a/UnitTestProject/Modules/SwapModule/Penalty/PenaltyInterestFeeMergerTest.cs +++ b/UnitTestProject/Modules/SwapModule/Penalty/PenaltyInterestFeeMergerTest.cs @@ -157,40 +157,40 @@ namespace UnitTestProject.Modules.SwapModule.Penalty [TestMethod] public void 无preEod复利段中兜底为零且账龄超重置周期_留退化告警trace() { - // 场景:无日终快照 + 复利 + 段中平仓,事件 InterestPrincipal 仍是种子值(=平仓本金)→兜底①=0。 - // 账龄 25 天 ≥ 7 天重置周期:复利每周期并本理应①>0,①=0 属退化—— + // 场景:无日终快照 + 复利 + 段中平仓,事件 InterestPrincipal 仍是种子值(=平仓本金)→兜底已并复利本金=0。 + // 账龄 25 天 ≥ 7 天重置周期:复利每周期并本理应>0,已并复利本金=0 属退化—— // 典型成因=interestWindowEmpty(当日已结息)早退未重放覆盖种子、或日终归档缺失。 var e = NormalEvent(settledAmount: 50_000m); e.InterestPrincipal = Notional; // GetInterests 种子值:interestWindowEmpty 早退路径不会用重放基数覆盖它 var trace = new AccrualTrace(); RunMerge(Leg(InterestTypeEnum.复利), e, preEod: null, trace: trace); - StringAssert.Contains(trace.ToString(), "无preEod兜底①=0", - "①=0 且账龄超周期必须留告警,供事后核对日终归档/计息窗口根因"); + StringAssert.Contains(trace.ToString(), "无preEod兜底已并复利本金=0", + "已并复利本金=0 且账龄超周期必须留告警,供事后核对日终归档/计息窗口根因"); } [TestMethod] public void 无preEod兜底为正_不留退化告警() { var e = NormalEvent(settledAmount: 50_000m); - e.InterestPrincipal = Notional + 100_000m; // 重放末次并本金后基数 → ①=100000 正常路径 + e.InterestPrincipal = Notional + 100_000m; // 重放末次并本金后基数 → 已并复利本金=100000 正常路径 var trace = new AccrualTrace(); RunMerge(Leg(InterestTypeEnum.复利), e, preEod: null, trace: trace); - Assert.IsFalse(trace.ToString().Contains("兜底①=0"), "①>0 是正常兜底路径,不得告警"); + Assert.IsFalse(trace.ToString().Contains("兜底已并复利本金=0"), "已并复利本金>0 是正常兜底路径,不得告警"); } [TestMethod] public void 无preEod真首日兜底为零_不留退化告警() { var p = Leg(InterestTypeEnum.复利); - p.PosiStartDate = UnwindDate; // 起息日当天平仓:账龄 0 < 重置周期,①=0 是设计内约定(类头注) + p.PosiStartDate = UnwindDate; // 起息日当天平仓:账龄 0 < 重置周期,已并复利本金=0 是设计内约定(类头注) var e = NormalEvent(settledAmount: 50_000m); e.InterestPrincipal = Notional; var trace = new AccrualTrace(); RunMerge(p, e, preEod: null, trace: trace); - Assert.IsFalse(trace.ToString().Contains("兜底①=0"), "真首日 ①=0 合法,不得告警"); + Assert.IsFalse(trace.ToString().Contains("兜底已并复利本金=0"), "真首日 已并复利本金=0 合法,不得告警"); } [TestMethod] diff --git a/YLErpDAL/Modules/SwapModule/Penalty/PenaltyInterestFeeMerger.cs b/YLErpDAL/Modules/SwapModule/Penalty/PenaltyInterestFeeMerger.cs index 54289c5b..59b64956 100644 --- a/YLErpDAL/Modules/SwapModule/Penalty/PenaltyInterestFeeMerger.cs +++ b/YLErpDAL/Modules/SwapModule/Penalty/PenaltyInterestFeeMerger.cs @@ -12,9 +12,9 @@ namespace YLErp.Modules.SwapModule.Penalty; /// getSpread(加点利差)/ getPreEod(上一日终快照行)/ tryGetFixing(定盘取价),本类零 DB 耦合、可 headless 单测。 /// /// 复利承接量(精确续接口径的关键)**必须取实际计息状态**,严禁冻结利率重放推导: -/// 承接① capitalized = max(0, preEod.TdInterestPrincipal×份额 − closePrincipal) —— 实际滚动复利基数中已并入部分; -/// 承接② carryIn = 正常平仓流实结 InterestAmount − ① —— 最近重置日后实际已计利息; -/// 无 preEod(首日平仓):①=0、②=实结金额。 +/// 已并复利本金 capitalized = max(0, preEod.TdInterestPrincipal×份额 − closePrincipal) —— 实际滚动复利基数中已并入部分; +/// 段内已计利息 carryIn = 正常平仓流实结 InterestAmount − 已并复利本金 —— 最近重置日后实际已计利息; +/// 无 preEod(首日平仓):已并复利本金=0、段内已计利息=实结金额。 /// 逐腿全程 trace 落盘(SwapCalcTrace),供计算过程分析与错误定位。 /// public static class PenaltyInterestFeeMerger @@ -48,7 +48,7 @@ public static class PenaltyInterestFeeMerger foreach (var position in fundingPositions) { - // 正常平仓利息流(GetInterests 刚产出)——承接②的事实源与罚息并入目标 + // 正常平仓利息流(GetInterests 刚产出)——段内已计利息的事实源与罚息并入目标 var normalEvent = interests.FirstOrDefault(x => x.PositionId == position.id); if (normalEvent == null) { @@ -92,7 +92,7 @@ public static class PenaltyInterestFeeMerger continue; } - // 复利承接:实际滚动基数中已并入部分(①)+ 段内实际已计利息(②)。单利无并本金语义恒 0。 + // 复利承接:实际滚动基数中已并入部分(已并复利本金)+ 段内实际已计利息(段内已计利息)。单利无并本金语义恒 0。 var (capitalized, carryIn) = isCompound ? ResolveCompoundCarry(position, normalEvent, preEod, closePrincipal, share, unwindDate, trace) : (0m, 0m); @@ -115,18 +115,18 @@ public static class PenaltyInterestFeeMerger $"窗口=[{unwindDate:yyyy-MM-dd}→{maturityDate:yyyy-MM-dd}] 平仓日已结={unwindDaySettled} 到期算尾={maturityCalcLast} | " + $"本金 close={closePrincipal:F2} posi={r.PosiPrincipal:F2} share={share:P4} | " + $"冻结利率={frozenRate.AllInRate:P6} 来源={rateSource} | " + - $"承接①={capitalized:F4} ②={carryIn:F4} 实结={normalEvent.InterestAmount:F4} | " + + $"承接[已并复利本金]={capitalized:F4} [段内已计利息]={carryIn:F4} 实结={normalEvent.InterestAmount:F4} | " + $"罚息={penalty:F2} → InterestFee {feeBefore:F2}→{normalEvent.InterestFee:F2} PnL含罚息={normalEvent.InterestClosePnL:F2}"); } } /// - /// 复利承接量:① 实际滚动基数中已并入部分 + ② 最近重置日后实际已计利息(= 实结 − ①)。 + /// 复利承接量:已并复利本金(实际滚动基数中已并入部分)+ 段内已计利息(最近重置日后实际已计,= 实结 − 已并复利本金)。 /// - /// ① 的取值依赖平仓日是否为重置日、有无日终快照(数据契约): - /// 段中平仓 + 有快照:TdInterestPrincipal 即当前段滚动基数(=本金+①),直接作差; + /// 已并复利本金的取值依赖平仓日是否为重置日、有无日终快照(数据契约): + /// 段中平仓 + 有快照:TdInterestPrincipal 即当前段滚动基数(=本金+已并复利本金),直接作差; /// 段中平仓 + 无快照:兜底取 normalEvent.InterestPrincipal——复利重放(CalcDailyCompoundInterest) - /// 会把它写为末次并本金后的基数(=被平份额本金+①),同样是实际值而非推导值; + /// 会把它写为末次并本金后的基数(=被平份额本金+已并复利本金),同样是实际值而非推导值; /// 重置日当天平仓:快照基数仍是【上一段】的(今日并入尚未发生),须改取 /// preEod.InterestIncomeSum(昨日全部待实现利息 = 今日并入新段基数的那部分)。 /// @@ -143,41 +143,41 @@ public static class PenaltyInterestFeeMerger capitalized = (preEod?.InterestIncomeSum ?? 0m) * share; if (preEod != null) trace?.Note( - $"PENALTY|融资腿{position.id} 承接①推导 重置日平仓+有快照:快照{preEod.ValueDate:yyyy-MM-dd} " + - $"昨日待实现利息InterestIncomeSum={preEod.InterestIncomeSum:F4} ×share={share:P4} → ①={capitalized:F4}"); + $"PENALTY|融资腿{position.id} 承接量推导(已并复利本金) 重置日平仓+有快照:快照{preEod.ValueDate:yyyy-MM-dd} " + + $"昨日待实现利息InterestIncomeSum={preEod.InterestIncomeSum:F4} ×share={share:P4} → 已并复利本金={capitalized:F4}"); if (preEod == null && (unwindDate - position.PosiStartDate).Days >= periodDays) - trace?.Note($"PENALTY|融资腿{position.id} 注意 无preEod且平仓日=重置日:①退化0(此前重置并入额缺失,请核对日终归档完整性)"); + trace?.Note($"PENALTY|融资腿{position.id} 注意 无preEod且平仓日=重置日:已并复利本金退化0(此前重置并入额缺失,请核对日终归档完整性)"); } else if (preEod != null) { - // 段中平仓+有快照(复利承接主路径):① = 快照滚动基数×份额 − 平仓本金。全程留推导—— - // ①异常时凭此行即可区分"快照基数错 / share错 / 平仓本金错"三因,不必反推。 + // 段中平仓+有快照(复利承接主路径):已并复利本金 = 快照滚动基数×份额 − 平仓本金。全程留推导—— + // 结果异常时凭此行即可区分"快照基数错 / share错 / 平仓本金错"三因,不必反推。 var rawCarry = preEod.TdInterestPrincipal * share - closePrincipal; capitalized = Math.Max(0m, rawCarry); trace?.Note( - $"PENALTY|融资腿{position.id} 承接①推导 段中平仓+有快照:快照{preEod.ValueDate:yyyy-MM-dd} " + - $"滚动基数TdInterestPrincipal={preEod.TdInterestPrincipal:F4} ×share={share:P4} −平仓本金{closePrincipal:F4} = {rawCarry:F4} → ①={capitalized:F4}" + + $"PENALTY|融资腿{position.id} 承接量推导(已并复利本金) 段中平仓+有快照:快照{preEod.ValueDate:yyyy-MM-dd} " + + $"滚动基数TdInterestPrincipal={preEod.TdInterestPrincipal:F4} ×share={share:P4} −平仓本金{closePrincipal:F4} = {rawCarry:F4} → 已并复利本金={capitalized:F4}" + (rawCarry < 0m ? "(原始差为负已钳0:快照滚动基数×份额小于平仓本金,疑部分平仓比例与快照归档口径不一致,请核对eod_swap_position.TdInterestPrincipal)" : "")); } else { capitalized = Math.Max(0m, normalEvent.InterestPrincipal - closePrincipal); trace?.Note( - $"PENALTY|融资腿{position.id} 承接①推导 段中平仓+无快照兜底:事件基数InterestPrincipal={normalEvent.InterestPrincipal:F4} −平仓本金{closePrincipal:F4} → ①={capitalized:F4}"); - // 兜底①=0 但账龄已过重置周期:复利每周期并本,理应 ①>0——多为 interestWindowEmpty + $"PENALTY|融资腿{position.id} 承接量推导(已并复利本金) 段中平仓+无快照兜底:事件基数InterestPrincipal={normalEvent.InterestPrincipal:F4} −平仓本金{closePrincipal:F4} → 已并复利本金={capitalized:F4}"); + // 兜底已并复利本金=0 但账龄已过重置周期:复利每周期并本,理应 >0——多为 interestWindowEmpty // (当日已结息)早退未重放覆盖种子值、或日终归档缺失。留痕含两侧基数与账龄,供直接定位根因。 var ageDays = (unwindDate - position.PosiStartDate).Days; if (capitalized == 0m && ageDays >= periodDays) trace?.Note( - $"PENALTY|融资腿{position.id} 注意 无preEod兜底①=0但账龄{ageDays}天≥重置周期{periodDays}天:" + + $"PENALTY|融资腿{position.id} 注意 无preEod兜底已并复利本金=0但账龄{ageDays}天≥重置周期{periodDays}天:" + $"事件基数{normalEvent.InterestPrincipal:F2}=平仓本金{closePrincipal:F2}(疑似interestWindowEmpty种子未重放/日终归档缺失," + $"请核对swap_flow_event.InterestPrincipal重放回写与eod_swap_position归档)"); } - // ① 不得超过实结金额(数据异常时钳制并留痕,避免负②进入计息) + // 已并复利本金不得超过实结金额(数据异常时钳制并留痕,避免负的段内已计利息进入计息) if (capitalized > Math.Max(0m, normalEvent.InterestAmount)) { - trace?.Note($"PENALTY|融资腿{position.id} 注意 承接①钳制:推导 {capitalized:F4} > 实结 {normalEvent.InterestAmount:F4}(快照/事件数据异常,请核对 preEod.TdInterestPrincipal/InterestIncomeSum)"); + trace?.Note($"PENALTY|融资腿{position.id} 注意 承接已并复利本金钳制:推导 {capitalized:F4} > 实结 {normalEvent.InterestAmount:F4}(快照/事件数据异常,请核对 preEod.TdInterestPrincipal/InterestIncomeSum)"); capitalized = Math.Max(0m, normalEvent.InterestAmount); } return (capitalized, normalEvent.InterestAmount - capitalized); diff --git a/YLErpDAL/Modules/SwapModule/SwapDealService.cs b/YLErpDAL/Modules/SwapModule/SwapDealService.cs index 0a238637..25376977 100644 --- a/YLErpDAL/Modules/SwapModule/SwapDealService.cs +++ b/YLErpDAL/Modules/SwapModule/SwapDealService.cs @@ -905,13 +905,13 @@ namespace YLErp.Modules.SwapModule isResetDay ? endDate : startDate, position.interest_rule); // 历史上有"取错重置日利率"的线上 bug,取价决策必须常驻落盘(SwapCalcTrace.Critical 无条件 Info)。 SwapCalcTrace.Critical( - $"FIX GetFloatRate p{position.id} [{startDate:yyyy-MM-dd}→{endDate:yyyy-MM-dd}] days={days} period={period} " + + $"FIX GetFloatRate 融资腿{position.id} [{startDate:yyyy-MM-dd}→{endDate:yyyy-MM-dd}] days={days} period={period} " + $"重置日={isResetDay} rule={position.interest_rule} 取价日={rateDate:yyyy-MM-dd} calcLast={calcLast} " + $"preEod={(preEod.id != 0 ? $"{preEod.ValueDate:yyyy-MM-dd}:{preEod.FloatRate:P6}" : "无")}"); if (preEod.id != 0 && !isResetDay) { - SwapCalcTrace.Critical($"FIX GetFloatRate p{position.id} 非重置日→沿用昨日终FloatRate={preEod.FloatRate:P6}"); + SwapCalcTrace.Critical($"FIX GetFloatRate 融资腿{position.id} 非重置日→沿用昨日终FloatRate={preEod.FloatRate:P6}"); position.FloatRate = positionClone.FloatRate = preEod.FloatRate; return preEod.FloatRate; } @@ -923,13 +923,13 @@ namespace YLErp.Modules.SwapModule { var keptNoFetch = preEod.id != 0 ? preEod.FloatRate : position.FloatRate; SwapCalcTrace.Critical( - $"FIX GetFloatRate p{position.id} 不算尾重置日→不取尾日定盘,沿用已有利率={keptNoFetch:P6}(来源={(preEod.id != 0 ? "preEod.FloatRate" : "position.FloatRate")})"); + $"FIX GetFloatRate 融资腿{position.id} 不算尾重置日→不取尾日定盘,沿用已有利率={keptNoFetch:P6}(来源={(preEod.id != 0 ? "preEod.FloatRate" : "position.FloatRate")})"); return keptNoFetch; } if (IndexFixer.TryGetFixing(rateDate, position.FloatRateUnderlyingCode, out decimal rate)) { - SwapCalcTrace.Critical($"FIX GetFloatRate p{position.id} 重置日→取{rateDate:yyyy-MM-dd}定盘={rate:P6}"); + SwapCalcTrace.Critical($"FIX GetFloatRate 融资腿{position.id} 重置日→取{rateDate:yyyy-MM-dd}定盘={rate:P6}"); position.FloatRate = positionClone.FloatRate = rate; return position.FloatRate; } @@ -937,17 +937,17 @@ namespace YLErp.Modules.SwapModule { if (calcLast) { - SwapCalcTrace.Critical($"FIX GetFloatRate p{position.id} {rateDate:yyyy-MM-dd}缺价且算尾→抛异常拦截"); + SwapCalcTrace.Critical($"FIX GetFloatRate 融资腿{position.id} {rateDate:yyyy-MM-dd}缺价且算尾→抛异常拦截"); throw new Exception($"获取不到{position.FloatRateUnderlyingCode}在{rateDate:yyyy年MM月dd日}的价格"); } // 算头不算尾(calcLast=false):endDate 当天不计息,其 FR007 利率不参与计息, // 缺价时直接沿用已有利率,不回退取其他日期利率,不告警。 var kept = preEod.id != 0 ? preEod.FloatRate : position.FloatRate; SwapCalcTrace.Critical( - $"FIX GetFloatRate p{position.id} {rateDate:yyyy-MM-dd}缺价且不算尾→沿用已有利率={kept:P6}(来源={(preEod.id != 0 ? "preEod.FloatRate" : "position.FloatRate")})"); + $"FIX GetFloatRate 融资腿{position.id} {rateDate:yyyy-MM-dd}缺价且不算尾→沿用已有利率={kept:P6}(来源={(preEod.id != 0 ? "preEod.FloatRate" : "position.FloatRate")})"); return kept; } - SwapCalcTrace.Critical($"FIX GetFloatRate p{position.id} 计息窗口为空→利率不参与,返回0"); + SwapCalcTrace.Critical($"FIX GetFloatRate 融资腿{position.id} 计息窗口为空→利率不参与,返回0"); return 0m; } @@ -1376,15 +1376,15 @@ namespace YLErp.Modules.SwapModule if (fixing != 0m) { SwapCalcTrace.Critical( - $"FIX Resolve p{position.id} {date:yyyy-MM-dd}(取价日={fixingDate:yyyy-MM-dd} rule={position.interest_rule})→定盘={fixing:P6}"); + $"FIX Resolve 融资腿{position.id} {date:yyyy-MM-dd}(取价日={fixingDate:yyyy-MM-dd} rule={position.interest_rule})→定盘={fixing:P6}"); return fixing; } SwapCalcTrace.Critical( - $"FIX Resolve p{position.id} {date:yyyy-MM-dd}(取价日={fixingDate:yyyy-MM-dd})→定盘=0视为缺价,沿用fallback={fallback:P6}"); + $"FIX Resolve 融资腿{position.id} {date:yyyy-MM-dd}(取价日={fixingDate:yyyy-MM-dd})→定盘=0视为缺价,沿用fallback={fallback:P6}"); return fallback; } SwapCalcTrace.Critical( - $"FIX Resolve p{position.id} {date:yyyy-MM-dd}(取价日={fixingDate:yyyy-MM-dd} rule={position.interest_rule})→缺价,抛异常"); + $"FIX Resolve 融资腿{position.id} {date:yyyy-MM-dd}(取价日={fixingDate:yyyy-MM-dd} rule={position.interest_rule})→缺价,抛异常"); throw new Exception($"获取不到{position.FloatRateUnderlyingCode}在{fixingDate:yyyy年MM月dd日}的价格"); } @@ -1403,7 +1403,7 @@ namespace YLErp.Modules.SwapModule var calcDays = (endDate - startDate).Days; decimal currentFloat = initialFloat; SwapCalcTrace.Critical( - $"FIX Segments p{position.id} [{startDate:yyyy-MM-dd}→{endDate:yyyy-MM-dd}] period={interestPeriod} " + + $"FIX Segments 融资腿{position.id} [{startDate:yyyy-MM-dd}→{endDate:yyyy-MM-dd}] period={interestPeriod} " + $"fetchAfter={(fetchAfterDate?.ToString("yyyy-MM-dd") ?? "全程")} calcLast={calcLast} " + $"排除起点={(exclusionStart?.ToString("yyyy-MM-dd") ?? (calcLast ? "无" : endDate.ToString("yyyy-MM-dd")))} seed={initialFloat:P6} spread={spread:P6}"); for (int i = 0; i <= calcDays; i += interestPeriod) @@ -1422,7 +1422,7 @@ namespace YLErp.Modules.SwapModule else if (needFetch && isExcludedEnd) { SwapCalcTrace.Critical( - $"FIX Segment p{position.id} {resetDate:yyyy-MM-dd} 排除日(不计息)→不取价,沿用末段={currentFloat:P6}"); + $"FIX Segment 融资腿{position.id} {resetDate:yyyy-MM-dd} 排除日(不计息)→不取价,沿用末段={currentFloat:P6}"); } rates.Add((resetDate, spread + currentFloat)); } diff --git a/YLErpDAL/Modules/SwapModule/SwapEodPositionService.cs b/YLErpDAL/Modules/SwapModule/SwapEodPositionService.cs index 714ba36d..f81b2f7f 100644 --- a/YLErpDAL/Modules/SwapModule/SwapEodPositionService.cs +++ b/YLErpDAL/Modules/SwapModule/SwapEodPositionService.cs @@ -1380,7 +1380,7 @@ namespace YLErp.Modules.SwapModule { var ongoingFixing = ResolveOngoingResetFixing(position, valueDate); SwapCalcTrace.Critical( - $"FIX EodCloseRefix p{position.id} {valueDate:yyyy-MM-dd} 平仓日=重置日→剩余持仓快照再定盘 {newEodPayPosition.FloatRate:P6}→{ongoingFixing:P6}"); + $"FIX EodCloseRefix 融资腿{position.id} {valueDate:yyyy-MM-dd} 平仓日=重置日→剩余持仓快照再定盘 {newEodPayPosition.FloatRate:P6}→{ongoingFixing:P6}"); newEodPayPosition.FloatRate = ongoingFixing; } //利息端估值用信息 From 433bca953065970910247a1d825cab3be5807dc0 Mon Sep 17 00:00:00 2001 From: hjhan Date: Fri, 21 Aug 2026 09:16:28 +0800 Subject: [PATCH 14/16] =?UTF-8?q?fix(web):=20EQD-5320=20=E6=89=B9=E9=87=8F?= =?UTF-8?q?=E5=8F=91=E9=80=81=E7=A1=AE=E8=AE=A4=E4=B9=A6=E6=8C=89=E9=92=AE?= =?UTF-8?q?=E7=82=B9=E5=87=BB=E6=97=A0=E5=8F=8D=E5=BA=94=E2=80=94=E2=80=94?= =?UTF-8?q?$.ajax=E5=8E=9F=E6=97=A0error=E5=9B=9E=E8=B0=83=EF=BC=8C/trs=5F?= =?UTF-8?q?hub=5Fapi=E4=BB=A3=E7=90=86=E4=B8=8D=E9=80=9A/=E8=B6=85?= =?UTF-8?q?=E6=97=B6/=E8=BF=94=E5=9B=9E=E9=9D=9EJSON(=E5=A6=82=E8=A2=AB?= =?UTF-8?q?=E7=99=BB=E5=BD=95=E9=A1=B5=E9=87=8D=E5=AE=9A=E5=90=91)?= =?UTF-8?q?=E6=97=B6=E5=AE=8C=E5=85=A8=E9=9D=99=E9=BB=98=EF=BC=9B=E8=A1=A5?= =?UTF-8?q?error=E5=9B=9E=E8=B0=83=E7=BB=99HTTP=E7=8A=B6=E6=80=81+?= =?UTF-8?q?=E6=8E=92=E6=9F=A5=E6=8C=87=E5=BC=95(=E6=8E=A7=E5=88=B6?= =?UTF-8?q?=E5=8F=B0=E5=90=8C=E6=AD=A5=E8=AF=A6=E9=94=99)=EF=BC=8Csuccess?= =?UTF-8?q?=E5=85=9C=E5=BA=95=E9=9D=9E=E6=A0=87=E5=87=86=E8=BF=94=E5=9B=9E?= =?UTF-8?q?=E7=BB=93=E6=9E=84=E5=B9=B6=E6=8F=90=E7=A4=BA=E7=AC=94=E6=95=B0?= =?UTF-8?q?=EF=BC=8C=E6=88=90=E5=8A=9F=E5=90=8E=E5=88=B7=E6=96=B0=E5=88=97?= =?UTF-8?q?=E8=A1=A8=EF=BC=9B232/232=E5=89=8D=E7=AB=AF=E6=B5=8B=E8=AF=95?= =?UTF-8?q?=E9=80=9A=E8=BF=87?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Scripts/app/swaptrade/tradeEndConfirmList.js | 16 +++++++++++++--- 1 file changed, 13 insertions(+), 3 deletions(-) diff --git a/YLErpWeb/wwwroot/Scripts/app/swaptrade/tradeEndConfirmList.js b/YLErpWeb/wwwroot/Scripts/app/swaptrade/tradeEndConfirmList.js index 6f82f664..90eb900d 100644 --- a/YLErpWeb/wwwroot/Scripts/app/swaptrade/tradeEndConfirmList.js +++ b/YLErpWeb/wwwroot/Scripts/app/swaptrade/tradeEndConfirmList.js @@ -176,12 +176,22 @@ function SendEmailEitherReport() { dataType: "json", contentType:"application/json", success: function (res) { - if (res.success) { - main.message("发送成功"); + // 代理/网关异常时可能返回非标准结构——统一兜底提示,绝不让点击"无反应" + if (res && res.success) { + main.message("发送成功(共" + selIds.length + "笔),详情见bond-oms日志[结算确认书邮件]"); + SearchClick(); // 刷新列表以反映发送状态 } else { - main.message(res.message); + var msg = (res && (res.message || res.msg)) || "发送失败:服务返回异常结构"; + main.message(msg); + console.error("[批量发送确认书] 业务失败:", res); } }, + error: function (xhr, textStatus, errThrown) { + // 请求层失败:代理不通/超时/返回非JSON(如被登录页重定向)——此前无error回调导致点击"毫无反应" + var detail = "HTTP " + xhr.status + " " + (textStatus || "") + (errThrown ? " " + errThrown : ""); + main.message("发送请求失败(" + detail + "):请检查服务是否可用(含/trs_hub_api代理),详情见控制台与网络面板"); + console.error("[批量发送确认书] 请求失败:", detail, xhr); + }, beforeSend(jqXHR) { main.waitMe(true); }, From 00ae047e01469bc7b1b023701b49f0e64aad5781 Mon Sep 17 00:00:00 2001 From: hjhan Date: Fri, 21 Aug 2026 09:24:23 +0800 Subject: [PATCH 15/16] =?UTF-8?q?docs(swap):=20EQD-5320=20EmailTemplateSer?= =?UTF-8?q?vice=E8=A1=A5=E8=AE=BE=E8=AE=A1=E5=AE=88=E5=8D=AB=E6=B3=A8?= =?UTF-8?q?=E9=87=8A=E2=80=94=E2=80=94=E5=8D=A0=E4=BD=8D=E7=AC=A6=E6=9C=B4?= =?UTF-8?q?=E7=B4=A0=E6=9B=BF=E6=8D=A2/=E4=B8=8D=E5=81=9AHTML=E8=BD=AC?= =?UTF-8?q?=E4=B9=89=E5=9D=87=E4=B8=BA=E6=9C=89=E6=84=8F=E5=86=B3=E7=AD=96?= =?UTF-8?q?=EF=BC=8C=E4=B8=8Ebond-oms=20Java=20SwapEmailHandler=E5=90=8C?= =?UTF-8?q?=E6=9E=84=EF=BC=8C=E5=8B=BF=E5=8D=95=E8=BE=B9=E5=8D=87=E7=BA=A7?= =?UTF-8?q?=E6=A8=A1=E6=9D=BF=E5=BC=95=E6=93=8E=E6=88=96=E5=8A=A0=E8=BD=AC?= =?UTF-8?q?=E4=B9=89=EF=BC=8C=E6=96=B0=E5=8D=A0=E4=BD=8D=E7=AC=A6=E4=B8=A4?= =?UTF-8?q?=E4=BE=A7=E5=90=8C=E6=AD=A5?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- YLErpDAL/Modules/AppModule/EmailTemplateService.cs | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/YLErpDAL/Modules/AppModule/EmailTemplateService.cs b/YLErpDAL/Modules/AppModule/EmailTemplateService.cs index c98fb9d8..aeca2cbc 100644 --- a/YLErpDAL/Modules/AppModule/EmailTemplateService.cs +++ b/YLErpDAL/Modules/AppModule/EmailTemplateService.cs @@ -74,7 +74,12 @@ namespace YLErp.Modules.AppModule } /// - /// 生成邮件信息,如果template为null,返回null + /// 生成邮件信息,如果template为null,返回null。 + /// 【设计决策·勿单边"升级"】占位符为朴素文本替换(非模板引擎),与本表另一消费者 + /// bond-oms Java SwapEmailHandler.replaceMailPlaceholders 保持同构渲染语义—— + /// 单边引入 FreeMarker/Thymeleaf 等更强语法或 HTML 转义,会造成两侧发出内容不一致。 + /// 替换值(客户名称/文档编号等)不做 HTML 转义是有意为之:均为内部维护的可信数据; + /// 若未来要拼接用户自由输入的内容,必须两侧同步加转义。新占位符同样两侧同步加白名单。 /// public static MailInfoResultModel GenerateMailInfo(EmailTemplate template, MailInfoRequestModel reqModel) { From 0567955434b1d2b881636b919c6b5d88e2c3a864 Mon Sep 17 00:00:00 2001 From: hjhan Date: Fri, 21 Aug 2026 09:40:01 +0800 Subject: [PATCH 16/16] =?UTF-8?q?fix(swap):=20EQD-5320=20=E6=89=B9?= =?UTF-8?q?=E9=87=8F=E5=8F=91=E9=80=81=E7=A1=AE=E8=AE=A4=E4=B9=A6=E6=94=B9?= =?UTF-8?q?=E8=B5=B0C#=E6=9C=8D=E5=8A=A1=E7=AB=AF=E4=BB=A3=E7=90=86?= =?UTF-8?q?=E2=80=94=E2=80=94=E5=8E=9F=E5=89=8D=E7=AB=AF=E7=9B=B4=E8=BF=9E?= =?UTF-8?q?/trs=5Fhub=5Fapi=E5=8F=8D=E5=90=91=E4=BB=A3=E7=90=86=E5=9C=A8?= =?UTF-8?q?=E6=9C=AA=E9=85=8Dnginx=E7=9A=84=E7=8E=AF=E5=A2=83404(UAT?= =?UTF-8?q?=E5=AE=9E=E6=B5=8B)=EF=BC=8C=E4=B8=8E=E8=AE=A1=E7=AE=97?= =?UTF-8?q?=E5=99=A8(SendConfirmEamil=E5=90=8C=E6=AC=BEBondOmsInterface=5F?= =?UTF-8?q?BaseUrl=E6=9C=8D=E5=8A=A1=E7=AB=AF=E5=87=BA=E5=8F=A3)=E9=80=9A?= =?UTF-8?q?=E8=B7=AF=E4=B8=8D=E4=B8=80=E8=87=B4=EF=BC=9B=E6=96=B0=E5=A2=9E?= =?UTF-8?q?SwapEndConfirmService.BatchSendSettleEmail(POST=E4=BB=A3?= =?UTF-8?q?=E7=90=86bond-oms=20batchSend,=E5=A5=91=E7=BA=A6DTO+=E6=88=90?= =?UTF-8?q?=E8=B4=A5=E6=97=A5=E5=BF=97)=E4=B8=8ESwapTrade2Controller.Batch?= =?UTF-8?q?SendSettleEmail(=E9=80=97=E5=8F=B7id=E4=B8=B2=E9=98=B2=E5=91=86?= =?UTF-8?q?=E8=A7=A3=E6=9E=90)=EF=BC=9B=E5=89=8D=E7=AB=AF=E6=94=B9?= =?UTF-8?q?=E8=B0=83=E5=90=8C=E6=BA=90/swaptrade2=E7=AB=AF=E7=82=B9?= =?UTF-8?q?=E4=BF=9D=E7=95=99error=E5=85=9C=E5=BA=95=EF=BC=9B232/232?= =?UTF-8?q?=E5=89=8D=E7=AB=AF=E6=B5=8B=E8=AF=95=E9=80=9A=E8=BF=87?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../SwapModule/SwapEndConfirmService.cs | 42 +++++++++++++++++++ YLErpWeb/Controllers/SwapTrade2Controller.cs | 28 +++++++++++++ .../app/swaptrade/tradeEndConfirmList.js | 19 +++++---- 3 files changed, 80 insertions(+), 9 deletions(-) diff --git a/YLErpDAL/Modules/SwapModule/SwapEndConfirmService.cs b/YLErpDAL/Modules/SwapModule/SwapEndConfirmService.cs index 05c0ec86..0517f9c3 100644 --- a/YLErpDAL/Modules/SwapModule/SwapEndConfirmService.cs +++ b/YLErpDAL/Modules/SwapModule/SwapEndConfirmService.cs @@ -256,5 +256,47 @@ namespace YLErp.Modules.SwapModule } return "未配置邮件接口地址"; } + + /// + /// EQD-5320 批量发送结算确认书邮件:服务端代理 bond-oms /swap/email/settle/batchSend。 + /// 前端原直连 /trs_hub_api 反向代理(依赖 nginx 配置,未配的环境 404)——统一改走本代理, + /// 与债券计算器/SendEmail 同一条 BondOmsInterface_BaseUrl 出口,不再依赖前端网关。 + /// 返回 空串=成功;非空=失败原因(透传 bond-oms message)。 + /// + public string BatchSendSettleEmail(List swapFlowEventIds) + { + var baseUrl = Environment.GetEnvironmentVariable("BondOmsInterface_BaseUrl"); + if (string.IsNullOrEmpty(baseUrl)) + { + return "未配置邮件接口地址(BondOmsInterface_BaseUrl)"; + } + const string url = "/swap/email/settle/batchSend"; + var logger = LogFactory.GetLogger("SwapEndConfirm"); + var idsDesc = string.Join(",", swapFlowEventIds); + try + { + var result = new HttpHelper(baseUrl, null) + .PostRequestNoAuth(url, + new OmsSettleBatchSendReq { swapFlowEventIds = swapFlowEventIds }) + .Result; + logger.Info($"批量发送结算确认书: url={baseUrl}{url} ids=[{idsDesc}] → success={result?.success} message={result?.message}"); + if (result == null) + { + return "邮件服务无响应"; + } + return result.success ? "" : (result.message ?? "发送失败"); + } + catch (Exception ex) + { + logger.Error($"批量发送结算确认书异常: url={baseUrl}{url} ids=[{idsDesc}]", ex); + return "请求邮件服务异常:" + ex.GetBaseException().Message; + } + } + + /// bond-oms SettleEmailSendParam 契约(字段名须与 Java 端一致,Jackson 按 swapFlowEventIds 绑定) + private class OmsSettleBatchSendReq + { + public List swapFlowEventIds { get; set; } + } } } diff --git a/YLErpWeb/Controllers/SwapTrade2Controller.cs b/YLErpWeb/Controllers/SwapTrade2Controller.cs index 33c82881..91512f91 100644 --- a/YLErpWeb/Controllers/SwapTrade2Controller.cs +++ b/YLErpWeb/Controllers/SwapTrade2Controller.cs @@ -1207,6 +1207,34 @@ namespace YLErp.Web.Controllers return JsonSuccess(result); } + /// + /// EQD-5320 批量发送结算确认书邮件——经服务端代理 bond-oms(BondOmsInterface_BaseUrl 出口), + /// 替代前端直连 /trs_hub_api 反向代理(未配 nginx 的环境 404)。 + /// + /// 平仓流水id,逗号分隔 + [HttpPost] + public JsonResult BatchSendSettleEmail(string swapFlowEventIds) + { + if (string.IsNullOrWhiteSpace(swapFlowEventIds)) + { + return JsonError("请选择交易"); + } + var ids = new List(); + foreach (var s in swapFlowEventIds.Split(',', StringSplitOptions.RemoveEmptyEntries)) + { + if (long.TryParse(s.Trim(), out var id)) + { + ids.Add(id); + } + } + if (ids.Count == 0) + { + return JsonError("平仓流水id解析为空"); + } + var result = new SwapEndConfirmService(CurUser).BatchSendSettleEmail(ids); + return string.IsNullOrEmpty(result) ? JsonSuccess("发送成功") : JsonError(result); + } + } } diff --git a/YLErpWeb/wwwroot/Scripts/app/swaptrade/tradeEndConfirmList.js b/YLErpWeb/wwwroot/Scripts/app/swaptrade/tradeEndConfirmList.js index 90eb900d..f6ee26e4 100644 --- a/YLErpWeb/wwwroot/Scripts/app/swaptrade/tradeEndConfirmList.js +++ b/YLErpWeb/wwwroot/Scripts/app/swaptrade/tradeEndConfirmList.js @@ -167,29 +167,30 @@ function SendEmailEitherReport() { main.message("请选择普通交易"); return; } - var url = "/trs_hub_api/swap/email/settle/batchSend"; - var postData = { swapFlowEventIds: selIds } + // EQD-5320: 改走本系统后端代理(/swaptrade2/BatchSendSettleEmail → BondOmsInterface_BaseUrl → bond-oms), + // 与债券计算器同一条服务端出口;原直连 /trs_hub_api 反向代理在未配 nginx 的环境 404 + var url = "/swaptrade2/BatchSendSettleEmail"; + var postData = { swapFlowEventIds: selIds.join(',') } $.ajax({ type: "post", url: url, - data: JSON.stringify(postData), + data: postData, dataType: "json", - contentType:"application/json", success: function (res) { - // 代理/网关异常时可能返回非标准结构——统一兜底提示,绝不让点击"无反应" + // 兜底非标准返回结构,绝不让点击"无反应" if (res && res.success) { - main.message("发送成功(共" + selIds.length + "笔),详情见bond-oms日志[结算确认书邮件]"); + main.message(res.msg || ("发送成功(共" + selIds.length + "笔)")); SearchClick(); // 刷新列表以反映发送状态 } else { - var msg = (res && (res.message || res.msg)) || "发送失败:服务返回异常结构"; + var msg = (res && (res.msg || res.message)) || "发送失败:服务返回异常结构"; main.message(msg); console.error("[批量发送确认书] 业务失败:", res); } }, error: function (xhr, textStatus, errThrown) { - // 请求层失败:代理不通/超时/返回非JSON(如被登录页重定向)——此前无error回调导致点击"毫无反应" + // 请求层失败:超时/返回非JSON(如被登录页重定向) var detail = "HTTP " + xhr.status + " " + (textStatus || "") + (errThrown ? " " + errThrown : ""); - main.message("发送请求失败(" + detail + "):请检查服务是否可用(含/trs_hub_api代理),详情见控制台与网络面板"); + main.message("发送请求失败(" + detail + "):请检查服务是否可用,详情见控制台与网络面板"); console.error("[批量发送确认书] 请求失败:", detail, xhr); }, beforeSend(jqXHR) {