2023-10-11 11:10:35 +10:00
|
|
|
|
using AutoMapper;
|
|
|
|
|
|
using PARR.API.Contracts.V1.Responses;
|
|
|
|
|
|
using PARR.DAL.Models;
|
|
|
|
|
|
using PARR.DAL.Services.Interfaces;
|
|
|
|
|
|
|
|
|
|
|
|
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
|
|
|
|
|
|
});
|
2023-10-11 11:10:35 +10:00
|
|
|
|
|
|
|
|
|
|
return response.OrderBy(t => t.Order).ToList();
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|