Новый контроллер, обслуживающий ТКСР и всё, что с ним связано: модель БД, DTO, сервис.

This commit is contained in:
Оля Бизюкова 2025-01-09 17:43:21 +05:00
parent dc7c126ee2
commit 3d39099534
12 changed files with 12947 additions and 0 deletions

View File

@ -0,0 +1,76 @@
using System;
using System.ComponentModel.DataAnnotations;
namespace AsbCloudApp.Data.SAUB;
/// <summary>
/// телеметрия ТКРС
/// </summary>
public class TelemetryDataWellWorkoverDto : ITelemetryData
{
/// <summary>
/// Идентификатор телеметрии
/// </summary>
public int IdTelemetry { get; set; }
/// <summary>
/// Дата
/// </summary>
[Required]
public DateTime DateTime { get; set; }
/// <summary>
/// Глубина инструмента, м
/// </summary>
public float BitDepth { get; set; }
/// <summary>
/// Высота крюкоблока, м
/// </summary>
public float BlockPosition { get; set; }
/// <summary>
/// Вес на крюке
/// </summary>
public float HookLoad { get; set; }
/// <summary>
/// Скорость СПО, м/с
/// </summary>
public float TripInOutSpeed { get; set; }
/// <summary>
/// Объем доливной емкости (ДЕ), м3
/// </summary>
public float TripTankVolume { get; set; }
/// <summary>
/// Плотность жидкости в ДЕ, г/см3
/// </summary>
public float MudDensity { get; set; }
/// <summary>
/// Расход доливаемой жидкости, м3/ч
/// </summary>
public float FlowRate { get; set; }
/// <summary>
/// Уровень в скважине (по эхолоту), м
/// </summary>
public float WellLevel { get; set; }
/// <summary>
/// Температура жидкости в отводе крестовины ПВО, С
/// </summary>
public float MudTemperatureInBlowOutPreventor { get; set; }
/// <summary>
/// Газопоказания (СН4), %
/// </summary>
public float GasIndicationsCH4 { get; set; }
/// <summary>
/// Газопоказания (Н2S), %
/// </summary>
public float GasIndicationsH2S { get; set; }
}

File diff suppressed because it is too large Load Diff

View File

@ -0,0 +1,53 @@
using System;
using Microsoft.EntityFrameworkCore.Migrations;
#nullable disable
namespace AsbCloudDb.Migrations
{
/// <inheritdoc />
public partial class TelemetryDataWellWorkover : Migration
{
/// <inheritdoc />
protected override void Up(MigrationBuilder migrationBuilder)
{
migrationBuilder.CreateTable(
name: "t_telemetry_data_well_workover",
columns: table => new
{
id_telemetry = table.Column<int>(type: "integer", nullable: false),
date = table.Column<DateTimeOffset>(type: "timestamp with time zone", nullable: false, comment: "'2021-10-19 18:23:54+05'"),
id_user = table.Column<int>(type: "integer", nullable: true, comment: "Пользователь ТКРС"),
tool_depth = table.Column<float>(type: "real", nullable: false, comment: "Глубина инструмента, м "),
hook_block_depth = table.Column<float>(type: "real", nullable: false, comment: "Высота крюкоблока, м"),
hook_weight = table.Column<float>(type: "real", nullable: false, comment: "Вес на крюке"),
up_and_down_operations_speed = table.Column<float>(type: "real", nullable: false, comment: "Скорость СПО, м/с"),
slagging_tank_volume = table.Column<float>(type: "real", nullable: false, comment: "Объем доливной емкости (ДЕ), м3"),
liquid_density = table.Column<float>(type: "real", nullable: false, comment: "Плотность жидкости в ДЕ, г/см3"),
liquid_rate = table.Column<float>(type: "real", nullable: false, comment: "Расход доливаемой жидкости, м3/ч"),
well_level = table.Column<float>(type: "real", nullable: false, comment: "Уровень в скважине (по эхолоту), м"),
liquid_branch_brace_temperature = table.Column<float>(type: "real", nullable: false, comment: "Температура жидкости в отводе крестовины ПВО, С"),
gas_indications_CH4 = table.Column<float>(type: "real", nullable: false, comment: "Газопоказания (СН4), %"),
gas_indications_H2S = table.Column<float>(type: "real", nullable: false, comment: "Газопоказания (Н2S), %")
},
constraints: table =>
{
table.PrimaryKey("PK_t_telemetry_data_well_workover", x => new { x.id_telemetry, x.date });
table.ForeignKey(
name: "t_telemetry_data_well_workover_t_telemetry_id_fk",
column: x => x.id_telemetry,
principalTable: "t_telemetry",
principalColumn: "id",
onDelete: ReferentialAction.Cascade);
},
comment: "набор основных данных для ТКРС");
}
/// <inheritdoc />
protected override void Down(MigrationBuilder migrationBuilder)
{
migrationBuilder.DropTable(
name: "t_telemetry_data_well_workover");
}
}
}

