fix: теперь отчет смещения работает нормально

This commit is contained in:
mfnefd 2024-12-01 23:49:16 +04:00
parent f800f6cf0e
commit 5cb4937bcf
4 changed files with 29 additions and 6 deletions

View File

@ -0,0 +1,13 @@
using Contracts.Services;
using Services.Reports;
namespace Controllers.Extensions;
public static class AddReportServicesExtension
{
public static void AddReportServices(this IServiceCollection services)
{
services.AddTransient<IReportPeriodService, ReportPeriodService>();
services.AddTransient<IReportOffsetFromPlanService, ReportOffsetFromPlanService>();
}
}

View File

@ -6,6 +6,7 @@ var builder = WebApplication.CreateBuilder(args);
builder.Services.AddDbConnectionService(builder.Configuration);
builder.Services.AddRepos();
builder.Services.AddDomainServices();
builder.Services.AddReportServices();
builder.Services.AddControllers();
// Learn more about configuring Swagger/OpenAPI at https://aka.ms/aspnetcore/swashbuckle

View File

@ -46,6 +46,7 @@ public class SpendingGroupRepo : ISpendingGroupRepo
using var context = _factory.CreateDbContext();
var group = await context.SpendingGroups
.AsNoTracking()
.Include(x => x.ChangeRecords)
.Include(x => x.SpendingPlans)
.FirstOrDefaultAsync(x => x.Id == search.Id
@ -58,6 +59,7 @@ public class SpendingGroupRepo : ISpendingGroupRepo
{
using var context = _factory.CreateDbContext();
var plan = await context.SpendingPlans
.AsNoTracking()
.FirstOrDefaultAsync(x => x.Id == search.Id);
if (plan == null)
@ -66,13 +68,20 @@ public class SpendingGroupRepo : ISpendingGroupRepo
}
var group = await context.SpendingGroups
.AsNoTracking()
.Where(x => x.Id == plan.SpendingGroupId)
.Include(x => x.ChangeRecords != null
? x.ChangeRecords
.Include(x => x.ChangeRecords
// Выбираем из них только те, которые попадают в диапазон дат плана
.Where(cg => cg.ChangedAt >= plan.StartAt && cg.ChangedAt <= plan.EndAt)
// И сортируем их по дате
.OrderBy(cg => cg.ChangedAt)
: null)
.LastAsync();
)
.FirstOrDefaultAsync();
if (group == null)
{
return null;
}
group.SpendingPlans = [plan];
return group.ToDto();
@ -82,7 +91,7 @@ public class SpendingGroupRepo : ISpendingGroupRepo
{
using var context = _factory.CreateDbContext();
var query = context.SpendingGroups.AsQueryable();
var query = context.SpendingGroups.AsNoTracking().AsQueryable();
if (search != null)
{

View File

@ -3,7 +3,7 @@ using Contracts.Repositories;
using Contracts.SearchModels;
using Contracts.Services;
using Contracts.ViewModels;
using Services.Support;
using Services.Support.Exceptions;
namespace Services.Reports;