forked from ddrilling/AsbCloudServer
CS2-43: Доработанный контроллер, Dto и EF модели для 'Последних данных'
This commit is contained in:
parent
4f703fb53e
commit
4d08e0e562
33
AsbCloudApp/Data/FluidDataDto.cs
Normal file
33
AsbCloudApp/Data/FluidDataDto.cs
Normal 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; }
|
||||||
|
}
|
||||||
|
}
|
@ -3,6 +3,6 @@
|
|||||||
public interface ILastDataService<Tdto>
|
public interface ILastDataService<Tdto>
|
||||||
{
|
{
|
||||||
Tdto Get(int idWell, int idCategory);
|
Tdto Get(int idWell, int idCategory);
|
||||||
int Upsert(int idCategory, Tdto value);
|
int Upsert(int idWell, int idCategory, Tdto value);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -31,6 +31,7 @@ namespace AsbCloudDb.Model
|
|||||||
public virtual DbSet<WellSection> WellSections { get; set; }
|
public virtual DbSet<WellSection> WellSections { get; set; }
|
||||||
public virtual DbSet<WellOperation> WellOperations { get; set; }
|
public virtual DbSet<WellOperation> WellOperations { get; set; }
|
||||||
public virtual DbSet<WellType> WellTypes { get; set; }
|
public virtual DbSet<WellType> WellTypes { get; set; }
|
||||||
|
public virtual DbSet<LastData> LastData { get; set; }
|
||||||
|
|
||||||
//var options = new DbContextOptionsBuilder<AsbCloudDbContext>()
|
//var options = new DbContextOptionsBuilder<AsbCloudDbContext>()
|
||||||
// .UseNpgsql("Host=localhost;Database=postgres;Username=postgres;Password=q;Persist Security Info=True")
|
// .UseNpgsql("Host=localhost;Database=postgres;Username=postgres;Password=q;Persist Security Info=True")
|
||||||
@ -367,7 +368,7 @@ namespace AsbCloudDb.Model
|
|||||||
IdOperation = 10,
|
IdOperation = 10,
|
||||||
UnixDate = 1626870370,
|
UnixDate = 1626870370,
|
||||||
DurationSec = 2,
|
DurationSec = 2,
|
||||||
OperationStartDepth = null,
|
OperationStartDepth = 206,
|
||||||
OperationEndDepth = 206,
|
OperationEndDepth = 206,
|
||||||
IsWellDepthIncreasing = false,
|
IsWellDepthIncreasing = false,
|
||||||
IsWellDepthDecreasing = false,
|
IsWellDepthDecreasing = false,
|
||||||
|
67
AsbCloudDb/Model/FluidData.cs
Normal file
67
AsbCloudDb/Model/FluidData.cs
Normal 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; }
|
||||||
|
}
|
||||||
|
}
|
@ -28,6 +28,7 @@ namespace AsbCloudDb.Model
|
|||||||
DbSet<WellSection> WellSections { get; set; }
|
DbSet<WellSection> WellSections { get; set; }
|
||||||
DbSet<WellOperation> WellOperations { get; set; }
|
DbSet<WellOperation> WellOperations { get; set; }
|
||||||
DbSet<WellType> WellTypes { get; set; }
|
DbSet<WellType> WellTypes { get; set; }
|
||||||
|
DbSet<LastData> LastData { get; set; }
|
||||||
|
|
||||||
int SaveChanges();
|
int SaveChanges();
|
||||||
int SaveChanges(bool acceptAllChangesOnSuccess);
|
int SaveChanges(bool acceptAllChangesOnSuccess);
|
||||||
|
27
AsbCloudDb/Model/LastData.cs
Normal file
27
AsbCloudDb/Model/LastData.cs
Normal 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; }
|
||||||
|
}
|
||||||
|
}
|
28
AsbCloudDb/Model/MudDiagramData.cs
Normal file
28
AsbCloudDb/Model/MudDiagramData.cs
Normal 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; }
|
||||||
|
}
|
||||||
|
}
|
23
AsbCloudDb/Model/NnbData.cs
Normal file
23
AsbCloudDb/Model/NnbData.cs
Normal 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; }
|
||||||
|
}
|
||||||
|
}
|
@ -36,6 +36,10 @@ namespace AsbCloudInfrastructure
|
|||||||
services.AddTransient<IReportService, ReportService>();
|
services.AddTransient<IReportService, ReportService>();
|
||||||
services.AddTransient<IAnalyticsService, AnalyticsService>();
|
services.AddTransient<IAnalyticsService, AnalyticsService>();
|
||||||
services.AddTransient<IFileService, FileService>();
|
services.AddTransient<IFileService, FileService>();
|
||||||
|
|
||||||
|
|
||||||
|
services.AddTransient<ILastDataService<FluidDataDto>, LastDataService<FluidDataDto, FluidData>>();
|
||||||
|
|
||||||
|
|
||||||
return services;
|
return services;
|
||||||
}
|
}
|
||||||
|
@ -1,43 +1,56 @@
|
|||||||
using System.Collections.Generic;
|
using System;
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
using AsbCloudDb.Model;
|
using AsbCloudDb.Model;
|
||||||
using AsbCloudApp.Services;
|
using AsbCloudApp.Services;
|
||||||
using Mapster;
|
using Mapster;
|
||||||
using Microsoft.EntityFrameworkCore;
|
|
||||||
using Microsoft.Extensions.Configuration;
|
|
||||||
|
|
||||||
namespace AsbCloudInfrastructure.Services
|
namespace AsbCloudInfrastructure.Services
|
||||||
{
|
{
|
||||||
public class LastDataService<Tdto, TModel> : ILastDataService<Tdto>
|
public class LastDataService<Tdto, TModel> : ILastDataService<Tdto>
|
||||||
where TModel : class, IIdWellCategory
|
|
||||||
{
|
{
|
||||||
private readonly DbContext context;
|
|
||||||
private readonly IAsbCloudDbContext db;
|
private readonly IAsbCloudDbContext db;
|
||||||
|
|
||||||
//private Dictioanary dict =
|
public LastDataService(IAsbCloudDbContext db)
|
||||||
|
|
||||||
public LastDataService(IConfiguration configuration, IAsbCloudDbContext db)
|
|
||||||
{
|
{
|
||||||
this.db = db;
|
this.db = db;
|
||||||
}
|
}
|
||||||
|
|
||||||
public Tdto Get(int idWell, int idCategory)
|
public Tdto Get(int idWell, int idCategory)
|
||||||
{
|
{
|
||||||
var dbSet = context.Set<TModel>();
|
var entity = db.LastData.FirstOrDefault(e =>
|
||||||
var entity = dbSet.FirstOrDefault(e =>
|
|
||||||
e.IdWell == idWell && e.IdCategory == idCategory);
|
e.IdWell == idWell && e.IdCategory == idCategory);
|
||||||
|
|
||||||
|
if (entity is null)
|
||||||
|
return default;
|
||||||
|
|
||||||
var dto = entity.Adapt<Tdto>();
|
var dto = entity.Adapt<Tdto>();
|
||||||
return dto;
|
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>();
|
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();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -37,7 +37,7 @@ namespace AsbCloudWebApi.Controllers
|
|||||||
if (idCompany is null || !wellService.IsCompanyInvolvedInWell((int)idCompany, idWell))
|
if (idCompany is null || !wellService.IsCompanyInvolvedInWell((int)idCompany, idWell))
|
||||||
return Forbid();
|
return Forbid();
|
||||||
|
|
||||||
lastDataService.Upsert(idCategory, data);
|
lastDataService.Upsert(idWell, idCategory, data);
|
||||||
return Ok();
|
return Ok();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
17
AsbCloudWebApi/Controllers/FluidController.cs
Normal file
17
AsbCloudWebApi/Controllers/FluidController.cs
Normal 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)
|
||||||
|
{ }
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in New Issue
Block a user