From 96d0c999abce9e01dca724e52e45e56f4718bde7 Mon Sep 17 00:00:00 2001 From: Mikhail Kuznetsov Date: Thu, 11 Jul 2024 14:42:55 +1000 Subject: [PATCH] =?UTF-8?q?fix(api):=20=D0=B8=D1=81=D0=BF=D1=80=D0=B0?= =?UTF-8?q?=D0=B2=D0=BB=D0=B5=D0=BD=D0=B0=20=D0=BE=D1=88=D0=B8=D0=B1=D0=BA?= =?UTF-8?q?=D0=B0=20=D0=BF=D1=80=D0=B8=20=D0=B7=D0=B0=D0=BF=D1=80=D0=BE?= =?UTF-8?q?=D1=81=D0=B5=20=D0=B7=D0=B0=D0=B4=D0=B0=D0=BD=D0=B8=D0=B9=20?= =?UTF-8?q?=D1=80=D0=BE=D0=B1=D0=BE=D1=82=D1=83=20=D0=BD=D0=B0=20=D0=BE?= =?UTF-8?q?=D0=B1=D0=BD=D0=BE=D0=B2=D0=BB=D0=B5=D0=BD=D0=B8=D0=B5=20=D1=80?= =?UTF-8?q?=D0=B0=D1=81=D0=BF=D0=B8=D1=81=D0=B0=D0=BD=D0=B8=D0=B9,=20?= =?UTF-8?q?=D0=BF=D0=BE=D0=BB=D1=83=D1=87=D0=B0=D0=BB=D0=B8=20null=20?= =?UTF-8?q?=D0=BF=D1=80=D0=B8=20=D0=B7=D0=B0=D0=BF=D1=80=D0=BE=D1=81=D0=B5?= =?UTF-8?q?=20=D0=B4=D0=B0=D1=82=D1=8B=20=D1=81=D0=BB=D0=B5=D0=B4=D1=83?= =?UTF-8?q?=D1=8E=D1=89=D0=B5=D0=B3=D0=BE=20=D0=B7=D0=B0=D0=BF=D1=83=D1=81?= =?UTF-8?q?=D0=BA=D0=B0=20=D0=A0=D0=A0=20=D0=B2=20include=20EsppSchTypeVal?= =?UTF-8?q?ues?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../EsppScheduleTransformService.cs | 11 ++++++++--- PARR.TemplateDistributor/TemplateDistributor.cs | 16 +++++++++++++--- 2 files changed, 21 insertions(+), 6 deletions(-) diff --git a/PARR.DAL/TransformServices/EsppScheduleTransformService.cs b/PARR.DAL/TransformServices/EsppScheduleTransformService.cs index dcbf24d2..bfc3e8fa 100644 --- a/PARR.DAL/TransformServices/EsppScheduleTransformService.cs +++ b/PARR.DAL/TransformServices/EsppScheduleTransformService.cs @@ -1,4 +1,5 @@ -using Microsoft.Extensions.Logging; +using Microsoft.EntityFrameworkCore; +using Microsoft.Extensions.Logging; using PARR.Constants; using PARR.DAL.Contracts; using PARR.DAL.DomainModels; @@ -134,13 +135,17 @@ namespace PARR.DAL.TransformServices public async Task GetNextDateAsync(Guid applicationInWorkId, DateTimeOffset lastRun) { - var appInWork = await applicationsInWorkService.GetAsync(applicationInWorkId); + var appInWork = await applicationsInWorkService.Get() + .Include(aiw => aiw.EsppSchValues) + .ThenInclude(esv => esv.EsppSchTypeValue) + .ThenInclude(etv => etv!.DistributionPeriod) + .FirstOrDefaultAsync(t => t.Id == applicationInWorkId); var esppSchedule = await GetEsppScheduleAsync(applicationInWorkId); if (appInWork!.IsAutoDistributionEnabled) { - var period = esppSchedule!.Values.FirstOrDefault()!.Value!.DistributionPeriod; + var period = appInWork.EsppSchValues.FirstOrDefault()?.EsppSchTypeValue?.DistributionPeriod; var periodType = ParseDistributionPeriodType(period!.Type); return GetNextDateForDistributionRun(lastRun, periodType, period.Duration); diff --git a/PARR.TemplateDistributor/TemplateDistributor.cs b/PARR.TemplateDistributor/TemplateDistributor.cs index ba3ce3e4..bd4cd3ae 100644 --- a/PARR.TemplateDistributor/TemplateDistributor.cs +++ b/PARR.TemplateDistributor/TemplateDistributor.cs @@ -46,7 +46,7 @@ namespace PARR.TemplateDistributor // сохранить в БД //applicationInWorkId = Guid.Parse("bdfefd77-bce3-4f62-a484-5042c06f4467"); - //var appInWork = await applicationsInWorkService.Get() + var appInWork = await applicationsInWorkService.GetAsync(applicationInWorkId ); // .Include(aiw => aiw.EsppSchValues) // .ThenInclude(esv => esv.EsppSchTypeValue) // .ThenInclude(etv => etv!.DistributionPeriod) @@ -69,6 +69,13 @@ namespace PARR.TemplateDistributor if (!values.Any()) continue; + //Обновляем сразу время при необходимости + values.ForEach(t=>{ + if (t.NextRun.TimeOfDay != appInWork!.ReferenceDate.TimeOfDay) + t.NextRun = new DateTimeOffset(t.NextRun.DateTime, new TimeSpan(appInWork!.ReferenceDate.Hour, appInWork!.ReferenceDate.Minute, appInWork!.ReferenceDate.Second)); + }); + + var distrTemplates = await DistributeTemplateAsync(values, applicationInWorkId, wgId); } @@ -108,7 +115,10 @@ namespace PARR.TemplateDistributor if (existingTemplates.Count > 0) templateToDistrib = GetTemplatesToDistribute(ref distrPlan, existingTemplates); - templateToDistrib.AddRange(templates); + templateToDistrib.AddRange(templates.Where(t=>existingTemplates.Any(et=>et.Id==t.Id)==false)); + + if (!templateToDistrib.Any()) + return new List