feat(all): исправления после добавления таблицы WorkGroup. Доработана логика генерации шаблонов с учетом рабочих групп
This commit is contained in:
@@ -58,7 +58,8 @@ namespace PARR.API.Controllers.V1
|
||||
{
|
||||
query = query.Include(t => t.Application).ThenInclude(t => t!.ApplicationType)
|
||||
.Include(t => t.Work)
|
||||
.Include(t => t.Templates);
|
||||
.Include(t => t.Templates)
|
||||
.Include(t => t.WorkGroups).ThenInclude(t => t.WorkGroup);
|
||||
}
|
||||
|
||||
query = query.OrderBy(t => t.ShortDescription);
|
||||
@@ -93,6 +94,7 @@ namespace PARR.API.Controllers.V1
|
||||
.Include(t => t.Application).ThenInclude(t => t!.ApplicationType)
|
||||
.Include(t => t.Work)
|
||||
.Include(t => t.Templates)
|
||||
.Include(t => t.WorkGroups).ThenInclude(t => t.WorkGroup)
|
||||
.FirstOrDefaultAsync(t => t.Id == id);
|
||||
|
||||
if (applicationInWork == null)
|
||||
@@ -149,6 +151,16 @@ namespace PARR.API.Controllers.V1
|
||||
});
|
||||
});
|
||||
|
||||
//Добавляем рабочие группы
|
||||
request.WorkGroups.ForEach(workGroupId =>
|
||||
{
|
||||
applicationInWork.WorkGroups.Add(new AppInWorkInWorkGroup
|
||||
{
|
||||
ApplicationsInWorkId = applicationInWork.Id,
|
||||
WorkGroupId = workGroupId
|
||||
});
|
||||
});
|
||||
|
||||
if (!await applicationsInWorkService.CreateAsync(applicationInWork) || !await applicationsInWorkService.CommitAsync())
|
||||
return BadRequest(new Response(false, new List<ErrorModel> { new ErrorModel { Message = "Ошибка при созании задания на выполнение работ" } }));
|
||||
|
||||
@@ -159,6 +171,7 @@ namespace PARR.API.Controllers.V1
|
||||
.Include(t => t.Application).ThenInclude(t => t!.ApplicationType)
|
||||
.Include(t => t.Work)
|
||||
.Include(t => t.Templates)
|
||||
.Include(t => t.WorkGroups).ThenInclude(t => t.WorkGroup)
|
||||
.FirstAsync(t => t.Id == applicationInWork.Id);
|
||||
|
||||
var locationUri = uriService.GetUri(ApiRoutes.Job.Get, ApiRoutes.Job.getParam, createdApplicationInWork.Id);
|
||||
@@ -215,6 +228,18 @@ namespace PARR.API.Controllers.V1
|
||||
});
|
||||
});
|
||||
|
||||
//Обновляем рабочие группы
|
||||
orig.WorkGroups.Clear();
|
||||
request.WorkGroups.ForEach(workGroupId =>
|
||||
{
|
||||
orig.WorkGroups.Add(new AppInWorkInWorkGroup
|
||||
{
|
||||
ApplicationsInWorkId = orig.Id,
|
||||
WorkGroupId = workGroupId
|
||||
});
|
||||
});
|
||||
|
||||
|
||||
if (!await applicationsInWorkService.CommitAsync())
|
||||
return BadRequest(new Response(false, new List<ErrorModel> { new ErrorModel { Message = "Ошибка при изменении задания на выполнение работ." } }));
|
||||
|
||||
@@ -227,6 +252,7 @@ namespace PARR.API.Controllers.V1
|
||||
.Include(t => t.Application).ThenInclude(t => t!.ApplicationType)
|
||||
.Include(t => t.Work)
|
||||
.Include(t => t.Templates)
|
||||
.Include(t => t.WorkGroups).ThenInclude(t => t.WorkGroup)
|
||||
.FirstAsync(t => t.Id == orig.Id);
|
||||
|
||||
return Ok(new Response<ApplicationInWorkResponse>(mapper.Map<ApplicationInWorkResponse>(updatedApplicationInWork), true));
|
||||
|
||||
@@ -63,19 +63,21 @@ namespace PARR.API.Controllers.V1
|
||||
// шаблоны
|
||||
query = query.Include(t => t.Template)
|
||||
.ThenInclude(t => t!.Host).ThenInclude(t => t!.ResponseArea)
|
||||
.ThenInclude(t => t!.Hosts).ThenInclude(t => t.WorkGroupItem)
|
||||
.Include(t => t.Template)
|
||||
.ThenInclude(a => a!.ApplicationsInWork)
|
||||
.ThenInclude(w => w!.Work)
|
||||
.ThenInclude(t => t!.Tnk)
|
||||
.ThenInclude(s => s!.Subprocess)
|
||||
.ThenInclude(p => p!.Process)
|
||||
.AsSplitQuery();
|
||||
.ThenInclude(p => p!.Process);
|
||||
//.AsSplitQuery();
|
||||
break;
|
||||
case RobotsEnum.ScheduleOrder:
|
||||
//расписание
|
||||
// тут не делаем AsSplitQuery, не может подтянуть все таблицы
|
||||
query = query.Include(t => t.Template)
|
||||
.ThenInclude(t => t!.Host).ThenInclude(t => t!.ResponseArea)
|
||||
.ThenInclude(t => t!.Hosts).ThenInclude(t => t.WorkGroupItem)
|
||||
.Include(t => t.Template)
|
||||
.ThenInclude(t => t!.ApplicationsInWork)
|
||||
.ThenInclude(t => t!.EsppSchValues)
|
||||
|
||||
83
PARR.API/Controllers/V1/WorkGroupController.cs
Normal file
83
PARR.API/Controllers/V1/WorkGroupController.cs
Normal file
@@ -0,0 +1,83 @@
|
||||
using AutoMapper;
|
||||
using Microsoft.AspNetCore.Authorization;
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using PARR.API.Contracts.V1;
|
||||
using PARR.API.Contracts.V1.Requests.Queries;
|
||||
using PARR.API.Contracts.V1.Responses;
|
||||
using PARR.API.Contracts.V1.Responses.Base;
|
||||
using PARR.API.Controllers.V1.Base;
|
||||
using PARR.API.Extensions;
|
||||
using PARR.Constants;
|
||||
using PARR.DAL.DomainModels;
|
||||
using PARR.DAL.Models;
|
||||
using PARR.DAL.Services.Interfaces;
|
||||
|
||||
namespace PARR.API.Controllers.V1
|
||||
{
|
||||
/// <summary>
|
||||
/// Рабочие группы
|
||||
/// </summary>
|
||||
[Authorize(Roles = ParrRoles.Administrator.Role)]
|
||||
public class WorkGroupController : BaseApiController
|
||||
{
|
||||
private readonly IMapper mapper;
|
||||
private readonly IWorkGroupService workGroupService;
|
||||
|
||||
public WorkGroupController(
|
||||
IMapper mapper,
|
||||
IWorkGroupService workGroupService
|
||||
)
|
||||
{
|
||||
this.mapper = mapper;
|
||||
this.workGroupService = workGroupService;
|
||||
}
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// Список рабочих групп постранично
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
[HttpGet(ApiRoutes.WorkGroup.GetAll)]
|
||||
public async Task<IActionResult> GetAll([FromQuery] PaginationQuery paginationQuery, [FromQuery] WorkGroupQuery filter)
|
||||
{
|
||||
var paginationFilter = mapper.Map<PaginationFilter>(paginationQuery);
|
||||
|
||||
IQueryable<WorkGroup> query = workGroupService.Get()
|
||||
.OrderBy(t => t.Name);
|
||||
|
||||
if (!string.IsNullOrEmpty(filter.Name))
|
||||
query = query.Where(t => t.Name.ToLower().Contains(filter.Name.ToLower()));
|
||||
|
||||
var workGroups = await workGroupService.GetPage(query, paginationFilter).ToListAsync();
|
||||
|
||||
if (!workGroups.Any())
|
||||
return NoContent();
|
||||
|
||||
var workGroupResponse = mapper.Map<List<WorkGroupResponse>>(workGroups);
|
||||
var paginationResponse = new PagedResponse<WorkGroupResponse>(workGroupResponse, true).GetPaginatedProps(paginationFilter, query);
|
||||
|
||||
return Ok(paginationResponse);
|
||||
}
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// Получить рабочую группу по id
|
||||
/// </summary>
|
||||
/// <param name="id"></param>
|
||||
/// <returns></returns>
|
||||
[HttpGet(ApiRoutes.WorkGroup.Get)]
|
||||
public async Task<IActionResult> Get([FromRoute] Guid id)
|
||||
{
|
||||
var workGroup = await workGroupService.GetAsync(id);
|
||||
|
||||
if (workGroup == null)
|
||||
return NotFound();
|
||||
|
||||
var response = mapper.Map<WorkGroupResponse>(workGroup);
|
||||
|
||||
return Ok(new Response<WorkGroupResponse>(response, true));
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user