diff --git a/FurnitureAssembly/FurnitureAssemblyBusinessLogic/BusinessLogics/ReportLogic.cs b/FurnitureAssembly/FurnitureAssemblyBusinessLogic/BusinessLogics/ReportWorkerLogic.cs similarity index 77% rename from FurnitureAssembly/FurnitureAssemblyBusinessLogic/BusinessLogics/ReportLogic.cs rename to FurnitureAssembly/FurnitureAssemblyBusinessLogic/BusinessLogics/ReportWorkerLogic.cs index 867c89f..f285943 100644 --- a/FurnitureAssembly/FurnitureAssemblyBusinessLogic/BusinessLogics/ReportLogic.cs +++ b/FurnitureAssembly/FurnitureAssemblyBusinessLogic/BusinessLogics/ReportWorkerLogic.cs @@ -13,8 +13,8 @@ using System.Threading.Tasks; namespace FurnitureAssemblyBusinessLogic.BusinessLogics { - public class ReportLogic : IReportLogic - { + public class ReportWorkerLogic : IReportWorkerLogic + { private readonly IFurnitureModuleStorage _furnitureModuleStorage; private readonly ISetStorage _setStorage; private readonly IOrderInfoStorage _orderInfoStorage; @@ -22,7 +22,7 @@ namespace FurnitureAssemblyBusinessLogic.BusinessLogics private readonly AbstractSaveToExcel _saveToExcel; private readonly AbstractSaveToWord _saveToWord; private readonly AbstractSaveToPdf _saveToPdf; - public ReportLogic(ISetStorage setStorage, IFurnitureModuleStorage furnitureModuleStorage, IOrderInfoStorage orderInfoStorage, + public ReportWorkerLogic(ISetStorage setStorage, IFurnitureModuleStorage furnitureModuleStorage, IOrderInfoStorage orderInfoStorage, IOrderStorage orderStorage, AbstractSaveToExcel saveToExcel, AbstractSaveToWord saveToWord, AbstractSaveToPdf saveToPdf) { _setStorage = setStorage; @@ -37,15 +37,27 @@ namespace FurnitureAssemblyBusinessLogic.BusinessLogics /// Получение списка мебельных модулей с указанием, в каких гарнитурах используются /// /// - public List GetSetFurnitureModule() + public List GetSetFurnitureModule(List setIds) { + if (setIds == null) + { + return new List(); + } var furnitureModules = _furnitureModuleStorage.GetFullList(); - var sets = _setStorage.GetFullList(); - var list = new List(); + List sets = new List(); + foreach (var setId in setIds) + { + var res = _setStorage.GetElement(new SetSearchModel { Id = setId }); + if (res != null) + { + sets.Add(res); + } + } + var list = new List(); foreach (var set in sets) { - var record = new ReportSetFurnitureModuleViewModel + var record = new ReportSetFurnitureModuleWorkerViewModel { SetName = set.Name, FurnitureModules = new List<(string, int)>(), @@ -69,7 +81,7 @@ namespace FurnitureAssemblyBusinessLogic.BusinessLogics /// /// /// - public List GetOrders(ReportBindingModel model) + public List GetOrders(ReportWorkerBindingModel model) { var orderInfos = _orderInfoStorage .GetFilteredList(new OrderInfoSearchModel { DateFrom = model.DateFrom, DateTo = model.DateTo }); @@ -81,11 +93,11 @@ namespace FurnitureAssemblyBusinessLogic.BusinessLogics var orders = _orderStorage.GetFilteredList(new OrderSearchModel { OrderInfoId = orderInfoIds }); var sets = _setStorage.GetFullList(); var furnitureModules = _furnitureModuleStorage.GetFullList(); - var list = new List(); + var list = new List(); foreach (var order in orders) { - var record = new ReportOrdersViewModel + var record = new ReportOrdersWorkerViewModel { Id = order.Id, SetName = order.SetName, @@ -96,7 +108,7 @@ namespace FurnitureAssemblyBusinessLogic.BusinessLogics { if (orderInfo.Id == order.OrderInfoId) { - record = new ReportOrdersViewModel + record = new ReportOrdersWorkerViewModel { Id = order.Id, SetName = order.SetName, @@ -129,42 +141,39 @@ namespace FurnitureAssemblyBusinessLogic.BusinessLogics /// Сохранение компонент в файл-Word /// /// - public void SaveFurnitureModuleToWordFile(ReportBindingModel model) + public void SaveFurnitureModuleToWordFile(ReportWorkerBindingModel model) { _saveToWord.CreateDoc(new WordInfo { - FileName = model.FileName, Title = "Список компонент", - Sets = _setStorage.GetFullList() - }); + SetsFurnitureModules = GetSetFurnitureModule(model.SetIds) + }); } /// /// Сохранение компонент с указаеним продуктов в файл-Excel /// /// - public void SaveSetFurnitureModuleToExcelFile(ReportBindingModel model) + public void SaveSetFurnitureModuleToExcelFile(ReportWorkerBindingModel model) { _saveToExcel.CreateReport(new ExcelInfo { - FileName = model.FileName, Title = "Список компонент", - SetFurnitureModules = GetSetFurnitureModule() + SetFurnitureModules = GetSetFurnitureModule(model.SetIds) }); } /// /// Сохранение заказов в файл-Pdf /// /// - public void SaveOrdersToPdfFile(ReportBindingModel model) + public void SaveOrdersToPdfFile(ReportWorkerBindingModel model) { _saveToPdf.CreateDoc(new PdfInfo { - FileName = model.FileName, Title = "Список заказов", DateFrom = model.DateFrom!.Value, DateTo = model.DateTo!.Value, Orders = GetOrders(model) }); } - } + } } diff --git a/FurnitureAssembly/FurnitureAssemblyBusinessLogic/OfficePackage/AbstractSaveToWord.cs b/FurnitureAssembly/FurnitureAssemblyBusinessLogic/OfficePackage/AbstractSaveToWord.cs index fd3004b..6a2bdb5 100644 --- a/FurnitureAssembly/FurnitureAssemblyBusinessLogic/OfficePackage/AbstractSaveToWord.cs +++ b/FurnitureAssembly/FurnitureAssemblyBusinessLogic/OfficePackage/AbstractSaveToWord.cs @@ -22,14 +22,13 @@ namespace FurnitureAssemblyBusinessLogic.OfficePackage JustificationType = WordJustificationType.Center } }); - foreach (var set in info.Sets) + foreach (var set in info.SetsFurnitureModules) { CreateParagraph(new WordParagraph { Texts = new List<(string, WordTextProperties)> { - (set.Name, new WordTextProperties { Bold = true, Size = "24", }), - (", price: " + set.Cost.ToString(), new WordTextProperties { Size = "24", }) + (set.SetName, new WordTextProperties { Bold = true, Size = "24", }) }, TextProperties = new WordTextProperties { @@ -37,7 +36,34 @@ namespace FurnitureAssemblyBusinessLogic.OfficePackage JustificationType = WordJustificationType.Both } }); - } + foreach (var furnitureModule in set.FurnitureModules) + { + CreateParagraph(new WordParagraph + { + Texts = new List<(string, WordTextProperties)> + { + (furnitureModule.Item1 + " " + furnitureModule.Count.ToString(), new WordTextProperties { Bold = false, Size = "20", }) + }, + TextProperties = new WordTextProperties + { + Size = "20", + JustificationType = WordJustificationType.Both + } + }); + } + CreateParagraph(new WordParagraph + { + Texts = new List<(string, WordTextProperties)> + { + ("Итого " + set.TotalCount.ToString(), new WordTextProperties { Bold = false, Size = "24", }) + }, + TextProperties = new WordTextProperties + { + Size = "24", + JustificationType = WordJustificationType.Both + } + }); + } SaveWord(info); } /// diff --git a/FurnitureAssembly/FurnitureAssemblyBusinessLogic/OfficePackage/HelperModels/ExcelInfo.cs b/FurnitureAssembly/FurnitureAssemblyBusinessLogic/OfficePackage/HelperModels/ExcelInfo.cs index d50d170..a446cc2 100644 --- a/FurnitureAssembly/FurnitureAssemblyBusinessLogic/OfficePackage/HelperModels/ExcelInfo.cs +++ b/FurnitureAssembly/FurnitureAssemblyBusinessLogic/OfficePackage/HelperModels/ExcelInfo.cs @@ -9,9 +9,9 @@ namespace FurnitureAssemblyBusinessLogic.OfficePackage.HelperModels { public class ExcelInfo { - public string FileName { get; set; } = string.Empty; + public string FileName { get; set; } = "C:\\temp\\excel_worker.xlsx"; public string Title { get; set; } = string.Empty; - public List SetFurnitureModules + public List SetFurnitureModules { get; set; diff --git a/FurnitureAssembly/FurnitureAssemblyBusinessLogic/OfficePackage/HelperModels/PdfInfo.cs b/FurnitureAssembly/FurnitureAssemblyBusinessLogic/OfficePackage/HelperModels/PdfInfo.cs index 6bea5e6..3f5211d 100644 --- a/FurnitureAssembly/FurnitureAssemblyBusinessLogic/OfficePackage/HelperModels/PdfInfo.cs +++ b/FurnitureAssembly/FurnitureAssemblyBusinessLogic/OfficePackage/HelperModels/PdfInfo.cs @@ -9,10 +9,10 @@ namespace FurnitureAssemblyBusinessLogic.OfficePackage.HelperModels { public class PdfInfo { - public string FileName { get; set; } = string.Empty; + public string FileName { get; set; } = "C:\\temp\\pdf_worker.pdf"; public string Title { get; set; } = string.Empty; public DateTime DateFrom { get; set; } public DateTime DateTo { get; set; } - public List Orders { get; set; } = new(); + public List Orders { get; set; } = new(); } } diff --git a/FurnitureAssembly/FurnitureAssemblyBusinessLogic/OfficePackage/HelperModels/WordInfo.cs b/FurnitureAssembly/FurnitureAssemblyBusinessLogic/OfficePackage/HelperModels/WordInfo.cs index c83e53b..7ecd984 100644 --- a/FurnitureAssembly/FurnitureAssemblyBusinessLogic/OfficePackage/HelperModels/WordInfo.cs +++ b/FurnitureAssembly/FurnitureAssemblyBusinessLogic/OfficePackage/HelperModels/WordInfo.cs @@ -9,8 +9,8 @@ namespace FurnitureAssemblyBusinessLogic.OfficePackage.HelperModels { public class WordInfo { - public string FileName { get; set; } = string.Empty; + public string FileName { get; set; } = "C:\\temp\\word_worker.docx"; public string Title { get; set; } = string.Empty; - public List Sets { get; set; } = new(); + public List SetsFurnitureModules { get; set; } = new(); } } diff --git a/FurnitureAssembly/FurnitureAssemblyContracts/BindingModels/ReportBindingModel.cs b/FurnitureAssembly/FurnitureAssemblyContracts/BindingModels/ReportWorkerBindingModel.cs similarity index 79% rename from FurnitureAssembly/FurnitureAssemblyContracts/BindingModels/ReportBindingModel.cs rename to FurnitureAssembly/FurnitureAssemblyContracts/BindingModels/ReportWorkerBindingModel.cs index fe6478e..fbe0878 100644 --- a/FurnitureAssembly/FurnitureAssemblyContracts/BindingModels/ReportBindingModel.cs +++ b/FurnitureAssembly/FurnitureAssemblyContracts/BindingModels/ReportWorkerBindingModel.cs @@ -6,10 +6,11 @@ using System.Threading.Tasks; namespace FurnitureAssemblyContracts.BindingModels { - public class ReportBindingModel + public class ReportWorkerBindingModel { public string FileName { get; set; } = string.Empty; public DateTime? DateFrom { get; set; } public DateTime? DateTo { get; set; } + public List? SetIds { get; set; } } } diff --git a/FurnitureAssembly/FurnitureAssemblyContracts/BusinessLogicContracts/IReportLogic.cs b/FurnitureAssembly/FurnitureAssemblyContracts/BusinessLogicContracts/IReportWorkerLogic.cs similarity index 73% rename from FurnitureAssembly/FurnitureAssemblyContracts/BusinessLogicContracts/IReportLogic.cs rename to FurnitureAssembly/FurnitureAssemblyContracts/BusinessLogicContracts/IReportWorkerLogic.cs index 67a0594..642aaf8 100644 --- a/FurnitureAssembly/FurnitureAssemblyContracts/BusinessLogicContracts/IReportLogic.cs +++ b/FurnitureAssembly/FurnitureAssemblyContracts/BusinessLogicContracts/IReportWorkerLogic.cs @@ -8,33 +8,33 @@ using System.Threading.Tasks; namespace FurnitureAssemblyContracts.BusinessLogicContracts { - public interface IReportLogic + public interface IReportWorkerLogic { /// /// Получение списка мебельных модулей с указанием, в каких гарнитурах используются /// /// - List GetSetFurnitureModule(); + List GetSetFurnitureModule(List setIds); /// /// Получение списка заказов за определенный период /// /// /// - List GetOrders(ReportBindingModel model); + List GetOrders(ReportWorkerBindingModel model); /// /// Сохранение материалов в файл-Word /// /// - void SaveFurnitureModuleToWordFile(ReportBindingModel model); + void SaveFurnitureModuleToWordFile(ReportWorkerBindingModel model); /// /// Сохранение материалов с указаеним мебельных модулей в файл-Excel /// /// - void SaveSetFurnitureModuleToExcelFile(ReportBindingModel model); + void SaveSetFurnitureModuleToExcelFile(ReportWorkerBindingModel model); /// /// Сохранение заказов в файл-Pdf /// /// - void SaveOrdersToPdfFile(ReportBindingModel model); + void SaveOrdersToPdfFile(ReportWorkerBindingModel model); } } diff --git a/FurnitureAssembly/FurnitureAssemblyContracts/ViewModels/ReportOrdersViewModel.cs b/FurnitureAssembly/FurnitureAssemblyContracts/ViewModels/ReportOrdersWorkerViewModel.cs similarity index 92% rename from FurnitureAssembly/FurnitureAssemblyContracts/ViewModels/ReportOrdersViewModel.cs rename to FurnitureAssembly/FurnitureAssemblyContracts/ViewModels/ReportOrdersWorkerViewModel.cs index 6a7d408..771c8c9 100644 --- a/FurnitureAssembly/FurnitureAssemblyContracts/ViewModels/ReportOrdersViewModel.cs +++ b/FurnitureAssembly/FurnitureAssemblyContracts/ViewModels/ReportOrdersWorkerViewModel.cs @@ -7,7 +7,7 @@ using System.Threading.Tasks; namespace FurnitureAssemblyContracts.ViewModels { - public class ReportOrdersViewModel + public class ReportOrdersWorkerViewModel { public int Id { get; set; } public DateTime DateCreate { get; set; } diff --git a/FurnitureAssembly/FurnitureAssemblyContracts/ViewModels/ReportSetFurnitureModuleViewModel.cs b/FurnitureAssembly/FurnitureAssemblyContracts/ViewModels/ReportSetFurnitureModuleWorkerViewModel.cs similarity index 86% rename from FurnitureAssembly/FurnitureAssemblyContracts/ViewModels/ReportSetFurnitureModuleViewModel.cs rename to FurnitureAssembly/FurnitureAssemblyContracts/ViewModels/ReportSetFurnitureModuleWorkerViewModel.cs index c619c1a..c62b807 100644 --- a/FurnitureAssembly/FurnitureAssemblyContracts/ViewModels/ReportSetFurnitureModuleViewModel.cs +++ b/FurnitureAssembly/FurnitureAssemblyContracts/ViewModels/ReportSetFurnitureModuleWorkerViewModel.cs @@ -6,7 +6,7 @@ using System.Threading.Tasks; namespace FurnitureAssemblyContracts.ViewModels { - public class ReportSetFurnitureModuleViewModel + public class ReportSetFurnitureModuleWorkerViewModel { public string SetName { get; set; } = string.Empty; public int TotalCount { get; set; } diff --git a/FurnitureAssembly/FurnitureAssemblyRestApi/Controllers/ReportController.cs b/FurnitureAssembly/FurnitureAssemblyRestApi/Controllers/ReportController.cs new file mode 100644 index 0000000..3c95540 --- /dev/null +++ b/FurnitureAssembly/FurnitureAssemblyRestApi/Controllers/ReportController.cs @@ -0,0 +1,52 @@ +using DocumentFormat.OpenXml.Spreadsheet; +using FurnitureAssemblyContracts.BindingModels; +using FurnitureAssemblyContracts.BusinessLogicContracts; +using FurnitureAssemblyContracts.SearchModels; +using FurnitureAssemblyContracts.ViewModels; +using FurnitureAssemblyDatabaseImplement.Models; +using Microsoft.AspNetCore.Mvc; +using System.Collections.Generic; + +namespace FurnitureAssemblyRestApi.Controllers +{ + [Route("api/[controller]/[action]")] + [ApiController] + public class ReportController : Controller + { + private readonly ILogger _logger; + private readonly IReportWorkerLogic _reportWorkerLogic; + public ReportController(ILogger logger, IReportWorkerLogic reportWorkerLogic) + { + _logger = logger; + _reportWorkerLogic = reportWorkerLogic; + } + + + [HttpPost] + public void CreateReportToDocx(ReportWorkerBindingModel model) + { + try + { + _reportWorkerLogic.SaveFurnitureModuleToWordFile(model); + } + catch (Exception ex) + { + _logger.LogError(ex, "Ошибка создания отчета"); + throw; + } + } + [HttpPost] + public void CreateReportToXlsx(ReportWorkerBindingModel model) + { + try + { + _reportWorkerLogic.SaveSetFurnitureModuleToExcelFile(model); + } + catch (Exception ex) + { + _logger.LogError(ex, "Ошибка создания отчета"); + throw; + } + } + } +} diff --git a/FurnitureAssembly/FurnitureAssemblyRestApi/Program.cs b/FurnitureAssembly/FurnitureAssemblyRestApi/Program.cs index 5dbcd35..ae7f22d 100644 --- a/FurnitureAssembly/FurnitureAssemblyRestApi/Program.cs +++ b/FurnitureAssembly/FurnitureAssemblyRestApi/Program.cs @@ -1,4 +1,6 @@ using FurnitureAssemblyBusinessLogic.BusinessLogics; +using FurnitureAssemblyBusinessLogic.OfficePackage.Implements; +using FurnitureAssemblyBusinessLogic.OfficePackage; using FurnitureAssemblyContracts.BusinessLogicContracts; using FurnitureAssemblyContracts.StorageContracts; using FurnitureAssemblyDatabaseImplement.Implements; @@ -29,6 +31,11 @@ builder.Services.AddTransient(); builder.Services.AddTransient(); builder.Services.AddTransient(); builder.Services.AddTransient(); +builder.Services.AddTransient(); + +builder.Services.AddTransient(); +builder.Services.AddTransient(); +builder.Services.AddTransient(); builder.Services.AddControllers(); // Learn more about configuring Swagger/OpenAPI at https://aka.ms/aspnetcore/swashbuckle diff --git a/FurnitureAssembly/FurnitureAssemblyWorkerClientApp/APIClient.cs b/FurnitureAssembly/FurnitureAssemblyWorkerClientApp/APIClient.cs index fca9a53..719ba93 100644 --- a/FurnitureAssembly/FurnitureAssemblyWorkerClientApp/APIClient.cs +++ b/FurnitureAssembly/FurnitureAssemblyWorkerClientApp/APIClient.cs @@ -29,6 +29,10 @@ namespace FurnitureAssemblyWorkerClientApp throw new Exception(result); } } + public static void GetBaseRequest(string requestUrl) + { + var response = _client.GetAsync(requestUrl); + } public static void PostRequest(string requestUrl, T model) { var json = JsonConvert.SerializeObject(model); diff --git a/FurnitureAssembly/FurnitureAssemblyWorkerClientApp/Controllers/HomeController.cs b/FurnitureAssembly/FurnitureAssemblyWorkerClientApp/Controllers/HomeController.cs index 14d4cf2..e83e602 100644 --- a/FurnitureAssembly/FurnitureAssemblyWorkerClientApp/Controllers/HomeController.cs +++ b/FurnitureAssembly/FurnitureAssemblyWorkerClientApp/Controllers/HomeController.cs @@ -226,9 +226,11 @@ namespace FurnitureAssemblyWorkerClientApp.Controllers [HttpGet] public IActionResult AddFurnitureModuleInSet() { - ViewBag.Shops = APIClient.GetRequest>("api/set/getsetlist"); - ViewBag.Manufactures = APIClient.GetRequest>("api/furnituremodule/getfurnituremodulelist"); - return View(Tuple.Create(APIClient.GetRequest>("api/set/getsetlist"), APIClient.GetRequest>("api/furnituremodule/getfurnituremodulelist"))); + if (APIClient.User == null) + { + return Redirect("~/Home/Enter"); + } + return View(Tuple.Create(APIClient.GetRequest>("api/set/getsetlist"), APIClient.GetRequest>("api/furnituremodule/getfurnituremodulelist"))); } [HttpPost] public void AddFurnitureModuleInSet(int set, int furnitureModule, int count) @@ -248,5 +250,61 @@ namespace FurnitureAssemblyWorkerClientApp.Controllers )); Response.Redirect("Sets"); } - } + [HttpGet] + public IActionResult ListSetsFurnitureModulesToFile() + { + if (APIClient.User == null) + { + return Redirect("~/Home/Enter"); + } + return View(APIClient.GetRequest>($"api/set/getsetlist")); + } + [HttpPost] + public void ListSetsFurnitureModulesToFile(int[] setIds, string type) + { + if (APIClient.User == null) + { + throw new Exception("Вы как суда попали? Суда вход только авторизованным"); + } + if (setIds.Length <= 0) + { + throw new Exception("Количество должно быть больше 0"); + } + if (string.IsNullOrEmpty(type)) + { + throw new Exception("Неверный тип отчета"); + } + + List res = new List(); + foreach (var item in setIds) + { + res.Add(item); + } + if (type == "docx") + { + APIClient.PostRequest("api/report/createreporttodocx", new ReportWorkerBindingModel + { + SetIds = res + }); + Response.Redirect("GetDocxFile"); + } + else + { + APIClient.PostRequest("api/report/createreporttoxlsx", new ReportWorkerBindingModel + { + SetIds = res + }); + Response.Redirect("GetXlsxFile"); + } + } + [HttpGet] + public IActionResult GetDocxFile() + { + return new PhysicalFileResult("C:\\temp\\word_worker.docx", "application/vnd.openxmlformats-officedocument.wordprocessingml.document"); + } + public IActionResult GetXlsxFile() + { + return new PhysicalFileResult("C:\\temp\\excel_worker.xlsx", "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet"); + } + } } \ No newline at end of file diff --git a/FurnitureAssembly/FurnitureAssemblyWorkerClientApp/Views/Home/ListSetsFurnitureModulesToFile.cshtml b/FurnitureAssembly/FurnitureAssemblyWorkerClientApp/Views/Home/ListSetsFurnitureModulesToFile.cshtml new file mode 100644 index 0000000..10c5376 --- /dev/null +++ b/FurnitureAssembly/FurnitureAssemblyWorkerClientApp/Views/Home/ListSetsFurnitureModulesToFile.cshtml @@ -0,0 +1,77 @@ +@using FurnitureAssemblyContracts.ViewModels + +@model List + +@{ + ViewData["Title"] = "Формирование гарнитуров"; +} + +
+

Гарнитуры

+
+ +
+ @{ + if (Model == null) + { +

Авторизируйтесь

+ return; + } + + +
+
+
+ + +
+
+ + +
+
+ + + + + + + + + + + @foreach (var item in Model) + { + + + + + + + } + +
+ + + Название + + Стоимость + + Дата создания +
+ + + @Html.DisplayFor(modelItem => item.Name) + + @Html.DisplayFor(modelItem => item.Cost) + + @Html.DisplayFor(modelItem => item.DateCreate) +
+ +
+ } +
\ No newline at end of file diff --git a/FurnitureAssembly/FurnitureAssemblyWorkerClientApp/Views/Shared/_Layout.cshtml b/FurnitureAssembly/FurnitureAssemblyWorkerClientApp/Views/Shared/_Layout.cshtml index e5c2f89..76e2ea4 100644 --- a/FurnitureAssembly/FurnitureAssemblyWorkerClientApp/Views/Shared/_Layout.cshtml +++ b/FurnitureAssembly/FurnitureAssemblyWorkerClientApp/Views/Shared/_Layout.cshtml @@ -35,6 +35,9 @@ +