From b7ce104e4e50aefa5f6d902e4c837c1d79a1a83a Mon Sep 17 00:00:00 2001 From: Olga Nemt Date: Fri, 20 Oct 2023 11:24:04 +0500 Subject: [PATCH 01/10] =?UTF-8?q?-=20=D0=AD=D0=BA=D1=81=D0=BF=D0=BE=D1=80?= =?UTF-8?q?=D1=82=20=D0=BE=D1=82=D1=87=D0=B5=D1=82=D0=B0=20Drill=20test=20?= =?UTF-8?q?-=20=D0=94=D0=BE=D0=B1=D0=B0=D0=B2=D0=BB=D0=B5=D0=BD=20=D0=BD?= =?UTF-8?q?=D0=BE=D0=B2=D1=8B=D0=B9=20extension=20=D0=BC=D0=B5=D1=82=D0=BE?= =?UTF-8?q?=D0=B4=20AssemblyExtensions.GetTemplateCopyStreamAsync=20-=20IA?= =?UTF-8?q?utoGeneratedDailyReportMakerService=20=D0=BF=D0=B5=D1=80=D0=B5?= =?UTF-8?q?=D0=B8=D0=BC=D0=B5=D0=BD=D0=BE=D0=B2=D0=B0=D0=BD=20=D0=B2=20IRe?= =?UTF-8?q?portMakerService=20=D0=B8=20=D1=81=D1=82=D0=B0=D0=BB=20=D0=B1?= =?UTF-8?q?=D0=BE=D0=BB=D0=B5=D0=B5=20=D1=83=D0=BD=D0=B8=D0=B2=D0=B5=D1=80?= =?UTF-8?q?=D1=81=D0=B0=D0=BB=D1=8C=D0=BD=D1=8B=D0=BC?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../AutoGeneratedDailyReportInfoDto.cs | 21 +- .../DrillTestReport/DrillTestReportDataDto.cs | 26 ++ .../DrillTestReport/DrillTestReportInfoDto.cs | 25 + AsbCloudApp/Data/ReportInfoDto.cs | 18 + .../Repositories/IDrillTestRepository.cs | 19 + .../AutoGeneratedDailyReportRequest.cs | 22 +- .../IAutoGeneratedDailyReportMakerService.cs | 19 +- .../IAutoGeneratedDailyReportService.cs | 2 +- .../Services/IDrillTestReportService.cs | 35 ++ .../AsbCloudInfrastructure.csproj | 2 + AsbCloudInfrastructure/AssemblyExtensions.cs | 30 ++ AsbCloudInfrastructure/DependencyInjection.cs | 442 +++++++++--------- .../Repository/DrillTestRepository.cs | 43 ++ .../AutoGeneratedDailyReportMakerService.cs | 28 +- .../AutoGeneratedDailyReportService.cs | 18 +- .../DrillTestReportMakerService.cs | 89 ++++ .../DrillTestReport/DrillTestReportService.cs | 103 ++++ .../DrillTestReportTemplate.xlsx | Bin 0 -> 7284 bytes AsbCloudInfrastructure/XLExtentions.cs | 12 +- .../AutoGeneratedDailyReportController.cs | 5 +- .../Controllers/DrillTestsReportController.cs | 84 ++++ 21 files changed, 751 insertions(+), 292 deletions(-) create mode 100644 AsbCloudApp/Data/DrillTestReport/DrillTestReportDataDto.cs create mode 100644 AsbCloudApp/Data/DrillTestReport/DrillTestReportInfoDto.cs create mode 100644 AsbCloudApp/Data/ReportInfoDto.cs create mode 100644 AsbCloudApp/Services/IDrillTestReportService.cs create mode 100644 AsbCloudInfrastructure/AssemblyExtensions.cs create mode 100644 AsbCloudInfrastructure/Services/DrillTestReport/DrillTestReportMakerService.cs create mode 100644 AsbCloudInfrastructure/Services/DrillTestReport/DrillTestReportService.cs create mode 100644 AsbCloudInfrastructure/Services/DrillTestReport/DrillTestReportTemplate.xlsx create mode 100644 AsbCloudWebApi/Controllers/DrillTestsReportController.cs diff --git a/AsbCloudApp/Data/AutogeneratedDailyReport/AutoGeneratedDailyReportInfoDto.cs b/AsbCloudApp/Data/AutogeneratedDailyReport/AutoGeneratedDailyReportInfoDto.cs index 0034879a..22e34cf2 100644 --- a/AsbCloudApp/Data/AutogeneratedDailyReport/AutoGeneratedDailyReportInfoDto.cs +++ b/AsbCloudApp/Data/AutogeneratedDailyReport/AutoGeneratedDailyReportInfoDto.cs @@ -5,21 +5,10 @@ namespace AsbCloudApp.Data.AutogeneratedDailyReport; /// /// Базовая информация о суточном отчёте /// -public class AutoGeneratedDailyReportInfoDto +public class AutoGeneratedDailyReportInfoDto : ReportInfoDto { - /// - /// Дата формирования отчёта - /// - public DateOnly ReportDate { get; set; } - - /// - /// Название файла - /// - public string FileName { get; set; } = null!; - - /// - /// Размер файла - /// - public int FileSize { get; set; } - + /// + /// Дата формирования отчёта + /// + public DateOnly ReportDate { get; set; } } \ No newline at end of file diff --git a/AsbCloudApp/Data/DrillTestReport/DrillTestReportDataDto.cs b/AsbCloudApp/Data/DrillTestReport/DrillTestReportDataDto.cs new file mode 100644 index 00000000..ee63bf9b --- /dev/null +++ b/AsbCloudApp/Data/DrillTestReport/DrillTestReportDataDto.cs @@ -0,0 +1,26 @@ +using AsbCloudApp.Data.SAUB; +using System; + +namespace AsbCloudApp.Data.DrillTestReport +{ + /// + /// Информация о drill test, выгружаемая в отчете + /// + public class DrillTestReportDataDto + { + /// + /// Данные для отчета + /// + public DrillTestDto Data { get; set; } = null!; + + /// + /// Заголовок отчета + /// + public string Caption { get; set; } = null!; + + /// + /// Дата отчета + /// + public DateTime Date { get; set; } = DateTime.Now; + } +} diff --git a/AsbCloudApp/Data/DrillTestReport/DrillTestReportInfoDto.cs b/AsbCloudApp/Data/DrillTestReport/DrillTestReportInfoDto.cs new file mode 100644 index 00000000..8d3a9244 --- /dev/null +++ b/AsbCloudApp/Data/DrillTestReport/DrillTestReportInfoDto.cs @@ -0,0 +1,25 @@ +using System; + +namespace AsbCloudApp.Data.DrillTestReport +{ + /// + /// Базовая информация о drill_test отчёте + /// + public class DrillTestReportInfoDto : ReportInfoDto + { + /// + /// Идентификатор отчета + /// + public int Id { get; set; } + + /// + /// Проходка + /// + public float DrillDepth { get; set; } + + /// + /// Дата и время + /// + public DateTime DateTime { get; set; } + } +} diff --git a/AsbCloudApp/Data/ReportInfoDto.cs b/AsbCloudApp/Data/ReportInfoDto.cs new file mode 100644 index 00000000..bd55d33c --- /dev/null +++ b/AsbCloudApp/Data/ReportInfoDto.cs @@ -0,0 +1,18 @@ +namespace AsbCloudApp.Data +{ + /// + /// Справочная информация об отчете + /// + public class ReportInfoDto + { + /// + /// Название файла + /// + public string FileName { get; set; } = null!; + + /// + /// Размер файла + /// + public int FileSize { get; set; } = 0; + } +} diff --git a/AsbCloudApp/Repositories/IDrillTestRepository.cs b/AsbCloudApp/Repositories/IDrillTestRepository.cs index 45552871..18ff0e9b 100644 --- a/AsbCloudApp/Repositories/IDrillTestRepository.cs +++ b/AsbCloudApp/Repositories/IDrillTestRepository.cs @@ -1,4 +1,5 @@ using AsbCloudApp.Data.SAUB; +using AsbCloudApp.Requests; using System.Threading; using System.Threading.Tasks; @@ -9,6 +10,24 @@ namespace AsbCloudApp.Repositories /// public interface IDrillTestRepository { + /// + /// Получить данные drill_test в соответствии с параметрами запроса + /// + /// ключ телеметрии + /// запрос + /// + /// + Task GetAllAsync(int idTelemetry, FileReportRequest request, CancellationToken cancellationToken); + + /// + /// Получить запись drill_test + /// + /// ключ телеметрии + /// ключ записи drill_test + /// + /// + Task GetAsync(int idTelemetry, int id, CancellationToken cancellationToken); + /// /// Сохранить данные drill_test /// diff --git a/AsbCloudApp/Requests/AutoGeneratedDailyReportRequest.cs b/AsbCloudApp/Requests/AutoGeneratedDailyReportRequest.cs index 5e7dae7c..a9984016 100644 --- a/AsbCloudApp/Requests/AutoGeneratedDailyReportRequest.cs +++ b/AsbCloudApp/Requests/AutoGeneratedDailyReportRequest.cs @@ -3,17 +3,17 @@ using System; namespace AsbCloudApp.Requests; /// -/// Параметры запроса для получения авто-генерируемых суточных отчётов +/// Параметры запроса для получения отчетов (файлов) /// -public class AutoGeneratedDailyReportRequest : RequestBase +public class FileReportRequest : RequestBase { - /// - /// Дата начала периода - /// - public DateOnly? StartDate { get; set; } - - /// - /// Дата конца периода - /// - public DateOnly? FinishDate { get; set; } + /// + /// Дата начала периода + /// + public DateOnly? GeDate { get; set; } + + /// + /// Дата конца периода + /// + public DateOnly? LeDate { get; set; } } \ No newline at end of file diff --git a/AsbCloudApp/Services/AutoGeneratedDailyReports/IAutoGeneratedDailyReportMakerService.cs b/AsbCloudApp/Services/AutoGeneratedDailyReports/IAutoGeneratedDailyReportMakerService.cs index 8571e356..8c2e9a46 100644 --- a/AsbCloudApp/Services/AutoGeneratedDailyReports/IAutoGeneratedDailyReportMakerService.cs +++ b/AsbCloudApp/Services/AutoGeneratedDailyReports/IAutoGeneratedDailyReportMakerService.cs @@ -1,20 +1,19 @@ using System.IO; using System.Threading; using System.Threading.Tasks; -using AsbCloudApp.Data.AutogeneratedDailyReport; namespace AsbCloudApp.Services.AutoGeneratedDailyReports; /// -/// Сервис для генерации файлов авто-генерируемых суточный отчётов +/// Сервис для генерации файлов отчётов /// -public interface IAutoGeneratedDailyReportMakerService +public interface IReportMakerService { - /// - /// Генерация файла - /// - /// - /// - /// - Task MakeReportAsync(AutoGeneratedDailyReportDto report, CancellationToken cancellationToken); + /// + /// Генерация файла + /// + /// модель с данными для построения отчета + /// + /// + Task MakeReportAsync(T report, CancellationToken cancellationToken); } \ No newline at end of file diff --git a/AsbCloudApp/Services/AutoGeneratedDailyReports/IAutoGeneratedDailyReportService.cs b/AsbCloudApp/Services/AutoGeneratedDailyReports/IAutoGeneratedDailyReportService.cs index 13bdb1ea..979f948c 100644 --- a/AsbCloudApp/Services/AutoGeneratedDailyReports/IAutoGeneratedDailyReportService.cs +++ b/AsbCloudApp/Services/AutoGeneratedDailyReports/IAutoGeneratedDailyReportService.cs @@ -21,7 +21,7 @@ public interface IAutoGeneratedDailyReportService /// /// Task> GetListAsync(int idWell, - AutoGeneratedDailyReportRequest request, + FileReportRequest request, CancellationToken cancellationToken); /// diff --git a/AsbCloudApp/Services/IDrillTestReportService.cs b/AsbCloudApp/Services/IDrillTestReportService.cs new file mode 100644 index 00000000..6dd97b83 --- /dev/null +++ b/AsbCloudApp/Services/IDrillTestReportService.cs @@ -0,0 +1,35 @@ +using AsbCloudApp.Data; +using AsbCloudApp.Data.DrillTestReport; +using AsbCloudApp.Requests; +using System.IO; +using System.Threading; +using System.Threading.Tasks; + +namespace AsbCloudApp.Services +{ + /// + /// сервис по работе с отчетами drill test + /// + public interface IDrillTestReportService + { + /// + /// Список файлов drill test + /// + /// ключ скважины + /// параметры запроса + /// + /// + Task> GetListAsync(int idWell, + FileReportRequest request, + CancellationToken cancellationToken); + + /// + /// Генерация файла с отчётом + /// + /// ключ скважины + /// ключ drill test записи + /// + /// + Task<(string fileName, Stream stream)> GenerateAsync(int idWell, int id, CancellationToken cancellationToken); + } +} diff --git a/AsbCloudInfrastructure/AsbCloudInfrastructure.csproj b/AsbCloudInfrastructure/AsbCloudInfrastructure.csproj index bc825b4b..2c2bd528 100644 --- a/AsbCloudInfrastructure/AsbCloudInfrastructure.csproj +++ b/AsbCloudInfrastructure/AsbCloudInfrastructure.csproj @@ -13,6 +13,7 @@ + @@ -30,6 +31,7 @@ + diff --git a/AsbCloudInfrastructure/AssemblyExtensions.cs b/AsbCloudInfrastructure/AssemblyExtensions.cs new file mode 100644 index 00000000..9594261b --- /dev/null +++ b/AsbCloudInfrastructure/AssemblyExtensions.cs @@ -0,0 +1,30 @@ +using System; +using System.Collections.Generic; +using System.IO; +using System.Linq; +using System.Reflection; +using System.Text; +using System.Threading; +using System.Threading.Tasks; + +namespace AsbCloudInfrastructure +{ + public static class AssemblyExtensions + { + public static async Task GetTemplateCopyStreamAsync(this Assembly assembly, string templateName, CancellationToken cancellationToken) + { + var resourceName = assembly + .GetManifestResourceNames() + .FirstOrDefault(n => n.EndsWith(templateName))!; + + using var stream = Assembly.GetExecutingAssembly() + .GetManifestResourceStream(resourceName)!; + + var memoryStream = new MemoryStream(); + await stream.CopyToAsync(memoryStream, cancellationToken); + memoryStream.Position = 0; + + return memoryStream; + } + } +} diff --git a/AsbCloudInfrastructure/DependencyInjection.cs b/AsbCloudInfrastructure/DependencyInjection.cs index 85caf0b2..0ce35409 100644 --- a/AsbCloudInfrastructure/DependencyInjection.cs +++ b/AsbCloudInfrastructure/DependencyInjection.cs @@ -1,5 +1,6 @@ -using System; -using AsbCloudApp.Data; +using AsbCloudApp.Data; +using AsbCloudApp.Data.AutogeneratedDailyReport; +using AsbCloudApp.Data.DrillTestReport; using AsbCloudApp.Data.Manuals; using AsbCloudApp.Data.ProcessMaps; using AsbCloudApp.Data.SAUB; @@ -24,6 +25,7 @@ using AsbCloudInfrastructure.Services.AutoGeneratedDailyReports; using AsbCloudInfrastructure.Services.DailyReport; using AsbCloudInfrastructure.Services.DetectOperations; using AsbCloudInfrastructure.Services.DrillingProgram; +using AsbCloudInfrastructure.Services.DrillTestReport; using AsbCloudInfrastructure.Services.ProcessMaps.Report; using AsbCloudInfrastructure.Services.ProcessMaps.WellDrilling; using AsbCloudInfrastructure.Services.SAUB; @@ -37,273 +39,275 @@ using Microsoft.EntityFrameworkCore; using Microsoft.Extensions.Caching.Memory; using Microsoft.Extensions.Configuration; using Microsoft.Extensions.DependencyInjection; +using System; namespace AsbCloudInfrastructure { public static class DependencyInjection { - public static IAsbCloudDbContext MakeContext(string connectionString) - { - var options = new DbContextOptionsBuilder() - .UseNpgsql(connectionString) - .Options; - var context = new AsbCloudDbContext(options); - return context; - } + public static IAsbCloudDbContext MakeContext(string connectionString) + { + var options = new DbContextOptionsBuilder() + .UseNpgsql(connectionString) + .Options; + var context = new AsbCloudDbContext(options); + return context; + } - public static void MapsterSetup() - { - TypeAdapterConfig.GlobalSettings.Default.Config - .ForType() - .MapWith((source) => source.DateTime); + public static void MapsterSetup() + { + TypeAdapterConfig.GlobalSettings.Default.Config + .ForType() + .MapWith((source) => source.DateTime); - TypeAdapterConfig.GlobalSettings.Default.Config - .ForType() - .MapWith((source) => source == default ? new DateTime(0, DateTimeKind.Utc) : source); + TypeAdapterConfig.GlobalSettings.Default.Config + .ForType() + .MapWith((source) => source == default ? new DateTime(0, DateTimeKind.Utc) : source); - TypeAdapterConfig.GlobalSettings.Default.Config - .ForType() - .MapWith((source) => source.MakeTimeOnly()); + TypeAdapterConfig.GlobalSettings.Default.Config + .ForType() + .MapWith((source) => source.MakeTimeOnly()); - TypeAdapterConfig.GlobalSettings.Default.Config - .ForType() - .MapWith((source) => new(source)); + TypeAdapterConfig.GlobalSettings.Default.Config + .ForType() + .MapWith((source) => new(source)); - TypeAdapterConfig.GlobalSettings.Default.Config - .ForType() - .MapWith((source) => new(source)); + TypeAdapterConfig.GlobalSettings.Default.Config + .ForType() + .MapWith((source) => new(source)); #pragma warning disable CS8603 // Possible null reference return. - TypeAdapterConfig.GlobalSettings.Default.Config - .ForType() - .Ignore(dst => dst.Cluster, - dst => dst.RelationCompaniesWells, - dst => dst.Telemetry, - dst => dst.WellComposites, - dst => dst.WellCompositeSrcs, - dst => dst.WellOperations, - dst => dst.WellType); + TypeAdapterConfig.GlobalSettings.Default.Config + .ForType() + .Ignore(dst => dst.Cluster, + dst => dst.RelationCompaniesWells, + dst => dst.Telemetry, + dst => dst.WellComposites, + dst => dst.WellCompositeSrcs, + dst => dst.WellOperations, + dst => dst.WellType); #pragma warning restore CS8603 // Possible null reference return. - TypeAdapterConfig.GlobalSettings.Default.Config - .ForType() - .Ignore(dst => dst.Deposit, - dst => dst.Wells); + TypeAdapterConfig.GlobalSettings.Default.Config + .ForType() + .Ignore(dst => dst.Deposit, + dst => dst.Wells); - TypeAdapterConfig.GlobalSettings.Default.Config - .ForType(); + TypeAdapterConfig.GlobalSettings.Default.Config + .ForType(); - TypeAdapterConfig.GlobalSettings.Default.Config - .ForType(); + TypeAdapterConfig.GlobalSettings.Default.Config + .ForType(); - TypeAdapterConfig.GlobalSettings.Default.Config - .ForType() - .Ignore(dst => dst.NotificationCategory, - dst => dst.User); + TypeAdapterConfig.GlobalSettings.Default.Config + .ForType() + .Ignore(dst => dst.NotificationCategory, + dst => dst.User); - TypeAdapterConfig.GlobalSettings.Default.Config - .ForType() - .Map(dest => dest.AxialLoad, src => new PlanLimitDto - { - LimitMax = src.AxialLoadLimitMax, - Plan = src.AxialLoadPlan - }) - .Map(dest => dest.Flow, src => new PlanLimitDto - { - LimitMax = src.FlowLimitMax, - Plan = src.FlowPlan - }) - .Map(dest => dest.Pressure, src => new PlanLimitDto - { - LimitMax = src.PressureLimitMax, - Plan = src.PressurePlan - }) - .Map(dest => dest.TopDriveSpeed, src => new PlanLimitDto - { - LimitMax = src.TopDriveSpeedLimitMax, - Plan = src.TopDriveSpeedPlan - }) - .Map(dest => dest.TopDriveTorque, src => new PlanLimitDto - { - LimitMax = src.TopDriveTorqueLimitMax, - Plan = src.TopDriveTorquePlan - }); + TypeAdapterConfig.GlobalSettings.Default.Config + .ForType() + .Map(dest => dest.AxialLoad, src => new PlanLimitDto + { + LimitMax = src.AxialLoadLimitMax, + Plan = src.AxialLoadPlan + }) + .Map(dest => dest.Flow, src => new PlanLimitDto + { + LimitMax = src.FlowLimitMax, + Plan = src.FlowPlan + }) + .Map(dest => dest.Pressure, src => new PlanLimitDto + { + LimitMax = src.PressureLimitMax, + Plan = src.PressurePlan + }) + .Map(dest => dest.TopDriveSpeed, src => new PlanLimitDto + { + LimitMax = src.TopDriveSpeedLimitMax, + Plan = src.TopDriveSpeedPlan + }) + .Map(dest => dest.TopDriveTorque, src => new PlanLimitDto + { + LimitMax = src.TopDriveTorqueLimitMax, + Plan = src.TopDriveTorquePlan + }); - TypeAdapterConfig.GlobalSettings.Default.Config - .ForType() - .Map(dest => dest.AxialLoadPlan, src => src.AxialLoad.Plan) - .Map(dest => dest.AxialLoadLimitMax, src => src.AxialLoad.LimitMax) - .Map(dest => dest.FlowPlan, src => src.Flow.Plan) - .Map(dest => dest.FlowLimitMax, src => src.Flow.LimitMax) - .Map(dest => dest.PressurePlan, src => src.Pressure.Plan) - .Map(dest => dest.PressureLimitMax, src => src.Pressure.LimitMax) - .Map(dest => dest.TopDriveSpeedPlan, src => src.TopDriveSpeed.Plan) - .Map(dest => dest.TopDriveSpeedLimitMax, src => src.TopDriveSpeed.LimitMax) - .Map(dest => dest.TopDriveTorquePlan, src => src.TopDriveTorque.Plan) - .Map(dest => dest.TopDriveTorqueLimitMax, src => src.TopDriveTorque.LimitMax); - } + TypeAdapterConfig.GlobalSettings.Default.Config + .ForType() + .Map(dest => dest.AxialLoadPlan, src => src.AxialLoad.Plan) + .Map(dest => dest.AxialLoadLimitMax, src => src.AxialLoad.LimitMax) + .Map(dest => dest.FlowPlan, src => src.Flow.Plan) + .Map(dest => dest.FlowLimitMax, src => src.Flow.LimitMax) + .Map(dest => dest.PressurePlan, src => src.Pressure.Plan) + .Map(dest => dest.PressureLimitMax, src => src.Pressure.LimitMax) + .Map(dest => dest.TopDriveSpeedPlan, src => src.TopDriveSpeed.Plan) + .Map(dest => dest.TopDriveSpeedLimitMax, src => src.TopDriveSpeed.LimitMax) + .Map(dest => dest.TopDriveTorquePlan, src => src.TopDriveTorque.Plan) + .Map(dest => dest.TopDriveTorqueLimitMax, src => src.TopDriveTorque.LimitMax); + } - public static IServiceCollection AddInfrastructure(this IServiceCollection services, IConfiguration configuration) - { - MapsterSetup(); - string connectionStringName = "DefaultConnection"; + public static IServiceCollection AddInfrastructure(this IServiceCollection services, IConfiguration configuration) + { + MapsterSetup(); + string connectionStringName = "DefaultConnection"; #if DEBUG - connectionStringName = "DebugConnection"; + connectionStringName = "DebugConnection"; #endif - services.AddDbContext(options => - options.UseNpgsql(configuration.GetConnectionString(connectionStringName))); + services.AddDbContext(options => + options.UseNpgsql(configuration.GetConnectionString(connectionStringName))); - services.AddMemoryCache(); - services.AddScoped(provider => provider.GetRequiredService()); + services.AddMemoryCache(); + services.AddScoped(provider => provider.GetRequiredService()); - services.AddSingleton(new WitsInfoService()); - services.AddSingleton(provider => TelemetryDataCache.GetInstance(provider)); - services.AddSingleton(provider => TelemetryDataCache.GetInstance(provider)); - services.AddSingleton(); - services.AddSingleton(); - services.AddSingleton(); - services.AddSingleton(provider => ReduceSamplingService.GetInstance(configuration)); + services.AddSingleton(new WitsInfoService()); + services.AddSingleton(provider => TelemetryDataCache.GetInstance(provider)); + services.AddSingleton(provider => TelemetryDataCache.GetInstance(provider)); + services.AddSingleton(); + services.AddSingleton(); + services.AddSingleton(); + services.AddSingleton(provider => ReduceSamplingService.GetInstance(configuration)); - services.AddTransient(); - services.AddTransient, ProcessMapPlanRepository>(); - services.AddTransient, ProcessMapPlanRepository>(); - services.AddTransient(); - services.AddTransient(); - services.AddTransient(); - services.AddTransient(); - services.AddTransient(); - services.AddTransient(); - services.AddTransient(); - services.AddTransient(); - services.AddTransient(); - services.AddTransient(); - services.AddTransient(); - services.AddTransient(); - services.AddTransient(); - services.AddTransient(); - services.AddTransient(); - services.AddTransient(); - services.AddTransient(); - services.AddTransient(); - services.AddTransient(); - services.AddTransient(); - services.AddTransient(); - services.AddTransient(); - services.AddTransient, CrudWellRelatedRepositoryBase>(); - services.AddTransient(); - services.AddTransient(); - services.AddTransient(); - services.AddTransient(); - services.AddTransient(); - services.AddTransient(); - services.AddTransient(); - services.AddTransient(); + services.AddTransient(); + services.AddTransient, ProcessMapPlanRepository>(); + services.AddTransient, ProcessMapPlanRepository>(); + services.AddTransient(); + services.AddTransient(); + services.AddTransient(); + services.AddTransient(); + services.AddTransient(); + services.AddTransient(); + services.AddTransient(); + services.AddTransient(); + services.AddTransient(); + services.AddTransient(); + services.AddTransient(); + services.AddTransient(); + services.AddTransient(); + services.AddTransient(); + services.AddTransient(); + services.AddTransient(); + services.AddTransient(); + services.AddTransient(); + services.AddTransient(); + services.AddTransient(); + services.AddTransient(); + services.AddTransient, CrudWellRelatedRepositoryBase>(); + services.AddTransient(); + services.AddTransient(); + services.AddTransient(); + services.AddTransient(); + services.AddTransient(); + services.AddTransient(); + services.AddTransient(); + services.AddTransient(); - services.AddTransient(); + services.AddTransient(); - services.AddTransient(); + services.AddTransient(); services.AddTransient(); services.AddTransient(); - services.AddTransient, CrudCacheRepositoryBase, CrudCacheRepositoryBase>(); services.AddTransient(); - // admin crud services: - services.AddTransient, CrudCacheRepositoryBase>(s => - new CrudCacheRepositoryBase( - s.GetRequiredService(), - s.GetRequiredService(), - dbSet => dbSet.Include(t => t.Well))); // может быть включен в сервис TelemetryService - services.AddTransient, CrudCacheRepositoryBase>(s => - new CrudCacheRepositoryBase( - s.GetRequiredService(), - s.GetRequiredService(), - dbSet => dbSet.Include(d => d.Clusters))); - services.AddTransient, CrudCacheRepositoryBase>(s => - new CrudCacheRepositoryBase( - s.GetRequiredService(), - s.GetRequiredService(), - dbSet => dbSet.Include(c => c.CompanyType))); + // admin crud services: + services.AddTransient, CrudCacheRepositoryBase>(s => + new CrudCacheRepositoryBase( + s.GetRequiredService(), + s.GetRequiredService(), + dbSet => dbSet.Include(t => t.Well))); // может быть включен в сервис TelemetryService + services.AddTransient, CrudCacheRepositoryBase>(s => + new CrudCacheRepositoryBase( + s.GetRequiredService(), + s.GetRequiredService(), + dbSet => dbSet.Include(d => d.Clusters))); + services.AddTransient, CrudCacheRepositoryBase>(s => + new CrudCacheRepositoryBase( + s.GetRequiredService(), + s.GetRequiredService(), + dbSet => dbSet.Include(c => c.CompanyType))); - services.AddTransient, CrudCacheRepositoryBase>(); - services.AddTransient, CrudCacheRepositoryBase>(s => - new CrudCacheRepositoryBase( - s.GetRequiredService(), - s.GetRequiredService(), - dbSet => dbSet - .Include(c => c.Wells) - .Include(c => c.Deposit))); // может быть включен в сервис ClusterService + services.AddTransient, CrudCacheRepositoryBase>(); + services.AddTransient, CrudCacheRepositoryBase>(s => + new CrudCacheRepositoryBase( + s.GetRequiredService(), + s.GetRequiredService(), + dbSet => dbSet + .Include(c => c.Wells) + .Include(c => c.Deposit))); // может быть включен в сервис ClusterService - services.AddTransient, CrudCacheRepositoryBase>(); + services.AddTransient, CrudCacheRepositoryBase>(); - services.AddTransient(); - services.AddTransient(); - services.AddTransient(); - services.AddTransient(); - services.AddTransient(); - services.AddTransient(); - services.AddTransient(); - services.AddTransient(); - services.AddTransient(); - services.AddTransient(); - services.AddTransient(); - services.AddTransient(); - services.AddTransient(); - services.AddTransient(); - services.AddTransient, CrudCacheRepositoryBase>(); + services.AddTransient(); + services.AddTransient(); + services.AddTransient(); + services.AddTransient(); + services.AddTransient(); + services.AddTransient(); + services.AddTransient(); + services.AddTransient(); + services.AddTransient(); + services.AddTransient(); + services.AddTransient(); + services.AddTransient(); + services.AddTransient(); + services.AddTransient(); + services.AddTransient, CrudCacheRepositoryBase>(); - // Subsystem service - services.AddTransient, CrudCacheRepositoryBase>(); - services.AddTransient(); + // Subsystem service + services.AddTransient, CrudCacheRepositoryBase>(); + services.AddTransient(); - services.AddTransient, CrudCacheRepositoryBase>(); + services.AddTransient, CrudCacheRepositoryBase>(); - // TelemetryData services - services.AddTransient(); - services.AddTransient, TelemetryDataSpinService>(); + // TelemetryData services + services.AddTransient(); + services.AddTransient, TelemetryDataSpinService>(); - // Wits - services.AddTransient, WitsRecordRepository>(); - services.AddTransient, WitsRecordRepository>(); - services.AddTransient, WitsRecordRepository>(); - services.AddTransient, WitsRecordRepository>(); - services.AddTransient, WitsRecordRepository>(); - services.AddTransient, WitsRecordRepository>(); + // Wits + services.AddTransient, WitsRecordRepository>(); + services.AddTransient, WitsRecordRepository>(); + services.AddTransient, WitsRecordRepository>(); + services.AddTransient, WitsRecordRepository>(); + services.AddTransient, WitsRecordRepository>(); + services.AddTransient, WitsRecordRepository>(); - services.AddTransient(); - services.AddTransient(); + services.AddTransient(); + services.AddTransient, AutoGeneratedDailyReportMakerService>(); + services.AddTransient(); + services.AddTransient, DrillTestReportMakerService>(); - services.AddTransient(); - services.AddTransient(); - services.AddTransient, CrudRepositoryBase>(); + services.AddTransient(); + services.AddTransient(); + services.AddTransient, CrudRepositoryBase>(); - services.AddTransient(); + services.AddTransient(); - services.AddTransient(); - services.AddTransient(); - services.AddTransient(); + services.AddTransient(); + services.AddTransient(); + services.AddTransient(); - services.AddTransient, WellOperationDefaultExcelParser>(); - services.AddTransient, WellOperationGazpromKhantosExcelParser>(); + services.AddTransient, WellOperationDefaultExcelParser>(); + services.AddTransient, WellOperationGazpromKhantosExcelParser>(); - return services; - } + return services; + } - public static IServiceCollection AddTransientLazy(this IServiceCollection services) - where TService : class - where TImplementation : class, TService - => services.AddTransient() - .AddTransient(provider => new Lazy(provider.GetRequiredService)); + public static IServiceCollection AddTransientLazy(this IServiceCollection services) + where TService : class + where TImplementation : class, TService + => services.AddTransient() + .AddTransient(provider => new Lazy(provider.GetRequiredService)); - public static IServiceCollection AddTransientLazy(this IServiceCollection services, Func implementationFactory) - where TService : class - where TImplementation : class, TService - => services.AddTransient(implementationFactory) - .AddTransient(provider => new Lazy(() => implementationFactory(provider))); + public static IServiceCollection AddTransientLazy(this IServiceCollection services, Func implementationFactory) + where TService : class + where TImplementation : class, TService + => services.AddTransient(implementationFactory) + .AddTransient(provider => new Lazy(() => implementationFactory(provider))); } diff --git a/AsbCloudInfrastructure/Repository/DrillTestRepository.cs b/AsbCloudInfrastructure/Repository/DrillTestRepository.cs index a308cb0b..e349db2c 100644 --- a/AsbCloudInfrastructure/Repository/DrillTestRepository.cs +++ b/AsbCloudInfrastructure/Repository/DrillTestRepository.cs @@ -1,7 +1,12 @@ using AsbCloudApp.Data.SAUB; using AsbCloudApp.Repositories; +using AsbCloudApp.Requests; +using AsbCloudApp.Services; using AsbCloudDb.Model; using Mapster; +using Microsoft.EntityFrameworkCore; +using System; +using System.Linq; using System.Threading; using System.Threading.Tasks; @@ -16,6 +21,44 @@ namespace AsbCloudInfrastructure.Repository this.db = db; } + public async Task GetAllAsync(int idTelemetry, FileReportRequest request, CancellationToken cancellationToken) + { + var query = db.DrillTests + .Where(d => d.IdTelemetry == idTelemetry) + .AsNoTracking(); + + if (request.GeDate.HasValue) + { + var startDate = new DateTime(request.GeDate.Value.Year, request.GeDate.Value.Month, request.GeDate.Value.Day); + query = query.Where(q => q.TimeStampStart >= startDate); + } + if (request.LeDate.HasValue) + { + var finishDate = new DateTime(request.LeDate.Value.Year, request.LeDate.Value.Month, request.LeDate.Value.Day); + query = query.Where(q => q.TimeStampStart <= finishDate); + } + + var entities = await query.ToListAsync(cancellationToken); + var dtos = entities.Select(e => e.Adapt()).ToArray(); + + return dtos; + } + + + public async Task GetAsync(int idTelemetry, int id, CancellationToken cancellationToken) + { + var drillTest = await db.DrillTests + .Where(d => d.IdTelemetry == idTelemetry) + .Where(d => d.Id == id) + .FirstOrDefaultAsync(cancellationToken); + + if (drillTest is null) + throw new Exception($"Drill test with id: {id} and idTelemetry: {idTelemetry} does not exist."); + + var dto = drillTest.Adapt(); + return dto; + } + public async Task SaveDataAsync(int idTelemetry, DrillTestDto dto, CancellationToken token) { var entity = dto.Adapt(); diff --git a/AsbCloudInfrastructure/Services/AutoGeneratedDailyReports/AutoGeneratedDailyReportMakerService.cs b/AsbCloudInfrastructure/Services/AutoGeneratedDailyReports/AutoGeneratedDailyReportMakerService.cs index 0f1c7076..8fee9b2c 100644 --- a/AsbCloudInfrastructure/Services/AutoGeneratedDailyReports/AutoGeneratedDailyReportMakerService.cs +++ b/AsbCloudInfrastructure/Services/AutoGeneratedDailyReports/AutoGeneratedDailyReportMakerService.cs @@ -11,8 +11,10 @@ using ClosedXML.Excel; namespace AsbCloudInfrastructure.Services.AutoGeneratedDailyReports; -public class AutoGeneratedDailyReportMakerService : IAutoGeneratedDailyReportMakerService +public class AutoGeneratedDailyReportMakerService : IReportMakerService { + private readonly string templateName = "AutogeneratedDailyReportTemplate.xlsx"; + private readonly IEnumerable blockWriters = new List() { new HeadExcelBlockWriter(), @@ -20,10 +22,12 @@ public class AutoGeneratedDailyReportMakerService : IAutoGeneratedDailyReportMak new LimitingParameterExcelBlockWriter(), new TimeBalanceExcelBlockWriter() }; - - public async Task MakeReportAsync(AutoGeneratedDailyReportDto report, CancellationToken cancellationToken) + + public async Task MakeReportAsync(AutoGeneratedDailyReportDto report, CancellationToken cancellationToken) { - using var excelTemplateStream = await GetExcelTemplateStreamAsync(cancellationToken); + using var excelTemplateStream = await Assembly + .GetExecutingAssembly() + .GetTemplateCopyStreamAsync(templateName, cancellationToken); using var workbook = new XLWorkbook(excelTemplateStream, XLEventTracking.Disabled); @@ -35,22 +39,6 @@ public class AutoGeneratedDailyReportMakerService : IAutoGeneratedDailyReportMak return memoryStream; } - - private async Task GetExcelTemplateStreamAsync(CancellationToken cancellationToken) - { - var resourceName = Assembly.GetExecutingAssembly() - .GetManifestResourceNames() - .FirstOrDefault(n => n.EndsWith("AutogeneratedDailyReportTemplate.xlsx"))!; - - using var stream = Assembly.GetExecutingAssembly() - .GetManifestResourceStream(resourceName)!; - - var memoryStream = new MemoryStream(); - await stream.CopyToAsync(memoryStream, cancellationToken); - memoryStream.Position = 0; - - return memoryStream; - } private void AddToWorkbook(XLWorkbook workbook, AutoGeneratedDailyReportDto report) { diff --git a/AsbCloudInfrastructure/Services/AutoGeneratedDailyReports/AutoGeneratedDailyReportService.cs b/AsbCloudInfrastructure/Services/AutoGeneratedDailyReports/AutoGeneratedDailyReportService.cs index 03ed6e07..1ada2676 100644 --- a/AsbCloudInfrastructure/Services/AutoGeneratedDailyReports/AutoGeneratedDailyReportService.cs +++ b/AsbCloudInfrastructure/Services/AutoGeneratedDailyReports/AutoGeneratedDailyReportService.cs @@ -26,14 +26,14 @@ public class AutoGeneratedDailyReportService : IAutoGeneratedDailyReportService private readonly ISubsystemOperationTimeService subsystemOperationTimeService; private readonly ICrudRepository subsystemRepository; private readonly ILimitingParameterService limitingParameterService; - private readonly IAutoGeneratedDailyReportMakerService autoGeneratedDailyReportMakerService; + private readonly IReportMakerService autoGeneratedDailyReportMakerService; public AutoGeneratedDailyReportService(IWellService wellService, IWellOperationRepository wellOperationRepository, ISubsystemOperationTimeService subsystemOperationTimeService, ICrudRepository subsystemRepository, ILimitingParameterService limitingParameterService, - IAutoGeneratedDailyReportMakerService autoGeneratedDailyReportMakerService) + IReportMakerService autoGeneratedDailyReportMakerService) { this.wellOperationRepository = wellOperationRepository; this.wellService = wellService; @@ -44,7 +44,7 @@ public class AutoGeneratedDailyReportService : IAutoGeneratedDailyReportService } public async Task> GetListAsync(int idWell, - AutoGeneratedDailyReportRequest request, + FileReportRequest request, CancellationToken cancellationToken) { var result = new PaginationContainer @@ -67,19 +67,19 @@ public class AutoGeneratedDailyReportService : IAutoGeneratedDailyReportService if (datesRange is null) return result; - if (request.StartDate.HasValue) + if (request.GeDate.HasValue) { - var startDate = new DateTime(request.StartDate.Value.Year, request.StartDate.Value.Month, - request.StartDate.Value.Day); + var startDate = new DateTime(request.GeDate.Value.Year, request.GeDate.Value.Month, + request.GeDate.Value.Day); if(startDate.Date >= datesRange.From.Date) datesRange.From = startDate; } - if (request.FinishDate.HasValue) + if (request.LeDate.HasValue) { - var finishDate = new DateTime(request.FinishDate.Value.Year, request.FinishDate.Value.Month, - request.FinishDate.Value.Day); + var finishDate = new DateTime(request.LeDate.Value.Year, request.LeDate.Value.Month, + request.LeDate.Value.Day); if (finishDate.Date <= datesRange.To.Date) datesRange.To = finishDate; diff --git a/AsbCloudInfrastructure/Services/DrillTestReport/DrillTestReportMakerService.cs b/AsbCloudInfrastructure/Services/DrillTestReport/DrillTestReportMakerService.cs new file mode 100644 index 00000000..68ad690f --- /dev/null +++ b/AsbCloudInfrastructure/Services/DrillTestReport/DrillTestReportMakerService.cs @@ -0,0 +1,89 @@ +using AsbCloudApp.Data.DrillTestReport; +using AsbCloudApp.Services.AutoGeneratedDailyReports; +using ClosedXML.Excel; +using System.IO; +using System.Linq; +using System.Reflection; +using System.Threading; +using System.Threading.Tasks; + +namespace AsbCloudInfrastructure.Services.DrillTestReport +{ + public class DrillTestReportMakerService : IReportMakerService + { + private readonly string templateName = "DrillTestReportTemplate.xlsx"; + private readonly string sheetName = "Лист1"; + private readonly int startRowNumber = 8; + + public async Task MakeReportAsync(DrillTestReportDataDto report, CancellationToken cancellationToken) + { + using var excelTemplateStream = await Assembly.GetExecutingAssembly().GetTemplateCopyStreamAsync(templateName, cancellationToken); + + using var workbook = new XLWorkbook(excelTemplateStream, XLEventTracking.Disabled); + + AddToWorkbook(workbook, report); + + MemoryStream memoryStream = new MemoryStream(); + workbook.SaveAs(memoryStream, new SaveOptions { }); + memoryStream.Seek(0, SeekOrigin.Begin); + + return memoryStream; + } + + + private void AddToWorkbook(XLWorkbook workbook, DrillTestReportDataDto report) + { + var drillTestEntities = report.Data.Params; + if (!drillTestEntities.Any()) + return; + + var sheet = workbook.Worksheets.FirstOrDefault(ws => ws.Name == sheetName) + ?? throw new FileFormatException($"Книга excel не содержит листа {sheetName}."); + + sheet.Cell(4, 2).Value = report.Caption; + sheet.Cell(5, 2)._SetValue(report.Date, setAllBorders: false); + + var rowNumber = startRowNumber; + + var stepWithMaxDepthSpeed = drillTestEntities.OrderByDescending(p => p.DepthSpeed).FirstOrDefault()!.Step; + var startDepth = report.Data.DepthStart; + var startDate = report.Data.TimeStampStart; + + foreach (var drillTestEntity in drillTestEntities) + { + var endDepth = startDepth + (drillTestEntity.DepthDrillStep ?? 0); + var endDateTime = startDate.AddSeconds(drillTestEntity.TimeDrillStep ?? 0); + + sheet.Cell(rowNumber, 2).Value = startDepth; + + sheet.Cell(rowNumber, 3).Value = endDepth; + + sheet.Cell(rowNumber, 4).Value = drillTestEntity.DepthDrillStep; + + sheet.Cell(rowNumber, 5).Value = drillTestEntity.Workload; + + sheet.Cell(rowNumber, 6).Value = drillTestEntity.Speed; + + var cell = sheet.Cell(rowNumber, 7); + cell._SetValue(startDate.DateTime); + + cell = sheet.Cell(rowNumber, 8); + cell._SetValue(endDateTime.DateTime); + + sheet.Cell(rowNumber, 9).Value = drillTestEntity.TimeDrillStep; + + sheet.Cell(rowNumber, 10).Value = drillTestEntity.DepthSpeed; + + if (drillTestEntity.Step == stepWithMaxDepthSpeed) + { + var currentCells = sheet.Row(rowNumber).Cells(1, 10); + currentCells.Style.Fill.BackgroundColor = XLColor.Yellow; + } + + startDepth = endDepth; + startDate = endDateTime; + rowNumber++; + } + } + } +} diff --git a/AsbCloudInfrastructure/Services/DrillTestReport/DrillTestReportService.cs b/AsbCloudInfrastructure/Services/DrillTestReport/DrillTestReportService.cs new file mode 100644 index 00000000..a3d6074e --- /dev/null +++ b/AsbCloudInfrastructure/Services/DrillTestReport/DrillTestReportService.cs @@ -0,0 +1,103 @@ +using AsbCloudApp.Data; +using AsbCloudApp.Data.DrillTestReport; +using AsbCloudApp.Repositories; +using AsbCloudApp.Requests; +using AsbCloudApp.Services; +using AsbCloudApp.Services.AutoGeneratedDailyReports; +using System; +using System.Collections.Generic; +using System.IO; +using System.Linq; +using System.Threading; +using System.Threading.Tasks; + +namespace AsbCloudInfrastructure.Services.DrillTestReport +{ + public class DrillTestReportService : IDrillTestReportService + { + private readonly IWellService wellService; + private readonly IDrillTestRepository drillTestRepository; + private readonly ITelemetryService telemetryService; + private readonly IReportMakerService drillTestReportMakerService; + + public DrillTestReportService( + IWellService wellService, + IDrillTestRepository drillTestRepository, + ITelemetryService telemetryService, + IReportMakerService drillTestReportMakerService) + { + this.wellService = wellService; + this.drillTestRepository = drillTestRepository; + this.telemetryService = telemetryService; + this.drillTestReportMakerService = drillTestReportMakerService; + } + + public async Task<(string fileName, Stream stream)> GenerateAsync(int idWell, int id, CancellationToken cancellationToken) + { + var telemetry = telemetryService.GetOrDefaultTelemetryByIdWell(idWell); + if (telemetry is null) + throw new Exception($"Telemetry with idWell: {idWell} does not exist."); + + var dto = await drillTestRepository.GetAsync(telemetry.Id, id, cancellationToken); + + var timezone = telemetryService.GetTimezone(telemetry.Id); + var remoteDateTime = dto.TimeStampStart.ToRemoteDateTime(timezone.Hours); + dto.TimeStampStart = remoteDateTime; + + var cluster = telemetry.Info?.Cluster ?? "-"; + var deposit = telemetry.Info?.Deposit ?? "-"; + var wellCaption = wellService.GetOrDefault(idWell)!.Caption ?? "-"; + + + var report = new DrillTestReportDataDto() + { + Data = dto, + Caption = string.Format("Месторождение: {0}, куст: {1}, скважина: {2}", deposit, cluster, wellCaption), + Date = DateTime.Now, + }; + + var fileName = string.Format("Drill_test_{0}.xlsx", remoteDateTime.ToString("dd.mm.yyyy_HH_MM_ss")); + var stream = await drillTestReportMakerService.MakeReportAsync(report, cancellationToken); + + return (fileName, stream); + } + + + public async Task> GetListAsync(int idWell, FileReportRequest request, CancellationToken cancellationToken) + { + var telemetry = telemetryService.GetOrDefaultTelemetryByIdWell(idWell); + if (telemetry is null) + throw new Exception($"Telemetry with idWell: {idWell} does not exist."); + + var result = new PaginationContainer + { + Skip = request.Skip ?? 0, + Take = request.Take ?? 10, + Items = Enumerable.Empty() + }; + + var reports = new List(); + var timezone = telemetryService.GetTimezone(telemetry.Id); + + var dtos = await drillTestRepository.GetAllAsync(telemetry.Id, request, cancellationToken); + foreach (var dto in dtos) + { + var remoteDateTime = dto.TimeStampStart.ToRemoteDateTime(timezone.Hours); + + reports.Add(new DrillTestReportInfoDto + { + FileName = string.Format("Drill_test_{0}", remoteDateTime), + DrillDepth = (dto.Params + .Where(p => p.DepthDrillStep.HasValue) + .Sum(x => x.DepthDrillStep) ?? 0) + dto.DepthStart, + DateTime = remoteDateTime, + Id = dto.Id, + }); + } + + result.Items = reports; + + return result; + } + } +} diff --git a/AsbCloudInfrastructure/Services/DrillTestReport/DrillTestReportTemplate.xlsx b/AsbCloudInfrastructure/Services/DrillTestReport/DrillTestReportTemplate.xlsx new file mode 100644 index 0000000000000000000000000000000000000000..5b9e8ec1c720e867771050303bf2431eb91d03a9 GIT binary patch literal 7284 zcmaJ`1z40@^QRkRVQC3Lx>H)Za{=iF0f{A+mImn(q#H>=I+X5`&IRc%DJiKx-1|L` zT)+Q!XPRGbX6F1xMIIgj2!n!x0wcnvt_kyq(C_aJ9nEc=SXmyvOW(IC zb+BQ)JMau+IOm=hLCMZ

