merge dev to ProcessMapReport

This commit is contained in:
ngfrolov 2023-01-12 16:24:10 +05:00
commit 1a7d643c50
Signed by untrusted user who does not match committer: ng.frolov
GPG Key ID: E99907A0357B29A7
30 changed files with 35744 additions and 111 deletions

View File

@ -0,0 +1,104 @@
using System;
namespace AsbCloudApp.Data
{
#nullable enable
/// <summary>
/// Формирование данных по плановой траектории
/// </summary>
public class PlannedTrajectoryDto
{
/// <summary>
/// ИД строки с координатами
/// </summary>
public int Id { get; set; }
/// <summary>
/// ИД скважины
/// </summary>
public int IdWell { get; set; }
/// <summary>
/// Дата загрузки
/// </summary>
public DateTime UpdateDate { get; set; }
/// <summary>
/// ИД пользователя
/// </summary>
public int IdUser { get; set; }
/// <summary>
/// Глубина по стволу
/// </summary>
public double WellboreDepth { get; set; }
/// <summary>
/// Угол зенитный
/// </summary>
public double ZenithAngle { get; set; }
/// <summary>
/// Азимут Географ.
/// </summary>
public double AzimuthGeo { get; set; }
/// <summary>
/// Азимут Магнитный
/// </summary>
public double AzimuthMagnetic { get; set; }
/// <summary>
/// Глубина вертикальная
/// </summary>
public double VerticalDepth { get; set; }
/// <summary>
/// Абсолютная отметка
/// </summary>
public double AbsoluteMark { get; set; }
/// <summary>
/// Север отн- но устья
/// </summary>
public double NorthOrifice { get; set; }
/// <summary>
/// Восток отн- но устья
/// </summary>
public double EastOrifice { get; set; }
/// <summary>
/// Восток картографический
/// </summary>
public double EastCartographic { get; set; }
/// <summary>
/// Север картографический
/// </summary>
public double NorthCartographic { get; set; }
/// <summary>
/// Пространственная интенсивность
/// </summary>
public double SpatialIntensity { get; set; }
/// <summary>
/// Интенсивность по углу
/// </summary>
public double AngleIntensity { get; set; }
/// <summary>
/// Интенсивность по азимуту
/// </summary>
public double AzimuthIntensity { get; set; }
/// <summary>
/// Смещение от устья
/// </summary>
public double OrificeOffset { get; set; }
/// <summary>
/// Комментарии
/// </summary>
public string? Comment { get; set; }
}
#nullable disable
}

View File

@ -2,6 +2,7 @@
namespace AsbCloudApp.Data.SAUB
{
#nullable enable
/// <summary>
/// DTO телеметрии наработки талевого каната
/// </summary>
@ -32,5 +33,10 @@ namespace AsbCloudApp.Data.SAUB
/// </summary>
public float ReplaceWarnSp { get; set; }
/// <summary>
/// Информация по скважине
/// </summary>
public WellInfoDto WellInfo { get; set; } = null!;
}
#nullable disable
}

View File

@ -0,0 +1,41 @@
using AsbCloudApp.Data;
using AsbCloudApp.Data.SAUB;
using System.Collections.Generic;
using System.Threading;
using System.Threading.Tasks;
namespace AsbCloudApp.Repositories
{
#nullable enable
/// <summary>
/// Наработка талевого каната
/// </summary>
public interface ITelemetryWirelineRunOutRepository
{
/// <summary>
/// Принимает данные от панели
/// </summary>
/// <param name="uid"></param>
/// <param name="dto"></param>
/// <param name="token"></param>
/// <returns></returns>
Task<int> AddOrUpdateAsync(string uid, TelemetryWirelineRunOutDto dto, CancellationToken token);
/// <summary>
/// Выдает данные по скважине
/// </summary>
/// <param name="idWell"></param>
/// <param name="token"></param>
/// <returns></returns>
Task<TelemetryWirelineRunOutDto?> GetOrDefaultAsync(int idWell, CancellationToken token);
/// <summary>
/// Возвращает данные по всем скважинам
/// </summary>
/// <param name="idCompany"></param>
/// <param name="token"></param>
/// <returns></returns>
Task<IEnumerable<TelemetryWirelineRunOutDto>> GetAllAsync(int idCompany, CancellationToken token);
}
#nullable disable
}

View File

@ -0,0 +1,42 @@
using System.IO;
using System.Threading;
using System.Threading.Tasks;
namespace AsbCloudApp.Services
{
#nullable enable
/// <summary>
/// Сервис загрузки и обработки плановой траектории из файла
/// </summary>
public interface IPlannedTrajectoryImportService
{
/// <summary>
/// скачать шаблон для заполнения плановой траектории
/// </summary>
/// <returns></returns>
Stream GetTemplateFile();
/// <summary>
/// Получить имя файла (исходя из названия скважины)
/// </summary>
/// <returns></returns>
Task<string> GetFileNameAsync(int idWell, CancellationToken token);
/// <summary>
/// загрузить текущую плановую траекторию в .xlsx
/// </summary>
/// <param name="idWell"></param>
/// <param name="token"></param>
/// <returns></returns>
Task<Stream> ExportAsync(int idWell, CancellationToken token);
/// <summary>
/// импортировать из excel плановую траекторию
/// </summary>
/// <param name="idWell"></param>
/// <param name="idUser"></param>
/// <param name="stream"></param>
/// <param name="token"></param>
/// <param name="deleteBeforeImport">Очистить старые координаты перед импортом (если файл проходит валидацию)</param>
Task<int> ImportAsync(int idWell, int idUser, Stream stream, bool deleteBeforeImport, CancellationToken token);
}
#nullable disable
}

View File

@ -0,0 +1,65 @@
using AsbCloudApp.Data;
using System.Collections.Generic;
using System.Threading;
using System.Threading.Tasks;
namespace AsbCloudApp.Services
{
#nullable enable
/// <summary>
/// CRUD для работы с плановой траекторией из клиента
/// </summary>
/// <returns></returns>
public interface IPlannedTrajectoryService
{
/// <summary>
/// Получить все добавленные по скважине координаты плановой траектории
/// </summary>
/// <param name="idWell"></param>
/// <param name="token"></param>
/// <returns></returns>
Task<IEnumerable<PlannedTrajectoryDto>> GetAsync(int idWell, CancellationToken token);
/// <summary>
/// Добавить строки с координатами по одной скважине. Если в коллекции координаты для разных скважин получаем exception.
/// </summary>
/// <param name="plannedTrajectoryRows"></param>
/// <param name="token"></param>
/// <returns>количество записанных строк или exception с описанием</returns>
Task<int> AddRangeAsync(IEnumerable<PlannedTrajectoryDto> plannedTrajectoryRows, CancellationToken token);
/// <summary>
/// Добавить одну строку с координатами
/// </summary>
/// <param name="plannedTrajectoryRow"></param>
/// <param name="token"></param>
/// <returns></returns>
Task<int> AddAsync(PlannedTrajectoryDto plannedTrajectoryRow, CancellationToken token);
/// <summary>
/// Обновить строку с координатами
/// </summary>
/// <param name="row"></param>
/// <param name="token"></param>
/// <returns></returns>
Task<int> UpdateAsync(PlannedTrajectoryDto row,
CancellationToken token);
/// <summary>
/// Удалить строки с координатами
/// </summary>
/// <param name="ids"></param>
/// <param name="token"></param>
/// <returns></returns>
Task<int> DeleteRangeAsync(IEnumerable<int> ids, CancellationToken token);
/// <summary>
/// Удалить всю плановую траекторию по ИД скважины
/// </summary>
/// <param name="idWell"></param>
/// <param name="token"></param>
/// <returns></returns>
Task<int> DeleteByIdWellAsync(int idWell, CancellationToken token);
}
#nullable disable
}

File diff suppressed because it is too large Load Diff

View File

