forked from ddrilling/AsbCloudServer
154 lines
5.1 KiB
C#
154 lines
5.1 KiB
C#
using AsbCloudApp.Data;
|
|
using AsbCloudApp.Services;
|
|
using AsbCloudDb.Model;
|
|
using AsbCloudInfrastructure.Services.Cache;
|
|
using Microsoft.EntityFrameworkCore;
|
|
using System;
|
|
using System.Collections.Generic;
|
|
using System.Linq;
|
|
using System.Text;
|
|
using System.Threading.Tasks;
|
|
|
|
namespace AsbCloudInfrastructure.Services
|
|
{
|
|
public class ClusterService : IClusterService
|
|
{
|
|
private readonly IAsbCloudDbContext db;
|
|
|
|
public ClusterService(IAsbCloudDbContext db)
|
|
{
|
|
this.db = db;
|
|
}
|
|
|
|
public IEnumerable<DepositDto> GetDeposits(int idCompany)
|
|
{
|
|
var entities = db.GetWellsForCompany(idCompany)
|
|
.Select(e=>e.Cluster.Deposit)
|
|
.Distinct()
|
|
.ToList();
|
|
|
|
var dtos = entities.Select(e => new DepositDto
|
|
{
|
|
Id = e.Id,
|
|
Name = e.Caption,
|
|
Latitude = e.Latitude,
|
|
Longitude = e.Longitude,
|
|
});
|
|
|
|
return dtos;
|
|
}
|
|
|
|
public IEnumerable<ClusterDto> GetClusters(int idCompany)
|
|
{
|
|
var entities = db.GetWellsForCompany(idCompany)
|
|
.Select(e => e.Cluster)
|
|
.Distinct()
|
|
.ToList();
|
|
|
|
var dtos = entities.Select(e => new ClusterDto
|
|
{
|
|
Id = e.Id,
|
|
Name = e.Caption,
|
|
Latitude = e.Latitude,
|
|
Longitude = e.Longitude,
|
|
});
|
|
|
|
return dtos;
|
|
}
|
|
|
|
public IEnumerable<ClusterDto> GetClusters(int idCompany, int depositId)
|
|
{
|
|
var entities = db.GetWellsForCompany(idCompany)
|
|
.Select(e => e.Cluster)
|
|
.Where(e=>e.IdDeposit == depositId)
|
|
.Distinct()
|
|
.ToList();
|
|
|
|
var dtos = entities.Select(e => new ClusterDto
|
|
{
|
|
Id = e.Id,
|
|
Name = e.Caption,
|
|
Latitude = e.Latitude,
|
|
Longitude = e.Longitude,
|
|
});
|
|
|
|
return dtos;
|
|
}
|
|
|
|
public IEnumerable<WellDto> GetWells(int idCompany, int idCluster)
|
|
{
|
|
var entities = db.GetWellsForCompany(idCompany)
|
|
.Where(e => e.IdCluster == idCluster)
|
|
.ToList();
|
|
|
|
var dtos = entities.Select(e => new WellDto
|
|
{
|
|
Id = e.Id,
|
|
Caption = e.Caption,
|
|
Latitude = e.Latitude,
|
|
Longitude = e.Longitude,
|
|
Cluster = e.Cluster.Caption,
|
|
Deposit = e.Cluster.Deposit.Caption,
|
|
});
|
|
|
|
return dtos;
|
|
}
|
|
|
|
public IEnumerable<WellDrillingStatDto> GetStat(int idCompany, int idCluster)
|
|
{
|
|
var entities = from w in db.Wells
|
|
.Include(e => e.Companies)
|
|
.Include(e => e.Sections)
|
|
|
|
where w.IdCluster == idCluster && w.Companies.Any(c => c.Id == idCompany)
|
|
select w;
|
|
|
|
var dtos = entities.Select(e => new WellDrillingStatDto
|
|
{
|
|
Id = e.Id,
|
|
Caption = e.Caption,
|
|
Cluster = e.Cluster.Caption,
|
|
Deposit = e.Cluster.Deposit.Caption,
|
|
Latitude = e.Latitude,
|
|
Longitude = e.Longitude,
|
|
FactEnd = e.FactEnd,
|
|
FactStart = e.FactStart,
|
|
LastData = null,
|
|
PlanEnd = e.PlanEnd,
|
|
PlanStart = e.PlanStart,
|
|
RateOfPenetrationFact = e.RateOfPenetrationFact,
|
|
RateOfPenetrationPlan = e.RateOfPenetrationPlan,
|
|
RouteSpeedFact = e.RouteSpeedFact,
|
|
RouteSpeedPlan = e.RouteSpeedPlan,
|
|
Sections = e.Sections.Select(s => new WellSectionDto {
|
|
BhaDownSpeedFact = s.BhaDownSpeedFact,
|
|
BhaDownSpeedPlan = s.BhaDownSpeedPlan,
|
|
BhaUpSpeedFact = s.BhaUpSpeedFact,
|
|
BhaUpSpeedPlan = s.BhaUpSpeedPlan,
|
|
BuildDaysFact = s.BuildDaysFact,
|
|
BuildDaysPlan = s.BuildDaysPlan,
|
|
CasingDownSpeedFact = s.CasingDownSpeedFact,
|
|
CasingDownSpeedPlan = s.CasingDownSpeedPlan,
|
|
RateOfPenetrationFact = s.RateOfPenetrationFact,
|
|
RateOfPenetrationPlan = s.RateOfPenetrationPlan,
|
|
RouteSpeedFact = s.RouteSpeedFact,
|
|
RouteSpeedPlan = s.RouteSpeedPlan,
|
|
SectionType = s.WellSectionType.Caption,
|
|
WellDepthFact = s.WellDepthFact,
|
|
WellDepthPlan = s.WellDepthPlan,
|
|
}),
|
|
UnProductiveDays = e.UnProductiveDays,
|
|
Companies = e.Companies.Select(c => new CompanyDto
|
|
{
|
|
Id = c.Id,
|
|
Caption = c.Caption,
|
|
CompanyType = c.CompanyType.Caption,
|
|
}),
|
|
WellType = e.WellType.Caption,
|
|
});
|
|
|
|
return dtos;
|
|
}
|
|
}
|
|
}
|