using System; using System.Collections.Generic; using YLErp.DBModels; namespace YLErp.Modules.SwapModule.InterestLegs; /// /// 利息腿策略工厂。按 InterestMode 返回对应策略实例。 /// 替换原 SwapDealService.CalcNotionalByMode 的 switch,收敛 mode 分发逻辑到一处。 /// /// 当前界面活跃 mode:1 固定值 / 2 合约名义本金规模 / 9 标的期初全价。 /// 注:mode 5/6 预付金已迁出本上下文(见 YLErp.Modules.SwapModule.Margin / MarginLeg),不再作为利息腿注册。 /// 死代码 mode 3/4 不注册;半死 mode 7/8 不注册(界面已注释)。 /// 传入未注册的 mode 会抛异常,防止静默走默认分支。 /// public static class InterestLegStrategyFactory { private static readonly Dictionary _strategies = new() { [InterestModeEnum.固定值] = new FixedNotionalLeg(), [InterestModeEnum.合约名义本金规模] = new ContractNotionalLeg(), [InterestModeEnum.标的期初全价] = new UnderlyingFullPriceLeg(), }; /// 按 mode 返回对应策略。未注册的 mode 抛 ArgumentException。 public static IInterestLegStrategy Get(InterestModeEnum mode) { if (_strategies.TryGetValue(mode, out var strategy)) return strategy; throw new ArgumentException($"未注册的计息模式: {mode}(mode 3/4/7/8 当前未启用)", nameof(mode)); } /// 按 mode 值返回对应策略,便于调用方直接传 int。 public static IInterestLegStrategy Get(int mode) => Get((InterestModeEnum)mode); }