Merge branch 'operation_grouping' into dev

This commit is contained in:
ngfrolov 2022-06-10 10:42:37 +05:00
commit 12c97a4119
12 changed files with 6267 additions and 3 deletions

View File

@ -57,5 +57,15 @@ namespace AsbCloudApp.Data
/// Пользователь панели оператора
/// </summary>
public string TelemetryUserName { get; set; }
/// <summary>
/// Бурильщик
/// </summary>
public DrillerDto Driller { get; set; }
/// <summary>
/// Целевые/нормативные показатели
/// </summary>
public OperationValueDto OperationValue { get; set; }
}
}

View File

@ -0,0 +1,44 @@
namespace AsbCloudApp.Data
{
/// <summary>
/// Описание целевых/нормативных показателей операций
/// </summary>
public class OperationValueDto : IId
{
/// <summary>
/// Идентификатор в БД
/// </summary>
public int Id { get; set; }
/// <summary>
/// Идентификатор скважины
/// </summary>
public int IdWell { get; set; }
/// <summary>
/// Идентификатор категории операции
/// </summary>
public int IdOperationCategory { get; set; }
/// <summary>
/// Целевой показатель
/// </summary>
public double TargetValue { get; set; }
/// <summary>
/// Нормативный показатель
/// </summary>
public double StandardValue { get; set; }
/// <summary>
/// Стартовая глубина
/// </summary>
public double DepthStart { get; set; }
/// <summary>
/// Конечная глубина
/// </summary>
public double DepthEnd { get; set; }
}
}

View File

@ -0,0 +1,8 @@
using AsbCloudApp.Data;
namespace AsbCloudApp.Services
{
public interface IOperationValueService : ICrudService<OperationValueDto>
{
}
}

File diff suppressed because it is too large Load Diff

View File

@ -0,0 +1,60 @@
using Microsoft.EntityFrameworkCore.Migrations;
using Npgsql.EntityFrameworkCore.PostgreSQL.Metadata;
#nullable disable
namespace AsbCloudDb.Migrations
{
public partial class AddOperationValue : Migration
{
protected override void Up(MigrationBuilder migrationBuilder)
{
migrationBuilder.CreateTable(
name: "t_operationvalue",
columns: table => new
{
id = table.Column<int>(type: "integer", nullable: false, comment: "Идентификатор")
.Annotation("Npgsql:ValueGenerationStrategy", NpgsqlValueGenerationStrategy.IdentityByDefaultColumn),
id_well = table.Column<int>(type: "integer", nullable: false, comment: "Ид скважины"),
id_operation_category = table.Column<int>(type: "integer", nullable: false, comment: "Ид категории операции"),
target_value = table.Column<double>(type: "double precision", nullable: false, comment: "Целевой показатель"),
standard_value = table.Column<double>(type: "double precision", nullable: false, comment: "Нормативный показатель"),
depth_start = table.Column<double>(type: "double precision", nullable: false, comment: "Старотовая глубина"),
depth_end = table.Column<double>(type: "double precision", nullable: false, comment: "Конечная глубина")
},
constraints: table =>
{
table.PrimaryKey("PK_t_operationvalue", x => x.id);
table.ForeignKey(
name: "FK_t_operationvalue_t_well_id_well",
column: x => x.id_well,
principalTable: "t_well",
principalColumn: "id",
onDelete: ReferentialAction.Cascade);
table.ForeignKey(
name: "FK_t_operationvalue_t_well_operation_category_id_operation_cat~",
column: x => x.id_operation_category,
principalTable: "t_well_operation_category",
principalColumn: "id",
onDelete: ReferentialAction.Cascade);
},
comment: "Целевые/нормативные показатели операции");
migrationBuilder.CreateIndex(
name: "IX_t_operationvalue_id_operation_category",
table: "t_operationvalue",
column: "id_operation_category");
migrationBuilder.CreateIndex(
name: "IX_t_operationvalue_id_well",
table: "t_operationvalue",
column: "id_well");
}
protected override void Down(MigrationBuilder migrationBuilder)
{
migrationBuilder.DropTable(
name: "t_operationvalue");
}
}
}

View File

@ -46,6 +46,7 @@ namespace AsbCloudDb.Model
public virtual DbSet<WellType> WellTypes => Set<WellType>();
public virtual DbSet<Driller> Drillers => Set<Driller>();
public virtual DbSet<Schedule> Schedule => Set<Schedule>();
public virtual DbSet<OperationValue> OperationValues => Set<OperationValue>();
// WITS
public DbSet<WITS.Record1> Record1 => Set<WITS.Record1>();

View File

@ -45,6 +45,7 @@ namespace AsbCloudDb.Model
DbSet<WellType> WellTypes { get; }
DbSet<Driller> Drillers { get; }
DbSet<Schedule> Schedule { get; }
DbSet<OperationValue> OperationValues { get; }
DbSet<Record1> Record1 { get; }
DbSet<Record7> Record7 { get; }

