1067 lines
56 KiB
C#
1067 lines
56 KiB
C#
using System.Data;
|
|
using System.Text.RegularExpressions;
|
|
using YieldChain.Helpers;
|
|
using YLErp.BLL;
|
|
using YLErp.DBModels.Consts;
|
|
using YLErp.DBModels.Enums;
|
|
using YLErp.Modules.EodModule;
|
|
using YLErp.Modules.SuperviseReportModule.SAC.Common;
|
|
using YLErp.Modules.SuperviseReportModule.SAC.Model;
|
|
using static alglib;
|
|
using static YLErp.DBModels.Consts.ConsReport;
|
|
|
|
namespace YLErp.Modules.SuperviseReportModule.SAC.Service
|
|
{
|
|
class ReportSwapTerminationService : ReportBaseService
|
|
{
|
|
public ReportSwapTerminationService(OptUserInfo optUser) : base(optUser)
|
|
{
|
|
}
|
|
|
|
protected override string _excelDataSourcePath => "交易相关\\";
|
|
|
|
protected override string _excelDataSourceFileName => "import_SwapTermination_template.xlsx";
|
|
|
|
protected override DataFlagsEnum BusiDataType => DataFlagsEnum.A1006;
|
|
|
|
private List<OptFlagsEnum> _validOperationType = null;
|
|
public override List<OptFlagsEnum> ValidOperationType
|
|
{
|
|
get
|
|
{
|
|
if (_validOperationType == null)
|
|
{
|
|
_validOperationType = new List<OptFlagsEnum>() {
|
|
OptFlagsEnum.A,
|
|
OptFlagsEnum.U,
|
|
OptFlagsEnum.D,
|
|
};
|
|
}
|
|
return _validOperationType;
|
|
}
|
|
}
|
|
|
|
protected override SuperviseReportTypeEnum ReportType => SuperviseReportTypeEnum.SAC_SwapDurationManagement;
|
|
List<SACReportNotes> noteList = new List<SACReportNotes>();
|
|
|
|
protected override BodyModel GenerateBody(out bool noData, out List<string> fileList)
|
|
{
|
|
fileList = new List<string>();
|
|
BodyModel model = new BodyModel();
|
|
List<SwapDurationManagementModel> dataList = new List<SwapDurationManagementModel>();
|
|
if ((PS.Config.ErpElement.SAC_ReportDataSource & SAC_ReportDataSourceEnum.Template) == SAC_ReportDataSourceEnum.Template)
|
|
{
|
|
dataList = GetSwapDurationManagementModel(out fileList);
|
|
}
|
|
if ((PS.Config.ErpElement.SAC_ReportDataSource & SAC_ReportDataSourceEnum.System) == SAC_ReportDataSourceEnum.System)
|
|
{
|
|
var cacheKey = $"{BusiDataType}";
|
|
var nextDate = _reqInfo.ReportDate.AddDays(1);
|
|
using (var db = new YLContext())
|
|
{
|
|
dataList.AddRange(GetOptionTerminationExtensionTimeFromDb(db, cacheKey, nextDate));
|
|
|
|
dataList.AddRange(GetOptionTerminationSettlementFromDb(db, cacheKey, nextDate));
|
|
}
|
|
}
|
|
|
|
if ((PS.Config.ErpElement.SAC_ReportDataSource & SAC_ReportDataSourceEnum.KingstarView) == SAC_ReportDataSourceEnum.KingstarView)
|
|
{
|
|
dataList.AddRange(GetSwapDurationManagementModelFromView(out fileList));
|
|
}
|
|
|
|
var subsystemDataList = loadSubsystemDataSource<SwapDurationManagementModel>(fileList, AddSubsystemNote);
|
|
if (subsystemDataList != null && subsystemDataList.Count > 0)
|
|
dataList.AddRange(subsystemDataList);
|
|
|
|
noData = dataList.Count == 0;
|
|
model.SwapDurationManagement = dataList;
|
|
return model;
|
|
}
|
|
|
|
public bool AddSubsystemNote(SwapDurationManagementModel model, List<string> fileList, string tag)
|
|
{
|
|
SACReportNotes note = base.GetReportNotes(ReportType, formatInfoTag(model, true)).FirstOrDefault();//参数true要加,要不A和D会查到同一条记录,在D时候,就会和A相同的数据
|
|
var isExtensionTime = model.DurationOperationType == ConsReport.OperationTypeMap["展期"];
|
|
DateTime date = DateTime.MinValue;
|
|
if (isExtensionTime)
|
|
{
|
|
DateTime.TryParse(model.RenewalDate, out date);
|
|
}
|
|
else
|
|
{
|
|
DateTime.TryParse(model.DurationOperationDate, out date);
|
|
}
|
|
if (note == null)
|
|
{
|
|
if (isExtensionTime)
|
|
{
|
|
string oldDateStr = "";
|
|
var oldData = base.GetReportNotes(SuperviseReportTypeEnum.SAC_OptionConfirmation, $"A1005_{model.ConfirmationNo.Replace("_", "-")}_成交_A").FirstOrDefault();
|
|
oldDateStr = Regex.Match(oldData?.InfoCache ?? "", "(?<=DueDate\":\")[^\"]+(?=\")").Value;
|
|
if (DateTime.TryParse(oldDateStr, out var oldDate))
|
|
{
|
|
oldDateStr = $",\"OldMaturityDate\":\"{oldDate.ToString("yyyy-MM-dd")}\"";
|
|
}
|
|
note = new SACReportNotes()
|
|
{
|
|
InfoCache = $"{{\"Tag\":\"{model.ConfirmationNo}\"{oldDateStr},\"NewMaturityDate\":\"{date.ToString("yyyy-MM-dd")}\",\"DurationEventNO\":\"{model.DurationEventNO}\",\"Source\":\"Subsystem\",\"SubFileTag\":\"{tag}\",\"ExceID\":\"{model.ExceID}\"}}",
|
|
IsValid = true,
|
|
};
|
|
}
|
|
else
|
|
{
|
|
note = new SACReportNotes()
|
|
{
|
|
InfoCache = $"{{\"Tag\":\"{model.ConfirmationNo}\",\"ValueDate\":\"{date.ToString("yyyy-MM-dd")}\",\"DurationEventNO\":\"{model.DurationEventNO}\",\"Source\":\"Subsystem\",\"SubFileTag\":\"{tag}\",\"ExceID\":\"{model.ExceID}\"}}",
|
|
IsValid = true,
|
|
};
|
|
}
|
|
|
|
}
|
|
else
|
|
{
|
|
switch (_operationType)
|
|
{
|
|
case OptFlagsEnum.A:
|
|
return false;//新增数据已报送,跳过
|
|
case OptFlagsEnum.U:
|
|
if (isExtensionTime)
|
|
{
|
|
string oldDateStr = "";
|
|
var oldData = base.GetReportNotes(SuperviseReportTypeEnum.SAC_OptionConfirmation, $"A1005_{model.ConfirmationNo.Replace("_", "-")}_成交_A").FirstOrDefault();
|
|
oldDateStr = Regex.Match(oldData?.InfoCache ?? "", "(?<=DueDate\":\")[^\"]+(?=\")").Value;
|
|
if (DateTime.TryParse(oldDateStr, out var oldDate))
|
|
{
|
|
oldDateStr = $",\"OldMaturityDate\":\"{oldDate.ToString("yyyy-MM-dd")}\"";
|
|
}
|
|
note.InfoCache = $"{{\"Tag\":\"{model.ConfirmationNo}\"{oldDateStr},\"NewMaturityDate\":\"{date.ToString("yyyy-MM-dd")}\",\"DurationEventNO\":\"{model.DurationEventNO}\",\"Source\":\"Subsystem\",\"SubFileTag\":\"{tag}\",\"ExceID\":\"{model.ExceID}\"}}";
|
|
}
|
|
else
|
|
{
|
|
note.InfoCache = $"{{\"Tag\":\"{model.ConfirmationNo}\",\"ValueDate\":\"{date.ToString("yyyy-MM-dd")}\",\"DurationEventNO\":\"{model.DurationEventNO}\",\"Source\":\"Subsystem\",\"SubFileTag\":\"{tag}\",\"ExceID\":\"{model.ExceID}\"}}";
|
|
}
|
|
note.IsValid = true;
|
|
break;
|
|
case OptFlagsEnum.D:
|
|
note.IsValid = false;
|
|
break;
|
|
case OptFlagsEnum.NONE:
|
|
default:
|
|
throw new ServiceException("未知操作类型");
|
|
}
|
|
}
|
|
|
|
if (!string.IsNullOrWhiteSpace(model.SwapDurationManagementAtt))
|
|
{
|
|
fileList.Add(model.SwapDurationManagementAtt);
|
|
}
|
|
|
|
var extensionTimeInfo = isExtensionTime ? "-" : "";
|
|
model.ExceID = base.formatExceID();
|
|
note.id = 0;
|
|
note.ExceId = model.ExceID;
|
|
note.CreateTime = DateTime.Now;
|
|
note.FileTag = FileTag;
|
|
note.ReportType = ReportType;
|
|
note.ReportDate = _reqInfo.ReportDate;
|
|
note.InfoTag = formatInfoTag(model, true, extensionTimeInfo);
|
|
note.OptTime = note.CreateTime;
|
|
note.RetCode = "";
|
|
note.RetMsg = "";
|
|
note.ReportResponse = false;
|
|
note.BizId = "";
|
|
note.changeStatus = false;
|
|
noteList.Add(note);
|
|
return true;
|
|
}
|
|
|
|
private List<SwapDurationManagementModel> GetOptionTerminationExtensionTimeFromDb(YLContext db, string cacheKey, DateTime nextDate)
|
|
{
|
|
List<SwapDurationManagementModel> dataList = new List<SwapDurationManagementModel>();
|
|
var extensionTimeList = (from et in db.ExtensionTime
|
|
join t in db.trade
|
|
on et.TradeId equals t.id
|
|
join tr in db.trade_contract_r.Where(O => O.Type == "交易确认书")
|
|
on t.id equals tr.TradeId
|
|
join ts in db.trade_swap
|
|
on t.id equals ts.TradeId
|
|
where
|
|
et.OptDate >= _reqInfo.ReportDate &&
|
|
et.OptDate < nextDate &&
|
|
t.TradeType == "收益互换" &&
|
|
tr.IsValid
|
|
select new
|
|
{
|
|
et.id,
|
|
et.TradeId,
|
|
et.OldMaturityDate,
|
|
et.NewMaturityDate,
|
|
et.IsValid,
|
|
et.OptDate,
|
|
tr.ContractCode,
|
|
t.StockEqvNotional,
|
|
ts.GetMarginRate,
|
|
ts.PayMarginRate
|
|
}).ToArray();
|
|
|
|
List<int> ids = extensionTimeList.Select(O => O.TradeId).ToList();
|
|
Dictionary<int, Dictionary<string, string>> metaDic = DbContext.TradeMeta.Where(O => ids.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 extensionTimeList)
|
|
{
|
|
var cacheValue = item.id.ToString();
|
|
if (ReportStatus.CheckCacheInfo(cacheKey, cacheValue))
|
|
{
|
|
continue;
|
|
}
|
|
if (metaDic.ContainsKey(item.TradeId))
|
|
{
|
|
var metaInfo = metaDic[item.TradeId];
|
|
if (metaInfo.ContainsKey(ConsTradeMetaKey.TradingPlace) && TradingPlaceMap[metaInfo[ConsTradeMetaKey.TradingPlace]] == "1")//跳过交易场所为报价系统的交易;
|
|
{
|
|
continue;
|
|
}
|
|
}
|
|
var info = new SwapDurationManagementModel();
|
|
|
|
//info.TradeId = item.TradeId.ToString();
|
|
var tempDate = item.OptDate.GetValueOrDefault().Date;
|
|
var count = db.trade_cash.Where(O => O.TradeId == item.TradeId && O.ValueDate < tempDate && (O.Action == "系统操作-行权费" || O.Action == "系统操作-平仓费")).Select(O => O.ValueDate).ToHashSet().Count;
|
|
count += db.ExtensionTime.Where(O => O.TradeId == item.TradeId && O.OptDate < tempDate).Select(O => O.OptDate).ToArray().Select(O => O.GetValueOrDefault().Date).ToHashSet().Count;
|
|
info.DurationEventNO = count.ToString("0000");
|
|
info.ConfirmationNo = item.ContractCode;
|
|
info.DurationOperationDate = item.OptDate?.ToString("yyyy-MM-dd");
|
|
List<SACReportNotes> notes = base.GetReportNotes(ReportType, $"_{info.ConfirmationNo.Replace("_", "-")}_", true);
|
|
var note = notes.FirstOrDefault(O => O.IsValid && O.InfoTag.Contains(formatInfoTag(info, extensionTimeInfo: item.id.ToString())));
|
|
if (!item.IsValid)
|
|
{//当前信息是无效的,报送过就是废止,否则就不需要报
|
|
if (note != null)
|
|
{
|
|
info.OperationType = OptFlagsEnum.D;
|
|
}
|
|
else
|
|
{
|
|
continue;
|
|
}
|
|
}
|
|
else
|
|
{//当前信息是有效的,报送过,就是修改,否则就是新增
|
|
if (note == null)
|
|
{
|
|
info.OperationType = OptFlagsEnum.A;
|
|
}
|
|
else
|
|
{
|
|
if (!note.changeStatus)
|
|
{
|
|
continue;
|
|
}
|
|
info.OperationType = OptFlagsEnum.U;
|
|
}
|
|
}
|
|
if (info.OperationType != _operationType)
|
|
{
|
|
continue;
|
|
}
|
|
switch (info.OperationType)
|
|
{
|
|
case OptFlagsEnum.A:
|
|
note = new SACReportNotes()
|
|
{
|
|
IsValid = true,
|
|
};
|
|
break;
|
|
case OptFlagsEnum.U:
|
|
note.IsValid = true;
|
|
break;
|
|
case OptFlagsEnum.D:
|
|
note.IsValid = false;
|
|
break;
|
|
}
|
|
if (info.OperationType != OptFlagsEnum.A)
|
|
{
|
|
info.BizID = note.BizId;
|
|
}
|
|
var infoCache = JsonHelper.Deserialize<Dictionary<string, string>>(note?.InfoCache) ?? new Dictionary<string, string>();
|
|
var oldMaturityDate = infoCache.TryGetValue("NewMaturityDate", out var date) ? DateTime.Parse(date) : item.OldMaturityDate;
|
|
var newMaturityDate = item.NewMaturityDate;
|
|
if (info.OperationType == OptFlagsEnum.D)
|
|
{
|
|
oldMaturityDate = infoCache.TryGetValue("OldMaturityDate", out date) ? DateTime.Parse(date) : item.OldMaturityDate;
|
|
newMaturityDate = infoCache.TryGetValue("NewMaturityDate", out date) ? DateTime.Parse(date) : item.NewMaturityDate;
|
|
}
|
|
else
|
|
{
|
|
if (newMaturityDate <= oldMaturityDate)
|
|
{
|
|
throw new ServiceException($"确认书编号:{item.ContractCode}\r\n新展期日:{newMaturityDate.ToString("yyyy-MM-dd")}\r\n原到期日:{oldMaturityDate.ToString("yyyy-MM-dd")}\r\n新展期日应大于原到期日");
|
|
}
|
|
}
|
|
//info.ExpirationDate = item.OldMaturityDate.ToString("yyyy-MM-dd");
|
|
info.DurationOperationType = OperationTypeMap["展期"];
|
|
info.RenewalDate = newMaturityDate.ToString("yyyy-MM-dd");
|
|
info.Balance = Math.Max(item.StockEqvNotional, 0).ToString("0.00");
|
|
info.MarginRatio = ((item.GetMarginRate ?? item.PayMarginRate) * 100)?.ToString("0.00");
|
|
info.ExceID = base.formatExceID();
|
|
|
|
ReportStatus.AddCacheInfo(cacheKey, cacheValue);
|
|
dataList.Add(info);
|
|
note.id = 0;
|
|
note.ExceId = info.ExceID;
|
|
note.InfoCache = $"{{\"Tag\":\"{info.ConfirmationNo}\",\"OldMaturityDate\":\"{oldMaturityDate.ToString("yyyy-MM-dd")}\",\"NewMaturityDate\":\"{newMaturityDate.ToString("yyyy-MM-dd")}\",\"DurationEventNO\":\"{info.DurationEventNO}\",\"Source\":\"System\"}}";
|
|
note.CreateTime = DateTime.Now;
|
|
note.FileTag = FileTag;
|
|
note.ReportType = ReportType;
|
|
note.ReportDate = _reqInfo.ReportDate;
|
|
note.InfoTag = formatInfoTag(info, true, item.id.ToString());
|
|
note.OptTime = note.CreateTime;
|
|
note.RetCode = "";
|
|
note.RetMsg = "";
|
|
note.ReportResponse = false;
|
|
note.BizId = "";
|
|
note.DataId = "";
|
|
note.changeStatus = false;
|
|
noteList.Add(note);
|
|
}
|
|
return dataList;
|
|
}
|
|
|
|
private List<SwapDurationManagementModel> GetOptionTerminationSettlementFromDb(YLContext db, string cacheKey, DateTime nextDate)
|
|
{
|
|
List<SwapDurationManagementModel> dataList = new List<SwapDurationManagementModel>();
|
|
var actions = new List<string>() { "系统操作-平仓费", "系统操作-行权费"/*, "系统操作-互换"*/ };
|
|
//当天有回退记录的资金记录
|
|
var query = (from t in db.trade
|
|
join log in db.TradeAuditLog on t.id equals log.TradeId
|
|
join tc in db.trade_cash on t.id equals tc.TradeId
|
|
join tr in db.trade_contract_r.Where(O => O.Type == "交易确认书")
|
|
on t.id equals tr.TradeId
|
|
join td in db.trade_contract_document
|
|
on tr.ContractCode equals td.Code
|
|
join ts in db.trade_swap
|
|
on t.id equals ts.TradeId
|
|
where log.OptDate >= _reqInfo.ReportDate && log.OptDate < nextDate && log.OptType == "交易回退" &&
|
|
(actions.Contains(tc.Action) || (tc.Action == "系统操作-互换" && tc.ExerciseWay == "到期行权")) && /*t.UnderlyingInstrumentType == "Stock" &&*/ t.TradeType == "收益互换" && tr.IsValid
|
|
select new
|
|
{
|
|
tcId = tc.id,
|
|
tc.OptDate,
|
|
tradeValid = t.ValidState != "InValid",
|
|
tradecashValid = tc.ValidState != "InValid" && !tc.IsDeleted,
|
|
tradeContractRValid = tr.IsValid,
|
|
t.id,
|
|
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,
|
|
tc.ValueDate,
|
|
tc.Notional,
|
|
tc.UnwindNotional,
|
|
tc.Amount,
|
|
t.OriginalNotional,
|
|
tr.ContractCode,
|
|
t.QuoteCurrency,
|
|
t.SettlementCurrency,
|
|
ts.SwapType,
|
|
ts.IsPayFloatingProfit,
|
|
ts.GetLongShort,
|
|
ts.PayLongShort,
|
|
ts.GetMarginRate,
|
|
ts.PayMarginRate,
|
|
}).Union//当天有了结的资金记录
|
|
(from t in db.trade
|
|
join tc in db.trade_cash
|
|
on t.id equals tc.TradeId
|
|
join tr in db.trade_contract_r.Where(O => O.Type == "交易确认书")
|
|
on t.id equals tr.TradeId
|
|
join td in db.trade_contract_document
|
|
on tr.ContractCode equals td.Code
|
|
join ts in db.trade_swap
|
|
on t.id equals ts.TradeId
|
|
where tc.ValueDate == _reqInfo.DataDate &&
|
|
t.ValidState != "InValid" && tc.ValidState != "InValid" && !tc.IsDeleted && tr.IsValid &&
|
|
/*t.UnderlyingInstrumentType == "Stock" &&*/ t.TradeType == "收益互换" &&
|
|
(actions.Contains(tc.Action) || (tc.Action == "系统操作-互换" && tc.ExerciseWay == "到期行权"))
|
|
select new
|
|
{
|
|
tcId = tc.id,
|
|
tc.OptDate,
|
|
tradeValid = t.ValidState != "InValid",
|
|
tradecashValid = tc.ValidState != "InValid" && !tc.IsDeleted,
|
|
tradeContractRValid = tr.IsValid,
|
|
t.id,
|
|
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,
|
|
tc.ValueDate,
|
|
tc.Notional,
|
|
tc.UnwindNotional,
|
|
tc.Amount,
|
|
t.OriginalNotional,
|
|
tr.ContractCode,
|
|
t.QuoteCurrency,
|
|
t.SettlementCurrency,
|
|
ts.SwapType,
|
|
ts.IsPayFloatingProfit,
|
|
ts.GetLongShort,
|
|
ts.PayLongShort,
|
|
ts.GetMarginRate,
|
|
ts.PayMarginRate,
|
|
}).ToArray().GroupBy(O => new { O.id, O.ValueDate }).ToDictionary(K => K.Key, V => V.ToList());
|
|
List<int> ids = query.Keys.Select(O => O.id).ToList();
|
|
Dictionary<int, Dictionary<string, string>> metaDic = DbContext.TradeMeta.Where(O => ids.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())
|
|
{
|
|
var cacheValue = item.Key.id.ToString() + item.Key.ValueDate.ToString("_yyyy-MM-dd");
|
|
if (ReportStatus.CheckCacheInfo(cacheKey, cacheValue))
|
|
{
|
|
continue;
|
|
}
|
|
if (metaDic.ContainsKey(item.Key.id))
|
|
{
|
|
var metaInfo = metaDic[item.Key.id];
|
|
if (metaInfo.ContainsKey(ConsTradeMetaKey.TradingPlace) && TradingPlaceMap[metaInfo[ConsTradeMetaKey.TradingPlace]] == "1")//跳过交易场所为报价系统的交易;
|
|
{
|
|
continue;
|
|
}
|
|
}
|
|
var info = new SwapDurationManagementModel();
|
|
|
|
//info.TradeId = item.Key.id.ToString();
|
|
var validItem = item.Value.FirstOrDefault(O => O.tradecashValid);
|
|
var invalidItem = item.Value.FirstOrDefault(O => !O.tradecashValid);
|
|
var obj = invalidItem ?? validItem;
|
|
var tempDate = obj.ValueDate;
|
|
var tcQuery = db.trade_cash.Where(O => O.TradeId == obj.id && O.ValueDate < tempDate && actions.Contains(O.Action));
|
|
var count = tcQuery.Select(O => O.ValueDate).ToHashSet().Count;
|
|
count += db.ExtensionTime.Where(O => O.TradeId == obj.id && O.OptDate < tempDate).Select(O => O.OptDate).ToArray().Select(O => O.GetValueOrDefault().Date).ToHashSet().Count;
|
|
info.DurationEventNO = count.ToString("0000");
|
|
info.DurationOperationDate = obj.ValueDate.ToString("yyyy-MM-dd");
|
|
info.ConfirmationNo = obj.ContractCode;
|
|
List<SACReportNotes> notes = base.GetReportNotes(ReportType, $"_{info.ConfirmationNo.Replace("_", "-")}_", true);
|
|
var note = notes.FirstOrDefault(O => O.IsValid && O.InfoTag.Contains(formatInfoTag(info)) && O.InfoCache.Contains(info.DurationOperationDate));
|
|
if (validItem == null && invalidItem != null)
|
|
{//有效资金记录不存在,无效资金记录存在时,当天报送过就是废止,否则就不需要报
|
|
obj = invalidItem;
|
|
if (note != null)
|
|
{
|
|
info.OperationType = OptFlagsEnum.D;
|
|
}
|
|
else
|
|
{
|
|
continue;
|
|
}
|
|
}
|
|
else
|
|
{//有效资金记录存在时,当天报送过,就是修改,否则就是新增
|
|
obj = validItem;
|
|
if (note == null)
|
|
{
|
|
info.OperationType = OptFlagsEnum.A;
|
|
}
|
|
else
|
|
{
|
|
if (!note.changeStatus)
|
|
{
|
|
continue;
|
|
}
|
|
info.OperationType = OptFlagsEnum.U;
|
|
}
|
|
}
|
|
if (info.OperationType != _operationType)
|
|
{
|
|
continue;
|
|
}
|
|
switch (info.OperationType)
|
|
{
|
|
case OptFlagsEnum.A:
|
|
note = new SACReportNotes()
|
|
{
|
|
IsValid = true,
|
|
};
|
|
break;
|
|
case OptFlagsEnum.U:
|
|
note.IsValid = true;
|
|
break;
|
|
case OptFlagsEnum.D:
|
|
note.IsValid = false;
|
|
break;
|
|
}
|
|
if (info.OperationType != OptFlagsEnum.A)
|
|
{
|
|
info.BizID = note.BizId;
|
|
}
|
|
info.DurationOperationType = OperationTypeMap["终止"];
|
|
if (obj.SwapType == "普通")
|
|
{
|
|
var longShort = obj.IsPayFloatingProfit ? obj.PayLongShort : obj.GetLongShort;
|
|
info.SwapType = ConsReport.SwapTypeMap["客户" + longShort];
|
|
}
|
|
else
|
|
{
|
|
info.SwapType = ConsReport.SwapTypeMap[obj.SwapType];
|
|
}
|
|
var quoteRate = new EodCurrencyRateService(UserInfo).GetCurrencyRate(obj.QuoteCurrency, "CNY", obj.ValueDate);
|
|
var settlementRate = new EodCurrencyRateService(UserInfo).GetCurrencyRate(obj.SettlementCurrency, "CNY", obj.ValueDate);
|
|
var currentStockEqvNotional = Math.Round(Math.Min((obj.UnwindNotional / obj.OriginalNotional * obj.OriginalStockEqvNotional) ?? 0, obj.OriginalStockEqvNotional ?? 0) * quoteRate, 2);
|
|
var latestStockEqvNotional = Math.Round(Math.Min((obj.Notional / obj.OriginalNotional * obj.OriginalStockEqvNotional) ?? 0, obj.OriginalStockEqvNotional ?? 0) * quoteRate, 2);
|
|
var isComplete = Math.Abs(obj.Notional - (obj.UnwindNotional ?? 0)) < 1e-4;
|
|
if (isComplete)
|
|
{
|
|
var tcArr = tcQuery.Where(O => O.ValidState != "InValid" && O.IsDeleted == false).ToArray();
|
|
var originalStockEqvNotional = obj.OriginalStockEqvNotional ?? 0;
|
|
currentStockEqvNotional = originalStockEqvNotional - tcArr.Sum(O => Math.Round(Math.Min((O.UnwindNotional / obj.OriginalNotional * originalStockEqvNotional) ?? 0, originalStockEqvNotional) * quoteRate, 2));
|
|
latestStockEqvNotional = currentStockEqvNotional;
|
|
}
|
|
//info.TerminationAmount = currentStockEqvNotional.ToString("0.00");
|
|
info.ChangeAmount = (-currentStockEqvNotional).ToString("0.00");
|
|
info.Balance = Math.Max((latestStockEqvNotional - currentStockEqvNotional), 0).ToString("0.00");
|
|
info.AmountPaidThisTime = (obj.Amount * settlementRate * -1).ToString();
|
|
info.MarginRatio = ((obj.GetMarginRate ?? obj.PayMarginRate) * 100)?.ToString("0.00");
|
|
if (double.TryParse(info.Balance, out var temp) && temp > 0)
|
|
{
|
|
var currentPosition = new CurrentPositionDetailModel();
|
|
currentPosition.UndrlygAssetCode = obj.UnderlyingCode;
|
|
var codeInfo = DataCacheProvider.GetUnderlyingDataSource().GetData(obj.UnderlyingCode);
|
|
currentPosition.UndrlygAssetTradgPlc = string.IsNullOrWhiteSpace(codeInfo.MarketName) ? "其他" : codeInfo.MarketName;
|
|
|
|
if (SwapUndrlygAssetDtldTypeMap.TryGetValue(ConsGlobal.InstrumentType.GetDesc(codeInfo.UnderlyingInstrumentType), out var AssetDtldType))
|
|
{
|
|
currentPosition.UndrlygAssetDtldType = AssetDtldType;
|
|
}
|
|
else
|
|
{
|
|
currentPosition.UndrlygAssetDtldType = UndrlygAssetDtldTypeMap["其他标的"];
|
|
}
|
|
var notional = obj.Notional - (obj.UnwindNotional ?? 0);
|
|
currentPosition.UndrlygAssetName = codeInfo.UnderlyingName;
|
|
currentPosition.InvestorPosition = ConsReport.SwapTypeMap["客户" + (obj.IsPayFloatingProfit ? obj.PayLongShort : obj.GetLongShort)];
|
|
currentPosition.UndrlygAssetAmt = (notional / codeInfo.CountRatio / codeInfo.ContractSize).ToString("0.000000");
|
|
currentPosition.ContractMultiplier = codeInfo.ContractSize.ToString("0");
|
|
currentPosition.UndrlygAssetPrice = (obj.SpotPrice * quoteRate)?.ToString("0.0000");
|
|
currentPosition.NotinalPrincipleAmt = Math.Max((latestStockEqvNotional - currentStockEqvNotional), 0).ToString("0.0000");
|
|
info.CurrentPositionDetails = new List<CurrentPositionDetailModel>() { currentPosition };
|
|
}
|
|
info.ExceID = base.formatExceID();
|
|
|
|
ReportStatus.AddCacheInfo(cacheKey, cacheValue);
|
|
ReportStatus.AddCacheInfo($"{cacheKey}_{info.ConfirmationNo}_{info.DurationEventNO}", currentStockEqvNotional.ToString("0.00"));
|
|
dataList.Add(info);
|
|
note.id = 0;
|
|
note.ExceId = info.ExceID;
|
|
note.InfoCache = $"{{\"Tag\":\"{info.ConfirmationNo}\",\"ValueDate\":\"{info.DurationOperationDate}\",\"DurationEventNO\":\"{info.DurationEventNO}\",\"Source\":\"System\"}}";
|
|
note.CreateTime = DateTime.Now;
|
|
note.FileTag = FileTag;
|
|
note.ReportType = ReportType;
|
|
note.ReportDate = _reqInfo.ReportDate;
|
|
note.InfoTag = formatInfoTag(info, true);
|
|
note.OptTime = note.CreateTime;
|
|
note.RetCode = "";
|
|
note.RetMsg = "";
|
|
note.ReportResponse = false;
|
|
note.BizId = "";
|
|
note.DataId = "";
|
|
note.changeStatus = false;
|
|
noteList.Add(note);
|
|
}
|
|
return dataList;
|
|
}
|
|
|
|
private List<SwapDurationManagementModel> GetSwapDurationManagementModel(out List<string> fileList)
|
|
{
|
|
fileList = new List<string>();
|
|
List<SwapDurationManagementModel> result = new List<SwapDurationManagementModel>();
|
|
if (_excelDataSource != null && _excelDataSource.Tables.Contains("互换交易存续期明细"))
|
|
{
|
|
string sourcePath = Path.Combine(_excelDataSourceRootPath, "附件");
|
|
var cacheKey = $"{BusiDataType}";
|
|
DataTable dt = _excelDataSource.Tables["互换交易存续期明细"];
|
|
for (int i = 1; i < dt.Rows.Count; i++)
|
|
{
|
|
if (string.IsNullOrWhiteSpace(dt.Rows[i][0]?.ToString()))
|
|
{
|
|
//第一列空白说明数据结束了;
|
|
break;
|
|
}
|
|
var optType = OptFlagsEnum.NONE;
|
|
switch (dt.Rows[i][1]?.ToString())
|
|
{
|
|
case "首次":
|
|
optType = OptFlagsEnum.A;
|
|
break;
|
|
case "变更":
|
|
optType = OptFlagsEnum.U;
|
|
break;
|
|
case "废止":
|
|
optType = OptFlagsEnum.D;
|
|
break;
|
|
}
|
|
if (optType != _operationType)
|
|
{
|
|
continue;
|
|
}
|
|
|
|
SwapDurationManagementModel model = new SwapDurationManagementModel();
|
|
|
|
model.ConfirmationNo = GetDataSetValue(dt, i, 0);
|
|
model.OperationType = optType;
|
|
model.SwapType = ConsReport.SwapTypeMap[GetDataSetValue(dt, i, 2)];
|
|
model.DurationEventNO = GetDataSetValue(dt, i, 3);
|
|
model.DurationOperationType = ConsReport.OperationTypeMap[GetDataSetValue(dt, i, 4)];
|
|
model.DurationOperationDate = GetDataSetValue(dt, i, 5);
|
|
model.RenewalDate = GetDataSetValue(dt, i, 6);
|
|
model.DefaultingParty = ConsReport.FillPartyMap[GetDataSetValue(dt, i, 7)];
|
|
model.DefaultEvent = GetDataSetValue(dt, i, 8);
|
|
model.ChangeAmount = GetDataSetValue(dt, i, 9);
|
|
model.Balance = GetDataSetValue(dt, i, 10);
|
|
model.AmountPaidThisTime = GetDataSetValue(dt, i, 11);
|
|
model.MarginRatio = GetDataSetValue(dt, i, 12);
|
|
model.SwapDurationManagementAtt = GetDataSetValue(dt, i, 13);
|
|
model.Blank1 = GetDataSetValue(dt, i, 14);
|
|
model.Blank2 = GetDataSetValue(dt, i, 15);
|
|
|
|
var isExtensionTime = model.DurationOperationType == ConsReport.OperationTypeMap["展期"];
|
|
DateTime date = DateTime.MinValue;
|
|
if (isExtensionTime)
|
|
{
|
|
DateTime.TryParse(model.RenewalDate, out date);
|
|
}
|
|
else
|
|
{
|
|
DateTime.TryParse(model.DurationOperationDate, out date);
|
|
}
|
|
var cacheValue = $"{model.ConfirmationNo}_{model.DurationEventNO}_";
|
|
if (ReportStatus.CheckCacheInfo(cacheKey, cacheValue))
|
|
{
|
|
continue;
|
|
}
|
|
if (!string.IsNullOrWhiteSpace(model.SwapDurationManagementAtt))
|
|
{
|
|
var path = Path.Combine(sourcePath, model.SwapDurationManagementAtt);
|
|
if (!ReportStatus.CheckFileLength(path))
|
|
{
|
|
break;
|
|
}
|
|
fileList.Add(path);
|
|
}
|
|
var extensionTimeInfo = isExtensionTime ? "-" : "";
|
|
List<SACReportNotes> notes = base.GetReportNotes(ReportType, $"_{model.ConfirmationNo.Replace("_", "-")}_", true);
|
|
//永远查找现有成功报送了结的新增记录,而不是修改;
|
|
var note = notes.LastOrDefault(O => O.IsValid && O.InfoTag.Contains(formatInfoTag(model, extensionTimeInfo: extensionTimeInfo)) && O.InfoCache.Contains(date.ToString("yyyy-MM-dd")));
|
|
if (note == null && _operationType == OptFlagsEnum.A)
|
|
{
|
|
if (isExtensionTime)
|
|
{
|
|
string oldDateStr = "";
|
|
var oldData = base.GetReportNotes(SuperviseReportTypeEnum.SAC_OptionConfirmation, $"A1005_{model.ConfirmationNo.Replace("_", "-")}_成交_A").FirstOrDefault();
|
|
oldDateStr = Regex.Match(oldData?.InfoCache ?? "", "(?<=DueDate\":\")[^\"]+(?=\")").Value;
|
|
if (DateTime.TryParse(oldDateStr, out var oldDate))
|
|
{
|
|
oldDateStr = $",\"OldMaturityDate\":\"{oldDate.ToString("yyyy-MM-dd")}\"";
|
|
}
|
|
note = new SACReportNotes()
|
|
{
|
|
InfoCache = $"{{\"Tag\":\"{model.ConfirmationNo}\"{oldDateStr},\"NewMaturityDate\":\"{date.ToString("yyyy-MM-dd")}\",\"DurationEventNO\":\"{model.DurationEventNO}\",\"Source\":\"Template\"}}",
|
|
IsValid = true,
|
|
};
|
|
}
|
|
else
|
|
{
|
|
note = new SACReportNotes()
|
|
{
|
|
InfoCache = $"{{\"Tag\":\"{model.ConfirmationNo}\",\"ValueDate\":\"{date.ToString("yyyy-MM-dd")}\",\"DurationEventNO\":\"{model.DurationEventNO}\",\"Source\":\"Template\"}}",
|
|
IsValid = true,
|
|
};
|
|
}
|
|
}
|
|
else
|
|
{
|
|
if (note == null)
|
|
{
|
|
continue;
|
|
}
|
|
switch (_operationType)
|
|
{
|
|
case OptFlagsEnum.A:
|
|
continue;//新增数据已报送,跳过
|
|
case OptFlagsEnum.U:
|
|
note.IsValid = true;
|
|
break;
|
|
case OptFlagsEnum.D:
|
|
note.IsValid = false;
|
|
break;
|
|
case OptFlagsEnum.NONE:
|
|
default:
|
|
throw new ServiceException("未知操作类型");
|
|
}
|
|
note.InfoCache = Regex.Replace(note.InfoCache, "(?<=NewMaturityDate\":\")[^\"]+ (?= \")", date.ToString("yyyy-MM-dd"));
|
|
}
|
|
|
|
model.CurrentPositionDetails = GetCurrentPositionDetailsModel(model.ConfirmationNo);
|
|
|
|
if (model.OperationType != OptFlagsEnum.A)
|
|
{
|
|
model.BizID = note.BizId;
|
|
}
|
|
model.ExceID = base.formatExceID();
|
|
result.Add(model);
|
|
ReportStatus.AddCacheInfo(cacheKey, cacheValue);
|
|
note.id = 0;
|
|
note.ExceId = model.ExceID;
|
|
note.CreateTime = DateTime.Now;
|
|
note.FileTag = FileTag;
|
|
note.ReportType = ReportType;
|
|
note.ReportDate = _reqInfo.ReportDate;
|
|
note.InfoTag = formatInfoTag(model, true, extensionTimeInfo);
|
|
note.OptTime = note.CreateTime;
|
|
note.RetCode = "";
|
|
note.RetMsg = "";
|
|
note.ReportResponse = false;
|
|
note.BizId = "";
|
|
note.DataId = "";
|
|
note.changeStatus = false;
|
|
noteList.Add(note);
|
|
}
|
|
}
|
|
return result;
|
|
}
|
|
|
|
private List<SwapDurationManagementModel> GetSwapDurationManagementModelFromView(out List<string> fileList)
|
|
{
|
|
fileList = new List<string>();
|
|
List<SwapDurationManagementModel> result = new List<SwapDurationManagementModel>();
|
|
if (_viewDataSource != null && _viewDataSource.Tables.Contains("互换交易存续期管理"))
|
|
{
|
|
var ftpHelper = new FtpHelper(PS.Config.ErpElement.KingstarView_RemotePath, PS.Config.ErpElement.KingstarView_RemoteUser, PS.Config.ErpElement.KingstarView_RemotePassword, PS.Config.ErpElement.KingstarView_FtpUsePassive, 3000, PS.Config.ErpElement.KingstarView_EnableSsl);
|
|
var cacheKey = $"{BusiDataType}";
|
|
DataTable dt = _viewDataSource.Tables["互换交易存续期管理"];
|
|
for (int i = 0; i < dt.Rows.Count; i++)
|
|
{
|
|
|
|
var optType = OptFlagsEnum.NONE;
|
|
switch (GetDataSetValue(dt, i, "OPERATIONTYPE"))
|
|
{
|
|
case "A":
|
|
optType = OptFlagsEnum.A;
|
|
break;
|
|
case "U":
|
|
optType = OptFlagsEnum.U;
|
|
break;
|
|
case "D":
|
|
optType = OptFlagsEnum.D;
|
|
break;
|
|
}
|
|
if (optType != _operationType)
|
|
{
|
|
continue;
|
|
}
|
|
|
|
SwapDurationManagementModel model = new SwapDurationManagementModel();
|
|
model.IgnoreCheck = true;
|
|
model.ConfirmationNo = GetDataSetValue(dt, i, "CONFIRMATIONNO");
|
|
model.OperationType = optType;
|
|
|
|
model.DurationEventNO = GetDataSetValue(dt, i, "DURATIONEVENTNO");
|
|
model.DurationOperationType = GetDataSetValue(dt, i, "DURATIONOPERATIONTYPE");
|
|
model.DurationOperationDate = GetDataSetValue(dt, i, "DURATIONOPERATIONDATE");
|
|
model.RenewalDate = GetDataSetValue(dt, i, "RENEWALDATE");
|
|
model.DefaultingParty = GetDataSetValue(dt, i, "DEFAULTINGPARTY");
|
|
model.DefaultEvent = GetDataSetValue(dt, i, "DEFAULTEVENT");
|
|
model.ChangeAmount = GetDataSetValue(dt, i, "CHANGEAMOUNT");
|
|
model.Balance = GetDataSetValue(dt, i, "BALANCE");
|
|
model.AmountPaidThisTime = GetDataSetValue(dt, i, "AMOUNTPAIDTHISTIME");
|
|
model.MarginRatio = GetDataSetValue(dt, i, "MARGINRATIO");
|
|
model.SwapDurationManagementAtt = GetDataSetValue(dt, i, "SWAPDURATIONMANAGEMENTATT");
|
|
model.Blank1 = GetDataSetValue(dt, i, "BLANK1");
|
|
model.Blank2 = GetDataSetValue(dt, i, "BLANK2");
|
|
|
|
var isExtensionTime = model.DurationOperationType == ConsReport.OperationTypeMap["展期"];
|
|
DateTime date = DateTime.MinValue;
|
|
if (isExtensionTime)
|
|
{
|
|
DateTime.TryParse(model.RenewalDate, out date);
|
|
}
|
|
else
|
|
{
|
|
DateTime.TryParse(model.DurationOperationDate, out date);
|
|
}
|
|
var cacheValue = $"{model.ConfirmationNo}_{model.DurationEventNO}_";
|
|
if (ReportStatus.CheckCacheInfo(cacheKey, cacheValue))
|
|
{
|
|
continue;
|
|
}
|
|
if (!string.IsNullOrWhiteSpace(model.SwapDurationManagementAtt))
|
|
{
|
|
var downloadRet = ftpHelper.DownloadFile(CreateViewAttDownloadPath(model.SwapDurationManagementAtt), ViewLocalAttFileDir + @"\kingstar\", out string message);
|
|
LogFactory.GetLogger("ftpHelper.DownloadFile").Info($"下载结果:{ViewLocalAttFileDir},{model.SwapDurationManagementAtt},{downloadRet}");
|
|
var path = downloadRet;
|
|
if (!ReportStatus.CheckFileLength(path))
|
|
{
|
|
break;
|
|
}
|
|
fileList.Add(path);
|
|
model.SwapDurationManagementAtt = Path.GetFileName(path);
|
|
}
|
|
var extensionTimeInfo = isExtensionTime ? "-" : "";
|
|
List<SACReportNotes> notes = base.GetReportNotes(ReportType, $"_{model.ConfirmationNo.Replace("_", "-")}_", true);
|
|
//永远查找现有成功报送了结的新增记录,而不是修改;
|
|
var note = notes.LastOrDefault(O => O.IsValid && O.InfoTag.Contains(formatInfoTag(model, extensionTimeInfo: extensionTimeInfo)) && O.InfoCache.Contains(date.ToString("yyyy-MM-dd")));
|
|
if (note == null && _operationType == OptFlagsEnum.A)
|
|
{
|
|
if (isExtensionTime)
|
|
{
|
|
string oldDateStr = "";
|
|
var oldData = base.GetReportNotes(SuperviseReportTypeEnum.SAC_OptionConfirmation, $"A1005_{model.ConfirmationNo.Replace("_", "-")}_成交_A").FirstOrDefault();
|
|
oldDateStr = Regex.Match(oldData?.InfoCache ?? "", "(?<=DueDate\":\")[^\"]+(?=\")").Value;
|
|
if (DateTime.TryParse(oldDateStr, out var oldDate))
|
|
{
|
|
oldDateStr = $",\"OldMaturityDate\":\"{oldDate.ToString("yyyy-MM-dd")}\"";
|
|
}
|
|
note = new SACReportNotes()
|
|
{
|
|
InfoCache = $"{{\"Tag\":\"{model.ConfirmationNo}\"{oldDateStr},\"NewMaturityDate\":\"{date.ToString("yyyy-MM-dd")}\",\"DurationEventNO\":\"{model.DurationEventNO}\",\"Source\":\"KingstarView\"}}",
|
|
IsValid = true,
|
|
};
|
|
}
|
|
else
|
|
{
|
|
note = new SACReportNotes()
|
|
{
|
|
InfoCache = $"{{\"Tag\":\"{model.ConfirmationNo}\",\"ValueDate\":\"{date.ToString("yyyy-MM-dd")}\",\"DurationEventNO\":\"{model.DurationEventNO}\",\"Source\":\"KingstarView\"}}",
|
|
IsValid = true,
|
|
};
|
|
}
|
|
}
|
|
else
|
|
{
|
|
if (note == null)
|
|
{
|
|
continue;
|
|
}
|
|
switch (_operationType)
|
|
{
|
|
case OptFlagsEnum.A:
|
|
continue;//新增数据已报送,跳过
|
|
case OptFlagsEnum.U:
|
|
note.IsValid = true;
|
|
break;
|
|
case OptFlagsEnum.D:
|
|
note.IsValid = false;
|
|
break;
|
|
case OptFlagsEnum.NONE:
|
|
default:
|
|
throw new ServiceException("未知操作类型");
|
|
}
|
|
note.InfoCache = Regex.Replace(note.InfoCache, "(?<=NewMaturityDate\":\")[^\"]+ (?= \")", date.ToString("yyyy-MM-dd"));
|
|
}
|
|
|
|
model.CurrentPositionDetails = GetCurrentPositionDetailsModelFromView(model.ConfirmationNo);
|
|
|
|
if (model.OperationType != OptFlagsEnum.A)
|
|
{
|
|
model.BizID = note.BizId;
|
|
}
|
|
model.ExceID = base.formatExceID();
|
|
result.Add(model);
|
|
ReportStatus.AddCacheInfo(cacheKey, cacheValue);
|
|
note.id = 0;
|
|
note.ExceId = model.ExceID;
|
|
note.CreateTime = DateTime.Now;
|
|
note.FileTag = FileTag;
|
|
note.ReportType = ReportType;
|
|
note.ReportDate = _reqInfo.ReportDate;
|
|
note.InfoTag = formatInfoTag(model, true, extensionTimeInfo);
|
|
note.OptTime = note.CreateTime;
|
|
note.RetCode = "";
|
|
note.RetMsg = "";
|
|
note.ReportResponse = false;
|
|
note.BizId = "";
|
|
note.DataId = "";
|
|
note.changeStatus = false;
|
|
noteList.Add(note);
|
|
}
|
|
}
|
|
return result;
|
|
}
|
|
|
|
private List<CurrentPositionDetailModel> GetCurrentPositionDetailsModel(string confirmationNo)
|
|
{
|
|
List<CurrentPositionDetailModel> result = new List<CurrentPositionDetailModel>();
|
|
if (_excelDataSource != null && _excelDataSource.Tables.Contains("合约持仓明细"))
|
|
{
|
|
DataTable dt = _excelDataSource.Tables["合约持仓明细"];
|
|
for (int i = 1; i < dt.Rows.Count; i++)
|
|
{
|
|
if (string.IsNullOrWhiteSpace(dt.Rows[i][0]?.ToString()))
|
|
{
|
|
//第一列空白说明数据结束了;
|
|
break;
|
|
}
|
|
if (dt.Rows[i][0]?.ToString() != confirmationNo)
|
|
{
|
|
continue;
|
|
}
|
|
|
|
CurrentPositionDetailModel model = new CurrentPositionDetailModel();
|
|
|
|
model.UndrlygAssetCode = GetDataSetValue(dt, i, 1);
|
|
model.UndrlygAssetDtldType = ConsReport.SwapUndrlygAssetDtldTypeMap[GetDataSetValue(dt, i, 2)];
|
|
model.UndrlygAssetName = GetDataSetValue(dt, i, 3);
|
|
model.UndrlygAssetTradgPlc = GetDataSetValue(dt, i, 4);
|
|
model.UndrlygAssetPrice = GetDataSetValue(dt, i, 5);
|
|
model.InvestorPosition = ConsReport.SwapTypeMap[GetDataSetValue(dt, i, 6)];
|
|
model.UndrlygAssetAmt = GetDataSetValue(dt, i, 7);
|
|
model.ContractMultiplier = GetDataSetValue(dt, i, 8);
|
|
model.NotinalPrincipleAmt = GetDataSetValue(dt, i, 9);
|
|
model.Blank1 = GetDataSetValue(dt, i, 10);
|
|
model.Blank2 = GetDataSetValue(dt, i, 11);
|
|
|
|
result.Add(model);
|
|
}
|
|
}
|
|
return result;
|
|
}
|
|
|
|
private List<CurrentPositionDetailModel> GetCurrentPositionDetailsModelFromView(string confirmationNo)
|
|
{
|
|
List<CurrentPositionDetailModel> result = new List<CurrentPositionDetailModel>();
|
|
if (_viewDataSource != null && _viewDataSource.Tables.Contains("合约持仓明细"))
|
|
{
|
|
DataTable dt = _viewDataSource.Tables["合约持仓明细"];
|
|
for (int i = 0; i < dt.Rows.Count; i++)
|
|
{
|
|
if (GetDataSetValue(dt, i, "CONFIRMATIONNO") != confirmationNo)
|
|
{
|
|
continue;
|
|
}
|
|
|
|
CurrentPositionDetailModel model = new CurrentPositionDetailModel();
|
|
model.UndrlygAssetCode = GetDataSetValue(dt, i, "UNDRLYGASSETCODE");
|
|
model.UndrlygAssetDtldType = GetDataSetValue(dt, i, "UNDRLYGASSETDTLDTYPE");
|
|
model.UndrlygAssetName = GetDataSetValue(dt, i, "UNDRLYGASSETNAME");
|
|
model.UndrlygAssetTradgPlc = GetDataSetValue(dt, i, "UNDRLYGASSETTRADEPLACE");
|
|
model.UndrlygAssetPrice = GetDataSetValue(dt, i, "UNDRLYGASSETPRICE");
|
|
model.InvestorPosition = GetDataSetValue(dt, i, "INVESTORPOSITION");
|
|
model.UndrlygAssetAmt = GetDataSetValue(dt, i, "UNDRLYGASSETAMT");
|
|
model.ContractMultiplier = GetDataSetValue(dt, i, "CONTRACTMULTIPLIER");
|
|
model.NotinalPrincipleAmt = GetDataSetValue(dt, i, "NOTINALPRINCIPLEAMT");
|
|
model.Blank1 = GetDataSetValue(dt, i, "BLANK1");
|
|
model.Blank2 = GetDataSetValue(dt, i, "BLANK2");
|
|
|
|
result.Add(model);
|
|
}
|
|
}
|
|
return result;
|
|
}
|
|
|
|
|
|
private string formatInfoTag(SwapDurationManagementModel model, bool suffixType = false, string extensionTimeInfo = "")
|
|
{
|
|
string result = $"{BusiDataType}_{model.ConfirmationNo.Replace("_", "-")}_{(string.IsNullOrWhiteSpace(extensionTimeInfo) ? "了结" : ($"_{extensionTimeInfo}_展期"))}_{model.DurationEventNO}_";
|
|
if (suffixType)
|
|
{
|
|
result = $"{result}{_operationType}";
|
|
}
|
|
return result;
|
|
}
|
|
|
|
protected override List<SacInfo> CheckBodyValue(BodyModel model, out bool checkStatus)
|
|
{
|
|
List<SacInfo> result = new List<SacInfo>();
|
|
if (model?.SwapDurationManagement != null)
|
|
{
|
|
CheckHelper<SwapDurationManagementModel> helper = new CheckHelper<SwapDurationManagementModel>();
|
|
CheckHelper<CurrentPositionDetailModel> positionhelper = new CheckHelper<CurrentPositionDetailModel>();
|
|
for (int i = 0; i < model.SwapDurationManagement.Count; i++)
|
|
{
|
|
List<SacInfo> listRoot = new List<SacInfo>();
|
|
var item = model.SwapDurationManagement[i];
|
|
if (item.IgnoreCheck) continue;
|
|
helper.ExecuteCheck(item, (name, value, msg) =>
|
|
{
|
|
listRoot.Add(new SacInfo(name, value, msg));
|
|
});
|
|
if (item.CurrentPositionDetails != null)
|
|
{
|
|
for (int j = 0; j < item.CurrentPositionDetails.Count; j++)
|
|
{
|
|
List<SacInfo> attList = new List<SacInfo>();
|
|
var attItem = item.CurrentPositionDetails[j];
|
|
positionhelper.ExecuteCheck(attItem, (name, value, msg) =>
|
|
{
|
|
attList.Add(new SacInfo(name, value, msg));
|
|
});
|
|
if (attList.Count > 0)
|
|
{
|
|
var temp = new SacInfo("CurrentPositionDetails", j);
|
|
temp.SubMaps = new List<SacInfo>(attList);
|
|
listRoot.Add(temp);
|
|
}
|
|
|
|
}
|
|
}
|
|
if (listRoot.Count > 0)
|
|
{
|
|
var errMsg = new SacInfo("SwapDurationManagement", i);
|
|
errMsg.SubMaps = new List<SacInfo>(listRoot);
|
|
result.Add(errMsg);
|
|
}
|
|
}
|
|
}
|
|
checkStatus = result.Count > 0;
|
|
return result;
|
|
}
|
|
|
|
public override bool BeforeOfGenerated(out string errMsg)
|
|
{
|
|
errMsg = "";
|
|
foreach (var file in xmlAttachmentList)
|
|
{
|
|
try
|
|
{
|
|
File.Delete(file);
|
|
}
|
|
catch (Exception e)
|
|
{
|
|
LogFactory.GetLogger<ReportMasterAgrmtProductService>().Error(e);
|
|
};
|
|
|
|
}
|
|
for (int i = 0; i < noteList.Count; i++)
|
|
{
|
|
base.SaveReportNotes(noteList[i]);
|
|
}
|
|
return true;
|
|
}
|
|
}
|
|
}
|