diff --git a/YLErpDAL/Modules/SwapModule/SwapDealService.cs b/YLErpDAL/Modules/SwapModule/SwapDealService.cs
index 2ef85c63..e478d4de 100644
--- a/YLErpDAL/Modules/SwapModule/SwapDealService.cs
+++ b/YLErpDAL/Modules/SwapModule/SwapDealService.cs
@@ -8,7 +8,6 @@ using YLErp.DBModels.Enums;
using YLErp.Helpers;
using YLErp.Modules.DataProviderModule;
using YLErp.Modules.EodModule;
-using YLErp.Modules.RiskEngine;
using YLErp.Modules.TradeModule;
using YLErp.Modules.TradeModule.DealModule;
using YLErp.QdpModule;
@@ -1261,24 +1260,38 @@ namespace YLErp.Modules.SwapModule
/// 新风控二次确认信息;首次提交传空。
/// 本次平仓的新风控试算结果。
///
- public RiskTrialResult SwapUnwind(UnwindData unwindData, RiskTrialConfirmation confirmation = null)
+ public YLErp.Modules.RiskEngine.RiskTrialResult SwapUnwind(UnwindData unwindData, YLErp.Modules.RiskEngine.RiskTrialConfirmation confirmation)
{
if (unwindData == null)
{
throw new ServiceException("平仓信息不能为空");
}
- var td = FindTrade(unwindData.SwapTradeId);
- if (td == null)
+ if (FindTrade(unwindData.SwapTradeId) == null)
{
throw new ServiceException("未找到交易信息");
}
- // 直接平仓不经过审核提交入口,落库前仍需执行平仓阶段的新风控,避免绕过 CLOSE_REVIEW 规则。
var riskTrialResult = CheckCloseRisk(unwindData, confirmation);
if (!riskTrialResult.Passed)
{
return riskTrialResult;
}
+ SwapUnwind(unwindData);
+ return riskTrialResult;
+ }
+
+ ///
+ /// 单标的平仓
+ ///
+ ///
+ ///
+ public void SwapUnwind(UnwindData unwindData)
+ {
+ var td = FindTrade(unwindData.SwapTradeId);
+ if (td == null)
+ {
+ throw new ServiceException("未找到交易信息");
+ }
//CheckLastEod(unwindData.ValueDate, td.StartDate.Value, unwindData.SwapTradeId); //去掉平仓收盘限制
ValidateFrontendPnL(unwindData, isIncome: false); // 只读校验告警,不阻断交易
// 前端按"占期初(original)"语义传 ClosePercent(A);后端全链路按"占剩余(remaining)"语义(B)消费。
@@ -1318,7 +1331,6 @@ namespace YLErp.Modules.SwapModule
{
TriggerRealtimeSwapPosition();
}
- return riskTrialResult;
}
///
/// 自动全平仓
@@ -1842,33 +1854,39 @@ namespace YLErp.Modules.SwapModule
/// 新风控二次确认信息;首次提交传空。
/// 平仓事件返回新风控试算结果,互换事件返回空。
///
- public RiskTrialResult ApplySwapTrade(UnwindData unwindData, int eventType, RiskTrialConfirmation confirmation = null)
+ public YLErp.Modules.RiskEngine.RiskTrialResult ApplySwapTrade(UnwindData unwindData, int eventType, YLErp.Modules.RiskEngine.RiskTrialConfirmation confirmation)
{
- if (unwindData == null)
+ YLErp.Modules.RiskEngine.RiskTrialResult riskTrialResult = null;
+ if (eventType == (int)SwapEventTypeEnum.平仓)
{
- throw new ServiceException("互换或平仓信息不能为空");
- }
-
- var td = FindTrade(unwindData.SwapTradeId);
- if (td == null)
- {
- throw new ServiceException("未找到交易信息");
- }
- RiskTrialResult riskTrialResult = null;
- if (eventType == (int)SwapEventTypeEnum.互换)
- {
- NormalizeIncomeUnwindDate(unwindData);
- ValidateIncomeValueDate(unwindData, td);
- }
- else if (eventType == (int)SwapEventTypeEnum.平仓)
- {
- // 审核提交保存待审核事件前执行平仓阶段的新风控,需确认时先返回前端,不创建待审核事件。
riskTrialResult = CheckCloseRisk(unwindData, confirmation);
if (!riskTrialResult.Passed)
{
return riskTrialResult;
}
}
+ ApplySwapTrade(unwindData, eventType);
+ return riskTrialResult;
+ }
+
+ ///
+ /// 互换/平仓提交审核
+ ///
+ ///
+ ///
+ ///
+ public void ApplySwapTrade(UnwindData unwindData, int eventType)
+ {
+ var td = FindTrade(unwindData.SwapTradeId);
+ if (td == null)
+ {
+ throw new ServiceException("未找到交易信息");
+ }
+ if (eventType == (int)SwapEventTypeEnum.互换)
+ {
+ NormalizeIncomeUnwindDate(unwindData);
+ ValidateIncomeValueDate(unwindData, td);
+ }
unwindData.SwapRealizedPnL = unwindData.SwapCloseAmount;
// 前端按"占期初(original)"语义传 ClosePercent(A);后端全链路按"占剩余(remaining)"语义(B)消费。
// 入口统一转换为 B,落库展示用的 A 由 SaveSwapDealInternal 还原。
@@ -1895,7 +1913,6 @@ namespace YLErp.Modules.SwapModule
});
}
});
- return riskTrialResult;
}
///
@@ -1905,7 +1922,7 @@ namespace YLErp.Modules.SwapModule
/// 新风控二次确认信息;首次提交传空。
/// 包含阻断、审批、提示及试算记录ID的新风控结果。
/// 平仓请求为空。
- private RiskTrialResult CheckCloseRisk(UnwindData unwindData, RiskTrialConfirmation confirmation)
+ private YLErp.Modules.RiskEngine.RiskTrialResult CheckCloseRisk(UnwindData unwindData, YLErp.Modules.RiskEngine.RiskTrialConfirmation confirmation)
{
if (unwindData == null)
{
@@ -1914,14 +1931,14 @@ namespace YLErp.Modules.SwapModule
const string triggerPoint = "CLOSE_REVIEW";
const int closeTrialSource = 2;
- var riskContext = new RiskContext
+ var riskContext = new YLErp.Modules.RiskEngine.RiskContext
{
TradeId = unwindData.SwapTradeId,
TriggerPoint = triggerPoint,
UnwindDate = unwindData.UnwindDate,
PayDate = unwindData.PayDate
};
- return new RiskTrialService(this).CheckRisk(riskContext, closeTrialSource, confirmation);
+ return new YLErp.Modules.RiskEngine.RiskTrialService(this).CheckRisk(riskContext, closeTrialSource, confirmation);
}
private void ValidateIncomeValueDate(UnwindData unwindData, trade td)