added get list in docx or xlsx page

This commit is contained in:
Калышев Ян 2023-05-16 17:29:22 -07:00
parent 27da6a9552
commit 35abda9b93
15 changed files with 281 additions and 44 deletions

View File

@ -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
/// Получение списка мебельных модулей с указанием, в каких гарнитурах используются
/// </summary>
/// <returns></returns>
public List<ReportSetFurnitureModuleViewModel> GetSetFurnitureModule()
public List<ReportSetFurnitureModuleWorkerViewModel> GetSetFurnitureModule(List<int> setIds)
{
if (setIds == null)
{
return new List<ReportSetFurnitureModuleWorkerViewModel>();
}
var furnitureModules = _furnitureModuleStorage.GetFullList();
var sets = _setStorage.GetFullList();
var list = new List<ReportSetFurnitureModuleViewModel>();
List<SetViewModel> sets = new List<SetViewModel>();
foreach (var setId in setIds)
{
var res = _setStorage.GetElement(new SetSearchModel { Id = setId });
if (res != null)
{
sets.Add(res);
}
}
var list = new List<ReportSetFurnitureModuleWorkerViewModel>();
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
/// </summary>
/// <param name="model"></param>
/// <returns></returns>
public List<ReportOrdersViewModel> GetOrders(ReportBindingModel model)
public List<ReportOrdersWorkerViewModel> 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<ReportOrdersViewModel>();
var list = new List<ReportOrdersWorkerViewModel>();
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
/// </summary>
/// <param name="model"></param>
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)
});
}
/// <summary>
/// Сохранение компонент с указаеним продуктов в файл-Excel
/// </summary>
/// <param name="model"></param>
public void SaveSetFurnitureModuleToExcelFile(ReportBindingModel model)
public void SaveSetFurnitureModuleToExcelFile(ReportWorkerBindingModel model)
{
_saveToExcel.CreateReport(new ExcelInfo
{
FileName = model.FileName,
Title = "Список компонент",
SetFurnitureModules = GetSetFurnitureModule()
SetFurnitureModules = GetSetFurnitureModule(model.SetIds)
});
}
/// <summary>
/// Сохранение заказов в файл-Pdf
/// </summary>
/// <param name="model"></param>
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)
});
}
}
}
}

View File

@ -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);
}
/// <summary>

View File

@ -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<ReportSetFurnitureModuleViewModel> SetFurnitureModules
public List<ReportSetFurnitureModuleWorkerViewModel> SetFurnitureModules
{
get;
set;

View File

@ -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<ReportOrdersViewModel> Orders { get; set; } = new();
public List<ReportOrdersWorkerViewModel> Orders { get; set; } = new();
}
}

View File

@ -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<SetViewModel> Sets { get; set; } = new();
public List<ReportSetFurnitureModuleWorkerViewModel> SetsFurnitureModules { get; set; } = new();
}
}

View File

@ -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<int>? SetIds { get; set; }
}
}

View File

@ -8,33 +8,33 @@ using System.Threading.Tasks;
namespace FurnitureAssemblyContracts.BusinessLogicContracts
{
public interface IReportLogic
public interface IReportWorkerLogic
{
/// <summary>
/// Получение списка мебельных модулей с указанием, в каких гарнитурах используются
/// </summary>
/// <returns></returns>
List<ReportSetFurnitureModuleViewModel> GetSetFurnitureModule();
List<ReportSetFurnitureModuleWorkerViewModel> GetSetFurnitureModule(List<int> setIds);
/// <summary>
/// Получение списка заказов за определенный период
/// </summary>
/// <param name="model"></param>
/// <returns></returns>
List<ReportOrdersViewModel> GetOrders(ReportBindingModel model);
List<ReportOrdersWorkerViewModel> GetOrders(ReportWorkerBindingModel model);
/// <summary>
/// Сохранение материалов в файл-Word
/// </summary>
/// <param name="model"></param>
void SaveFurnitureModuleToWordFile(ReportBindingModel model);
void SaveFurnitureModuleToWordFile(ReportWorkerBindingModel model);
/// <summary>
/// Сохранение материалов с указаеним мебельных модулей в файл-Excel
/// </summary>
/// <param name="model"></param>
void SaveSetFurnitureModuleToExcelFile(ReportBindingModel model);
void SaveSetFurnitureModuleToExcelFile(ReportWorkerBindingModel model);
/// <summary>
/// Сохранение заказов в файл-Pdf
/// </summary>
/// <param name="model"></param>
void SaveOrdersToPdfFile(ReportBindingModel model);
void SaveOrdersToPdfFile(ReportWorkerBindingModel model);
}
}

