feat(api): StatOrderController - статистика загрузки нарядов за период
This commit is contained in:
@@ -226,6 +226,7 @@
|
|||||||
public static class StatOrder
|
public static class StatOrder
|
||||||
{
|
{
|
||||||
public const string Get = BaseStat + "/orders/";
|
public const string Get = BaseStat + "/orders/";
|
||||||
|
public const string GetForPeriod = BaseStat + "/orders/period";
|
||||||
public const string TaskToEspp = BaseStat + "/orders/tasks";
|
public const string TaskToEspp = BaseStat + "/orders/tasks";
|
||||||
public const string Statuses = BaseStat + "/orders/statuses";
|
public const string Statuses = BaseStat + "/orders/statuses";
|
||||||
public const string GetStatusesLastDay = BaseStat + "/orders/statuses/last-day/{statusCode}";
|
public const string GetStatusesLastDay = BaseStat + "/orders/statuses/last-day/{statusCode}";
|
||||||
|
|||||||
@@ -25,4 +25,10 @@
|
|||||||
public int AllCount { get; set; }
|
public int AllCount { get; set; }
|
||||||
public int TaskCount { get; set; }
|
public int TaskCount { get; set; }
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public class StatOrderGetForPeriodResponse
|
||||||
|
{
|
||||||
|
public DateOnly Date { get; set; }
|
||||||
|
public int OrderCount { get; set; }
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -3,10 +3,12 @@ using Microsoft.AspNetCore.Authorization;
|
|||||||
using Microsoft.AspNetCore.Mvc;
|
using Microsoft.AspNetCore.Mvc;
|
||||||
using Microsoft.EntityFrameworkCore;
|
using Microsoft.EntityFrameworkCore;
|
||||||
using PARR.API.Contracts.V1;
|
using PARR.API.Contracts.V1;
|
||||||
|
using PARR.API.Contracts.V1.Requests.BaseRequests;
|
||||||
using PARR.API.Contracts.V1.Responses;
|
using PARR.API.Contracts.V1.Responses;
|
||||||
using PARR.API.Contracts.V1.Responses.Base;
|
using PARR.API.Contracts.V1.Responses.Base;
|
||||||
using PARR.API.Contracts.V1.Responses.Statistics;
|
using PARR.API.Contracts.V1.Responses.Statistics;
|
||||||
using PARR.API.Controllers.V1.Base;
|
using PARR.API.Controllers.V1.Base;
|
||||||
|
using PARR.BLL.Services.Interfaces;
|
||||||
using PARR.Constants;
|
using PARR.Constants;
|
||||||
using PARR.DAL.Services.Interfaces;
|
using PARR.DAL.Services.Interfaces;
|
||||||
|
|
||||||
@@ -21,16 +23,19 @@ namespace PARR.API.Controllers.V1.Statistics
|
|||||||
private readonly IOrderService orderService;
|
private readonly IOrderService orderService;
|
||||||
private readonly IOrderStatusService orderStatusService;
|
private readonly IOrderStatusService orderStatusService;
|
||||||
private readonly IMapper mapper;
|
private readonly IMapper mapper;
|
||||||
|
private readonly ICalendarService calendarService;
|
||||||
|
|
||||||
public StatOrderController(
|
public StatOrderController(
|
||||||
IOrderService orderService,
|
IOrderService orderService,
|
||||||
IOrderStatusService orderStatusService,
|
IOrderStatusService orderStatusService,
|
||||||
IMapper mapper
|
IMapper mapper,
|
||||||
|
ICalendarService calendarService
|
||||||
)
|
)
|
||||||
{
|
{
|
||||||
this.orderService = orderService;
|
this.orderService = orderService;
|
||||||
this.orderStatusService = orderStatusService;
|
this.orderStatusService = orderStatusService;
|
||||||
this.mapper = mapper;
|
this.mapper = mapper;
|
||||||
|
this.calendarService = calendarService;
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
@@ -119,5 +124,49 @@ namespace PARR.API.Controllers.V1.Statistics
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Получить статистику добавления новых нарядов за период
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="timeZoneQuery"></param>
|
||||||
|
/// <param name="startPeriodDays"></param>
|
||||||
|
/// <returns></returns>
|
||||||
|
[HttpGet(ApiRoutes.StatOrder.GetForPeriod)]
|
||||||
|
public async Task<IActionResult> GetForPeriod([FromQuery] TimeZoneOffsetClient timeZoneQuery, [FromQuery] int startPeriodDays = 3)
|
||||||
|
{
|
||||||
|
var endPeriod = calendarService.GetDateWithTimeZoneOffset(DateTimeOffset.UtcNow, timeZoneQuery.TimeZoneOffsetHours);
|
||||||
|
var startPeriod = endPeriod.AddDays(-startPeriodDays);
|
||||||
|
|
||||||
|
var query = orderService.Get()
|
||||||
|
.Where(t =>
|
||||||
|
t.DateCreated.DateTime.AddHours(timeZoneQuery.TimeZoneOffsetHours).Date >= startPeriod.Date
|
||||||
|
&& t.DateCreated.DateTime.AddHours(timeZoneQuery.TimeZoneOffsetHours) <= endPeriod.Date
|
||||||
|
).GroupBy(t => t.DateCreated.AddHours(timeZoneQuery.TimeZoneOffsetHours).Date)
|
||||||
|
.Select(t => new
|
||||||
|
{
|
||||||
|
Date = t.Key,
|
||||||
|
OrderCount = t.Count()
|
||||||
|
});
|
||||||
|
|
||||||
|
var result = await query.ToListAsync();
|
||||||
|
|
||||||
|
var daysList = calendarService.GetDatesForPeriod(startPeriod, endPeriod);
|
||||||
|
|
||||||
|
var response = new List<StatOrderGetForPeriodResponse>();
|
||||||
|
|
||||||
|
daysList.ForEach(date =>
|
||||||
|
{
|
||||||
|
response.Add(new StatOrderGetForPeriodResponse
|
||||||
|
{
|
||||||
|
Date = date,
|
||||||
|
OrderCount = result.FirstOrDefault(t => DateOnly.FromDateTime(t.Date) == date)?.OrderCount ?? 0
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
response = response.OrderBy(t => t.Date).ToList();
|
||||||
|
|
||||||
|
return Ok(new Response<List<StatOrderGetForPeriodResponse>>(response, true));
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user