feat(api): изменены респонсы Job и JobGroup.
This commit is contained in:
@@ -1,6 +1,8 @@
|
|||||||
namespace PARR.API.Contracts.V1.Requests.Queries
|
using PARR.API.Contracts.V1.Requests.BaseRequests;
|
||||||
|
|
||||||
|
namespace PARR.API.Contracts.V1.Requests.Queries
|
||||||
{
|
{
|
||||||
public class JobQuery
|
public class JobQuery : FullQuery
|
||||||
{
|
{
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Поиск по имени
|
/// Поиск по имени
|
||||||
|
|||||||
@@ -1,6 +1,4 @@
|
|||||||
using PARR.DAL.Models.Job;
|
namespace PARR.API.Contracts.V1.Responses
|
||||||
|
|
||||||
namespace PARR.API.Contracts.V1.Responses
|
|
||||||
{
|
{
|
||||||
public class JobBaseResponse
|
public class JobBaseResponse
|
||||||
{
|
{
|
||||||
@@ -10,24 +8,65 @@ namespace PARR.API.Contracts.V1.Responses
|
|||||||
|
|
||||||
public required string TemplateNameMask { get; set; }
|
public required string TemplateNameMask { get; set; }
|
||||||
|
|
||||||
public TnkResponse? Tnk { get; set; }
|
public required string WorkName { get; set; }
|
||||||
public JobGroupBaseResponse? Group { get; set; }
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
public class JobResponse : JobBaseResponse
|
public class JobResponse : JobBaseResponse
|
||||||
{
|
{
|
||||||
public int TemplatesCount { get; set; }
|
|
||||||
|
public TnkResponse? Tnk { get; set; }
|
||||||
|
|
||||||
|
public JobGroupBaseResponse? Group { get; set; }
|
||||||
|
|
||||||
|
public int? TemplatesCount { get; set; }
|
||||||
|
|
||||||
|
public List<UnitFilterResponse>? UnitFilters { get; set; }
|
||||||
|
|
||||||
#region Статистика
|
#region Статистика
|
||||||
|
|
||||||
public TemplateStats? TemplateStatistics { get; set; }
|
//public TemplateStats? TemplateStatistics { get; set; }
|
||||||
|
|
||||||
public ScheduleStats? ScheduleStatistics { get; set; }
|
//public ScheduleStats? ScheduleStatistics { get; set; }
|
||||||
|
|
||||||
#endregion
|
#endregion
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
public class UnitFilterResponse
|
||||||
|
{
|
||||||
|
public required string UnitFilterMask { get; set; }
|
||||||
|
|
||||||
|
public List<FieldFilterResponse>? FieldFilters { get; set; }
|
||||||
|
|
||||||
|
public List<RelationshipFilterResponse>? RelationshipFilters { get; set; }
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
public class FieldFilterResponse
|
||||||
|
{
|
||||||
|
public required FieldResponse Field { get; set; }
|
||||||
|
|
||||||
|
public string? ValueMask { get; set; }
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
public class RelationshipFilterResponse
|
||||||
|
{
|
||||||
|
public required FieldResponse Field { get; set; }
|
||||||
|
|
||||||
|
public bool? IsParent { get; set; }
|
||||||
|
|
||||||
|
public string? ValueMask { get; set; }
|
||||||
|
|
||||||
|
public bool? IsFullMatch { get; set; }
|
||||||
|
|
||||||
|
public bool? IsInverse { get; set; }
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
public class TemplateStats
|
public class TemplateStats
|
||||||
{
|
{
|
||||||
/// <summary>
|
/// <summary>
|
||||||
@@ -32,9 +32,9 @@
|
|||||||
|
|
||||||
public bool IsAutoDistributionEnabled { get; set; }
|
public bool IsAutoDistributionEnabled { get; set; }
|
||||||
|
|
||||||
public UnitBaseResponse? Unit { get; set; }
|
public UnitResponse? Unit { get; set; }
|
||||||
|
|
||||||
public JobBaseResponse? Job { get; set; }
|
public JobResponse? Job { get; set; }
|
||||||
|
|
||||||
public ProcessResponse? Process { get; set; }
|
public ProcessResponse? Process { get; set; }
|
||||||
|
|
||||||
|
|||||||
@@ -18,15 +18,15 @@
|
|||||||
/// <summary>
|
/// <summary>
|
||||||
/// Response с всеми аттребутами и их значениями
|
/// Response с всеми аттребутами и их значениями
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public class UnitWithAttributesResponse : UnitBaseResponse
|
public class UnitWithAttributesResponse : UnitResponse
|
||||||
{
|
{
|
||||||
public DateTimeOffset? LastLogon { get; set; }
|
public DateTimeOffset? LastLogon { get; set; }
|
||||||
|
|
||||||
public List<AttributeResponse>? Attributes { get; set; }
|
public List<AttributeResponse>? Attributes { get; set; }
|
||||||
|
|
||||||
public List<UnitBaseResponse>? Parents { get; set; }
|
public List<UnitResponse>? Parents { get; set; }
|
||||||
|
|
||||||
public List<UnitBaseResponse>? Childrens { get; set; }
|
public List<UnitResponse>? Childrens { get; set; }
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
@@ -59,7 +59,7 @@ namespace PARR.API.Controllers.V1
|
|||||||
{
|
{
|
||||||
var paginationFilter = mapper.Map<PaginationFilter>(paginationQuery);
|
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);
|
query = query.OrderBy(t => t.Name);
|
||||||
|
|
||||||
@@ -69,6 +69,21 @@ namespace PARR.API.Controllers.V1
|
|||||||
if (filter.GroupId.HasValue)
|
if (filter.GroupId.HasValue)
|
||||||
query = query.Where(t => t.GroupId == filter.GroupId.Value);
|
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();
|
var jobs = await jobService.GetPage(query, paginationFilter).ToListAsync();
|
||||||
|
|
||||||
if (!jobs.Any())
|
if (!jobs.Any())
|
||||||
@@ -90,12 +105,21 @@ namespace PARR.API.Controllers.V1
|
|||||||
[HttpGet(ApiRoutes.Job.Get)]
|
[HttpGet(ApiRoutes.Job.Get)]
|
||||||
public async Task<IActionResult> GetById([FromRoute] Guid id)
|
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)
|
if (job == null)
|
||||||
return NotFound();
|
return NotFound();
|
||||||
|
|
||||||
var response = mapper.Map<JobResponse>(job);
|
var response = mapper.Map<JobResponse>(job);
|
||||||
|
|
||||||
response.TemplatesCount = await templateService.Get().CountAsync(t => t.JobId == id);
|
response.TemplatesCount = await templateService.Get().CountAsync(t => t.JobId == id);
|
||||||
|
|
||||||
var statistics = await GetStatisticsAsync(response.Id);
|
var statistics = await GetStatisticsAsync(response.Id);
|
||||||
@@ -270,8 +294,8 @@ namespace PARR.API.Controllers.V1
|
|||||||
|
|
||||||
private void BindStatistics(JobResponse job, JobStatModel statistics)
|
private void BindStatistics(JobResponse job, JobStatModel statistics)
|
||||||
{
|
{
|
||||||
job.TemplateStatistics = new TemplateStats { Activated = statistics.TemplateStatistics.Activated, Errors = statistics.TemplateStatistics.Errors, Synchronized = statistics.TemplateStatistics.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 };
|
//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.Extensions;
|
||||||
using PARR.API.Services.Interfaces;
|
using PARR.API.Services.Interfaces;
|
||||||
using PARR.Constants;
|
using PARR.Constants;
|
||||||
|
using PARR.DAL.Contracts;
|
||||||
using PARR.DAL.DomainModels;
|
using PARR.DAL.DomainModels;
|
||||||
using PARR.DAL.Models;
|
using PARR.DAL.Models;
|
||||||
using PARR.DAL.Models.Job;
|
using PARR.DAL.Models.Job;
|
||||||
|
using PARR.DAL.Services.Interfaces;
|
||||||
using PARR.DAL.Services.Interfaces.Job;
|
using PARR.DAL.Services.Interfaces.Job;
|
||||||
|
|
||||||
namespace PARR.API.Controllers.V1
|
namespace PARR.API.Controllers.V1
|
||||||
@@ -30,7 +32,9 @@ namespace PARR.API.Controllers.V1
|
|||||||
private readonly IUriService uriService;
|
private readonly IUriService uriService;
|
||||||
private readonly IJobGroupService groupService;
|
private readonly IJobGroupService groupService;
|
||||||
private readonly IJobService jobService;
|
private readonly IJobService jobService;
|
||||||
|
private readonly IEsppSchTypeConfigService esppConfigService;
|
||||||
private readonly IValidator<JobGroupRequest> validator;
|
private readonly IValidator<JobGroupRequest> validator;
|
||||||
|
private readonly SettingsFromDb settingsFromDb;
|
||||||
|
|
||||||
public JobGroupController(
|
public JobGroupController(
|
||||||
ILogger<JobController> logger,
|
ILogger<JobController> logger,
|
||||||
@@ -38,7 +42,9 @@ namespace PARR.API.Controllers.V1
|
|||||||
IUriService uriService,
|
IUriService uriService,
|
||||||
IJobGroupService groupService,
|
IJobGroupService groupService,
|
||||||
IJobService jobService,
|
IJobService jobService,
|
||||||
IValidator<JobGroupRequest> validator
|
IEsppSchTypeConfigService esppConfigService,
|
||||||
|
IValidator<JobGroupRequest> validator,
|
||||||
|
SettingsFromDb settingsFromDb
|
||||||
)
|
)
|
||||||
{
|
{
|
||||||
this.logger = logger;
|
this.logger = logger;
|
||||||
@@ -46,7 +52,9 @@ namespace PARR.API.Controllers.V1
|
|||||||
this.uriService = uriService;
|
this.uriService = uriService;
|
||||||
this.groupService = groupService;
|
this.groupService = groupService;
|
||||||
this.jobService = jobService;
|
this.jobService = jobService;
|
||||||
|
this.esppConfigService = esppConfigService;
|
||||||
this.validator = validator;
|
this.validator = validator;
|
||||||
|
this.settingsFromDb = settingsFromDb;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@@ -66,7 +74,7 @@ namespace PARR.API.Controllers.V1
|
|||||||
if (!string.IsNullOrEmpty(filter.Name))
|
if (!string.IsNullOrEmpty(filter.Name))
|
||||||
query = query.Where(t => t.GroupName.ToLower().Contains(filter.Name.ToLower()));
|
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);
|
query = query.Include(t => t.Jobs).ThenInclude(t => t.Tnk);
|
||||||
|
|
||||||
var jobGroups = await groupService.GetPage(query, paginationFilter).ToListAsync();
|
var jobGroups = await groupService.GetPage(query, paginationFilter).ToListAsync();
|
||||||
@@ -76,6 +84,10 @@ namespace PARR.API.Controllers.V1
|
|||||||
|
|
||||||
var response = mapper.Map<List<JobGroupResponse>>(jobGroups);
|
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);
|
var paginationResponse = new PagedResponse<JobGroupResponse>(response, true).GetPaginatedProps(paginationFilter, query);
|
||||||
|
|
||||||
return Ok(paginationResponse);
|
return Ok(paginationResponse);
|
||||||
@@ -255,7 +267,7 @@ namespace PARR.API.Controllers.V1
|
|||||||
|
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Удалить группу заданий на выполнение работ (только если нет связанных шаблонов)
|
/// Удалить группу заданий на выполнение работ (только если нет связанных заданий)
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="id"></param>
|
/// <param name="id"></param>
|
||||||
/// <returns></returns>
|
/// <returns></returns>
|
||||||
@@ -322,5 +334,29 @@ namespace PARR.API.Controllers.V1
|
|||||||
|
|
||||||
return isScheduleChanged;
|
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);
|
||||||
|
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -114,7 +114,7 @@ namespace PARR.API.MappingProfiles
|
|||||||
.ForMember(d => d.Field, o => o.MapFrom(s => s.Field))
|
.ForMember(d => d.Field, o => o.MapFrom(s => s.Field))
|
||||||
.ForMember(d => d.Value, o => o.MapFrom(s => s.Value));
|
.ForMember(d => d.Value, o => o.MapFrom(s => s.Value));
|
||||||
|
|
||||||
CreateMap<Unit, UnitBaseResponse>()
|
CreateMap<Unit, UnitResponse>()
|
||||||
.Include<Unit, UnitWithAttributesResponse>()
|
.Include<Unit, UnitWithAttributesResponse>()
|
||||||
.ForMember(d => d.Name, o => o.MapFrom(s => s.Name));
|
.ForMember(d => d.Name, o => o.MapFrom(s => s.Name));
|
||||||
|
|
||||||
@@ -300,10 +300,15 @@ namespace PARR.API.MappingProfiles
|
|||||||
#endregion
|
#endregion
|
||||||
|
|
||||||
#region Job
|
#region Job
|
||||||
CreateMap<Job, JobBaseResponse>()
|
CreateMap<Job, JobBaseResponse>();
|
||||||
.Include<Job, JobResponse>();
|
|
||||||
|
|
||||||
CreateMap<Job, JobResponse>();
|
CreateMap<Job, JobResponse>();
|
||||||
|
|
||||||
|
CreateMap<JobUnitFilter, UnitFilterResponse>();
|
||||||
|
CreateMap<FieldFilter, FieldResponse>();
|
||||||
|
CreateMap<FieldFilter, FieldFilterResponse>();
|
||||||
|
CreateMap<JobRelationshipFilter, RelationshipFilterResponse>()
|
||||||
|
.ForMember(d => d.Field, o => o.MapFrom(s => s.UnitField));
|
||||||
|
|
||||||
#endregion
|
#endregion
|
||||||
|
|
||||||
#region JobGroup
|
#region JobGroup
|
||||||
@@ -313,9 +318,9 @@ namespace PARR.API.MappingProfiles
|
|||||||
CreateMap<JobGroup, JobGroupBaseResponse>()
|
CreateMap<JobGroup, JobGroupBaseResponse>()
|
||||||
.ForMember(d => d.Name, o => o.MapFrom(s => s.GroupName));
|
.ForMember(d => d.Name, o => o.MapFrom(s => s.GroupName));
|
||||||
|
|
||||||
CreateMap<JobGroup, JobGroupResponse>()
|
CreateMap<JobGroup, JobGroupResponse>();
|
||||||
.ForMember(d => d.Schedule, o => o.MapFrom<JobGroupScheduleResolver>())
|
//.ForMember(d => d.Schedule, o => o.MapFrom<JobGroupScheduleResolver>())
|
||||||
.ForMember(d => d.JobsCount, o => o.MapFrom(s => s.Jobs.Count()));
|
//.ForMember(d => d.JobsCount, o => o.MapFrom(s => s.Jobs.Count()));
|
||||||
|
|
||||||
#endregion
|
#endregion
|
||||||
|
|
||||||
|
|||||||
@@ -14,7 +14,7 @@ namespace PARR.API.MappingProfiles.Resolvers
|
|||||||
private readonly SettingsFromDb settingsFromDb;
|
private readonly SettingsFromDb settingsFromDb;
|
||||||
|
|
||||||
public JobGroupScheduleResolver(
|
public JobGroupScheduleResolver(
|
||||||
IEsppSchTypeConfigService esppConfigService,
|
IEsppSchTypeConfigService esppConfigService,
|
||||||
ILogger<JobGroupScheduleResolver> logger,
|
ILogger<JobGroupScheduleResolver> logger,
|
||||||
IMapper mapper,
|
IMapper mapper,
|
||||||
SettingsFromDb settingsFromDb
|
SettingsFromDb settingsFromDb
|
||||||
|
|||||||
@@ -9,7 +9,7 @@ namespace PARR.DAL.Models.Job
|
|||||||
{
|
{
|
||||||
[Table("FieldFilters", Schema = DataContextSettings.Job)]
|
[Table("FieldFilters", Schema = DataContextSettings.Job)]
|
||||||
[Comment("Таблица описания критериев выборки аттрибутов ЭК")]
|
[Comment("Таблица описания критериев выборки аттрибутов ЭК")]
|
||||||
public class FieldFilter : IBase
|
public class FieldFilter : IBase//TODO Почему этот не Job тра та та
|
||||||
{
|
{
|
||||||
[Key]
|
[Key]
|
||||||
public Guid Id { get; set; }
|
public Guid Id { get; set; }
|
||||||
@@ -26,7 +26,7 @@ namespace PARR.DAL.Models.Job
|
|||||||
|
|
||||||
|
|
||||||
[ForeignKey(nameof(FieldId))]
|
[ForeignKey(nameof(FieldId))]
|
||||||
public UnitField? Field { get; set; }
|
public UnitField? Field { get; set; }//TODO как-то определитесь уже просто Field или UnitField
|
||||||
|
|
||||||
[ForeignKey(nameof(UnitFilterId))]
|
[ForeignKey(nameof(UnitFilterId))]
|
||||||
public JobUnitFilter? UnitFilter { get; set; }
|
public JobUnitFilter? UnitFilter { get; set; }
|
||||||
|
|||||||
@@ -8,7 +8,7 @@ namespace PARR.DAL.Models.Job
|
|||||||
[Table("RelationshipFilters", Schema = DataContextSettings.Job)]
|
[Table("RelationshipFilters", Schema = DataContextSettings.Job)]
|
||||||
[Comment("Таблица фильтров связей ЭК")]
|
[Comment("Таблица фильтров связей ЭК")]
|
||||||
[PrimaryKey(nameof(UnitFilterId), nameof(FieldId))]
|
[PrimaryKey(nameof(UnitFilterId), nameof(FieldId))]
|
||||||
public class JobRelationshipFilter //: IBase
|
public class JobRelationshipFilter //: IBase //TODO Почему этот Job тра та та
|
||||||
{
|
{
|
||||||
//[Key]
|
//[Key]
|
||||||
//public Guid Id { get; set; }
|
//public Guid Id { get; set; }
|
||||||
@@ -45,7 +45,7 @@ namespace PARR.DAL.Models.Job
|
|||||||
|
|
||||||
|
|
||||||
[ForeignKey(nameof(FieldId))]
|
[ForeignKey(nameof(FieldId))]
|
||||||
public UnitField? UnitField { get; set; }
|
public UnitField? UnitField { get; set; }//TODO как-то определитесь уже просто Field или UnitField
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user