View File

@ -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; }

View File

@ -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; }

View File

@ -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<ReportController> 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;
}
}
}
}

View File

@ -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<IRoleLogic, RoleLogic>();
builder.Services.AddTransient<IScopeLogic, ScopeLogic>();
builder.Services.AddTransient<ISetLogic, SetLogic>();
builder.Services.AddTransient<IUserLogic, UserLogic>();
builder.Services.AddTransient<IReportWorkerLogic, ReportWorkerLogic>();
builder.Services.AddTransient<AbstractSaveToExcel, SaveToExcel>();
builder.Services.AddTransient<AbstractSaveToWord, SaveToWord>();
builder.Services.AddTransient<AbstractSaveToPdf, SaveToPdf>();
builder.Services.AddControllers();
// Learn more about configuring Swagger/OpenAPI at https://aka.ms/aspnetcore/swashbuckle

View File

@ -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<T>(string requestUrl, T model)
{
var json = JsonConvert.SerializeObject(model);

View File

@ -226,9 +226,11 @@ namespace FurnitureAssemblyWorkerClientApp.Controllers
[HttpGet]
public IActionResult AddFurnitureModuleInSet()
{
ViewBag.Shops = APIClient.GetRequest<List<SetViewModel>>("api/set/getsetlist");
ViewBag.Manufactures = APIClient.GetRequest<List<FurnitureModuleViewModel>>("api/furnituremodule/getfurnituremodulelist");
return View(Tuple.Create(APIClient.GetRequest<List<SetViewModel>>("api/set/getsetlist"), APIClient.GetRequest<List<FurnitureModuleViewModel>>("api/furnituremodule/getfurnituremodulelist")));
if (APIClient.User == null)
{
return Redirect("~/Home/Enter");
}
return View(Tuple.Create(APIClient.GetRequest<List<SetViewModel>>("api/set/getsetlist"), APIClient.GetRequest<List<FurnitureModuleViewModel>>("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<List<SetViewModel>>($"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<int> res = new List<int>();
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");
}
}
}

View File

@ -0,0 +1,77 @@
@using FurnitureAssemblyContracts.ViewModels
@model List<SetViewModel>
@{
ViewData["Title"] = "Формирование гарнитуров";
}
<div class="text-center">
<h1 class="display-4">Гарнитуры</h1>
</div>
<div class="text-center">
@{
if (Model == null)
{
<h3 class="display-4">Авторизируйтесь</h3>
return;
}
<form method="post">
<div>
<div class="form-check form-check-inline">
<input class="form-check-input" type="radio" name="type" value="docx" id="docx">
<label class="form-check-label" for="docx">
В docx
</label>
</div>
<div class="form-check form-check-inline">
<input class="form-check-input" type="radio" name="type" value="xlsx" id="xlsx" checked>
<label class="form-check-label" for="xlsx">
В xlsx
</label>
</div>
</div>
<table class="table">
<thead>
<tr>
<th>
</th>
<th>
Название
</th>
<th>
Стоимость
</th>
<th>
Дата создания
</th>
</tr>
</thead>
<tbody>
@foreach (var item in Model)
{
<tr>
<td>
<input type="checkbox" class="form-check-input" name="setIds[]" value="@item.Id" id="@item.Id">
</td>
<td>
@Html.DisplayFor(modelItem => item.Name)
</td>
<td>
@Html.DisplayFor(modelItem => item.Cost)
</td>
<td>
@Html.DisplayFor(modelItem => item.DateCreate)
</td>
</tr>
}
</tbody>
</table>
<button class="btn btn-primary" type="submit">Сгенерировать</button>
</form>
}
</div>

View File

@ -35,6 +35,9 @@
<li class="nav-item">
<a class="nav-link text-dark" asp-area="" asp-controller="Home" asp-action="Sets">Гарнитуры</a>
</li>
<li class="nav-item">
<a class="nav-link text-dark" asp-area="" asp-controller="Home" asp-action="ListSetsFurnitureModulesToFile">Получение списка</a>
</li>
</ul>
</div>
</div>