From 44e24b31724504e39efcee9a1ff99888e1fb2332 Mon Sep 17 00:00:00 2001 From: hjhan Date: Sun, 16 Aug 2026 10:47:45 +0800 Subject: [PATCH] =?UTF-8?q?refactor(margin):=20MarginModes=20=E5=8F=8D?= =?UTF-8?q?=E8=BD=AC=E4=BE=9D=E8=B5=96=20ConsTrade.InterestMarginModels=20?= =?UTF-8?q?=E5=B9=B6=E5=88=A0=E9=99=A4=20premiumModes=20=E7=A1=AC=E7=BC=96?= =?UTF-8?q?=E7=A0=81=E5=89=AF=E6=9C=AC?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - MarginModes.All/ForLinq/FixedAmountAndMargin 改为由框架常量 ConsTrade.InterestMarginModels 派生,消除 DAL 层独立重写集合(单一真源在 Core 层,本类退化为形态包装,避免新增保证金形态时口径分裂) - SwapEodPositionService.premiumModes 局部 new List 字面量替换为 MarginModes.ForLinq(DAL 内部冗余副本消除) - 重写 MarginModes.cs 过时的“复制 6 次/待收敛”注释,改为记录依赖方向与收敛历史;ForLinq 注释改为“派生自框架常量,仅做形态适配” - 更新 MarginModesTest 类注释与一致性测试注释以反映派生关系 - 验证:YLErpDAL/UnitTestProject 编译 0 错误;MarginModesTest 5/5 通过 --- .../SwapModule/Margin/MarginModesTest.cs | 4 +- .../Modules/SwapModule/Margin/MarginModes.cs | 42 ++++++++----------- .../SwapModule/SwapEodPositionService.cs | 2 +- 3 files changed, 21 insertions(+), 27 deletions(-) diff --git a/UnitTestProject/Modules/SwapModule/Margin/MarginModesTest.cs b/UnitTestProject/Modules/SwapModule/Margin/MarginModesTest.cs index edf94c89..7732e13b 100644 --- a/UnitTestProject/Modules/SwapModule/Margin/MarginModesTest.cs +++ b/UnitTestProject/Modules/SwapModule/Margin/MarginModesTest.cs @@ -8,7 +8,7 @@ namespace UnitTestProject.Modules.SwapModule.Margin { /// /// MarginModes 统一判断口径测试。 - /// 验证它和现有散落的 marginTypes/InterestMarginModels/premiumModes 内容一致。 + /// 验证 MarginModes 由框架常量 ConsTrade.InterestMarginModels 派生,内容一致。 /// [TestClass] public class MarginModesTest @@ -37,7 +37,7 @@ namespace UnitTestProject.Modules.SwapModule.Margin Assert.IsFalse(MarginModes.Contains((int)InterestModeEnum.标的期初全价)); } - /// 守护:和 ConsTrade.InterestMarginModels 内容必须一致(迁移期对齐)。 + /// 回归护栏:MarginModes 由 ConsTrade.InterestMarginModels 派生,内容须一致(防止有人又独立重写集合导致口径分裂)。 [TestMethod] public void 与ConsTradeInterestMarginModels内容一致() { diff --git a/YLErpDAL/Modules/SwapModule/Margin/MarginModes.cs b/YLErpDAL/Modules/SwapModule/Margin/MarginModes.cs index 359e3fc9..99346d4b 100644 --- a/YLErpDAL/Modules/SwapModule/Margin/MarginModes.cs +++ b/YLErpDAL/Modules/SwapModule/Margin/MarginModes.cs @@ -7,14 +7,18 @@ namespace YLErp.Modules.SwapModule.Margin; /// /// 保证金计息模式(mode 5 初始预付金 / mode 6 追加预付金)的统一判断口径。 /// -/// 现状(待收敛):同一集合 {初始预付金, 追加预付金} 在代码里复制了至少 6 次—— -/// ConsTrade.InterestMarginModels(框架级) -/// SwapEodPositionService.marginTypes(实例字段) -/// SwapEodPositionService.premiumModes(局部变量) -/// SwapEventEmailService.marginTypes -/// EodClientBalanceCalc.marginTypes -/// ClientBalanceUtility.marginTypes -/// 任何一处漏改(如新增保证金形态)都会导致口径分裂。本类收敛到单一来源。 +/// 依赖方向:本类位于 YLErpDAL 层,单一真源是框架层常量 +/// (YLErp.DBModels)。Core 不能反向依赖 DAL, +/// 故本类的集合直接由该框架常量派生(new HashSet/List),而非独立重写—— +/// 任何一处要新增保证金形态,只需改 ConsTrade.InterestMarginModels 即全局生效。 +/// +/// 收敛历史:早期同一集合 {初始预付金, 追加预付金} 在代码里被复制多次 +/// (ConsTrade.InterestMarginModels / SwapEodPositionService.marginTypes / +/// SwapEodPositionService.premiumModes / SwapEventEmailService.marginTypes / +/// EodClientBalanceCalc.marginTypes / ClientBalanceUtility.marginTypes)。 +/// 现余额/邮件/利息等入口已改用本类;SwapEodPositionService.premiumModes 局部变量 +/// 也已替换为 MarginModes.ForLinq。ConsTrade.InterestMarginModels 作为框架级常量保留 +/// (它是唯一真源,并非冗余)。 /// /// 注意:这里的"保证金 mode"是现有系统把保证金错误建模为计息腿的历史遗留。 /// 按 Margin 限界上下文的设计方向,未来保证金不应用 InterestMode 标识, @@ -22,34 +26,24 @@ namespace YLErp.Modules.SwapModule.Margin; /// public static class MarginModes { - /// 所有属于保证金的 InterestMode(初始预付金 / 追加预付金)。 - public static readonly IReadOnlyCollection All = new HashSet - { - (int)InterestModeEnum.初始预付金, - (int)InterestModeEnum.追加预付金, - }; + /// 所有属于保证金的 InterestMode(派生自 ConsTrade.InterestMarginModels)。 + public static readonly IReadOnlyCollection All = new HashSet(ConsTrade.InterestMarginModels); /// /// List 形态,供 EF Core LINQ 表达式用(HashSet.Contains 无法翻译成 SQL)。 - /// 替代 ConsTrade.InterestMarginModels。 + /// 内容派生自框架常量 ConsTrade.InterestMarginModels(单一真源),本类仅做形态适配。 /// - public static readonly List ForLinq = new() - { - (int)InterestModeEnum.初始预付金, - (int)InterestModeEnum.追加预付金, - }; + public static readonly List ForLinq = new List(ConsTrade.InterestMarginModels); /// 判断 mode 是否属于保证金(非 LINQ 场景用)。 public static bool Contains(int interestMode) => All.Contains(interestMode); /// 固定值 + 保证金 mode 集合(固定值/初始预付金/追加预付金)。 /// 用于 EOD 场景判断"计息基数取 InterestPrincipalFix 而非持仓名义本金"的腿。 - /// 替代 SwapEodPositionService 中 3 处内联 new List{固定值, 初始预付金, 追加预付金}。 - public static readonly IReadOnlyCollection FixedAmountAndMargin = new HashSet + /// 保证金部分派生自 ConsTrade.InterestMarginModels,固定值额外并入。 + public static readonly IReadOnlyCollection FixedAmountAndMargin = new HashSet(ConsTrade.InterestMarginModels) { (int)InterestModeEnum.固定值, - (int)InterestModeEnum.初始预付金, - (int)InterestModeEnum.追加预付金, }; /// 判断 mode 是否为固定值或保证金。 diff --git a/YLErpDAL/Modules/SwapModule/SwapEodPositionService.cs b/YLErpDAL/Modules/SwapModule/SwapEodPositionService.cs index d6fa2a48..d96ed571 100644 --- a/YLErpDAL/Modules/SwapModule/SwapEodPositionService.cs +++ b/YLErpDAL/Modules/SwapModule/SwapEodPositionService.cs @@ -615,7 +615,7 @@ namespace YLErp.Modules.SwapModule autoInterests.ForEach(x => x.PayDate = settleDate); - var premiumModes = new List() { (int)InterestModeEnum.初始预付金, (int)InterestModeEnum.追加预付金 }; + var premiumModes = MarginModes.ForLinq; var premiumInterests = autoInterests.Where(x => premiumModes.Contains(x.InterestMode)).ToList(); var interestLegs = autoInterests.Where(x => !premiumModes.Contains(x.InterestMode)).ToList();