forked from ddrilling/AsbCloudServer
#7963103 Замечания
This commit is contained in:
parent
193b9ff9f6
commit
60a80745a9
@ -11,7 +11,7 @@ namespace AsbCloudApp.Data.SAUB
|
||||
/// <summary>
|
||||
/// отметка времени
|
||||
/// </summary>
|
||||
public DateTime DateTime { get; set; }
|
||||
public DateTimeOffset DateTime { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Наработка талевого каната с момента перетяжки каната, т*км
|
||||
|
@ -1,5 +1,6 @@
|
||||
using AsbCloudApp.Data;
|
||||
using AsbCloudApp.Data.SAUB;
|
||||
using System.Collections.Generic;
|
||||
using System.Threading;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
@ -14,19 +15,28 @@ namespace AsbCloudApp.Repositories
|
||||
/// <summary>
|
||||
/// Принимает данные от панели
|
||||
/// </summary>
|
||||
/// <param name="idTelemetry"></param>
|
||||
/// <param name="uid"></param>
|
||||
/// <param name="dto"></param>
|
||||
/// <param name="token"></param>
|
||||
/// <returns></returns>
|
||||
int AddOrUpdate(int idTelemetry, TelemetryWirelineRunOutDto dto);
|
||||
Task<int> AddOrUpdateAsync(string uid, TelemetryWirelineRunOutDto dto, CancellationToken token);
|
||||
|
||||
/// <summary>
|
||||
/// Выдает данные по скважине
|
||||
/// </summary>
|
||||
/// <param name="idTelemetry"></param>
|
||||
/// <param name="idWell"></param>
|
||||
/// <param name="token"></param>
|
||||
/// <param name="wellInfo"></param>
|
||||
/// <returns></returns>
|
||||
Task<TelemetryWirelineRunOutDto?> GetValueOrDefaultAsync(int idTelemetry, WellInfoDto wellInfo, CancellationToken token);
|
||||
Task<TelemetryWirelineRunOutDto?> GetValueOrDefaultAsync(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
|
||||
}
|
||||
|
6780
AsbCloudDb/Migrations/20230111043034_UpdateTable_t_telemetry_wireline_run_out_comment.Designer.cs
generated
Normal file
6780
AsbCloudDb/Migrations/20230111043034_UpdateTable_t_telemetry_wireline_run_out_comment.Designer.cs
generated
Normal file
File diff suppressed because it is too large
Load Diff
@ -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");
|
||||
}
|
||||
}
|
||||
}
|
@ -3552,38 +3552,40 @@ namespace AsbCloudDb.Migrations
|
||||
|
||||
modelBuilder.Entity("AsbCloudDb.Model.TelemetryWirelineRunOut", b =>
|
||||
{
|
||||
b.Property<int>("Id")
|
||||
b.Property<int>("IdTelemetry")
|
||||
.ValueGeneratedOnAdd()
|
||||
.HasColumnType("integer")
|
||||
.HasColumnName("id");
|
||||
.HasColumnName("id_telemetry")
|
||||
.HasComment("Идентификатор телеметрии");
|
||||
|
||||
NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property<int>("Id"));
|
||||
NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property<int>("IdTelemetry"));
|
||||
|
||||
b.Property<DateTimeOffset>("DateTime")
|
||||
b.Property<DateTime>("DateTime")
|
||||
.HasColumnType("timestamp with time zone")
|
||||
.HasColumnName("date_time");
|
||||
.HasColumnName("date_time")
|
||||
.HasComment("Отметка времени");
|
||||
|
||||
b.Property<float>("Hauling")
|
||||
.HasColumnType("real")
|
||||
.HasColumnName("hauling");
|
||||
.HasColumnName("hauling")
|
||||
.HasComment("Наработка талевого каната с момента перетяжки каната, т*км");
|
||||
|
||||
b.Property<float>("HaulingWarnSp")
|
||||
.HasColumnType("real")
|
||||
.HasColumnName("hauling_warn_sp");
|
||||
|
||||
b.Property<int>("IdTelemetry")
|
||||
.HasColumnType("integer")
|
||||
.HasColumnName("id_telemetry");
|
||||
.HasColumnName("hauling_warn_sp")
|
||||
.HasComment("Наработка талевого каната до сигнализации о необходимости перетяжки, т*км");
|
||||
|
||||
b.Property<float>("Replace")
|
||||
.HasColumnType("real")
|
||||
.HasColumnName("replace");
|
||||
.HasColumnName("replace")
|
||||
.HasComment("Наработка талевого каната с момента замены каната, т*км");
|
||||
|
||||
b.Property<float>("ReplaceWarnSp")
|
||||
.HasColumnType("real")
|
||||
.HasColumnName("replace_warn_sp");
|
||||
.HasColumnName("replace_warn_sp")
|
||||
.HasComment("Наработка талевого каната до сигнализации о необходимости замены, т*км");
|
||||
|
||||
b.HasKey("Id");
|
||||
b.HasKey("IdTelemetry");
|
||||
|
||||
b.ToTable("t_telemetry_wireline_run_out");
|
||||
|
||||
|
@ -1,11 +1,7 @@
|
||||
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
|
||||
{
|
||||
@ -13,25 +9,22 @@ namespace AsbCloudDb.Model
|
||||
public class TelemetryWirelineRunOut
|
||||
{
|
||||
[Key]
|
||||
[Column("id")]
|
||||
public int Id { get; set; }
|
||||
|
||||
[Column("id_telemetry")]
|
||||
[Column("id_telemetry"), Comment("Идентификатор телеметрии")]
|
||||
public int IdTelemetry { get; set; }
|
||||
|
||||
[Column("date_time")]
|
||||
public DateTimeOffset DateTime { get; set; }
|
||||
[Column("date_time"), Comment("Отметка времени")]
|
||||
public DateTime DateTime { get; set; }
|
||||
|
||||
[Column("hauling")]
|
||||
[Column("hauling"), Comment("Наработка талевого каната с момента перетяжки каната, т*км")]
|
||||
public float Hauling { get; set; }
|
||||
|
||||
[Column("hauling_warn_sp")]
|
||||
[Column("hauling_warn_sp"), Comment("Наработка талевого каната до сигнализации о необходимости перетяжки, т*км")]
|
||||
public float HaulingWarnSp { get; set; }
|
||||
|
||||
[Column("replace")]
|
||||
[Column("replace"), Comment("Наработка талевого каната с момента замены каната, т*км")]
|
||||
public float Replace { get; set; }
|
||||
|
||||
[Column("replace_warn_sp")]
|
||||
[Column("replace_warn_sp"), Comment("Наработка талевого каната до сигнализации о необходимости замены, т*км")]
|
||||
public float ReplaceWarnSp { get; set; }
|
||||
}
|
||||
}
|
||||
|
@ -1,9 +1,13 @@
|
||||
using AsbCloudApp.Data;
|
||||
using AsbCloudApp.Data.SAUB;
|
||||
using AsbCloudApp.Repositories;
|
||||
using AsbCloudApp.Services;
|
||||
using AsbCloudDb;
|
||||
using AsbCloudDb.Model;
|
||||
using DocumentFormat.OpenXml.Spreadsheet;
|
||||
using Mapster;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Threading;
|
||||
using System.Threading.Tasks;
|
||||
@ -14,25 +18,48 @@ namespace AsbCloudInfrastructure.Repository
|
||||
public class TelemetryWirelineRunOutRepository : ITelemetryWirelineRunOutRepository
|
||||
{
|
||||
private readonly IAsbCloudDbContext context;
|
||||
private readonly ITelemetryService telemetryService;
|
||||
private readonly IWellService wellService;
|
||||
|
||||
public TelemetryWirelineRunOutRepository(IAsbCloudDbContext context)
|
||||
public TelemetryWirelineRunOutRepository(IAsbCloudDbContext context,
|
||||
ITelemetryService telemetryService,
|
||||
IWellService wellService)
|
||||
{
|
||||
this.context = context;
|
||||
this.telemetryService = telemetryService;
|
||||
this.wellService = wellService;
|
||||
}
|
||||
|
||||
public int AddOrUpdate(int idTelemetry, TelemetryWirelineRunOutDto dto)
|
||||
/// <inheritdoc/>
|
||||
public async Task<int> AddOrUpdateAsync(string uid, TelemetryWirelineRunOutDto dto, CancellationToken token)
|
||||
{
|
||||
context.TelemetryWirelineRunOut.RemoveRange(context.TelemetryWirelineRunOut
|
||||
.Where(x => x.IdTelemetry == idTelemetry));
|
||||
|
||||
var idTelemetry = telemetryService.GetOrCreateTelemetryIdByUid(uid);
|
||||
var entity = Convert(idTelemetry, dto);
|
||||
context.TelemetryWirelineRunOut.Add(entity);
|
||||
|
||||
return context.SaveChanges();
|
||||
var updatingItem = context.TelemetryWirelineRunOut
|
||||
.Where(x => x.IdTelemetry == idTelemetry)
|
||||
.AsNoTracking()
|
||||
.FirstOrDefault();
|
||||
|
||||
if (updatingItem is null)
|
||||
context.TelemetryWirelineRunOut.Add(entity);
|
||||
else
|
||||
context.TelemetryWirelineRunOut.Upsert(entity);
|
||||
|
||||
return await context.SaveChangesAsync(token);
|
||||
}
|
||||
|
||||
public async Task<TelemetryWirelineRunOutDto?> GetValueOrDefaultAsync(int idTelemetry, WellInfoDto wellInfo, CancellationToken token)
|
||||
/// <inheritdoc/>
|
||||
public async Task<TelemetryWirelineRunOutDto?> GetValueOrDefaultAsync(int idWell, CancellationToken token)
|
||||
{
|
||||
var well = await wellService.GetOrDefaultAsync(idWell, token).ConfigureAwait(false);
|
||||
if (well is null)
|
||||
return null;
|
||||
|
||||
var idTelemetry = telemetryService.GetOrDefaultIdTelemetryByIdWell(idWell);
|
||||
if (idTelemetry is null)
|
||||
return null;
|
||||
|
||||
var entity = await context.TelemetryWirelineRunOut
|
||||
.Where(x => x.IdTelemetry == idTelemetry)
|
||||
.AsNoTracking()
|
||||
@ -41,19 +68,46 @@ namespace AsbCloudInfrastructure.Repository
|
||||
|
||||
if (entity is null)
|
||||
return null;
|
||||
return Convert(entity, wellInfo);
|
||||
|
||||
var timezone = telemetryService.GetTimezone((int)idTelemetry);
|
||||
return Convert(entity, well, timezone.Hours);
|
||||
}
|
||||
|
||||
/// <inheritdoc/>
|
||||
public async Task<IEnumerable<TelemetryWirelineRunOutDto>> GetAllAsync(int idCompany, CancellationToken token)
|
||||
{
|
||||
var result = new List<TelemetryWirelineRunOutDto>();
|
||||
var wells = await wellService.GetAllAsync(token)
|
||||
.ConfigureAwait(false);
|
||||
|
||||
foreach (var well in wells)
|
||||
{
|
||||
bool isCompanyOwnsWell = await wellService.IsCompanyInvolvedInWellAsync(idCompany, well.Id, token)
|
||||
.ConfigureAwait(false);
|
||||
|
||||
if (!isCompanyOwnsWell)
|
||||
continue;
|
||||
|
||||
var dto = await GetValueOrDefaultAsync(well.Id, token);
|
||||
if (dto is not null)
|
||||
result.Add(dto);
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
private static TelemetryWirelineRunOut Convert(int idTelemetry, TelemetryWirelineRunOutDto dto)
|
||||
{
|
||||
var entity = dto.Adapt<TelemetryWirelineRunOut>();
|
||||
entity.IdTelemetry = idTelemetry;
|
||||
entity.DateTime = entity.DateTime.ToUniversalTime();
|
||||
return entity;
|
||||
}
|
||||
private static TelemetryWirelineRunOutDto Convert(TelemetryWirelineRunOut entity, WellInfoDto wellInfo)
|
||||
private static TelemetryWirelineRunOutDto Convert(TelemetryWirelineRunOut entity, WellDto well, double timezoneOffset)
|
||||
{
|
||||
var dto = entity.Adapt<TelemetryWirelineRunOutDto>();
|
||||
dto.WellInfo = wellInfo;
|
||||
dto.DateTime = entity.DateTime.ToUtcDateTimeOffset(timezoneOffset);
|
||||
dto.WellInfo = well;
|
||||
return dto;
|
||||
}
|
||||
}
|
||||
|
@ -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);
|
||||
}
|
||||
}
|
||||
}
|
@ -1,6 +1,5 @@
|
||||
using AsbCloudApp.Data.SAUB;
|
||||
using AsbCloudApp.Services;
|
||||
using AsbCloudDb.Model;
|
||||
using AsbCloudWebApi.SignalR;
|
||||
using Microsoft.AspNetCore.Authorization;
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
@ -8,9 +7,7 @@ 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
|
||||
{
|
||||
@ -20,7 +17,7 @@ namespace AsbCloudWebApi.Controllers.SAUB
|
||||
[ApiController]
|
||||
[Authorize]
|
||||
[Route("api/[controller]")]
|
||||
public class TelemetryWirelineRunOutController : ControllerBase //TelemetryInstantDataController<TelemetryWirelineRunOutDto>
|
||||
public class TelemetryWirelineRunOutController : ControllerBase
|
||||
{
|
||||
private readonly ITelemetryService telemetryService;
|
||||
private readonly IWellService wellService;
|
||||
@ -45,18 +42,17 @@ namespace AsbCloudWebApi.Controllers.SAUB
|
||||
/// </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)
|
||||
public IActionResult PostData(string uid, [FromBody] TelemetryWirelineRunOutDto dto, CancellationToken token)
|
||||
{
|
||||
if (dto is null)
|
||||
return BadRequest("Dto shouldn't be null");
|
||||
|
||||
var idTelemetry = telemetryService.GetOrCreateTelemetryIdByUid(uid);
|
||||
|
||||
var data = repository.AddOrUpdate(idTelemetry, dto);
|
||||
var data = repository.AddOrUpdateAsync(uid, dto, token);
|
||||
|
||||
var idWell = telemetryService.GetIdWellByTelemetryUid(uid);
|
||||
if (idWell is not null)
|
||||
@ -76,8 +72,8 @@ namespace AsbCloudWebApi.Controllers.SAUB
|
||||
/// <param name="token"></param>
|
||||
/// <returns></returns>
|
||||
[HttpGet("{idWell}")]
|
||||
//[Permission]
|
||||
public virtual async Task<ActionResult<TelemetryWirelineRunOutDto>> GetDataAsync(int idWell, CancellationToken token)
|
||||
[Permission]
|
||||
public async Task<ActionResult<TelemetryWirelineRunOutDto>> GetDataAsync(int idWell, CancellationToken token)
|
||||
{
|
||||
int? idCompany = User.GetCompanyId();
|
||||
|
||||
@ -90,15 +86,7 @@ namespace AsbCloudWebApi.Controllers.SAUB
|
||||
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);
|
||||
var dto = await repository.GetValueOrDefaultAsync(idWell, token);
|
||||
|
||||
if (dto is null)
|
||||
return NoContent();
|
||||
@ -106,35 +94,14 @@ namespace AsbCloudWebApi.Controllers.SAUB
|
||||
}
|
||||
|
||||
[HttpGet]
|
||||
public virtual async Task<ActionResult<IEnumerable<TelemetryWirelineRunOutDto>>> GetAllAsync(CancellationToken token)
|
||||
public 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);
|
||||
var dtos = await repository.GetAllAsync((int)idCompany, token);
|
||||
return Ok(dtos);
|
||||
}
|
||||
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user