feat(api): jobGroup при создании и обновлении принимает поле GroupingUnitFieldId. Валидации. Контроллеры KiiUnitController, RegionalEkPtkGroupController
This commit is contained in:
@@ -100,7 +100,8 @@ namespace PARR.API.Controllers.V1
|
||||
{
|
||||
query = query
|
||||
.Include(t => t.Tnk)
|
||||
.Include(t => t.Group).ThenInclude(t => t.GroupType);
|
||||
.Include(t => t.Group).ThenInclude(t => t.GroupType)
|
||||
.Include(t => t.Group).ThenInclude(t => t.GroupingUnitField);
|
||||
|
||||
query = query
|
||||
.Include(t => t.UnitFilters)
|
||||
@@ -140,6 +141,7 @@ namespace PARR.API.Controllers.V1
|
||||
var job = await jobService.Get()
|
||||
.Include(t => t.Tnk)
|
||||
.Include(t => t.Group).ThenInclude(t => t.GroupType)
|
||||
.Include(t => t.Group).ThenInclude(t => t.GroupingUnitField)
|
||||
.Include(t => t.UnitFilters)
|
||||
.ThenInclude(t => t.FieldFilters)
|
||||
.ThenInclude(t => t.UnitField)
|
||||
@@ -178,14 +180,15 @@ namespace PARR.API.Controllers.V1
|
||||
return BadRequest(new Response(jobValidateResult.Errors));
|
||||
#endregion
|
||||
|
||||
//TODO: !!!!!!! проверить, если тип ЗОНТИК или ГРУППИРОВКА, то обязательно должны быть заполнены поля min max
|
||||
|
||||
#region Проверка существования работы с такими же параметрами
|
||||
|
||||
var isExistTheSameLinks = await jobService.Get()
|
||||
.Include(t => t.Group).ThenInclude(t => t.GroupType)
|
||||
.CountAsync(t =>
|
||||
//t.Group!.IsUmbrella == true &&
|
||||
t.Group!.GroupType!.Code == JobGroupTypesEnum.Umbrella &&
|
||||
//t.Group!.GroupType!.Code == JobGroupTypesEnum.Umbrella
|
||||
(t.Group!.GroupType!.Code == JobGroupTypesEnum.Umbrella || t.Group!.GroupType!.Code == JobGroupTypesEnum.Group) &&
|
||||
t.GroupId == request.GroupId &&
|
||||
(t.MinValueRelationships == request.MinValueRelationships ||
|
||||
t.MaxValueRelationships == request.MaxValueRelationships)
|
||||
@@ -215,6 +218,7 @@ namespace PARR.API.Controllers.V1
|
||||
var createdJob = await jobService.Get()
|
||||
.Include(t => t.Tnk)
|
||||
.Include(t => t.Group).ThenInclude(t => t.GroupType)
|
||||
.Include(t => t.Group).ThenInclude(t => t.GroupingUnitField)
|
||||
.Include(t => t.UnitFilters)
|
||||
.ThenInclude(t => t.FieldFilters)
|
||||
.ThenInclude(t => t.UnitField)
|
||||
@@ -249,6 +253,7 @@ namespace PARR.API.Controllers.V1
|
||||
var orig = await jobService.Get()
|
||||
.Include(t => t.Tnk)
|
||||
.Include(t => t.Group).ThenInclude(t => t.GroupType)
|
||||
.Include(t => t.Group).ThenInclude(t => t.GroupingUnitField)
|
||||
.Include(t => t.UnitFilters)
|
||||
.ThenInclude(t => t.FieldFilters)
|
||||
.Include(t => t.UnitFilters)
|
||||
@@ -263,6 +268,11 @@ namespace PARR.API.Controllers.V1
|
||||
// если изменили маску шаблона, ниже отправим в очередь, на изменение связанных имен шаблонов
|
||||
var isChangedTemplateNameMask = orig.TemplateNameMask != request.TemplateNameMask.Trim();
|
||||
|
||||
|
||||
//TODO: ВОТ ЭТО ВООБЩЕ МЫ БУДЕМ ПРОВЕРЯТЬ, АААА???? - Проверка существования работы с такими же параметрами
|
||||
|
||||
//TODO: !!!!!!! проверить, если тип ЗОНТИК или ГРУППИРОВКА, то обязательно должны быть заполнены поля min max
|
||||
|
||||
#region обновление полей задания на работу
|
||||
|
||||
orig.Name = request.Name.Trim();
|
||||
@@ -331,6 +341,7 @@ namespace PARR.API.Controllers.V1
|
||||
var updatedJob = await jobService.Get()
|
||||
.Include(t => t.Tnk)
|
||||
.Include(t => t.Group).ThenInclude(t => t.GroupType)
|
||||
.Include(t => t.Group).ThenInclude(t => t.GroupingUnitField)
|
||||
.Include(t => t.UnitFilters)
|
||||
.ThenInclude(t => t.FieldFilters)
|
||||
.ThenInclude(t => t.UnitField)
|
||||
|
||||
@@ -34,6 +34,7 @@ namespace PARR.API.Controllers.V1
|
||||
private readonly IJobService jobService;
|
||||
private readonly IEsppSchTypeConfigService esppConfigService;
|
||||
private readonly IValidator<JobGroupRequest> validator;
|
||||
private readonly IJobGroupTypeService jobGroupTypeService;
|
||||
private readonly SettingsFromDb settingsFromDb;
|
||||
|
||||
public JobGroupController(
|
||||
@@ -44,6 +45,7 @@ namespace PARR.API.Controllers.V1
|
||||
IJobService jobService,
|
||||
IEsppSchTypeConfigService esppConfigService,
|
||||
IValidator<JobGroupRequest> validator,
|
||||
IJobGroupTypeService jobGroupTypeService,
|
||||
SettingsFromDb settingsFromDb
|
||||
)
|
||||
{
|
||||
@@ -54,6 +56,7 @@ namespace PARR.API.Controllers.V1
|
||||
this.jobService = jobService;
|
||||
this.esppConfigService = esppConfigService;
|
||||
this.validator = validator;
|
||||
this.jobGroupTypeService = jobGroupTypeService;
|
||||
this.settingsFromDb = settingsFromDb;
|
||||
}
|
||||
|
||||
@@ -67,7 +70,9 @@ namespace PARR.API.Controllers.V1
|
||||
{
|
||||
var paginationFilter = mapper.Map<PaginationFilter>(paginationQuery);
|
||||
|
||||
IQueryable<JobGroup> query = groupService.Get().Include(t => t.GroupType);
|
||||
IQueryable<JobGroup> query = groupService.Get()
|
||||
.Include(t => t.GroupType)
|
||||
.Include(t => t.GroupingUnitField);
|
||||
|
||||
query = query.OrderBy(t => t.GroupName);
|
||||
|
||||
@@ -105,6 +110,7 @@ namespace PARR.API.Controllers.V1
|
||||
var jobGroup = await groupService.Get()
|
||||
.Include(t => t.Jobs).ThenInclude(t => t.Tnk)
|
||||
.Include(t => t.GroupType)
|
||||
.Include(t => t.GroupingUnitField)
|
||||
.FirstOrDefaultAsync(t => t.Id == id);
|
||||
|
||||
if (jobGroup == null)
|
||||
@@ -136,6 +142,7 @@ namespace PARR.API.Controllers.V1
|
||||
GroupName = request.Name.Trim(),
|
||||
//IsUmbrella = request.IsUmbrella,
|
||||
GroupTypeId = request.GroupTypeId,
|
||||
GroupingUnitFieldId = await GetGroupingUnitFieldIdAsync(request),
|
||||
ShortDescription = request.ShortDescription.Trim(),
|
||||
FullDescription = request.FullDescription.Trim(),
|
||||
Solution = request.Solution.Trim(),
|
||||
@@ -167,6 +174,7 @@ namespace PARR.API.Controllers.V1
|
||||
|
||||
var createdJobGroup = await groupService.Get().Include(t => t.Jobs).ThenInclude(t => t.Tnk)
|
||||
.Include(t => t.GroupType)
|
||||
.Include(t => t.GroupingUnitField)
|
||||
.FirstAsync(t => t.Id == jobGroup.Id);
|
||||
|
||||
var locationUri = uriService.GetUri(ApiRoutes.JobGroup.Get, ApiRoutes.JobGroup.getParam, createdJobGroup.Id);
|
||||
@@ -206,6 +214,7 @@ namespace PARR.API.Controllers.V1
|
||||
orig.GroupName = request.Name.Trim();
|
||||
//orig.IsUmbrella = request.IsUmbrella;
|
||||
orig.GroupTypeId = request.GroupTypeId;
|
||||
orig.GroupingUnitFieldId = await GetGroupingUnitFieldIdAsync(request);
|
||||
orig.ShortDescription = request.ShortDescription.Trim();
|
||||
orig.FullDescription = request.FullDescription.Trim();
|
||||
orig.Solution = request.Solution.Trim();
|
||||
@@ -263,6 +272,7 @@ namespace PARR.API.Controllers.V1
|
||||
.Include(t => t.Jobs)
|
||||
.ThenInclude(t => t.Tnk)
|
||||
.Include(t => t.GroupType)
|
||||
.Include(t => t.GroupingUnitField)
|
||||
.FirstAsync(t => t.Id == orig.Id);
|
||||
|
||||
var response = mapper.Map<JobGroupResponse>(updatedJobGroup);
|
||||
@@ -361,7 +371,34 @@ namespace PARR.API.Controllers.V1
|
||||
jobGroupResponse.Schedule = scheduleResponse;
|
||||
|
||||
jobGroupResponse.JobsCount = await jobService.Get().CountAsync(t => t.GroupId == jobGroupResponse.Id);
|
||||
}
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// Смотрим на тип Группы, и возвращаем GroupingUnitFieldId или обнуляем его
|
||||
/// </summary>
|
||||
/// <param name="request"></param>
|
||||
/// <returns></returns>
|
||||
private async Task<Guid?> GetGroupingUnitFieldIdAsync(JobGroupRequest request)
|
||||
{
|
||||
// Если request.GroupingUnitFieldId == null, то ничего проверять не будем
|
||||
if (request.GroupingUnitFieldId == null)
|
||||
return request.GroupingUnitFieldId;
|
||||
|
||||
|
||||
var groupingType = await jobGroupTypeService.Get().FirstAsync(t => t.Code == JobGroupTypesEnum.Group);
|
||||
|
||||
if (request.GroupTypeId == groupingType.Id)
|
||||
{
|
||||
// Это сгруппированный тип, все ок
|
||||
return request.GroupingUnitFieldId;
|
||||
}
|
||||
else
|
||||
{
|
||||
// Это не сгруппированный тип, обнуляем GroupingUnitFieldId
|
||||
logger.LogWarning($"При сохраненни JobGroup, был передан {nameof(request.GroupingUnitFieldId)}: {request.GroupingUnitFieldId}, но при этом тип группы был не ГРУППА, а {request.GroupTypeId}. Обнулил request.GroupingUnitFieldId");
|
||||
return null;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
57
PARR.API/Controllers/V1/KiiUnitController.cs
Normal file
57
PARR.API/Controllers/V1/KiiUnitController.cs
Normal file
@@ -0,0 +1,57 @@
|
||||
using AutoMapper;
|
||||
using Microsoft.AspNetCore.Authorization;
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using PARR.API.Contracts.V1;
|
||||
using PARR.API.Contracts.V1.Responses;
|
||||
using PARR.API.Contracts.V1.Responses.Base;
|
||||
using PARR.API.Controllers.V1.Base;
|
||||
using PARR.Constants;
|
||||
using PARR.DAL.Services.Interfaces.Unit;
|
||||
|
||||
namespace PARR.API.Controllers.V1
|
||||
{
|
||||
/// <summary>
|
||||
/// Список КИИ ЭК
|
||||
/// </summary>
|
||||
[Authorize(Roles = ParrRoles.Administrator.Role)]
|
||||
public class KiiUnitController : BaseApiController
|
||||
{
|
||||
private readonly IMapper mapper;
|
||||
private readonly IUnitKiiUnitService unitKiiUnitService;
|
||||
|
||||
public KiiUnitController(
|
||||
IMapper mapper,
|
||||
IUnitKiiUnitService unitKiiUnitService
|
||||
)
|
||||
{
|
||||
this.mapper = mapper;
|
||||
this.unitKiiUnitService = unitKiiUnitService;
|
||||
}
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// Список КИИ ЭК
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
[HttpGet(ApiRoutes.KiiUnit.GetAll)]
|
||||
public async Task<IActionResult> GetAll()
|
||||
{
|
||||
var query = unitKiiUnitService.Get()
|
||||
.Include(t => t.Unit)
|
||||
.Select(t => t.Unit)
|
||||
.OrderBy(t => t.Name);
|
||||
|
||||
var units = await query.ToListAsync();
|
||||
|
||||
if (!units.Any())
|
||||
return NoContent();
|
||||
|
||||
var response = mapper.Map<List<UnitBaseResponse>>(units);
|
||||
|
||||
return Ok(new Response<List<UnitBaseResponse>>(response, true));
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
56
PARR.API/Controllers/V1/RegionalEkPtkGroupController.cs
Normal file
56
PARR.API/Controllers/V1/RegionalEkPtkGroupController.cs
Normal file
@@ -0,0 +1,56 @@
|
||||
using AutoMapper;
|
||||
using Microsoft.AspNetCore.Authorization;
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using PARR.API.Contracts.V1;
|
||||
using PARR.API.Contracts.V1.Responses;
|
||||
using PARR.API.Contracts.V1.Responses.Base;
|
||||
using PARR.API.Controllers.V1.Base;
|
||||
using PARR.Constants;
|
||||
using PARR.DAL.Services.Interfaces.Unit;
|
||||
|
||||
namespace PARR.API.Controllers.V1
|
||||
{
|
||||
/// <summary>
|
||||
/// Региональные ЭК ПТК для групповых работ
|
||||
/// </summary>
|
||||
[Authorize(Roles = ParrRoles.Administrator.Role)]
|
||||
public class RegionalEkPtkGroupController : BaseApiController
|
||||
{
|
||||
private readonly IMapper mapper;
|
||||
private readonly IUnitRegionalEkPtkGroupService unitRegionalEkPtkGroupService;
|
||||
|
||||
public RegionalEkPtkGroupController(
|
||||
IMapper mapper,
|
||||
IUnitRegionalEkPtkGroupService unitRegionalEkPtkGroupService
|
||||
)
|
||||
{
|
||||
this.mapper = mapper;
|
||||
this.unitRegionalEkPtkGroupService = unitRegionalEkPtkGroupService;
|
||||
}
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// Региональные ЭК ПТК для групповых работ
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
[HttpGet(ApiRoutes.RegionalEkPtkGroup.GetAll)]
|
||||
public async Task<IActionResult> GetAll()
|
||||
{
|
||||
var query = unitRegionalEkPtkGroupService.Get()
|
||||
.Include(t => t.FieldValue)
|
||||
.Select(t => t.FieldValue)
|
||||
.OrderBy(t => t.Value);
|
||||
|
||||
var objs = await query.ToListAsync();
|
||||
|
||||
if (!objs.Any())
|
||||
return NoContent();
|
||||
|
||||
var response = mapper.Map<List<UnitFieldValueResponse>>(objs);
|
||||
|
||||
return Ok(new Response<List<UnitFieldValueResponse>>(response, true));
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user