forked from ddrilling/AsbCloudServer
add new file categories
This commit is contained in:
parent
ebd3e4ec4c
commit
e8bfe3b443
@ -286,7 +286,8 @@ namespace AsbCloudDb.Model
|
||||
new FileCategory {Id = 10, Name = "Последние данные Шламограммы", ShortName = "mudLastData"},
|
||||
new FileCategory {Id = 11, Name = "Последние данные ННБ", ShortName = "nnbLastData"},
|
||||
new FileCategory {Id = 12, Name = "Рапорт", ShortName = "report"},
|
||||
new FileCategory {Id = 13, Name = "Программа бурения", ShortName = "ПБ"},
|
||||
new FileCategory {Id = 13, Name = "Программа бурения, части", ShortName = "ПБч"},
|
||||
new FileCategory {Id = 14, Name = "Программа бурения", ShortName = "ПБ"},
|
||||
});
|
||||
});
|
||||
|
||||
|
@ -17,7 +17,8 @@ namespace AsbCloudInfrastructure.Services
|
||||
{
|
||||
private readonly IFileService fileService;
|
||||
private readonly IWellService wellService;
|
||||
private const int idFileCategoryPlan = 13;
|
||||
private const int idFileCategoryDrillingProgramItems = 13;
|
||||
private const int idFileCategoryDrillingProgram = 14;
|
||||
|
||||
public DrillingProgramService(IFileService fileService, IWellService wellService)
|
||||
{
|
||||
@ -27,7 +28,7 @@ namespace AsbCloudInfrastructure.Services
|
||||
|
||||
public async Task<FileInfoDto> GetAsync(int idWell, CancellationToken token = default)
|
||||
{
|
||||
var filesInfos = await fileService.GetInfosByCategoryAsync(idWell, idFileCategoryPlan, token)
|
||||
var filesInfos = await fileService.GetInfosByCategoryAsync(idWell, idFileCategoryDrillingProgramItems, token)
|
||||
.ConfigureAwait(false);
|
||||
|
||||
var well = await wellService.GetAsync(idWell, token)
|
||||
@ -35,12 +36,23 @@ namespace AsbCloudInfrastructure.Services
|
||||
|
||||
var resultFileName = $"Программа бурения {well.Cluster} {well.Caption}.xlsx";
|
||||
|
||||
var matchFile = filesInfos.FirstOrDefault(f=>f.Name == resultFileName);
|
||||
if (matchFile is not null) {
|
||||
var matchFiles = await fileService.GetInfosByCategoryAsync(idWell, idFileCategoryDrillingProgram, token)
|
||||
.ConfigureAwait(false);
|
||||
|
||||
if (matchFiles is not null) {
|
||||
matchFiles = matchFiles.OrderByDescending(f => f.UploadDate);
|
||||
var matchFilesIterator = matchFiles.GetEnumerator();
|
||||
matchFilesIterator.MoveNext();
|
||||
var matchFile = matchFilesIterator.Current;
|
||||
while (matchFilesIterator.MoveNext())
|
||||
await fileService.DeletedAsync(matchFilesIterator.Current.Id, token)
|
||||
.ConfigureAwait(false);
|
||||
|
||||
if (filesInfos.All(f => f.UploadDate <= matchFile.UploadDate))
|
||||
return matchFile;
|
||||
else
|
||||
await fileService.DeletedAsync(matchFile.Id, token);
|
||||
await fileService.DeletedAsync(matchFile.Id, token)
|
||||
.ConfigureAwait(false);
|
||||
}
|
||||
|
||||
var fileNames = filesInfos
|
||||
@ -50,7 +62,7 @@ namespace AsbCloudInfrastructure.Services
|
||||
var stream = new MemoryStream(1024 * 1024);
|
||||
UniteExcelFiles(fileNames, stream);
|
||||
stream.Seek(0, SeekOrigin.Begin);
|
||||
return await fileService.SaveAsync(idWell, 0, idFileCategoryPlan, resultFileName, stream, token)
|
||||
return await fileService.SaveAsync(idWell, 0, idFileCategoryDrillingProgramItems, resultFileName, stream, token)
|
||||
.ConfigureAwait(false);
|
||||
}
|
||||
|
||||
|
@ -175,7 +175,7 @@ namespace AsbCloudInfrastructure.Services
|
||||
|
||||
public string GetFileName(FileInfoDto fileInfo)
|
||||
{
|
||||
var fileName = Path.Combine(fileInfo.Id.ToString(), Path.GetExtension(fileInfo.Name));
|
||||
var fileName = $"{fileInfo.Id}{Path.GetExtension(fileInfo.Name)}";
|
||||
fileName = Path.Combine(RootPath, fileInfo.IdWell.ToString(), fileInfo.IdCategory.ToString(), fileName);
|
||||
fileName = Path.GetFullPath(fileName);
|
||||
return fileName;
|
||||
|
@ -66,6 +66,30 @@ namespace AsbCloudWebApi.Controllers
|
||||
return Ok();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Возвращает информацию о файлах для скважины в выбраной категории
|
||||
/// </summary>
|
||||
/// <param name="idWell">id скважины</param>
|
||||
/// <param name="idCategory">id категории файла</param>
|
||||
/// <param name="token"> Токен отмены задачи </param>
|
||||
/// <returns>Список информации о файлах в этой категории</returns>
|
||||
[HttpGet]
|
||||
[Route("category/{idCategory}")]
|
||||
[ProducesResponseType(typeof(IEnumerable<FileInfoDto>), (int)System.Net.HttpStatusCode.OK)]
|
||||
public async Task<IActionResult> GetInfosByCategoryAsync([FromRoute] int idWell, int idCategory, CancellationToken token = default)
|
||||
{
|
||||
int? idCompany = User.GetCompanyId();
|
||||
|
||||
if (idCompany is null || !await wellService.IsCompanyInvolvedInWellAsync((int)idCompany,
|
||||
idWell, token).ConfigureAwait(false))
|
||||
return Forbid();
|
||||
|
||||
var filesInfo = await fileService.GetInfosByCategoryAsync(idWell, idCategory, token)
|
||||
.ConfigureAwait(false);
|
||||
|
||||
return Ok(filesInfo);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Возвращает информацию о файлах для скважины в выбраной категории
|
||||
/// </summary>
|
||||
|
Loading…
Reference in New Issue
Block a user