From 21a175d1975264d278d8dd0fd77165f985a45a4b Mon Sep 17 00:00:00 2001 From: Mikhail Kuznetsov Date: Fri, 5 Jul 2024 15:17:48 +1000 Subject: [PATCH] =?UTF-8?q?feat(templateDistributor):=20=D0=BB=D0=BE=D0=B3?= =?UTF-8?q?=D0=B8=D0=BA=D0=B0=20=D1=80=D0=B0=D1=81=D0=BF=D1=80=D0=B5=D0=B4?= =?UTF-8?q?=D0=B5=D0=BB=D0=B5=D0=BD=D0=B8=D1=8F=20=D1=88=D0=B0=D0=B1=D0=BB?= =?UTF-8?q?=D0=BE=D0=BD=D0=BE=D0=B2=20=D0=BF=D0=BE=20=D0=BF=D0=B5=D1=80?= =?UTF-8?q?=D0=B8=D0=BE=D0=B4=D1=83?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../EsppScheduleTransformService.cs | 32 ++- .../IEsppScheduleTransformService.cs | 9 + .../ITemplateDistributor.cs | 2 +- .../MqTemplateDistributor.cs | 70 +++++- .../Services/IValidatorService.cs | 7 + .../Services/ValidatorService.cs | 50 ++++ .../TemplateDistributor.cs | 217 +++++++++++++++++- .../TemplateDistributorInstaller.cs | 2 + 8 files changed, 370 insertions(+), 19 deletions(-) create mode 100644 PARR.TemplateDistributor/Services/IValidatorService.cs create mode 100644 PARR.TemplateDistributor/Services/ValidatorService.cs diff --git a/PARR.DAL/TransformServices/EsppScheduleTransformService.cs b/PARR.DAL/TransformServices/EsppScheduleTransformService.cs index 0f914d81..d33890ef 100644 --- a/PARR.DAL/TransformServices/EsppScheduleTransformService.cs +++ b/PARR.DAL/TransformServices/EsppScheduleTransformService.cs @@ -3,6 +3,7 @@ using PARR.Constants; using PARR.DAL.Contracts; using PARR.DAL.DomainModels; using PARR.DAL.Extensions; +using PARR.DAL.Models; using PARR.DAL.Services.Interfaces; namespace PARR.DAL.TransformServices @@ -10,6 +11,7 @@ namespace PARR.DAL.TransformServices internal class EsppScheduleTransformService : IEsppScheduleTransformService { private readonly IEsppSchTypeConfigService esppSchTypeConfigService; + private readonly IApplicationsInWorkService applicationsInWorkService; private readonly ILogger logger; private readonly Dictionary monthDict = new Dictionary() @@ -49,11 +51,14 @@ namespace PARR.DAL.TransformServices }; public EsppScheduleTransformService( + ILogger logger, IEsppSchTypeConfigService esppSchTypeConfigService, - ILogger logger + IApplicationsInWorkService applicationsInWorkService + ) { this.esppSchTypeConfigService = esppSchTypeConfigService; + this.applicationsInWorkService = applicationsInWorkService; this.logger = logger; } @@ -130,7 +135,9 @@ namespace PARR.DAL.TransformServices public async Task GetNextDateAsync(Guid applicationInWorkId, DateTimeOffset lastRun) { - return GetNextDate(await GetEsppScheduleAsync(applicationInWorkId), lastRun); + var esppSchedule = await GetEsppScheduleAsync(applicationInWorkId); + + return GetNextDate(esppSchedule, lastRun); } @@ -337,10 +344,6 @@ namespace PARR.DAL.TransformServices case (DistributionPeriodTypeEnum.Year): return lastRun.AddYears(ParseInt(distributionPeriod)); - - //case (DistributionPeriodTypeEnum.TimeSpan): - // var timeSpan = ParseTimeSpan(distributionPeriod); - // return timeSpan.Days > 0 ? startPeriod.AddDays(); } @@ -348,6 +351,23 @@ namespace PARR.DAL.TransformServices return lastRun; } + public async Task GetStartPeriodForDateAsync(Guid applicationInWorkId, DateTimeOffset date, DateTimeOffset refrenceDate, DistributionPeriodTypeEnum periodType, string distributionPeriod) + { + + var esppSchedule = await GetEsppScheduleAsync(applicationInWorkId); + + var currentStartPeriod = refrenceDate; + var currentEndPeriod = GetNextDateForDistributionRun(currentStartPeriod,periodType,distributionPeriod); + + while (!(date>=currentStartPeriod && date< currentEndPeriod)) + { + currentStartPeriod = currentEndPeriod; + currentEndPeriod = GetNextDateForDistributionRun(currentStartPeriod, periodType, distributionPeriod); + } + + return DateOnly.FromDateTime(currentStartPeriod.DateTime); + } + private int ParseInt(string value) { diff --git a/PARR.DAL/TransformServices/IEsppScheduleTransformService.cs b/PARR.DAL/TransformServices/IEsppScheduleTransformService.cs index b548d806..604309a9 100644 --- a/PARR.DAL/TransformServices/IEsppScheduleTransformService.cs +++ b/PARR.DAL/TransformServices/IEsppScheduleTransformService.cs @@ -49,5 +49,14 @@ namespace PARR.DAL.TransformServices /// /// DateTimeOffset GetNextDateForDistributionRun(DateTimeOffset lastRun, DistributionPeriodTypeEnum periodType, string distributionPeriod); + + + /// + /// Получить дату начала периода распределения относительно опорной даты (Reference Date) + /// + /// + /// + /// + Task GetStartPeriodForDateAsync(Guid applicationInWorkId, DateTimeOffset date, DateTimeOffset refrenceDate, DistributionPeriodTypeEnum periodType, string distributionPeriod); } } diff --git a/PARR.TemplateDistributor/ITemplateDistributor.cs b/PARR.TemplateDistributor/ITemplateDistributor.cs index ceacc2a3..c28dd8ac 100644 --- a/PARR.TemplateDistributor/ITemplateDistributor.cs +++ b/PARR.TemplateDistributor/ITemplateDistributor.cs @@ -10,7 +10,7 @@ namespace PARR.TemplateDistributor /// /// /// - Task> DistributeTemplateAsync(List