View File

@ -0,0 +1,43 @@
using Microsoft.EntityFrameworkCore;
using System;
using System.Collections.Generic;
using System.ComponentModel.DataAnnotations;
using System.ComponentModel.DataAnnotations.Schema;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace AsbCloudDb.Model
{
[Table("t_operationvalue"), Comment("Целевые/нормативные показатели операции")]
public class OperationValue:IId
{
[Key]
[Column("id"), Comment("Идентификатор")]
public int Id { get; set; }
[Column("id_well"), Comment("Ид скважины")]
public int IdWell { get; set; }
[Column("id_operation_category"), Comment("Ид категории операции")]
public int IdOperationCategory { get; set; }
[Column("target_value"), Comment("Целевой показатель")]
public double TargetValue { get; set; }
[Column("standard_value"), Comment("Нормативный показатель")]
public double StandardValue { get; set; }
[Column("depth_start"), Comment("Старотовая глубина")]
public double DepthStart { get; set; }
[Column("depth_end"), Comment("Конечная глубина")]
public double DepthEnd { get; set; }
[ForeignKey(nameof(IdWell))]
public virtual Well Well { get; set; } = null!;
[ForeignKey(nameof(IdOperationCategory))]
public virtual WellOperationCategory OperationCategory { get; set; } = null!;
}
}

View File

@ -117,6 +117,7 @@ namespace AsbCloudInfrastructure
services.AddTransient<IDetectedOperationService, DetectedOperationService>();
services.AddTransient<IDrillerService, DrillerService>();
services.AddTransient<IScheduleService, ScheduleService>();
services.AddTransient<IOperationValueService, OperationValueService>();
// admin crud services:
services.AddTransient<ICrudService<TelemetryDto>, CrudServiceBase<TelemetryDto, Telemetry>>(s =>

View File

@ -17,11 +17,18 @@ namespace AsbCloudInfrastructure.Services.DetectOperations
{
private readonly IAsbCloudDbContext db;
private readonly IWellService wellService;
private readonly IOperationValueService operationValueService;
private readonly IScheduleService scheduleService;
public DetectedOperationService(IAsbCloudDbContext db, IWellService wellService)
private IEnumerable<OperationValueDto> operationValues;
public DetectedOperationService(IAsbCloudDbContext db, IWellService wellService,
IOperationValueService operationValueService, IScheduleService scheduleService)
{
this.db = db;
this.wellService = wellService;
this.operationValueService = operationValueService;
this.scheduleService = scheduleService;
}
public async Task<IEnumerable<DetectedOperationDto>> GetAsync(int idWell, DetectedOperationRequest request, CancellationToken token)
@ -34,7 +41,15 @@ namespace AsbCloudInfrastructure.Services.DetectOperations
.AsNoTracking();
var data = await query.ToListAsync(token);
var dtos = data.Select(o => Convert(o, well));
operationValues = await operationValueService.GetAllAsync(token);
operationValues = operationValues.Where(o => o.IdWell == idWell);
var dtos = data.Select(o => Convert(o, well, operationValues));
foreach (var item in dtos)
{
item.Driller = await scheduleService.GetDrillerAsync(idWell, item.DateStart);
}
return dtos;
}
@ -97,12 +112,14 @@ namespace AsbCloudInfrastructure.Services.DetectOperations
return query;
}
private static DetectedOperationDto Convert(DetectedOperation operation, WellDto well)
private static DetectedOperationDto Convert(DetectedOperation operation, WellDto well, IEnumerable<OperationValueDto> operationValues)
{
var dto = operation.Adapt<DetectedOperationDto>();
dto.IdWell = well.Id;
dto.DateStart = operation.DateStart.ToRemoteDateTime(well.Timezone.Hours);
dto.DateEnd = operation.DateEnd.ToRemoteDateTime(well.Timezone.Hours);
dto.OperationValue = operationValues.FirstOrDefault(e => e.IdOperationCategory == dto.IdCategory
&& e.DepthStart <= dto.DepthStart);
return dto;
}

View File

@ -0,0 +1,13 @@
using AsbCloudApp.Data;
using AsbCloudApp.Services;
using AsbCloudDb.Model;
namespace AsbCloudInfrastructure.Services
{
public class OperationValueService : CrudServiceBase<OperationValueDto, OperationValue>, IOperationValueService
{
public OperationValueService(IAsbCloudDbContext context) : base(context)
{
}
}
}

View File

@ -0,0 +1,17 @@
using AsbCloudApp.Data;
using AsbCloudApp.Services;
using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Mvc;
namespace AsbCloudWebApi.Controllers
{
[Route("api/operationvalue")]
[ApiController]
[Authorize]
public class OperationValueController : CrudController<OperationValueDto, IOperationValueService>
{
public OperationValueController(IOperationValueService service) : base(service)
{
}
}
}