using Microsoft.Extensions.Logging; using ProjectLibrary.Repositores; using ProjectLibrary.Repositories; using ProjectLibrary.Repositories.Implementations; using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; namespace ProjectLibrary.Reports; public class DocReport { private readonly IBookRepository _bookRepository; private readonly IReaderRepository _readerRepository; private readonly ITicketExtensionsRepository _ticketExtensionsRepository; private readonly ILogger _logger; public DocReport(IBookRepository bookRepository, IReaderRepository readerRepository, ITicketExtensionsRepository ticketExtensionsRepository, ILogger logger) { _bookRepository = bookRepository ?? throw new ArgumentNullException(nameof(bookRepository)); _readerRepository = readerRepository ?? throw new ArgumentNullException(nameof(readerRepository)); _ticketExtensionsRepository = ticketExtensionsRepository ?? throw new ArgumentNullException(nameof(ticketExtensionsRepository)); _logger = logger ?? throw new ArgumentNullException(nameof(logger)); } public bool CreateDoc(string filePath, bool includeBooks, bool includeReaders, bool includeTicketExtensions) { try { var builder = new WordBuilder(filePath).AddHeader("Документ со справочниками"); if (includeBooks) { builder.AddParagraph("Книги").AddTable([2400, 2400, 1200], GetBooks()); } if (includeReaders) { builder.AddParagraph("Читатели").AddTable([2400, 1200, 1200], GetReaders()); } if (includeTicketExtensions) { builder.AddParagraph("Библиотеки").AddTable([2400, 2400, 2400], GetTicketExtensions()); } builder.Build(); return true; } catch (Exception ex) { _logger.LogError(ex, "Ошибка при формировании документа"); return false; } } private List GetBooks() { return [ ["Автор", "Название", "Тип книги"], .. _bookRepository .ReadBooks() .Select(x => new string[] { x.Author, x.Name, x.TypeBookID.ToString()}), ]; } private List GetReaders() { return [ ["ФИО читателя", "Билет читателя", "Дата регистрации"], .. _readerRepository .ReadReaders() .Select(x => new string[] { x.Name, x.ReaderTicket.ToString(), x.RegistrationDateRT.ToString()}), ]; } private List GetTicketExtensions() { return [ ["ID Читателя", "Последняя дата обновления", "Следующая дата обновления"], .. _ticketExtensionsRepository .ReadTicketExtensions() .Select(x => new string[] {x.ReaderID.ToString(), x.LastUpdateDate.ToString(), x.NextUpdateDate.ToString()}), ]; } }