From 88de48c73e9f77318192ba11758214c111f548c0 Mon Sep 17 00:00:00 2001 From: urlilpolly Date: Thu, 30 May 2024 00:36:30 +0400 Subject: [PATCH] =?UTF-8?q?the=20end=20(=D0=BD=D0=B0=D0=B4=D0=B5=D1=8E?= =?UTF-8?q?=D1=81=D1=8C)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../BusinessLogic/GuarantorReportLogic.cs | 88 +++++++++++++++++++ .../IGuarantorReportLogic.cs | 17 ++++ .../SearchModels/WorkerSearchModel.cs | 2 + .../WorkerMachineCountChartViewModel.cs | 14 +++ .../WorkerWorkshopCountChartViewModel.cs | 14 +++ .../Controllers/HomeController.cs | 37 +++++++- Course/GuarantorAPP/GuarantorData.cs | 42 +++------ Course/GuarantorAPP/Program.cs | 1 + Course/GuarantorAPP/Views/Home/Index.cshtml | 1 + .../Views/Home/MachineHistogram.cshtml | 42 +++++++++ Course/GuarantorAPP/Views/Home/Menu.cshtml | 11 +++ .../Views/Home/WorkshopHistogram.cshtml | 42 +++++++++ 12 files changed, 282 insertions(+), 29 deletions(-) create mode 100644 Course/BusinessLogic/BusinessLogic/GuarantorReportLogic.cs create mode 100644 Course/Contracts/BusinessLogicsContracts/IGuarantorReportLogic.cs create mode 100644 Course/Contracts/ViewModels/WorkerMachineCountChartViewModel.cs create mode 100644 Course/Contracts/ViewModels/WorkerWorkshopCountChartViewModel.cs create mode 100644 Course/GuarantorAPP/Views/Home/MachineHistogram.cshtml create mode 100644 Course/GuarantorAPP/Views/Home/Menu.cshtml create mode 100644 Course/GuarantorAPP/Views/Home/WorkshopHistogram.cshtml diff --git a/Course/BusinessLogic/BusinessLogic/GuarantorReportLogic.cs b/Course/BusinessLogic/BusinessLogic/GuarantorReportLogic.cs new file mode 100644 index 0000000..2342495 --- /dev/null +++ b/Course/BusinessLogic/BusinessLogic/GuarantorReportLogic.cs @@ -0,0 +1,88 @@ +using Contracts.BusinessLogicsContracts; +using Contracts.StoragesContracts; +using Contracts.ViewModels; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace BusinessLogic.BusinessLogic +{ + public class GuarantorReportLogic : IGuarantorReportLogic + { + private readonly IWorkerStorage _workerStorage; + private readonly IMachineStorage _machineStorage; + private readonly IWorkshopStorage _workshopStorage; + private readonly IProductStorage _productStorage; + + public GuarantorReportLogic(IWorkerStorage workerStorage, IMachineStorage machineStorage, IWorkshopStorage workshopStorage, IProductStorage productStorage) + { + _workerStorage = workerStorage; + _machineStorage = machineStorage; + _workshopStorage = workshopStorage; + _productStorage = productStorage; + } + public List? GetWorkerMachineChart(int UserId) + { + var machines = _machineStorage.GetFilteredList(new() { UserId = UserId }); + List workerChart = new(); + foreach (var mach in machines) + { + WorkerMachineCountChartViewModel worker = new WorkerMachineCountChartViewModel(); + worker.MachineName = mach.Title; + var count = _workerStorage.GetFilteredList(new() { MachineId = mach.Id, UserId = UserId }).Count; + worker.WorkerCount = count; + workerChart.Add(worker); + } + return workerChart; + } + + public List? GetWorkerWorkshopChart(int UserId) + { + var workshops = _workshopStorage.GetFilteredList(new() { UserId = UserId }); + List workerChart = new(); + foreach (var work in workshops) + { + WorkerWorkshopCountChartViewModel worker = new WorkerWorkshopCountChartViewModel(); + worker.WorkshopName = work.Title; + var count = _workerStorage.GetFilteredList(new() { WorkshopId = work.Id, UserId = UserId }).Count; + worker.WorkerCount = count; + workerChart.Add(worker); + } + return workerChart; + } + public List? GetMachineWorkshopTimeReport(DateTime startDate, DateTime endDate, int UserId) + { + var workshops = _workshopStorage.GetFilteredList(new() { DateFrom = startDate, DateTo = endDate, UserId = UserId }); + if (workshops == null) + return new(); + List machineWorkshopTimeReports = new List(); + foreach (var workshop in workshops) + { + var report = new MachineWorkshopTimeReport(); + report.WorkshopName = workshop.Title; + var machines = _machineStorage.GetFilteredList(new() { WorkshopId = workshop.Id, UserId = UserId }); + if (machines != null) + report.Machines = machines.Select(p => p.Title).ToList(); + machineWorkshopTimeReports.Add(report); + } + return machineWorkshopTimeReports; + } + public List? GetWorkerProductReport(List ids) + { + List reports = new(); + foreach (int i in ids) + { + WorkerProductReportViewModel report = new(); + var worker = _workerStorage.GetElement(new() { Id = i }); + report.WorkerName = worker!.Name; + var products = _productStorage.GetFilteredList(new() { WorkerId = i }); + if (products != null) + report.Products = products.Select(x => x.Name).ToList(); + reports.Add(report); + } + return reports; + } + } +} diff --git a/Course/Contracts/BusinessLogicsContracts/IGuarantorReportLogic.cs b/Course/Contracts/BusinessLogicsContracts/IGuarantorReportLogic.cs new file mode 100644 index 0000000..9567439 --- /dev/null +++ b/Course/Contracts/BusinessLogicsContracts/IGuarantorReportLogic.cs @@ -0,0 +1,17 @@ +using Contracts.ViewModels; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace Contracts.BusinessLogicsContracts +{ + public interface IGuarantorReportLogic + { + List? GetWorkerProductReport(List ids); + List? GetMachineWorkshopTimeReport(DateTime start, DateTime end, int UserId); + List? GetWorkerMachineChart(int UserId); + List? GetWorkerWorkshopChart(int UserId); + } +} diff --git a/Course/Contracts/SearchModels/WorkerSearchModel.cs b/Course/Contracts/SearchModels/WorkerSearchModel.cs index 4a03a46..c90c8a1 100644 --- a/Course/Contracts/SearchModels/WorkerSearchModel.cs +++ b/Course/Contracts/SearchModels/WorkerSearchModel.cs @@ -5,5 +5,7 @@ public int? Id { get; set; } public string? Name { get; set; } public int? UserId { get; set; } + public int MachineId { get; set; } + public int WorkshopId { get; set; } } } diff --git a/Course/Contracts/ViewModels/WorkerMachineCountChartViewModel.cs b/Course/Contracts/ViewModels/WorkerMachineCountChartViewModel.cs new file mode 100644 index 0000000..084a29e --- /dev/null +++ b/Course/Contracts/ViewModels/WorkerMachineCountChartViewModel.cs @@ -0,0 +1,14 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace Contracts.ViewModels +{ + public class WorkerMachineCountChartViewModel + { + public string MachineName { get; set; } = string.Empty; + public int WorkerCount { get; set; } + } +} diff --git a/Course/Contracts/ViewModels/WorkerWorkshopCountChartViewModel.cs b/Course/Contracts/ViewModels/WorkerWorkshopCountChartViewModel.cs new file mode 100644 index 0000000..9bd80f4 --- /dev/null +++ b/Course/Contracts/ViewModels/WorkerWorkshopCountChartViewModel.cs @@ -0,0 +1,14 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace Contracts.ViewModels +{ + public class WorkerWorkshopCountChartViewModel + { + public string WorkshopName { get; set; } = string.Empty; + public int WorkerCount { get; set; } + } +} diff --git a/Course/GuarantorAPP/Controllers/HomeController.cs b/Course/GuarantorAPP/Controllers/HomeController.cs index fc05a80..3f88598 100644 --- a/Course/GuarantorAPP/Controllers/HomeController.cs +++ b/Course/GuarantorAPP/Controllers/HomeController.cs @@ -537,12 +537,47 @@ namespace GuarantorAPP.Controllers var workshop = _data.GetWorkshop(workshopId); if (workshop == null) return RedirectToAction("Index"); - WorkshopBindingModel workshopBinding = new() { Id = workshopId, Title = workshop.Title, Address = workshop.Address, Director = workshop.Director, UserId = workshop.UserId, ProductionId = workshop.ProductionId, WorkshopWorker = workshop.WorkerWorkshops }; + WorkshopBindingModel workshopBinding = new() { Id = workshopId, Title = workshop.Title, Address = workshop.Address, Director = workshop.Director, UserId = workshop.UserId, ProductionId = productionId, WorkshopWorker = workshop.WorkerWorkshops }; _data.UpdateWorkshop(workshopBinding); } catch (Exception) { } return RedirectToAction("IndexWorkshop"); } + [HttpGet] + public IActionResult MachineHistogram() + { + if (!IsLoggedIn) + return RedirectToAction("IndexNonReg"); + try + { + var chart = _data.GetMachineChart(UserId); + return View(chart); + } catch + { + return RedirectToAction("IndexNonReg"); + } + } + public IActionResult Menu() + { + if (!IsLoggedIn) + return RedirectToAction("IndexNonReg"); + return View(); + } + [HttpGet] + public IActionResult WorkshopHistogram() + { + if (!IsLoggedIn) + return RedirectToAction("IndexNonReg"); + try + { + var chart = _data.GetWorkshopChart(UserId); + return View(chart); + } + catch + { + return RedirectToAction("IndexNonReg"); + } + } [ResponseCache(Duration = 0, Location = ResponseCacheLocation.None, NoStore = true)] public IActionResult Error(string ex) { diff --git a/Course/GuarantorAPP/GuarantorData.cs b/Course/GuarantorAPP/GuarantorData.cs index 2abe74c..8ace7b9 100644 --- a/Course/GuarantorAPP/GuarantorData.cs +++ b/Course/GuarantorAPP/GuarantorData.cs @@ -18,12 +18,13 @@ namespace GuarantorAPP private readonly IWorkshopLogic _workshopLogic; private readonly IProductionLogic _productionLogic; private readonly IProductLogic _productLogic; + private readonly IGuarantorReportLogic _reportLogic; private readonly AbstractSaveToExcelGuarantor _excel; private readonly AbstractSaveToWordGuarantor _word; private readonly AbstractSaveToPdfGuarantor _pdf; private readonly AbstractMailWorker _mail; - public GuarantorData(ILogger logger, IGuarantorLogic guarantorLogic, IWorkerLogic workerLogic, IMachineLogic machineLogic, IWorkshopLogic workshopLogic, IProductionLogic productionLogic, IProductLogic productLogic, AbstractSaveToExcelGuarantor excel, AbstractSaveToPdfGuarantor pdf, AbstractSaveToWordGuarantor word, AbstractMailWorker mail) + public GuarantorData(ILogger logger, IGuarantorLogic guarantorLogic, IWorkerLogic workerLogic, IMachineLogic machineLogic, IWorkshopLogic workshopLogic, IProductionLogic productionLogic, IProductLogic productLogic, IGuarantorReportLogic reportLogic, AbstractSaveToExcelGuarantor excel, AbstractSaveToPdfGuarantor pdf, AbstractSaveToWordGuarantor word, AbstractMailWorker mail) { _logger = logger; _guarantorLogic = guarantorLogic; @@ -32,6 +33,7 @@ namespace GuarantorAPP _workshopLogic = workshopLogic; _productionLogic = productionLogic; _productLogic = productLogic; + _reportLogic = reportLogic; _excel = excel; _pdf = pdf; _mail = mail; @@ -138,37 +140,13 @@ namespace GuarantorAPP { return _productionLogic.ReadList(null); } - public List GetTimeReport(DateTime? startDate, DateTime? endDate, int UserId) + public List? GetTimeReport(DateTime? startDate, DateTime? endDate, int UserId) { - var workshops = _workshopLogic.ReadList(new() { DateFrom = startDate, DateTo = endDate, UserId = UserId }); - if (workshops == null) - return new(); - List machineWorkshopTimeReports = new List(); - foreach (var workshop in workshops) - { - var report = new MachineWorkshopTimeReport(); - report.WorkshopName = workshop.Title; - var machines = _machineLogic.ReadList(new() { WorkshopId = workshop.Id, UserId = UserId }); - if (machines != null) - report.Machines = machines.Select(p => p.Title).ToList(); - machineWorkshopTimeReports.Add(report); - } - return machineWorkshopTimeReports; + return _reportLogic.GetMachineWorkshopTimeReport(startDate!.Value, endDate!.Value, UserId); } public List? GetProductReports(List workers) { - List reports = new(); - foreach (int i in workers) - { - WorkerProductReportViewModel report = new(); - var worker = _workerLogic.ReadElement(new() { Id = i }); - report.WorkerName = worker!.Name; - var products = _productLogic.ReadList(new() { WorkerId = i }); - if (products != null) - report.Products = products.Select(x => x.Name).ToList(); - reports.Add(report); - } - return reports; + return _reportLogic.GetWorkerProductReport(workers); } public void SaveReportExcel(List workers, MemoryStream stream) { @@ -225,5 +203,13 @@ namespace GuarantorAPP MailAddress = UserGuarantor.user!.Email, Subject = "Отчет", FileName = "PdfReport.pdf", Pdf = report }); } + public List? GetMachineChart(int UserId) + { + return _reportLogic.GetWorkerMachineChart(UserId); + } + public List? GetWorkshopChart(int UserId) + { + return _reportLogic.GetWorkerWorkshopChart(UserId); + } } } diff --git a/Course/GuarantorAPP/Program.cs b/Course/GuarantorAPP/Program.cs index 495b51f..7dcd2f7 100644 --- a/Course/GuarantorAPP/Program.cs +++ b/Course/GuarantorAPP/Program.cs @@ -26,6 +26,7 @@ builder.Services.AddTransient(); builder.Services.AddTransient(); builder.Services.AddTransient(); builder.Services.AddTransient(); +builder.Services.AddTransient(); builder.Services.AddTransient(); builder.Services.AddTransient(); builder.Services.AddTransient(); diff --git a/Course/GuarantorAPP/Views/Home/Index.cshtml b/Course/GuarantorAPP/Views/Home/Index.cshtml index ba5486e..5a02c75 100644 --- a/Course/GuarantorAPP/Views/Home/Index.cshtml +++ b/Course/GuarantorAPP/Views/Home/Index.cshtml @@ -10,6 +10,7 @@ Цеха Меню отчетов Личные данные + Графики Выйти diff --git a/Course/GuarantorAPP/Views/Home/MachineHistogram.cshtml b/Course/GuarantorAPP/Views/Home/MachineHistogram.cshtml new file mode 100644 index 0000000..d9359ba --- /dev/null +++ b/Course/GuarantorAPP/Views/Home/MachineHistogram.cshtml @@ -0,0 +1,42 @@ +@using Contracts.ViewModels; +@model List; + + + + + Histogram Example + + + +
+ +
+ + + \ No newline at end of file diff --git a/Course/GuarantorAPP/Views/Home/Menu.cshtml b/Course/GuarantorAPP/Views/Home/Menu.cshtml new file mode 100644 index 0000000..d3a82d8 --- /dev/null +++ b/Course/GuarantorAPP/Views/Home/Menu.cshtml @@ -0,0 +1,11 @@ +@{ + ViewData["Title"] = "Меню графиков"; +} + + \ No newline at end of file diff --git a/Course/GuarantorAPP/Views/Home/WorkshopHistogram.cshtml b/Course/GuarantorAPP/Views/Home/WorkshopHistogram.cshtml new file mode 100644 index 0000000..b39d8bf --- /dev/null +++ b/Course/GuarantorAPP/Views/Home/WorkshopHistogram.cshtml @@ -0,0 +1,42 @@ +@using Contracts.ViewModels; +@model List; + + + + + Histogram Example + + + +
+ +
+ + + \ No newline at end of file