From 0a00c532dbf8adbd2799eab06b773360357172db Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D0=9C=D0=BA=20=D0=98=D0=B3=D0=BE=D1=80=D1=8C?= Date: Fri, 7 Apr 2023 19:57:21 +0400 Subject: [PATCH] =?UTF-8?q?=D0=BF=D0=BE=D0=BB=D1=83=D1=87=D0=B5=D0=BD?= =?UTF-8?q?=D0=B8=D0=B5=20=D0=B4=D0=B0=D0=BD=D0=BD=D1=8B=D1=85=20=D0=B4?= =?UTF-8?q?=D0=BB=D1=8F=20=D0=BE=D1=82=D1=87=D0=B5=D1=82=D0=B0=20=D0=BF?= =?UTF-8?q?=D0=BE=20=D0=B7=D0=B0=D1=8F=D0=B2=D0=BA=D0=B0=D0=BC?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../BusinessLogics/ReportLogic.cs | 35 ++++++++++++++++ .../BindingModels/ReportBindingModel.cs | 19 +++++++++ .../BusinessLogicsContracts/IReportLogic.cs | 35 ++++++++++++++++ .../SearchModels/WorkSearchModel.cs | 4 ++ .../StorageContracts/IWorkStorage.cs | 1 + .../ReportRepairRequestViewModel.cs | 33 +++++++++++++++ .../ReportWorkWithRequestsViewModel.cs | 17 ++++++++ .../Implements/WorkStorage.cs | 40 +++++++++++++++++++ CarService/CarServiceView/Program.cs | 3 ++ 9 files changed, 187 insertions(+) create mode 100644 CarService/CarServiceBusinessLogic/BusinessLogics/ReportLogic.cs create mode 100644 CarService/CarServiceContracts/BindingModels/ReportBindingModel.cs create mode 100644 CarService/CarServiceContracts/BusinessLogicsContracts/IReportLogic.cs create mode 100644 CarService/CarServiceContracts/ViewModels/ReportRepairRequestViewModel.cs create mode 100644 CarService/CarServiceContracts/ViewModels/ReportWorkWithRequestsViewModel.cs diff --git a/CarService/CarServiceBusinessLogic/BusinessLogics/ReportLogic.cs b/CarService/CarServiceBusinessLogic/BusinessLogics/ReportLogic.cs new file mode 100644 index 0000000..972e9c1 --- /dev/null +++ b/CarService/CarServiceBusinessLogic/BusinessLogics/ReportLogic.cs @@ -0,0 +1,35 @@ +using CarServiceContracts.BindingModels; +using CarServiceContracts.BusinessLogicsContracts; +using CarServiceContracts.StorageContracts; +using CarServiceContracts.ViewModels; +using Microsoft.Extensions.Logging; + +namespace CarServiceBusinessLogic.BusinessLogics +{ + public class ReportLogic : IReportLogic + { + //private readonly ILogger _logger; + private readonly IWorkStorage _workStorage; + public ReportLogic(/*ILogger logger,*/ IWorkStorage workStorage) + { + //_logger = logger; + _workStorage = workStorage; + } + public List GetRequestsByWorks(ReportBindingModel model) + { + return _workStorage.GetWorksWithRequest(new() { SelectedWorksIds = model.SelectedWorks }); + } + public void SaveComponentsToWordFile(ReportBindingModel model) + { + throw new NotImplementedException(); + } + public void SaveManufactureComponentToExcelFile(ReportBindingModel model) + { + throw new NotImplementedException(); + } + public void SaveOrdersToPdfFile(ReportBindingModel model) + { + throw new NotImplementedException(); + } + } +} diff --git a/CarService/CarServiceContracts/BindingModels/ReportBindingModel.cs b/CarService/CarServiceContracts/BindingModels/ReportBindingModel.cs new file mode 100644 index 0000000..e2977cd --- /dev/null +++ b/CarService/CarServiceContracts/BindingModels/ReportBindingModel.cs @@ -0,0 +1,19 @@ +namespace CarServiceContracts.BindingModels +{ + public class ReportBindingModel + { + public string FileName { get; set; } = string.Empty; + /// + /// Выбранные работы для отчета по заявкам + /// + public List? SelectedWorks { get; set; } + /// + /// Начало периода для отчета по оплатам + /// + public DateTime? DateFrom { get; set; } + /// + /// Конец периода для отчета по оплатам + /// + public DateTime? DateTo { get; set; } + } +} diff --git a/CarService/CarServiceContracts/BusinessLogicsContracts/IReportLogic.cs b/CarService/CarServiceContracts/BusinessLogicsContracts/IReportLogic.cs new file mode 100644 index 0000000..859756c --- /dev/null +++ b/CarService/CarServiceContracts/BusinessLogicsContracts/IReportLogic.cs @@ -0,0 +1,35 @@ +using CarServiceContracts.BindingModels; +using CarServiceContracts.ViewModels; + +namespace CarServiceContracts.BusinessLogicsContracts +{ + public interface IReportLogic + { + /// + /// Получение списка заявок по выбранным работам + /// + /// + List GetRequestsByWorks(ReportBindingModel model); + /// + /// Получение списка оплат за определенный период + /// + /// + /// + //List GetPayments(ReportBindingModel model); + /// + /// Сохранение компонент в файл-Word + /// + /// + void SaveComponentsToWordFile(ReportBindingModel model); + /// + /// Сохранение компонент с указаеним продуктов в файл-Excel + /// + /// + void SaveManufactureComponentToExcelFile(ReportBindingModel model); + /// + /// Сохранение заказов в файл-Pdf + /// + /// + void SaveOrdersToPdfFile(ReportBindingModel model); + } +} diff --git a/CarService/CarServiceContracts/SearchModels/WorkSearchModel.cs b/CarService/CarServiceContracts/SearchModels/WorkSearchModel.cs index b88f0bd..6f69953 100644 --- a/CarService/CarServiceContracts/SearchModels/WorkSearchModel.cs +++ b/CarService/CarServiceContracts/SearchModels/WorkSearchModel.cs @@ -4,5 +4,9 @@ { public int? Id { get; set; } public string? Name { get; set; } + /// + /// Id выбранных работ + /// + public List? SelectedWorksIds { get; set; } } } diff --git a/CarService/CarServiceContracts/StorageContracts/IWorkStorage.cs b/CarService/CarServiceContracts/StorageContracts/IWorkStorage.cs index 8f19270..904a446 100644 --- a/CarService/CarServiceContracts/StorageContracts/IWorkStorage.cs +++ b/CarService/CarServiceContracts/StorageContracts/IWorkStorage.cs @@ -9,6 +9,7 @@ namespace CarServiceContracts.StorageContracts List GetFullList(); List GetFilteredList(WorkSearchModel model); WorkViewModel? GetElement(WorkSearchModel model); + List GetWorksWithRequest(WorkSearchModel model); WorkViewModel? Insert(WorkBindingModel model); WorkViewModel? Update(WorkBindingModel model); WorkViewModel? Delete(WorkBindingModel model); diff --git a/CarService/CarServiceContracts/ViewModels/ReportRepairRequestViewModel.cs b/CarService/CarServiceContracts/ViewModels/ReportRepairRequestViewModel.cs new file mode 100644 index 0000000..6447ddd --- /dev/null +++ b/CarService/CarServiceContracts/ViewModels/ReportRepairRequestViewModel.cs @@ -0,0 +1,33 @@ +namespace CarServiceContracts.ViewModels +{ + /// + /// Модель для получения одной заявки для отчета + /// + public class ReportRepairRequestViewModel + { + /// + /// Номер заявки + /// + public int RepairRequestId { get; set; } + /// + /// Дата создания заявки + /// + public DateTime RepairRequestDateCreated { get; set; } = DateTime.Now; + /// + /// Имя клиента + /// + public string CustomerName { get; set; } = string.Empty; + /// + /// Название ТС + /// + public string VehicleName { get; set; } = string.Empty; + /// + /// Гос. номер + /// + public string Plate { get; set; } = string.Empty; + /// + /// Количество работ + /// + public int WorksCount { get; set; } + } +} diff --git a/CarService/CarServiceContracts/ViewModels/ReportWorkWithRequestsViewModel.cs b/CarService/CarServiceContracts/ViewModels/ReportWorkWithRequestsViewModel.cs new file mode 100644 index 0000000..2d7f19e --- /dev/null +++ b/CarService/CarServiceContracts/ViewModels/ReportWorkWithRequestsViewModel.cs @@ -0,0 +1,17 @@ +namespace CarServiceContracts.ViewModels +{ + /// + /// Модель для получения всех заявок по работе для отчета + /// + public class ReportWorkWithRequestsViewModel + { + /// + /// Название работы + /// + public string WorkName { get; set; } = string.Empty; + /// + /// Заявки в работе + /// + public List RepairRequests { get; set; } = new(); + } +} diff --git a/CarService/CarServiceDatabase/Implements/WorkStorage.cs b/CarService/CarServiceDatabase/Implements/WorkStorage.cs index 7dee7aa..4dda831 100644 --- a/CarService/CarServiceDatabase/Implements/WorkStorage.cs +++ b/CarService/CarServiceDatabase/Implements/WorkStorage.cs @@ -47,6 +47,46 @@ namespace CarServiceDatabase.Implements } return null; } + public List GetWorksWithRequest(WorkSearchModel model) + { + if (model.SelectedWorksIds == null) + { + return new(); + } + using var context = new CarServiceDbContext(); + return context.Works + .Where(w => model.SelectedWorksIds.Contains(w.Id)) + .Select(w => new ReportWorkWithRequestsViewModel() + { + WorkName = w.Name, + RepairRequests = GetRepairRequestsByWork(model) + }) + .ToList(); + } + /// + /// Получение списка заявок по выбранной работе + /// + /// + /// + private List GetRepairRequestsByWork(WorkSearchModel model) + { + using var context = new CarServiceDbContext(); + return context.WorksInRequest + .Include(wir => wir.RepairRequest) + .ThenInclude(rr => rr.Vehicle) + .ThenInclude(v => v.Customer) + .Where(wir => wir.WorkId == model.Id) + .Select(wir => new ReportRepairRequestViewModel() + { + RepairRequestId = wir.RepairRequest.Id, + RepairRequestDateCreated = wir.RepairRequest.DateCreated, + CustomerName = wir.RepairRequest.Vehicle.Customer.Name, + VehicleName = wir.RepairRequest.Vehicle.Name, + Plate = wir.RepairRequest.Vehicle.Plate ?? "[отсутствует]", + WorksCount = wir.Count + }) + .ToList(); + } public WorkViewModel? Insert(WorkBindingModel model) { using var context = new CarServiceDbContext(); diff --git a/CarService/CarServiceView/Program.cs b/CarService/CarServiceView/Program.cs index d56fe77..e01cd04 100644 --- a/CarService/CarServiceView/Program.cs +++ b/CarService/CarServiceView/Program.cs @@ -19,6 +19,8 @@ namespace CarServiceView var services = new ServiceCollection(); ConfigureServices(services); _serviceProvider = services.BuildServiceProvider(); + var _reportLogic = _serviceProvider.GetRequiredService(); + var list = _reportLogic.GetRequestsByWorks(new() { SelectedWorks = new() { 1 } }); Application.Run(_serviceProvider.GetRequiredService()); } private static void ConfigureServices(ServiceCollection services) @@ -37,6 +39,7 @@ namespace CarServiceView services.AddTransient(); services.AddTransient(); services.AddTransient(); + services.AddTransient(); services.AddTransient(); services.AddTransient();