View File

@ -7361,6 +7361,85 @@ namespace AsbCloudDb.Migrations
}); });
}); });
modelBuilder.Entity("AsbCloudDb.Model.TelemetryDataWellWorkover", b =>
{
b.Property<int>("IdTelemetry")
.HasColumnType("integer")
.HasColumnName("id_telemetry");
b.Property<DateTimeOffset>("DateTime")
.HasColumnType("timestamp with time zone")
.HasColumnName("date")
.HasComment("'2021-10-19 18:23:54+05'");
b.Property<float>("BitDepth")
.HasColumnType("real")
.HasColumnName("tool_depth")
.HasComment("Глубина инструмента, м ");
b.Property<float>("BlockPosition")
.HasColumnType("real")
.HasColumnName("hook_block_depth")
.HasComment("Высота крюкоблока, м");
b.Property<float>("FlowRate")
.HasColumnType("real")
.HasColumnName("liquid_rate")
.HasComment("Расход доливаемой жидкости, м3/ч");
b.Property<float>("GasIndicationsCH4")
.HasColumnType("real")
.HasColumnName("gas_indications_CH4")
.HasComment("Газопоказания (СН4), %");
b.Property<float>("GasIndicationsH2S")
.HasColumnType("real")
.HasColumnName("gas_indications_H2S")
.HasComment("Газопоказания (Н2S), %");
b.Property<float>("HookLoad")
.HasColumnType("real")
.HasColumnName("hook_weight")
.HasComment("Вес на крюке");
b.Property<int?>("IdUser")
.HasColumnType("integer")
.HasColumnName("id_user")
.HasComment("Пользователь ТКРС");
b.Property<float>("MudDensity")
.HasColumnType("real")
.HasColumnName("liquid_density")
.HasComment("Плотность жидкости в ДЕ, г/см3");
b.Property<float>("MudTemperatureInBlowOutPreventor")
.HasColumnType("real")
.HasColumnName("liquid_branch_brace_temperature")
.HasComment("Температура жидкости в отводе крестовины ПВО, С");
b.Property<float>("TripInOutSpeed")
.HasColumnType("real")
.HasColumnName("up_and_down_operations_speed")
.HasComment("Скорость СПО, м/с");
b.Property<float>("TripTankVolume")
.HasColumnType("real")
.HasColumnName("slagging_tank_volume")
.HasComment("Объем доливной емкости (ДЕ), м3");
b.Property<float>("WellLevel")
.HasColumnType("real")
.HasColumnName("well_level")
.HasComment("Уровень в скважине (по эхолоту), м");
b.HasKey("IdTelemetry", "DateTime");
b.ToTable("t_telemetry_data_well_workover", t =>
{
t.HasComment("набор основных данных для ТКРС");
});
});
modelBuilder.Entity("AsbCloudDb.Model.TelemetryEvent", b => modelBuilder.Entity("AsbCloudDb.Model.TelemetryEvent", b =>
{ {
b.Property<int>("IdTelemetry") b.Property<int>("IdTelemetry")
@ -12010,6 +12089,18 @@ namespace AsbCloudDb.Migrations
b.Navigation("Telemetry"); b.Navigation("Telemetry");
}); });
modelBuilder.Entity("AsbCloudDb.Model.TelemetryDataWellWorkover", b =>
{
b.HasOne("AsbCloudDb.Model.Telemetry", "Telemetry")
.WithMany("DataWellWorkover")
.HasForeignKey("IdTelemetry")
.OnDelete(DeleteBehavior.Cascade)
.IsRequired()
.HasConstraintName("t_telemetry_data_well_workover_t_telemetry_id_fk");
b.Navigation("Telemetry");
});
modelBuilder.Entity("AsbCloudDb.Model.TelemetryEvent", b => modelBuilder.Entity("AsbCloudDb.Model.TelemetryEvent", b =>
{ {
b.HasOne("AsbCloudDb.Model.Telemetry", "Telemetry") b.HasOne("AsbCloudDb.Model.Telemetry", "Telemetry")
@ -12411,6 +12502,8 @@ namespace AsbCloudDb.Migrations
b.Navigation("DataSpin"); b.Navigation("DataSpin");
b.Navigation("DataWellWorkover");
b.Navigation("Events"); b.Navigation("Events");
b.Navigation("Messages"); b.Navigation("Messages");

View File

@ -60,6 +60,7 @@ namespace AsbCloudDb.Model
public virtual DbSet<TelemetryDataSaub> TelemetryDataSaub => Set<TelemetryDataSaub>(); public virtual DbSet<TelemetryDataSaub> TelemetryDataSaub => Set<TelemetryDataSaub>();
public virtual DbSet<TelemetryDataSaubStat> TelemetryDataSaubStats => Set<TelemetryDataSaubStat>(); public virtual DbSet<TelemetryDataSaubStat> TelemetryDataSaubStats => Set<TelemetryDataSaubStat>();
public virtual DbSet<TelemetryDataSpin> TelemetryDataSpin => Set<TelemetryDataSpin>(); public virtual DbSet<TelemetryDataSpin> TelemetryDataSpin => Set<TelemetryDataSpin>();
public virtual DbSet<TelemetryDataWellWorkover> TelemetryDataWellWorkover => Set<TelemetryDataWellWorkover>();
public virtual DbSet<TelemetryEvent> TelemetryEvents => Set<TelemetryEvent>(); public virtual DbSet<TelemetryEvent> TelemetryEvents => Set<TelemetryEvent>();
public virtual DbSet<TelemetryMessage> TelemetryMessages => Set<TelemetryMessage>(); public virtual DbSet<TelemetryMessage> TelemetryMessages => Set<TelemetryMessage>();
public virtual DbSet<TelemetryUser> TelemetryUsers => Set<TelemetryUser>(); public virtual DbSet<TelemetryUser> TelemetryUsers => Set<TelemetryUser>();
@ -233,6 +234,17 @@ namespace AsbCloudDb.Model
entity.HasKey(nameof(ITelemetryData.IdTelemetry), nameof(ITelemetryData.DateTime)); entity.HasKey(nameof(ITelemetryData.IdTelemetry), nameof(ITelemetryData.DateTime));
}); });
modelBuilder.Entity<TelemetryDataWellWorkover>(entity =>
{
entity.HasOne(d => d.Telemetry)
.WithMany(p => p.DataWellWorkover)
.HasForeignKey(d => d.IdTelemetry)
.OnDelete(DeleteBehavior.Cascade)
.HasConstraintName("t_telemetry_data_well_workover_t_telemetry_id_fk");
entity.HasKey(nameof(ITelemetryData.IdTelemetry), nameof(ITelemetryData.DateTime));
});
modelBuilder.Entity<TelemetryMessage>(entity => modelBuilder.Entity<TelemetryMessage>(entity =>
{ {
entity.HasOne(d => d.Telemetry) entity.HasOne(d => d.Telemetry)

View File

@ -44,6 +44,7 @@ namespace AsbCloudDb.Model
DbSet<TelemetryDataSaub> TelemetryDataSaub { get; } DbSet<TelemetryDataSaub> TelemetryDataSaub { get; }
DbSet<TelemetryDataSaubStat> TelemetryDataSaubStats { get; } DbSet<TelemetryDataSaubStat> TelemetryDataSaubStats { get; }
DbSet<TelemetryDataSpin> TelemetryDataSpin { get; } DbSet<TelemetryDataSpin> TelemetryDataSpin { get; }
DbSet<TelemetryDataWellWorkover> TelemetryDataWellWorkover { get; }
DbSet<TelemetryEvent> TelemetryEvents { get; } DbSet<TelemetryEvent> TelemetryEvents { get; }
DbSet<TelemetryMessage> TelemetryMessages { get; } DbSet<TelemetryMessage> TelemetryMessages { get; }
DbSet<TelemetryUser> TelemetryUsers { get; } DbSet<TelemetryUser> TelemetryUsers { get; }

View File

@ -31,6 +31,9 @@ namespace AsbCloudDb.Model
[InverseProperty(nameof(TelemetryDataSpin.Telemetry))] [InverseProperty(nameof(TelemetryDataSpin.Telemetry))]
public virtual ICollection<TelemetryDataSpin> DataSpin { get; set; } = null!; public virtual ICollection<TelemetryDataSpin> DataSpin { get; set; } = null!;
[InverseProperty(nameof(TelemetryDataWellWorkover.Telemetry))]
public virtual ICollection<TelemetryDataWellWorkover> DataWellWorkover { get; set; } = null!;
[InverseProperty(nameof(TelemetryMessage.Telemetry))] [InverseProperty(nameof(TelemetryMessage.Telemetry))]
public virtual ICollection<TelemetryMessage> Messages { get; set; } = null!; public virtual ICollection<TelemetryMessage> Messages { get; set; } = null!;

View File

@ -0,0 +1,59 @@
using Microsoft.EntityFrameworkCore;
using System;
using System.ComponentModel.DataAnnotations.Schema;
using System.Text.Json.Serialization;
namespace AsbCloudDb.Model
{
[Table("t_telemetry_data_well_workover"), Comment("набор основных данных для ТКРС")]
public partial class TelemetryDataWellWorkover : ITelemetryData
{
[Column("id_telemetry")]
public int IdTelemetry { get; set; }
[Column("id_user"), Comment("Пользователь ТКРС")]
public int? IdUser { get; set; }
[Column("date", TypeName = "timestamp with time zone"), Comment("'2021-10-19 18:23:54+05'")]
public DateTimeOffset DateTime { get; set; }
[Column("tool_depth"), Comment("Глубина инструмента, м ")]
public float BitDepth { get; set; }
[Column("hook_block_depth"), Comment("Высота крюкоблока, м")]
public float BlockPosition { get; set; }
[Column("hook_weight"), Comment("Вес на крюке")]
public float HookLoad { get; set; }
[Column("up_and_down_operations_speed"), Comment("Скорость СПО, м/с")]
public float TripInOutSpeed { get; set; }
[Column("slagging_tank_volume"), Comment("Объем доливной емкости (ДЕ), м3")]
public float TripTankVolume { get; set; }
[Column("liquid_density"), Comment("Плотность жидкости в ДЕ, г/см3")]
public float MudDensity { get; set; }
[Column("liquid_rate"), Comment("Расход доливаемой жидкости, м3/ч")]
public float FlowRate { get; set; }
[Column("well_level"), Comment("Уровень в скважине (по эхолоту), м")]
public float WellLevel { get; set; }
[Column("liquid_branch_brace_temperature"), Comment("Температура жидкости в отводе крестовины ПВО, С")]
public float MudTemperatureInBlowOutPreventor { get; set; }
[Column("gas_indications_CH4"), Comment("Газопоказания (СН4), %")]
public float GasIndicationsCH4 { get; set; }
[Column("gas_indications_H2S"), Comment("Газопоказания (Н2S), %")]
public float GasIndicationsH2S { get; set; }
[JsonIgnore]
[ForeignKey(nameof(IdTelemetry))]
[InverseProperty(nameof(Model.Telemetry.DataWellWorkover))]
public virtual Telemetry Telemetry { get; set; } = null!;
}
}

View File

@ -284,6 +284,8 @@ public static class DependencyInjection
TelemetryDataCache<TelemetryDataSaubDto>.GetInstance<TelemetryDataSaub>(provider)); TelemetryDataCache<TelemetryDataSaubDto>.GetInstance<TelemetryDataSaub>(provider));
services.AddSingleton<ITelemetryDataCache<TelemetryDataSpinDto>>(provider => services.AddSingleton<ITelemetryDataCache<TelemetryDataSpinDto>>(provider =>
TelemetryDataCache<TelemetryDataSpinDto>.GetInstance<TelemetryDataSpin>(provider)); TelemetryDataCache<TelemetryDataSpinDto>.GetInstance<TelemetryDataSpin>(provider));
services.AddSingleton<ITelemetryDataCache<TelemetryDataWellWorkoverDto>>(provider =>
TelemetryDataCache<TelemetryDataWellWorkoverDto>.GetInstance<TelemetryDataWellWorkover>(provider));
services.AddSingleton<IRequerstTrackerService, RequestTrackerService>(); services.AddSingleton<IRequerstTrackerService, RequestTrackerService>();
services.AddSingleton<PeriodicBackgroundWorker>(); services.AddSingleton<PeriodicBackgroundWorker>();
services.AddSingleton<BackgroundWorker>(); services.AddSingleton<BackgroundWorker>();
@ -488,6 +490,7 @@ public static class DependencyInjection
// TelemetryData services // TelemetryData services
services.AddTransient<ITelemetryDataSaubService, TelemetryDataSaubService>(); services.AddTransient<ITelemetryDataSaubService, TelemetryDataSaubService>();
services.AddTransient<ITelemetryDataService<TelemetryDataSpinDto>, TelemetryDataSpinService>(); services.AddTransient<ITelemetryDataService<TelemetryDataSpinDto>, TelemetryDataSpinService>();
services.AddTransient<ITelemetryDataService<TelemetryDataWellWorkoverDto>, TelemetryDataWellWorkoverService>();
// Subsystem service // Subsystem service
services.AddTransient<ISubsystemService, SubsystemService>(); services.AddTransient<ISubsystemService, SubsystemService>();

View File

@ -0,0 +1,32 @@
using AsbCloudApp.Data.SAUB;
using AsbCloudApp.Repositories;
using AsbCloudApp.Services;
using AsbCloudDb.Model;
using Mapster;
namespace AsbCloudInfrastructure.Services.SAUB;
public class TelemetryDataWellWorkoverService : TelemetryDataBaseService<TelemetryDataWellWorkoverDto, TelemetryDataWellWorkover>
{
public TelemetryDataWellWorkoverService(
IAsbCloudDbContext db,
ITelemetryService telemetryService,
ITelemetryDataCache<TelemetryDataWellWorkoverDto> telemetryDataCache)
: base(db, telemetryService, telemetryDataCache)
{ }
protected override TelemetryDataWellWorkover Convert(TelemetryDataWellWorkoverDto src, double timezoneOffset)
{
var entity = src.Adapt<TelemetryDataWellWorkover>();
entity.DateTime = src.DateTime.ToUtcDateTimeOffset(timezoneOffset);
return entity;
}
protected override TelemetryDataWellWorkoverDto Convert(TelemetryDataWellWorkover src, double timezoneOffset)
{
var dto = src.Adapt<TelemetryDataWellWorkoverDto>();
dto.DateTime = src.DateTime.ToRemoteDateTime(timezoneOffset);
return dto;
}
}

View File

@ -0,0 +1,38 @@
using AsbCloudApp.Data.SAUB;
using AsbCloudApp.Services;
using AsbCloudWebApi.SignalR;
using AsbCloudWebApi.SignalR.Clients;
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc;
using Microsoft.AspNetCore.SignalR;
using System;
using System.Collections.Generic;
using System.Threading;
using System.Threading.Tasks;
namespace AsbCloudWebApi.Controllers.SAUB;
/// <summary>
/// Данные ТКРС
/// </summary>
[Route("api/[controller]")]
[ApiController]
public class TelemetryDataWellWorkoverController : TelemetryDataBaseController<TelemetryDataWellWorkoverDto>
{
public TelemetryDataWellWorkoverController(
ITelemetryService telemetryService,
ITelemetryDataService<TelemetryDataWellWorkoverDto> telemetryDataWellWorkoverService,
IWellService wellService,
IHubContext<TelemetryHub, ITelemetryHubClient> telemetryHubContext)
: base(
telemetryService,
telemetryDataWellWorkoverService,
wellService,
telemetryHubContext)
{ }
protected override Task SignalRNotifyAsync(int idWell, IEnumerable<TelemetryDataWellWorkoverDto> dtos, CancellationToken token)
{
return telemetryHubContext.Clients.Group($"well_{idWell}").ReceiveDataWellWorkover(dtos, token);
}
}

View File

@ -49,4 +49,13 @@ public interface ITelemetryHubClient
/// <returns></returns> /// <returns></returns>
Task ReceiveDataSpin(IEnumerable<TelemetryDataSpinDto> dtos, CancellationToken token); Task ReceiveDataSpin(IEnumerable<TelemetryDataSpinDto> dtos, CancellationToken token);
/// <summary>
/// Отправка ткрс-данных клиенту.
/// Для подписки на метод необходимо отправить сообщение в формате $"well_{idWell}"
/// </summary>
/// <param name="dtos"></param>
/// <param name="token"></param>
/// <returns></returns>
Task ReceiveDataWellWorkover(IEnumerable<TelemetryDataWellWorkoverDto> dtos, CancellationToken token);
} }