Merge remote-tracking branch 'origin/dev' into dev

This commit is contained in:
KharchenkoVladimir 2021-10-12 11:30:21 +05:00
commit bf7c0895b3
21 changed files with 8065 additions and 96 deletions

View File

@ -0,0 +1,11 @@
namespace AsbCloudApp.Data
{
public class WellCompositeDto
{
public int IdWell { get; set; }
public int IdWellSrc { get; set; }
public int IdWellSectionType { get; set; }
}
}

View File

@ -10,7 +10,6 @@ namespace AsbCloudApp.Services
Task<Dictionary<int, string>> GetCategoriesAsync(CancellationToken token);
Task<MeasureDto> GetLastAsync(int idWell, int idCategory, CancellationToken token);
Task<IEnumerable<MeasureDto>> GetHisoryAsync(int idWell, CancellationToken token);
Task<IEnumerable<MeasureDto>> GetAllLastAsync(int idWell, CancellationToken token);
Task<int> InsertAsync(int idWell, MeasureDto data, CancellationToken token);
Task<int> UpdateAsync(int idWell, MeasureDto data, CancellationToken token);
Task<int> MarkAsDeleteAsync(int idWell, int idData, CancellationToken token);

View File

@ -10,7 +10,6 @@ namespace AsbCloudApp.Services
Task<IEnumerable<WellDto>> GetWellsByCompanyAsync(int idCompany, CancellationToken token);
Task<IEnumerable<WellDto>> GetTransmittingWellsAsync(int idCompany, CancellationToken token);
Task<bool> IsCompanyInvolvedInWellAsync(int idCompany, int idWell, CancellationToken token);
Task<IEnumerable<WellOperationDto>> GetOperationsAsync(int idWell, CancellationToken token);
Task<string> GetWellCaptionByIdAsync(int idWell, CancellationToken token);
Task<IEnumerable<CompanyDto>> GetCompaniesAsync(int idWell, CancellationToken token);
Task<WellDto> GetAsync(int idWell, CancellationToken token);

File diff suppressed because it is too large Load Diff

View File

@ -0,0 +1,54 @@
using Microsoft.EntityFrameworkCore.Migrations;
namespace AsbCloudDb.Migrations
{
public partial class Add_CompositeWell : Migration
{
protected override void Up(MigrationBuilder migrationBuilder)
{
migrationBuilder.CreateTable(
name: "t_сomposite_well",
columns: table => new
{
id_well = table.Column<int>(type: "integer", nullable: false, comment: "Id скважины получателя"),
id_well_src = table.Column<int>(type: "integer", nullable: false, comment: "Id скважины композита"),
id_well_section_type = table.Column<int>(type: "integer", nullable: false, comment: "Id тип секции композита"),
Id = table.Column<int>(type: "integer", nullable: false)
},
constraints: table =>
{
table.PrimaryKey("PK_t_сomposite_well", x => new { x.id_well, x.id_well_src, x.id_well_section_type });
table.ForeignKey(
name: "t_сomposite_well_src_t_well_id_fk",
column: x => x.id_well_src,
principalTable: "t_well",
principalColumn: "id",
onDelete: ReferentialAction.Cascade);
table.ForeignKey(
name: "t_сomposite_well_t_well_id_fk",
column: x => x.id_well,
principalTable: "t_well",
principalColumn: "id",
onDelete: ReferentialAction.Cascade);
table.ForeignKey(
name: "t_сomposite_well_t_well_section_type_id_fk",
column: x => x.id_well_src,
principalTable: "t_well_section_type",
principalColumn: "id",
onDelete: ReferentialAction.Cascade);
},
comment: "Композитная скважина");
migrationBuilder.CreateIndex(
name: "IX_t_сomposite_well_id_well_src",
table: "t_сomposite_well",
column: "id_well_src");
}
protected override void Down(MigrationBuilder migrationBuilder)
{
migrationBuilder.DropTable(
name: "t_сomposite_well");
}
}
}

File diff suppressed because it is too large Load Diff

View File

@ -0,0 +1,24 @@
using Microsoft.EntityFrameworkCore.Migrations;
namespace AsbCloudDb.Migrations
{
public partial class Remove_CompositeWell_id : Migration
{
protected override void Up(MigrationBuilder migrationBuilder)
{
migrationBuilder.DropColumn(
name: "Id",
table: "t_сomposite_well");
}
protected override void Down(MigrationBuilder migrationBuilder)
{
migrationBuilder.AddColumn<int>(
name: "Id",
table: "t_сomposite_well",
type: "integer",
nullable: false,
defaultValue: 0);
}
}
}

