test(swap): 回归测试对齐 GLMS-20260701-0008 四次部分平仓快照
生产 deal 又平仓两次(共四次),实时预付金腿 InterestPrincipalFix 由 73,260 降至 66,813.12(4 次返还 9,900+15,840+3,663+2,783.88=32,186.88; 99,000−32,186.88=66,813.12,与 dev 库实时腿完全勾稽)。 - SwapUnwindPrepayOrigVsRealBugTdd:RemainingFix 常量 73,260→66,813.12; 头部注释同步为四次平仓;新增 GLMS20260701_四次部分平仓_LiveSnapshot 用例, 把 4 次平仓真实数据硬编码为忠实回归(日后该 deal 再平仓需同步更新)。 - 纳入此前遗漏提交的连库诊断测试 GLMS20260701DbDiagnoseTest.cs (使用 DbContextFactory 取连接串,无硬编码密码,安全)。 验证:dotnet test --filter SwapUnwindPrepay → 26 passed(19+7)失败 0; YLErpDAL / UnitTestProject 编译通过(仅既有警告)。
This commit is contained in:
@@ -8,11 +8,12 @@ namespace YLErp.Modules.SwapModule
|
||||
/// ---------------------------------------------------------------
|
||||
/// 生产铁证 GLMS-20260701-0008(SwapTradeId=1993,dev DB 192.168.2.96 / glms_yltrs_ylcms):
|
||||
/// 预付金腿(InterestMode=5) 双轨记录——
|
||||
/// orig 35798 (IsInitial=1, PosiDirection=0, InterestPrincipalFix=99,000) ← 期初腿,恒为初始值
|
||||
/// real 35871 (IsInitial=0, PositionId=35798, InterestPrincipalFix=73,260) ← 实时腿,已扣减 2 次平仓(9,900+15,840)
|
||||
/// orig 35798 (IsInitial=1, PosiDirection=0, InterestPrincipalFix=99,000) ← 期初腿,恒为初始值
|
||||
/// real 35871 (IsInitial=0, PositionId=35798, InterestPrincipalFix=66,813.12) ← 实时腿,已扣减 4 次平仓
|
||||
/// (9,900 + 15,840 + 3,663 + 2,783.88 = 32,186.88;99,000 − 32,186.88 = 66,813.12,与 dev 库实时腿完全勾稽)
|
||||
///
|
||||
/// 根因:GetUnwindInterests 的利息腿迭代源取 origPositions(IsInitial=1),其预付金腿
|
||||
/// InterestPrincipalFix 恒=99,000;而"当前剩余本金"73,260 存在 real 腿。GetInterests 算
|
||||
/// InterestPrincipalFix 恒=99,000;而"当前剩余本金"66,813.12 存在 real 腿。GetInterests 算
|
||||
/// closePrincipal = Fix × closePercent 与预付金计息基数 orginPv 都读 position.InterestPrincipalFix,
|
||||
/// 于是多次部分平仓后打开平仓页,"返回预付金"仍按初始 99,000 计算——完全不对。
|
||||
/// 首次平仓时 orig==real,掩盖了该 bug(解释"为何只修好一次部分平仓")。
|
||||
@@ -33,7 +34,7 @@ namespace YLErp.Modules.SwapModule
|
||||
private const long OrigId = 35798;
|
||||
private const long RealId = 35871;
|
||||
private const decimal InitialFix = 99_000m; // orig 腿初始本金
|
||||
private const decimal RemainingFix = 73_260m; // real 腿剩余本金(已扣减 2 次平仓)
|
||||
private const decimal RemainingFix = 66_813.12m; // real 腿剩余本金(已扣减 4 次平仓 9,900+15,840+3,663+2,783.88=32,186.88)
|
||||
|
||||
private static swap_position OrigPrepay(decimal fix = InitialFix, int mode = (int)InterestModeEnum.初始预付金)
|
||||
=> new swap_position
|
||||
@@ -70,7 +71,7 @@ namespace YLErp.Modules.SwapModule
|
||||
|
||||
Assert.AreEqual(1, result.Count, "应保留 1 条利息腿");
|
||||
Assert.AreEqual(RemainingFix, result[0].InterestPrincipalFix,
|
||||
"多次部分平仓后:预付金腿本金应=实时腿剩余本金 73,260,而非原始腿初始值 99,000(bug 症状)");
|
||||
"多次部分平仓后:预付金腿本金应=实时腿剩余本金 66,813.12,而非原始腿初始值 99,000(bug 症状)");
|
||||
// 必须是 Clone,不能污染原始腿(原始腿要保留 99,000 供其他路径/审计)
|
||||
Assert.AreEqual(InitialFix, origs[0].InterestPrincipalFix,
|
||||
"修复必须走 Clone,绝不能就地改写 origPositions 的初始本金");
|
||||
@@ -148,5 +149,30 @@ namespace YLErp.Modules.SwapModule
|
||||
Assert.AreEqual(OrigId, result[0].id, "保留的应是预付金利息腿");
|
||||
Assert.AreEqual(RemainingFix, result[0].InterestPrincipalFix, "且其本金已对齐实时剩余本金");
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 生产 Live Snapshot(2026-07-16 11:00,dev DB 192.168.2.96 / glms_yltrs_ylcms 直连核实):
|
||||
/// GLMS-20260701-0008 已 4 次部分平仓。预付金腿(orig 35798 / real 35871) 实际值——
|
||||
/// orig InterestPrincipalFix = 99,000(期初腿恒为初始值)
|
||||
/// real InterestPrincipalFix = 66,813.12(= 99,000 − 9,900 − 15,840 − 3,663 − 2,783.88)
|
||||
/// swap_flow_event 4 次平仓返还:9,900 / 15,840 / 3,663 / 2,783.88,合计 32,186.88。
|
||||
/// 本用例把这份真实数据硬编码进来,断言修复后取实时腿剩余本金 66,813.12(非 99,000),
|
||||
/// 作为该 deal 在此快照点的忠实回归;日后该 deal 再被平仓,剩余本金会变,本例仍应同步更新。
|
||||
/// </summary>
|
||||
[TestMethod]
|
||||
public void GLMS20260701_四次部分平仓_LiveSnapshot_预付金腿应取实时腿剩余66813_12()
|
||||
{
|
||||
// 与生产一致的双轨数据:期初腿 99,000 / 实时腿 4 次平仓后 66,813.12
|
||||
var origs = new List<swap_position> { OrigPrepay(InitialFix) };
|
||||
var reals = new List<swap_position> { RealPrepay(fix: 66_813.12m) };
|
||||
|
||||
var result = SwapDealService.ResolveInterestLegPositions(origs, reals);
|
||||
|
||||
Assert.AreEqual(1, result.Count);
|
||||
Assert.AreEqual(66_813.12m, result[0].InterestPrincipalFix,
|
||||
"4 次部分平仓后:预付金腿本金应=实时腿剩余本金 66,813.12,而非原始腿初始值 99,000");
|
||||
// 不污染原始腿
|
||||
Assert.AreEqual(InitialFix, origs[0].InterestPrincipalFix, "修复必须走 Clone,不能改写 origPositions 的初始本金 99,000");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user