Changed Reports to one of the Documents' category

This commit is contained in:
KharchenkoVV 2021-07-27 16:55:32 +05:00
parent 16e52cacf5
commit 165cabd5dd
10 changed files with 74 additions and 42 deletions

View File

@ -6,11 +6,15 @@ namespace AsbCloudApp.Services
{
public interface IReportService
{
string RootPath { get; }
int CreateReport(int idWell, int stepSeconds, int format, DateTime begin, DateTime end,
Action<float, string, int> handleReportProgress, Action<string, int> handleReportName);
int GetReportPagesCount(int idWell, DateTime begin, DateTime end, int stepSeconds, int format);
IEnumerable<ReportPropertiesDto> GetSuitableReports(int idWell, DateTime begin, DateTime end, int stepSeconds, int format);
int ReportCategoryId { get; }
int CreateReport(int idWell, int idUser, int stepSeconds,
int format, DateTime begin, DateTime end,
Action<float, string, int> handleReportProgress,
Action<string, int> handleReportName);
int GetReportPagesCount(int idWell, DateTime begin, DateTime end,
int stepSeconds, int format);
IEnumerable<ReportPropertiesDto> GetSuitableReports(int idWell,
DateTime begin, DateTime end, int stepSeconds, int format);
DatesRangeDto GetReportsDatesRange(int idWell);
}
}

View File

@ -20,14 +20,14 @@ namespace AsbCloudDb.Model
public virtual DbSet<Message> Messages { get; set; }
public virtual DbSet<User> Users { get; set; }
public virtual DbSet<UserRole> UserRoles { get; set; }
public virtual DbSet<Report> Reports { get; set; }
public virtual DbSet<Well> Wells { get; set; }
public virtual DbSet<ReportProperties> ReportProperties { get; set; }
public virtual DbSet<File> Files { get; set; }
public virtual DbSet<FileCategory> FileCategories { get; set; }
public virtual DbSet<Telemetry> Telemetries { get; set; }
public virtual DbSet<TelemetryUser> TelemetryUsers { get; set; }
public virtual DbSet<TelemetryOperation> Operations { get; set; }
public virtual DbSet<TelemetryAnalysis> TelemetryAnalysis { get; set; }
public virtual DbSet<Well> Wells { get; set; }
public virtual DbSet<WellSection> WellSections { get; set; }
public virtual DbSet<WellOperation> WellOperations { get; set; }
public virtual DbSet<WellType> WellTypes { get; set; }

View File

@ -16,8 +16,8 @@ namespace AsbCloudDb.Model
[Column("id_well"), Comment("id скважины")]
public int IdWell { get; set; }
[Column("id_user"), Comment("Id пользователя, загрузившего файл")]
public int IdUser { get; set; }
[Column("id_author"), Comment("Id пользователя, загрузившего файл")]
public int IdAuthor { get; set; }
[Column("id_category"), Comment("id категории файла")]
public int IdCategory { get; set; }
@ -28,12 +28,15 @@ namespace AsbCloudDb.Model
[Column("date", TypeName = "timestamp with time zone")]
public DateTime Date { get; set; }
[Column("is_deleted"), Comment("Удален ли файл")]
public bool IsDeleted { get; set; }
[JsonIgnore]
[ForeignKey(nameof(IdWell))]
public virtual Well Well { get; set; }
[JsonIgnore]
[ForeignKey(nameof(IdUser))]
[ForeignKey(nameof(IdAuthor))]
public virtual User User { get; set; }
[JsonIgnore]

View File

@ -17,7 +17,7 @@ namespace AsbCloudDb.Model
DbSet<Message> Messages { get; set; }
DbSet<User> Users { get; set; }
DbSet<UserRole> UserRoles { get; set; }
DbSet<Report> Reports { get; set; }
DbSet<ReportProperties> ReportProperties { get; set; }
DbSet<File> Files { get; set; }
DbSet<FileCategory> FileCategories { get; set; }
DbSet<Telemetry> Telemetries { get; set; }

View File

