找回证券业报送的逻辑,仅支持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,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]);
}