using System.Collections.Generic; using System.Linq; using YLErp.DBModels; namespace YLErp.Modules.SwapModule.Margin; /// /// 保证金计息模式(mode 5 初始预付金 / mode 6 追加预付金)的统一判断口径。 /// /// 依赖方向:本类位于 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 标识, /// 但在历史代码完全迁出前,需要一个统一判断点。 /// public static class MarginModes { /// 所有属于保证金的 InterestMode(派生自 ConsTrade.InterestMarginModels)。 public static readonly IReadOnlyCollection All = new HashSet(ConsTrade.InterestMarginModels); /// /// List 形态,供 EF Core LINQ 表达式用(HashSet.Contains 无法翻译成 SQL)。 /// 内容派生自框架常量 ConsTrade.InterestMarginModels(单一真源),本类仅做形态适配。 /// public static readonly List ForLinq = new List(ConsTrade.InterestMarginModels); /// 判断 mode 是否属于保证金(非 LINQ 场景用)。 public static bool Contains(int interestMode) => All.Contains(interestMode); /// 固定值 + 保证金 mode 集合(固定值/初始预付金/追加预付金)。 /// 用于 EOD 场景判断"计息基数取 InterestPrincipalFix 而非持仓名义本金"的腿。 /// 保证金部分派生自 ConsTrade.InterestMarginModels,固定值额外并入。 public static readonly IReadOnlyCollection FixedAmountAndMargin = new HashSet(ConsTrade.InterestMarginModels) { (int)InterestModeEnum.固定值, }; /// 判断 mode 是否为固定值或保证金。 public static bool IsFixedAmountOrMargin(int interestMode) => FixedAmountAndMargin.Contains(interestMode); }