DD.WellWorkover.Cloud/AsbCloudInfrastructure/Services/WellService.cs

73 lines
2.3 KiB
C#
Raw Normal View History

using AsbCloudApp.Data;
using AsbCloudApp.Services;
using AsbCloudDb.Model;
using AsbCloudInfrastructure.Services.Cache;
2021-07-28 09:46:58 +05:00
using Mapster;
2021-07-21 15:29:19 +05:00
using System;
using System.Collections.Generic;
using System.Linq;
namespace AsbCloudInfrastructure.Services
{
public class WellService : IWellService
{
private readonly IAsbCloudDbContext db;
private readonly ITelemetryTracker telemetryTracker;
2021-07-21 17:23:57 +05:00
private readonly CacheTable<RelationCompanyWell> cacheRelationCompaniesWells;
public WellService(IAsbCloudDbContext db, ITelemetryTracker telemetryTracker, CacheDb cacheDb)
{
this.db = db;
this.telemetryTracker = telemetryTracker;
2021-07-21 17:23:57 +05:00
cacheRelationCompaniesWells = cacheDb.GetCachedTable<RelationCompanyWell>((AsbCloudDbContext)db);
}
public IEnumerable<WellDto> GetTransmittingWells(int idCompany)
{
var wells = new List<Well>();
IEnumerable<string> activeTelemetriesUids = telemetryTracker.GetTransmittingTelemetryUids();
2021-05-20 11:17:55 +05:00
if (activeTelemetriesUids.Any())
{
wells = db.GetWellsForCompany(idCompany)
.Where(w => activeTelemetriesUids.Contains(w.Telemetry.RemoteUid))
.ToList();
}
return wells.Select(w => From(w));
}
2021-07-21 15:22:58 +05:00
public IEnumerable<WellDto> GetWellsByCompany(int idCompany)
{
var wells = db.GetWellsForCompany(idCompany).ToList();
return wells.Select(w => From(w));
}
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-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
}
private static WellDto From(Well well)
{
var wellDto = new WellDto
{
Id = well.Id,
Caption = well.Caption,
Cluster = well.Cluster.Caption,
Deposit = well.Cluster.Deposit.Caption,
};
return wellDto;
}
}
}