diff --git a/YLErpDAL/Modules/SwapModule/Dto/RefreshFrozenCashCacheReq.cs b/YLErpDAL/Modules/SwapModule/Dto/RefreshFrozenCashCacheReq.cs new file mode 100644 index 00000000..46c8c0f2 --- /dev/null +++ b/YLErpDAL/Modules/SwapModule/Dto/RefreshFrozenCashCacheReq.cs @@ -0,0 +1,28 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using YLErp.Models; + +namespace YLErp.Modules.SwapModule.Dto +{ + public class RefreshFrozenCashCacheReq + { + public RefreshFrozenCashCacheReq() { } + public RefreshFrozenCashCacheReq(long clientId, List underlyingCodes) + { + this.clientId = clientId; + this.underlyingCodes = underlyingCodes; + } + public long clientId { get; set; } + + public List underlyingCodes { get; set; } + } + + + public class RefreshFrozenCashCacheResp : ApiResponse + { + + } +} diff --git a/YLErpDAL/Modules/SwapModule/SwapTradeAutoService.cs b/YLErpDAL/Modules/SwapModule/SwapTradeAutoService.cs index ad24400f..ae143923 100644 --- a/YLErpDAL/Modules/SwapModule/SwapTradeAutoService.cs +++ b/YLErpDAL/Modules/SwapModule/SwapTradeAutoService.cs @@ -3,10 +3,13 @@ using Confluent.Kafka; using CsvHelper; using Dapper; using DocumentFormat.OpenXml.Drawing; +using DocumentFormat.OpenXml.Spreadsheet; using MoreLinq; using Newtonsoft.Json; using NPOI.SS.Formula.Functions; +using Org.BouncyCastle.Asn1.Ocsp; using Qdp.ComputeServiceV2.Data.CommonModels.TradeInfos; +using Qdp.Foundation.Utilities; using Qdp.Pricing.Base.Enums; using Qdp.Pricing.Base.Implementations; using System.Linq; @@ -26,6 +29,7 @@ using YLErp.Models; using YLErp.Modules.AppModule; using YLErp.Modules.EodModule.QueryModule; using YLErp.Modules.RiskModule; +using YLErp.Modules.SwapModule.Dto; using YLErp.Modules.TradeMsgOutputModule; using YLErp.QdpModule; using static alglib; @@ -461,13 +465,13 @@ namespace YLErp.Modules.SwapModule /// /// /// - public void MergeAvgModeCompose(List mergeList, DateTime valueDate, Action? action) + public Dictionary> MergeAvgModeCompose(List mergeList, DateTime valueDate, Action? action) { var flowquery = mergeList.GroupBy(g => g.ClientId); var flowCount = flowquery.Count(); if (flowCount == 0) { - return; + return null; } var swaptrades = DbContext.trade.Where(t => t.TradeType == "收益互换" && t.TradeDate <= valueDate @@ -479,11 +483,59 @@ namespace YLErp.Modules.SwapModule var floatRatePredicate = PredicateBuilder.Create(x => x.StartDate <= valueDate && x.EndDate >= matuirityDate); var floatRateQuery = DbContext.swap_float_rate.Where(floatRatePredicate); int dealCount = 0; + + Dictionary> clientUmsDic = new Dictionary>(); + foreach (var groupItem in flowquery) { MergeAvgModelItem(groupItem, swaptrades, swapPositions, floatRateQuery, ref dealCount, action); + clientUmsDic.Add(groupItem.Key ?? 0, groupItem.Select(p => p.UnderlyingCode).Distinct().ToList()); } + return clientUmsDic; } + + /// + /// 刷新冻结资金缓存 + /// + /// + public void refreshFrozenCashCache(Dictionary> clientUmsDic) + { + if (clientUmsDic == null || clientUmsDic.Count == 0) + { + return; + } + Task.Run(() => { + try + { + //发送http请求 + var baseUrl = Environment.GetEnvironmentVariable("BondOmsInterface_BaseUrl"); + + if (!string.IsNullOrEmpty(baseUrl)) + { + var httpHelper = new HttpHelper(baseUrl, null); + var url = $"{baseUrl}/riskJob/refreshClientFrozenCash"; + foreach (var item in clientUmsDic) + { + var clientId = item.Key; + var underlyingCodes = item.Value; + //请求参数 + RefreshFrozenCashCacheReq req = new RefreshFrozenCashCacheReq(clientId, underlyingCodes); + // http 请求 Web项目接口 + var result = httpHelper.PostRequestNoAuth(url, req).Result; + if (result != null && !result.success) + { + LogFactory.GetLogger("刷新冻结资金").Info("刷新冻结资金:" + result.message); + } + } + } + } + catch (Exception ex) + { + LogFactory.GetLogger("刷新冻结资金").Error("刷新冻结资金:" + ex.Message); + } + }); + } + public void UpdateSwapFlowState(List swapFlows) { foreach (var item in swapFlows) diff --git a/YLErpWeb/Hubs/SwapFlowCombookingHub.cs b/YLErpWeb/Hubs/SwapFlowCombookingHub.cs index 582786d7..9b3cd3be 100644 --- a/YLErpWeb/Hubs/SwapFlowCombookingHub.cs +++ b/YLErpWeb/Hubs/SwapFlowCombookingHub.cs @@ -75,14 +75,14 @@ namespace YLErp.Web.Hubs 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); - - service.MergeAvgModeCompose(mergeList, req.tradeDate, (dealCount) => + + clientUmsDic = service.MergeAvgModeCompose(mergeList, req.tradeDate, (dealCount) => { currentStep = $"正在合成簿记:{dealCount}/{mergeList.Count}"; client.SendAsync("ReceiveMessage", currentStep); @@ -95,6 +95,7 @@ namespace YLErp.Web.Hubs service.UpdateSwapFlowState(swapFlows); currentStep = "流水簿记完毕"; await client.SendAsync("ProcessCompleted", currentStep); + service.refreshFrozenCashCache(clientUmsDic); isProcessing = false; } catch (Exception ex) diff --git a/YLWinSer/RealTimeCalcPositionService/ClientNoDMABalanceTask.cs b/YLWinSer/RealTimeCalcPositionService/ClientNoDMABalanceTask.cs index 6dd124be..950f9ba3 100644 --- a/YLWinSer/RealTimeCalcPositionService/ClientNoDMABalanceTask.cs +++ b/YLWinSer/RealTimeCalcPositionService/ClientNoDMABalanceTask.cs @@ -81,7 +81,7 @@ namespace RealTimeCalcPositionService if (_yLCache != null) { _yLCache.StringSet("ClientBalance:" + cb.ClientId, obj); - _yLCache.HashSet("risk:cash:balance:amount", cb.ClientId.ToString(), (decimal)obj.AvailableAmount); + _yLCache.HashSet("risk:cash:balance:amount", cb.ClientId.ToString(), (decimal)obj.AvailableMoney); } } catch (Exception ex)