feat(api): Вынес логику формирования расписания в сервис IEsppSchTypeConfigService. В респонс шаблона добавил отображение расписания. Получение шаблона по ИД.
This commit is contained in:
@@ -8,29 +8,36 @@ namespace PARR.API.MappingProfiles.Resolvers
|
||||
public class RobotTaskScheduleSchResolver : IValueResolver<RobotConfiguration, RobotTaskScheduleResponse, List<RobotTaskScheduleSchResponse>?>
|
||||
{
|
||||
private readonly IEsppSchTypeConfigService esppConfigService;
|
||||
private readonly ILogger<RobotTaskScheduleSchResolver> logger;
|
||||
|
||||
public RobotTaskScheduleSchResolver(IEsppSchTypeConfigService esppConfigService)
|
||||
public RobotTaskScheduleSchResolver(
|
||||
IEsppSchTypeConfigService esppConfigService,
|
||||
ILogger<RobotTaskScheduleSchResolver> logger
|
||||
)
|
||||
{
|
||||
this.esppConfigService = esppConfigService;
|
||||
this.logger = logger;
|
||||
}
|
||||
|
||||
public List<RobotTaskScheduleSchResponse>? Resolve(RobotConfiguration source, RobotTaskScheduleResponse destination, List<RobotTaskScheduleSchResponse>? destMember, ResolutionContext context)
|
||||
{
|
||||
//todo: может вынести эту логику в сервис?
|
||||
var appInWorksId = source.Template!.ApplicationInWorkId;
|
||||
|
||||
var configs = esppConfigService.GetWithSchIncludes()
|
||||
.Where(t => t.EsppSchValues.Any(x => x.ApplicationsInWorkId == appInWorksId))
|
||||
.ToList();
|
||||
var schedule = esppConfigService.GetEsppScheduleDto(appInWorksId);
|
||||
|
||||
var response = configs.Select(conf =>
|
||||
new RobotTaskScheduleSchResponse
|
||||
{
|
||||
Order = conf.Order,
|
||||
Type = conf.EsppSchType!.Name,
|
||||
TypeCode = conf.EsppSchType!.Id,
|
||||
Value = conf.EsppSchValues.First().EsppSchTypeValue!.Value
|
||||
});
|
||||
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
|
||||
});
|
||||
|
||||
return response.OrderBy(t => t.Order).ToList();
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user