支持存续期报送

This commit is contained in:
gongpei
2026-04-21 14:32:16 +08:00
parent 94be69343b
commit 0bd3b6bb0e
3 changed files with 316 additions and 277 deletions
@@ -68,8 +68,6 @@ namespace YLErp.Modules.SuperviseReportModule.SAC.Service
{
dataList.AddRange(GetOptionTerminationSettlementFromDb(db, cacheKey, nextDate));
}
dataList = GetSwapDurationManagementModel(ref fileList);
}
var subsystemDataList = loadSubsystemDataSource<SwapDurationManagementModel>(fileList, AddSubsystemNote);
@@ -87,6 +85,7 @@ namespace YLErp.Modules.SuperviseReportModule.SAC.Service
DateTime nextDate)
{
// 所有的交易了结事件
var valueDate = _reqInfo.ReportDate;
var unwindEventList = (from a in db.swap_event
join b in (from sfe in db.swap_flow_event
group sfe by new { sfe.EventId, sfe.UnwindDate }
@@ -94,90 +93,56 @@ namespace YLErp.Modules.SuperviseReportModule.SAC.Service
select new { EventId = g.Key.EventId, UnwindDate = g.Key.UnwindDate })
on a.id equals b.EventId into leftJoin
from b in leftJoin.DefaultIfEmpty()
where (a.EventType == 2)
&& ((a.EventType == 2 && b.UnwindDate == _reqInfo.DataDate)
|| (a.EventType != 2 && a.OptTime >= _reqInfo.DataDate.Date &&
a.OptTime < _reqInfo.DataDate.Date.AddDays(1)))
where a.EventType == 2 && b.UnwindDate.HasValue && b.UnwindDate.Value == valueDate.Date
select new
{
a.id,
swapTradeId = a.SwapTradeId,
valueDate = a.EventType == 2 ? b.UnwindDate :
(a.EventType == 5 || a.EventType == 12) ? a.OptTime.Date :
a.ValueDate,
eventType = a.EventType,
valueDate = b.UnwindDate,
eventData = a.EventData,
invalid = a.Invalid,
backId = a.BackId,
optTime = a.OptTime
}).OrderBy(O => O.optTime).ToList();
}).ToList();
if (unwindEventList == null || unwindEventList.Count == 0)
{
return new List<SwapDurationManagementModel>();
}
var tradeIds = unwindEventList.Select(O => O.swapTradeId).Distinct().ToList();
List<SwapDurationManagementModel> dataList = new List<SwapDurationManagementModel>();
// 查找交易事件
var query = (from ue in unwindEventList
join t in db.trade on ue.swapTradeId equals t.id
var query = (from t in db.trade.Where(O => O.TradeType == "收益互换")
join cico in db.ClientCashInCashOut.Where(O => O.Action == "系统操作-平仓费") on t.id equals cico.TradeId
join tr in db.trade_contract_r.Where(O => O.Type == "交易确认书")
join tr in db.trade_contract_r.Where(O => O.Type == "交易确认书" && O.IsValid)
on t.id equals tr.TradeId
join es in db.eod_swap.Where(O => O.ValueDate == _reqInfo.DataDate)
on t.id equals es.SwapTradeId
join esp in db.eod_swap_position.Where(O =>
O.ValueDate == _reqInfo.DataDate && !O.Invalid && O.PositionType > 0)
O.ValueDate.Date == _reqInfo.ReportDate.Date && !O.Invalid && O.PositionType > 0)
on t.id equals esp.SwapTradeId
join te in db.trade_Report on t.id equals te.TradeId
where tradeIds.Contains(t.id) && (t.TradeType == "收益互换" && tr.IsValid)
where tradeIds.Contains(t.id)
select new
{
tradeValid = t.ValueStatus != "InValid",
tradeContractRValid = tr.IsValid,
t.id,
ue.valueDate,
t.ClientId,
t.TradeDate,
t.ExerciseDate,
t.SettlementDate,
t.ExerciseMode,
t.BuySell,
TradeType = t.StructureType ?? t.TradeType,
t.OptionType,
t.OriginalStockEqvNotional,
t.StockEqvNotionalReal,
t.IsMoneynessOption,
t.SpotPrice,
t.Strike,
t.MarginTemplateName,
t.MarginType,
t.InitialMargin,
t.UnderlyingCode,
t.AnnualizeFactor,
t.OriginalNotional,
tr.ContractCode,
t.QuoteCurrency,
t.SettlementCurrency,
es.NotionalValue,
es.NotionalValueLong,
es.NotionalValueShort,
es.PostionMarginGain,
es.PostionMarginLoss,
esp.PositionType,
esp.PosiNotionalValue,
esp.PosiQuantity,
esp.PosiGrossPrice,
cico.Money
}).ToArray().GroupBy(O => new { O.valueDate, O.ContractCode })
.ToDictionary(K => K.Key, V => V.ToList());
}).ToArray();
List<int> ids = query.Values.SelectMany(O => O.Select(x => x.id)).Distinct().ToList();
Dictionary<int, Dictionary<string, string>> metaDic = DbContext.TradeMeta
.Where(O => ids.Contains(O.TradeId)).AsEnumerable().GroupBy(O => O.TradeId).ToDictionary(K => K.Key,
.Where(O => tradeIds.Contains(O.TradeId)).AsEnumerable().GroupBy(O => O.TradeId).ToDictionary(K => K.Key,
V => V.ToDictionary(K1 => K1.MetaKey, V1 => V1.MetaValue));
foreach (var item in query.ToArray())
foreach (var item in query.GroupBy(O => O.ContractCode).ToDictionary(K => K.Key, V => V.ToList()))
{
// 交易确认书编号
var confirmationNo = item.Key.ContractCode;
var confirmationNo = item.Key;
var value = item.Value.First();
if (metaDic.ContainsKey(value.id))
@@ -194,8 +159,9 @@ namespace YLErp.Modules.SuperviseReportModule.SAC.Service
//info.TradeId = item.Key.id.ToString();
info.DurationEventNO = "0000";
info.DurationOperationDate = value.valueDate?.ToString("yyyy-MM-dd");
info.DurationOperationDate = valueDate.ToString("yyyy-MM-dd");
info.ConfirmationNo = confirmationNo;
info.OperationType = OptFlagsEnum.A;
List<SACReportNotes> notes =
base.GetReportNotes(ReportType, $"_{info.ConfirmationNo.Replace("_", "-")}_", true);
var note = notes.FirstOrDefault(O =>
@@ -225,7 +191,7 @@ namespace YLErp.Modules.SuperviseReportModule.SAC.Service
info.BizID = note.BizId;
}
info.DurationOperationType = OperationTypeMap["终止"];
info.DurationOperationType = "2";
var positionTypeList = item.Value.Select(o => o.PositionType).ToList();
if (positionTypeList.Contains(1) && positionTypeList.Contains(2))
{
@@ -246,14 +212,14 @@ namespace YLErp.Modules.SuperviseReportModule.SAC.Service
// 本次支付金额
info.AmountPaidThisTime = item.Value.Sum(O => O.Money).ToString();
var clientBalanceDailies = (from t in db.ClientBalanceDaily
where t.ClientId == value.ClientId && t.BalanceDate == value.valueDate
select new { t.ToDayRemainFund, t.TotalNominal, t.RoundedDailyPnl });
where t.ClientId == value.ClientId && t.BalanceDate == valueDate
select new { t.ToDayRemainFund, t.TotalNominal, t.RoundedPositionPnl });
if (clientBalanceDailies != null)
{
var first = clientBalanceDailies.First();
if (first.TotalNominal != 0)
{
var marginRate = (first.ToDayRemainFund + first.RoundedDailyPnl) * 100 / first.TotalNominal;
var marginRate = (first.ToDayRemainFund + first.RoundedPositionPnl) * 100 / first.TotalNominal;
if (marginRate > 100)
{
info.MarginRatio = "100";
@@ -265,6 +231,41 @@ namespace YLErp.Modules.SuperviseReportModule.SAC.Service
}
}
var list = item.Value.Select(O => O.id).Distinct().ToList();
var eventDataList = unwindEventList.Where(O => list.Contains(O.swapTradeId)).Select(O => O.eventData).ToList();
if (eventDataList != null && eventDataList.Count > 0)
{
double closeNotionalSum = 0;
foreach (var ed in eventDataList)
{
try
{
// 假设 eventData 是 JSON 字符串,尝试解析并获取 CloseNotionalValue
var jsonDoc = System.Text.Json.JsonDocument.Parse(ed);
if (jsonDoc.RootElement.TryGetProperty("CloseNotionalValue", out var closeNotionalElement))
{
if (closeNotionalElement.ValueKind == System.Text.Json.JsonValueKind.Number)
{
closeNotionalSum += closeNotionalElement.GetDouble();
}
else if (closeNotionalElement.ValueKind == System.Text.Json.JsonValueKind.String)
{
if (double.TryParse(closeNotionalElement.GetString(), out double val))
{
closeNotionalSum += val;
}
}
}
}
catch
{
// 忽略解析错误,避免影响主流程
}
}
info.ChangeAmount = closeNotionalSum.ToString("0.00");
}
#region
if (double.TryParse(info.Balance, out var temp) && temp > 0)
@@ -298,8 +299,11 @@ namespace YLErp.Modules.SuperviseReportModule.SAC.Service
#endregion
info.ExceID = base.formatExceID();
ReportStatus.AddCacheInfo(cacheKey, value.id.ToString());
ReportStatus.AddCacheInfo($"{cacheKey}_{info.ConfirmationNo}", "");
ReportStatus.AddCacheInfo(cacheKey, confirmationNo);
foreach (var swapTradeId in list)
{
ReportStatus.AddCacheInfo($"{cacheKey}_{info.ConfirmationNo}_{_operationType}", swapTradeId.ToString());
}
dataList.Add(info);
note.id = 0;
note.ExceId = info.ExceID;
@@ -308,7 +312,7 @@ namespace YLErp.Modules.SuperviseReportModule.SAC.Service
note.CreateTime = DateTime.Now;
note.FileTag = FileTag;
note.ReportType = ReportType;
note.ReportDate = _reqInfo.ReportDate;
note.ReportDate = valueDate;
note.InfoTag = formatInfoTag(info, true);
note.OptTime = note.CreateTime;
note.RetCode = "";