feat(api): Вынес логику формирования расписания в сервис IEsppSchTypeConfigService. В респонс шаблона добавил отображение расписания. Получение шаблона по ИД.
This commit is contained in:
23
PARR.DAL/DomainModels/EsppScheduleDto.cs
Normal file
23
PARR.DAL/DomainModels/EsppScheduleDto.cs
Normal file
@@ -0,0 +1,23 @@
|
||||
using PARR.DAL.Models;
|
||||
|
||||
namespace PARR.DAL.DomainModels
|
||||
{
|
||||
/// <summary>
|
||||
/// Расписание ЕСПП в нормальном виде
|
||||
/// </summary>
|
||||
public class EsppScheduleDto
|
||||
{
|
||||
public required EsppSchTypeSchedule TypeSchedule { get; set; }
|
||||
|
||||
public required List<EsppScheduleValDto> Values { get; set; }
|
||||
}
|
||||
|
||||
public class EsppScheduleValDto
|
||||
{
|
||||
public int Order { get; set; }
|
||||
|
||||
public required EsppSchType Type { get; set; }
|
||||
|
||||
public required EsppSchTypeValue Value { get; set; }
|
||||
}
|
||||
}
|
||||
@@ -1,6 +1,7 @@
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using Microsoft.Extensions.Logging;
|
||||
using PARR.DAL.Context;
|
||||
using PARR.DAL.DomainModels;
|
||||
using PARR.DAL.Models;
|
||||
using PARR.DAL.Services.Abstracts;
|
||||
using PARR.DAL.Services.Interfaces;
|
||||
@@ -30,12 +31,51 @@ namespace PARR.DAL.Services.Implementations
|
||||
.ThenInclude(t => t!.EsppSchValues);
|
||||
}
|
||||
|
||||
//public IQueryable<EsppSchTypeConfig> GetScheduleByAppInWorks(Guid applicationInWorksId)
|
||||
//{
|
||||
// var configs = GetWithSchIncludes()
|
||||
// .Where(t => t.EsppSchValues.Any(x => x.ApplicationsInWorkId == applicationInWorksId))
|
||||
// .ToList();
|
||||
public async Task<EsppScheduleDto?> GetEsppScheduleDtoAsync(Guid applicationInWorksId)
|
||||
{
|
||||
//Формирует расписание в нормальном понятном виде из БД
|
||||
|
||||
//}
|
||||
var configs = await GetWithSchIncludes()
|
||||
.Where(t => t.EsppSchValues.Any(x => x.ApplicationsInWorkId == applicationInWorksId))
|
||||
.ToListAsync();
|
||||
|
||||
if (!configs.Any())
|
||||
return null;
|
||||
|
||||
var values = new List<EsppScheduleValDto>();
|
||||
|
||||
foreach (var config in configs)
|
||||
{
|
||||
var value = new EsppScheduleValDto
|
||||
{
|
||||
Order = config.Order,
|
||||
Type = config.EsppSchType!,
|
||||
Value = config.EsppSchValues.First().EsppSchTypeValue!
|
||||
|
||||
};
|
||||
|
||||
values.Add(value);
|
||||
}
|
||||
|
||||
|
||||
var dto = new EsppScheduleDto
|
||||
{
|
||||
TypeSchedule = configs.First().EsppSchTypeSchedule!,
|
||||
Values = values.OrderBy(t => t.Order).ToList()
|
||||
};
|
||||
|
||||
|
||||
return dto;
|
||||
}
|
||||
|
||||
public EsppScheduleDto? GetEsppScheduleDto(Guid applicationInWorksId)
|
||||
{
|
||||
var result = Task.Run(async () =>
|
||||
{
|
||||
return await GetEsppScheduleDtoAsync(applicationInWorksId);
|
||||
}).Result;
|
||||
|
||||
return result;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,10 +1,25 @@
|
||||
using PARR.DAL.Models;
|
||||
using PARR.DAL.DomainModels;
|
||||
using PARR.DAL.Models;
|
||||
using PARR.DAL.Services.Interfaces.Base;
|
||||
|
||||
namespace PARR.DAL.Services.Interfaces
|
||||
{
|
||||
public interface IEsppSchTypeConfigService : IBaseService<EsppSchTypeConfig>
|
||||
{
|
||||
/// <summary>
|
||||
/// Формирует расписание в нормальном понятном виде из БД синхронно
|
||||
/// </summary>
|
||||
/// <param name="applicationInWorksId"></param>
|
||||
/// <returns></returns>
|
||||
EsppScheduleDto? GetEsppScheduleDto(Guid applicationInWorksId);
|
||||
|
||||
/// <summary>
|
||||
/// Формирует расписание в нормальном понятном виде из БД асинхронно
|
||||
/// </summary>
|
||||
/// <param name="applicationInWorksId"></param>
|
||||
/// <returns></returns>
|
||||
Task<EsppScheduleDto?> GetEsppScheduleDtoAsync(Guid applicationInWorksId);
|
||||
|
||||
IQueryable<EsppSchTypeConfig> GetWithSchIncludes();
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user