^YO#zofp+>WFsG`BP0_)G#92P3kwBg(P|?wyhi6?tTopcJl@ANNWaf`frk`JZZfa{q*z z4XZ2I(b@zIwq|j&wTV>gvzueXZaQZ~STJWccter^uUQ)dGjCMTm;7D|-#QE^;~_sP zenoN<>n(LGO{)4TB}eEdMQGLGpeJW8bh2n=2sZvTNaFd{WhZQGUs|ZGgz!Agk0jn% zl~^?vM2R(w6um*i!6?u^h~5=zfq+$uKh?72C zQkZAL?3=GfrfI`2nVNU1TxRXKq*dMhNoa<8me??Rj37&TO)ow6rk^d#?s&xCMW&Fq1HcB4c4GR4pqJ9p zlAdm%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sGh_D-y(U`O+ZGnOv(F6Kd=Y9uT?lxr;3N#~j>ES%(4@vE2*nqFbcANJgps@p zopLEL_&PLdC;2oBC)IW?ZO2!nA~n?w#}S)9L;ECg zz{Ir$1Iv6#>PeCw%ubA=O*u1?WgFq`=MbYyDAB71%@1=~r7%J3!F16fK~+}requzG z9~e(~1}K5!J|dvt$0caEFf4RD<~7u+LC$nbt6{q^kXXVnoS%{$t$Ph4th_DXO4f7` z31rs~Y)Kjh7%1b^_gnA{7Mxp~ez-!Nm)3V#XKJw89>X!Dpvss6iV&oXRZ@N(tI8=f zXD$N8gJM3Y1Pan+6E))rFq93IEp-Xf_95Fn=h=4^f1hrShURGn>=3Gw!S4JvcRl$B&G(JX+0{$kUrROCJJl50^pmx znV}`jL_Sj%DoHRX!vVw=4qSj zZ81miu&(7P7~jPESs&eB|Gq9=aj+f4+zw)>?rv}Hr2p5kK7Qc7dw?x@eiPQK3v4j= z!V$mWAd5nD0O zjRHUP15J-Pd}PY{ARN6LB*@R&^l-aBMvTt0;Y*;VAip6cj98npCOaA@_~uZtgjhbX zd>DpmO_`L`JsY4WDs(Ln^u_*2pe@=fQrx%biQeSb1CPvpUkFE|vXT5sYa%72mXv(*Sd zm}1J!2%q^yo+{EO)VsNLlyWK@qJKc;T-{@LE_mGo=xn!G`0C3V5Io*+w=uahkqx*g z#Jc;%3@9BYdokgv?=Sd)IpLX(7f*A|B`UdDiF+Px=7XJv7bu%8?tO3Kue<{b2ZZ_E z-+A29c{|a6z;kb$|7Y8)$Ri>>yanz4<9nZ67Kk4H{U4DwoaX=l literal 0 HcmV?d00001 diff --git a/AsbCloudInfrastructure/XLExtentions.cs b/AsbCloudInfrastructure/XLExtentions.cs index c1a463d0..f7b1654b 100644 --- a/AsbCloudInfrastructure/XLExtentions.cs +++ b/AsbCloudInfrastructure/XLExtentions.cs @@ -92,12 +92,16 @@ internal static class XLExtentions } - internal static IXLCell _SetValue(this IXLCell cell, DateTime value, string dateFormat = "DD.MM.YYYY HH:MM:SS") + internal static IXLCell _SetValue(this IXLCell cell, DateTime value, string dateFormat = "DD.MM.YYYY HH:MM:SS", bool? setAllBorders = true) { cell.Value = value; - cell.Style - .SetAllBorders() - .Alignment.WrapText = true; + if (setAllBorders == true) + { + cell.Style + .SetAllBorders() + .Alignment.WrapText = true; + } + cell.Value = value; diff --git a/AsbCloudWebApi/Controllers/AutoGeneratedDailyReportController.cs b/AsbCloudWebApi/Controllers/AutoGeneratedDailyReportController.cs index de26e843..a392bf51 100644 --- a/AsbCloudWebApi/Controllers/AutoGeneratedDailyReportController.cs +++ b/AsbCloudWebApi/Controllers/AutoGeneratedDailyReportController.cs @@ -25,7 +25,8 @@ public class AutoGeneratedDailyReportController : ControllerBase private readonly IAutoGeneratedDailyReportService autoGeneratedDailyReportService; private readonly IWellService wellService; - public AutoGeneratedDailyReportController(IAutoGeneratedDailyReportService autoGeneratedDailyReportService, + public AutoGeneratedDailyReportController( + IAutoGeneratedDailyReportService autoGeneratedDailyReportService, IWellService wellService) { this.autoGeneratedDailyReportService = autoGeneratedDailyReportService; @@ -66,7 +67,7 @@ public class AutoGeneratedDailyReportController : ControllerBase [HttpGet("all")] [ProducesResponseType(typeof(PaginationContainer), (int)HttpStatusCode.OK)] public async Task GetListAsync([FromRoute][Required] int idWell, - [FromQuery] AutoGeneratedDailyReportRequest request, + [FromQuery] FileReportRequest request, CancellationToken cancellationToken) { if (!await CanUserAccessToWellAsync(idWell, cancellationToken)) diff --git a/AsbCloudWebApi/Controllers/DrillTestsReportController.cs b/AsbCloudWebApi/Controllers/DrillTestsReportController.cs new file mode 100644 index 00000000..5f5f6b20 --- /dev/null +++ b/AsbCloudWebApi/Controllers/DrillTestsReportController.cs @@ -0,0 +1,84 @@ +using AsbCloudApp.Data; +using AsbCloudApp.Data.AutogeneratedDailyReport; +using AsbCloudApp.Requests; +using AsbCloudApp.Services; +using Microsoft.AspNetCore.Authorization; +using Microsoft.AspNetCore.Http; +using Microsoft.AspNetCore.Mvc; +using System.ComponentModel.DataAnnotations; +using System.Net; +using System.Threading; +using System.Threading.Tasks; + +namespace AsbCloudWebApi.Controllers; + +///

