forked from ddrilling/AsbCloudServer
#7912198 implement ReNotifyPublishers
This commit is contained in:
parent
0ea49dd72f
commit
4277850156
@ -25,10 +25,10 @@ namespace AsbCloudApp.Services
|
|||||||
/// Получение всех записей
|
/// Получение всех записей
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name = "idWell" ></param >
|
/// <param name = "idWell" ></param >
|
||||||
/// <param name = "idUser" ></param >
|
/// <param name = "idUser" >запрашивающий пользователь, для проверки его прав и текста сообщения</param >
|
||||||
/// <param name="token"></param>
|
/// <param name="token"></param>
|
||||||
/// <returns></returns>
|
/// <returns></returns>
|
||||||
Task<WellCaseDto> GetByWellId(int idWell, int idUser, CancellationToken token);
|
Task<WellCaseDto> GetByWellIdAsync(int idWell, int idUser, CancellationToken token);
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Получение списка ответственных
|
/// Получение списка ответственных
|
||||||
@ -45,19 +45,29 @@ namespace AsbCloudApp.Services
|
|||||||
/// <param name="idCategory"></param>
|
/// <param name="idCategory"></param>
|
||||||
/// <param name="token"></param>
|
/// <param name="token"></param>
|
||||||
/// <returns></returns>
|
/// <returns></returns>
|
||||||
Task<WellFinalDocumentsHistoryDto> GetFilesHistoryByIdCategory(int idWell, int idCategory, CancellationToken token);
|
Task<WellFinalDocumentsHistoryDto> GetFilesHistoryByIdCategoryAsync(int idWell, int idCategory, CancellationToken token);
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Сохранение файла
|
/// Сохранение файла
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="idWell"></param>
|
/// <param name="idWell"></param>
|
||||||
/// <param name="idCategory"></param>
|
/// <param name="idCategory"></param>
|
||||||
/// <param name="idUser"></param>
|
/// <param name="idUser">пользователь, который сохраняет файл</param>
|
||||||
/// <param name="fileStream"></param>
|
/// <param name="fileStream"></param>
|
||||||
/// <param name="fileName"></param>
|
/// <param name="fileName"></param>
|
||||||
/// <param name="token"></param>
|
/// <param name="token"></param>
|
||||||
/// <returns></returns>
|
/// <returns></returns>
|
||||||
Task<int> SaveCategoryFile(int idWell, int idCategory, int idUser, Stream fileStream, string fileName, CancellationToken token);
|
Task<int> SaveCategoryFileAsync(int idWell, int idCategory, int idUser, Stream fileStream, string fileName, CancellationToken token);
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Повторно оповестить ответственных за загрузку
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="idWell"></param>
|
||||||
|
/// <param name="idUser">запрашивающий пользователь, для проверки его прав и текста сообщения</param>
|
||||||
|
/// <param name="idCategory"></param>
|
||||||
|
/// <param name="token"></param>
|
||||||
|
/// <returns>count of notified publishers</returns>
|
||||||
|
Task<int> ReNotifyPublishersAsync(int idWell, int idUser, int idCategory, CancellationToken token);
|
||||||
}
|
}
|
||||||
#nullable disable
|
#nullable disable
|
||||||
}
|
}
|
@ -4,7 +4,6 @@ using AsbCloudApp.Repositories;
|
|||||||
using AsbCloudApp.Requests;
|
using AsbCloudApp.Requests;
|
||||||
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;
|
||||||
@ -50,6 +49,7 @@ namespace AsbCloudInfrastructure.Services
|
|||||||
this.fileCategoryService = fileCategoryService;
|
this.fileCategoryService = fileCategoryService;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
///<inheritdoc/>
|
||||||
public async Task<int> UpdateRangeAsync(int idWell, IEnumerable<WellFinalDocumentInputDto>? dtos, CancellationToken token)
|
public async Task<int> UpdateRangeAsync(int idWell, IEnumerable<WellFinalDocumentInputDto>? dtos, CancellationToken token)
|
||||||
{
|
{
|
||||||
if (dtos is not null)
|
if (dtos is not null)
|
||||||
@ -81,7 +81,8 @@ namespace AsbCloudInfrastructure.Services
|
|||||||
throw new ArgumentInvalidException("Данные по категориям отсутствуют.");
|
throw new ArgumentInvalidException("Данные по категориям отсутствуют.");
|
||||||
}
|
}
|
||||||
|
|
||||||
public async Task<WellCaseDto> GetByWellId(int idWell, int idUser, CancellationToken token)
|
///<inheritdoc/>
|
||||||
|
public async Task<WellCaseDto> GetByWellIdAsync(int idWell, int idUser, CancellationToken token)
|
||||||
{
|
{
|
||||||
var entities = await context.WellFinalDocuments
|
var entities = await context.WellFinalDocuments
|
||||||
.Include(d => d.Category)
|
.Include(d => d.Category)
|
||||||
@ -127,6 +128,7 @@ namespace AsbCloudInfrastructure.Services
|
|||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
///<inheritdoc/>
|
||||||
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
|
||||||
@ -145,7 +147,8 @@ namespace AsbCloudInfrastructure.Services
|
|||||||
.ToArray();
|
.ToArray();
|
||||||
}
|
}
|
||||||
|
|
||||||
public async Task<int> SaveCategoryFile(int idWell, int idCategory, int idUser, Stream fileStream, string fileName, CancellationToken token)
|
///<inheritdoc/>
|
||||||
|
public async Task<int> SaveCategoryFileAsync(int idWell, int idCategory, int idUser, Stream fileStream, string fileName, CancellationToken token)
|
||||||
{
|
{
|
||||||
var entity = await context.WellFinalDocuments
|
var entity = await context.WellFinalDocuments
|
||||||
.AsNoTracking()
|
.AsNoTracking()
|
||||||
@ -162,7 +165,8 @@ namespace AsbCloudInfrastructure.Services
|
|||||||
return file?.Id ?? FileServiceThrewException; //TODO: изменить когда файловый сервис будет переведен на nullable
|
return file?.Id ?? FileServiceThrewException; //TODO: изменить когда файловый сервис будет переведен на nullable
|
||||||
}
|
}
|
||||||
|
|
||||||
public async Task<WellFinalDocumentsHistoryDto> GetFilesHistoryByIdCategory(int idWell, int idCategory, CancellationToken token)
|
///<inheritdoc/>
|
||||||
|
public async Task<WellFinalDocumentsHistoryDto> GetFilesHistoryByIdCategoryAsync(int idWell, int idCategory, CancellationToken token)
|
||||||
{
|
{
|
||||||
var request = new FileRequest
|
var request = new FileRequest
|
||||||
{
|
{
|
||||||
@ -178,6 +182,37 @@ namespace AsbCloudInfrastructure.Services
|
|||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
///<inheritdoc/>
|
||||||
|
public async Task<int> ReNotifyPublishersAsync(int idWell, int idUser, int idCategory, CancellationToken token)
|
||||||
|
{
|
||||||
|
WellCaseDto wellCase = await GetByWellIdAsync(idWell, idUser, token);
|
||||||
|
|
||||||
|
if (wellCase.PermissionToSetPubliher)
|
||||||
|
throw new ForbidException("Повторная отправка оповещений Вам не разрешена");
|
||||||
|
|
||||||
|
var requester = userRepository.GetOrDefault(idUser);
|
||||||
|
if (requester is null)
|
||||||
|
throw new ForbidException("Не удается вас опознать");
|
||||||
|
|
||||||
|
var docs = wellCase.WellFinalDocuments
|
||||||
|
.Where(doc => doc.IdCategory == idCategory)
|
||||||
|
.Where(doc => doc.File is null)
|
||||||
|
.SelectMany(doc => doc.Publishers
|
||||||
|
.Select(pub => new WellFinalDocumentDBDto {
|
||||||
|
IdCategory = idCategory,
|
||||||
|
IdUser = pub.Id,
|
||||||
|
IdWell = idWell
|
||||||
|
}));
|
||||||
|
|
||||||
|
if(!docs.Any())
|
||||||
|
throw new Exception("Нет такой категории, или в нее уже загружен документ");
|
||||||
|
|
||||||
|
var message = requester.MakeDisplayName() + " ожидает от Вас загрузку на портал документа «{{0}}»";
|
||||||
|
await GenerateMessageAsync(docs, message, token);
|
||||||
|
|
||||||
|
return docs.Count();
|
||||||
|
}
|
||||||
|
|
||||||
private async Task GenerateMessageAsync(IEnumerable<WellFinalDocumentDBDto> dtos, string message, CancellationToken token)
|
private async Task GenerateMessageAsync(IEnumerable<WellFinalDocumentDBDto> dtos, string message, CancellationToken token)
|
||||||
{
|
{
|
||||||
foreach (var item in dtos)
|
foreach (var item in dtos)
|
||||||
@ -203,6 +238,7 @@ namespace AsbCloudInfrastructure.Services
|
|||||||
|
|
||||||
private static WellFinalDocumentDBDto Convert(WellFinalDocument entity)
|
private static WellFinalDocumentDBDto Convert(WellFinalDocument entity)
|
||||||
=> entity.Adapt<WellFinalDocumentDBDto>();
|
=> entity.Adapt<WellFinalDocumentDBDto>();
|
||||||
|
|
||||||
}
|
}
|
||||||
#nullable disable
|
#nullable disable
|
||||||
}
|
}
|
||||||
|
@ -47,7 +47,7 @@ namespace AsbCloudWebApi.Controllers
|
|||||||
return Forbid();
|
return Forbid();
|
||||||
|
|
||||||
var idUser = User?.GetUserId();
|
var idUser = User?.GetUserId();
|
||||||
var data = await this.wellFinalDocumentsService.GetByWellId(idWell, idUser ?? default, token);
|
var data = await this.wellFinalDocumentsService.GetByWellIdAsync(idWell, idUser ?? default, token);
|
||||||
return Ok(data);
|
return Ok(data);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -84,7 +84,27 @@ namespace AsbCloudWebApi.Controllers
|
|||||||
if (!await CanUserAccessToWellAsync(idWell, token).ConfigureAwait(false))
|
if (!await CanUserAccessToWellAsync(idWell, token).ConfigureAwait(false))
|
||||||
return Forbid();
|
return Forbid();
|
||||||
|
|
||||||
var data = await this.wellFinalDocumentsService.UpdateRangeAsync(idWell, dtos, token);
|
var data = await wellFinalDocumentsService.UpdateRangeAsync(idWell, dtos, token);
|
||||||
|
return Ok(data);
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Повторно оповестить ответственных за загрузку
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="idWell"></param>
|
||||||
|
/// <param name="idCategory"></param>
|
||||||
|
/// <param name="token"></param>
|
||||||
|
/// <returns>количество оповещенных публикаторов</returns>
|
||||||
|
[HttpPut("{idWell}")]
|
||||||
|
[Permission("WellFinalDocuments.editPublisher")]
|
||||||
|
[ProducesResponseType(typeof(int), (int)System.Net.HttpStatusCode.OK)]
|
||||||
|
public async Task<IActionResult> ReNotifyPublishersAsync(int idWell, [Required] int idCategory, CancellationToken token = default)
|
||||||
|
{
|
||||||
|
if (!await CanUserAccessToWellAsync(idWell, token).ConfigureAwait(false))
|
||||||
|
return Forbid();
|
||||||
|
|
||||||
|
var idUser = User.GetUserId() ?? -1;
|
||||||
|
var data = await wellFinalDocumentsService.ReNotifyPublishersAsync(idWell, idUser, idCategory, token);
|
||||||
return Ok(data);
|
return Ok(data);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -98,14 +118,14 @@ namespace AsbCloudWebApi.Controllers
|
|||||||
[HttpGet("{idWell}/history")]
|
[HttpGet("{idWell}/history")]
|
||||||
[Permission]
|
[Permission]
|
||||||
[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> GetFilesHistoryByIdCategoryAsync(int idWell,
|
||||||
[Required] 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))
|
||||||
return Forbid();
|
return Forbid();
|
||||||
|
|
||||||
var data = await this.wellFinalDocumentsService.GetFilesHistoryByIdCategory(idWell, idCategory, token);
|
var data = await this.wellFinalDocumentsService.GetFilesHistoryByIdCategoryAsync(idWell, idCategory, token);
|
||||||
return Ok(data);
|
return Ok(data);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -120,14 +140,14 @@ namespace AsbCloudWebApi.Controllers
|
|||||||
[HttpPost("{idWell}")]
|
[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, [Required] int idCategory, [Required] IFormFile file, CancellationToken token = default)
|
public async Task<IActionResult> SaveCategoryFileAsync(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();
|
||||||
|
|
||||||
var idUser = User.GetUserId() ?? -1;
|
var idUser = User.GetUserId() ?? -1;
|
||||||
var fileStream = file.OpenReadStream();
|
var fileStream = file.OpenReadStream();
|
||||||
var data = await this.wellFinalDocumentsService.SaveCategoryFile(idWell, idCategory, idUser, fileStream, file.FileName, token);
|
var data = await this.wellFinalDocumentsService.SaveCategoryFileAsync(idWell, idCategory, idUser, fileStream, file.FileName, token);
|
||||||
return Ok(data);
|
return Ok(data);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user