Files
parr_api/PARR.API/Services/Implementations/WorkLoadService.cs

59 lines
2.0 KiB
C#
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

using PARR.API.Contracts.V1.Requests.Queries;
using PARR.API.Services.Interfaces;
using PARR.DAL.Models;
namespace PARR.API.Services.Implementations
{
internal class WorkLoadService : IWorkLoadService
{
private DateTime GetStartDate()
{
//начинаем не с сегодняшнего дня, а с завтра, так как на сегодня уже некоторые работы были проведены и их дата изменилась
return DateTimeOffset.UtcNow.Date.AddDays(1);
}
private DateTime GetEndDate(bool? isMonth)
{
var startDate = GetStartDate();
return isMonth == true ? startDate.AddDays(30) : startDate.AddDays(6);
}
public List<DateTimeOffset> GetDatesForPeriod(WorkloadBaseQuery requestQuery)
{
var startDate = GetStartDate();
var endDate = GetEndDate(requestQuery.IsMonth);
var daysList = new List<DateTimeOffset>();
daysList.Add(new DateTimeOffset(startDate, new TimeSpan(0)));
while (daysList.Last() < endDate)
daysList.Add(daysList.Last().AddDays(1));
return daysList.OrderBy(t => t).ToList();
}
public IQueryable<Template> FilterTemplatesQuery(IQueryable<Template> query, WorkloadBaseQuery requestQuery)
{
var startDate = GetStartDate();
var endDate = GetEndDate(requestQuery.IsMonth);
query = query.Where(t =>
t.NextRun.DateTime.Date >= startDate.Date && t.NextRun.DateTime.Date <= endDate.Date
);
if (requestQuery.IsActiveTemplate.HasValue)
query = query.Where(t => t.IsActiveTemplate == requestQuery.IsActiveTemplate.Value);
if (requestQuery.IsActiveSchedule.HasValue)
query = query.Where(t => t.IsActiveSchedule == requestQuery.IsActiveSchedule.Value);
return query;
}
}
}