From 1b9a891f96bf9ddc28d35916e1023d3c8ff2e80f Mon Sep 17 00:00:00 2001 From: grishazagidulin Date: Wed, 11 Dec 2024 19:09:06 +0400 Subject: [PATCH] =?UTF-8?q?=D0=94=D0=BE=D0=B1=D0=B0=D0=B2=D0=BB=D1=8F?= =?UTF-8?q?=D0=B5=D1=82=20=D0=B7=D0=B0=D0=B2=D0=B8=D1=81=D0=B8=D0=BC=D0=BE?= =?UTF-8?q?=D1=81=D1=82=D0=B8,=20=D0=BD=D0=B0=D1=87=D0=B8=D0=BD=D0=B0?= =?UTF-8?q?=D0=B5=D1=82=20=D1=80=D0=B0=D0=B1=D0=BE=D1=82=D1=83=20=D1=81=20?= =?UTF-8?q?=D0=BE=D1=82=D1=87=D0=B5=D1=82=D0=BE=D0=BC-=D1=82=D0=B0=D0=B1?= =?UTF-8?q?=D0=BB=D0=B8=D1=86=D0=B5=D0=B9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Workshop/Reports/DocReport.cs | 5 --- Workshop/Reports/ExcelBuilder.cs | 5 --- Workshop/Reports/TableReport.cs | 72 ++++++++++++++++++++++++++++++++ Workshop/Reports/WordBuilder.cs | 6 --- Workshop/Workshop.csproj | 2 + 5 files changed, 74 insertions(+), 16 deletions(-) create mode 100644 Workshop/Reports/TableReport.cs diff --git a/Workshop/Reports/DocReport.cs b/Workshop/Reports/DocReport.cs index d607c44..0daf15a 100644 --- a/Workshop/Reports/DocReport.cs +++ b/Workshop/Reports/DocReport.cs @@ -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; diff --git a/Workshop/Reports/ExcelBuilder.cs b/Workshop/Reports/ExcelBuilder.cs index 5d432ea..cb08d17 100644 --- a/Workshop/Reports/ExcelBuilder.cs +++ b/Workshop/Reports/ExcelBuilder.cs @@ -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; diff --git a/Workshop/Reports/TableReport.cs b/Workshop/Reports/TableReport.cs new file mode 100644 index 0000000..037ceb6 --- /dev/null +++ b/Workshop/Reports/TableReport.cs @@ -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 _logger; + internal static readonly string[] item = ["Дата", "Изделие", "Операция"]; + public TableReport(IProductCreateRepository productCreateRepos, IChequeRepository chequeRepos, ILogger 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 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() { 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(); + } + } +} diff --git a/Workshop/Reports/WordBuilder.cs b/Workshop/Reports/WordBuilder.cs index 09b6ae0..ce43fc4 100644 --- a/Workshop/Reports/WordBuilder.cs +++ b/Workshop/Reports/WordBuilder.cs @@ -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; diff --git a/Workshop/Workshop.csproj b/Workshop/Workshop.csproj index 7c6a178..f39d9aa 100644 --- a/Workshop/Workshop.csproj +++ b/Workshop/Workshop.csproj @@ -10,11 +10,13 @@ + +