fix(swap): 修复公司行为事件生命周期管理问题
- 添加了股权登记日日期格式化显示功能 - 实现了公司行为类型的动态描述逻辑(配股、送股、拆分、分红) - 新增了过滤待生效公司行为事件的操作历史机制 - 修正了操作历史中隐藏未应用公司行为事件的逻辑 - 完善了公司行为事件原因描述的构建方法 - 添加了针对不同公司行为类型的单元测试验证
This commit is contained in:
@@ -1,6 +1,7 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Reflection;
|
||||
using Newtonsoft.Json;
|
||||
using Microsoft.VisualStudio.TestTools.UnitTesting;
|
||||
using YLErp.DBModels;
|
||||
@@ -20,6 +21,7 @@ namespace YLErp.Modules.SwapModule
|
||||
public void RegistrationSnapshot_IsPending_AndKeepsBeforeFields()
|
||||
{
|
||||
var info = CreateAction(77, ConsGlobal.InstrumentType.Stock);
|
||||
info.GiveShareAmount = 1m;
|
||||
var before = CreateEodPosition(9, info.UnderlyingCode, 1000m, 100m);
|
||||
|
||||
var snapshot = SwapEodPositionService.BuildCorporateActionEventData(
|
||||
@@ -37,6 +39,7 @@ namespace YLErp.Modules.SwapModule
|
||||
Assert.IsFalse(snapshot.Applied);
|
||||
|
||||
var reason = SwapEventService.BuildCorporateActionEventReason(snapshot);
|
||||
StringAssert.Contains(reason, "股权登记日:2026-08-14 发生公司行为(送股)");
|
||||
StringAssert.Contains(reason, "调整前:名义本金:100000 期初标的价格:100 持仓数量:1000");
|
||||
StringAssert.Contains(reason, "调整后:名义本金:0 期初标的价格:0 持仓数量:0");
|
||||
}
|
||||
@@ -65,6 +68,23 @@ namespace YLErp.Modules.SwapModule
|
||||
Assert.IsFalse(SwapEodPositionService.IsCorporateActionInstrument(ConsGlobal.InstrumentType.TBonds));
|
||||
}
|
||||
|
||||
[TestMethod]
|
||||
public void CorporateActionReason_ShowsOneActionTypeOrActualCashDividend()
|
||||
{
|
||||
AssertActionDescription(
|
||||
new CorporateActionEventData { ExDividendDate = RecordDate, RationedSharesAmount = 1m, GiveShareAmount = 1m, Split = 2m, GiveCashAmount = 10m, CashFlowChange = 1000m },
|
||||
"发生公司行为(配股)");
|
||||
AssertActionDescription(
|
||||
new CorporateActionEventData { ExDividendDate = RecordDate, GiveShareAmount = 1m, Split = 2m, GiveCashAmount = 10m, CashFlowChange = 1000m },
|
||||
"发生公司行为(送股)");
|
||||
AssertActionDescription(
|
||||
new CorporateActionEventData { ExDividendDate = RecordDate, Split = 2m, GiveCashAmount = 10m, CashFlowChange = 1000m },
|
||||
"发生公司行为(拆分)");
|
||||
AssertActionDescription(
|
||||
new CorporateActionEventData { ExDividendDate = RecordDate, GiveCashAmount = 11m, CashFlowChange = 220000m },
|
||||
"发生公司行为(产生分红:220000)");
|
||||
}
|
||||
|
||||
[TestMethod]
|
||||
public void Rerun_DoesNotCreateDuplicateCorporateActionEvent()
|
||||
{
|
||||
@@ -113,7 +133,7 @@ namespace YLErp.Modules.SwapModule
|
||||
}
|
||||
|
||||
[TestMethod]
|
||||
public void OperationHistory_PreservesPendingCorporateActionForAudit()
|
||||
public void OperationHistory_HidesPendingCorporateActionUntilItIsApplied()
|
||||
{
|
||||
var info = CreateAction(80, ConsGlobal.InstrumentType.Stock);
|
||||
var pendingData = SwapEodPositionService.BuildCorporateActionEventData(
|
||||
@@ -133,12 +153,17 @@ namespace YLErp.Modules.SwapModule
|
||||
new swap_event { id = 3, EventType = (int)SwapEventTypeEnum.互换, EventData = "{}" }
|
||||
};
|
||||
|
||||
// 操作历史不再隐藏登记日待生效事件;Applied=false 是事件状态,不是展示过滤条件。
|
||||
Assert.AreEqual(3, events.Count);
|
||||
Assert.IsTrue(SwapEventService.TryDeserializeCorporateActionEventData(events[0], out var pendingSnapshot));
|
||||
Assert.IsFalse(pendingSnapshot.Applied);
|
||||
Assert.IsTrue(SwapEventService.TryDeserializeCorporateActionEventData(events[1], out var appliedSnapshot));
|
||||
Assert.IsTrue(appliedSnapshot.Applied);
|
||||
var filter = typeof(SwapEventService).GetMethod(
|
||||
"FilterOperationHistory",
|
||||
BindingFlags.NonPublic | BindingFlags.Static);
|
||||
Assert.IsNotNull(filter, "操作历史必须过滤登记日创建的待生效公司行为事件。");
|
||||
|
||||
var visibleEvents = (List<swap_event>)filter.Invoke(null, new object[] { events });
|
||||
|
||||
Assert.AreEqual(2, visibleEvents.Count);
|
||||
Assert.IsFalse(visibleEvents.Any(x => x.id == 1));
|
||||
Assert.IsTrue(visibleEvents.Any(x => x.id == 2));
|
||||
Assert.IsTrue(visibleEvents.Any(x => x.id == 3));
|
||||
}
|
||||
|
||||
[TestMethod]
|
||||
@@ -283,6 +308,11 @@ namespace YLErp.Modules.SwapModule
|
||||
};
|
||||
}
|
||||
|
||||
private static void AssertActionDescription(CorporateActionEventData data, string expected)
|
||||
{
|
||||
StringAssert.Contains(SwapEventService.BuildCorporateActionEventReason(data), expected);
|
||||
}
|
||||
|
||||
private static eod_swap_position CreateEodPosition(long positionId, string code, decimal quantity, decimal price)
|
||||
{
|
||||
return new eod_swap_position
|
||||
|
||||
Reference in New Issue
Block a user