forked from ddrilling/AsbCloudServer
CS2-10: Добавлен поиск по имеющимся отчетам, которые удовлетворяют заданным параметрам
This commit is contained in:
parent
3a4a27942a
commit
6803f836b4
@ -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<float, string, int > handleReportProgress);
|
||||
int GetReportPagesCount(int wellId, DateTime begin, DateTime end, int stepSeconds, int format);
|
||||
IEnumerable<string> GetExistingReportNames(int wellId, DateTime begin, DateTime end, int stepSeconds, int format);
|
||||
DatesRangeDto GetReportsDatesRange(int wellId);
|
||||
}
|
||||
}
|
||||
|
@ -19,6 +19,7 @@ namespace AsbCloudDb.Model
|
||||
DbSet<User> Users { get; set; }
|
||||
DbSet<Well> Wells { get; set; }
|
||||
DbSet<UserRole> UserRoles { get; set; }
|
||||
DbSet<Report> Reports { get; set; }
|
||||
|
||||
int SaveChanges();
|
||||
int SaveChanges(bool acceptAllChangesOnSuccess);
|
||||
|
@ -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")]
|
||||
|
@ -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<string> 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<Report>(telemetry.Id);
|
||||
// Убран общий с другими сущностями интерфейс IIdTelemetryDate,
|
||||
// т.к. у Report нет IdTelemetry. GetDatesRange() уже не работает для Report.
|
||||
// Будет исправлено следом за этим коммитом
|
||||
//var (From, To) = db.GetDatesRange<Report>(telemetry.Id);
|
||||
|
||||
return new DatesRangeDto { From = From, To = To };
|
||||
return new DatesRangeDto {
|
||||
From = DateTime.MinValue,
|
||||
To = DateTime.MaxValue
|
||||
};
|
||||
}
|
||||
|
||||
private IEnumerable<string> 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)
|
||||
|
@ -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
|
||||
/// <returns>id фоновой задачи формирования отчета</returns>
|
||||
[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
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Возвращает имена отчетов, хранящихся на диске,
|
||||
/// которые подходят под указанные параметры
|
||||
/// </summary>
|
||||
/// <param name="wellId">id скважины</param>
|
||||
/// <param name="stepSeconds">шаг интервала</param>
|
||||
/// <param name="format">формат отчета (0-PDF, 1-LASS)</param>
|
||||
/// <param name="begin">дата начала интервала</param>
|
||||
/// <param name="end">дата окончания интервала</param>
|
||||
/// <returns>Список имен существующих отчетов (отчетов)</returns>
|
||||
[HttpGet]
|
||||
[Route("{wellId}/suitableReports")]
|
||||
[ProducesResponseType(typeof(IEnumerable<string>), (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);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Возвращает прогнозируемое количество страниц будущего отчета
|
||||
/// </summary>
|
||||
|
Loading…
Reference in New Issue
Block a user