forked from ddrilling/AsbCloudServer
"красивости"
This commit is contained in:
parent
44be18f5ed
commit
698803fbf8
@ -16,6 +16,6 @@ namespace AsbCloudApp.Services
|
|||||||
/// Получение справочника категорий файлов
|
/// Получение справочника категорий файлов
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <returns></returns>
|
/// <returns></returns>
|
||||||
Task<IEnumerable<FileCategoryDto>> GetWellCategoryAsync(CancellationToken token);
|
Task<IEnumerable<FileCategoryDto>> GetWellCaseCategoriesAsync(CancellationToken token);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -2,8 +2,6 @@
|
|||||||
using AsbCloudApp.Services;
|
using AsbCloudApp.Services;
|
||||||
using AsbCloudDb.Model;
|
using AsbCloudDb.Model;
|
||||||
using AsbCloudInfrastructure.Repository;
|
using AsbCloudInfrastructure.Repository;
|
||||||
using DocumentFormat.OpenXml.InkML;
|
|
||||||
using Microsoft.EntityFrameworkCore;
|
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
using System.Threading;
|
using System.Threading;
|
||||||
@ -13,37 +11,21 @@ namespace AsbCloudInfrastructure.Services
|
|||||||
{
|
{
|
||||||
public class FileCategoryService : CrudCacheServiceBase<FileCategoryDto, FileCategory>, IFileCategoryService
|
public class FileCategoryService : CrudCacheServiceBase<FileCategoryDto, FileCategory>, IFileCategoryService
|
||||||
{
|
{
|
||||||
private readonly IAsbCloudDbContext db;
|
|
||||||
|
|
||||||
public FileCategoryService(IAsbCloudDbContext context)
|
public FileCategoryService(IAsbCloudDbContext context)
|
||||||
: base(context)
|
: base(context)
|
||||||
{
|
{
|
||||||
this.db = context;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public async Task<IEnumerable<FileCategoryDto>> GetWellCategoryAsync(CancellationToken token)
|
public async Task<IEnumerable<FileCategoryDto>> GetWellCaseCategoriesAsync(CancellationToken token)
|
||||||
{
|
{
|
||||||
var data = await (from category in db.FileCategories
|
var cache = await GetCacheAsync(token)
|
||||||
where category.Id >= 10000 && category.Id <= 20000
|
.ConfigureAwait(false);
|
||||||
select new FileCategoryDto
|
var dtos = cache
|
||||||
{
|
.Where(kv => kv.Key >= 10000)
|
||||||
Id = category.Id,
|
.Where(kv => kv.Key <= 20000)
|
||||||
Name = category.Name,
|
.Select(kv => kv.Value);
|
||||||
ShortName = category.ShortName
|
|
||||||
})
|
|
||||||
.ToListAsync(token)
|
|
||||||
.ConfigureAwait(false);
|
|
||||||
|
|
||||||
return data.ToList();
|
return dtos;
|
||||||
}
|
|
||||||
|
|
||||||
public override async Task<FileCategoryDto> GetOrDefaultAsync(int id, CancellationToken token)
|
|
||||||
{
|
|
||||||
var entity = await db.FileCategories
|
|
||||||
.FirstOrDefaultAsync(x => x.Id == id)
|
|
||||||
.ConfigureAwait(false);
|
|
||||||
var dto = Convert(entity);
|
|
||||||
return dto;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -2,7 +2,6 @@
|
|||||||
using AsbCloudApp.Exceptions;
|
using AsbCloudApp.Exceptions;
|
||||||
using AsbCloudApp.Services;
|
using AsbCloudApp.Services;
|
||||||
using AsbCloudDb.Model;
|
using AsbCloudDb.Model;
|
||||||
using AsbCloudInfrastructure.Repository;
|
|
||||||
using Mapster;
|
using Mapster;
|
||||||
using Microsoft.EntityFrameworkCore;
|
using Microsoft.EntityFrameworkCore;
|
||||||
using Microsoft.Extensions.Configuration;
|
using Microsoft.Extensions.Configuration;
|
||||||
@ -77,7 +76,7 @@ namespace AsbCloudInfrastructure.Services
|
|||||||
throw new ArgumentInvalidException("Данные по категориям отсутствуют.");
|
throw new ArgumentInvalidException("Данные по категориям отсутствуют.");
|
||||||
}
|
}
|
||||||
|
|
||||||
public async Task<WellCaseDto> GetByWellId(int idWell, int idUser, CancellationToken token)
|
public async Task<WellCaseDto> GetByWellId_old(int idWell, int idUser, CancellationToken token)
|
||||||
{
|
{
|
||||||
var wellFinalDocuments = new List<WellFinalDocumentDto>();
|
var wellFinalDocuments = new List<WellFinalDocumentDto>();
|
||||||
|
|
||||||
@ -140,6 +139,52 @@ namespace AsbCloudInfrastructure.Services
|
|||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public async Task<WellCaseDto> GetByWellId(int idWell, int idUser, CancellationToken token)
|
||||||
|
{
|
||||||
|
var entities = await context.WellFinalDocuments
|
||||||
|
.Include(d => d.Category)
|
||||||
|
.Include(d => d.User)
|
||||||
|
.Where(d => d.IdWell == idWell)
|
||||||
|
.AsNoTracking()
|
||||||
|
.ToArrayAsync(token)
|
||||||
|
.ConfigureAwait(false);
|
||||||
|
|
||||||
|
var entitiesGroups = entities
|
||||||
|
.GroupBy(d => d.Category);
|
||||||
|
|
||||||
|
var categoriesIds = entitiesGroups
|
||||||
|
.Select(g => g.Key.Id);
|
||||||
|
|
||||||
|
var files = (await fileService
|
||||||
|
.GetInfosByWellIdAsync(idWell, token)
|
||||||
|
.ConfigureAwait(false))
|
||||||
|
.Where(f => categoriesIds.Contains(f.IdCategory))
|
||||||
|
.ToArray();
|
||||||
|
|
||||||
|
var docs = entitiesGroups.Select((g) => new WellFinalDocumentDto
|
||||||
|
{
|
||||||
|
IdCategory = g.Key.Id,
|
||||||
|
FilesCount = files
|
||||||
|
.Where(f => f.IdCategory == g.Key.Id)
|
||||||
|
.Count(),
|
||||||
|
File = files
|
||||||
|
.Where(f => f.IdCategory == g.Key.Id)
|
||||||
|
.OrderBy(f => f.UploadDate)
|
||||||
|
.LastOrDefault(),
|
||||||
|
NameCategory = g.Key.Name,
|
||||||
|
Publishers = g.Select(i => i.User.Adapt<UserDto>()),
|
||||||
|
PermissionToUpload = g.Any(i => i.IdUser == idUser),
|
||||||
|
});
|
||||||
|
|
||||||
|
var result = new WellCaseDto
|
||||||
|
{
|
||||||
|
IdWell = idWell,
|
||||||
|
PermissionToSetPubliher = userService.HasPermission(idUser, "WellFinalDocument.editPublisher"),
|
||||||
|
WellFinalDocuments = docs,
|
||||||
|
};
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
public async Task<IEnumerable<UserDto>> GetAvailableUsersAsync(int idWell, CancellationToken token)
|
public async Task<IEnumerable<UserDto>> GetAvailableUsersAsync(int idWell, CancellationToken token)
|
||||||
{
|
{
|
||||||
var companyIds = await context.RelationCompaniesWells
|
var companyIds = await context.RelationCompaniesWells
|
||||||
|
@ -29,7 +29,7 @@ namespace AsbCloudWebApi.Tests.ServicesTests
|
|||||||
[Fact]
|
[Fact]
|
||||||
public async Task GetWellCategoryAsync_return_cnt_file_category()
|
public async Task GetWellCategoryAsync_return_cnt_file_category()
|
||||||
{
|
{
|
||||||
var cnt = (await service.GetWellCategoryAsync(CancellationToken.None)).Count();
|
var cnt = (await service.GetWellCaseCategoriesAsync(CancellationToken.None)).Count();
|
||||||
Assert.NotEqual(0, cnt);
|
Assert.NotEqual(0, cnt);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -2,9 +2,6 @@
|
|||||||
using AsbCloudApp.Services;
|
using AsbCloudApp.Services;
|
||||||
using Microsoft.AspNetCore.Authorization;
|
using Microsoft.AspNetCore.Authorization;
|
||||||
using Microsoft.AspNetCore.Mvc;
|
using Microsoft.AspNetCore.Mvc;
|
||||||
using System.Threading.Tasks;
|
|
||||||
using System.Threading;
|
|
||||||
using System.Collections.Generic;
|
|
||||||
|
|
||||||
namespace AsbCloudWebApi.Controllers
|
namespace AsbCloudWebApi.Controllers
|
||||||
{
|
{
|
||||||
@ -16,24 +13,9 @@ namespace AsbCloudWebApi.Controllers
|
|||||||
[Authorize]
|
[Authorize]
|
||||||
public class FileCategoryController : CrudController<FileCategoryDto, ICrudService<FileCategoryDto>>
|
public class FileCategoryController : CrudController<FileCategoryDto, ICrudService<FileCategoryDto>>
|
||||||
{
|
{
|
||||||
private readonly IFileCategoryService fileCategoryService;
|
|
||||||
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("/getWellFileCategory")]
|
|
||||||
//[Permission]
|
|
||||||
public async Task<IActionResult> GetWellFileCategory(CancellationToken token = default)
|
|
||||||
{
|
|
||||||
var data = await fileCategoryService.GetWellCategoryAsync(token);
|
|
||||||
return Ok(data);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -6,7 +6,7 @@ using System.Threading.Tasks;
|
|||||||
using System.Threading;
|
using System.Threading;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using Microsoft.AspNetCore.Http;
|
using Microsoft.AspNetCore.Http;
|
||||||
using AsbCloudInfrastructure.Services;
|
using System.ComponentModel.DataAnnotations;
|
||||||
|
|
||||||
namespace AsbCloudWebApi.Controllers
|
namespace AsbCloudWebApi.Controllers
|
||||||
{
|
{
|
||||||
@ -21,10 +21,29 @@ namespace AsbCloudWebApi.Controllers
|
|||||||
{
|
{
|
||||||
private readonly IWellFinalDocumentsService wellFinalDocumentsService;
|
private readonly IWellFinalDocumentsService wellFinalDocumentsService;
|
||||||
private readonly IWellService wellService;
|
private readonly IWellService wellService;
|
||||||
public WellFinalDocumentsController(IWellFinalDocumentsService wellFinalDocumentsService, IWellService wellService)
|
private readonly IFileCategoryService fileCategoryService;
|
||||||
|
|
||||||
|
public WellFinalDocumentsController(
|
||||||
|
IWellFinalDocumentsService wellFinalDocumentsService,
|
||||||
|
IWellService wellService,
|
||||||
|
IFileCategoryService fileCategoryService)
|
||||||
{
|
{
|
||||||
this.wellFinalDocumentsService = wellFinalDocumentsService;
|
this.wellFinalDocumentsService = wellFinalDocumentsService;
|
||||||
this.wellService = wellService;
|
this.wellService = wellService;
|
||||||
|
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>
|
||||||
@ -33,7 +52,7 @@ namespace AsbCloudWebApi.Controllers
|
|||||||
/// <param name="idWell"></param>
|
/// <param name="idWell"></param>
|
||||||
/// <param name="token"></param>
|
/// <param name="token"></param>
|
||||||
/// <returns></returns>
|
/// <returns></returns>
|
||||||
[HttpGet]
|
[HttpGet("{idWell}")]
|
||||||
[Permission]
|
[Permission]
|
||||||
[ProducesResponseType(typeof(WellCaseDto), (int)System.Net.HttpStatusCode.OK)]
|
[ProducesResponseType(typeof(WellCaseDto), (int)System.Net.HttpStatusCode.OK)]
|
||||||
public async Task<IActionResult> GetAsync(int idWell, CancellationToken token = default)
|
public async Task<IActionResult> GetAsync(int idWell, CancellationToken token = default)
|
||||||
@ -52,9 +71,8 @@ namespace AsbCloudWebApi.Controllers
|
|||||||
/// <param name="idWell"></param>
|
/// <param name="idWell"></param>
|
||||||
/// <param name="token"></param>
|
/// <param name="token"></param>
|
||||||
/// <returns></returns>
|
/// <returns></returns>
|
||||||
[HttpGet]
|
[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)
|
||||||
{
|
{
|
||||||
@ -72,10 +90,10 @@ namespace AsbCloudWebApi.Controllers
|
|||||||
/// <param name="dtos"></param>
|
/// <param name="dtos"></param>
|
||||||
/// <param name="token"></param>
|
/// <param name="token"></param>
|
||||||
/// <returns></returns>
|
/// <returns></returns>
|
||||||
[HttpPut]
|
[HttpPut("{idWell}")]
|
||||||
[Permission("WellFinalDocument.editPublisher")]
|
[Permission("WellFinalDocument.editPublisher")]
|
||||||
[ProducesResponseType(typeof(int), (int)System.Net.HttpStatusCode.OK)]
|
[ProducesResponseType(typeof(int), (int)System.Net.HttpStatusCode.OK)]
|
||||||
public async Task<IActionResult> UpdateRangeAsync(int idWell, IEnumerable<WellFinalDocumentInputDto> dtos, CancellationToken token = default)
|
public async Task<IActionResult> UpdateRangeAsync(int idWell, [Required] IEnumerable<WellFinalDocumentInputDto> dtos, CancellationToken token = default)
|
||||||
{
|
{
|
||||||
if (!await CanUserAccessToWellAsync(idWell, token).ConfigureAwait(false))
|
if (!await CanUserAccessToWellAsync(idWell, token).ConfigureAwait(false))
|
||||||
return Forbid();
|
return Forbid();
|
||||||
@ -91,12 +109,11 @@ namespace AsbCloudWebApi.Controllers
|
|||||||
/// <param name="idCategory"></param>
|
/// <param name="idCategory"></param>
|
||||||
/// <param name="token"></param>
|
/// <param name="token"></param>
|
||||||
/// <returns></returns>
|
/// <returns></returns>
|
||||||
[HttpGet]
|
[HttpGet("{idWell}/history")]
|
||||||
[Permission]
|
[Permission]
|
||||||
[Route("filesHistoryByIdCategory")]
|
|
||||||
[ProducesResponseType(typeof(WellFinalDocumentsHistoryDto), (int)System.Net.HttpStatusCode.OK)]
|
[ProducesResponseType(typeof(WellFinalDocumentsHistoryDto), (int)System.Net.HttpStatusCode.OK)]
|
||||||
public async Task<IActionResult> GetFilesHistoryByIdCategory(int idWell,
|
public async Task<IActionResult> GetFilesHistoryByIdCategory(int idWell,
|
||||||
int idCategory,
|
[Required] int idCategory,
|
||||||
CancellationToken token = default)
|
CancellationToken token = default)
|
||||||
{
|
{
|
||||||
if (!await CanUserAccessToWellAsync(idWell, token).ConfigureAwait(false))
|
if (!await CanUserAccessToWellAsync(idWell, token).ConfigureAwait(false))
|
||||||
@ -114,10 +131,10 @@ namespace AsbCloudWebApi.Controllers
|
|||||||
/// <param name="file"></param>
|
/// <param name="file"></param>
|
||||||
/// <param name="token"></param>
|
/// <param name="token"></param>
|
||||||
/// <returns></returns>
|
/// <returns></returns>
|
||||||
[HttpPost]
|
[HttpPost("{idWell}")]
|
||||||
[Permission]
|
[Permission]
|
||||||
[ProducesResponseType(typeof(int), (int)System.Net.HttpStatusCode.OK)]
|
[ProducesResponseType(typeof(int), (int)System.Net.HttpStatusCode.OK)]
|
||||||
public async Task<IActionResult> SaveCategoryFile(int idWell, int idCategory, IFormFile file, CancellationToken token = default)
|
public async Task<IActionResult> SaveCategoryFile(int idWell, [Required] int idCategory, [Required] IFormFile file, CancellationToken token = default)
|
||||||
{
|
{
|
||||||
if (!await CanUserAccessToWellAsync(idWell, token).ConfigureAwait(false))
|
if (!await CanUserAccessToWellAsync(idWell, token).ConfigureAwait(false))
|
||||||
return Forbid();
|
return Forbid();
|
||||||
|
Loading…
Reference in New Issue
Block a user