From 7336fdaf7073b4364fca5f16a66d85c887ef221f Mon Sep 17 00:00:00 2001 From: gongpei Date: Fri, 26 Dec 2025 15:46:53 +0800 Subject: [PATCH] =?UTF-8?q?=E5=AE=A2=E6=88=B7=E8=B4=B9=E7=8E=87=E8=B0=83?= =?UTF-8?q?=E6=95=B4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Framework/YLErp.Core/DBModels/SwapRate.cs | 8 ++ .../Modules/SwapModule/SwapRateService.cs | 115 +----------------- YLErpWeb/Controllers/SwapRateController.cs | 23 ++-- 3 files changed, 21 insertions(+), 125 deletions(-) diff --git a/Framework/YLErp.Core/DBModels/SwapRate.cs b/Framework/YLErp.Core/DBModels/SwapRate.cs index 04aa3850..452d1a26 100644 --- a/Framework/YLErp.Core/DBModels/SwapRate.cs +++ b/Framework/YLErp.Core/DBModels/SwapRate.cs @@ -57,6 +57,14 @@ namespace YLErp.DBModels [Column("temp_rate")] [DataChange] public decimal? TempRate { get; set; } + + /// + /// 线下费率 + /// + [DisplayName("线下费率")] + [Column("off_line_rate")] + [DataChange] + public decimal? OffLineRate { get; set; } /// /// 基础费率百分比 diff --git a/YLErpDAL/Modules/SwapModule/SwapRateService.cs b/YLErpDAL/Modules/SwapModule/SwapRateService.cs index 9d2da793..c84a6e24 100644 --- a/YLErpDAL/Modules/SwapModule/SwapRateService.cs +++ b/YLErpDAL/Modules/SwapModule/SwapRateService.cs @@ -14,6 +14,7 @@ using OfficeOpenXml; using YieldChain.Commons; using YLErp.Abstract; using Microsoft.Extensions.DependencyInjection; +using YLErp.Cache; namespace YLErp.Modules.SwapModule { @@ -75,7 +76,7 @@ namespace YLErp.Modules.SwapModule /// /// /// - public void SaveSwapRate(SwapRate req) + public void SaveSwapRate(SwapRate req, IYLCache ylCache) { var changeClient = DataCacheProvider.GetClientDataSource().GetData(req.ClientId); req.ClientNumber = changeClient?.Number; @@ -112,6 +113,9 @@ namespace YLErp.Modules.SwapModule // swapRate.BackDeskChargeIsPercent = req.BackDeskChargeIsPercent; swapRate.OfflineRate = req.OfflineRate; swapRate.SetOpt(UserId, UserName); + + // 盘中修改了阶梯费率,存储到redis中 + ylCache.StringSetWithNoPrefix("TRS:Update:ClientRate:" + swapRate.ClientId, swapRate.id, TimeSpan.FromHours(8)); } else { @@ -357,113 +361,6 @@ namespace YLErp.Modules.SwapModule ExcelPackage.LicenseContext = LicenseContext.NonCommercial; return new ExcelTemplateGenerator().SetTemplateFile(sourceFileName).SetTemplateData(modelDict).Output(); } - /// - /// 将最新的费率发送到kafka - /// - /// - /// - public void SendSwapRateToKafka(int clientId) - { - var swapRate = GetClientSwapRate(clientId); - if (swapRate == null) - { - swapRate = new SwapRate() - { - ClientId = clientId, - }; - } - var monthStart = GetMonthStart(); - var clientPosiNotional = DbContext.trade.Where(x => x.TradeDate >= monthStart - && x.ValidState != ConsGlobal.InValid - && x.TradeType == "收益互换" - && x.ClientId == clientId - && ConsTrade.TradeStatusCustomexport.Contains(x.TradeStatus)).ToList().Sum(s => s.OriginalStockEqvNotional ?? 0); - SendToKafka(swapRate, clientPosiNotional); - } - public void SendAllSwapRateToKafka() - { - var swapRates = DbContext.swap_rate.Where(x => x.TakeEffectDate <= DateTime.Now.Date).ToList().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 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) - { - 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); - } - } - /// - /// 获取月初 - /// - /// - private DateTime GetMonthStart() - { - DateTime currentDate = DateTime.Today; // 获取当前日期(包括当前年月日) - DateTime monthStart = new DateTime(currentDate.Year, currentDate.Month, 1); - return monthStart; - } - private void SendToKafka(SwapRate swapRate, double clientPosiNotional) - { - SwapRateKafkaModel swapRateKafkaModel = new SwapRateKafkaModel(); - swapRateKafkaModel.clientId = swapRate.ClientId; - //swapRateKafkaModel.frontDeskCharge = swapRate.FrontDeskCharge ?? 0; - //swapRateKafkaModel.isFrontDeskChargePercent = swapRate.FrontDeskChargeIsPercent ?? true; - //swapRateKafkaModel.backDeskCharge = swapRate.BackDeskCharge ?? 0; - //swapRateKafkaModel.isBackDeskChargePercent = swapRate.BackDeskChargeIsPercent ?? true; - if (swapRate.TempRate.HasValue) - { - swapRateKafkaModel.isRate = swapRate.TempRateIsPercent; - swapRateKafkaModel.rate = swapRate.TempRate ?? 0; - } - else - { - swapRateKafkaModel.isRate = swapRate.BaseRateIsPercent; - swapRateKafkaModel.rate = swapRate.BaseRate ?? 0; - swapRateKafkaModel.disRateDown = swapRate.DiscountAccDown ?? 0; - if (swapRate.DiscountAccDown.HasValue && Convert.ToDecimal(clientPosiNotional) >= swapRateKafkaModel.disRateDown) - { - swapRateKafkaModel.isDisRate = swapRate.DiscountRateIsPercent; - swapRateKafkaModel.disRate = swapRate.DiscountRate ?? 0; - swapRateKafkaModel.rate = swapRateKafkaModel.disRate; - } - - } - kafkaProduceHelper.Produce(Environment.GetEnvironmentVariable("KafkaConfig_ClientRateTopic"), JsonConvert.SerializeObject(swapRateKafkaModel)); - } - private SwapRate GetClientSwapRate(int clientId) - { - return DbContext.swap_rate.Where(x => x.ClientId == clientId && x.TakeEffectDate <= DateTime.Now.Date).OrderByDescending(o => o.TakeEffectDate).FirstOrDefault(); - } + } } diff --git a/YLErpWeb/Controllers/SwapRateController.cs b/YLErpWeb/Controllers/SwapRateController.cs index 593c9fdb..2a0a70da 100644 --- a/YLErpWeb/Controllers/SwapRateController.cs +++ b/YLErpWeb/Controllers/SwapRateController.cs @@ -1,4 +1,5 @@ using Microsoft.AspNetCore.Authorization; +using YLErp.Cache; using YLErp.Modules.SwapModule; using YLErp.Modules.TradeModule.QueryModule; @@ -6,7 +7,11 @@ namespace YLErp.Web.Controllers { public class SwapRateController : BaseController { - public SwapRateController() { + + private readonly IYLCache _ylCache; + + public SwapRateController(IYLCache ylCache) { + _ylCache = ylCache; } /// /// 互换费率 @@ -78,8 +83,7 @@ namespace YLErp.Web.Controllers public JsonResult SaveSwapRate(SwapRate req) { var service = new SwapRateService(CurUser); - service.SaveSwapRate(req); - service.SendSwapRateToKafka(req.ClientId); + service.SaveSwapRate(req, _ylCache); return JsonSuccess(""); } /// @@ -91,7 +95,6 @@ namespace YLErp.Web.Controllers var intid = DecryptInt(enid); var service = new SwapRateService(CurUser); var clientId= service.DeleteSwapRate(intid); - service.SendSwapRateToKafka(clientId); return JsonSuccess(""); } /// @@ -113,10 +116,6 @@ namespace YLErp.Web.Controllers using var stream = file.OpenReadStream(); var service = new SwapRateService(CurUser); var clientIds= service.ImportSwapRateFromExcel(stream, out var TotalNum, out var SuccessNum); - foreach (var clientId in clientIds) - { - service.SendSwapRateToKafka(clientId); - } return Json(new { success = true, @@ -136,13 +135,5 @@ namespace YLErp.Web.Controllers var bytes = new SwapRateService(CurUser).exprotSwapRateExcel(req); return File(bytes, xlsxMimeType, $"阶梯费率信息_{DateTime.Now:yyyyMMddHHmmss}.xlsx"); } - - [HttpPost] - [AllowAnonymous] - public JsonResult SendToKafka() - { - new SwapRateService(OptUserInfo.SystemUser).SendAllSwapRateToKafka(); - return JsonSuccess(); - } } }