@ -5,8 +5,8 @@ using System.ComponentModel.DataAnnotations.Schema;
namespace AsbCloudDb.Model
{
[Table("t_report"), Comment("Отчеты с данными по буровым")]
public class Report : IId
[Table("t_report_properties"), Comment("Отчеты с данными по буровым")]
public class ReportProperties : IId
{
[Key]
[Column("id")]
@ -15,11 +15,8 @@ namespace AsbCloudDb.Model
[Column("id_well"), Comment("id скважины")]
public int IdWell { get; set; }
[Column("name"), Comment("Название отчета (файла)")]
public string Name { get; set; }
[Column("date", TypeName = "timestamp with time zone")]
public DateTime Date { get; set; }
[Column("id_file"), Comment("id файла-родителя")]
public int IdFile { get; set; }
[Column("begin", TypeName = "timestamp with time zone")]
public DateTimeOffset Begin { get; set; }
@ -35,5 +32,8 @@ namespace AsbCloudDb.Model
[ForeignKey(nameof(IdWell))]
public virtual Well Well { get; set; }
[ForeignKey(nameof(IdFile))]
public virtual File File { get; set; }
}
}

View File

@ -1,4 +1,5 @@
using Microsoft.EntityFrameworkCore;
using System.Collections.Generic;
using Microsoft.EntityFrameworkCore;
using System.ComponentModel.DataAnnotations;
using System.ComponentModel.DataAnnotations.Schema;
@ -54,6 +55,8 @@ namespace AsbCloudDb.Model
[InverseProperty(nameof(Model.UserRole.Users))]
public virtual UserRole Role { get; set; }
public virtual ICollection<File> Files { get; set; }
public string MakeDisplayName()
{
if (string.IsNullOrEmpty(Surname))

View File

@ -34,7 +34,7 @@ namespace AsbCloudInfrastructure.Services
IdWell = fileInfo.idWell,
IdCategory = fileInfo.idCategory,
Date = fileInfo.date,
IdUser = fileInfo.idUser
IdAuthor = fileInfo.idUser
};
db.Files.Add(file);
@ -73,7 +73,7 @@ namespace AsbCloudInfrastructure.Services
if (skip > 0)
filesInfoQuery = filesInfoQuery.Skip(skip);
var filesInfoList = filesInfoQuery.Take(take).ToList();
var filesInfoList = filesInfoQuery.OrderBy(f => f.Date).Take(take).ToList();
if (filesInfoList.Count == 0)
return result;

View File

@ -17,20 +17,25 @@ namespace AsbCloudInfrastructure.Services
private readonly IAsbCloudDbContext db;
private readonly IConfiguration configuration;
private readonly ITelemetryService telemetryService;
private readonly IFileService fileService;
private readonly IBackgroundQueue queue;
public ReportService(IAsbCloudDbContext db, IConfiguration configuration, ITelemetryService telemetryService, IBackgroundQueue queue)
public ReportService(IAsbCloudDbContext db, IConfiguration configuration,
ITelemetryService telemetryService, IFileService fileService,
IBackgroundQueue queue)
{
this.db = db;
this.configuration = configuration;
this.telemetryService = telemetryService;
this.fileService = fileService;
this.queue = queue;
RootPath = "reports";
ReportCategoryId = db.FileCategories.FirstOrDefault(c =>
c.Name.Equals("Рапорт")).Id;
}
public string RootPath { get; private set; }
public int ReportCategoryId { get; private set; }
public int CreateReport(int idWell, int stepSeconds, int format, DateTime begin,
public int CreateReport(int idWell, int idUser, int stepSeconds, int format, DateTime begin,
DateTime end, Action<float, string, int> progressHandler, Action<string, int> reportNameHandler)
{
var newReportId = queue.EnqueueTask((id) =>
@ -48,17 +53,28 @@ namespace AsbCloudInfrastructure.Services
var shorReportName = Path.GetFileName(newReportName);
reportNameHandler.Invoke(shorReportName, id);
var newReportProperties = new Report
var newReportFile = new AsbCloudDb.Model.File
{
Name = newReportName,
IdWell = idWell,
IdAuthor = idUser,
IdCategory = ReportCategoryId,
Name = newReportName,
Date = DateTime.Now,
};
context.Files.Add(newReportFile);
context.SaveChanges();
var newReportProperties = new ReportProperties
{
IdWell = idWell,
IdFile = newReportFile.Id,
Begin = begin,
End = end,
Step = stepSeconds,
Format = format
};
context.Reports.Add(newReportProperties);
context.ReportProperties.Add(newReportProperties);
context.SaveChanges();
}
}
@ -80,10 +96,10 @@ namespace AsbCloudInfrastructure.Services
var suitableReportsProperties = suitableReportsFromDb.Select(r => new ReportPropertiesDto
{
Id = r.Id,
Name = Path.GetFileName(r.Name),
FullName = r.Name,
Name = Path.GetFileName(r.File.Name),
FullName = r.File.Name,
idWell = r.IdWell,
Date = r.Date,
Date = r.File.Date,
Begin = r.Begin,
End = r.End,
Step = r.Step,
@ -119,15 +135,16 @@ namespace AsbCloudInfrastructure.Services
};
}
private IEnumerable<Report> GetSuitableReportsFromDb(int idWell, DateTime begin, DateTime end, int stepSeconds, int format)
private IEnumerable<ReportProperties> GetSuitableReportsFromDb(int idWell, DateTime begin, DateTime end, int stepSeconds, int format)
{
var suitableReportsNames = (from r in db.Reports
var suitableReportsNames = (from r in db.ReportProperties.Include(r => r.File)
where r.IdWell == idWell
&& r.Begin >= begin
&& r.End <= end
&& r.Step <= stepSeconds
&& r.Format == format
select r).OrderBy(o => o.Date).Take(512).ToList();
select r).OrderBy(o => o.File.Date)
.Take(512).ToList();
return suitableReportsNames;
}
@ -148,7 +165,7 @@ namespace AsbCloudInfrastructure.Services
break;
}
generator.ReportDirectory = Path.Combine(RootPath, $"{idWell}");
generator.ReportDirectory = Path.Combine(fileService.RootPath, $"{idWell}", $"{ReportCategoryId}");
generator.Begin = begin;
generator.End = end;
generator.Step = TimeSpan.FromSeconds(stepSeconds);

