候选F: 3处内联 new List{固定值,初始预付金,追加预付金} → MarginModes.FixedAmountAndMargin
候选I: 7处内联 收取?Buy:Sell → DirectionRatio.RateType(direction)
SwapModule零回归(7基线/510通过)
58 lines
2.6 KiB
C#
58 lines
2.6 KiB
C#
using System.Collections.Generic;
|
|
using System.Linq;
|
|
using YLErp.DBModels;
|
|
|
|
namespace YLErp.Modules.SwapModule.Margin;
|
|
|
|
/// <summary>
|
|
/// 保证金计息模式(mode 5 初始预付金 / mode 6 追加预付金)的统一判断口径。
|
|
///
|
|
/// 现状(待收敛):同一集合 {初始预付金, 追加预付金} 在代码里复制了至少 6 次——
|
|
/// ConsTrade.InterestMarginModels(框架级)
|
|
/// SwapEodPositionService.marginTypes(实例字段)
|
|
/// SwapEodPositionService.premiumModes(局部变量)
|
|
/// SwapEventEmailService.marginTypes
|
|
/// EodClientBalanceCalc.marginTypes
|
|
/// ClientBalanceUtility.marginTypes
|
|
/// 任何一处漏改(如新增保证金形态)都会导致口径分裂。本类收敛到单一来源。
|
|
///
|
|
/// 注意:这里的"保证金 mode"是现有系统把保证金错误建模为计息腿的历史遗留。
|
|
/// 按 Margin 限界上下文的设计方向,未来保证金不应用 InterestMode 标识,
|
|
/// 但在历史代码完全迁出前,需要一个统一判断点。
|
|
/// </summary>
|
|
public static class MarginModes
|
|
{
|
|
/// <summary>所有属于保证金的 InterestMode(初始预付金 / 追加预付金)。</summary>
|
|
public static readonly IReadOnlyCollection<int> All = new HashSet<int>
|
|
{
|
|
(int)InterestModeEnum.初始预付金,
|
|
(int)InterestModeEnum.追加预付金,
|
|
};
|
|
|
|
/// <summary>
|
|
/// List 形态,供 EF Core LINQ 表达式用(HashSet.Contains 无法翻译成 SQL)。
|
|
/// 替代 ConsTrade.InterestMarginModels。
|
|
/// </summary>
|
|
public static readonly List<int> ForLinq = new()
|
|
{
|
|
(int)InterestModeEnum.初始预付金,
|
|
(int)InterestModeEnum.追加预付金,
|
|
};
|
|
|
|
/// <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>
|
|
{
|
|
(int)InterestModeEnum.固定值,
|
|
(int)InterestModeEnum.初始预付金,
|
|
(int)InterestModeEnum.追加预付金,
|
|
};
|
|
|
|
/// <summary>判断 mode 是否为固定值或保证金。</summary>
|
|
public static bool IsFixedAmountOrMargin(int interestMode) => FixedAmountAndMargin.Contains(interestMode);
|
|
}
|