From 6803f836b481e98198af27810e1403e88abd03d9 Mon Sep 17 00:00:00 2001 From: KharchenkoVV Date: Mon, 31 May 2021 12:33:17 +0500 Subject: [PATCH] =?UTF-8?q?CS2-10:=20=D0=94=D0=BE=D0=B1=D0=B0=D0=B2=D0=BB?= =?UTF-8?q?=D0=B5=D0=BD=20=D0=BF=D0=BE=D0=B8=D1=81=D0=BA=20=D0=BF=D0=BE=20?= =?UTF-8?q?=D0=B8=D0=BC=D0=B5=D1=8E=D1=89=D0=B8=D0=BC=D1=81=D1=8F=20=D0=BE?= =?UTF-8?q?=D1=82=D1=87=D0=B5=D1=82=D0=B0=D0=BC,=20=D0=BA=D0=BE=D1=82?= =?UTF-8?q?=D0=BE=D1=80=D1=8B=D0=B5=20=D1=83=D0=B4=D0=BE=D0=B2=D0=BB=D0=B5?= =?UTF-8?q?=D1=82=D0=B2=D0=BE=D1=80=D1=8F=D1=8E=D1=82=20=D0=B7=D0=B0=D0=B4?= =?UTF-8?q?=D0=B0=D0=BD=D0=BD=D1=8B=D0=BC=20=D0=BF=D0=B0=D1=80=D0=B0=D0=BC?= =?UTF-8?q?=D0=B5=D1=82=D1=80=D0=B0=D0=BC?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- AsbCloudApp/Services/IReportService.cs | 2 + AsbCloudDb/Model/IAsbCloudDbContext.cs | 1 + AsbCloudDb/Model/Report.cs | 6 +-- .../Services/ReportService.cs | 52 +++++++++++++++++-- .../Controllers/ReportController.cs | 23 +++++++- 5 files changed, 77 insertions(+), 7 deletions(-) diff --git a/AsbCloudApp/Services/IReportService.cs b/AsbCloudApp/Services/IReportService.cs index df6c2102..7e21ca7b 100644 --- a/AsbCloudApp/Services/IReportService.cs +++ b/AsbCloudApp/Services/IReportService.cs @@ -1,4 +1,5 @@ using System; +using System.Collections.Generic; using AsbCloudApp.Data; namespace AsbCloudApp.Services @@ -9,6 +10,7 @@ namespace AsbCloudApp.Services int CreateReport(int wellId, int stepSeconds, int format, DateTime begin, DateTime end, Action handleReportProgress); int GetReportPagesCount(int wellId, DateTime begin, DateTime end, int stepSeconds, int format); + IEnumerable GetExistingReportNames(int wellId, DateTime begin, DateTime end, int stepSeconds, int format); DatesRangeDto GetReportsDatesRange(int wellId); } } diff --git a/AsbCloudDb/Model/IAsbCloudDbContext.cs b/AsbCloudDb/Model/IAsbCloudDbContext.cs index e7c46bca..367b57a0 100644 --- a/AsbCloudDb/Model/IAsbCloudDbContext.cs +++ b/AsbCloudDb/Model/IAsbCloudDbContext.cs @@ -19,6 +19,7 @@ namespace AsbCloudDb.Model DbSet Users { get; set; } DbSet Wells { get; set; } DbSet UserRoles { get; set; } + DbSet Reports { get; set; } int SaveChanges(); int SaveChanges(bool acceptAllChangesOnSuccess); diff --git a/AsbCloudDb/Model/Report.cs b/AsbCloudDb/Model/Report.cs index 03ac060a..d17bdd33 100644 --- a/AsbCloudDb/Model/Report.cs +++ b/AsbCloudDb/Model/Report.cs @@ -6,13 +6,13 @@ using System.ComponentModel.DataAnnotations.Schema; namespace AsbCloudDb.Model { [Table("t_report"), Comment("Отчеты с данными по буровым")] - public class Report : IId, IIdTelemetryDate + public class Report : IId { [Key] [Column("id")] public int Id { get; set; } - [Column("id_telemetry")] - public int IdTelemetry { get; set; } + [Column("name"), Comment("Название отчета (файла)")] + public string Name { get; set; } [Column("id_well"), Comment("id скважины")] public int WellId { get; set; } [Column("date", TypeName = "timestamp with time zone")] diff --git a/AsbCloudInfrastructure/Services/ReportService.cs b/AsbCloudInfrastructure/Services/ReportService.cs index 0dbfa1c9..abbc06df 100644 --- a/AsbCloudInfrastructure/Services/ReportService.cs +++ b/AsbCloudInfrastructure/Services/ReportService.cs @@ -2,6 +2,8 @@ using AsbCloudApp.Data; using AsbCloudDb.Model; using System; +using System.Collections.Generic; +using System.Linq; using System.IO; using Microsoft.EntityFrameworkCore; using Microsoft.Extensions.Configuration; @@ -39,7 +41,22 @@ namespace AsbCloudInfrastructure.Services { var generator = GetReportGenerator(wellId, begin, end, stepSeconds, format, context); generator.OnProgress += (s,e) => progressHandler.Invoke(e.progress, e.operation, id); - generator.Make(); + var newReportName = generator.Make(); + if(newReportName is not null) + { + var newReportProperties = new Report + { + Name = newReportName, + WellId = wellId, + Date = DateTime.Now, + Begin = begin, + End = end, + Step = stepSeconds, + Format = format + }; + context.Reports.Add(newReportProperties); + db.SaveChanges(); + } } }); return newReportId; @@ -52,6 +69,19 @@ namespace AsbCloudInfrastructure.Services return generator.GetPagesCount(); } + public IEnumerable GetExistingReportNames(int wellId, DateTime begin, DateTime end, int stepSeconds, int format) + { + var suitableReportsFromDb = GetSuitableReportNamesFromDb(wellId, begin, end, stepSeconds, format); + + var reportsFolder = Path.Combine(RootPath, $"{wellId}"); + + var suitableReportNames = Directory.GetFiles(reportsFolder) + .Select(Path.GetFileName) + .Where(name => suitableReportsFromDb.Contains(name)); + + return suitableReportNames; + } + public DatesRangeDto GetReportsDatesRange(int wellId) { var telemetry = telemetryService.GetTelemetryByWellId(wellId); @@ -59,9 +89,25 @@ namespace AsbCloudInfrastructure.Services if (telemetry is null) return null; - var (From, To) = db.GetDatesRange(telemetry.Id); + // Убран общий с другими сущностями интерфейс IIdTelemetryDate, + // т.к. у Report нет IdTelemetry. GetDatesRange() уже не работает для Report. + // Будет исправлено следом за этим коммитом + //var (From, To) = db.GetDatesRange(telemetry.Id); - return new DatesRangeDto { From = From, To = To }; + return new DatesRangeDto { + From = DateTime.MinValue, + To = DateTime.MaxValue + }; + } + + private IEnumerable GetSuitableReportNamesFromDb(int wellId, DateTime begin, DateTime end, int stepSeconds, int format) + { + var suitableReportsNames = (from r in db.Reports + where r.WellId == wellId && r.Begin == begin + && r.End == end && r.Step == stepSeconds + && r.Format == format + select r.Name).ToList(); + return suitableReportsNames; } private IReportGenerator GetReportGenerator(int wellId, DateTime begin, DateTime end, int stepSeconds, int format, AsbCloudDbContext context) diff --git a/AsbCloudWebApi/Controllers/ReportController.cs b/AsbCloudWebApi/Controllers/ReportController.cs index c7f90766..151520b5 100644 --- a/AsbCloudWebApi/Controllers/ReportController.cs +++ b/AsbCloudWebApi/Controllers/ReportController.cs @@ -1,4 +1,5 @@ using System; +using System.Collections.Generic; using System.IO; using Microsoft.AspNetCore.Mvc; using AsbCloudApp.Data; @@ -41,7 +42,7 @@ namespace AsbCloudWebApi.Controllers /// id фоновой задачи формирования отчета [HttpPost] [Route("{wellId}/report")] - [ProducesResponseType(typeof(string), (int)System.Net.HttpStatusCode.OK)] + [ProducesResponseType(typeof(int), (int)System.Net.HttpStatusCode.OK)] public IActionResult CreateReport(int wellId, int stepSeconds, int format, DateTime begin = default, DateTime end = default) { @@ -87,6 +88,26 @@ namespace AsbCloudWebApi.Controllers } } + /// + /// Возвращает имена отчетов, хранящихся на диске, + /// которые подходят под указанные параметры + /// + /// id скважины + /// шаг интервала + /// формат отчета (0-PDF, 1-LASS) + /// дата начала интервала + /// дата окончания интервала + /// Список имен существующих отчетов (отчетов) + [HttpGet] + [Route("{wellId}/suitableReports")] + [ProducesResponseType(typeof(IEnumerable), (int)System.Net.HttpStatusCode.OK)] + public IActionResult GetSuitableReportsNames(int wellId, int stepSeconds, int format, + DateTime begin = default, DateTime end = default) + { + var suitableReportsNames = reportService.GetExistingReportNames(wellId, begin, end, stepSeconds, format); + return Ok(suitableReportsNames); + } + /// /// Возвращает прогнозируемое количество страниц будущего отчета ///