NotCompleted LasdData Weekend

This commit is contained in:
Фролов 2021-08-27 17:55:22 +05:00
parent f744b49824
commit 843dd276a3
16 changed files with 153 additions and 318 deletions

View File

@ -1,38 +0,0 @@
using System;
namespace AsbCloudApp.Data
{
public class FluidDataDto
{
public int Key { get; set; }
public DateTime LastUpdate { get; set; } = DateTime.Now;
public string Name { get; set; }
public double Temperature { get; set; }
public double Density { get; set; }
public double ConditionalViscosity { get; set; }
public double R300 { get; set; }
public double R600 { get; set; }
public double R3r6 { get; set; }
public double DnsDpa { get; set; }
public double PlasticViscocity { get; set; }
public double SnsDpa { get; set; }
public double R3r649С { get; set; }
public double Dns49Cdpa { get; set; }
public double PlasticViscocity49c { get; set; }
public double Sns49Cdpa { get; set; }
public double Mbt { get; set; }
public double Sand { get; set; }
public double Filtering { get; set; }
public double Crust { get; set; }
public double Ktk { get; set; }
public double Ph { get; set; }
public double Hardness { get; set; }
public double Chlorides { get; set; }
public double Pf { get; set; }
public double Mf { get; set; }
public double Pm { get; set; }
public double FluidSolidPhase { get; set; }
public double Grease { get; set; }
public double CalciumCarbonate { get; set; }
}
}

View File

@ -0,0 +1,22 @@
using System;
using System.Collections.Generic;
namespace AsbCloudApp.Data
{
public class LastDataDto
{
public int Id { get; set; }
public int IdWell { get; set; }
public int IdCategory { get; set; }
public string CategoryName { get; set; }
public DateTime DateInsert { get; set; }
public DateTime DateModify { get; set; }
public Dictionary<string, object> Data { get; set; }
}
}

View File

