feat(api): jobGroup - управление автораспределением
This commit is contained in:
@@ -160,14 +160,28 @@ namespace PARR.API.Controllers.V1
|
||||
TemplateDuration = request.TemplateDuration.Trim(),
|
||||
ReferenceDate = request.ReferenceDate,
|
||||
ScheduleExcludeTypeId = request.ScheduleExcludeTypeId,
|
||||
ScheduleExcludeTypeCalendarId = request.ScheduleExcludeTypeCalendarId
|
||||
//IsAutoDistributionEnabled = request.IsAutoDistributionEnabled,
|
||||
ScheduleExcludeTypeCalendarId = request.ScheduleExcludeTypeCalendarId,
|
||||
IsAutoDistributionEnabled = request.IsAutoDistributionEnabled,
|
||||
//IsAgent = request.IsAgent,
|
||||
//AgentName = request.AgentName,
|
||||
//AgentTimeOutSec = request.AgentTimeOutSec,
|
||||
//AgentScript = request.AgentScript
|
||||
};
|
||||
|
||||
#region Если включено автораспределение, добавляем настройки
|
||||
if (request.IsAutoDistributionEnabled)
|
||||
{
|
||||
// на всякий проверим, но вообще это проверяется в валидаторе
|
||||
if (request.DistributionConfig == null)
|
||||
{
|
||||
logger.LogError("Ошибка при создании группы работ '{name}', отсутствуют настройки автораспределения", request.Name);
|
||||
return BadRequest(new Response(false, new List<ErrorModel> { new ErrorModel { Message = "Ошибка при создании группы заданий на выполнение работ" } }));
|
||||
}
|
||||
|
||||
jobGroup.DistributionConfig = CreateDistributionConfig(request.DistributionConfig, jobGroup.Id);
|
||||
}
|
||||
#endregion
|
||||
|
||||
//Добавляем настройки планировщика
|
||||
request.Schedule.ForEach(item =>
|
||||
{
|
||||
@@ -220,6 +234,7 @@ namespace PARR.API.Controllers.V1
|
||||
.Include(t => t.Jobs)
|
||||
.ThenInclude(t => t.Tnk)
|
||||
.Include(t => t.EsppSchValues)
|
||||
.Include(t => t.DistributionConfig).ThenInclude(t => t.DistributionPeriod)
|
||||
.FirstOrDefaultAsync(t => t.Id == id);
|
||||
|
||||
if (orig == null)
|
||||
@@ -239,12 +254,45 @@ namespace PARR.API.Controllers.V1
|
||||
orig.ReferenceDate = request.ReferenceDate;
|
||||
orig.ScheduleExcludeTypeId = request.ScheduleExcludeTypeId;
|
||||
orig.ScheduleExcludeTypeCalendarId = request.ScheduleExcludeTypeCalendarId;
|
||||
//orig.IsAutoDistributionEnabled = request.IsAutoDistributionEnabled;
|
||||
orig.IsAutoDistributionEnabled = request.IsAutoDistributionEnabled;
|
||||
//orig.IsAgent = request.IsAgent;
|
||||
//orig.AgentName = request.AgentName;
|
||||
//orig.AgentTimeOutSec = request.AgentTimeOutSec;
|
||||
//orig.AgentScript = request.AgentScript;
|
||||
orig.DateModified = DateTimeOffset.UtcNow;
|
||||
|
||||
#region Обновляем настройки автораспределения
|
||||
|
||||
if (request.IsAutoDistributionEnabled)
|
||||
{
|
||||
if (request.DistributionConfig == null)
|
||||
{
|
||||
logger.LogError("Ошибка при изменении группы работ '{name}', отсутствуют настройки автораспределения", request.Name);
|
||||
return BadRequest(new Response(false, new List<ErrorModel> { new ErrorModel { Message = "Ошибка при изменении группы заданий на выполнение работ" } }));
|
||||
}
|
||||
|
||||
// если настройки были, меняем, если не было, создаем
|
||||
if (orig.DistributionConfig != null)
|
||||
{
|
||||
orig.DistributionConfig.DistributionPeriodId = request.DistributionConfig.DistributionPeriodId;
|
||||
orig.DistributionConfig.IsExcludeWeekends = request.DistributionConfig.IsExcludeWeekends;
|
||||
orig.DistributionConfig.IsGroupingByWorkGroup = request.DistributionConfig.IsGroupingByWorkGroup;
|
||||
}
|
||||
else
|
||||
{
|
||||
//создаем
|
||||
orig.DistributionConfig = CreateDistributionConfig(request.DistributionConfig, orig.Id);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
// удаляем настройки распределения если они были
|
||||
if (orig.DistributionConfig != null)
|
||||
{
|
||||
groupService.DeleteDistributionConfig(orig.DistributionConfig);
|
||||
}
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
//обновляем планировщик
|
||||
orig.EsppSchValues.Clear();
|
||||
@@ -443,5 +491,23 @@ namespace PARR.API.Controllers.V1
|
||||
|
||||
return mapper.Map<MatchingStatusResponse>(statusMatching);
|
||||
}
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// Создать конфиг распределения
|
||||
/// </summary>
|
||||
/// <param name="distributionConfigRequest"></param>
|
||||
/// <param name="jobGroupId"></param>
|
||||
/// <returns></returns>
|
||||
private JobGroupDistributionConfig CreateDistributionConfig(DistributionConfigRequest distributionConfigRequest, Guid jobGroupId)
|
||||
{
|
||||
return new JobGroupDistributionConfig
|
||||
{
|
||||
GroupId = jobGroupId,
|
||||
DistributionPeriodId = distributionConfigRequest.DistributionPeriodId,
|
||||
IsExcludeWeekends = distributionConfigRequest.IsExcludeWeekends,
|
||||
IsGroupingByWorkGroup = distributionConfigRequest.IsGroupingByWorkGroup
|
||||
};
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user