2021-04-02 17:28:07 +05:00
|
|
|
|
using AsbCloudApp.Data;
|
2022-01-18 11:04:15 +05:00
|
|
|
|
using AsbCloudApp.Exceptions;
|
2021-04-02 17:28:07 +05:00
|
|
|
|
using AsbCloudApp.Services;
|
|
|
|
|
using AsbCloudDb.Model;
|
2021-05-14 17:02:29 +05:00
|
|
|
|
using AsbCloudInfrastructure.Services.Cache;
|
2021-07-28 09:46:58 +05:00
|
|
|
|
using Mapster;
|
2021-07-21 15:29:19 +05:00
|
|
|
|
using System;
|
2021-04-02 17:28:07 +05:00
|
|
|
|
using System.Collections.Generic;
|
|
|
|
|
using System.Linq;
|
2021-08-11 12:11:21 +05:00
|
|
|
|
using System.Threading;
|
|
|
|
|
using System.Threading.Tasks;
|
2021-04-02 17:28:07 +05:00
|
|
|
|
|
|
|
|
|
namespace AsbCloudInfrastructure.Services
|
|
|
|
|
{
|
2021-12-21 11:52:53 +05:00
|
|
|
|
public class WellService : CrudCacheServiceBase<WellDto, Well>, IWellService
|
2021-12-22 11:41:18 +05:00
|
|
|
|
{
|
|
|
|
|
private static readonly TypeAdapterConfig typeAdapterConfig = TypeAdapterConfig<WellDto, Well>
|
|
|
|
|
.NewConfig()
|
|
|
|
|
.Ignore(dst => dst.Cluster,
|
|
|
|
|
dst => dst.RelationCompaniesWells,
|
|
|
|
|
dst => dst.Telemetry,
|
|
|
|
|
dst => dst.WellComposites,
|
|
|
|
|
dst => dst.WellCompositeSrcs,
|
|
|
|
|
dst => dst.WellOperations,
|
|
|
|
|
dst => dst.WellType)
|
|
|
|
|
.Config;
|
|
|
|
|
|
2021-10-15 12:24:04 +05:00
|
|
|
|
private readonly ITelemetryService telemetryService;
|
2021-07-21 17:23:57 +05:00
|
|
|
|
private readonly CacheTable<RelationCompanyWell> cacheRelationCompaniesWells;
|
2021-12-22 11:41:18 +05:00
|
|
|
|
private readonly CacheTable<CompanyType> cacheCompanyWellTypes;
|
2022-01-05 17:50:45 +05:00
|
|
|
|
private readonly ITimezoneService timezoneService;
|
2022-05-06 16:35:16 +05:00
|
|
|
|
private readonly Lazy<IWellOperationService> wellOperationService;
|
2021-04-02 17:28:07 +05:00
|
|
|
|
|
2021-12-30 17:05:44 +05:00
|
|
|
|
public ITelemetryService TelemetryService => telemetryService;
|
|
|
|
|
|
2022-01-05 17:50:45 +05:00
|
|
|
|
public WellService(IAsbCloudDbContext db, CacheDb cacheDb, ITelemetryService telemetryService, ITimezoneService timezoneService)
|
2022-04-11 18:00:34 +05:00
|
|
|
|
: base(db, cacheDb)
|
2021-04-02 17:28:07 +05:00
|
|
|
|
{
|
2021-10-15 12:24:04 +05:00
|
|
|
|
this.telemetryService = telemetryService;
|
2022-01-05 17:50:45 +05:00
|
|
|
|
this.timezoneService = timezoneService;
|
2022-05-06 16:35:16 +05:00
|
|
|
|
this.wellOperationService = new Lazy<IWellOperationService>(() => new WellOperationService.WellOperationService(db, cacheDb, this));
|
2021-12-21 11:52:53 +05:00
|
|
|
|
cacheRelationCompaniesWells = cacheDb.GetCachedTable<RelationCompanyWell>((AsbCloudDbContext)db, nameof(RelationCompanyWell.Company), nameof(RelationCompanyWell.Well));
|
2021-12-22 11:41:18 +05:00
|
|
|
|
cacheCompanyWellTypes = cacheDb.GetCachedTable<CompanyType>((AsbCloudDbContext)db);
|
|
|
|
|
Includes.Add($"{nameof(Well.Cluster)}.{nameof(Cluster.Deposit)}");
|
|
|
|
|
Includes.Add(nameof(Well.Telemetry));
|
|
|
|
|
Includes.Add($"{nameof(Well.RelationCompaniesWells)}.{nameof(RelationCompanyWell.Company)}");
|
|
|
|
|
Includes.Add(nameof(Well.WellType));
|
2021-05-12 16:03:14 +05:00
|
|
|
|
}
|
2021-10-20 12:52:31 +05:00
|
|
|
|
|
2021-12-30 17:05:44 +05:00
|
|
|
|
public DateTimeOffset GetLastTelemetryDate(int idWell)
|
2021-10-20 12:52:31 +05:00
|
|
|
|
{
|
2021-12-21 11:52:53 +05:00
|
|
|
|
var well = Cache.FirstOrDefault(w => w.Id == idWell);
|
2022-05-06 16:35:16 +05:00
|
|
|
|
|
2021-10-21 15:57:20 +05:00
|
|
|
|
if (well?.IdTelemetry is null)
|
2021-12-30 17:05:44 +05:00
|
|
|
|
return DateTimeOffset.MinValue;
|
2021-10-20 12:52:31 +05:00
|
|
|
|
|
2021-10-25 16:32:55 +05:00
|
|
|
|
var lastTelemetryDate = telemetryService.GetLastTelemetryDate((int)well.IdTelemetry);
|
|
|
|
|
return lastTelemetryDate;
|
2021-10-20 12:52:31 +05:00
|
|
|
|
}
|
|
|
|
|
|
2021-12-21 11:52:53 +05:00
|
|
|
|
public async Task<IEnumerable<WellDto>> GetWellsByCompanyAsync(int idCompany, CancellationToken token)
|
2021-10-21 15:57:20 +05:00
|
|
|
|
{
|
2021-12-21 11:52:53 +05:00
|
|
|
|
var relations = await cacheRelationCompaniesWells
|
|
|
|
|
.WhereAsync(r => r.IdCompany == idCompany, token);
|
2021-12-22 11:41:18 +05:00
|
|
|
|
|
|
|
|
|
var wellsIds = relations.Select(r => r.IdWell);
|
2022-01-05 17:50:45 +05:00
|
|
|
|
var wells = await Cache.WhereAsync(w => wellsIds.Contains(w.Id), token);
|
2022-05-06 16:35:16 +05:00
|
|
|
|
|
2021-12-22 11:41:18 +05:00
|
|
|
|
var dtos = wells.Select(Convert);
|
2021-12-21 11:52:53 +05:00
|
|
|
|
return dtos;
|
2021-10-21 15:57:20 +05:00
|
|
|
|
}
|
2021-04-02 17:28:07 +05:00
|
|
|
|
|
2022-04-11 18:00:34 +05:00
|
|
|
|
public override async Task<int> InsertAsync(WellDto dto, CancellationToken token = default)
|
2021-04-02 17:28:07 +05:00
|
|
|
|
{
|
2021-12-22 11:41:18 +05:00
|
|
|
|
if (dto.IdWellType is < 1 or > 2)
|
2022-01-18 11:04:15 +05:00
|
|
|
|
throw new ArgumentInvalidException("Тип скважины указан неправильно.", nameof(dto));
|
2021-12-22 11:41:18 +05:00
|
|
|
|
|
|
|
|
|
if (dto.IdState is < 0 or > 2)
|
2022-01-18 11:04:15 +05:00
|
|
|
|
throw new ArgumentInvalidException("Текущее состояние работы скважины указано неправильно.", nameof(dto));
|
2021-12-22 11:41:18 +05:00
|
|
|
|
|
|
|
|
|
if (dto.Id != 0 && await Cache.ContainsAsync(w => w.Id == dto.Id, token))
|
2022-01-18 11:04:15 +05:00
|
|
|
|
throw new ArgumentInvalidException($"Нельзя повторно добавить скважину с id: {dto.Id}", nameof(dto));
|
2021-12-22 11:41:18 +05:00
|
|
|
|
|
|
|
|
|
var entity = Convert(dto);
|
|
|
|
|
|
|
|
|
|
var result = await Cache.InsertAsync(entity, token);
|
|
|
|
|
|
|
|
|
|
if (dto.Companies.Any())
|
|
|
|
|
{
|
|
|
|
|
var newRelations = dto.Companies.Select(c => new RelationCompanyWell { IdWell = result.Id, IdCompany = c.Id });
|
|
|
|
|
await cacheRelationCompaniesWells.InsertAsync(newRelations, token);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return result.Id;
|
2021-04-02 17:28:07 +05:00
|
|
|
|
}
|
2021-12-21 11:52:53 +05:00
|
|
|
|
|
|
|
|
|
public override Task<int> InsertRangeAsync(IEnumerable<WellDto> dtos, CancellationToken token)
|
|
|
|
|
{
|
|
|
|
|
throw new NotImplementedException();
|
|
|
|
|
}
|
|
|
|
|
|
2022-04-11 18:00:34 +05:00
|
|
|
|
public override async Task<int> UpdateAsync(int idWell, WellDto dto,
|
2021-10-18 16:30:14 +05:00
|
|
|
|
CancellationToken token = default)
|
2021-10-18 12:38:49 +05:00
|
|
|
|
{
|
2021-10-18 16:30:14 +05:00
|
|
|
|
if (dto.IdWellType is < 1 or > 2)
|
2022-01-18 11:04:15 +05:00
|
|
|
|
throw new ArgumentInvalidException("Тип скважины указан неправильно.", nameof(dto));
|
2022-04-11 18:00:34 +05:00
|
|
|
|
|
2021-10-20 12:52:31 +05:00
|
|
|
|
if (dto.IdState is < 0 or > 2)
|
2022-01-18 11:04:15 +05:00
|
|
|
|
throw new ArgumentInvalidException("Текущее состояние работы скважины указано неправильно.", nameof(dto));
|
2022-04-11 18:00:34 +05:00
|
|
|
|
|
|
|
|
|
if (dto.Id != idWell)
|
2022-01-18 11:04:15 +05:00
|
|
|
|
throw new ArgumentInvalidException($"Нельзя поменять id для скважины: {idWell} => {dto.Id}.", nameof(dto));
|
2021-10-27 17:48:19 +05:00
|
|
|
|
|
2021-12-21 11:52:53 +05:00
|
|
|
|
var entity = Convert(dto);
|
2021-10-18 12:38:49 +05:00
|
|
|
|
|
2021-12-22 11:41:18 +05:00
|
|
|
|
var oldRelations = await cacheRelationCompaniesWells
|
|
|
|
|
.WhereAsync(r => r.IdWell == idWell, token);
|
|
|
|
|
|
2022-04-11 18:00:34 +05:00
|
|
|
|
if (dto.Companies.Count() != oldRelations.Count() ||
|
2021-12-22 11:41:18 +05:00
|
|
|
|
dto.Companies.Any(c => !oldRelations.Any(oldC => oldC.IdCompany == c.Id)))
|
|
|
|
|
{
|
|
|
|
|
await cacheRelationCompaniesWells.RemoveAsync(r => r.IdWell == idWell, token);
|
2022-04-11 18:00:34 +05:00
|
|
|
|
var newRelations = dto.Companies.Select(c => new RelationCompanyWell { IdWell = idWell, IdCompany = c.Id });
|
2021-12-22 11:41:18 +05:00
|
|
|
|
await cacheRelationCompaniesWells.InsertAsync(newRelations, token);
|
|
|
|
|
}
|
2021-10-18 12:38:49 +05:00
|
|
|
|
|
2021-12-21 11:52:53 +05:00
|
|
|
|
var result = await Cache.UpsertAsync(entity, token);
|
|
|
|
|
return result;
|
2021-10-18 12:38:49 +05:00
|
|
|
|
}
|
2021-04-02 17:28:07 +05:00
|
|
|
|
|
2021-10-12 16:07:08 +05:00
|
|
|
|
public bool IsCompanyInvolvedInWell(int idCompany, int idWell)
|
|
|
|
|
=> cacheRelationCompaniesWells.Contains(r => r.IdWell == idWell && r.IdCompany == idCompany);
|
|
|
|
|
|
2021-08-11 16:54:42 +05:00
|
|
|
|
public async Task<bool> IsCompanyInvolvedInWellAsync(int idCompany, int idWell, CancellationToken token)
|
2021-08-24 10:59:10 +05:00
|
|
|
|
=> await cacheRelationCompaniesWells.ContainsAsync(r => r.IdWell == idWell &&
|
2021-08-11 17:26:02 +05:00
|
|
|
|
r.IdCompany == idCompany, token).ConfigureAwait(false);
|
2021-08-09 15:41:42 +05:00
|
|
|
|
|
2021-08-25 11:13:56 +05:00
|
|
|
|
public async Task<string> GetWellCaptionByIdAsync(int idWell, CancellationToken token)
|
|
|
|
|
{
|
2021-12-21 11:52:53 +05:00
|
|
|
|
var entity = await Cache.FirstOrDefaultAsync(w => w.Id == idWell, token).ConfigureAwait(false);
|
2021-10-21 15:57:20 +05:00
|
|
|
|
var dto = Convert(entity);
|
2021-08-25 11:13:56 +05:00
|
|
|
|
return dto.Caption;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public async Task<IEnumerable<CompanyDto>> GetCompaniesAsync(int idWell, CancellationToken token)
|
|
|
|
|
{
|
2021-12-21 11:52:53 +05:00
|
|
|
|
var relations = await cacheRelationCompaniesWells.WhereAsync(r => r.IdWell == idWell, token);
|
|
|
|
|
var dtos = relations.Select(r => Convert(r.Company));
|
|
|
|
|
return dtos;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private IEnumerable<CompanyDto> GetCompanies(int idWell)
|
|
|
|
|
{
|
|
|
|
|
var relations = cacheRelationCompaniesWells.Where(r => r.IdWell == idWell);
|
|
|
|
|
var dtos = relations.Select(r => Convert(r.Company));
|
|
|
|
|
return dtos;
|
2021-08-25 11:13:56 +05:00
|
|
|
|
}
|
2021-10-20 12:52:31 +05:00
|
|
|
|
|
|
|
|
|
public string GetStateText(int state)
|
|
|
|
|
{
|
|
|
|
|
return state switch
|
|
|
|
|
{
|
|
|
|
|
1 => "В работе",
|
|
|
|
|
2 => "Завершена",
|
2021-12-30 17:05:44 +05:00
|
|
|
|
_ => "Неизвестно",
|
2021-10-20 12:52:31 +05:00
|
|
|
|
};
|
|
|
|
|
}
|
2022-04-11 18:00:34 +05:00
|
|
|
|
|
2021-11-23 11:41:27 +05:00
|
|
|
|
public async Task<IEnumerable<int>> GetClusterWellsIdsAsync(int idWell, CancellationToken token)
|
|
|
|
|
{
|
2021-12-21 11:52:53 +05:00
|
|
|
|
var well = await Cache.FirstOrDefaultAsync(w => w.Id == idWell, token)
|
2021-11-23 11:41:27 +05:00
|
|
|
|
.ConfigureAwait(false);
|
2022-04-11 18:00:34 +05:00
|
|
|
|
|
|
|
|
|
if (well is null)
|
2021-11-23 11:41:27 +05:00
|
|
|
|
return null;
|
2022-04-11 18:00:34 +05:00
|
|
|
|
|
2021-12-21 11:52:53 +05:00
|
|
|
|
var clusterWells = await Cache.WhereAsync(w => w.IdCluster == well.IdCluster, token)
|
2021-11-23 11:41:27 +05:00
|
|
|
|
.ConfigureAwait(false);
|
2022-04-11 18:00:34 +05:00
|
|
|
|
|
2021-11-23 11:41:27 +05:00
|
|
|
|
return clusterWells.Select(w => w.Id);
|
|
|
|
|
}
|
2021-10-21 15:57:20 +05:00
|
|
|
|
|
2021-12-22 11:41:18 +05:00
|
|
|
|
protected override Well Convert(WellDto dto)
|
|
|
|
|
{
|
|
|
|
|
var entity = dto.Adapt<Well>(typeAdapterConfig);
|
2022-01-10 11:45:14 +05:00
|
|
|
|
|
|
|
|
|
entity.IdTelemetry = entity.IdTelemetry ?? dto.IdTelemetry ?? dto.Telemetry?.Id;
|
|
|
|
|
|
2022-01-05 17:50:45 +05:00
|
|
|
|
if (dto.Timezone is null)
|
2022-01-10 17:39:33 +05:00
|
|
|
|
if (TryGetTimezone(dto.Id, out var timezoneDto))
|
|
|
|
|
entity.Timezone = timezoneDto.Adapt<SimpleTimezone>();
|
2022-01-10 11:45:14 +05:00
|
|
|
|
|
2021-12-22 11:41:18 +05:00
|
|
|
|
return entity;
|
|
|
|
|
}
|
|
|
|
|
|
2021-12-21 11:52:53 +05:00
|
|
|
|
protected override WellDto Convert(Well entity)
|
2021-10-21 15:57:20 +05:00
|
|
|
|
{
|
2022-01-05 17:50:45 +05:00
|
|
|
|
if (entity is null)
|
|
|
|
|
return null;
|
|
|
|
|
|
2021-12-21 11:52:53 +05:00
|
|
|
|
var dto = base.Convert(entity);
|
2022-01-05 17:50:45 +05:00
|
|
|
|
|
|
|
|
|
if (entity.Timezone is null)
|
2022-04-11 18:00:34 +05:00
|
|
|
|
if (TryGetTimezone(entity, out var timezone))
|
|
|
|
|
dto.Timezone = timezone;
|
2022-01-05 17:50:45 +05:00
|
|
|
|
|
2022-05-06 16:35:16 +05:00
|
|
|
|
dto.StartDate = wellOperationService.Value.FirstOperationDate(entity.Id)?.ToRemoteDateTime(dto.Timezone.Hours);
|
2021-12-22 11:41:18 +05:00
|
|
|
|
dto.WellType = entity.WellType?.Caption;
|
2021-12-21 11:52:53 +05:00
|
|
|
|
dto.Cluster = entity.Cluster?.Caption;
|
|
|
|
|
dto.Deposit = entity.Cluster?.Deposit?.Caption;
|
2021-12-30 17:05:44 +05:00
|
|
|
|
dto.LastTelemetryDate = GetLastTelemetryDate(entity.Id).DateTime;
|
2021-12-21 11:52:53 +05:00
|
|
|
|
dto.Companies = GetCompanies(entity.Id);
|
|
|
|
|
return dto;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private CompanyDto Convert(Company entity)
|
|
|
|
|
{
|
|
|
|
|
var dto = entity.Adapt<CompanyDto>();
|
2022-04-11 18:00:34 +05:00
|
|
|
|
dto.CompanyTypeCaption = entity.CompanyType?.Caption
|
2021-12-22 11:41:18 +05:00
|
|
|
|
?? cacheCompanyWellTypes.FirstOrDefault(c => c.Id == entity.IdCompanyType).Caption;
|
2021-12-21 11:52:53 +05:00
|
|
|
|
return dto;
|
2021-10-21 15:57:20 +05:00
|
|
|
|
}
|
2021-12-30 17:05:44 +05:00
|
|
|
|
|
2022-01-05 17:50:45 +05:00
|
|
|
|
public void EnshureTimezonesIsSet()
|
2021-12-30 17:05:44 +05:00
|
|
|
|
{
|
2022-01-05 17:50:45 +05:00
|
|
|
|
var wells = Cache.Where(w => w.Timezone is null).ToList();
|
|
|
|
|
foreach (var well in wells)
|
2022-01-10 17:39:33 +05:00
|
|
|
|
{
|
|
|
|
|
if (TryGetTimezone(well, out var timezone))
|
|
|
|
|
well.Timezone = timezone.Adapt<SimpleTimezone>();
|
|
|
|
|
else
|
|
|
|
|
well.Timezone = new SimpleTimezone
|
|
|
|
|
{
|
|
|
|
|
Hours = 5,
|
|
|
|
|
IsOverride = false,
|
|
|
|
|
TimeZoneId = "Assumed",
|
|
|
|
|
};
|
|
|
|
|
}
|
|
|
|
|
|
2022-01-05 17:50:45 +05:00
|
|
|
|
var wellsWithTz = wells.Where(w => w.Timezone is not null);
|
|
|
|
|
if (wellsWithTz.Any())
|
|
|
|
|
{
|
|
|
|
|
var adaptedWells = wellsWithTz.Adapt<WellDto>().Select(Convert);
|
|
|
|
|
Cache.Upsert(adaptedWells);
|
2022-04-11 18:00:34 +05:00
|
|
|
|
}
|
2021-12-30 17:05:44 +05:00
|
|
|
|
}
|
|
|
|
|
|
2022-01-10 17:39:33 +05:00
|
|
|
|
private bool TryGetTimezone(int idWell, out SimpleTimezoneDto timezone)
|
|
|
|
|
{
|
|
|
|
|
timezone = null;
|
|
|
|
|
try
|
|
|
|
|
{
|
|
|
|
|
timezone = GetTimezone(idWell);
|
|
|
|
|
return timezone is not null;
|
|
|
|
|
}
|
|
|
|
|
catch
|
|
|
|
|
{
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2022-01-05 17:50:45 +05:00
|
|
|
|
public SimpleTimezoneDto GetTimezone(int idWell)
|
|
|
|
|
{
|
|
|
|
|
var well = Cache.FirstOrDefault(c => c.Id == idWell);
|
|
|
|
|
if (well == null)
|
2022-01-18 11:04:15 +05:00
|
|
|
|
throw new ArgumentInvalidException($"idWell: {idWell} does not exist.", nameof(idWell));
|
2022-01-05 17:50:45 +05:00
|
|
|
|
return GetTimezone(well);
|
|
|
|
|
}
|
2021-12-30 17:05:44 +05:00
|
|
|
|
|
2022-01-10 17:39:33 +05:00
|
|
|
|
private bool TryGetTimezone(Well well, out SimpleTimezoneDto timezone)
|
|
|
|
|
{
|
|
|
|
|
timezone = null;
|
|
|
|
|
try
|
|
|
|
|
{
|
|
|
|
|
timezone = GetTimezone(well);
|
|
|
|
|
return timezone is not null;
|
|
|
|
|
}
|
2022-04-11 18:00:34 +05:00
|
|
|
|
catch
|
2022-01-10 17:39:33 +05:00
|
|
|
|
{
|
|
|
|
|
return false;
|
2022-04-11 18:00:34 +05:00
|
|
|
|
}
|
2022-01-10 17:39:33 +05:00
|
|
|
|
}
|
|
|
|
|
|
2022-01-05 17:50:45 +05:00
|
|
|
|
private SimpleTimezoneDto GetTimezone(Well well)
|
2021-12-30 17:05:44 +05:00
|
|
|
|
{
|
2022-01-05 17:50:45 +05:00
|
|
|
|
if (well == null)
|
|
|
|
|
throw new ArgumentNullException(nameof(well));
|
|
|
|
|
|
|
|
|
|
if (well.Timezone is not null)
|
|
|
|
|
return well.Timezone.Adapt<SimpleTimezoneDto>();
|
|
|
|
|
|
|
|
|
|
if (well.Telemetry is not null)
|
|
|
|
|
{
|
|
|
|
|
var timezone = telemetryService.GetTimezone(well.Telemetry.Id);
|
|
|
|
|
if (timezone is not null)
|
|
|
|
|
{
|
|
|
|
|
well.Timezone = timezone.Adapt<SimpleTimezone>();
|
|
|
|
|
return timezone;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
var point = GetCoordinates(well);
|
|
|
|
|
if (point is not null)
|
2021-12-30 17:05:44 +05:00
|
|
|
|
{
|
2022-01-05 17:50:45 +05:00
|
|
|
|
if (point.Timezone is not null)
|
|
|
|
|
{
|
|
|
|
|
well.Timezone = point.Timezone;
|
|
|
|
|
return point.Timezone.Adapt<SimpleTimezoneDto>();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (point.Latitude is not null & point.Longitude is not null)
|
|
|
|
|
{
|
|
|
|
|
var timezone = timezoneService.GetByCoordinates((double)point.Latitude, (double)point.Longitude);
|
|
|
|
|
if (timezone is not null)
|
|
|
|
|
{
|
|
|
|
|
well.Timezone = timezone.Adapt<SimpleTimezone>();
|
|
|
|
|
return timezone;
|
|
|
|
|
}
|
|
|
|
|
}
|
2021-12-30 17:05:44 +05:00
|
|
|
|
}
|
2022-01-05 17:50:45 +05:00
|
|
|
|
|
|
|
|
|
throw new Exception($"Can't find timezone for well {well.Caption} id: {well.Id}");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private static AsbCloudDb.Model.IMapPoint GetCoordinates(Well well)
|
|
|
|
|
{
|
2022-04-11 18:00:34 +05:00
|
|
|
|
if (well is null)
|
2022-01-05 17:50:45 +05:00
|
|
|
|
throw new ArgumentNullException(nameof(well));
|
|
|
|
|
|
|
|
|
|
if (well.Latitude is not null & well.Longitude is not null)
|
|
|
|
|
return well;
|
|
|
|
|
|
|
|
|
|
if (well.Cluster is null)
|
|
|
|
|
throw new Exception($"Can't find coordinates of well {well.Caption} id: {well.Id}");
|
|
|
|
|
|
|
|
|
|
var cluster = well.Cluster;
|
|
|
|
|
|
|
|
|
|
if (cluster.Latitude is not null & cluster.Longitude is not null)
|
|
|
|
|
return cluster;
|
|
|
|
|
|
|
|
|
|
if (cluster.Deposit is null)
|
|
|
|
|
throw new Exception($"Can't find coordinates of well by cluster {cluster.Caption} id: {cluster.Id}");
|
|
|
|
|
|
|
|
|
|
var deposit = cluster.Deposit;
|
|
|
|
|
|
|
|
|
|
if (deposit.Latitude is not null & deposit.Longitude is not null)
|
|
|
|
|
return deposit;
|
|
|
|
|
|
|
|
|
|
throw new Exception($"Can't find coordinates of well by deposit {deposit.Caption} id: {deposit.Id}");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public DatesRangeDto GetDatesRange(int idWell)
|
|
|
|
|
{
|
|
|
|
|
var well = Cache.FirstOrDefault(w => w.Id == idWell);
|
|
|
|
|
if (well is null)
|
|
|
|
|
throw new Exception($"Well id: {idWell} does not exist.");
|
|
|
|
|
|
|
|
|
|
if (well.IdTelemetry is null)
|
|
|
|
|
throw new Exception($"Well id: {idWell} does not contain telemetry.");
|
|
|
|
|
|
|
|
|
|
return telemetryService.GetDatesRange((int)well.IdTelemetry);
|
2021-12-30 17:05:44 +05:00
|
|
|
|
}
|
2021-04-02 17:28:07 +05:00
|
|
|
|
}
|
|
|
|
|
}
|