File diff suppressed because it is too large Load Diff

View File

@ -0,0 +1,93 @@
using Microsoft.EntityFrameworkCore.Migrations;
namespace AsbCloudDb.Migrations
{
public partial class Rename_CompositeWell_to_WellComposite : Migration
{
protected override void Up(MigrationBuilder migrationBuilder)
{
migrationBuilder.DropTable(
name: "t_сomposite_well");
migrationBuilder.CreateTable(
name: "t_well_сomposite",
columns: table => new
{
id_well = table.Column<int>(type: "integer", nullable: false, comment: "Id скважины получателя"),
id_well_src = table.Column<int>(type: "integer", nullable: false, comment: "Id скважины композита"),
id_well_section_type = table.Column<int>(type: "integer", nullable: false, comment: "Id тип секции композита")
},
constraints: table =>
{
table.PrimaryKey("PK_t_well_сomposite", x => new { x.id_well, x.id_well_src, x.id_well_section_type });
table.ForeignKey(
name: "t_well_сomposite_src_t_well_id_fk",
column: x => x.id_well_src,
principalTable: "t_well",
principalColumn: "id",
onDelete: ReferentialAction.Cascade);
table.ForeignKey(
name: "t_well_сomposite_t_well_id_fk",
column: x => x.id_well,
principalTable: "t_well",
principalColumn: "id",
onDelete: ReferentialAction.Cascade);
table.ForeignKey(
name: "t_well_сomposite_t_well_section_type_id_fk",
column: x => x.id_well_src,
principalTable: "t_well_section_type",
principalColumn: "id",
onDelete: ReferentialAction.Cascade);
},
comment: "Композитная скважина");
migrationBuilder.CreateIndex(
name: "IX_t_well_сomposite_id_well_src",
table: "t_well_сomposite",
column: "id_well_src");
}
protected override void Down(MigrationBuilder migrationBuilder)
{
migrationBuilder.DropTable(
name: "t_well_сomposite");
migrationBuilder.CreateTable(
name: "t_сomposite_well",
columns: table => new
{
id_well = table.Column<int>(type: "integer", nullable: false, comment: "Id скважины получателя"),
id_well_src = table.Column<int>(type: "integer", nullable: false, comment: "Id скважины композита"),
id_well_section_type = table.Column<int>(type: "integer", nullable: false, comment: "Id тип секции композита")
},
constraints: table =>
{
table.PrimaryKey("PK_t_сomposite_well", x => new { x.id_well, x.id_well_src, x.id_well_section_type });
table.ForeignKey(
name: "t_сomposite_well_src_t_well_id_fk",
column: x => x.id_well_src,
principalTable: "t_well",
principalColumn: "id",
onDelete: ReferentialAction.Cascade);
table.ForeignKey(
name: "t_сomposite_well_t_well_id_fk",
column: x => x.id_well,
principalTable: "t_well",
principalColumn: "id",
onDelete: ReferentialAction.Cascade);
table.ForeignKey(
name: "t_сomposite_well_t_well_section_type_id_fk",
column: x => x.id_well_src,
principalTable: "t_well_section_type",
principalColumn: "id",
onDelete: ReferentialAction.Cascade);
},
comment: "Композитная скважина");
migrationBuilder.CreateIndex(
name: "IX_t_сomposite_well_id_well_src",
table: "t_сomposite_well",
column: "id_well_src");
}
}
}

View File

