forked from ddrilling/AsbCloudServer
CS2-98: Added State to Well. Added .UpdateWell() in WellController.
This commit is contained in:
parent
589959c802
commit
6e4c85843f
@ -9,6 +9,10 @@ namespace AsbCloudApp.Data
|
|||||||
public double? Latitude { get; set; }
|
public double? Latitude { get; set; }
|
||||||
public double? Longitude { get; set; }
|
public double? Longitude { get; set; }
|
||||||
public string WellType { get; set; }
|
public string WellType { get; set; }
|
||||||
|
// 0 - незвестно,
|
||||||
|
// 1 - в работе,
|
||||||
|
// 2 - завершена
|
||||||
|
public int State { get; set; }
|
||||||
public DateTime LastTelemetryDate { get; set; }
|
public DateTime LastTelemetryDate { get; set; }
|
||||||
public TelemetryDto Telemetry { get; set; }
|
public TelemetryDto Telemetry { get; set; }
|
||||||
}
|
}
|
||||||
|
@ -8,6 +8,9 @@ namespace AsbCloudApp.Services
|
|||||||
public interface IWellService
|
public interface IWellService
|
||||||
{
|
{
|
||||||
Task<IEnumerable<WellDto>> GetWellsByCompanyAsync(int idCompany, CancellationToken token);
|
Task<IEnumerable<WellDto>> GetWellsByCompanyAsync(int idCompany, CancellationToken token);
|
||||||
|
Task<int> UpdateWellAsync(int idWell, string caption = default,
|
||||||
|
double latitude = default, double longitude = default, int idWellType = default,
|
||||||
|
int state = default, CancellationToken token = default);
|
||||||
Task<IEnumerable<WellDto>> GetTransmittingWellsAsync(int idCompany, CancellationToken token);
|
Task<IEnumerable<WellDto>> GetTransmittingWellsAsync(int idCompany, CancellationToken token);
|
||||||
Task<bool> IsCompanyInvolvedInWellAsync(int idCompany, int idWell, CancellationToken token);
|
Task<bool> IsCompanyInvolvedInWellAsync(int idCompany, int idWell, CancellationToken token);
|
||||||
Task<string> GetWellCaptionByIdAsync(int idWell, CancellationToken token);
|
Task<string> GetWellCaptionByIdAsync(int idWell, CancellationToken token);
|
||||||
|
2695
AsbCloudDb/Migrations/20211018071004_Add_Well_State.Designer.cs
generated
Normal file
2695
AsbCloudDb/Migrations/20211018071004_Add_Well_State.Designer.cs
generated
Normal file
File diff suppressed because it is too large
Load Diff
25
AsbCloudDb/Migrations/20211018071004_Add_Well_State.cs
Normal file
25
AsbCloudDb/Migrations/20211018071004_Add_Well_State.cs
Normal file
@ -0,0 +1,25 @@
|
|||||||
|
using Microsoft.EntityFrameworkCore.Migrations;
|
||||||
|
|
||||||
|
namespace AsbCloudDb.Migrations
|
||||||
|
{
|
||||||
|
public partial class Add_Well_State : Migration
|
||||||
|
{
|
||||||
|
protected override void Up(MigrationBuilder migrationBuilder)
|
||||||
|
{
|
||||||
|
migrationBuilder.AddColumn<int>(
|
||||||
|
name: "state",
|
||||||
|
table: "t_well",
|
||||||
|
type: "integer",
|
||||||
|
nullable: false,
|
||||||
|
defaultValue: 0,
|
||||||
|
comment: "0 - неизвестно, 1 - в работе, 2 - завершена");
|
||||||
|
}
|
||||||
|
|
||||||
|
protected override void Down(MigrationBuilder migrationBuilder)
|
||||||
|
{
|
||||||
|
migrationBuilder.DropColumn(
|
||||||
|
name: "state",
|
||||||
|
table: "t_well");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@ -1652,6 +1652,11 @@ namespace AsbCloudDb.Migrations
|
|||||||
.HasColumnType("double precision")
|
.HasColumnType("double precision")
|
||||||
.HasColumnName("longitude");
|
.HasColumnName("longitude");
|
||||||
|
|
||||||
|
b.Property<int>("State")
|
||||||
|
.HasColumnType("integer")
|
||||||
|
.HasColumnName("state")
|
||||||
|
.HasComment("0 - неизвестно, 1 - в работе, 2 - завершена");
|
||||||
|
|
||||||
b.HasKey("Id");
|
b.HasKey("Id");
|
||||||
|
|
||||||
b.HasIndex("IdCluster");
|
b.HasIndex("IdCluster");
|
||||||
|
@ -27,6 +27,9 @@ namespace AsbCloudDb.Model
|
|||||||
|
|
||||||
[Column("id_well_type")]
|
[Column("id_well_type")]
|
||||||
public int? IdWellType { get; set; }
|
public int? IdWellType { get; set; }
|
||||||
|
|
||||||
|
[Column("state"), Comment("0 - неизвестно, 1 - в работе, 2 - завершена")]
|
||||||
|
public int State { get; set; }
|
||||||
|
|
||||||
[Column("latitude")]
|
[Column("latitude")]
|
||||||
public double? Latitude { get; set; }
|
public double? Latitude { get; set; }
|
||||||
|
@ -15,13 +15,11 @@ namespace AsbCloudInfrastructure.Services
|
|||||||
IDrillFlowChartService
|
IDrillFlowChartService
|
||||||
{
|
{
|
||||||
private readonly IAsbCloudDbContext db;
|
private readonly IAsbCloudDbContext db;
|
||||||
private readonly ITelemetryService telemetryService;
|
|
||||||
|
public DrillFlowChartService(IAsbCloudDbContext context)
|
||||||
public DrillFlowChartService(IAsbCloudDbContext context, ITelemetryService telemetryService)
|
|
||||||
: base(context)
|
: base(context)
|
||||||
{
|
{
|
||||||
this.db = context;
|
this.db = context;
|
||||||
this.telemetryService = telemetryService;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public async Task<IEnumerable<DrillFlowChartDto>> GetAllAsync(int idWell,
|
public async Task<IEnumerable<DrillFlowChartDto>> GetAllAsync(int idWell,
|
||||||
|
@ -42,6 +42,39 @@ namespace AsbCloudInfrastructure.Services
|
|||||||
Deposit = w.Cluster.Deposit.Caption,
|
Deposit = w.Cluster.Deposit.Caption,
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public async Task<int> UpdateWellAsync(int idWell, string caption = default,
|
||||||
|
double latitude = default, double longitude = default, int idWellType = default,
|
||||||
|
int state = default, CancellationToken token = default)
|
||||||
|
{
|
||||||
|
var well = await db.Wells
|
||||||
|
.FirstOrDefaultAsync(w => w.Id == idWell, token)
|
||||||
|
.ConfigureAwait(false);
|
||||||
|
|
||||||
|
if (well is null)
|
||||||
|
return 0;
|
||||||
|
|
||||||
|
if (caption != default)
|
||||||
|
well.Caption = caption;
|
||||||
|
|
||||||
|
if (latitude != default)
|
||||||
|
well.Latitude = latitude;
|
||||||
|
|
||||||
|
if (longitude != default)
|
||||||
|
well.Longitude = longitude;
|
||||||
|
|
||||||
|
if (idWellType != default)
|
||||||
|
well.IdWellType = idWellType;
|
||||||
|
|
||||||
|
if (state < 3)
|
||||||
|
well.State = state;
|
||||||
|
else
|
||||||
|
throw new ArgumentException("Недопустимое значение состояния работы скважины");
|
||||||
|
|
||||||
|
db.Wells.Update(well);
|
||||||
|
|
||||||
|
return await db.SaveChangesAsync(token);
|
||||||
|
}
|
||||||
|
|
||||||
public bool IsCompanyInvolvedInWell(int idCompany, int idWell)
|
public bool IsCompanyInvolvedInWell(int idCompany, int idWell)
|
||||||
=> cacheRelationCompaniesWells.Contains(r => r.IdWell == idWell && r.IdCompany == idCompany);
|
=> cacheRelationCompaniesWells.Contains(r => r.IdWell == idWell && r.IdCompany == idCompany);
|
||||||
|
@ -20,7 +20,12 @@ namespace AsbCloudWebApi.Controllers
|
|||||||
{
|
{
|
||||||
this.wellService = wellService;
|
this.wellService = wellService;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Возвращает список доступных скважин
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="token"> Токен отмены задачи </param>
|
||||||
|
/// <returns>Список скважин</returns>
|
||||||
[HttpGet]
|
[HttpGet]
|
||||||
[ProducesResponseType(typeof(IEnumerable<WellDto>), (int)System.Net.HttpStatusCode.OK)]
|
[ProducesResponseType(typeof(IEnumerable<WellDto>), (int)System.Net.HttpStatusCode.OK)]
|
||||||
public async Task<IActionResult> GetWellsAsync(CancellationToken token = default)
|
public async Task<IActionResult> GetWellsAsync(CancellationToken token = default)
|
||||||
@ -40,7 +45,12 @@ namespace AsbCloudWebApi.Controllers
|
|||||||
|
|
||||||
return Ok(wells);
|
return Ok(wells);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Возвращает список скважин, передающих телеметрию в данный момент
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="token"> Токен отмены задачи </param>
|
||||||
|
/// <returns>Список скважин</returns>
|
||||||
[HttpGet("transmittingWells")]
|
[HttpGet("transmittingWells")]
|
||||||
[ProducesResponseType(typeof(IEnumerable<WellDto>), (int)System.Net.HttpStatusCode.OK)]
|
[ProducesResponseType(typeof(IEnumerable<WellDto>), (int)System.Net.HttpStatusCode.OK)]
|
||||||
public async Task<IActionResult> GetTransmittingWellsAsync(CancellationToken token = default)
|
public async Task<IActionResult> GetTransmittingWellsAsync(CancellationToken token = default)
|
||||||
@ -59,5 +69,35 @@ namespace AsbCloudWebApi.Controllers
|
|||||||
return Ok(transmittingWells);
|
return Ok(transmittingWells);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Редактирует указанные поля скважины
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="idWell"> Id скважины </param>
|
||||||
|
/// <param name="caption"> Название скважины </param>
|
||||||
|
/// <param name="latitude"> Широта координат скважины </param>
|
||||||
|
/// <param name="longitude"> Долгота координат скважины </param>
|
||||||
|
/// <param name="idWellType"> Id типа скважины </param>
|
||||||
|
/// <param name="state"> Id текущего состояния скважины </param>
|
||||||
|
/// <param name="token"> Токен отмены задачи </param>
|
||||||
|
/// <returns></returns>
|
||||||
|
[HttpPut]
|
||||||
|
[ProducesResponseType(typeof(int), (int)System.Net.HttpStatusCode.OK)]
|
||||||
|
public async Task<IActionResult> UpdateWellAsync(int idWell, string caption = default,
|
||||||
|
double latitude = default, double longitude = default, int idWellType = default,
|
||||||
|
int state = default, CancellationToken token = default)
|
||||||
|
{
|
||||||
|
var idCompany = User.GetCompanyId();
|
||||||
|
|
||||||
|
if (idCompany is null || !await wellService.IsCompanyInvolvedInWellAsync((int)idCompany,
|
||||||
|
idWell, token).ConfigureAwait(false))
|
||||||
|
return Forbid();
|
||||||
|
|
||||||
|
var result = await wellService.UpdateWellAsync(idWell, caption, latitude, longitude,
|
||||||
|
idWellType, state, token).ConfigureAwait(false);
|
||||||
|
|
||||||
|
return Ok(result);
|
||||||
|
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user