From cdf1ca5e9f1f39865e7d2a9eed8038c5f8ef2479 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D0=9C=D0=B0=D0=BA=D1=81=D0=B8=D0=BC=20=D0=AF=D0=BA=D0=BE?= =?UTF-8?q?=D0=B2=D0=BB=D0=B5=D0=B2?= Date: Tue, 28 May 2024 17:06:11 +0400 Subject: [PATCH] =?UTF-8?q?=D0=BF=D0=BE=D0=B4=D0=BF=D1=80=D0=B0=D0=B2?= =?UTF-8?q?=D0=B8=D0=BB=20=D0=BE=D1=82=D1=87=D0=B5=D1=82=D1=8B?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../BusinessLogics/ExecutorReportLogic.cs | 48 ++++++---- .../AbstractSaveToPdfExecutor.cs | 8 +- .../Implements/RepairStorage.cs | 2 +- .../Implements/TechnicalWorkStorage.cs | 2 +- .../Controllers/HomeController.cs | 93 +++++++++++++++---- .../ServiceStationExecutorApp/Program.cs | 16 ++++ .../ServiceStationExecutorApp.csproj | 2 + .../Views/Home/ListCarsToPdf.cshtml | 27 +++++- .../Controllers/MainController.cs | 14 +++ .../ServiceStationRestApi/Program.cs | 7 ++ 10 files changed, 176 insertions(+), 43 deletions(-) diff --git a/ServiceStation/ServiceStationBusinessLogic/BusinessLogics/ExecutorReportLogic.cs b/ServiceStation/ServiceStationBusinessLogic/BusinessLogics/ExecutorReportLogic.cs index cf443e3..27013af 100644 --- a/ServiceStation/ServiceStationBusinessLogic/BusinessLogics/ExecutorReportLogic.cs +++ b/ServiceStation/ServiceStationBusinessLogic/BusinessLogics/ExecutorReportLogic.cs @@ -20,17 +20,19 @@ namespace ServiceStationBusinessLogic.BusinessLogics private readonly IRepairStorage _repairStorage; private readonly IWorkStorage _workStorage; private readonly ICarStorage _carStorage; + private readonly IDefectStorage _defectStorage; private readonly AbstractSaveToExcelExecutor _saveToExcel; private readonly AbstractSaveToWordExecutor _saveToWord; private readonly AbstractSaveToPdfExecutor _saveToPdf; - public ExecutorReportLogic(ITechnicalWorkStorage technicalWorkStorage, IRepairStorage repairStorage, IWorkStorage workStorage, ICarStorage carStorage, + public ExecutorReportLogic(ITechnicalWorkStorage technicalWorkStorage, IRepairStorage repairStorage, IWorkStorage workStorage, ICarStorage carStorage, IDefectStorage defectStorage, AbstractSaveToExcelExecutor saveToExcel, AbstractSaveToWordExecutor saveToWord, AbstractSaveToPdfExecutor saveToPdf) { _techWorkStorage = technicalWorkStorage; _repairStorage = repairStorage; _workStorage = workStorage; _carStorage = carStorage; + _defectStorage = defectStorage; _saveToExcel = saveToExcel; _saveToWord = saveToWord; _saveToPdf = saveToPdf; @@ -42,7 +44,7 @@ namespace ServiceStationBusinessLogic.BusinessLogics List allList = new List(); - double price = 0; + var works = _workStorage.GetFullList(); List cars = new List(); @@ -60,6 +62,7 @@ namespace ServiceStationBusinessLogic.BusinessLogics foreach(var car in cars) { + double price = 0; var rec = new ReportWorksViewModel { CarNumber = car.CarNumber, @@ -96,6 +99,9 @@ namespace ServiceStationBusinessLogic.BusinessLogics ExecutorId = model.ExecutorId, }); + List defectList = _defectStorage.GetFullList(); + + foreach(var techWork in techWorkList) { foreach(var car in techWork.TechnicalWorkCars.Values) @@ -108,25 +114,31 @@ namespace ServiceStationBusinessLogic.BusinessLogics TechnicalWorkDate = techWork.DateStartWork, TechnicalWorkPrice = techWork.WorkPrice, }); + List defects = new(); + foreach (var defect in defectList) + { + if (defect.DefectCars.ContainsKey(car.Id)) + { + defects.Add(defect); + } + } + + foreach(var defect in defects) + { + //if (defect.RepairId.HasValue) + //{ + var repair = _repairStorage.GetElement(new RepairSearchModel { Id = 1 }); + allList.Add(new ReportCarsViewModel + { + RepairName = repair.RepairName, + RepairStartDate = repair.RepairStartDate, + RepairPrice = repair.RepairPrice, + }); + //} + } } } - List repairList = _repairStorage.GetFilteredList(new RepairSearchModel - { - DateFrom = model.DateFrom, - DateTo = model.DateTo, - }); - - foreach(var repair in repairList) - { - allList.Add(new ReportCarsViewModel - { - RepairName = repair.RepairName, - RepairStartDate = repair.RepairStartDate, - RepairPrice = repair.RepairPrice, - }); - } - return allList; } diff --git a/ServiceStation/ServiceStationBusinessLogic/OfficePackage/AbstractSaveToPdfExecutor.cs b/ServiceStation/ServiceStationBusinessLogic/OfficePackage/AbstractSaveToPdfExecutor.cs index 59e3a24..1062795 100644 --- a/ServiceStation/ServiceStationBusinessLogic/OfficePackage/AbstractSaveToPdfExecutor.cs +++ b/ServiceStation/ServiceStationBusinessLogic/OfficePackage/AbstractSaveToPdfExecutor.cs @@ -16,11 +16,11 @@ namespace ServiceStationBusinessLogic.OfficePackage CreateParagraph(new PdfParagraph { Text = info.Title, Style = "NormalTitle", ParagraphAligment = PdfParagraphAlignmentType.Center }); CreateParagraph(new PdfParagraph { Text = $"с {info.DateFrom.ToShortDateString()} по {info.DateTo.ToShortDateString()}", Style = "Normal", ParagraphAligment = PdfParagraphAlignmentType.Center }); - CreateTable(new List { "3cm", "2cm", "2cm", "3cm", "2cm", "3cm", "3cm", "2cm" }); + CreateTable(new List { "3cm", "2cm", "2cm", "3cm", "2cm", "3cm", "2cm" }); CreateRow( new PdfRowParameters { - Texts = new List { "Номер машины", "Марка машины", "Тип ТО", "Дата ТО", "Цена ТО", "Название ремонта", "Дата ремонта", "Цена ремонта" }, + Texts = new List { "Номер машины", "Марка машины", "Тип ТО", "Дата ТО", "Цена ТО", "Название ремонта", "Цена ремонта" }, Style = "NormalTitle", ParagraphAligment = PdfParagraphAlignmentType.Left }); @@ -34,8 +34,8 @@ namespace ServiceStationBusinessLogic.OfficePackage } CreateRow(new PdfRowParameters { - Texts = new List { car.CarNumber, car.CarBrand, car.WorkType, car.TechnicalWorkDate.Value.ToShortDateString(), car.TechnicalWorkPrice.ToString(), - isRepair is true ? car.RepairName : "", isRepair is true ? car.RepairStartDate.Value.ToShortDateString() : "", isRepair is true ? car.RepairPrice.ToString() : "" }, + Texts = new List { car.CarNumber, car.CarBrand, car.WorkType, isRepair is true ? "" : car.TechnicalWorkDate.Value.ToShortDateString(), isRepair is true ? "" : car.TechnicalWorkPrice.ToString(), + isRepair is true ? car.RepairName : "", isRepair is true ? car.RepairPrice.ToString() : "" }, Style = "Normal", ParagraphAligment = PdfParagraphAlignmentType.Center }); diff --git a/ServiceStation/ServiceStationDatabaseImplement/Implements/RepairStorage.cs b/ServiceStation/ServiceStationDatabaseImplement/Implements/RepairStorage.cs index f7af6a7..fb645b7 100644 --- a/ServiceStation/ServiceStationDatabaseImplement/Implements/RepairStorage.cs +++ b/ServiceStation/ServiceStationDatabaseImplement/Implements/RepairStorage.cs @@ -32,7 +32,7 @@ namespace ServiceStationDatabaseImplement.Implements if (string.IsNullOrEmpty(model.RepairName) && !model.GuarantorId.HasValue && !model.DateFrom.HasValue && !model.DateTo.HasValue) return new(); using var context = new ServiceStationDatabase(); - if(model.DateTo.HasValue && model.DateTo.HasValue && model.GuarantorId.HasValue) + if(model.DateTo.HasValue && model.DateTo.HasValue) { return context.Repairs .Include(x => x.SpareParts) diff --git a/ServiceStation/ServiceStationDatabaseImplement/Implements/TechnicalWorkStorage.cs b/ServiceStation/ServiceStationDatabaseImplement/Implements/TechnicalWorkStorage.cs index 397ecf0..5dca170 100644 --- a/ServiceStation/ServiceStationDatabaseImplement/Implements/TechnicalWorkStorage.cs +++ b/ServiceStation/ServiceStationDatabaseImplement/Implements/TechnicalWorkStorage.cs @@ -36,7 +36,7 @@ namespace ServiceStationDatabaseImplement.Implements } using var context = new ServiceStationDatabase(); - if(model.DateTo.HasValue && model.DateTo.HasValue && model.ExecutorId.HasValue) + if(model.DateTo.HasValue && model.DateTo.HasValue) { return context.TechnicalWorks .Include(x => x.Cars) diff --git a/ServiceStation/ServiceStationExecutorApp/Controllers/HomeController.cs b/ServiceStation/ServiceStationExecutorApp/Controllers/HomeController.cs index 49ae955..5e498fd 100644 --- a/ServiceStation/ServiceStationExecutorApp/Controllers/HomeController.cs +++ b/ServiceStation/ServiceStationExecutorApp/Controllers/HomeController.cs @@ -1,5 +1,6 @@ using Microsoft.AspNetCore.Mvc; using ServiceStationContracts.BindingModels; +using ServiceStationContracts.BusinessLogicsContracts; using ServiceStationContracts.SearchModels; using ServiceStationContracts.ViewModels; using ServiceStationExecutorApp.Models; @@ -11,10 +12,12 @@ namespace ServiceStationExecutorApp.Controllers public class HomeController : Controller { private readonly ILogger _logger; + private readonly IExecutorReportLogic _report; - public HomeController(ILogger logger) + public HomeController(ILogger logger, IExecutorReportLogic executorReportLogic) { _logger = logger; + _report = executorReportLogic; } public IActionResult Index() @@ -436,24 +439,21 @@ namespace ServiceStationExecutorApp.Controllers { return RedirectToAction("Enter"); } - var technicalWork = new TechnicalWorkViewModel + return View(Tuple.Create(APIExecutor.GetRequest>($"api/main/gettechnicalworklist?executorId={APIExecutor.Executor.Id}"), + APIExecutor.GetRequest>("api/main/getworks"))); + } + [HttpPost] + public void BindingTechnicalWorkToWork(int technicalWork, int work) + { + if (APIExecutor.Executor == null) { - Id = 1, - WorkType = "type1", - WorkPrice = 1000.0, - DateStartWork = DateTime.Now, - ExecutorId = 1 - }; - var work = new WorkViewModel + throw new Exception("Авторизироваться не забыли?"); + } + APIExecutor.PostRequest("api/main/updatework", new WorkBindingModel { - Id = 1, - WorkName = "work1", - WorkPrice = 1000.0, - Status = ServiceStationDataModels.Enums.WorkStatus.Принята - }; - List works = new(); - works.Add(work); - return View(Tuple.Create(APIExecutor.GetRequest>($"api/main/gettechnicalworklist?executorId={APIExecutor.Executor.Id}"), works)); + Id = work, + TechnicalWorkId = technicalWork + }); } [HttpGet] public IActionResult ListWorkToFile() @@ -547,6 +547,65 @@ namespace ServiceStationExecutorApp.Controllers Response.Redirect("GetPdfFile"); } + [HttpGet] + public string GetCarsReport(DateTime dateFrom, DateTime dateTo) + { + if (APIExecutor.Executor == null) + { + throw new Exception("Авторизироваться не забыли?"); + } + List cars; + try + { + cars = _report.GetCars(new ReportExecutorBindingModel + { + ExecutorId = APIExecutor.Executor.Id, + DateFrom = dateFrom, + DateTo = dateTo, + }); + } + catch (Exception ex) + { + _logger.LogError(ex, "Ошибка создания отчета"); + throw; + } + string table = ""; + table += "

Предварительный отчет

"; + table += ""; + table += ""; + table += ""; + table += ""; + table += ""; + table += ""; + table += ""; + table += ""; + table += ""; + table += ""; + table += ""; + table += ""; + foreach(var car in cars) + { + bool isRepair = true; + if (car.RepairPrice == 0) + { + isRepair = false; + } + table += ""; + table += ""; + table += $""; + table += $""; + table += $""; + table += $""; + table += $""; + table += $""; + table += $""; + table += ""; + table += ""; + } + table += "
Номер машиныМарка машиныТип ТОДата ТОЦена ТОНазвание ремонтаЦена ремонта
{car.CarNumber}{car.CarBrand}{car.WorkType}{(isRepair ? string.Empty : car.TechnicalWorkDate)}{(isRepair ? string.Empty : car.TechnicalWorkPrice)}{(isRepair ? car.RepairName : string.Empty)}{(isRepair ? car.RepairPrice : string.Empty)}
"; + return table; + } + [ResponseCache(Duration = 0, Location = ResponseCacheLocation.None, NoStore = true)] public IActionResult Error() { diff --git a/ServiceStation/ServiceStationExecutorApp/Program.cs b/ServiceStation/ServiceStationExecutorApp/Program.cs index d9b457a..4317c84 100644 --- a/ServiceStation/ServiceStationExecutorApp/Program.cs +++ b/ServiceStation/ServiceStationExecutorApp/Program.cs @@ -1,7 +1,23 @@ +using ServiceStationBusinessLogic.BusinessLogics; +using ServiceStationBusinessLogic.OfficePackage; +using ServiceStationBusinessLogic.OfficePackage.Implements; +using ServiceStationContracts.BusinessLogicsContracts; +using ServiceStationContracts.StoragesContracts; +using ServiceStationDatabaseImplement.Implements; using ServiceStationExecutorApp; var builder = WebApplication.CreateBuilder(args); +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.AddTransient(); + // Add services to the container. builder.Services.AddControllersWithViews(); diff --git a/ServiceStation/ServiceStationExecutorApp/ServiceStationExecutorApp.csproj b/ServiceStation/ServiceStationExecutorApp/ServiceStationExecutorApp.csproj index 121900d..430c226 100644 --- a/ServiceStation/ServiceStationExecutorApp/ServiceStationExecutorApp.csproj +++ b/ServiceStation/ServiceStationExecutorApp/ServiceStationExecutorApp.csproj @@ -11,7 +11,9 @@ + + diff --git a/ServiceStation/ServiceStationExecutorApp/Views/Home/ListCarsToPdf.cshtml b/ServiceStation/ServiceStationExecutorApp/Views/Home/ListCarsToPdf.cshtml index f834c7c..0c51013 100644 --- a/ServiceStation/ServiceStationExecutorApp/Views/Home/ListCarsToPdf.cshtml +++ b/ServiceStation/ServiceStationExecutorApp/Views/Home/ListCarsToPdf.cshtml @@ -32,6 +32,29 @@
-
+
- \ No newline at end of file + + +@section Scripts{ + +} \ No newline at end of file diff --git a/ServiceStation/ServiceStationRestApi/Controllers/MainController.cs b/ServiceStation/ServiceStationRestApi/Controllers/MainController.cs index 141454c..b02caf6 100644 --- a/ServiceStation/ServiceStationRestApi/Controllers/MainController.cs +++ b/ServiceStation/ServiceStationRestApi/Controllers/MainController.cs @@ -370,6 +370,20 @@ namespace ServiceStationRestApi.Controllers } } + [HttpGet] + public List? GetWorks() + { + try + { + return _wlogic.ReadList(null); + } + catch (Exception ex) + { + _logger.LogError(ex, "Ошибка получения списка работ"); + throw; + } + } + [HttpGet] public List? GetWorkList(int guarantorId) { diff --git a/ServiceStation/ServiceStationRestApi/Program.cs b/ServiceStation/ServiceStationRestApi/Program.cs index 8436d5f..b1a332c 100644 --- a/ServiceStation/ServiceStationRestApi/Program.cs +++ b/ServiceStation/ServiceStationRestApi/Program.cs @@ -18,6 +18,8 @@ builder.Services.AddTransient(); builder.Services.AddTransient(); builder.Services.AddTransient(); +builder.Services.AddTransient(); +builder.Services.AddTransient(); builder.Services.AddTransient(); builder.Services.AddTransient(); @@ -27,6 +29,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.AddTransient(); builder.Services.AddTransient();