2021-04-02 17:28:07 +05:00
|
|
|
|
using AsbCloudApp.Data;
|
|
|
|
|
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;
|
|
|
|
|
|
|
|
|
|
namespace AsbCloudInfrastructure.Services
|
|
|
|
|
{
|
|
|
|
|
public class WellService : IWellService
|
|
|
|
|
{
|
|
|
|
|
private readonly IAsbCloudDbContext db;
|
2021-05-12 16:03:14 +05:00
|
|
|
|
private readonly ITelemetryTracker telemetryTracker;
|
2021-07-21 17:23:57 +05:00
|
|
|
|
private readonly CacheTable<RelationCompanyWell> cacheRelationCompaniesWells;
|
2021-04-02 17:28:07 +05:00
|
|
|
|
|
2021-05-14 17:02:29 +05:00
|
|
|
|
public WellService(IAsbCloudDbContext db, ITelemetryTracker telemetryTracker, CacheDb cacheDb)
|
2021-04-02 17:28:07 +05:00
|
|
|
|
{
|
|
|
|
|
this.db = db;
|
2021-05-12 16:03:14 +05:00
|
|
|
|
this.telemetryTracker = telemetryTracker;
|
2021-07-21 17:23:57 +05:00
|
|
|
|
cacheRelationCompaniesWells = cacheDb.GetCachedTable<RelationCompanyWell>((AsbCloudDbContext)db);
|
2021-05-12 16:03:14 +05:00
|
|
|
|
}
|
|
|
|
|
|
2021-07-21 12:30:51 +05:00
|
|
|
|
public IEnumerable<WellDto> GetTransmittingWells(int idCompany)
|
2021-05-12 16:03:14 +05:00
|
|
|
|
{
|
2021-05-12 17:25:52 +05:00
|
|
|
|
var wells = new List<Well>();
|
2021-05-14 10:58:23 +05:00
|
|
|
|
IEnumerable<string> activeTelemetriesUids = telemetryTracker.GetTransmittingTelemetryUids();
|
2021-05-20 11:17:55 +05:00
|
|
|
|
if (activeTelemetriesUids.Any())
|
2021-05-12 17:25:52 +05:00
|
|
|
|
{
|
2021-07-21 12:30:51 +05:00
|
|
|
|
wells = db.GetWellsForCompany(idCompany)
|
2021-05-12 17:25:52 +05:00
|
|
|
|
.Where(w => activeTelemetriesUids.Contains(w.Telemetry.RemoteUid))
|
|
|
|
|
.ToList();
|
|
|
|
|
}
|
2021-05-12 16:03:14 +05:00
|
|
|
|
return wells.Select(w => From(w));
|
2021-04-02 17:28:07 +05:00
|
|
|
|
}
|
|
|
|
|
|
2021-07-21 15:22:58 +05:00
|
|
|
|
public IEnumerable<WellDto> GetWellsByCompany(int idCompany)
|
2021-04-02 17:28:07 +05:00
|
|
|
|
{
|
2021-07-21 12:30:51 +05:00
|
|
|
|
var wells = db.GetWellsForCompany(idCompany).ToList();
|
2021-04-02 17:28:07 +05:00
|
|
|
|
return wells.Select(w => From(w));
|
|
|
|
|
}
|
|
|
|
|
|
2021-07-29 12:39:22 +05:00
|
|
|
|
public bool IsCompanyInvolvedInWell(int idCompany, int idWell)
|
2021-07-21 17:23:57 +05:00
|
|
|
|
=> cacheRelationCompaniesWells.Contains(r => r.IdWell == idWell && r.IdCompany == idCompany);
|
2021-08-09 15:41:42 +05:00
|
|
|
|
|
2021-07-27 14:43:30 +05:00
|
|
|
|
public IEnumerable<WellOperationDto> GetOperations(int idWell)
|
|
|
|
|
{
|
2021-07-28 09:46:58 +05:00
|
|
|
|
var entities = db
|
|
|
|
|
.WellOperations
|
|
|
|
|
.Where(o => o.IdWell == idWell)
|
|
|
|
|
.ToList();
|
|
|
|
|
|
|
|
|
|
var dtos = entities.Adapt<WellOperationDto>();
|
|
|
|
|
|
|
|
|
|
return dtos;
|
2021-07-27 14:43:30 +05:00
|
|
|
|
}
|
|
|
|
|
|
2021-05-12 16:03:14 +05:00
|
|
|
|
private static WellDto From(Well well)
|
2021-04-02 17:28:07 +05:00
|
|
|
|
{
|
|
|
|
|
var wellDto = new WellDto
|
|
|
|
|
{
|
|
|
|
|
Id = well.Id,
|
|
|
|
|
Caption = well.Caption,
|
|
|
|
|
Cluster = well.Cluster.Caption,
|
|
|
|
|
Deposit = well.Cluster.Deposit.Caption,
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
return wellDto;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|