refactor(swap): 提取 EodSwapPositionQueries.ActiveByTradeAndDate 收口日终有效持仓查询
将 eod_swap_position 上'SwapTradeId + ValueDate + !Invalid'的 5 处重复谓词 (SwapEodPositionService.cs:2133/2195/2246/2487、ConfirmationGenerateContext.cs:2868) 收口到 EodSwapPositionQueries.ActiveByTradeAndDate(tradeId, valueDate), 与 SwapPositionQueries.ActiveByTrade 同构,零逻辑变更。
This commit is contained in:
@@ -0,0 +1,19 @@
|
||||
using System;
|
||||
using System.Linq;
|
||||
using YLErp.DBModels;
|
||||
|
||||
namespace YLErp.Modules.SwapModule
|
||||
{
|
||||
/// <summary>
|
||||
/// eod_swap_position 查询收口(Query Object)。
|
||||
/// 规则"某交易某日日终的有效持仓 = SwapTradeId 匹配 + ValueDate 匹配 + 未作废(!Invalid)"集中于此,
|
||||
/// 避免多处复制同一谓词导致语义漂移(漏写 !Invalid 即静默出 bug)。
|
||||
/// 仅返回 IQueryable,不调用 SaveChanges,不破坏跟踪/Include/事务边界。
|
||||
/// </summary>
|
||||
public static class EodSwapPositionQueries
|
||||
{
|
||||
public static IQueryable<eod_swap_position> ActiveByTradeAndDate(
|
||||
this IQueryable<eod_swap_position> query, int tradeId, DateTime valueDate)
|
||||
=> query.Where(x => x.SwapTradeId == tradeId && x.ValueDate == valueDate && !x.Invalid);
|
||||
}
|
||||
}
|
||||
@@ -2130,7 +2130,7 @@ namespace YLErp.Modules.SwapModule
|
||||
var tradeSpan = DbContext.trade_span.FirstOrDefault(x => x.TradeId == td.id && x.ValueDate == settleDate);
|
||||
// eod_swap 是交易级汇总;eod_swap_position 是浮动腿、利息腿和保证金腿的明细。
|
||||
// 以下先按日终明细拆腿,再按框架合约展示口径汇总。
|
||||
var eodSwapPositions = DbContext.eod_swap_position.Where(x => x.SwapTradeId == td.id && x.ValueDate == settleDate && !x.Invalid).ToList();
|
||||
var eodSwapPositions = DbContext.eod_swap_position.ActiveByTradeAndDate(td.id, settleDate).ToList();
|
||||
var interestPositions = eodSwapPositions.Where(x => string.IsNullOrEmpty(x.UnderlyingCode)).ToList();//利息腿
|
||||
var positions = eodSwapPositions.Where(x => !string.IsNullOrEmpty(x.UnderlyingCode)).ToList();//持仓腿
|
||||
// 框架合约的方向约定:多头为正、空头为负;总名义本金取交易原始规模,
|
||||
@@ -2192,7 +2192,7 @@ namespace YLErp.Modules.SwapModule
|
||||
DbContext.eod_swap.Add(eod_Swap);
|
||||
}
|
||||
// 单标的调整与首次归档使用同一套框架合约汇总口径,避免重算后多空和名义本金展示不一致。
|
||||
var eodSwapPositions = DbContext.eod_swap_position.Where(x => x.SwapTradeId == td.id && x.ValueDate == settleDate && !x.Invalid).ToList();
|
||||
var eodSwapPositions = DbContext.eod_swap_position.ActiveByTradeAndDate(td.id, settleDate).ToList();
|
||||
var interestPositions = eodSwapPositions.Where(x => string.IsNullOrEmpty(x.UnderlyingCode)).ToList();//利息腿
|
||||
var positions = eodSwapPositions.Where(x => !string.IsNullOrEmpty(x.UnderlyingCode)).ToList();//持仓腿
|
||||
eod_Swap.NotionalValue = Math.Round(Convert.ToDecimal(td.OriginalStockEqvNotional ?? td.StockEqvNotional), ConsGlobal.MoneyRound, MidpointRounding.AwayFromZero);
|
||||
@@ -2243,7 +2243,7 @@ namespace YLErp.Modules.SwapModule
|
||||
public SwapLongShortCloseModel GetCloseDetails(int tradeId, DateTime valueDate)
|
||||
{
|
||||
SwapLongShortCloseModel closeModel = new SwapLongShortCloseModel();
|
||||
var eodPositions = DbContext.eod_swap_position.Where(x => x.SwapTradeId == tradeId && x.ValueDate == valueDate && !x.Invalid).ToList();
|
||||
var eodPositions = DbContext.eod_swap_position.ActiveByTradeAndDate(tradeId, valueDate).ToList();
|
||||
var flowEvents = DbContext.swap_flow_event.Where(x => x.SwapTradeId == tradeId && x.EventDate == valueDate && x.DataState == (int)SwapFlowDateStateEnum.完成 && x.EventType == (int)SwapEventTypeEnum.平仓 && string.IsNullOrEmpty(x.UnderlyingCode)).ToList();
|
||||
closeModel.DealPositions = eodPositions.Where(x => x.TdCloseQty != 0).ToList();
|
||||
closeModel.DealInterests = flowEvents;
|
||||
@@ -2484,7 +2484,7 @@ namespace YLErp.Modules.SwapModule
|
||||
/// <returns></returns>
|
||||
public List<eod_swap_position> GetPreEodPositions(int tradeId, DateTime valueDate)
|
||||
{
|
||||
return DbContext.eod_swap_position.Where(x => x.SwapTradeId == tradeId && x.ValueDate == valueDate && !x.Invalid).ToList();
|
||||
return DbContext.eod_swap_position.ActiveByTradeAndDate(tradeId, valueDate).ToList();
|
||||
}
|
||||
/// <summary>
|
||||
/// 获取互换交易日终持仓数据集合
|
||||
|
||||
@@ -34,6 +34,7 @@ using YLErp.Office.Converters;
|
||||
using YLErp.Plugins.TradeDocGenerator;
|
||||
using YLErp.Plugins.TradeDocGenerator.Abstracts;
|
||||
using YLErp.QdpModule;
|
||||
using YLErp.Modules.SwapModule;
|
||||
|
||||
namespace YLErp.Modules.TradeModule.DocGenerateModule
|
||||
{
|
||||
@@ -2864,7 +2865,7 @@ namespace YLErp.Modules.TradeModule.DocGenerateModule
|
||||
}
|
||||
public List<eod_swap_position> GetEodPositions(int tradeId, DateTime valueDate)
|
||||
{
|
||||
return DbContext.eod_swap_position.Where(x => x.SwapTradeId == tradeId && !x.Invalid && x.ValueDate == valueDate).AsNoTracking().ToList();
|
||||
return DbContext.eod_swap_position.ActiveByTradeAndDate(tradeId, valueDate).AsNoTracking().ToList();
|
||||
}
|
||||
|
||||
public List<SwapFlowDeal> GetSwapFlowDeals(int tradeId)
|
||||
|
||||
Reference in New Issue
Block a user