新增(零生产改动): - InterestLegs/PrepayLeg.cs mode 5 初始预付金 / mode 6 追加预付金 共用。 计息基数=InterestPrincipalFix, 平仓本金=Fix×closePercent。 构造时校验mode合法性(只接受5/6)。 方向翻转/orginPv重映射等独有逻辑后续单独抽。 - InterestLegs/InterestLegStrategyFactory.cs 按InterestMode返回对应策略, 收敛switch分发。 死代码mode 3/4/7/8不注册, 传入会抛ArgumentException。 测试(14个全过): - 预付金: 部分平仓/全平/非法mode构造 - 工厂: 各活跃mode返回正确类型/未注册mode抛异常/int重载等价 fixing接入尝试(已回退): - 尝试用Fr007IndexFixer.Instance替换SwapDealService的6处取价 - 发现问题: 静态Instance绕过TryGetFloatRate(virtual)接缝, 破坏测试stub机制(CI_007/CI_008失败) - 已回退, 下次改用实例级IIndexFixer(委托TryGetFloatRate)方式接入
37 lines
1.7 KiB
C#
37 lines
1.7 KiB
C#
using System;
|
||
using System.Collections.Generic;
|
||
using YLErp.DBModels;
|
||
|
||
namespace YLErp.Modules.SwapModule.InterestLegs;
|
||
|
||
/// <summary>
|
||
/// 利息腿策略工厂。按 InterestMode 返回对应策略实例。
|
||
/// 替换原 SwapDealService.CalcNotionalByMode 的 switch,收敛 mode 分发逻辑到一处。
|
||
///
|
||
/// 当前界面活跃 mode:1 固定值 / 2 合约名义本金规模 / 9 标的期初全价 / 5/6 预付金。
|
||
/// 死代码 mode 3/4 不注册;半死 mode 7/8 不注册(界面已注释)。
|
||
/// 传入未注册的 mode 会抛异常,防止静默走默认分支。
|
||
/// </summary>
|
||
public static class InterestLegStrategyFactory
|
||
{
|
||
private static readonly Dictionary<InterestModeEnum, IInterestLegStrategy> _strategies = new()
|
||
{
|
||
[InterestModeEnum.固定值] = new FixedNotionalLeg(),
|
||
[InterestModeEnum.合约名义本金规模] = new ContractNotionalLeg(),
|
||
[InterestModeEnum.标的期初全价] = new UnderlyingFullPriceLeg(),
|
||
[InterestModeEnum.初始预付金] = new PrepayLeg(InterestModeEnum.初始预付金),
|
||
[InterestModeEnum.追加预付金] = new PrepayLeg(InterestModeEnum.追加预付金),
|
||
};
|
||
|
||
/// <summary>按 mode 返回对应策略。未注册的 mode 抛 ArgumentException。</summary>
|
||
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));
|
||
}
|
||
|
||
/// <summary>按 mode 值返回对应策略,便于调用方直接传 int。</summary>
|
||
public static IInterestLegStrategy Get(int mode) => Get((InterestModeEnum)mode);
|
||
}
|