fix(swap): 修复平仓事件中事件日期=平仓日期的处理逻辑
- 将平仓条件判断从 UnwindDate 改为 EventDate - 移除不再使用的 priorClosePositionIds 变量 - 统一使用 NormalizeEventUnwindDate 替代 NormalizeIncomeUnwindDate - 在多个平仓方法中添加 NormalizeEventUnwindDate 调用 - 更新流程事件的 EventDate 和 UnwindDate 字段 - 修改单元测试以验证按 EventDate 分桶的逻辑 - 在前端控制器中将 unwindDate 设置为 valueDate - 添加 maxdate 属性到平仓日期选择器 - 实现事件日期与平仓日期的双向同步功能 - 更新利息列表获取接口使用统一日期参数
This commit is contained in:
@@ -694,7 +694,7 @@ namespace YLErp.Modules.SwapModule
|
||||
{
|
||||
realPositions ??= new List<swap_position>();
|
||||
var futureFlows = (completedFlowEvents ?? Enumerable.Empty<swap_flow_event>())
|
||||
.Where(x => x.EventType == (int)SwapEventTypeEnum.平仓 && x.UnwindDate > settleDate)
|
||||
.Where(x => x.EventType == (int)SwapEventTypeEnum.平仓 && x.EventDate > settleDate)
|
||||
.ToList();
|
||||
var originalNotional = origPositions.Where(x => x.PosiDirection > 0)
|
||||
.Sum(x => x.PosiNotionalValue);
|
||||
@@ -706,10 +706,6 @@ namespace YLErp.Modules.SwapModule
|
||||
|| x.InterestMode == (int)InterestModeEnum.追加预付金)
|
||||
.GroupBy(x => x.PositionId)
|
||||
.ToDictionary(x => x.Key, x => x.Sum(v => v.InterestPrincipal));
|
||||
var priorClosePositionIds = new HashSet<long>((completedFlowEvents ?? Enumerable.Empty<swap_flow_event>())
|
||||
.Where(x => x.EventType == (int)SwapEventTypeEnum.平仓 && x.UnwindDate <= settleDate)
|
||||
.Select(x => x.PositionId));
|
||||
|
||||
return origPositions.Where(x => x.PosiDirection == 0).Select(p =>
|
||||
{
|
||||
if (p.InterestMode == (int)InterestModeEnum.初始预付金
|
||||
@@ -718,10 +714,6 @@ namespace YLErp.Modules.SwapModule
|
||||
var realLeg = realPositions.FirstOrDefault(r => r.PositionId == p.id);
|
||||
if (realLeg != null)
|
||||
{
|
||||
if (!priorClosePositionIds.Contains(p.id))
|
||||
{
|
||||
return p;
|
||||
}
|
||||
var futurePrincipal = hasNotionalFlows
|
||||
? p.InterestPrincipalFix * futureCloseNotional / originalNotional
|
||||
: futureClosePrincipal.TryGetValue(p.id, out var flowPrincipal) ? flowPrincipal : 0m;
|
||||
@@ -1505,6 +1497,7 @@ namespace YLErp.Modules.SwapModule
|
||||
{
|
||||
throw new ServiceException("未找到交易信息");
|
||||
}
|
||||
NormalizeEventUnwindDate(unwindData);
|
||||
NormalizeNotionalValues(unwindData);
|
||||
NormalizeManualSettlementAmounts(unwindData, (int)SwapEventTypeEnum.平仓, "系统操作_平仓");
|
||||
//CheckLastEod(unwindData.ValueDate, td.StartDate.Value, unwindData.SwapTradeId); //去掉平仓收盘限制
|
||||
@@ -1919,6 +1912,7 @@ namespace YLErp.Modules.SwapModule
|
||||
{
|
||||
throw new ServiceException("未找到交易信息");
|
||||
}
|
||||
NormalizeEventUnwindDate(unwindData);
|
||||
unwindData.SwapRealizedPnL = unwindData.SwapCloseAmount;
|
||||
NormalizeManualSettlementAmounts(unwindData, (int)SwapEventTypeEnum.平仓, "系统操作_平仓");
|
||||
var trans = DbContext.Database.BeginTransaction();
|
||||
@@ -1963,6 +1957,7 @@ namespace YLErp.Modules.SwapModule
|
||||
{
|
||||
throw new ServiceException("未找到交易信息");
|
||||
}
|
||||
NormalizeEventUnwindDate(unwindData);
|
||||
unwindData.SwapRealizedPnL = unwindData.SwapCloseAmount;
|
||||
NormalizeManualSettlementAmounts(unwindData, (int)SwapEventTypeEnum.互换, "系统操作_互换");
|
||||
var trans = DbContext.Database.BeginTransaction();
|
||||
@@ -2002,7 +1997,7 @@ namespace YLErp.Modules.SwapModule
|
||||
{
|
||||
throw new ServiceException("未找到交易信息");
|
||||
}
|
||||
NormalizeIncomeUnwindDate(unwindData);
|
||||
NormalizeEventUnwindDate(unwindData);
|
||||
ValidateIncomeValueDate(unwindData, td);
|
||||
NormalizeManualSettlementAmounts(unwindData, (int)SwapEventTypeEnum.互换, "系统操作_互换");
|
||||
//CheckLastEod(unwindData.ValueDate, td.StartDate.Value, unwindData.SwapTradeId); //去掉平仓收盘限制
|
||||
@@ -2043,6 +2038,7 @@ namespace YLErp.Modules.SwapModule
|
||||
throw new Exception("该笔交易状态为平仓待复核,未找到相关记录,请检查该笔交易是否有效");
|
||||
}
|
||||
swapEvent.unwindData = JsonConvert.DeserializeObject<UnwindData>(swapEvent.EventData);
|
||||
NormalizeEventUnwindDate(swapEvent.unwindData);
|
||||
NormalizeNotionalValues(swapEvent.unwindData);
|
||||
// Stored events keep display ratio A; approval calculations consume remaining ratio B.
|
||||
swapEvent.unwindData.ClosePercent = ToRemainingClosePercent(
|
||||
@@ -2050,6 +2046,11 @@ namespace YLErp.Modules.SwapModule
|
||||
swapEvent.unwindData.NotionalValue,
|
||||
swapEvent.unwindData.PosiNotionalValue);
|
||||
var flowList = FindFlowEventsByEventId(swapEvent.id);
|
||||
foreach (var item in flowList)
|
||||
{
|
||||
item.EventDate = swapEvent.unwindData.ValueDate;
|
||||
item.UnwindDate = swapEvent.unwindData.UnwindDate;
|
||||
}
|
||||
swapEvent.unwindData.FlowEvents = flowList;
|
||||
if (eventType == (int)SwapEventTypeEnum.平仓)
|
||||
{
|
||||
@@ -2060,7 +2061,6 @@ namespace YLErp.Modules.SwapModule
|
||||
}
|
||||
if (eventType == (int)SwapEventTypeEnum.互换)
|
||||
{
|
||||
NormalizeIncomeUnwindDate(swapEvent.unwindData);
|
||||
ValidateIncomeValueDate(swapEvent.unwindData, td);
|
||||
}
|
||||
if (eventType == (int)SwapEventTypeEnum.平仓)
|
||||
@@ -2130,9 +2130,9 @@ namespace YLErp.Modules.SwapModule
|
||||
{
|
||||
throw new ServiceException("未找到交易信息");
|
||||
}
|
||||
NormalizeEventUnwindDate(unwindData);
|
||||
if (eventType == (int)SwapEventTypeEnum.互换)
|
||||
{
|
||||
NormalizeIncomeUnwindDate(unwindData);
|
||||
ValidateIncomeValueDate(unwindData, td);
|
||||
}
|
||||
unwindData.SwapRealizedPnL = unwindData.SwapCloseAmount;
|
||||
@@ -2179,7 +2179,7 @@ namespace YLErp.Modules.SwapModule
|
||||
}
|
||||
}
|
||||
|
||||
private void NormalizeIncomeUnwindDate(UnwindData unwindData)
|
||||
private static void NormalizeEventUnwindDate(UnwindData unwindData)
|
||||
{
|
||||
unwindData.UnwindDate = unwindData.ValueDate;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user