Добавляет зависимости, начинает работу с отчетом-таблицей
This commit is contained in:
parent
6bd408b31f
commit
1b9a891f96
@ -1,9 +1,4 @@
|
||||
using Microsoft.Extensions.Logging;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using Workshop.Repositories;
|
||||
|
||||
namespace Workshop.Reports;
|
||||
|
@ -1,11 +1,6 @@
|
||||
using DocumentFormat.OpenXml.Packaging;
|
||||
using DocumentFormat.OpenXml.Spreadsheet;
|
||||
using DocumentFormat.OpenXml;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace Workshop.Reports;
|
||||
|
||||
|
72
Workshop/Reports/TableReport.cs
Normal file
72
Workshop/Reports/TableReport.cs
Normal file
@ -0,0 +1,72 @@
|
||||
using Microsoft.Extensions.Logging;
|
||||
using Workshop.Repositories;
|
||||
using Workshop.Repositories.Implementations;
|
||||
|
||||
namespace Workshop.Reports
|
||||
{
|
||||
internal class TableReport
|
||||
{
|
||||
private readonly IProductCreateRepository _productCreateRepository;
|
||||
private readonly IChequeRepository _chequeRepository;
|
||||
private readonly ILogger<TableReport> _logger;
|
||||
internal static readonly string[] item = ["Дата", "Изделие", "Операция"];
|
||||
public TableReport(IProductCreateRepository productCreateRepos, IChequeRepository chequeRepos, ILogger<TableReport> logger)
|
||||
{
|
||||
_chequeRepository = chequeRepos ?? throw new ArgumentNullException(nameof(chequeRepos));
|
||||
_productCreateRepository = productCreateRepos ?? throw new ArgumentNullException(nameof(productCreateRepos));
|
||||
_logger = logger ??
|
||||
throw new ArgumentNullException(nameof(logger));
|
||||
}
|
||||
public bool CreateTable(string filePath, long studentId, DateTime startDate, DateTime endDate)
|
||||
{
|
||||
try
|
||||
{
|
||||
new ExcelBuilder(filePath)
|
||||
.AddHeader("Сводка по движению изделия", 0, 3)
|
||||
.AddParagraph("за период", 0)
|
||||
.AddTable([15, 15, 15], GetData(studentId, startDate,
|
||||
endDate))
|
||||
.Build();
|
||||
return true;
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
_logger.LogError(ex, "Ошибка при формировании документа");
|
||||
return false;
|
||||
}
|
||||
}
|
||||
private List<string[]> GetData(long studentId, DateTime startDate, DateTime
|
||||
endDate)
|
||||
{
|
||||
var data = _chequeRepository
|
||||
.ReadStatements()
|
||||
.Where(x => x.Date >= startDate && x.Date <= endDate &&
|
||||
x.Marks.Any(y => y.StudentId == studentId))
|
||||
.Select(x => new
|
||||
{
|
||||
Date = x.Date,
|
||||
Mark = x.Marks.FirstOrDefault(y => y.StudentId == studentId)?.Mark,
|
||||
Operation = (Operations?)null
|
||||
})
|
||||
.Union(
|
||||
_productCreateRepository
|
||||
.ReadStudentTransitions()
|
||||
.Where(x => x.Date >= startDate && x.Date <= endDate && x.StudentId == studentId)
|
||||
.Select(x => new
|
||||
{
|
||||
Date = x.Date,
|
||||
Mark = (int?)null,
|
||||
Operation = (Operations?)x.Operation
|
||||
}))
|
||||
.OrderBy(x => x.Date).ToList();
|
||||
return
|
||||
new List<string[]>() { item }
|
||||
.Union(
|
||||
data
|
||||
.Select(x => new string[] {
|
||||
x.Date.ToString(), x.Mark?.ToString() ?? string.Empty, x.Operation.ToString() ?? string.Empty}))
|
||||
.Union(
|
||||
[["Всего", data.Where((x) => x.Mark.HasValue).Average(x => x.Mark).ToString(), data.Count(x => x.Operation.HasValue).ToString()]]).ToList();
|
||||
}
|
||||
}
|
||||
}
|
@ -1,12 +1,6 @@
|
||||
using DocumentFormat.OpenXml;
|
||||
using DocumentFormat.OpenXml.Packaging;
|
||||
using DocumentFormat.OpenXml.Wordprocessing;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace Workshop.Reports;
|
||||
|
||||
|
@ -10,11 +10,13 @@
|
||||
|
||||
<ItemGroup>
|
||||
<PackageReference Include="Dapper" Version="2.1.35" />
|
||||
<PackageReference Include="DocumentFormat.OpenXml" Version="3.2.0" />
|
||||
<PackageReference Include="Microsoft.Extensions.Configuration" Version="9.0.0" />
|
||||
<PackageReference Include="Microsoft.Extensions.Configuration.Json" Version="9.0.0" />
|
||||
<PackageReference Include="Microsoft.Extensions.Logging" Version="9.0.0" />
|
||||
<PackageReference Include="Newtonsoft.Json" Version="13.0.3" />
|
||||
<PackageReference Include="Npgsql" Version="9.0.1" />
|
||||
<PackageReference Include="PDFsharp-MigraDoc-GDI" Version="6.1.1" />
|
||||
<PackageReference Include="Serilog" Version="4.1.0" />
|
||||
<PackageReference Include="Serilog.Extensions.Logging" Version="8.0.0" />
|
||||
<PackageReference Include="Serilog.Settings.Configuration" Version="8.0.4" />
|
||||
|
Loading…
x
Reference in New Issue
Block a user