forked from ddrilling/AsbCloudServer
Changed Reports to one of the Documents' category
This commit is contained in:
parent
16e52cacf5
commit
165cabd5dd
@ -6,11 +6,15 @@ namespace AsbCloudApp.Services
|
|||||||
{
|
{
|
||||||
public interface IReportService
|
public interface IReportService
|
||||||
{
|
{
|
||||||
string RootPath { get; }
|
int ReportCategoryId { get; }
|
||||||
int CreateReport(int idWell, int stepSeconds, int format, DateTime begin, DateTime end,
|
int CreateReport(int idWell, int idUser, int stepSeconds,
|
||||||
Action<float, string, int> handleReportProgress, Action<string, int> handleReportName);
|
int format, DateTime begin, DateTime end,
|
||||||
int GetReportPagesCount(int idWell, DateTime begin, DateTime end, int stepSeconds, int format);
|
Action<float, string, int> handleReportProgress,
|
||||||
IEnumerable<ReportPropertiesDto> GetSuitableReports(int idWell, DateTime begin, DateTime end, int stepSeconds, int format);
|
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);
|
DatesRangeDto GetReportsDatesRange(int idWell);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -20,14 +20,14 @@ namespace AsbCloudDb.Model
|
|||||||
public virtual DbSet<Message> Messages { get; set; }
|
public virtual DbSet<Message> Messages { get; set; }
|
||||||
public virtual DbSet<User> Users { get; set; }
|
public virtual DbSet<User> Users { get; set; }
|
||||||
public virtual DbSet<UserRole> UserRoles { 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<File> Files { get; set; }
|
||||||
public virtual DbSet<FileCategory> FileCategories { get; set; }
|
public virtual DbSet<FileCategory> FileCategories { get; set; }
|
||||||
public virtual DbSet<Telemetry> Telemetries { get; set; }
|
public virtual DbSet<Telemetry> Telemetries { get; set; }
|
||||||
public virtual DbSet<TelemetryUser> TelemetryUsers { get; set; }
|
public virtual DbSet<TelemetryUser> TelemetryUsers { get; set; }
|
||||||
public virtual DbSet<TelemetryOperation> Operations { get; set; }
|
public virtual DbSet<TelemetryOperation> Operations { get; set; }
|
||||||
public virtual DbSet<TelemetryAnalysis> TelemetryAnalysis { 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<WellSection> WellSections { get; set; }
|
||||||
public virtual DbSet<WellOperation> WellOperations { get; set; }
|
public virtual DbSet<WellOperation> WellOperations { get; set; }
|
||||||
public virtual DbSet<WellType> WellTypes { get; set; }
|
public virtual DbSet<WellType> WellTypes { get; set; }
|
||||||
|
@ -16,8 +16,8 @@ namespace AsbCloudDb.Model
|
|||||||
[Column("id_well"), Comment("id скважины")]
|
[Column("id_well"), Comment("id скважины")]
|
||||||
public int IdWell { get; set; }
|
public int IdWell { get; set; }
|
||||||
|
|
||||||
[Column("id_user"), Comment("Id пользователя, загрузившего файл")]
|
[Column("id_author"), Comment("Id пользователя, загрузившего файл")]
|
||||||
public int IdUser { get; set; }
|
public int IdAuthor { get; set; }
|
||||||
|
|
||||||
[Column("id_category"), Comment("id категории файла")]
|
[Column("id_category"), Comment("id категории файла")]
|
||||||
public int IdCategory { get; set; }
|
public int IdCategory { get; set; }
|
||||||
@ -28,12 +28,15 @@ namespace AsbCloudDb.Model
|
|||||||
[Column("date", TypeName = "timestamp with time zone")]
|
[Column("date", TypeName = "timestamp with time zone")]
|
||||||
public DateTime Date { get; set; }
|
public DateTime Date { get; set; }
|
||||||
|
|
||||||
|
[Column("is_deleted"), Comment("Удален ли файл")]
|
||||||
|
public bool IsDeleted { get; set; }
|
||||||
|
|
||||||
[JsonIgnore]
|
[JsonIgnore]
|
||||||
[ForeignKey(nameof(IdWell))]
|
[ForeignKey(nameof(IdWell))]
|
||||||
public virtual Well Well { get; set; }
|
public virtual Well Well { get; set; }
|
||||||
|
|
||||||
[JsonIgnore]
|
[JsonIgnore]
|
||||||
[ForeignKey(nameof(IdUser))]
|
[ForeignKey(nameof(IdAuthor))]
|
||||||
public virtual User User { get; set; }
|
public virtual User User { get; set; }
|
||||||
|
|
||||||
[JsonIgnore]
|
[JsonIgnore]
|
||||||
|
@ -17,7 +17,7 @@ namespace AsbCloudDb.Model
|
|||||||
DbSet<Message> Messages { get; set; }
|
DbSet<Message> Messages { get; set; }
|
||||||
DbSet<User> Users { get; set; }
|
DbSet<User> Users { get; set; }
|
||||||
DbSet<UserRole> UserRoles { get; set; }
|
DbSet<UserRole> UserRoles { get; set; }
|
||||||
DbSet<Report> Reports { get; set; }
|
DbSet<ReportProperties> ReportProperties { get; set; }
|
||||||
DbSet<File> Files { get; set; }
|
DbSet<File> Files { get; set; }
|
||||||
DbSet<FileCategory> FileCategories { get; set; }
|
DbSet<FileCategory> FileCategories { get; set; }
|
||||||
DbSet<Telemetry> Telemetries { get; set; }
|
DbSet<Telemetry> Telemetries { get; set; }
|
||||||
|
@ -5,8 +5,8 @@ using System.ComponentModel.DataAnnotations.Schema;
|
|||||||
|
|
||||||
namespace AsbCloudDb.Model
|
namespace AsbCloudDb.Model
|
||||||
{
|
{
|
||||||
[Table("t_report"), Comment("Отчеты с данными по буровым")]
|
[Table("t_report_properties"), Comment("Отчеты с данными по буровым")]
|
||||||
public class Report : IId
|
public class ReportProperties : IId
|
||||||
{
|
{
|
||||||
[Key]
|
[Key]
|
||||||
[Column("id")]
|
[Column("id")]
|
||||||
@ -15,11 +15,8 @@ namespace AsbCloudDb.Model
|
|||||||
[Column("id_well"), Comment("id скважины")]
|
[Column("id_well"), Comment("id скважины")]
|
||||||
public int IdWell { get; set; }
|
public int IdWell { get; set; }
|
||||||
|
|
||||||
[Column("name"), Comment("Название отчета (файла)")]
|
[Column("id_file"), Comment("id файла-родителя")]
|
||||||
public string Name { get; set; }
|
public int IdFile { get; set; }
|
||||||
|
|
||||||
[Column("date", TypeName = "timestamp with time zone")]
|
|
||||||
public DateTime Date { get; set; }
|
|
||||||
|
|
||||||
[Column("begin", TypeName = "timestamp with time zone")]
|
[Column("begin", TypeName = "timestamp with time zone")]
|
||||||
public DateTimeOffset Begin { get; set; }
|
public DateTimeOffset Begin { get; set; }
|
||||||
@ -35,5 +32,8 @@ namespace AsbCloudDb.Model
|
|||||||
|
|
||||||
[ForeignKey(nameof(IdWell))]
|
[ForeignKey(nameof(IdWell))]
|
||||||
public virtual Well Well { get; set; }
|
public virtual Well Well { get; set; }
|
||||||
|
|
||||||
|
[ForeignKey(nameof(IdFile))]
|
||||||
|
public virtual File File { get; set; }
|
||||||
}
|
}
|
||||||
}
|
}
|
@ -1,4 +1,5 @@
|
|||||||
using Microsoft.EntityFrameworkCore;
|
using System.Collections.Generic;
|
||||||
|
using Microsoft.EntityFrameworkCore;
|
||||||
using System.ComponentModel.DataAnnotations;
|
using System.ComponentModel.DataAnnotations;
|
||||||
using System.ComponentModel.DataAnnotations.Schema;
|
using System.ComponentModel.DataAnnotations.Schema;
|
||||||
|
|
||||||
@ -54,6 +55,8 @@ namespace AsbCloudDb.Model
|
|||||||
[InverseProperty(nameof(Model.UserRole.Users))]
|
[InverseProperty(nameof(Model.UserRole.Users))]
|
||||||
public virtual UserRole Role { get; set; }
|
public virtual UserRole Role { get; set; }
|
||||||
|
|
||||||
|
public virtual ICollection<File> Files { get; set; }
|
||||||
|
|
||||||
public string MakeDisplayName()
|
public string MakeDisplayName()
|
||||||
{
|
{
|
||||||
if (string.IsNullOrEmpty(Surname))
|
if (string.IsNullOrEmpty(Surname))
|
||||||
|
@ -34,7 +34,7 @@ namespace AsbCloudInfrastructure.Services
|
|||||||
IdWell = fileInfo.idWell,
|
IdWell = fileInfo.idWell,
|
||||||
IdCategory = fileInfo.idCategory,
|
IdCategory = fileInfo.idCategory,
|
||||||
Date = fileInfo.date,
|
Date = fileInfo.date,
|
||||||
IdUser = fileInfo.idUser
|
IdAuthor = fileInfo.idUser
|
||||||
};
|
};
|
||||||
|
|
||||||
db.Files.Add(file);
|
db.Files.Add(file);
|
||||||
@ -73,7 +73,7 @@ namespace AsbCloudInfrastructure.Services
|
|||||||
if (skip > 0)
|
if (skip > 0)
|
||||||
filesInfoQuery = filesInfoQuery.Skip(skip);
|
filesInfoQuery = filesInfoQuery.Skip(skip);
|
||||||
|
|
||||||
var filesInfoList = filesInfoQuery.Take(take).ToList();
|
var filesInfoList = filesInfoQuery.OrderBy(f => f.Date).Take(take).ToList();
|
||||||
|
|
||||||
if (filesInfoList.Count == 0)
|
if (filesInfoList.Count == 0)
|
||||||
return result;
|
return result;
|
||||||
|
@ -17,20 +17,25 @@ namespace AsbCloudInfrastructure.Services
|
|||||||
private readonly IAsbCloudDbContext db;
|
private readonly IAsbCloudDbContext db;
|
||||||
private readonly IConfiguration configuration;
|
private readonly IConfiguration configuration;
|
||||||
private readonly ITelemetryService telemetryService;
|
private readonly ITelemetryService telemetryService;
|
||||||
|
private readonly IFileService fileService;
|
||||||
private readonly IBackgroundQueue queue;
|
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.db = db;
|
||||||
this.configuration = configuration;
|
this.configuration = configuration;
|
||||||
this.telemetryService = telemetryService;
|
this.telemetryService = telemetryService;
|
||||||
|
this.fileService = fileService;
|
||||||
this.queue = queue;
|
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)
|
DateTime end, Action<float, string, int> progressHandler, Action<string, int> reportNameHandler)
|
||||||
{
|
{
|
||||||
var newReportId = queue.EnqueueTask((id) =>
|
var newReportId = queue.EnqueueTask((id) =>
|
||||||
@ -48,17 +53,28 @@ namespace AsbCloudInfrastructure.Services
|
|||||||
var shorReportName = Path.GetFileName(newReportName);
|
var shorReportName = Path.GetFileName(newReportName);
|
||||||
reportNameHandler.Invoke(shorReportName, id);
|
reportNameHandler.Invoke(shorReportName, id);
|
||||||
|
|
||||||
var newReportProperties = new Report
|
var newReportFile = new AsbCloudDb.Model.File
|
||||||
{
|
{
|
||||||
Name = newReportName,
|
|
||||||
IdWell = idWell,
|
IdWell = idWell,
|
||||||
|
IdAuthor = idUser,
|
||||||
|
IdCategory = ReportCategoryId,
|
||||||
|
Name = newReportName,
|
||||||
Date = DateTime.Now,
|
Date = DateTime.Now,
|
||||||
|
};
|
||||||
|
|
||||||
|
context.Files.Add(newReportFile);
|
||||||
|
context.SaveChanges();
|
||||||
|
|
||||||
|
var newReportProperties = new ReportProperties
|
||||||
|
{
|
||||||
|
IdWell = idWell,
|
||||||
|
IdFile = newReportFile.Id,
|
||||||
Begin = begin,
|
Begin = begin,
|
||||||
End = end,
|
End = end,
|
||||||
Step = stepSeconds,
|
Step = stepSeconds,
|
||||||
Format = format
|
Format = format
|
||||||
};
|
};
|
||||||
context.Reports.Add(newReportProperties);
|
context.ReportProperties.Add(newReportProperties);
|
||||||
context.SaveChanges();
|
context.SaveChanges();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -80,10 +96,10 @@ namespace AsbCloudInfrastructure.Services
|
|||||||
var suitableReportsProperties = suitableReportsFromDb.Select(r => new ReportPropertiesDto
|
var suitableReportsProperties = suitableReportsFromDb.Select(r => new ReportPropertiesDto
|
||||||
{
|
{
|
||||||
Id = r.Id,
|
Id = r.Id,
|
||||||
Name = Path.GetFileName(r.Name),
|
Name = Path.GetFileName(r.File.Name),
|
||||||
FullName = r.Name,
|
FullName = r.File.Name,
|
||||||
idWell = r.IdWell,
|
idWell = r.IdWell,
|
||||||
Date = r.Date,
|
Date = r.File.Date,
|
||||||
Begin = r.Begin,
|
Begin = r.Begin,
|
||||||
End = r.End,
|
End = r.End,
|
||||||
Step = r.Step,
|
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
|
where r.IdWell == idWell
|
||||||
&& r.Begin >= begin
|
&& r.Begin >= begin
|
||||||
&& r.End <= end
|
&& r.End <= end
|
||||||
&& r.Step <= stepSeconds
|
&& r.Step <= stepSeconds
|
||||||
&& r.Format == format
|
&& r.Format == format
|
||||||
select r).OrderBy(o => o.Date).Take(512).ToList();
|
select r).OrderBy(o => o.File.Date)
|
||||||
|
.Take(512).ToList();
|
||||||
|
|
||||||
return suitableReportsNames;
|
return suitableReportsNames;
|
||||||
}
|
}
|
||||||
@ -148,7 +165,7 @@ namespace AsbCloudInfrastructure.Services
|
|||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
generator.ReportDirectory = Path.Combine(RootPath, $"{idWell}");
|
generator.ReportDirectory = Path.Combine(fileService.RootPath, $"{idWell}", $"{ReportCategoryId}");
|
||||||
generator.Begin = begin;
|
generator.Begin = begin;
|
||||||
generator.End = end;
|
generator.End = end;
|
||||||
generator.Step = TimeSpan.FromSeconds(stepSeconds);
|
generator.Step = TimeSpan.FromSeconds(stepSeconds);
|
||||||
|
@ -46,9 +46,9 @@ namespace AsbCloudInfrastructure.Services
|
|||||||
|
|
||||||
public IEnumerable<WellSectionDto> GetSections(int idWell)
|
public IEnumerable<WellSectionDto> GetSections(int idWell)
|
||||||
{
|
{
|
||||||
var query = from s in db.WellSections
|
//var query = from s in db.WellSections
|
||||||
where s.IdWell ==
|
// where s.IdWell ==
|
||||||
return ;
|
return new List<WellSectionDto>();
|
||||||
}
|
}
|
||||||
|
|
||||||
public IEnumerable<WellOperationDto> GetOperations(int idWell)
|
public IEnumerable<WellOperationDto> GetOperations(int idWell)
|
||||||
|
@ -19,12 +19,15 @@ namespace AsbCloudWebApi.Controllers
|
|||||||
public class ReportController : ControllerBase
|
public class ReportController : ControllerBase
|
||||||
{
|
{
|
||||||
private readonly IReportService reportService;
|
private readonly IReportService reportService;
|
||||||
|
private readonly IFileService fileService;
|
||||||
private readonly IWellService wellService;
|
private readonly IWellService wellService;
|
||||||
private readonly IHubContext<ReportsHub> reportsHubContext;
|
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.reportService = reportService;
|
||||||
|
this.fileService = fileService;
|
||||||
this.wellService = wellService;
|
this.wellService = wellService;
|
||||||
this.reportsHubContext = reportsHubContext;
|
this.reportsHubContext = reportsHubContext;
|
||||||
}
|
}
|
||||||
@ -52,6 +55,7 @@ namespace AsbCloudWebApi.Controllers
|
|||||||
/// Создает отчет по скважине с указанными параметрами
|
/// Создает отчет по скважине с указанными параметрами
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="idWell">id скважины</param>
|
/// <param name="idWell">id скважины</param>
|
||||||
|
/// <param name="idUser">id пользователя</param>
|
||||||
/// <param name="stepSeconds">шаг интервала</param>
|
/// <param name="stepSeconds">шаг интервала</param>
|
||||||
/// <param name="format">формат отчета (0-PDF, 1-LAS)</param>
|
/// <param name="format">формат отчета (0-PDF, 1-LAS)</param>
|
||||||
/// <param name="begin">дата начала интервала</param>
|
/// <param name="begin">дата начала интервала</param>
|
||||||
@ -60,7 +64,7 @@ namespace AsbCloudWebApi.Controllers
|
|||||||
[HttpPost]
|
[HttpPost]
|
||||||
[Route("{idWell}/report")]
|
[Route("{idWell}/report")]
|
||||||
[ProducesResponseType(typeof(int), (int)System.Net.HttpStatusCode.OK)]
|
[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)
|
DateTime begin = default, DateTime end = default)
|
||||||
{
|
{
|
||||||
int? idCompany = User.GetCompanyId();
|
int? idCompany = User.GetCompanyId();
|
||||||
@ -71,7 +75,8 @@ namespace AsbCloudWebApi.Controllers
|
|||||||
if (!wellService.IsCompanyOwnsWell((int)idCompany, idWell))
|
if (!wellService.IsCompanyOwnsWell((int)idCompany, idWell))
|
||||||
return Forbid();
|
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);
|
return Ok(id);
|
||||||
}
|
}
|
||||||
@ -97,7 +102,7 @@ namespace AsbCloudWebApi.Controllers
|
|||||||
if (!wellService.IsCompanyOwnsWell((int)idCompany, idWell))
|
if (!wellService.IsCompanyOwnsWell((int)idCompany, idWell))
|
||||||
return Forbid();
|
return Forbid();
|
||||||
// TODO: словарь content typoв
|
// 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);
|
return PhysicalFile(Path.GetFullPath(relativePath), "application/pdf", reportName);
|
||||||
}
|
}
|
||||||
catch (FileNotFoundException ex)
|
catch (FileNotFoundException ex)
|
||||||
|
Loading…
Reference in New Issue
Block a user