Files
zszq-trs/YLErpDAL/Helpers/BondPriceConverter.cs
T
hjhan 782e1f6a7a refactor(swap): 债券价格÷100转换收敛到BondPriceConverter统一入口
消除9处价格转换字面量(*0.01m/*100),统一走BondPriceConverter.ToStorage/ToDisplay。
- 新增YLErpDAL/Helpers/BondPriceConverter.cs(含可空重载)
- 批次1(危险字面量): BondPaymentService/RealtimePnlCalc/RealTimeClientBanlanceService/SwapTradeAutoService
- 批次2-4(调用收敛): SwapFlowService/SwapFlowImportService/SwapEndConfirmService/EodPriceProvider/EodPriceQueryService
- RealtimePnlCalc:601/602价格×数量维度交织处加注释,不机械合并

不改bondPriceMultiple常量值,纯调用方式收敛。SwapModule 155测试全绿,行为不变。
2026-07-03 08:22:27 +08:00

61 lines
3.0 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;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace YLErp.Helpers
{
/// <summary>
/// 债券价格展示态 ↔ 入库态 统一转换入口。
/// ============================================================================
/// 背景:债券价格习惯用"面值的百分比"报价(如全价 99.50 = 面值 100 的 99.5%)。
/// 入库时统一存为小数形式(0.995),展示时再 ×100 还原为 99.5。
///
/// 过去这组转换散落在 11+ 个文件、87 处,多数用 ConsGlobal.bondPriceMultiple/
/// bondShowPriceMultiple,但有 4 处用字面量 *0.01m / *100 绕过常量(改常量值时不会跟随,
/// 极易引入 Bug)。本类收敛所有调用入口,杜绝散落。
///
/// 命名口径(见《互换价格字段命名规范决策文档》):
/// ToStorage = 展示态(99.5) → 入库态(0.995) 即 × bondPriceMultiple(0.01)
/// ToDisplay = 入库态(0.995) → 展示态(99.5) 即 × bondShowPriceMultiple(100)
/// ============================================================================
/// </summary>
public static class BondPriceConverter
{
/// <summary>
/// 展示态 → 入库态。债券报价(如 99.5)转为库内小数(0.995)。
/// 用于:成交流水导入、EOD 价格缓存、债券付息计算等入库/计算场景。
/// </summary>
/// <param name="displayPrice">展示态价格(面值百分比形式,如 99.5</param>
/// <returns>入库态价格(小数形式,如 0.995</returns>
public static decimal ToStorage(decimal displayPrice)
{
return displayPrice * ConsGlobal.bondPriceMultiple;
}
/// <summary>
/// 入库态 → 展示态。库内小数(0.995)转为债券报价(99.5)。
/// 用于:列表查询、详情展示、报表导出等展示场景。
/// </summary>
/// <param name="storagePrice">入库态价格(小数形式,如 0.995</param>
/// <returns>展示态价格(面值百分比形式,如 99.5</returns>
public static decimal ToDisplay(decimal storagePrice)
{
return storagePrice * ConsGlobal.bondShowPriceMultiple;
}
/// <summary>可空重载:null 保持 null 语义(与原 *= ConsGlobal.bondPriceMultiple 行为一致)</summary>
public static decimal? ToStorage(decimal? displayPrice)
{
return displayPrice.HasValue ? displayPrice.Value * ConsGlobal.bondPriceMultiple : displayPrice;
}
/// <summary>可空重载:null 保持 null 语义(与原 *= ConsGlobal.bondShowPriceMultiple 行为一致)</summary>
public static decimal? ToDisplay(decimal? storagePrice)
{
return storagePrice.HasValue ? storagePrice.Value * ConsGlobal.bondShowPriceMultiple : storagePrice;
}
}
}