@ -1572,6 +1572,33 @@ namespace AsbCloudDb.Migrations
.HasComment("скважины");
});
modelBuilder.Entity("AsbCloudDb.Model.WellComposite", b =>
{
b.Property<int>("IdWell")
.HasColumnType("integer")
.HasColumnName("id_well")
.HasComment("Id скважины получателя");
b.Property<int>("IdWellSrc")
.HasColumnType("integer")
.HasColumnName("id_well_src")
.HasComment("Id скважины композита");
b.Property<int>("IdWellSectionType")
.HasColumnType("integer")
.HasColumnName("id_well_section_type")
.HasComment("Id тип секции композита");
b.HasKey("IdWell", "IdWellSrc", "IdWellSectionType");
b.HasIndex("IdWellSrc");
b.ToTable("t_well_сomposite");
b
.HasComment("Композитная скважина");
});
modelBuilder.Entity("AsbCloudDb.Model.WellOperation", b =>
{
b.Property<int>("Id")
@ -2407,6 +2434,36 @@ namespace AsbCloudDb.Migrations
b.Navigation("WellType");
});
modelBuilder.Entity("AsbCloudDb.Model.WellComposite", b =>
{
b.HasOne("AsbCloudDb.Model.Well", "Well")
.WithMany("WellComposites")
.HasForeignKey("IdWell")
.HasConstraintName("t_well_сomposite_t_well_id_fk")
.OnDelete(DeleteBehavior.Cascade)
.IsRequired();
b.HasOne("AsbCloudDb.Model.Well", "WellSrc")
.WithMany("WellCompositeSrcs")
.HasForeignKey("IdWellSrc")
.HasConstraintName("t_well_сomposite_src_t_well_id_fk")
.OnDelete(DeleteBehavior.Cascade)
.IsRequired();
b.HasOne("AsbCloudDb.Model.WellSectionType", "WellSectionType")
.WithMany("WellComposites")
.HasForeignKey("IdWellSrc")
.HasConstraintName("t_well_сomposite_t_well_section_type_id_fk")
.OnDelete(DeleteBehavior.Cascade)
.IsRequired();
b.Navigation("Well");
b.Navigation("WellSectionType");
b.Navigation("WellSrc");
});
modelBuilder.Entity("AsbCloudDb.Model.WellOperation", b =>
{
b.HasOne("AsbCloudDb.Model.WellOperationCategory", "OperationCategory")
@ -2492,6 +2549,10 @@ namespace AsbCloudDb.Migrations
{
b.Navigation("RelationCompaniesWells");
b.Navigation("WellComposites");
b.Navigation("WellCompositeSrcs");
b.Navigation("WellOperations");
});
@ -2504,6 +2565,8 @@ namespace AsbCloudDb.Migrations
{
b.Navigation("DrillParamsCollection");
b.Navigation("WellComposites");
b.Navigation("WellOperations");
});

View File

@ -14,6 +14,7 @@ namespace AsbCloudDb.Model
{
public virtual DbSet<Cluster> Clusters { get; set; }
public virtual DbSet<Company> Companies { get; set; }
public virtual DbSet<WellComposite> WellComposites { get; set; }
public virtual DbSet<Deposit> Deposits { get; set; }
public virtual DbSet<FileCategory> FileCategories { get; set; }
public virtual DbSet<FileInfo> Files { get; set; }
@ -71,6 +72,29 @@ namespace AsbCloudDb.Model
.HasConstraintName("t_cluster_t_deposit_id_fk");
});
modelBuilder.Entity<WellComposite>(entity =>
{
entity.HasKey(
nameof(WellComposite.IdWell),
nameof(WellComposite.IdWellSrc),
nameof(WellComposite.IdWellSectionType));
entity.HasOne(d => d.Well)
.WithMany(p => p.WellComposites)
.HasForeignKey(d => d.IdWell)
.HasConstraintName("t_well_сomposite_t_well_id_fk");
entity.HasOne(d => d.WellSrc)
.WithMany(p => p.WellCompositeSrcs)
.HasForeignKey(d => d.IdWellSrc)
.HasConstraintName("t_well_сomposite_src_t_well_id_fk");
entity.HasOne(d => d.WellSectionType)
.WithMany(p => p.WellComposites)
.HasForeignKey(d => d.IdWellSrc)
.HasConstraintName("t_well_сomposite_t_well_section_type_id_fk");
});
modelBuilder.Entity<TelemetryDataSaub>(entity =>
{
entity.HasOne(d => d.Telemetry)

View File

@ -16,7 +16,6 @@ namespace AsbCloudDb.Model
[Column("id_telemetry")]
public int IdTelemetry { get; set; }
[JsonIgnore]
[ForeignKey(nameof(IdTelemetry))]
[InverseProperty(nameof(Model.Telemetry.Users))]
@ -37,7 +36,6 @@ namespace AsbCloudDb.Model
[Column("level")]
public int? Level { get; set; }
public string MakeDisplayName()
{
if (!string.IsNullOrEmpty(Surname))

View File

@ -20,7 +20,6 @@ namespace AsbCloudDb.Model
[Column("id_role")]
public int? IdRole { get; set; }
[Column("login")]
[StringLength(255)]
public string Login { get; set; }

View File

@ -52,5 +52,11 @@ namespace AsbCloudDb.Model
[JsonIgnore]
[InverseProperty(nameof(WellOperation.Well))]
public virtual ICollection<WellOperation> WellOperations { get; set; }
[InverseProperty(nameof(WellComposite.Well))]
public virtual ICollection<WellComposite> WellComposites { get; set; }
[InverseProperty(nameof(WellComposite.WellSrc))]
public virtual ICollection<WellComposite> WellCompositeSrcs { get; set; }
}
}

View File

@ -0,0 +1,32 @@
using Microsoft.EntityFrameworkCore;
using System.ComponentModel.DataAnnotations;
using System.ComponentModel.DataAnnotations.Schema;
#nullable disable
namespace AsbCloudDb.Model
{
[Table("t_well_сomposite"), Comment("Композитная скважина")]
public class WellComposite : IIdWell
{
[Column("id_well"), Comment("Id скважины получателя")]
public int IdWell { get; set; }
[Column("id_well_src"), Comment("Id скважины композита")]
public int IdWellSrc { get; set; }
[Column("id_well_section_type"), Comment("Id тип секции композита")]
public int IdWellSectionType { get; set; }
[ForeignKey(nameof(IdWell))]
[InverseProperty(nameof(Model.Well.WellComposites))]
public virtual Well Well { get; set; }
[ForeignKey(nameof(IdWellSrc))]
[InverseProperty(nameof(Model.Well.WellCompositeSrcs))]
public virtual Well WellSrc { get; set; }
[ForeignKey(nameof(IdWellSectionType))]
[InverseProperty(nameof(Model.WellSectionType.WellComposites))]
public virtual WellSectionType WellSectionType { get; set; }
}
}

View File

@ -25,5 +25,9 @@ namespace AsbCloudDb.Model
[JsonIgnore]
[InverseProperty(nameof(DrillParams.WellSectionType))]
public virtual ICollection<DrillParams> DrillParamsCollection { get; set; }
[JsonIgnore]
[InverseProperty(nameof(WellComposite.WellSectionType))]
public virtual ICollection<WellComposite> WellComposites { get; set; }
}
}

