Fix operations ids in services

This commit is contained in:
Фролов 2022-12-09 18:32:18 +05:00
parent af43cb7588
commit 39a2ddc3a5
10 changed files with 7020 additions and 75 deletions

File diff suppressed because it is too large Load Diff

View File

@ -0,0 +1,37 @@
using Microsoft.EntityFrameworkCore.Migrations;
#nullable disable
namespace AsbCloudDb.Migrations
{
public partial class Make_wellOperationCategory_name_notNull : Migration
{
protected override void Up(MigrationBuilder migrationBuilder)
{
migrationBuilder.AlterColumn<string>(
name: "name",
table: "t_well_operation_category",
type: "text",
nullable: false,
defaultValue: "",
comment: "Название категории операции",
oldClrType: typeof(string),
oldType: "text",
oldNullable: true,
oldComment: "Название категории операции");
}
protected override void Down(MigrationBuilder migrationBuilder)
{
migrationBuilder.AlterColumn<string>(
name: "name",
table: "t_well_operation_category",
type: "text",
nullable: true,
comment: "Название категории операции",
oldClrType: typeof(string),
oldType: "text",
oldComment: "Название категории операции");
}
}
}

View File

@ -4322,6 +4322,7 @@ namespace AsbCloudDb.Migrations
.HasComment("Единицы измерения ключевого показателя операции");
b.Property<string>("Name")
.IsRequired()
.HasColumnType("text")
.HasColumnName("name")
.HasComment("Название категории операции");

View File

