From 853a5fde835980d116f0ddfa2454f6933dde94dd Mon Sep 17 00:00:00 2001 From: Olga Nemt Date: Fri, 16 Feb 2024 12:02:54 +0500 Subject: [PATCH 1/5] =?UTF-8?q?=D0=AD=D0=BA=D1=81=D0=BF=D0=BE=D1=80=D1=82?= =?UTF-8?q?=20=D0=BD=D0=BE=D0=B2=D0=BE=D0=B3=D0=BE=20=D0=A0=D0=A2=D0=9A-?= =?UTF-8?q?=D0=BE=D1=82=D1=87=D0=B5=D1=82=D0=B0=20=D0=B2=20=D1=8D=D0=BA?= =?UTF-8?q?=D1=81=D0=B5=D0=BB=D1=8C?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../AsbCloudInfrastructure.csproj | 2 + AsbCloudInfrastructure/DependencyInjection.cs | 1 + ...ocessMapReportDataSaubStatExportService.cs | 260 ++++++++++++++++++ .../ProcessMapReportDataSaubStatTemplate.xlsx | Bin 0 -> 13706 bytes AsbCloudInfrastructure/XLExtentions.cs | 12 +- .../ProcessMapWellDrillingController.cs | 10 +- 6 files changed, 278 insertions(+), 7 deletions(-) create mode 100644 AsbCloudInfrastructure/Services/ProcessMaps/Report/ProcessMapReportDataSaubStatExportService.cs create mode 100644 AsbCloudInfrastructure/Services/ProcessMaps/Report/ProcessMapReportDataSaubStatTemplate.xlsx diff --git a/AsbCloudInfrastructure/AsbCloudInfrastructure.csproj b/AsbCloudInfrastructure/AsbCloudInfrastructure.csproj index cdb57ae5..05875bb8 100644 --- a/AsbCloudInfrastructure/AsbCloudInfrastructure.csproj +++ b/AsbCloudInfrastructure/AsbCloudInfrastructure.csproj @@ -14,6 +14,7 @@ + @@ -36,6 +37,7 @@ + diff --git a/AsbCloudInfrastructure/DependencyInjection.cs b/AsbCloudInfrastructure/DependencyInjection.cs index 5e1ea903..f1e3c84d 100644 --- a/AsbCloudInfrastructure/DependencyInjection.cs +++ b/AsbCloudInfrastructure/DependencyInjection.cs @@ -202,6 +202,7 @@ namespace AsbCloudInfrastructure services.AddScoped(); services.AddTransient(); services.AddTransient(); + services.AddTransient(); services.AddTransient(); services.AddTransient(); services.AddTransient(); diff --git a/AsbCloudInfrastructure/Services/ProcessMaps/Report/ProcessMapReportDataSaubStatExportService.cs b/AsbCloudInfrastructure/Services/ProcessMaps/Report/ProcessMapReportDataSaubStatExportService.cs new file mode 100644 index 00000000..1bee0843 --- /dev/null +++ b/AsbCloudInfrastructure/Services/ProcessMaps/Report/ProcessMapReportDataSaubStatExportService.cs @@ -0,0 +1,260 @@ +using AsbCloudApp.Data.ProcessMaps.Report; +using AsbCloudApp.Requests; +using AsbCloudApp.Services; +using AsbCloudApp.Services.ProcessMaps.WellDrilling; +using ClosedXML.Excel; +using System; +using System.Collections.Generic; +using System.IO; +using System.Reflection; +using System.Threading; +using System.Threading.Tasks; + +namespace AsbCloudInfrastructure.Services.ProcessMaps.Report +{ + public class ProcessMapReportDataSaubStatExportService : IProcessMapReportWellDrillingExportService + { + const int firstColumn = 2; + const int lastColumn = 35; + + const int headerRowsCount = 5; + + private readonly IWellService wellService; + private readonly IProcessMapReportDataSaubStatService processMapReportDataSaubStatService; + private readonly string TemplateName = "ProcessMapReportDataSaubStatTemplate.xlsx"; + + public ProcessMapReportDataSaubStatExportService(IWellService wellService, + IProcessMapReportDataSaubStatService processMapReportDataSaubStatService) + { + this.wellService = wellService; + this.processMapReportDataSaubStatService = processMapReportDataSaubStatService; + } + + public async Task<(string Name, Stream File)?> ExportAsync(int idWell, CancellationToken cancellationToken) + { + var well = await wellService.GetOrDefaultAsync(idWell, cancellationToken); + + if (well is null) + return null; + + var stream = Assembly.GetExecutingAssembly().GetTemplateCopyStream(TemplateName); + using var workbook = new XLWorkbook(stream); + + var request = new DataSaubStatRequest(); + var data = await processMapReportDataSaubStatService.GetAsync(idWell, request, cancellationToken); + + FillProcessMapToWorkbook(workbook, data); + + MemoryStream memoryStream = new(); + workbook.SaveAs(memoryStream, new SaveOptions { }); + memoryStream.Seek(0, SeekOrigin.Begin); + + var name = $"РТК бурение. Отчёт по скважине {well.Caption} куст {well.Cluster}.xlsx"; + + return (name, memoryStream); + } + + private static void FillProcessMapToWorkbook(XLWorkbook workbook, + IEnumerable data) + { + const string sheetName = "Отчёт"; + + var sheet = workbook.GetWorksheet(sheetName); + + var startRow = headerRowsCount + 1; + foreach (var item in data) + { + startRow = FillRow(sheet, item, startRow); + } + } + + + private static int FillRow(IXLWorksheet sheet, ProcessMapReportDataSaubStatDto item, + int startRow) + { + var endRow = FillIntervalData(sheet, item, startRow); + + var sectionStyle = sheet.Range(startRow, firstColumn, endRow - 1, lastColumn).Style; + SetStyle(sectionStyle); + return endRow; + } + + private static int FillIntervalData(IXLWorksheet sheet, ProcessMapReportDataSaubStatDto interval, int row) + { + const int columnSection = firstColumn + 1; + const int columnDepthStart = firstColumn + 2; + const int columnDepthEnd = firstColumn + 3; + const int columnDeltaDepth = firstColumn + 4; + const int columnDrilledTime = firstColumn + 5; + const int columnMode = firstColumn + 6; + + double? deltaDepth = interval.DeltaDepth.HasValue + ? Math.Round(interval.DeltaDepth.Value, 1) + : null; + + sheet.Cell(row, firstColumn).SetCellValue(interval.DateStart, "DD.MM.YYYY HH:MM"); + sheet.Cell(row, columnSection).SetCellValue(interval.WellSectionTypeName); + sheet.Cell(row, columnDepthStart).SetCellValue(Math.Round(interval.DepthStart, 2)); + sheet.Cell(row, columnDepthEnd).SetCellValue(Math.Round(interval.DepthEnd, 2)); + sheet.Cell(row, columnDeltaDepth).SetCellValue(deltaDepth); + sheet.Cell(row, columnDrilledTime).SetCellValue(Math.Round(interval.DrilledTime, 2)); + sheet.Cell(row, columnMode).SetCellValue(interval.DrillingMode); + + row = FillIntervalModeData(sheet, interval, columnMode, row); + + return row; + } + + private static int FillIntervalModeData(IXLWorksheet sheet, ProcessMapReportDataSaubStatDto modeData, + int column, int row) + { + int columnPressure = column + 1; + int columnLoad = columnPressure + 5; + int columnTorque = columnLoad + 5; + int columnSpeed = columnTorque + 5; + int columnTopDriveSpeed = columnSpeed + 4; + int columnFlow = columnTopDriveSpeed + 2; + int columnRopPlan = columnFlow + 3; + int columnRopFact = columnRopPlan + 1; + + FillIntervalModeDataParam(sheet, modeData.PressureDiff, columnPressure, row); + FillIntervalModeDataParam(sheet, modeData.AxialLoad, columnLoad, row); + FillIntervalModeDataParam(sheet, modeData.TopDriveTorque, columnTorque, row); + FillIntervalModeDataSpeed(sheet, modeData.SpeedLimit, columnSpeed, row); + FillIntervalModeTopDriveSpeed(sheet, modeData.TopDriveSpeed, columnTopDriveSpeed, row); + FillIntervalModeFlow(sheet, modeData.Flow, columnFlow, row); + + double? ropPlan = modeData.Rop.Plan.HasValue + ? Math.Round(modeData.Rop.Plan.Value, 1) + : null; + + double? ropFact = modeData.Rop.Fact.HasValue + ? Math.Round(modeData.Rop.Fact.Value, 1) + : null; + + sheet.Cell(row, columnRopPlan).SetCellValue(ropPlan); + sheet.Cell(row, columnRopFact).SetCellValue(ropFact); + + return row + 1; + } + + private static void FillIntervalModeDataParam(IXLWorksheet sheet, + ProcessMapReportDataSaubStatParamsDto dataParam, int column, int row) + { + const int columnOffsetSpPlan = 0; + const int columnOffsetSpFact = 1; + const int columnOffsetFact = 2; + const int columnOffsetLimit = 3; + const int columnOffsetPercent = 4; + + double? setpointPlan = dataParam.SetpointPlan.HasValue + ? Math.Round(dataParam.SetpointPlan.Value) + : null; + + double? setpointFact = dataParam.SetpointFact.HasValue + ? Math.Round(dataParam.SetpointFact.Value, 1) + : null; + + double? factWavg = dataParam.FactWavg.HasValue + ? Math.Round(dataParam.FactWavg.Value, 1) + : null; + + double? limit = dataParam.Limit.HasValue + ? Math.Round(dataParam.Limit.Value, 1) + : null; + + double? setpointUsage = dataParam.SetpointUsage.HasValue + ? Math.Round(dataParam.SetpointUsage.Value, 1) + : null; + + sheet.Cell(row, column + columnOffsetSpPlan).SetCellValue(setpointPlan); + sheet.Cell(row, column + columnOffsetSpFact).SetCellValue(setpointFact); + sheet.Cell(row, column + columnOffsetFact).SetCellValue(factWavg); + sheet.Cell(row, column + columnOffsetLimit).SetCellValue(limit); + sheet.Cell(row, column + columnOffsetPercent).SetCellValue(setpointUsage); + } + + private static void FillIntervalModeDataSpeed(IXLWorksheet sheet, + ProcessMapReportDataSaubStatParamsDto dataParam, int column, int row) + { + const int columnOffsetSpPlan = 0; + const int columnOffsetSpFact = 1; + const int columnOffsetFact = 2; + const int columnOffsetPercent = 3; + + double? setpointPlan = dataParam.SetpointPlan.HasValue + ? Math.Round(dataParam.SetpointPlan.Value) + : null; + + double? setpointFact = dataParam.SetpointFact.HasValue + ? Math.Round(dataParam.SetpointFact.Value, 1) + : null; + + double? factWavg = dataParam.FactWavg.HasValue + ? Math.Round(dataParam.FactWavg.Value, 1) + : null; + + double? setpointUsage = dataParam.SetpointUsage.HasValue + ? Math.Round(dataParam.SetpointUsage.Value, 1) + : null; + + sheet.Cell(row, column + columnOffsetSpPlan).SetCellValue(setpointPlan); + sheet.Cell(row, column + columnOffsetSpFact).SetCellValue(setpointFact); + sheet.Cell(row, column + columnOffsetFact).SetCellValue(factWavg); + sheet.Cell(row, column + columnOffsetPercent).SetCellValue(setpointUsage); + } + + private static void FillIntervalModeTopDriveSpeed(IXLWorksheet sheet, + ProcessMapReportDataSaubStatParamsDto dataParam, int column, int row) + { + const int columnOffsetSpPlan = 0; + const int columnOffsetFact = 1; + + double? setpointPlan = dataParam.SetpointPlan.HasValue + ? Math.Round(dataParam.SetpointPlan.Value) + : null; + + double? factWavg = dataParam.FactWavg.HasValue + ? Math.Round(dataParam.FactWavg.Value, 1) + : null; + + sheet.Cell(row, column + columnOffsetSpPlan).SetCellValue(setpointPlan); + sheet.Cell(row, column + columnOffsetFact).SetCellValue(factWavg); + } + + private static void FillIntervalModeFlow(IXLWorksheet sheet, + ProcessMapReportDataSaubStatParamsDto dataParam, int column, int row) + { + const int columnOffsetSpPlan = 0; + const int columnOffsetFact = 1; + const int columnOffsetLimit = 2; + + double? setpointPlan = dataParam.SetpointPlan.HasValue + ? Math.Round(dataParam.SetpointPlan.Value) + : null; + + double? factWavg = dataParam.FactWavg.HasValue + ? Math.Round(dataParam.FactWavg.Value, 1) + : null; + + double? limit = dataParam.Limit.HasValue + ? Math.Round(dataParam.Limit.Value, 1) + : null; + + sheet.Cell(row, column + columnOffsetSpPlan).SetCellValue(setpointPlan); + sheet.Cell(row, column + columnOffsetFact).SetCellValue(factWavg); + sheet.Cell(row, column + columnOffsetLimit).SetCellValue(limit); + } + + private static void SetStyle(IXLStyle style) + { + style.Border.RightBorder = XLBorderStyleValues.Thin; + style.Border.LeftBorder = XLBorderStyleValues.Thin; + style.Border.TopBorder = XLBorderStyleValues.Thin; + style.Border.BottomBorder = XLBorderStyleValues.Thin; + style.Border.InsideBorder = XLBorderStyleValues.Thin; + + style.Alignment.Horizontal = XLAlignmentHorizontalValues.Center; + } + } +} diff --git a/AsbCloudInfrastructure/Services/ProcessMaps/Report/ProcessMapReportDataSaubStatTemplate.xlsx b/AsbCloudInfrastructure/Services/ProcessMaps/Report/ProcessMapReportDataSaubStatTemplate.xlsx new file mode 100644 index 0000000000000000000000000000000000000000..063659a8904edcc60a1524644693efa883caf04d GIT binary patch literal 13706 zcmeHucT`i`)~_gvsEBj{1ql+2O51?a0xAR*A|O?zLkPWv-c?XK7(^gcMG+!RL3)!O zdfBu90R;h3LNA8;!MXRldc5bHckcV+jq%2~Gb72&FLSMxJ?GqOtvT{rYRU(wnfDz& ze0X1upxT{%KgrQu-4J7D<0K@w_nIA5tx_v|?D3pe$oVyK(v`z6UY8+nl<|mheK>2! zSrGiP&VO-Lfr;^0cwTLUqp#n#N!kd~?&63rRM{X{>u&J=3aF`1dR@!5qleI?wp8B+ z28rwH_VVX3k*Z3|t)H$ozw&Z^qIBfT(kih$tb-E7p2H*9m0IWQ@Kl75WYsUertu>Md7Yx$ZDtm+4h>tb8TU0 zoyHJpFSYoa4A|#WOf(8mC+H;xigRqS>6nE)LZyWH1eVDHBkm_IeWT!3+OU+n;g_K3 zh8~R$@G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#=!sL{FaBlbLAwl96nhkm=RPksCD$L{{>-4*!%a9z6c_IA!@cFu;H9u8(s`g_+^ z5#6$Trs4!*Z7YPJ%Uovm;Dpl9!AL&M)GX{f{$R_^C*+vbIow$_Exz}f;dkyXv{sm- zO{5cYT%KippfPKU3;XiqtWm(TW@ghx!0$$GlQTe=uh#r?EPH zGVF7oHP-^j*6R4~>nP4@#rkR~-X?wyP%m*FQRC>v z$Afd^<}PWVUcKj5W6`nYjO}CDcCO_oj@}g;*EMYv8ea9-g^P`LdyVCuP3xipj zPG%AF^23@Z)?Z(K?f0defx7SF%jD33b?$^KO>n~0mxcHh*&zKnUYGZcc55=5jSO`) z<|C!|h5Q4-vYpA^uRSjqzGocYSr=f)?%=xI8h^@O z{&kE%D$RFuujk-ioT&CQ@B4A;<>!MQd#7H0FF&1u`L*HCwEn$wAU}kEcc@=Zh5Xw1 zXHxDS^Z$onc25cHHvVxA;Mb-<@B8*xyFX-s=3nFf8;AGTUVdJ;_x6ZCq-mEYy!Qis z-7)^!!_Vv6-unJSR4@M4!=J47zxMO(this IXLCell cell, T value, string format) + { + if (typeof(T) == typeof(DateTime)) + cell.Style.DateFormat.Format = format; + + cell.Value = XLCellValue.FromObject(value); + + return cell; + } + + public static IXLCell SetHyperlink(this IXLCell cell, string link) { cell.SetHyperlink(new XLHyperlink(link)); diff --git a/AsbCloudWebApi/Controllers/ProcessMaps/ProcessMapWellDrillingController.cs b/AsbCloudWebApi/Controllers/ProcessMaps/ProcessMapWellDrillingController.cs index 857e4a68..9b189e87 100644 --- a/AsbCloudWebApi/Controllers/ProcessMaps/ProcessMapWellDrillingController.cs +++ b/AsbCloudWebApi/Controllers/ProcessMaps/ProcessMapWellDrillingController.cs @@ -24,9 +24,8 @@ namespace AsbCloudWebApi.Controllers.ProcessMaps; /// public class ProcessMapWellDrillingController : ProcessMapBaseController { - private readonly IProcessMapReportWellDrillingService processMapReportWellDrillingService; private readonly IProcessMapReportDataSaubStatService processMapReportDataSaubStatService; - private readonly IProcessMapReportWellDrillingExportService processMapReportWellDrillingExportService; + private readonly IProcessMapReportWellDrillingExportService processMapReportDataSaubStatExportService; private readonly IProcessMapPlanImportService processMapPlanImportService; protected override string SignalRGroup => "ProcessMapWellDrilling"; @@ -34,7 +33,7 @@ public class ProcessMapWellDrillingController : ProcessMapBaseController repository, IUserRepository userRepository, - IProcessMapReportWellDrillingExportService processMapReportWellDrillingExportService, + IProcessMapReportWellDrillingExportService processMapReportDataSaubStatExportService, IProcessMapPlanImportService processMapPlanImportService, IProcessMapReportWellDrillingService processMapReportWellDrillingService, IProcessMapReportDataSaubStatService processMapReportDataSaubStatService, @@ -44,10 +43,9 @@ public class ProcessMapWellDrillingController : ProcessMapBaseController service) : base(wellService, repository, userRepository, wellSectionRepository, telemetryHubContext, telemetryService, service) { - this.processMapReportWellDrillingExportService = processMapReportWellDrillingExportService; + this.processMapReportDataSaubStatExportService = processMapReportDataSaubStatExportService; this.processMapPlanImportService = processMapPlanImportService; this.processMapReportDataSaubStatService = processMapReportDataSaubStatService; - this.processMapReportWellDrillingService = processMapReportWellDrillingService; } /// @@ -77,7 +75,7 @@ public class ProcessMapWellDrillingController : ProcessMapBaseController ExportReportAsync(int idWell, CancellationToken cancellationToken) { - var report = await processMapReportWellDrillingExportService.ExportAsync(idWell, cancellationToken); + var report = await processMapReportDataSaubStatExportService.ExportAsync(idWell, cancellationToken); if (report is null) return NoContent(); From 30d8632dd7294db2ea5fd01f4a65b3e6cddeca04 Mon Sep 17 00:00:00 2001 From: Olga Nemt Date: Fri, 16 Feb 2024 12:07:30 +0500 Subject: [PATCH 2/5] =?UTF-8?q?=D0=A3=D0=B1=D1=80=D0=B0=D0=BD=D0=BE=20?= =?UTF-8?q?=D0=BB=D0=B8=D1=88=D0=BD=D0=B5=D0=B5=20=D0=B8=D0=B7=20=D0=BA?= =?UTF-8?q?=D0=BE=D0=BD=D1=82=D1=80=D0=BE=D0=BB=D0=BB=D0=B5=D1=80=D0=B0=20?= =?UTF-8?q?ProcessMapWellDrillingController?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Controllers/ProcessMaps/ProcessMapWellDrillingController.cs | 1 - 1 file changed, 1 deletion(-) diff --git a/AsbCloudWebApi/Controllers/ProcessMaps/ProcessMapWellDrillingController.cs b/AsbCloudWebApi/Controllers/ProcessMaps/ProcessMapWellDrillingController.cs index 9b189e87..c50c5bb9 100644 --- a/AsbCloudWebApi/Controllers/ProcessMaps/ProcessMapWellDrillingController.cs +++ b/AsbCloudWebApi/Controllers/ProcessMaps/ProcessMapWellDrillingController.cs @@ -35,7 +35,6 @@ public class ProcessMapWellDrillingController : ProcessMapBaseController wellSectionRepository, IHubContext telemetryHubContext, From 9b5bc227b0f192000c042b79381281bc05cd65bc Mon Sep 17 00:00:00 2001 From: Olga Nemt Date: Fri, 16 Feb 2024 15:21:01 +0500 Subject: [PATCH 3/5] =?UTF-8?q?=D0=9F=D1=80=D0=B0=D0=B2=D0=BA=D0=B8=20?= =?UTF-8?q?=D0=BF=D0=BE=D1=81=D0=BB=D0=B5=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 --- ...ocessMapReportDataSaubStatExportService.cs | 26 +++++++++ AsbCloudInfrastructure/DependencyInjection.cs | 2 +- ...ocessMapReportDataSaubStatExportService.cs | 5 +- AsbCloudInfrastructure/XLExtentions.cs | 58 ++++++++----------- 4 files changed, 54 insertions(+), 37 deletions(-) create mode 100644 AsbCloudApp/Services/ProcessMaps/WellDrilling/IProcessMapReportDataSaubStatExportService.cs diff --git a/AsbCloudApp/Services/ProcessMaps/WellDrilling/IProcessMapReportDataSaubStatExportService.cs b/AsbCloudApp/Services/ProcessMaps/WellDrilling/IProcessMapReportDataSaubStatExportService.cs new file mode 100644 index 00000000..2f36fed0 --- /dev/null +++ b/AsbCloudApp/Services/ProcessMaps/WellDrilling/IProcessMapReportDataSaubStatExportService.cs @@ -0,0 +1,26 @@ +using AsbCloudApp.Requests; +using System; +using System.Collections.Generic; +using System.IO; +using System.Linq; +using System.Text; +using System.Threading; +using System.Threading.Tasks; + +namespace AsbCloudApp.Services.ProcessMaps.WellDrilling +{ + /// + /// Сервис экспорт РТК + /// + public interface IProcessMapReportDataSaubStatExportService + { + /// + /// Сформировать файл с данными + /// + /// + /// параметры запроса + /// + /// + Task<(string Name, Stream File)?> ExportAsync(int idWell, DataSaubStatRequest request, CancellationToken cancellationToken); + } +} diff --git a/AsbCloudInfrastructure/DependencyInjection.cs b/AsbCloudInfrastructure/DependencyInjection.cs index f1e3c84d..f4c62479 100644 --- a/AsbCloudInfrastructure/DependencyInjection.cs +++ b/AsbCloudInfrastructure/DependencyInjection.cs @@ -202,7 +202,7 @@ namespace AsbCloudInfrastructure services.AddScoped(); services.AddTransient(); services.AddTransient(); - services.AddTransient(); + services.AddTransient(); services.AddTransient(); services.AddTransient(); services.AddTransient(); diff --git a/AsbCloudInfrastructure/Services/ProcessMaps/Report/ProcessMapReportDataSaubStatExportService.cs b/AsbCloudInfrastructure/Services/ProcessMaps/Report/ProcessMapReportDataSaubStatExportService.cs index 1bee0843..6f9fa9a3 100644 --- a/AsbCloudInfrastructure/Services/ProcessMaps/Report/ProcessMapReportDataSaubStatExportService.cs +++ b/AsbCloudInfrastructure/Services/ProcessMaps/Report/ProcessMapReportDataSaubStatExportService.cs @@ -12,7 +12,7 @@ using System.Threading.Tasks; namespace AsbCloudInfrastructure.Services.ProcessMaps.Report { - public class ProcessMapReportDataSaubStatExportService : IProcessMapReportWellDrillingExportService + public class ProcessMapReportDataSaubStatExportService : IProcessMapReportDataSaubStatExportService { const int firstColumn = 2; const int lastColumn = 35; @@ -30,7 +30,7 @@ namespace AsbCloudInfrastructure.Services.ProcessMaps.Report this.processMapReportDataSaubStatService = processMapReportDataSaubStatService; } - public async Task<(string Name, Stream File)?> ExportAsync(int idWell, CancellationToken cancellationToken) + public async Task<(string Name, Stream File)?> ExportAsync(int idWell, DataSaubStatRequest request, CancellationToken cancellationToken) { var well = await wellService.GetOrDefaultAsync(idWell, cancellationToken); @@ -40,7 +40,6 @@ namespace AsbCloudInfrastructure.Services.ProcessMaps.Report var stream = Assembly.GetExecutingAssembly().GetTemplateCopyStream(TemplateName); using var workbook = new XLWorkbook(stream); - var request = new DataSaubStatRequest(); var data = await processMapReportDataSaubStatService.GetAsync(idWell, request, cancellationToken); FillProcessMapToWorkbook(workbook, data); diff --git a/AsbCloudInfrastructure/XLExtentions.cs b/AsbCloudInfrastructure/XLExtentions.cs index 5b9517e4..b15fa71f 100644 --- a/AsbCloudInfrastructure/XLExtentions.cs +++ b/AsbCloudInfrastructure/XLExtentions.cs @@ -7,24 +7,16 @@ namespace AsbCloudInfrastructure; public static class XLExtentions { - public static IXLWorksheet GetWorksheet(this IXLWorkbook workbook, string sheetName) => - workbook.Worksheets.FirstOrDefault(ws => string.Equals(ws.Name.Trim(), sheetName.Trim(), StringComparison.CurrentCultureIgnoreCase)) - ?? throw new FileFormatException($"Книга excel не содержит листа {sheetName}."); + public static IXLWorksheet GetWorksheet(this IXLWorkbook workbook, string sheetName) => + workbook.Worksheets.FirstOrDefault(ws => string.Equals(ws.Name.Trim(), sheetName.Trim(), StringComparison.CurrentCultureIgnoreCase)) + ?? throw new FileFormatException($"Книга excel не содержит листа {sheetName}."); - public static IXLCell SetCellValue(this IXLCell cell, T value) - { - if (typeof(T) == typeof(DateTime)) - cell.Style.DateFormat.Format = "DD.MM.YYYY HH:MM:SS"; - - cell.Value = XLCellValue.FromObject(value); - - return cell; - } - - public static IXLCell SetCellValue(this IXLCell cell, T value, string format) + public static IXLCell SetCellValue(this IXLCell cell, T value, string? format = null) { if (typeof(T) == typeof(DateTime)) - cell.Style.DateFormat.Format = format; + { + cell.Style.DateFormat.Format = format ?? "DD.MM.YYYY HH:MM:SS"; + } cell.Value = XLCellValue.FromObject(value); @@ -32,25 +24,25 @@ public static class XLExtentions } public static IXLCell SetHyperlink(this IXLCell cell, string link) - { - cell.SetHyperlink(new XLHyperlink(link)); + { + cell.SetHyperlink(new XLHyperlink(link)); - return cell; - } + return cell; + } - public static T? GetCellValue(this IXLCell cell) - { - try - { - if (cell.IsEmpty() && default(T) == null) - return default; + public static T? GetCellValue(this IXLCell cell) + { + try + { + if (cell.IsEmpty() && default(T) == null) + return default; - return cell.GetValue(); - } - catch - { - throw new FileFormatException( - $"Лист '{cell.Worksheet.Name}'. {cell.Address.RowNumber} строка содержит некорректное значение в {cell.Address.ColumnNumber} столбце"); - } - } + return cell.GetValue(); + } + catch + { + throw new FileFormatException( + $"Лист '{cell.Worksheet.Name}'. {cell.Address.RowNumber} строка содержит некорректное значение в {cell.Address.ColumnNumber} столбце"); + } + } } \ No newline at end of file From 87d46f08e60b2d39b631b382659e415df4367d70 Mon Sep 17 00:00:00 2001 From: Olga Nemt Date: Fri, 16 Feb 2024 15:22:05 +0500 Subject: [PATCH 4/5] =?UTF-8?q?=D0=9F=D1=80=D0=B0=D0=B2=D0=BA=D0=B8=20?= =?UTF-8?q?=D0=BF=D0=BE=D1=81=D0=BB=D0=B5=20=D1=80=D0=B5=D0=B2=D1=8C=D1=8E?= =?UTF-8?q?=20(=D0=BF=D1=83=D1=88=20=D0=BD=D0=B5=D0=B4=D0=BE=D1=81=D1=82?= =?UTF-8?q?=D0=B0=D1=8E=D1=89=D0=B5=D0=B3=D0=BE)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../ProcessMaps/ProcessMapWellDrillingController.cs | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/AsbCloudWebApi/Controllers/ProcessMaps/ProcessMapWellDrillingController.cs b/AsbCloudWebApi/Controllers/ProcessMaps/ProcessMapWellDrillingController.cs index c50c5bb9..55657882 100644 --- a/AsbCloudWebApi/Controllers/ProcessMaps/ProcessMapWellDrillingController.cs +++ b/AsbCloudWebApi/Controllers/ProcessMaps/ProcessMapWellDrillingController.cs @@ -25,7 +25,7 @@ namespace AsbCloudWebApi.Controllers.ProcessMaps; public class ProcessMapWellDrillingController : ProcessMapBaseController { private readonly IProcessMapReportDataSaubStatService processMapReportDataSaubStatService; - private readonly IProcessMapReportWellDrillingExportService processMapReportDataSaubStatExportService; + private readonly IProcessMapReportDataSaubStatExportService processMapReportDataSaubStatExportService; private readonly IProcessMapPlanImportService processMapPlanImportService; protected override string SignalRGroup => "ProcessMapWellDrilling"; @@ -33,7 +33,7 @@ public class ProcessMapWellDrillingController : ProcessMapBaseController repository, IUserRepository userRepository, - IProcessMapReportWellDrillingExportService processMapReportDataSaubStatExportService, + IProcessMapReportDataSaubStatExportService processMapReportDataSaubStatExportService, IProcessMapPlanImportService processMapPlanImportService, IProcessMapReportDataSaubStatService processMapReportDataSaubStatService, ICrudRepository wellSectionRepository, @@ -67,14 +67,15 @@ public class ProcessMapWellDrillingController : ProcessMapBaseController /// Id скважины + /// Параметры запроса /// /// [HttpGet("report/export")] [ProducesResponseType(typeof(PhysicalFileResult), StatusCodes.Status200OK, "application/octet-stream")] [ProducesResponseType(StatusCodes.Status204NoContent)] - public async Task ExportReportAsync(int idWell, CancellationToken cancellationToken) + public async Task ExportReportAsync(int idWell, [FromQuery] DataSaubStatRequest request, CancellationToken cancellationToken) { - var report = await processMapReportDataSaubStatExportService.ExportAsync(idWell, cancellationToken); + var report = await processMapReportDataSaubStatExportService.ExportAsync(idWell, request, cancellationToken); if (report is null) return NoContent(); From 11873c676471161338c8ae34bd2d536af6477f3b Mon Sep 17 00:00:00 2001 From: ngfrolov Date: Fri, 16 Feb 2024 16:22:06 +0500 Subject: [PATCH 5/5] ProcessMapReportDataSaubStatExportService nit --- ...ocessMapReportDataSaubStatExportService.cs | 471 +++++++++--------- .../ProcessMapWellDrillingController.cs | 4 + 2 files changed, 237 insertions(+), 238 deletions(-) diff --git a/AsbCloudInfrastructure/Services/ProcessMaps/Report/ProcessMapReportDataSaubStatExportService.cs b/AsbCloudInfrastructure/Services/ProcessMaps/Report/ProcessMapReportDataSaubStatExportService.cs index 6f9fa9a3..286ec122 100644 --- a/AsbCloudInfrastructure/Services/ProcessMaps/Report/ProcessMapReportDataSaubStatExportService.cs +++ b/AsbCloudInfrastructure/Services/ProcessMaps/Report/ProcessMapReportDataSaubStatExportService.cs @@ -10,250 +10,245 @@ using System.Reflection; using System.Threading; using System.Threading.Tasks; -namespace AsbCloudInfrastructure.Services.ProcessMaps.Report +namespace AsbCloudInfrastructure.Services.ProcessMaps.Report; + +public class ProcessMapReportDataSaubStatExportService : IProcessMapReportDataSaubStatExportService { - public class ProcessMapReportDataSaubStatExportService : IProcessMapReportDataSaubStatExportService + private const int firstColumn = 2; + private const int lastColumn = 35; + private const int headerRowsCount = 5; + private const string TemplateName = "ProcessMapReportDataSaubStatTemplate.xlsx"; + private const string sheetName = "Отчёт"; + + private readonly IWellService wellService; + private readonly IProcessMapReportDataSaubStatService processMapReportDataSaubStatService; + + public ProcessMapReportDataSaubStatExportService(IWellService wellService, + IProcessMapReportDataSaubStatService processMapReportDataSaubStatService) { - const int firstColumn = 2; - const int lastColumn = 35; + this.wellService = wellService; + this.processMapReportDataSaubStatService = processMapReportDataSaubStatService; + } - const int headerRowsCount = 5; + public async Task<(string Name, Stream File)?> ExportAsync(int idWell, DataSaubStatRequest request, CancellationToken cancellationToken) + { + var well = await wellService.GetOrDefaultAsync(idWell, cancellationToken); - private readonly IWellService wellService; - private readonly IProcessMapReportDataSaubStatService processMapReportDataSaubStatService; - private readonly string TemplateName = "ProcessMapReportDataSaubStatTemplate.xlsx"; + if (well is null) + return null; - public ProcessMapReportDataSaubStatExportService(IWellService wellService, - IProcessMapReportDataSaubStatService processMapReportDataSaubStatService) + var stream = Assembly.GetExecutingAssembly().GetTemplateCopyStream(TemplateName); + using var workbook = new XLWorkbook(stream); + + var data = await processMapReportDataSaubStatService.GetAsync(idWell, request, cancellationToken); + + FillProcessMapToWorkbook(workbook, data); + + MemoryStream memoryStream = new(); + workbook.SaveAs(memoryStream, new SaveOptions { }); + memoryStream.Seek(0, SeekOrigin.Begin); + + var name = $"РТК бурение. Отчёт по скважине {well.Caption} куст {well.Cluster}.xlsx"; + + return (name, memoryStream); + } + + private static void FillProcessMapToWorkbook(XLWorkbook workbook, IEnumerable data) + { + var sheet = workbook.GetWorksheet(sheetName); + + var startRow = headerRowsCount + 1; + foreach (var item in data) { - this.wellService = wellService; - this.processMapReportDataSaubStatService = processMapReportDataSaubStatService; - } - - public async Task<(string Name, Stream File)?> ExportAsync(int idWell, DataSaubStatRequest request, CancellationToken cancellationToken) - { - var well = await wellService.GetOrDefaultAsync(idWell, cancellationToken); - - if (well is null) - return null; - - var stream = Assembly.GetExecutingAssembly().GetTemplateCopyStream(TemplateName); - using var workbook = new XLWorkbook(stream); - - var data = await processMapReportDataSaubStatService.GetAsync(idWell, request, cancellationToken); - - FillProcessMapToWorkbook(workbook, data); - - MemoryStream memoryStream = new(); - workbook.SaveAs(memoryStream, new SaveOptions { }); - memoryStream.Seek(0, SeekOrigin.Begin); - - var name = $"РТК бурение. Отчёт по скважине {well.Caption} куст {well.Cluster}.xlsx"; - - return (name, memoryStream); - } - - private static void FillProcessMapToWorkbook(XLWorkbook workbook, - IEnumerable data) - { - const string sheetName = "Отчёт"; - - var sheet = workbook.GetWorksheet(sheetName); - - var startRow = headerRowsCount + 1; - foreach (var item in data) - { - startRow = FillRow(sheet, item, startRow); - } - } - - - private static int FillRow(IXLWorksheet sheet, ProcessMapReportDataSaubStatDto item, - int startRow) - { - var endRow = FillIntervalData(sheet, item, startRow); - - var sectionStyle = sheet.Range(startRow, firstColumn, endRow - 1, lastColumn).Style; - SetStyle(sectionStyle); - return endRow; - } - - private static int FillIntervalData(IXLWorksheet sheet, ProcessMapReportDataSaubStatDto interval, int row) - { - const int columnSection = firstColumn + 1; - const int columnDepthStart = firstColumn + 2; - const int columnDepthEnd = firstColumn + 3; - const int columnDeltaDepth = firstColumn + 4; - const int columnDrilledTime = firstColumn + 5; - const int columnMode = firstColumn + 6; - - double? deltaDepth = interval.DeltaDepth.HasValue - ? Math.Round(interval.DeltaDepth.Value, 1) - : null; - - sheet.Cell(row, firstColumn).SetCellValue(interval.DateStart, "DD.MM.YYYY HH:MM"); - sheet.Cell(row, columnSection).SetCellValue(interval.WellSectionTypeName); - sheet.Cell(row, columnDepthStart).SetCellValue(Math.Round(interval.DepthStart, 2)); - sheet.Cell(row, columnDepthEnd).SetCellValue(Math.Round(interval.DepthEnd, 2)); - sheet.Cell(row, columnDeltaDepth).SetCellValue(deltaDepth); - sheet.Cell(row, columnDrilledTime).SetCellValue(Math.Round(interval.DrilledTime, 2)); - sheet.Cell(row, columnMode).SetCellValue(interval.DrillingMode); - - row = FillIntervalModeData(sheet, interval, columnMode, row); - - return row; - } - - private static int FillIntervalModeData(IXLWorksheet sheet, ProcessMapReportDataSaubStatDto modeData, - int column, int row) - { - int columnPressure = column + 1; - int columnLoad = columnPressure + 5; - int columnTorque = columnLoad + 5; - int columnSpeed = columnTorque + 5; - int columnTopDriveSpeed = columnSpeed + 4; - int columnFlow = columnTopDriveSpeed + 2; - int columnRopPlan = columnFlow + 3; - int columnRopFact = columnRopPlan + 1; - - FillIntervalModeDataParam(sheet, modeData.PressureDiff, columnPressure, row); - FillIntervalModeDataParam(sheet, modeData.AxialLoad, columnLoad, row); - FillIntervalModeDataParam(sheet, modeData.TopDriveTorque, columnTorque, row); - FillIntervalModeDataSpeed(sheet, modeData.SpeedLimit, columnSpeed, row); - FillIntervalModeTopDriveSpeed(sheet, modeData.TopDriveSpeed, columnTopDriveSpeed, row); - FillIntervalModeFlow(sheet, modeData.Flow, columnFlow, row); - - double? ropPlan = modeData.Rop.Plan.HasValue - ? Math.Round(modeData.Rop.Plan.Value, 1) - : null; - - double? ropFact = modeData.Rop.Fact.HasValue - ? Math.Round(modeData.Rop.Fact.Value, 1) - : null; - - sheet.Cell(row, columnRopPlan).SetCellValue(ropPlan); - sheet.Cell(row, columnRopFact).SetCellValue(ropFact); - - return row + 1; - } - - private static void FillIntervalModeDataParam(IXLWorksheet sheet, - ProcessMapReportDataSaubStatParamsDto dataParam, int column, int row) - { - const int columnOffsetSpPlan = 0; - const int columnOffsetSpFact = 1; - const int columnOffsetFact = 2; - const int columnOffsetLimit = 3; - const int columnOffsetPercent = 4; - - double? setpointPlan = dataParam.SetpointPlan.HasValue - ? Math.Round(dataParam.SetpointPlan.Value) - : null; - - double? setpointFact = dataParam.SetpointFact.HasValue - ? Math.Round(dataParam.SetpointFact.Value, 1) - : null; - - double? factWavg = dataParam.FactWavg.HasValue - ? Math.Round(dataParam.FactWavg.Value, 1) - : null; - - double? limit = dataParam.Limit.HasValue - ? Math.Round(dataParam.Limit.Value, 1) - : null; - - double? setpointUsage = dataParam.SetpointUsage.HasValue - ? Math.Round(dataParam.SetpointUsage.Value, 1) - : null; - - sheet.Cell(row, column + columnOffsetSpPlan).SetCellValue(setpointPlan); - sheet.Cell(row, column + columnOffsetSpFact).SetCellValue(setpointFact); - sheet.Cell(row, column + columnOffsetFact).SetCellValue(factWavg); - sheet.Cell(row, column + columnOffsetLimit).SetCellValue(limit); - sheet.Cell(row, column + columnOffsetPercent).SetCellValue(setpointUsage); - } - - private static void FillIntervalModeDataSpeed(IXLWorksheet sheet, - ProcessMapReportDataSaubStatParamsDto dataParam, int column, int row) - { - const int columnOffsetSpPlan = 0; - const int columnOffsetSpFact = 1; - const int columnOffsetFact = 2; - const int columnOffsetPercent = 3; - - double? setpointPlan = dataParam.SetpointPlan.HasValue - ? Math.Round(dataParam.SetpointPlan.Value) - : null; - - double? setpointFact = dataParam.SetpointFact.HasValue - ? Math.Round(dataParam.SetpointFact.Value, 1) - : null; - - double? factWavg = dataParam.FactWavg.HasValue - ? Math.Round(dataParam.FactWavg.Value, 1) - : null; - - double? setpointUsage = dataParam.SetpointUsage.HasValue - ? Math.Round(dataParam.SetpointUsage.Value, 1) - : null; - - sheet.Cell(row, column + columnOffsetSpPlan).SetCellValue(setpointPlan); - sheet.Cell(row, column + columnOffsetSpFact).SetCellValue(setpointFact); - sheet.Cell(row, column + columnOffsetFact).SetCellValue(factWavg); - sheet.Cell(row, column + columnOffsetPercent).SetCellValue(setpointUsage); - } - - private static void FillIntervalModeTopDriveSpeed(IXLWorksheet sheet, - ProcessMapReportDataSaubStatParamsDto dataParam, int column, int row) - { - const int columnOffsetSpPlan = 0; - const int columnOffsetFact = 1; - - double? setpointPlan = dataParam.SetpointPlan.HasValue - ? Math.Round(dataParam.SetpointPlan.Value) - : null; - - double? factWavg = dataParam.FactWavg.HasValue - ? Math.Round(dataParam.FactWavg.Value, 1) - : null; - - sheet.Cell(row, column + columnOffsetSpPlan).SetCellValue(setpointPlan); - sheet.Cell(row, column + columnOffsetFact).SetCellValue(factWavg); - } - - private static void FillIntervalModeFlow(IXLWorksheet sheet, - ProcessMapReportDataSaubStatParamsDto dataParam, int column, int row) - { - const int columnOffsetSpPlan = 0; - const int columnOffsetFact = 1; - const int columnOffsetLimit = 2; - - double? setpointPlan = dataParam.SetpointPlan.HasValue - ? Math.Round(dataParam.SetpointPlan.Value) - : null; - - double? factWavg = dataParam.FactWavg.HasValue - ? Math.Round(dataParam.FactWavg.Value, 1) - : null; - - double? limit = dataParam.Limit.HasValue - ? Math.Round(dataParam.Limit.Value, 1) - : null; - - sheet.Cell(row, column + columnOffsetSpPlan).SetCellValue(setpointPlan); - sheet.Cell(row, column + columnOffsetFact).SetCellValue(factWavg); - sheet.Cell(row, column + columnOffsetLimit).SetCellValue(limit); - } - - private static void SetStyle(IXLStyle style) - { - style.Border.RightBorder = XLBorderStyleValues.Thin; - style.Border.LeftBorder = XLBorderStyleValues.Thin; - style.Border.TopBorder = XLBorderStyleValues.Thin; - style.Border.BottomBorder = XLBorderStyleValues.Thin; - style.Border.InsideBorder = XLBorderStyleValues.Thin; - - style.Alignment.Horizontal = XLAlignmentHorizontalValues.Center; + startRow = FillRow(sheet, item, startRow); } } + + + private static int FillRow(IXLWorksheet sheet, ProcessMapReportDataSaubStatDto item, int startRow) + { + var endRow = FillIntervalData(sheet, item, startRow); + + var sectionStyle = sheet.Range(startRow, firstColumn, endRow - 1, lastColumn).Style; + SetStyle(sectionStyle); + return endRow; + } + + private static int FillIntervalData(IXLWorksheet sheet, ProcessMapReportDataSaubStatDto interval, int row) + { + const int columnSection = firstColumn + 1; + const int columnDepthStart = firstColumn + 2; + const int columnDepthEnd = firstColumn + 3; + const int columnDeltaDepth = firstColumn + 4; + const int columnDrilledTime = firstColumn + 5; + const int columnMode = firstColumn + 6; + + double? deltaDepth = interval.DeltaDepth.HasValue + ? Math.Round(interval.DeltaDepth.Value, 1) + : null; + + sheet.Cell(row, firstColumn).SetCellValue(interval.DateStart, "DD.MM.YYYY HH:MM"); + sheet.Cell(row, columnSection).SetCellValue(interval.WellSectionTypeName); + sheet.Cell(row, columnDepthStart).SetCellValue(Math.Round(interval.DepthStart, 2)); + sheet.Cell(row, columnDepthEnd).SetCellValue(Math.Round(interval.DepthEnd, 2)); + sheet.Cell(row, columnDeltaDepth).SetCellValue(deltaDepth); + sheet.Cell(row, columnDrilledTime).SetCellValue(Math.Round(interval.DrilledTime, 2)); + sheet.Cell(row, columnMode).SetCellValue(interval.DrillingMode); + + row = FillIntervalModeData(sheet, interval, columnMode, row); + + return row; + } + + private static int FillIntervalModeData(IXLWorksheet sheet, ProcessMapReportDataSaubStatDto modeData, + int column, int row) + { + int columnPressure = column + 1; + int columnLoad = columnPressure + 5; + int columnTorque = columnLoad + 5; + int columnSpeed = columnTorque + 5; + int columnTopDriveSpeed = columnSpeed + 4; + int columnFlow = columnTopDriveSpeed + 2; + int columnRopPlan = columnFlow + 3; + int columnRopFact = columnRopPlan + 1; + + FillIntervalModeDataParam(sheet, modeData.PressureDiff, columnPressure, row); + FillIntervalModeDataParam(sheet, modeData.AxialLoad, columnLoad, row); + FillIntervalModeDataParam(sheet, modeData.TopDriveTorque, columnTorque, row); + FillIntervalModeDataSpeed(sheet, modeData.SpeedLimit, columnSpeed, row); + FillIntervalModeTopDriveSpeed(sheet, modeData.TopDriveSpeed, columnTopDriveSpeed, row); + FillIntervalModeFlow(sheet, modeData.Flow, columnFlow, row); + + double? ropPlan = modeData.Rop.Plan.HasValue + ? Math.Round(modeData.Rop.Plan.Value, 1) + : null; + + double? ropFact = modeData.Rop.Fact.HasValue + ? Math.Round(modeData.Rop.Fact.Value, 1) + : null; + + sheet.Cell(row, columnRopPlan).SetCellValue(ropPlan); + sheet.Cell(row, columnRopFact).SetCellValue(ropFact); + + return row + 1; + } + + private static void FillIntervalModeDataParam(IXLWorksheet sheet, + ProcessMapReportDataSaubStatParamsDto dataParam, int column, int row) + { + const int columnOffsetSpPlan = 0; + const int columnOffsetSpFact = 1; + const int columnOffsetFact = 2; + const int columnOffsetLimit = 3; + const int columnOffsetPercent = 4; + + double? setpointPlan = dataParam.SetpointPlan.HasValue + ? Math.Round(dataParam.SetpointPlan.Value) + : null; + + double? setpointFact = dataParam.SetpointFact.HasValue + ? Math.Round(dataParam.SetpointFact.Value, 1) + : null; + + double? factWavg = dataParam.FactWavg.HasValue + ? Math.Round(dataParam.FactWavg.Value, 1) + : null; + + double? limit = dataParam.Limit.HasValue + ? Math.Round(dataParam.Limit.Value, 1) + : null; + + double? setpointUsage = dataParam.SetpointUsage.HasValue + ? Math.Round(dataParam.SetpointUsage.Value, 1) + : null; + + sheet.Cell(row, column + columnOffsetSpPlan).SetCellValue(setpointPlan); + sheet.Cell(row, column + columnOffsetSpFact).SetCellValue(setpointFact); + sheet.Cell(row, column + columnOffsetFact).SetCellValue(factWavg); + sheet.Cell(row, column + columnOffsetLimit).SetCellValue(limit); + sheet.Cell(row, column + columnOffsetPercent).SetCellValue(setpointUsage); + } + + private static void FillIntervalModeDataSpeed(IXLWorksheet sheet, + ProcessMapReportDataSaubStatParamsDto dataParam, int column, int row) + { + const int columnOffsetSpPlan = 0; + const int columnOffsetSpFact = 1; + const int columnOffsetFact = 2; + const int columnOffsetPercent = 3; + + double? setpointPlan = dataParam.SetpointPlan.HasValue + ? Math.Round(dataParam.SetpointPlan.Value) + : null; + + double? setpointFact = dataParam.SetpointFact.HasValue + ? Math.Round(dataParam.SetpointFact.Value, 1) + : null; + + double? factWavg = dataParam.FactWavg.HasValue + ? Math.Round(dataParam.FactWavg.Value, 1) + : null; + + double? setpointUsage = dataParam.SetpointUsage.HasValue + ? Math.Round(dataParam.SetpointUsage.Value, 1) + : null; + + sheet.Cell(row, column + columnOffsetSpPlan).SetCellValue(setpointPlan); + sheet.Cell(row, column + columnOffsetSpFact).SetCellValue(setpointFact); + sheet.Cell(row, column + columnOffsetFact).SetCellValue(factWavg); + sheet.Cell(row, column + columnOffsetPercent).SetCellValue(setpointUsage); + } + + private static void FillIntervalModeTopDriveSpeed(IXLWorksheet sheet, + ProcessMapReportDataSaubStatParamsDto dataParam, int column, int row) + { + const int columnOffsetSpPlan = 0; + const int columnOffsetFact = 1; + + double? setpointPlan = dataParam.SetpointPlan.HasValue + ? Math.Round(dataParam.SetpointPlan.Value) + : null; + + double? factWavg = dataParam.FactWavg.HasValue + ? Math.Round(dataParam.FactWavg.Value, 1) + : null; + + sheet.Cell(row, column + columnOffsetSpPlan).SetCellValue(setpointPlan); + sheet.Cell(row, column + columnOffsetFact).SetCellValue(factWavg); + } + + private static void FillIntervalModeFlow(IXLWorksheet sheet, + ProcessMapReportDataSaubStatParamsDto dataParam, int column, int row) + { + const int columnOffsetSpPlan = 0; + const int columnOffsetFact = 1; + const int columnOffsetLimit = 2; + + double? setpointPlan = dataParam.SetpointPlan.HasValue + ? Math.Round(dataParam.SetpointPlan.Value) + : null; + + double? factWavg = dataParam.FactWavg.HasValue + ? Math.Round(dataParam.FactWavg.Value, 1) + : null; + + double? limit = dataParam.Limit.HasValue + ? Math.Round(dataParam.Limit.Value, 1) + : null; + + sheet.Cell(row, column + columnOffsetSpPlan).SetCellValue(setpointPlan); + sheet.Cell(row, column + columnOffsetFact).SetCellValue(factWavg); + sheet.Cell(row, column + columnOffsetLimit).SetCellValue(limit); + } + + private static void SetStyle(IXLStyle style) + { + style.Border.RightBorder = XLBorderStyleValues.Thin; + style.Border.LeftBorder = XLBorderStyleValues.Thin; + style.Border.TopBorder = XLBorderStyleValues.Thin; + style.Border.BottomBorder = XLBorderStyleValues.Thin; + style.Border.InsideBorder = XLBorderStyleValues.Thin; + + style.Alignment.Horizontal = XLAlignmentHorizontalValues.Center; + } } diff --git a/AsbCloudWebApi/Controllers/ProcessMaps/ProcessMapWellDrillingController.cs b/AsbCloudWebApi/Controllers/ProcessMaps/ProcessMapWellDrillingController.cs index 55657882..9c284220 100644 --- a/AsbCloudWebApi/Controllers/ProcessMaps/ProcessMapWellDrillingController.cs +++ b/AsbCloudWebApi/Controllers/ProcessMaps/ProcessMapWellDrillingController.cs @@ -11,6 +11,7 @@ using AsbCloudWebApi.SignalR.Clients; using Microsoft.AspNetCore.Http; using Microsoft.AspNetCore.Mvc; using Microsoft.AspNetCore.SignalR; +using System; using System.Collections.Generic; using System.ComponentModel.DataAnnotations; using System.IO; @@ -91,6 +92,7 @@ public class ProcessMapWellDrillingController : ProcessMapBaseController /// /// + [Obsolete] [HttpPost("import/{options}")] [ProducesResponseType(typeof(ValidationProblemDetails), StatusCodes.Status400BadRequest)] public async Task ImportAsync(int idWell, @@ -129,6 +131,7 @@ public class ProcessMapWellDrillingController : ProcessMapBaseControllerId скважины /// /// + [Obsolete] [HttpGet("export")] [ProducesResponseType(typeof(PhysicalFileResult), StatusCodes.Status200OK, "application/octet-stream")] [ProducesResponseType(typeof(ValidationProblemDetails), StatusCodes.Status400BadRequest)] @@ -143,6 +146,7 @@ public class ProcessMapWellDrillingController : ProcessMapBaseController /// Запрашиваемый файл + [Obsolete] [HttpGet("template")] [ProducesResponseType(typeof(PhysicalFileResult), StatusCodes.Status200OK, "application/octet-stream")] public async Task GetTemplateAsync(CancellationToken cancellationToken)