forked from ddrilling/AsbCloudServer
108 lines
4.1 KiB
C#
108 lines
4.1 KiB
C#
|
using AsbSaubReport.Model;
|
|||
|
using System;
|
|||
|
using System.Collections.Generic;
|
|||
|
using System.Linq;
|
|||
|
using AsbCloudDb.Model;
|
|||
|
using Microsoft.EntityFrameworkCore;
|
|||
|
|
|||
|
namespace AsbSaubReport
|
|||
|
{
|
|||
|
public class ReportDataSourcePgCloud : IReportDataSource
|
|||
|
{
|
|||
|
private readonly AsbCloudDbContext context;
|
|||
|
|
|||
|
private readonly int? idTelemetry;
|
|||
|
private readonly WellInfoReport info;
|
|||
|
|
|||
|
private readonly Dictionary<int, Event> events;
|
|||
|
private readonly Dictionary<int, TelemetryUser> users;
|
|||
|
private readonly Dictionary<int, string> categories = new Dictionary<int, string>
|
|||
|
{
|
|||
|
{1, "Авария"},
|
|||
|
{2, "Предупреждение"},
|
|||
|
{3, "Информация"},
|
|||
|
};
|
|||
|
|
|||
|
public ReportDataSourcePgCloud(AsbCloudDbContext context, int wellId)
|
|||
|
{
|
|||
|
this.context = context;
|
|||
|
var well = context.Wells
|
|||
|
.Include(w=>w.Cluster)
|
|||
|
.ThenInclude(c=>c.Deposit)
|
|||
|
.Include(w=>w.Customer)
|
|||
|
.Include(w => w.Telemetry)
|
|||
|
.FirstOrDefault(w => w.Id == wellId);
|
|||
|
|
|||
|
idTelemetry = well?.IdTelemetry;
|
|||
|
if (idTelemetry is null)
|
|||
|
throw new ArgumentException($"Well {wellId} doesn't contain telemetry", nameof(wellId));
|
|||
|
|
|||
|
events = context.Events
|
|||
|
.Where(e => e.IdTelemetry == idTelemetry)
|
|||
|
.ToDictionary(e => e.IdEvent, e => e);
|
|||
|
|
|||
|
users = context.TelemetryUsers
|
|||
|
.Where(u => u.IdTelemetry == idTelemetry)
|
|||
|
.ToDictionary(u => u.IdUser, u => u);
|
|||
|
|
|||
|
info = new WellInfoReport
|
|||
|
{
|
|||
|
Deposit = well.Cluster.Deposit.Caption,
|
|||
|
Cluster = well.Cluster.Caption,
|
|||
|
Well = well.Caption,
|
|||
|
Customer = well.Customer.Caption,
|
|||
|
DrillingStartDate = well.Telemetry?.Info?.DrillingStartDate??default,
|
|||
|
TimeZoneId = well.Telemetry?.Info?.TimeZoneId??default,
|
|||
|
};
|
|||
|
}
|
|||
|
|
|||
|
public IQueryable<DataSaubReport> GetDataSaubItems(DateTime begin, DateTime end)
|
|||
|
=> from item in context.DataSaubBases
|
|||
|
where item.IdTelemetry == idTelemetry
|
|||
|
&& item.Date >= begin
|
|||
|
&& item.Date <= end
|
|||
|
select new DataSaubReport
|
|||
|
{
|
|||
|
Id = item.Id,
|
|||
|
Date = item.Date,
|
|||
|
Mode = item.Mode,
|
|||
|
WellDepth = item.WellDepth,
|
|||
|
BitDepth = item.BitDepth,
|
|||
|
BlockPosition = item.BlockPosition,
|
|||
|
BlockSpeed = item.BlockSpeed,
|
|||
|
BlockSpeedSp = item.BlockSpeedSp,
|
|||
|
BlockSpeedSpDevelop = item.BlockSpeedSpDevelop,
|
|||
|
Pressure = item.Pressure,
|
|||
|
PressureSp = item.PressureSp,
|
|||
|
AxialLoad = item.AxialLoad,
|
|||
|
AxialLoadSp = item.AxialLoadSp,
|
|||
|
AxialLoadLimitMax = item.AxialLoadLimitMax,
|
|||
|
HookWeight = item.HookWeight,
|
|||
|
RotorTorque = item.RotorTorque,
|
|||
|
RotorTorqueSp = item.RotorTorqueSp,
|
|||
|
RotorSpeed = item.RotorSpeed,
|
|||
|
Flow = item.Flow,
|
|||
|
PressureSpDevelop = item.PressureSpDevelop,
|
|||
|
};
|
|||
|
|
|||
|
public IQueryable<MessageReport> GetMessages(DateTime begin, DateTime end)
|
|||
|
=> from item in context.Messages
|
|||
|
where item.IdTelemetry == idTelemetry
|
|||
|
&& item.Date >= begin
|
|||
|
&& item.Date <= end
|
|||
|
select new MessageReport
|
|||
|
{
|
|||
|
Id = item.Id,
|
|||
|
Date = item.Date,
|
|||
|
Category = categories[events[item.IdEvent].IdCategory],
|
|||
|
User = item.IdTelemetryUser == null
|
|||
|
? ""
|
|||
|
: users[(int)item.IdTelemetryUser].MakeDisplayName(),
|
|||
|
Text = events[item.IdEvent].MakeMessageText(item)
|
|||
|
};
|
|||
|
|
|||
|
public WellInfoReport GetWellInfo()
|
|||
|
=> info;
|
|||
|
}
|
|||
|
}
|