找回证券业报送的逻辑,仅支持Excel模板报送

This commit is contained in:
嬴政 时
2025-05-14 20:00:04 +08:00
parent 0c9cd64038
commit fe2ff3bbcf
52 changed files with 10829 additions and 7124 deletions
@@ -1,4 +1,4 @@
using System.Data;
using DocumentFormat.OpenXml.Bibliography;
using YLErp.DBModels.Enums;
using YLErp.Modules.SuperviseReportModule.SAC.Common;
using YLErp.Modules.SuperviseReportModule.SAC.Model;
@@ -19,44 +19,46 @@ namespace YLErp.Modules.SuperviseReportModule.SAC.Service
protected override DataFlagsEnum BusiDataType => DataFlagsEnum.A1015;
private List<OptFlagsEnum> _validOperationType = null;
private List<OptFlagsEnum>? _validOperationType = null;
public override List<OptFlagsEnum> ValidOperationType
{
get
{
if (_validOperationType == null)
{
_validOperationType = new List<OptFlagsEnum>() {
_validOperationType ??= new List<OptFlagsEnum>() {
OptFlagsEnum.A,
};
}
return _validOperationType;
}
}
protected override SuperviseReportTypeEnum ReportType => SuperviseReportTypeEnum.SAC_ContractNumberProcess;
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();
model.ContractNumberProcess = new ContractNumberProcessModel();
model.ContractNumberProcess.MasterAgrmtTuple = new List<ChangeMasterAgrmtModel>();
model.ContractNumberProcess.SupAgrmtTuple = new List<ChangeSupAgrmtModel>();
model.ContractNumberProcess.OptionConfirmationTuple = new List<ChangeOptionConfirmationModel>();
model.ContractNumberProcess.SwapConfirmationTuple = new List<ChangeOptionConfirmationModel>();
HashSet<string> masterAgrmtTupleId = new HashSet<string>();
HashSet<string> masterAgrmtTupleNo = new HashSet<string>();
HashSet<string> supAgrmtTupleId = new HashSet<string>();
HashSet<string> supAgrmtTupleNo = new HashSet<string>();
HashSet<string> confirmationTupleId = new HashSet<string>();
HashSet<string> confirmationTupleNo = new HashSet<string>();
var model = new BodyModel
{
ContractNumberProcess = new ContractNumberProcessModel
{
MasterAgrmtTuple = new List<ChangeMasterAgrmtModel>(),
SupAgrmtTuple = new List<ChangeSupAgrmtModel>(),
OptionConfirmationTuple = new List<ChangeOptionConfirmationModel>(),
SwapConfirmationTuple = new List<ChangeOptionConfirmationModel>()
}
};
var masterAgrmtTupleId = new HashSet<string>();
var masterAgrmtTupleNo = new HashSet<string>();
var supAgrmtTupleId = new HashSet<string>();
var supAgrmtTupleNo = new HashSet<string>();
var confirmationTupleId = new HashSet<string>();
var confirmationTupleNo = new HashSet<string>();
string id = "", no = "";
if (_excelDataSource != null && _excelDataSource.Tables.Contains("双方约定编号数据明细"))
{
DataTable dt = _excelDataSource.Tables["双方约定编号数据明细"];
for (int i = 1; i < dt.Rows.Count; i++)
var dt = _excelDataSource.Tables["双方约定编号数据明细"];
for (var i = 1; i < dt.Rows.Count; i++)
{
if (string.IsNullOrWhiteSpace(dt.Rows[i][0]?.ToString()))
{
@@ -137,27 +139,44 @@ namespace YLErp.Modules.SuperviseReportModule.SAC.Service
{
model.ContractNumberProcess.SwapConfirmationTuple.Add(new ChangeOptionConfirmationModel());
}
ReportService.EditContractNumber(DbContextFactory.GetYLDbContext(), model.ContractNumberProcess, out _);
var note = new SACReportNotes();
note.IsValid = true;
note.InfoCache = $"{{\"Tag\":\"\"}}";
note.ExceId = model.ContractNumberProcess.ExceID;
note.CreateTime = DateTime.Now;
note.FileTag = FileTag;
note.ReportType = ReportType;
note.ReportDate = _reqInfo.ReportDate;
note.InfoTag = BusiDataType.ToString();
note.OptTime = note.CreateTime;
note.RetCode = "";
note.RetMsg = "";
note.ReportResponse = false;
note.BizId = "";
note.changeStatus = false;
noteList.Add(note);
}
return model;
}
protected override List<SacInfo> CheckBodyValue(BodyModel model, out bool checkStatus)
{
List<SacInfo> result = new List<SacInfo>();
var result = new List<SacInfo>();
if (model.ContractNumberProcess != null)
{
List<SacInfo> listRoot = new List<SacInfo>();
CheckHelper<ContractNumberProcessModel> helper = new CheckHelper<ContractNumberProcessModel>();
CheckHelper<ChangeMasterAgrmtModel> masterAgrmtHelper = new CheckHelper<ChangeMasterAgrmtModel>();
CheckHelper<ChangeSupAgrmtModel> supAgrmtHelper = new CheckHelper<ChangeSupAgrmtModel>();
CheckHelper<ChangeOptionConfirmationModel> optionConfirmationHelper = new CheckHelper<ChangeOptionConfirmationModel>();
var listRoot = new List<SacInfo>();
var helper = new CheckHelper<ContractNumberProcessModel>();
var masterAgrmtHelper = new CheckHelper<ChangeMasterAgrmtModel>();
var supAgrmtHelper = new CheckHelper<ChangeSupAgrmtModel>();
var optionConfirmationHelper = new CheckHelper<ChangeOptionConfirmationModel>();
helper.ExecuteCheck(model.ContractNumberProcess, (name, value, msg) =>
{
listRoot.Add(new SacInfo(name, value, msg));
});
if (model.ContractNumberProcess.MasterAgrmtTuple != null)
{
for (int i = 0; i < model.ContractNumberProcess.MasterAgrmtTuple.Count; i++)
for (var i = 0; i < model.ContractNumberProcess.MasterAgrmtTuple.Count; i++)
{
var listItem = new List<SacInfo>();
var item = model.ContractNumberProcess.MasterAgrmtTuple[i];
@@ -167,15 +186,17 @@ namespace YLErp.Modules.SuperviseReportModule.SAC.Service
});
if (listItem.Count > 0)
{
var temp = new SacInfo("MasterAgrmtTuple", i);
temp.SubMaps = new List<SacInfo>(listItem);
var temp = new SacInfo("MasterAgrmtTuple", i)
{
SubMaps = new List<SacInfo>(listItem)
};
listRoot.Add(temp);
}
}
}
if (model.ContractNumberProcess.SupAgrmtTuple != null)
{
for (int i = 0; i < model.ContractNumberProcess.SupAgrmtTuple.Count; i++)
for (var i = 0; i < model.ContractNumberProcess.SupAgrmtTuple.Count; i++)
{
var listItem = new List<SacInfo>();
var item = model.ContractNumberProcess.SupAgrmtTuple[i];
@@ -185,15 +206,17 @@ namespace YLErp.Modules.SuperviseReportModule.SAC.Service
});
if (listItem.Count > 0)
{
var temp = new SacInfo("SupAgrmtTuple", i);
temp.SubMaps = new List<SacInfo>(listItem);
var temp = new SacInfo("SupAgrmtTuple", i)
{
SubMaps = new List<SacInfo>(listItem)
};
listRoot.Add(temp);
}
}
}
if (model.ContractNumberProcess.OptionConfirmationTuple != null)
{
for (int i = 0; i < model.ContractNumberProcess.OptionConfirmationTuple.Count; i++)
for (var i = 0; i < model.ContractNumberProcess.OptionConfirmationTuple.Count; i++)
{
var listItem = new List<SacInfo>();
var item = model.ContractNumberProcess.OptionConfirmationTuple[i];
@@ -203,15 +226,17 @@ namespace YLErp.Modules.SuperviseReportModule.SAC.Service
});
if (listItem.Count > 0)
{
var temp = new SacInfo("OptionConfirmationTuple", i);
temp.SubMaps = new List<SacInfo>(listItem);
var temp = new SacInfo("OptionConfirmationTuple", i)
{
SubMaps = new List<SacInfo>(listItem)
};
listRoot.Add(temp);
}
}
}
if (model.ContractNumberProcess.SwapConfirmationTuple != null)
{
for (int i = 0; i < model.ContractNumberProcess.SwapConfirmationTuple.Count; i++)
for (var i = 0; i < model.ContractNumberProcess.SwapConfirmationTuple.Count; i++)
{
var listItem = new List<SacInfo>();
var item = model.ContractNumberProcess.SwapConfirmationTuple[i];
@@ -221,21 +246,42 @@ namespace YLErp.Modules.SuperviseReportModule.SAC.Service
});
if (listItem.Count > 0)
{
var temp = new SacInfo("SwapConfirmationTuple", i);
temp.SubMaps = new List<SacInfo>(listItem);
var temp = new SacInfo("SwapConfirmationTuple", i)
{
SubMaps = new List<SacInfo>(listItem)
};
listRoot.Add(temp);
}
}
}
if (listRoot.Count > 0)
{
var errMsg = new SacInfo("ContractNumberProcess");
errMsg.SubMaps = new List<SacInfo>(listRoot);
var errMsg = new SacInfo("ContractNumberProcess")
{
SubMaps = new List<SacInfo>(listRoot)
};
result.Add(errMsg);
}
}
checkStatus = result.Count > 0;
return result;
}
protected override string _changeCodeOfInfoTag(string infoTag, string newCode, out string originalCode)
{
//这个报告只有新增,不存在后续报送,所以InfoTag中只有报告类型,不存在编号,也就不存在修改编号的情况;
throw new NotImplementedException();
}
public override bool BeforeOfGenerated(out string errMsg)
{
errMsg = "";
for (int i = 0; i < noteList.Count; i++)
{
base.SaveReportNotes(noteList[i]);
}
return true;
}
}
}
File diff suppressed because it is too large Load Diff
@@ -15,25 +15,23 @@ namespace YLErp.Modules.SuperviseReportModule.SAC.Service
protected override DataFlagsEnum BusiDataType => DataFlagsEnum.A1009;
private List<OptFlagsEnum> _validOperationType = null;
private List<OptFlagsEnum>? _validOperationType = null;
public override List<OptFlagsEnum> ValidOperationType
{
get
{
if (_validOperationType == null)
{
_validOperationType = new List<OptFlagsEnum>() {
_validOperationType ??= new List<OptFlagsEnum>() {
OptFlagsEnum.A,
OptFlagsEnum.U,
OptFlagsEnum.D,
};
}
return _validOperationType;
}
}
protected override SuperviseReportTypeEnum ReportType => SuperviseReportTypeEnum.SAC_EventReport;
List<SACReportNotes> noteList = new List<SACReportNotes>();
readonly List<SACReportNotes> noteList = new();
public override bool CheckRequestParamer(ReportInfo req, out string errMsg)
{
@@ -63,7 +61,7 @@ namespace YLErp.Modules.SuperviseReportModule.SAC.Service
errMsg = "重大事件报告非新增报送时,对应的业务编码不应为空";
return false;
}
SACReportNotes note = base.GetReportNotes(ReportType, formatInfoTag(req.EventReportDate?.ToString("yyyy-MM-dd"))).Where(O => O.ReportDate == req.EventReportDate).FirstOrDefault();
var note = base.GetReportNotes(ReportType, formatInfoTag(req.EventReportDate?.ToString("yyyy-MM-dd"))).Where(O => O.ReportDate == req.EventReportDate).FirstOrDefault();
if (note == null)
{
errMsg = $"{req.EventReportDate?.ToString("yyyy-MM-dd")}不存在报送成功的重大事项报告记录,请重新选择";
@@ -72,7 +70,7 @@ namespace YLErp.Modules.SuperviseReportModule.SAC.Service
if (req.EventReportStatus == OptFlagsEnum.U)
{
var fileIds = tempFilesService.QueryTempFile(req.ReportDate, "重大事项报告").Select(O => O.id.ToString()).ToArray();
string[] fileIdArr = note.DataId.Split(new[] { ',' }, StringSplitOptions.RemoveEmptyEntries);
var fileIdArr = note.DataId.Split(new[] { ',' }, StringSplitOptions.RemoveEmptyEntries);
if (!fileIds.Except(fileIdArr).Any())
{
errMsg = $"{req.ReportDate.ToString("yyyy-MM-dd")}已上传重大事项报告附件都已报送成功,不需要再次报送";
@@ -103,9 +101,11 @@ namespace YLErp.Modules.SuperviseReportModule.SAC.Service
fileList = new List<string>();
noData = false;
var noteKey = formatInfoTag(_reqInfo.ReportDate.ToString("yyyy-MM-dd"));
BodyModel model = new BodyModel();
model.EventReport = new EventReportModel();
SACReportNotes note = base.GetReportNotes(ReportType, noteKey).FirstOrDefault();
var model = new BodyModel
{
EventReport = new EventReportModel()
};
var note = base.GetReportNotes(ReportType, noteKey).FirstOrDefault();
if (note == null && _operationType == OptFlagsEnum.A)
{
note = new SACReportNotes()
@@ -161,8 +161,10 @@ namespace YLErp.Modules.SuperviseReportModule.SAC.Service
{
ReportStatus.AddCacheInfo(noteKey, item.fileName);
}
var info = new EventReportDetailModel();
info.EventReport = item.fileName;
var info = new EventReportDetailModel
{
EventReport = item.fileName
};
if (model.EventReport.EventReportTuple == null)
{
model.EventReport.EventReportTuple = new List<EventReportDetailModel>();
@@ -173,7 +175,7 @@ namespace YLErp.Modules.SuperviseReportModule.SAC.Service
}
model.EventReport.DetailedDescription = _reqInfo.EventReportDesc;
}
noData = (!(model.EventReport.EventReportTuple?.Count > 0));
noData = !(model.EventReport.EventReportTuple?.Count > 0);
if (!noData)
{
note.id = 0;
@@ -197,19 +199,19 @@ namespace YLErp.Modules.SuperviseReportModule.SAC.Service
protected override List<SacInfo> CheckBodyValue(BodyModel model, out bool checkStatus)
{
List<SacInfo> result = new List<SacInfo>();
var result = new List<SacInfo>();
if (model.EventReport != null)
{
List<SacInfo> listRoot = new List<SacInfo>();
CheckHelper<EventReportModel> helper = new CheckHelper<EventReportModel>();
CheckHelper<EventReportDetailModel> attHelper = new CheckHelper<EventReportDetailModel>();
var listRoot = new List<SacInfo>();
var helper = new CheckHelper<EventReportModel>();
var attHelper = new CheckHelper<EventReportDetailModel>();
helper.ExecuteCheck(model.EventReport, (name, value, msg) =>
{
listRoot.Add(new SacInfo(name, value, msg));
});
if (model.EventReport.EventReportTuple != null)
{
for (int i = 0; i < model.EventReport.EventReportTuple.Count; i++)
for (var i = 0; i < model.EventReport.EventReportTuple.Count; i++)
{
var listItem = new List<SacInfo>();
var item = model.EventReport.EventReportTuple[i];
@@ -219,16 +221,20 @@ namespace YLErp.Modules.SuperviseReportModule.SAC.Service
});
if (listItem.Count > 0)
{
var temp = new SacInfo("EventReportTuple", i);
temp.SubMaps = new List<SacInfo>(listItem);
var temp = new SacInfo("EventReportTuple", i)
{
SubMaps = new List<SacInfo>(listItem)
};
listRoot.Add(temp);
}
}
}
if (listRoot.Count > 0)
{
var errMsg = new SacInfo("EventReport");
errMsg.SubMaps = new List<SacInfo>(listRoot);
var errMsg = new SacInfo("EventReport")
{
SubMaps = new List<SacInfo>(listRoot)
};
result.Add(errMsg);
}
}
@@ -238,7 +244,7 @@ namespace YLErp.Modules.SuperviseReportModule.SAC.Service
private string formatInfoTag(string tag, bool suffixType = false)
{
string result = $"{BusiDataType}_{tag}_";
var result = $"{BusiDataType}_{tag}_";
if (suffixType)
{
result = $"{result}{_operationType}";
@@ -246,10 +252,16 @@ namespace YLErp.Modules.SuperviseReportModule.SAC.Service
return result;
}
protected override string _changeCodeOfInfoTag(string infoTag, string newCode, out string originalCode)
{
//定期报告中不存在编号,也就不存在修改编号的情况;
throw new NotImplementedException();
}
public override bool BeforeOfGenerated(out string errMsg)
{
errMsg = "";
for (int i = 0; i < noteList.Count; i++)
for (var i = 0; i < noteList.Count; i++)
{
base.SaveReportNotes(noteList[i]);
}
@@ -23,168 +23,38 @@ namespace YLErp.Modules.SuperviseReportModule.SAC.Service
protected override DataFlagsEnum BusiDataType => DataFlagsEnum.A1002;
private List<OptFlagsEnum> _validOperationType = null;
private List<OptFlagsEnum>? _validOperationType = null;
public override List<OptFlagsEnum> ValidOperationType
{
get
{
if (_validOperationType == null)
{
_validOperationType = new List<OptFlagsEnum>() {
_validOperationType ??= new List<OptFlagsEnum>() {
OptFlagsEnum.A,
OptFlagsEnum.U,
OptFlagsEnum.D,
};
}
return _validOperationType;
}
}
protected override SuperviseReportTypeEnum ReportType => SuperviseReportTypeEnum.SAC_MasterAgrmtProduct;
List<SACReportNotes> noteList = new List<SACReportNotes>();
readonly List<SACReportNotes> noteList = new();
protected override BodyModel GenerateBody(out bool noData, out List<string> fileList)
{
fileList = new List<string>();
BodyModel model = new BodyModel();
List<MasterAgrmtProductModel> dataList = new List<MasterAgrmtProductModel>();
if ((PS.Config.ErpElement.SAC_ReportDataSource & SAC_ReportDataSourceEnum.Template) == SAC_ReportDataSourceEnum.Template)
var model = new BodyModel();
var dataList = new List<MasterAgrmtProductModel>();
if (_reqInfo.DataSource.HasFlag(SAC_ReportDataSourceEnum.Template))
{
dataList = GetMasterAgrmtProductModel(ref fileList);
}
if ((PS.Config.ErpElement.SAC_ReportDataSource & SAC_ReportDataSourceEnum.System) == SAC_ReportDataSourceEnum.System)
{
using (var baseDb = DbContextFactory.GetClientDbContext(null))
{
var nextDate = _reqInfo.ReportDate.AddDays(1);
var fileObjList = (from c in baseDb.client
join cf in baseDb.client_file
on c.id equals cf.ClientId
where c.ProcessStatus == "已开户" && cf.HasSent == false && cf.IsValid &&
cf.FileTypeName == ConsGlobal.ClientFileType.AllographProduct && cf.OptState == _operationType &&
((c.ProcessOptDate >= _reqInfo.ReportDate && c.ProcessOptDate < nextDate && cf.OptDate < nextDate) ||//如果这一天开户,则把这一天之前(含这一天)的所有文件都报送了
(cf.OptDate >= _reqInfo.ReportDate && cf.OptDate < nextDate && c.ProcessOptDate < _reqInfo.ReportDate))//如果这一天不是开户日期,则只在报送日期大于开户日期时,报送当日修改的文件
&& cf.ApprovalOrder < 1
select new
{
cf.id,
cf.ClientId,
cf.OptState,
cf.ProtocolNumber,
cf.MainProtocolNumber,
cf.SignDate,
cf.FilePath,
cf.FileName,
c.Name,
c.ClientType,
c.Number,
c.ParentId,
}).ToArray();
var clientIds = fileObjList.Select(O => O.ClientId);
var ct = baseDb.contactype.Where(O => O.ContactType == "产品投资经理").FirstOrDefault();
ExpandoDictionary<int, ClientDuty> clientdutyDict = null;
if (ct != null)
{
clientdutyDict = new ExpandoDictionary<int, ClientDuty>(
(from cd in baseDb.clientduty.Where(t => t.ApprovalOrder < 1)
where clientIds.Contains(cd.ClientId ?? 0) && (cd.DeadLine == null || cd.DeadLine >= _reqInfo.ReportDate)
select cd)
.ToList()
.Where(O => O.ContactTypeIdsInt.Contains(ct.id)).GroupBy(O => O.ClientId ?? 0)
.ToDictionary(K => K.Key, V => V.FirstOrDefault()));
}
var cacheKey = $"{BusiDataType}";
var service = new ClientQueryService(UserInfo);
foreach (var item in fileObjList)
{
if (item.ClientType != "产品") { continue; }
var info = new MasterAgrmtProductModel();
info.ClientType = item.ClientType;
info.MasterAgrmtNo = item.MainProtocolNumber;
info.OperationType = item.OptState;
info.ProductName = service.GetProductName(item.ClientId);
if (string.IsNullOrWhiteSpace(info.ProductName))
{
info.ProductName = item.Name;
}
info.CounterpartyCodeProducts = item.Number;
info.ManagerName = clientdutyDict == null ? null : clientdutyDict[item.ClientId]?.ContactName;
info.InvestmentManagerContactNumber = clientdutyDict == null ? null : clientdutyDict[item.ClientId]?.PhoneNumber;
info.TrusteeAgency = service.GetTrusteeAgency(item.ClientId);// ?? DataCacheProvider.GetClientDataSource().GetData(item.ParentId)?.Name;
info.TheDateTable = item.SignDate?.ToString("yyyy-MM-dd");
info.SuchProducts = item.FileName;
var cacheValue = info.MasterAgrmtNo + "_" + info.ProductName;
if (ReportStatus.CheckCacheInfo(cacheKey, cacheValue))
{
continue;
}
SACReportNotes note = base.GetReportNotes(ReportType, formatInfoTag(info)).FirstOrDefault();
if (note == null && _operationType == OptFlagsEnum.A)
{
note = new SACReportNotes()
{
InfoCache = $"{{\"Tag\":\"{info.ProductName}\",\"Source\":\"System\"}}",
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("未知操作类型");
}
}
if (info.OperationType != OptFlagsEnum.A)
{
info.ProductNo = note.BizId;
}
note.id = 0;
info.ExceID = base.formatExceID();
note.DataId = item.id.ToString();
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.changeStatus = false;
if (!ReportStatus.CheckFileLength(item.FilePath))
{
break;
}
else
{
ReportStatus.AddCacheInfo(cacheKey, cacheValue);
}
dataList.Add(info);
fileList.Add(item.FilePath);
note.ExceId = info.ExceID;
noteList.Add(note);
}
}
dataList.AddRange(GetMasterAgrmtProductModelFromExcel(ref fileList));
}
var subsystemDataList = loadSubsystemDataSource<MasterAgrmtProductModel>(fileList, AddSubsystemNote);
if (subsystemDataList != null && subsystemDataList.Count > 0)
{
dataList.AddRange(subsystemDataList);
}
noData = dataList.Count == 0;
model.MasterAgrmtProduct = dataList;
@@ -193,7 +63,7 @@ namespace YLErp.Modules.SuperviseReportModule.SAC.Service
public bool AddSubsystemNote(MasterAgrmtProductModel model, List<string> fileList, string tag)
{
SACReportNotes note = base.GetReportNotes(ReportType, formatInfoTag(model, true)).FirstOrDefault();//参数true要加,要不A和D会查到同一条记录,在D时候,就会和A相同的数据
var note = base.GetReportNotes(ReportType, formatInfoTag(model, true)).FirstOrDefault();//参数true要加,要不A和D会查到同一条记录,在D时候,就会和A相同的数据
if (note == null)
{
note = new SACReportNotes()
@@ -244,16 +114,14 @@ namespace YLErp.Modules.SuperviseReportModule.SAC.Service
return true;
}
private List<MasterAgrmtProductModel> GetMasterAgrmtProductModel(ref List<string> fileList)
private List<MasterAgrmtProductModel> GetMasterAgrmtProductModelFromExcel(ref List<string> fileList)
{
List<MasterAgrmtProductModel> result = new List<MasterAgrmtProductModel>();
var result = new List<MasterAgrmtProductModel>();
if (_excelDataSource != null && _excelDataSource.Tables.Contains("主协议关联产品列表"))
{
var cacheKey = $"{BusiDataType}";
string sourcePath = Path.Combine(_excelDataSourceRootPath, "附件");
DataTable dt = _excelDataSource.Tables["主协议关联产品列表"];
for (int i = 1; i < dt.Rows.Count; i++)
var sourcePath = Path.Combine(_excelDataSourceRootPath, "附件");
var dt = _excelDataSource.Tables["主协议关联产品列表"];
for (var i = 1; i < dt.Rows.Count; i++)
{
if (string.IsNullOrWhiteSpace(dt.Rows[i][0]?.ToString()))
{
@@ -263,12 +131,18 @@ namespace YLErp.Modules.SuperviseReportModule.SAC.Service
var optType = OptFlagsEnum.NONE;
switch (dt.Rows[i][1]?.ToString())
{
case "0":
case "A":
case "首次":
optType = OptFlagsEnum.A;
break;
case "1":
case "U":
case "变更":
optType = OptFlagsEnum.U;
break;
case "2":
case "D":
case "废止":
optType = OptFlagsEnum.D;
break;
@@ -278,25 +152,26 @@ namespace YLErp.Modules.SuperviseReportModule.SAC.Service
continue;
}
MasterAgrmtProductModel model = new MasterAgrmtProductModel();
model.ClientType = "产品";
model.MasterAgrmtNo = GetDataSetValue(dt, i, 0);
model.OperationType = optType == OptFlagsEnum.A ? OptFlagsEnum.A : OptFlagsEnum.U;
model.ProductName = GetDataSetValue(dt, i, 2);
model.CounterpartyCodeProducts = GetDataSetValue(dt, i, 3);
model.ManagerName = GetDataSetValue(dt, i, 4);
model.InvestmentManagerContactNumber = GetDataSetValue(dt, i, 5);
model.TrusteeAgency = GetDataSetValue(dt, i, 6);
model.TheDateTable = GetDataSetValue(dt, i, 7);
model.SuchProducts = GetDataSetValue(dt, i, 8);
var model = new MasterAgrmtProductModel
{
ClientType = "产品",
MasterAgrmtNo = GetDataSetValue(dt, i, 0),
OperationType = optType == OptFlagsEnum.A ? OptFlagsEnum.A : OptFlagsEnum.U,
ProductName = GetDataSetValue(dt, i, 2),
CounterpartyCodeProducts = GetDataSetValue(dt, i, 3),
ManagerName = GetDataSetValue(dt, i, 4),
InvestmentManagerContactNumber = GetDataSetValue(dt, i, 5),
TrusteeAgency = GetDataSetValue(dt, i, 6),
TheDateTable = GetDataSetValue(dt, i, 7),
SuchProducts = GetDataSetValue(dt, i, 8)
};
var cacheValue = model.MasterAgrmtNo + "_" + model.ProductName;
if (ReportStatus.CheckCacheInfo(cacheKey, cacheValue))
if (ReportStatus.CheckCacheInfo(CacheKey, cacheValue))
{
continue;
}
SACReportNotes note = base.GetReportNotes(ReportType, formatInfoTag(model)).FirstOrDefault();
var note = base.GetReportNotes(ReportType, formatInfoTag(model)).FirstOrDefault();
if (note == null && _operationType == OptFlagsEnum.A)
{
note = new SACReportNotes()
@@ -332,14 +207,14 @@ namespace YLErp.Modules.SuperviseReportModule.SAC.Service
}
if (!string.IsNullOrWhiteSpace(model.SuchProducts))
{
string path = Path.Combine(sourcePath, model.SuchProducts);
var path = Path.Combine(sourcePath, model.SuchProducts);
if (!ReportStatus.CheckFileLength(path))
{
break;
}
else
{
ReportStatus.AddCacheInfo(cacheKey, cacheValue);
ReportStatus.AddCacheInfo(CacheKey, cacheValue);
}
note.id = 0;
model.ExceID = base.formatExceID();
@@ -366,23 +241,30 @@ namespace YLErp.Modules.SuperviseReportModule.SAC.Service
protected override List<SacInfo> CheckBodyValue(BodyModel model, out bool checkStatus)
{
List<SacInfo> result = new List<SacInfo>();
var result = new List<SacInfo>();
if (model?.MasterAgrmtProduct != null)
{
List<SacInfo> listRoot = new List<SacInfo>();
CheckHelper<MasterAgrmtProductModel> helper = new Common.CheckHelper<MasterAgrmtProductModel>();
for (int i = 0; i < model.MasterAgrmtProduct.Count; i++)
var helper = new Common.CheckHelper<MasterAgrmtProductModel>();
for (var i = 0; i < model.MasterAgrmtProduct.Count; i++)
{
var listRoot = new List<SacInfo>();
var item = model.MasterAgrmtProduct[i];
if (item.IgnoreCheck) continue;
if (item.IgnoreCheck)
{
continue;
}
helper.ExecuteCheck(item, (name, value, msg) =>
{
listRoot.Add(new SacInfo(name, value, msg));
});
if (listRoot.Count > 0)
{
var errMsg = new SacInfo("MasterAgrmtProduct", i);
errMsg.SubMaps = new List<SacInfo>(listRoot);
var errMsg = new SacInfo("MasterAgrmtProduct", i)
{
FieldValue = item.ProductName,
SubMaps = new List<SacInfo>(listRoot)
};
result.Add(errMsg);
}
}
@@ -408,7 +290,7 @@ namespace YLErp.Modules.SuperviseReportModule.SAC.Service
};
}
for (int i = 0; i < noteList.Count; i++)
for (var i = 0; i < noteList.Count; i++)
{
base.SaveReportNotes(noteList[i]);
}
@@ -423,12 +305,24 @@ namespace YLErp.Modules.SuperviseReportModule.SAC.Service
}
private string formatInfoTag(MasterAgrmtProductModel model, bool suffixType = false)
{
string result = $"{BusiDataType}_{model.MasterAgrmtNo.Replace("_", "-")}_{model.ProductName.Replace("_", "-")}_";
var result = $"{BusiDataType}_{model.MasterAgrmtNo.Replace("_", "-")}_{model.ProductName.Replace("_", "-")}_";
if (suffixType)
{
result = $"{result}{_operationType}";
}
return result;
}
protected override string _changeCodeOfInfoTag(string infoTag, string newCode, out string originalCode)
{
var arr = infoTag.Split('_');
if (arr.Length != 4)
{
throw new ServiceException($"InfoTag信息不匹配:{infoTag}");
}
originalCode = arr[2];
arr[2] = newCode.Replace("_", "-");
return string.Join("_", arr);
}
}
}
@@ -1,7 +1,9 @@
using System.Data;
using BaseOUDAL;
using System.Data;
using YLErp.Commons;
using YLErp.DBModels.Consts;
using YLErp.DBModels.Enums;
using YLErp.Helpers;
using YLErp.Modules.SuperviseReportModule.SAC.Common;
using YLErp.Modules.SuperviseReportModule.SAC.Model;
using static YLErp.DBModels.Consts.ConsReport;
@@ -23,60 +25,39 @@ namespace YLErp.Modules.SuperviseReportModule.SAC.Service
protected override DataFlagsEnum BusiDataType => DataFlagsEnum.A1001;
private List<OptFlagsEnum> _validOperationType = null;
private List<OptFlagsEnum>? _validOperationType = null;
public override List<OptFlagsEnum> ValidOperationType
{
get
{
if (_validOperationType == null)
{
_validOperationType = new List<OptFlagsEnum>() {
_validOperationType ??= new List<OptFlagsEnum>() {
OptFlagsEnum.A,
OptFlagsEnum.U,
OptFlagsEnum.D,
};
}
return _validOperationType;
}
}
protected override SuperviseReportTypeEnum ReportType => SuperviseReportTypeEnum.SAC_MasterAgrmt;
List<SACReportNotes> noteList = new List<SACReportNotes>();
readonly List<SACReportNotes> noteList = new();
protected override BodyModel GenerateBody(out bool noData, out List<string> fileList)
{
fileList = new List<string>();
BodyModel model = new BodyModel();
List<MasterAgrmtModel> dataList = new List<MasterAgrmtModel>();
if ((PS.Config.ErpElement.SAC_ReportDataSource & SAC_ReportDataSourceEnum.Template) == SAC_ReportDataSourceEnum.Template)
var model = new BodyModel();
var dataList = new List<MasterAgrmtModel>();
if (_reqInfo.DataSource.HasFlag(SAC_ReportDataSourceEnum.Template))
{
dataList = GetMasterAgrmtModelFromExcel(ref fileList);
}
if ((PS.Config.ErpElement.SAC_ReportDataSource & SAC_ReportDataSourceEnum.System) == SAC_ReportDataSourceEnum.System)
{
try
{
LogFactory.GetLogger("GenerateBody").Info($"System:1111x");
var resultList = GetMasterAgrmtModelFromDb(ref fileList);
if (resultList != null && resultList.Count() > 0)
{
LogFactory.GetLogger("GenerateBody").Info($"ok");
dataList.AddRange(resultList);
}
LogFactory.GetLogger("GenerateBody").Info($"System:2222x");
}
catch (Exception ex)
{
LogFactory.GetLogger("GenerateBody").Info($"System:1111x系统异常:" + ex.ToString());
}
}
LogFactory.GetLogger("GenerateBody").Info($"System:11112");
var subsystemDataList = loadSubsystemDataSource<MasterAgrmtModel>(fileList, AddSubsystemNote);
if (subsystemDataList != null && subsystemDataList.Count > 0)
{
dataList.AddRange(subsystemDataList);
}
noData = dataList.Count == 0;
model.MasterAgrmt = dataList;
return model;
@@ -84,7 +65,7 @@ namespace YLErp.Modules.SuperviseReportModule.SAC.Service
public bool AddSubsystemNote(MasterAgrmtModel model, List<string> fileList, string tag)
{
SACReportNotes note = base.GetReportNotes(ReportType, formatInfoTag(model, true)).FirstOrDefault();//参数true要加,要不A和D会查到同一条记录,在D时候,就会和A相同的数据
var note = base.GetReportNotes(ReportType, formatInfoTag(model, true)).FirstOrDefault();//参数true要加,要不A和D会查到同一条记录,在D时候,就会和A相同的数据
if (note == null)
{
note = new SACReportNotes()
@@ -136,186 +117,14 @@ namespace YLErp.Modules.SuperviseReportModule.SAC.Service
return true;
}
private IEnumerable<MasterAgrmtModel> GetMasterAgrmtModelFromDb(ref List<string> fileList)
{
var dataList = new List<MasterAgrmtModel>();
using (var baseDb = DbContextFactory.GetClientDbContext(null))
{
var nextDate = _reqInfo.ReportDate.AddDays(1);
var fileObjList = (from c in baseDb.client
join cf in baseDb.client_file
on c.id equals cf.ClientId
where c.ProcessStatus == "已开户" && cf.HasSent == false && cf.IsValid &&
cf.FileTypeName == ConsGlobal.ClientFileType.MainProtocol && cf.OptState == _operationType &&
((c.ProcessOptDate >= _reqInfo.ReportDate && c.ProcessOptDate < nextDate && cf.OptDate < nextDate) ||//如果这一天开户,则把这一天之前(含这一天)的所有文件都报送了
(cf.OptDate >= _reqInfo.ReportDate && cf.OptDate < nextDate && c.ProcessOptDate < _reqInfo.ReportDate))//如果这一天不是开户日期,则只在报送日期大于开户日期时,报送当日修改的文件
&& cf.ApprovalOrder < 1
select new
{
cf.id,
cf.ClientId,
cf.OptState,
cf.ProtocolNumber,
cf.SignDate,
cf.SignType,
cf.ReportorRole,
cf.FilePath,
cf.FileName,
cf.FileDesc,
c.Name,
c.CounterpartyCode,
c.Number,
c.ProperClientClass,
c.CustomerNature1,
c.NFICode,
c.RegisteredCapital,
c.ClientType
}).ToArray();
var clientIds = fileObjList.Select(O => O.ClientId);
var ct = baseDb.contactype.Where(O => O.ContactType == "联系人").FirstOrDefault();
ExpandoDictionary<int, ClientDuty> clientdutyDict = null;
if (ct != null)
{
clientdutyDict = new ExpandoDictionary<int, ClientDuty>(
(from cd in baseDb.clientduty.Where(t => t.ApprovalOrder < 1)
where clientIds.Contains(cd.ClientId ?? 0) && (cd.DeadLine == null || cd.DeadLine >= _reqInfo.ReportDate)
select cd)
.ToList()
.Where(O => O.ContactTypeIdsInt.Contains(ct.id)).GroupBy(O => O.ClientId ?? 0)
.ToDictionary(K => K.Key, V => V.FirstOrDefault()));
}
LogFactory.GetLogger("ReportMasterAgrmtService").Error("查询到: " + fileObjList.Length.ToString());
var cacheKey = $"{BusiDataType}";
foreach (var item in fileObjList)
{
var cacheValue = item.ProtocolNumber;
if (ReportStatus.CheckCacheInfo(cacheKey, cacheValue))
{
LogFactory.GetLogger("ReportMasterAgrmtService").Error("有重复编号跳过 " + item.ProtocolNumber);
continue;
}
try
{
var info = new MasterAgrmtModel();
info.OperationType = item.OptState;
info.MasterAgrmtNo = item.ProtocolNumber;
info.SigningDate = item.SignDate?.ToString("yyyy-MM-dd");
info.MasterAgrmtVer = ConsReport.MasterAgrmtVerMap[item.SignType ?? ""];
info.FillParty = ConsReport.FillPartyMap[item.ReportorRole ?? ""];
info.NameOfCounterparty = item.Name;
info.CounterpartyCode = item.Number;
info.ProCounterparty = item.ProperClientClass != null && item.ProperClientClass.Contains("专业") ? ProCounterpartyMap["专业"] : ProCounterpartyMap["非专业"];
info.CounterpartyType = CounterpartyTypeMap[item.CustomerNature1 ?? ""];
if ((info.CounterpartyType == CounterpartyTypeMap["境外金融机构"] || info.CounterpartyType == CounterpartyTypeMap["境外非金融机构"]))
{
info.LEI = item.CounterpartyCode;
}
else
{
info.CODS = item.CounterpartyCode;
}
if (item.CustomerNature1 != null && item.CustomerNature1.Contains("非金融机构"))
{
info.NFICode = item.NFICode;
}
info.CounterpartyRegdCptl = item.RegisteredCapital;
info.MasterAgrmtAtt = item.FileName;
info.MasterAgrmtRemark = item.FileDesc;
if (clientdutyDict != null && clientdutyDict.ContainsKey(item.ClientId))
{
info.CounterpartyInformationTuple = new List<CounterpartyInfomationModel>();
CounterpartyInfomationModel userInfo = new CounterpartyInfomationModel();
userInfo.Name = clientdutyDict[item.ClientId]?.ContactName;
userInfo.Title = clientdutyDict[item.ClientId] == null ? null : "联系人";
userInfo.Email = clientdutyDict[item.ClientId]?.Email;
userInfo.Telephone = clientdutyDict[item.ClientId]?.PhoneNumber;
//userInfo.Mobile = clientdutyDict[item.ClientId]?.PhoneNumber;
info.CounterpartyInformationTuple.Add(userInfo);
}
info.CounterpartyIdentity = item.ClientType == "机构" ? CounterpartyIdentityMap["自营"] : CounterpartyIdentityMap["产品管理人"];
SACReportNotes note = base.GetReportNotes(ReportType, formatInfoTag(info)).FirstOrDefault();
if (note == null && _operationType == OptFlagsEnum.A)
{
note = new SACReportNotes()
{
InfoCache = $"{{\"Tag\":\"{info.MasterAgrmtNo}\",\"Source\":\"System\"}}",
IsValid = true,
};
}
else
{
if (note == null)
{
LogFactory.GetLogger("ReportMasterAgrmtService").Error("未找到历史报送信息跳过 " + formatInfoTag(info));
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("未知操作类型");
}
}
if (info.OperationType != OptFlagsEnum.A)
{
info.MasterAgrmtID = note.BizId;
}
if (!ReportStatus.CheckFileLength(item.FilePath))
{
break;
}
else
{
ReportStatus.AddCacheInfo(cacheKey, cacheValue);
}
info.ExceID = base.formatExceID();
dataList.Add(info);
fileList.Add(item.FilePath);
note.id = 0;
note.DataId = item.id.ToString();
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.RetCode = "";
note.RetMsg = "";
note.ReportResponse = false;
note.BizId = "";
note.changeStatus = false;
noteList.Add(note);
}
catch (Exception ex)
{
LogFactory.GetLogger("ReportMasterAgrmtService").Error(ex);
LogFactory.GetLogger("ReportMasterAgrmtService").Error(item.ToJson());
throw;
}
}
}
return dataList;
}
private List<MasterAgrmtModel> GetMasterAgrmtModelFromExcel(ref List<string> fileList)
{
List<MasterAgrmtModel> result = new List<MasterAgrmtModel>();
var result = new List<MasterAgrmtModel>();
if (_excelDataSource != null && _excelDataSource.Tables.Contains("主协议"))
{
var cacheKey = $"{BusiDataType}";
string sourcePath = Path.Combine(_excelDataSourceRootPath, "附件");
DataTable dt = _excelDataSource.Tables["主协议"];
for (int i = 1; i < dt.Rows.Count; i++)
var sourcePath = Path.Combine(_excelDataSourceRootPath, "附件");
var dt = _excelDataSource.Tables["主协议"];
for (var i = 1; i < dt.Rows.Count; i++)
{
if (string.IsNullOrWhiteSpace(dt.Rows[i][0]?.ToString()))
{
@@ -325,12 +134,18 @@ namespace YLErp.Modules.SuperviseReportModule.SAC.Service
var optType = OptFlagsEnum.NONE;
switch (dt.Rows[i][3]?.ToString())
{
case "0":
case "A":
case "首次":
optType = OptFlagsEnum.A;
break;
case "1":
case "U":
case "变更":
optType = OptFlagsEnum.U;
break;
case "2":
case "D":
case "废止":
optType = OptFlagsEnum.D;
break;
@@ -340,14 +155,14 @@ namespace YLErp.Modules.SuperviseReportModule.SAC.Service
continue;
}
MasterAgrmtModel model = generiterInfoFromExcel(dt, i, optType);
var model = generiterInfoFromExcel(dt, i, optType);
model.CounterpartyInformationTuple = GetCounterpartyInfomationModelFromExcel(model.MasterAgrmtNo);
string cacheValue = model.MasterAgrmtNo;
if (ReportStatus.CheckCacheInfo(cacheKey, cacheValue))
var cacheValue = model.MasterAgrmtNo;
if (ReportStatus.CheckCacheInfo(CacheKey, cacheValue))
{
continue;
}
SACReportNotes note = base.GetReportNotes(ReportType, formatInfoTag(model)).FirstOrDefault();
var note = base.GetReportNotes(ReportType, formatInfoTag(model)).FirstOrDefault();
if (note == null && _operationType == OptFlagsEnum.A)
{
note = new SACReportNotes()
@@ -385,14 +200,14 @@ namespace YLErp.Modules.SuperviseReportModule.SAC.Service
if (!string.IsNullOrWhiteSpace(model.MasterAgrmtAtt))
{
model.ExceID = base.formatExceID();
string path = Path.Combine(sourcePath, model.MasterAgrmtAtt);
var path = Path.Combine(sourcePath, model.MasterAgrmtAtt);
if (!ReportStatus.CheckFileLength(path))
{
break;
}
else
{
ReportStatus.AddCacheInfo(cacheKey, cacheValue);
ReportStatus.AddCacheInfo(CacheKey, cacheValue);
}
result.Add(model);
fileList.Add(path);
@@ -418,29 +233,31 @@ namespace YLErp.Modules.SuperviseReportModule.SAC.Service
private MasterAgrmtModel generiterInfoFromExcel(DataTable dt, int i, OptFlagsEnum optType)
{
var model = new MasterAgrmtModel();
model.MasterAgrmtNo = GetDataSetValue(dt, i, 0);
model.SigningDate = GetDataSetValue(dt, i, 1);
model.MasterAgrmtVer = ConsReport.MasterAgrmtVerMap[GetDataSetValue(dt, i, 2)];
model.OperationType = optType == OptFlagsEnum.A ? OptFlagsEnum.A : OptFlagsEnum.U;
model.FillParty = ConsReport.FillPartyMap[GetDataSetValue(dt, i, 4)];
model.NameOfCounterparty = GetDataSetValue(dt, i, 5);
model.CODS = GetDataSetValue(dt, i, 6);
model.CounterpartyCode = GetDataSetValue(dt, i, 7);
model.LEI = GetDataSetValue(dt, i, 8);
model.ProCounterparty = ConsReport.ProCounterpartyMap[GetDataSetValue(dt, i, 9)];
model.CounterpartyType = ConsReport.CounterpartyTypeMap[GetDataSetValue(dt, i, 10)];
model.NFICode = GetDataSetValue(dt, i, 11);
model.CounterpartyRegdCptl = GetDataSetValue(dt, i, 12);
model.MasterAgrmtRemark = GetDataSetValue(dt, i, 13);
model.MasterAgrmtAtt = GetDataSetValue(dt, i, 14);
model.CounterpartyIdentity = ConsReport.CounterpartyIdentityMap[GetDataSetValue(dt, i, 15)];
var model = new MasterAgrmtModel
{
MasterAgrmtNo = GetDataSetValue(dt, i, 0),
SigningDate = GetDataSetValue(dt, i, 1),
MasterAgrmtVer = ConsReport.MasterAgrmtVerMap[GetDataSetValue(dt, i, 2)],
OperationType = optType == OptFlagsEnum.A ? OptFlagsEnum.A : OptFlagsEnum.U,
FillParty = ConsReport.FillPartyMap[GetDataSetValue(dt, i, 4)],
NameOfCounterparty = GetDataSetValue(dt, i, 5),
CODS = GetDataSetValue(dt, i, 6),
CounterpartyCode = GetDataSetValue(dt, i, 7),
LEI = GetDataSetValue(dt, i, 8),
ProCounterparty = ConsReport.ProCounterpartyMap[GetDataSetValue(dt, i, 9)],
CounterpartyType = ConsReport.CounterpartyTypeMap[GetDataSetValue(dt, i, 10)],
NFICode = GetDataSetValue(dt, i, 11),
CounterpartyRegdCptl = GetDataSetValue(dt, i, 12),
MasterAgrmtRemark = GetDataSetValue(dt, i, 13),
MasterAgrmtAtt = GetDataSetValue(dt, i, 14),
CounterpartyIdentity = ConsReport.CounterpartyIdentityMap[GetDataSetValue(dt, i, 15)]
};
return model;
}
private string formatInfoTag(MasterAgrmtModel model, bool suffixType = false)
{
string result = $"{BusiDataType}_{model.MasterAgrmtNo.Replace("_", "-")}_";
var result = $"{BusiDataType}_{model.MasterAgrmtNo.Replace("_", "-")}_";
if (suffixType)
{
result = $"{result}{_operationType}";
@@ -448,31 +265,44 @@ namespace YLErp.Modules.SuperviseReportModule.SAC.Service
return result;
}
protected override string _changeCodeOfInfoTag(string infoTag, string newCode, out string originalCode)
{
var arr = infoTag.Split('_');
if (arr.Length != 3)
{
throw new ServiceException($"InfoTag信息不匹配:{infoTag}");
}
originalCode = arr[1];
arr[1] = newCode.Replace("_", "-");
return string.Join("_", arr);
}
private List<CounterpartyInfomationModel> GetCounterpartyInfomationModelFromExcel(string masterAgrmtNo)
{
List<CounterpartyInfomationModel> result = new List<CounterpartyInfomationModel>();
var result = new List<CounterpartyInfomationModel>();
if (_excelDataSource != null && _excelDataSource.Tables.Contains("填报方业务代表明细"))
{
DataTable dt = _excelDataSource.Tables["填报方业务代表明细"];
for (int i = 1; i < dt.Rows.Count; i++)
var dt = _excelDataSource.Tables["填报方业务代表明细"];
for (var i = 1; i < dt.Rows.Count; i++)
{
if (string.IsNullOrWhiteSpace(dt.Rows[i][0]?.ToString()))
{
//第一列空白说明数据结束了;
break;
}
if (dt.Rows[i][0]?.ToString() != masterAgrmtNo)
if (dt.Rows[i][0]?.ToString().Trim() != masterAgrmtNo)
{
continue;
}
CounterpartyInfomationModel model = new CounterpartyInfomationModel();
model.Name = GetDataSetValue(dt, i, 1);
model.Title = GetDataSetValue(dt, i, 2);
model.Telephone = GetDataSetValue(dt, i, 3);
model.Mobile = GetDataSetValue(dt, i, 4);
model.Email = GetDataSetValue(dt, i, 5);
var model = new CounterpartyInfomationModel
{
Name = GetDataSetValue(dt, i, 1),
Title = GetDataSetValue(dt, i, 2),
Telephone = GetDataSetValue(dt, i, 3),
Mobile = GetDataSetValue(dt, i, 4),
Email = GetDataSetValue(dt, i, 5)
};
result.Add(model);
}
@@ -482,23 +312,27 @@ namespace YLErp.Modules.SuperviseReportModule.SAC.Service
protected override List<SacInfo> CheckBodyValue(BodyModel model, out bool checkStatus)
{
List<SacInfo> result = new List<SacInfo>();
var result = new List<SacInfo>();
if (model?.MasterAgrmt != null)
{
CheckHelper<MasterAgrmtModel> helper = new Common.CheckHelper<MasterAgrmtModel>();
CheckHelper<CounterpartyInfomationModel> infoHelper = new Common.CheckHelper<CounterpartyInfomationModel>();
for (int i = 0; i < model.MasterAgrmt.Count; i++)
var helper = new Common.CheckHelper<MasterAgrmtModel>();
var infoHelper = new Common.CheckHelper<CounterpartyInfomationModel>();
for (var i = 0; i < model.MasterAgrmt.Count; i++)
{
List<SacInfo> listRoot = new List<SacInfo>();
var listRoot = new List<SacInfo>();
var item = model.MasterAgrmt[i];
if (item.IgnoreCheck) continue;
if (item.IgnoreCheck)
{
continue;
}
helper.ExecuteCheck(item, (name, value, msg) =>
{
listRoot.Add(new SacInfo(name, value, msg));
});
if (item.CounterpartyInformationTuple != null)
{
for (int j = 0; j < item.CounterpartyInformationTuple.Count; j++)
for (var j = 0; j < item.CounterpartyInformationTuple.Count; j++)
{
var listItem = new List<SacInfo>();
var tuple = item.CounterpartyInformationTuple[j];
@@ -508,16 +342,21 @@ namespace YLErp.Modules.SuperviseReportModule.SAC.Service
});
if (listItem.Count > 0)
{
var temp = new SacInfo("CounterpartyInformationTuple", j);
temp.SubMaps = new List<SacInfo>(listItem);
var temp = new SacInfo("CounterpartyInformationTuple", j)
{
SubMaps = new List<SacInfo>(listItem)
};
listRoot.Add(temp);
}
}
}
if (listRoot.Count > 0)
{
var errMsg = new SacInfo("MasterAgrmt", i);
errMsg.SubMaps = new List<SacInfo>(listRoot);
var errMsg = new SacInfo("MasterAgrmt", i)
{
FieldValue = item.MasterAgrmtNo,
SubMaps = new List<SacInfo>(listRoot)
};
result.Add(errMsg);
}
}
@@ -542,7 +381,7 @@ namespace YLErp.Modules.SuperviseReportModule.SAC.Service
LogFactory.GetLogger<ReportMasterAgrmtProductService>().Error(e);
};
}
for (int i = 0; i < noteList.Count; i++)
for (var i = 0; i < noteList.Count; i++)
{
base.SaveReportNotes(noteList[i]);
}
@@ -0,0 +1,320 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using static YLErp.DBModels.Consts.ConsReport;
using YLErp.BLL;
using YLErp.DBModels.Consts;
using YLErp.DBModels.Enums;
using YLErp.DBModels;
using YLErp.Modules.SuperviseReportModule.SAC.Common;
using YLErp.Modules.SuperviseReportModule.SAC.Model;
using System.Data;
using System.IO;
using NPOI.SS.Formula.Functions;
using YLErp.Helpers;
namespace YLErp.Modules.SuperviseReportModule.SAC.Service
{
class ReportOptionConfirmationAttService : ReportBaseService
{
public ReportOptionConfirmationAttService(OptUserInfo optUser) : base(optUser)
{
}
protected override string _excelDataSourcePath => "交易相关\\";
protected override string _excelDataSourceFileName => "import_OptionConfirmationAtt_template.xlsx";
protected override DataFlagsEnum BusiDataType => DataFlagsEnum.A1019;
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_OptionConfirmationAtt;
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<ConfirmationAttModel> dataList = new List<ConfirmationAttModel>();
if (_reqInfo.DataSource.HasFlag(SAC_ReportDataSourceEnum.Template))
{
dataList = GetOptionConfirmationAttModel(out fileList);
}
var subsystemDataList = loadSubsystemDataSource<ConfirmationAttModel>(fileList, AddSubsystemNote);
if (subsystemDataList != null && subsystemDataList.Count > 0)
dataList.AddRange(subsystemDataList);
noData = dataList.Count == 0;
model.ConfirmationAtt = dataList;
return model;
}
public bool AddSubsystemNote(ConfirmationAttModel model, List<string> fileList, string tag)
{
SACReportNotes note = base.GetReportNotes(ReportType, formatInfoTag(model, true)).FirstOrDefault();//参数true要加,要不A和D会查到同一条记录,在D时候,就会和A相同的数据
if (note == null)
{
note = new SACReportNotes()
{
InfoCache = $"{{\"Tag\":\"{model.ConfirmationNo}\",\"Source\":\"Subsystem\",\"SubFileTag\":\"{tag}\",\"ExceID\":\"{model.ExceID}\"}}",
IsValid = true,
};
}
else
{
switch (model.OperationType)
{
case OptFlagsEnum.A:
return false;//新增数据已报送,跳过
case OptFlagsEnum.U:
//多次U的时候,每次用最新的tag来赋值SubFileTag
note.InfoCache = $"{{\"Tag\":\"{model.ConfirmationNo}\",\"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 (model.ConfirmationFilesTuple != null && model.ConfirmationFilesTuple.Count > 0)
{
fileList.AddRange(model.ConfirmationFilesTuple.Select(x => x.ConfirmationAtt));
}
model.ExceID = base.formatExceID();
note.ExceId = model.ExceID;
note.id = 0;
note.CreateTime = DateTime.Now;
note.FileTag = FileTag;
note.ReportType = ReportType;
note.ReportDate = _reqInfo.ReportDate;
note.InfoTag = formatInfoTag(model, true);
note.OptTime = note.CreateTime;
note.RetCode = "";
note.RetMsg = "";
note.ReportResponse = false;
note.BizId = "";
note.changeStatus = false;
noteList.Add(note);
return true;
}
private List<ConfirmationAttModel> GetOptionConfirmationAttModel(out List<string> fileList)
{
fileList = new List<string>();
List<ConfirmationAttModel> result = new List<ConfirmationAttModel>();
if (_excelDataSource != null && _excelDataSource.Tables.Contains("场外期权确认书附件明细"))
{
DataTable dt = _excelDataSource.Tables["场外期权确认书附件明细"];
string sourcePath = Path.Combine(_excelDataSourceRootPath, "附件");
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 "0":
case "A":
case "首次":
optType = OptFlagsEnum.A;
break;
case "1":
case "U":
case "变更":
optType = OptFlagsEnum.U;
break;
case "2":
case "D":
case "废止":
optType = OptFlagsEnum.D;
break;
}
if (optType != _operationType)
{
continue;
}
ConfirmationAttModel model = new ConfirmationAttModel();
model.ConfirmationNo = GetDataSetValue(dt, i, 0);
model.OperationType = optType;
var cacheValue = (model.ConfirmationNo ?? "").ToString();
if (cacheValue.IsNullOrWhiteSpace())
{
continue;
}
if (ReportStatus.CheckCacheInfo(CacheKey, cacheValue))
{
continue;
}
model.ConfirmationFilesTuple = new List<ConfirmationFilesTupleModel>();
var files = GetDataSetValue(dt, i, 2).Split(',');
foreach (var f in files)
{
if (!string.IsNullOrWhiteSpace(f))
{
var path = Path.Combine(sourcePath, f);
if (!ReportStatus.CheckFileLength(path))
{
break;
}
fileList.Add(path);
model.ConfirmationFilesTuple.Add(new ConfirmationFilesTupleModel() { IsSwap = "false", ConfirmationAtt = f });
}
}
List<SACReportNotes> notes = base.GetReportNotes(ReportType, formatInfoTag(model));
var note = notes.LastOrDefault(O => O.InfoCache.Contains(cacheValue));
if (note == null && _operationType == OptFlagsEnum.A)
{
note = new SACReportNotes()
{
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("未知操作类型");
}
}
if (_operationType != OptFlagsEnum.A)
{
model.BizID = note.BizId;
}
model.ExceID = base.formatExceID();
result.Add(model);
ReportStatus.AddCacheInfo(CacheKey, cacheValue);
note.InfoCache = $"{{\"Tag\":\"{model.ConfirmationNo}\",\"Source\":\"Template\"}}";
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);
note.OptTime = note.CreateTime;
note.RetCode = "";
note.RetMsg = "";
note.ReportResponse = false;
note.BizId = "";
note.DataId = "";
note.changeStatus = false;
noteList.Add(note);
}
}
return result;
}
private string formatInfoTag(ConfirmationAttModel model, bool suffixType = false)
{
string result = $"{BusiDataType}_{model.ConfirmationNo.Replace("_", "-")}_成交_确认书_";
if (suffixType)
{
result = $"{result}{_operationType}";
}
return result;
}
protected override string _changeCodeOfInfoTag(string infoTag, string newCode, out string originalCode)
{
var arr = infoTag.Split('_');
if (arr.Length != 5)
{
throw new ServiceException($"InfoTag信息不匹配:{infoTag}");
}
originalCode = arr[1];
arr[1] = newCode.Replace("_", "-");
return string.Join("_", arr);
}
protected override List<SacInfo> CheckBodyValue(BodyModel model, out bool checkStatus)
{
List<SacInfo> result = new List<SacInfo>();
if (model?.ConfirmationAtt != null)
{
CheckHelper<ConfirmationAttModel> helper = new CheckHelper<ConfirmationAttModel>();
CheckHelper<ConfirmationFilesTupleModel> attHelper = new CheckHelper<ConfirmationFilesTupleModel>();
for (int i = 0; i < model.ConfirmationAtt.Count; i++)
{
List<SacInfo> listRoot = new List<SacInfo>();
var item = model.ConfirmationAtt[i];
helper.ExecuteCheck(item, (name, value, msg) =>
{
listRoot.Add(new SacInfo(name, value, msg));
});
if (item.ConfirmationFilesTuple != null)
{
for (int j = 0; j < item.ConfirmationFilesTuple.Count; j++)
{
var att = item.ConfirmationFilesTuple[j];
attHelper.ExecuteCheck(att, (name, value, msg) =>
{
listRoot.Add(new SacInfo(name, value, msg));
});
}
}
if (listRoot.Count > 0)
{
var errMsg = new SacInfo("OptionConfirmationAtt", i);
errMsg.FieldValue = item.ConfirmationNo;
errMsg.SubMaps = new List<SacInfo>(listRoot);
result.Add(errMsg);
}
}
}
checkStatus = result.Count > 0;
return result;
}
public override bool BeforeOfGenerated(out string errMsg)
{
errMsg = "";
for (int i = 0; i < noteList.Count; i++)
{
base.SaveReportNotes(noteList[i]);
}
return true;
}
}
}
File diff suppressed because it is too large Load Diff
@@ -1,8 +1,14 @@
using System.Data;
using FluentFTP.Helpers;
using MoreLinq;
using NPOI.SS.Formula.Functions;
using System.Data;
using System.Linq;
using System.Text.RegularExpressions;
using YLErp.BLL;
using YLErp.Commons;
using YLErp.DBModels.Consts;
using YLErp.DBModels.Enums;
using YLErp.Helpers;
using YLErp.Modules.EodModule;
using YLErp.Modules.SuperviseReportModule.SAC.Common;
using YLErp.Modules.SuperviseReportModule.SAC.Model;
@@ -10,6 +16,7 @@ using static YLErp.DBModels.Consts.ConsReport;
namespace YLErp.Modules.SuperviseReportModule.SAC.Service
{
//交易存续期管理
class ReportOptionTerminationService : ReportBaseService
{
public ReportOptionTerminationService(OptUserInfo optUser) : base(optUser)
@@ -22,53 +29,39 @@ namespace YLErp.Modules.SuperviseReportModule.SAC.Service
protected override DataFlagsEnum BusiDataType => DataFlagsEnum.A1007;
private List<OptFlagsEnum> _validOperationType = null;
private List<OptFlagsEnum>? _validOperationType = null;
public override List<OptFlagsEnum> ValidOperationType
{
get
{
if (_validOperationType == null)
{
_validOperationType = new List<OptFlagsEnum>() {
_validOperationType ??= new List<OptFlagsEnum>() {
OptFlagsEnum.A,
OptFlagsEnum.U,
OptFlagsEnum.D,
OptFlagsEnum.U,
};
}
return _validOperationType;
}
}
protected override SuperviseReportTypeEnum ReportType => SuperviseReportTypeEnum.SAC_OptionTermination;
List<SACReportNotes> noteList = new List<SACReportNotes>();
private List<string> _cacheCodeList = new List<string>();
readonly List<SACReportNotes> noteList = new();
private readonly List<string> _cacheCodeList = new();
protected override BodyModel GenerateBody(out bool noData, out List<string> fileList)
{
fileList = new List<string>();
BodyModel model = new BodyModel();
List<OptionTerminationModel> dataList = new List<OptionTerminationModel>();
if ((PS.Config.ErpElement.SAC_ReportDataSource & SAC_ReportDataSourceEnum.Template) == SAC_ReportDataSourceEnum.Template)
var model = new BodyModel();
var dataList = new List<OptionTerminationModel>();
if (_reqInfo.DataSource.HasFlag(SAC_ReportDataSourceEnum.Template))
{
dataList = GetOptionTerminationFromExcel();
dataList = GetOptionTerminationModel(ref fileList);
}
if ((PS.Config.ErpElement.SAC_ReportDataSource & SAC_ReportDataSourceEnum.System) == SAC_ReportDataSourceEnum.System)
{
var cacheKey = $"{BusiDataType}";
var nextDate = _reqInfo.ReportDate.AddDays(1);
var actions = new List<string>() { "系统操作-平仓费", "系统操作-行权费" };
using (var db = new YLContext())
{
dataList.AddRange(GetOptionTerminationExtensionTimeFromDb(db, cacheKey, nextDate));
dataList.AddRange(GetOptionTerminationSettlementFromDb(db, cacheKey, nextDate));
}
}
var subsystemDataList = loadSubsystemDataSource<OptionTerminationModel>(fileList, AddSubsystemNote);
if (subsystemDataList != null && subsystemDataList.Count > 0)
{
dataList.AddRange(subsystemDataList);
}
noData = dataList.Count == 0;
model.OptionTermination = dataList;
@@ -78,7 +71,7 @@ namespace YLErp.Modules.SuperviseReportModule.SAC.Service
public bool AddSubsystemNote(OptionTerminationModel model, List<string> fileList, string tag)
{
var isExtensionTime = model.DurationOperationType == ConsReport.OperationTypeMap["展期"];
DateTime date = DateTime.MinValue;
var date = DateTime.MinValue;
if (isExtensionTime)
{
DateTime.TryParse(model.RenewalDate, out date);
@@ -88,14 +81,14 @@ namespace YLErp.Modules.SuperviseReportModule.SAC.Service
DateTime.TryParse(model.ExpirationDate, out date);
}
var extensionTimeInfo = model.DurationOperationType == ConsReport.OperationTypeMap["展期"] ? "-" : "";
List<SACReportNotes> notes = base.GetReportNotes(ReportType, $"_{model.ConfirmationNo.Replace("_", "-")}_{_operationType}", true);//添加了operationType,要不A和D会查到同一条记录,在D时候,就会和A相同的数据
var notes = base.GetReportNotes(ReportType, $"_{model.ConfirmationNo.Replace("_", "-")}_{_operationType}", true);//添加了operationType,要不A和D会查到同一条记录,在D时候,就会和A相同的数据
//永远查找现有成功报送了结的新增记录,而不是修改;
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)
{
if (isExtensionTime)
{
string oldDateStr = "";
var oldDateStr = "";
var oldData = base.GetReportNotes(SuperviseReportTypeEnum.SAC_OptionConfirmation, $"A1004_{model.ConfirmationNo.Replace("_", "-")}_成交_A").FirstOrDefault();
oldDateStr = Regex.Match(oldData?.InfoCache ?? "", "(?<=DueDate\":\")[^\"]+(?=\")").Value;
if (DateTime.TryParse(oldDateStr, out var oldDate))
@@ -127,7 +120,7 @@ namespace YLErp.Modules.SuperviseReportModule.SAC.Service
//多次U的时候,每次用最新的tag来赋值SubFileTag
if (isExtensionTime)
{
string oldDateStr = "";
var oldDateStr = "";
var oldData = base.GetReportNotes(SuperviseReportTypeEnum.SAC_OptionConfirmation, $"A1004_{model.ConfirmationNo.Replace("_", "-")}_成交_A").FirstOrDefault();
oldDateStr = Regex.Match(oldData?.InfoCache ?? "", "(?<=DueDate\":\")[^\"]+(?=\")").Value;
if (DateTime.TryParse(oldDateStr, out var oldDate))
@@ -169,374 +162,6 @@ namespace YLErp.Modules.SuperviseReportModule.SAC.Service
return true;
}
/// <summary>
/// 从数据库获取展期记录
/// </summary>
/// <param name="db"></param>
/// <param name="cacheKey"></param>
/// <param name="nextDate"></param>
/// <returns></returns>
private List<OptionTerminationModel> GetOptionTerminationExtensionTimeFromDb(YLContext db, string cacheKey, DateTime nextDate)
{
List<OptionTerminationModel> dataList = new List<OptionTerminationModel>();
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
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
}).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 OptionTerminationModel();
info.TradeId = item.TradeId.ToString();
info.ConfirmationNo = item.ContractCode;
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.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")}\",\"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;
}
/// <summary>
/// 从数据库获取结算信息
/// </summary>
/// <param name="db"></param>
/// <param name="cacheKey"></param>
/// <param name="nextDate"></param>
/// <returns></returns>
private IEnumerable<OptionTerminationModel> GetOptionTerminationSettlementFromDb(YLContext db, string cacheKey, DateTime nextDate)
{
List<OptionTerminationModel> dataList = new List<OptionTerminationModel>();
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
where log.OptDate >= _reqInfo.ReportDate && log.OptDate < nextDate && log.OptType == "交易回退" && t.ParentTradeId == 0 &&
actions.Contains(tc.Action) && /*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
}).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
where tc.ValueDate == _reqInfo.DataDate &&
t.ValidState != "InValid" && tc.ValidState != "InValid" && !tc.IsDeleted && tr.IsValid &&
/*t.UnderlyingInstrumentType == "Stock" &&*/ t.TradeType != "收益互换" &&
actions.Contains(tc.Action)
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
}).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)
{
string 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 OptionTerminationModel();
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;
info.ExpirationDate = 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.ExpirationDate));
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.ExpirationDate = obj.ValueDate.ToString("yyyy-MM-dd");
info.DurationOperationType = OperationTypeMap["终止"];
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 = DbContext.trade_cash.Where(O => O.TradeId == obj.id && O.ValueDate < obj.ValueDate && actions.Contains(O.Action)).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.Balance = Math.Max((latestStockEqvNotional - currentStockEqvNotional), 0).ToString("0.00");
info.AmountPaidThisTime = (obj.Amount * settlementRate).ToString();
info.ExceID = base.formatExceID();
ReportStatus.AddCacheInfo(cacheKey, cacheValue);
dataList.Add(info);
note.id = 0;
note.InfoCache = $"{{\"Tag\":\"{info.ConfirmationNo}\",\"ValueDate\":\"{info.ExpirationDate}\",\"Source\":\"System\"}}";
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.RetCode = "";
note.RetMsg = "";
note.ReportResponse = false;
note.BizId = "";
note.DataId = "";
note.changeStatus = false;
noteList.Add(note);
}
return dataList;
}
/// <summary>
/// 格式化报送标签,用于关联报表和业务信息
/// </summary>
@@ -546,25 +171,50 @@ namespace YLErp.Modules.SuperviseReportModule.SAC.Service
/// <returns></returns>
private string formatInfoTag(OptionTerminationModel model, bool suffixType = false, string extensionTimeInfo = "")
{
string result = $"{BusiDataType}_{model.ConfirmationNo.Replace("_", "-")}_{(string.IsNullOrWhiteSpace(extensionTimeInfo) ? "" : ($"_{extensionTimeInfo}_展期"))}_";
var operationTag = "";
if (model.DurationOperationType == ConsReport.OperationTypeMap["敲入"] || model.DurationOperationType == ConsReport.OperationTypeMap["敲出"])
{
operationTag = $"_{model.DurationOperationType}";
}
string result = $"{formatInfoTagStr(model)}{operationTag}_{model.DurationEventNO}_";
if (suffixType)
{
result = $"{result}{_operationType}";
}
return result;
}
private string formatInfoTagStr(OptionTerminationModel model, string extensionTimeInfo = "")
{
string result = $"{BusiDataType}_{model.ConfirmationNo.Replace("_", "-")}_{(string.IsNullOrWhiteSpace(extensionTimeInfo) ? "" : ($"_{extensionTimeInfo}_展期"))}";
return result;
}
protected override string _changeCodeOfInfoTag(string infoTag, string newCode, out string originalCode)
{
var arr = infoTag.Split('_');
if (arr.Length != 5 && arr.Length != 6)
{
throw new ServiceException($"InfoTag信息不匹配:{infoTag}");
}
originalCode = arr[1];
arr[1] = newCode.Replace("_", "-");
return string.Join("_", arr);
}
/// <summary>
/// 从Excel获取结算信息
/// </summary>
/// <returns></returns>
private List<OptionTerminationModel> GetOptionTerminationFromExcel()
private List<OptionTerminationModel> GetOptionTerminationModel(ref List<string> fileList)
{
List<OptionTerminationModel> result = new List<OptionTerminationModel>();
var result = new List<OptionTerminationModel>();
string path = "";
if (_excelDataSource != null && _excelDataSource.Tables.Contains("期权交易存续期明细"))
{
var cacheKey = $"{BusiDataType}";
DataTable dt = _excelDataSource.Tables["期权交易存续期明细"];
for (int i = 1; i < dt.Rows.Count; i++)
string sourcePath = Path.Combine(_excelDataSourceRootPath, "附件");
var dt = _excelDataSource.Tables["期权交易存续期明细"];
for (var i = 1; i < dt.Rows.Count; i++)
{
if (string.IsNullOrWhiteSpace(dt.Rows[i][0]?.ToString()))
{
@@ -572,14 +222,20 @@ namespace YLErp.Modules.SuperviseReportModule.SAC.Service
break;
}
var optType = OptFlagsEnum.NONE;
switch (dt.Rows[i][1]?.ToString())
switch (dt.Rows[i][2]?.ToString())
{
case "0":
case "A":
case "首次":
optType = OptFlagsEnum.A;
break;
case "1":
case "U":
case "变更":
optType = OptFlagsEnum.U;
break;
case "2":
case "D":
case "废止":
optType = OptFlagsEnum.D;
break;
@@ -589,63 +245,55 @@ namespace YLErp.Modules.SuperviseReportModule.SAC.Service
continue;
}
OptionTerminationModel model = new OptionTerminationModel();
model.ConfirmationNo = GetDataSetValue(dt, i, 0);
model.OperationType = optType;
model.ExpirationDate = GetDataSetValue(dt, i, 2);
model.DefaultingParty = ConsReport.OptionTraderMap[GetDataSetValue(dt, i, 3)];
model.DefaultEvent = GetDataSetValue(dt, i, 4);
model.RenewalDate = GetDataSetValue(dt, i, 5);
model.DurationOperationType = ConsReport.OperationTypeMap[GetDataSetValue(dt, i, 6)];
model.TerminationAmount = GetDataSetValue(dt, i, 7);
model.Balance = GetDataSetValue(dt, i, 8);
model.AmountPaidThisTime = GetDataSetValue(dt, i, 9);
var isExtensionTime = model.DurationOperationType == ConsReport.OperationTypeMap["展期"];
DateTime date = DateTime.MinValue;
if (isExtensionTime)
DateTime.TryParse(GetDataSetValue(dt, i, 4), out DateTime expirationDate);
var model = new OptionTerminationModel
{
DateTime.TryParse(model.RenewalDate, out date);
}
else
DurationEventNO = GetDataSetValue(dt, i, 0),
ConfirmationNo = GetDataSetValue(dt, i, 1),
OperationType = optType,
DurationOperationType = ConsReport.OperationTypeMap[GetDataSetValue(dt, i, 3)],
ExpirationDate = expirationDate == DateTime.MinValue ? null : expirationDate.ToString("yyyy-MM-dd"),
RenewalDate = GetDataSetValue(dt, i, 5),
};
model.DefaultingParty = ConsReport.FillPartyMap[GetDataSetValue(dt, i, 6)];
model.DefaultEvent = GetDataSetValue(dt, i, 7);
model.TerminationAmount = GetDataSetValue(dt, i, 8);
model.Balance = GetDataSetValueToDoubleOrNull(dt, i, 9)?.ToString("0.00");
model.AmountPaidThisTime = GetDataSetValue(dt, i, 10);
model.ClosedTransactionsRealRateReturn = GetDataSetValue(dt, i, 11);
// model.TerminationAmount = GetDataSetValueToDouble(dt, i, 8).ToString("0.00");
// model.Balance = GetDataSetValueToDouble(dt, i, 9).ToString("0.00");
// model.AmountPaidThisTime = GetDataSetValueToDouble(dt, i, 10).ToString("0.00");
// model.ClosedTransactionsRealRateReturn = GetDataSetValueToDouble(dt, i, 11).ToString("0.00");
model.OptionDurationManagementAtt = GetDataSetValue(dt, i, 12);
var eventStatus = "";
switch (model.DurationOperationType)
{
DateTime.TryParse(model.ExpirationDate, out date);
case "05":
eventStatus = "01";
break;
case "06":
eventStatus = "02";
break;
}
var cacheValue = model.ConfirmationNo + date.ToString("yyyy-MM-dd");
if (ReportStatus.CheckCacheInfo(cacheKey, cacheValue))
model.BarrierEventStatus = eventStatus;
model.Blank1 = GetDataSetValue(dt, i, 14);
model.Blank2 = GetDataSetValue(dt, i, 15);
DateTime.TryParse(model.ExpirationDate, out DateTime date);
var cacheValue = $"{model.ConfirmationNo}_{model.DurationEventNO}_";
if (ReportStatus.CheckCacheInfo(CacheKey, cacheValue))
{
continue;
}
var extensionTimeInfo = model.DurationOperationType == ConsReport.OperationTypeMap["展期"] ? "-" : "";
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")));
List<SACReportNotes> notes = base.GetReportNotes(ReportType, formatInfoTag(model));
var note = notes.LastOrDefault(O => O.InfoCache.Contains(date.ToString("yyyy-MM-dd")));
if (note == null && _operationType == OptFlagsEnum.A)
{
if (isExtensionTime)
note = new SACReportNotes()
{
string oldDateStr = "";
var oldData = base.GetReportNotes(SuperviseReportTypeEnum.SAC_OptionConfirmation, $"A1004_{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")}\",\"Source\":\"Template\"}}",
IsValid = true,
};
}
else
{
note = new SACReportNotes()
{
InfoCache = $"{{\"Tag\":\"{model.ConfirmationNo}\",\"ValueDate\":\"{date.ToString("yyyy-MM-dd")}\",\"Source\":\"Template\"}}",
IsValid = true,
};
}
IsValid = true,
};
}
else
{
@@ -667,22 +315,31 @@ namespace YLErp.Modules.SuperviseReportModule.SAC.Service
default:
throw new ServiceException("未知操作类型");
}
note.InfoCache = Regex.Replace(note.InfoCache, "(?<=NewMaturityDate\":\")[^\"]+ (?= \")", date.ToString("yyyy-MM-dd"));
}
if (model.OperationType != OptFlagsEnum.A)
{
model.BizID = note.BizId;//确认书编号;
}
path = Path.Combine(sourcePath, model.OptionDurationManagementAtt);
if (!string.IsNullOrWhiteSpace(model.OptionDurationManagementAtt))
{
if (!ReportStatus.CheckFileLength(path))
{
break;
}
fileList.Add(path);
}
model.ExceID = base.formatExceID();
result.Add(model);
ReportStatus.AddCacheInfo(cacheKey, cacheValue);
ReportStatus.AddCacheInfo(CacheKey, cacheValue);
note.InfoCache = $"{{\"Tag\":\"{model.ConfirmationNo}\",\"ValueDate\":\"{date.ToString("yyyy-MM-dd")}\",\"DurationEventNO\":\"{model.DurationEventNO}\"}}";
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.InfoTag = formatInfoTag(model, true);
note.OptTime = note.CreateTime;
note.RetCode = "";
note.RetMsg = "";
@@ -698,13 +355,13 @@ namespace YLErp.Modules.SuperviseReportModule.SAC.Service
protected override List<SacInfo> CheckBodyValue(BodyModel model, out bool checkStatus)
{
List<SacInfo> result = new List<SacInfo>();
var result = new List<SacInfo>();
if (model?.OptionTermination != null)
{
CheckHelper<OptionTerminationModel> helper = new Common.CheckHelper<OptionTerminationModel>();
for (int i = 0; i < model.OptionTermination.Count; i++)
var helper = new Common.CheckHelper<OptionTerminationModel>();
for (var i = 0; i < model.OptionTermination.Count; i++)
{
List<SacInfo> listRoot = new List<SacInfo>();
var listRoot = new List<SacInfo>();
var item = model.OptionTermination[i];
helper.ExecuteCheck(item, (name, value, msg) =>
{
@@ -712,8 +369,11 @@ namespace YLErp.Modules.SuperviseReportModule.SAC.Service
});
if (listRoot.Count > 0)
{
var errMsg = new SacInfo("OptionTermination", i);
errMsg.SubMaps = new List<SacInfo>(listRoot);
var errMsg = new SacInfo("OptionTermination", i)
{
FieldValue = item.ConfirmationNo,
SubMaps = new List<SacInfo>(listRoot)
};
result.Add(errMsg);
}
}
@@ -736,7 +396,7 @@ namespace YLErp.Modules.SuperviseReportModule.SAC.Service
LogFactory.GetLogger<ReportMasterAgrmtProductService>().Error(e);
};
}
for (int i = 0; i < noteList.Count; i++)
for (var i = 0; i < noteList.Count; i++)
{
base.SaveReportNotes(noteList[i]);
}
@@ -15,25 +15,23 @@ namespace YLErp.Modules.SuperviseReportModule.SAC.Service
protected override DataFlagsEnum BusiDataType => DataFlagsEnum.A1010;
private List<OptFlagsEnum> _validOperationType = null;
private List<OptFlagsEnum>? _validOperationType = null;
public override List<OptFlagsEnum> ValidOperationType
{
get
{
if (_validOperationType == null)
{
_validOperationType = new List<OptFlagsEnum>() {
_validOperationType ??= new List<OptFlagsEnum>() {
OptFlagsEnum.A,
OptFlagsEnum.U,
OptFlagsEnum.D,
};
}
return _validOperationType;
}
}
protected override SuperviseReportTypeEnum ReportType => SuperviseReportTypeEnum.SAC_OtherReport;
List<SACReportNotes> noteList = new List<SACReportNotes>();
readonly List<SACReportNotes> noteList = new();
public override bool CheckRequestParamer(ReportInfo req, out string errMsg)
{
@@ -63,7 +61,7 @@ namespace YLErp.Modules.SuperviseReportModule.SAC.Service
errMsg = "其他事项报告非新增报送时,对应的业务编码不应为空";
return false;
}
SACReportNotes note = base.GetReportNotes(ReportType, formatInfoTag(req.OtherReportDate?.ToString("yyyy-MM-dd"))).Where(O => O.ReportDate == req.OtherReportDate).FirstOrDefault();
var note = base.GetReportNotes(ReportType, formatInfoTag(req.OtherReportDate?.ToString("yyyy-MM-dd"))).Where(O => O.ReportDate == req.OtherReportDate).FirstOrDefault();
if (note == null)
{
errMsg = $"{req.OtherReportDate?.ToString("yyyy-MM-dd")}不存在报送成功的其他事项报告记录,请重新选择";
@@ -72,7 +70,7 @@ namespace YLErp.Modules.SuperviseReportModule.SAC.Service
if (req.OtherReportStatus == OptFlagsEnum.U)
{
var fileIds = tempFilesService.QueryTempFile(req.ReportDate, "其他事项报告").Select(O => O.id.ToString()).ToArray();
string[] fileIdArr = note.DataId.Split(new[] { ',' }, StringSplitOptions.RemoveEmptyEntries);
var fileIdArr = note.DataId.Split(new[] { ',' }, StringSplitOptions.RemoveEmptyEntries);
if (!fileIds.Except(fileIdArr).Any())
{
errMsg = $"{req.ReportDate.ToString("yyyy-MM-dd")}已上传其他事项报告附件都已报送成功,不需要再次报送";
@@ -103,9 +101,11 @@ namespace YLErp.Modules.SuperviseReportModule.SAC.Service
fileList = new List<string>();
noData = false;
var noteKey = formatInfoTag(_reqInfo.ReportDate.ToString("yyyy-MM-dd"));
BodyModel model = new BodyModel();
model.OtherReport = new OtherReportModel();
SACReportNotes note = base.GetReportNotes(ReportType, noteKey).FirstOrDefault();
var model = new BodyModel
{
OtherReport = new OtherReportModel()
};
var note = base.GetReportNotes(ReportType, noteKey).FirstOrDefault();
if (note == null && _operationType == OptFlagsEnum.A)
{
note = new SACReportNotes()
@@ -161,8 +161,10 @@ namespace YLErp.Modules.SuperviseReportModule.SAC.Service
{
ReportStatus.AddCacheInfo(noteKey, item.fileName);
}
var info = new OtherReportFileDetailModel();
info.OtherReportFile = item.fileName;
var info = new OtherReportFileDetailModel
{
OtherReportFile = item.fileName
};
if (model.OtherReport.OtherReportFileTuple == null)
{
model.OtherReport.OtherReportFileTuple = new List<OtherReportFileDetailModel>();
@@ -174,8 +176,8 @@ namespace YLErp.Modules.SuperviseReportModule.SAC.Service
model.OtherReport.DetailedDescription = _reqInfo.OtherReportDesc;
}
model.OtherReport.ExceID = base.formatExceID();
List<SACReportNotes> notes = base.GetReportNotes(ReportType, noteKey);
noData = (!(model.OtherReport.OtherReportFileTuple?.Count > 0));
var notes = base.GetReportNotes(ReportType, noteKey);
noData = !(model.OtherReport.OtherReportFileTuple?.Count > 0);
if (!noData)
{
note.id = 0;
@@ -198,19 +200,19 @@ namespace YLErp.Modules.SuperviseReportModule.SAC.Service
protected override List<SacInfo> CheckBodyValue(BodyModel model, out bool checkStatus)
{
List<SacInfo> result = new List<SacInfo>();
var result = new List<SacInfo>();
if (model?.OtherReport != null)
{
List<SacInfo> listRoot = new List<SacInfo>();
CheckHelper<OtherReportModel> helper = new CheckHelper<OtherReportModel>();
CheckHelper<OtherReportFileDetailModel> detailHelper = new CheckHelper<OtherReportFileDetailModel>();
var listRoot = new List<SacInfo>();
var helper = new CheckHelper<OtherReportModel>();
var detailHelper = new CheckHelper<OtherReportFileDetailModel>();
helper.ExecuteCheck(model.OtherReport, (name, value, msg) =>
{
listRoot.Add(new SacInfo(name, value, msg));
});
if (model.OtherReport.OtherReportFileTuple != null)
{
for (int i = 0; i < model.OtherReport.OtherReportFileTuple.Count; i++)
for (var i = 0; i < model.OtherReport.OtherReportFileTuple.Count; i++)
{
var listItem = new List<SacInfo>();
var item = model.OtherReport.OtherReportFileTuple[i];
@@ -220,16 +222,20 @@ namespace YLErp.Modules.SuperviseReportModule.SAC.Service
});
if (listItem.Count > 0)
{
var temp = new SacInfo("OtherReportFileTuple", i);
temp.SubMaps = new List<SacInfo>(listItem);
var temp = new SacInfo("OtherReportFileTuple", i)
{
SubMaps = new List<SacInfo>(listItem)
};
listRoot.Add(temp);
}
}
}
if (listRoot.Count > 0)
{
var errMsg = new SacInfo("OtherReport");
errMsg.SubMaps = new List<SacInfo>(listRoot);
var errMsg = new SacInfo("OtherReport")
{
SubMaps = new List<SacInfo>(listRoot)
};
result.Add(errMsg);
}
}
@@ -239,7 +245,7 @@ namespace YLErp.Modules.SuperviseReportModule.SAC.Service
private string formatInfoTag(string tag, bool suffixType = false)
{
string result = $"{BusiDataType}_{tag}_";
var result = $"{BusiDataType}_{tag}_";
if (suffixType)
{
result = $"{result}{_operationType}";
@@ -247,10 +253,16 @@ namespace YLErp.Modules.SuperviseReportModule.SAC.Service
return result;
}
protected override string _changeCodeOfInfoTag(string infoTag, string newCode, out string originalCode)
{
//定期报告中不存在编号,也就不存在修改编号的情况;
throw new NotImplementedException();
}
public override bool BeforeOfGenerated(out string errMsg)
{
errMsg = "";
for (int i = 0; i < noteList.Count; i++)
for (var i = 0; i < noteList.Count; i++)
{
base.SaveReportNotes(noteList[i]);
}
@@ -19,151 +19,38 @@ namespace YLErp.Modules.SuperviseReportModule.SAC.Service
protected override DataFlagsEnum BusiDataType => DataFlagsEnum.A1008;
private List<OptFlagsEnum> _validOperationType = null;
private List<OptFlagsEnum>? _validOperationType = null;
public override List<OptFlagsEnum> ValidOperationType
{
get
{
if (_validOperationType == null)
{
_validOperationType = new List<OptFlagsEnum>() {
_validOperationType ??= new List<OptFlagsEnum>() {
OptFlagsEnum.A,
OptFlagsEnum.U,
OptFlagsEnum.D,
};
}
return _validOperationType;
}
}
protected override SuperviseReportTypeEnum ReportType => SuperviseReportTypeEnum.SAC_PerformanceGuaranteeAgrmt;
List<SACReportNotes> noteList = new List<SACReportNotes>();
readonly List<SACReportNotes> noteList = new();
protected override BodyModel GenerateBody(out bool noData, out List<string> fileList)
{
fileList = new List<string>();
BodyModel model = new BodyModel();
List<PerformanceGuaranteeAgrmtModel> dataList = new List<PerformanceGuaranteeAgrmtModel>();
if ((PS.Config.ErpElement.SAC_ReportDataSource & SAC_ReportDataSourceEnum.Template) == SAC_ReportDataSourceEnum.Template)
var model = new BodyModel();
var dataList = new List<PerformanceGuaranteeAgrmtModel>();
if (_reqInfo.DataSource.HasFlag(SAC_ReportDataSourceEnum.Template))
{
dataList = GetPerformanceGuaranteeAgrmtModel(ref fileList);
}
if ((PS.Config.ErpElement.SAC_ReportDataSource & SAC_ReportDataSourceEnum.System) == SAC_ReportDataSourceEnum.System)
{
var cacheKey = $"{BusiDataType}";
using (var baseDb = DbContextFactory.GetClientDbContext(null))
{
var nextDate = _reqInfo.ReportDate.AddDays(1);
var fileObjList = (from c in baseDb.client
join cf in baseDb.client_file
on c.id equals cf.ClientId
where c.ProcessStatus == "已开户" && cf.HasSent == false && cf.IsValid &&
cf.FileTypeName == ConsGlobal.ClientFileType.DateMargin && cf.OptState == _operationType &&
((c.ProcessOptDate >= _reqInfo.ReportDate && c.ProcessOptDate < nextDate && cf.OptDate < nextDate) ||//如果这一天开户,则把这一天之前(含这一天)的所有文件都报送了
(cf.OptDate >= _reqInfo.ReportDate && cf.OptDate < nextDate && c.ProcessOptDate < _reqInfo.ReportDate))//如果这一天不是开户日期,则只在报送日期大于开户日期时,报送当日修改的文件
&& cf.ApprovalOrder < 1
select new
{
cf.id,
cf.ProtocolNumber,
cf.MainProtocolNumber,
cf.FilePath,
cf.FileName,
cf.SignDate,
}).ToArray();
var codes = fileObjList.Select(O => O.MainProtocolNumber);
ExpandoDictionary<string, client_file> protocolFileDict = null;
if (codes.Count() > 0)
{
protocolFileDict = new ExpandoDictionary<string, client_file>(
baseDb.client_file
.Where(O => O.ApprovalOrder < 1 && O.FileTypeName == ConsGlobal.ClientFileType.EnhanceProtocol && codes.Contains(O.ProtocolNumber) && O.IsValid)
.AsEnumerable()
.GroupBy(O => O.ProtocolNumber)
.ToDictionary(K => K.Key, V => V.FirstOrDefault())
);
}
foreach (var item in fileObjList)
{
var info = new PerformanceGuaranteeAgrmtModel();
info.OperationType = _operationType;
info.MasterAgrmtNo = protocolFileDict[item.MainProtocolNumber ?? ""]?.MainProtocolNumber;
info.SupAgrmtNo = protocolFileDict[item.MainProtocolNumber ?? ""]?.ProtocolNumber;
info.PerformanceGuaranteeAgrmt = item.FileName;
info.SigningDate = item.SignDate?.ToString("yyyy-MM-dd");
var cacheValue = info.MasterAgrmtNo + "_" + info.SupAgrmtNo;
if (ReportStatus.CheckCacheInfo(cacheKey, cacheValue))
{
continue;
}
SACReportNotes note = base.GetReportNotes(ReportType, formatInfoTag(info)).FirstOrDefault();
if (note == null && _operationType == OptFlagsEnum.A)
{
note = new SACReportNotes()
{
InfoCache = $"{{\"Tag\":\"{info.PerformanceGuaranteeAgrmt}\",\"Source\":\"System\"}}",
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("未知操作类型");
}
}
if (info.OperationType != OptFlagsEnum.A)
{
info.PerformanceGuaranteeAgrmtID = note.BizId;
}
info.ExceID = base.formatExceID();
if (!ReportStatus.CheckFileLength(item.FilePath))
{
break;
}
else
{
ReportStatus.AddCacheInfo(cacheKey, cacheValue);
}
dataList.Add(info);
fileList.Add(item.FilePath);
note.id = 0;
note.DataId = item.id.ToString();
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.RetCode = "";
note.RetMsg = "";
note.ReportResponse = false;
note.BizId = "";
note.changeStatus = false;
noteList.Add(note);
}
}
}
var subsystemDataList = loadSubsystemDataSource<PerformanceGuaranteeAgrmtModel>(fileList, AddSubsystemNote);
if (subsystemDataList != null && subsystemDataList.Count > 0)
{
dataList.AddRange(subsystemDataList);
}
noData = dataList.Count == 0;
model.PerformanceGuaranteeAgrmt = dataList;
@@ -172,7 +59,7 @@ namespace YLErp.Modules.SuperviseReportModule.SAC.Service
public bool AddSubsystemNote(PerformanceGuaranteeAgrmtModel model, List<string> fileList, string tag)
{
SACReportNotes note = base.GetReportNotes(ReportType, formatInfoTag(model,true)).FirstOrDefault();//参数true要加,要不A和D会查到同一条记录,在D时候,就会和A相同的数据
var note = base.GetReportNotes(ReportType, formatInfoTag(model, true)).FirstOrDefault();//参数true要加,要不A和D会查到同一条记录,在D时候,就会和A相同的数据
if (note == null)
{
note = new SACReportNotes()
@@ -200,7 +87,7 @@ namespace YLErp.Modules.SuperviseReportModule.SAC.Service
throw new ServiceException("未知操作类型");
}
}
if (!string.IsNullOrEmpty(model.PerformanceGuaranteeAgrmt))
{
fileList.Add(model.PerformanceGuaranteeAgrmt);
@@ -225,7 +112,7 @@ namespace YLErp.Modules.SuperviseReportModule.SAC.Service
private string formatInfoTag(PerformanceGuaranteeAgrmtModel model, bool suffixType = false)
{
string result = $"{BusiDataType}_{model.MasterAgrmtNo.Replace("_", "-")}_{model.SupAgrmtNo.Replace("_", "-")}_";
var result = $"{BusiDataType}_{model.MasterAgrmtNo.Replace("_", "-")}_{model.SupAgrmtNo.Replace("_", "-")}_{model.PerformanceGuaranteeAgrmt.Replace("_", "-")}_";
if (suffixType)
{
result = $"{result}{_operationType}";
@@ -233,15 +120,20 @@ namespace YLErp.Modules.SuperviseReportModule.SAC.Service
return result;
}
protected override string _changeCodeOfInfoTag(string infoTag, string newCode, out string originalCode)
{
originalCode = "";
return infoTag;
}
private List<PerformanceGuaranteeAgrmtModel> GetPerformanceGuaranteeAgrmtModel(ref List<string> fileList)
{
List<PerformanceGuaranteeAgrmtModel> result = new List<PerformanceGuaranteeAgrmtModel>();
var result = new List<PerformanceGuaranteeAgrmtModel>();
if (_excelDataSource != null && _excelDataSource.Tables.Contains("履约保证书明细"))
{
var cacheKey = $"{BusiDataType}";
string sourcePath = Path.Combine(_excelDataSourceRootPath, "附件");
DataTable dt = _excelDataSource.Tables["履约保证书明细"];
for (int i = 1; i < dt.Rows.Count; i++)
var sourcePath = Path.Combine(_excelDataSourceRootPath, "附件");
var dt = _excelDataSource.Tables["履约保证书明细"];
for (var i = 1; i < dt.Rows.Count; i++)
{
if (string.IsNullOrWhiteSpace(dt.Rows[i][0]?.ToString()))
{
@@ -251,12 +143,18 @@ namespace YLErp.Modules.SuperviseReportModule.SAC.Service
var optType = OptFlagsEnum.NONE;
switch (dt.Rows[i][2]?.ToString())
{
case "0":
case "A":
case "首次":
optType = OptFlagsEnum.A;
break;
case "1":
case "U":
case "变更":
optType = OptFlagsEnum.U;
break;
case "2":
case "D":
case "废止":
optType = OptFlagsEnum.D;
break;
@@ -266,20 +164,21 @@ namespace YLErp.Modules.SuperviseReportModule.SAC.Service
continue;
}
PerformanceGuaranteeAgrmtModel model = new PerformanceGuaranteeAgrmtModel();
model.MasterAgrmtNo = GetDataSetValue(dt, i, 0);
model.SupAgrmtNo = GetDataSetValue(dt, i, 1);
model.OperationType = optType == OptFlagsEnum.A ? OptFlagsEnum.A : OptFlagsEnum.U;
model.PerformanceGuaranteeAgrmt = GetDataSetValue(dt, i, 3);
model.SigningDate = GetDataSetValue(dt, i, 4);
var cacheValue = model.MasterAgrmtNo + "_" + model.SupAgrmtNo;
if (ReportStatus.CheckCacheInfo(cacheKey, cacheValue))
var model = new PerformanceGuaranteeAgrmtModel
{
MasterAgrmtNo = GetDataSetValue(dt, i, 0),
SupAgrmtNo = GetDataSetValue(dt, i, 1),
OperationType = optType == OptFlagsEnum.A ? OptFlagsEnum.A : OptFlagsEnum.U,
PerformanceGuaranteeAgrmt = GetDataSetValue(dt, i, 3),
SigningDate = GetDataSetValue(dt, i, 4)
};
var cacheValue = model.MasterAgrmtNo + "_" + model.SupAgrmtNo + "_" + model.PerformanceGuaranteeAgrmt;
if (ReportStatus.CheckCacheInfo(CacheKey, cacheValue))
{
continue;
}
SACReportNotes note = base.GetReportNotes(ReportType, formatInfoTag(model)).FirstOrDefault();
var note = base.GetReportNotes(ReportType, formatInfoTag(model)).FirstOrDefault();
if (note == null && _operationType == OptFlagsEnum.A)
{
note = new SACReportNotes()
@@ -316,14 +215,14 @@ namespace YLErp.Modules.SuperviseReportModule.SAC.Service
if (!string.IsNullOrWhiteSpace(model.PerformanceGuaranteeAgrmt))
{
model.ExceID = base.formatExceID();
string path = Path.Combine(sourcePath, model.PerformanceGuaranteeAgrmt);
var path = Path.Combine(sourcePath, model.PerformanceGuaranteeAgrmt);
if (!ReportStatus.CheckFileLength(path))
{
break;
}
else
{
ReportStatus.AddCacheInfo(cacheKey, cacheValue);
ReportStatus.AddCacheInfo(CacheKey, cacheValue);
}
result.Add(model);
fileList.Add(path);
@@ -349,23 +248,30 @@ namespace YLErp.Modules.SuperviseReportModule.SAC.Service
protected override List<SacInfo> CheckBodyValue(BodyModel model, out bool checkStatus)
{
List<SacInfo> result = new List<SacInfo>();
var result = new List<SacInfo>();
if (model.PerformanceGuaranteeAgrmt != null)
{
CheckHelper<PerformanceGuaranteeAgrmtModel> helper = new Common.CheckHelper<PerformanceGuaranteeAgrmtModel>();
for (int i = 0; i < model.PerformanceGuaranteeAgrmt.Count; i++)
var helper = new Common.CheckHelper<PerformanceGuaranteeAgrmtModel>();
for (var i = 0; i < model.PerformanceGuaranteeAgrmt.Count; i++)
{
List<SacInfo> listRoot = new List<SacInfo>();
var listRoot = new List<SacInfo>();
var item = model.PerformanceGuaranteeAgrmt[i];
if (item.IgnoreCheck) continue;
if (item.IgnoreCheck)
{
continue;
}
helper.ExecuteCheck(item, (name, value, msg) =>
{
listRoot.Add(new SacInfo(name, value, msg));
});
if (listRoot.Count > 0)
{
var errMsg = new SacInfo("PerformanceGuaranteeAgrmt", i);
errMsg.SubMaps = new List<SacInfo>(listRoot);
var errMsg = new SacInfo("PerformanceGuaranteeAgrmt", i)
{
FieldValue = item.MasterAgrmtNo,
SubMaps = new List<SacInfo>(listRoot)
};
result.Add(errMsg);
}
}
@@ -391,7 +297,7 @@ namespace YLErp.Modules.SuperviseReportModule.SAC.Service
};
}
for (int i = 0; i < noteList.Count; i++)
for (var i = 0; i < noteList.Count; i++)
{
base.SaveReportNotes(noteList[i]);
}
@@ -20,19 +20,16 @@ namespace YLErp.Modules.SuperviseReportModule.SAC.Service
protected override DataFlagsEnum BusiDataType => DataFlagsEnum.A1013;
private List<OptFlagsEnum> _validOperationType = null;
private List<OptFlagsEnum>? _validOperationType = null;
public override List<OptFlagsEnum> ValidOperationType
{
get
{
if (_validOperationType == null)
{
_validOperationType = new List<OptFlagsEnum>() {
_validOperationType ??= new List<OptFlagsEnum>() {
OptFlagsEnum.A,
OptFlagsEnum.U,
OptFlagsEnum.D,
};
}
return _validOperationType;
}
}
@@ -40,7 +37,8 @@ namespace YLErp.Modules.SuperviseReportModule.SAC.Service
DateTime minDate = DateTime.MinValue;
DateTime maxDate = DateTime.MinValue;
protected override SuperviseReportTypeEnum ReportType => SuperviseReportTypeEnum.SAC_PeriodicReportISDA;
List<SACReportNotes> noteList = new List<SACReportNotes>();
readonly List<SACReportNotes> noteList = new();
public override bool CheckRequestParamer(ReportInfo req, out string errMsg)
{
@@ -59,7 +57,7 @@ namespace YLErp.Modules.SuperviseReportModule.SAC.Service
case OptFlagsEnum.D:
minDate = req.ISDAReportDate.Value.Date.AddDays(-req.ISDAReportDate.Value.Day).AddDays(1);
maxDate = req.ISDAReportDate.Value.Date.AddMonths(1).AddDays(-req.ISDAReportDate.Value.Day);
SACReportNotes note = base.GetReportNotes(ReportType, formatInfoTag(req.ISDAReportDate.Value.ToString("yyyy-MM"))).FirstOrDefault();
var note = base.GetReportNotes(ReportType, formatInfoTag(req.ISDAReportDate.Value.ToString("yyyy-MM"))).FirstOrDefault();
if (note == null)
{
errMsg = $"{minDate.ToString("yyyy-MM-dd")}~{maxDate.ToString("yyyy-MM-dd")}不存在报送成功的ISDA定期报告记录,请重新选择";
@@ -86,16 +84,17 @@ namespace YLErp.Modules.SuperviseReportModule.SAC.Service
{
fileList = new List<string>();
noData = true;
BodyModel model = new BodyModel();
var cacheKey = $"{BusiDataType}";
var model = new BodyModel();
var cacheValue = formatInfoTag(_reqInfo.ISDAReportDate.Value.ToString("yyyy-MM"));
if (ReportStatus.CheckCacheInfo(cacheKey, cacheValue))
if (ReportStatus.CheckCacheInfo(CacheKey, cacheValue))
{
return model;
}
model.PeriodicReportISDA = new PeriodicReportISDAModel();
model.PeriodicReportISDA.OperationType = _operationType;
SACReportNotes note = base.GetReportNotes(ReportType, cacheValue).FirstOrDefault();
model.PeriodicReportISDA = new PeriodicReportISDAModel
{
OperationType = _operationType
};
var note = base.GetReportNotes(ReportType, cacheValue).FirstOrDefault();
if (note == null && _operationType == OptFlagsEnum.A)
{
note = new SACReportNotes()
@@ -128,7 +127,7 @@ namespace YLErp.Modules.SuperviseReportModule.SAC.Service
}
if (_excelDataSource != null)
{
DataTable dt = _excelDataSource.Tables["业务统计"];
var dt = _excelDataSource.Tables["业务统计"];
model.PeriodicReportISDA.Year = _reqInfo.ISDAReportDate.Value.Year.ToString("0000");
model.PeriodicReportISDA.Month = _reqInfo.ISDAReportDate.Value.Month.ToString("0");
model.PeriodicReportISDA.OperationType = _operationType;
@@ -151,7 +150,7 @@ namespace YLErp.Modules.SuperviseReportModule.SAC.Service
model.PeriodicReportISDA.ExceID = base.formatExceID();
}
ReportStatus.AddCacheInfo(cacheKey, cacheValue);
ReportStatus.AddCacheInfo(CacheKey, cacheValue);
noData = string.IsNullOrWhiteSpace(model.PeriodicReportISDA?.MainAgreementLastMonthAccumulatedThisYear);
if (!noData)
{
@@ -486,24 +485,26 @@ namespace YLErp.Modules.SuperviseReportModule.SAC.Service
/// <returns></returns>
private List<ISDAIncreaseBusinessDetailsThisMonthModel> GetIncreaseBusinessDetailsThisMonthTuple()
{
List<ISDAIncreaseBusinessDetailsThisMonthModel> result = new List<ISDAIncreaseBusinessDetailsThisMonthModel>();
var result = new List<ISDAIncreaseBusinessDetailsThisMonthModel>();
if (_excelDataSource != null && _excelDataSource.Tables.Contains("本月新增业务明细"))
{
DataTable dt = _excelDataSource.Tables["本月新增业务明细"];
for (int i = 1; i < dt.Rows.Count; i++)
var dt = _excelDataSource.Tables["本月新增业务明细"];
for (var i = 1; i < dt.Rows.Count; i++)
{
string colHead = dt.Rows[i][0]?.ToString();
var colHead = dt.Rows[i][0]?.ToString();
if (string.IsNullOrWhiteSpace(colHead) || colHead.Contains("合计"))
{
//第一列空白说明数据结束了;
break;
}
ISDAIncreaseBusinessDetailsThisMonthModel model = new ISDAIncreaseBusinessDetailsThisMonthModel();
model.NameOfSecuritiesCompany = GetDataSetValue(dt, i, 1).ToString();
model.NameOfCounterparty = GetDataSetValue(dt, i, 2).ToString();
model.NameOfCounterpartyProduct = GetDataSetValue(dt, i, 3).ToString();
model.TradeConfirmationNumber = GetDataSetValue(dt, i, 4);
model.TransactionConfirmationNumber = GetDataSetValue(dt, i, 5);
var model = new ISDAIncreaseBusinessDetailsThisMonthModel
{
NameOfSecuritiesCompany = GetDataSetValue(dt, i, 1).ToString(),
NameOfCounterparty = GetDataSetValue(dt, i, 2).ToString(),
NameOfCounterpartyProduct = GetDataSetValue(dt, i, 3).ToString(),
TradeConfirmationNumber = GetDataSetValue(dt, i, 4),
TransactionConfirmationNumber = GetDataSetValue(dt, i, 5)
};
if (model.TransactionConfirmationNumber.IsNullOrWhiteSpace())
{
model.TransactionConfirmationNumber = base.GetBizIdFromInfoTag(model.TradeConfirmationNumber);
@@ -516,7 +517,7 @@ namespace YLErp.Modules.SuperviseReportModule.SAC.Service
model.InvestmentTargetType = ConsReport.UndrlygAssetTypeMap[GetDataSetValue(dt, i, 11).ToString()];
model.UndrlygAssetName = GetDataSetValue(dt, i, 12).ToString();
model.UndrlygAssetCode = GetDataSetValue(dt, i, 13).ToString();
model.OptionObjectSecondClass = ConsReport.UndrlygAssetDtldTypeMap[GetDataSetValue(dt, i, 14).ToString()];
model.OptionObjectSecondClass = ConsReport.SwapUndrlygAssetDtldTypeMap[GetDataSetValue(dt, i, 14).ToString()];
model.SwapObjectSecondClass = ConsReport.SwapUndrlygAssetDtldTypeMap[GetDataSetValue(dt, i, 15).ToString()];
model.NonAnnualOptionFee = GetDataSetValue(dt, i, 16).ToString();
model.OptionType = ConsReport.OptionStructureTypeMap[GetDataSetValue(dt, i, 17).ToString()];
@@ -532,24 +533,26 @@ namespace YLErp.Modules.SuperviseReportModule.SAC.Service
/// <returns></returns>
private List<ISDAInventoryBusinessDetailsAtTheEndOfThisMonthModel> GetInventoryBusinessDetailsAtTheEndOfThisMonthTuple()
{
List<ISDAInventoryBusinessDetailsAtTheEndOfThisMonthModel> result = new List<ISDAInventoryBusinessDetailsAtTheEndOfThisMonthModel>();
var result = new List<ISDAInventoryBusinessDetailsAtTheEndOfThisMonthModel>();
if (_excelDataSource != null && _excelDataSource.Tables.Contains("本月末存量业务明细"))
{
DataTable dt = _excelDataSource.Tables["本月末存量业务明细"];
for (int i = 1; i < dt.Rows.Count; i++)
var dt = _excelDataSource.Tables["本月末存量业务明细"];
for (var i = 1; i < dt.Rows.Count; i++)
{
string colHead = dt.Rows[i][0]?.ToString();
var colHead = dt.Rows[i][0]?.ToString();
if (string.IsNullOrWhiteSpace(colHead) || colHead.Contains("合计"))
{
//第一列空白说明数据结束了;
break;
}
ISDAInventoryBusinessDetailsAtTheEndOfThisMonthModel model = new ISDAInventoryBusinessDetailsAtTheEndOfThisMonthModel();
model.NameOfSecuritiesCompany = GetDataSetValue(dt, i, 1).ToString();
model.NameOfCounterparty = GetDataSetValue(dt, i, 2).ToString();
model.NameOfCounterpartyProduct = GetDataSetValue(dt, i, 3).ToString();
model.TradeConfirmationNumber = GetDataSetValue(dt, i, 4);
model.TransactionConfirmationNumber = GetDataSetValue(dt, i, 5);
var model = new ISDAInventoryBusinessDetailsAtTheEndOfThisMonthModel
{
NameOfSecuritiesCompany = GetDataSetValue(dt, i, 1).ToString(),
NameOfCounterparty = GetDataSetValue(dt, i, 2).ToString(),
NameOfCounterpartyProduct = GetDataSetValue(dt, i, 3).ToString(),
TradeConfirmationNumber = GetDataSetValue(dt, i, 4),
TransactionConfirmationNumber = GetDataSetValue(dt, i, 5)
};
if (model.TransactionConfirmationNumber.IsNullOrWhiteSpace())
{
model.TransactionConfirmationNumber = base.GetBizIdFromInfoTag(model.TradeConfirmationNumber);
@@ -563,7 +566,7 @@ namespace YLErp.Modules.SuperviseReportModule.SAC.Service
model.UndrlygAssetName = GetDataSetValue(dt, i, 12).ToString();
model.UndrlygAssetCode = GetDataSetValue(dt, i, 13).ToString();
model.UndrlygAssetTradgPlc = GetDataSetValue(dt, i, 14).ToString();
model.OptionObjectSecondClass = ConsReport.UndrlygAssetDtldTypeMap[GetDataSetValue(dt, i, 15).ToString()];
model.OptionObjectSecondClass = ConsReport.SwapUndrlygAssetDtldTypeMap[GetDataSetValue(dt, i, 15).ToString()];
model.SwapObjectSecondClass = ConsReport.SwapUndrlygAssetDtldTypeMap[GetDataSetValue(dt, i, 16).ToString()];
model.NonAnnualOptionFee = GetDataSetValue(dt, i, 17).ToString();
model.OptionType = ConsReport.OptionStructureTypeMap[GetDataSetValue(dt, i, 18).ToString()];
@@ -583,30 +586,32 @@ namespace YLErp.Modules.SuperviseReportModule.SAC.Service
/// <returns></returns>
private List<ISDATargetCaseAndHedgeModel> GetTargetCaseAndHedgeTuple()
{
List<ISDATargetCaseAndHedgeModel> result = new List<ISDATargetCaseAndHedgeModel>();
var result = new List<ISDATargetCaseAndHedgeModel>();
if (_excelDataSource != null && _excelDataSource.Tables.Contains("标的情况与对冲"))
{
DataTable dt = _excelDataSource.Tables["标的情况与对冲"];
for (int i = 2; i < dt.Rows.Count; i++)
var dt = _excelDataSource.Tables["标的情况与对冲"];
for (var i = 1; i < dt.Rows.Count; i++)
{
if (string.IsNullOrWhiteSpace(dt.Rows[i][0]?.ToString()))
{
//第一列空白说明数据结束了;
break;
}
ISDATargetCaseAndHedgeModel model = new ISDATargetCaseAndHedgeModel();
model.NameOfSecuritiesCompany = GetDataSetValue(dt, i, 1).ToString();
model.BusinessType = ConsReport.BusinessTypeMap[GetDataSetValue(dt, i, 2).ToString()];
model.InvestmentTargetType = ConsReport.HedgeSACUndrlygAssetDtldTypeMap[GetDataSetValue(dt, i, 3).ToString()];
model.InvestmentTarget = GetDataSetValue(dt, i, 4).ToString();
model.UnderlyingCode = GetDataSetValue(dt, i, 5).ToString();
model.UndrlygAssetTradgPlc = GetDataSetValue(dt, i, 6).ToString();
model.BuyingImpulseVolume = GetDataSetValue(dt, i, 7).ToString();
model.SellingImpulseVolume = GetDataSetValue(dt, i, 8).ToString();
model.ImpulseVolume = GetDataSetValue(dt, i, 9).ToString();
model.PositionAtTheEndOfThisMonth = GetDataSetValue(dt, i, 10).ToString();
model.TheNumberOfPositionsHeldAtTheEndOfThisMonth = GetDataSetValue(dt, i, 11).ToString();
model.AveragePriceAtTheEndOfTheMonth = GetDataSetValue(dt, i, 12).ToString();
var model = new ISDATargetCaseAndHedgeModel
{
NameOfSecuritiesCompany = GetDataSetValue(dt, i, 1).ToString(),
BusinessType = ConsReport.BusinessTypeMap[GetDataSetValue(dt, i, 2).ToString()],
InvestmentTargetType = ConsReport.HedgeSACUndrlygAssetDtldTypeMap[GetDataSetValue(dt, i, 3).ToString()],
InvestmentTarget = GetDataSetValue(dt, i, 4).ToString(),
UnderlyingCode = GetDataSetValue(dt, i, 5).ToString(),
UndrlygAssetTradgPlc = GetDataSetValue(dt, i, 6).ToString(),
BuyingImpulseVolume = GetDataSetValue(dt, i, 7).ToString(),
SellingImpulseVolume = GetDataSetValue(dt, i, 8).ToString(),
ImpulseVolume = GetDataSetValue(dt, i, 9).ToString(),
PositionAtTheEndOfThisMonth = GetDataSetValue(dt, i, 10).ToString(),
TheNumberOfPositionsHeldAtTheEndOfThisMonth = GetDataSetValue(dt, i, 11).ToString(),
AveragePriceAtTheEndOfTheMonth = GetDataSetValue(dt, i, 12).ToString()
};
result.Add(model);
}
@@ -616,21 +621,21 @@ namespace YLErp.Modules.SuperviseReportModule.SAC.Service
protected override List<SacInfo> CheckBodyValue(BodyModel model, out bool checkStatus)
{
List<SacInfo> result = new List<SacInfo>();
var result = new List<SacInfo>();
if (model?.PeriodicReportISDA != null)
{
List<SacInfo> listRoot = new List<SacInfo>();
CheckHelper<PeriodicReportISDAModel> helper = new Common.CheckHelper<PeriodicReportISDAModel>();
CheckHelper<ISDAIncreaseBusinessDetailsThisMonthModel> detailHelper = new Common.CheckHelper<ISDAIncreaseBusinessDetailsThisMonthModel>();
CheckHelper<ISDAInventoryBusinessDetailsAtTheEndOfThisMonthModel> detail2Helper = new Common.CheckHelper<ISDAInventoryBusinessDetailsAtTheEndOfThisMonthModel>();
CheckHelper<ISDATargetCaseAndHedgeModel> hedgeHelper = new Common.CheckHelper<ISDATargetCaseAndHedgeModel>();
var listRoot = new List<SacInfo>();
var helper = new Common.CheckHelper<PeriodicReportISDAModel>();
var detailHelper = new Common.CheckHelper<ISDAIncreaseBusinessDetailsThisMonthModel>();
var detail2Helper = new Common.CheckHelper<ISDAInventoryBusinessDetailsAtTheEndOfThisMonthModel>();
var hedgeHelper = new Common.CheckHelper<ISDATargetCaseAndHedgeModel>();
helper.ExecuteCheck(model.PeriodicReportISDA, (name, value, msg) =>
{
listRoot.Add(new SacInfo(name, value, msg));
});
if (model.PeriodicReportISDA.IncreaseBusinessDetailsThisMonthTuple != null)
{
for (int i = 0; i < model.PeriodicReportISDA.IncreaseBusinessDetailsThisMonthTuple.Count; i++)
for (var i = 0; i < model.PeriodicReportISDA.IncreaseBusinessDetailsThisMonthTuple.Count; i++)
{
var listItem = new List<SacInfo>();
var item = model.PeriodicReportISDA.IncreaseBusinessDetailsThisMonthTuple[i];
@@ -640,15 +645,17 @@ namespace YLErp.Modules.SuperviseReportModule.SAC.Service
});
if (listItem.Count > 0)
{
var temp = new SacInfo("IncreaseBusinessDetailsThisMonthTuple", i);
temp.SubMaps = new List<SacInfo>(listItem);
var temp = new SacInfo("IncreaseBusinessDetailsThisMonthTuple", i)
{
SubMaps = new List<SacInfo>(listItem)
};
listRoot.Add(temp);
}
}
}
if (model.PeriodicReportISDA.InventoryBusinessDetailsAtTheEndOfThisMonthTuple != null)
{
for (int i = 0; i < model.PeriodicReportISDA.InventoryBusinessDetailsAtTheEndOfThisMonthTuple.Count; i++)
for (var i = 0; i < model.PeriodicReportISDA.InventoryBusinessDetailsAtTheEndOfThisMonthTuple.Count; i++)
{
var listItem = new List<SacInfo>();
var item = model.PeriodicReportISDA.InventoryBusinessDetailsAtTheEndOfThisMonthTuple[i];
@@ -658,15 +665,17 @@ namespace YLErp.Modules.SuperviseReportModule.SAC.Service
});
if (listItem.Count > 0)
{
var temp = new SacInfo("InventoryBusinessDetailsAtTheEndOfThisMonthTuple", i);
temp.SubMaps = new List<SacInfo>(listItem);
var temp = new SacInfo("InventoryBusinessDetailsAtTheEndOfThisMonthTuple", i)
{
SubMaps = new List<SacInfo>(listItem)
};
listRoot.Add(temp);
}
}
}
if (model.PeriodicReportISDA.TargetCaseAndHedgeTuple != null)
{
for (int i = 0; i < model.PeriodicReportISDA.TargetCaseAndHedgeTuple.Count; i++)
for (var i = 0; i < model.PeriodicReportISDA.TargetCaseAndHedgeTuple.Count; i++)
{
var listItem = new List<SacInfo>();
var item = model.PeriodicReportISDA.TargetCaseAndHedgeTuple[i];
@@ -676,16 +685,20 @@ namespace YLErp.Modules.SuperviseReportModule.SAC.Service
});
if (listItem.Count > 0)
{
var temp = new SacInfo("TargetCaseAndHedgeTuple", i);
temp.SubMaps = new List<SacInfo>(listItem);
var temp = new SacInfo("TargetCaseAndHedgeTuple", i)
{
SubMaps = new List<SacInfo>(listItem)
};
listRoot.Add(temp);
}
}
}
if (listRoot.Count > 0)
{
var errMsg = new SacInfo("PeriodicReportISDA");
errMsg.SubMaps = new List<SacInfo>(listRoot);
var errMsg = new SacInfo("PeriodicReportISDA")
{
SubMaps = new List<SacInfo>(listRoot)
};
result.Add(errMsg);
}
}
@@ -695,7 +708,7 @@ namespace YLErp.Modules.SuperviseReportModule.SAC.Service
private string formatInfoTag(string tag, bool suffixType = false)
{
string result = $"{BusiDataType}_{tag}_";
var result = $"{BusiDataType}_{tag}_";
if (suffixType)
{
result = $"{result}{_operationType}";
@@ -703,10 +716,16 @@ namespace YLErp.Modules.SuperviseReportModule.SAC.Service
return result;
}
protected override string _changeCodeOfInfoTag(string infoTag, string newCode, out string originalCode)
{
//定期报告中不存在编号,也就不存在修改编号的情况;
throw new NotImplementedException();
}
public override bool BeforeOfGenerated(out string errMsg)
{
errMsg = "";
for (int i = 0; i < noteList.Count; i++)
for (var i = 0; i < noteList.Count; i++)
{
base.SaveReportNotes(noteList[i]);
}
@@ -19,19 +19,16 @@ namespace YLErp.Modules.SuperviseReportModule.SAC.Service
protected override DataFlagsEnum BusiDataType => DataFlagsEnum.A1012;
private List<OptFlagsEnum> _validOperationType = null;
private List<OptFlagsEnum>? _validOperationType = null;
public override List<OptFlagsEnum> ValidOperationType
{
get
{
if (_validOperationType == null)
{
_validOperationType = new List<OptFlagsEnum>() {
_validOperationType ??= new List<OptFlagsEnum>() {
OptFlagsEnum.A,
OptFlagsEnum.U,
OptFlagsEnum.D,
};
}
return _validOperationType;
}
}
@@ -39,7 +36,8 @@ namespace YLErp.Modules.SuperviseReportModule.SAC.Service
DateTime minDate = DateTime.MinValue;
DateTime maxDate = DateTime.MinValue;
protected override SuperviseReportTypeEnum ReportType => SuperviseReportTypeEnum.SAC_PeriodicReportNAFMII;
List<SACReportNotes> noteList = new List<SACReportNotes>();
readonly List<SACReportNotes> noteList = new();
public override bool CheckRequestParamer(ReportInfo req, out string errMsg)
{
@@ -58,7 +56,7 @@ namespace YLErp.Modules.SuperviseReportModule.SAC.Service
case OptFlagsEnum.D:
minDate = req.NAFMIIReportDate.Value.Date.AddDays(-req.NAFMIIReportDate.Value.Day).AddDays(1);
maxDate = req.NAFMIIReportDate.Value.Date.AddMonths(1).AddDays(-req.NAFMIIReportDate.Value.Day);
SACReportNotes note = base.GetReportNotes(ReportType, formatInfoTag(req.NAFMIIReportDate.Value.ToString("yyyy-MM"))).FirstOrDefault();
var note = base.GetReportNotes(ReportType, formatInfoTag(req.NAFMIIReportDate.Value.ToString("yyyy-MM"))).FirstOrDefault();
if (note == null)
{
errMsg = $"{minDate.ToString("yyyy-MM-dd")}~{maxDate.ToString("yyyy-MM-dd")}不存在报送成功的NAFMII定期报告记录,请重新选择";
@@ -85,16 +83,17 @@ namespace YLErp.Modules.SuperviseReportModule.SAC.Service
{
fileList = new List<string>();
noData = true;
BodyModel model = new BodyModel();
var cacheKey = $"{BusiDataType}";
var model = new BodyModel();
var cacheValue = formatInfoTag(_reqInfo.NAFMIIReportDate.Value.ToString("yyyy-MM"));
if (ReportStatus.CheckCacheInfo(cacheKey, cacheValue))
if (ReportStatus.CheckCacheInfo(CacheKey, cacheValue))
{
return model;
}
model.PeriodicReportNAFMII = new PeriodicReportNAFMIIModel();
model.PeriodicReportNAFMII.OperationType = _operationType;
SACReportNotes note = base.GetReportNotes(ReportType, cacheValue).FirstOrDefault();
model.PeriodicReportNAFMII = new PeriodicReportNAFMIIModel
{
OperationType = _operationType
};
var note = base.GetReportNotes(ReportType, cacheValue).FirstOrDefault();
if (note == null && _operationType == OptFlagsEnum.A)
{
note = new SACReportNotes()
@@ -131,7 +130,7 @@ namespace YLErp.Modules.SuperviseReportModule.SAC.Service
}
if (_excelDataSource != null)
{
DataTable dt = _excelDataSource.Tables["业务统计"];
var dt = _excelDataSource.Tables["业务统计"];
model.PeriodicReportNAFMII.Year = _reqInfo.NAFMIIReportDate.Value.Year.ToString("0000");
model.PeriodicReportNAFMII.Month = _reqInfo.NAFMIIReportDate.Value.Month.ToString("0");
model.PeriodicReportNAFMII.OperationType = _operationType;
@@ -145,7 +144,7 @@ namespace YLErp.Modules.SuperviseReportModule.SAC.Service
model.PeriodicReportNAFMII.ExceID = base.formatExceID();
}
noData = string.IsNullOrWhiteSpace(model.PeriodicReportNAFMII?.MainAgreementLastMonthAccumulatedThisYear);
ReportStatus.AddCacheInfo(cacheKey, cacheValue);
ReportStatus.AddCacheInfo(CacheKey, cacheValue);
if (!noData)
{
note.id = 0;
@@ -276,31 +275,33 @@ namespace YLErp.Modules.SuperviseReportModule.SAC.Service
/// <returns></returns>
private List<ScheduleOfOtherTransactionModel> GetScheduleOfOtherTransactionModel()
{
List<ScheduleOfOtherTransactionModel> result = new List<ScheduleOfOtherTransactionModel>();
var result = new List<ScheduleOfOtherTransactionModel>();
if (_excelDataSource != null && _excelDataSource.Tables.Contains("其他交易明细"))
{
DataTable dt = _excelDataSource.Tables["其他交易明细"];
for (int i = 1; i < dt.Rows.Count; i++)
var dt = _excelDataSource.Tables["其他交易明细"];
for (var i = 1; i < dt.Rows.Count; i++)
{
if (string.IsNullOrWhiteSpace(dt.Rows[i][0]?.ToString()))
{
//第一列空白说明数据结束了;
break;
}
ScheduleOfOtherTransactionModel model = new ScheduleOfOtherTransactionModel();
model.TradingDate = GetDataSetValue(dt, i, 1).ToString();
model.NameOfSecuritiesCompany = GetDataSetValue(dt, i, 2).ToString();
model.FillInTheNameOfTheAgency = GetDataSetValue(dt, i, 3).ToString();
model.NameOfCounterparty = GetDataSetValue(dt, i, 4).ToString();
model.CounterpartyAllographProduct = GetDataSetValue(dt, i, 5).ToString();
model.BusinessType = ConsReport.BusinessTypeMap[GetDataSetValue(dt, i, 6).ToString()];
model.CounterpartyType = ConsReport.NAFMIICounterpartyTypeMap[GetDataSetValue(dt, i, 7).ToString()];
model.CounterpartyIsProfessionalInstitutionsOrNot = ConsReport.BoolNumberMap[GetDataSetValue(dt, i, 8).ToString()];
model.NotionalPrincipalAmount = GetDataSetValue(dt, i, 9).ToString();
model.InvestmentTargetType = ConsReport.NAFMIIUndrlygAssetDtldTypeMap[GetDataSetValue(dt, i, 10).ToString()];
model.InvestmentTarget = GetDataSetValue(dt, i, 11).ToString();
model.StartDate = GetDataSetValue(dt, i, 12).ToString();
model.ContractExpirationDate = GetDataSetValue(dt, i, 13).ToString();
var model = new ScheduleOfOtherTransactionModel
{
TradingDate = GetDataSetValue(dt, i, 1).ToString(),
NameOfSecuritiesCompany = GetDataSetValue(dt, i, 2).ToString(),
FillInTheNameOfTheAgency = GetDataSetValue(dt, i, 3).ToString(),
NameOfCounterparty = GetDataSetValue(dt, i, 4).ToString(),
CounterpartyAllographProduct = GetDataSetValue(dt, i, 5).ToString(),
BusinessType = ConsReport.BusinessTypeMap[GetDataSetValue(dt, i, 6).ToString()],
CounterpartyType = ConsReport.NAFMIICounterpartyTypeMap[GetDataSetValue(dt, i, 7).ToString()],
CounterpartyIsProfessionalInstitutionsOrNot = ConsReport.BoolNumberMap[GetDataSetValue(dt, i, 8).ToString()],
NotionalPrincipalAmount = GetDataSetValue(dt, i, 9).ToString(),
InvestmentTargetType = ConsReport.NAFMIIUndrlygAssetDtldTypeMap[GetDataSetValue(dt, i, 10).ToString()],
InvestmentTarget = GetDataSetValue(dt, i, 11).ToString(),
StartDate = GetDataSetValue(dt, i, 12).ToString(),
ContractExpirationDate = GetDataSetValue(dt, i, 13).ToString()
};
result.Add(model);
}
@@ -314,40 +315,42 @@ namespace YLErp.Modules.SuperviseReportModule.SAC.Service
/// <returns></returns>
private List<InterestRateSwapDetailModel> GetInterestRateSwapDetailModel()
{
List<InterestRateSwapDetailModel> result = new List<InterestRateSwapDetailModel>();
var result = new List<InterestRateSwapDetailModel>();
if (_excelDataSource != null && _excelDataSource.Tables.Contains("利率互换明细"))
{
DataTable dt = _excelDataSource.Tables["利率互换明细"];
for (int i = 2; i < dt.Rows.Count; i++)
var dt = _excelDataSource.Tables["利率互换明细"];
for (var i = 2; i < dt.Rows.Count; i++)
{
if (string.IsNullOrWhiteSpace(dt.Rows[i][0]?.ToString()))
{
//第一列空白说明数据结束了;
break;
}
InterestRateSwapDetailModel model = new InterestRateSwapDetailModel();
model.TransactionDate = GetDataSetValue(dt, i, 1).ToString();
model.NameOfSecuritiesCompany = GetDataSetValue(dt, i, 2).ToString();
model.FillInTheNameOfTheAgency = GetDataSetValue(dt, i, 3).ToString();
model.NameOfCounterparty = GetDataSetValue(dt, i, 4).ToString();
model.CounterpartyAllographProduct = GetDataSetValue(dt, i, 5).ToString();
model.CounterpartyType = ConsReport.NAFMIICounterpartyTypeMap[GetDataSetValue(dt, i, 6).ToString()];
model.CounterpartyIsProfessionalInstitutionsOrNot = ConsReport.BoolNumberMap[GetDataSetValue(dt, i, 7).ToString()];
model.FixedInterestPaymentParty = GetDataSetValue(dt, i, 8).ToString();
model.FloatingInterestPaymentParty = GetDataSetValue(dt, i, 9).ToString();
model.NotionalPrincipalAmount = GetDataSetValue(dt, i, 10).ToString();
model.ContractPeriod = GetDataSetValue(dt, i, 11).ToString();
model.DalueDate = GetDataSetValue(dt, i, 12).ToString();
model.DueDate = GetDataSetValue(dt, i, 13).ToString();
model.FixedRate = GetDataSetValue(dt, i, 14).ToString();
model.FixedRatePaymentCycle = GetDataSetValue(dt, i, 15).ToString();
model.FixedInterestRateBasis = GetDataSetValue(dt, i, 16).ToString();
model.NameOfReferenceRate = GetDataSetValue(dt, i, 17).ToString();
model.Spreads = GetDataSetValue(dt, i, 18).ToString();
model.FloatingRatePaymentCycle = GetDataSetValue(dt, i, 19).ToString();
model.ResetTheFrequency = GetDataSetValue(dt, i, 20).ToString();
model.FloatingInterestRateBasis = GetDataSetValue(dt, i, 21).ToString();
model.FirstInterestPaymentDay = GetDataSetValue(dt, i, 22).ToString();
var model = new InterestRateSwapDetailModel
{
TransactionDate = GetDataSetValue(dt, i, 1).ToString(),
NameOfSecuritiesCompany = GetDataSetValue(dt, i, 2).ToString(),
FillInTheNameOfTheAgency = GetDataSetValue(dt, i, 3).ToString(),
NameOfCounterparty = GetDataSetValue(dt, i, 4).ToString(),
CounterpartyAllographProduct = GetDataSetValue(dt, i, 5).ToString(),
CounterpartyType = ConsReport.NAFMIICounterpartyTypeMap[GetDataSetValue(dt, i, 6).ToString()],
CounterpartyIsProfessionalInstitutionsOrNot = ConsReport.BoolNumberMap[GetDataSetValue(dt, i, 7).ToString()],
FixedInterestPaymentParty = GetDataSetValue(dt, i, 8).ToString(),
FloatingInterestPaymentParty = GetDataSetValue(dt, i, 9).ToString(),
NotionalPrincipalAmount = GetDataSetValue(dt, i, 10).ToString(),
ContractPeriod = GetDataSetValue(dt, i, 11).ToString(),
DalueDate = GetDataSetValue(dt, i, 12).ToString(),
DueDate = GetDataSetValue(dt, i, 13).ToString(),
FixedRate = GetDataSetValue(dt, i, 14).ToString(),
FixedRatePaymentCycle = GetDataSetValue(dt, i, 15).ToString(),
FixedInterestRateBasis = GetDataSetValue(dt, i, 16).ToString(),
NameOfReferenceRate = GetDataSetValue(dt, i, 17).ToString(),
Spreads = GetDataSetValue(dt, i, 18).ToString(),
FloatingRatePaymentCycle = GetDataSetValue(dt, i, 19).ToString(),
ResetTheFrequency = GetDataSetValue(dt, i, 20).ToString(),
FloatingInterestRateBasis = GetDataSetValue(dt, i, 21).ToString(),
FirstInterestPaymentDay = GetDataSetValue(dt, i, 22).ToString()
};
result.Add(model);
}
@@ -361,34 +364,36 @@ namespace YLErp.Modules.SuperviseReportModule.SAC.Service
/// <returns></returns>
private List<InterestRateOptionDetailModel> GetInterestRateOptionDetailModel()
{
List<InterestRateOptionDetailModel> result = new List<InterestRateOptionDetailModel>();
var result = new List<InterestRateOptionDetailModel>();
if (_excelDataSource != null && _excelDataSource.Tables.Contains("利率期权明细"))
{
DataTable dt = _excelDataSource.Tables["利率期权明细"];
for (int i = 1; i < dt.Rows.Count; i++)
var dt = _excelDataSource.Tables["利率期权明细"];
for (var i = 1; i < dt.Rows.Count; i++)
{
if (string.IsNullOrWhiteSpace(dt.Rows[i][0]?.ToString()))
{
//第一列空白说明数据结束了;
break;
}
InterestRateOptionDetailModel model = new InterestRateOptionDetailModel();
model.TradingDate = GetDataSetValue(dt, i, 1).ToString();
model.NameOfSecuritiesCompany = GetDataSetValue(dt, i, 2).ToString();
model.FillInTheNameOfTheAgency = GetDataSetValue(dt, i, 3).ToString();
model.NameOfCounterparty = GetDataSetValue(dt, i, 4).ToString();
model.CounterpartyAllographProduct = GetDataSetValue(dt, i, 5).ToString();
model.BusinessType = ConsReport.OptionTraderMap[GetDataSetValue(dt, i, 6).ToString()];
model.OptionType = ConsReport.BusinessTypeMap[GetDataSetValue(dt, i, 7).ToString()];
model.OptionPosition = ConsReport.NAFMIIOptionDirectionMap[GetDataSetValue(dt, i, 8).ToString()];
model.CounterpartyType = ConsReport.NAFMIICounterpartyTypeMap[GetDataSetValue(dt, i, 9).ToString()];
model.CounterpartyIsProfessionalInstitutionsOrNot = ConsReport.BoolNumberMap[GetDataSetValue(dt, i, 10).ToString()];
model.NotionalPrincipalAmount = GetDataSetValue(dt, i, 11).ToString();
model.ExcerciseInterestRate = GetDataSetValue(dt, i, 12).ToString();
model.InvestmentTarget = ConsReport.NAFMIIInvestmentNameMap[GetDataSetValue(dt, i, 13).ToString()];
model.DeliveryType = ConsReport.NAFMIIDeliveryTypeMap[GetDataSetValue(dt, i, 14).ToString()];
model.StartDate = GetDataSetValue(dt, i, 15).ToString();
model.ContractExpirationDate = GetDataSetValue(dt, i, 16).ToString();
var model = new InterestRateOptionDetailModel
{
TradingDate = GetDataSetValue(dt, i, 1).ToString(),
NameOfSecuritiesCompany = GetDataSetValue(dt, i, 2).ToString(),
FillInTheNameOfTheAgency = GetDataSetValue(dt, i, 3).ToString(),
NameOfCounterparty = GetDataSetValue(dt, i, 4).ToString(),
CounterpartyAllographProduct = GetDataSetValue(dt, i, 5).ToString(),
BusinessType = ConsReport.OptionTraderMap[GetDataSetValue(dt, i, 6).ToString()],
OptionType = ConsReport.BusinessTypeMap[GetDataSetValue(dt, i, 7).ToString()],
OptionPosition = ConsReport.NAFMIIOptionDirectionMap[GetDataSetValue(dt, i, 8).ToString()],
CounterpartyType = ConsReport.NAFMIICounterpartyTypeMap[GetDataSetValue(dt, i, 9).ToString()],
CounterpartyIsProfessionalInstitutionsOrNot = ConsReport.BoolNumberMap[GetDataSetValue(dt, i, 10).ToString()],
NotionalPrincipalAmount = GetDataSetValue(dt, i, 11).ToString(),
ExcerciseInterestRate = GetDataSetValue(dt, i, 12).ToString(),
InvestmentTarget = ConsReport.NAFMIIInvestmentNameMap[GetDataSetValue(dt, i, 13).ToString()],
DeliveryType = ConsReport.NAFMIIDeliveryTypeMap[GetDataSetValue(dt, i, 14).ToString()],
StartDate = GetDataSetValue(dt, i, 15).ToString(),
ContractExpirationDate = GetDataSetValue(dt, i, 16).ToString()
};
result.Add(model);
}
@@ -398,21 +403,21 @@ namespace YLErp.Modules.SuperviseReportModule.SAC.Service
protected override List<SacInfo> CheckBodyValue(BodyModel model, out bool checkStatus)
{
List<SacInfo> result = new List<SacInfo>();
var result = new List<SacInfo>();
if (model?.PeriodicReportNAFMII != null)
{
List<SacInfo> listRoot = new List<SacInfo>();
CheckHelper<PeriodicReportNAFMIIModel> helper = new Common.CheckHelper<PeriodicReportNAFMIIModel>();
CheckHelper<InterestRateSwapDetailModel> swapDetailHelper = new Common.CheckHelper<InterestRateSwapDetailModel>();
CheckHelper<InterestRateOptionDetailModel> optionDetailHelper = new Common.CheckHelper<InterestRateOptionDetailModel>();
CheckHelper<ScheduleOfOtherTransactionModel> transactionHelper = new Common.CheckHelper<ScheduleOfOtherTransactionModel>();
var listRoot = new List<SacInfo>();
var helper = new Common.CheckHelper<PeriodicReportNAFMIIModel>();
var swapDetailHelper = new Common.CheckHelper<InterestRateSwapDetailModel>();
var optionDetailHelper = new Common.CheckHelper<InterestRateOptionDetailModel>();
var transactionHelper = new Common.CheckHelper<ScheduleOfOtherTransactionModel>();
helper.ExecuteCheck(model.PeriodicReportNAFMII, (name, value, msg) =>
{
listRoot.Add(new SacInfo(name, value, msg));
});
if (model.PeriodicReportNAFMII.InterestRateSwapDetails != null)
{
for (int i = 0; i < model.PeriodicReportNAFMII.InterestRateSwapDetails.Count; i++)
for (var i = 0; i < model.PeriodicReportNAFMII.InterestRateSwapDetails.Count; i++)
{
var listItem = new List<SacInfo>();
var item = model.PeriodicReportNAFMII.InterestRateSwapDetails[i];
@@ -422,15 +427,17 @@ namespace YLErp.Modules.SuperviseReportModule.SAC.Service
});
if (listItem.Count > 0)
{
var temp = new SacInfo("InterestRateSwapDetails", i);
temp.SubMaps = new List<SacInfo>(listItem);
var temp = new SacInfo("InterestRateSwapDetails", i)
{
SubMaps = new List<SacInfo>(listItem)
};
listRoot.Add(temp);
}
}
}
if (model.PeriodicReportNAFMII.InterestRateOptionDetails != null)
{
for (int i = 0; i < model.PeriodicReportNAFMII.InterestRateOptionDetails.Count; i++)
for (var i = 0; i < model.PeriodicReportNAFMII.InterestRateOptionDetails.Count; i++)
{
var listItem = new List<SacInfo>();
var item = model.PeriodicReportNAFMII.InterestRateOptionDetails[i];
@@ -440,15 +447,17 @@ namespace YLErp.Modules.SuperviseReportModule.SAC.Service
});
if (listItem.Count > 0)
{
var temp = new SacInfo("InterestRateOptionDetails", i);
temp.SubMaps = new List<SacInfo>(listItem);
var temp = new SacInfo("InterestRateOptionDetails", i)
{
SubMaps = new List<SacInfo>(listItem)
};
listRoot.Add(temp);
}
}
}
if (model.PeriodicReportNAFMII.ScheduleOfOtherTransactions != null)
{
for (int i = 0; i < model.PeriodicReportNAFMII.ScheduleOfOtherTransactions.Count; i++)
for (var i = 0; i < model.PeriodicReportNAFMII.ScheduleOfOtherTransactions.Count; i++)
{
var listItem = new List<SacInfo>();
var item = model.PeriodicReportNAFMII.ScheduleOfOtherTransactions[i];
@@ -458,16 +467,20 @@ namespace YLErp.Modules.SuperviseReportModule.SAC.Service
});
if (listItem.Count > 0)
{
var temp = new SacInfo("ScheduleOfOtherTransactions", i);
temp.SubMaps = new List<SacInfo>(listItem);
var temp = new SacInfo("ScheduleOfOtherTransactions", i)
{
SubMaps = new List<SacInfo>(listItem)
};
listRoot.Add(temp);
}
}
}
if (listRoot.Count > 0)
{
var errMsg = new SacInfo("PeriodicReportNAFMII");
errMsg.SubMaps = new List<SacInfo>(listRoot);
var errMsg = new SacInfo("PeriodicReportNAFMII")
{
SubMaps = new List<SacInfo>(listRoot)
};
result.Add(errMsg);
}
}
@@ -477,7 +490,7 @@ namespace YLErp.Modules.SuperviseReportModule.SAC.Service
private string formatInfoTag(string tag, bool suffixType = false)
{
string result = $"{BusiDataType}_{tag}_";
var result = $"{BusiDataType}_{tag}_";
if (suffixType)
{
result = $"{result}{_operationType}";
@@ -485,10 +498,16 @@ namespace YLErp.Modules.SuperviseReportModule.SAC.Service
return result;
}
protected override string _changeCodeOfInfoTag(string infoTag, string newCode, out string originalCode)
{
//定期报告中不存在编号,也就不存在修改编号的情况;
throw new NotImplementedException();
}
public override bool BeforeOfGenerated(out string errMsg)
{
errMsg = "";
for (int i = 0; i < noteList.Count; i++)
for (var i = 0; i < noteList.Count; i++)
{
base.SaveReportNotes(noteList[i]);
}
@@ -15,19 +15,16 @@ namespace YLErp.Modules.SuperviseReportModule.SAC.Service
protected override ConsReport.DataFlagsEnum BusiDataType => ConsReport.DataFlagsEnum.A1014;
private List<OptFlagsEnum> _validOperationType = null;
private List<OptFlagsEnum>? _validOperationType = null;
public override List<ConsReport.OptFlagsEnum> ValidOperationType
{
get
{
if (_validOperationType == null)
{
_validOperationType = new List<OptFlagsEnum>() {
_validOperationType ??= new List<OptFlagsEnum>() {
OptFlagsEnum.A,
OptFlagsEnum.U,
OptFlagsEnum.D,
};
}
return _validOperationType;
}
}
@@ -37,7 +34,8 @@ namespace YLErp.Modules.SuperviseReportModule.SAC.Service
DateTime minDate = DateTime.MinValue;
DateTime maxDate = DateTime.MinValue;
protected override SuperviseReportTypeEnum ReportType => SuperviseReportTypeEnum.SAC_PeriodicReportQuarter;
List<SACReportNotes> noteList = new List<SACReportNotes>();
readonly List<SACReportNotes> noteList = new();
public override bool CheckRequestParamer(ReportInfo req, out string errMsg)
{
@@ -52,7 +50,7 @@ namespace YLErp.Modules.SuperviseReportModule.SAC.Service
}
SACReportNotes note = null;
quarter = GetQuarterRange(req.PeriodicReportQuarterDate.Value, out minDate, out maxDate);
fileType = (quarter == "05" ? "半年报" : "季度报告");
fileType = quarter == "05" ? "半年报" : "季度报告";
switch (req.PeriodicReportQuarterStatus)
{
case OptFlagsEnum.A:
@@ -80,7 +78,7 @@ namespace YLErp.Modules.SuperviseReportModule.SAC.Service
if (req.PeriodicReportQuarterStatus == OptFlagsEnum.U)
{
var fileIds = tempFilesService.QueryTempFile(minDate, maxDate, fileType).Select(O => O.id.ToString()).ToArray();
string[] fileIdArr = note.DataId.Split(new[] { ',' }, StringSplitOptions.RemoveEmptyEntries);
var fileIdArr = note.DataId.Split(new[] { ',' }, StringSplitOptions.RemoveEmptyEntries);
if (!fileIds.Except(fileIdArr).Any())
{
errMsg = $"{minDate.ToString("yyyy-MM-dd")}~{maxDate.ToString("yyyy-MM-dd")}已上传季度报告附件都已报送,不需要再次报送";
@@ -99,15 +97,14 @@ namespace YLErp.Modules.SuperviseReportModule.SAC.Service
{
fileList = new List<string>();
noData = true;
BodyModel model = new BodyModel();
var cacheKey = $"{BusiDataType}";
var model = new BodyModel();
var cacheValue = formatInfoTag(_reqInfo.PeriodicReportQuarterDate.Value.Year + quarter);
if (ReportStatus.CheckCacheInfo(cacheKey, cacheValue))
if (ReportStatus.CheckCacheInfo(CacheKey, cacheValue))
{
return model;
}
model.PeriodicReportQuarter = new PeriodicReportQuarterModel();
SACReportNotes note = base.GetReportNotes(ReportType, cacheValue).FirstOrDefault();
var note = base.GetReportNotes(ReportType, cacheValue).FirstOrDefault();
if (note == null)
{
note = new SACReportNotes()
@@ -154,8 +151,10 @@ namespace YLErp.Modules.SuperviseReportModule.SAC.Service
fileList.Clear();
break;
}
var info = new DerivativesQuarterlyReportAnnexModel();
info.DerivativesQuarterlyReportAnnex = item.fileName;
var info = new DerivativesQuarterlyReportAnnexModel
{
DerivativesQuarterlyReportAnnex = item.fileName
};
if (model.PeriodicReportQuarter.DerivativesQuarterlyReportAnnexTuple == null)
{
model.PeriodicReportQuarter.DerivativesQuarterlyReportAnnexTuple = new List<DerivativesQuarterlyReportAnnexModel>();
@@ -165,10 +164,10 @@ namespace YLErp.Modules.SuperviseReportModule.SAC.Service
note.DataId += item.id + ",";
}
}
noData = (!(model.PeriodicReportQuarter.DerivativesQuarterlyReportAnnexTuple?.Count > 0));
noData = !(model.PeriodicReportQuarter.DerivativesQuarterlyReportAnnexTuple?.Count > 0);
if (!noData)
{
ReportStatus.AddCacheInfo(cacheKey, cacheValue);
ReportStatus.AddCacheInfo(CacheKey, cacheValue);
note.id = 0;
note.ExceId = model.PeriodicReportQuarter.ExceID;
note.CreateTime = DateTime.Now;
@@ -189,19 +188,19 @@ namespace YLErp.Modules.SuperviseReportModule.SAC.Service
protected override List<SacInfo> CheckBodyValue(BodyModel model, out bool checkStatus)
{
List<SacInfo> result = new List<SacInfo>();
var result = new List<SacInfo>();
if (model?.PeriodicReportQuarter != null)
{
List<SacInfo> listRoot = new List<SacInfo>();
CheckHelper<PeriodicReportQuarterModel> helper = new Common.CheckHelper<PeriodicReportQuarterModel>();
CheckHelper<DerivativesQuarterlyReportAnnexModel> annexHelper = new Common.CheckHelper<DerivativesQuarterlyReportAnnexModel>();
var listRoot = new List<SacInfo>();
var helper = new Common.CheckHelper<PeriodicReportQuarterModel>();
var annexHelper = new Common.CheckHelper<DerivativesQuarterlyReportAnnexModel>();
helper.ExecuteCheck(model.PeriodicReportQuarter, (name, value, msg) =>
{
listRoot.Add(new SacInfo(name, value, msg));
});
if (model.PeriodicReportQuarter.DerivativesQuarterlyReportAnnexTuple != null)
{
for (int i = 0; i < model.PeriodicReportQuarter.DerivativesQuarterlyReportAnnexTuple.Count; i++)
for (var i = 0; i < model.PeriodicReportQuarter.DerivativesQuarterlyReportAnnexTuple.Count; i++)
{
var listItem = new List<SacInfo>();
var item = model.PeriodicReportQuarter.DerivativesQuarterlyReportAnnexTuple[i];
@@ -211,16 +210,20 @@ namespace YLErp.Modules.SuperviseReportModule.SAC.Service
});
if (listItem.Count > 0)
{
var temp = new SacInfo("DerivativesQuarterlyReportAnnexTuple", i);
temp.SubMaps = new List<SacInfo>(listItem);
var temp = new SacInfo("DerivativesQuarterlyReportAnnexTuple", i)
{
SubMaps = new List<SacInfo>(listItem)
};
listRoot.Add(temp);
}
}
}
if (listRoot.Count > 0)
{
var errMsg = new SacInfo("PeriodicReportQuarter");
errMsg.SubMaps = new List<SacInfo>(listRoot);
var errMsg = new SacInfo("PeriodicReportQuarter")
{
SubMaps = new List<SacInfo>(listRoot)
};
result.Add(errMsg);
}
}
@@ -230,7 +233,7 @@ namespace YLErp.Modules.SuperviseReportModule.SAC.Service
private string formatInfoTag(string tag, bool suffixType = false)
{
string result = $"{BusiDataType}_{tag}_";
var result = $"{BusiDataType}_{tag}_";
if (suffixType)
{
result = $"{result}{_operationType}";
@@ -238,10 +241,16 @@ namespace YLErp.Modules.SuperviseReportModule.SAC.Service
return result;
}
protected override string _changeCodeOfInfoTag(string infoTag, string newCode, out string originalCode)
{
//定期报告中不存在编号,也就不存在修改编号的情况;
throw new NotImplementedException();
}
public override bool BeforeOfGenerated(out string errMsg)
{
errMsg = "";
for (int i = 0; i < noteList.Count; i++)
for (var i = 0; i < noteList.Count; i++)
{
base.SaveReportNotes(noteList[i]);
}
File diff suppressed because it is too large Load Diff
File diff suppressed because it is too large Load Diff
@@ -19,158 +19,39 @@ namespace YLErp.Modules.SuperviseReportModule.SAC.Service
protected override DataFlagsEnum BusiDataType => DataFlagsEnum.A1003;
private List<OptFlagsEnum> _validOperationType = null;
private List<OptFlagsEnum>? _validOperationType = null;
public override List<OptFlagsEnum> ValidOperationType
{
get
{
if (_validOperationType == null)
{
_validOperationType = new List<OptFlagsEnum>() {
_validOperationType ??= new List<OptFlagsEnum>() {
OptFlagsEnum.A,
OptFlagsEnum.U,
OptFlagsEnum.D,
};
}
return _validOperationType;
}
}
protected override SuperviseReportTypeEnum ReportType => SuperviseReportTypeEnum.SAC_SupAgrmt;
List<SACReportNotes> noteList = new List<SACReportNotes>();
private List<string> _cacheCodeList = new List<string>();
readonly List<SACReportNotes> noteList = new();
private readonly List<string> _cacheCodeList = new();
protected override BodyModel GenerateBody(out bool noData, out List<string> fileList)
{
fileList = new List<string>();
BodyModel model = new BodyModel();
List<SupAgrmtModel> dataList = new List<SupAgrmtModel>();
if ((PS.Config.ErpElement.SAC_ReportDataSource & SAC_ReportDataSourceEnum.Template) == SAC_ReportDataSourceEnum.Template)
var model = new BodyModel();
var dataList = new List<SupAgrmtModel>();
if (_reqInfo.DataSource.HasFlag(SAC_ReportDataSourceEnum.Template))
{
dataList = GetSupAgrmtModel(ref fileList);
}
if ((PS.Config.ErpElement.SAC_ReportDataSource & SAC_ReportDataSourceEnum.System) == SAC_ReportDataSourceEnum.System)
{
LogFactory.GetLogger("GenerateBody").Info($"System:1");
try
{
using (var baseDb = DbContextFactory.GetClientDbContext(null))
{
var nextDate = _reqInfo.ReportDate.AddDays(1);
var fileObjList = (from c in baseDb.client
join cf in baseDb.client_file
on c.id equals cf.ClientId
where c.ProcessStatus == "已开户" && cf.HasSent == false && cf.IsValid &&
cf.FileTypeName == ConsGlobal.ClientFileType.EnhanceProtocol && cf.OptState == _operationType &&
((c.ProcessOptDate >= _reqInfo.ReportDate && c.ProcessOptDate < nextDate && cf.OptDate < nextDate) ||//如果这一天开户,则把这一天之前(含这一天)的所有文件都报送了
(cf.OptDate >= _reqInfo.ReportDate && cf.OptDate < nextDate && c.ProcessOptDate < _reqInfo.ReportDate))//如果这一天不是开户日期,则只在报送日期大于开户日期时,报送当日修改的文件
&& cf.ApprovalOrder < 1
select new
{
cf.id,
cf.OptState,
cf.ProtocolNumber,
cf.MainProtocolNumber,
cf.SignDate,
cf.FilePath,
cf.FileName,
cf.FileDesc,
}).ToArray();
var cacheKey = $"{BusiDataType}";
foreach (var item in fileObjList)
{
var info = new SupAgrmtModel();
info.MasterAgrmtNo = item.MainProtocolNumber;
info.OperationType = item.OptState;
info.SupAgrmtNo = item.ProtocolNumber;
info.SigningDate = item.SignDate?.ToString("yyyy-MM-dd");
info.SupAgrmtType = ReportTypeMap[item.OptState == OptFlagsEnum.A ? "首次" : "变更"];
info.SupAgrmtRemark = item.FileDesc;
info.SupAgrmtAttTuple = new List<SupAgrmtAttModel>();
var tuple = new SupAgrmtAttModel();
tuple.SupAgrmtAtt = item.FileName;
var cacheValue = info.MasterAgrmtNo + "_" + info.SupAgrmtNo;
if (ReportStatus.CheckCacheInfo(cacheKey, cacheValue))
{
continue;
}
info.SupAgrmtAttTuple.Add(tuple);
SACReportNotes note = base.GetReportNotes(ReportType, formatInfoTag(info)).FirstOrDefault();
if (note == null && _operationType == OptFlagsEnum.A)
{
note = new SACReportNotes()
{
InfoCache = $"{{\"Tag\":\"{info.SupAgrmtNo}\",\"Source\":\"System\"}}",
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("未知操作类型");
}
}
if (info.OperationType != OptFlagsEnum.A)
{
info.SupAgrmtID = note.BizId;
}
info.ExceID = base.formatExceID();
if (!ReportStatus.CheckFileLength(item.FilePath))
{
break;
}
else
{
ReportStatus.AddCacheInfo(cacheKey, cacheValue);
}
dataList.Add(info);
fileList.Add(item.FilePath);
note.id = 0;
note.DataId = item.id.ToString();
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.RetCode = "";
note.RetMsg = "";
note.ReportResponse = false;
note.BizId = "";
note.changeStatus = false;
noteList.Add(note);
}
}
}
catch(Exception ex)
{
LogFactory.GetLogger("GenerateBody").Info($"System:发生异常:" + ex.ToString()); ;
}
}
LogFactory.GetLogger("GenerateBody").Info($"System:2");
var subsystemDataList = loadSubsystemDataSource<SupAgrmtModel>(fileList, AddSubsystemNote);
if (subsystemDataList != null && subsystemDataList.Count > 0)
{
dataList.AddRange(subsystemDataList);
}
noData = dataList.Count == 0;
model.SupAgrmt = dataList;
@@ -179,7 +60,7 @@ namespace YLErp.Modules.SuperviseReportModule.SAC.Service
public bool AddSubsystemNote(SupAgrmtModel model, List<string> fileList, string tag)
{
SACReportNotes note = base.GetReportNotes(ReportType, formatInfoTag(model, true)).FirstOrDefault();//参数true要加,要不A和D会查到同一条记录,在D时候,就会和A相同的数据
var note = base.GetReportNotes(ReportType, formatInfoTag(model, true)).FirstOrDefault();//参数true要加,要不A和D会查到同一条记录,在D时候,就会和A相同的数据
if (note == null)
{
note = new SACReportNotes()
@@ -208,9 +89,9 @@ namespace YLErp.Modules.SuperviseReportModule.SAC.Service
}
}
if(model.SupAgrmtAttTuple != null && model.SupAgrmtAttTuple.Count > 0)
if (model.SupAgrmtAttTuple != null && model.SupAgrmtAttTuple.Count > 0)
{
fileList.AddRange(model.SupAgrmtAttTuple.Select(x => x.SupAgrmtAtt));
fileList.AddRange(model.SupAgrmtAttTuple.Select(x => x.SupAgrmtAtt)!);
}
model.ExceID = base.formatExceID();
note.id = 0;
@@ -232,13 +113,12 @@ namespace YLErp.Modules.SuperviseReportModule.SAC.Service
private List<SupAgrmtModel> GetSupAgrmtModel(ref List<string> fileList)
{
List<SupAgrmtModel> result = new List<SupAgrmtModel>();
var result = new List<SupAgrmtModel>();
if (_excelDataSource != null && _excelDataSource.Tables.Contains("补充协议"))
{
var cacheKey = $"{BusiDataType}";
string sourcePath = Path.Combine(_excelDataSourceRootPath, "附件");
DataTable dt = _excelDataSource.Tables["补充协议"];
for (int i = 1; i < dt.Rows.Count; i++)
var sourcePath = Path.Combine(_excelDataSourceRootPath, "附件");
var dt = _excelDataSource.Tables["补充协议"];
for (var i = 1; i < dt!.Rows.Count; i++)
{
if (string.IsNullOrWhiteSpace(dt.Rows[i][0]?.ToString()))
{
@@ -248,12 +128,18 @@ namespace YLErp.Modules.SuperviseReportModule.SAC.Service
var optType = OptFlagsEnum.NONE;
switch (dt.Rows[i][2]?.ToString())
{
case "0":
case "A":
case "首次":
optType = OptFlagsEnum.A;
break;
case "1":
case "U":
case "变更":
optType = OptFlagsEnum.U;
break;
case "2":
case "D":
case "废止":
optType = OptFlagsEnum.D;
break;
@@ -263,40 +149,38 @@ namespace YLErp.Modules.SuperviseReportModule.SAC.Service
continue;
}
SupAgrmtModel model = new SupAgrmtModel();
model.OperationType = optType == OptFlagsEnum.A ? OptFlagsEnum.A : OptFlagsEnum.U;
model.MasterAgrmtNo = GetDataSetValue(dt, i, 0);
model.SupAgrmtNo = GetDataSetValue(dt, i, 1);
var model = new SupAgrmtModel
{
OperationType = optType == OptFlagsEnum.A ? OptFlagsEnum.A : OptFlagsEnum.U,
MasterAgrmtNo = GetDataSetValue(dt, i, 0),
SupAgrmtNo = GetDataSetValue(dt, i, 1)
};
var cacheValue = model.MasterAgrmtNo + "_" + model.SupAgrmtNo;
if (ReportStatus.CheckCacheInfo(cacheKey, cacheValue))
if (ReportStatus.CheckCacheInfo(CacheKey, cacheValue))
{
continue;
}
model.SupAgrmtType = ConsReport.ReportTypeMap[optType == OptFlagsEnum.A ? "首次" : "变更"];
model.SigningDate = GetDataSetValue(dt, i, 3);
model.SupAgrmtRemark = GetDataSetValue(dt, i, 4);
string[] atts = ((GetDataSetValue(dt, i, 5)) ?? "").Split(',');
var atts = ((GetDataSetValue(dt, i, 5)) ?? "").Split(',');
foreach (var item in atts)
{
if (string.IsNullOrWhiteSpace(item))
{
continue;
}
string path = Path.Combine(sourcePath, item);
var path = Path.Combine(sourcePath, item);
if (!ReportStatus.CheckFileLength(path))
{
break;
}
if (model.SupAgrmtAttTuple == null)
{
model.SupAgrmtAttTuple = new List<SupAgrmtAttModel>();
}
model.SupAgrmtAttTuple ??= new List<SupAgrmtAttModel>();
model.SupAgrmtAttTuple.Add(new SupAgrmtAttModel() { SupAgrmtAtt = item });
fileList.Add(path);
}
SACReportNotes note = base.GetReportNotes(ReportType, formatInfoTag(model)).FirstOrDefault();
var note = base.GetReportNotes(ReportType, formatInfoTag(model)).FirstOrDefault();
if (note == null && _operationType == OptFlagsEnum.A)
{
note = new SACReportNotes()
@@ -332,7 +216,7 @@ namespace YLErp.Modules.SuperviseReportModule.SAC.Service
}
if (model.SupAgrmtAttTuple?.Count > 0)
{
ReportStatus.AddCacheInfo(cacheKey, cacheValue);
ReportStatus.AddCacheInfo(CacheKey, cacheValue);
model.ExceID = base.formatExceID();
result.Add(model);
note.id = 0;
@@ -357,7 +241,7 @@ namespace YLErp.Modules.SuperviseReportModule.SAC.Service
private string formatInfoTag(SupAgrmtModel model, bool suffixType = false)
{
string result = $"{BusiDataType}_{model.MasterAgrmtNo.Replace("_", "-")}_{model.SupAgrmtNo.Replace("_", "-")}_";
var result = $"{BusiDataType}_{model.MasterAgrmtNo.Replace("_", "-")}_{model.SupAgrmtNo.Replace("_", "-")}_";
if (suffixType)
{
result = $"{result}{_operationType}";
@@ -365,25 +249,41 @@ namespace YLErp.Modules.SuperviseReportModule.SAC.Service
return result;
}
protected override string _changeCodeOfInfoTag(string infoTag, string newCode, out string originalCode)
{
var arr = infoTag.Split('_');
if (arr.Length != 4)
{
throw new ServiceException($"InfoTag信息不匹配:{infoTag}");
}
originalCode = arr[2];
arr[2] = newCode.Replace("_", "-");
return string.Join("_", arr);
}
protected override List<SacInfo> CheckBodyValue(BodyModel model, out bool checkStatus)
{
List<SacInfo> result = new List<SacInfo>();
var result = new List<SacInfo>();
if (model?.SupAgrmt != null)
{
CheckHelper<SupAgrmtModel> helper = new Common.CheckHelper<SupAgrmtModel>();
CheckHelper<SupAgrmtAttModel> attHelper = new CheckHelper<SupAgrmtAttModel>();
for (int i = 0; i < model.SupAgrmt.Count; i++)
var helper = new Common.CheckHelper<SupAgrmtModel>();
var attHelper = new CheckHelper<SupAgrmtAttModel>();
for (var i = 0; i < model.SupAgrmt.Count; i++)
{
List<SacInfo> listRoot = new List<SacInfo>();
var listRoot = new List<SacInfo>();
var item = model.SupAgrmt[i];
if (item.IgnoreCheck) continue;
if (item.IgnoreCheck)
{
continue;
}
helper.ExecuteCheck(item, (name, value, msg) =>
{
listRoot.Add(new SacInfo(name, value, msg));
});
if (item.SupAgrmtAttTuple != null)
{
for (int j = 0; j < item.SupAgrmtAttTuple.Count; j++)
for (var j = 0; j < item.SupAgrmtAttTuple.Count; j++)
{
var listItem = new List<SacInfo>();
var tuple = item.SupAgrmtAttTuple[j];
@@ -393,16 +293,21 @@ namespace YLErp.Modules.SuperviseReportModule.SAC.Service
});
if (listItem.Count > 0)
{
var temp = new SacInfo("SupAgrmtAttTuple", j);
temp.SubMaps = new List<SacInfo>(listItem);
var temp = new SacInfo("SupAgrmtAttTuple", j)
{
SubMaps = new List<SacInfo>(listItem)
};
listRoot.Add(temp);
}
}
}
if (listRoot.Count > 0)
{
var errMsg = new SacInfo("SupAgrmt", i);
errMsg.SubMaps = new List<SacInfo>(listRoot);
var errMsg = new SacInfo("SupAgrmt", i)
{
FieldValue = item.MasterAgrmtNo,
SubMaps = new List<SacInfo>(listRoot)
};
result.Add(errMsg);
}
}
@@ -428,7 +333,7 @@ namespace YLErp.Modules.SuperviseReportModule.SAC.Service
};
}
for (int i = 0; i < noteList.Count; i++)
for (var i = 0; i < noteList.Count; i++)
{
base.SaveReportNotes(noteList[i]);
}
@@ -1,8 +1,9 @@
using System.Data;
using System.Data;
using YieldChain.Helpers;
using YLErp.BLL;
using YLErp.DBModels.Consts;
using YLErp.DBModels.Enums;
using YLErp.Helpers;
using YLErp.Modules.SuperviseReportModule.SAC.Common;
using YLErp.Modules.SuperviseReportModule.SAC.Model;
using static YLErp.DBModels.Consts.ConsReport;
@@ -21,258 +22,51 @@ namespace YLErp.Modules.SuperviseReportModule.SAC.Service
protected override DataFlagsEnum BusiDataType => DataFlagsEnum.A1017;
private List<OptFlagsEnum> _validOperationType = null;
private List<OptFlagsEnum>? _validOperationType = null;
public override List<OptFlagsEnum> ValidOperationType
{
get
{
if (_validOperationType == null)
{
_validOperationType = new List<OptFlagsEnum>() {
_validOperationType ??= new List<OptFlagsEnum>() {
OptFlagsEnum.A,
OptFlagsEnum.U,
OptFlagsEnum.D,
};
}
return _validOperationType;
}
}
protected override SuperviseReportTypeEnum ReportType => SuperviseReportTypeEnum.SAC_ConfirmationAtt;
List<SACReportNotes> noteList = new List<SACReportNotes>();
readonly List<SACReportNotes> noteList = new();
IEnumerable<SACReportNotes> SACReportNotesCache = null;
IEnumerable<SACReportNotes> SACReportNotesCache_confirmation = null;
protected override BodyModel GenerateBody(out bool noData, out List<string> fileList)
{
fileList = new List<string>();
BodyModel model = new BodyModel();
var cacheKey = $"{BusiDataType}";
List<SwapConfirmationAttModel> dataList = new List<SwapConfirmationAttModel>();
if ((PS.Config.ErpElement.SAC_ReportDataSource & SAC_ReportDataSourceEnum.Template) == SAC_ReportDataSourceEnum.Template)
var model = new BodyModel();
SACReportNotesCache = base.InitReportNotes(ReportType);
SACReportNotesCache_confirmation = base.InitReportNotes(SuperviseReportTypeEnum.SAC_SwapConfirmation);
var dataList = new List<ConfirmationAttModel>();
if (_reqInfo.DataSource.HasFlag(SAC_ReportDataSourceEnum.Template))
{
dataList = GetSwapConfirmationAttModel(out fileList);
dataList = GetSwapConfirmationAttModel(ref fileList);
}
if ((PS.Config.ErpElement.SAC_ReportDataSource & SAC_ReportDataSourceEnum.System) == SAC_ReportDataSourceEnum.System)
{
var nextDate = _reqInfo.ReportDate.AddDays(1);
var nextDataDate = _reqInfo.DataDate.AddDays(1);
using (var db = new YLContext())
{
var codeList = ReportStatus.GetCacheInfo(cacheKey);
var query = (from t in db.trade
join tc in db.trade_cash
on t.id equals tc.TradeId
join tr in db.trade_contract_r
on tc.id equals tr.TradeCashId
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
((_operationType == OptFlagsEnum.A && t.TradeDate >= _reqInfo.DataDate && t.TradeDate < nextDataDate)//新增时使用交易日期判断
|| (_operationType != OptFlagsEnum.A && tc.OptDate >= _reqInfo.ReportDate && tc.OptDate < nextDate)//补正和废止时使用操作日期判断
|| tr.OptDate >= _reqInfo.DataDate)
&& (_operationType == OptFlagsEnum.D || (t.ValidState != "InValid" && tc.ValidState != "InValid" && !tc.IsDeleted && tr.IsValid))
&& /*t.UnderlyingInstrumentType == "Stock" &&*/ t.TradeType == "收益互换"
&& tc.Action == "系统操作-期权费"
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,
ts.IsGetFloatingProfit,
ts.IsPayFloatingProfit,
ts.GetVarietyId,
ts.PayVarietyId,
ts.GetUnderlyingCode,
ts.PayUnderlyingCode,
ts.GetLongShort,
ts.PayLongShort,
ts.GetSpotPrice,
ts.PaySpotPrice,
ts.GetTradePrice,
ts.PayTradePrice,
ts.GetSwapTimeAndRate,
ts.PaySwapTimeAndRate,
ts.GetFixedProfit,
ts.PayFixedProfit,
ts.GetMarginRate,
ts.PayMarginRate,
ts.GetTradeAmount,
ts.PayTradeAmount,
tr.ContractCode,
td.Paths,
td.StampDocumentFileName,
t.QuoteCurrency,
t.SettlementCurrency,
ts.GetUnAnnualRate,
ts.GetSingleFee,
ts.PayUnAnnualRate,
ts.PaySingleFee,
}).OrderBy(O => O.OptDate).ToArray().Where(O => !codeList.Contains(O.id + "")).ToArray();
List<int> ids = query.Select(O => O.id).ToList();
List<int> delIds = new List<int>();
if (_operationType == OptFlagsEnum.D)
{
delIds = DbContext.TradeAuditLog.Where(O => ids.Contains(O.TradeId) && O.OptDate >= _reqInfo.ReportDate && O.OptDate < nextDate && O.OptType == "删除交易").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));
Dictionary<string, string> reportDescDic = DbContext.AppConfig.Where(O => O.PGroup == ConsAppConfig.ReportDescSwap).ToDictionary(K => K.PName, V => V.PValue);
foreach (var item in query)
{
var cacheValue = item.id.ToString();
if (ReportStatus.CheckCacheInfo(cacheKey, cacheValue))
{
continue;
}
//如果存在重复数据,则始终用较新的数据
SwapConfirmationAttModel info = new SwapConfirmationAttModel();
info.ConfirmationNo = item.ContractCode;
var confirmationNote = base.GetReportNotes(SuperviseReportTypeEnum.SAC_SwapConfirmation, $"_{info.ConfirmationNo.Replace("_", "-")}_").FirstOrDefault();
var currentCodes = ReportStatus.GetCacheInfo(DataFlagsEnum.A1005.ToString());//取出这一次报送交易要素的交易编号
if (!currentCodes.Contains(item.id.ToString()) && (confirmationNote == null || !confirmationNote.ReportResponse))
{
continue;//跳过交易要素还没报送的确认书附件;
}
SACReportNotes note = base.GetReportNotes(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:
if (!delIds.Contains(item.id))
{
continue;//交易没有被删除,跳过
}
info.OperationType = OptFlagsEnum.D;
note.IsValid = false;
break;
case OptFlagsEnum.NONE:
default:
throw new ServiceException("未知操作类型");
}
}
Dictionary<string, string> reportCacheDic = JsonHelper.ToObject<Dictionary<string, string>>(note.InfoCache) ?? new Dictionary<string, string>();
if (info.OperationType != _operationType)
{
continue;
}
if (info.OperationType != OptFlagsEnum.D && (!item.tradeValid || !item.tradecashValid || !item.tradeContractRValid))
{//非废止报送中,应跳过所有存在无效数据的数据
continue;
}
if (metaDic.ContainsKey(item.id))
{
var metaInfo = metaDic[item.id];
var tradingPlace = metaInfo.ContainsKey(ConsTradeMetaKey.TradingPlace) ? TradingPlaceMap[metaInfo[ConsTradeMetaKey.TradingPlace]] : "";
if (tradingPlace == "1")//跳过交易场所为报价系统的交易;
{
continue;
}
}
if (info.OperationType != OptFlagsEnum.A)
{
info.BizID = note.BizId;//确认书编号;
}
string path = item.StampDocumentFileName ?? item.Paths;
if (!path.StartsWith("\\") || path.StartsWith("/"))
{
path = "\\" + path;
}
var absolutePath = OtcAppContext.MapPath(path);
absolutePath = Path.ChangeExtension(absolutePath, "pdf");
info.ConfirmationFilesTuple = new List<ConfirmationFilesTupleModel>() { new ConfirmationFilesTupleModel() { ConfirmationFiles = Path.GetFileName(absolutePath) } };
info.ExceID = base.formatExceID();
if (!ReportStatus.CheckFileLength(absolutePath))
{
break;
}
fileList.Add(absolutePath);
ReportStatus.AddCacheInfo(cacheKey, cacheValue);
dataList.Add(info);
note.id = 0;
note.InfoCache = $"{{\"DueDate\":\"{item.OptDate?.ToString("yyyy-MM-dd")}\",\"Tag\":\"{info.ConfirmationNo}\",\"Source\":\"System\"}}";
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.RetCode = "";
note.RetMsg = "";
note.ReportResponse = false;
note.DataId = item.tcId.ToString();
note.BizId = "";
note.changeStatus = false;
noteList.Add(note);
}
}
}
if ((PS.Config.ErpElement.SAC_ReportDataSource & SAC_ReportDataSourceEnum.KingstarView) == SAC_ReportDataSourceEnum.KingstarView)
{
dataList.AddRange(GetSwapConfirmationAttModelFromView(out fileList));
}
var subsystemDataList = loadSubsystemDataSource<SwapConfirmationAttModel>(fileList, AddSubsystemNote);
var subsystemDataList = loadSubsystemDataSource<ConfirmationAttModel>(fileList, AddSubsystemNote);
if (subsystemDataList != null && subsystemDataList.Count > 0)
{
dataList.AddRange(subsystemDataList);
}
noData = dataList.Count == 0;
model.ConfirmationAtt = dataList;
return model;
}
public bool AddSubsystemNote(SwapConfirmationAttModel model, List<string> fileList, string tag)
public bool AddSubsystemNote(ConfirmationAttModel model, List<string> fileList, string tag)
{
SACReportNotes note = base.GetReportNotes(ReportType, formatInfoTag(model, true)).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()
@@ -305,7 +99,7 @@ namespace YLErp.Modules.SuperviseReportModule.SAC.Service
{
fileList.AddRange(model.ConfirmationFilesTuple.Select(x => x.ConfirmationFiles));
}
model.ExceID = base.formatExceID();
model.ExceID = base.formatExceID(SACReportNotesCache);
note.id = 0;
note.ExceId = model.ExceID;
note.CreateTime = DateTime.Now;
@@ -323,16 +117,14 @@ namespace YLErp.Modules.SuperviseReportModule.SAC.Service
return true;
}
private List<SwapConfirmationAttModel> GetSwapConfirmationAttModel(out List<string> fileList)
private List<ConfirmationAttModel> GetSwapConfirmationAttModel(ref List<string> fileList)
{
fileList = new List<string>();
List<SwapConfirmationAttModel> result = new List<SwapConfirmationAttModel>();
var result = new List<ConfirmationAttModel>();
if (_excelDataSource != null && _excelDataSource.Tables.Contains("收益互换确认书附件明细"))
{
var cacheKey = $"{BusiDataType}";
DataTable dt = _excelDataSource.Tables["收益互换确认书附件明细"];
string sourcePath = Path.Combine(_excelDataSourceRootPath, "附件");
for (int i = 1; i < dt.Rows.Count; i++)
var dt = _excelDataSource.Tables["收益互换确认书附件明细"];
var sourcePath = Path.Combine(_excelDataSourceRootPath, "附件");
for (var i = 1; i < dt.Rows.Count; i++)
{
if (string.IsNullOrWhiteSpace(dt.Rows[i][0]?.ToString()))
{
@@ -342,12 +134,18 @@ namespace YLErp.Modules.SuperviseReportModule.SAC.Service
var optType = OptFlagsEnum.NONE;
switch (dt.Rows[i][1]?.ToString())
{
case "0":
case "A":
case "首次":
optType = OptFlagsEnum.A;
break;
case "1":
case "U":
case "变更":
optType = OptFlagsEnum.U;
break;
case "2":
case "D":
case "废止":
optType = OptFlagsEnum.D;
break;
@@ -357,12 +155,17 @@ namespace YLErp.Modules.SuperviseReportModule.SAC.Service
continue;
}
SwapConfirmationAttModel model = new SwapConfirmationAttModel();
model.ConfirmationNo = GetDataSetValue(dt, i, 0);
model.OperationType = optType;
var cacheValue = model.ConfirmationNo;
if (ReportStatus.CheckCacheInfo(cacheKey, cacheValue))
var model = new ConfirmationAttModel
{
ConfirmationNo = GetDataSetValue(dt, i, 0),
OperationType = optType
};
var cacheValue = (model.ConfirmationNo ?? "").ToString();
if (cacheValue.IsNullOrWhiteSpace())
{
continue;
}
if (ReportStatus.CheckCacheInfo(CacheKey, cacheValue))
{
continue;
}
@@ -378,10 +181,10 @@ namespace YLErp.Modules.SuperviseReportModule.SAC.Service
break;
}
fileList.Add(path);
model.ConfirmationFilesTuple.Add(new ConfirmationFilesTupleModel() { ConfirmationFiles = f });
model.ConfirmationFilesTuple.Add(new ConfirmationFilesTupleModel() { IsSwap = "true", ConfirmationFiles = f });
}
}
List<SACReportNotes> notes = base.GetReportNotes(ReportType, formatInfoTag(model));
List<SACReportNotes> notes = base.GetReportNotes(ReportType, formatInfoTag(model), dataSource: SACReportNotesCache);
var note = notes.LastOrDefault(O => O.InfoCache.Contains(cacheValue));
if (note == null && _operationType == OptFlagsEnum.A)
{
@@ -417,9 +220,9 @@ namespace YLErp.Modules.SuperviseReportModule.SAC.Service
{
model.BizID = note.BizId;
}
model.ExceID = base.formatExceID();
model.ExceID = base.formatExceID(SACReportNotesCache);
result.Add(model);
ReportStatus.AddCacheInfo(cacheKey, cacheValue);
ReportStatus.AddCacheInfo(CacheKey, cacheValue);
note.id = 0;
note.ExceId = model.ExceID;
note.CreateTime = DateTime.Now;
@@ -440,126 +243,9 @@ namespace YLErp.Modules.SuperviseReportModule.SAC.Service
return result;
}
private List<SwapConfirmationAttModel> GetSwapConfirmationAttModelFromView(out List<string> fileList)
private string formatInfoTag(ConfirmationAttModel model, bool suffixType = false)
{
fileList = new List<string>();
List<SwapConfirmationAttModel> result = new List<SwapConfirmationAttModel>();
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;
}
SwapConfirmationAttModel model = new SwapConfirmationAttModel();
model.IgnoreCheck = true;
model.ConfirmationNo = GetDataSetValue(dt, i, "CONFIRMATIONNO");
model.OperationType = optType;
var cacheValue = model.ConfirmationNo;
if (ReportStatus.CheckCacheInfo(cacheKey, cacheValue))
{
continue;
}
model.ConfirmationFilesTuple = new List<ConfirmationFilesTupleModel>();
;
var files = GetDataSetValue(dt, i, "CONFIRMATIONFILES").Split(',');
foreach (var f in files)
{
if (!string.IsNullOrWhiteSpace(f))
{
var downloadRet = ftpHelper.DownloadFile(CreateViewAttDownloadPath(f), ViewLocalAttFileDir + @"\kingstar\", out string message);
LogFactory.GetLogger("ftpHelper.DownloadFile").Info($"下载结果:{ViewLocalAttFileDir},{f},{downloadRet}");
var path = downloadRet;
if (!ReportStatus.CheckFileLength(path))
{
break;
}
fileList.Add(path);
model.ConfirmationFilesTuple.Add(new ConfirmationFilesTupleModel() { ConfirmationFiles = Path.GetFileName(path) });
}
}
List<SACReportNotes> notes = base.GetReportNotes(ReportType, formatInfoTag(model));
var note = notes.LastOrDefault(O => O.InfoCache.Contains(cacheValue));
if (note == null && _operationType == OptFlagsEnum.A)
{
note = new SACReportNotes()
{
InfoCache = $"{{\"Tag\":\"{model.ConfirmationNo}\",\"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("未知操作类型");
}
}
if (_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);
note.OptTime = note.CreateTime;
note.RetCode = "";
note.RetMsg = "";
note.ReportResponse = false;
note.BizId = "";
note.DataId = "";
note.changeStatus = false;
noteList.Add(note);
}
}
return result;
}
private string formatInfoTag(SwapConfirmationAttModel model, bool suffixType = false)
{
string result = $"{BusiDataType}_{model.ConfirmationNo.Replace("_", "-")}_成交_确认书_";
var result = $"{BusiDataType}_{model.ConfirmationNo.Replace("_", "-")}_成交_确认书_";
if (suffixType)
{
result = $"{result}{_operationType}";
@@ -567,25 +253,56 @@ namespace YLErp.Modules.SuperviseReportModule.SAC.Service
return result;
}
protected override string _changeCodeOfInfoTag(string infoTag, string newCode, out string originalCode)
{
var arr = infoTag.Split('_');
if (arr.Length != 5)
{
throw new ServiceException($"InfoTag信息不匹配:{infoTag}");
}
originalCode = arr[1];
arr[1] = newCode.Replace("_", "-");
return string.Join("_", arr);
}
protected override List<SacInfo> CheckBodyValue(BodyModel model, out bool checkStatus)
{
List<SacInfo> result = new List<SacInfo>();
var result = new List<SacInfo>();
if (model?.ConfirmationAtt != null)
{
CheckHelper<SwapConfirmationAttModel> helper = new CheckHelper<SwapConfirmationAttModel>();
for (int i = 0; i < model.ConfirmationAtt.Count; i++)
var helper = new CheckHelper<ConfirmationAttModel>();
var attHelper = new CheckHelper<ConfirmationFilesTupleModel>();
for (var i = 0; i < model.ConfirmationAtt.Count; i++)
{
List<SacInfo> listRoot = new List<SacInfo>();
var listRoot = new List<SacInfo>();
var item = model.ConfirmationAtt[i];
if (item.IgnoreCheck) continue;
if (item.IgnoreCheck)
{
continue;
}
helper.ExecuteCheck(item, (name, value, msg) =>
{
listRoot.Add(new SacInfo(name, value, msg));
});
if (item.ConfirmationFilesTuple != null)
{
for (int j = 0; j < item.ConfirmationFilesTuple.Count; j++)
{
var att = item.ConfirmationFilesTuple[j];
attHelper.ExecuteCheck(att, (name, value, msg) =>
{
listRoot.Add(new SacInfo(name, value, msg));
});
}
}
if (listRoot.Count > 0)
{
var errMsg = new SacInfo("SwapConfirmationAtt", i);
errMsg.SubMaps = new List<SacInfo>(listRoot);
var errMsg = new SacInfo("SwapConfirmationAtt", i)
{
FieldValue = item.ConfirmationNo,
SubMaps = new List<SacInfo>(listRoot)
};
result.Add(errMsg);
}
}
@@ -609,7 +326,7 @@ namespace YLErp.Modules.SuperviseReportModule.SAC.Service
};
}
for (int i = 0; i < noteList.Count; i++)
for (var i = 0; i < noteList.Count; i++)
{
base.SaveReportNotes(noteList[i]);
}
File diff suppressed because it is too large Load Diff
@@ -1,6 +1,9 @@
using Qdp.Foundation.Implementations;
using MoreLinq;
using Qdp.Foundation.Implementations;
using System.Collections.ObjectModel;
using System.Data;
using YLErp.BLL;
using YLErp.Commons;
using YLErp.DBModels.Consts;
using YLErp.DBModels.Enums;
using YLErp.Modules.SuperviseReportModule.SAC.Common;
@@ -22,339 +25,40 @@ namespace YLErp.Modules.SuperviseReportModule.SAC.Service
protected override DataFlagsEnum BusiDataType => DataFlagsEnum.A1016;
private List<OptFlagsEnum> _validOperationType = null;
private List<OptFlagsEnum>? _validOperationType = null;
public override List<OptFlagsEnum> ValidOperationType
{
get
{
if (_validOperationType == null)
{
_validOperationType = new List<OptFlagsEnum>() {
_validOperationType ??= new List<OptFlagsEnum>() {
OptFlagsEnum.A,
OptFlagsEnum.U,
};
}
return _validOperationType;
}
}
protected override SuperviseReportTypeEnum ReportType => SuperviseReportTypeEnum.SAC_SwapEquityPayment;
List<SACReportNotes> noteList = new List<SACReportNotes>();
readonly List<SACReportNotes> noteList = new();
IEnumerable<SACReportNotes> SACReportNotesCache = null;
protected override BodyModel GenerateBody(out bool noData, out List<string> fileList)
{
fileList = new List<string>();
BodyModel model = new BodyModel();
var cacheKey = $"{BusiDataType}";
List<SwapEquityPaymentModel> dataList = new List<SwapEquityPaymentModel>();
var model = new BodyModel();
SACReportNotesCache = base.InitReportNotes(ReportType);
var dataList = new List<SwapEquityPaymentModel>();
if ((PS.Config.ErpElement.SAC_ReportDataSource & SAC_ReportDataSourceEnum.Template) == SAC_ReportDataSourceEnum.Template)
if (_reqInfo.DataSource.HasFlag(SAC_ReportDataSourceEnum.Template))
{
dataList = GetSwapEquityPaymentModel();
}
if ((PS.Config.ErpElement.SAC_ReportDataSource & SAC_ReportDataSourceEnum.System) == SAC_ReportDataSourceEnum.System)
{
var nextDate = _reqInfo.ReportDate.AddDays(1);
var nextDataDate = _reqInfo.DataDate.AddDays(1);
using (var db = new YLContext())
{
var actions = new List<string>() { "系统操作-平仓费", "系统操作-行权费", "系统操作-期权费" };
var codeList = ReportStatus.GetCacheInfo(cacheKey);
var query = (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 tc.TradeId 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
((_operationType == OptFlagsEnum.A && tc.ValueDate >= _reqInfo.DataDate && t.TradeDate < nextDataDate)//新增时使用交易日期判断
|| (_operationType != OptFlagsEnum.A && tc.OptDate >= _reqInfo.ReportDate && tc.OptDate < nextDate))//补正和废止时使用操作日期判断
&& (_operationType == OptFlagsEnum.D || (t.ValidState != "InValid" && tc.ValidState != "InValid" && !tc.IsDeleted && tr.IsValid))
&& /*t.UnderlyingInstrumentType == "Stock" &&*/ t.TradeType == "收益互换"
&& actions.Contains(tc.Action)
select new
{
ValueDate = tc.HappenedDate ?? tc.ValueDate,
isSettle = tc.Action != "系统操作-期权费",
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,
ts.IsGetFloatingProfit,
ts.IsPayFloatingProfit,
ts.GetVarietyId,
ts.PayVarietyId,
ts.GetUnderlyingCode,
ts.PayUnderlyingCode,
ts.GetLongShort,
ts.PayLongShort,
ts.GetSpotPrice,
ts.PaySpotPrice,
ts.GetTradePrice,
ts.PayTradePrice,
ts.GetSwapTimeAndRate,
ts.PaySwapTimeAndRate,
ts.GetFixedProfit,
ts.PayFixedProfit,
ts.GetMarginRate,
ts.PayMarginRate,
ts.GetTradeAmount,
ts.PayTradeAmount,
tr.ContractCode,
td.Paths,
t.QuoteCurrency,
t.SettlementCurrency,
ts.GetUnAnnualRate,
ts.GetSingleFee,
ts.PayUnAnnualRate,
ts.PaySingleFee,
ts.SwapType,
tc.Notional,
tc.UnwindNotional,
tc.FinalPrice,
}).OrderBy(O => O.OptDate).ToArray().Where(O => !codeList.Contains(O.id + "")).ToArray();
List<int> ids = query.Select(O => O.id).ToList();
List<int> delIds = new List<int>();
if (_operationType == OptFlagsEnum.D)
{
delIds = DbContext.TradeAuditLog.Where(O => ids.Contains(O.TradeId) && O.OptDate >= _reqInfo.ReportDate && O.OptDate < nextDate && O.OptType == "删除交易").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));
Dictionary<string, string> reportDescDic = DbContext.AppConfig.Where(O => O.PGroup == ConsAppConfig.ReportDescSwap).ToDictionary(K => K.PName, V => V.PValue);
foreach (var item in query)
{
var cacheValue = item.id.ToString() + item.isSettle;
if (ReportStatus.CheckCacheInfo(cacheKey, cacheValue))
{
continue;
}
//如果存在重复数据,则始终用较新的数据
SwapEquityPaymentModel info = new SwapEquityPaymentModel();
info.ConfirmationNo = item.ContractCode;
var currentDealCodes = ReportStatus.GetCacheInfo(DataFlagsEnum.A1005.ToString());//取出这一次报送交易要素的交易编号
var currentSettleCodes = ReportStatus.GetCacheInfo(DataFlagsEnum.A1006.ToString()).Select(O => O.Split('_')[0]);//取出这一次报送交易要素的交易编号
if ((!item.isSettle && !currentDealCodes.Contains(item.id.ToString())) || (item.isSettle && !currentSettleCodes.Contains(item.id.ToString())))
{
continue;//跳过交易要素还没报送的确认书附件;
}
if (item.isSettle)
{
var tempDate = item.ValueDate;
var count = db.trade_cash.Where(O => O.TradeId == item.id && O.ValueDate < tempDate && (O.Action == "系统操作-行权费" || O.Action == "系统操作-平仓费")).Select(O => O.ValueDate).ToHashSet().Count;
count += db.ExtensionTime.Where(O => O.TradeId == item.id && O.OptDate < tempDate).Select(O => O.OptDate).ToArray().Select(O => O.GetValueOrDefault().Date).ToHashSet().Count;
info.DurationEventNO = count.ToString("0000");
}
List<SACReportNotes> notes = base.GetReportNotes(formatInfoTag(info));
SACReportNotes note = notes.FirstOrDefault(O => O.InfoCache.Contains(item.ValueDate.ToString("yyyy-MM-dd")) && O.InfoCache.Contains(item.isSettle.ToString()));
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:
if (!delIds.Contains(item.id))
{
continue;//交易没有被删除,跳过
}
info.OperationType = OptFlagsEnum.D;
note.IsValid = false;
break;
case OptFlagsEnum.NONE:
default:
throw new ServiceException("未知操作类型");
}
}
if (info.OperationType != _operationType)
{
continue;
}
if (info.OperationType != OptFlagsEnum.D && (!item.tradeValid || !item.tradecashValid || !item.tradeContractRValid))
{//非废止报送中,应跳过所有存在无效数据的数据
continue;
}
if (metaDic.ContainsKey(item.id))
{
var metaInfo = metaDic[item.id];
var tradingPlace = metaInfo.ContainsKey(ConsTradeMetaKey.TradingPlace) ? TradingPlaceMap[metaInfo[ConsTradeMetaKey.TradingPlace]] : "";
if (tradingPlace == "1")//跳过交易场所为报价系统的交易;
{
continue;
}
}
if (info.OperationType != OptFlagsEnum.A)
{
info.BizID = note.BizId;//确认书编号;
}
var swapEquityPayment = new SwapEquityPaymentTupleModel();
var longShort = item.IsPayFloatingProfit ? item.PayLongShort : item.GetLongShort;
if (item.SwapType == "普通")
{
swapEquityPayment.PaymentMethod = ConsReport.PaymentMethodMap["权益收益(" + longShort + ")"];
}
else
{
swapEquityPayment.PaymentMethod = ConsReport.SwapTypeMap["权益收益" + item.SwapType];
}
swapEquityPayment.Payer = item.IsPayFloatingProfit ? ConsReport.PayerMap["甲方"] : ConsReport.PayerMap["乙方"];
var customizedResultsGet = QdpHelper.ParseAutocallCustomizedInfo(item.GetSwapTimeAndRate);
var getSwapRates = customizedResultsGet.Item2.Distinct();
var customizedResultsPay = QdpHelper.ParseAutocallCustomizedInfo(item.PaySwapTimeAndRate);
var paySwapRates = customizedResultsPay.Item2.Distinct();
if (item.IsGetFloatingProfit)
{
var getSwapDates = customizedResultsGet.Item1.Distinct();
if (getSwapDates.Count() == 1)
{
Date date = getSwapDates.First();
swapEquityPayment.PaymentFreq = date == new Date(item.TradeDate.Value) ? PaymentFreqMap["期初支付"] : PaymentFreqMap["期末支付"];
}
else
{
swapEquityPayment.PaymentFreq = PaymentFreqMap["期间多次支付"];
}
swapEquityPayment.InterestRate = (getSwapRates.FirstOrDefault() * 100).ToString();
}
else
{
var paySwapDates = customizedResultsPay.Item1.Distinct();
if (paySwapDates.Count() == 1)
{
Date date = paySwapDates.First();
swapEquityPayment.PaymentFreq = date == new Date(item.TradeDate.Value) ? PaymentFreqMap["期初支付"] : PaymentFreqMap["期末支付"];
}
else
{
swapEquityPayment.PaymentFreq = PaymentFreqMap["期间多次支付"];
}
swapEquityPayment.InterestRate = (paySwapRates.FirstOrDefault() * 100).ToString();
}
swapEquityPayment.OpenandClosingDate = item.ValueDate.ToString("yyyy-MM-dd");
var codeInfo = DataCacheProvider.GetUnderlyingDataSource().GetData(item.UnderlyingCode);
swapEquityPayment.UndrlygAssetTradgPlc = string.IsNullOrWhiteSpace(codeInfo.MarketName) ? "其他" : codeInfo.MarketName;
if (SwapUndrlygAssetDtldTypeMap.TryGetValue(ConsGlobal.InstrumentType.GetDesc(codeInfo.UnderlyingInstrumentType), out var AssetDtldType))
{
swapEquityPayment.UndrlygAssetDtldType = AssetDtldType;
}
else
{
swapEquityPayment.UndrlygAssetDtldType = UndrlygAssetDtldTypeMap["其他标的"];
}
var rate = new EodModule.EodCurrencyRateService(UserInfo).GetCurrencyRate(item.QuoteCurrency, "CNY", item.ValueDate);
var notional = item.isSettle ? (item.UnwindNotional ?? 0) : item.Notional;
var price = (item.isSettle ? item.FinalPrice : item.SpotPrice) ?? 0;
swapEquityPayment.UndrlygAssetCode = codeInfo.UnderlyingCode;
swapEquityPayment.UndrlygAssetName = codeInfo.UnderlyingName;
swapEquityPayment.UndrlygAssetAmt = (notional / codeInfo.CountRatio / codeInfo.ContractSize).ToString("0.000000");
swapEquityPayment.ContractMultiplier = codeInfo.ContractSize.ToString("0");
swapEquityPayment.UndrlygAssetPrice = (price * rate).ToString("0.0000");
var notionalAmt = (price * notional / codeInfo.CountRatio * rate);
if (item.isSettle)
{
var list = ReportStatus.GetCacheInfo($"{DataFlagsEnum.A1006.ToString()}_{info.ConfirmationNo}_{info.DurationEventNO}");
if (list.Count > 0 && double.TryParse(list[0], out var temp))
{
notionalAmt = temp;
}
}
else
{
var list = ReportStatus.GetCacheInfo($"{DataFlagsEnum.A1005.ToString()}_{info.ConfirmationNo}");
if (list.Count > 0 && double.TryParse(list[0], out var temp))
{
notionalAmt = temp;
}
}
if (longShort == "多头")
{
swapEquityPayment.UndrlygAssetPosition = UndrlygAssetPositionMap[item.isSettle ? "平多仓" : "开多仓"];
swapEquityPayment.LNotinalPrincipleAmt = notionalAmt.ToString("0.0000");
}
else
{
swapEquityPayment.UndrlygAssetPosition = UndrlygAssetPositionMap[item.isSettle ? "平空仓" : "开空仓"];
swapEquityPayment.SNotinalPrincipleAmt = (-notionalAmt).ToString("0.0000");
}
info.SwapEquityPaymentTuple = new List<SwapEquityPaymentTupleModel>();
info.SwapEquityPaymentTuple.Add(swapEquityPayment);
info.ExceID = base.formatExceID();
ReportStatus.AddCacheInfo(cacheKey, cacheValue);
dataList.Add(info);
note.id = 0;
note.InfoCache = $"{{\"DueDate\":\"{swapEquityPayment.OpenandClosingDate}\",\"OptType\":\"{(item.isSettle)}\",\"Tag\":\"{info.ConfirmationNo}\",\"DurationEventNO\":\"{info.DurationEventNO}\",\"Source\":\"System\"}}";
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.RetCode = "";
note.RetMsg = "";
note.ReportResponse = false;
note.DataId = item.tcId.ToString();
note.BizId = "";
note.changeStatus = false;
noteList.Add(note);
}
}
}
if ((PS.Config.ErpElement.SAC_ReportDataSource & SAC_ReportDataSourceEnum.KingstarView) == SAC_ReportDataSourceEnum.KingstarView)
{
dataList.AddRange(GetSwapEquityPaymentModelFromView());
}
var subsystemDataList = loadSubsystemDataSource<SwapEquityPaymentModel>(fileList, AddSubsystemNote);
if (subsystemDataList != null && subsystemDataList.Count > 0)
{
dataList.AddRange(subsystemDataList);
}
noData = dataList.Count == 0;
model.SwapEquityPayment = dataList;
@@ -363,7 +67,7 @@ namespace YLErp.Modules.SuperviseReportModule.SAC.Service
public bool AddSubsystemNote(SwapEquityPaymentModel model, List<string> fileList, string tag)
{
SACReportNotes note = base.GetReportNotes(ReportType, formatInfoTag(model, true)).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()
@@ -392,7 +96,7 @@ namespace YLErp.Modules.SuperviseReportModule.SAC.Service
}
}
model.ExceID = base.formatExceID();
model.ExceID = base.formatExceID(SACReportNotesCache);
note.id = 0;
note.ExceId = model.ExceID;
note.CreateTime = DateTime.Now;
@@ -412,12 +116,11 @@ namespace YLErp.Modules.SuperviseReportModule.SAC.Service
private List<SwapEquityPaymentModel> GetSwapEquityPaymentModel()
{
List<SwapEquityPaymentModel> result = new List<SwapEquityPaymentModel>();
var result = new List<SwapEquityPaymentModel>();
if (_excelDataSource != null && _excelDataSource.Tables.Contains("收益互换交易权益端支付"))
{
var cacheKey = $"{BusiDataType}";
DataTable dt = _excelDataSource.Tables["收益互换交易权益端支付"];
for (int i = 1; i < dt.Rows.Count; i++)
var dt = _excelDataSource.Tables["收益互换交易权益端支付"];
for (var i = 1; i < dt.Rows.Count; i++)
{
if (string.IsNullOrWhiteSpace(dt.Rows[i][0]?.ToString()))
{
@@ -427,12 +130,18 @@ namespace YLErp.Modules.SuperviseReportModule.SAC.Service
var optType = OptFlagsEnum.NONE;
switch (dt.Rows[i][1]?.ToString())
{
case "0":
case "A":
case "首次":
optType = OptFlagsEnum.A;
break;
case "1":
case "U":
case "变更":
optType = OptFlagsEnum.U;
break;
case "2":
case "D":
case "废止":
optType = OptFlagsEnum.D;
break;
@@ -442,11 +151,12 @@ namespace YLErp.Modules.SuperviseReportModule.SAC.Service
continue;
}
SwapEquityPaymentModel model = new SwapEquityPaymentModel();
model.ConfirmationNo = GetDataSetValue(dt, i, 0);
model.OperationType = optType;
model.DurationEventNO = GetDataSetValue(dt, i, 2);
var model = new SwapEquityPaymentModel
{
ConfirmationNo = GetDataSetValue(dt, i, 0),
OperationType = optType,
DurationEventNO = GetDataSetValue(dt, i, 2)
};
if (string.IsNullOrWhiteSpace(model.DurationEventNO))
{
model.DurationEventNO = null;
@@ -455,11 +165,11 @@ namespace YLErp.Modules.SuperviseReportModule.SAC.Service
model.Blank2 = GetDataSetValue(dt, i, 4);
var cacheValue = formatInfoTag(model);
if (ReportStatus.CheckCacheInfo(cacheKey, cacheValue))
if (ReportStatus.CheckCacheInfo(CacheKey, cacheValue))
{
continue;
}
List<SACReportNotes> notes = base.GetReportNotes(ReportType, formatInfoTag(model));
List<SACReportNotes> notes = base.GetReportNotes(ReportType, formatInfoTag(model), dataSource: SACReportNotesCache);
var note = notes.LastOrDefault();
if (note == null && _operationType == OptFlagsEnum.A)
{
@@ -497,114 +207,9 @@ namespace YLErp.Modules.SuperviseReportModule.SAC.Service
{
model.BizID = note.BizId;
}
model.ExceID = base.formatExceID();
model.ExceID = base.formatExceID(SACReportNotesCache);
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);
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<SwapEquityPaymentModel> GetSwapEquityPaymentModelFromView()
{
List<SwapEquityPaymentModel> result = new List<SwapEquityPaymentModel>();
if (_viewDataSource != null && _viewDataSource.Tables.Contains("互换交易权益端支付"))
{
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;
}
SwapEquityPaymentModel model = new SwapEquityPaymentModel();
model.IgnoreCheck = true;
model.ConfirmationNo = GetDataSetValue(dt, i, "CONFIRMATIONNO");
model.OperationType = optType;
model.DurationEventNO = GetDataSetValue(dt, i, "DURATIONEVENTNO");
if (string.IsNullOrWhiteSpace(model.DurationEventNO))
{
model.DurationEventNO = null;
}
model.Blank1 = GetDataSetValue(dt, i, "BLANK1");
model.Blank2 = GetDataSetValue(dt, i, "BLANK2");
var cacheValue = formatInfoTag(model);
if (ReportStatus.CheckCacheInfo(cacheKey, cacheValue))
{
continue;
}
List<SACReportNotes> notes = base.GetReportNotes(ReportType, formatInfoTag(model));
var note = notes.LastOrDefault();
if (note == null && _operationType == OptFlagsEnum.A)
{
note = new SACReportNotes()
{
InfoCache = $"{{\"Tag\":\"{model.ConfirmationNo}\",\"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("未知操作类型");
}
}
model.SwapEquityPaymentTuple = GetSwapEquityPaymentTupleFromView(model.ConfirmationNo);
if (model.OperationType != OptFlagsEnum.A)
{
model.BizID = note.BizId;
}
model.ExceID = base.formatExceID();
result.Add(model);
ReportStatus.AddCacheInfo(cacheKey, cacheValue);
ReportStatus.AddCacheInfo(CacheKey, cacheValue);
note.id = 0;
note.ExceId = model.ExceID;
note.CreateTime = DateTime.Now;
@@ -632,30 +237,31 @@ namespace YLErp.Modules.SuperviseReportModule.SAC.Service
/// <returns></returns>
private List<SwapEquityPaymentTupleModel> GetSwapEquityPaymentTuple(string confirmationNo)
{
List<SwapEquityPaymentTupleModel> result = new List<SwapEquityPaymentTupleModel>();
var result = new List<SwapEquityPaymentTupleModel>();
if (_excelDataSource != null && _excelDataSource.Tables.Contains("权益端支付明细"))
{
DataTable dt = _excelDataSource.Tables["权益端支付明细"];
for (int i = 1; i < dt.Rows.Count; i++)
var dt = _excelDataSource.Tables["权益端支付明细"];
for (var i = 1; i < dt.Rows.Count; i++)
{
if (string.IsNullOrWhiteSpace(dt.Rows[i][0]?.ToString()))
{
//第一列空白说明数据结束了;
break;
}
if (dt.Rows[i][0]?.ToString() != confirmationNo)
if (dt.Rows[i][0]?.ToString().Trim() != confirmationNo)
{
continue;
}
SwapEquityPaymentTupleModel model = new SwapEquityPaymentTupleModel();
model.UndrlygAssetCode = GetDataSetValue(dt, i, 0);
model.PaymentMethod = ConsReport.PaymentMethodMap[GetDataSetValue(dt, i, 1)];
model.Payer = ConsReport.PayerMap[GetDataSetValue(dt, i, 2)];
model.PaymentFreq = ConsReport.PaymentFreqMap[GetDataSetValue(dt, i, 3)];
model.OpenandClosingDate = GetDataSetValue(dt, i, 4);
model.UndrlygAssetDtldType = ConsReport.SwapUndrlygAssetDtldTypeMap[GetDataSetValue(dt, i, 5)];
var model = new SwapEquityPaymentTupleModel
{
UndrlygAssetCode = GetDataSetValue(dt, i, 0),
PaymentMethod = ConsReport.PaymentMethodMap[GetDataSetValue(dt, i, 1)],
Payer = ConsReport.PayerMap[GetDataSetValue(dt, i, 2)],
PaymentFreq = ConsReport.PaymentFreqMap[GetDataSetValue(dt, i, 3)],
OpenandClosingDate = GetDataSetValue(dt, i, 4),
UndrlygAssetDtldType = ConsReport.SwapUndrlygAssetDtldTypeMap[GetDataSetValue(dt, i, 5)]
};
model.UndrlygAssetCode = GetDataSetValue(dt, i, 6);
model.UndrlygAssetName = GetDataSetValue(dt, i, 7);
model.UndrlygAssetTradgPlc = GetDataSetValue(dt, i, 8);
@@ -675,54 +281,9 @@ namespace YLErp.Modules.SuperviseReportModule.SAC.Service
return result;
}
/// <summary>
/// 获取权益端支付明细
/// </summary>
/// <param name="confirmationNo"></param>
/// <returns></returns>
private List<SwapEquityPaymentTupleModel> GetSwapEquityPaymentTupleFromView(string confirmationNo)
{
List<SwapEquityPaymentTupleModel> result = new List<SwapEquityPaymentTupleModel>();
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;
}
SwapEquityPaymentTupleModel model = new SwapEquityPaymentTupleModel();
model.UndrlygAssetCode = GetDataSetValue(dt, i, "UNDRLYGASSETCODE");
model.PaymentMethod = GetDataSetValue(dt, i, "PAYMENTMETHOD");
model.Payer = GetDataSetValue(dt, i, "PAYER");
model.PaymentFreq = GetDataSetValue(dt, i, "PAYMENTFREQ");
model.OpenandClosingDate = GetDataSetValue(dt, i, "OPENANDCLOSINGDATE");
model.UndrlygAssetDtldType = GetDataSetValue(dt, i, "UNDRLYGASSETDTLDTYPE");
model.UndrlygAssetCode = GetDataSetValue(dt, i, "UNDRLYGASSETCODE");
model.UndrlygAssetName = GetDataSetValue(dt, i, "UNDRLYGASSETNAME");
model.UndrlygAssetTradgPlc = GetDataSetValue(dt, i, "UNDRLYGASSETTRADEPLC");
model.UndrlygAssetPrice = GetDataSetValue(dt, i, "UNDRLYGASSETPRICE");
model.UndrlygAssetPosition = GetDataSetValue(dt, i, "UNDRLYGASSETPOSITION");
model.UndrlygAssetAmt = GetDataSetValue(dt, i, "UNDRLYGASSETAMT");
model.ContractMultiplier = GetDataSetValue(dt, i, "CONTRACTMULTIPLIER");
model.LNotinalPrincipleAmt = GetDataSetValue(dt, i, "LNOTINALPRINCIPLEAMT");
model.SNotinalPrincipleAmt = GetDataSetValue(dt, i, "SNOTINALPRINCIPLEAMT");
model.InterestRate = GetDataSetValue(dt, i, "INTERESTRATE");
model.Blank1 = GetDataSetValue(dt, i, "BLANK1");
model.Blank2 = GetDataSetValue(dt, i, "BLANK2");
result.Add(model);
}
}
return result;
}
private string formatInfoTag(SwapEquityPaymentModel model, bool suffixType = false)
{
string result = $"{BusiDataType}_{model.ConfirmationNo.Replace("_", "-")}_成交_权益端支付_{model.DurationEventNO}_";
var result = $"{BusiDataType}_{model.ConfirmationNo.Replace("_", "-")}_成交_权益端支付_{model.DurationEventNO}_";
if (suffixType)
{
result = $"{result}{_operationType}";
@@ -730,25 +291,41 @@ namespace YLErp.Modules.SuperviseReportModule.SAC.Service
return result;
}
protected override string _changeCodeOfInfoTag(string infoTag, string newCode, out string originalCode)
{
var arr = infoTag.Split('_');
if (arr.Length != 6)
{
throw new ServiceException($"InfoTag信息不匹配:{infoTag}");
}
originalCode = arr[1];
arr[1] = newCode.Replace("_", "-");
return string.Join("_", arr);
}
protected override List<SacInfo> CheckBodyValue(BodyModel model, out bool checkStatus)
{
List<SacInfo> result = new List<SacInfo>();
var result = new List<SacInfo>();
if (model?.SwapEquityPayment != null)
{
CheckHelper<SwapEquityPaymentModel> helper = new CheckHelper<SwapEquityPaymentModel>();
CheckHelper<SwapEquityPaymentTupleModel> tupleHelper = new CheckHelper<SwapEquityPaymentTupleModel>();
for (int i = 0; i < model.SwapEquityPayment.Count; i++)
var helper = new CheckHelper<SwapEquityPaymentModel>();
var tupleHelper = new CheckHelper<SwapEquityPaymentTupleModel>();
for (var i = 0; i < model.SwapEquityPayment.Count; i++)
{
List<SacInfo> listRoot = new List<SacInfo>();
var listRoot = new List<SacInfo>();
var item = model.SwapEquityPayment[i];
if (item.IgnoreCheck) continue;
if (item.IgnoreCheck)
{
continue;
}
helper.ExecuteCheck(item, (name, value, msg) =>
{
listRoot.Add(new SacInfo(name, value, msg));
});
if (item.SwapEquityPaymentTuple != null)
{
for (int j = 0; j < item.SwapEquityPaymentTuple.Count; j++)
for (var j = 0; j < item.SwapEquityPaymentTuple.Count; j++)
{
var listItem = new List<SacInfo>();
var attItem = item.SwapEquityPaymentTuple[j];
@@ -758,16 +335,21 @@ namespace YLErp.Modules.SuperviseReportModule.SAC.Service
});
if (listItem.Count > 0)
{
var temp = new SacInfo("SwapEquityPaymentTuple", j);
temp.SubMaps = new List<SacInfo>(listItem);
var temp = new SacInfo("SwapEquityPaymentTuple", j)
{
SubMaps = new List<SacInfo>(listItem)
};
listRoot.Add(temp);
}
}
}
if (listRoot.Count > 0)
{
var errMsg = new SacInfo("SwapEquityPayment", i);
errMsg.SubMaps = new List<SacInfo>(listRoot);
var errMsg = new SacInfo("SwapEquityPayment", i)
{
FieldValue = item.ConfirmationNo,
SubMaps = new List<SacInfo>(listRoot)
};
result.Add(errMsg);
}
}
@@ -791,7 +373,7 @@ namespace YLErp.Modules.SuperviseReportModule.SAC.Service
};
}
for (int i = 0; i < noteList.Count; i++)
for (var i = 0; i < noteList.Count; i++)
{
base.SaveReportNotes(noteList[i]);
}
File diff suppressed because it is too large Load Diff
@@ -0,0 +1,484 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using static YLErp.DBModels.Consts.ConsReport;
using YLErp.BLL;
using YLErp.DBModels.Consts;
using YLErp.DBModels.Enums;
using YLErp.DBModels;
using YLErp.Modules.SuperviseReportModule.SAC.Common;
using YLErp.Modules.SuperviseReportModule.SAC.Model;
using System.Data;
using System.IO;
using static iTextSharp.text.pdf.AcroFields;
using YLErp.DBModels.Helpers;
using YLErp.Modules.EodModule;
using System.Collections.ObjectModel;
using YLErp.Helpers;
using YLErp.Modules.PricingModule.Models;
using YLErp.Modules.CalculationModule;
using YLErp.BLL.Calculation;
using YLErp.Enums;
using YLErp.Modules.DataProviderModule;
using YLErp.QdpModule;
using Qdp.Pricing.Base.Utilities;
using YLErp.Enums;
using YLErp.Configuration;
using Qdp.Foundation.Implementations;
using YLErp.Modules.VolatilityModule;
using MoreLinq;
namespace YLErp.Modules.SuperviseReportModule.SAC.Service
{
class ReportValuationInformationService : ReportBaseService
{
public ReportValuationInformationService(OptUserInfo optUser) : base(optUser)
{
}
protected override string _excelDataSourcePath => "交易相关\\";
protected override string _excelDataSourceFileName => "import_ValuationInformation_template.xlsx";
protected override DataFlagsEnum BusiDataType => DataFlagsEnum.A1018;
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_ValuationInformation;
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<ValuationInformationModel> dataList = new List<ValuationInformationModel>();
if (_reqInfo.DataSource.HasFlag(SAC_ReportDataSourceEnum.Template))
{
dataList = GetValuationInformationModelFromExcel(ref fileList);
}
ReadOnlyCollection<string> useDel = null;
if (_operationType == OptFlagsEnum.D && (useDel = ReportStatus.GetCacheInfo($"{DataFlagsEnum.A1018}_D")).Count > 0)
{
dataList.AddRange(GetValuationInformationModelFromCache(useDel));
}
var subsystemDataList = loadSubsystemDataSource<ValuationInformationModel>(fileList, AddSubsystemNote);
if (subsystemDataList != null && subsystemDataList.Count > 0)
dataList.AddRange(subsystemDataList);
noData = dataList.Count == 0;
model.ValuationInformation = dataList;
return model;
}
private List<ValuationInformationModel> GetValuationInformationModelFromCache(IEnumerable<string> useDel)
{
List<ValuationInformationModel> result = new List<ValuationInformationModel>();
foreach (var item in useDel)
{
var notes = base.GetReportNotes(formatInfoTag(item));
foreach (var note in notes)
{
var info = new ValuationInformationModel();
var reportCacheDic = JsonHelper.ToObject<Dictionary<string, string>>(note.InfoCache) ?? new Dictionary<string, string>();
info.ValuationDate = reportCacheDic.ContainsKey("ValuationDate") ? reportCacheDic["ValuationDate"] : "";
if (info.ValuationDate.IsNullOrWhiteSpace())
{
continue;
}
info.ConfirmationNo = item;
var cacheValue = $"{info.ConfirmationNo}_{info.ValuationDate}";
if (ReportStatus.CheckCacheInfo(CacheKey, cacheValue))
{
continue;
}
info.BizID = note.BizId;
info.OperationType = OptFlagsEnum.D;
info.Balance = "0.00";
info.MarginRatio = "0.00";
info.OptionValuation = "0.00";
info.Delta = "0.00";
info.Gamma = "0.00";
info.Vega = "0.00";
info.Theta = "0.00";
info.Rho = "0.00";
info.RhoQ = "0.00";
info.DeltaCash = "0.00";
info.GammaCash = "0.00";
info.VegaCash = "0.00";
info.ThetaCash = "0.00";
info.RhoCash = "0.00";
info.RhoQCash = "0.00";
info.Blank1 = "0.00";
info.Blank2 = "0.00";
var exceId_TY = $"{info.ConfirmationNo}_{info.ValuationDate}";
info.ExceID = base.formatExceID();
result.Add(info);
ReportStatus.AddCacheInfo(CacheKey, cacheValue);
note.id = 0;
note.InfoCache = $"{{\"Tag\":\"{info.ConfirmationNo}\",\"ValuationDate\":\"{info.ValuationDate}\",\"ExceId_TY\":\"{exceId_TY}\"}}";
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.RetCode = "";
note.RetMsg = "";
note.ReportResponse = false;
note.BizId = "";
note.DataId = "";
note.changeStatus = false;
noteList.Add(note);
}
}
return result;
}
public bool AddSubsystemNote(ValuationInformationModel model, List<string> fileList, string tag)
{
SACReportNotes note = base.GetReportNotes(ReportType, formatInfoTag(model, true)).FirstOrDefault();//参数true要加,要不A和D会查到同一条记录,在D时候,就会和A相同的数据
if (note == null)
{
note = new SACReportNotes()
{
InfoCache = $"{{\"Tag\":\"{model.ConfirmationNo}\",\"Source\":\"Subsystem\",\"SubFileTag\":\"{tag}\",\"ExceID\":\"{model.ExceID}\"}}",
IsValid = true,
};
}
else
{
switch (model.OperationType)
{
case OptFlagsEnum.A:
return false;//新增数据已报送,跳过
case OptFlagsEnum.U:
//多次U的时候,每次用最新的tag来赋值SubFileTag
note.InfoCache = $"{{\"Tag\":\"{model.ConfirmationNo}\",\"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("未知操作类型");
}
}
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);
note.OptTime = note.CreateTime;
note.RetCode = "";
note.RetMsg = "";
note.ReportResponse = false;
note.BizId = "";
note.changeStatus = false;
noteList.Add(note);
return true;
}
private List<ValuationInformationModel> GetValuationInformationModelFromExcel(ref List<string> fileList)
{
List<ValuationInformationModel> result = new List<ValuationInformationModel>();
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;
}
var optType = OptFlagsEnum.NONE;
switch (dt.Rows[i][1]?.ToString())
{
case "0":
case "A":
case "首次":
optType = OptFlagsEnum.A;
break;
case "1":
case "U":
case "变更":
optType = OptFlagsEnum.U;
break;
case "2":
case "D":
case "废止":
optType = OptFlagsEnum.D;
break;
}
if (optType != _operationType)
{
continue;
}
ValuationInformationModel model = new ValuationInformationModel();
model.ConfirmationNo = GetDataSetValue(dt, i, 0);
model.OperationType = _operationType;
DateTime.TryParse(GetDataSetValue(dt, i, 2), out DateTime date);
model.ValuationDate = date == DateTime.MinValue ? null : date.ToString("yyyy-MM-dd");
var cacheValue = $"{model.ConfirmationNo}_{model.ValuationDate}";
if (ReportStatus.CheckCacheInfo(CacheKey, cacheValue))
{
continue;
}
List<SACReportNotes> notes = base.GetReportNotes(ReportType, formatInfoTag(model));
var note = notes.LastOrDefault(O => O.InfoCache.Contains(model.ConfirmationNo));
if (note == null && _operationType == OptFlagsEnum.A)
{
note = new SACReportNotes()
{
InfoCache = $"{{\"Tag\":\"{model.ConfirmationNo}\",\"ValuationDate\":\"{model.ValuationDate}\",\"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("未知操作类型");
}
}
if (_operationType != OptFlagsEnum.A)
{
model.BizID = note.BizId;
}
model.Balance = GetDataSetValueToDoubleOrNull(dt, i, 3)?.ToString("0.00");
model.MarginRatio = GetDataSetValue(dt, i, 4);
model.OptionValuation = GetDataSetValueToDoubleOrNull(dt, i, 5)?.ToString("0.00");
model.Delta = GetDataSetValue(dt, i, 6);
model.Gamma = GetDataSetValue(dt, i, 7);
model.Vega = GetDataSetValue(dt, i, 8);
model.Theta = GetDataSetValue(dt, i, 9);
model.Rho = GetDataSetValue(dt, i, 10);
model.RhoQ = GetDataSetValue(dt, i, 11);
model.DeltaCash = GetDataSetValue(dt, i, 12);
model.GammaCash = GetDataSetValue(dt, i, 13);
model.VegaCash = GetDataSetValue(dt, i, 14);
model.ThetaCash = GetDataSetValue(dt, i, 15);
model.RhoCash = GetDataSetValue(dt, i, 16);
model.RhoQCash = GetDataSetValue(dt, i, 17);
model.Blank1 = GetDataSetValue(dt, i, 18); ;
model.Blank2 = GetDataSetValue(dt, i, 19);
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);
note.OptTime = note.CreateTime;
note.RetCode = "";
note.RetMsg = "";
note.ReportResponse = false;
note.BizId = "";
note.DataId = "";
note.changeStatus = false;
noteList.Add(note);
}
}
return result;
}
private string formatInfoTag(ValuationInformationModel model, bool suffixType = false)
{
string result = $"{BusiDataType}_{model.ConfirmationNo.Replace("_", "-")}_{model.ValuationDate}_";
if (suffixType)
{
result = $"{result}{_operationType}";
}
return result;
}
private string formatInfoTag(string confirmationNo)
{
string result = $"{BusiDataType}_{confirmationNo.Replace("_", "-")}_";
return result;
}
protected override string _changeCodeOfInfoTag(string infoTag, string newCode, out string originalCode)
{
var arr = infoTag.Split('_');
if (arr.Length != 4)
{
throw new ServiceException($"InfoTag信息不匹配:{infoTag}");
}
originalCode = arr[1];
arr[1] = newCode.Replace("_", "-");
return string.Join("_", arr);
}
protected override List<SacInfo> CheckBodyValue(BodyModel model, out bool checkStatus)
{
List<SacInfo> result = new List<SacInfo>();
if (model?.ValuationInformation != null)
{
CheckHelper<ValuationInformationModel> helper = new CheckHelper<ValuationInformationModel>();
for (int i = 0; i < model.ValuationInformation.Count; i++)
{
List<SacInfo> listRoot = new List<SacInfo>();
var item = model.ValuationInformation[i];
helper.ExecuteCheck(item, (name, value, msg) =>
{
listRoot.Add(new SacInfo(name, value, msg));
});
if (listRoot.Count > 0)
{
var errMsg = new SacInfo("ValuationInformation", i);
errMsg.FieldValue = item.ConfirmationNo;
errMsg.SubMaps = new List<SacInfo>(listRoot);
result.Add(errMsg);
}
}
}
checkStatus = result.Count > 0;
return result;
}
public override bool BeforeOfGenerated(out string errMsg)
{
errMsg = "";
for (int i = 0; i < noteList.Count; i++)
{
base.SaveReportNotes(noteList[i]);
}
return true;
}
private enum clacTargetEnum
{
/// <summary>
/// 波动率变动
/// </summary>
vol,
/// <summary>
/// 无风险利率变动
/// </summary>
r,
/// <summary>
/// 分红率变动
/// </summary>
q
}
/// <summary>
/// 计算参数
/// </summary>
private class calcParam
{
/// <summary>
/// 计算指标
/// </summary>
public clacTargetEnum Target { get; set; }
/// <summary>
/// 交易列表
/// </summary>
public IEnumerable<trade> TradeList { get; set; }
/// <summary>
/// 估值日期
/// </summary>
public DateTime Date { get; set; }
/// <summary>
/// 偏移值
/// <para>每次只变动一个参数,所以只需要一个</para>
/// </summary>
public double Offset { get; set; }
/// <summary>
/// 波动率变动
/// </summary>
public Dictionary<int, double> UpVolForTrade { get; set; }
/// <summary>
/// 无风险利率或分红率变动
/// </summary>
public Action<OptionTradeParamBase> UpParamOverride { get; set; }
/// <summary>
/// 波动率变动
/// </summary>
public Dictionary<int, double> DownVolForTrade { get; set; }
/// <summary>
/// 无风险利率或分红率变动
/// </summary>
public Action<OptionTradeParamBase> DownParamOverride { get; set; }
/// <summary>
/// PV差
/// </summary>
public Dictionary<int, double> PvDiff { get; set; }
/// <summary>
///
/// </summary>
/// <param name="offset"></param>
/// <param name="volForTrade"></param>
/// <param name="rParamOverride"></param>
/// <param name="qParamOverride"></param>
public calcParam(
clacTargetEnum target,
IEnumerable<trade> tradeList,
DateTime date,
double offset,
Dictionary<int, double> upVolForTrade,
Dictionary<int, double> downVolForTrade,
Action<OptionTradeParamBase> upParamOverride,
Action<OptionTradeParamBase> downParamOverride)
{
this.Target = target;
this.TradeList = tradeList;
this.Date = date;
this.Offset = offset;
this.UpVolForTrade = upVolForTrade;
this.DownVolForTrade = downVolForTrade;
this.UpParamOverride = upParamOverride;
this.DownParamOverride = downParamOverride;
}
}
}
}