Merge branch 'glms/feature/1.4.2' of http://git.yiliantech.com/gitlab/otc-dev/zszq-trs into glms/feature/1.4.2
This commit is contained in:
@@ -4952,13 +4952,13 @@ namespace YLErp.Modules.RiskModule
|
||||
var item = positions[i];
|
||||
if (item == null)
|
||||
{
|
||||
_logger.Error($"[CheckUnderlyingWhiteList] 错误: positions[{i}] 为 null");
|
||||
_logger.Info($"[CheckUnderlyingWhiteList] positions[{i}] 为 null");
|
||||
quotaMsg = "持仓数据异常:存在空记录";
|
||||
return false;
|
||||
}
|
||||
if (string.IsNullOrEmpty(item.UnderlyingCode))
|
||||
{
|
||||
_logger.Error($"[CheckUnderlyingWhiteList] 错误: positions[{i}].UnderlyingCode 为 null 或空 - id: {item.id}, SwapTradeId: {item.SwapTradeId}");
|
||||
_logger.Info($"[CheckUnderlyingWhiteList] positions[{i}].UnderlyingCode 为 null 或空 - id: {item.id}, SwapTradeId: {item.SwapTradeId}");
|
||||
quotaMsg = "持仓数据异常:标的代码为空";
|
||||
return false;
|
||||
}
|
||||
@@ -5073,7 +5073,7 @@ namespace YLErp.Modules.RiskModule
|
||||
|
||||
if (trades == null || trades.Count == 0)
|
||||
{
|
||||
_logger.Error("[CheckFund] 错误: trades 为 null 或空列表");
|
||||
_logger.Info("[CheckFund] trades 为 null 或空列表");
|
||||
msg = "交易列表为空";
|
||||
return false;
|
||||
}
|
||||
@@ -5139,7 +5139,7 @@ namespace YLErp.Modules.RiskModule
|
||||
// 检查 ExerciseDate 是否为 null
|
||||
if (!trades[0].ExerciseDate.HasValue)
|
||||
{
|
||||
_logger.Error($"[CheckFund] 错误: trades[0].ExerciseDate 为 null - tradeId: {trades[0].id}");
|
||||
_logger.Info($"[CheckFund] trades[0].ExerciseDate 为 null - tradeId: {trades[0].id}");
|
||||
msg = "交易行权日期不能为空";
|
||||
return false;
|
||||
}
|
||||
|
||||
@@ -223,25 +223,25 @@ namespace YLErp.Modules.SwapModule
|
||||
// 验证关键参数
|
||||
if (td == null)
|
||||
{
|
||||
Log.Error("[DealInterests] 参数错误: td (trade) 为 null");
|
||||
Log.Info("[DealInterests] 参数验证: td (trade) 为 null");
|
||||
throw new ArgumentNullException(nameof(td), "交易对象不能为null");
|
||||
}
|
||||
|
||||
if (interestList == null)
|
||||
{
|
||||
Log.Error($"[DealInterests] 参数错误: interestList 为 null, td.id: {td.id}");
|
||||
Log.Info($"[DealInterests] 参数验证: interestList 为 null, td.id: {td.id}");
|
||||
throw new ArgumentNullException(nameof(interestList), "利息腿列表不能为null");
|
||||
}
|
||||
|
||||
if (flowEvents == null)
|
||||
{
|
||||
Log.Error($"[DealInterests] 参数错误: flowEvents 为 null, td.id: {td.id}");
|
||||
Log.Info($"[DealInterests] 参数验证: flowEvents 为 null, td.id: {td.id}");
|
||||
throw new ArgumentNullException(nameof(flowEvents), "流水事件列表不能为null");
|
||||
}
|
||||
|
||||
if (autoInterests == null)
|
||||
{
|
||||
Log.Error($"[DealInterests] 参数错误: autoInterests 为 null, td.id: {td.id}");
|
||||
Log.Info($"[DealInterests] 参数验证: autoInterests 为 null, td.id: {td.id}");
|
||||
throw new ArgumentNullException(nameof(autoInterests), "自动互换列表不能为null");
|
||||
}
|
||||
var hasClose = flowEvents.Any(x => x.EventType == (int)SwapEventTypeEnum.平仓);
|
||||
@@ -715,25 +715,25 @@ namespace YLErp.Modules.SwapModule
|
||||
// 详细的参数验证
|
||||
if (td == null)
|
||||
{
|
||||
Log.Error("[SaveAutoEodInterestPosition] 参数错误: td (trade) 为 null");
|
||||
Log.Info("[SaveAutoEodInterestPosition] 参数验证: td (trade) 为 null");
|
||||
throw new ArgumentNullException(nameof(td), "交易对象不能为null");
|
||||
}
|
||||
|
||||
if (position == null)
|
||||
{
|
||||
Log.Error($"[SaveAutoEodInterestPosition] 参数错误: position 为 null, td.id: {td.id}");
|
||||
Log.Info($"[SaveAutoEodInterestPosition] 参数验证: position 为 null, td.id: {td.id}");
|
||||
throw new ArgumentNullException(nameof(position), "持仓对象不能为null");
|
||||
}
|
||||
|
||||
if (interval == null)
|
||||
{
|
||||
Log.Error($"[SaveAutoEodInterestPosition] 参数错误: interval 为 null, td.id: {td.id}, position.id: {position.id}");
|
||||
Log.Info($"[SaveAutoEodInterestPosition] 参数验证: interval 为 null, td.id: {td.id}, position.id: {position.id}");
|
||||
throw new ArgumentNullException(nameof(interval), "观察日信息不能为null");
|
||||
}
|
||||
|
||||
if (td.trade_extend == null)
|
||||
{
|
||||
Log.Error($"[SaveAutoEodInterestPosition] 参数错误: td.trade_extend 为 null, td.id: {td.id}, td.TradeNumber: {td.TradeNumber}");
|
||||
Log.Info($"[SaveAutoEodInterestPosition] 参数验证: td.trade_extend 为 null, td.id: {td.id}, td.TradeNumber: {td.TradeNumber}");
|
||||
throw new ArgumentNullException("td.trade_extend", "交易扩展信息不能为null");
|
||||
}
|
||||
|
||||
@@ -742,7 +742,7 @@ namespace YLErp.Modules.SwapModule
|
||||
// 验证 ExtendObj
|
||||
if (td.trade_extend.ExtendObj == null)
|
||||
{
|
||||
Log.Error($"[SaveAutoEodInterestPosition] 参数错误: td.trade_extend.ExtendObj 为 null, td.id: {td.id}");
|
||||
Log.Info($"[SaveAutoEodInterestPosition] 参数验证: td.trade_extend.ExtendObj 为 null, td.id: {td.id}");
|
||||
throw new ArgumentNullException("td.trade_extend.ExtendObj", "交易扩展对象不能为null");
|
||||
}
|
||||
|
||||
|
||||
@@ -195,6 +195,9 @@ namespace YLErp.Modules.TradeModule.DealModule
|
||||
public bool GJGenerateConfirmBook(List<int> tradeIds, string docType,
|
||||
out IEnumerable<string> errors, out IEnumerable<string> files, DateTime? startDate = null, DateTime? endDate = null)
|
||||
{
|
||||
var logger = LogFactory.GetLogger("生成确认书");
|
||||
logger.Info($"[GJGenerateConfirmBook] 开始生成确认书 - tradeIds.Count: {tradeIds?.Count ?? 0}, docType: {docType}, startDate: {startDate}, endDate: {endDate}");
|
||||
|
||||
Func<int, string> getUnderlyingInstrumentType = new Func<int, string>((underlyingId) =>
|
||||
{
|
||||
return DataCacheProvider.GetUnderlyingDataSource().GetData(underlyingId)?.UnderlyingInstrumentType;
|
||||
@@ -204,9 +207,30 @@ namespace YLErp.Modules.TradeModule.DealModule
|
||||
List<string> file = new List<string>();
|
||||
if (PS.Config.Company == CompanyEnum.浙商)
|
||||
{
|
||||
LogFactory.GetLogger("生成确认书").Error("浙商生成确认书");
|
||||
logger.Info("[GJGenerateConfirmBook] 生成确认书流程");
|
||||
|
||||
if (tradeIds == null || !tradeIds.Any())
|
||||
{
|
||||
logger.Info("[GJGenerateConfirmBook] tradeIds 为空,直接返回");
|
||||
errors = new List<string>();
|
||||
files = new List<string>();
|
||||
return true;
|
||||
}
|
||||
|
||||
var trades = DbContext.trade.Where(x => tradeIds.Contains(x.id)).AsNoTracking().ToList();
|
||||
logger.Info($"[GJGenerateConfirmBook] 查询到交易记录数: {trades.Count}");
|
||||
|
||||
if (!trades.Any())
|
||||
{
|
||||
logger.Info("[GJGenerateConfirmBook] 未找到交易记录,直接返回");
|
||||
errors = new List<string>();
|
||||
files = new List<string>();
|
||||
return true;
|
||||
}
|
||||
|
||||
var clientIds = trades.Select(x => x.ClientId).Distinct().ToList();
|
||||
logger.Info($"[GJGenerateConfirmBook] 客户ID数: {clientIds.Count}");
|
||||
|
||||
var allTrades = DbContext.trade.Where(x => clientIds.Contains(x.ClientId) && x.ValidState != ConsGlobal.InValid);
|
||||
if (startDate.HasValue)
|
||||
{
|
||||
@@ -219,59 +243,127 @@ namespace YLErp.Modules.TradeModule.DealModule
|
||||
var Ids = allTrades.Select(o => o.id).Distinct().ToArray();
|
||||
var swapPositions = DbContext.swap_position.Where(s => Ids.Contains(s.SwapTradeId) && s.IsInitial && s.PositionType > 0 && !s.Invalid)
|
||||
.Distinct().ToList();
|
||||
logger.Info($"[GJGenerateConfirmBook] 查询到持仓记录数: {swapPositions.Count}");
|
||||
|
||||
var allTradeList = allTrades.AsNoTracking().ToList();
|
||||
foreach (var item in allTradeList)
|
||||
{
|
||||
item.swap_positions.Add(swapPositions.FirstOrDefault(o => o.SwapTradeId == item.id));
|
||||
}
|
||||
allTradeList = allTradeList.Where(x => x.swap_positions.Any()).ToList();
|
||||
logger.Info($"[GJGenerateConfirmBook] 过滤后有持仓的交易数: {allTradeList.Count}");
|
||||
|
||||
// 按照客户ID、交易日期、多空头进行分组
|
||||
var group = allTradeList.GroupBy(O => new { O.ClientId, O.StartDate, O.swap_positions.FirstOrDefault().PositionType })
|
||||
var group = allTradeList.GroupBy(O => new { O.ClientId, O.StartDate, O.swap_positions.FirstOrDefault()?.PositionType })
|
||||
.ToDictionary(K => K.Key, V => V.Select(O => O.id).ToList());
|
||||
|
||||
logger.Info($"[GJGenerateConfirmBook] 分组数: {group.Count}");
|
||||
|
||||
foreach (var item in group)
|
||||
{
|
||||
LogFactory.GetLogger("生成确认书").Error("浙商生成确认书" + item.Value.Distinct().ToList().Count());
|
||||
var tradeCount = item.Value.Distinct().Count();
|
||||
logger.Info($"[GJGenerateConfirmBook] 处理分组 - ClientId: {item.Key.ClientId}, StartDate: {item.Key.StartDate}, PositionType: {item.Key.PositionType}, 交易数: {tradeCount}");
|
||||
groupGenerateHandle(item.Value.Distinct().ToList(), docType, startDate, endDate, results, error, file);
|
||||
}
|
||||
}
|
||||
errors = results.Where(n => !string.IsNullOrWhiteSpace(n.ErrorMessage)).Select(n => n.ErrorMessage).ToList();
|
||||
files = results.Where(n => !string.IsNullOrWhiteSpace(n.OutputFilePath)).Select(n => n.OutputFilePath).ToList();
|
||||
logger.Info($"[GJGenerateConfirmBook] 完成生成确认书 - 错误数: {errors.Count()}, 文件数: {files.Count()}");
|
||||
return !errors.Any();
|
||||
}
|
||||
|
||||
private void groupGenerateHandle_Date(List<int> ids, string docType, DateTime? startDate, DateTime? endDate, List<TradeDocGenerateResult> results, List<string> error, List<string> file)
|
||||
{
|
||||
var logger = LogFactory.GetLogger("生成确认书");
|
||||
logger.Info($"[groupGenerateHandle_Date] 开始处理 - ids.Count: {ids?.Count ?? 0}");
|
||||
|
||||
if (ids == null || !ids.Any())
|
||||
{
|
||||
logger.Info("[groupGenerateHandle_Date] ids 为空,直接返回");
|
||||
return;
|
||||
}
|
||||
|
||||
var trades = DbContext.trade.Where(c => ids.Contains(c.id)).ToList();
|
||||
var supProtocolDate = DataCacheProvider.GetClientDataSource().GetData(trades.FirstOrDefault().ClientId).SupProtocolDate;
|
||||
logger.Info($"[groupGenerateHandle_Date] 查询到交易数: {trades.Count}");
|
||||
|
||||
if (!trades.Any())
|
||||
{
|
||||
logger.Info("[groupGenerateHandle_Date] 未找到交易记录,直接返回");
|
||||
return;
|
||||
}
|
||||
|
||||
var firstTrade = trades.FirstOrDefault();
|
||||
if (firstTrade == null)
|
||||
{
|
||||
logger.Info("[groupGenerateHandle_Date] 第一条交易记录为 null,直接返回");
|
||||
return;
|
||||
}
|
||||
|
||||
var client = DataCacheProvider.GetClientDataSource().GetData(firstTrade.ClientId);
|
||||
if (client == null)
|
||||
{
|
||||
logger.Info($"[groupGenerateHandle_Date] 未找到客户信息 - ClientId: {firstTrade.ClientId}");
|
||||
return;
|
||||
}
|
||||
|
||||
var supProtocolDate = client.SupProtocolDate;
|
||||
logger.Info($"[groupGenerateHandle_Date] 客户补充协议日期: {supProtocolDate}");
|
||||
|
||||
var groupDateDouble = trades.Where(x => supProtocolDate == null || x.TradeDate < supProtocolDate).Select(x => x.id).ToList();
|
||||
var groupDateSingle = trades.Where(x => supProtocolDate != null && x.TradeDate >= supProtocolDate).Select(x => x.id).ToList();
|
||||
|
||||
logger.Info($"[groupGenerateHandle_Date] 双章确认书交易数: {groupDateDouble.Count}, 单章确认书交易数: {groupDateSingle.Count}");
|
||||
|
||||
// 单章确认书和双章确认书同时生成要生成两个文件
|
||||
if (groupDateDouble.Any() && groupDateSingle.Any())
|
||||
{
|
||||
logger.Info("[groupGenerateHandle_Date] 同时生成单章和双章确认书");
|
||||
groupGenerateHandle(groupDateDouble, docType, startDate, supProtocolDate.Value.AddDays(-1), results, error, file);
|
||||
groupGenerateHandle(groupDateSingle, docType, supProtocolDate, endDate, results, error, file);
|
||||
}
|
||||
else if (groupDateDouble.Any())
|
||||
{
|
||||
logger.Info("[groupGenerateHandle_Date] 仅生成双章确认书");
|
||||
groupGenerateHandle(groupDateDouble, docType, startDate, endDate, results, error, file);
|
||||
}
|
||||
else if (groupDateSingle.Any())
|
||||
{
|
||||
logger.Info("[groupGenerateHandle_Date] 仅生成单章确认书");
|
||||
groupGenerateHandle(groupDateSingle, docType, startDate, endDate, results, error, file);
|
||||
}
|
||||
else
|
||||
{
|
||||
logger.Info("[groupGenerateHandle_Date] 没有需要生成的确认书");
|
||||
}
|
||||
}
|
||||
|
||||
private void groupGenerateHandle(List<int> ids, string docType, DateTime? startDate, DateTime? endDate, List<TradeDocGenerateResult> results, List<string> error, List<string> file)
|
||||
{
|
||||
var logger = LogFactory.GetLogger("生成确认书");
|
||||
logger.Info($"[groupGenerateHandle] 开始处理 - ids.Count: {ids?.Count ?? 0}, docType: {docType}");
|
||||
|
||||
if (ids == null || !ids.Any())
|
||||
{
|
||||
logger.Info("[groupGenerateHandle] ids 为空,直接返回");
|
||||
return;
|
||||
}
|
||||
|
||||
var trade_contract_r = DbContext.trade_contract_r.Where(c => ids.Contains(c.TradeId) && c.Type == "交易确认书" && c.IsValid).ToList();
|
||||
logger.Info($"[groupGenerateHandle] 找到已存在的确认书记录数: {trade_contract_r.Count}");
|
||||
|
||||
//DbContext.trade_contract_r.RemoveRange(trade_contract_r);
|
||||
trade_contract_r.ForEach(O => O.IsValid = false);
|
||||
DbContext.SaveChanges();
|
||||
|
||||
logger.Info("[groupGenerateHandle] 调用 BatchConfirmationGenerateService.Generate");
|
||||
var result = new BatchConfirmationGenerateService(this).Generate(ids, docType, startDate, endDate);
|
||||
logger.Info($"[groupGenerateHandle] 生成结果 - 成功数: {result.Count(r => string.IsNullOrWhiteSpace(r.ErrorMessage))}, 失败数: {result.Count(r => !string.IsNullOrWhiteSpace(r.ErrorMessage))}");
|
||||
|
||||
results.AddRange(result);
|
||||
error.AddRange(results.Where(n => !string.IsNullOrWhiteSpace(n.ErrorMessage)).Select(n => n.ErrorMessage).ToArray());
|
||||
file.AddRange(results.Where(n => !string.IsNullOrWhiteSpace(n.OutputFilePath)).Select(n => n.OutputFilePath).ToList());
|
||||
|
||||
logger.Info($"[groupGenerateHandle] 完成处理 - 当前总错误数: {error.Count}, 当前总文件数: {file.Count}");
|
||||
}
|
||||
|
||||
public bool GXJY_CorrespondingConfirmationTemplate(List<int> tradeIds, out string ErrMsg)
|
||||
|
||||
Reference in New Issue
Block a user