diff --git a/.gitignore b/.gitignore index 9491a2fd..61d23209 100644 --- a/.gitignore +++ b/.gitignore @@ -33,6 +33,9 @@ bld/ [Ll]og/ [Ll]ogs/ +# VS Code +.vscode/ + # Visual Studio 2015/2017 cache/options directory .vs/ # Uncomment if you have tasks that create the project's static files in wwwroot diff --git a/PARR.TemplateDistributor/TemplateDistributor.cs b/PARR.TemplateDistributor/TemplateDistributor.cs index 802b2c08..3939f993 100644 --- a/PARR.TemplateDistributor/TemplateDistributor.cs +++ b/PARR.TemplateDistributor/TemplateDistributor.cs @@ -13,7 +13,6 @@ namespace PARR.TemplateDistributor private readonly ILogger logger; private readonly ITemplateService templateService; private readonly IApplicationsInWorkService applicationsInWorkService; - private readonly IEsppSchTypeScheduleService esppSchTypeScheduleService; private readonly ICalendarService calendarService; private readonly IEsppScheduleTransformService esppScheduleTransformService; private readonly IWeekendDayService weekendDayService; @@ -22,7 +21,6 @@ namespace PARR.TemplateDistributor ILogger logger, ITemplateService templateService, IApplicationsInWorkService applicationsInWorkService, - IEsppSchTypeScheduleService esppSchTypeScheduleService, ICalendarService calendarService, IEsppScheduleTransformService esppScheduleTransformService, IWeekendDayService weekendDayService @@ -31,7 +29,6 @@ namespace PARR.TemplateDistributor this.logger = logger; this.templateService = templateService; this.applicationsInWorkService = applicationsInWorkService; - this.esppSchTypeScheduleService = esppSchTypeScheduleService; this.calendarService = calendarService; this.esppScheduleTransformService = esppScheduleTransformService; this.weekendDayService = weekendDayService; @@ -40,57 +37,45 @@ namespace PARR.TemplateDistributor public async Task UpdateScheduleAsync(Guid applicationInWorkId) { - // все шаблоны по applicationInWorkId - // группирует по РР - // -> DistributeTemplateForPeriodAsync - // сохранить в БД - //applicationInWorkId = Guid.Parse("bdfefd77-bce3-4f62-a484-5042c06f4467"); - var appInWork = await applicationsInWorkService.GetAsync(applicationInWorkId); - // .Include(aiw => aiw.EsppSchValues) - // .ThenInclude(esv => esv.EsppSchTypeValue) - // .ThenInclude(etv => etv!.DistributionPeriod) - // .FirstOrDefaultAsync(t => t.Id == applicationInWorkId); var templates = await templateService.Get() .Include(t => t.Host) .ThenInclude(h => h.WorkGroup) - .Where(t => t.ApplicationInWorkId == applicationInWorkId) + .Where(t => t.ApplicationInWorkId == applicationInWorkId && t.Host!.WorkGroupId != null) .ToListAsync(); - + //Группируем шаблоны по рабочим группам var workGroupsWithTemplates = templates.GroupBy(t => t.Host!.WorkGroupId); foreach (var workGroupWithTemplates in workGroupsWithTemplates) { - var wgId = workGroupWithTemplates.Key ?? Guid.NewGuid();//TODO сделать правильно + var wgId = (Guid)workGroupWithTemplates.Key!; var values = workGroupWithTemplates.ToList(); - if (!values.Any()) - continue; - - //Обновляем сразу время при необходимости - values.ForEach(t => + //Обновляем сразу время при необходимости, так как дальше будем работать только с датой + var timesList = values.Select(t => t.NextRun.TimeOfDay).Distinct().ToList(); + if (timesList.Count() > 1 || (timesList.Count() == 1 && timesList[0] != appInWork!.ReferenceDate.TimeOfDay)) { - 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)); - t.NextRun = new DateTimeOffset(t.NextRun.Year, t.NextRun.Month, t.NextRun.Day, - appInWork!.ReferenceDate.Hour, appInWork!.ReferenceDate.Minute, appInWork!.ReferenceDate.Second, - new TimeSpan(0, 0, 0)); - }); - - if (!await applicationsInWorkService.CommitAsync()) - { - logger.LogError($"Ошибка записи изменений в БД при актуализации времени NextRun шаблонов"); - return; + values.ForEach(t => + { + if (t.NextRun.TimeOfDay != appInWork!.ReferenceDate.TimeOfDay) + t.NextRun = new DateTimeOffset(t.NextRun.Year, t.NextRun.Month, t.NextRun.Day, + appInWork!.ReferenceDate.Hour, appInWork!.ReferenceDate.Minute, appInWork!.ReferenceDate.Second, + new TimeSpan(0, 0, 0)); + }); + if (!await templateService.CommitAsync()) + { + logger.LogError($"Ошибка записи изменений в БД при актуализации времени NextRun шаблонов РР({applicationInWorkId})"); + return; + } } - - var distrTemplates = await DistributeTemplateAsync(values, applicationInWorkId, wgId); + var distrTemplates = await DistributeTemplateAsync(new List