2023-09-25 11:56:40 +05:00
|
|
|
|
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)
|
|
|
|
|
{
|
2023-09-29 12:06:46 +05:00
|
|
|
|
var well = await wellService.GetOrDefaultAsync(processMapWellboreDevelopment.IdWell, cancellationToken)
|
|
|
|
|
?? throw new ArgumentInvalidException(nameof(processMapWellboreDevelopment.IdWell),
|
|
|
|
|
$"Скважины с Id: {processMapWellboreDevelopment.IdWell} не существует");
|
2023-09-25 11:56:40 +05:00
|
|
|
|
|
|
|
|
|
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)
|
2023-09-29 12:06:46 +05:00
|
|
|
|
throw new ArgumentInvalidException(nameof(processMapWellboreDevelopment.IdWell),
|
|
|
|
|
$"Скважины с Id: {processMapWellboreDevelopment.IdWell} не существует");
|
2023-09-25 11:56:40 +05:00
|
|
|
|
|
|
|
|
|
processMapWellboreDevelopment.LastUpdate = DateTimeOffset.UtcNow;
|
|
|
|
|
|
|
|
|
|
var result = await processMapWellboreDevelopmentRepository.UpdateAsync(processMapWellboreDevelopment, cancellationToken);
|
|
|
|
|
|
|
|
|
|
if (result == ICrudRepository<ProcessMapWellboreDevelopmentDto>.ErrorIdNotFound)
|
2023-09-29 12:06:46 +05:00
|
|
|
|
throw new ArgumentInvalidException(nameof(processMapWellboreDevelopment.Id),
|
|
|
|
|
$"Проработки с Id: {processMapWellboreDevelopment.Id} не существует");
|
2023-09-25 11:56:40 +05:00
|
|
|
|
|
|
|
|
|
return result;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public async Task<IEnumerable<ProcessMapWellboreDevelopmentDto>> GetByTelemetryAsync(string uid, DateTime updateFrom,
|
|
|
|
|
CancellationToken cancellationToken)
|
|
|
|
|
{
|
|
|
|
|
var idWell = telemetryService.GetIdWellByTelemetryUid(uid);
|
|
|
|
|
|
|
|
|
|
if (!idWell.HasValue)
|
2023-09-29 12:06:46 +05:00
|
|
|
|
throw new ArgumentInvalidException(nameof(uid), $"Неправильный телеметрии. Uid: {uid}");
|
2023-09-25 11:56:40 +05:00
|
|
|
|
|
|
|
|
|
return await processMapWellboreDevelopmentRepository.GetAllAsync(idWell.Value, updateFrom, cancellationToken);
|
|
|
|
|
}
|
|
|
|
|
}
|