2024-08-19 13:36:56 +10:00
|
|
|
|
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.Contracts.V1.Responses.Statistics;
|
|
|
|
|
|
using PARR.API.Controllers.V1.Base;
|
2024-08-20 09:33:13 +10:00
|
|
|
|
using PARR.API.Services.Interfaces;
|
2024-08-19 13:36:56 +10:00
|
|
|
|
using PARR.Constants;
|
2024-08-20 09:33:13 +10:00
|
|
|
|
using PARR.DAL.Models;
|
2024-08-19 13:36:56 +10:00
|
|
|
|
using PARR.DAL.Services.Interfaces;
|
|
|
|
|
|
|
|
|
|
|
|
namespace PARR.API.Controllers.V1.Statistics
|
|
|
|
|
|
{
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
|
/// Статистика загрузки регламентными работами по ЗО
|
|
|
|
|
|
/// </summary>
|
|
|
|
|
|
[Authorize(Roles = ParrRoles.EsppRobot.RoleOrAdmin)]
|
|
|
|
|
|
public class StatResponseAreaWorkLoadController : BaseApiController
|
|
|
|
|
|
{
|
|
|
|
|
|
private readonly ITemplateService templateService;
|
|
|
|
|
|
private readonly IResponseAreaService responseAreaService;
|
|
|
|
|
|
private readonly IMapper mapper;
|
2024-08-20 09:33:13 +10:00
|
|
|
|
private readonly IWorkLoadService workLoadService;
|
2024-08-19 13:36:56 +10:00
|
|
|
|
|
|
|
|
|
|
public StatResponseAreaWorkLoadController(
|
|
|
|
|
|
ITemplateService templateService,
|
|
|
|
|
|
IResponseAreaService responseAreaService,
|
2024-08-20 09:33:13 +10:00
|
|
|
|
IMapper mapper,
|
|
|
|
|
|
IWorkLoadService workLoadService
|
2024-08-19 13:36:56 +10:00
|
|
|
|
)
|
|
|
|
|
|
{
|
|
|
|
|
|
this.templateService = templateService;
|
|
|
|
|
|
this.responseAreaService = responseAreaService;
|
|
|
|
|
|
this.mapper = mapper;
|
2024-08-20 09:33:13 +10:00
|
|
|
|
this.workLoadService = workLoadService;
|
2024-08-19 13:36:56 +10:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
|
/// Статистика загрузки РР по всем ЗО
|
|
|
|
|
|
/// </summary>
|
|
|
|
|
|
/// <returns></returns>
|
2024-08-20 09:33:13 +10:00
|
|
|
|
[HttpGet(ApiRoutes.StatResponseAreaWorkLoad.GetAll)]
|
2024-08-19 13:36:56 +10:00
|
|
|
|
public async Task<IActionResult> GetAll([FromQuery] WorkloadBaseQuery requestQuery)
|
|
|
|
|
|
{
|
2024-08-20 09:33:13 +10:00
|
|
|
|
var daysList = workLoadService.GetDatesForPeriod(requestQuery);
|
2024-08-19 13:36:56 +10:00
|
|
|
|
|
2024-08-20 09:33:13 +10:00
|
|
|
|
IQueryable<Template> query = templateService.Get()
|
|
|
|
|
|
.Include(t => t.Host).ThenInclude(t => t.WorkGroup);
|
2024-08-19 13:36:56 +10:00
|
|
|
|
|
2024-08-20 09:33:13 +10:00
|
|
|
|
query = workLoadService.FilterTemplatesQuery(query, requestQuery);
|
2024-08-19 13:36:56 +10:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
var groupedQuery = query.GroupBy(t => new { t.NextRun.DateTime.Date, t.Host!.WorkGroup!.ResponseAreaCode })
|
|
|
|
|
|
.Select(t => new
|
|
|
|
|
|
{
|
|
|
|
|
|
ResponseAreaCode = t.Key.ResponseAreaCode,
|
|
|
|
|
|
Date = t.Key.Date,
|
|
|
|
|
|
TemplateCount = t.Count()
|
|
|
|
|
|
|
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
|
|
var queryResult = await groupedQuery.ToListAsync();
|
|
|
|
|
|
|
|
|
|
|
|
var allResponseArea = await responseAreaService.Get().ToListAsync();
|
|
|
|
|
|
|
2024-08-22 12:26:27 +10:00
|
|
|
|
if (!allResponseArea.Any())
|
|
|
|
|
|
return NoContent();
|
|
|
|
|
|
|
2024-08-19 13:36:56 +10:00
|
|
|
|
var response = new List<StatResponseAreaWorkLoadResponse>();
|
|
|
|
|
|
|
|
|
|
|
|
allResponseArea.ForEach(respArea =>
|
|
|
|
|
|
{
|
|
|
|
|
|
var workLoads = daysList.Select(t => new StatWorkLoadDataResponse
|
|
|
|
|
|
{
|
|
|
|
|
|
Date = t,
|
|
|
|
|
|
TemplateCount = queryResult.FirstOrDefault(x => x.ResponseAreaCode == respArea.Code && x.Date.Date == t.Date)?.TemplateCount ?? 0
|
|
|
|
|
|
}).OrderBy(t => t.Date).ToList();
|
|
|
|
|
|
|
|
|
|
|
|
response.Add(
|
|
|
|
|
|
new StatResponseAreaWorkLoadResponse
|
|
|
|
|
|
{
|
|
|
|
|
|
ResponseArea = mapper.Map<ResponseAreaResponse>(respArea),
|
|
|
|
|
|
WorkLoad = workLoads
|
|
|
|
|
|
});
|
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
|
|
response = response.OrderBy(t => t.ResponseArea.Code).ToList();
|
|
|
|
|
|
|
|
|
|
|
|
return Ok(new Response<List<StatResponseAreaWorkLoadResponse>>(response, true));
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|