CS2-43: Доработанный контроллер, Dto и EF модели для 'Последних данных'

This commit is contained in:
KharchenkoVV 2021-08-02 12:23:18 +05:00
parent 4f703fb53e
commit 4d08e0e562
12 changed files with 232 additions and 18 deletions

View File

@ -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; }
}
}

View File

@ -3,6 +3,6 @@
public interface ILastDataService<Tdto>
{
Tdto Get(int idWell, int idCategory);
int Upsert(int idCategory, Tdto value);
int Upsert(int idWell, int idCategory, Tdto value);
}
}

View File

@ -31,6 +31,7 @@ namespace AsbCloudDb.Model
public virtual DbSet<WellSection> WellSections { get; set; }
public virtual DbSet<WellOperation> WellOperations { get; set; }
public virtual DbSet<WellType> WellTypes { get; set; }
public virtual DbSet<LastData> LastData { get; set; }
//var options = new DbContextOptionsBuilder<AsbCloudDbContext>()
// .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,

View File

@ -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; }
}
}

View File

@ -28,6 +28,7 @@ namespace AsbCloudDb.Model
DbSet<WellSection> WellSections { get; set; }
DbSet<WellOperation> WellOperations { get; set; }
DbSet<WellType> WellTypes { get; set; }
DbSet<LastData> LastData { get; set; }
int SaveChanges();
int SaveChanges(bool acceptAllChangesOnSuccess);

View File

@ -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; }
}
}

View File

@ -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; }
}
}

View File

@ -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; }
}
}

View File

@ -37,6 +37,10 @@ namespace AsbCloudInfrastructure
services.AddTransient<IAnalyticsService, AnalyticsService>();
services.AddTransient<IFileService, FileService>();
services.AddTransient<ILastDataService<FluidDataDto>, LastDataService<FluidDataDto, FluidData>>();
return services;
}

View File

@ -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<Tdto, TModel> : ILastDataService<Tdto>
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<TModel>();
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<Tdto>();
return dto;
}
public int Upsert(int idCategory, Tdto value)
public int Upsert(int idWell, int idCategory, Tdto value)
{
//var dbSet = context.Set<TModel>();
//var dbSet = db.LastData;
var model = value.Adapt<TModel>();
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();
}
}

View File

@ -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();
}
}

View File

@ -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<FluidDataDto>
{
public FluidController(ILastDataService<FluidDataDto> lastDataService,
IWellService wellService) : base(lastDataService, wellService)
{ }
}
}