forked from ddrilling/AsbCloudServer
Merge branch 'reports' into dev
This commit is contained in:
commit
4ef8702948
10
AsbCloudApp/Data/ReportProgressDto.cs
Normal file
10
AsbCloudApp/Data/ReportProgressDto.cs
Normal file
@ -0,0 +1,10 @@
|
|||||||
|
namespace AsbCloudApp.Data
|
||||||
|
{
|
||||||
|
public class ReportProgressDto
|
||||||
|
{
|
||||||
|
public float Progress { get; set; }
|
||||||
|
public string Operation { get; set; }
|
||||||
|
public int CurrentPage { get; set; }
|
||||||
|
public int TotalPages { get; set; }
|
||||||
|
}
|
||||||
|
}
|
@ -6,7 +6,7 @@ namespace AsbCloudApp.Data
|
|||||||
{
|
{
|
||||||
public int Id { get; set; }
|
public int Id { get; set; }
|
||||||
public string Name { get; set; }
|
public string Name { get; set; }
|
||||||
public string FullName { get; set; }
|
public string Url { get; set; }
|
||||||
public int IdWell { get; set; }
|
public int IdWell { get; set; }
|
||||||
public DateTime Date { get; set; }
|
public DateTime Date { get; set; }
|
||||||
public DateTimeOffset Begin { get; set; }
|
public DateTimeOffset Begin { get; set; }
|
||||||
|
@ -24,6 +24,8 @@ namespace AsbCloudApp.Services
|
|||||||
CancellationToken token = default);
|
CancellationToken token = default);
|
||||||
Task<IEnumerable<FileInfoDto>> GetInfosByCategoryAsync(int idWell, int idCategory, CancellationToken token = default);
|
Task<IEnumerable<FileInfoDto>> GetInfosByCategoryAsync(int idWell, int idCategory, CancellationToken token = default);
|
||||||
Task<int> DeletedAsync(int id, CancellationToken token);
|
Task<int> DeletedAsync(int id, CancellationToken token);
|
||||||
string GetFileName(FileInfoDto fileInfo);
|
string GetUrl(FileInfoDto fileInfo);
|
||||||
|
string GetUrl(int idFile);
|
||||||
|
string GetUrl(int idWell, int idCategory, int idFile, string dotExtention);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -11,14 +11,15 @@ namespace AsbCloudApp.Services
|
|||||||
int ReportCategoryId { get; }
|
int ReportCategoryId { get; }
|
||||||
int CreateReport(int idWell, int idUser, int stepSeconds,
|
int CreateReport(int idWell, int idUser, int stepSeconds,
|
||||||
int format, DateTime begin, DateTime end,
|
int format, DateTime begin, DateTime end,
|
||||||
Action<float, string, int> handleReportProgress,
|
Action<object, int> handleReportProgress);
|
||||||
Action<string, int> handleReportName);
|
|
||||||
int GetReportPagesCount(int idWell, DateTime begin, DateTime end,
|
int GetReportPagesCount(int idWell, DateTime begin, DateTime end,
|
||||||
int stepSeconds, int format);
|
int stepSeconds, int format);
|
||||||
Task<IEnumerable<ReportPropertiesDto>> GetSuitableReportsAsync(int idWell,
|
|
||||||
|
Task<List<ReportPropertiesDto>> GetSuitableReportsAsync(int idWell,
|
||||||
DateTime begin, DateTime end, int stepSeconds, int format,
|
DateTime begin, DateTime end, int stepSeconds, int format,
|
||||||
CancellationToken token);
|
CancellationToken token);
|
||||||
Task<DatesRangeDto> GetReportsDatesRangeAsync(int idWell,
|
Task<DatesRangeDto> GetReportsDatesRangeAsync(int idWell,
|
||||||
CancellationToken token);
|
CancellationToken token);
|
||||||
|
Task<List<ReportPropertiesDto>> GetAllReportsByWellAsync(int idWell, CancellationToken token);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -5,11 +5,11 @@
|
|||||||
</PropertyGroup>
|
</PropertyGroup>
|
||||||
|
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
<PackageReference Include="Microsoft.EntityFrameworkCore.Tools" Version="5.0.2">
|
<PackageReference Include="Microsoft.EntityFrameworkCore.Tools" Version="5.0.10">
|
||||||
<PrivateAssets>all</PrivateAssets>
|
<PrivateAssets>all</PrivateAssets>
|
||||||
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
|
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
|
||||||
</PackageReference>
|
</PackageReference>
|
||||||
<PackageReference Include="Npgsql.EntityFrameworkCore.PostgreSQL" Version="5.0.2" />
|
<PackageReference Include="Npgsql.EntityFrameworkCore.PostgreSQL" Version="5.0.10" />
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
|
|
||||||
</Project>
|
</Project>
|
||||||
|
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
@ -54,6 +54,7 @@ namespace AsbSaubReport
|
|||||||
Customer = well.RelationCompaniesWells.FirstOrDefault(c => c.Company.IdCompanyType == 1)?.Company.Caption,
|
Customer = well.RelationCompaniesWells.FirstOrDefault(c => c.Company.IdCompanyType == 1)?.Company.Caption,
|
||||||
DrillingStartDate = well.Telemetry?.Info?.DrillingStartDate ?? default,
|
DrillingStartDate = well.Telemetry?.Info?.DrillingStartDate ?? default,
|
||||||
TimeZoneId = well.Telemetry?.Info?.TimeZoneId ?? default,
|
TimeZoneId = well.Telemetry?.Info?.TimeZoneId ?? default,
|
||||||
|
TimeZoneOffsetTotalHours = well.Telemetry?.Info?.TimeZoneOffsetTotalHours ?? default,
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -62,7 +63,7 @@ namespace AsbSaubReport
|
|||||||
var messagesStat = (from item in context.TelemetryMessages
|
var messagesStat = (from item in context.TelemetryMessages
|
||||||
where item.IdTelemetry == idTelemetry
|
where item.IdTelemetry == idTelemetry
|
||||||
group item.Date by item.IdTelemetry into g
|
group item.Date by item.IdTelemetry into g
|
||||||
select new { min = g.Min(), max = g.Max(), count = g.Count()})
|
select new { min = g.Min(), max = g.Max(), count = g.Count() })
|
||||||
.FirstOrDefault();
|
.FirstOrDefault();
|
||||||
|
|
||||||
var dataStat = (from item in context.TelemetryDataSaub
|
var dataStat = (from item in context.TelemetryDataSaub
|
||||||
@ -73,8 +74,8 @@ namespace AsbSaubReport
|
|||||||
|
|
||||||
var result = new AnalyzeResult
|
var result = new AnalyzeResult
|
||||||
{
|
{
|
||||||
MinDate = dataStat?.max ?? messagesStat?.min ?? default,
|
MinDate = dataStat?.min ?? messagesStat?.min ?? default,
|
||||||
MaxDate = dataStat?.max ?? messagesStat?.min ?? default,
|
MaxDate = dataStat?.max ?? messagesStat?.max ?? default,
|
||||||
MessagesCount = messagesStat?.count ?? 0,
|
MessagesCount = messagesStat?.count ?? 0,
|
||||||
};
|
};
|
||||||
|
|
||||||
@ -86,6 +87,7 @@ namespace AsbSaubReport
|
|||||||
where item.IdTelemetry == idTelemetry
|
where item.IdTelemetry == idTelemetry
|
||||||
&& item.Date >= begin
|
&& item.Date >= begin
|
||||||
&& item.Date <= end
|
&& item.Date <= end
|
||||||
|
orderby item.Date
|
||||||
select new DataSaubReport
|
select new DataSaubReport
|
||||||
{
|
{
|
||||||
Id = item.Id,
|
Id = item.Id,
|
||||||
@ -115,6 +117,7 @@ namespace AsbSaubReport
|
|||||||
where item.IdTelemetry == idTelemetry
|
where item.IdTelemetry == idTelemetry
|
||||||
&& item.Date >= begin
|
&& item.Date >= begin
|
||||||
&& item.Date <= end
|
&& item.Date <= end
|
||||||
|
orderby item.Date
|
||||||
select new MessageReport
|
select new MessageReport
|
||||||
{
|
{
|
||||||
Id = item.Id,
|
Id = item.Id,
|
||||||
|
@ -55,7 +55,7 @@ namespace AsbCloudInfrastructure.Services
|
|||||||
|
|
||||||
var fileNames = filesInfos
|
var fileNames = filesInfos
|
||||||
.Where(f => f.Name != resultFileName)
|
.Where(f => f.Name != resultFileName)
|
||||||
.Select(f => fileService.GetFileName(f));
|
.Select(f => fileService.GetUrl(f));
|
||||||
|
|
||||||
var stream = new MemoryStream(1024 * 1024);
|
var stream = new MemoryStream(1024 * 1024);
|
||||||
UniteExcelFiles(fileNames, stream);
|
UniteExcelFiles(fileNames, stream);
|
||||||
|
@ -52,10 +52,8 @@ namespace AsbCloudInfrastructure.Services
|
|||||||
|
|
||||||
Directory.CreateDirectory(Path.GetDirectoryName(relativePath));
|
Directory.CreateDirectory(Path.GetDirectoryName(relativePath));
|
||||||
|
|
||||||
using (var newfileStream = new FileStream(relativePath, FileMode.Create))
|
using var newfileStream = new FileStream(relativePath, FileMode.Create);
|
||||||
{
|
await fileStream.CopyToAsync(newfileStream, token).ConfigureAwait(false);
|
||||||
await fileStream.CopyToAsync(newfileStream);
|
|
||||||
}
|
|
||||||
|
|
||||||
var dto = entry.Entity.Adapt<FileInfoDto>();
|
var dto = entry.Entity.Adapt<FileInfoDto>();
|
||||||
return dto;
|
return dto;
|
||||||
@ -164,7 +162,7 @@ namespace AsbCloudInfrastructure.Services
|
|||||||
if (fileInfo is null)
|
if (fileInfo is null)
|
||||||
return 0;
|
return 0;
|
||||||
|
|
||||||
var fileName = GetFileName(fileInfo.Adapt<FileInfoDto>());
|
var fileName = GetUrl(fileInfo.Adapt<FileInfoDto>());
|
||||||
if (File.Exists(fileName))
|
if (File.Exists(fileName))
|
||||||
File.Delete(fileName);
|
File.Delete(fileName);
|
||||||
|
|
||||||
@ -172,12 +170,22 @@ namespace AsbCloudInfrastructure.Services
|
|||||||
return await db.SaveChangesAsync(token).ConfigureAwait(false);
|
return await db.SaveChangesAsync(token).ConfigureAwait(false);
|
||||||
}
|
}
|
||||||
|
|
||||||
public string GetFileName(FileInfoDto fileInfo)
|
public string GetUrl(FileInfoDto fileInfo) =>
|
||||||
|
GetUrl(fileInfo.IdWell, fileInfo.IdCategory, fileInfo.Id, Path.GetExtension(fileInfo.Name));
|
||||||
|
|
||||||
|
public string GetUrl(int idFile)
|
||||||
{
|
{
|
||||||
var fileName = $"{fileInfo.Id}{Path.GetExtension(fileInfo.Name)}";
|
var fileInfo = db.Files
|
||||||
fileName = Path.Combine(RootPath, fileInfo.IdWell.ToString(), fileInfo.IdCategory.ToString(), fileName);
|
.FirstOrDefault(f => f.Id == idFile);
|
||||||
fileName = Path.GetFullPath(fileName);
|
|
||||||
return fileName;
|
if (fileInfo is null)
|
||||||
|
return null;
|
||||||
|
|
||||||
|
return GetUrl(fileInfo.IdWell, fileInfo.IdCategory, fileInfo.Id, Path.GetExtension(fileInfo.Name));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public string GetUrl(int idWell, int idCategory, int idFile, string dotExtention) =>
|
||||||
|
Path.Combine(RootPath, idWell.ToString(), idCategory.ToString(), $"{idFile}{dotExtention}");
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -2,7 +2,7 @@
|
|||||||
using AsbCloudApp.Services;
|
using AsbCloudApp.Services;
|
||||||
using AsbCloudDb.Model;
|
using AsbCloudDb.Model;
|
||||||
using AsbSaubReport;
|
using AsbSaubReport;
|
||||||
using AsbSaubReportPdf;
|
using Mapster;
|
||||||
using Microsoft.EntityFrameworkCore;
|
using Microsoft.EntityFrameworkCore;
|
||||||
using Microsoft.Extensions.Configuration;
|
using Microsoft.Extensions.Configuration;
|
||||||
using System;
|
using System;
|
||||||
@ -39,41 +39,44 @@ namespace AsbCloudInfrastructure.Services
|
|||||||
public int ReportCategoryId { get; private set; }
|
public int ReportCategoryId { get; private set; }
|
||||||
|
|
||||||
public int CreateReport(int idWell, int idUser, 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<object, int> progressHandler)
|
||||||
{
|
{
|
||||||
var newReportId = queue.EnqueueTask((id) =>
|
var newReportId = queue.EnqueueTask((id) =>
|
||||||
{
|
{
|
||||||
var optionsBuilder = new DbContextOptionsBuilder<AsbCloudDbContext>();
|
var optionsBuilder = new DbContextOptionsBuilder<AsbCloudDbContext>();
|
||||||
optionsBuilder.UseNpgsql(configuration.GetConnectionString("DefaultConnection"));
|
optionsBuilder.UseNpgsql(configuration.GetConnectionString("DefaultConnection"));
|
||||||
|
var tempDir = Path.Combine(Path.GetTempPath(), "report");
|
||||||
|
|
||||||
|
using var context = new AsbCloudDbContext(optionsBuilder.Options);
|
||||||
|
|
||||||
using (var context = new AsbCloudDbContext(optionsBuilder.Options))
|
|
||||||
{
|
|
||||||
var generator = GetReportGenerator(idWell, begin, end, stepSeconds, format, context);
|
var generator = GetReportGenerator(idWell, begin, end, stepSeconds, format, context);
|
||||||
generator.OnProgress += (s, e) => progressHandler.Invoke(e.progress, e.operation, id);
|
var reportFileName = Path.Combine(tempDir, generator.GetReportDefaultFileName());
|
||||||
|
var totalPages = generator.GetPagesCount();
|
||||||
|
|
||||||
var reportFileName = GetReportFileName(context, idWell);
|
generator.OnProgress += (s, e) =>
|
||||||
|
|
||||||
generator.Make(reportFileName);
|
|
||||||
if (reportFileName is not null)
|
|
||||||
{
|
{
|
||||||
var shorReportName = Path.GetFileName(reportFileName);
|
progressHandler.Invoke(e.Adapt<ReportProgressDto>(), id);
|
||||||
reportNameHandler.Invoke(shorReportName, id);
|
|
||||||
|
|
||||||
var newReportFile = new AsbCloudDb.Model.FileInfo
|
|
||||||
{
|
|
||||||
IdWell = idWell,
|
|
||||||
IdAuthor = idUser,
|
|
||||||
IdCategory = ReportCategoryId,
|
|
||||||
Name = reportFileName,
|
|
||||||
UploadDate = DateTime.Now,
|
|
||||||
};
|
};
|
||||||
|
generator.Make(reportFileName);
|
||||||
|
|
||||||
context.Files.Add(newReportFile);
|
var fileService = new FileService(context);
|
||||||
|
using var filestream = File.OpenRead(reportFileName);
|
||||||
|
var fileInfo = fileService.SaveAsync(idWell, idUser, ReportCategoryId, reportFileName, filestream).Result;
|
||||||
|
filestream.Close();
|
||||||
|
|
||||||
|
progressHandler.Invoke(new
|
||||||
|
{
|
||||||
|
Operation = "done",
|
||||||
|
Progress = 100f,
|
||||||
|
TotalPages = totalPages,
|
||||||
|
CurrentPage = totalPages,
|
||||||
|
file = fileInfo,
|
||||||
|
}, id);
|
||||||
|
|
||||||
var newReportProperties = new ReportProperty
|
var newReportProperties = new ReportProperty
|
||||||
{
|
{
|
||||||
IdWell = idWell,
|
IdWell = idWell,
|
||||||
IdFile = newReportFile.Id,
|
IdFile = fileInfo.Id,
|
||||||
Begin = begin,
|
Begin = begin,
|
||||||
End = end,
|
End = end,
|
||||||
Step = stepSeconds,
|
Step = stepSeconds,
|
||||||
@ -81,48 +84,21 @@ namespace AsbCloudInfrastructure.Services
|
|||||||
};
|
};
|
||||||
context.ReportProperties.Add(newReportProperties);
|
context.ReportProperties.Add(newReportProperties);
|
||||||
context.SaveChanges();
|
context.SaveChanges();
|
||||||
}
|
|
||||||
}
|
|
||||||
});
|
});
|
||||||
return newReportId;
|
progressHandler.Invoke(new ReportProgressDto
|
||||||
}
|
|
||||||
|
|
||||||
private string GetReportFileName(AsbCloudDbContext context, int idWell)
|
|
||||||
{
|
{
|
||||||
var well = context.Wells.Include(w => w.Cluster).FirstOrDefault(w => w.Id == idWell);
|
Operation = "Ожидает начала в очереди.",
|
||||||
var fileName = Path.Combine(fileService.RootPath, $"{idWell}", $"{ReportCategoryId}", $"Рапорт куст{well?.Cluster?.Caption} скв{well.Caption}.pdf") ;
|
Progress = 0f,
|
||||||
return fileName;
|
}, newReportId);
|
||||||
|
return newReportId;
|
||||||
}
|
}
|
||||||
|
|
||||||
public int GetReportPagesCount(int idWell, DateTime begin, DateTime end, int stepSeconds, int format)
|
public int GetReportPagesCount(int idWell, DateTime begin, DateTime end, int stepSeconds, int format)
|
||||||
{
|
{
|
||||||
var generator = GetReportGenerator(idWell, begin, end, stepSeconds, format, (AsbCloudDbContext)db);
|
var generator = GetReportGenerator(idWell, begin, end, stepSeconds, format, (AsbCloudDbContext)db);
|
||||||
|
|
||||||
return generator.GetPagesCount();
|
return generator.GetPagesCount();
|
||||||
}
|
}
|
||||||
|
|
||||||
public async Task<IEnumerable<ReportPropertiesDto>> GetSuitableReportsAsync(int idWell,
|
|
||||||
DateTime begin, DateTime end, int stepSeconds, int format, CancellationToken token = default)
|
|
||||||
{
|
|
||||||
var suitableReportsFromDb = await GetSuitableReportsFromDbAsync(idWell,
|
|
||||||
begin, end, stepSeconds, format, token).ConfigureAwait(false);
|
|
||||||
|
|
||||||
var suitableReportsProperties = suitableReportsFromDb.Select(r => new ReportPropertiesDto
|
|
||||||
{
|
|
||||||
Id = r.Id,
|
|
||||||
Name = Path.GetFileName(r.File.Name),
|
|
||||||
FullName = r.File.Name,
|
|
||||||
IdWell = r.IdWell,
|
|
||||||
Date = r.File.UploadDate,
|
|
||||||
Begin = r.Begin,
|
|
||||||
End = r.End,
|
|
||||||
Step = r.Step,
|
|
||||||
Format = r.Format == 0 ? ".pdf" : ".las"
|
|
||||||
});
|
|
||||||
|
|
||||||
return suitableReportsProperties;
|
|
||||||
}
|
|
||||||
|
|
||||||
public async Task<DatesRangeDto> GetReportsDatesRangeAsync(int idWell,
|
public async Task<DatesRangeDto> GetReportsDatesRangeAsync(int idWell,
|
||||||
CancellationToken token = default)
|
CancellationToken token = default)
|
||||||
{
|
{
|
||||||
@ -154,25 +130,53 @@ namespace AsbCloudInfrastructure.Services
|
|||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
private async Task<IEnumerable<ReportProperty>> GetSuitableReportsFromDbAsync(int idWell,
|
|
||||||
DateTime begin, DateTime end, int stepSeconds, int format,
|
[Obsolete]
|
||||||
CancellationToken token = default)
|
Task<List<ReportPropertiesDto>> IReportService.GetSuitableReportsAsync(int idWell, DateTime begin, DateTime end, int stepSeconds, int format, CancellationToken token) =>
|
||||||
{
|
(from r in db.ReportProperties.Include(r => r.File)
|
||||||
var suitableReportsNames = await (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.File.UploadDate)
|
select new ReportPropertiesDto
|
||||||
|
{
|
||||||
|
Id = r.Id,
|
||||||
|
Name = r.File.Name,
|
||||||
|
Url = fileService.GetUrl(r.IdFile),
|
||||||
|
IdWell = r.IdWell,
|
||||||
|
Date = r.File.UploadDate,
|
||||||
|
Begin = r.Begin,
|
||||||
|
End = r.End,
|
||||||
|
Step = r.Step,
|
||||||
|
Format = r.Format == 0 ? ".pdf" : ".las"
|
||||||
|
})
|
||||||
|
.OrderBy(o => o.Date)
|
||||||
.AsNoTracking()
|
.AsNoTracking()
|
||||||
.Take(512).ToListAsync(token)
|
.Take(512).ToListAsync(token);
|
||||||
.ConfigureAwait(false);
|
|
||||||
|
|
||||||
return suitableReportsNames;
|
public Task<List<ReportPropertiesDto>> GetAllReportsByWellAsync(int idWell, CancellationToken token) =>
|
||||||
}
|
(from r in db.ReportProperties.Include(r => r.File)
|
||||||
|
where r.IdWell == idWell
|
||||||
|
select new ReportPropertiesDto
|
||||||
|
{
|
||||||
|
Id = r.Id,
|
||||||
|
Name = r.File.Name,
|
||||||
|
#pragma warning disable IDE0057 // Use range operator
|
||||||
|
Url = fileService.GetUrl(r.IdWell, ReportCategoryId, r.File.Id, r.File.Name.Substring(r.File.Name.LastIndexOf(".") > 0 ? r.File.Name.LastIndexOf(".") : r.File.Name.Length)),
|
||||||
|
#pragma warning restore IDE0057 // Use range operator
|
||||||
|
IdWell = r.IdWell,
|
||||||
|
Date = r.File.UploadDate,
|
||||||
|
Begin = r.Begin,
|
||||||
|
End = r.End,
|
||||||
|
Step = r.Step,
|
||||||
|
Format = r.Format == 0 ? ".pdf" : ".las"
|
||||||
|
})
|
||||||
|
.OrderBy(o => o.Date)
|
||||||
|
.AsNoTracking()
|
||||||
|
.Take(1024).ToListAsync(token);
|
||||||
|
|
||||||
private IReportGenerator GetReportGenerator(int idWell, DateTime begin,
|
private static IReportGenerator GetReportGenerator(int idWell, DateTime begin,
|
||||||
DateTime end, int stepSeconds, int format, AsbCloudDbContext context)
|
DateTime end, int stepSeconds, int format, AsbCloudDbContext context)
|
||||||
{
|
{
|
||||||
var dataSource = new ReportDataSourcePgCloud(context, idWell);
|
var dataSource = new ReportDataSourcePgCloud(context, idWell);
|
||||||
@ -181,11 +185,11 @@ namespace AsbCloudInfrastructure.Services
|
|||||||
switch (format)
|
switch (format)
|
||||||
{
|
{
|
||||||
case 1: //LAS
|
case 1: //LAS
|
||||||
generator = new AsbSaubReportLas.LasReprotGenerator(dataSource);
|
generator = new AsbSaubReportLas.ReprotGeneratorLas(dataSource);
|
||||||
break;
|
break;
|
||||||
case 0: //PDF
|
case 0: //PDF
|
||||||
default:
|
default:
|
||||||
generator = new PdfReprotGenerator(dataSource);
|
generator = new AsbSaubReportPdf.ReprotGeneratorPdf(dataSource);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -12,7 +12,7 @@ using System.Threading.Tasks;
|
|||||||
|
|
||||||
namespace AsbCloudInfrastructure.Services
|
namespace AsbCloudInfrastructure.Services
|
||||||
{
|
{
|
||||||
public abstract class TelemetryDataService<TDto, TModel> : ITelemetryDataService<TDto>, IConverter<TDto, TModel>
|
public abstract class TelemetryDataBaseService<TDto, TModel> : ITelemetryDataService<TDto>, IConverter<TDto, TModel>
|
||||||
where TDto : AsbCloudApp.Data.ITelemetryData
|
where TDto : AsbCloudApp.Data.ITelemetryData
|
||||||
where TModel : class, AsbCloudDb.Model.ITelemetryData
|
where TModel : class, AsbCloudDb.Model.ITelemetryData
|
||||||
{
|
{
|
||||||
@ -23,7 +23,7 @@ namespace AsbCloudInfrastructure.Services
|
|||||||
protected readonly CacheTable<TelemetryUser> cacheTelemetryUsers;
|
protected readonly CacheTable<TelemetryUser> cacheTelemetryUsers;
|
||||||
protected readonly CacheTable<Well> cacheWells;
|
protected readonly CacheTable<Well> cacheWells;
|
||||||
|
|
||||||
public TelemetryDataService(
|
public TelemetryDataBaseService(
|
||||||
IAsbCloudDbContext db,
|
IAsbCloudDbContext db,
|
||||||
ITelemetryService telemetryService,
|
ITelemetryService telemetryService,
|
||||||
CacheDb cacheDb)
|
CacheDb cacheDb)
|
@ -6,7 +6,7 @@ using Mapster;
|
|||||||
|
|
||||||
namespace AsbCloudInfrastructure.Services
|
namespace AsbCloudInfrastructure.Services
|
||||||
{
|
{
|
||||||
public class TelemetryDataSaubService: TelemetryDataService<AsbCloudApp.Data.TelemetryDataSaubDto, AsbCloudDb.Model.TelemetryDataSaub>
|
public class TelemetryDataSaubService: TelemetryDataBaseService<AsbCloudApp.Data.TelemetryDataSaubDto, AsbCloudDb.Model.TelemetryDataSaub>
|
||||||
{
|
{
|
||||||
public TelemetryDataSaubService(
|
public TelemetryDataSaubService(
|
||||||
IAsbCloudDbContext db,
|
IAsbCloudDbContext db,
|
||||||
@ -18,18 +18,18 @@ namespace AsbCloudInfrastructure.Services
|
|||||||
public override TelemetryDataSaub Convert(TelemetryDataSaubDto src)
|
public override TelemetryDataSaub Convert(TelemetryDataSaubDto src)
|
||||||
{
|
{
|
||||||
var entity = src.Adapt<TelemetryDataSaub>();
|
var entity = src.Adapt<TelemetryDataSaub>();
|
||||||
var telemetryUser = cacheTelemetryUsers
|
var telemetryUser = cacheTelemetryUsers?
|
||||||
.FirstOrDefault(u => u.IdTelemetry == src.IdTelemetry && (u.Name == src.User || u.Surname == src.User));
|
.FirstOrDefault(u => u.IdTelemetry == src.IdTelemetry && (u.Name == src.User || u.Surname == src.User));
|
||||||
entity.IdUser = telemetryUser.IdUser;
|
entity.IdUser = telemetryUser?.IdUser;
|
||||||
return entity;
|
return entity;
|
||||||
}
|
}
|
||||||
|
|
||||||
public override TelemetryDataSaubDto Convert(TelemetryDataSaub src)
|
public override TelemetryDataSaubDto Convert(TelemetryDataSaub src)
|
||||||
{
|
{
|
||||||
var dto = src.Adapt<TelemetryDataSaubDto>();
|
var dto = src.Adapt<TelemetryDataSaubDto>();
|
||||||
var telemetryUser = cacheTelemetryUsers
|
var telemetryUser = cacheTelemetryUsers?
|
||||||
.FirstOrDefault(u => u.IdTelemetry == src.IdTelemetry && u.IdUser == src.IdUser);
|
.FirstOrDefault(u => u.IdTelemetry == src.IdTelemetry && u.IdUser == src.IdUser);
|
||||||
dto.User = telemetryUser.MakeDisplayName();
|
dto.User = telemetryUser?.MakeDisplayName();
|
||||||
return dto;
|
return dto;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -6,7 +6,7 @@ using Mapster;
|
|||||||
|
|
||||||
namespace AsbCloudInfrastructure.Services
|
namespace AsbCloudInfrastructure.Services
|
||||||
{
|
{
|
||||||
public class TelemetryDataSpinService : TelemetryDataService<AsbCloudApp.Data.TelemetryDataSpinDto, AsbCloudDb.Model.TelemetryDataSpin>
|
public class TelemetryDataSpinService : TelemetryDataBaseService<AsbCloudApp.Data.TelemetryDataSpinDto, AsbCloudDb.Model.TelemetryDataSpin>
|
||||||
{
|
{
|
||||||
public TelemetryDataSpinService(
|
public TelemetryDataSpinService(
|
||||||
IAsbCloudDbContext db,
|
IAsbCloudDbContext db,
|
||||||
|
@ -52,7 +52,7 @@ namespace AsbCloudInfrastructure.Services
|
|||||||
}
|
}
|
||||||
|
|
||||||
private Telemetry GetOrCreateTelemetryByUid(string uid)
|
private Telemetry GetOrCreateTelemetryByUid(string uid)
|
||||||
=> cacheTelemetry.FirstOrDefault(t => t.RemoteUid == uid, RefreshMode.IfResultEmpty)
|
=> cacheTelemetry.FirstOrDefault(t => t.RemoteUid == uid)
|
||||||
?? cacheTelemetry.Insert(new Telemetry { RemoteUid = uid, });
|
?? cacheTelemetry.Insert(new Telemetry { RemoteUid = uid, });
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -29,7 +29,7 @@ namespace AsbCloudWebApi.Controllers
|
|||||||
.ConfigureAwait(false);
|
.ConfigureAwait(false);
|
||||||
if (fileInfo is null)
|
if (fileInfo is null)
|
||||||
return NoContent();
|
return NoContent();
|
||||||
var relativePath = fileService.GetFileName(fileInfo);
|
var relativePath = fileService.GetUrl(fileInfo);
|
||||||
return PhysicalFile(Path.GetFullPath(relativePath), "application/octet-stream", fileInfo.Name);
|
return PhysicalFile(Path.GetFullPath(relativePath), "application/octet-stream", fileInfo.Name);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -157,8 +157,7 @@ namespace AsbCloudWebApi.Controllers
|
|||||||
if (fileInfo is null)
|
if (fileInfo is null)
|
||||||
throw new FileNotFoundException();
|
throw new FileNotFoundException();
|
||||||
|
|
||||||
// TODO: словарь content typoв
|
var relativePath = fileService.GetUrl(fileInfo);
|
||||||
var relativePath = fileService.GetFileName(fileInfo);
|
|
||||||
return PhysicalFile(Path.GetFullPath(relativePath), "application/octet-stream", fileInfo.Name);
|
return PhysicalFile(Path.GetFullPath(relativePath), "application/octet-stream", fileInfo.Name);
|
||||||
}
|
}
|
||||||
catch (FileNotFoundException ex)
|
catch (FileNotFoundException ex)
|
||||||
|
@ -5,8 +5,6 @@ using Microsoft.AspNetCore.Mvc;
|
|||||||
using Microsoft.AspNetCore.SignalR;
|
using Microsoft.AspNetCore.SignalR;
|
||||||
using System;
|
using System;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using System.IO;
|
|
||||||
using System.Linq;
|
|
||||||
using System.Threading;
|
using System.Threading;
|
||||||
using System.Threading.Tasks;
|
using System.Threading.Tasks;
|
||||||
|
|
||||||
@ -33,25 +31,6 @@ namespace AsbCloudWebApi.Controllers
|
|||||||
this.reportsHubContext = reportsHubContext;
|
this.reportsHubContext = reportsHubContext;
|
||||||
}
|
}
|
||||||
|
|
||||||
private void HandleReportProgressAsync(float progress, string operation, int id) =>
|
|
||||||
Task.Run(() =>
|
|
||||||
{
|
|
||||||
reportsHubContext.Clients.Group($"Report_{id}").SendAsync(
|
|
||||||
nameof(IReportHubClient.GetReportProgress),
|
|
||||||
new { Progress = progress, Operation = operation, ReportName = "" }
|
|
||||||
).ConfigureAwait(false);
|
|
||||||
});
|
|
||||||
|
|
||||||
private void HandleReportNameAsync(string reportName, int groupId) =>
|
|
||||||
Task.Run(() =>
|
|
||||||
{
|
|
||||||
reportsHubContext.Clients.All.SendAsync(
|
|
||||||
nameof(IReportHubClient.GetReportProgress),
|
|
||||||
new { Progress = 100, Operation = "Отчет успешно создан", ReportName = reportName }
|
|
||||||
).ConfigureAwait(false);
|
|
||||||
});
|
|
||||||
|
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Создает отчет по скважине с указанными параметрами
|
/// Создает отчет по скважине с указанными параметрами
|
||||||
/// </summary>
|
/// </summary>
|
||||||
@ -65,39 +44,44 @@ namespace AsbCloudWebApi.Controllers
|
|||||||
/// <returns>id фоновой задачи формирования отчета</returns>
|
/// <returns>id фоновой задачи формирования отчета</returns>
|
||||||
[HttpPost]
|
[HttpPost]
|
||||||
[ProducesResponseType(typeof(int), (int)System.Net.HttpStatusCode.OK)]
|
[ProducesResponseType(typeof(int), (int)System.Net.HttpStatusCode.OK)]
|
||||||
public async Task<IActionResult> CreateReportAsync(int idWell, int idUser, int stepSeconds, int format,
|
public async Task<IActionResult> CreateReportAsync(int idWell, int stepSeconds, int format,
|
||||||
DateTime begin = default, DateTime end = default,
|
DateTime begin = default, DateTime end = default,
|
||||||
CancellationToken token = default)
|
CancellationToken token = default)
|
||||||
{
|
{
|
||||||
int? idCompany = User.GetCompanyId();
|
var idCompany = User.GetCompanyId();
|
||||||
|
var idUser = User.GetUserId();
|
||||||
|
|
||||||
if (idCompany is null)
|
if ((idCompany is null) || (idUser is null))
|
||||||
return Forbid();
|
return Forbid();
|
||||||
|
|
||||||
if (!await wellService.IsCompanyInvolvedInWellAsync((int)idCompany,
|
if (!await wellService.IsCompanyInvolvedInWellAsync((int)idCompany,
|
||||||
idWell, token).ConfigureAwait(false))
|
idWell, token).ConfigureAwait(false))
|
||||||
return Forbid();
|
return Forbid();
|
||||||
|
|
||||||
var id = reportService.CreateReport(idWell, idUser,
|
void HandleReportProgressAsync(object progress, int id) =>
|
||||||
stepSeconds, format, begin, end, HandleReportProgressAsync, HandleReportNameAsync);
|
Task.Run(() =>
|
||||||
|
{
|
||||||
|
reportsHubContext.Clients.Group($"Report_{id}").SendAsync(
|
||||||
|
nameof(IReportHubClient.GetReportProgress),
|
||||||
|
progress
|
||||||
|
).ConfigureAwait(false);
|
||||||
|
});
|
||||||
|
|
||||||
|
var id = reportService.CreateReport(idWell, (int)idUser,
|
||||||
|
stepSeconds, format, begin, end, HandleReportProgressAsync);
|
||||||
|
|
||||||
return Ok(id);
|
return Ok(id);
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Возвращает файл-отчет с диска на сервере
|
/// Возвращает имена всех отчетов по скважине
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="idWell">id скважины</param>
|
/// <param name="idWell">id скважины</param>
|
||||||
/// <param name="reportName">имя запрашиваемого файла (отчета)</param>
|
|
||||||
/// <param name="token">Токен для отмены задачи</param>
|
/// <param name="token">Токен для отмены задачи</param>
|
||||||
/// <returns>файл с отчетом</returns>
|
/// <returns>Список имен существующих отчетов (отчетов)</returns>
|
||||||
[HttpGet]
|
[HttpGet]
|
||||||
[Route("{reportName}")]
|
[ProducesResponseType(typeof(IEnumerable<string>), (int)System.Net.HttpStatusCode.OK)]
|
||||||
[ProducesResponseType(typeof(PhysicalFileResult), (int)System.Net.HttpStatusCode.OK)]
|
public async Task<IActionResult> GetAllReportsNamesByWellAsync(int idWell, CancellationToken token = default)
|
||||||
public async Task<IActionResult> GetReportAsync([FromRoute] int idWell,
|
|
||||||
string reportName, CancellationToken token = default)
|
|
||||||
{
|
|
||||||
try
|
|
||||||
{
|
{
|
||||||
int? idCompany = User.GetCompanyId();
|
int? idCompany = User.GetCompanyId();
|
||||||
|
|
||||||
@ -108,15 +92,9 @@ namespace AsbCloudWebApi.Controllers
|
|||||||
idWell, token).ConfigureAwait(false))
|
idWell, token).ConfigureAwait(false))
|
||||||
return Forbid();
|
return Forbid();
|
||||||
|
|
||||||
// TODO: словарь content typoв
|
var reports = await reportService.GetAllReportsByWellAsync(idWell, token).ConfigureAwait(false);
|
||||||
var relativePath = Path.Combine(fileService.RootPath, $"{idWell}",
|
|
||||||
$"{reportService.ReportCategoryId}", reportName);
|
return Ok(reports);
|
||||||
return PhysicalFile(Path.GetFullPath(relativePath), "application/pdf", reportName);
|
|
||||||
}
|
|
||||||
catch (FileNotFoundException ex)
|
|
||||||
{
|
|
||||||
return NotFound($"Файл не найден. Текст ошибки: {ex.Message}");
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
@ -130,6 +108,7 @@ namespace AsbCloudWebApi.Controllers
|
|||||||
/// <param name="end">дата окончания интервала</param>
|
/// <param name="end">дата окончания интервала</param>
|
||||||
/// <param name="token">Токен для отмены задачи</param>
|
/// <param name="token">Токен для отмены задачи</param>
|
||||||
/// <returns>Список имен существующих отчетов (отчетов)</returns>
|
/// <returns>Список имен существующих отчетов (отчетов)</returns>
|
||||||
|
[Obsolete]
|
||||||
[HttpGet]
|
[HttpGet]
|
||||||
[Route("suitableReports")]
|
[Route("suitableReports")]
|
||||||
[ProducesResponseType(typeof(IEnumerable<string>), (int)System.Net.HttpStatusCode.OK)]
|
[ProducesResponseType(typeof(IEnumerable<string>), (int)System.Net.HttpStatusCode.OK)]
|
||||||
@ -137,12 +116,18 @@ namespace AsbCloudWebApi.Controllers
|
|||||||
DateTime begin = default, DateTime end = default,
|
DateTime begin = default, DateTime end = default,
|
||||||
CancellationToken token = default)
|
CancellationToken token = default)
|
||||||
{
|
{
|
||||||
|
int? idCompany = User.GetCompanyId();
|
||||||
|
|
||||||
|
if (idCompany is null)
|
||||||
|
return Forbid();
|
||||||
|
|
||||||
|
if (!await wellService.IsCompanyInvolvedInWellAsync((int)idCompany,
|
||||||
|
idWell, token).ConfigureAwait(false))
|
||||||
|
return Forbid();
|
||||||
|
|
||||||
var suitableReportsNames = await reportService.GetSuitableReportsAsync(idWell,
|
var suitableReportsNames = await reportService.GetSuitableReportsAsync(idWell,
|
||||||
begin, end, stepSeconds, format, token).ConfigureAwait(false);
|
begin, end, stepSeconds, format, token).ConfigureAwait(false);
|
||||||
|
|
||||||
if (suitableReportsNames is null || !suitableReportsNames.Any())
|
|
||||||
return NoContent();
|
|
||||||
|
|
||||||
return Ok(suitableReportsNames);
|
return Ok(suitableReportsNames);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user