forked from ddrilling/AsbCloudServer
File author is optional (for drillingProgram)
This commit is contained in:
parent
a7962492af
commit
b471efc59e
@ -11,7 +11,7 @@ namespace AsbCloudApp.Services
|
|||||||
{
|
{
|
||||||
string RootPath { get; }
|
string RootPath { get; }
|
||||||
|
|
||||||
Task<FileInfoDto> SaveAsync(int idWell, int idUser, int idCategory, string fileFullName, Stream fileStream, CancellationToken token = default);
|
Task<FileInfoDto> SaveAsync(int idWell, int? idUser, int idCategory, string fileFullName, Stream fileStream, CancellationToken token = default);
|
||||||
|
|
||||||
Task<PaginationContainer<FileInfoDto>> GetInfosAsync(int idWell,
|
Task<PaginationContainer<FileInfoDto>> GetInfosAsync(int idWell,
|
||||||
int idCategory, string companyName = default, string fileName = default, DateTime begin = default, DateTime end = default,
|
int idCategory, string companyName = default, string fileName = default, DateTime begin = default, DateTime end = default,
|
||||||
|
@ -17,7 +17,7 @@ namespace AsbCloudDb.Model
|
|||||||
public int IdWell { get; set; }
|
public int IdWell { get; set; }
|
||||||
|
|
||||||
[Column("id_author"), Comment("Id пользователя, загрузившего файл")]
|
[Column("id_author"), Comment("Id пользователя, загрузившего файл")]
|
||||||
public int IdAuthor { 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; }
|
||||||
|
@ -39,14 +39,14 @@ namespace AsbCloudInfrastructure.Services
|
|||||||
var matchFiles = await fileService.GetInfosByCategoryAsync(idWell, idFileCategoryDrillingProgram, token)
|
var matchFiles = await fileService.GetInfosByCategoryAsync(idWell, idFileCategoryDrillingProgram, token)
|
||||||
.ConfigureAwait(false);
|
.ConfigureAwait(false);
|
||||||
|
|
||||||
if (matchFiles is not null) {
|
if (matchFiles is not null && matchFiles.Any()) {
|
||||||
matchFiles = matchFiles.OrderByDescending(f => f.UploadDate);
|
matchFiles = matchFiles.OrderByDescending(f => f.UploadDate);
|
||||||
var matchFilesIterator = matchFiles.GetEnumerator();
|
var matchFilesIterator = matchFiles.GetEnumerator();
|
||||||
matchFilesIterator.MoveNext();
|
matchFilesIterator.MoveNext();
|
||||||
var matchFile = matchFilesIterator.Current;
|
var matchFile = matchFilesIterator.Current;
|
||||||
while (matchFilesIterator.MoveNext())
|
while (matchFilesIterator.MoveNext())
|
||||||
await fileService.DeletedAsync(matchFilesIterator.Current.Id, token)
|
await fileService.DeletedAsync(matchFilesIterator.Current.Id, token)
|
||||||
.ConfigureAwait(false);
|
.ConfigureAwait(false);
|
||||||
|
|
||||||
if (filesInfos.All(f => f.UploadDate <= matchFile.UploadDate))
|
if (filesInfos.All(f => f.UploadDate <= matchFile.UploadDate))
|
||||||
return matchFile;
|
return matchFile;
|
||||||
@ -61,8 +61,9 @@ namespace AsbCloudInfrastructure.Services
|
|||||||
|
|
||||||
var stream = new MemoryStream(1024 * 1024);
|
var stream = new MemoryStream(1024 * 1024);
|
||||||
UniteExcelFiles(fileNames, stream);
|
UniteExcelFiles(fileNames, stream);
|
||||||
stream.Seek(0, SeekOrigin.Begin);
|
var buffer = stream.ToArray();
|
||||||
return await fileService.SaveAsync(idWell, 0, idFileCategoryDrillingProgramItems, resultFileName, stream, token)
|
var fileStream = new MemoryStream(buffer);
|
||||||
|
return await fileService.SaveAsync(idWell, null, idFileCategoryDrillingProgram, resultFileName, fileStream, token)
|
||||||
.ConfigureAwait(false);
|
.ConfigureAwait(false);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -29,7 +29,7 @@ namespace AsbCloudInfrastructure.Services
|
|||||||
.ThenInclude(c => c.CompanyType);
|
.ThenInclude(c => c.CompanyType);
|
||||||
}
|
}
|
||||||
|
|
||||||
public async Task<FileInfoDto> SaveAsync(int idWell, int idUser, int idCategory, string fileFullName, Stream fileStream, CancellationToken token = default)
|
public async Task<FileInfoDto> SaveAsync(int idWell, int? idUser, int idCategory, string fileFullName, Stream fileStream, CancellationToken token = default)
|
||||||
{
|
{
|
||||||
//save info to db
|
//save info to db
|
||||||
var fileInfo = new AsbCloudDb.Model.FileInfo()
|
var fileInfo = new AsbCloudDb.Model.FileInfo()
|
||||||
|
@ -27,6 +27,8 @@ namespace AsbCloudWebApi.Controllers
|
|||||||
{
|
{
|
||||||
var fileInfo = await drillingProgramService.GetAsync(idWell, token)
|
var fileInfo = await drillingProgramService.GetAsync(idWell, token)
|
||||||
.ConfigureAwait(false);
|
.ConfigureAwait(false);
|
||||||
|
if (fileInfo is null)
|
||||||
|
return NoContent();
|
||||||
var relativePath = fileService.GetFileName(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);
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user