@ -1,32 +0,0 @@
using System;
namespace AsbCloudApp.Data
{
public class MudDiagramDataDto
{
public int Key { get; set; }
public DateTime LastUpdate { get; set; } = DateTime.Now;
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 Ethane { 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

@ -1,28 +0,0 @@
using System;
namespace AsbCloudApp.Data
{
public class NnbDataDto
{
public int Key { get; set; }
public DateTime LastUpdate { get; set; } = DateTime.Now;
public double Depth { get; set; }
public double ZenithAngle { get; set; }
public double MagneticAzimuth { 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

@ -1,13 +1,18 @@
using System.Threading;
using AsbCloudApp.Data;
using System.Collections.Generic;
using System.Threading;
using System.Threading.Tasks;
namespace AsbCloudApp.Services
{
public interface ILastDataService<Tdto>
public interface ILastDataService
{
Task<Tdto> GetAsync(int idWell, int idCategory,
CancellationToken token);
Task<int> UpsertAsync(int idWell, int idCategory, Tdto value,
CancellationToken token);
Task<Dictionary<int, string>> GetCategoriesAsync(CancellationToken token);
Task<IEnumerable<LastDataDto>> GetHisoryAsync(int idWell, int idCategory, CancellationToken token);
Task<IEnumerable<LastDataDto>> GetAllLastAsync(int idWell, CancellationToken token);
Task<int> InsertAsync(int idWell, LastDataDto data, CancellationToken token);
Task<int> UpdateAsync(int idWell, LastDataDto data, CancellationToken token);
Task<int> MarkAsDeleteAsync(int idWell, int idData, CancellationToken token);
Task<int> DeleteAsync(int idWell, int idData, CancellationToken token);
}
}

View File

@ -1,38 +0,0 @@
using System;
namespace AsbCloudDb.Model
{
public class FluidData
{
public int Key { get; set; }
public DateTime LastUpdate { get; set; } = DateTime.Now;
public string Name { get; set; }
public double Temperature { get; set; }
public double Density { get; set; }
public double ConditionalViscosity { get; set; }
public double R300 { get; set; }
public double R600 { get; set; }
public double R3r6 { get; set; }
public double DnsDpa { get; set; }
public double PlasticViscocity { get; set; }
public double SnsDpa { get; set; }
public double R3r649С { get; set; }
public double Dns49Cdpa { get; set; }
public double PlasticViscocity49c { get; set; }
public double Sns49Cdpa { get; set; }
public double Mbt { get; set; }
public double Sand { get; set; }
public double Filtering { get; set; }
public double Crust { get; set; }
public double Ktk { get; set; }
public double Ph { get; set; }
public double Hardness { get; set; }
public double Chlorides { get; set; }
public double Pf { get; set; }
public double Mf { get; set; }
public double Pm { get; set; }
public double FluidSolidPhase { get; set; }
public double Grease { get; set; }
public double CalciumCarbonate { get; set; }
}
}

View File

@ -1,4 +1,6 @@
using Microsoft.EntityFrameworkCore;
using System;
using System.Collections.Generic;
using System.ComponentModel.DataAnnotations;
using System.ComponentModel.DataAnnotations.Schema;
using System.Text.Json.Serialization;
@ -18,8 +20,14 @@ namespace AsbCloudDb.Model
[Column("id_category"), Comment("id категории")]
public int IdCategory { get; set; }
[Column("date_insert"), Comment("время добавления")]
public DateTime DateInsert { get; set; }
[Column("date_modify"), Comment("время изменения")]
public DateTime DateModify { get; set; }
[Column("data", TypeName = "jsonb"), Comment("Данные таблицы последних данных")]
public object Data { get; set; }
public Dictionary<string, object> Data { get; set; }
[JsonIgnore]
[ForeignKey(nameof(IdWell))]
@ -27,6 +35,6 @@ namespace AsbCloudDb.Model
[JsonIgnore]
[ForeignKey(nameof(IdCategory))]
public virtual LastDataCategory LastDataCategory { get; set; }
public virtual LastDataCategory Category { get; set; }
}
}

View File

@ -1,32 +0,0 @@
using System;
namespace AsbCloudDb.Model
{
public class MudDiagramData
{
public int Key { get; set; }
public DateTime LastUpdate { get; set; } = DateTime.Now;
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 Ethane { 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

@ -1,28 +0,0 @@
using System;
namespace AsbCloudDb.Model
{
public class NnbData
{
public int Key { get; set; }
public DateTime LastUpdate { get; set; } = DateTime.Now;
public double Depth { get; set; }
public double ZenithAngle { get; set; }
public double MagneticAzimuth { 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

@ -38,10 +38,7 @@ namespace AsbCloudInfrastructure
services.AddTransient<IFileService, FileService>();
services.AddTransient<IWellOperationService, WellOperationService>();
services.AddTransient<IWellOperationsStatService, WellOperationsStatService>();
services.AddTransient<ILastDataService<FluidDataDto>, LastDataService<FluidDataDto, FluidData>>();
services.AddTransient<ILastDataService<MudDiagramDataDto>, LastDataService<MudDiagramDataDto, MudDiagramData>>();
services.AddTransient<ILastDataService<NnbDataDto>, LastDataService<NnbDataDto, NnbData>>();
services.AddTransient<ILastDataService, LastDataService>();
return services;
}

View File

@ -148,6 +148,9 @@ namespace AsbCloudInfrastructure.Services.Cache
return result;
}
public Task<IEnumerable<TEntity>> WhereAsync(CancellationToken token = default)
=> WhereAsync(default, RefreshMode.IfResultEmpty, token);
public Task<IEnumerable<TEntity>> WhereAsync(Func<TEntity, bool> predicate, CancellationToken token = default)
=> WhereAsync(predicate, RefreshMode.IfResultEmpty, token);

View File

@ -1,64 +1,69 @@
using AsbCloudApp.Services;
using AsbCloudApp.Data;
using AsbCloudApp.Services;
using AsbCloudDb.Model;
using AsbCloudInfrastructure.Services.Cache;
using Mapster;
using Microsoft.EntityFrameworkCore;
using System.Text.Json;
using System.Collections.Generic;
using System.Linq;
using System.Threading;
using System.Threading.Tasks;
namespace AsbCloudInfrastructure.Services
{
public class LastDataService<Tdto, TModel> : ILastDataService<Tdto> where Tdto : new()
public class LastDataService : ILastDataService
{
private readonly IAsbCloudDbContext db;
private readonly CacheTable<LastDataCategory> cacheCategories;
public LastDataService(IAsbCloudDbContext db)
public LastDataService(IAsbCloudDbContext db, Cache.CacheDb cacheDb)
{
this.db = db;
cacheCategories = cacheDb.GetCachedTable<LastDataCategory>((DbContext)db);
}
public async Task<Tdto> GetAsync(int idWell, int idCategory,
CancellationToken token = default)
public async Task<Dictionary<int, string>> GetCategoriesAsync(CancellationToken token)
{
var entity = await db.LastData.AsNoTracking().FirstOrDefaultAsync(e =>
e.IdWell == idWell && e.IdCategory == idCategory, token)
.ConfigureAwait(false);
if (entity is null)
return new Tdto();
var dto = JsonSerializer.Deserialize<Tdto>(entity.Data.ToString());
var entities = await cacheCategories.WhereAsync(token).ConfigureAwait(false);
var dto = entities.ToDictionary(e=>e.Id, e=>e.Name);
return dto;
}
public async Task<int> UpsertAsync(int idWell, int idCategory,
Tdto value, CancellationToken token = default)
public async Task<IEnumerable<LastDataDto>> GetAllLastAsync(int idWell, CancellationToken token)
{
var model = value.Adapt<TModel>();
var entity = await db.LastData.AsNoTracking()
.FirstOrDefaultAsync(ld => ld.IdWell == idWell &&
ld.IdCategory == idCategory, token)
var entities = await db.LastData
.Include(e => e.Category)
.Where(e => e.IdWell == idWell)
.AsNoTracking()
.ToListAsync(token)
.ConfigureAwait(false);
var dtos = entities.Adapt<LastDataDto, LastData>((d, s) => d.CategoryName = s.Category.Name);
return dtos;
}
if (entity is not null)
{
entity.Data = model;
db.LastData.Update(entity);
}
else
{
var newLastData = new LastData
{
IdWell = idWell,
IdCategory = idCategory,
Data = model
};
db.LastData.Add(newLastData);
}
public Task<IEnumerable<LastDataDto>> GetHisoryAsync(int idWell, int idCategory, CancellationToken token)
{
throw new System.NotImplementedException();
}
return await db.SaveChangesAsync(token);
public Task<int> InsertAsync(int idWell, LastDataDto data, CancellationToken token)
{
throw new System.NotImplementedException();
}
public Task<int> MarkAsDeleteAsync(int idWell, int idData, CancellationToken token)
{
throw new System.NotImplementedException();
}
public Task<int> UpdateAsync(int idWell, LastDataDto data, CancellationToken token)
{
throw new System.NotImplementedException();
}
public Task<int> DeleteAsync(int idWell, int idData, CancellationToken token)
{
throw new System.NotImplementedException();
}
}
}

View File

@ -1,17 +0,0 @@
using AsbCloudApp.Data;
using AsbCloudApp.Services;
using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Mvc;
namespace AsbCloudWebApi.Controllers
{
[Route("api/well/{idWell}/fluidLastData")]
[ApiController]
[Authorize]
public class FluidController : LastDataController<FluidDataDto>
{
public FluidController(ILastDataService<FluidDataDto> lastDataService,
IWellService wellService) : base(lastDataService, wellService)
{ }
}
}

View File

@ -1,4 +1,5 @@
using AsbCloudApp.Services;
using AsbCloudApp.Data;
using AsbCloudApp.Services;
using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Mvc;
using System.Threading;
@ -8,45 +9,86 @@ namespace AsbCloudWebApi.Controllers
{
[ApiController]
[Authorize]
public abstract class LastDataController<T> : ControllerBase where T : class
[Route("api/well/{idWell}/lastData")]
public class LastDataController: ControllerBase
{
private readonly ILastDataService<T> lastDataService;
private readonly ILastDataService lastDataService;
private readonly IWellService wellService;
public LastDataController(ILastDataService<T> lastDataService, IWellService wellService)
public LastDataController(ILastDataService lastDataService, IWellService wellService)
{
this.lastDataService = lastDataService;
this.wellService = wellService;
}
[HttpGet]
public async Task<IActionResult> GetAsync([FromRoute] int idWell,
[FromQuery] int idCategory, CancellationToken token = default)
[Route("categories")]
public async Task<IActionResult> GetCategoriesAsync([FromRoute] int idWell, CancellationToken token = default)
{
int? idCompany = User.GetCompanyId();
if (idCompany is null || !await wellService.IsCompanyInvolvedInWellAsync((int)idCompany,
idWell, token).ConfigureAwait(false))
if (!await CanUserAccessToWellAsync(idWell, token).ConfigureAwait(false))
return Forbid();
var result = await lastDataService.GetAsync(idWell,
idCategory, token).ConfigureAwait(false);
var result = await lastDataService.GetCategoriesAsync(token).ConfigureAwait(false);
return Ok(result);
}
[HttpGet]
[Route("last")]
public async Task<IActionResult> GetAllLastAsync([FromRoute] int idWell, CancellationToken token = default)
{
if (!await CanUserAccessToWellAsync(idWell, token).ConfigureAwait(false))
return Forbid();
var result = await lastDataService.GetAllLastAsync(idWell, token).ConfigureAwait(false);
return Ok(result);
}
[HttpGet]
[Route("{idCategory}/history")]
public async Task<IActionResult> GetHisoryAsync([FromRoute] int idWell, [FromQuery] int idCategory, CancellationToken token = default)
{
if (!await CanUserAccessToWellAsync(idWell, token).ConfigureAwait(false))
return Forbid();
var result = await lastDataService.GetHisoryAsync(idWell, idCategory, token).ConfigureAwait(false);
return Ok(result);
}
[HttpPost]
public async Task<IActionResult> PutAsync([FromRoute] int idWell,
[FromQuery] int idCategory, T data, CancellationToken token = default)
public async Task<IActionResult> InsertAsync([FromRoute] int idWell, LastDataDto data, CancellationToken token = default)
{
int? idCompany = User.GetCompanyId();
if (idCompany is null || !await wellService.IsCompanyInvolvedInWellAsync((int)idCompany,
idWell, token).ConfigureAwait(false))
if (!await CanUserAccessToWellAsync(idWell, token).ConfigureAwait(false))
return Forbid();
await lastDataService.UpsertAsync(idWell,
idCategory, data, token).ConfigureAwait(false);
return Ok();
var result = await lastDataService.InsertAsync(idWell, data, token).ConfigureAwait(false);
return Ok(result);
}
[HttpPut]
public async Task<IActionResult> UpdateAsync([FromRoute] int idWell, LastDataDto data, CancellationToken token = default)
{
if (!await CanUserAccessToWellAsync(idWell, token).ConfigureAwait(false))
return Forbid();
var result = await lastDataService.UpdateAsync(idWell, data, token).ConfigureAwait(false);
return Ok(result);
}
[HttpDelete]
public async Task<IActionResult> MarkAsDeleteAsync([FromRoute] int idWell, [FromRoute] int idData, CancellationToken token = default)
{
if (!await CanUserAccessToWellAsync(idWell, token).ConfigureAwait(false))
return Forbid();
var result = await lastDataService.MarkAsDeleteAsync(idWell, idData, token).ConfigureAwait(false);
return Ok(result);
}
private async Task<bool> CanUserAccessToWellAsync(int idWell, CancellationToken token = default)
{
int? idCompany = User.GetCompanyId();
return idCompany is not null && await wellService.IsCompanyInvolvedInWellAsync((int)idCompany,
idWell, token).ConfigureAwait(false);
}
}
}

View File

@ -1,17 +0,0 @@
using AsbCloudApp.Data;
using AsbCloudApp.Services;
using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Mvc;
namespace AsbCloudWebApi.Controllers
{
[Route("api/well/{idWell}/mudLastData")]
[ApiController]
[Authorize]
public class MudDiagramController : LastDataController<MudDiagramDataDto>
{
public MudDiagramController(ILastDataService<MudDiagramDataDto> lastDataService,
IWellService wellService) : base(lastDataService, wellService)
{ }
}
}

View File

@ -1,17 +0,0 @@
using AsbCloudApp.Data;
using AsbCloudApp.Services;
using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Mvc;
namespace AsbCloudWebApi.Controllers
{
[Route("api/well/{idWell}/nnbLastData")]
[ApiController]
[Authorize]
public class NnbDataController : LastDataController<NnbDataDto>
{
public NnbDataController(ILastDataService<NnbDataDto> lastDataService,
IWellService wellService) : base(lastDataService, wellService)
{ }
}
}