From 9f47caa3ed1a3a434c389e3dfb2afcf4b7ae72c0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=90=B4=E6=96=B9=E6=B5=B7?= Date: Wed, 23 Apr 2025 13:58:26 +0800 Subject: [PATCH] =?UTF-8?q?bug=E4=BF=AE=E5=A4=8D?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- YLErpDAL/BLL/EodSettlement/RealtimePnlCalc.cs | 4 +- .../ClientCashInCashOutDataService.cs | 4 ++ .../Modules/SwapModule/SwapDealService.cs | 2 +- .../Modules/SwapModule/SwapRateService.cs | 43 ++++++++++++++++--- YLErpWeb/Controllers/SwapRateController.cs | 5 +-- YLErpWeb/appsettings.dev.json | 2 +- YLErpWeb/appsettings.local.json | 2 +- .../Scripts/app/swaptrade/swapTradeEdit.js | 2 +- 8 files changed, 47 insertions(+), 17 deletions(-) diff --git a/YLErpDAL/BLL/EodSettlement/RealtimePnlCalc.cs b/YLErpDAL/BLL/EodSettlement/RealtimePnlCalc.cs index 31b7413c..51924251 100644 --- a/YLErpDAL/BLL/EodSettlement/RealtimePnlCalc.cs +++ b/YLErpDAL/BLL/EodSettlement/RealtimePnlCalc.cs @@ -563,14 +563,14 @@ namespace YLErp.BLL.Eod var multiplier = ConsGlobal.InstrumentType.IsBond(lastPosi.UnderlyingInstrumentType) ? ConsGlobal.bondShowPriceMultiple : 1; // 计算加权平均价格(区分债券和非债券) - var weightedPrice = positionGroupItems + var weightedPrice = posiQty==0?0: positionGroupItems .Sum(s => { decimal price = ConsGlobal.InstrumentType.IsBond(lastPosi.UnderlyingInstrumentType) ? s.PosiGrossPrice * ConsGlobal.bondShowPriceMultiple : s.PosiGrossPrice; return s.PosiQuantity * price; }) / posiQty; - var weightedNetPrice = positionGroupItems + var weightedNetPrice = posiQty==0?0: positionGroupItems .Sum(s => { decimal price = ConsGlobal.InstrumentType.IsBond(lastPosi.UnderlyingInstrumentType) ? s.PosiNetPrice * ConsGlobal.bondShowPriceMultiple diff --git a/YLErpDAL/Modules/ClientModule/ClientCashInCashOutDataService.cs b/YLErpDAL/Modules/ClientModule/ClientCashInCashOutDataService.cs index 6be1294f..cb899926 100644 --- a/YLErpDAL/Modules/ClientModule/ClientCashInCashOutDataService.cs +++ b/YLErpDAL/Modules/ClientModule/ClientCashInCashOutDataService.cs @@ -676,6 +676,10 @@ namespace YLErp.Modules.ClientModule // 出金金额小于等于 追保账户金额 r.cash_type = CashTypeEnum.追保账户.ToString(); } + else if (clientbalance.VmFundSum==0) + { + r.cash_type = CashTypeEnum.初保账户.ToString(); + } else { // 出金金额大于 追保账户金额,首先处理 VM 部分 diff --git a/YLErpDAL/Modules/SwapModule/SwapDealService.cs b/YLErpDAL/Modules/SwapModule/SwapDealService.cs index f3345033..0ef903a5 100644 --- a/YLErpDAL/Modules/SwapModule/SwapDealService.cs +++ b/YLErpDAL/Modules/SwapModule/SwapDealService.cs @@ -775,7 +775,7 @@ namespace YLErp.Modules.SwapModule DealFloatPosition(unwindData); var flowList = new List(unwindData.FlowEvents); var eventId = SaveSwapDeal(unwindData, (int)SwapEventTypeEnum.平仓, clientCashId, "系统操作_平仓"); - if (unwindData.CloseMethod == (int)CloseMethodEnum.全部平仓) + if (unwindData.CloseMethod == (int)CloseMethodEnum.全部平仓|| unwindData.ClosePercent==1) { td.TradeStatus = "已平仓"; td.trade_extend = DbContext.trade_extend.FirstOrDefault(x => x.TradeId == td.id); diff --git a/YLErpDAL/Modules/SwapModule/SwapRateService.cs b/YLErpDAL/Modules/SwapModule/SwapRateService.cs index 3b6ac440..0f07b55a 100644 --- a/YLErpDAL/Modules/SwapModule/SwapRateService.cs +++ b/YLErpDAL/Modules/SwapModule/SwapRateService.cs @@ -381,15 +381,44 @@ namespace YLErp.Modules.SwapModule public void SendAllSwapRateToKafka() { var swapRates = DbContext.swap_rate.Where(x => x.TakeEffectDate <= DateTime.Now.Date).GroupBy(g => g.ClientId).Select(g => g.OrderByDescending(o => o.TakeEffectDate).FirstOrDefault()).ToList(); + var swapRateAll = DbContext.swap_rate + .Where(x => x.ClientId == 0 && x.TakeEffectDate <= DateTime.Now.Date) + .OrderByDescending(o => o.TakeEffectDate) + .FirstOrDefault(); var monthStart = GetMonthStart(); - var posiNotionalValueGroup = DbContext.trade.Where(x => x.TradeDate >= monthStart - && x.ValidState != ConsGlobal.InValid - && x.TradeType == "收益互换" - && ConsTrade.TradeStatusCustomexport.Contains(x.TradeStatus)).ToList().GroupBy(x => x.ClientId); - foreach (var swapRate in swapRates) + // 预计算客户持仓总额(在数据库端完成聚合) + var posiNotionalValues = DbContext.trade + .Where(x => x.TradeDate >= monthStart && + x.ValidState != ConsGlobal.InValid && + x.TradeType == "收益互换" && + ConsTrade.TradeStatusCustomexport.Contains(x.TradeStatus)) + .GroupBy(x => x.ClientId) + .Select(g => new + { + ClientId = g.Key, + Total = g.Sum(s => s.OriginalStockEqvNotional ?? 0) + }) + .AsNoTracking() + .ToDictionary(x => x.ClientId, x => x.Total); + using ClientDBContext clientDBContext = new ClientDBContext(); + var clients = clientDBContext.client.Where(x => x.ProcessStatus == "已开户").AsQueryable().ToList(); + foreach (var client in clients) { - var clientPosiNotional = posiNotionalValueGroup.FirstOrDefault(x => x.Key == swapRate.ClientId).ToList().Sum(s => s.OriginalStockEqvNotional ?? 0); - SendToKafka(swapRate, clientPosiNotional); + SwapRate swapRate = swapRates.FirstOrDefault(s => s.ClientId == client.id); + if (swapRate == null) + { + swapRate = swapRateAll; + } + if (swapRate == null) + { + swapRate = new SwapRate() { ClientId = client.id }; + } + else + { + swapRate.ClientId= client.id; + } + posiNotionalValues.TryGetValue(client.id, out var clientPosiNotional); + SendToKafka(swapRate,clientPosiNotional); } } /// diff --git a/YLErpWeb/Controllers/SwapRateController.cs b/YLErpWeb/Controllers/SwapRateController.cs index e73cc700..593c9fdb 100644 --- a/YLErpWeb/Controllers/SwapRateController.cs +++ b/YLErpWeb/Controllers/SwapRateController.cs @@ -141,10 +141,7 @@ namespace YLErp.Web.Controllers [AllowAnonymous] public JsonResult SendToKafka() { - Task.Run(() => - { - new SwapRateService(OptUserInfo.SystemUser).SendAllSwapRateToKafka(); - }); + new SwapRateService(OptUserInfo.SystemUser).SendAllSwapRateToKafka(); return JsonSuccess(); } } diff --git a/YLErpWeb/appsettings.dev.json b/YLErpWeb/appsettings.dev.json index be4b20ce..8d34d9d8 100644 --- a/YLErpWeb/appsettings.dev.json +++ b/YLErpWeb/appsettings.dev.json @@ -28,7 +28,7 @@ } }, "KafkaConfig": { - "BootstrapServers": "122.112.205.57:9092", // Kafka 集群的地址 + "BootstrapServers": "139.196.109.225:9092", // Kafka 集群的地址 "Acks": -1, // 消息确认方式,可以是 All(-1)、Leader(1)、None(0) 中的一种 "EnableIdempotence": false, // 开启幂等性,确保消息只被发送一次 "MaxInFlight": 5, // 控制生产者在同一时间最多可以发送的未确认消息数 diff --git a/YLErpWeb/appsettings.local.json b/YLErpWeb/appsettings.local.json index 308bb4f5..2d971f10 100644 --- a/YLErpWeb/appsettings.local.json +++ b/YLErpWeb/appsettings.local.json @@ -28,7 +28,7 @@ } }, "KafkaConfig": { - "BootstrapServers": "122.112.205.57:9092", // Kafka 集群的地址 + "BootstrapServers": "139.196.109.225:9092", // Kafka 集群的地址 "Acks": -1, // 消息确认方式,可以是 All(-1)、Leader(1)、None(0) 中的一种 "EnableAutoCommit": false, //是否自动提交 "EnableIdempotence": false, // 开启幂等性,确保消息只被发送一次 diff --git a/YLErpWeb/wwwroot/Scripts/app/swaptrade/swapTradeEdit.js b/YLErpWeb/wwwroot/Scripts/app/swaptrade/swapTradeEdit.js index eb68b66a..6f033b4e 100644 --- a/YLErpWeb/wwwroot/Scripts/app/swaptrade/swapTradeEdit.js +++ b/YLErpWeb/wwwroot/Scripts/app/swaptrade/swapTradeEdit.js @@ -344,7 +344,7 @@ const vue = new Vue({ } x.SwapIntervalList.push(interval); } - if (x.InterestType == 1 && item.interest_rest_days<0) { + if (x.InterestType == 1 && x.interest_rest_days<0) { main.message("利息端第" + (index + 1) + "重置频率必须大于0"); errorcount++; return false;