forked from ddrilling/AsbCloudServer
#7963103 Отображение общей наработки тальканата по всем объектам
This commit is contained in:
parent
8e896a887d
commit
193b9ff9f6
@ -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
|
||||
}
|
||||
|
@ -0,0 +1,32 @@
|
||||
using AsbCloudApp.Data;
|
||||
using AsbCloudApp.Data.SAUB;
|
||||
using System.Threading;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace AsbCloudApp.Repositories
|
||||
{
|
||||
#nullable enable
|
||||
/// <summary>
|
||||
/// Наработка талевого каната
|
||||
/// </summary>
|
||||
public interface ITelemetryWirelineRunOutRepository
|
||||
{
|
||||
/// <summary>
|
||||
/// Принимает данные от панели
|
||||
/// </summary>
|
||||
/// <param name="idTelemetry"></param>
|
||||
/// <param name="dto"></param>
|
||||
/// <returns></returns>
|
||||
int AddOrUpdate(int idTelemetry, TelemetryWirelineRunOutDto dto);
|
||||
|
||||
/// <summary>
|
||||
/// Выдает данные по скважине
|
||||
/// </summary>
|
||||
/// <param name="idTelemetry"></param>
|
||||
/// <param name="token"></param>
|
||||
/// <param name="wellInfo"></param>
|
||||
/// <returns></returns>
|
||||
Task<TelemetryWirelineRunOutDto?> GetValueOrDefaultAsync(int idTelemetry, WellInfoDto wellInfo, CancellationToken token);
|
||||
}
|
||||
#nullable disable
|
||||
}
|
6782
AsbCloudDb/Migrations/20230110035135_AddTable_t_telemetry_wireline_run_out.Designer.cs
generated
Normal file
6782
AsbCloudDb/Migrations/20230110035135_AddTable_t_telemetry_wireline_run_out.Designer.cs
generated
Normal file
File diff suppressed because it is too large
Load Diff
@ -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");
|
||||
}
|
||||
}
|
||||
}
|
6778
AsbCloudDb/Migrations/20230110043915_UpdateTable_t_telemetry_wireline_run_out.Designer.cs
generated
Normal file
6778
AsbCloudDb/Migrations/20230110043915_UpdateTable_t_telemetry_wireline_run_out.Designer.cs
generated
Normal file
File diff suppressed because it is too large
Load Diff
@ -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);
|
||||
}
|
||||
}
|
||||
}
|
@ -3550,6 +3550,46 @@ namespace AsbCloudDb.Migrations
|
||||
b.HasComment("Пользователи панели САУБ. Для сообщений.");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("AsbCloudDb.Model.TelemetryWirelineRunOut", b =>
|
||||
{
|
||||
b.Property<int>("Id")
|
||||
.ValueGeneratedOnAdd()
|
||||
.HasColumnType("integer")
|
||||
.HasColumnName("id");
|
||||
|
||||
NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property<int>("Id"));
|
||||
|
||||
b.Property<DateTimeOffset>("DateTime")
|
||||
.HasColumnType("timestamp with time zone")
|
||||
.HasColumnName("date_time");
|
||||
|
||||
b.Property<float>("Hauling")
|
||||
.HasColumnType("real")
|
||||
.HasColumnName("hauling");
|
||||
|
||||
b.Property<float>("HaulingWarnSp")
|
||||
.HasColumnType("real")
|
||||
.HasColumnName("hauling_warn_sp");
|
||||
|
||||
b.Property<int>("IdTelemetry")
|
||||
.HasColumnType("integer")
|
||||
.HasColumnName("id_telemetry");
|
||||
|
||||
b.Property<float>("Replace")
|
||||
.HasColumnType("real")
|
||||
.HasColumnName("replace");
|
||||
|
||||
b.Property<float>("ReplaceWarnSp")
|
||||
.HasColumnType("real")
|
||||
.HasColumnName("replace_warn_sp");
|
||||
|
||||
b.HasKey("Id");
|
||||
|
||||
b.ToTable("t_telemetry_wireline_run_out");
|
||||
|
||||
b.HasComment("Наработка талевого каната");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("AsbCloudDb.Model.User", b =>
|
||||
{
|
||||
b.Property<int>("Id")
|
||||
|
@ -52,6 +52,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>();
|
||||
|
@ -51,6 +51,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; }
|
||||
|
37
AsbCloudDb/Model/TelemetryWirelineRunOut.cs
Normal file
37
AsbCloudDb/Model/TelemetryWirelineRunOut.cs
Normal file
@ -0,0 +1,37 @@
|
||||
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_telemetry_wireline_run_out"), Comment("Наработка талевого каната")]
|
||||
public class TelemetryWirelineRunOut
|
||||
{
|
||||
[Key]
|
||||
[Column("id")]
|
||||
public int Id { get; set; }
|
||||
|
||||
[Column("id_telemetry")]
|
||||
public int IdTelemetry { get; set; }
|
||||
|
||||
[Column("date_time")]
|
||||
public DateTimeOffset DateTime { get; set; }
|
||||
|
||||
[Column("hauling")]
|
||||
public float Hauling { get; set; }
|
||||
|
||||
[Column("hauling_warn_sp")]
|
||||
public float HaulingWarnSp { get; set; }
|
||||
|
||||
[Column("replace")]
|
||||
public float Replace { get; set; }
|
||||
|
||||
[Column("replace_warn_sp")]
|
||||
public float ReplaceWarnSp { get; set; }
|
||||
}
|
||||
}
|
@ -169,6 +169,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>();
|
||||
|
@ -0,0 +1,61 @@
|
||||
using AsbCloudApp.Data;
|
||||
using AsbCloudApp.Data.SAUB;
|
||||
using AsbCloudApp.Repositories;
|
||||
using AsbCloudDb.Model;
|
||||
using Mapster;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using System.Linq;
|
||||
using System.Threading;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace AsbCloudInfrastructure.Repository
|
||||
{
|
||||
#nullable enable
|
||||
public class TelemetryWirelineRunOutRepository : ITelemetryWirelineRunOutRepository
|
||||
{
|
||||
private readonly IAsbCloudDbContext context;
|
||||
|
||||
public TelemetryWirelineRunOutRepository(IAsbCloudDbContext context)
|
||||
{
|
||||
this.context = context;
|
||||
}
|
||||
|
||||
public int AddOrUpdate(int idTelemetry, TelemetryWirelineRunOutDto dto)
|
||||
{
|
||||
context.TelemetryWirelineRunOut.RemoveRange(context.TelemetryWirelineRunOut
|
||||
.Where(x => x.IdTelemetry == idTelemetry));
|
||||
|
||||
var entity = Convert(idTelemetry, dto);
|
||||
context.TelemetryWirelineRunOut.Add(entity);
|
||||
|
||||
return context.SaveChanges();
|
||||
}
|
||||
|
||||
public async Task<TelemetryWirelineRunOutDto?> GetValueOrDefaultAsync(int idTelemetry, WellInfoDto wellInfo, CancellationToken token)
|
||||
{
|
||||
var entity = await context.TelemetryWirelineRunOut
|
||||
.Where(x => x.IdTelemetry == idTelemetry)
|
||||
.AsNoTracking()
|
||||
.FirstOrDefaultAsync(token)
|
||||
.ConfigureAwait(false);
|
||||
|
||||
if (entity is null)
|
||||
return null;
|
||||
return Convert(entity, wellInfo);
|
||||
}
|
||||
|
||||
private static TelemetryWirelineRunOut Convert(int idTelemetry, TelemetryWirelineRunOutDto dto)
|
||||
{
|
||||
var entity = dto.Adapt<TelemetryWirelineRunOut>();
|
||||
entity.IdTelemetry = idTelemetry;
|
||||
return entity;
|
||||
}
|
||||
private static TelemetryWirelineRunOutDto Convert(TelemetryWirelineRunOut entity, WellInfoDto wellInfo)
|
||||
{
|
||||
var dto = entity.Adapt<TelemetryWirelineRunOutDto>();
|
||||
dto.WellInfo = wellInfo;
|
||||
return dto;
|
||||
}
|
||||
}
|
||||
#nullable disable
|
||||
}
|
@ -1,9 +1,16 @@
|
||||
using AsbCloudApp.Data.SAUB;
|
||||
using AsbCloudApp.Services;
|
||||
using AsbCloudDb.Model;
|
||||
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 System;
|
||||
using AsbCloudApp.Repositories;
|
||||
using System.Linq;
|
||||
|
||||
namespace AsbCloudWebApi.Controllers.SAUB
|
||||
{
|
||||
@ -13,16 +20,121 @@ namespace AsbCloudWebApi.Controllers.SAUB
|
||||
[ApiController]
|
||||
[Authorize]
|
||||
[Route("api/[controller]")]
|
||||
public class TelemetryWirelineRunOutController : TelemetryInstantDataController<TelemetryWirelineRunOutDto>
|
||||
public class TelemetryWirelineRunOutController : ControllerBase //TelemetryInstantDataController<TelemetryWirelineRunOutDto>
|
||||
{
|
||||
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>
|
||||
/// <returns></returns>
|
||||
[HttpPost]
|
||||
[Route("{uid}")]
|
||||
[AllowAnonymous]
|
||||
public IActionResult PostData(string uid, [FromBody] TelemetryWirelineRunOutDto dto)
|
||||
{
|
||||
if (dto is null)
|
||||
return BadRequest("Dto shouldn't be null");
|
||||
|
||||
var idTelemetry = telemetryService.GetOrCreateTelemetryIdByUid(uid);
|
||||
|
||||
var data = repository.AddOrUpdate(idTelemetry, 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<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 well = await wellService.GetOrDefaultAsync(idWell, token).ConfigureAwait(false);
|
||||
if (well is null)
|
||||
return NoContent();
|
||||
|
||||
int? idTelemetry = telemetryService.GetOrDefaultIdTelemetryByIdWell(idWell);
|
||||
if (idTelemetry is null)
|
||||
return NoContent();
|
||||
|
||||
var dto = await repository.GetValueOrDefaultAsync((int)idTelemetry, well, token);
|
||||
|
||||
if (dto is null)
|
||||
return NoContent();
|
||||
return Ok(dto);
|
||||
}
|
||||
|
||||
[HttpGet]
|
||||
public virtual async Task<ActionResult<IEnumerable<TelemetryWirelineRunOutDto>>> GetAllAsync(CancellationToken token)
|
||||
{
|
||||
var result = new List<TelemetryWirelineRunOutDto>();
|
||||
int? idCompany = User.GetCompanyId();
|
||||
|
||||
var wells = await wellService.GetAllAsync(token)
|
||||
.ConfigureAwait(false);
|
||||
|
||||
if (idCompany is null)
|
||||
return Forbid();
|
||||
|
||||
foreach (var well in wells)
|
||||
{
|
||||
bool isCompanyOwnsWell = await wellService.IsCompanyInvolvedInWellAsync((int)idCompany,
|
||||
well.Id, token).ConfigureAwait(false);
|
||||
|
||||
if (!isCompanyOwnsWell)
|
||||
return Forbid();
|
||||
|
||||
int? idTelemetry = telemetryService.GetOrDefaultIdTelemetryByIdWell(well.Id);
|
||||
if (idTelemetry is null)
|
||||
return NoContent();
|
||||
|
||||
var dto = await repository.GetValueOrDefaultAsync((int)idTelemetry, well, token);
|
||||
if (dto is not null)
|
||||
result.Add(dto);
|
||||
}
|
||||
|
||||
return Ok(result);
|
||||
}
|
||||
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user