new migration

refact entity model
wits rep and interface
This commit is contained in:
eugeniy_ivanov 2023-04-04 21:21:06 +05:00
parent 2e1678f401
commit 3ced1a0e20
9 changed files with 129 additions and 34 deletions

View File

@ -13,6 +13,11 @@ namespace AsbCloudApp.Data.GTR
/// </summary>
public int Id { get; set; }
/// <summary>
/// Id телеметрии
/// </summary>
public int IdTelemetry { get; set; }
/// <summary>
/// Дата создания записи
/// </summary>

View 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
}

View File

@ -57,9 +57,9 @@ namespace AsbCloudDb.Model
public virtual DbSet<TelemetryWirelineRunOut> TelemetryWirelineRunOut => Set<TelemetryWirelineRunOut>();
// GTR WITS
public DbSet<WitsFloat> WitsFloat => Set<WitsFloat>();
public DbSet<WitsInt> WitsInt => Set<WitsInt>();
public DbSet<WitsStr> WitsStr => Set<WitsStr>();
public DbSet<WitsItemFloat> WitsItemFloat => Set<WitsItemFloat>();
public DbSet<WitsItemInt> WitsItemInt => Set<WitsItemInt>();
public DbSet<WitsItemString> WitsItemString => Set<WitsItemString>();
// WITS
public DbSet<WITS.Record1> Record1 => Set<WITS.Record1>();
@ -340,21 +340,21 @@ namespace AsbCloudDb.Model
.HasJsonConversion();
});
modelBuilder.Entity<WitsFloat>(entity =>
{
modelBuilder.Entity<WitsItemFloat>(entity =>
{
entity.HasKey(
nameof(ITelemetryData.IdTelemetry),
nameof(WitsItemBase<float>.IdRecord),
nameof(WitsItemBase<float>.IdItem));
});
modelBuilder.Entity<WitsInt>(entity =>
modelBuilder.Entity<WitsItemInt>(entity =>
{
entity.HasKey(
nameof(ITelemetryData.IdTelemetry),
nameof(WitsItemBase<int>.IdRecord),
nameof(WitsItemBase<int>.IdItem));
});
modelBuilder.Entity<WitsStr>(entity =>
modelBuilder.Entity<WitsItemString>(entity =>
{
entity.HasKey(
nameof(ITelemetryData.IdTelemetry),

View File

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

View File

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

View File

@ -1,4 +1,5 @@
using System;
using Microsoft.EntityFrameworkCore;
using System;
using System.ComponentModel.DataAnnotations.Schema;
namespace AsbCloudDb.Model.GTR
@ -24,7 +25,12 @@ namespace AsbCloudDb.Model.GTR
public virtual Telemetry? Telemetry { get; set; }
}
[Table("t_wits_string"), Comment("таблица данных ГТИ с типом значения string")]
public class WitsItemString : WitsItemBase<string> { }
[Table("t_wits_float"), Comment("таблица данных ГТИ с типом значения ")]
public class WitsItemFloat : WitsItemBase<float> { }
[Table("t_wits_int"), Comment("таблица данных ГТИ с типом значения int16 int32")]
public class WitsItemInt : WitsItemBase<int> { }
}

View File

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

View File

@ -48,9 +48,9 @@ namespace AsbCloudDb.Model
DbSet<WellOperationCategory> WellOperationCategories { get; }
DbSet<WellSectionType> WellSectionTypes { get; }
DbSet<WellType> WellTypes { get; }
DbSet<WitsFloat> WitsFloat { get; }
DbSet<WitsInt> WitsInt { get; }
DbSet<WitsStr> WitsStr { get; }
DbSet<WitsItemFloat> WitsItemFloat { get; }
DbSet<WitsItemInt> WitsItemInt { get; }
DbSet<WitsItemString> WitsItemString { get; }
DbSet<Driller> Drillers { get; }
DbSet<Schedule> Schedule { get; }
DbSet<OperationValue> OperationValues { get; }

View 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
}