Files
zszq-trs/YLErpDAL/Modules/SwapModule/Margin/MarginModes.cs
T
hjhan 44e24b3172 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 通过
2026-08-16 10:47:45 +08:00

52 lines
2.9 KiB
C#
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
using System.Collections.Generic;
using System.Linq;
using YLErp.DBModels;
namespace YLErp.Modules.SwapModule.Margin;
/// <summary>
/// 保证金计息模式(mode 5 初始预付金 / mode 6 追加预付金)的统一判断口径。
///
/// 依赖方向:本类位于 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 标识,
/// 但在历史代码完全迁出前,需要一个统一判断点。
/// </summary>
public static class MarginModes
{
/// <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(单一真源),本类仅做形态适配。
/// </summary>
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 而非持仓名义本金"的腿。
/// 保证金部分派生自 ConsTrade.InterestMarginModels,固定值额外并入。</summary>
public static readonly IReadOnlyCollection<int> FixedAmountAndMargin = new HashSet<int>(ConsTrade.InterestMarginModels)
{
(int)InterestModeEnum.固定值,
};
/// <summary>判断 mode 是否为固定值或保证金。</summary>
public static bool IsFixedAmountOrMargin(int interestMode) => FixedAmountAndMargin.Contains(interestMode);
}