+/// Контроллер для drill_test отчётов +/// +[ApiController] +[Route("api/well/{idWell}/[controller]")] +[Authorize] +public class DrillTestsReportController : ControllerBase +{ + private readonly IDrillTestReportService drillTestReportService; + private readonly IWellService wellService; + + public DrillTestsReportController(IDrillTestReportService drillTestReportService, + IWellService wellService) + { + this.drillTestReportService = drillTestReportService; + this.wellService = wellService; + } + + /// + /// Формирование отчёта + /// + /// Id скважины + /// Ключ entity test записи + /// + /// + [HttpGet] + [ProducesResponseType(typeof(PhysicalFileResult), (int)HttpStatusCode.OK, "application/octet-stream")] + [ProducesResponseType(StatusCodes.Status204NoContent)] + public async Task GenerateReportAsync([FromRoute] int idWell, + [FromQuery] int id, + CancellationToken cancellationToken) + { + if (!await CanUserAccessToWellAsync(idWell, cancellationToken)) + return Forbid(); + + var reportFile = await drillTestReportService.GenerateAsync(idWell, id, cancellationToken); + + return File(reportFile.stream, "application/octet-stream", reportFile.fileName); + } + + /// + /// Список файлов drill test отчётов + /// + /// Id скважины + /// Параметры запроса + /// + /// + [HttpGet("all")] + [ProducesResponseType(typeof(PaginationContainer), (int)HttpStatusCode.OK)] + public async Task GetListAsync([FromRoute][Required] int idWell, + [FromQuery] FileReportRequest request, + CancellationToken cancellationToken) + { + if (!await CanUserAccessToWellAsync(idWell, cancellationToken)) + return Forbid(); + + var reports = await drillTestReportService.GetListAsync(idWell, + request, + cancellationToken); + + return Ok(reports); + } + + private async Task CanUserAccessToWellAsync(int idWell, CancellationToken cancellationToken) + { + int? idCompany = User.GetCompanyId(); + return idCompany is not null && await wellService.IsCompanyInvolvedInWellAsync((int)idCompany, + idWell, cancellationToken).ConfigureAwait(false); + } +} \ No newline at end of file From 50e8f557d8f3c630895b27beec94d33e00d8641f Mon Sep 17 00:00:00 2001 From: Olga Nemt Date: Fri, 20 Oct 2023 11:41:55 +0500 Subject: [PATCH 02/10] =?UTF-8?q?-=20IReportMakerService=20=D0=BF=D0=B5?= =?UTF-8?q?=D1=80=D0=B5=D0=BC=D0=B5=D1=89=D0=B5=D0=BD=20-=20=D0=9F=D0=BE?= =?UTF-8?q?=D0=B4=D0=BF=D1=80=D0=B0=D0=B2=D0=BB=D0=B5=D0=BD=D1=8B=20usings?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- ...tedDailyReportMakerService.cs => IReportMakerService.cs} | 2 +- AsbCloudInfrastructure/Repository/DrillTestRepository.cs | 6 ++++-- .../AutoGeneratedDailyReportMakerService.cs | 2 +- .../Services/DrillTestReport/DrillTestReportMakerService.cs | 2 +- .../Services/DrillTestReport/DrillTestReportService.cs | 1 - 5 files changed, 7 insertions(+), 6 deletions(-) rename AsbCloudApp/Services/{AutoGeneratedDailyReports/IAutoGeneratedDailyReportMakerService.cs => IReportMakerService.cs} (90%) diff --git a/AsbCloudApp/Services/AutoGeneratedDailyReports/IAutoGeneratedDailyReportMakerService.cs b/AsbCloudApp/Services/IReportMakerService.cs similarity index 90% rename from AsbCloudApp/Services/AutoGeneratedDailyReports/IAutoGeneratedDailyReportMakerService.cs rename to AsbCloudApp/Services/IReportMakerService.cs index 8c2e9a46..e1269a25 100644 --- a/AsbCloudApp/Services/AutoGeneratedDailyReports/IAutoGeneratedDailyReportMakerService.cs +++ b/AsbCloudApp/Services/IReportMakerService.cs @@ -2,7 +2,7 @@ using System.IO; using System.Threading; using System.Threading.Tasks; -namespace AsbCloudApp.Services.AutoGeneratedDailyReports; +namespace AsbCloudApp.Services; /// /// Сервис для генерации файлов отчётов diff --git a/AsbCloudInfrastructure/Repository/DrillTestRepository.cs b/AsbCloudInfrastructure/Repository/DrillTestRepository.cs index e349db2c..3a16b703 100644 --- a/AsbCloudInfrastructure/Repository/DrillTestRepository.cs +++ b/AsbCloudInfrastructure/Repository/DrillTestRepository.cs @@ -30,12 +30,14 @@ namespace AsbCloudInfrastructure.Repository if (request.GeDate.HasValue) { var startDate = new DateTime(request.GeDate.Value.Year, request.GeDate.Value.Month, request.GeDate.Value.Day); - query = query.Where(q => q.TimeStampStart >= startDate); + DateTimeOffset startDateUTC = DateTime.SpecifyKind(startDate, DateTimeKind.Utc); + query = query.Where(q => q.TimeStampStart >= startDateUTC); } if (request.LeDate.HasValue) { var finishDate = new DateTime(request.LeDate.Value.Year, request.LeDate.Value.Month, request.LeDate.Value.Day); - query = query.Where(q => q.TimeStampStart <= finishDate); + DateTimeOffset finishDateUTC = DateTime.SpecifyKind(finishDate, DateTimeKind.Utc); + query = query.Where(q => q.TimeStampStart <= finishDateUTC); } var entities = await query.ToListAsync(cancellationToken); diff --git a/AsbCloudInfrastructure/Services/AutoGeneratedDailyReports/AutoGeneratedDailyReportMakerService.cs b/AsbCloudInfrastructure/Services/AutoGeneratedDailyReports/AutoGeneratedDailyReportMakerService.cs index 8fee9b2c..cfc95753 100644 --- a/AsbCloudInfrastructure/Services/AutoGeneratedDailyReports/AutoGeneratedDailyReportMakerService.cs +++ b/AsbCloudInfrastructure/Services/AutoGeneratedDailyReports/AutoGeneratedDailyReportMakerService.cs @@ -5,7 +5,7 @@ using System.Reflection; using System.Threading; using System.Threading.Tasks; using AsbCloudApp.Data.AutogeneratedDailyReport; -using AsbCloudApp.Services.AutoGeneratedDailyReports; +using AsbCloudApp.Services; using AsbCloudInfrastructure.Services.AutoGeneratedDailyReports.AutogeneratedDailyReportBlocks; using ClosedXML.Excel; diff --git a/AsbCloudInfrastructure/Services/DrillTestReport/DrillTestReportMakerService.cs b/AsbCloudInfrastructure/Services/DrillTestReport/DrillTestReportMakerService.cs index 68ad690f..1badc97e 100644 --- a/AsbCloudInfrastructure/Services/DrillTestReport/DrillTestReportMakerService.cs +++ b/AsbCloudInfrastructure/Services/DrillTestReport/DrillTestReportMakerService.cs @@ -1,5 +1,5 @@ using AsbCloudApp.Data.DrillTestReport; -using AsbCloudApp.Services.AutoGeneratedDailyReports; +using AsbCloudApp.Services; using ClosedXML.Excel; using System.IO; using System.Linq; diff --git a/AsbCloudInfrastructure/Services/DrillTestReport/DrillTestReportService.cs b/AsbCloudInfrastructure/Services/DrillTestReport/DrillTestReportService.cs index a3d6074e..6dbc9528 100644 --- a/AsbCloudInfrastructure/Services/DrillTestReport/DrillTestReportService.cs +++ b/AsbCloudInfrastructure/Services/DrillTestReport/DrillTestReportService.cs @@ -3,7 +3,6 @@ using AsbCloudApp.Data.DrillTestReport; using AsbCloudApp.Repositories; using AsbCloudApp.Requests; using AsbCloudApp.Services; -using AsbCloudApp.Services.AutoGeneratedDailyReports; using System; using System.Collections.Generic; using System.IO; From 85086e72063a201d9577b5b4ad465db18b194488 Mon Sep 17 00:00:00 2001 From: Olga Nemt Date: Fri, 20 Oct 2023 11:52:04 +0500 Subject: [PATCH 03/10] =?UTF-8?q?=D0=A4=D0=BE=D1=80=D0=BC=D0=B0=D1=82?= =?UTF-8?q?=D0=B8=D1=80=D0=BE=D0=B2=D0=B0=D0=BD=D0=B8=D0=B5=20=D1=84=D0=B0?= =?UTF-8?q?=D0=B9=D0=BB=D0=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- AsbCloudInfrastructure/XLExtentions.cs | 286 ++++++++++++------------- 1 file changed, 143 insertions(+), 143 deletions(-) diff --git a/AsbCloudInfrastructure/XLExtentions.cs b/AsbCloudInfrastructure/XLExtentions.cs index f7b1654b..2f75c820 100644 --- a/AsbCloudInfrastructure/XLExtentions.cs +++ b/AsbCloudInfrastructure/XLExtentions.cs @@ -8,123 +8,123 @@ namespace AsbCloudInfrastructure; internal static class XLExtentions { - internal static IXLRange _SetValue(this IXLRange range, object value) - { - var mergedRange = range.Merge(); - mergedRange.FirstCell()._SetValue(value); - var colWidth = mergedRange.FirstCell().WorksheetColumn().Width; - var maxCharsToWrap = colWidth / (0.1d * mergedRange.FirstCell().Style.Font.FontSize); - if (value is string valueString && valueString.Length > maxCharsToWrap) - { - var row = mergedRange.FirstCell().WorksheetRow(); - var baseHeight = row.Height; - row.Height = 0.5d * baseHeight * Math.Ceiling(1d + valueString.Length / maxCharsToWrap); - } + internal static IXLRange _SetValue(this IXLRange range, object value) + { + var mergedRange = range.Merge(); + mergedRange.FirstCell()._SetValue(value); + var colWidth = mergedRange.FirstCell().WorksheetColumn().Width; + var maxCharsToWrap = colWidth / (0.1d * mergedRange.FirstCell().Style.Font.FontSize); + if (value is string valueString && valueString.Length > maxCharsToWrap) + { + var row = mergedRange.FirstCell().WorksheetRow(); + var baseHeight = row.Height; + row.Height = 0.5d * baseHeight * Math.Ceiling(1d + valueString.Length / maxCharsToWrap); + } - mergedRange.Style.SetAllBorders() - .Alignment.SetWrapText(true); - return mergedRange; - } + mergedRange.Style.SetAllBorders() + .Alignment.SetWrapText(true); + return mergedRange; + } - internal static IXLCell _SetValue(this IXLCell cell, object value) - { - switch (value) - { - case DateTime dateTime: - cell._SetValue(dateTime); - break; - case IFormattable formattable: - cell._SetValue(formattable); - break; - case string valueString: - cell._SetValue(valueString); - break; - default: - cell.Value = value; - break; - } + internal static IXLCell _SetValue(this IXLCell cell, object value) + { + switch (value) + { + case DateTime dateTime: + cell._SetValue(dateTime); + break; + case IFormattable formattable: + cell._SetValue(formattable); + break; + case string valueString: + cell._SetValue(valueString); + break; + default: + cell.Value = value; + break; + } - return cell; - } + return cell; + } - internal static IXLCell _SetValue(this IXLCell cell, string value, bool adaptRowHeight = false) - { - cell.Value = value; - cell.Style - .SetAllBorders() - .Alignment.WrapText = true; + internal static IXLCell _SetValue(this IXLCell cell, string value, bool adaptRowHeight = false) + { + cell.Value = value; + cell.Style + .SetAllBorders() + .Alignment.WrapText = true; - cell.Value = value; - if (adaptRowHeight) - { - var colWidth = cell.WorksheetColumn().Width; - var maxCharsToWrap = colWidth / (0.1d * cell.Style.Font.FontSize); - if (value.Length > maxCharsToWrap) - { - var row = cell.WorksheetRow(); - var baseHeight = row.Height; - row.Height = 0.5d * baseHeight * Math.Ceiling(1d + value.Length / maxCharsToWrap); - } - } + cell.Value = value; + if (adaptRowHeight) + { + var colWidth = cell.WorksheetColumn().Width; + var maxCharsToWrap = colWidth / (0.1d * cell.Style.Font.FontSize); + if (value.Length > maxCharsToWrap) + { + var row = cell.WorksheetRow(); + var baseHeight = row.Height; + row.Height = 0.5d * baseHeight * Math.Ceiling(1d + value.Length / maxCharsToWrap); + } + } - return cell; - } + return cell; + } - internal static IXLCell _ValueNoBorder(this IXLCell cell, string value, bool adaptRowHeight = false) - { - cell.Value = value; - cell.Style.Alignment.WrapText = true; + internal static IXLCell _ValueNoBorder(this IXLCell cell, string value, bool adaptRowHeight = false) + { + cell.Value = value; + cell.Style.Alignment.WrapText = true; - cell.Value = value; - if (adaptRowHeight) - { - var colWidth = cell.WorksheetColumn().Width; - var maxCharsToWrap = colWidth / (0.1d * cell.Style.Font.FontSize); - if (value.Length > maxCharsToWrap) - { - var row = cell.WorksheetRow(); - var baseHeight = row.Height; - row.Height = 0.5d * baseHeight * Math.Ceiling(1d + value.Length / maxCharsToWrap); - } - } + cell.Value = value; + if (adaptRowHeight) + { + var colWidth = cell.WorksheetColumn().Width; + var maxCharsToWrap = colWidth / (0.1d * cell.Style.Font.FontSize); + if (value.Length > maxCharsToWrap) + { + var row = cell.WorksheetRow(); + var baseHeight = row.Height; + row.Height = 0.5d * baseHeight * Math.Ceiling(1d + value.Length / maxCharsToWrap); + } + } - return cell; - } + return cell; + } - internal static IXLCell _SetValue(this IXLCell cell, DateTime value, string dateFormat = "DD.MM.YYYY HH:MM:SS", bool? setAllBorders = true) - { - cell.Value = value; - if (setAllBorders == true) - { + internal static IXLCell _SetValue(this IXLCell cell, DateTime value, string dateFormat = "DD.MM.YYYY HH:MM:SS", bool? setAllBorders = true) + { + cell.Value = value; + if (setAllBorders == true) + { cell.Style .SetAllBorders() .Alignment.WrapText = true; } - - cell.Value = value; - cell.DataType = XLDataType.DateTime; - cell.Style.DateFormat.Format = "DD.MM.YYYY HH:MM:SS"; + cell.Value = value; - return cell; - } + cell.DataType = XLDataType.DateTime; + cell.Style.DateFormat.Format = "DD.MM.YYYY HH:MM:SS"; - internal static IXLCell _SetValue(this IXLCell cell, IFormattable value, string format = "0.00") - { - cell.Value = value; - cell.Style - .SetAllBorders() - .Alignment.WrapText = true; + return cell; + } - cell.Value = value; + internal static IXLCell _SetValue(this IXLCell cell, IFormattable value, string format = "0.00") + { + cell.Value = value; + cell.Style + .SetAllBorders() + .Alignment.WrapText = true; - cell.DataType = XLDataType.Number; - cell.Style.NumberFormat.Format = "0.00"; + cell.Value = value; - return cell; - } + cell.DataType = XLDataType.Number; + cell.Style.NumberFormat.Format = "0.00"; + + return cell; + } public static IXLCell SetVal(this IXLCell cell, double? value, string format = "0.00") { @@ -162,60 +162,60 @@ internal static class XLExtentions } internal static IXLStyle SetAllBorders(this IXLStyle style, XLBorderStyleValues borderStyle = XLBorderStyleValues.Thin) - { - style.Border.RightBorder = borderStyle; - style.Border.LeftBorder = borderStyle; - style.Border.TopBorder = borderStyle; - style.Border.BottomBorder = borderStyle; - style.Border.InsideBorder = borderStyle; - style.Border.OutsideBorder = borderStyle; - return style; - } + { + style.Border.RightBorder = borderStyle; + style.Border.LeftBorder = borderStyle; + style.Border.TopBorder = borderStyle; + style.Border.BottomBorder = borderStyle; + style.Border.InsideBorder = borderStyle; + style.Border.OutsideBorder = borderStyle; + return style; + } - internal static IXLStyle SetBaseFont(this IXLStyle style) - { - style.Font.FontName = "Calibri"; - style.Font.FontSize = 10; - return style; - } + internal static IXLStyle SetBaseFont(this IXLStyle style) + { + style.Font.FontName = "Calibri"; + style.Font.FontSize = 10; + return style; + } - internal static IXLStyle SetH1(this IXLStyle style) - { - style.Font.FontName = "Calibri"; - style.Font.FontSize = 14; - return style; - } + internal static IXLStyle SetH1(this IXLStyle style) + { + style.Font.FontName = "Calibri"; + style.Font.FontSize = 14; + return style; + } - /// - /// Костыль исправляющий проблему в библиотеке IXLRange Range(this IXLWorksheet, IXLAddress, IXLAddress) с кастингом IXLAddress к XLAddress. - /// - /// - /// - /// - /// - internal static IXLRange _Range(this IXLWorksheet sheet, CellAddress begin, CellAddress end) - => sheet.Range(begin.RowNumber, begin.ColumnNumber, end.RowNumber, end.ColumnNumber); - - - internal static T? GetCellValue(this IXLCell cell) - { - try - { - if (cell.IsEmpty() && default(T) == null) - return default; - - if (typeof(T) != typeof(DateTime)) - return (T)Convert.ChangeType(cell.GetFormattedString(), typeof(T), CultureInfo.InvariantCulture); + /// + /// Костыль исправляющий проблему в библиотеке IXLRange Range(this IXLWorksheet, IXLAddress, IXLAddress) с кастингом IXLAddress к XLAddress. + /// + /// + /// + /// + /// + internal static IXLRange _Range(this IXLWorksheet sheet, CellAddress begin, CellAddress end) + => sheet.Range(begin.RowNumber, begin.ColumnNumber, end.RowNumber, end.ColumnNumber); + + + internal static T? GetCellValue(this IXLCell cell) + { + try + { + if (cell.IsEmpty() && default(T) == null) + return default; + + if (typeof(T) != typeof(DateTime)) + return (T)Convert.ChangeType(cell.GetFormattedString(), typeof(T), CultureInfo.InvariantCulture); if (cell.Value is DateTime dateTime) return (T)(object)dateTime; return (T)(object)DateTime.FromOADate((double)cell.Value); - } - catch - { - throw new FileFormatException( - $"Лист '{cell.Worksheet.Name}'. Ячейка: ({cell.Address.RowNumber},{cell.Address.ColumnNumber}) содержит некорректное значение"); - } - } + } + catch + { + throw new FileFormatException( + $"Лист '{cell.Worksheet.Name}'. Ячейка: ({cell.Address.RowNumber},{cell.Address.ColumnNumber}) содержит некорректное значение"); + } + } } \ No newline at end of file From 1552cc4576464cf2fb889e431b4e82d16a31c467 Mon Sep 17 00:00:00 2001 From: Olga Nemt Date: Fri, 20 Oct 2023 15:44:51 +0500 Subject: [PATCH 04/10] =?UTF-8?q?DrillTestSReportController=20=D0=BF=D0=B5?= =?UTF-8?q?=D1=80=D0=B5=D0=B8=D0=BC=D0=B5=D0=BD=D0=BE=D0=B2=D0=B0=D0=BD=20?= =?UTF-8?q?=D0=B2=20DrillTestReportController?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- ...lTestsReportController.cs => DrillTestReportController.cs} | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) rename AsbCloudWebApi/Controllers/{DrillTestsReportController.cs => DrillTestReportController.cs} (95%) diff --git a/AsbCloudWebApi/Controllers/DrillTestsReportController.cs b/AsbCloudWebApi/Controllers/DrillTestReportController.cs similarity index 95% rename from AsbCloudWebApi/Controllers/DrillTestsReportController.cs rename to AsbCloudWebApi/Controllers/DrillTestReportController.cs index 5f5f6b20..62cae132 100644 --- a/AsbCloudWebApi/Controllers/DrillTestsReportController.cs +++ b/AsbCloudWebApi/Controllers/DrillTestReportController.cs @@ -18,12 +18,12 @@ namespace AsbCloudWebApi.Controllers; [ApiController] [Route("api/well/{idWell}/[controller]")] [Authorize] -public class DrillTestsReportController : ControllerBase +public class DrillTestReportController : ControllerBase { private readonly IDrillTestReportService drillTestReportService; private readonly IWellService wellService; - public DrillTestsReportController(IDrillTestReportService drillTestReportService, + public DrillTestReportController(IDrillTestReportService drillTestReportService, IWellService wellService) { this.drillTestReportService = drillTestReportService; From 88e2afc1b299501df4ee81511a413c0a5eae3548 Mon Sep 17 00:00:00 2001 From: Olga Nemt Date: Fri, 20 Oct 2023 16:55:08 +0500 Subject: [PATCH 05/10] =?UTF-8?q?=D0=9F=D1=80=D0=B0=D0=B2=D0=BA=D0=B8=20?= =?UTF-8?q?=D0=B2=D0=BD=D1=83=D1=82=D1=80=D0=B8=20=D1=88=D0=B0=D0=B1=D0=BB?= =?UTF-8?q?=D0=BE=D0=BD=D0=B0=20=D0=B8=D0=BC=D0=BF=D0=BE=D1=80=D1=82=D0=B0?= =?UTF-8?q?,=20=D0=BF=D0=B5=D1=80=D0=B5=D0=B2=D0=BE=D0=B4=20=D1=81=D0=B5?= =?UTF-8?q?=D0=BA=D1=83=D0=BD=D0=B4=20=D0=B2=20=D1=87=D0=B0=D1=81=D1=8B=20?= =?UTF-8?q?=D0=B4=D0=BB=D1=8F=20=D0=BE=D1=82=D1=87=D0=B5=D1=82=D0=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- AsbCloudApp/Data/SAUB/DrillTestParamsDto.cs | 2 +- .../DrillTestReportMakerService.cs | 3 ++- .../DrillTestReportTemplate.xlsx | Bin 7284 -> 8013 bytes 3 files changed, 3 insertions(+), 2 deletions(-) diff --git a/AsbCloudApp/Data/SAUB/DrillTestParamsDto.cs b/AsbCloudApp/Data/SAUB/DrillTestParamsDto.cs index f2b8ceac..f8d9d168 100644 --- a/AsbCloudApp/Data/SAUB/DrillTestParamsDto.cs +++ b/AsbCloudApp/Data/SAUB/DrillTestParamsDto.cs @@ -26,7 +26,7 @@ public float? DepthSpeed { get; set; } /// - /// Время бурения шага + /// Время бурения шага, сек /// public float? TimeDrillStep { get; set; } diff --git a/AsbCloudInfrastructure/Services/DrillTestReport/DrillTestReportMakerService.cs b/AsbCloudInfrastructure/Services/DrillTestReport/DrillTestReportMakerService.cs index 1badc97e..27a01e85 100644 --- a/AsbCloudInfrastructure/Services/DrillTestReport/DrillTestReportMakerService.cs +++ b/AsbCloudInfrastructure/Services/DrillTestReport/DrillTestReportMakerService.cs @@ -1,6 +1,7 @@ using AsbCloudApp.Data.DrillTestReport; using AsbCloudApp.Services; using ClosedXML.Excel; +using System; using System.IO; using System.Linq; using System.Reflection; @@ -70,7 +71,7 @@ namespace AsbCloudInfrastructure.Services.DrillTestReport cell = sheet.Cell(rowNumber, 8); cell._SetValue(endDateTime.DateTime); - sheet.Cell(rowNumber, 9).Value = drillTestEntity.TimeDrillStep; + sheet.Cell(rowNumber, 9).Value = Math.Round((drillTestEntity.TimeDrillStep ?? 0) / (60 * 60), 2); sheet.Cell(rowNumber, 10).Value = drillTestEntity.DepthSpeed; diff --git a/AsbCloudInfrastructure/Services/DrillTestReport/DrillTestReportTemplate.xlsx b/AsbCloudInfrastructure/Services/DrillTestReport/DrillTestReportTemplate.xlsx index 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7=D1=80=D0=B5=D1=88=D0=B5=D0=BD=D0=B8=D0=B5=20=D0=BD?= =?UTF-8?q?=D0=B0=20=D0=BF=D0=BE=D0=BB=D1=83=D1=87=D0=B5=D0=BD=D0=B8=D0=B5?= =?UTF-8?q?=20=D0=BE=D1=82=D1=87=D0=B5=D1=82=D0=BE=D0=B2=20drill=20test?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- AsbCloudDb/Model/DefaultData/EntityFillerPermission.cs | 2 ++ AsbCloudWebApi/Controllers/DrillTestReportController.cs | 2 ++ 2 files changed, 4 insertions(+) diff --git a/AsbCloudDb/Model/DefaultData/EntityFillerPermission.cs b/AsbCloudDb/Model/DefaultData/EntityFillerPermission.cs index b6bc8e6a..713fc6f0 100644 --- a/AsbCloudDb/Model/DefaultData/EntityFillerPermission.cs +++ b/AsbCloudDb/Model/DefaultData/EntityFillerPermission.cs @@ -161,6 +161,8 @@ new() { Id = 527, Name = "Manual.delete", Description = "Разрешение на удаление инструкций"}, new (){ Id = 528, Name="WellContact.delete", Description="Разрешение на удаление контакта"}, + + new (){ Id = 529, Name="DrillTestReport.get", Description="Разрешение на получение отчетов drill test"}, }; } } diff --git a/AsbCloudWebApi/Controllers/DrillTestReportController.cs b/AsbCloudWebApi/Controllers/DrillTestReportController.cs index 62cae132..c390e09e 100644 --- a/AsbCloudWebApi/Controllers/DrillTestReportController.cs +++ b/AsbCloudWebApi/Controllers/DrillTestReportController.cs @@ -38,6 +38,7 @@ public class DrillTestReportController : ControllerBase /// /// [HttpGet] + [Permission] [ProducesResponseType(typeof(PhysicalFileResult), (int)HttpStatusCode.OK, "application/octet-stream")] [ProducesResponseType(StatusCodes.Status204NoContent)] public async Task GenerateReportAsync([FromRoute] int idWell, @@ -60,6 +61,7 @@ public class DrillTestReportController : ControllerBase /// /// [HttpGet("all")] + [Permission] [ProducesResponseType(typeof(PaginationContainer), (int)HttpStatusCode.OK)] public async Task GetListAsync([FromRoute][Required] int idWell, [FromQuery] FileReportRequest request, From 445880854f7ca0c7726ebfbafbaddd27de94a5b1 Mon Sep 17 00:00:00 2001 From: Olga Nemt Date: Mon, 23 Oct 2023 13:43:29 +0500 Subject: [PATCH 07/10] =?UTF-8?q?=D0=9F=D1=80=D0=B0=D0=B2=D0=BA=D0=B8=20?= =?UTF-8?q?=D0=BF=D0=BE=20=D1=80=D0=B5=D0=B7=D1=83=D0=BB=D1=8C=D1=82=D0=B0?= =?UTF-8?q?=D1=82=D0=B0=D0=BC=20=D1=80=D0=B5=D0=B2=D1=8C=D1=8E?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- AsbCloudApp/Data/SAUB/DrillTestDto.cs | 5 ++ .../Exceptions/ArgumentInvalidException.cs | 15 +++- .../Repositories/IDrillTestRepository.cs | 3 +- ...yReportRequest.cs => FileReportRequest.cs} | 0 .../Repository/DrillTestRepository.cs | 23 ++++--- .../DrillTestReport/DrillTestReportService.cs | 29 ++++---- AsbCloudInfrastructure/XLExtentions.cs | 2 +- ...rtController.cs => DrillTestController.cs} | 63 ++++++++++++++--- .../Controllers/SAUB/DrillTestController.cs | 69 ------------------- .../SimplifyExceptionsMiddleware.cs | 4 +- 10 files changed, 105 insertions(+), 108 deletions(-) rename AsbCloudApp/Requests/{AutoGeneratedDailyReportRequest.cs => FileReportRequest.cs} (100%) rename AsbCloudWebApi/Controllers/{DrillTestReportController.cs => DrillTestController.cs} (52%) delete mode 100644 AsbCloudWebApi/Controllers/SAUB/DrillTestController.cs diff --git a/AsbCloudApp/Data/SAUB/DrillTestDto.cs b/AsbCloudApp/Data/SAUB/DrillTestDto.cs index e53ffbbb..acd8ccc6 100644 --- a/AsbCloudApp/Data/SAUB/DrillTestDto.cs +++ b/AsbCloudApp/Data/SAUB/DrillTestDto.cs @@ -24,6 +24,11 @@ namespace AsbCloudApp.Data.SAUB /// public float DepthStart { get; set; } + /// + /// Связанная с drill_test телеметрия + /// + public TelemetryDto Telemetry { get; set; } = null!; + /// /// Параметры теста /// diff --git a/AsbCloudApp/Exceptions/ArgumentInvalidException.cs b/AsbCloudApp/Exceptions/ArgumentInvalidException.cs index 4fe150e3..46057ff0 100644 --- a/AsbCloudApp/Exceptions/ArgumentInvalidException.cs +++ b/AsbCloudApp/Exceptions/ArgumentInvalidException.cs @@ -10,7 +10,7 @@ namespace AsbCloudApp.Exceptions /// /// название аргумента /// - public string ParamName { get; } = string.Empty; + public string[] ParamsNames { get; } = null!; /// /// конструктор @@ -20,7 +20,18 @@ namespace AsbCloudApp.Exceptions public ArgumentInvalidException(string paramName, string message) : base(message) { - ParamName = paramName; + ParamsNames = new string[1] { paramName }; + } + + /// + /// конструктор + /// + /// + /// + public ArgumentInvalidException(string[] paramsNames, string message) + : base(message) + { + ParamsNames = paramsNames; } } } diff --git a/AsbCloudApp/Repositories/IDrillTestRepository.cs b/AsbCloudApp/Repositories/IDrillTestRepository.cs index 18ff0e9b..9c7a2f50 100644 --- a/AsbCloudApp/Repositories/IDrillTestRepository.cs +++ b/AsbCloudApp/Repositories/IDrillTestRepository.cs @@ -1,5 +1,6 @@ using AsbCloudApp.Data.SAUB; using AsbCloudApp.Requests; +using System.Collections.Generic; using System.Threading; using System.Threading.Tasks; @@ -17,7 +18,7 @@ namespace AsbCloudApp.Repositories /// запрос /// /// - Task GetAllAsync(int idTelemetry, FileReportRequest request, CancellationToken cancellationToken); + Task> GetAllAsync(int idTelemetry, FileReportRequest request, CancellationToken cancellationToken); /// /// Получить запись drill_test diff --git a/AsbCloudApp/Requests/AutoGeneratedDailyReportRequest.cs b/AsbCloudApp/Requests/FileReportRequest.cs similarity index 100% rename from AsbCloudApp/Requests/AutoGeneratedDailyReportRequest.cs rename to AsbCloudApp/Requests/FileReportRequest.cs diff --git a/AsbCloudInfrastructure/Repository/DrillTestRepository.cs b/AsbCloudInfrastructure/Repository/DrillTestRepository.cs index 3a16b703..427556a2 100644 --- a/AsbCloudInfrastructure/Repository/DrillTestRepository.cs +++ b/AsbCloudInfrastructure/Repository/DrillTestRepository.cs @@ -1,4 +1,5 @@ using AsbCloudApp.Data.SAUB; +using AsbCloudApp.Exceptions; using AsbCloudApp.Repositories; using AsbCloudApp.Requests; using AsbCloudApp.Services; @@ -6,6 +7,7 @@ using AsbCloudDb.Model; using Mapster; using Microsoft.EntityFrameworkCore; using System; +using System.Collections.Generic; using System.Linq; using System.Threading; using System.Threading.Tasks; @@ -15,13 +17,15 @@ namespace AsbCloudInfrastructure.Repository public class DrillTestRepository : IDrillTestRepository { private readonly IAsbCloudDbContext db; + private readonly IWellService wellService; - public DrillTestRepository(IAsbCloudDbContext db) + public DrillTestRepository(IAsbCloudDbContext db, IWellService wellService) { this.db = db; + this.wellService = wellService; } - public async Task GetAllAsync(int idTelemetry, FileReportRequest request, CancellationToken cancellationToken) + public async Task> GetAllAsync(int idTelemetry, FileReportRequest request, CancellationToken cancellationToken) { var query = db.DrillTests .Where(d => d.IdTelemetry == idTelemetry) @@ -29,19 +33,17 @@ namespace AsbCloudInfrastructure.Repository if (request.GeDate.HasValue) { - var startDate = new DateTime(request.GeDate.Value.Year, request.GeDate.Value.Month, request.GeDate.Value.Day); - DateTimeOffset startDateUTC = DateTime.SpecifyKind(startDate, DateTimeKind.Utc); + var startDateUTC = new DateTimeOffset(request.GeDate.Value.Year, request.GeDate.Value.Month, request.GeDate.Value.Day, 0, 0, 0, TimeSpan.Zero); query = query.Where(q => q.TimeStampStart >= startDateUTC); } if (request.LeDate.HasValue) { - var finishDate = new DateTime(request.LeDate.Value.Year, request.LeDate.Value.Month, request.LeDate.Value.Day); - DateTimeOffset finishDateUTC = DateTime.SpecifyKind(finishDate, DateTimeKind.Utc); + var finishDateUTC = new DateTimeOffset(request.LeDate.Value.Year, request.LeDate.Value.Month, request.LeDate.Value.Day, 0, 0, 0, TimeSpan.Zero); query = query.Where(q => q.TimeStampStart <= finishDateUTC); } var entities = await query.ToListAsync(cancellationToken); - var dtos = entities.Select(e => e.Adapt()).ToArray(); + var dtos = entities.Select(e => e.Adapt()); return dtos; } @@ -50,14 +52,17 @@ namespace AsbCloudInfrastructure.Repository public async Task GetAsync(int idTelemetry, int id, CancellationToken cancellationToken) { var drillTest = await db.DrillTests - .Where(d => d.IdTelemetry == idTelemetry) .Where(d => d.Id == id) + .Include(d => d.Telemetry) + .Where(d => d.Telemetry.Id == idTelemetry) .FirstOrDefaultAsync(cancellationToken); if (drillTest is null) - throw new Exception($"Drill test with id: {id} and idTelemetry: {idTelemetry} does not exist."); + throw new ArgumentInvalidException(new string[] { nameof(id), nameof(idTelemetry) }, $"Drill test with id: {id} and idTelemetry: {idTelemetry} does not exist."); var dto = drillTest.Adapt(); + dto.TimeStampStart = dto.TimeStampStart.ToRemoteDateTime(dto.Telemetry.TimeZone?.Hours ?? 0); + return dto; } diff --git a/AsbCloudInfrastructure/Services/DrillTestReport/DrillTestReportService.cs b/AsbCloudInfrastructure/Services/DrillTestReport/DrillTestReportService.cs index 6dbc9528..6784ad26 100644 --- a/AsbCloudInfrastructure/Services/DrillTestReport/DrillTestReportService.cs +++ b/AsbCloudInfrastructure/Services/DrillTestReport/DrillTestReportService.cs @@ -1,5 +1,6 @@ using AsbCloudApp.Data; using AsbCloudApp.Data.DrillTestReport; +using AsbCloudApp.Exceptions; using AsbCloudApp.Repositories; using AsbCloudApp.Requests; using AsbCloudApp.Services; @@ -33,29 +34,25 @@ namespace AsbCloudInfrastructure.Services.DrillTestReport public async Task<(string fileName, Stream stream)> GenerateAsync(int idWell, int id, CancellationToken cancellationToken) { - var telemetry = telemetryService.GetOrDefaultTelemetryByIdWell(idWell); - if (telemetry is null) - throw new Exception($"Telemetry with idWell: {idWell} does not exist."); - - var dto = await drillTestRepository.GetAsync(telemetry.Id, id, cancellationToken); - - var timezone = telemetryService.GetTimezone(telemetry.Id); - var remoteDateTime = dto.TimeStampStart.ToRemoteDateTime(timezone.Hours); - dto.TimeStampStart = remoteDateTime; - - var cluster = telemetry.Info?.Cluster ?? "-"; - var deposit = telemetry.Info?.Deposit ?? "-"; - var wellCaption = wellService.GetOrDefault(idWell)!.Caption ?? "-"; - + var well = wellService.GetOrDefault(idWell); + if (well is null) + throw new ArgumentInvalidException(nameof(idWell), $"Well with id: {idWell} does not exist."); + if (well.IdTelemetry is null) + throw new ArgumentInvalidException(nameof(well.IdTelemetry), $"Well with id: {idWell} does not have telemetry."); + var dto = await drillTestRepository.GetAsync(well.IdTelemetry.Value, id, cancellationToken); + var report = new DrillTestReportDataDto() { Data = dto, - Caption = string.Format("Месторождение: {0}, куст: {1}, скважина: {2}", deposit, cluster, wellCaption), + Caption = string.Format("Месторождение: {0}, куст: {1}, скважина: {2}", + well.Deposit ?? "-", + well.Cluster ?? "-", + well.Caption ?? "-"), Date = DateTime.Now, }; - var fileName = string.Format("Drill_test_{0}.xlsx", remoteDateTime.ToString("dd.mm.yyyy_HH_MM_ss")); + var fileName = string.Format("Drill_test_{0}.xlsx", dto.TimeStampStart.ToString("dd.mm.yyyy_HH_MM_ss")); var stream = await drillTestReportMakerService.MakeReportAsync(report, cancellationToken); return (fileName, stream); diff --git a/AsbCloudInfrastructure/XLExtentions.cs b/AsbCloudInfrastructure/XLExtentions.cs index 2f75c820..ca083b6a 100644 --- a/AsbCloudInfrastructure/XLExtentions.cs +++ b/AsbCloudInfrastructure/XLExtentions.cs @@ -92,7 +92,7 @@ internal static class XLExtentions } - internal static IXLCell _SetValue(this IXLCell cell, DateTime value, string dateFormat = "DD.MM.YYYY HH:MM:SS", bool? setAllBorders = true) + internal static IXLCell _SetValue(this IXLCell cell, DateTime value, string dateFormat = "DD.MM.YYYY HH:MM:SS", bool setAllBorders = true) { cell.Value = value; if (setAllBorders == true) diff --git a/AsbCloudWebApi/Controllers/DrillTestReportController.cs b/AsbCloudWebApi/Controllers/DrillTestController.cs similarity index 52% rename from AsbCloudWebApi/Controllers/DrillTestReportController.cs rename to AsbCloudWebApi/Controllers/DrillTestController.cs index c390e09e..bda32d6e 100644 --- a/AsbCloudWebApi/Controllers/DrillTestReportController.cs +++ b/AsbCloudWebApi/Controllers/DrillTestController.cs @@ -1,10 +1,15 @@ using AsbCloudApp.Data; -using AsbCloudApp.Data.AutogeneratedDailyReport; +using AsbCloudApp.Data.DrillTestReport; +using AsbCloudApp.Data.SAUB; +using AsbCloudApp.Repositories; using AsbCloudApp.Requests; using AsbCloudApp.Services; +using AsbCloudWebApi.SignalR; using Microsoft.AspNetCore.Authorization; using Microsoft.AspNetCore.Http; using Microsoft.AspNetCore.Mvc; +using Microsoft.AspNetCore.SignalR; +using System; using System.ComponentModel.DataAnnotations; using System.Net; using System.Threading; @@ -16,18 +21,60 @@ namespace AsbCloudWebApi.Controllers; /// Контроллер для drill_test отчётов /// [ApiController] -[Route("api/well/{idWell}/[controller]")] [Authorize] -public class DrillTestReportController : ControllerBase +public class DrillTestController : ControllerBase { private readonly IDrillTestReportService drillTestReportService; + private readonly IDrillTestRepository drillTestRepository; private readonly IWellService wellService; + private readonly ITelemetryService telemetryService; + private readonly IHubContext telemetryHubContext; - public DrillTestReportController(IDrillTestReportService drillTestReportService, - IWellService wellService) + public string SignalRMethodGetDataName { get; protected set; } = "ReceiveDrilltestData"; + + public DrillTestController( + IDrillTestReportService drillTestReportService, + IDrillTestRepository drillTestRepository, + IWellService wellService, + ITelemetryService telemetryService, + IHubContext telemetryHubContext) { this.drillTestReportService = drillTestReportService; + this.drillTestRepository = drillTestRepository; this.wellService = wellService; + this.telemetryService = telemetryService; + this.telemetryHubContext = telemetryHubContext; + } + + /// + /// Метод получения данных drill_test и drill_test_params от панели оператора. + /// Сохраняет в БД. + /// + /// уникальный идентификатор записи drill_test + /// запись drill test + /// + /// + [AllowAnonymous] + [HttpPost("api/telemetry/{uid}/[controller]")] + public async Task PostDataAsync( + string uid, + [FromBody] DrillTestDto dto, + CancellationToken token) + { + var telemetry = telemetryService.GetOrCreateTelemetryByUid(uid); + if (telemetry is null) + throw new Exception($"Telemetry with RemoteUid: {uid} does not exist."); + + await drillTestRepository.SaveDataAsync(telemetry.Id, dto, token); + var idWell = telemetryService.GetIdWellByTelemetryUid(uid); + if (idWell is not null) + _ = Task.Run(async () => + { + var clients = telemetryHubContext.Clients.Group($"well_{idWell}"); + await clients.SendAsync(SignalRMethodGetDataName, dto); + }, CancellationToken.None); + + return Ok(); } /// @@ -37,7 +84,7 @@ public class DrillTestReportController : ControllerBase /// Ключ entity test записи /// /// - [HttpGet] + [HttpGet("api/well/{idWell}/[controller]")] [Permission] [ProducesResponseType(typeof(PhysicalFileResult), (int)HttpStatusCode.OK, "application/octet-stream")] [ProducesResponseType(StatusCodes.Status204NoContent)] @@ -60,9 +107,9 @@ public class DrillTestReportController : ControllerBase /// Параметры запроса /// /// - [HttpGet("all")] + [HttpGet("api/well/{idWell}/[controller]/all")] [Permission] - [ProducesResponseType(typeof(PaginationContainer), (int)HttpStatusCode.OK)] + [ProducesResponseType(typeof(PaginationContainer), (int)HttpStatusCode.OK)] public async Task GetListAsync([FromRoute][Required] int idWell, [FromQuery] FileReportRequest request, CancellationToken cancellationToken) diff --git a/AsbCloudWebApi/Controllers/SAUB/DrillTestController.cs b/AsbCloudWebApi/Controllers/SAUB/DrillTestController.cs deleted file mode 100644 index 45330d26..00000000 --- a/AsbCloudWebApi/Controllers/SAUB/DrillTestController.cs +++ /dev/null @@ -1,69 +0,0 @@ -using AsbCloudApp.Data.SAUB; -using AsbCloudApp.Repositories; -using AsbCloudApp.Services; -using AsbCloudWebApi.SignalR; -using Microsoft.AspNetCore.Mvc; -using Microsoft.AspNetCore.SignalR; -using System; -using System.Threading; -using System.Threading.Tasks; - -namespace AsbCloudWebApi.Controllers.SAUB -{ - - [Route("api/telemetry")] - [ApiController] - public class DrillTestController : ControllerBase - - { - protected readonly IWellService wellService; - private readonly ITelemetryService telemetryService; - private readonly IDrillTestRepository drillTestRepository; - private readonly IHubContext telemetryHubContext; - - public string SignalRMethodGetDataName { get; protected set; } = "ReceiveDrilltestData"; - - public DrillTestController( - ITelemetryService telemetryService, - IDrillTestRepository drillTestRepository, - IWellService wellService, - IHubContext telemetryHubContext) - { - this.telemetryService = telemetryService; - this.drillTestRepository = drillTestRepository; - this.wellService = wellService; - this.telemetryHubContext = telemetryHubContext; - } - - /// - /// Метод получения данных drill_test и drill_test_params от панели оператора. - /// Сохраняет в БД. - /// - /// уникальный идентификатор записи drill_test - /// запись drill test - /// - /// - [HttpPost("{uid}/[controller]")] - public async Task PostDataAsync( - string uid, - [FromBody] DrillTestDto dto, - CancellationToken token) - { - var telemetry = telemetryService.GetOrCreateTelemetryByUid(uid); - if (telemetry is null) - throw new Exception($"Telemetry with RemoteUid: {uid} does not exist."); - - await drillTestRepository.SaveDataAsync(telemetry.Id, dto, token); - var idWell = telemetryService.GetIdWellByTelemetryUid(uid); - if (idWell is not null) - _ = Task.Run(async () => - { - var clients = telemetryHubContext.Clients.Group($"well_{idWell}"); - await clients.SendAsync(SignalRMethodGetDataName, dto); - }, CancellationToken.None); - - return Ok(); - } - } - -} diff --git a/AsbCloudWebApi/Middlewares/SimplifyExceptionsMiddleware.cs b/AsbCloudWebApi/Middlewares/SimplifyExceptionsMiddleware.cs index 3180f41d..0bdf0683 100644 --- a/AsbCloudWebApi/Middlewares/SimplifyExceptionsMiddleware.cs +++ b/AsbCloudWebApi/Middlewares/SimplifyExceptionsMiddleware.cs @@ -56,8 +56,8 @@ namespace AsbCloudWebApi.Middlewares private static string MakeJsonBody(ArgumentInvalidException ex) { - var errors = new Dictionary { - { ex.ParamName, new[]{ ex.Message } } + var errors = new Dictionary() { + { string.Join(", ", ex.ParamsNames), new[]{ ex.Message } } }; var problem = new ValidationProblemDetails(errors); var buffer = System.Text.Json.JsonSerializer.Serialize(problem); From fee782f08f8d14e0381a04d629552d0ddf65f3e0 Mon Sep 17 00:00:00 2001 From: Olga Nemt Date: Mon, 23 Oct 2023 14:15:48 +0500 Subject: [PATCH 08/10] =?UTF-8?q?=D0=A2=D0=B5=D1=81=D1=82=20DrillTest.http?= =?UTF-8?q?=20+=20=D0=BF=D1=80=D0=B0=D0=B2=D0=BA=D0=B0=20DrillTestDto?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- AsbCloudApp/Data/SAUB/DrillTestDto.cs | 2 +- .../Repository/DrillTestRepository.cs | 6 +-- AsbCloudWebApi/Rest/DrillTest.http | 45 +++++++++++++++++++ 3 files changed, 48 insertions(+), 5 deletions(-) create mode 100644 AsbCloudWebApi/Rest/DrillTest.http diff --git a/AsbCloudApp/Data/SAUB/DrillTestDto.cs b/AsbCloudApp/Data/SAUB/DrillTestDto.cs index acd8ccc6..03f344c2 100644 --- a/AsbCloudApp/Data/SAUB/DrillTestDto.cs +++ b/AsbCloudApp/Data/SAUB/DrillTestDto.cs @@ -27,7 +27,7 @@ namespace AsbCloudApp.Data.SAUB /// /// Связанная с drill_test телеметрия /// - public TelemetryDto Telemetry { get; set; } = null!; + public TelemetryDto? Telemetry { get; set; } /// /// Параметры теста diff --git a/AsbCloudInfrastructure/Repository/DrillTestRepository.cs b/AsbCloudInfrastructure/Repository/DrillTestRepository.cs index 427556a2..4ab892a3 100644 --- a/AsbCloudInfrastructure/Repository/DrillTestRepository.cs +++ b/AsbCloudInfrastructure/Repository/DrillTestRepository.cs @@ -17,12 +17,10 @@ namespace AsbCloudInfrastructure.Repository public class DrillTestRepository : IDrillTestRepository { private readonly IAsbCloudDbContext db; - private readonly IWellService wellService; - public DrillTestRepository(IAsbCloudDbContext db, IWellService wellService) + public DrillTestRepository(IAsbCloudDbContext db) { this.db = db; - this.wellService = wellService; } public async Task> GetAllAsync(int idTelemetry, FileReportRequest request, CancellationToken cancellationToken) @@ -61,7 +59,7 @@ namespace AsbCloudInfrastructure.Repository throw new ArgumentInvalidException(new string[] { nameof(id), nameof(idTelemetry) }, $"Drill test with id: {id} and idTelemetry: {idTelemetry} does not exist."); var dto = drillTest.Adapt(); - dto.TimeStampStart = dto.TimeStampStart.ToRemoteDateTime(dto.Telemetry.TimeZone?.Hours ?? 0); + dto.TimeStampStart = dto.TimeStampStart.ToRemoteDateTime(dto.Telemetry?.TimeZone?.Hours ?? 0); return dto; } diff --git a/AsbCloudWebApi/Rest/DrillTest.http b/AsbCloudWebApi/Rest/DrillTest.http new file mode 100644 index 00000000..47d7db66 --- /dev/null +++ b/AsbCloudWebApi/Rest/DrillTest.http @@ -0,0 +1,45 @@ +@baseUrl = http://127.0.0.1:5000 +@contentType = application/json +@contentTypeForFiles = application/octet-stream +@auth = Bearer eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpZCI6IjEiLCJodHRwOi8vc2NoZW1hcy54bWxzb2FwLm9yZy93cy8yMDA1LzA1L2lkZW50aXR5L2NsYWltcy9uYW1lIjoiZGV2IiwiaWRDb21wYW55IjoiMSIsImh0dHA6Ly9zY2hlbWFzLm1pY3Jvc29mdC5jb20vd3MvMjAwOC8wNi9pZGVudGl0eS9jbGFpbXMvcm9sZSI6InJvb3QiLCJuYmYiOjE2OTc0MzcwMzEsImV4cCI6MTcyODk5NDYzMSwiaXNzIjoiYSIsImF1ZCI6ImEifQ.vB7Qb3K9gG77iP8y25zB3RcZIQk9cHkq3I1SkcooYJs + +@uid = 20210101_000000000 +@id = 1 +@idWell = 55 + +### drill test +POST {{baseUrl}}/api/telemetry/{{uid}}/DrillTest +Content-Type: {{contentType}} +accept: */* + +{ + "id": @id, + "timeStampStart": "2023-10-23T08:55:36.882Z", + "depthStart": 10, + "params": [ + { + "step": 1, + "workload": 2, + "speed": 3, + "depthSpeed": 4, + "timeDrillStep": 5, + "depthDrillStep": 15 + } + ] +} + + +### drill test +GET {{baseUrl}}/api/well/{{idWell}}/DrillTest/all +Content-Type: {{contentType}} +accept: */* +Authorization: {{auth}} + +### drill test +GET {{baseUrl}}/api/well/{{idWell}}/DrillTest?id={{id}} +Content-Type: {{contentTypeForFiles}} +accept: */* +Authorization: {{auth}} + + + From 01765d05ec9d74821f03a1e20c22828e06aa0d2c Mon Sep 17 00:00:00 2001 From: Olga Nemt Date: Mon, 23 Oct 2023 15:54:29 +0500 Subject: [PATCH 09/10] =?UTF-8?q?=D0=9F=D1=80=D0=B0=D0=B2=D0=BA=D0=B0=20?= =?UTF-8?q?=D0=BF=D0=BE=20=D1=80=D0=B5=D0=B7=D1=83=D0=BB=D1=8C=D1=82=D0=B0?= =?UTF-8?q?=D1=82=D0=B0=D0=BC=20=D1=80=D0=B5=D0=B2=D1=8C=D1=8E=20-=202?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- AsbCloudApp/Exceptions/ArgumentInvalidException.cs | 11 ++++++++--- .../Repository/DrillTestRepository.cs | 14 ++++++++++---- .../DrillTestReport/DrillTestReportService.cs | 4 ++-- .../Middlewares/SimplifyExceptionsMiddleware.cs | 5 +---- AsbCloudWebApi/Rest/DrillTest.http | 2 +- 5 files changed, 22 insertions(+), 14 deletions(-) diff --git a/AsbCloudApp/Exceptions/ArgumentInvalidException.cs b/AsbCloudApp/Exceptions/ArgumentInvalidException.cs index 46057ff0..f5e3f3cd 100644 --- a/AsbCloudApp/Exceptions/ArgumentInvalidException.cs +++ b/AsbCloudApp/Exceptions/ArgumentInvalidException.cs @@ -1,4 +1,5 @@ using System; +using System.Collections.Generic; namespace AsbCloudApp.Exceptions { @@ -10,7 +11,7 @@ namespace AsbCloudApp.Exceptions /// /// название аргумента /// - public string[] ParamsNames { get; } = null!; + public IDictionary ParamsNames { get; } = null!; /// /// конструктор @@ -20,7 +21,9 @@ namespace AsbCloudApp.Exceptions public ArgumentInvalidException(string paramName, string message) : base(message) { - ParamsNames = new string[1] { paramName }; + ParamsNames = new Dictionary() { + { paramName, new[]{ message } } + }; } /// @@ -31,7 +34,9 @@ namespace AsbCloudApp.Exceptions public ArgumentInvalidException(string[] paramsNames, string message) : base(message) { - ParamsNames = paramsNames; + ParamsNames = new Dictionary() { + { string.Join(", ", paramsNames), new[]{ message } } + }; } } } diff --git a/AsbCloudInfrastructure/Repository/DrillTestRepository.cs b/AsbCloudInfrastructure/Repository/DrillTestRepository.cs index 4ab892a3..f5fb4ece 100644 --- a/AsbCloudInfrastructure/Repository/DrillTestRepository.cs +++ b/AsbCloudInfrastructure/Repository/DrillTestRepository.cs @@ -2,7 +2,6 @@ using AsbCloudApp.Exceptions; using AsbCloudApp.Repositories; using AsbCloudApp.Requests; -using AsbCloudApp.Services; using AsbCloudDb.Model; using Mapster; using Microsoft.EntityFrameworkCore; @@ -27,6 +26,7 @@ namespace AsbCloudInfrastructure.Repository { var query = db.DrillTests .Where(d => d.IdTelemetry == idTelemetry) + .Include(d => d.Telemetry) .AsNoTracking(); if (request.GeDate.HasValue) @@ -41,7 +41,7 @@ namespace AsbCloudInfrastructure.Repository } var entities = await query.ToListAsync(cancellationToken); - var dtos = entities.Select(e => e.Adapt()); + var dtos = entities.Select(e => Convert(e)); return dtos; } @@ -58,8 +58,7 @@ namespace AsbCloudInfrastructure.Repository if (drillTest is null) throw new ArgumentInvalidException(new string[] { nameof(id), nameof(idTelemetry) }, $"Drill test with id: {id} and idTelemetry: {idTelemetry} does not exist."); - var dto = drillTest.Adapt(); - dto.TimeStampStart = dto.TimeStampStart.ToRemoteDateTime(dto.Telemetry?.TimeZone?.Hours ?? 0); + var dto = Convert(drillTest); return dto; } @@ -72,5 +71,12 @@ namespace AsbCloudInfrastructure.Repository var result = await db.SaveChangesAsync(token); return result; } + + private DrillTestDto Convert(DrillTest entity) + { + var dto = entity.Adapt(); + dto.TimeStampStart = dto.TimeStampStart.ToRemoteDateTime(dto.Telemetry?.TimeZone?.Hours ?? 0); + return dto; + } } } diff --git a/AsbCloudInfrastructure/Services/DrillTestReport/DrillTestReportService.cs b/AsbCloudInfrastructure/Services/DrillTestReport/DrillTestReportService.cs index 6784ad26..983d1f7c 100644 --- a/AsbCloudInfrastructure/Services/DrillTestReport/DrillTestReportService.cs +++ b/AsbCloudInfrastructure/Services/DrillTestReport/DrillTestReportService.cs @@ -82,11 +82,11 @@ namespace AsbCloudInfrastructure.Services.DrillTestReport reports.Add(new DrillTestReportInfoDto { - FileName = string.Format("Drill_test_{0}", remoteDateTime), + FileName = string.Format("Drill_test_{0}", dto.TimeStampStart.DateTime), DrillDepth = (dto.Params .Where(p => p.DepthDrillStep.HasValue) .Sum(x => x.DepthDrillStep) ?? 0) + dto.DepthStart, - DateTime = remoteDateTime, + DateTime = dto.TimeStampStart.DateTime, Id = dto.Id, }); } diff --git a/AsbCloudWebApi/Middlewares/SimplifyExceptionsMiddleware.cs b/AsbCloudWebApi/Middlewares/SimplifyExceptionsMiddleware.cs index 0bdf0683..3b3f052a 100644 --- a/AsbCloudWebApi/Middlewares/SimplifyExceptionsMiddleware.cs +++ b/AsbCloudWebApi/Middlewares/SimplifyExceptionsMiddleware.cs @@ -56,10 +56,7 @@ namespace AsbCloudWebApi.Middlewares private static string MakeJsonBody(ArgumentInvalidException ex) { - var errors = new Dictionary() { - { string.Join(", ", ex.ParamsNames), new[]{ ex.Message } } - }; - var problem = new ValidationProblemDetails(errors); + var problem = new ValidationProblemDetails(ex.ParamsNames); var buffer = System.Text.Json.JsonSerializer.Serialize(problem); return buffer; } diff --git a/AsbCloudWebApi/Rest/DrillTest.http b/AsbCloudWebApi/Rest/DrillTest.http index 47d7db66..a5348ead 100644 --- a/AsbCloudWebApi/Rest/DrillTest.http +++ b/AsbCloudWebApi/Rest/DrillTest.http @@ -13,7 +13,7 @@ Content-Type: {{contentType}} accept: */* { - "id": @id, + "id": {{id}}, "timeStampStart": "2023-10-23T08:55:36.882Z", "depthStart": 10, "params": [ From f234dc11429a0a4d1c1f7df7a5d1dcf732b717b2 Mon Sep 17 00:00:00 2001 From: Olga Nemt Date: Mon, 23 Oct 2023 16:45:49 +0500 Subject: [PATCH 10/10] =?UTF-8?q?ParamsNames=20=D0=BF=D0=B5=D1=80=D0=B5?= =?UTF-8?q?=D0=B8=D0=BC=D0=B5=D0=BD=D0=BE=D0=B2=D0=B0=D0=BD=20=D0=B2=20Err?= =?UTF-8?q?orState,=20=D0=BF=D1=80=D0=B0=D0=B2=D0=BA=D0=B0=20=D0=BF=D0=BE?= =?UTF-8?q?=20=D1=80=D0=B5=D0=B2=D1=8C=D1=8E=20=20-=203?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- AsbCloudApp/Exceptions/ArgumentInvalidException.cs | 11 +++++------ .../Middlewares/SimplifyExceptionsMiddleware.cs | 2 +- 2 files changed, 6 insertions(+), 7 deletions(-) diff --git a/AsbCloudApp/Exceptions/ArgumentInvalidException.cs b/AsbCloudApp/Exceptions/ArgumentInvalidException.cs index f5e3f3cd..5db63313 100644 --- a/AsbCloudApp/Exceptions/ArgumentInvalidException.cs +++ b/AsbCloudApp/Exceptions/ArgumentInvalidException.cs @@ -1,5 +1,6 @@ using System; using System.Collections.Generic; +using System.Linq; namespace AsbCloudApp.Exceptions { @@ -9,9 +10,9 @@ namespace AsbCloudApp.Exceptions public class ArgumentInvalidException : Exception { /// - /// название аргумента + /// словарь с ошибками, где ключ - имя аргумента, а значение - массив из одного сообщения /// - public IDictionary ParamsNames { get; } = null!; + public IDictionary ErrorState { get; } = null!; /// /// конструктор @@ -21,7 +22,7 @@ namespace AsbCloudApp.Exceptions public ArgumentInvalidException(string paramName, string message) : base(message) { - ParamsNames = new Dictionary() { + ErrorState = new Dictionary() { { paramName, new[]{ message } } }; } @@ -34,9 +35,7 @@ namespace AsbCloudApp.Exceptions public ArgumentInvalidException(string[] paramsNames, string message) : base(message) { - ParamsNames = new Dictionary() { - { string.Join(", ", paramsNames), new[]{ message } } - }; + ErrorState = paramsNames.ToDictionary(paramName => paramName, item => new[] { message }); } } } diff --git a/AsbCloudWebApi/Middlewares/SimplifyExceptionsMiddleware.cs b/AsbCloudWebApi/Middlewares/SimplifyExceptionsMiddleware.cs index 3b3f052a..3c444b4a 100644 --- a/AsbCloudWebApi/Middlewares/SimplifyExceptionsMiddleware.cs +++ b/AsbCloudWebApi/Middlewares/SimplifyExceptionsMiddleware.cs @@ -56,7 +56,7 @@ namespace AsbCloudWebApi.Middlewares private static string MakeJsonBody(ArgumentInvalidException ex) { - var problem = new ValidationProblemDetails(ex.ParamsNames); + var problem = new ValidationProblemDetails(ex.ErrorState); var buffer = System.Text.Json.JsonSerializer.Serialize(problem); return buffer; }