View File

@ -47,42 +47,6 @@ namespace AsbCloudInfrastructure.Services
return dtos;
}
public async Task<IEnumerable<MeasureDto>> GetAllLastAsync(int idWell, CancellationToken token)
{
var categories = await cacheCategories.WhereAsync(token).ConfigureAwait(false);
if (!categories.Any())
return default;
var queries = categories.Select(c => db.Measures.Include(m => m.Category)
.Where(m => m.IdWell == idWell && m.IdCategory == c.Id && !m.IsDeleted)
.OrderByDescending(m => m.Timestamp)
.Take(1)
);
var qi = queries.GetEnumerator();
qi.MoveNext();
var query = qi.Current;
while (qi.MoveNext())
query = query.Union(qi.Current);
//var query = db.Measures
// .Where(e => e.IdWell == idWell)
// .GroupBy(e => e.IdCategory)
// .Select(g => g.Where(e => e.Timestamp == g.Max(m => m.Timestamp)).First());
//var query = db.Measures
// .Where(m => m.IdWell == idWell && m.Timestamp == db.Measures
// .Where(subm => subm.IdWell == m.IdWell && subm.IdCategory == m.IdCategory).Max(subm => subm.Timestamp));
var entities = await query
.AsNoTracking()
.ToListAsync(token)
.ConfigureAwait(false);
var dtos = entities.Adapt<MeasureDto, Measure>((d, s) => d.CategoryName = s.Category?.Name);
return dtos;
}
public async Task<IEnumerable<MeasureDto>> GetHisoryAsync(int idWell, CancellationToken token)
{
var query = db.Measures.Include(m => m.Category)
@ -105,6 +69,7 @@ namespace AsbCloudInfrastructure.Services
if (data.Data is null)
throw new ArgumentException("data.data is not optional", nameof(data));
var entity = data.Adapt<Measure>();
entity.IdWell = idWell;
db.Measures.Add(entity);
return db.SaveChangesAsync(token);
}
@ -122,10 +87,10 @@ namespace AsbCloudInfrastructure.Services
.Where(m => m.Id == data.Id && !m.IsDeleted)
.FirstOrDefaultAsync(token)
.ConfigureAwait(false);
if (entity is null)
throw new ArgumentException("id doesn't exist", nameof(data));
entity.IdWell = idWell;
entity.Timestamp = data.Timestamp;
entity.Data = data.Data;