View File

@ -46,9 +46,9 @@ namespace AsbCloudInfrastructure.Services
public IEnumerable<WellSectionDto> GetSections(int idWell)
{
var query = from s in db.WellSections
where s.IdWell ==
return ;
//var query = from s in db.WellSections
// where s.IdWell ==
return new List<WellSectionDto>();
}
public IEnumerable<WellOperationDto> GetOperations(int idWell)

View File

@ -19,12 +19,15 @@ namespace AsbCloudWebApi.Controllers
public class ReportController : ControllerBase
{
private readonly IReportService reportService;
private readonly IFileService fileService;
private readonly IWellService wellService;
private readonly IHubContext<ReportsHub> reportsHubContext;
public ReportController(IReportService reportService, IWellService wellService, IHubContext<ReportsHub> reportsHubContext)
public ReportController(IReportService reportService, IWellService wellService,
IFileService fileService, IHubContext<ReportsHub> reportsHubContext)
{
this.reportService = reportService;
this.fileService = fileService;
this.wellService = wellService;
this.reportsHubContext = reportsHubContext;
}
@ -52,6 +55,7 @@ namespace AsbCloudWebApi.Controllers
/// Создает отчет по скважине с указанными параметрами
/// </summary>
/// <param name="idWell">id скважины</param>
/// <param name="idUser">id пользователя</param>
/// <param name="stepSeconds">шаг интервала</param>
/// <param name="format">формат отчета (0-PDF, 1-LAS)</param>
/// <param name="begin">дата начала интервала</param>
@ -60,7 +64,7 @@ namespace AsbCloudWebApi.Controllers
[HttpPost]
[Route("{idWell}/report")]
[ProducesResponseType(typeof(int), (int)System.Net.HttpStatusCode.OK)]
public IActionResult CreateReport(int idWell, int stepSeconds, int format,
public IActionResult CreateReport(int idWell, int idUser, int stepSeconds, int format,
DateTime begin = default, DateTime end = default)
{
int? idCompany = User.GetCompanyId();
@ -71,7 +75,8 @@ namespace AsbCloudWebApi.Controllers
if (!wellService.IsCompanyOwnsWell((int)idCompany, idWell))
return Forbid();
var id = reportService.CreateReport(idWell, stepSeconds, format, begin, end, HandleReportProgressAsync, HandleReportNameAsync);
var id = reportService.CreateReport(idWell, idUser,
stepSeconds, format, begin, end, HandleReportProgressAsync, HandleReportNameAsync);
return Ok(id);
}
@ -97,7 +102,7 @@ namespace AsbCloudWebApi.Controllers
if (!wellService.IsCompanyOwnsWell((int)idCompany, idWell))
return Forbid();
// TODO: словарь content typoв
var relativePath = Path.Combine(reportService.RootPath, $"{idWell}", reportName);
var relativePath = Path.Combine(fileService.RootPath, $"{idWell}", reportName);
return PhysicalFile(Path.GetFullPath(relativePath), "application/pdf", reportName);
}
catch (FileNotFoundException ex)