feat(api): статистика по регламентным работам по ЗО, РГ, РР
This commit is contained in:
@@ -8,7 +8,9 @@ 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;
|
||||
using PARR.API.Services.Interfaces;
|
||||
using PARR.Constants;
|
||||
using PARR.DAL.Models;
|
||||
using PARR.DAL.Services.Interfaces;
|
||||
|
||||
namespace PARR.API.Controllers.V1.Statistics
|
||||
@@ -22,16 +24,19 @@ namespace PARR.API.Controllers.V1.Statistics
|
||||
private readonly ITemplateService templateService;
|
||||
private readonly IResponseAreaService responseAreaService;
|
||||
private readonly IMapper mapper;
|
||||
private readonly IWorkLoadService workLoadService;
|
||||
|
||||
public StatResponseAreaWorkLoadController(
|
||||
ITemplateService templateService,
|
||||
IResponseAreaService responseAreaService,
|
||||
IMapper mapper
|
||||
IMapper mapper,
|
||||
IWorkLoadService workLoadService
|
||||
)
|
||||
{
|
||||
this.templateService = templateService;
|
||||
this.responseAreaService = responseAreaService;
|
||||
this.mapper = mapper;
|
||||
this.workLoadService = workLoadService;
|
||||
}
|
||||
|
||||
|
||||
@@ -39,35 +44,15 @@ namespace PARR.API.Controllers.V1.Statistics
|
||||
/// Статистика загрузки РР по всем ЗО
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
[HttpGet(ApiRoutes.StatStatResponseAreaWorkLoad.GetAll)]
|
||||
[HttpGet(ApiRoutes.StatResponseAreaWorkLoad.GetAll)]
|
||||
public async Task<IActionResult> GetAll([FromQuery] WorkloadBaseQuery requestQuery)
|
||||
{
|
||||
//начинаем не с сегодняшнего дня, а с завтра, так как на сегодня уже некоторые работы были проведены и дата изменилась
|
||||
var queryStartDate = DateTimeOffset.UtcNow.Date.AddDays(1);
|
||||
var queryEndDate = requestQuery.IsMonth == true ? queryStartDate.AddDays(30) : queryStartDate.AddDays(6);
|
||||
var daysList = workLoadService.GetDatesForPeriod(requestQuery);
|
||||
|
||||
//-----------
|
||||
var daysList = new List<DateTimeOffset>();
|
||||
daysList.Add(new DateTimeOffset(queryStartDate, new TimeSpan(0)));
|
||||
IQueryable<Template> query = templateService.Get()
|
||||
.Include(t => t.Host).ThenInclude(t => t.WorkGroup);
|
||||
|
||||
while (daysList.Last() < queryEndDate)
|
||||
{
|
||||
daysList.Add(daysList.Last().AddDays(1));
|
||||
}
|
||||
//-----------
|
||||
|
||||
|
||||
var query = templateService.Get()
|
||||
.Include(t => t.Host).ThenInclude(t => t.WorkGroup)
|
||||
.Where(t =>
|
||||
t.NextRun.DateTime.Date >= queryStartDate.Date && t.NextRun.DateTime.Date <= queryEndDate.Date
|
||||
);
|
||||
|
||||
if (requestQuery.IsActiveTemplate.HasValue)
|
||||
query = query.Where(t => t.IsActiveTemplate == requestQuery.IsActiveTemplate.Value);
|
||||
|
||||
if (requestQuery.IsActiveSchedule.HasValue)
|
||||
query = query.Where(t => t.IsActiveTemplate == requestQuery.IsActiveSchedule.Value);
|
||||
query = workLoadService.FilterTemplatesQuery(query, requestQuery);
|
||||
|
||||
|
||||
var groupedQuery = query.GroupBy(t => new { t.NextRun.DateTime.Date, t.Host!.WorkGroup!.ResponseAreaCode })
|
||||
|
||||
@@ -0,0 +1,97 @@
|
||||
using AutoMapper;
|
||||
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;
|
||||
using PARR.API.Services.Interfaces;
|
||||
using PARR.DAL.Models;
|
||||
using PARR.DAL.Services.Interfaces;
|
||||
|
||||
namespace PARR.API.Controllers.V1.Statistics
|
||||
{
|
||||
/// <summary>
|
||||
/// Статистика загрузки регламентными работами по рабочим группам
|
||||
/// </summary>
|
||||
public class StatWorkGroupWorkLoadController : BaseApiController
|
||||
{
|
||||
private readonly ITemplateService templateService;
|
||||
private readonly IWorkLoadService workLoadService;
|
||||
private readonly IWorkGroupService workGroupService;
|
||||
private readonly IMapper mapper;
|
||||
|
||||
public StatWorkGroupWorkLoadController(
|
||||
ITemplateService templateService,
|
||||
IWorkLoadService workLoadService,
|
||||
IWorkGroupService workGroupService,
|
||||
IMapper mapper
|
||||
)
|
||||
{
|
||||
this.templateService = templateService;
|
||||
this.workLoadService = workLoadService;
|
||||
this.workGroupService = workGroupService;
|
||||
this.mapper = mapper;
|
||||
}
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// Статистика загрузки регламентными работами рабочих групп по ЗО
|
||||
/// </summary>
|
||||
/// <param name="responseAreaCode"></param>
|
||||
/// <param name="requestQuery"></param>
|
||||
/// <returns></returns>
|
||||
[HttpGet(ApiRoutes.StatWorkGroupWorkLoad.Get)]
|
||||
public async Task<IActionResult> Get([FromRoute] int responseAreaCode, [FromQuery] WorkloadBaseQuery requestQuery)
|
||||
{
|
||||
var daysList = workLoadService.GetDatesForPeriod(requestQuery);
|
||||
|
||||
IQueryable<Template> query = templateService.Get()
|
||||
.Include(t => t.Host);
|
||||
|
||||
query = workLoadService.FilterTemplatesQuery(query, requestQuery).Where(t => t.Host!.WorkGroup!.ResponseAreaCode == responseAreaCode);
|
||||
|
||||
var groupedQuery = query.GroupBy(t => new { t.NextRun.DateTime.Date, t.Host!.WorkGroupId })
|
||||
.Select(t => new
|
||||
{
|
||||
WorkGroupId = t.Key.WorkGroupId,
|
||||
Date = t.Key.Date,
|
||||
TemplateCount = t.Count()
|
||||
});
|
||||
|
||||
var queryResult = await groupedQuery.ToListAsync();
|
||||
|
||||
//if (!queryResult.Any())
|
||||
// return NoContent();
|
||||
|
||||
|
||||
var allWorkGroups = await workGroupService.Get()
|
||||
.Include(t => t.ResponseArea)
|
||||
.Where(t => t.ResponseAreaCode == responseAreaCode)
|
||||
.ToListAsync();
|
||||
|
||||
var response = new List<StatWorkGroupWorkLoadResponse>();
|
||||
|
||||
allWorkGroups.ForEach(wg =>
|
||||
{
|
||||
var workLoads = daysList.Select(t => new StatWorkLoadDataResponse
|
||||
{
|
||||
Date = t,
|
||||
TemplateCount = queryResult.FirstOrDefault(x => x.WorkGroupId == wg.Id && x.Date.Date == t.Date)?.TemplateCount ?? 0
|
||||
}).OrderBy(t => t.Date).ToList();
|
||||
|
||||
response.Add(new StatWorkGroupWorkLoadResponse
|
||||
{
|
||||
WorkGroup = mapper.Map<WorkGroupResponse>(wg),
|
||||
WorkLoad = workLoads
|
||||
});
|
||||
});
|
||||
|
||||
response = response.OrderBy(t => t.WorkGroup.Name).ToList();
|
||||
|
||||
return Ok(new Response<List<StatWorkGroupWorkLoadResponse>>(response, true));
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,95 @@
|
||||
using AutoMapper;
|
||||
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;
|
||||
using PARR.API.Services.Interfaces;
|
||||
using PARR.DAL.Models;
|
||||
using PARR.DAL.Services.Interfaces;
|
||||
|
||||
namespace PARR.API.Controllers.V1.Statistics
|
||||
{
|
||||
/// <summary>
|
||||
/// Статистика загрузки регламентными работами по Видам работ(works)
|
||||
/// </summary>
|
||||
public class StatWorkWorkLoadController : BaseApiController
|
||||
{
|
||||
private readonly ITemplateService templateService;
|
||||
private readonly IWorkLoadService workLoadService;
|
||||
private readonly IMapper mapper;
|
||||
|
||||
public StatWorkWorkLoadController(
|
||||
ITemplateService templateService,
|
||||
IWorkLoadService workLoadService,
|
||||
IMapper mapper
|
||||
)
|
||||
{
|
||||
this.templateService = templateService;
|
||||
this.workLoadService = workLoadService;
|
||||
this.mapper = mapper;
|
||||
}
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// Статистика загрузки регламентными работами по Видам работ(works)
|
||||
/// </summary>
|
||||
/// <param name="workGroupId"></param>
|
||||
/// <param name="requestQuery"></param>
|
||||
/// <returns></returns>
|
||||
[HttpGet(ApiRoutes.StatWorkWorkLoad.Get)]
|
||||
public async Task<IActionResult> Get([FromRoute] Guid workGroupId, [FromQuery] WorkloadBaseQuery requestQuery)
|
||||
{
|
||||
var daysList = workLoadService.GetDatesForPeriod(requestQuery);
|
||||
|
||||
IQueryable<Template> query = templateService.Get()
|
||||
.Include(t => t.Host);
|
||||
|
||||
query = workLoadService.FilterTemplatesQuery(query, requestQuery).Where(t => t.Host!.WorkGroupId == workGroupId);
|
||||
|
||||
var groupedQuery = query.GroupBy(t => new { t.NextRun.DateTime.Date, t.ApplicationInWorkId })
|
||||
.Select(t => new
|
||||
{
|
||||
ApplicationInWorkId = t.Key.ApplicationInWorkId,
|
||||
Date = t.Key.Date,
|
||||
TemplateCount = t.Count()
|
||||
});
|
||||
|
||||
var queryResult = await groupedQuery.ToListAsync();
|
||||
|
||||
|
||||
// получаем только работы по которым есть шаблоны (активированные/деакт) и за любой период
|
||||
var allAppInWorks = await templateService.Get()
|
||||
.Include(t => t.Host)
|
||||
.Include(t => t.ApplicationsInWork).ThenInclude(t => t.Application).ThenInclude(t => t.ApplicationType)
|
||||
.Where(t => t.Host.WorkGroupId == workGroupId)
|
||||
.Select(t => t.ApplicationsInWork)
|
||||
.Distinct()
|
||||
.ToListAsync();
|
||||
|
||||
var response = new List<StatWorkWorkLoadResponse>();
|
||||
|
||||
allAppInWorks.ForEach(appInWork =>
|
||||
{
|
||||
var workLoads = daysList.Select(t => new StatWorkLoadDataResponse
|
||||
{
|
||||
Date = t,
|
||||
TemplateCount = queryResult.FirstOrDefault(x => x.ApplicationInWorkId == appInWork.Id && x.Date.Date == t.Date)?.TemplateCount ?? 0
|
||||
}).OrderBy(t => t.Date).ToList();
|
||||
|
||||
response.Add(new StatWorkWorkLoadResponse
|
||||
{
|
||||
Job = mapper.Map<ApplicationInWorkBaseResponse>(appInWork),
|
||||
WorkLoad = workLoads
|
||||
});
|
||||
});
|
||||
|
||||
response = response.OrderBy(t => t.Job.ShortDescription).ToList();
|
||||
|
||||
return Ok(new Response<List<StatWorkWorkLoadResponse>>(response, true));
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user