View File

@ -52,18 +52,6 @@ namespace AsbCloudInfrastructure.Services
=> await cacheRelationCompaniesWells.ContainsAsync(r => r.IdWell == idWell &&
r.IdCompany == idCompany, token).ConfigureAwait(false);
public async Task<IEnumerable<WellOperationDto>> GetOperationsAsync(int idWell, CancellationToken token)
{
var entities = await db.WellOperations.Where(o => o.IdWell == idWell)
.AsNoTracking()
.ToListAsync(token)
.ConfigureAwait(false);
var dtos = entities.Adapt<WellOperationDto>();
return dtos;
}
private static WellDto From(Well well)
{
var wellDto = new WellDto

View File

@ -32,17 +32,6 @@ namespace AsbCloudWebApi.Controllers
return Ok(result);
}
[HttpGet]
[Route("lastAll")]
public async Task<IActionResult> GetAllLastAsync([FromRoute] int idWell, CancellationToken token = default)
{
if (!await CanUserAccessToWellAsync(idWell, token).ConfigureAwait(false))
return Forbid();
var result = await measureService.GetAllLastAsync(idWell, token).ConfigureAwait(false);
return Ok(result);
}
[HttpGet]
[Route("last/{idCategory}")]
public async Task<IActionResult> GetLastAsync([FromRoute] int idWell, [FromRoute] int idCategory, CancellationToken token = default)

View File

@ -18,7 +18,6 @@ namespace AsbCloudWebApi.Controllers
[ApiController]
public class TelemetryController : ControllerBase
{
private readonly IDataService DataService;
private readonly ITelemetryService telemetryService;
private readonly IMessageService messageService;
private readonly IEventService eventService;
@ -28,14 +27,12 @@ namespace AsbCloudWebApi.Controllers
public TelemetryController(
ITelemetryService telemetryService,
IDataService DataService,
IMessageService messageService,
IEventService eventService,
ITelemetryUserService telemetryUserService,
IHubContext<TelemetryHub> telemetryHubContext,
ITelemetryTracker telemetryTracker)
{
this.DataService = DataService;
this.telemetryService = telemetryService;
this.messageService = messageService;
this.eventService = eventService;
@ -59,31 +56,6 @@ namespace AsbCloudWebApi.Controllers
return Ok();
}
//TODO: remove when panels update will be done.
/// <summary>
/// Принимает данные от разных систем по скважине
/// </summary>
/// <param name="uid">Уникальный идентификатор отправителя</param>
/// <param name="dtos">Данные</param>
/// <param name="token">Токен для отмены задачи</param>
/// <returns></returns>
[HttpPost]
[Obsolete]
[Route("{uid}/data")]
public async Task<IActionResult> PostDataAsync(string uid, [FromBody] IEnumerable<TelemetryDataSaubDto> dtos,
CancellationToken token = default)
{
var idWell = telemetryService.GetidWellByTelemetryUid(uid);
await DataService.UpdateDataAsync(uid, dtos, token).ConfigureAwait(false);
if (idWell != null && dtos.Any())
await Task.Run(() => telemetryHubContext.Clients.Group($"well_{idWell}")
.SendAsync("ReceiveDataSaub", dtos), token).ConfigureAwait(false);
telemetryTracker.SaveRequestDate(uid);
return Ok();
}
/// <summary>
/// Принимает список новых сообщений от телеметрии
/// </summary>

View File

@ -1,4 +1,4 @@
using AsbCloudDb.Model;
using AsbCloudApp.Data;
using System.Security.Claims;
namespace AsbCloudWebApi
@ -7,7 +7,7 @@ namespace AsbCloudWebApi
{
public static int? GetCompanyId(this ClaimsPrincipal user)
{
var claimIdCompany = user.FindFirst(nameof(User.IdCompany));
var claimIdCompany = user.FindFirst(nameof(UserDto.IdCompany));
if (claimIdCompany is null)
return null;
@ -18,7 +18,7 @@ namespace AsbCloudWebApi
public static int? GetUserId(this ClaimsPrincipal user)
{
var userId = user.FindFirst(nameof(User.Id));
var userId = user.FindFirst(nameof(UserDto.Id));
if (userId is null)
return null;