forked from ddrilling/AsbCloudServer
Добавление логики для проработки скважины
1. Добавлена реализация сервиса 2. Добавлена реализация репозитория 3. Добавил контроллер для проработки скважины 4. Зарегистрировал все новые зависимости
This commit is contained in:
parent
abf3f4e60b
commit
ef54d3bb20
@ -28,6 +28,7 @@ using AsbCloudApp.Services.AutoGeneratedDailyReports;
|
||||
using AsbCloudApp.Services.Notifications;
|
||||
using AsbCloudDb.Model.Manuals;
|
||||
using AsbCloudInfrastructure.Services.AutoGeneratedDailyReports;
|
||||
using AsbCloudInfrastructure.Services.ProcessMap.ProcessMapWellboreDevelopment;
|
||||
|
||||
namespace AsbCloudInfrastructure
|
||||
{
|
||||
@ -119,6 +120,7 @@ namespace AsbCloudInfrastructure
|
||||
services.AddTransient<IAuthService, AuthService>();
|
||||
services.AddTransient<IDepositRepository, DepositRepository>();
|
||||
services.AddTransient<IProcessMapPlanRepository, ProcessMapRepository>();
|
||||
services.AddTransient<IProcessMapWellboreDevelopmentRepository, ProcessMapWellboreDevelopmentRepository>();
|
||||
services.AddTransient<IDrillingProgramService, DrillingProgramService>();
|
||||
services.AddTransient<IEventService, EventService>();
|
||||
services.AddTransient<FileService>();
|
||||
@ -147,6 +149,7 @@ namespace AsbCloudInfrastructure
|
||||
services.AddTransient<ILimitingParameterService, LimitingParameterService>();
|
||||
services.AddTransient<IProcessMapReportMakerService, ProcessMapReportMakerService>();
|
||||
services.AddTransient<IProcessMapService, ProcessMapService>();
|
||||
services.AddTransient<IProcessMapWellboreDevelopmentService, ProcessMapWellboreDevelopmentService>();
|
||||
services.AddTransient<WellInfoService>();
|
||||
services.AddTransient<IHelpPageService, HelpPageService>();
|
||||
|
||||
|
@ -0,0 +1,45 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Threading;
|
||||
using System.Threading.Tasks;
|
||||
using AsbCloudApp.Data.ProcessMap;
|
||||
using AsbCloudApp.Repositories;
|
||||
using AsbCloudApp.Services;
|
||||
using AsbCloudDb.Model;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
|
||||
namespace AsbCloudInfrastructure.Repository;
|
||||
|
||||
public class ProcessMapWellboreDevelopmentRepository :
|
||||
CrudWellRelatedRepositoryBase<ProcessMapWellboreDevelopmentDto, ProcessMapWellboreDevelopment>,
|
||||
IProcessMapWellboreDevelopmentRepository
|
||||
{
|
||||
private readonly IWellService wellService;
|
||||
|
||||
public ProcessMapWellboreDevelopmentRepository(IAsbCloudDbContext context, IWellService wellService) : base(context)
|
||||
{
|
||||
this.wellService = wellService;
|
||||
}
|
||||
|
||||
public async Task<IEnumerable<ProcessMapWellboreDevelopmentDto>> GetAllAsync(int idWell, DateTime? updateFrom,
|
||||
CancellationToken cancellationToken)
|
||||
{
|
||||
var query = dbContext.ProcessMapWellboreDevelopments
|
||||
.Where(p => p.IdWell == idWell);
|
||||
|
||||
if (updateFrom.HasValue)
|
||||
{
|
||||
var timezone = wellService.GetTimezone(idWell);
|
||||
var updateFromUtc = updateFrom.Value.ToUtcDateTimeOffset(timezone.Hours);
|
||||
query = query.Where(p => p.LastUpdate >= updateFromUtc);
|
||||
}
|
||||
|
||||
var entities = await query
|
||||
.OrderBy(p => p.DepthStart)
|
||||
.ThenBy(p => p.Id)
|
||||
.ToArrayAsync(cancellationToken);
|
||||
|
||||
return entities.Select(Convert);
|
||||
}
|
||||
}
|
@ -0,0 +1,77 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Threading;
|
||||
using System.Threading.Tasks;
|
||||
using AsbCloudApp.Data.ProcessMap;
|
||||
using AsbCloudApp.Exceptions;
|
||||
using AsbCloudApp.Repositories;
|
||||
using AsbCloudApp.Services;
|
||||
|
||||
namespace AsbCloudInfrastructure.Services.ProcessMap.ProcessMapWellboreDevelopment;
|
||||
|
||||
public class ProcessMapWellboreDevelopmentService : IProcessMapWellboreDevelopmentService
|
||||
{
|
||||
private readonly ITelemetryService telemetryService;
|
||||
private readonly IWellService wellService;
|
||||
private readonly IProcessMapWellboreDevelopmentRepository processMapWellboreDevelopmentRepository;
|
||||
|
||||
public ProcessMapWellboreDevelopmentService(ITelemetryService telemetryService,
|
||||
IWellService wellService,
|
||||
IProcessMapWellboreDevelopmentRepository processMapWellboreDevelopmentRepository)
|
||||
{
|
||||
this.telemetryService = telemetryService;
|
||||
this.wellService = wellService;
|
||||
this.processMapWellboreDevelopmentRepository = processMapWellboreDevelopmentRepository;
|
||||
}
|
||||
|
||||
public async Task<int> InsertAsync(ProcessMapWellboreDevelopmentDto processMapWellboreDevelopment, CancellationToken cancellationToken)
|
||||
{
|
||||
var well = await wellService.GetOrDefaultAsync(processMapWellboreDevelopment.IdWell, cancellationToken);
|
||||
|
||||
if (well is null)
|
||||
throw new ArgumentInvalidException($"Скважины с Id: {processMapWellboreDevelopment.IdWell} не существует",
|
||||
nameof(processMapWellboreDevelopment.IdWell));
|
||||
|
||||
if (processMapWellboreDevelopment.DepthStart > processMapWellboreDevelopment.DepthEnd)
|
||||
throw new ArgumentInvalidException("Значение стартовой глубины не может превышать конечную глубину",
|
||||
nameof(processMapWellboreDevelopment.DepthStart));
|
||||
|
||||
processMapWellboreDevelopment.LastUpdate = DateTimeOffset.UtcNow;
|
||||
|
||||
return await processMapWellboreDevelopmentRepository.InsertAsync(processMapWellboreDevelopment, cancellationToken);
|
||||
}
|
||||
|
||||
public async Task<int> UpdateAsync(ProcessMapWellboreDevelopmentDto processMapWellboreDevelopment, CancellationToken cancellationToken)
|
||||
{
|
||||
var well = await wellService.GetOrDefaultAsync(processMapWellboreDevelopment.IdWell, cancellationToken);
|
||||
|
||||
if (well is null)
|
||||
throw new ArgumentInvalidException($"Скважины с Id: {processMapWellboreDevelopment.IdWell} не существует",
|
||||
nameof(processMapWellboreDevelopment.IdWell));
|
||||
|
||||
if (processMapWellboreDevelopment.DepthStart > processMapWellboreDevelopment.DepthEnd)
|
||||
throw new ArgumentInvalidException("Значение стартовой глубины не может превышать конечную глубину",
|
||||
nameof(processMapWellboreDevelopment.DepthStart));
|
||||
|
||||
processMapWellboreDevelopment.LastUpdate = DateTimeOffset.UtcNow;
|
||||
|
||||
var result = await processMapWellboreDevelopmentRepository.UpdateAsync(processMapWellboreDevelopment, cancellationToken);
|
||||
|
||||
if (result == ICrudRepository<ProcessMapWellboreDevelopmentDto>.ErrorIdNotFound)
|
||||
throw new ArgumentInvalidException($"Проработки с Id: {processMapWellboreDevelopment.Id} не существует",
|
||||
nameof(processMapWellboreDevelopment.Id));
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
public async Task<IEnumerable<ProcessMapWellboreDevelopmentDto>> GetByTelemetryAsync(string uid, DateTime updateFrom,
|
||||
CancellationToken cancellationToken)
|
||||
{
|
||||
var idWell = telemetryService.GetIdWellByTelemetryUid(uid);
|
||||
|
||||
if (!idWell.HasValue)
|
||||
throw new ArgumentInvalidException($"Неправильный телеметрии. Uid: {uid}", nameof(uid));
|
||||
|
||||
return await processMapWellboreDevelopmentRepository.GetAllAsync(idWell.Value, updateFrom, cancellationToken);
|
||||
}
|
||||
}
|
@ -0,0 +1,89 @@
|
||||
using System.Collections.Generic;
|
||||
using System.Threading;
|
||||
using System.Threading.Tasks;
|
||||
using AsbCloudApp.Data.ProcessMap;
|
||||
using AsbCloudApp.Exceptions;
|
||||
using AsbCloudApp.Repositories;
|
||||
using AsbCloudApp.Services;
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
using System;
|
||||
|
||||
namespace AsbCloudWebApi.Controllers;
|
||||
|
||||
/// <summary>
|
||||
/// Проработка скважины
|
||||
/// </summary>
|
||||
public class ProcessMapWellboreDevelopmentController : CrudWellRelatedController<ProcessMapWellboreDevelopmentDto,
|
||||
IProcessMapWellboreDevelopmentRepository>
|
||||
{
|
||||
private readonly IUserRepository userRepository;
|
||||
private readonly IProcessMapWellboreDevelopmentService processMapWellboreDevelopmentService;
|
||||
|
||||
public ProcessMapWellboreDevelopmentController(IWellService wellService,
|
||||
IProcessMapWellboreDevelopmentRepository processMapWellboreDevelopmentRepository,
|
||||
IUserRepository userRepository,
|
||||
IProcessMapWellboreDevelopmentService processMapWellboreDevelopmentService)
|
||||
: base(wellService, processMapWellboreDevelopmentRepository)
|
||||
{
|
||||
this.userRepository = userRepository;
|
||||
this.processMapWellboreDevelopmentService = processMapWellboreDevelopmentService;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Добавить запись проработки
|
||||
/// </summary>
|
||||
/// <param name="value"></param>
|
||||
/// <param name="token"></param>
|
||||
/// <returns></returns>
|
||||
/// <exception cref="ForbidException"></exception>
|
||||
public override async Task<ActionResult<int>> InsertAsync(ProcessMapWellboreDevelopmentDto value, CancellationToken token)
|
||||
{
|
||||
await AssertUserHasAccessToProcessMapWellboreDevelopmentAsync(value.IdWell, token);
|
||||
|
||||
return await processMapWellboreDevelopmentService.InsertAsync(value, token);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Обновить запись проработки
|
||||
/// </summary>
|
||||
/// <param name="value"></param>
|
||||
/// <param name="token"></param>
|
||||
/// <returns></returns>
|
||||
public override async Task<ActionResult<int>> UpdateAsync(ProcessMapWellboreDevelopmentDto value, CancellationToken token)
|
||||
{
|
||||
await AssertUserHasAccessToProcessMapWellboreDevelopmentAsync(value.IdWell, token);
|
||||
|
||||
return await processMapWellboreDevelopmentService.UpdateAsync(value, token);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Возвращает проработки по uid телеметрии
|
||||
/// </summary>
|
||||
/// <param name="uid">Уникальный ключ телеметрии</param>
|
||||
/// <param name="updateFrom">Необязательный параметр. Начальная дата</param>
|
||||
/// <param name="cancellationToken"></param>
|
||||
/// <returns></returns>
|
||||
[HttpGet("telemetry/{uid}")]
|
||||
[ProducesResponseType(typeof(IEnumerable<ProcessMapWellboreDevelopmentDto>), (int)System.Net.HttpStatusCode.OK)]
|
||||
public async Task<IActionResult> GetByUidAsync(string uid, DateTime updateFrom, CancellationToken cancellationToken)
|
||||
{
|
||||
var dto = await processMapWellboreDevelopmentService.GetByTelemetryAsync(uid,
|
||||
updateFrom, cancellationToken);
|
||||
|
||||
return Ok(dto);
|
||||
}
|
||||
|
||||
private async Task AssertUserHasAccessToProcessMapWellboreDevelopmentAsync(int idWell, CancellationToken cancellationToken)
|
||||
{
|
||||
var idUser = User.GetUserId();
|
||||
|
||||
if (!idUser.HasValue)
|
||||
throw new ForbidException("Неизвестный пользователь");
|
||||
|
||||
var well = await wellService.GetOrDefaultAsync(idWell, cancellationToken) ??
|
||||
throw new ForbidException($"Скважины с {idWell} не существует");
|
||||
|
||||
if (well.IdState == 2 && !userRepository.HasPermission(idUser.Value, "ProcessMap.editCompletedWell"))
|
||||
throw new ForbidException("Недостаточно прав для редактирования проработки");
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user