This commit is contained in:
ai.astrakhantsev 2022-09-13 12:43:22 +05:00
parent 5bb2d3ea10
commit 1fe48ee03f
3 changed files with 7 additions and 96 deletions

View File

@ -28,6 +28,8 @@ namespace AsbCloudInfrastructure.Services
private readonly IEmailService emailService;
private readonly IFileCategoryService fileCategoryService;
private const int FileServiceThrewException = -1;
public WellFinalDocumentsService(IAsbCloudDbContext context,
IFileService fileService,
IUserService userService,
@ -76,69 +78,6 @@ namespace AsbCloudInfrastructure.Services
throw new ArgumentInvalidException("Данные по категориям отсутствуют.");
}
public async Task<WellCaseDto> GetByWellId_old(int idWell, int idUser, CancellationToken token)
{
var wellFinalDocuments = new List<WellFinalDocumentDto>();
var wells = await context.WellFinalDocuments.Where(x => x.IdWell == idWell)
.ToListAsync(token)
.ConfigureAwait(false);
if (wells.Any())
{
var category = await context.FileCategories
.Where(x => wells.Select(w => w.IdCategory).Contains(x.Id))
.ToListAsync(token)
.ConfigureAwait(false);
var wellFinalDocs = category
.GroupJoin(wells,
fc => fc.Id,
w => w.IdCategory,
(o, i) => new {
IdCategory = o.Id,
NameCategory = o.Name,
Wells = i
})
.ToList();
var wellFiles = await fileService.GetInfosByWellIdAsync(idWell, token).ConfigureAwait(false);
wellFinalDocs.ForEach(async item => {
var userIds = item.Wells
.Select(x => x.IdUser)
.ToList();
var allUsers = await userService.GetAllAsync(token)
.ConfigureAwait(false);
var allFiles = wellFiles.Where(x => x.IdCategory == item.IdCategory);
FileInfoDto? actualFile = null;
if (allFiles.Any())
{
actualFile = allFiles.OrderByDescending(x => x.Id)
.FirstOrDefault();
}
var publishers = allUsers.Where(x => userIds.Contains(x.Id));
wellFinalDocuments.Add(new WellFinalDocumentDto {
IdCategory = item.IdCategory,
NameCategory = item.NameCategory,
Publishers = publishers,
FilesCount = allFiles.Count(),
File = actualFile,
PermissionToUpload = publishers.Any(x => x.Id == idUser)
});
});
}
return new WellCaseDto {
IdWell = idWell,
WellFinalDocuments = wellFinalDocuments
};
}
public async Task<WellCaseDto> GetByWellId(int idWell, int idUser, CancellationToken token)
{
var entities = await context.WellFinalDocuments
@ -200,7 +139,7 @@ namespace AsbCloudInfrastructure.Services
return companyIds.Contains(idCompany);
})
.OrderBy(x => x.Surname)
.ToList();
.ToArray();
}
public async Task<int> SaveCategoryFile(int idWell, int idCategory, int idUser, Stream fileStream, string fileName, CancellationToken token)
@ -217,7 +156,7 @@ namespace AsbCloudInfrastructure.Services
var file = await fileService.SaveAsync(dto.IdWell, dto.IdUser, dto.IdCategory, fileName,
fileStream, token).ConfigureAwait(false);
return file?.Id ?? -1;
return file?.Id ?? FileServiceThrewException; //TODO: изменить когда файловый сервис будет переведен на nullable
}
public async Task<WellFinalDocumentsHistoryDto> GetFilesHistoryByIdCategory(int idWell, int idCategory, CancellationToken token)

View File

@ -16,20 +16,6 @@ namespace AsbCloudWebApi.Controllers
public FileCategoryController(ICrudService<FileCategoryDto> service, IFileCategoryService fileCategoryService)
: base(service)
{
this.fileCategoryService = fileCategoryService;
}
/// <summary>
/// Получение справочника категорий файлов
/// </summary>
/// <returns></returns>
[HttpGet]
[Route("/api/fileCategories")]
[Permission]
public async Task<IActionResult> GetWellFileCategory(CancellationToken token = default)
{
var data = await fileCategoryService.GetWellCategoryAsync(token);
return Ok(data);
}
}
}

View File

@ -32,19 +32,6 @@ namespace AsbCloudWebApi.Controllers
this.fileCategoryService = fileCategoryService;
}
/// <summary>
/// Получение справочника категорий файлов
/// </summary>
/// <returns></returns>
[HttpGet]
[Route("fileCategories")]
[ProducesResponseType(typeof(IEnumerable<FileCategoryDto>), (int)System.Net.HttpStatusCode.OK)]
public async Task<IActionResult> GetFileCategories(CancellationToken token = default)
{
var data = await fileCategoryService.GetWellCaseCategoriesAsync(token);
return Ok(data);
}
/// <summary>
/// Получение всех записей
/// </summary>
@ -72,7 +59,6 @@ namespace AsbCloudWebApi.Controllers
/// <returns></returns>
[HttpGet("{idWell}/availableUsers")]
[Permission]
[Route("publishers")]
[ProducesResponseType(typeof(IEnumerable<UserDto>), (int)System.Net.HttpStatusCode.OK)]
public async Task<IActionResult> GetAvailableUsersAsync(int idWell, CancellationToken token = default)
{
@ -150,11 +136,11 @@ namespace AsbCloudWebApi.Controllers
/// </summary>
/// <returns></returns>
[HttpGet]
[Route("/api/wellFileCategories")]
[Route("wellCaseCategories")]
[Permission]
public async Task<IActionResult> GetWellFileCategory(CancellationToken token = default)
public async Task<IActionResult> GetWellCaseCategoriesAsync(CancellationToken token = default)
{
var data = await fileCategoryService.GetWellCategoryAsync(token);
var data = await fileCategoryService.GetWellCaseCategoriesAsync(token);
return Ok(data);
}