forked from ddrilling/AsbCloudServer
new migration
refact entity model wits rep and interface
This commit is contained in:
parent
2e1678f401
commit
3ced1a0e20
@ -13,6 +13,11 @@ namespace AsbCloudApp.Data.GTR
|
|||||||
/// </summary>
|
/// </summary>
|
||||||
public int Id { get; set; }
|
public int Id { get; set; }
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Id телеметрии
|
||||||
|
/// </summary>
|
||||||
|
public int IdTelemetry { get; set; }
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Дата создания записи
|
/// Дата создания записи
|
||||||
/// </summary>
|
/// </summary>
|
||||||
|
41
AsbCloudApp/Services/WITS/IGtrService.cs
Normal file
41
AsbCloudApp/Services/WITS/IGtrService.cs
Normal file
@ -0,0 +1,41 @@
|
|||||||
|
using AsbCloudApp.Data.GTR;
|
||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Threading;
|
||||||
|
using System.Threading.Tasks;
|
||||||
|
|
||||||
|
namespace AsbCloudApp.Services.WITS
|
||||||
|
{
|
||||||
|
#nullable enable
|
||||||
|
/// <summary>
|
||||||
|
/// данные ГТИ
|
||||||
|
/// </summary>
|
||||||
|
public interface IGtrService
|
||||||
|
|
||||||
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// добавить/изменить данные (для панели бурильщика)
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="uid"></param>
|
||||||
|
/// <param name="dtos"></param>
|
||||||
|
/// <param name="token"></param>
|
||||||
|
/// <returns></returns>
|
||||||
|
Task<int> UpdateAsync(string uid, IEnumerable<WitsRecordDto> dtos, CancellationToken token);
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// получить данные для клиента
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="idWell"></param>
|
||||||
|
/// <param name="dateBegin"></param>
|
||||||
|
/// <param name="intervalSec"></param>
|
||||||
|
/// <param name="approxPointsCount">кол-во элементов до которых эти данные прореживаются</param>
|
||||||
|
/// <param name="token"></param>
|
||||||
|
/// <returns></returns>
|
||||||
|
Task<IEnumerable<WitsRecordDto>> GetAsync(int idWell,
|
||||||
|
DateTime dateBegin = default, double intervalSec = 600d,
|
||||||
|
int approxPointsCount = 1024, CancellationToken token = default);
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
|
#nullable disable
|
||||||
|
}
|
@ -57,9 +57,9 @@ namespace AsbCloudDb.Model
|
|||||||
public virtual DbSet<TelemetryWirelineRunOut> TelemetryWirelineRunOut => Set<TelemetryWirelineRunOut>();
|
public virtual DbSet<TelemetryWirelineRunOut> TelemetryWirelineRunOut => Set<TelemetryWirelineRunOut>();
|
||||||
|
|
||||||
// GTR WITS
|
// GTR WITS
|
||||||
public DbSet<WitsFloat> WitsFloat => Set<WitsFloat>();
|
public DbSet<WitsItemFloat> WitsItemFloat => Set<WitsItemFloat>();
|
||||||
public DbSet<WitsInt> WitsInt => Set<WitsInt>();
|
public DbSet<WitsItemInt> WitsItemInt => Set<WitsItemInt>();
|
||||||
public DbSet<WitsStr> WitsStr => Set<WitsStr>();
|
public DbSet<WitsItemString> WitsItemString => Set<WitsItemString>();
|
||||||
|
|
||||||
// WITS
|
// WITS
|
||||||
public DbSet<WITS.Record1> Record1 => Set<WITS.Record1>();
|
public DbSet<WITS.Record1> Record1 => Set<WITS.Record1>();
|
||||||
@ -340,21 +340,21 @@ namespace AsbCloudDb.Model
|
|||||||
.HasJsonConversion();
|
.HasJsonConversion();
|
||||||
});
|
});
|
||||||
|
|
||||||
modelBuilder.Entity<WitsFloat>(entity =>
|
modelBuilder.Entity<WitsItemFloat>(entity =>
|
||||||
{
|
{
|
||||||
entity.HasKey(
|
entity.HasKey(
|
||||||
nameof(ITelemetryData.IdTelemetry),
|
nameof(ITelemetryData.IdTelemetry),
|
||||||
nameof(WitsItemBase<float>.IdRecord),
|
nameof(WitsItemBase<float>.IdRecord),
|
||||||
nameof(WitsItemBase<float>.IdItem));
|
nameof(WitsItemBase<float>.IdItem));
|
||||||
});
|
});
|
||||||
modelBuilder.Entity<WitsInt>(entity =>
|
modelBuilder.Entity<WitsItemInt>(entity =>
|
||||||
{
|
{
|
||||||
entity.HasKey(
|
entity.HasKey(
|
||||||
nameof(ITelemetryData.IdTelemetry),
|
nameof(ITelemetryData.IdTelemetry),
|
||||||
nameof(WitsItemBase<int>.IdRecord),
|
nameof(WitsItemBase<int>.IdRecord),
|
||||||
nameof(WitsItemBase<int>.IdItem));
|
nameof(WitsItemBase<int>.IdItem));
|
||||||
});
|
});
|
||||||
modelBuilder.Entity<WitsStr>(entity =>
|
modelBuilder.Entity<WitsItemString>(entity =>
|
||||||
{
|
{
|
||||||
entity.HasKey(
|
entity.HasKey(
|
||||||
nameof(ITelemetryData.IdTelemetry),
|
nameof(ITelemetryData.IdTelemetry),
|
||||||
|
@ -1,7 +0,0 @@
|
|||||||
using Microsoft.EntityFrameworkCore;
|
|
||||||
using System.ComponentModel.DataAnnotations.Schema;
|
|
||||||
namespace AsbCloudDb.Model.GTR
|
|
||||||
{
|
|
||||||
[Table("t_wits_float"), Comment("таблица данных ГТИ с типом значения float")]
|
|
||||||
public class WitsFloat : WitsItemBase<float> { }
|
|
||||||
}
|
|
@ -1,8 +0,0 @@
|
|||||||
using Microsoft.EntityFrameworkCore;
|
|
||||||
using System.ComponentModel.DataAnnotations.Schema;
|
|
||||||
|
|
||||||
namespace AsbCloudDb.Model.GTR
|
|
||||||
{
|
|
||||||
[Table("t_wits_int"), Comment("таблица данных ГТИ с типом значения int16 int32")]
|
|
||||||
public class WitsInt : WitsItemBase<int>, ITelemetryData { }
|
|
||||||
}
|
|
@ -1,4 +1,5 @@
|
|||||||
using System;
|
using Microsoft.EntityFrameworkCore;
|
||||||
|
using System;
|
||||||
using System.ComponentModel.DataAnnotations.Schema;
|
using System.ComponentModel.DataAnnotations.Schema;
|
||||||
|
|
||||||
namespace AsbCloudDb.Model.GTR
|
namespace AsbCloudDb.Model.GTR
|
||||||
@ -24,7 +25,12 @@ namespace AsbCloudDb.Model.GTR
|
|||||||
public virtual Telemetry? Telemetry { get; set; }
|
public virtual Telemetry? Telemetry { get; set; }
|
||||||
}
|
}
|
||||||
|
|
||||||
|
[Table("t_wits_string"), Comment("таблица данных ГТИ с типом значения string")]
|
||||||
public class WitsItemString : WitsItemBase<string> { }
|
public class WitsItemString : WitsItemBase<string> { }
|
||||||
|
|
||||||
|
[Table("t_wits_float"), Comment("таблица данных ГТИ с типом значения ")]
|
||||||
public class WitsItemFloat : WitsItemBase<float> { }
|
public class WitsItemFloat : WitsItemBase<float> { }
|
||||||
|
|
||||||
|
[Table("t_wits_int"), Comment("таблица данных ГТИ с типом значения int16 int32")]
|
||||||
public class WitsItemInt : WitsItemBase<int> { }
|
public class WitsItemInt : WitsItemBase<int> { }
|
||||||
}
|
}
|
||||||
|
@ -1,8 +0,0 @@
|
|||||||
using Microsoft.EntityFrameworkCore;
|
|
||||||
using System.ComponentModel.DataAnnotations.Schema;
|
|
||||||
|
|
||||||
namespace AsbCloudDb.Model.GTR
|
|
||||||
{
|
|
||||||
[Table("t_wits_string"), Comment("таблица данных ГТИ с типом значения string")]
|
|
||||||
public class WitsStr: WitsItemBase<string> { }
|
|
||||||
}
|
|
@ -48,9 +48,9 @@ namespace AsbCloudDb.Model
|
|||||||
DbSet<WellOperationCategory> WellOperationCategories { get; }
|
DbSet<WellOperationCategory> WellOperationCategories { get; }
|
||||||
DbSet<WellSectionType> WellSectionTypes { get; }
|
DbSet<WellSectionType> WellSectionTypes { get; }
|
||||||
DbSet<WellType> WellTypes { get; }
|
DbSet<WellType> WellTypes { get; }
|
||||||
DbSet<WitsFloat> WitsFloat { get; }
|
DbSet<WitsItemFloat> WitsItemFloat { get; }
|
||||||
DbSet<WitsInt> WitsInt { get; }
|
DbSet<WitsItemInt> WitsItemInt { get; }
|
||||||
DbSet<WitsStr> WitsStr { get; }
|
DbSet<WitsItemString> WitsItemString { get; }
|
||||||
DbSet<Driller> Drillers { get; }
|
DbSet<Driller> Drillers { get; }
|
||||||
DbSet<Schedule> Schedule { get; }
|
DbSet<Schedule> Schedule { get; }
|
||||||
DbSet<OperationValue> OperationValues { get; }
|
DbSet<OperationValue> OperationValues { get; }
|
||||||
|
66
AsbCloudInfrastructure/Repository/GtrWitsRepository.cs
Normal file
66
AsbCloudInfrastructure/Repository/GtrWitsRepository.cs
Normal file
@ -0,0 +1,66 @@
|
|||||||
|
using AsbCloudApp.Data.GTR;
|
||||||
|
using AsbCloudApp.Services;
|
||||||
|
using AsbCloudApp.Services.WITS;
|
||||||
|
using AsbCloudDb.Model;
|
||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Linq;
|
||||||
|
using System.Threading;
|
||||||
|
using System.Threading.Tasks;
|
||||||
|
|
||||||
|
namespace AsbCloudInfrastructure.Repository
|
||||||
|
{
|
||||||
|
#nullable enable
|
||||||
|
public class GtrWitsRepository: IGtrService
|
||||||
|
|
||||||
|
{
|
||||||
|
|
||||||
|
private readonly IAsbCloudDbContext db;
|
||||||
|
private readonly ITelemetryService telemetryService;
|
||||||
|
|
||||||
|
public GtrWitsRepository(
|
||||||
|
IAsbCloudDbContext db,
|
||||||
|
ITelemetryService telemetryService)
|
||||||
|
{
|
||||||
|
this.db = db;
|
||||||
|
this.telemetryService = telemetryService;
|
||||||
|
}
|
||||||
|
|
||||||
|
public async Task<IEnumerable<WitsRecordDto>> GetAsync(int idWell, DateTime dateBegin = default, double intervalSec = 600, int approxPointsCount = 1024, CancellationToken token = default)
|
||||||
|
{
|
||||||
|
var telemetry = telemetryService.GetOrDefaultTelemetryByIdWell(idWell);
|
||||||
|
if (telemetry is null)
|
||||||
|
return Enumerable.Empty<WitsRecordDto>();
|
||||||
|
var timezone = telemetryService.GetTimezone(telemetry.Id);
|
||||||
|
|
||||||
|
var filterByDateEnd = dateBegin != default;
|
||||||
|
DateTimeOffset dateBeginUtc;
|
||||||
|
if (dateBegin == default)
|
||||||
|
{
|
||||||
|
dateBeginUtc = telemetryService.GetLastTelemetryDate(telemetry.Id)
|
||||||
|
.ToUtcDateTimeOffset(timezone.Hours);
|
||||||
|
if (dateBeginUtc != default)
|
||||||
|
dateBeginUtc = dateBeginUtc.AddSeconds(-intervalSec);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
dateBeginUtc = dateBegin.ToUtcDateTimeOffset(timezone.Hours);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (dateBeginUtc == default)
|
||||||
|
dateBeginUtc = DateTime.UtcNow.AddSeconds(-intervalSec);
|
||||||
|
var dateEnd = dateBeginUtc.AddSeconds(intervalSec);
|
||||||
|
|
||||||
|
//временная заглушка(для билда без ошибок)
|
||||||
|
return Enumerable.Empty<WitsRecordDto>();
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
public Task<int> UpdateAsync(string uid, IEnumerable<WitsRecordDto> dtos, CancellationToken token)
|
||||||
|
{
|
||||||
|
throw new NotImplementedException();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
#nullable disable
|
||||||
|
}
|
Loading…
Reference in New Issue
Block a user