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-04-02 17:28:07 +05:00
|
|
|
|
using System.Collections.Generic;
|
|
|
|
|
using System.Linq;
|
2021-05-12 16:03:14 +05:00
|
|
|
|
using System;
|
2021-04-02 17:28:07 +05:00
|
|
|
|
|
|
|
|
|
namespace AsbCloudInfrastructure.Services
|
|
|
|
|
{
|
|
|
|
|
public class WellService : IWellService
|
|
|
|
|
{
|
|
|
|
|
private readonly IAsbCloudDbContext db;
|
2021-05-12 16:03:14 +05:00
|
|
|
|
private readonly ITelemetryTracker telemetryTracker;
|
2021-05-14 17:02:29 +05:00
|
|
|
|
private readonly ICacheTable<Well> cacheWells;
|
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-05-14 17:02:29 +05:00
|
|
|
|
cacheWells = cacheDb.GetCachedTable<Well>((AsbCloudDbContext)db);
|
2021-05-12 16:03:14 +05:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public IEnumerable<WellDto> GetTransmittingWells(int idCustomer)
|
|
|
|
|
{
|
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
|
|
|
|
{
|
|
|
|
|
wells = db.GetWellsByCustomer(idCustomer)
|
|
|
|
|
.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
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public IEnumerable<WellDto> GetWellsByCustomer(int idCustomer)
|
|
|
|
|
{
|
|
|
|
|
var wells = db.GetWellsByCustomer(idCustomer).ToList();
|
|
|
|
|
return wells.Select(w => From(w));
|
|
|
|
|
}
|
|
|
|
|
|
2021-05-14 17:02:29 +05:00
|
|
|
|
public bool CheckWellOwnership(int idCustomer, int wellId)
|
|
|
|
|
=> cacheWells.Contains(w => w.Id == wellId && w.IdCustomer == idCustomer);
|
|
|
|
|
|
|
|
|
|
|
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;
|
|
|
|
|
}
|
2021-05-12 16:03:14 +05:00
|
|
|
|
|
2021-04-02 17:28:07 +05:00
|
|
|
|
}
|
|
|
|
|
}
|