From 613d4cb4f4bb32d1347d5937017c7d7b797f4c4c Mon Sep 17 00:00:00 2001 From: Mikhail Trubnikov Date: Thu, 28 May 2026 15:50:14 +1000 Subject: [PATCH] =?UTF-8?q?feat(api,core,domain):=20=D0=9A=D0=BB=D1=8E?= =?UTF-8?q?=D1=87=D0=B8=20=D0=B4=D0=BB=D1=8F=20=D1=80=D0=B5=D0=B4=D0=B8?= =?UTF-8?q?=D1=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../StatResponseAreaWorkLoadController.cs | 8 +- .../StatWorkGroupWorkLoadController.cs | 6 +- .../Statistics/StatWorkWorkLoadController.cs | 6 +- PARR.API/Controllers/V1/TestController.cs | 25 ++- PARR.API/Installers/ApiServicesInstaller.cs | 1 - .../Services/Implementations/AuthService.cs | 7 +- .../Implementations/WorkLoadService.cs | 80 --------- .../Services/Interfaces/IWorkLoadService.cs | 15 -- .../Implementations/WorkloadCacheService.cs | 92 ++++++----- PARR.Domain/Cache/CacheKeys.cs | 156 ++++++++++++++++++ .../Redis/RedisCacheService.cs | 3 +- PARR.Test/Worker.cs | 1 + 12 files changed, 251 insertions(+), 149 deletions(-) delete mode 100644 PARR.API/Services/Implementations/WorkLoadService.cs delete mode 100644 PARR.API/Services/Interfaces/IWorkLoadService.cs create mode 100644 PARR.Domain/Cache/CacheKeys.cs diff --git a/PARR.API/Controllers/V1/Statistics/StatResponseAreaWorkLoadController.cs b/PARR.API/Controllers/V1/Statistics/StatResponseAreaWorkLoadController.cs index a18c7e65..1f676195 100644 --- a/PARR.API/Controllers/V1/Statistics/StatResponseAreaWorkLoadController.cs +++ b/PARR.API/Controllers/V1/Statistics/StatResponseAreaWorkLoadController.cs @@ -24,19 +24,19 @@ namespace PARR.API.Controllers.V1.Statistics private readonly ITemplateRepository templateService; //private readonly IResponseAreaService responseAreaService; private readonly IMapper mapper; - private readonly IWorkLoadService workLoadService; + //private readonly IWorkLoadService workLoadService; public StatResponseAreaWorkLoadController( ITemplateRepository templateService, //IResponseAreaService responseAreaService, - IMapper mapper, - IWorkLoadService workLoadService + IMapper mapper + //IWorkLoadService workLoadService ) { this.templateService = templateService; //this.responseAreaService = responseAreaService; this.mapper = mapper; - this.workLoadService = workLoadService; + //this.workLoadService = workLoadService; } diff --git a/PARR.API/Controllers/V1/Statistics/StatWorkGroupWorkLoadController.cs b/PARR.API/Controllers/V1/Statistics/StatWorkGroupWorkLoadController.cs index 384c54ad..9fe2a151 100644 --- a/PARR.API/Controllers/V1/Statistics/StatWorkGroupWorkLoadController.cs +++ b/PARR.API/Controllers/V1/Statistics/StatWorkGroupWorkLoadController.cs @@ -19,21 +19,21 @@ namespace PARR.API.Controllers.V1.Statistics public class StatWorkGroupWorkLoadController : BaseApiController { private readonly ITemplateRepository templateService; - private readonly IWorkLoadService workLoadService; + //private readonly IWorkLoadService workLoadService; //private readonly IWorkGroupService workGroupService; private readonly IMapper mapper; private readonly ILogger logger; public StatWorkGroupWorkLoadController( ITemplateRepository templateService, - IWorkLoadService workLoadService, + //IWorkLoadService workLoadService, //IWorkGroupService workGroupService, IMapper mapper, ILogger logger ) { this.templateService = templateService; - this.workLoadService = workLoadService; + //this.workLoadService = workLoadService; //this.workGroupService = workGroupService; this.mapper = mapper; this.logger = logger; diff --git a/PARR.API/Controllers/V1/Statistics/StatWorkWorkLoadController.cs b/PARR.API/Controllers/V1/Statistics/StatWorkWorkLoadController.cs index 3cac498b..c051499e 100644 --- a/PARR.API/Controllers/V1/Statistics/StatWorkWorkLoadController.cs +++ b/PARR.API/Controllers/V1/Statistics/StatWorkWorkLoadController.cs @@ -11,21 +11,21 @@ namespace PARR.API.Controllers.V1.Statistics public class StatWorkWorkLoadController : BaseApiController { private readonly ITemplateRepository templateService; - private readonly IWorkLoadService workLoadService; + //private readonly IWorkLoadService workLoadService; private readonly IMapper mapper; private readonly ILogger logger; //private readonly IWorkGroupService workGroupService; public StatWorkWorkLoadController( ITemplateRepository templateService, - IWorkLoadService workLoadService, + //IWorkLoadService workLoadService, IMapper mapper, ILogger logger //IWorkGroupService workGroupService ) { this.templateService = templateService; - this.workLoadService = workLoadService; + //this.workLoadService = workLoadService; this.mapper = mapper; this.logger = logger; //this.workGroupService = workGroupService; diff --git a/PARR.API/Controllers/V1/TestController.cs b/PARR.API/Controllers/V1/TestController.cs index c2d75ce2..886d5c13 100644 --- a/PARR.API/Controllers/V1/TestController.cs +++ b/PARR.API/Controllers/V1/TestController.cs @@ -9,6 +9,7 @@ using PARR.Core.Common.Interfaces; using PARR.Core.Repositories.Interfaces; using PARR.Core.Services.NextRunServices; using PARR.Core.Services.Workload.Implementations; +using PARR.Domain.Cache; namespace PARR.API.Controllers.V1 { @@ -20,6 +21,7 @@ namespace PARR.API.Controllers.V1 private readonly INextRunService nextRunService; private readonly ITemplateRepository templateService; private readonly WorkloadCacheService workloadCacheService; + private readonly ILogger logger; public TestController( IClientService clientService, @@ -27,7 +29,8 @@ namespace PARR.API.Controllers.V1 INextRunService nextRunService, ITemplateRepository templateService, MqSettings mqSettings, - WorkloadCacheService workloadCacheService + WorkloadCacheService workloadCacheService, + ILogger logger ) { this.clientService = clientService; @@ -35,6 +38,7 @@ namespace PARR.API.Controllers.V1 this.nextRunService = nextRunService; this.templateService = templateService; this.workloadCacheService = workloadCacheService; + this.logger = logger; } @@ -78,8 +82,25 @@ namespace PARR.API.Controllers.V1 [HttpPost(ApiRoutes.Test.CreateCache)] public async Task CreateCache() { + #region Test bucket id - // var aaa = await workloadCacheService.GetTemplateReportDataAsync(); + var idList = new List(); + + for (int i = 0; i < 100; i++) + idList.Add( Guid.NewGuid()); + + foreach(var id in idList.OrderBy(t => t)) + { + var key = CacheKeys.Unit.UnitHashWithBucket(id); + var redisKey = redisCacheService.GetKey(key); + + logger.LogDebug("Id: {Id}, key: '{Key}', redis key: '{RedisKey}'", id, key, redisKey); + } + + #endregion + + + // var aaa = await workloadCacheService.GetTemplateReportDataAsync(); //var val = await redisCacheService.GetCachedDataAsync("96dAoIH/8Q9Bg8VY"); diff --git a/PARR.API/Installers/ApiServicesInstaller.cs b/PARR.API/Installers/ApiServicesInstaller.cs index 4e8a548c..321bbdc6 100644 --- a/PARR.API/Installers/ApiServicesInstaller.cs +++ b/PARR.API/Installers/ApiServicesInstaller.cs @@ -21,7 +21,6 @@ namespace PARR.API.Installers services.AddTransient(); services.AddTransient(); - services.AddTransient(); } diff --git a/PARR.API/Services/Implementations/AuthService.cs b/PARR.API/Services/Implementations/AuthService.cs index 0c47daf4..f6405247 100644 --- a/PARR.API/Services/Implementations/AuthService.cs +++ b/PARR.API/Services/Implementations/AuthService.cs @@ -6,6 +6,7 @@ using PARR.API.Settings; using PARR.Core.Common.Interfaces; using PARR.Core.Repositories.Interfaces; using PARR.Core.Repositories.Interfaces.Unit; +using PARR.Domain.Cache; using PARR.Domain.Common.Roles; using PARR.Domain.Settings; @@ -162,13 +163,15 @@ namespace PARR.API.Services.Implementations private string GetBlockKey(string ipAddress) { // d - deny - return $"d_{ipAddress}"; + //return $"d_{ipAddress}"; + return cacheService.GetKey(CacheKeys.UserAuth.Banned(ipAddress)); } private string GetAllowKey(string ipAddress) { // a - allow - return $"a_{ipAddress}"; + //return $"a_{ipAddress}"; + return cacheService.GetKey(CacheKeys.UserAuth.Session(ipAddress)); } diff --git a/PARR.API/Services/Implementations/WorkLoadService.cs b/PARR.API/Services/Implementations/WorkLoadService.cs deleted file mode 100644 index cad7157b..00000000 --- a/PARR.API/Services/Implementations/WorkLoadService.cs +++ /dev/null @@ -1,80 +0,0 @@ -using PARR.API.Services.Interfaces; - -namespace PARR.API.Services.Implementations -{ - internal class WorkLoadService : IWorkLoadService - { - //private readonly ICalendarService calendarService; - - //public WorkLoadService(ICalendarService calendarService) - //{ - // this.calendarService = calendarService; - //} - - //private DateTime GetStartDate(int timeZoneOffsetHours) - //{ - // //(так уже не делаем) начинаем не с сегодняшнего дня, а с завтра, так как на сегодня уже некоторые работы были проведены и их дата изменилась - // //return DateTimeOffset.UtcNow.AddHours(timeZoneOffsetHours).Date.AddDays(1); - - // var dateWithTimeZoneOffset = calendarService.GetDateWithTimeZoneOffset(DateTimeOffset.UtcNow, timeZoneOffsetHours); - // //var dateWithAddDays = dateWithTimeZoneOffset.DateTime.AddDays(1); - // var dateWithAddDays = dateWithTimeZoneOffset.DateTime.AddDays(0); - - // //var bbb = dateWithTimeZoneOffset.DateTime.AddDays(1); - - // //return calendarService.GetDateWithTimeZoneOffset(DateTimeOffset.UtcNow, timeZoneOffsetHours).UtcDateTime.AddDays(1); - // return dateWithAddDays; - //} - - - //private DateTime GetEndDate(bool? isMonth, int timeZoneOffsetHours) - //{ - // var startDate = GetStartDate(timeZoneOffsetHours); - - // return isMonth == true ? startDate.AddDays(30) : startDate.AddDays(6); - //} - - - //public List GetDatesForPeriod(WorkloadBaseQuery requestQuery) - //{ - // var startDate = GetStartDate(requestQuery.TimeZoneOffsetHours); - // var endDate = GetEndDate(requestQuery.IsMonth, requestQuery.TimeZoneOffsetHours); - - // //var daysList = new List(); - - // //daysList.Add(new DateTimeOffset(startDate, new TimeSpan(0))); - - // //while (daysList.Last() < endDate) - // // daysList.Add(daysList.Last().AddDays(1)); - - // //return daysList.OrderBy(t => t).ToList(); - - // //var aaa = DateOnly.FromDateTime(startDate); - - // return calendarService.GetDatesForPeriod(DateOnly.FromDateTime(startDate), DateOnly.FromDateTime(endDate)); - //} - - - //public IQueryable