@ -5,16 +5,16 @@
public override WellOperationCategory[] GetData() => new WellOperationCategory[]{
// Этап работ
new () {Id = 3000, Name = "БУРЕНИЕ", KeyValueName = "dT", KeyValueUnits = "м/ч" },
new () {Id = WellOperationCategory.IdDrilling, Name = "БУРЕНИЕ", KeyValueName = "dT", KeyValueUnits = "м/ч" },
new () {Id = 3001, Name = "СПО", KeyValueName = "dT", KeyValueUnits = "мин" },
new () {Id = 3002, Name = "КРЕПЛЕНИЕ", KeyValueName = "dT", KeyValueUnits = "мин" },
new () {Id = 3003, Name = "ГФР", KeyValueName = "dT", KeyValueUnits = "мин" },
new () {Id = 3004, Name = "Вспомогательные операции", KeyValueName = "dT", KeyValueUnits = "мин" },
new () {Id = 3005, Name = "Непроизводительное время (НПВ)", KeyValueName = "dT", KeyValueUnits = "мин" },
new () {Id = WellOperationCategory.IdNonProductiveTime, Name = "Непроизводительное время (НПВ)", KeyValueName = "dT", KeyValueUnits = "мин" },
// Виды работ
new () {Id = 4000, IdParent = 3000, Name = "КНБК", KeyValueName = "dT", KeyValueUnits = "мин" },
new () {Id = 4001, IdParent = 3000, Name = "Механическое. бурение", KeyValueName = "dT", KeyValueUnits = "м/ч" },
new () {Id = WellOperationCategory.IdMechanicalDrilling, IdParent = 3000, Name = "Механическое. бурение", KeyValueName = "dT", KeyValueUnits = "м/ч" },
new () {Id = 4002, IdParent = 3000, Name = "Статический замер", KeyValueName = "dT", KeyValueUnits = "мин" },
new () {Id = 4003, IdParent = 3000, Name = "Нормализация диаметра скважины", KeyValueName = "dT", KeyValueUnits = "мин" },
new () {Id = 4004, IdParent = 3000, Name = "Наращивание", KeyValueName = "dT", KeyValueUnits = "мин" },
@ -46,11 +46,11 @@
new () {Id = 5010, IdParent = 4004, Name = "Наращивание", KeyValueName = "dT", KeyValueUnits = "мин" },
new () {Id = WellOperationCategory.IdSlipsTime, IdParent = 4004, Name = "Удержание в клиньях", KeyValueName = "dT", KeyValueUnits = "мин" },
new () {Id = 5012, IdParent = 4005, Name = "Подъем инструмента", KeyValueName = "dT", KeyValueUnits = "мин" },
new () {Id = 5013, IdParent = 4005, Name = "Подъем КНБК", KeyValueName = "dT", KeyValueUnits = "мин" },
new () {Id = WellOperationCategory.IdBhaUp, IdParent = 4005, Name = "Подъем КНБК", KeyValueName = "dT", KeyValueUnits = "мин" },
new () {Id = 5014, IdParent = 4005, Name = "Спуск инструмента", KeyValueName = "dT", KeyValueUnits = "мин" },
new () {Id = 5015, IdParent = 4005, Name = "Спуск КНБК", KeyValueName = "dT", KeyValueUnits = "мин" },
new () {Id = WellOperationCategory.IdBhaDown, IdParent = 4005, Name = "Спуск КНБК", KeyValueName = "dT", KeyValueUnits = "мин" },
new () {Id = 5016, IdParent = 4006, Name = "Промывка при спуске ОК", KeyValueName = "dT", KeyValueUnits = "мин" },
new () {Id = 5017, IdParent = 4006, Name = "Спуск ОК", KeyValueName = "dT", KeyValueUnits = "мин" },
new () {Id = WellOperationCategory.IdCasingDown, IdParent = 4006, Name = "Спуск ОК", KeyValueName = "dT", KeyValueUnits = "мин" },
new () {Id = 5018, IdParent = 4007, Name = "ОЗЦ", KeyValueName = "dT", KeyValueUnits = "мин" },
new () {Id = 5019, IdParent = 4007, Name = "Цементирование", KeyValueName = "dT", KeyValueUnits = "мин" },
new () {Id = 5020, IdParent = 4008, Name = "Опрессовка БИ", KeyValueName = "dT", KeyValueUnits = "мин" },
@ -91,7 +91,7 @@
new () {Id = 5055, IdParent = 4013, Name = "Тех.отстой", KeyValueName = "dT", KeyValueUnits = "мин" },
new () {Id = 5056, IdParent = 4013, Name = "Учебная тревога \"Выброс\"", KeyValueName = "dT", KeyValueUnits = "мин" },
new () {Id = 5057, IdParent = 4013, Name = "Чистка ЦСГО/емкостного блока", KeyValueName = "dT", KeyValueUnits = "мин" },
new () {Id = 5058, IdParent = 4014, Name = "Ремонт бурового оборудования", KeyValueName = "dT", KeyValueUnits = "мин" },
new () {Id = WellOperationCategory.IdEquipmentRepair, IdParent = 4014, Name = "Ремонт бурового оборудования", KeyValueName = "dT", KeyValueUnits = "мин" },
new () {Id = 5059, IdParent = 4015, Name = "Ловильные работы", KeyValueName = "dT", KeyValueUnits = "мин" },
new () {Id = 5060, IdParent = 4015, Name = "Ожидание", KeyValueName = "dT", KeyValueUnits = "мин" },
new () {Id = 5061, IdParent = 4015, Name = "Определение места прихвата и ЛМ", KeyValueName = "dT", KeyValueUnits = "мин" },

View File

@ -2,58 +2,126 @@
using System.ComponentModel.DataAnnotations;
using System.ComponentModel.DataAnnotations.Schema;
using System.Text.Json.Serialization;
using System;
namespace AsbCloudDb.Model
{
#nullable disable
#nullable enable
[Table("t_well_operation_category"), Comment("Справочник операций на скважине")]
public class WellOperationCategory : IId
{
#region ids constants
#region constants category operations ids
/// <summary>
/// Проработка перед наращиванием
/// БУРЕНИЕ
/// </summary>
public const int IdDevelopment = 5007;
public const int IdDrilling = 3000;
/// <summary>
/// Промывка
/// Непроизводительное время (НПВ)
/// </summary>
public const int IdFlashing = 5036;
public const int IdNonProductiveTime = 3005;
/// <summary>
/// Промывка перед наращиванием
/// Механическое. бурение
/// </summary>
public const int IdFlashingBeforeConnection = 5005;
public const int IdMechanicalDrilling = 4001;
/// <summary>
/// Ротором (РУС)
/// Разборка КНБК
/// </summary>
public const int IdRotor = 5003;
/// <summary>
/// Направленно (СЛАЙД)
/// </summary>
public const int IdSlide = 5002;
/// <summary>
/// Удержание в клиньях
/// </summary>
public const int IdSlipsTime = 5011;
/// <summary>
/// Замер ЗТС (запись MWD)
/// </summary>
public const int IdStaticSurveying = 5004;
/// <summary>
/// Шаблонировка перед наращиванием
/// </summary>
public const int IdTemplating = 5009;
/// <summary>
/// Шаблонировка во время бурения
/// </summary>
public const int IdTemplatingWhileDrilling = 5008;
public const int IdBhaDisassembly = 5000;
/// <summary>
/// Сборка КНБК
/// </summary>
public const int IdBhaAssembly = 5001;
/// <summary>
/// Разборка КНБК
/// Направленно (СЛАЙД)
/// </summary>
public const int IdBhaDisassembly = 5000;
public const int IdSlide = 5002;
/// <summary>
/// Ротором (РУС)
/// </summary>
public const int IdRotor = 5003;
/// <summary>
/// Замер ЗТС (запись MWD)
/// </summary>
public const int IdStaticSurveying = 5004;
/// <summary>
/// Промывка перед наращиванием
/// </summary>
public const int IdFlashingBeforeConnection = 5005;
/// <summary>
/// Проработка перед наращиванием
/// </summary>
public const int IdDevelopment = 5007;
/// <summary>
/// Шаблонировка во время бурения
/// </summary>
public const int IdTemplatingWhileDrilling = 5008;
/// <summary>
/// Шаблонировка перед наращиванием
/// </summary>
public const int IdTemplating = 5009;
/// <summary>
/// Удержание в клиньях
/// </summary>
public const int IdSlipsTime = 5011;
/// <summary>
/// Подъем КНБК
/// </summary>
public const int IdBhaUp = 5013;
/// <summary>
/// Спуск КНБК
/// </summary>
public const int IdBhaDown = 5015;
/// <summary>
/// Спуск ОК
/// </summary>
public const int IdCasingDown = 5017;
/// <summary>
/// Промывка
/// </summary>
public const int IdFlashing = 5036;
/// <summary>
/// Ремонт бурового оборудования
/// </summary>
public const int IdEquipmentRepair = 5058;
/// <summary>
/// Список всех категорий НПВ
/// </summary>
public static readonly int[] NonProductiveTimeSubIds = {
IdEquipmentRepair,
5059,
5060,
5061,
5062,
5063,
5064,
5065,
5066,
5067,
5068,
5069,
5070,
5071,
5072,
5073,
5074,
5075,
5076,
5077,
5078,
5079,
4014,
4015,
4016,
4017,
IdNonProductiveTime,
};
public static readonly int[] MechanicalDrillingSubIds = { IdRotor, IdSlide, IdMechanicalDrilling, };
#endregion
[Key]
@ -61,19 +129,20 @@ namespace AsbCloudDb.Model
public int Id { get; set; }
[Column("name"), Comment("Название категории операции")]
public string Name { get; set; }
public string Name { get; set; } = null!;
[Column("id_parent"), Comment("id родительской категории")]
public int? IdParent { get; set; }
[Column("key_value_name"), Comment("Название ключевого показателя операции"), StringLength(32)]
public string KeyValueName { get; set; }
public string? KeyValueName { get; set; }
[Column("key_value_units"), Comment("Единицы измерения ключевого показателя операции"), StringLength(16)]
public string KeyValueUnits { get; set; }
public string? KeyValueUnits { get; set; }
[JsonIgnore]
[ForeignKey(nameof(IdParent))]
public virtual WellOperationCategory Parent { get; set; } = null!;
public virtual WellOperationCategory? Parent { get; set; } = null!;
}
#nullable disable
}

View File

@ -9,9 +9,6 @@ using AsbCloudApp.Services;
using AsbCloudDb.Model;
using System.Collections.Generic;
using AsbCloudApp.Data.DailyReport;
using AsbCloudApp.Requests;
using AsbCloudInfrastructure.Services.DetectOperations;
using AsbCloudApp.Data.DetectedOperation;
using AsbCloudApp.Exceptions;
namespace AsbCloudInfrastructure.Services.DailyReport
@ -21,14 +18,12 @@ namespace AsbCloudInfrastructure.Services.DailyReport
{
private readonly IAsbCloudDbContext db;
private readonly IWellService wellService;
private readonly IDetectedOperationService detectedOperationService;
private readonly DailyReportMakerExcel dailyReportMaker = new DailyReportMakerExcel();
public DailyReportService(IAsbCloudDbContext db, IWellService wellService, IDetectedOperationService detectedOperationService)
public DailyReportService(IAsbCloudDbContext db, IWellService wellService)
{
this.db = db;
this.wellService = wellService;
this.detectedOperationService = detectedOperationService;
}
public async Task<IEnumerable<DailyReportDto>> GetListAsync(int idWell, DateTime? begin, DateTime? end, CancellationToken token)

View File

@ -237,7 +237,7 @@ namespace AsbCloudInfrastructure.Services.WellOperationService
BhaUpSpeed = CalcBhaUpSpeed(races),
CasingDownSpeed = CalcCasingDownSpeed(operations),
NonProductiveHours = operations
.Where(o => o.IdCategory == WellOperationService.idOperationNonProductiveTime)
.Where(o => WellOperationCategory.NonProductiveTimeSubIds.Contains( o.IdCategory))
.Sum(o => o.DurationHours),
};
return section;
@ -245,7 +245,7 @@ namespace AsbCloudInfrastructure.Services.WellOperationService
private static double CalcROP(IEnumerable<WellOperation> operationsProps)
{
var drillingOperations = operationsProps.Where(o => o.IdCategory == WellOperationService.idOperationDrilling);
var drillingOperations = operationsProps.Where(o => WellOperationCategory.MechanicalDrillingSubIds.Contains(o.IdCategory));
var dDepth = 0d;
var dHours = 0d;
foreach (var operation in drillingOperations)
@ -259,7 +259,7 @@ namespace AsbCloudInfrastructure.Services.WellOperationService
private static double CalcCasingDownSpeed(IEnumerable<WellOperation> operationsProps)
{
var ops = operationsProps.Where(o => o.IdCategory == WellOperationService.idOperationCasingDown);
var ops = operationsProps.Where(o => o.IdCategory == WellOperationCategory.IdCasingDown);
var depth = 0d;
var dHours = 0d;
foreach (var operation in ops)
@ -278,7 +278,7 @@ namespace AsbCloudInfrastructure.Services.WellOperationService
.GetEnumerator();
while (iterator.MoveNext())
{
if (iterator.Current.IdCategory == WellOperationService.idOperationBhaAssembly)
if (iterator.Current.IdCategory == WellOperationCategory.IdBhaAssembly)
{
var race = new Race
{
@ -288,13 +288,13 @@ namespace AsbCloudInfrastructure.Services.WellOperationService
};
while (iterator.MoveNext())
{
if (iterator.Current.IdCategory == WellOperationService.idOperationTypeRepair)
if (iterator.Current.IdCategory == WellOperationCategory.IdEquipmentRepair)
race.RepairHours += iterator.Current.DurationHours;
if (iterator.Current.IdCategory == WellOperationService.idOperationNonProductiveTime)
if (WellOperationCategory.NonProductiveTimeSubIds.Contains(iterator.Current.IdCategory))
race.NonProductiveHours += iterator.Current.DurationHours;
if (iterator.Current.IdCategory == WellOperationService.idOperationBhaDisassembly)
if (iterator.Current.IdCategory == WellOperationCategory.IdBhaDisassembly)
{
race.EndDate = iterator.Current.DateStart.ToRemoteDateTime(timezoneOffsetH);
race.EndWellDepth = iterator.Current.DepthStart;
@ -329,9 +329,9 @@ namespace AsbCloudInfrastructure.Services.WellOperationService
dDepth += race.StartWellDepth;
for (var i = 0; i < race.Operations.Count; i++)
{
if (race.Operations[i].IdCategory == WellOperationService.idOperationBhaDown)
if (race.Operations[i].IdCategory == WellOperationCategory.IdBhaDown)
dHours += race.Operations[i].DurationHours;
if (race.Operations[i].IdCategory == WellOperationService.idOperationDrilling)
if (WellOperationCategory.MechanicalDrillingSubIds.Contains( race.Operations[i].IdCategory))
break;
}
}
@ -347,9 +347,9 @@ namespace AsbCloudInfrastructure.Services.WellOperationService
dDepth += race.EndWellDepth;
for (var i = race.Operations.Count - 1; i > 0; i--)
{
if (race.Operations[i].IdCategory == WellOperationService.idOperationBhaUp)
if (race.Operations[i].IdCategory == WellOperationCategory.IdBhaUp)
dHours += race.Operations[i].DurationHours;
if (race.Operations[i].IdCategory == WellOperationService.idOperationDrilling)
if (WellOperationCategory.MechanicalDrillingSubIds.Contains(race.Operations[i].IdCategory))
break;
}
}
@ -400,7 +400,7 @@ namespace AsbCloudInfrastructure.Services.WellOperationService
var plan = item.Item1;
var fact = item.Item2;
if (fact?.IdCategory == WellOperationService.idOperationNonProductiveTime)
if (fact is not null && WellOperationCategory.NonProductiveTimeSubIds.Contains(fact.IdCategory))
{
nptHours += fact.DurationHours;
}

View File

@ -1,5 +1,6 @@
using AsbCloudApp.Data;
using AsbCloudApp.Services;
using AsbCloudDb.Model;
using ClosedXML.Excel;
using System;
using System.Collections.Generic;
@ -141,7 +142,7 @@ namespace AsbCloudInfrastructure.Services.WellOperationService
SetCell(row, columnDateEndFact, tvdItem.Fact?.DateStart.AddHours(tvdItem.Fact?.DurationHours ?? 0));
SetCell(row, columnDateEndPredict, tvdItem.Predict?.DateStart.AddHours(tvdItem.Predict?.DurationHours ?? 0));
if (tvdItem.Fact?.IdCategory == WellOperationService.idOperationNonProductiveTime)
if (tvdItem.Fact is not null && WellOperationCategory.NonProductiveTimeSubIds.Contains(tvdItem.Fact.IdCategory))
{
SetCell(row, columnGuilty, tvdItem.Fact.Comment);
SetCell(row, columnNpt, tvdItem.Fact.DurationHours);

View File

@ -21,16 +21,8 @@ namespace AsbCloudInfrastructure.Services.WellOperationService
private Dictionary<int, DateTimeOffset?>? firstOperationsCache = null;
public const int idOperationBhaAssembly = 1025;
public const int idOperationBhaDisassembly = 1026;
public const int idOperationNonProductiveTime = 1043;
public const int idOperationDrilling = 1001;
public const int idOperationBhaDown = 1046;
public const int idOperationBhaUp = 1047;
public const int idOperationCasingDown = 1048;
public const int idOperationTypePlan = 0;
public const int idOperationTypeFact = 1;
public const int idOperationTypeRepair = 1031;
public WellOperationService(IAsbCloudDbContext db, IMemoryCache memoryCache, IWellService wellService)
{
@ -46,10 +38,18 @@ namespace AsbCloudInfrastructure.Services.WellOperationService
public IEnumerable<WellOperationCategoryDto> GetCategories()
{
var operationCategories = memoryCache
.GetOrCreateBasic<WellOperationCategory>(db)
.Distinct()
.OrderBy(o => o.Name);
var allCategories = memoryCache
.GetOrCreateBasic<WellOperationCategory>(db);
var parentIds = allCategories
.Select(o => o.IdParent)
.Distinct();
var operationCategories = allCategories
.Where(o => !parentIds.Contains(o.Id))
.OrderBy(o => o.IdParent)
.ThenBy(o => o.Name);
var result = operationCategories.Adapt<IEnumerable<WellOperationCategoryDto>>();
return result;
}
@ -129,7 +129,7 @@ namespace AsbCloudInfrastructure.Services.WellOperationService
dto.CategoryName = entity.OperationCategory.Name;
if (entity.IdType == idOperationTypeFact)
{
if (entity.IdCategory == idOperationNonProductiveTime)
if (WellOperationCategory.NonProductiveTimeSubIds.Contains(entity.IdCategory))
nptHours += entity.DurationHours;
dto.NptHours = nptHours;
}