支持存续期报送
This commit is contained in:
+246
-216
@@ -25,14 +25,12 @@ namespace YLErp.Modules.SuperviseReportModule.SAC.Service
|
||||
protected override DataFlagsEnum BusiDataType => DataFlagsEnum.A1016;
|
||||
|
||||
private List<OptFlagsEnum>? _validOperationType = null;
|
||||
|
||||
public override List<OptFlagsEnum> ValidOperationType
|
||||
{
|
||||
get
|
||||
{
|
||||
_validOperationType ??= new List<OptFlagsEnum>() {
|
||||
OptFlagsEnum.A,
|
||||
OptFlagsEnum.U,
|
||||
};
|
||||
_validOperationType ??= new List<OptFlagsEnum>() { OptFlagsEnum.A, OptFlagsEnum.U, };
|
||||
return _validOperationType;
|
||||
}
|
||||
}
|
||||
@@ -54,208 +52,14 @@ namespace YLErp.Modules.SuperviseReportModule.SAC.Service
|
||||
dataList = GetSwapEquityPaymentModel();
|
||||
}
|
||||
|
||||
if ((PS.Config.ErpElement.SAC_ReportDataSource & SAC_ReportDataSourceEnum.System) == SAC_ReportDataSourceEnum.System)
|
||||
if ((PS.Config.ErpElement.SAC_ReportDataSource & SAC_ReportDataSourceEnum.System) ==
|
||||
SAC_ReportDataSourceEnum.System)
|
||||
{
|
||||
// 当前生成的交易确认书编号
|
||||
var confirmationNos = ReportStatus.GetCacheInfo(DataFlagsEnum.A1005.ToString());//取出这一次报送交易要素的交易编号
|
||||
foreach (var confirmationNo in confirmationNos)
|
||||
{
|
||||
var info = new SwapEquityPaymentModel();
|
||||
var tradeIds = ReportStatus.GetCacheInfo(DataFlagsEnum.A1005.ToString() + "_" + confirmationNo + "_" + _operationType).Select(x => int.Parse(x)).ToList();
|
||||
info.OperationType = _operationType;
|
||||
info.ConfirmationNo = confirmationNo;
|
||||
SACReportNotes note = base.GetReportNotes(ReportType, formatInfoTag(info)).FirstOrDefault();
|
||||
if (note == null && _operationType == OptFlagsEnum.A)
|
||||
{
|
||||
info.OperationType = OptFlagsEnum.A;
|
||||
note = new SACReportNotes() { IsValid = true, };
|
||||
}
|
||||
else
|
||||
{
|
||||
if (note == null)
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
switch (_operationType)
|
||||
{
|
||||
case OptFlagsEnum.A:
|
||||
continue; //新增数据已报送,跳过
|
||||
case OptFlagsEnum.U:
|
||||
if (!note.changeStatus)
|
||||
{
|
||||
continue; //交易没有被修改过,跳过
|
||||
}
|
||||
|
||||
info.OperationType = OptFlagsEnum.U;
|
||||
note.IsValid = true;
|
||||
break;
|
||||
case OptFlagsEnum.D:
|
||||
// 如果有删除事件,报废止
|
||||
info.OperationType = OptFlagsEnum.D;
|
||||
note.IsValid = false;
|
||||
break;
|
||||
case OptFlagsEnum.NONE:
|
||||
default:
|
||||
throw new ServiceException("未知操作类型");
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
var swapEquityPaymentTupleModels = new List<SwapEquityPaymentTupleModel>();
|
||||
|
||||
#region 权益端支付明细
|
||||
|
||||
using (var db = new YLContext())
|
||||
{
|
||||
// 查询 swap flow event
|
||||
var query = (from sfe in db.swap_flow_event
|
||||
join t in db.trade on sfe.SwapTradeId equals t.id
|
||||
where tradeIds.Contains(sfe.SwapTradeId) && sfe.DataState == 100 && (sfe.UnderlyingCode != null && sfe.UnderlyingCode != "")
|
||||
select new
|
||||
{
|
||||
sfe.SwapTradeId,
|
||||
sfe.PositionType,
|
||||
sfe.PayDirection,
|
||||
sfe.TradingAmountAvg,
|
||||
sfe.Quantity,
|
||||
sfe.TradingAmount,
|
||||
sfe.InterestFee,
|
||||
sfe.InterestClosePnL,
|
||||
sfe.PositionQty,
|
||||
sfe.UnderlyingCode,
|
||||
sfe.EventType,
|
||||
sfe.ContractSize,
|
||||
t.StructureType,
|
||||
t.OpponentRole
|
||||
}).ToList();
|
||||
|
||||
var positionTypes = query.Select(O => O.PositionType).Distinct().ToList();
|
||||
|
||||
foreach (var item in query)
|
||||
{
|
||||
var underlyingManager = DataCacheProvider.GetUnderlyingDataSource().GetData(item.UnderlyingCode);
|
||||
var variety = DataCacheProvider.GetVarietyDataSource().GetData(underlyingManager.UnderlyingTypeId);
|
||||
var sept = new SwapEquityPaymentTupleModel();
|
||||
sept.ConfirmationNo = confirmationNo;
|
||||
sept.OpenandClosingDate = _reqInfo.ReportDate.ToString();
|
||||
sept.UndrlygAssetCode = item.UnderlyingCode;
|
||||
sept.UndrlygAssetName = underlyingManager.UnderlyingName;
|
||||
sept.UndrlygAssetTradgPlc = variety.TradingMarket;
|
||||
if (positionTypes.Contains(1) && positionTypes.Contains(2))
|
||||
{
|
||||
// 多空组合
|
||||
sept.PaymentMethod = "4";
|
||||
}
|
||||
else if (positionTypes.Contains(1))
|
||||
{
|
||||
sept.PaymentMethod = "0";
|
||||
}
|
||||
else if (positionTypes.Contains(2))
|
||||
{
|
||||
sept.PaymentMethod = "1";
|
||||
}
|
||||
|
||||
if (item.PayDirection == 1)
|
||||
{
|
||||
if (item.OpponentRole.Equals("乙方"))
|
||||
{
|
||||
sept.Payer = "1";
|
||||
}
|
||||
else
|
||||
{
|
||||
sept.Payer = "0";
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
if (item.OpponentRole.Equals("乙方"))
|
||||
{
|
||||
sept.Payer = "0";
|
||||
}
|
||||
else
|
||||
{
|
||||
sept.Payer = "1";
|
||||
}
|
||||
}
|
||||
|
||||
if (item.ContractSize != null)
|
||||
{
|
||||
sept.ContractMultiplier = item.ContractSize.ToString();
|
||||
}
|
||||
|
||||
sept.PaymentFreq = "1";
|
||||
sept.UndrlygAssetPrice = item.TradingAmountAvg.RoundToMultiple(100.0m).ToString();
|
||||
if (item.EventType == 1)
|
||||
{
|
||||
if (item.PositionType == 1)
|
||||
{
|
||||
sept.UndrlygAssetPosition = "0";
|
||||
}
|
||||
else
|
||||
{
|
||||
sept.UndrlygAssetPosition = "1";
|
||||
}
|
||||
} else if (item.EventType == 2)
|
||||
{
|
||||
if (item.PositionType == 1)
|
||||
{
|
||||
sept.UndrlygAssetPosition = "2";
|
||||
}
|
||||
else
|
||||
{
|
||||
sept.UndrlygAssetPosition = "3";
|
||||
}
|
||||
}
|
||||
sept.UndrlygAssetAmt = item.Quantity.ToString();
|
||||
sept.LNotinalPrincipleAmt = item.Quantity.ToString();
|
||||
if (item.PositionType == 1)
|
||||
{
|
||||
sept.LNotinalPrincipleAmt = item.TradingAmount.ToString();
|
||||
}
|
||||
|
||||
if (item.PositionType == 2)
|
||||
{
|
||||
sept.SNotinalPrincipleAmt = (-item.TradingAmount).ToString();
|
||||
}
|
||||
|
||||
if (!string.IsNullOrWhiteSpace(underlyingManager.UnderlyingInstrumentType))
|
||||
{
|
||||
sept.UndrlygAssetDtldType = "6";
|
||||
}
|
||||
else
|
||||
{
|
||||
sept.UndrlygAssetDtldType = "99";
|
||||
}
|
||||
swapEquityPaymentTupleModels.Add(sept);
|
||||
}
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
info.SwapEquityPaymentTuple = swapEquityPaymentTupleModels;
|
||||
info.ExceID = base.formatExceID();
|
||||
dataList.Add(info);
|
||||
note.id = 0;
|
||||
note.ExceId = info.ExceID;
|
||||
note.CreateTime = DateTime.Now;
|
||||
note.FileTag = FileTag;
|
||||
note.ReportType = ReportType;
|
||||
note.ReportDate = _reqInfo.ReportDate;
|
||||
note.InfoTag = formatInfoTag(info, true);
|
||||
note.OptTime = note.CreateTime;
|
||||
note.InfoCache = "";
|
||||
note.RetCode = "";
|
||||
note.RetMsg = "";
|
||||
note.ReportResponse = false;
|
||||
note.DataId = "";
|
||||
note.BizId = "";
|
||||
note.changeStatus = false;
|
||||
noteList.Add(note);
|
||||
}
|
||||
generateData(dataList, DataFlagsEnum.A1005.ToString());
|
||||
generateData(dataList, DataFlagsEnum.A1006.ToString());
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
var subsystemDataList = loadSubsystemDataSource<SwapEquityPaymentModel>(fileList, AddSubsystemNote);
|
||||
if (subsystemDataList != null && subsystemDataList.Count > 0)
|
||||
{
|
||||
@@ -267,14 +71,222 @@ namespace YLErp.Modules.SuperviseReportModule.SAC.Service
|
||||
return model;
|
||||
}
|
||||
|
||||
private void generateData(List<SwapEquityPaymentModel> dataList, string reportType)
|
||||
{
|
||||
// 当前生成的交易确认书编号
|
||||
var confirmationNos = ReportStatus.GetCacheInfo(reportType); //取出这一次报送交易要素的交易编号
|
||||
foreach (var confirmationNo in confirmationNos)
|
||||
{
|
||||
var info = new SwapEquityPaymentModel();
|
||||
var tradeIds = ReportStatus
|
||||
.GetCacheInfo(reportType + "_" + confirmationNo + "_" + _operationType)
|
||||
.Select(x => int.Parse(x)).ToList();
|
||||
info.OperationType = _operationType;
|
||||
info.ConfirmationNo = confirmationNo;
|
||||
SACReportNotes note = base.GetReportNotes(ReportType, formatInfoTag(info)).FirstOrDefault();
|
||||
if (note == null && _operationType == OptFlagsEnum.A)
|
||||
{
|
||||
info.OperationType = OptFlagsEnum.A;
|
||||
note = new SACReportNotes() { IsValid = true, };
|
||||
}
|
||||
else
|
||||
{
|
||||
if (note == null)
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
switch (_operationType)
|
||||
{
|
||||
case OptFlagsEnum.A:
|
||||
continue; //新增数据已报送,跳过
|
||||
case OptFlagsEnum.U:
|
||||
if (!note.changeStatus)
|
||||
{
|
||||
continue; //交易没有被修改过,跳过
|
||||
}
|
||||
|
||||
info.OperationType = OptFlagsEnum.U;
|
||||
note.IsValid = true;
|
||||
break;
|
||||
case OptFlagsEnum.D:
|
||||
// 如果有删除事件,报废止
|
||||
info.OperationType = OptFlagsEnum.D;
|
||||
note.IsValid = false;
|
||||
break;
|
||||
case OptFlagsEnum.NONE:
|
||||
default:
|
||||
throw new ServiceException("未知操作类型");
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
var swapEquityPaymentTupleModels = new List<SwapEquityPaymentTupleModel>();
|
||||
|
||||
#region 权益端支付明细
|
||||
|
||||
using (var db = new YLContext())
|
||||
{
|
||||
// 查询 swap flow event
|
||||
var query = (from sfe in db.swap_flow_event
|
||||
join t in db.trade on sfe.SwapTradeId equals t.id
|
||||
where tradeIds.Contains(sfe.SwapTradeId) && sfe.DataState == 100 &&
|
||||
(sfe.UnderlyingCode != null && sfe.UnderlyingCode != "")
|
||||
select new
|
||||
{
|
||||
sfe.PositionType,
|
||||
sfe.PayDirection,
|
||||
sfe.TradingAmountAvg,
|
||||
sfe.Quantity,
|
||||
sfe.TradingAmount,
|
||||
sfe.UnderlyingCode,
|
||||
sfe.EventType,
|
||||
sfe.ContractSize,
|
||||
t.StructureType,
|
||||
t.OpponentRole
|
||||
}).ToList();
|
||||
|
||||
var positionTypes = query.Select(O => O.PositionType).Distinct().ToList();
|
||||
|
||||
foreach (var item in query)
|
||||
{
|
||||
var underlyingManager =
|
||||
DataCacheProvider.GetUnderlyingDataSource().GetData(item.UnderlyingCode);
|
||||
var variety = DataCacheProvider.GetVarietyDataSource()
|
||||
.GetData(underlyingManager.UnderlyingTypeId);
|
||||
var sept = new SwapEquityPaymentTupleModel();
|
||||
sept.ConfirmationNo = confirmationNo;
|
||||
sept.OpenandClosingDate = _reqInfo.ReportDate.ToString();
|
||||
sept.UndrlygAssetCode = item.UnderlyingCode;
|
||||
sept.UndrlygAssetName = underlyingManager.UnderlyingName;
|
||||
sept.UndrlygAssetTradgPlc = variety.TradingMarket;
|
||||
if (positionTypes.Contains(1) && positionTypes.Contains(2))
|
||||
{
|
||||
// 多空组合
|
||||
sept.PaymentMethod = "4";
|
||||
}
|
||||
else if (positionTypes.Contains(1))
|
||||
{
|
||||
sept.PaymentMethod = "0";
|
||||
}
|
||||
else if (positionTypes.Contains(2))
|
||||
{
|
||||
sept.PaymentMethod = "1";
|
||||
}
|
||||
|
||||
if (item.PayDirection == 1)
|
||||
{
|
||||
if (item.OpponentRole.Equals("乙方"))
|
||||
{
|
||||
sept.Payer = "1";
|
||||
}
|
||||
else
|
||||
{
|
||||
sept.Payer = "0";
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
if (item.OpponentRole.Equals("乙方"))
|
||||
{
|
||||
sept.Payer = "0";
|
||||
}
|
||||
else
|
||||
{
|
||||
sept.Payer = "1";
|
||||
}
|
||||
}
|
||||
|
||||
if (item.ContractSize != null)
|
||||
{
|
||||
sept.ContractMultiplier = item.ContractSize.ToString();
|
||||
}
|
||||
|
||||
sept.PaymentFreq = "1";
|
||||
sept.UndrlygAssetPrice = item.TradingAmountAvg.RoundToMultiple(100.0m).ToString();
|
||||
if (item.EventType == 1)
|
||||
{
|
||||
if (item.PositionType == 1)
|
||||
{
|
||||
sept.UndrlygAssetPosition = "0";
|
||||
}
|
||||
else
|
||||
{
|
||||
sept.UndrlygAssetPosition = "1";
|
||||
}
|
||||
}
|
||||
else if (item.EventType == 2)
|
||||
{
|
||||
if (item.PositionType == 1)
|
||||
{
|
||||
sept.UndrlygAssetPosition = "2";
|
||||
}
|
||||
else
|
||||
{
|
||||
sept.UndrlygAssetPosition = "3";
|
||||
}
|
||||
}
|
||||
|
||||
sept.UndrlygAssetAmt = item.Quantity.ToString();
|
||||
sept.LNotinalPrincipleAmt = item.Quantity.ToString();
|
||||
if (item.PositionType == 1)
|
||||
{
|
||||
sept.LNotinalPrincipleAmt = item.TradingAmount.ToString();
|
||||
}
|
||||
|
||||
if (item.PositionType == 2)
|
||||
{
|
||||
sept.SNotinalPrincipleAmt = (-item.TradingAmount).ToString();
|
||||
}
|
||||
|
||||
if (!string.IsNullOrWhiteSpace(underlyingManager.UnderlyingInstrumentType))
|
||||
{
|
||||
sept.UndrlygAssetDtldType = "6";
|
||||
}
|
||||
else
|
||||
{
|
||||
sept.UndrlygAssetDtldType = "99";
|
||||
}
|
||||
|
||||
swapEquityPaymentTupleModels.Add(sept);
|
||||
}
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
info.SwapEquityPaymentTuple = swapEquityPaymentTupleModels;
|
||||
info.ExceID = base.formatExceID();
|
||||
dataList.Add(info);
|
||||
note.id = 0;
|
||||
note.ExceId = info.ExceID;
|
||||
note.CreateTime = DateTime.Now;
|
||||
note.FileTag = FileTag;
|
||||
note.ReportType = ReportType;
|
||||
note.ReportDate = _reqInfo.ReportDate;
|
||||
note.InfoTag = formatInfoTag(info, true);
|
||||
note.OptTime = note.CreateTime;
|
||||
note.InfoCache = "";
|
||||
note.RetCode = "";
|
||||
note.RetMsg = "";
|
||||
note.ReportResponse = false;
|
||||
note.DataId = "";
|
||||
note.BizId = "";
|
||||
note.changeStatus = false;
|
||||
noteList.Add(note);
|
||||
}
|
||||
}
|
||||
|
||||
public bool AddSubsystemNote(SwapEquityPaymentModel model, List<string> fileList, string tag)
|
||||
{
|
||||
SACReportNotes note = base.GetReportNotes(ReportType, formatInfoTag(model, true), dataSource: SACReportNotesCache).FirstOrDefault();//参数true要加,要不A和D会查到同一条记录,在D时候,就会和A相同的数据
|
||||
SACReportNotes note = base
|
||||
.GetReportNotes(ReportType, formatInfoTag(model, true), dataSource: SACReportNotesCache)
|
||||
.FirstOrDefault(); //参数true要加,要不A和D会查到同一条记录,在D时候,就会和A相同的数据
|
||||
if (note == null)
|
||||
{
|
||||
note = new SACReportNotes()
|
||||
{
|
||||
InfoCache = $"{{\"Tag\":\"{model.ConfirmationNo}\",\"DurationEventNO\":\"{model.DurationEventNO}\",\"Source\":\"Subsystem\",\"SubFileTag\":\"{tag}\",\"ExceID\":\"{model.ExceID}\"}}",
|
||||
InfoCache =
|
||||
$"{{\"Tag\":\"{model.ConfirmationNo}\",\"DurationEventNO\":\"{model.DurationEventNO}\",\"Source\":\"Subsystem\",\"SubFileTag\":\"{tag}\",\"ExceID\":\"{model.ExceID}\"}}",
|
||||
IsValid = true,
|
||||
};
|
||||
}
|
||||
@@ -283,13 +295,14 @@ namespace YLErp.Modules.SuperviseReportModule.SAC.Service
|
||||
switch (model.OperationType)
|
||||
{
|
||||
case OptFlagsEnum.A:
|
||||
return false;//新增数据已报送,跳过
|
||||
return false; //新增数据已报送,跳过
|
||||
case OptFlagsEnum.U:
|
||||
//多次U的时候,每次用最新的tag来赋值SubFileTag
|
||||
note.InfoCache = $"{{\"Tag\":\"{model.ConfirmationNo}\",\"DurationEventNO\":\"{model.DurationEventNO}\",\"Source\":\"Subsystem\",\"SubFileTag\":\"{tag}\",\"ExceID\":\"{model.ExceID}\"}}";
|
||||
note.InfoCache =
|
||||
$"{{\"Tag\":\"{model.ConfirmationNo}\",\"DurationEventNO\":\"{model.DurationEventNO}\",\"Source\":\"Subsystem\",\"SubFileTag\":\"{tag}\",\"ExceID\":\"{model.ExceID}\"}}";
|
||||
note.IsValid = true;
|
||||
break;
|
||||
case OptFlagsEnum.D://
|
||||
case OptFlagsEnum.D: //
|
||||
note.IsValid = false;
|
||||
break;
|
||||
case OptFlagsEnum.NONE:
|
||||
@@ -329,6 +342,7 @@ namespace YLErp.Modules.SuperviseReportModule.SAC.Service
|
||||
//第一列空白说明数据结束了;
|
||||
break;
|
||||
}
|
||||
|
||||
var optType = OptFlagsEnum.NONE;
|
||||
switch (dt.Rows[i][1]?.ToString())
|
||||
{
|
||||
@@ -348,6 +362,7 @@ namespace YLErp.Modules.SuperviseReportModule.SAC.Service
|
||||
optType = OptFlagsEnum.D;
|
||||
break;
|
||||
}
|
||||
|
||||
if (optType != _operationType)
|
||||
{
|
||||
continue;
|
||||
@@ -363,6 +378,7 @@ namespace YLErp.Modules.SuperviseReportModule.SAC.Service
|
||||
{
|
||||
model.DurationEventNO = null;
|
||||
}
|
||||
|
||||
model.Blank1 = GetDataSetValue(dt, i, 3);
|
||||
model.Blank2 = GetDataSetValue(dt, i, 4);
|
||||
|
||||
@@ -371,13 +387,16 @@ namespace YLErp.Modules.SuperviseReportModule.SAC.Service
|
||||
{
|
||||
continue;
|
||||
}
|
||||
List<SACReportNotes> notes = base.GetReportNotes(ReportType, formatInfoTag(model), dataSource: SACReportNotesCache);
|
||||
|
||||
List<SACReportNotes> notes = base.GetReportNotes(ReportType, formatInfoTag(model),
|
||||
dataSource: SACReportNotesCache);
|
||||
var note = notes.LastOrDefault();
|
||||
if (note == null && _operationType == OptFlagsEnum.A)
|
||||
{
|
||||
note = new SACReportNotes()
|
||||
{
|
||||
InfoCache = $"{{\"Tag\":\"{model.ConfirmationNo}\",\"DurationEventNO\":\"{model.DurationEventNO}\",\"Source\":\"Template\"}}",
|
||||
InfoCache =
|
||||
$"{{\"Tag\":\"{model.ConfirmationNo}\",\"DurationEventNO\":\"{model.DurationEventNO}\",\"Source\":\"Template\"}}",
|
||||
IsValid = true,
|
||||
};
|
||||
}
|
||||
@@ -387,10 +406,11 @@ namespace YLErp.Modules.SuperviseReportModule.SAC.Service
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
switch (_operationType)
|
||||
{
|
||||
case OptFlagsEnum.A:
|
||||
continue;//新增数据已报送,跳过
|
||||
continue; //新增数据已报送,跳过
|
||||
case OptFlagsEnum.U:
|
||||
note.IsValid = true;
|
||||
break;
|
||||
@@ -409,6 +429,7 @@ namespace YLErp.Modules.SuperviseReportModule.SAC.Service
|
||||
{
|
||||
model.BizID = note.BizId;
|
||||
}
|
||||
|
||||
model.ExceID = base.formatExceID(SACReportNotesCache);
|
||||
result.Add(model);
|
||||
ReportStatus.AddCacheInfo(CacheKey, cacheValue);
|
||||
@@ -429,6 +450,7 @@ namespace YLErp.Modules.SuperviseReportModule.SAC.Service
|
||||
noteList.Add(note);
|
||||
}
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
@@ -450,6 +472,7 @@ namespace YLErp.Modules.SuperviseReportModule.SAC.Service
|
||||
//第一列空白说明数据结束了;
|
||||
break;
|
||||
}
|
||||
|
||||
if (dt.Rows[i][0]?.ToString().Trim() != confirmationNo)
|
||||
{
|
||||
continue;
|
||||
@@ -480,6 +503,7 @@ namespace YLErp.Modules.SuperviseReportModule.SAC.Service
|
||||
result.Add(model);
|
||||
}
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
@@ -490,6 +514,7 @@ namespace YLErp.Modules.SuperviseReportModule.SAC.Service
|
||||
{
|
||||
result = $"{result}{_operationType}";
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
@@ -500,6 +525,7 @@ namespace YLErp.Modules.SuperviseReportModule.SAC.Service
|
||||
{
|
||||
throw new ServiceException($"InfoTag信息不匹配:{infoTag}");
|
||||
}
|
||||
|
||||
originalCode = arr[1];
|
||||
arr[1] = newCode.Replace("_", "-");
|
||||
return string.Join("_", arr);
|
||||
@@ -545,17 +571,18 @@ namespace YLErp.Modules.SuperviseReportModule.SAC.Service
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (listRoot.Count > 0)
|
||||
{
|
||||
var errMsg = new SacInfo("SwapEquityPayment", i)
|
||||
{
|
||||
FieldValue = item.ConfirmationNo,
|
||||
SubMaps = new List<SacInfo>(listRoot)
|
||||
FieldValue = item.ConfirmationNo, SubMaps = new List<SacInfo>(listRoot)
|
||||
};
|
||||
result.Add(errMsg);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
checkStatus = result.Count > 0;
|
||||
return result;
|
||||
}
|
||||
@@ -572,14 +599,17 @@ namespace YLErp.Modules.SuperviseReportModule.SAC.Service
|
||||
catch (Exception e)
|
||||
{
|
||||
LogFactory.GetLogger<ReportMasterAgrmtProductService>().Error(e);
|
||||
};
|
||||
}
|
||||
|
||||
;
|
||||
}
|
||||
|
||||
for (var i = 0; i < noteList.Count; i++)
|
||||
{
|
||||
base.SaveReportNotes(noteList[i]);
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
+65
-61
@@ -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 = "";
|
||||
|
||||
@@ -264,4 +264,9 @@
|
||||
<UpToDateCheckInput Remove="Views\TrsAccountManage\Edit.cshtml" />
|
||||
</ItemGroup>
|
||||
|
||||
|
||||
<ItemGroup>
|
||||
<Folder Include="App_Docs\导出模板\报送模板\" />
|
||||
</ItemGroup>
|
||||
|
||||
</Project>
|
||||
|
||||
Reference in New Issue
Block a user