@ -0,0 +1,73 @@
using System;
using Microsoft.EntityFrameworkCore.Migrations;
using Npgsql.EntityFrameworkCore.PostgreSQL.Metadata;
#nullable disable
namespace AsbCloudDb.Migrations
{
public partial class AddTable_PlannedTrajectory : Migration
{
protected override void Up(MigrationBuilder migrationBuilder)
{
migrationBuilder.CreateTable(
name: "t_planned_trajectory",
columns: table => new
{
id = table.Column<int>(type: "integer", nullable: false)
.Annotation("Npgsql:ValueGenerationStrategy", NpgsqlValueGenerationStrategy.IdentityByDefaultColumn),
id_user = table.Column<int>(type: "integer", nullable: false, comment: "ID пользователя который внес/изменил запись"),
id_well = table.Column<int>(type: "integer", nullable: false, comment: "ID скважины"),
load_date = table.Column<DateTimeOffset>(type: "timestamp with time zone", nullable: false, comment: "Дата загрузки траектории"),
wellbore_depth = table.Column<double>(type: "double precision", nullable: false, comment: "Глубина по стволу"),
zenith_angle = table.Column<double>(type: "double precision", nullable: false, comment: "Угол зенитный"),
azimuth_geo = table.Column<double>(type: "double precision", nullable: false, comment: "Азимут Географ."),
azimuth_magnetic = table.Column<double>(type: "double precision", nullable: false, comment: "Азимут Магнитный"),
vertical_depth = table.Column<double>(type: "double precision", nullable: false, comment: "Глубина вертикальная"),
absolute_mark = table.Column<double>(type: "double precision", nullable: false, comment: "Абсолютная отметка"),
north_orifice = table.Column<double>(type: "double precision", nullable: false, comment: "Север отн-но устья"),
east_orifice = table.Column<double>(type: "double precision", nullable: false, comment: "Восток отн-но устья"),
east_cartographic = table.Column<double>(type: "double precision", nullable: false, comment: "Восток картографический"),
north_cartographic = table.Column<double>(type: "double precision", nullable: false, comment: "Север картографический"),
spatial_intensity = table.Column<double>(type: "double precision", nullable: false, comment: "Пространственная интенсивность"),
angle_intensity = table.Column<double>(type: "double precision", nullable: false, comment: "Интенсивность по углу"),
azimuth_intensity = table.Column<double>(type: "double precision", nullable: false, comment: "Интенсивность по азимуту"),
orifice_offset = table.Column<double>(type: "double precision", nullable: false, comment: "Смещение от устья"),
comment = table.Column<string>(type: "text", nullable: true, comment: "Комментарии")
},
constraints: table =>
{
table.PrimaryKey("PK_t_planned_trajectory", x => x.id);
table.ForeignKey(
name: "FK_t_planned_trajectory_t_user_id_user",
column: x => x.id_user,
principalTable: "t_user",
principalColumn: "id",
onDelete: ReferentialAction.Cascade);
table.ForeignKey(
name: "FK_t_planned_trajectory_t_well_id_well",
column: x => x.id_well,
principalTable: "t_well",
principalColumn: "id",
onDelete: ReferentialAction.Cascade);
},
comment: "Загрузка плановой траектории");
migrationBuilder.CreateIndex(
name: "IX_t_planned_trajectory_id_user",
table: "t_planned_trajectory",
column: "id_user");
migrationBuilder.CreateIndex(
name: "IX_t_planned_trajectory_id_well",
table: "t_planned_trajectory",
column: "id_well");
}
protected override void Down(MigrationBuilder migrationBuilder)
{
migrationBuilder.DropTable(
name: "t_planned_trajectory");
}
}
}

File diff suppressed because it is too large Load Diff

View File

@ -0,0 +1,25 @@
using Microsoft.EntityFrameworkCore.Migrations;
#nullable disable
namespace AsbCloudDb.Migrations
{
public partial class editTable_PlannedTrajectory : Migration
{
protected override void Up(MigrationBuilder migrationBuilder)
{
migrationBuilder.RenameColumn(
name: "load_date",
table: "t_planned_trajectory",
newName: "update_date");
}
protected override void Down(MigrationBuilder migrationBuilder)
{
migrationBuilder.RenameColumn(
name: "update_date",
table: "t_planned_trajectory",
newName: "load_date");
}
}
}

File diff suppressed because it is too large Load Diff

View File

@ -0,0 +1,40 @@
using System;
using Microsoft.EntityFrameworkCore.Migrations;
using Npgsql.EntityFrameworkCore.PostgreSQL.Metadata;
#nullable disable
namespace AsbCloudDb.Migrations
{
public partial class AddTable_t_telemetry_wireline_run_out : Migration
{
protected override void Up(MigrationBuilder migrationBuilder)
{
migrationBuilder.CreateTable(
name: "t_telemetry_wireline_run_out",
columns: table => new
{
id = table.Column<int>(type: "integer", nullable: false)
.Annotation("Npgsql:ValueGenerationStrategy", NpgsqlValueGenerationStrategy.IdentityByDefaultColumn),
id_well = table.Column<int>(type: "integer", nullable: false),
id_telemetry = table.Column<int>(type: "integer", nullable: false),
date_time = table.Column<DateTimeOffset>(type: "timestamp with time zone", nullable: false),
hauling = table.Column<float>(type: "real", nullable: false),
hauling_warn_sp = table.Column<float>(type: "real", nullable: false),
replace = table.Column<float>(type: "real", nullable: false),
replace_warn_sp = table.Column<float>(type: "real", nullable: false)
},
constraints: table =>
{
table.PrimaryKey("PK_t_telemetry_wireline_run_out", x => x.id);
},
comment: "Наработка талевого каната");
}
protected override void Down(MigrationBuilder migrationBuilder)
{
migrationBuilder.DropTable(
name: "t_telemetry_wireline_run_out");
}
}
}

File diff suppressed because it is too large Load Diff

View File

@ -0,0 +1,26 @@
using Microsoft.EntityFrameworkCore.Migrations;
#nullable disable
namespace AsbCloudDb.Migrations
{
public partial class UpdateTable_t_telemetry_wireline_run_out : Migration
{
protected override void Up(MigrationBuilder migrationBuilder)
{
migrationBuilder.DropColumn(
name: "id_well",
table: "t_telemetry_wireline_run_out");
}
protected override void Down(MigrationBuilder migrationBuilder)
{
migrationBuilder.AddColumn<int>(
name: "id_well",
table: "t_telemetry_wireline_run_out",
type: "integer",
nullable: false,
defaultValue: 0);
}
}
}

View File

@ -0,0 +1,157 @@
using System;
using Microsoft.EntityFrameworkCore.Migrations;
using Npgsql.EntityFrameworkCore.PostgreSQL.Metadata;
#nullable disable
namespace AsbCloudDb.Migrations
{
public partial class UpdateTable_t_telemetry_wireline_run_out_comment : Migration
{
protected override void Up(MigrationBuilder migrationBuilder)
{
migrationBuilder.DropPrimaryKey(
name: "PK_t_telemetry_wireline_run_out",
table: "t_telemetry_wireline_run_out");
migrationBuilder.DropColumn(
name: "id",
table: "t_telemetry_wireline_run_out");
migrationBuilder.AlterColumn<float>(
name: "replace_warn_sp",
table: "t_telemetry_wireline_run_out",
type: "real",
nullable: false,
comment: "Наработка талевого каната до сигнализации о необходимости замены, т*км",
oldClrType: typeof(float),
oldType: "real");
migrationBuilder.AlterColumn<float>(
name: "replace",
table: "t_telemetry_wireline_run_out",
type: "real",
nullable: false,
comment: "Наработка талевого каната с момента замены каната, т*км",
oldClrType: typeof(float),
oldType: "real");
migrationBuilder.AlterColumn<int>(
name: "id_telemetry",
table: "t_telemetry_wireline_run_out",
type: "integer",
nullable: false,
comment: "Идентификатор телеметрии",
oldClrType: typeof(int),
oldType: "integer")
.Annotation("Npgsql:ValueGenerationStrategy", NpgsqlValueGenerationStrategy.IdentityByDefaultColumn);
migrationBuilder.AlterColumn<float>(
name: "hauling_warn_sp",
table: "t_telemetry_wireline_run_out",
type: "real",
nullable: false,
comment: "Наработка талевого каната до сигнализации о необходимости перетяжки, т*км",
oldClrType: typeof(float),
oldType: "real");
migrationBuilder.AlterColumn<float>(
name: "hauling",
table: "t_telemetry_wireline_run_out",
type: "real",
nullable: false,
comment: "Наработка талевого каната с момента перетяжки каната, т*км",
oldClrType: typeof(float),
oldType: "real");
migrationBuilder.AlterColumn<DateTimeOffset>(
name: "date_time",
table: "t_telemetry_wireline_run_out",
type: "timestamp with time zone",
nullable: false,
comment: "Отметка времени",
oldClrType: typeof(DateTimeOffset),
oldType: "timestamp with time zone");
migrationBuilder.AddPrimaryKey(
name: "PK_t_telemetry_wireline_run_out",
table: "t_telemetry_wireline_run_out",
column: "id_telemetry");
}
protected override void Down(MigrationBuilder migrationBuilder)
{
migrationBuilder.DropPrimaryKey(
name: "PK_t_telemetry_wireline_run_out",
table: "t_telemetry_wireline_run_out");
migrationBuilder.AlterColumn<float>(
name: "replace_warn_sp",
table: "t_telemetry_wireline_run_out",
type: "real",
nullable: false,
oldClrType: typeof(float),
oldType: "real",
oldComment: "Наработка талевого каната до сигнализации о необходимости замены, т*км");
migrationBuilder.AlterColumn<float>(
name: "replace",
table: "t_telemetry_wireline_run_out",
type: "real",
nullable: false,
oldClrType: typeof(float),
oldType: "real",
oldComment: "Наработка талевого каната с момента замены каната, т*км");
migrationBuilder.AlterColumn<float>(
name: "hauling_warn_sp",
table: "t_telemetry_wireline_run_out",
type: "real",
nullable: false,
oldClrType: typeof(float),
oldType: "real",
oldComment: "Наработка талевого каната до сигнализации о необходимости перетяжки, т*км");
migrationBuilder.AlterColumn<float>(
name: "hauling",
table: "t_telemetry_wireline_run_out",
type: "real",
nullable: false,
oldClrType: typeof(float),
oldType: "real",
oldComment: "Наработка талевого каната с момента перетяжки каната, т*км");
migrationBuilder.AlterColumn<DateTimeOffset>(
name: "date_time",
table: "t_telemetry_wireline_run_out",
type: "timestamp with time zone",
nullable: false,
oldClrType: typeof(DateTimeOffset),
oldType: "timestamp with time zone",
oldComment: "Отметка времени");
migrationBuilder.AlterColumn<int>(
name: "id_telemetry",
table: "t_telemetry_wireline_run_out",
type: "integer",
nullable: false,
oldClrType: typeof(int),
oldType: "integer",
oldComment: "Идентификатор телеметрии")
.OldAnnotation("Npgsql:ValueGenerationStrategy", NpgsqlValueGenerationStrategy.IdentityByDefaultColumn);
migrationBuilder.AddColumn<int>(
name: "id",
table: "t_telemetry_wireline_run_out",
type: "integer",
nullable: false,
defaultValue: 0)
.Annotation("Npgsql:ValueGenerationStrategy", NpgsqlValueGenerationStrategy.IdentityByDefaultColumn);
migrationBuilder.AddPrimaryKey(
name: "PK_t_telemetry_wireline_run_out",
table: "t_telemetry_wireline_run_out",
column: "id");
}
}
}

