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;
|
2022-06-06 15:43:47 +05:00
|
|
|
|
using AsbCloudInfrastructure.EfCache;
|
2022-06-15 14:57:37 +05:00
|
|
|
|
using AsbCloudInfrastructure.Services.Cache;
|
2021-07-28 09:46:58 +05:00
|
|
|
|
using Mapster;
|
2022-06-06 15:43:47 +05:00
|
|
|
|
using Microsoft.EntityFrameworkCore;
|
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
|
|
|
|
{
|
2022-06-06 15:43:47 +05:00
|
|
|
|
private const string relationCompaniesWellsCacheTag = "RelationCompaniesWells";
|
|
|
|
|
private static readonly TimeSpan relationCompaniesWellsCacheObsolence = TimeSpan.FromMinutes(15);
|
|
|
|
|
|
2021-10-15 12:24:04 +05:00
|
|
|
|
private readonly ITelemetryService telemetryService;
|
2022-06-06 15:43:47 +05:00
|
|
|
|
private readonly ICrudService<CompanyTypeDto> companyTypesService;
|
2022-01-05 17:50:45 +05:00
|
|
|
|
private readonly ITimezoneService timezoneService;
|
2022-06-06 15:43:47 +05:00
|
|
|
|
private readonly IWellOperationService wellOperationService;
|
2021-04-02 17:28:07 +05:00
|
|
|
|
|
2021-12-30 17:05:44 +05:00
|
|
|
|
public ITelemetryService TelemetryService => telemetryService;
|
|
|
|
|
|
2022-06-15 14:57:37 +05:00
|
|
|
|
private static IQueryable<Well> MakeQueryWell(DbSet<Well> dbSet)
|
2022-06-06 15:43:47 +05:00
|
|
|
|
=> dbSet
|
|
|
|
|
.Include(w => w.Cluster)
|
|
|
|
|
.ThenInclude(c => c.Deposit)
|
|
|
|
|
.Include(w => w.Telemetry)
|
|
|
|
|
.Include(w => w.WellType)
|
|
|
|
|
.Include(w => w.RelationCompaniesWells)
|
|
|
|
|
.ThenInclude(r => r.Company);
|
|
|
|
|
|
2022-01-05 17:50:45 +05:00
|
|
|
|
public WellService(IAsbCloudDbContext db, CacheDb cacheDb, ITelemetryService telemetryService, ITimezoneService timezoneService)
|
2022-06-06 15:43:47 +05:00
|
|
|
|
: base(db, MakeQueryWell)
|
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-06-06 15:43:47 +05:00
|
|
|
|
|
|
|
|
|
this.wellOperationService = new WellOperationService.WellOperationService(db, cacheDb, this);
|
|
|
|
|
companyTypesService = new CrudCacheServiceBase<CompanyTypeDto, CompanyType>(dbContext);
|
2021-05-12 16:03:14 +05:00
|
|
|
|
}
|
2021-10-20 12:52:31 +05:00
|
|
|
|
|
2022-06-06 15:43:47 +05:00
|
|
|
|
private IEnumerable<RelationCompanyWell> GetCacheRelationCompanyWell()
|
|
|
|
|
=> dbContext.RelationCompaniesWells
|
|
|
|
|
.Include(r => r.Company)
|
|
|
|
|
.Include(r => r.Well)
|
|
|
|
|
.FromCache(relationCompaniesWellsCacheTag, relationCompaniesWellsCacheObsolence);
|
|
|
|
|
|
|
|
|
|
private Task<IEnumerable<RelationCompanyWell>> GetCacheRelationCompanyWellAsync(CancellationToken token)
|
|
|
|
|
=> dbContext.RelationCompaniesWells
|
|
|
|
|
.Include(r => r.Company)
|
|
|
|
|
.Include(r => r.Well)
|
|
|
|
|
.FromCacheAsync(relationCompaniesWellsCacheTag, relationCompaniesWellsCacheObsolence, token);
|
|
|
|
|
|
|
|
|
|
private void DropCacheRelationCompanyWell()
|
|
|
|
|
=> dbContext.RelationCompaniesWells.DropCache(relationCompaniesWellsCacheTag);
|
|
|
|
|
|
2021-12-30 17:05:44 +05:00
|
|
|
|
public DateTimeOffset GetLastTelemetryDate(int idWell)
|
2021-10-20 12:52:31 +05:00
|
|
|
|
{
|
2022-06-06 15:43:47 +05:00
|
|
|
|
var well = Get(idWell);
|
2022-06-15 14:57:37 +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
|
|
|
|
{
|
2022-06-15 14:57:37 +05:00
|
|
|
|
var relationsCache = await GetCacheRelationCompanyWellAsync(token);
|
2022-06-06 15:43:47 +05:00
|
|
|
|
|
|
|
|
|
var wellsIds = relationsCache
|
|
|
|
|
.Where(r => r.IdCompany == idCompany)
|
|
|
|
|
.Select(r => r.IdWell);
|
2021-12-22 11:41:18 +05:00
|
|
|
|
|
2022-06-06 15:43:47 +05:00
|
|
|
|
var wellsDtos = (await GetCacheAsync(token))
|
|
|
|
|
.Where(kv => wellsIds.Contains(kv.Key))
|
2022-06-15 14:57:37 +05:00
|
|
|
|
.Select(kv => kv.Value);
|
|
|
|
|
|
2022-06-06 15:43:47 +05:00
|
|
|
|
return wellsDtos.ToList();
|
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
|
|
|
|
|
2022-06-06 15:43:47 +05:00
|
|
|
|
if (dto.Id != 0 && (await GetCacheAsync(token)).ContainsKey(dto.Id))
|
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);
|
|
|
|
|
|
2022-06-06 15:43:47 +05:00
|
|
|
|
var result = await base.InsertAsync(dto, token);
|
2021-12-22 11:41:18 +05:00
|
|
|
|
|
|
|
|
|
if (dto.Companies.Any())
|
|
|
|
|
{
|
2022-06-06 15:43:47 +05:00
|
|
|
|
var newRelations = dto.Companies.Select(c => new RelationCompanyWell { IdWell = result, IdCompany = c.Id });
|
|
|
|
|
dbContext.RelationCompaniesWells.AddRange(newRelations);
|
|
|
|
|
await dbContext.SaveChangesAsync(token);
|
|
|
|
|
DropCacheRelationCompanyWell();
|
2021-12-22 11:41:18 +05:00
|
|
|
|
}
|
|
|
|
|
|
2022-06-06 15:43:47 +05:00
|
|
|
|
return result;
|
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-06-09 11:19:52 +05:00
|
|
|
|
public override async Task<int> UpdateAsync(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
|
|
|
|
|
2022-06-06 15:43:47 +05:00
|
|
|
|
var oldRelations = (await GetCacheRelationCompanyWellAsync(token))
|
2022-06-09 11:19:52 +05:00
|
|
|
|
.Where(r => r.IdWell == dto.Id);
|
2021-12-22 11:41:18 +05:00
|
|
|
|
|
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)))
|
|
|
|
|
{
|
2022-06-06 15:43:47 +05:00
|
|
|
|
dbContext.RelationCompaniesWells
|
|
|
|
|
.RemoveRange(dbContext.RelationCompaniesWells
|
2022-06-09 11:19:52 +05:00
|
|
|
|
.Where(r => r.IdWell == dto.Id));
|
2022-06-06 15:43:47 +05:00
|
|
|
|
|
2022-06-09 11:19:52 +05:00
|
|
|
|
var newRelations = dto.Companies.Select(c => new RelationCompanyWell { IdWell = dto.Id, IdCompany = c.Id });
|
2022-06-06 15:43:47 +05:00
|
|
|
|
dbContext.RelationCompaniesWells.AddRange(newRelations);
|
2021-12-22 11:41:18 +05:00
|
|
|
|
}
|
2021-10-18 12:38:49 +05:00
|
|
|
|
|
2022-06-09 11:19:52 +05:00
|
|
|
|
var result = await base.UpdateAsync(dto, token);
|
2021-12-21 11:52:53 +05:00
|
|
|
|
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)
|
2022-06-06 15:43:47 +05:00
|
|
|
|
=> GetCacheRelationCompanyWell()
|
|
|
|
|
.Any(r => r.IdWell == idWell && r.IdCompany == idCompany);
|
2021-10-12 16:07:08 +05:00
|
|
|
|
|
2021-08-11 16:54:42 +05:00
|
|
|
|
public async Task<bool> IsCompanyInvolvedInWellAsync(int idCompany, int idWell, CancellationToken token)
|
2022-06-06 15:43:47 +05:00
|
|
|
|
=> (await GetCacheRelationCompanyWellAsync(token))
|
|
|
|
|
.Any(r => r.IdWell == idWell && r.IdCompany == idCompany);
|
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)
|
|
|
|
|
{
|
2022-06-06 15:43:47 +05:00
|
|
|
|
var entity = await GetAsync(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)
|
|
|
|
|
{
|
2022-06-06 15:43:47 +05:00
|
|
|
|
var relations = (await GetCacheRelationCompanyWellAsync(token))
|
|
|
|
|
.Where(r => r.IdWell == idWell);
|
2021-12-21 11:52:53 +05:00
|
|
|
|
var dtos = relations.Select(r => Convert(r.Company));
|
|
|
|
|
return dtos;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private IEnumerable<CompanyDto> GetCompanies(int idWell)
|
|
|
|
|
{
|
2022-06-06 15:43:47 +05:00
|
|
|
|
var relations = GetCacheRelationCompanyWell().Where(r => r.IdWell == idWell);
|
2021-12-21 11:52:53 +05:00
|
|
|
|
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)
|
|
|
|
|
{
|
2022-06-06 15:43:47 +05:00
|
|
|
|
var well = await GetAsync(idWell, token);
|
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
|
|
|
|
|
2022-06-06 15:43:47 +05:00
|
|
|
|
var cache = await GetCacheAsync(token);
|
|
|
|
|
|
|
|
|
|
var clusterWellsIds = cache.Values
|
|
|
|
|
.Where((w) => w.IdCluster == well.IdCluster)
|
|
|
|
|
.Select(w => w.Id);
|
2022-04-11 18:00:34 +05:00
|
|
|
|
|
2022-06-06 15:43:47 +05:00
|
|
|
|
return clusterWellsIds;
|
2021-11-23 11:41:27 +05:00
|
|
|
|
}
|
2021-10-21 15:57:20 +05:00
|
|
|
|
|
2021-12-22 11:41:18 +05:00
|
|
|
|
protected override Well Convert(WellDto dto)
|
|
|
|
|
{
|
2022-06-06 17:00:53 +05:00
|
|
|
|
var entity = dto.Adapt<Well>();
|
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-06-06 15:43:47 +05:00
|
|
|
|
entity.Timezone = GetTimezone(dto.Id)
|
|
|
|
|
.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-06-06 15:43:47 +05:00
|
|
|
|
dto.Timezone = GetTimezone(entity.Id);
|
2022-01-05 17:50:45 +05:00
|
|
|
|
|
2022-06-06 15:43:47 +05:00
|
|
|
|
dto.StartDate = wellOperationService.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;
|
2022-06-15 14:57:37 +05:00
|
|
|
|
if (entity.IdTelemetry is not null)
|
2022-06-06 15:43:47 +05:00
|
|
|
|
dto.LastTelemetryDate = telemetryService.GetLastTelemetryDate((int)entity.IdTelemetry);
|
|
|
|
|
dto.Companies = entity.RelationCompaniesWells
|
|
|
|
|
.Select(r => Convert(r.Company))
|
|
|
|
|
.ToList();
|
2021-12-21 11:52:53 +05:00
|
|
|
|
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
|
2022-06-06 15:43:47 +05:00
|
|
|
|
?? companyTypesService.Get(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-06-06 15:43:47 +05:00
|
|
|
|
public async Task EnshureTimezonesIsSetAsync(CancellationToken token)
|
2021-12-30 17:05:44 +05:00
|
|
|
|
{
|
2022-06-06 15:43:47 +05:00
|
|
|
|
var cache = await GetCacheAsync(token);
|
|
|
|
|
if (!cache.Values.Any(w => w.Timezone is null))
|
|
|
|
|
return;
|
2022-01-10 17:39:33 +05:00
|
|
|
|
|
2022-06-06 15:43:47 +05:00
|
|
|
|
var defaultTimeZone = new SimpleTimezone
|
2022-01-05 17:50:45 +05:00
|
|
|
|
{
|
2022-06-06 15:43:47 +05:00
|
|
|
|
Hours = 5,
|
|
|
|
|
IsOverride = false,
|
2022-06-06 17:00:53 +05:00
|
|
|
|
TimezoneId = "Assumed",
|
2022-06-06 15:43:47 +05:00
|
|
|
|
};
|
2021-12-30 17:05:44 +05:00
|
|
|
|
|
2022-06-06 15:43:47 +05:00
|
|
|
|
await dbSet.Where(w => w.Timezone == null)
|
|
|
|
|
.ForEachAsync(w => w.Timezone = defaultTimeZone, token);
|
|
|
|
|
|
|
|
|
|
await dbContext.SaveChangesAsync(token);
|
|
|
|
|
DropCache();
|
2022-01-10 17:39:33 +05:00
|
|
|
|
}
|
|
|
|
|
|
2022-01-05 17:50:45 +05:00
|
|
|
|
public SimpleTimezoneDto GetTimezone(int idWell)
|
|
|
|
|
{
|
2022-06-06 15:43:47 +05:00
|
|
|
|
var well = Get(idWell);
|
2022-01-05 17:50:45 +05:00
|
|
|
|
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-06-06 15:43:47 +05:00
|
|
|
|
private SimpleTimezoneDto GetTimezone(WellDto wellDto)
|
2022-01-10 17:39:33 +05:00
|
|
|
|
{
|
2022-06-06 15:43:47 +05:00
|
|
|
|
if (wellDto.Timezone is not null)
|
|
|
|
|
return wellDto.Timezone;
|
2022-01-10 17:39:33 +05:00
|
|
|
|
|
2022-06-06 15:43:47 +05:00
|
|
|
|
if (wellDto.Telemetry is not null)
|
2022-01-05 17:50:45 +05:00
|
|
|
|
{
|
2022-06-06 15:43:47 +05:00
|
|
|
|
var timezone = telemetryService.GetTimezone(wellDto.Telemetry.Id);
|
2022-01-05 17:50:45 +05:00
|
|
|
|
if (timezone is not null)
|
|
|
|
|
return timezone;
|
|
|
|
|
}
|
|
|
|
|
|
2022-06-06 15:43:47 +05:00
|
|
|
|
var well = GetQuery().FirstOrDefault(w => w.Id == wellDto.Id);
|
2022-01-05 17:50:45 +05:00
|
|
|
|
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)
|
|
|
|
|
{
|
|
|
|
|
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)
|
|
|
|
|
{
|
|
|
|
|
return timezone;
|
|
|
|
|
}
|
|
|
|
|
}
|
2021-12-30 17:05:44 +05:00
|
|
|
|
}
|
2022-01-05 17:50:45 +05:00
|
|
|
|
|
2022-06-06 15:43:47 +05:00
|
|
|
|
throw new Exception($"Can't find timezone for well {wellDto.Caption} id: {wellDto.Id}");
|
2022-01-05 17:50:45 +05:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
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;
|
|
|
|
|
|
2022-06-06 15:43:47 +05:00
|
|
|
|
if (well.IdCluster is null)
|
2022-01-05 17:50:45 +05:00
|
|
|
|
throw new Exception($"Can't find coordinates of well {well.Caption} id: {well.Id}");
|
2022-06-15 14:57:37 +05:00
|
|
|
|
|
2022-01-05 17:50:45 +05:00
|
|
|
|
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)
|
|
|
|
|
{
|
2022-06-06 15:43:47 +05:00
|
|
|
|
var well = Get(idWell);
|
2022-01-05 17:50:45 +05:00
|
|
|
|
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
|
|
|
|
}
|
|
|
|
|
}
|