diff --git a/YLErpDAL/Modules/SwapModule/SwapDealService.cs b/YLErpDAL/Modules/SwapModule/SwapDealService.cs
index c4bdd523..70733b47 100644
--- a/YLErpDAL/Modules/SwapModule/SwapDealService.cs
+++ b/YLErpDAL/Modules/SwapModule/SwapDealService.cs
@@ -1172,15 +1172,23 @@ namespace YLErp.Modules.SwapModule
/// 待迁入 Margin 模块。
///
private void RecordMarginCashFlow(trade td, UnwindData unwindData)
+ => RecordMarginCashFlow(td, unwindData.ValueDate,
+ unwindData.SwapMarginAmount, unwindData.SwapMarginRebatePnl,
+ AddClientCashInCashOut);
+
+ ///
+ /// 写入保证金资金记录的通用重载,接受资金写入委托。
+ /// AddClientCash(virtual,测试可stub) 和 AddClientCashInCashOut(非virtual,直接写库)
+ /// 都可通过此重载统一。
+ ///
+ private void RecordMarginCashFlow(trade td, DateTime valueDate,
+ decimal marginAmount, decimal marginRebate,
+ Func writeCash)
{
- if (unwindData.SwapMarginAmount != 0)
- {
- AddClientCashInCashOut(td, Convert.ToDouble(unwindData.SwapMarginAmount), ClientCashInCashOut.系统操作_应付预付金, unwindData.ValueDate);
- }
- if (unwindData.SwapMarginRebatePnl != 0)
- {
- AddClientCashInCashOut(td, Convert.ToDouble(-unwindData.SwapMarginRebatePnl), ClientCashInCashOut.系统操作_预付金返息, unwindData.ValueDate);
- }
+ if (marginAmount != 0)
+ writeCash(td, Convert.ToDouble(marginAmount), ClientCashInCashOut.系统操作_应付预付金, valueDate);
+ if (marginRebate != 0)
+ writeCash(td, Convert.ToDouble(-marginRebate), ClientCashInCashOut.系统操作_预付金返息, valueDate);
}
///
@@ -1652,14 +1660,7 @@ namespace YLErp.Modules.SwapModule
ExecuteInTransaction(() =>
{
int clientCashId = AddClientCash(td, Convert.ToDouble(-unwindData.SwapRealizedPnL), ClientCashInCashOut.系统操作_平仓费, unwindData.ValueDate);
- if (unwindData.SwapMarginAmount != 0)
- {
- AddClientCash(td, Convert.ToDouble(unwindData.SwapMarginAmount), ClientCashInCashOut.系统操作_应付预付金, unwindData.ValueDate);
- }
- //if (unwindData.SwapMarginRebatePnl != 0)
- //{
- // AddClientCash(td, Convert.ToDouble(-unwindData.SwapMarginRebatePnl), ClientCashInCashOut.系统操作_预付金返息, unwindData.ValueDate);
- //}
+ RecordMarginCashFlow(td, unwindData.ValueDate, unwindData.SwapMarginAmount, 0m, AddClientCash);
DealFloatPosition(unwindData);
var flowList = new List(unwindData.FlowEvents);
var eventId = SaveSwapDeal(unwindData, (int)SwapEventTypeEnum.平仓, clientCashId, "系统操作_平仓");
@@ -1975,14 +1976,7 @@ namespace YLErp.Modules.SwapModule
private void DealUnwind(UnwindData unwindData, trade td, string actionMsg = "系统操作_自动平仓")
{
int clientCashId = AddClientCashInCashOut(td, Convert.ToDouble(-unwindData.SwapRealizedPnL), ClientCashInCashOut.系统操作_平仓费, unwindData.ValueDate);
- if (unwindData.SwapMarginAmount != 0)
- {
- AddClientCashInCashOut(td, Convert.ToDouble(unwindData.SwapMarginAmount), ClientCashInCashOut.系统操作_应付预付金, unwindData.ValueDate);
- }
- //if (unwindData.SwapMarginRebatePnl != 0)
- //{
- // AddClientCashInCashOut(td, Convert.ToDouble(-unwindData.SwapMarginRebatePnl), ClientCashInCashOut.系统操作_预付金返息, unwindData.ValueDate);
- //}
+ RecordMarginCashFlow(td, unwindData.ValueDate, unwindData.SwapMarginAmount, 0m, AddClientCashInCashOut);
var flowList = new List(unwindData.FlowEvents);
var eventId = SaveSwapDeal(unwindData, (int)SwapEventTypeEnum.平仓, clientCashId, actionMsg);
if (unwindData.CloseMethod == (int)CloseMethodEnum.全部平仓)
@@ -2131,10 +2125,7 @@ namespace YLErp.Modules.SwapModule
ExecuteInTransaction(() =>
{
int clientCashId = AddClientCash(td, Convert.ToDouble(-unwindData.SwapRealizedPnL), ClientCashInCashOut.系统操作_互换, unwindData.ValueDate);
- if (unwindData.SwapMarginRebatePnl != 0)
- {
- AddClientCash(td, Convert.ToDouble(-unwindData.SwapMarginRebatePnl), ClientCashInCashOut.系统操作_预付金返息, unwindData.ValueDate);
- }
+ RecordMarginCashFlow(td, unwindData.ValueDate, 0m, unwindData.SwapMarginRebatePnl, AddClientCash);
foreach (var item in unwindData.FlowEvents)
{
item.OptLog = "手工操作";
@@ -2201,9 +2192,9 @@ namespace YLErp.Modules.SwapModule
}
string action = eventType == (int)SwapEventTypeEnum.互换 ? ClientCashInCashOut.系统操作_互换 : ClientCashInCashOut.系统操作_平仓费;
int clientCashId = AddClientCash(td, Convert.ToDouble(-swapEvent.unwindData.SwapRealizedPnL), action, swapEvent.unwindData.ValueDate);
- if (eventType == (int)SwapEventTypeEnum.平仓 && swapEvent.unwindData.SwapMarginAmount != 0)
+ if (eventType == (int)SwapEventTypeEnum.平仓)
{
- AddClientCash(td, Convert.ToDouble(swapEvent.unwindData.SwapMarginAmount), ClientCashInCashOut.系统操作_应付预付金, swapEvent.unwindData.ValueDate);
+ RecordMarginCashFlow(td, swapEvent.unwindData.ValueDate, swapEvent.unwindData.SwapMarginAmount, 0m, AddClientCash);
}
swapEvent.ClientCashId = clientCashId;
td.UnWindDate = swapEvent.unwindData.UnwindDate;