View File

@ -1762,6 +1762,116 @@ namespace AsbCloudDb.Migrations
});
});
modelBuilder.Entity("AsbCloudDb.Model.PlannedTrajectory", b =>
{
b.Property<int>("Id")
.ValueGeneratedOnAdd()
.HasColumnType("integer")
.HasColumnName("id");
NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property<int>("Id"));
b.Property<double>("AbsoluteMark")
.HasColumnType("double precision")
.HasColumnName("absolute_mark")
.HasComment("Абсолютная отметка");
b.Property<double>("AngleIntensity")
.HasColumnType("double precision")
.HasColumnName("angle_intensity")
.HasComment("Интенсивность по углу");
b.Property<double>("AzimuthGeo")
.HasColumnType("double precision")
.HasColumnName("azimuth_geo")
.HasComment("Азимут Географ.");
b.Property<double>("AzimuthIntensity")
.HasColumnType("double precision")
.HasColumnName("azimuth_intensity")
.HasComment("Интенсивность по азимуту");
b.Property<double>("AzimuthMagnetic")
.HasColumnType("double precision")
.HasColumnName("azimuth_magnetic")
.HasComment("Азимут Магнитный");
b.Property<string>("Comment")
.HasColumnType("text")
.HasColumnName("comment")
.HasComment("Комментарии");
b.Property<double>("EastCartographic")
.HasColumnType("double precision")
.HasColumnName("east_cartographic")
.HasComment("Восток картографический");
b.Property<double>("EastOrifice")
.HasColumnType("double precision")
.HasColumnName("east_orifice")
.HasComment("Восток отн-но устья");
b.Property<int>("IdUser")
.HasColumnType("integer")
.HasColumnName("id_user")
.HasComment("ID пользователя который внес/изменил запись");
b.Property<int>("IdWell")
.HasColumnType("integer")
.HasColumnName("id_well")
.HasComment("ID скважины");
b.Property<double>("NorthCartographic")
.HasColumnType("double precision")
.HasColumnName("north_cartographic")
.HasComment("Север картографический");
b.Property<double>("NorthOrifice")
.HasColumnType("double precision")
.HasColumnName("north_orifice")
.HasComment("Север отн-но устья");
b.Property<double>("OrificeOffset")
.HasColumnType("double precision")
.HasColumnName("orifice_offset")
.HasComment("Смещение от устья");
b.Property<double>("SpatialIntensity")
.HasColumnType("double precision")
.HasColumnName("spatial_intensity")
.HasComment("Пространственная интенсивность");
b.Property<DateTimeOffset>("UpdateDate")
.HasColumnType("timestamp with time zone")
.HasColumnName("update_date")
.HasComment("Дата загрузки траектории");
b.Property<double>("VerticalDepth")
.HasColumnType("double precision")
.HasColumnName("vertical_depth")
.HasComment("Глубина вертикальная");
b.Property<double>("WellboreDepth")
.HasColumnType("double precision")
.HasColumnName("wellbore_depth")
.HasComment("Глубина по стволу");
b.Property<double>("ZenithAngle")
.HasColumnType("double precision")
.HasColumnName("zenith_angle")
.HasComment("Угол зенитный");
b.HasKey("Id");
b.HasIndex("IdUser");
b.HasIndex("IdWell");
b.ToTable("t_planned_trajectory");
b.HasComment("Загрузка плановой траектории");
});
modelBuilder.Entity("AsbCloudDb.Model.ProcessMap", b =>
{
b.Property<int>("Id")
@ -3550,6 +3660,48 @@ namespace AsbCloudDb.Migrations
b.HasComment("Пользователи панели САУБ. Для сообщений.");
});
modelBuilder.Entity("AsbCloudDb.Model.TelemetryWirelineRunOut", b =>
{
b.Property<int>("IdTelemetry")
.ValueGeneratedOnAdd()
.HasColumnType("integer")
.HasColumnName("id_telemetry")
.HasComment("Идентификатор телеметрии");
NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property<int>("IdTelemetry"));
b.Property<DateTime>("DateTime")
.HasColumnType("timestamp with time zone")
.HasColumnName("date_time")
.HasComment("Отметка времени");
b.Property<float>("Hauling")
.HasColumnType("real")
.HasColumnName("hauling")
.HasComment("Наработка талевого каната с момента перетяжки каната, т*км");
b.Property<float>("HaulingWarnSp")
.HasColumnType("real")
.HasColumnName("hauling_warn_sp")
.HasComment("Наработка талевого каната до сигнализации о необходимости перетяжки, т*км");
b.Property<float>("Replace")
.HasColumnType("real")
.HasColumnName("replace")
.HasComment("Наработка талевого каната с момента замены каната, т*км");
b.Property<float>("ReplaceWarnSp")
.HasColumnType("real")
.HasColumnName("replace_warn_sp")
.HasComment("Наработка талевого каната до сигнализации о необходимости замены, т*км");
b.HasKey("IdTelemetry");
b.ToTable("t_telemetry_wireline_run_out");
b.HasComment("Наработка талевого каната");
});
modelBuilder.Entity("AsbCloudDb.Model.User", b =>
{
b.Property<int>("Id")
@ -6144,6 +6296,25 @@ namespace AsbCloudDb.Migrations
b.Navigation("Well");
});
modelBuilder.Entity("AsbCloudDb.Model.PlannedTrajectory", b =>
{
b.HasOne("AsbCloudDb.Model.User", "User")
.WithMany()
.HasForeignKey("IdUser")
.OnDelete(DeleteBehavior.Cascade)
.IsRequired();
b.HasOne("AsbCloudDb.Model.Well", "Well")
.WithMany()
.HasForeignKey("IdWell")
.OnDelete(DeleteBehavior.Cascade)
.IsRequired();
b.Navigation("User");
b.Navigation("Well");
});
modelBuilder.Entity("AsbCloudDb.Model.ProcessMap", b =>
{
b.HasOne("AsbCloudDb.Model.Well", "Well")

View File

@ -13,6 +13,7 @@ namespace AsbCloudDb.Model
public virtual DbSet<DailyReport.DailyReport> DailyReports => Set <DailyReport.DailyReport >();
public virtual DbSet<Deposit> Deposits => Set<Deposit>();
public virtual DbSet<DetectedOperation> DetectedOperations => Set<DetectedOperation>();
public virtual DbSet<PlannedTrajectory> PlannedTrajectories => Set<PlannedTrajectory>();
public virtual DbSet<ProcessMap> ProcessMap => Set<ProcessMap>();
public virtual DbSet<DrillingProgramPart> DrillingProgramParts => Set<DrillingProgramPart>();
public virtual DbSet<FileCategory> FileCategories => Set<FileCategory>();
@ -52,6 +53,8 @@ namespace AsbCloudDb.Model
public virtual DbSet<WellFinalDocument> WellFinalDocuments => Set<WellFinalDocument>();
public virtual DbSet<LimitingParameter> LimitingParameter => Set<LimitingParameter>();
public virtual DbSet<TelemetryWirelineRunOut> TelemetryWirelineRunOut => Set<TelemetryWirelineRunOut>();
// WITS
public DbSet<WITS.Record1> Record1 => Set<WITS.Record1>();
public DbSet<WITS.Record7> Record7 => Set<WITS.Record7>();

View File

@ -15,6 +15,7 @@ namespace AsbCloudDb.Model
DbSet<DailyReport.DailyReport> DailyReports { get; }
DbSet<Deposit> Deposits { get; }
DbSet<DetectedOperation> DetectedOperations { get; }
DbSet<PlannedTrajectory> PlannedTrajectories { get; }
DbSet<ProcessMap> ProcessMap { get; }
DbSet<DrillingProgramPart> DrillingProgramParts { get; }
DbSet<FileCategory> FileCategories { get; }
@ -51,6 +52,7 @@ namespace AsbCloudDb.Model
DbSet<OperationValue> OperationValues { get; }
DbSet<WellFinalDocument> WellFinalDocuments { get; }
DbSet<LimitingParameter> LimitingParameter { get; }
DbSet<TelemetryWirelineRunOut> TelemetryWirelineRunOut { get; }
DbSet<Record1> Record1 { get; }
DbSet<Record7> Record7 { get; }

View File

@ -0,0 +1,76 @@
using Microsoft.EntityFrameworkCore;
using System;
using System.ComponentModel.DataAnnotations;
using System.ComponentModel.DataAnnotations.Schema;
namespace AsbCloudDb.Model
{
#nullable enable
[Table("t_planned_trajectory"), Comment("Загрузка плановой траектории")]
public class PlannedTrajectory : IId, IWellRelated
{
[Column("id"), Key]
public int Id { get; set; }
[Column("id_user"), Comment("ID пользователя который внес/изменил запись")]
public int IdUser { get; set; }
[Column("id_well"), Comment("ID скважины")]
public int IdWell { get; set; }
[Column("update_date"), Comment("Дата загрузки траектории")]
public DateTimeOffset UpdateDate { get; set; }
[Column("wellbore_depth"), Comment("Глубина по стволу")]
public double WellboreDepth { get; set; }
[Column("zenith_angle"), Comment("Угол зенитный")]
public double ZenithAngle { get; set; }
[Column("azimuth_geo"), Comment("Азимут Географ.")]
public double AzimuthGeo { get; set; }
[Column("azimuth_magnetic"), Comment("Азимут Магнитный")]
public double AzimuthMagnetic { get; set; }
[Column("vertical_depth"), Comment("Глубина вертикальная")]
public double VerticalDepth { get; set; }
[Column("absolute_mark"), Comment("Абсолютная отметка")]
public double AbsoluteMark { get; set; }
[Column("north_orifice"), Comment("Север отн-но устья")]
public double NorthOrifice { get; set; }
[Column("east_orifice"), Comment("Восток отн-но устья")]
public double EastOrifice { get; set; }
[Column("east_cartographic"), Comment("Восток картографический")]
public double EastCartographic { get; set; }
[Column("north_cartographic"), Comment("Север картографический")]
public double NorthCartographic { get; set; }
[Column("spatial_intensity"), Comment("Пространственная интенсивность")]
public double SpatialIntensity { get; set; }
[Column("angle_intensity"), Comment("Интенсивность по углу")]
public double AngleIntensity { get; set; }
[Column("azimuth_intensity"), Comment("Интенсивность по азимуту")]
public double AzimuthIntensity { get; set; }
[Column("orifice_offset"), Comment("Смещение от устья")]
public double OrificeOffset { get; set; }
[Column("comment"), Comment("Комментарии")]
public string? Comment { get; set; }
[ForeignKey(nameof(IdWell))]
public virtual Well Well { get; set; } = null!;
[ForeignKey(nameof(IdUser))]
public virtual User User { get; set; } = null!;
}
#nullable disable
}

View File

@ -0,0 +1,30 @@
using Microsoft.EntityFrameworkCore;
using System;
using System.ComponentModel.DataAnnotations;
using System.ComponentModel.DataAnnotations.Schema;
namespace AsbCloudDb.Model
{
[Table("t_telemetry_wireline_run_out"), Comment("Наработка талевого каната")]
public class TelemetryWirelineRunOut
{
[Key]
[Column("id_telemetry"), Comment("Идентификатор телеметрии")]
public int IdTelemetry { get; set; }
[Column("date_time"), Comment("Отметка времени")]
public DateTimeOffset DateTime { get; set; }
[Column("hauling"), Comment("Наработка талевого каната с момента перетяжки каната, т*км")]
public float Hauling { get; set; }
[Column("hauling_warn_sp"), Comment("Наработка талевого каната до сигнализации о необходимости перетяжки, т*км")]
public float HaulingWarnSp { get; set; }
[Column("replace"), Comment("Наработка талевого каната с момента замены каната, т*км")]
public float Replace { get; set; }
[Column("replace_warn_sp"), Comment("Наработка талевого каната до сигнализации о необходимости замены, т*км")]
public float ReplaceWarnSp { get; set; }
}
}

View File

@ -12,6 +12,7 @@
<None Remove="CommonLibs\logo_720x404.png" />
<None Remove="CommonLibs\Readme.md" />
<None Remove="Services\DailyReport\DailyReportTemplate.xlsx" />
<None Remove="Services\PlannedTrajectory\PlannedTrajectoryTemplate.xlsx" />
<None Remove="Services\ProcessMap\ProcessMapReportTemplate.xlsx" />
<None Remove="Services\WellOperationService\ScheduleReportTemplate.xlsx" />
<None Remove="Services\WellOperationService\WellOperationImportTemplate.xlsx" />
@ -29,6 +30,7 @@
<ItemGroup>
<EmbeddedResource Include="Services\DailyReport\DailyReportTemplate.xlsx" />
<EmbeddedResource Include="Services\PlannedTrajectory\PlannedTrajectoryTemplate.xlsx" />
<EmbeddedResource Include="Services\ProcessMap\ProcessMapReportTemplate.xlsx" />
<EmbeddedResource Include="Services\WellOperationService\ScheduleReportTemplate.xlsx" />
<EmbeddedResource Include="Services\WellOperationService\WellOperationImportTemplate.xlsx" />

View File

@ -4,6 +4,12 @@ namespace AsbCloudInfrastructure
{
public static class DateTimeExtentions
{
/// <summary>
/// Приветсти к UTC из времени куста
/// </summary>
/// <param name="date"></param>
/// <param name="remoteTimezoneOffsetHours"></param>
/// <returns></returns>
public static DateTimeOffset ToUtcDateTimeOffset(this DateTime date, double remoteTimezoneOffsetHours)
{
if (date == default)
@ -18,6 +24,12 @@ namespace AsbCloudInfrastructure
return new DateTimeOffset(dateUtc);
}
/// <summary>
/// Привести ко времени куста из utc
/// </summary>
/// <param name="date"></param>
/// <param name="remoteTimezoneOffsetHours"></param>
/// <returns></returns>
public static DateTime ToRemoteDateTime(this DateTimeOffset date, double remoteTimezoneOffsetHours)
{
if (date == default)

View File

@ -12,6 +12,7 @@ using AsbCloudInfrastructure.Services;
using AsbCloudInfrastructure.Services.DailyReport;
using AsbCloudInfrastructure.Services.DetectOperations;
using AsbCloudInfrastructure.Services.DrillingProgram;
using AsbCloudInfrastructure.Services.PlannedTrajectory;
using AsbCloudInfrastructure.Services.ProcessMap;
using AsbCloudInfrastructure.Services.SAUB;
using AsbCloudInfrastructure.Services.Subsystems;
@ -124,6 +125,8 @@ namespace AsbCloudInfrastructure
services.AddTransient<ITimezoneService, TimezoneService>();
services.AddTransient<IWellService, WellService>();
services.AddTransient<IWellOperationImportService, WellOperationImportService>();
services.AddTransient<IPlannedTrajectoryImportService, PlannedTrajectoryImportService>();
services.AddTransient<IPlannedTrajectoryService, PlannedTrajectoryService>();
services.AddTransient<IWellOperationRepository, WellOperationRepository>();
services.AddTransient<IScheduleReportService, ScheduleReportService>();
services.AddTransient<IDailyReportService, DailyReportService>();
@ -172,6 +175,8 @@ namespace AsbCloudInfrastructure
services.AddTransient<IUserRoleRepository, UserRoleRepository>();
services.AddTransient<IUserRepository, UserRepository>();
services.AddTransient<ILimitingParameterRepository, LimitingParameterRepository>();
services.AddTransient<ITelemetryWirelineRunOutRepository, TelemetryWirelineRunOutRepository>();
// Subsystem service
services.AddTransient<ICrudRepository<SubsystemDto>, CrudCacheRepositoryBase<SubsystemDto, Subsystem>>();
services.AddTransient<ISubsystemService, SubsystemService>();

View File

@ -0,0 +1,115 @@
using AsbCloudApp.Data;
using AsbCloudApp.Data.SAUB;
using AsbCloudApp.Repositories;
using AsbCloudApp.Services;
using AsbCloudDb;
using AsbCloudDb.Model;
using AsbCloudInfrastructure.Services.SAUB;
using Mapster;
using Microsoft.EntityFrameworkCore;
using System.Collections.Generic;
using System.Linq;
using System.Threading;
using System.Threading.Tasks;
namespace AsbCloudInfrastructure.Repository
{
#nullable enable
public class TelemetryWirelineRunOutRepository : ITelemetryWirelineRunOutRepository
{
private readonly IAsbCloudDbContext context;
private readonly ITelemetryService telemetryService;
private readonly IWellService wellService;
public TelemetryWirelineRunOutRepository(IAsbCloudDbContext context,
ITelemetryService telemetryService,
IWellService wellService)
{
this.context = context;
this.telemetryService = telemetryService;
this.wellService = wellService;
}
/// <inheritdoc/>
public async Task<int> AddOrUpdateAsync(string uid, TelemetryWirelineRunOutDto dto, CancellationToken token)
{
var idTelemetry = telemetryService.GetOrCreateTelemetryIdByUid(uid);
var timezoneOffset = telemetryService.GetTimezone(idTelemetry).Hours;
var entity = Convert(idTelemetry, dto, timezoneOffset);
var updatingItem = context.TelemetryWirelineRunOut
.Where(x => x.IdTelemetry == idTelemetry)
.FirstOrDefault();
if (updatingItem is null)
context.TelemetryWirelineRunOut.Add(entity);
else
context.TelemetryWirelineRunOut.Update(entity);
return await context.SaveChangesAsync(token);
}
/// <inheritdoc/>
public async Task<TelemetryWirelineRunOutDto?> GetOrDefaultAsync(int idWell, CancellationToken token)
{
var well = await wellService.GetOrDefaultAsync(idWell, token).ConfigureAwait(false);
if (well is null)
return null;
return await GetOrDefaultAsync(well, token);
}
private async Task<TelemetryWirelineRunOutDto?> GetOrDefaultAsync(WellDto well, CancellationToken token)
{
var idTelemetry = telemetryService.GetOrDefaultIdTelemetryByIdWell(well.Id);
if (idTelemetry is null)
return null;
var entity = await context.TelemetryWirelineRunOut
.Where(x => x.IdTelemetry == idTelemetry)
.AsNoTracking()
.FirstOrDefaultAsync(token)
.ConfigureAwait(false);
if (entity is null)
return null;
var timezoneHours = well.Timezone.Hours;
return Convert(entity, well, timezoneHours);
}
/// <inheritdoc/>
public async Task<IEnumerable<TelemetryWirelineRunOutDto>> GetAllAsync(int idCompany, CancellationToken token)
{
var wells = await wellService.GetWellsByCompanyAsync(idCompany, token)
.ConfigureAwait(false);
var result = new List<TelemetryWirelineRunOutDto>(wells.Count());
foreach (var well in wells)
{
var dto = await GetOrDefaultAsync(well, token);
if (dto is not null)
result.Add(dto);
}
return result;
}
private static TelemetryWirelineRunOut Convert(int idTelemetry, TelemetryWirelineRunOutDto dto, double timezoneOffset)
{
var entity = dto.Adapt<TelemetryWirelineRunOut>();
entity.IdTelemetry = idTelemetry;
entity.DateTime = dto.DateTime.ToUtcDateTimeOffset(timezoneOffset);
return entity;
}
private static TelemetryWirelineRunOutDto Convert(TelemetryWirelineRunOut entity, WellDto well, double timezoneOffset)
{
var dto = entity.Adapt<TelemetryWirelineRunOutDto>();
dto.DateTime = entity.DateTime.ToRemoteDateTime(timezoneOffset);
dto.WellInfo = well;
return dto;
}
}
#nullable disable
}

View File

@ -0,0 +1,237 @@
using AsbCloudApp.Data;
using AsbCloudApp.Services;
using ClosedXML.Excel;
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Threading;
using System.Threading.Tasks;
namespace AsbCloudInfrastructure.Services.PlannedTrajectory
{
#nullable enable
public class PlannedTrajectoryImportService : IPlannedTrajectoryImportService
{
/*
* password for PlannedTrajectoryTemplate.xlsx is Drill2022
*/
private readonly IWellService wellService;
private readonly IPlannedTrajectoryService plannedTrajectoryService;
private const string templateFileName = "PlannedTrajectoryTemplate.xlsx";
private const string usingTemplateFile = "AsbCloudInfrastructure.Services.PlannedTrajectory";
private const string sheetNamePlannedTrajectory = "Плановая траектория";
private const int headerRowsCount = 2;
private const int ColumnWellboreDepth = 1;
private const int ColumnZenithAngle = 2;
private const int ColumnAzimuthGeo = 3;
private const int ColumnAzimuthMagnetic = 4;
private const int ColumnVerticalDepth = 5;
private const int ColumnAbsoluteMark = 6;
private const int ColumnNorthOrifice = 7;
private const int ColumnEastOrifice = 8;
private const int ColumnEastCartographic = 9;
private const int ColumnNorthCartographic = 10;
private const int ColumnSpatialIntensity = 11;
private const int ColumnAngleIntensity = 12;
private const int ColumnAzimuthIntensity = 13;
private const int ColumnOrificeOffset = 14;
private const int ColumnComment = 15;
public PlannedTrajectoryImportService(IWellService wellService, IPlannedTrajectoryService plannedTrajectoryService)
{
this.wellService = wellService;
this.plannedTrajectoryService = plannedTrajectoryService;
}
public Stream GetTemplateFile()
{
var stream = System.Reflection.Assembly.GetExecutingAssembly()
.GetManifestResourceStream($"{usingTemplateFile}.{templateFileName}");
if (stream is null)
throw new Exception($"Область {usingTemplateFile} не содержит файла с названием {templateFileName}");
return stream;
}
public async Task<string> GetFileNameAsync (int idWell, CancellationToken token)
{
var fileName = await wellService.GetWellCaptionByIdAsync(idWell, token) + "_plannedTrajectory.xlsx";
return fileName;
}
public async Task<Stream> ExportAsync(int idWell, CancellationToken token)
{
var plannedTrajectorys = await plannedTrajectoryService.GetAsync(idWell, token);
return MakeExelFileStream(plannedTrajectorys);
}
private Stream MakeExelFileStream(IEnumerable<PlannedTrajectoryDto> plannedTrajectories)
{
using Stream ecxelTemplateStream = GetTemplateFile();
using var workbook = new XLWorkbook(ecxelTemplateStream, XLEventTracking.Disabled);
AddPlannedTrajecoryToWorkbook(workbook, plannedTrajectories);
MemoryStream memoryStream = new MemoryStream();
workbook.SaveAs(memoryStream, new SaveOptions { });
memoryStream.Seek(0, SeekOrigin.Begin);
return memoryStream;
}
private static void AddPlannedTrajecoryToWorkbook(XLWorkbook workbook, IEnumerable<PlannedTrajectoryDto> plannedTrajectories)
{
if (plannedTrajectories.Any())
{
var sheet = workbook.Worksheets.FirstOrDefault(ws => ws.Name == sheetNamePlannedTrajectory);
if (sheet is null)
throw new FileFormatException($"Лист с именем {sheetNamePlannedTrajectory} отсутствует, либо имеет некорректное название");
AddPlannedTrajecoryToSheet(sheet, plannedTrajectories);
}
}
private static void AddPlannedTrajecoryToSheet(IXLWorksheet sheet, IEnumerable<PlannedTrajectoryDto> plannedTrajectories)
{
var rowList = plannedTrajectories.ToList();
for (int i = 0; i < rowList.Count; i++)
{
var row = sheet.Row(1 + i + headerRowsCount);
AddCoordinatesToRow(row, rowList[i]);
}
}
private static void AddCoordinatesToRow(IXLRow row, PlannedTrajectoryDto trajectory)
{
row.Cell(ColumnWellboreDepth).Value = trajectory.WellboreDepth;
row.Cell(ColumnZenithAngle).Value = trajectory.ZenithAngle;
row.Cell(ColumnAzimuthGeo).Value = trajectory.AzimuthGeo;
row.Cell(ColumnAzimuthMagnetic).Value = trajectory.AzimuthMagnetic;
row.Cell(ColumnVerticalDepth).Value = trajectory.VerticalDepth;
row.Cell(ColumnAbsoluteMark).Value = trajectory.AbsoluteMark;
row.Cell(ColumnNorthOrifice).Value = trajectory.NorthOrifice;
row.Cell(ColumnEastOrifice).Value = trajectory.EastOrifice;
row.Cell(ColumnEastCartographic).Value = trajectory.EastCartographic;
row.Cell(ColumnNorthCartographic).Value = trajectory.NorthCartographic;
row.Cell(ColumnSpatialIntensity).Value = trajectory.SpatialIntensity;
row.Cell(ColumnAngleIntensity).Value = trajectory.AngleIntensity;
row.Cell(ColumnAzimuthIntensity).Value = trajectory.AzimuthIntensity;
row.Cell(ColumnOrificeOffset).Value = trajectory.OrificeOffset;
row.Cell(ColumnComment).Value = trajectory.Comment;
}
public async Task<int> ImportAsync(int idWell, int idUser, Stream stream, bool deletePrevRows, CancellationToken token)
{
using var workbook = new XLWorkbook(stream, XLEventTracking.Disabled);
var trajectoryRows = ParseFileStream(stream);
foreach (var row in trajectoryRows)
{
row.IdWell = idWell;
row.IdUser = idUser;
}
var rowsCount = await SavePlannedTrajectoryAsync(idWell,trajectoryRows, deletePrevRows, token);
return rowsCount;
}
private async Task<int> SavePlannedTrajectoryAsync(int idWell, IEnumerable<PlannedTrajectoryDto> newRows, bool deletePrevRow, CancellationToken token)
{
if (deletePrevRow)
await plannedTrajectoryService.DeleteByIdWellAsync(idWell, token);
var rowsCount = await plannedTrajectoryService.AddRangeAsync(newRows, token);
return rowsCount;
}
private IEnumerable<PlannedTrajectoryDto> ParseFileStream(Stream stream)
{
using var workbook = new XLWorkbook(stream, XLEventTracking.Disabled);
return ParseWorkbook(workbook);
}
private IEnumerable<PlannedTrajectoryDto> ParseWorkbook(IXLWorkbook workbook)
{
var sheetPlannedTrajectory = workbook.Worksheets.FirstOrDefault(ws => ws.Name == sheetNamePlannedTrajectory);
if (sheetPlannedTrajectory is null)
throw new FileFormatException($"Книга excel не содержит листа {sheetNamePlannedTrajectory}.");
var plannedTrajectoryRows = ParseSheet(sheetPlannedTrajectory);
return plannedTrajectoryRows;
}
private IEnumerable<PlannedTrajectoryDto> ParseSheet(IXLWorksheet sheet)
{
if (sheet.RangeUsed().RangeAddress.LastAddress.ColumnNumber < 15)
throw new FileFormatException($"Лист {sheet.Name} содержит меньшее количество столбцов.");
var count = sheet.RowsUsed().Count() - headerRowsCount;
if (count > 1024)
throw new FileFormatException($"Лист {sheet.Name} содержит слишком большое количество строк.");
if (count <= 0)
throw new FileFormatException($"Лист {sheet.Name} некорректного формата либо пустой");
var trajectoryRows = new List<PlannedTrajectoryDto>(count);
var parseErrors = new List<string>();
for (int i = 0; i < count; i++)
{
var row = sheet.Row(1 + i + headerRowsCount);
try
{
var trajectoryRow = ParseRow(row);
trajectoryRows.Add(trajectoryRow);
}
catch (FileFormatException ex)
{
parseErrors.Add(ex.Message);
}
};
return trajectoryRows;
}
private PlannedTrajectoryDto ParseRow(IXLRow row)
{
var _wellboreDepth = row.Cell(ColumnWellboreDepth).Value;
var _zenithAngle = row.Cell(ColumnZenithAngle).Value;
var _azimuthGeo = row.Cell(ColumnAzimuthGeo).Value;
var _azimuthMagnetic = row.Cell(ColumnAzimuthMagnetic).Value;
var _verticalDepth = row.Cell(ColumnVerticalDepth).Value;
var _absoluteMark = row.Cell(ColumnAbsoluteMark).Value;
var _northOrifice = row.Cell(ColumnNorthOrifice).Value;
var _eastOrifice = row.Cell(ColumnEastOrifice).Value;
var _eastCartographic = row.Cell(ColumnEastCartographic).Value;
var _northCartographic = row.Cell(ColumnNorthCartographic).Value;
var _spatialIntensity = row.Cell(ColumnSpatialIntensity).Value;
var _angleIntensity = row.Cell(ColumnAngleIntensity).Value;
var _azimuthIntensity = row.Cell(ColumnAzimuthIntensity).Value;
var _orificeOffset = row.Cell(ColumnOrificeOffset).Value;
var _comment = row.Cell(ColumnComment).Value;
var trajectoryRow = new PlannedTrajectoryDto();
static double getDoubleValue(object value, string nameParam, IXLRow row)
{
if (value is double _value)
return _value;
throw new FileFormatException($"Лист {row.Worksheet.Name}. Строка {row.RowNumber()} - некорректные данные - {nameParam}");
}
trajectoryRow.WellboreDepth = getDoubleValue(_wellboreDepth, "Глубина по стволу", row);
trajectoryRow.ZenithAngle = getDoubleValue(_zenithAngle, "Зенитный угол", row);
trajectoryRow.AzimuthGeo = getDoubleValue(_azimuthGeo, "Азимут географический", row);
trajectoryRow.AzimuthMagnetic = getDoubleValue(_azimuthMagnetic, "Азимут магнитный", row);
trajectoryRow.VerticalDepth = getDoubleValue(_verticalDepth, "Глубина вертикальная", row);
trajectoryRow.AbsoluteMark = getDoubleValue(_absoluteMark, "Абсолютная отметка", row);
trajectoryRow.NorthOrifice = getDoubleValue(_northOrifice, "Север относительно устья", row);
trajectoryRow.EastOrifice = getDoubleValue(_eastOrifice, "Восток относительно устья", row);
trajectoryRow.EastCartographic = getDoubleValue(_eastCartographic, "Восток картографический", row);
trajectoryRow.NorthCartographic = getDoubleValue(_northCartographic, "Север картографический", row);
trajectoryRow.SpatialIntensity = getDoubleValue(_spatialIntensity, "Простр. интенсивность", row);
trajectoryRow.AngleIntensity = getDoubleValue(_angleIntensity, "Интенсивность по углу", row);
trajectoryRow.AzimuthIntensity = getDoubleValue(_azimuthIntensity, "Интенсивность по азимуту", row);
trajectoryRow.OrificeOffset = getDoubleValue(_orificeOffset, "Смещение от устья", row);
if (_comment is not null)
trajectoryRow.Comment = _comment.ToString();
return trajectoryRow;
}
}
#nullable disable
}

View File

@ -0,0 +1,117 @@
using AsbCloudApp.Data;
using AsbCloudApp.Exceptions;
using AsbCloudApp.Services;
using AsbCloudDb.Model;
using Mapster;
using Microsoft.EntityFrameworkCore;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading;
using System.Threading.Tasks;
namespace AsbCloudInfrastructure.Services.PlannedTrajectory
{
#nullable enable
public class PlannedTrajectoryService : IPlannedTrajectoryService
{
private readonly IAsbCloudDbContext db;
private readonly IWellService wellService;
public PlannedTrajectoryService(IAsbCloudDbContext db, IWellService wellService)
{
this.db = db;
this.wellService = wellService;
}
/// <inheritdoc/>
public async Task<int> AddRangeAsync(IEnumerable<PlannedTrajectoryDto> plannedTrajectoryRows, CancellationToken token)
{
var idWell = plannedTrajectoryRows.First().IdWell;
if (!plannedTrajectoryRows.All(r => r.IdWell == idWell))
throw new ArgumentInvalidException("Все строки должны относиться к одной скважине", nameof(plannedTrajectoryRows));
var offsetHours = wellService.GetTimezone(idWell).Hours;
var entities = plannedTrajectoryRows
.Select(e => {
var entity = Convert(e, offsetHours);
entity.Id = 0;
return entity;});
db.PlannedTrajectories.AddRange(entities);
return await db.SaveChangesAsync(token)
.ConfigureAwait(false);
}
/// <inheritdoc/>
public async Task<int> AddAsync(PlannedTrajectoryDto plannedTrajectoryRow, CancellationToken token)
{
var offsetHours = wellService.GetTimezone(plannedTrajectoryRow.IdWell).Hours;
var entity = Convert(plannedTrajectoryRow, offsetHours);
entity.Id = 0;
db.PlannedTrajectories.Add(entity);
return await db.SaveChangesAsync(token)
.ConfigureAwait(false);
}
/// <inheritdoc/>
public async Task<int> DeleteRangeAsync(IEnumerable<int> ids, CancellationToken token)
{
var query = db.PlannedTrajectories
.Where(e => ids.Contains(e.Id));
db.PlannedTrajectories.RemoveRange(query);
return await db.SaveChangesAsync(token)
.ConfigureAwait(false);
}
/// <inheritdoc/>
public async Task<int> DeleteByIdWellAsync(int idWell, CancellationToken token)
{
var query = db.PlannedTrajectories
.Where(e => e.IdWell == idWell);
db.PlannedTrajectories.RemoveRange(query);
return await db.SaveChangesAsync(token)
.ConfigureAwait(false);
}
/// <inheritdoc/>
public async Task<IEnumerable<PlannedTrajectoryDto>> GetAsync(int idWell, CancellationToken token)
{
var well = wellService.GetOrDefault(idWell);
if (well is null || well.Timezone is null)
throw new ArgumentInvalidException("idWell doesn`t exist", nameof(idWell));
var offsetHours = well.Timezone.Hours;
var query = db.PlannedTrajectories
.AsNoTracking()
.Where(x => x.IdWell == idWell);
var entities = await query
.OrderBy(e => e.WellboreDepth)
.ToListAsync(token);
var result = entities
.Select(r => Convert(r, offsetHours));
return result;
}
/// <inheritdoc/>
public async Task<int> UpdateAsync(PlannedTrajectoryDto row, CancellationToken token)
{
var offsetHours = wellService.GetTimezone(row.IdWell).Hours;
var entity = Convert(row, offsetHours);
db.PlannedTrajectories.Update(entity);
return await db.SaveChangesAsync(token)
.ConfigureAwait(false);
}
private PlannedTrajectoryDto Convert(AsbCloudDb.Model.PlannedTrajectory entity, double offsetHours)
{
var dto = entity.Adapt<PlannedTrajectoryDto>();
dto.UpdateDate = entity.UpdateDate.ToRemoteDateTime(offsetHours);
return dto;
}
private AsbCloudDb.Model.PlannedTrajectory Convert(PlannedTrajectoryDto dto, double offsetHours)
{
var entity = dto.Adapt<AsbCloudDb.Model.PlannedTrajectory>();
entity.UpdateDate = DateTime.Now.ToUtcDateTimeOffset(offsetHours);
return entity;
}
}
#nullable disable
}

View File

@ -0,0 +1,236 @@
using AsbCloudApp.Data;
using AsbCloudApp.Services;
using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc;
using System.Collections.Generic;
using System.IO;
using System.Threading;
using System.Threading.Tasks;
namespace AsbCloudWebApi.Controllers
{
#nullable enable
/// <summary>
/// Плановая траектория (загрузка и хранение)
/// </summary>
[Route("api/well/{idWell}/plannedTrajectory")]
[ApiController]
[Authorize]
public class PlannedTrajectoryController : ControllerBase
{
private readonly IWellService wellService;
private readonly IPlannedTrajectoryImportService plannedTrajectoryImportService;
private readonly IPlannedTrajectoryService plannedTrajectoryService;
public PlannedTrajectoryController(IWellService wellService, IPlannedTrajectoryImportService plannedTrajectoryImportService, IPlannedTrajectoryService plannedTrajectoryService)
{
this.plannedTrajectoryImportService = plannedTrajectoryImportService;
this.wellService = wellService;
this.plannedTrajectoryService = plannedTrajectoryService;
}
/// <summary>
/// Возвращает шаблон для заполнения строк плановой траектории
/// </summary>
/// <returns>Запрашиваемый файл</returns>
[HttpGet]
[Route("template")]
[AllowAnonymous]
[ProducesResponseType(typeof(PhysicalFileResult), (int)System.Net.HttpStatusCode.OK)]
public IActionResult GetTemplate()
{
var stream = plannedTrajectoryImportService.GetTemplateFile();
var fileName = "ЕЦП_шаблон_файла_плановая_траектория.xlsx";
return File(stream, "application/octet-stream", fileName);
}
/// <summary>
/// Формируем excel файл с текущими строками плановой траектории
/// </summary>
/// <param name="idWell">id скважины</param>
/// <param name="token"> Токен отмены задачи </param>
/// <returns>Запрашиваемый файл</returns>
[HttpGet]
[Route("export")]
[Permission]
[ProducesResponseType(typeof(PhysicalFileResult), (int)System.Net.HttpStatusCode.OK)]
public async Task<IActionResult> ExportAsync([FromRoute] int idWell, CancellationToken token = default)
{
if (!await CanUserAccessToWellAsync(idWell,
token).ConfigureAwait(false))
return Forbid();
var stream = await plannedTrajectoryImportService.ExportAsync(idWell, token);
var fileName = await plannedTrajectoryImportService.GetFileNameAsync(idWell, token);
return File(stream, "application/octet-stream", fileName);
}
/// <summary>
/// Импортирует координаты из excel (xlsx) файла
/// </summary>
/// <param name="idWell">id скважины</param>
/// <param name="files">Коллекция из одного файла xlsx</param>
/// <param name="deleteBeforeImport">Удалить операции перед импортом, если фал валидный</param>
/// <param name="token"> Токен отмены задачи </param>
/// <returns>количество успешно записанных строк в БД</returns>
[HttpPost]
[Permission]
[Route("import/{deleteBeforeImport}")]
[ProducesResponseType(typeof(int), (int)System.Net.HttpStatusCode.OK)]
public async Task<IActionResult> ImportAsync(int idWell,
[FromForm] IFormFileCollection files,
bool deleteBeforeImport,
CancellationToken token)
{
int? idUser = User.GetUserId();
if (!idUser.HasValue)
return Forbid();
if (!await CanUserAccessToWellAsync(idWell,
token).ConfigureAwait(false))
return Forbid();
if (files.Count < 1)
return BadRequest("нет файла");
var file = files[0];
if (Path.GetExtension(file.FileName).ToLower() != ".xlsx")
return BadRequest("Требуется xlsx файл.");
using Stream stream = file.OpenReadStream();
try
{
var result = await plannedTrajectoryImportService.ImportAsync(idWell, idUser.Value, stream, deleteBeforeImport, token);
return Ok(result);
}
catch (FileFormatException ex)
{
return BadRequest(ex.Message);
}
}
/// <summary>
/// Получаем список всех строк координат плановой траектории (для клиента)
/// </summary>
/// <param name="idWell">id скважины</param>
/// <param name="token"> Токен отмены задачи </param>
/// <returns>Список добавленных координат плановой траектории</returns>
[HttpGet]
[Route("getRows")]
[Permission]
[ProducesResponseType(typeof(IEnumerable<PlannedTrajectoryDto>), (int)System.Net.HttpStatusCode.OK)]
public async Task<IActionResult> GetAsync([FromRoute] int idWell, CancellationToken token = default)
{
if (!await CanUserAccessToWellAsync(idWell,
token).ConfigureAwait(false))
return Forbid();
var result = await plannedTrajectoryService.GetAsync(idWell, token);
return Ok(result);
}
/// <summary>
/// Добавить одну новую строчку координат для плановой траектории
/// </summary>
/// <param name="idWell"></param>
/// <param name="row"></param>
/// <param name="token"></param>
/// <returns>количество успешно записанных строк в БД</returns>
[HttpPost]
[Route("addRow")]
[Permission]
[ProducesResponseType(typeof(int), (int)System.Net.HttpStatusCode.OK)]
public async Task<IActionResult> AddAsync(int idWell, [FromBody] PlannedTrajectoryDto row,
CancellationToken token = default)
{
if (!await CanUserAccessToWellAsync(idWell, token).ConfigureAwait(false))
return Forbid();
var idUser = User.GetUserId();
if (!idUser.HasValue)
return Forbid();
row.IdUser = idUser.Value;
row.IdWell = idWell;
var result = await plannedTrajectoryService.AddAsync(row, token);
return Ok(result);
}
/// <summary>
/// Добавить массив строчек координат для плановой траектории
/// </summary>
/// <param name="idWell"></param>
/// <param name="rows"></param>
/// <param name="token"></param>
/// <returns>количество успешно записанных строк в БД</returns>
[HttpPost]
[Route("addRangeRows")]
[Permission]
[ProducesResponseType(typeof(int), (int)System.Net.HttpStatusCode.OK)]
public async Task<IActionResult> AddRangeAsync(int idWell, [FromBody] IEnumerable<PlannedTrajectoryDto> rows,
CancellationToken token = default)
{
if (!await CanUserAccessToWellAsync(idWell, token).ConfigureAwait(false))
return Forbid();
int? idUser = User.GetUserId();
if (!idUser.HasValue)
return Forbid();
foreach (var item in rows)
{
item.IdUser = idUser.Value;
item.IdWell = idWell;
}
var result = await plannedTrajectoryService.AddRangeAsync(rows, token);
return Ok(result);
}
/// <summary>
/// Изменить выбранную строку с координатами
/// </summary>
/// <param name="idWell"></param>
/// <param name="idRow"></param>
/// <param name="row"></param>
/// <param name="token"></param>
/// <returns>количество успешно обновленных строк в БД</returns>
[HttpPut("{idRow}")]
[Permission]
[ProducesResponseType(typeof(int), (int)System.Net.HttpStatusCode.OK)]
public async Task<IActionResult> UpdateAsync(int idWell, int idRow,
[FromBody] PlannedTrajectoryDto row, CancellationToken token = default)
{
if (!await CanUserAccessToWellAsync(idWell, token).ConfigureAwait(false))
return Forbid();
int? idUser = User.GetUserId();
if (!idUser.HasValue)
return Forbid();
row.Id = idRow;
row.IdUser = idUser.Value;
row.IdWell = idWell;
var result = await plannedTrajectoryService.UpdateAsync(row, token);
return Ok(result);
}
/// <summary>
/// Удалить выбранную строку с координатами
/// </summary>
/// <param name="idWell"></param>
/// <param name="idRow"></param>
/// <param name="token"></param>
/// <returns>количество успешно удаленных строк из БД</returns>
[HttpDelete("{idRow}")]
[Permission]
[ProducesResponseType(typeof(int), (int)System.Net.HttpStatusCode.OK)]
public async Task<IActionResult> DeleteAsync(int idWell, int idRow, CancellationToken token = default)
{
if (!await CanUserAccessToWellAsync(idWell,
token).ConfigureAwait(false))
return Forbid();
var result = await plannedTrajectoryService.DeleteRangeAsync(new int[] { idRow }, token);
return Ok(result);
}
private async Task<bool> CanUserAccessToWellAsync(int idWell, CancellationToken token = default)
{
int? idCompany = User.GetCompanyId();
return idCompany is not null && await wellService.IsCompanyInvolvedInWellAsync((int)idCompany,
idWell, token).ConfigureAwait(false);
}
}
#nullable disable
}

View File

@ -1,107 +0,0 @@
using AsbCloudApp.Services;
using AsbCloudWebApi.SignalR;
using Microsoft.AspNetCore.Authorization;
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
{
[Route("api/[controller]")]
[ApiController]
public abstract class TelemetryInstantDataController<TDto> : ControllerBase
{
private readonly ITelemetryService telemetryService;
private readonly IWellService wellService;
private readonly IHubContext<TelemetryHub> telemetryHubContext;
private readonly InstantDataRepository repository;
protected abstract string SirnalRMethodGetDataName { get; }
public TelemetryInstantDataController(
ITelemetryService telemetryService,
IWellService wellService,
IHubContext<TelemetryHub> telemetryHubContext,
InstantDataRepository repository)
{
this.telemetryService = telemetryService;
this.wellService = wellService;
this.telemetryHubContext = telemetryHubContext;
this.repository = repository;
}
/// <summary>
/// Принимает данные от панели
/// </summary>
/// <param name="uid"></param>
/// <param name="dto"></param>
/// <returns></returns>
[HttpPost]
[Route("{uid}")]
[AllowAnonymous]
public virtual IActionResult PostData(
string uid,
[FromBody] TDto dto)
{
if (dto is null)
return BadRequest("Dto shouldn't be null");
var idTelemetry = telemetryService.GetOrCreateTelemetryIdByUid(uid);
var typedStore = repository.GetOrAdd(idTelemetry, (id) => new System.Collections.Concurrent.ConcurrentDictionary<Type, object>());
var typeDto = typeof(TDto);
typedStore.AddOrUpdate(typeDto, dto, (_, _) => dto);
var idWell = telemetryService.GetIdWellByTelemetryUid(uid);
if (idWell is not null)
_ = Task.Run(async () =>
{
var clients = telemetryHubContext.Clients.Group($"well_{idWell}");
await clients.SendAsync(SirnalRMethodGetDataName, dto);
}, CancellationToken.None);
return Ok();
}
/// <summary>
/// Выдает данные по скважине
/// </summary>
/// <param name="idWell"></param>
/// <param name="token"></param>
/// <returns></returns>
[HttpGet("{idWell}")]
//[Permission]
public virtual async Task<ActionResult<TDto>> GetDataAsync(
int idWell,
CancellationToken token = default)
{
int? idCompany = User.GetCompanyId();
if (idCompany is null)
return Forbid();
bool isCompanyOwnsWell = await wellService.IsCompanyInvolvedInWellAsync((int)idCompany,
idWell, token).ConfigureAwait(false);
if (!isCompanyOwnsWell)
return Forbid();
int? idTelemetry = telemetryService.GetOrDefaultIdTelemetryByIdWell(idWell);
if (idTelemetry is null)
return NoContent();
var typedStore = repository.GetValueOrDefault((int)idTelemetry, null);
if (typedStore is null)
return NoContent();
var typeDto = typeof(TDto);
var dto = typedStore.GetValueOrDefault(typeDto);
return Ok(dto);
}
}
}

View File

@ -4,26 +4,107 @@ using AsbCloudWebApi.SignalR;
using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Mvc;
using Microsoft.AspNetCore.SignalR;
using System.Collections.Generic;
using System.Threading.Tasks;
using System.Threading;
using AsbCloudApp.Repositories;
namespace AsbCloudWebApi.Controllers.SAUB
{
#nullable enable
/// <summary>
/// Наработка талевого каната
/// </summary>
[ApiController]
[Authorize]
[Route("api/[controller]")]
public class TelemetryWirelineRunOutController : TelemetryInstantDataController<TelemetryWirelineRunOutDto>
public class TelemetryWirelineRunOutController : ControllerBase
{
protected override string SirnalRMethodGetDataName => "ReceiveWirelineRunOut";
private readonly ITelemetryService telemetryService;
private readonly IWellService wellService;
private readonly IHubContext<TelemetryHub> telemetryHubContext;
private readonly ITelemetryWirelineRunOutRepository repository;
private string SirnalRMethodGetDataName => "ReceiveWirelineRunOut";
public TelemetryWirelineRunOutController(
ITelemetryService telemetryService,
IWellService wellService,
IHubContext<TelemetryHub> telemetryHubContext,
InstantDataRepository repository)
: base(telemetryService, wellService, telemetryHubContext, repository)
ITelemetryWirelineRunOutRepository repository)
{
this.telemetryService = telemetryService;
this.wellService = wellService;
this.telemetryHubContext = telemetryHubContext;
this.repository = repository;
}
/// <summary>
/// Принимает данные от панели
/// </summary>
/// <param name="uid"></param>
/// <param name="dto"></param>
/// <param name="token"></param>
/// <returns></returns>
[HttpPost]
[Route("{uid}")]
[AllowAnonymous]
public IActionResult PostData(string uid, [FromBody] TelemetryWirelineRunOutDto dto, CancellationToken token)
{
if (dto is null)
return BadRequest("Dto shouldn't be null");
var data = repository.AddOrUpdateAsync(uid, dto, token);
var idWell = telemetryService.GetIdWellByTelemetryUid(uid);
if (idWell is not null)
_ = Task.Run(async () =>
{
var clients = telemetryHubContext.Clients.Group($"well_{idWell}");
await clients.SendAsync(SirnalRMethodGetDataName, dto);
}, CancellationToken.None);
return Ok();
}
/// <summary>
/// Выдает данные по скважине
/// </summary>
/// <param name="idWell"></param>
/// <param name="token"></param>
/// <returns></returns>
[HttpGet("{idWell}")]
[Permission]
public async Task<ActionResult<TelemetryWirelineRunOutDto>> GetDataAsync(int idWell, CancellationToken token)
{
int? idCompany = User.GetCompanyId();
if (idCompany is null)
return Forbid();
bool isCompanyOwnsWell = await wellService.IsCompanyInvolvedInWellAsync((int)idCompany,
idWell, token).ConfigureAwait(false);
if (!isCompanyOwnsWell)
return Forbid();
var dto = await repository.GetOrDefaultAsync(idWell, token);
if (dto is null)
return NoContent();
return Ok(dto);
}
[HttpGet]
public async Task<ActionResult<IEnumerable<TelemetryWirelineRunOutDto>>> GetAllAsync(CancellationToken token)
{
int? idCompany = User.GetCompanyId();
if (idCompany is null)
return Forbid();
var dtos = await repository.GetAllAsync((int)idCompany, token);
return Ok(dtos);
}
}
#nullable disable
}