From 134ae985f7c6bb2ec8cbcf7b329f04510185b8e1 Mon Sep 17 00:00:00 2001 From: yexuzhong <120511780@qq.com> Date: Thu, 11 Sep 2025 14:18:51 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E6=94=B9=20=E5=88=A0=E9=99=A4=20=20?= =?UTF-8?q?=E5=AF=BC=E5=85=A5=20=E6=B5=81=E6=B0=B4=20=20=E6=9B=B4=E6=96=B0?= =?UTF-8?q?=E9=A3=8E=E6=8E=A7=E7=BC=93=E5=AD=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Modules/SwapModule/RiskCacheService.cs | 57 +++++++++++++++++++ .../SwapModule/SwapFlowImportService.cs | 13 +++++ .../Modules/SwapModule/SwapFlowService.cs | 7 +++ .../SwapModule/SwapTradeAutoService.cs | 42 +------------- YLErpWeb/Hubs/SwapFlowCombookingHub.cs | 2 +- YLErpWeb/Hubs/SwapFlowResetHub.cs | 2 +- 6 files changed, 80 insertions(+), 43 deletions(-) create mode 100644 YLErpDAL/Modules/SwapModule/RiskCacheService.cs diff --git a/YLErpDAL/Modules/SwapModule/RiskCacheService.cs b/YLErpDAL/Modules/SwapModule/RiskCacheService.cs new file mode 100644 index 00000000..a41051e6 --- /dev/null +++ b/YLErpDAL/Modules/SwapModule/RiskCacheService.cs @@ -0,0 +1,57 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using YLErp.Helpers; +using YLErp.Modules.SwapModule.Dto; + +namespace YLErp.Modules.SwapModule +{ + public class RiskCacheService + { + public RiskCacheService() { } + + /// + /// 刷新风控缓存 + /// + /// + public void refreshRiskCache(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/refreshClientRiskCache"; + 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); + } + }); + } + } +} diff --git a/YLErpDAL/Modules/SwapModule/SwapFlowImportService.cs b/YLErpDAL/Modules/SwapModule/SwapFlowImportService.cs index 5a39abbe..3246277b 100644 --- a/YLErpDAL/Modules/SwapModule/SwapFlowImportService.cs +++ b/YLErpDAL/Modules/SwapModule/SwapFlowImportService.cs @@ -79,6 +79,7 @@ namespace YLErp.Modules.SwapModule var reader = new DataRowReaderHelper(table); rowIndex = 1; totalNum = table.Rows.Count - rowIndex; + Dictionary> clientUmsDic = new Dictionary>(); foreach (var row in table.Rows.Cast().Skip(rowIndex)) { rowIndex++; @@ -134,6 +135,17 @@ namespace YLErp.Modules.SwapModule swap_flow.OptName = UserName; swap_flow.OptTime = DateTime.Now; DbContext.swap_flow.Add(swap_flow); + if (!clientUmsDic.ContainsKey(swap_flow.ClientId ?? 0)) + { + clientUmsDic.Add(swap_flow.ClientId ?? 0, new List { swap_flow.UnderlyingCode }); + } + else + { + if (!clientUmsDic[swap_flow.ClientId ?? 0].Contains(swap_flow.UnderlyingCode)) + { + clientUmsDic[swap_flow.ClientId ?? 0].Add(swap_flow.UnderlyingCode); + } + } successNum++; } DbContext.SaveChanges(); @@ -141,6 +153,7 @@ namespace YLErp.Modules.SwapModule { RealtimePnlCalc.RealtimeSwapPosition(new OptUserInfo(0, "互换实时持仓服务", OptUserFrom.Service)); }); + new RiskCacheService().refreshRiskCache(clientUmsDic); } catch (Exception ex) { diff --git a/YLErpDAL/Modules/SwapModule/SwapFlowService.cs b/YLErpDAL/Modules/SwapModule/SwapFlowService.cs index dff60649..7f10aabe 100644 --- a/YLErpDAL/Modules/SwapModule/SwapFlowService.cs +++ b/YLErpDAL/Modules/SwapModule/SwapFlowService.cs @@ -484,6 +484,10 @@ namespace YLErp.Modules.SwapModule RealtimePnlCalc.RealtimeSwapPosition(new OptUserInfo(0, "互换实时持仓服务", OptUserFrom.Service)); }); DbContext.SaveChanges(); + + Dictionary> clientUmsDic = new Dictionary>(); + clientUmsDic.Add(swap_Flow.ClientId ?? 0, new List { swap_Flow.UnderlyingCode }); + new RiskCacheService().refreshRiskCache(clientUmsDic); } /// @@ -554,6 +558,9 @@ namespace YLErp.Modules.SwapModule { RealtimePnlCalc.RealtimeSwapPosition(new OptUserInfo(0, "互换实时持仓服务", OptUserFrom.Service)); }); + Dictionary> clientUmsDic = new Dictionary>(); + clientUmsDic.Add(capitalAccount.ClientId ?? 0, new List { capitalAccount.UnderlyingCode }); + new RiskCacheService().refreshRiskCache(clientUmsDic); } /// /// 删除流水 diff --git a/YLErpDAL/Modules/SwapModule/SwapTradeAutoService.cs b/YLErpDAL/Modules/SwapModule/SwapTradeAutoService.cs index 479d5c39..b3966c9a 100644 --- a/YLErpDAL/Modules/SwapModule/SwapTradeAutoService.cs +++ b/YLErpDAL/Modules/SwapModule/SwapTradeAutoService.cs @@ -502,47 +502,7 @@ namespace YLErp.Modules.SwapModule 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) { diff --git a/YLErpWeb/Hubs/SwapFlowCombookingHub.cs b/YLErpWeb/Hubs/SwapFlowCombookingHub.cs index 9b3cd3be..3183b55b 100644 --- a/YLErpWeb/Hubs/SwapFlowCombookingHub.cs +++ b/YLErpWeb/Hubs/SwapFlowCombookingHub.cs @@ -95,7 +95,7 @@ namespace YLErp.Web.Hubs service.UpdateSwapFlowState(swapFlows); currentStep = "流水簿记完毕"; await client.SendAsync("ProcessCompleted", currentStep); - service.refreshFrozenCashCache(clientUmsDic); + new RiskCacheService().refreshRiskCache(clientUmsDic); isProcessing = false; } catch (Exception ex) diff --git a/YLErpWeb/Hubs/SwapFlowResetHub.cs b/YLErpWeb/Hubs/SwapFlowResetHub.cs index db5474f6..3328d068 100644 --- a/YLErpWeb/Hubs/SwapFlowResetHub.cs +++ b/YLErpWeb/Hubs/SwapFlowResetHub.cs @@ -54,7 +54,7 @@ namespace YLErp.Web.Hubs }, tradeIds); isProcessing = false; await client.SendAsync("ProcessCompleted", ""); - service.refreshFrozenCashCache(clientUmsDic); + new RiskCacheService().refreshRiskCache(clientUmsDic); } catch (Exception ex) {