Files
zszq-trs/YLErpDAL/Modules/SuperviseReportModule/SAC/Service/ReportSwapConfirmationService.cs
T
2024-05-09 14:06:26 +08:00

1156 lines
64 KiB
C#

using BaseOUDAL;
using NPOI.SS.Formula.Functions;
using Qdp.Foundation.Implementations;
using System.Data;
using YieldChain.Helpers;
using YLErp.BLL;
using YLErp.DBModels.Consts;
using YLErp.DBModels.Enums;
using YLErp.Modules.EodModule;
using YLErp.Modules.SuperviseReportModule.SAC.Common;
using YLErp.Modules.SuperviseReportModule.SAC.Model;
using YLErp.QdpModule;
using static YLErp.DBModels.Consts.ConsReport;
namespace YLErp.Modules.SuperviseReportModule.SAC.Service
{
class ReportSwapConfirmationService : ReportBaseService
{
public ReportSwapConfirmationService(OptUserInfo optUser) : base(optUser)
{
}
protected override string _excelDataSourcePath => "交易相关\\";
protected override string _excelDataSourceFileName => "import_SwapConfirmation_template.xlsx";
protected override DataFlagsEnum BusiDataType => DataFlagsEnum.A1005;
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_SwapConfirmation;
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();
var cacheKey = $"{BusiDataType}";
LogFactory.GetLogger("GenerateBody").Info($"SAC_ReportDataSource:" + PS.Config.ErpElement.SAC_ReportDataSource.ToString());
List<SwapConfirmationModel> dataList = new List<SwapConfirmationModel>();
if ((PS.Config.ErpElement.SAC_ReportDataSource & SAC_ReportDataSourceEnum.Template) == SAC_ReportDataSourceEnum.Template)
{
dataList = GetSwapConfirmationModel(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))//补正和废止时使用操作日期判断
&& (_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,
t.QuoteCurrency,
t.SettlementCurrency,
ts.GetUnAnnualRate,
ts.GetSingleFee,
ts.PayUnAnnualRate,
ts.PaySingleFee,
ts.SwapType,
td.Comments,
}).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;
}
//如果存在重复数据,则始终用较新的数据
SwapConfirmationModel info = new SwapConfirmationModel();
//info.TradeId = item.id.ToString();
info.ConfirmationNo = item.ContractCode;
SACReportNotes note = base.GetReportNotes(ReportType, formatInfoTag(info)).FirstOrDefault();
if (note == null && _operationType == OptFlagsEnum.A)
{
info.OperationType = OptFlagsEnum.A;
note = new SACReportNotes()
{
IsValid = true,
};
}
else
{
if (note == null)
{
continue;
}
switch (_operationType)
{
case OptFlagsEnum.A:
continue;//新增数据已报送,跳过
case OptFlagsEnum.U:
if (!note.changeStatus)
{
continue;//交易没有被修改过,跳过
}
info.OperationType = OptFlagsEnum.U;
note.IsValid = true;
break;
case OptFlagsEnum.D:
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];
info.MasterAgrmtNo = metaInfo.ContainsKey(ConsTradeMetaKey.MainProtocolCode) ? metaInfo[ConsTradeMetaKey.MainProtocolCode] : "";
info.SupAgrmtNo = metaInfo.ContainsKey(ConsTradeMetaKey.SupProtocolCode) ? metaInfo[ConsTradeMetaKey.SupProtocolCode] : "";
info.ClearingAgency = metaInfo.ContainsKey(ConsTradeMetaKey.ClearingAgency) ? ClearingAgencyMap[metaInfo[ConsTradeMetaKey.ClearingAgency]] : "";
info.TradingPlace = metaInfo.ContainsKey(ConsTradeMetaKey.TradingPlace) ? TradingPlaceMap[metaInfo[ConsTradeMetaKey.TradingPlace]] : "";
if (info.TradingPlace == "1")//跳过交易场所为报价系统的交易;
{
continue;
}
}
if (info.OperationType != OptFlagsEnum.A)
{
info.ConfirmationID = note.BizId;//确认书编号;
}
info.ConfirmationType = ReportTypeMap[info.OperationType == OptFlagsEnum.A ? "首次" : "变更"];
info.FillParty = FillPartyMap["甲方"];
if (item.SwapType == "普通")
{
var longShort = item.IsPayFloatingProfit ? item.PayLongShort : item.GetLongShort;
info.SwapType = ConsReport.SwapTypeMap["客户" + longShort];
}
else
{
info.SwapType = ConsReport.SwapTypeMap[item.SwapType];
}
var variety = DataCacheProvider.GetVariety(item.UnderlyingCode);
var customizedResultsGet = QdpHelper.ParseAutocallCustomizedInfo(item.GetSwapTimeAndRate);
var getSwapRates = customizedResultsGet.Item2?.Distinct();
var customizedResultsPay = QdpHelper.ParseAutocallCustomizedInfo(item.PaySwapTimeAndRate);
var paySwapRates = customizedResultsPay.Item2?.Distinct();
var rates = item.IsPayFloatingProfit ? getSwapRates : paySwapRates;
var paymentMethod = new PaymentMethodModel();
if (GetPaySide(item.IsPayFloatingProfit, info.ClearingAgency))
{
var underlyingCode = string.IsNullOrWhiteSpace(item.GetUnderlyingCode) ? item.PayUnderlyingCode : item.GetUnderlyingCode;
var um = DataCacheProvider.GetUnderlyingDataSource().GetData(underlyingCode);
info.PtyAUndrlygAssetNo = um.CommodityCode == "组合标的" ? UndrlygAssetNoMap["组合标的"] : UndrlygAssetNoMap["单一标的"];
if (rates.Count() == 1)
{
info.PaymentMethod = PaymentMethodMap["固定利率收益"];
paymentMethod.FixedInterestRate = (rates.First() * 100).ToString();
}
else
{
info.PaymentMethod = PaymentMethodMap["浮动利率收益"];
paymentMethod.FloatInterestRate = ConsReport.RefRateTypeMap["其他"];
paymentMethod.ReferenceofFloatingInterestRate = "其他";
paymentMethod.BasePoint = "0";
}
}
else
{
info.PtyAUndrlygAssetNo = UndrlygAssetNoMap["单一标的"];
if (rates.Count() == 1)
{
info.PaymentMethod = PaymentMethodMap["固定利率收益"];
paymentMethod.FixedInterestRate = (rates.First() * 100).ToString();
}
else
{
info.PaymentMethod = PaymentMethodMap["浮动利率收益"];
paymentMethod.FloatInterestRate = ConsReport.RefRateTypeMap["其他"];
paymentMethod.ReferenceofFloatingInterestRate = "其他";
paymentMethod.BasePoint = "其他";
paymentMethod.BasePoint = "0";
}
}
paymentMethod.PaymentMethod = info.PaymentMethod;
paymentMethod.Payer = item.IsPayFloatingProfit ? ConsReport.PayerMap["乙方"] : ConsReport.PayerMap["甲方"];
var getSwapDates = customizedResultsGet.Item1?.Distinct();
if (getSwapDates?.Count() == 1)
{
Date date = getSwapDates.First();
paymentMethod.PaymentFreq = date == new Date(item.TradeDate.Value) ? PaymentFreqMap["期初支付"] : PaymentFreqMap["期末支付"];
}
else
{
paymentMethod.PaymentFreq = PaymentFreqMap["期间多次支付"];
}
var paySwapDates = customizedResultsPay.Item1?.Distinct();
if (paySwapDates?.Count() == 1)
{
Date date = paySwapDates.First();
paymentMethod.PaymentFreq = date == new Date(item.TradeDate.Value) ? PaymentFreqMap["期初支付"] : PaymentFreqMap["期末支付"];
}
else
{
paymentMethod.PaymentFreq = PaymentFreqMap["期间多次支付"];
}
info.StartDate = item.TradeDate?.ToString("yyyy-MM-dd");
info.DueDate = item.ExerciseDate?.ToString("yyyy-MM-dd");
info.SettlementDate = (item.SettlementDate ?? item.ExerciseDate)?.ToString("yyyy-MM-dd");
if (PS.Config.Company == Configuration.CompanyEnum.中金)
{
var um = DataCacheProvider.GetUnderlyingDataSource().GetData(item.UnderlyingCode);
if (um.CloseDate != null && um.CloseDate != DateTime.MinValue)
{
info.DueDate = um.CloseDate?.ToString("yyyy-MM-dd");
}
}
var currency = (item.SettlementCurrency == "CNH" ? "CNY" : item.SettlementCurrency) ?? "CNY";
info.Currency = ((int)(CurrencyEnum)Enum.Parse(typeof(CurrencyEnum), currency.ToUpper())).ToString();// ((int)CurrencyEnum.CNY).ToString();
var rate = new EodCurrencyRateService(UserInfo).GetCurrencyRate(item.QuoteCurrency, "CNY", _reqInfo.DataDate);
info.NotinalPrincipleAmt = (item.OriginalStockEqvNotional * rate)?.ToString("0.00");
info.UndrlygAssetType = string.IsNullOrWhiteSpace(variety.MainCategoryDesc) ? UndrlygAssetTypeMap["其他"] : UndrlygAssetTypeMap[variety.MainCategoryDesc];
//系统中的交易修改时必须回退,所以报送不存在修改时还存在有效的存续期记录的情况;
//if (info.OperationType == OptFlagsEnum.U)
//{
// if (reportCacheDic.ContainsKey("DueDate") && !reportCacheDic["DueDate"].StartsWith(info.DueDate) && !info.DueDate.StartsWith(reportCacheDic["DueDate"]))
// {
// throw new ServiceException("补正时,如果该交易还存在有效的存续期记录,到期日字段不能修改");
// }
// if (reportCacheDic.ContainsKey("NotinalPrincipleAmt") && reportCacheDic["NotinalPrincipleAmt"] != info.NotinalPrincipleAmt && reportCacheDic["NotinalPrincipleAmt"] != item.OriginalStockEqvNotional?.ToString("0"))
// {
// throw new ServiceException("补正时,如果该交易还存在有效的存续期记录,名义本金额(人民币)字段不能修改");
// }
//}
#region 履约担保
var files = db.trade_file.Where(O => O.TradeId == item.id).ToArray();
info.PerformanceGuaranteeType = item.MarginType == MarginTypeEnum.NONE ? PerformanceGuaranteeMap["无履约担保"] : PerformanceGuaranteeMap["部分担保"];
if (item.MarginType != MarginTypeEnum.NONE)
{
info.PerformanceCollProvider = PerformanceCollProviderMap["乙方"];
info.PartyUseColl = ConsReport.BoolMap[valuedateBLL.SystemDate.PartyUseColl || PS.Config.Company == Configuration.CompanyEnum.东莞 ? "是" : "否"];//todo:读取用户输入
info.CollInstruction = valuedateBLL.SystemDate.CollInstruction;//todo:读取用户输入
info.CalculateCollInterest = BoolMap["否"];
info.PerformanceCollInitialRatio = (item.GetMarginRate * 100)?.ToString("0.##");//获取客户预付金率
info.PerformanceCollAddtlRatio = "100";
info.PerformanceCollOffsetRatio = "100";
info.MaintainGuaranteeRatio = info.PerformanceCollInitialRatio;
if (PS.Config.Company == Configuration.CompanyEnum.中金)
{
info.PerformanceCollAddtlRatio = info.PerformanceCollInitialRatio;
info.PerformanceCollOffsetRatio = info.PerformanceCollInitialRatio;
info.MaintainGuaranteeRatio = info.PerformanceCollInitialRatio;
}
var file_PerformanceGuarante = files.FirstOrDefault(O => O.Path.ToLower().EndsWith("履约保证书.pdf"));
info.PerformanceGuaranteeAtt = Path.GetFileName(file_PerformanceGuarante?.Path);
info.PerformanceGuaranteeRemark = file_PerformanceGuarante?.Description;
info.Remark = item.Comments;
info.PerformanceCollTuple = new List<SwapPerformanceGuaranteeAttModel>();
info.PerformanceCollTuple.Add(new SwapPerformanceGuaranteeAttModel()
{
PerformanceCollType = PerformanceCollTypeMap["现金"],
PerformanceCollRange = /*item.MarginType == MarginTypeEnum.DEFAULT ? PerformanceCollRangeMap["本笔交易对应主协议框架下的所有交易"] :*/ PerformanceCollRangeMap["仅本笔交易"]
});
if (!ReportStatus.CheckFileLength(file_PerformanceGuarante?.Path))
{
break;
}
fileList.Add(file_PerformanceGuarante?.Path);
}
else
{
info.PerformanceCollInitialRatio = "0";
info.MaintainGuaranteeRatio = "0";
}
#endregion
var file_ComplianceOpinion = files.FirstOrDefault(O => O.Path.ToLower().EndsWith("合规意见书.pdf"));
if (!string.IsNullOrWhiteSpace(file_ComplianceOpinion?.Path))
{
string fileName = Path.GetFileName(file_ComplianceOpinion?.Path);
info.ComplianceOpinion = fileName;
if (!ReportStatus.CheckFileLength(file_ComplianceOpinion?.Path))
{
break;
}
fileList.Add(file_ComplianceOpinion?.Path);
}
var client = DataCacheProvider.GetClientDataSource().GetData(item.ClientId);
switch (PS.Config.Company)
{
case Configuration.CompanyEnum.中金:
GetCalculationInfoFromZhongJin(info, item.QuoteCurrency, item.IsPayFloatingProfit, item.IsPayFloatingProfit ? item.PayLongShort : item.GetLongShort, client.BoundSide);
break;
default:
string defaultDesc = reportDescDic.ContainsKey("默认") ? reportDescDic["默认"] : "";
info.PtyAPrOfitCalculationInfo = reportDescDic.ContainsKey("甲方支付乙方") && !string.IsNullOrWhiteSpace(reportDescDic["甲方支付乙方"]) ? reportDescDic["甲方支付乙方"] : defaultDesc;//说明
//info.PtyBProfitCalculationInfo = reportDescDic.ContainsKey("乙方支付甲方") && !string.IsNullOrWhiteSpace(reportDescDic["乙方支付甲方"]) ? reportDescDic["乙方支付甲方"] : defaultDesc;//说明
break;
}
if (client.ClientType == "产品")
{
using (var baseDb = new ClientDBContext())
{
if (PS.Config.Company == Configuration.CompanyEnum.中金)
{
info.FillParty = FillPartyMap["甲方"];
info.PtyBPdctName = new ClientModule.ClientQueryService(OptUser).GetProductName(client.id) ?? "";
info.PytBPdctCode = client.ProductNumber ?? "";
}
else
{
//var clientFile = baseDb.client_file.Where(O => ((O.FileTypeName == ConsGlobal.ClientFileType.MainProtocol && O.ProtocolNumber == info.MasterAgrmtNo) || (O.FileTypeName == ConsGlobal.ClientFileType.AllographProduct && O.MainProtocolNumber == info.MasterAgrmtNo)) && O.ClientId == client.id && O.IsValid).AsEnumerable().GroupBy(O => O.FileTypeName).ToDictionary(K => K.Key, V => V.FirstOrDefault());
//if (!clientFile.ContainsKey(ConsGlobal.ClientFileType.MainProtocol))
//{
// throw new ServiceException($"{client.Name} 主协议文件不存在,生成失败!");
//}
////下面这行注释掉是因为目前系统报送互换时只处理了报送方是甲方的情况,假如报送方为乙方,则所有涉及支付方向的参数都应该对调;
////info.FillParty = FillPartyMap[clientFile[ConsGlobal.ClientFileType.MainProtocol].ReportorRole];
//info.FillParty = FillPartyMap["甲方"];
//var productFile = clientFile.ContainsKey(ConsGlobal.ClientFileType.AllographProduct) ? clientFile[ConsGlobal.ClientFileType.AllographProduct] : null;
if (info.FillParty == FillPartyMap["甲方"])
{
info.PtyBPdctName = client.Name ?? "";
info.PytBPdctCode = client.Number ?? "";
}
else
{
info.PtyAPdctName = client.Name ?? "";
info.PytAPdctCode = client.Number ?? "";
}
}
}
}
info.CostPaymentTuple = new List<PaymentMethodModel>() { paymentMethod };
info.ExceID = base.formatExceID();
ReportStatus.AddCacheInfo(cacheKey, cacheValue);
ReportStatus.AddCacheInfo($"{cacheKey}_{info.ConfirmationNo}", info.NotinalPrincipleAmt);
dataList.Add(info);
note.id = 0;
note.InfoCache = $"{{\"NotinalPrincipleAmt\":\"{info.NotinalPrincipleAmt}\",\"DueDate\":\"{info.DueDate}\",\"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)
{
LogFactory.GetLogger("GenerateBody").Info($"SAC_ReportDataSourceEnum.KingstarView");
dataList.AddRange(GetSwapConfirmationModelFromView(ref fileList));
}
var subsystemDataList = loadSubsystemDataSource<SwapConfirmationModel>(fileList, AddSubsystemNote);
if (subsystemDataList != null && subsystemDataList.Count > 0)
dataList.AddRange(subsystemDataList);
fileList = fileList.Distinct().ToList();
noData = dataList.Count == 0;
model.SwapConfirmation = dataList;
return model;
}
public bool AddSubsystemNote(SwapConfirmationModel 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 = $"{{\"NotinalPrincipleAmt\":\"{model.NotinalPrincipleAmt}\",\"DueDate\":\"{model.DueDate}\",\"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 = $"{{\"NotinalPrincipleAmt\":\"{model.NotinalPrincipleAmt}\",\"DueDate\":\"{model.DueDate}\",\"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 (!string.IsNullOrWhiteSpace(model.PerformanceGuaranteeAtt))
{
fileList.Add(model.PerformanceGuaranteeAtt);
}
if (!string.IsNullOrWhiteSpace(model.ComplianceOpinion))
{
fileList.Add(model.ComplianceOpinion);
}
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;
}
/// <summary>
/// 中金填写收益说明
/// </summary>
/// <param name="info"></param>
/// <param name="quoteCurrency"></param>
/// <param name="buySell"></param>
private void GetCalculationInfoFromZhongJin(SwapConfirmationModel info, string quoteCurrency, bool IsPaySide, string longShort, BoundSideEnum side)
{
//根据现金流支付方式
info.PtyAPrOfitCalculationInfo = GetSingleCalculationInfo(info.PaymentMethod);
var currency = (quoteCurrency == "CNH" || string.IsNullOrWhiteSpace(quoteCurrency)) ? "CNY" : quoteCurrency;
var qCurrency = ((CurrencyEnum)Enum.Parse(typeof(CurrencyEnum), currency));
if (qCurrency != CurrencyEnum.CNY)
{
info.PtyAPrOfitCalculationInfo += "*结算汇率";
//info.PtyBProfitCalculationInfo += "*结算汇率";
}
}
private string GetSingleCalculationInfo(string paymentMethod)
{
switch (paymentMethod)
{
case "0":
return "(期初价格-期末价格)*标的资产数量";
case "1":
return "(期末价格 - 期初价格) * 标的资产数量";
case "2":
return "";
case "3":
return "标的资产数量*期初价格*固定收益率";
default:
return "";
}
}
private List<SwapConfirmationModel> GetSwapConfirmationModel(ref List<string> fileList)
{
List<SwapConfirmationModel> result = new List<SwapConfirmationModel>();
string path = "";
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++)
{
if (string.IsNullOrWhiteSpace(dt.Rows[i][0]?.ToString()))
{
//第一列空白说明数据结束了;
break;
}
var optType = OptFlagsEnum.NONE;
switch (dt.Rows[i][3]?.ToString())
{
case "首次":
optType = OptFlagsEnum.A;
break;
case "变更":
optType = OptFlagsEnum.U;
break;
case "废止":
optType = OptFlagsEnum.D;
break;
}
if (optType != _operationType)
{
continue;
}
SwapConfirmationModel model = new SwapConfirmationModel();
model.OperationType = optType;
model.MasterAgrmtNo = GetDataSetValue(dt, i, 0);
model.SupAgrmtNo = GetDataSetValue(dt, i, 1);
model.ConfirmationNo = GetDataSetValue(dt, i, 2);
model.ConfirmationType = ConsReport.ReportTypeMap[optType == OptFlagsEnum.A ? "首次" : "变更"];
model.FillParty = ConsReport.FillPartyMap[GetDataSetValue(dt, i, 4)];
model.SwapType = ConsReport.SwapTypeMap[GetDataSetValue(dt, i, 5)];
model.StartDate = GetDataSetValue(dt, i, 6);
model.DueDate = GetDataSetValue(dt, i, 7);
model.SettlementDate = GetDataSetValue(dt, i, 8);
if (Enum.TryParse(GetDataSetValue(dt, i, 9).ToUpper(), out CurrencyEnum currency))
{
model.Currency = ((int)currency).ToString();
}
model.NotinalPrincipleAmt = GetDataSetValue(dt, i, 10);
model.ClearingAgency = ConsReport.ClearingAgencyMap[GetDataSetValue(dt, i, 11)];
model.TradingPlace = ConsReport.TradingPlaceMap[GetDataSetValue(dt, i, 12)];
model.TradingPlaceOther = GetDataSetValue(dt, i, 13);
model.UndrlygAssetType = ConsReport.UndrlygAssetTypeMap[GetDataSetValue(dt, i, 14)];
model.ConfirmationRemark = GetDataSetValue(dt, i, 15);
model.PerformanceGuaranteeType = ConsReport.PerformanceGuaranteeMap[GetDataSetValue(dt, i, 16)];
model.PerformanceCollProvider = ConsReport.PerformanceCollProviderMap[GetDataSetValue(dt, i, 17)];
model.PartyUseColl = ConsReport.BoolMap[GetDataSetValue(dt, i, 18)];
model.CollInstruction = GetDataSetValue(dt, i, 19);
model.CalculateCollInterest = ConsReport.BoolMap[GetDataSetValue(dt, i, 20)];
model.PerformanceCollInitialRatio = GetDataSetValue(dt, i, 21);
model.PerformanceCollAddtlRatio = GetDataSetValue(dt, i, 22);
model.PerformanceCollOffsetRatio = GetDataSetValue(dt, i, 23);
model.MaintainGuaranteeRatio = GetDataSetValue(dt, i, 24);
model.PerformanceGuaranteeAtt = GetDataSetValue(dt, i, 25);
model.PerformanceGuaranteeRemark = GetDataSetValue(dt, i, 26);
model.Remark = GetDataSetValue(dt, i, 27);
model.ComplianceOpinion = GetDataSetValue(dt, i, 28);
model.PtyAUndrlygAssetNo = ConsReport.UndrlygAssetNoMap[GetDataSetValue(dt, i, 29)];
model.PtyAPrOfitCalculationInfo = GetDataSetValue(dt, i, 30);
model.PtyAProfitRemark = GetDataSetValue(dt, i, 31);
model.PtyAPdctName = GetDataSetValue(dt, i, 32);
model.PytAPdctCode = GetDataSetValue(dt, i, 33);
model.PtyBPdctName = GetDataSetValue(dt, i, 34);
model.PytBPdctCode = GetDataSetValue(dt, i, 35);
model.Blank1 = GetDataSetValue(dt, i, 36);
model.Blank2 = GetDataSetValue(dt, i, 37);
model.CostPaymentTuple = GetCostPaymentTuple(model.ConfirmationNo);
model.PerformanceCollTuple = GetPerformanceGuaranteeAttModel(model.ConfirmationNo);
var notinalPrincipleAmt = GetDataSetValueToDouble(dt, i, 10);
var cacheValue = model.ConfirmationNo;
if (ReportStatus.CheckCacheInfo(cacheKey, cacheValue))
{
continue;
}
SACReportNotes note = base.GetReportNotes(ReportType, formatInfoTag(model)).FirstOrDefault();
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("未知操作类型");
}
Dictionary<string, string> reportCacheDic = JsonHelper.ToObject<Dictionary<string, string>>(note.InfoCache) ?? new Dictionary<string, string>();
if (_operationType == OptFlagsEnum.U)
{
if (reportCacheDic.ContainsKey("DueDate") && !reportCacheDic["DueDate"].StartsWith(model.DueDate) && !model.DueDate.StartsWith(reportCacheDic["DueDate"]))
{
throw new ServiceException("补正时,如果该交易还有存续期记录,到期日字段不能修改");
}
if (reportCacheDic.ContainsKey("NotinalPrincipleAmt") && reportCacheDic["NotinalPrincipleAmt"] != model.NotinalPrincipleAmt && reportCacheDic["NotinalPrincipleAmt"] != notinalPrincipleAmt.ToString("0"))
{
throw new ServiceException("补正时,如果该交易还有存续期记录,名义本金额(人民币)字段不能修改");
}
}
}
if (model.OperationType != OptFlagsEnum.A)
{
model.ConfirmationID = note.BizId;//确认书编号;
}
if (!string.IsNullOrWhiteSpace(model.PerformanceGuaranteeAtt))
{
path = Path.Combine(sourcePath, model.PerformanceGuaranteeAtt);
if (!ReportStatus.CheckFileLength(path))
{
break;
}
fileList.Add(path);
}
if (!string.IsNullOrWhiteSpace(model.ComplianceOpinion))
{
path = Path.Combine(sourcePath, model.ComplianceOpinion);
if (!ReportStatus.CheckFileLength(path))
{
break;
}
fileList.Add(path);
}
model.ExceID = base.formatExceID();
result.Add(model);
ReportStatus.AddCacheInfo(cacheKey, cacheValue);
note.id = 0;
note.InfoCache = $"{{\"NotinalPrincipleAmt\":\"{model.NotinalPrincipleAmt}\",\"DueDate\":\"{model.DueDate}\",\"Tag\":\"{model.ConfirmationNo}\",\"Source\":\"Template\"}}";
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 result;
}
private List<SwapConfirmationModel> GetSwapConfirmationModelFromView(ref List<string> fileList)
{
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);
List<SwapConfirmationModel> result = new List<SwapConfirmationModel>();
string path = "";
if (_viewDataSource != null && _viewDataSource.Tables.Contains("交易确认书"))
{
var cacheKey = $"{BusiDataType}";
DataTable dt = _viewDataSource.Tables["交易确认书"];
LogFactory.GetLogger("GetSwapConfirmationModelFromView").Info($"交易确认书记录数:" + dt.Rows.Count);
for (int i = 0; i < dt.Rows.Count; i++)
{
LogFactory.GetLogger("GetSwapConfirmationModelFromView").Info($"交易确认书记录数:" + dt.Rows.Count);
var operateType = GetDataSetValue(dt, i, "OPERATIONTYPE");
LogFactory.GetLogger("GetSwapConfirmationModelFromView").Info($"OperateType:" + operateType.ToString());
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;
}
SwapConfirmationModel model = new SwapConfirmationModel();
model.IgnoreCheck = true;
model.OperationType = optType;
model.MasterAgrmtNo = GetDataSetValue(dt, i, "MASTERAGRMTNO");
model.SupAgrmtNo = GetDataSetValue(dt, i, "SUPAGRMNO");
model.ConfirmationNo = GetDataSetValue(dt, i, "CONFIRMATIONNO");
model.ConfirmationType = ConsReport.ReportTypeMap[optType == OptFlagsEnum.A ? "首次" : "变更"];
model.FillParty = GetDataSetValue(dt, i, "FILLPARTY");
model.SwapType = GetDataSetValue(dt, i, "SWAPTYPE");
model.StartDate = GetDataSetValue(dt, i, "STARTDATE");
model.DueDate = GetDataSetValue(dt, i, "DUEDATE");
model.SettlementDate = GetDataSetValue(dt, i, "SETTLEMENTDATE");
model.Currency = GetDataSetValue(dt, i, "CURRENCY");
model.NotinalPrincipleAmt = GetDataSetValue(dt, i, "NOTIONALPRINCIPLEAMT");
model.ClearingAgency = GetDataSetValue(dt, i, "CLEARINGAGENCY");
model.TradingPlace = GetDataSetValue(dt, i, "TRADINGPLACE");
model.TradingPlaceOther = GetDataSetValue(dt, i, "TRADINGPLACEOTHER");
model.UndrlygAssetType = GetDataSetValue(dt, i, "UNDRLYGASSETTYPE");
model.ConfirmationRemark = GetDataSetValue(dt, i, "CONFIRMATIONREMARK");
model.PerformanceGuaranteeType = GetDataSetValue(dt, i, "PERFORMANCEGUARANTEETYPE");
model.PerformanceCollProvider = GetDataSetValue(dt, i, "PERFORMANCECOLLPROVIDER");
model.PartyUseColl = GetDataSetValue(dt, i, "PARTYUSECOLL");
model.CollInstruction = GetDataSetValue(dt, i, "COLLINSTRUCTION");
model.CalculateCollInterest = GetDataSetValue(dt, i, "CALCULATECOLLINTEREST");
model.PerformanceCollInitialRatio = GetDataSetValue(dt, i, "PERFORMANCECOLLINITIALRATIO");
model.PerformanceCollAddtlRatio = GetDataSetValue(dt, i, "PERFORMANCECOLLADDTLRATIO");
model.PerformanceCollOffsetRatio = GetDataSetValue(dt, i, "PERFORMANCECOLLOFFSETRATIO");
model.MaintainGuaranteeRatio = GetDataSetValue(dt, i, "MAINTAINGUARANTEERATIO");
model.PerformanceGuaranteeAtt = GetDataSetValue(dt, i, "PERFORMANCEGUARANTEEATT");
model.PerformanceGuaranteeRemark = GetDataSetValue(dt, i, "PERFORMANCEGUARANTEEREMARK");
model.Remark = GetDataSetValue(dt, i, "REMARK");
model.ComplianceOpinion = GetDataSetValue(dt, i, "COMPLIANCEOPINION");
model.PtyAUndrlygAssetNo = GetDataSetValue(dt, i, "PTYAUNDRLYGASSETNO");
model.PtyAPrOfitCalculationInfo = GetDataSetValue(dt, i, "PTYAPROFITCALCULATIONINFO");
model.PtyAProfitRemark = GetDataSetValue(dt, i, "PTYAPROFITREMARK");
model.PtyAPdctName = GetDataSetValue(dt, i, "PTYAPDCTNAME");
model.PytAPdctCode = GetDataSetValue(dt, i, "PTYAPDCTCODE");
model.PtyBPdctName = GetDataSetValue(dt, i, "PTYBPDCTNAME");
model.PytBPdctCode = GetDataSetValue(dt, i, "PTYBPDCTCODE");
model.Blank1 = GetDataSetValue(dt, i, "BLANK1");
model.Blank2 = GetDataSetValue(dt, i, "BLANK2");
model.CostPaymentTuple = GetCostPaymentTupleFromView(model.ConfirmationNo);
model.PerformanceCollTuple = GetPerformanceGuaranteeAttModelFromView(model.ConfirmationNo);
var notinalPrincipleAmt = GetDataSetValueToDouble(dt, i, "NOTIONALPRINCIPLEAMT");
var cacheValue = model.ConfirmationNo;
if (ReportStatus.CheckCacheInfo(cacheKey, cacheValue))
{
continue;
}
SACReportNotes note = base.GetReportNotes(ReportType, formatInfoTag(model)).FirstOrDefault();
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("未知操作类型");
}
Dictionary<string, string> reportCacheDic = JsonHelper.ToObject<Dictionary<string, string>>(note.InfoCache) ?? new Dictionary<string, string>();
if (_operationType == OptFlagsEnum.U)
{
if (reportCacheDic.ContainsKey("DueDate") && !reportCacheDic["DueDate"].StartsWith(model.DueDate) && !model.DueDate.StartsWith(reportCacheDic["DueDate"]))
{
throw new ServiceException("补正时,如果该交易还有存续期记录,到期日字段不能修改");
}
if (reportCacheDic.ContainsKey("NotinalPrincipleAmt") && reportCacheDic["NotinalPrincipleAmt"] != model.NotinalPrincipleAmt && reportCacheDic["NotinalPrincipleAmt"] != notinalPrincipleAmt.ToString("0"))
{
throw new ServiceException("补正时,如果该交易还有存续期记录,名义本金额(人民币)字段不能修改");
}
}
}
if (model.OperationType != OptFlagsEnum.A)
{
model.ConfirmationID = note.BizId;//确认书编号;
}
if (!string.IsNullOrWhiteSpace(model.PerformanceGuaranteeAtt))
{
var downloadRet = ftpHelper.DownloadFile(CreateViewAttDownloadPath(model.PerformanceGuaranteeAtt), ViewLocalAttFileDir + @"\kingstar\", out string message);
LogFactory.GetLogger("ftpHelper.DownloadFile").Info($"下载结果:{ViewLocalAttFileDir},{model.PerformanceGuaranteeAtt},{downloadRet}");
path = downloadRet;
if (!ReportStatus.CheckFileLength(path))
{
break;
}
fileList.Add(path);
model.PerformanceGuaranteeAtt = Path.GetFileName(path);
}
if (!string.IsNullOrWhiteSpace(model.ComplianceOpinion))
{
var downloadRet = ftpHelper.DownloadFile(CreateViewAttDownloadPath(model.ComplianceOpinion), ViewLocalAttFileDir + @"\kingstar\", out string message);
LogFactory.GetLogger("ftpHelper.DownloadFile").Info($"下载结果:{ViewLocalAttFileDir},{model.ComplianceOpinion},{downloadRet}");
path = downloadRet;
if (!ReportStatus.CheckFileLength(path))
{
break;
}
fileList.Add(path);
model.ComplianceOpinion = Path.GetFileName(path);
}
model.ExceID = base.formatExceID();
result.Add(model);
ReportStatus.AddCacheInfo(cacheKey, cacheValue);
note.id = 0;
note.InfoCache = $"{{\"NotinalPrincipleAmt\":\"{model.NotinalPrincipleAmt}\",\"DueDate\":\"{model.DueDate}\",\"Tag\":\"{model.ConfirmationNo}\",\"Source\":\"KingstarView\"}}";
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 result;
}
private List<PaymentMethodModel> GetCostPaymentTuple(string confirmationNo)
{
List<PaymentMethodModel> result = new List<PaymentMethodModel>();
if (_excelDataSource != null && _excelDataSource.Tables.Contains("收益互换交易费用支付端"))
{
DataTable dt = _excelDataSource.Tables["收益互换交易费用支付端"];
for (int i = 1; i < dt.Rows.Count; i++)
{
if (string.IsNullOrWhiteSpace(dt.Rows[i][0]?.ToString()))
{
//第一列空白说明数据结束了;
break;
}
if (dt.Rows[i][0]?.ToString() != confirmationNo)
{
continue;
}
PaymentMethodModel model = new PaymentMethodModel();
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.FixedInterestRate = GetDataSetValue(dt, i, 4);
model.FloatInterestRate = ConsReport.RefRateTypeMap[GetDataSetValue(dt, i, 5)];
model.ReferenceofFloatingInterestRate = GetDataSetValue(dt, i, 6);
model.BasePoint = GetDataSetValue(dt, i, 7);
model.Blank1 = GetDataSetValue(dt, i, 8);
model.Blank2 = GetDataSetValue(dt, i, 9);
result.Add(model);
}
}
return result;
}
private List<PaymentMethodModel> GetCostPaymentTupleFromView(string confirmationNo)
{
List<PaymentMethodModel> result = new List<PaymentMethodModel>();
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;
}
PaymentMethodModel model = new PaymentMethodModel();
model.PaymentMethod = GetDataSetValue(dt, i, "PAYMENTMETHOD");
model.Payer = GetDataSetValue(dt, i, "PAYER");
model.PaymentFreq = GetDataSetValue(dt, i, "PAYMENTFREQ");
model.FixedInterestRate = GetDataSetValue(dt, i, "FIXEDINTERESTRATE");
model.FloatInterestRate = GetDataSetValue(dt, i, "FLOATINTERESTRATE");
model.ReferenceofFloatingInterestRate = GetDataSetValue(dt, i, "REFFLOATINGINTERESTRATE");
model.BasePoint = GetDataSetValue(dt, i, "BASEPOINT");
model.Blank1 = GetDataSetValue(dt, i, "BLANK1");
model.Blank2 = GetDataSetValue(dt, i, "BLANK2");
result.Add(model);
}
}
return result;
}
private List<SwapPerformanceGuaranteeAttModel> GetPerformanceGuaranteeAttModel(string confirmationNo)
{
List<SwapPerformanceGuaranteeAttModel> result = new List<SwapPerformanceGuaranteeAttModel>();
if (_excelDataSource != null && _excelDataSource.Tables.Contains("履约担保品明细"))
{
DataTable dt = _excelDataSource.Tables["履约担保品明细"];
for (int i = 1; i < dt.Rows.Count; i++)
{
if (string.IsNullOrWhiteSpace(dt.Rows[i][0]?.ToString()))
{
//第一列空白说明数据结束了;
break;
}
if (dt.Rows[i][0]?.ToString() != confirmationNo)
{
continue;
}
SwapPerformanceGuaranteeAttModel model = new SwapPerformanceGuaranteeAttModel();
model.PerformanceCollType = ConsReport.PerformanceCollTypeMap[GetDataSetValue(dt, i, 1)];
model.PerformanceCollRange = ConsReport.PerformanceCollRangeMap[GetDataSetValue(dt, i, 2)];
model.MultiConfirmationID = GetDataSetValue(dt, i, 3);
model.Remarks = GetDataSetValue(dt, i, 4);
result.Add(model);
}
}
return result;
}
private List<SwapPerformanceGuaranteeAttModel> GetPerformanceGuaranteeAttModelFromView(string confirmationNo)
{
List<SwapPerformanceGuaranteeAttModel> result = new List<SwapPerformanceGuaranteeAttModel>();
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;
}
SwapPerformanceGuaranteeAttModel model = new SwapPerformanceGuaranteeAttModel();
model.PerformanceCollType = GetDataSetValue(dt, i, "PERFORMANCECOLLTYPE");
model.PerformanceCollRange = GetDataSetValue(dt, i, "PERFORMANCECOLLRANGE");
model.MultiConfirmationID = GetDataSetValue(dt, i, "MULTICONFIRMATIONID");
model.Remarks = GetDataSetValue(dt, i, "REMARKS");
result.Add(model);
}
}
return result;
}
private string formatInfoTag(SwapConfirmationModel model, bool suffixType = false, bool isSettlement = false)
{
string result = $"{(isSettlement ? "" : BusiDataType.ToString())}_{model.ConfirmationNo.Replace("_", "-")}_{(isSettlement ? "" : "成交_")}";
if (suffixType)
{
result = $"{result}{_operationType}";
}
return result;
}
protected override List<SacInfo> CheckBodyValue(BodyModel model, out bool checkStatus)
{
List<SacInfo> result = new List<SacInfo>();
if (model?.SwapConfirmation != null)
{
CheckHelper<SwapConfirmationModel> helper = new Common.CheckHelper<SwapConfirmationModel>();
CheckHelper<SwapPerformanceGuaranteeAttModel> pAttHelper = new Common.CheckHelper<SwapPerformanceGuaranteeAttModel>();
CheckHelper<PaymentMethodModel> cAttHelper = new Common.CheckHelper<PaymentMethodModel>();
for (int i = 0; i < model.SwapConfirmation.Count; i++)
{
List<SacInfo> listRoot = new List<SacInfo>();
var item = model.SwapConfirmation[i];
if (item.IgnoreCheck) continue;
helper.ExecuteCheck(item, (name, value, msg) =>
{
listRoot.Add(new SacInfo(name, value, msg));
});
if (item.CostPaymentTuple != null)
{
for (int j = 0; j < item.CostPaymentTuple.Count; j++)
{
var listItem = new List<SacInfo>();
var attItem = item.CostPaymentTuple[j];
cAttHelper.ExecuteCheck(attItem, (name, value, msg) =>
{
listItem.Add(new SacInfo(name, value, msg));
});
if (listItem.Count > 0)
{
var temp = new SacInfo("CostPaymentTuple", j);
temp.SubMaps = new List<SacInfo>(listItem);
listRoot.Add(temp);
}
}
}
if (item.PerformanceCollTuple != null)
{
for (int j = 0; j < item.PerformanceCollTuple.Count; j++)
{
var listItem = new List<SacInfo>();
var attItem = item.PerformanceCollTuple[j];
pAttHelper.ExecuteCheck(attItem, (name, value, msg) =>
{
listItem.Add(new SacInfo(name, value, msg));
});
if (listItem.Count > 0)
{
var temp = new SacInfo("PerformanceCollTuple", j);
temp.SubMaps = new List<SacInfo>(listItem);
listRoot.Add(temp);
}
}
}
if (listRoot.Count > 0)
{
var errMsg = new SacInfo("SwapConfirmation", i);
errMsg.SubMaps = new List<SacInfo>(listRoot);
result.Add(errMsg);
}
}
}
checkStatus = result.Count > 0;
return result;
}
public override bool BeforeOfGenerated(out string errMsg)
{
errMsg = "";
foreach (var file in xmlAttachmentList)
{
try
{
File.Delete(file);
}
catch (Exception e)
{
LogFactory.GetLogger<ReportMasterAgrmtProductService>().Error(e);
};
}
for (int i = 0; i < noteList.Count; i++)
{
base.SaveReportNotes(noteList[i]);
}
return true;
}
private bool GetPaySide(bool IsPaySide, string clearingAgency)
{
if (PS.Config.Company == Configuration.CompanyEnum.中金)
{
return clearingAgency == ClearingAgencyMap["甲方"];
}
return IsPaySide;
}
}
}