diff --git a/AsbCloudApp/Data/FluidDataDto.cs b/AsbCloudApp/Data/FluidDataDto.cs new file mode 100644 index 00000000..abf36da4 --- /dev/null +++ b/AsbCloudApp/Data/FluidDataDto.cs @@ -0,0 +1,33 @@ +namespace AsbCloudApp.Data +{ + public class FluidDataDto + { + public string Temperature { get; set; } + public string Density { get; set; } + public string ConditionalViscosity { get; set; } + public string R300 { get; set; } + public string R600 { get; set; } + public string R3r6 { get; set; } + public string DnsDpa { get; set; } + public string PlasticViscocity { get; set; } + public string SnsDpa { get; set; } + public string R3r649С { get; set; } + public string Dns49Cdpa { get; set; } + public string PlasticViscocity49c { get; set; } + public string Sns49Cdpa { get; set; } + public string Mbt { get; set; } + public string Sand { get; set; } + public string Filtering { get; set; } + public string Crust { get; set; } + public string Ktk { get; set; } + public string Ph { get; set; } + public string Hardness { get; set; } + public string Chlorides { get; set; } + public string Pf { get; set; } + public string Mf { get; set; } + public string Pm { get; set; } + public string FluidSolidPhase { get; set; } + public string Grease { get; set; } + public string CalciumCarbonate { get; set; } + } +} diff --git a/AsbCloudApp/Services/ILastDataService.cs b/AsbCloudApp/Services/ILastDataService.cs index 036bd3b9..3817f4cc 100644 --- a/AsbCloudApp/Services/ILastDataService.cs +++ b/AsbCloudApp/Services/ILastDataService.cs @@ -3,6 +3,6 @@ public interface ILastDataService { Tdto Get(int idWell, int idCategory); - int Upsert(int idCategory, Tdto value); + int Upsert(int idWell, int idCategory, Tdto value); } } diff --git a/AsbCloudDb/Model/AsbCloudDbContext.cs b/AsbCloudDb/Model/AsbCloudDbContext.cs index 5f4fd395..ebacb6e5 100644 --- a/AsbCloudDb/Model/AsbCloudDbContext.cs +++ b/AsbCloudDb/Model/AsbCloudDbContext.cs @@ -31,6 +31,7 @@ namespace AsbCloudDb.Model public virtual DbSet WellSections { get; set; } public virtual DbSet WellOperations { get; set; } public virtual DbSet WellTypes { get; set; } + public virtual DbSet LastData { get; set; } //var options = new DbContextOptionsBuilder() // .UseNpgsql("Host=localhost;Database=postgres;Username=postgres;Password=q;Persist Security Info=True") @@ -367,7 +368,7 @@ namespace AsbCloudDb.Model IdOperation = 10, UnixDate = 1626870370, DurationSec = 2, - OperationStartDepth = null, + OperationStartDepth = 206, OperationEndDepth = 206, IsWellDepthIncreasing = false, IsWellDepthDecreasing = false, diff --git a/AsbCloudDb/Model/FluidData.cs b/AsbCloudDb/Model/FluidData.cs new file mode 100644 index 00000000..2a84827a --- /dev/null +++ b/AsbCloudDb/Model/FluidData.cs @@ -0,0 +1,67 @@ +using System.ComponentModel.DataAnnotations; +using System.ComponentModel.DataAnnotations.Schema; + +namespace AsbCloudDb.Model +{ + [Table("t_fluid_data")] + public class FluidData + { + [Key] + [Column("id")] + public int Id { get; set; } + [Column("temperature")] + public double Temperature { get; set; } + [Column("density")] + public double Density { get; set; } + [Column("conditionalViscosity")] + public double ConditionalViscosity { get; set; } + [Column("r300")] + public double R300 { get; set; } + [Column("r600")] + public double R600 { get; set; } + [Column("r3r6")] + public double R3r6 { get; set; } + [Column("dnsDpa")] + public double DnsDpa { get; set; } + [Column("plasticViscocity")] + public double PlasticViscocity { get; set; } + [Column("snsDpa")] + public double SnsDpa { get; set; } + [Column("r3r649С")] + public double R3r649С { get; set; } + [Column("dns49Cdpa")] + public double Dns49Cdpa { get; set; } + [Column("plasticViscocity49c")] + public double PlasticViscocity49c { get; set; } + [Column("sns49Cdpa")] + public double Sns49Cdpa { get; set; } + [Column("mbt")] + public double Mbt { get; set; } + [Column("sand")] + public double Sand { get; set; } + [Column("filtering")] + public double Filtering { get; set; } + [Column("crust")] + public double Crust { get; set; } + [Column("ktk")] + public double Ktk { get; set; } + [Column("ph")] + public double Ph { get; set; } + [Column("hardness")] + public double Hardness { get; set; } + [Column("chlorides")] + public double Chlorides { get; set; } + [Column("pf")] + public double Pf { get; set; } + [Column("mf")] + public double Mf { get; set; } + [Column("pm")] + public double Pm { get; set; } + [Column("fluidSolidPhase")] + public double FluidSolidPhase { get; set; } + [Column("grease")] + public double Grease { get; set; } + [Column("calciumCarbonate")] + public double CalciumCarbonate { get; set; } + } +} diff --git a/AsbCloudDb/Model/IAsbCloudDbContext.cs b/AsbCloudDb/Model/IAsbCloudDbContext.cs index 4e52349e..a8626d3b 100644 --- a/AsbCloudDb/Model/IAsbCloudDbContext.cs +++ b/AsbCloudDb/Model/IAsbCloudDbContext.cs @@ -28,6 +28,7 @@ namespace AsbCloudDb.Model DbSet WellSections { get; set; } DbSet WellOperations { get; set; } DbSet WellTypes { get; set; } + DbSet LastData { get; set; } int SaveChanges(); int SaveChanges(bool acceptAllChangesOnSuccess); diff --git a/AsbCloudDb/Model/LastData.cs b/AsbCloudDb/Model/LastData.cs new file mode 100644 index 00000000..974318bf --- /dev/null +++ b/AsbCloudDb/Model/LastData.cs @@ -0,0 +1,27 @@ +using System; +using Microsoft.EntityFrameworkCore; +using System.ComponentModel.DataAnnotations; +using System.ComponentModel.DataAnnotations.Schema; + +namespace AsbCloudDb.Model +{ + [Table("t_last_data"), Comment("Таблица c данными для вкладки \'Последние данные\'")] + public class LastData : IId + { + [Key] + [Column("id")] + public int Id { get; set; } + + [Column("id_well"), Comment("id скважины")] + public int IdWell { get; set; } + + [Column("id_category"), Comment("id категории")] + public int IdCategory { get; set; } + + [Column("last_update_date")] + public DateTime LastUpdateDate { get; set; } + + [Column("data", TypeName = "jsonb"), Comment("Данные таблицы последних данных")] + public object Data { get; set; } + } +} diff --git a/AsbCloudDb/Model/MudDiagramData.cs b/AsbCloudDb/Model/MudDiagramData.cs new file mode 100644 index 00000000..82dd39ad --- /dev/null +++ b/AsbCloudDb/Model/MudDiagramData.cs @@ -0,0 +1,28 @@ +namespace AsbCloudDb.Model +{ + public class MudDiagramData + { + public double ProbeNumber { get; set; } + public double ProbeExtractionDepth { get; set; } + public double Sandstone { get; set; } + public double Siltstone { get; set; } + public double Argillit { get; set; } + public double BrokenArgillit { get; set; } + public double Coal { get; set; } + public double Sand { get; set; } + public double Clay { get; set; } + public double Camstone { get; set; } + public double Cement { get; set; } + public string Summary { get; set; } + public double DrillingMud { get; set; } + public double Sludge { get; set; } + public double MaxSum { get; set; } + public double Methane { get; set; } + public double Ethan { get; set; } + public double Propane { get; set; } + public double Butane { get; set; } + public double Pentane { get; set; } + public double MechanicalSpeed { get; set; } + public string PreliminaryConclusion { get; set; } + } +} diff --git a/AsbCloudDb/Model/NnbData.cs b/AsbCloudDb/Model/NnbData.cs new file mode 100644 index 00000000..010ce917 --- /dev/null +++ b/AsbCloudDb/Model/NnbData.cs @@ -0,0 +1,23 @@ +namespace AsbCloudDb.Model +{ + public class NnbData + { + public double Depth { get; set; } + public double ZenithAngle { get; set; } + public double TrueAzimuth { get; set; } + public double ConditionalViscosity { get; set; } + public double DirectAzimuth { get; set; } + public double VerticalDepth { get; set; } + public double AbsoluteMark { get; set; } + public double LocalNorthOffset { get; set; } + public double LocalEastOffset { get; set; } + public double OutFallOffset { get; set; } + public double OffsetAzimuth { get; set; } + public double AreaIntensity { get; set; } + public double OffsetStopAngle { get; set; } + public double ZenithIntensity { get; set; } + public double Comment { get; set; } + public double DepthPlanFactDifference { get; set; } + public double DistancePlanFactDifference { get; set; } + } +} diff --git a/AsbCloudInfrastructure/DependencyInjection.cs b/AsbCloudInfrastructure/DependencyInjection.cs index e2823a0e..bd638938 100644 --- a/AsbCloudInfrastructure/DependencyInjection.cs +++ b/AsbCloudInfrastructure/DependencyInjection.cs @@ -36,6 +36,10 @@ namespace AsbCloudInfrastructure services.AddTransient(); services.AddTransient(); services.AddTransient(); + + + services.AddTransient, LastDataService>(); + return services; } diff --git a/AsbCloudInfrastructure/Services/LastDataService.cs b/AsbCloudInfrastructure/Services/LastDataService.cs index 6cf4cdaa..1bf707bb 100644 --- a/AsbCloudInfrastructure/Services/LastDataService.cs +++ b/AsbCloudInfrastructure/Services/LastDataService.cs @@ -1,43 +1,56 @@ -using System.Collections.Generic; +using System; using System.Linq; using AsbCloudDb.Model; using AsbCloudApp.Services; using Mapster; -using Microsoft.EntityFrameworkCore; -using Microsoft.Extensions.Configuration; namespace AsbCloudInfrastructure.Services { public class LastDataService : ILastDataService - where TModel : class, IIdWellCategory { - private readonly DbContext context; private readonly IAsbCloudDbContext db; - //private Dictioanary dict = - - public LastDataService(IConfiguration configuration, IAsbCloudDbContext db) + public LastDataService(IAsbCloudDbContext db) { this.db = db; } public Tdto Get(int idWell, int idCategory) { - var dbSet = context.Set(); - var entity = dbSet.FirstOrDefault(e => + var entity = db.LastData.FirstOrDefault(e => e.IdWell == idWell && e.IdCategory == idCategory); + if (entity is null) + return default; + var dto = entity.Adapt(); return dto; } - public int Upsert(int idCategory, Tdto value) + public int Upsert(int idWell, int idCategory, Tdto value) { - //var dbSet = context.Set(); - //var dbSet = db.LastData; var model = value.Adapt(); - dbSet.Update(model); - return context.SaveChanges(); + + var entity = db.LastData.FirstOrDefault(ld => ld.IdWell == idWell && + ld.IdCategory == idCategory); + + if (entity is not null) + { + entity.LastUpdateDate = DateTime.Now; + entity.Data = model; + db.LastData.Update(entity); + } + else + { + var newLastData = new LastData + { + LastUpdateDate = DateTime.Now, + Data = model + }; + db.LastData.Add(newLastData); + } + + return db.SaveChanges(); } } diff --git a/AsbCloudWebApi/Controllers/CrudController.cs b/AsbCloudWebApi/Controllers/CrudController.cs index 3f19871f..2a476cf8 100644 --- a/AsbCloudWebApi/Controllers/CrudController.cs +++ b/AsbCloudWebApi/Controllers/CrudController.cs @@ -37,7 +37,7 @@ namespace AsbCloudWebApi.Controllers if (idCompany is null || !wellService.IsCompanyInvolvedInWell((int)idCompany, idWell)) return Forbid(); - lastDataService.Upsert(idCategory, data); + lastDataService.Upsert(idWell, idCategory, data); return Ok(); } } diff --git a/AsbCloudWebApi/Controllers/FluidController.cs b/AsbCloudWebApi/Controllers/FluidController.cs new file mode 100644 index 00000000..fc6ddb6a --- /dev/null +++ b/AsbCloudWebApi/Controllers/FluidController.cs @@ -0,0 +1,17 @@ +using Microsoft.AspNetCore.Mvc; +using Microsoft.AspNetCore.Authorization; +using AsbCloudApp.Data; +using AsbCloudApp.Services; + +namespace AsbCloudWebApi.Controllers +{ + [Route("api/lastData/{idWell}")] + [ApiController] + [Authorize] + public class FluidController : CrudController + { + public FluidController(ILastDataService lastDataService, + IWellService wellService) : base(lastDataService, wellService) + { } + } +}