feat(api,dal): tbl TemplateStatusType - добавлен новый тип Error. В API добавлен метод просмотра статистики распределения StatTemplateDistributionController
This commit is contained in:
@@ -281,7 +281,7 @@
|
||||
|
||||
public static class StatTemplateDistribution
|
||||
{
|
||||
public const string Get = BaseStat + "/template-distribution/{applicationInWorkId}";
|
||||
public const string Get = BaseStat + "/template-distribution/{jobGroupId}";
|
||||
}
|
||||
|
||||
public static class StatResponseAreaWorkLoad
|
||||
|
||||
@@ -39,7 +39,7 @@
|
||||
// public string? AgentScript { get; set; }
|
||||
}
|
||||
|
||||
public class JobGroupResponse : JobGroupBaseResponse
|
||||
public class JobGroupResponse : JobGroupWithDistributionConfigResponse //: JobGroupBaseResponse
|
||||
{
|
||||
//public List<JobResponse>? Jobs { get; set; }
|
||||
public int JobsCount { get; set; }
|
||||
@@ -58,11 +58,10 @@
|
||||
/// </summary>
|
||||
public ScheduleExcludeTypeCalendarResponse? ScheduleExcludeTypeCalendar { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Настройки автораспределения
|
||||
/// </summary>
|
||||
public JobGroupDistributionConfigResponse? DistributionConfig { get; set; }
|
||||
|
||||
///// <summary>
|
||||
///// Настройки автораспределения
|
||||
///// </summary>
|
||||
//public JobGroupDistributionConfigResponse? DistributionConfig { get; set; }
|
||||
}
|
||||
|
||||
public class JobGroupScheduleResponse
|
||||
@@ -74,5 +73,13 @@
|
||||
public List<EsppScheduleValResponse>? Values { get; set; }
|
||||
}
|
||||
|
||||
public class JobGroupWithDistributionConfigResponse : JobGroupBaseResponse
|
||||
{
|
||||
/// <summary>
|
||||
/// Настройки автораспределения
|
||||
/// </summary>
|
||||
public JobGroupDistributionConfigResponse? DistributionConfig { get; set; }
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
@@ -2,23 +2,50 @@
|
||||
{
|
||||
public class StatTemplateDistributorResponse
|
||||
{
|
||||
public WorkGroupResponse? WorkGroup { get; set; }
|
||||
public required JobGroupWithDistributionConfigResponse JobGroup { get; set; }
|
||||
|
||||
public int AllCount { get; set; }
|
||||
/// <summary>
|
||||
/// Всего шаблонов
|
||||
/// </summary>
|
||||
public int AllCount => ItemsList?.Sum(t => t.AllCount) ?? 0;
|
||||
|
||||
public int IsActivatedAllCount { get; set; }
|
||||
/// <summary>
|
||||
/// Всего шаблонов с активированными шаблонами и расписаниями
|
||||
/// </summary>
|
||||
public int IsActivatedAllCount => ItemsList?.Sum(t => t.IsActivatedCount) ?? 0;
|
||||
|
||||
public int IsDeactivatedAllCount { get; set; }
|
||||
/// <summary>
|
||||
/// Всего шаблонов с деактивированными шаблонами и/или расписаниями
|
||||
/// </summary>
|
||||
public int IsDeactivatedAllCount => ItemsList?.Sum(t => t.IsDeactivatedCount) ?? 0;
|
||||
|
||||
public List<StatDistributorItemResponse>? ItemsList { get; set; }
|
||||
}
|
||||
|
||||
public List<StatTemplateDistributorDateStat>? Stat { get; set; }
|
||||
public class StatDistributorItemResponse
|
||||
{
|
||||
public string? WorkGroupName { get; set; }
|
||||
|
||||
public int AllCount => Statistics?.Sum(t => t.AllCount) ?? 0;
|
||||
public int IsActivatedCount => Statistics?.Sum(t => t.IsActivatedCount) ?? 0;
|
||||
public int IsDeactivatedCount => Statistics?.Sum(t => t.IsDeactivatedCount) ?? 0;
|
||||
|
||||
public List<StatTemplateDistributorDateStat>? Statistics { get; set; }
|
||||
}
|
||||
|
||||
public class StatTemplateDistributorDateStat
|
||||
{
|
||||
public DateTimeOffset Date { get; set; }
|
||||
public DateOnly Date { get; set; }
|
||||
public int AllCount { get; set; }
|
||||
public int IsActivatedCount { get; set; }
|
||||
public int IsDeactivatedCount { get; set; }
|
||||
public List<StatTempleteDistribItem>? Templates { get; set; }
|
||||
}
|
||||
|
||||
public class StatTempleteDistribItem
|
||||
{
|
||||
public required string Name { get; set; }
|
||||
public bool IsActiveTemplate { get; set; }
|
||||
public bool IsActiveSchedular { get; set; }
|
||||
}
|
||||
}
|
||||
|
||||
@@ -8,7 +8,12 @@ using PARR.API.Contracts.V1.Responses.Base;
|
||||
using PARR.API.Contracts.V1.Responses.Statistics;
|
||||
using PARR.API.Controllers.V1.Base;
|
||||
using PARR.Constants;
|
||||
using PARR.DAL.DomainServices.Shortcodes;
|
||||
using PARR.DAL.Models;
|
||||
using PARR.DAL.Models.Job;
|
||||
using PARR.DAL.NextRunServices;
|
||||
using PARR.DAL.Services.Interfaces;
|
||||
using PARR.DAL.Services.Interfaces.Job;
|
||||
|
||||
namespace PARR.API.Controllers.V1.Statistics
|
||||
{
|
||||
@@ -19,83 +24,183 @@ namespace PARR.API.Controllers.V1.Statistics
|
||||
public class StatTemplateDistributionController : BaseApiController
|
||||
{
|
||||
private readonly ITemplateService templateService;
|
||||
private readonly IWorkGroupService workGroupService;
|
||||
private readonly IJobGroupService jobGroupService;
|
||||
private readonly IMapper mapper;
|
||||
private readonly IShortcodesService shortcodesService;
|
||||
private readonly INextRunService nextRunService;
|
||||
private readonly ILogger<StatTemplateDistributionController> logger;
|
||||
|
||||
public StatTemplateDistributionController(
|
||||
ITemplateService templateService,
|
||||
IWorkGroupService workGroupService,
|
||||
IMapper mapper
|
||||
IJobGroupService jobGroupService,
|
||||
IMapper mapper,
|
||||
IShortcodesService shortcodesService,
|
||||
INextRunService nextRunService,
|
||||
ILogger<StatTemplateDistributionController> logger
|
||||
)
|
||||
{
|
||||
this.templateService = templateService;
|
||||
this.workGroupService = workGroupService;
|
||||
this.jobGroupService = jobGroupService;
|
||||
this.mapper = mapper;
|
||||
this.shortcodesService = shortcodesService;
|
||||
this.nextRunService = nextRunService;
|
||||
this.logger = logger;
|
||||
}
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// Статистика распределения шаблонов по JobId (ApplicationInWorkId)
|
||||
/// Статистика распределения шаблонов по jobGroupId, только для Used
|
||||
/// </summary>
|
||||
/// <param name="JobId"></param>
|
||||
/// <param name="jobGroupId"></param>
|
||||
/// <returns></returns>
|
||||
[HttpGet(ApiRoutes.StatTemplateDistribution.Get)]
|
||||
public async Task<IActionResult> Get([FromRoute] Guid jobId)
|
||||
public async Task<IActionResult> Get([FromRoute] Guid jobGroupId)
|
||||
{
|
||||
// f87dbe9f-cabf-4108-9c93-12068d4b48a5
|
||||
// eadc5498-dba6-4f10-9b4b-a1653e3c3e61
|
||||
|
||||
var query = templateService.Get()
|
||||
.Include(t => t.Unit)
|
||||
.Where(t => t.JobId == jobId)
|
||||
.GroupBy(t => t.Unit!.BaseFields!.WorkGroup)
|
||||
.Select(x => new
|
||||
var jobGroup = await jobGroupService.Get()
|
||||
.Include(t => t.DistributionConfig)
|
||||
.ThenInclude(t => t.DistributionPeriod)
|
||||
.AsNoTracking()
|
||||
.FirstOrDefaultAsync(t => t.Id == jobGroupId);
|
||||
|
||||
if (jobGroup == null)
|
||||
return BadRequest(new Response(false, new List<ErrorModel> { new ErrorModel { Message = "Не найдена группа работ" } }));
|
||||
|
||||
if (!jobGroup.IsAutoDistributionEnabled || jobGroup.DistributionConfig == null)
|
||||
return BadRequest(new Response(false, new List<ErrorModel> { new ErrorModel { Message = "Для группы работ не включено автораспределение" } }));
|
||||
|
||||
var items = await templateService.Get()
|
||||
.Where(t => t.Job!.GroupId == jobGroupId && t.StatusTypeId == TemplateStatusTypeEnum.Used)
|
||||
.Select(t => new
|
||||
{
|
||||
WorkGroup = x.Key,
|
||||
CountTemplates = x.Count(),
|
||||
IsActivatedAllCount = x.Count(t => t.IsActiveTemplate && t.IsActiveSchedule),
|
||||
IsDeactivatedAllCount = x.Count(t => !t.IsActiveTemplate || !t.IsActiveSchedule || (!t.IsActiveTemplate && !t.IsActiveSchedule)),
|
||||
GroupingByDate =
|
||||
x.GroupBy(d => d.NextRun).OrderBy(d => d.Key).Select(d =>
|
||||
new
|
||||
{
|
||||
Date = d.Key,
|
||||
//Всего
|
||||
Count = d.Count(),
|
||||
//Только активированных
|
||||
IsActivatedCount = d.Count(t => t.IsActiveTemplate && t.IsActiveSchedule),
|
||||
//Только деактивированных
|
||||
IsDeactivatedCount = d.Count(t => !t.IsActiveTemplate || !t.IsActiveSchedule || (!t.IsActiveTemplate && !t.IsActiveSchedule))
|
||||
}
|
||||
)
|
||||
});
|
||||
|
||||
var statResult = await query.ToListAsync();
|
||||
|
||||
var workGroups = await workGroupService.Get()
|
||||
.Include(t => t.ResponseArea)
|
||||
.Where(t => statResult.Select(x => x.WorkGroup).Any(w => w == t.Name))
|
||||
WorkGroup = t.Job!.WorkGroupMask,
|
||||
Template = t
|
||||
})
|
||||
.AsNoTracking()
|
||||
.ToListAsync();
|
||||
|
||||
if (!items.Any())
|
||||
return Ok(new Response<StatTemplateDistributorResponse>(new StatTemplateDistributorResponse
|
||||
{
|
||||
JobGroup = mapper.Map<JobGroupWithDistributionConfigResponse>(jobGroup),
|
||||
ItemsList = null
|
||||
}, true));
|
||||
|
||||
var response = statResult.Select(stat => new StatTemplateDistributorResponse
|
||||
// получаем список рабочих дней
|
||||
var workDays = await GetWorkDaysAsync(jobGroup, items.Max(t => t.Template.NextRun));
|
||||
|
||||
var responseItemsList = new List<StatDistributorItemResponse>();
|
||||
|
||||
if (jobGroup.DistributionConfig.IsGroupingByWorkGroup)
|
||||
{
|
||||
WorkGroup = mapper.Map<WorkGroupResponse>(workGroups.FirstOrDefault(x => x.Name == stat.WorkGroup)),//TODO Migration to job
|
||||
AllCount = stat.CountTemplates,
|
||||
IsActivatedAllCount = stat.IsActivatedAllCount,
|
||||
IsDeactivatedAllCount = stat.IsDeactivatedAllCount,
|
||||
Stat = stat.GroupingByDate.Select(x => new StatTemplateDistributorDateStat
|
||||
// тут группируем по рабочим группам
|
||||
|
||||
// Получаем список пар (WorkGroupName, Template)
|
||||
var templatesWithWorkGroupNames = new List<(string WorkGroupName, Template Template)>();
|
||||
|
||||
// получаем названия рабочих групп
|
||||
foreach (var item in items)
|
||||
{
|
||||
AllCount = x.Count,
|
||||
Date = x.Date,
|
||||
IsActivatedCount = x.IsActivatedCount,
|
||||
IsDeactivatedCount = x.IsDeactivatedCount
|
||||
var workGroupName = await shortcodesService.ApplyShortcodesAsync(item.WorkGroup, item.Template);
|
||||
templatesWithWorkGroupNames.Add((workGroupName, item.Template));
|
||||
}
|
||||
|
||||
// Группируем по WorkGroupName
|
||||
var grouped = templatesWithWorkGroupNames
|
||||
.GroupBy(x => x.WorkGroupName)
|
||||
.ToDictionary(g => g.Key, g => g.Select(x => x.Template).ToList());
|
||||
|
||||
foreach (var groupedItem in grouped)
|
||||
{
|
||||
var statResult = GetResponseByWorkGroup(groupedItem.Key, groupedItem.Value, workDays);
|
||||
responseItemsList.Add(statResult);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
// не нужно группировать по рабочим группам
|
||||
|
||||
// сразу формируем response
|
||||
responseItemsList.Add(GetResponseByWorkGroup(null, items.Select(t => t.Template).ToList(), workDays));
|
||||
}
|
||||
|
||||
var response = new StatTemplateDistributorResponse
|
||||
{
|
||||
JobGroup = mapper.Map<JobGroupWithDistributionConfigResponse>(jobGroup),
|
||||
ItemsList = responseItemsList.OrderBy(t => t.WorkGroupName).ToList()
|
||||
};
|
||||
|
||||
return Ok(new Response<StatTemplateDistributorResponse>(response, true));
|
||||
}
|
||||
|
||||
|
||||
private async Task<List<DateOnly>> GetWorkDaysAsync(JobGroup jobGroup, DateTimeOffset maxNextRunTemplate)
|
||||
{
|
||||
var durationDays = nextRunService.GetDurationDays(jobGroup.DistributionConfig!);
|
||||
|
||||
var dateStart = DateOnly.FromDateTime(DateTime.UtcNow);
|
||||
|
||||
// последний день, не может быть меньше чем durationDays
|
||||
var dateEnd = dateStart.AddDays(durationDays);
|
||||
|
||||
// последний день, не может быть меньше чем refDate+durationDays
|
||||
var sumRefDuration = DateOnly.FromDateTime(jobGroup.ReferenceDate.AddDays(durationDays).Date);
|
||||
if (dateEnd < sumRefDuration)
|
||||
dateEnd = sumRefDuration;
|
||||
|
||||
// с DateEnd вообще какая-то шурпатня :(
|
||||
// как наглядно понять ок не ок распределяется, если на каком-то графике dateEnd может ухеать за период распределения
|
||||
// последний день, не может быть меньше чем дата последнего шаблона maxNextRunTemplate
|
||||
var lastTempalteDate = DateOnly.FromDateTime(maxNextRunTemplate.Date);
|
||||
if (dateEnd < lastTempalteDate)
|
||||
dateEnd = lastTempalteDate;
|
||||
|
||||
return await nextRunService.GetWorkDaysAsync(dateStart, dateEnd, jobGroup.DistributionConfig!.IsExcludeWeekends);
|
||||
}
|
||||
|
||||
private StatDistributorItemResponse GetResponseByWorkGroup(string? workGroupName, List<Template> templates, List<DateOnly> workDays)
|
||||
{
|
||||
var result = new StatDistributorItemResponse
|
||||
{
|
||||
WorkGroupName = workGroupName,
|
||||
Statistics = workDays.OrderBy(t => t).Select(t => new StatTemplateDistributorDateStat
|
||||
{
|
||||
AllCount = 0,
|
||||
Date = t,
|
||||
IsActivatedCount = 0,
|
||||
IsDeactivatedCount = 0,
|
||||
Templates = new List<StatTempleteDistribItem>()
|
||||
}).ToList()
|
||||
};
|
||||
|
||||
foreach (var templatesFromDate in templates.GroupBy(t => DateOnly.FromDateTime(t.NextRun.Date)))
|
||||
{
|
||||
var statisticsForDate = result.Statistics.FirstOrDefault(t => t.Date == templatesFromDate.Key);
|
||||
if (statisticsForDate == null)
|
||||
{
|
||||
logger.LogWarning("В списке рабочих дней, нет дня для шаблонов {count} шт. выполняющихся в {date}", templatesFromDate.Count(), templatesFromDate.Key);
|
||||
continue;
|
||||
}
|
||||
|
||||
statisticsForDate.AllCount = templatesFromDate.Count();
|
||||
statisticsForDate.IsDeactivatedCount = templatesFromDate.Count(t => !t.IsActiveTemplate || !t.IsActiveSchedule);
|
||||
statisticsForDate.IsActivatedCount = templatesFromDate.Count(t => t.IsActiveTemplate && t.IsActiveSchedule);
|
||||
statisticsForDate.Templates = templatesFromDate.Select(t => new StatTempleteDistribItem
|
||||
{
|
||||
Name = t.Name,
|
||||
IsActiveSchedular = t.IsActiveSchedule,
|
||||
IsActiveTemplate = t.IsActiveTemplate
|
||||
})
|
||||
.OrderBy(t => t.WorkGroup?.Name)
|
||||
.OrderBy(t => t.Name)
|
||||
.ToList();
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
return Ok(new Response<List<StatTemplateDistributorResponse>>(response, true));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -360,16 +360,20 @@ namespace PARR.API.MappingProfiles
|
||||
|
||||
CreateMap<JobGroup, JobGroupBaseResponse>()
|
||||
.Include<JobGroup, JobGroupResponse>()
|
||||
.Include<JobGroup, JobGroupWithDistributionConfigResponse>()
|
||||
.ForMember(d => d.GroupType, o => o.MapFrom(s => s.GroupType))
|
||||
.ForMember(d => d.GroupingUnitField, o => o.MapFrom(s => s.GroupingUnitField));
|
||||
|
||||
CreateMap<JobGroup, JobGroupBaseResponse>()
|
||||
.ForMember(d => d.Name, o => o.MapFrom(s => s.GroupName));
|
||||
|
||||
CreateMap<JobGroup, JobGroupWithDistributionConfigResponse>()
|
||||
.ForMember(d => d.DistributionConfig, o => o.MapFrom(s => s.DistributionConfig));
|
||||
|
||||
CreateMap<JobGroup, JobGroupResponse>()
|
||||
.ForMember(d => d.ScheduleExcludeType, o => o.MapFrom(s => s.ScheduleExcludeType))
|
||||
.ForMember(d => d.ScheduleExcludeTypeCalendar, o => o.MapFrom(s => s.ScheduleExcludeTypeCalendar))
|
||||
.ForMember(d => d.DistributionConfig, o => o.MapFrom(s => s.DistributionConfig));
|
||||
.ForMember(d => d.ScheduleExcludeTypeCalendar, o => o.MapFrom(s => s.ScheduleExcludeTypeCalendar));
|
||||
//.ForMember(d => d.DistributionConfig, o => o.MapFrom(s => s.DistributionConfig));
|
||||
|
||||
|
||||
#endregion
|
||||
|
||||
@@ -2,8 +2,24 @@
|
||||
{
|
||||
public enum TemplateStatusTypeEnum
|
||||
{
|
||||
/// <summary>
|
||||
/// Шаблон используется
|
||||
/// </summary>
|
||||
Used = 0,
|
||||
|
||||
/// <summary>
|
||||
/// Шаблон не используется
|
||||
/// </summary>
|
||||
Unused = 1,
|
||||
Updating =2
|
||||
|
||||
/// <summary>
|
||||
/// Шаблон в статусе обновления
|
||||
/// </summary>
|
||||
Updating = 2,
|
||||
|
||||
/// <summary>
|
||||
/// Шаблон в статусе ошибки
|
||||
/// </summary>
|
||||
Error = 3
|
||||
}
|
||||
}
|
||||
|
||||
@@ -512,7 +512,8 @@ namespace PARR.DAL.Context
|
||||
f.HasData(
|
||||
new() { Id = TemplateStatusTypeEnum.Used, Name = TemplateStatusTypeEnum.Used.ToString(), Description = "В работе" },
|
||||
new() { Id = TemplateStatusTypeEnum.Unused, Name = TemplateStatusTypeEnum.Unused.ToString(), Description = "Не используется" },
|
||||
new() { Id = TemplateStatusTypeEnum.Updating, Name = TemplateStatusTypeEnum.Updating.ToString(), Description = "Обновляется" }
|
||||
new() { Id = TemplateStatusTypeEnum.Updating, Name = TemplateStatusTypeEnum.Updating.ToString(), Description = "Обновляется" },
|
||||
new() { Id = TemplateStatusTypeEnum.Error, Name = TemplateStatusTypeEnum.Error.ToString(), Description = "Ошибка" }
|
||||
);
|
||||
});
|
||||
|
||||
|
||||
4117
PARR.DAL/Migrations/20260126042226_tblTemplateStatusTypeAddStatusError.Designer.cs
generated
Normal file
4117
PARR.DAL/Migrations/20260126042226_tblTemplateStatusTypeAddStatusError.Designer.cs
generated
Normal file
File diff suppressed because it is too large
Load Diff
@@ -0,0 +1,28 @@
|
||||
using Microsoft.EntityFrameworkCore.Migrations;
|
||||
|
||||
#nullable disable
|
||||
|
||||
namespace PARR.DAL.Migrations
|
||||
{
|
||||
/// <inheritdoc />
|
||||
public partial class tblTemplateStatusTypeAddStatusError : Migration
|
||||
{
|
||||
/// <inheritdoc />
|
||||
protected override void Up(MigrationBuilder migrationBuilder)
|
||||
{
|
||||
migrationBuilder.InsertData(
|
||||
table: "TemplateStatusTypes",
|
||||
columns: new[] { "Id", "Description", "Name" },
|
||||
values: new object[] { 3, "Ошибка", "Error" });
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
protected override void Down(MigrationBuilder migrationBuilder)
|
||||
{
|
||||
migrationBuilder.DeleteData(
|
||||
table: "TemplateStatusTypes",
|
||||
keyColumn: "Id",
|
||||
keyValue: 3);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -2900,6 +2900,12 @@ namespace PARR.DAL.Migrations
|
||||
Id = 2,
|
||||
Description = "Обновляется",
|
||||
Name = "Updating"
|
||||
},
|
||||
new
|
||||
{
|
||||
Id = 3,
|
||||
Description = "Ошибка",
|
||||
Name = "Error"
|
||||
});
|
||||
});
|
||||
|
||||
|
||||
@@ -1,9 +1,17 @@
|
||||
using PARR.DAL.NextRunServices.Models;
|
||||
using PARR.DAL.Models.Job;
|
||||
using PARR.DAL.NextRunServices.Models;
|
||||
|
||||
namespace PARR.DAL.NextRunServices
|
||||
{
|
||||
public interface INextRunService
|
||||
{
|
||||
/// <summary>
|
||||
/// Получить продолжительность распределения в днях
|
||||
/// </summary>
|
||||
/// <param name="config"></param>
|
||||
/// <returns></returns>
|
||||
int GetDurationDays(JobGroupDistributionConfig config);
|
||||
|
||||
/// <summary>
|
||||
/// Получить список TemplateId, NextRun по jobGroupId с автораспределением (распределить шаблоны в группе работ)
|
||||
/// </summary>
|
||||
@@ -36,5 +44,14 @@ namespace PARR.DAL.NextRunServices
|
||||
/// <returns></returns>
|
||||
Task<DateTimeOffset> GetNextRunForTemplateAsync(Guid templateId, bool isNew);
|
||||
|
||||
/// <summary>
|
||||
/// Получить список рабочих дней
|
||||
/// </summary>
|
||||
/// <param name="start"></param>
|
||||
/// <param name="end"></param>
|
||||
/// <param name="excludeWeekends"></param>
|
||||
/// <returns></returns>
|
||||
Task<List<DateOnly>> GetWorkDaysAsync(DateOnly start, DateOnly end, bool excludeWeekends);
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@@ -70,18 +70,19 @@ namespace PARR.DAL.NextRunServices
|
||||
var duration = GetDurationDays(jobGroup.DistributionConfig);
|
||||
var dateStart = GetDateStart(jobGroup.ReferenceDate);
|
||||
|
||||
//получаем шаблоны только в статусе Used
|
||||
var allTemplates = await templateService.Get()
|
||||
.Include(t => t.Job)
|
||||
.Where(t => t.Job!.GroupId == jobGroupId)
|
||||
.Where(t => t.Job!.GroupId == jobGroupId && t.StatusTypeId == TemplateStatusTypeEnum.Used)
|
||||
.AsNoTracking()
|
||||
.ToListAsync();
|
||||
if (!allTemplates.Any())
|
||||
{
|
||||
logger.LogInformation("В группе c ИД {jobGroupId} отсутствуют шаблоны", jobGroupId);
|
||||
logger.LogInformation("В группе c ИД {jobGroupId} отсутствуют шаблоны в статусе Used", jobGroupId);
|
||||
return null;
|
||||
}
|
||||
|
||||
logger.LogDebug("Всего шаблонов для распределения: {count} шт.", allTemplates.Count);
|
||||
logger.LogDebug("Всего шаблонов для распределения в статусе Used: {count} шт.", allTemplates.Count);
|
||||
|
||||
var result = new List<TemplateNextRunResultDto>();
|
||||
|
||||
@@ -258,7 +259,7 @@ namespace PARR.DAL.NextRunServices
|
||||
/// </summary>
|
||||
/// <param name="config"></param>
|
||||
/// <returns></returns>
|
||||
private int GetDurationDays(JobGroupDistributionConfig config)
|
||||
public int GetDurationDays(JobGroupDistributionConfig config)
|
||||
{
|
||||
var period = config.DistributionPeriod;
|
||||
var periodType = period!.Type;
|
||||
@@ -303,5 +304,11 @@ namespace PARR.DAL.NextRunServices
|
||||
else
|
||||
return DateOnly.FromDateTime(today.Date);
|
||||
}
|
||||
|
||||
|
||||
public async Task<List<DateOnly>> GetWorkDaysAsync(DateOnly start, DateOnly end, bool excludeWeekends)
|
||||
{
|
||||
return await templateDistributor.GetWorkDaysAsync(start, end, excludeWeekends);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -31,6 +31,16 @@ namespace PARR.DAL.NextRunServices.Subservices
|
||||
/// <param name="isNew">Новый шаблон</param>
|
||||
/// <returns></returns>
|
||||
Task<TemplateNextRunResultDto> GetValidNextRunForTemplateAsync(DateOnly startDate, int duration, DateTimeOffset referenceDate, TemplateNextRunDto targetTemplate, List<TemplateNextRunDto> allTemplates, bool excludeWeekends, bool isNew);
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// Получить список рабочих дней
|
||||
/// </summary>
|
||||
/// <param name="start"></param>
|
||||
/// <param name="end"></param>
|
||||
/// <param name="excludeWeekends"></param>
|
||||
/// <returns></returns>
|
||||
Task<List<DateOnly>> GetWorkDaysAsync(DateOnly start, DateOnly end, bool excludeWeekends);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -465,6 +465,8 @@ namespace PARR.DAL.NextRunServices.Subservices
|
||||
{
|
||||
var interval = (double)totalDays / totalWorks;
|
||||
|
||||
logger.LogDebug("Интевал между шаблонами: {interval}", interval);
|
||||
|
||||
return interval;
|
||||
}
|
||||
|
||||
@@ -562,7 +564,7 @@ namespace PARR.DAL.NextRunServices.Subservices
|
||||
/// <param name="end"></param>
|
||||
/// <param name="excludeWeekends">Исключить выходные и праздники</param>
|
||||
/// <returns></returns>
|
||||
private async Task<List<DateOnly>> GetWorkDaysAsync(DateOnly start, DateOnly end, bool excludeWeekends)
|
||||
public async Task<List<DateOnly>> GetWorkDaysAsync(DateOnly start, DateOnly end, bool excludeWeekends)
|
||||
{
|
||||
// Получаем список выходных/праздничных дней
|
||||
var weekends = new HashSet<DateOnly>();
|
||||
|
||||
Reference in New Issue
Block a user