2023-10-11 11:10:35 +10:00
|
|
|
|
using AutoMapper;
|
|
|
|
|
|
using PARR.API.Contracts.V1.Responses;
|
2024-07-16 12:06:46 +10:00
|
|
|
|
using PARR.DAL.Contracts;
|
2023-10-11 11:10:35 +10:00
|
|
|
|
using PARR.DAL.Models;
|
|
|
|
|
|
using PARR.DAL.Services.Interfaces;
|
2024-07-16 12:06:46 +10:00
|
|
|
|
using System.Threading.Tasks;
|
2023-10-11 11:10:35 +10:00
|
|
|
|
|
|
|
|
|
|
namespace PARR.API.MappingProfiles.Resolvers
|
|
|
|
|
|
{
|
|
|
|
|
|
public class RobotTaskScheduleSchResolver : IValueResolver<RobotConfiguration, RobotTaskScheduleResponse, List<RobotTaskScheduleSchResponse>?>
|
|
|
|
|
|
{
|
|
|
|
|
|
private readonly IEsppSchTypeConfigService esppConfigService;
|
2023-10-12 12:06:47 +10:00
|
|
|
|
private readonly ILogger<RobotTaskScheduleSchResolver> logger;
|
2023-10-11 11:10:35 +10:00
|
|
|
|
|
2023-10-12 12:06:47 +10:00
|
|
|
|
public RobotTaskScheduleSchResolver(
|
|
|
|
|
|
IEsppSchTypeConfigService esppConfigService,
|
|
|
|
|
|
ILogger<RobotTaskScheduleSchResolver> logger
|
|
|
|
|
|
)
|
2023-10-11 11:10:35 +10:00
|
|
|
|
{
|
|
|
|
|
|
this.esppConfigService = esppConfigService;
|
2023-10-12 12:06:47 +10:00
|
|
|
|
this.logger = logger;
|
2023-10-11 11:10:35 +10:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
public List<RobotTaskScheduleSchResponse>? Resolve(RobotConfiguration source, RobotTaskScheduleResponse destination, List<RobotTaskScheduleSchResponse>? destMember, ResolutionContext context)
|
|
|
|
|
|
{
|
|
|
|
|
|
var appInWorksId = source.Template!.ApplicationInWorkId;
|
|
|
|
|
|
|
2023-10-12 12:06:47 +10:00
|
|
|
|
var schedule = esppConfigService.GetEsppScheduleDto(appInWorksId);
|
2023-10-11 11:10:35 +10:00
|
|
|
|
|
2023-10-12 12:06:47 +10:00
|
|
|
|
if (schedule == null)
|
|
|
|
|
|
{
|
|
|
|
|
|
logger.LogError($"RobotTaskScheduleSchResolver: Не смог замапить расписание для робота, так как оно null. appInWorksId: {appInWorksId}");
|
|
|
|
|
|
return null;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
var response = schedule.Values.Select(t => new RobotTaskScheduleSchResponse
|
|
|
|
|
|
{
|
|
|
|
|
|
Order = t.Order,
|
|
|
|
|
|
Type = t.Type.Name,
|
|
|
|
|
|
TypeCode = t.Type.Id,
|
|
|
|
|
|
Value = t.Value.Value
|
2024-07-16 12:06:46 +10:00
|
|
|
|
}).OrderBy(t => t.Order).ToList();
|
2023-10-11 11:10:35 +10:00
|
|
|
|
|
2024-07-16 12:06:46 +10:00
|
|
|
|
//Если задача относится к распределенной модели исполнения за период месяц устанавливаем день равный NextRun
|
|
|
|
|
|
if (source.Template!.ApplicationsInWork!.IsAutoDistributionEnabled &&
|
|
|
|
|
|
schedule.TypeSchedule.Id == (int)EsppSchTypeScheduleEnum.Monthly)
|
|
|
|
|
|
response.First().Value = source.Template.NextRun.Day.ToString();
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
return response;
|
2023-10-11 11:10:35 +10:00
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|