69 lines
2.9 KiB
C#
69 lines
2.9 KiB
C#
using AutoMapper;
|
|
using Microsoft.EntityFrameworkCore;
|
|
using Microsoft.Extensions.Logging;
|
|
using PARR.Core.Repositories.Interfaces;
|
|
using PARR.Core.Services.RobotTaskDetailsServices.Interfaces;
|
|
using PARR.Domain.DTOs.RobotTaskDetails;
|
|
using PARR.Domain.DTOs.Shared;
|
|
using PARR.Domain.Enums;
|
|
|
|
namespace PARR.Core.Services.RobotTaskDetailsServices.Implementations
|
|
{
|
|
internal class RobotTaskDetailsService : IRobotTaskDetailsService
|
|
{
|
|
private readonly ILogger<RobotTaskDetailsService> _logger;
|
|
private readonly IRobotConfigurationRepository _robotConfigurationRepository;
|
|
private readonly IMapper _mapper;
|
|
private readonly IRobotRepository _robotRepository;
|
|
private readonly ITaskStatusRepository _taskStatusRepository;
|
|
|
|
public RobotTaskDetailsService(
|
|
ILogger<RobotTaskDetailsService> logger,
|
|
IRobotConfigurationRepository robotConfigurationRepository,
|
|
IMapper mapper,
|
|
IRobotRepository robotRepository,
|
|
ITaskStatusRepository taskStatusRepository
|
|
)
|
|
{
|
|
_logger = logger;
|
|
_robotConfigurationRepository = robotConfigurationRepository;
|
|
_mapper = mapper;
|
|
_robotRepository = robotRepository;
|
|
_taskStatusRepository = taskStatusRepository;
|
|
}
|
|
|
|
public async Task<RobotTaskDetailsResult> GetDetailsAsync(RobotsEnum robot, TaskStatusEnum task)
|
|
{
|
|
var details = await _robotConfigurationRepository.Get()
|
|
.Where(t => t.RobotCode == (int)robot && t.TaskStatusCode == (int)task)
|
|
.GroupBy(t => t.Template!.Job!.Group)
|
|
.Select(t => new
|
|
{
|
|
JobGroup = t.Key,
|
|
TemplatesCount = t.Count()
|
|
}).ToListAsync();
|
|
|
|
var robotObj = await _robotRepository.Get()
|
|
.AsNoTracking()
|
|
.FirstOrDefaultAsync(t => t.Code == (int)robot);
|
|
|
|
var taskObj = await _taskStatusRepository.Get()
|
|
.AsNoTracking()
|
|
.FirstOrDefaultAsync(t => t.Code == (int)task);
|
|
|
|
var result = new RobotTaskDetailsResult
|
|
{
|
|
Robot = _mapper.Map<RobotResult>(robotObj),
|
|
Task = _mapper.Map<RobotTaskStatusResult>(taskObj),
|
|
Details = details.Select(t => new RobotTaskGroupDetailsResult
|
|
{
|
|
JobGroup = _mapper.Map<JobGroupShortResult>(t.JobGroup),
|
|
TemplatesCount = t.TemplatesCount
|
|
}).OrderBy(t => t.JobGroup.GroupName).ToList()
|
|
};
|
|
|
|
return result;
|
|
}
|
|
}
|
|
}
|