forked from ddrilling/AsbCloudServer
#5998816 commit
This commit is contained in:
parent
5bb2d3ea10
commit
1fe48ee03f
@ -28,6 +28,8 @@ namespace AsbCloudInfrastructure.Services
|
|||||||
private readonly IEmailService emailService;
|
private readonly IEmailService emailService;
|
||||||
private readonly IFileCategoryService fileCategoryService;
|
private readonly IFileCategoryService fileCategoryService;
|
||||||
|
|
||||||
|
private const int FileServiceThrewException = -1;
|
||||||
|
|
||||||
public WellFinalDocumentsService(IAsbCloudDbContext context,
|
public WellFinalDocumentsService(IAsbCloudDbContext context,
|
||||||
IFileService fileService,
|
IFileService fileService,
|
||||||
IUserService userService,
|
IUserService userService,
|
||||||
@ -76,69 +78,6 @@ namespace AsbCloudInfrastructure.Services
|
|||||||
throw new ArgumentInvalidException("Данные по категориям отсутствуют.");
|
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)
|
public async Task<WellCaseDto> GetByWellId(int idWell, int idUser, CancellationToken token)
|
||||||
{
|
{
|
||||||
var entities = await context.WellFinalDocuments
|
var entities = await context.WellFinalDocuments
|
||||||
@ -200,7 +139,7 @@ namespace AsbCloudInfrastructure.Services
|
|||||||
return companyIds.Contains(idCompany);
|
return companyIds.Contains(idCompany);
|
||||||
})
|
})
|
||||||
.OrderBy(x => x.Surname)
|
.OrderBy(x => x.Surname)
|
||||||
.ToList();
|
.ToArray();
|
||||||
}
|
}
|
||||||
|
|
||||||
public async Task<int> SaveCategoryFile(int idWell, int idCategory, int idUser, Stream fileStream, string fileName, CancellationToken token)
|
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,
|
var file = await fileService.SaveAsync(dto.IdWell, dto.IdUser, dto.IdCategory, fileName,
|
||||||
fileStream, token).ConfigureAwait(false);
|
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)
|
public async Task<WellFinalDocumentsHistoryDto> GetFilesHistoryByIdCategory(int idWell, int idCategory, CancellationToken token)
|
||||||
|
@ -16,20 +16,6 @@ namespace AsbCloudWebApi.Controllers
|
|||||||
public FileCategoryController(ICrudService<FileCategoryDto> service, IFileCategoryService fileCategoryService)
|
public FileCategoryController(ICrudService<FileCategoryDto> service, IFileCategoryService fileCategoryService)
|
||||||
: base(service)
|
: 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);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -32,19 +32,6 @@ namespace AsbCloudWebApi.Controllers
|
|||||||
this.fileCategoryService = fileCategoryService;
|
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>
|
||||||
/// Получение всех записей
|
/// Получение всех записей
|
||||||
/// </summary>
|
/// </summary>
|
||||||
@ -72,7 +59,6 @@ namespace AsbCloudWebApi.Controllers
|
|||||||
/// <returns></returns>
|
/// <returns></returns>
|
||||||
[HttpGet("{idWell}/availableUsers")]
|
[HttpGet("{idWell}/availableUsers")]
|
||||||
[Permission]
|
[Permission]
|
||||||
[Route("publishers")]
|
|
||||||
[ProducesResponseType(typeof(IEnumerable<UserDto>), (int)System.Net.HttpStatusCode.OK)]
|
[ProducesResponseType(typeof(IEnumerable<UserDto>), (int)System.Net.HttpStatusCode.OK)]
|
||||||
public async Task<IActionResult> GetAvailableUsersAsync(int idWell, CancellationToken token = default)
|
public async Task<IActionResult> GetAvailableUsersAsync(int idWell, CancellationToken token = default)
|
||||||
{
|
{
|
||||||
@ -150,11 +136,11 @@ namespace AsbCloudWebApi.Controllers
|
|||||||
/// </summary>
|
/// </summary>
|
||||||
/// <returns></returns>
|
/// <returns></returns>
|
||||||
[HttpGet]
|
[HttpGet]
|
||||||
[Route("/api/wellFileCategories")]
|
[Route("wellCaseCategories")]
|
||||||
[Permission]
|
[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);
|
return Ok(data);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user