2024-12-03 00:34:28 +04:00
|
|
|
|
using Microsoft.Extensions.Logging;
|
|
|
|
|
using ProjectGSM.Entities;
|
|
|
|
|
using ProjectGSM.Repositories;
|
|
|
|
|
|
|
|
|
|
namespace ProjectGSM.Documents;
|
|
|
|
|
|
|
|
|
|
internal class TableReport
|
|
|
|
|
{
|
|
|
|
|
private readonly ICaseRepository _caseRepository;
|
|
|
|
|
private readonly IStatusHistoryRepository _statusHistoryRepository;
|
|
|
|
|
private readonly ILogger<TableReport> _logger;
|
|
|
|
|
internal static readonly string[] item = ["Статусы", "Дата", "Изменений статуса"];
|
|
|
|
|
|
|
|
|
|
public TableReport(
|
|
|
|
|
ICaseRepository caseRepository,
|
|
|
|
|
IStatusHistoryRepository statusHistoryRepository,
|
|
|
|
|
ILogger<TableReport> logger)
|
|
|
|
|
{
|
|
|
|
|
_caseRepository = caseRepository ??
|
|
|
|
|
throw new
|
|
|
|
|
ArgumentNullException(nameof(caseRepository));
|
|
|
|
|
_statusHistoryRepository = statusHistoryRepository ??
|
|
|
|
|
throw new
|
|
|
|
|
ArgumentNullException(nameof(statusHistoryRepository));
|
|
|
|
|
_logger = logger ??
|
|
|
|
|
throw new ArgumentNullException(nameof(logger));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public bool CreateTable(string filePath, int caseId, DateTime startDate,
|
|
|
|
|
DateTime endDate)
|
|
|
|
|
{
|
|
|
|
|
try
|
|
|
|
|
{
|
|
|
|
|
new ExcelBuilder(filePath)
|
|
|
|
|
.AddHeader($"Сводка по делу \"{_caseRepository.ReadCaseById(caseId).Description}\"", 0, 4)
|
2024-12-17 01:21:56 +04:00
|
|
|
|
.AddParagraph($"за период c {startDate:dd.MM.yyyy} по{endDate: dd.MM.yyyy}", 0)
|
2024-12-03 00:34:28 +04:00
|
|
|
|
.AddTable([10, 10, 15], GetData(caseId, startDate,
|
|
|
|
|
endDate))
|
|
|
|
|
.Build();
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
catch (Exception ex)
|
|
|
|
|
{
|
|
|
|
|
_logger.LogError(ex, "Ошибка при формировании документа");
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private List<string[]> GetData(int caseId, DateTime startDate, DateTime endDate)
|
|
|
|
|
{
|
|
|
|
|
var statusData = _statusHistoryRepository
|
2024-12-25 01:34:08 +04:00
|
|
|
|
.ReadStatusHistories(startDate, endDate, caseId)
|
2024-12-03 00:34:28 +04:00
|
|
|
|
.GroupBy(x => (x.Status, x.CreatedAt.Date))
|
|
|
|
|
.Select(x => new
|
|
|
|
|
{
|
|
|
|
|
Status = x.Key.Status,
|
|
|
|
|
Date = x.Key.Date,
|
|
|
|
|
Count = x.Count()
|
|
|
|
|
})
|
|
|
|
|
.ToList();
|
|
|
|
|
|
|
|
|
|
return new List<string[]>() { item }
|
|
|
|
|
.Union(
|
|
|
|
|
statusData
|
|
|
|
|
.Select(x => new string[]
|
|
|
|
|
{
|
2024-12-17 01:21:56 +04:00
|
|
|
|
x.Status.ToString(), x.Date.ToString("dd.MM.yyyy"), x.Count.ToString()
|
2024-12-03 00:34:28 +04:00
|
|
|
|
}))
|
|
|
|
|
.Union(
|
|
|
|
|
[
|
|
|
|
|
[
|
|
|
|
|
"Всего", "", statusData.Sum(x => x.Count).ToString()
|
|
|
|
|
]
|
|
|
|
|
])
|
|
|
|
|
.ToList();
|
|
|
|
|
}
|
|
|
|
|
}
|