using Autofac.Core; using Confluent.Kafka; using CsvHelper; using DocumentFormat.OpenXml.InkML; using DocumentFormat.OpenXml.Spreadsheet; using Microsoft.AspNetCore.SignalR; using Qdp.Pricing.Base.Enums; using YLErp.DBModels; using YLErp.Modules.SwapModule; namespace YLErp.Web.Hubs { /// /// 流水簿记hub /// public class SwapFlowCombookingHub : Hub { private static bool isProcessing = false; private static string currentStep = null; protected static IYcLogger Log = LogFactory.GetLogger(typeof(SwapFlowCombookingHub).FullName); public async Task StartProcessing( string jsonString) { SwpFlowCombookingReq req = JsonHelper.Deserialize(jsonString); var connectionId = Context.ConnectionId; var client = Clients.Client(connectionId); if (Context.User==null) { await client.SendAsync("ExceptionMessage", "登录已失效,请重新登录"); return; } var user= Server.CacheProvider.Get("loginUser^" + Context.User.GetUserId()) as UserInfo; if (user == null) { await client.SendAsync("ExceptionMessage", "登录已失效,请重新登录"); return; } //if (req.flowIds == null || req.flowIds.Count == 0) //{ // await client.SendAsync("ExceptionMessage", "未选择任何流水"); // return; //} var service = new SwapTradeAutoService(user); if (isProcessing) { await client.SendAsync("ReceiveMessage", "已有流水正在合成簿记,请稍后再试"); return; } try { isProcessing = true; var swapFlows = service.GetFlows(req.tradeDate); if (swapFlows.Count == 0) { isProcessing = false; await client.SendAsync("ProcessCompleted", $"没有需要合成的流水"); return; } currentStep = "正在合成流水"; await client.SendAsync("ReceiveMessage", currentStep); var mergeList = service.SummaryFlow(swapFlows, req.tradeDate, callback: async (str) => { await client.SendAsync("WarnMessage", str); }); // 数据校验逻辑 currentStep = "校验上一日是否收盘"; await client.SendAsync("ReceiveMessage", currentStep); // 数据校验逻辑 currentStep = "校验FR007数据"; await client.SendAsync("ReceiveMessage", currentStep); //检验FR007 service.CheckFR007Data(req.tradeDate); service.CheckTradEods(req.tradeDate, mergeList); //currentStep = "检测当前日期是否已经流水合成簿记"; //service.CheckBookByDate(tradeDate); currentStep = "校验簿记前置条件"; await client.SendAsync("ReceiveMessage", currentStep); service.BookingValidate(mergeList, req.tradeDate); currentStep = "正在合成簿记"; await client.SendAsync("ReceiveMessage", currentStep); //var dmaFlows = swapFlows.Where(x => dmaClientIds.Contains(x.ClientId)).ToList(); Dictionary> clientUmsDic = null; #region DMA合成持仓 if (mergeList.Count > 0) { currentStep = $"正在合成簿记:共{mergeList.Count}条合成流水"; await client.SendAsync("ReceiveMessage", currentStep); clientUmsDic = service.MergeAvgModeCompose(mergeList, req.tradeDate, (dealCount) => { currentStep = $"正在合成簿记:{dealCount}/{mergeList.Count}"; client.SendAsync("ReceiveMessage", currentStep); }); currentStep = "簿记合成完毕"; await client.SendAsync("ReceiveMessage", currentStep); } #endregion service.UpdateRiskCheckLog(swapFlows, mergeList); service.UpdateSwapFlowState(swapFlows); currentStep = "流水簿记完毕"; await client.SendAsync("ProcessCompleted", currentStep); new RiskCacheService().refreshRiskCache(clientUmsDic); isProcessing = false; } catch (Exception ex) { Log.Error("成交簿记报错",ex); isProcessing = false; await client.SendAsync("ExceptionMessage", ex.Message); } } } }