feat(api): изменены респонсы Job и JobGroup.
This commit is contained in:
@@ -59,7 +59,7 @@ namespace PARR.API.Controllers.V1
|
||||
{
|
||||
var paginationFilter = mapper.Map<PaginationFilter>(paginationQuery);
|
||||
|
||||
IQueryable<Job> query = jobService.Get().Include(t => t.Tnk).Include(t=>t.Group);
|
||||
IQueryable<Job> query = jobService.Get();
|
||||
|
||||
query = query.OrderBy(t => t.Name);
|
||||
|
||||
@@ -69,6 +69,21 @@ namespace PARR.API.Controllers.V1
|
||||
if (filter.GroupId.HasValue)
|
||||
query = query.Where(t => t.GroupId == filter.GroupId.Value);
|
||||
|
||||
if (filter.IsFull)
|
||||
{
|
||||
query = query
|
||||
.Include(t => t.Tnk)
|
||||
.Include(t => t.Group);
|
||||
|
||||
query = query
|
||||
.Include(t => t.UnitFilters)
|
||||
.ThenInclude(t => t.FieldFilters)
|
||||
.ThenInclude(t => t.Field)
|
||||
.Include(t => t.UnitFilters)
|
||||
.ThenInclude(t => t.RelationshipFilters)
|
||||
.ThenInclude(t => t.UnitField);
|
||||
}
|
||||
|
||||
var jobs = await jobService.GetPage(query, paginationFilter).ToListAsync();
|
||||
|
||||
if (!jobs.Any())
|
||||
@@ -90,12 +105,21 @@ namespace PARR.API.Controllers.V1
|
||||
[HttpGet(ApiRoutes.Job.Get)]
|
||||
public async Task<IActionResult> GetById([FromRoute] Guid id)
|
||||
{
|
||||
var job = await jobService.Get().Include(t => t.Tnk).FirstOrDefaultAsync(t => t.Id == id);
|
||||
var job = await jobService.Get()
|
||||
.Include(t => t.Tnk)
|
||||
.Include(t => t.Group)
|
||||
.Include(t => t.UnitFilters)
|
||||
.ThenInclude(t => t.FieldFilters)
|
||||
.ThenInclude(t => t.Field)
|
||||
.Include(t => t.UnitFilters)
|
||||
.ThenInclude(t => t.RelationshipFilters)
|
||||
.FirstOrDefaultAsync(t => t.Id == id);
|
||||
|
||||
if (job == null)
|
||||
return NotFound();
|
||||
|
||||
var response = mapper.Map<JobResponse>(job);
|
||||
|
||||
response.TemplatesCount = await templateService.Get().CountAsync(t => t.JobId == id);
|
||||
|
||||
var statistics = await GetStatisticsAsync(response.Id);
|
||||
@@ -270,8 +294,8 @@ namespace PARR.API.Controllers.V1
|
||||
|
||||
private void BindStatistics(JobResponse job, JobStatModel statistics)
|
||||
{
|
||||
job.TemplateStatistics = new TemplateStats { Activated = statistics.TemplateStatistics.Activated, Errors = statistics.TemplateStatistics.Errors, Synchronized = statistics.TemplateStatistics.Synchronized };
|
||||
job.ScheduleStatistics = new ScheduleStats { Activated = statistics.ScheduleStatistics.Activated, Errors = statistics.ScheduleStatistics.Errors, Synchronized = statistics.ScheduleStatistics.Synchronized };
|
||||
//job.TemplateStatistics = new TemplateStats { Activated = statistics.TemplateStatistics.Activated, Errors = statistics.TemplateStatistics.Errors, Synchronized = statistics.TemplateStatistics.Synchronized };
|
||||
//job.ScheduleStatistics = new ScheduleStats { Activated = statistics.ScheduleStatistics.Activated, Errors = statistics.ScheduleStatistics.Errors, Synchronized = statistics.ScheduleStatistics.Synchronized };
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -12,9 +12,11 @@ using PARR.API.Controllers.V1.Base;
|
||||
using PARR.API.Extensions;
|
||||
using PARR.API.Services.Interfaces;
|
||||
using PARR.Constants;
|
||||
using PARR.DAL.Contracts;
|
||||
using PARR.DAL.DomainModels;
|
||||
using PARR.DAL.Models;
|
||||
using PARR.DAL.Models.Job;
|
||||
using PARR.DAL.Services.Interfaces;
|
||||
using PARR.DAL.Services.Interfaces.Job;
|
||||
|
||||
namespace PARR.API.Controllers.V1
|
||||
@@ -30,7 +32,9 @@ namespace PARR.API.Controllers.V1
|
||||
private readonly IUriService uriService;
|
||||
private readonly IJobGroupService groupService;
|
||||
private readonly IJobService jobService;
|
||||
private readonly IEsppSchTypeConfigService esppConfigService;
|
||||
private readonly IValidator<JobGroupRequest> validator;
|
||||
private readonly SettingsFromDb settingsFromDb;
|
||||
|
||||
public JobGroupController(
|
||||
ILogger<JobController> logger,
|
||||
@@ -38,7 +42,9 @@ namespace PARR.API.Controllers.V1
|
||||
IUriService uriService,
|
||||
IJobGroupService groupService,
|
||||
IJobService jobService,
|
||||
IValidator<JobGroupRequest> validator
|
||||
IEsppSchTypeConfigService esppConfigService,
|
||||
IValidator<JobGroupRequest> validator,
|
||||
SettingsFromDb settingsFromDb
|
||||
)
|
||||
{
|
||||
this.logger = logger;
|
||||
@@ -46,7 +52,9 @@ namespace PARR.API.Controllers.V1
|
||||
this.uriService = uriService;
|
||||
this.groupService = groupService;
|
||||
this.jobService = jobService;
|
||||
this.esppConfigService = esppConfigService;
|
||||
this.validator = validator;
|
||||
this.settingsFromDb = settingsFromDb;
|
||||
}
|
||||
|
||||
|
||||
@@ -66,7 +74,7 @@ namespace PARR.API.Controllers.V1
|
||||
if (!string.IsNullOrEmpty(filter.Name))
|
||||
query = query.Where(t => t.GroupName.ToLower().Contains(filter.Name.ToLower()));
|
||||
|
||||
if (filter.IsFull)//TODO а зачем он тогда вообще???
|
||||
if (filter.IsFull)
|
||||
query = query.Include(t => t.Jobs).ThenInclude(t => t.Tnk);
|
||||
|
||||
var jobGroups = await groupService.GetPage(query, paginationFilter).ToListAsync();
|
||||
@@ -76,6 +84,10 @@ namespace PARR.API.Controllers.V1
|
||||
|
||||
var response = mapper.Map<List<JobGroupResponse>>(jobGroups);
|
||||
|
||||
if (filter.IsFull)
|
||||
foreach (var jobGroupResponse in response)
|
||||
await AppendMissingDataAsync(jobGroupResponse);
|
||||
|
||||
var paginationResponse = new PagedResponse<JobGroupResponse>(response, true).GetPaginatedProps(paginationFilter, query);
|
||||
|
||||
return Ok(paginationResponse);
|
||||
@@ -255,7 +267,7 @@ namespace PARR.API.Controllers.V1
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// Удалить группу заданий на выполнение работ (только если нет связанных шаблонов)
|
||||
/// Удалить группу заданий на выполнение работ (только если нет связанных заданий)
|
||||
/// </summary>
|
||||
/// <param name="id"></param>
|
||||
/// <returns></returns>
|
||||
@@ -322,5 +334,29 @@ namespace PARR.API.Controllers.V1
|
||||
|
||||
return isScheduleChanged;
|
||||
}
|
||||
|
||||
|
||||
private async Task AppendMissingDataAsync(JobGroupResponse jobGroupResponse)
|
||||
{
|
||||
var schedule = await esppConfigService.GetEsppScheduleDtoAsync(jobGroupResponse.Id);
|
||||
|
||||
if (schedule == null)
|
||||
{
|
||||
logger.LogError($"Не смог замапить расписание, так как оно null. JobGroupId: {jobGroupResponse.Id}");
|
||||
return;
|
||||
}
|
||||
|
||||
var scheduleResponse = new JobGroupScheduleResponse
|
||||
{
|
||||
Timezone = settingsFromDb.ScheduleTimezone,
|
||||
TypeSchedule = mapper.Map<EsppScheduleTypeScheduleResponse>(schedule.TypeSchedule),
|
||||
Values = mapper.Map<List<EsppScheduleValResponse>>(schedule.Values).OrderBy(t => t.Order).ToList()
|
||||
};
|
||||
|
||||
jobGroupResponse.Schedule = scheduleResponse;
|
||||
|
||||
jobGroupResponse.JobsCount = await jobService.Get().CountAsync(t => t.GroupId == jobGroupResponse.Id);
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user