refactor(margin): MarginModes 反转依赖 ConsTrade.InterestMarginModels 并删除 premiumModes 硬编码副本
- 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 通过
This commit is contained in:
@@ -8,7 +8,7 @@ namespace UnitTestProject.Modules.SwapModule.Margin
|
||||
{
|
||||
/// <summary>
|
||||
/// MarginModes 统一判断口径测试。
|
||||
/// 验证它和现有散落的 marginTypes/InterestMarginModels/premiumModes 内容一致。
|
||||
/// 验证 MarginModes 由框架常量 ConsTrade.InterestMarginModels 派生,内容一致。
|
||||
/// </summary>
|
||||
[TestClass]
|
||||
public class MarginModesTest
|
||||
@@ -37,7 +37,7 @@ namespace UnitTestProject.Modules.SwapModule.Margin
|
||||
Assert.IsFalse(MarginModes.Contains((int)InterestModeEnum.标的期初全价));
|
||||
}
|
||||
|
||||
/// <summary>守护:和 ConsTrade.InterestMarginModels 内容必须一致(迁移期对齐)。</summary>
|
||||
/// <summary>回归护栏:MarginModes 由 ConsTrade.InterestMarginModels 派生,内容须一致(防止有人又独立重写集合导致口径分裂)。</summary>
|
||||
[TestMethod]
|
||||
public void 与ConsTradeInterestMarginModels内容一致()
|
||||
{
|
||||
|
||||
@@ -7,14 +7,18 @@ namespace YLErp.Modules.SwapModule.Margin;
|
||||
/// <summary>
|
||||
/// 保证金计息模式(mode 5 初始预付金 / mode 6 追加预付金)的统一判断口径。
|
||||
///
|
||||
/// 现状(待收敛):同一集合 {初始预付金, 追加预付金} 在代码里复制了至少 6 次——
|
||||
/// ConsTrade.InterestMarginModels(框架级)
|
||||
/// SwapEodPositionService.marginTypes(实例字段)
|
||||
/// SwapEodPositionService.premiumModes(局部变量)
|
||||
/// SwapEventEmailService.marginTypes
|
||||
/// EodClientBalanceCalc.marginTypes
|
||||
/// ClientBalanceUtility.marginTypes
|
||||
/// 任何一处漏改(如新增保证金形态)都会导致口径分裂。本类收敛到单一来源。
|
||||
/// 依赖方向:本类位于 YLErpDAL 层,单一真源是框架层常量
|
||||
/// <see cref="ConsTrade.InterestMarginModels"/>(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;
|
||||
/// </summary>
|
||||
public static class MarginModes
|
||||
{
|
||||
/// <summary>所有属于保证金的 InterestMode(初始预付金 / 追加预付金)。</summary>
|
||||
public static readonly IReadOnlyCollection<int> All = new HashSet<int>
|
||||
{
|
||||
(int)InterestModeEnum.初始预付金,
|
||||
(int)InterestModeEnum.追加预付金,
|
||||
};
|
||||
/// <summary>所有属于保证金的 InterestMode(派生自 ConsTrade.InterestMarginModels)。</summary>
|
||||
public static readonly IReadOnlyCollection<int> All = new HashSet<int>(ConsTrade.InterestMarginModels);
|
||||
|
||||
/// <summary>
|
||||
/// List 形态,供 EF Core LINQ 表达式用(HashSet.Contains 无法翻译成 SQL)。
|
||||
/// 替代 ConsTrade.InterestMarginModels。
|
||||
/// 内容派生自框架常量 ConsTrade.InterestMarginModels(单一真源),本类仅做形态适配。
|
||||
/// </summary>
|
||||
public static readonly List<int> ForLinq = new()
|
||||
{
|
||||
(int)InterestModeEnum.初始预付金,
|
||||
(int)InterestModeEnum.追加预付金,
|
||||
};
|
||||
public static readonly List<int> ForLinq = new List<int>(ConsTrade.InterestMarginModels);
|
||||
|
||||
/// <summary>判断 mode 是否属于保证金(非 LINQ 场景用)。</summary>
|
||||
public static bool Contains(int interestMode) => All.Contains(interestMode);
|
||||
|
||||
/// <summary>固定值 + 保证金 mode 集合(固定值/初始预付金/追加预付金)。
|
||||
/// 用于 EOD 场景判断"计息基数取 InterestPrincipalFix 而非持仓名义本金"的腿。
|
||||
/// 替代 SwapEodPositionService 中 3 处内联 new List{固定值, 初始预付金, 追加预付金}。</summary>
|
||||
public static readonly IReadOnlyCollection<int> FixedAmountAndMargin = new HashSet<int>
|
||||
/// 保证金部分派生自 ConsTrade.InterestMarginModels,固定值额外并入。</summary>
|
||||
public static readonly IReadOnlyCollection<int> FixedAmountAndMargin = new HashSet<int>(ConsTrade.InterestMarginModels)
|
||||
{
|
||||
(int)InterestModeEnum.固定值,
|
||||
(int)InterestModeEnum.初始预付金,
|
||||
(int)InterestModeEnum.追加预付金,
|
||||
};
|
||||
|
||||
/// <summary>判断 mode 是否为固定值或保证金。</summary>
|
||||
|
||||
@@ -615,7 +615,7 @@ namespace YLErp.Modules.SwapModule
|
||||
|
||||
autoInterests.ForEach(x => x.PayDate = settleDate);
|
||||
|
||||
var premiumModes = new List<int>() { (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();
|
||||
|
||||
|
||||
Reference in New Issue
Block a user