forked from ddrilling/AsbCloudServer
Reorganize dtos
This commit is contained in:
parent
24b0bc9d8c
commit
c96bf87f17
@ -4,8 +4,4 @@
|
||||
<TargetFramework>net6.0</TargetFramework>
|
||||
</PropertyGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<Folder Include="Data\WITS\" />
|
||||
</ItemGroup>
|
||||
|
||||
</Project>
|
||||
|
@ -1,4 +1,4 @@
|
||||
using AsbCloudApp.Data;
|
||||
using AsbCloudApp.Data.SAUB;
|
||||
using System.Collections.Generic;
|
||||
|
||||
namespace AsbCloudApp.Comparators
|
||||
|
@ -4,7 +4,8 @@ namespace AsbCloudApp.Data
|
||||
{
|
||||
public interface ITelemetryData
|
||||
{
|
||||
int IdTelemetry { get; set; }
|
||||
DateTime Date { get; set; }
|
||||
int IdTelemetry { get; set; }
|
||||
|
||||
DateTime DateTime { get; set; }
|
||||
}
|
||||
}
|
||||
|
@ -1,4 +1,4 @@
|
||||
namespace AsbCloudApp.Data
|
||||
namespace AsbCloudApp.Data.SAUB
|
||||
{
|
||||
public class EventDto : IId
|
||||
{
|
2
AsbCloudApp/Data/SAUB/Readme.md
Normal file
2
AsbCloudApp/Data/SAUB/Readme.md
Normal file
@ -0,0 +1,2 @@
|
||||
Папка содержит dto для получаемые от панели оператора САУБ.
|
||||
Данные WITS вынесены в отдельную папку.
|
@ -1,13 +1,18 @@
|
||||
using System;
|
||||
|
||||
namespace AsbCloudApp.Data
|
||||
namespace AsbCloudApp.Data.SAUB
|
||||
{
|
||||
/// <summary>
|
||||
/// Сообщение получаемое по телеметрии и отправляемое в frontend
|
||||
/// </summary>
|
||||
public class TelemetryDataSaubDto : ITelemetryData
|
||||
{
|
||||
public DateTime Date { get; set; }
|
||||
public DateTime DateTime { get; set; }
|
||||
public DateTime Date // TODO: remove this legacy after all panels updated
|
||||
{
|
||||
get { return DateTime; }
|
||||
set { DateTime = value; }
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Режим работы САУБ:
|
@ -1,15 +1,16 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace AsbCloudApp.Data
|
||||
namespace AsbCloudApp.Data.SAUB
|
||||
{
|
||||
public class TelemetryDataSpinDto : ITelemetryData
|
||||
{
|
||||
public int IdTelemetry { get; set; }
|
||||
public DateTime Date { get; set; }
|
||||
public DateTime DateTime { get; set; }
|
||||
public DateTime Date // TODO: remove this legacy after all panels updated
|
||||
{
|
||||
get { return DateTime; }
|
||||
set { DateTime = value; }
|
||||
}
|
||||
public float? TopDriveSpeed { get; set; }
|
||||
public float? TopDriveSpeedMin { get; set; }
|
||||
public float? TopDriveSpeedMax { get; set; }
|
@ -1,6 +1,6 @@
|
||||
using System;
|
||||
|
||||
namespace AsbCloudApp.Data
|
||||
namespace AsbCloudApp.Data.SAUB
|
||||
{
|
||||
public class TelemetryInfoDto
|
||||
{
|
@ -1,6 +1,6 @@
|
||||
using System;
|
||||
|
||||
namespace AsbCloudApp.Data
|
||||
namespace AsbCloudApp.Data.SAUB
|
||||
{
|
||||
/// <summary>
|
||||
/// Сообщение получаемое от телеметрии с буровой
|
@ -1,4 +1,4 @@
|
||||
namespace AsbCloudApp.Data
|
||||
namespace AsbCloudApp.Data.SAUB
|
||||
{
|
||||
public class TelemetryUserDto : IId
|
||||
{
|
@ -1,4 +1,5 @@
|
||||
using System.Text.Json.Serialization;
|
||||
using AsbCloudApp.Data.SAUB;
|
||||
using System.Text.Json.Serialization;
|
||||
|
||||
namespace AsbCloudApp.Data
|
||||
{
|
||||
|
2
AsbCloudApp/Data/WITS/Readme.md
Normal file
2
AsbCloudApp/Data/WITS/Readme.md
Normal file
@ -0,0 +1,2 @@
|
||||
Данные WITS см.: http://www.petrospec-technologies.com/resource/wits_doc.htm.
|
||||
Дополнительное описание параметров в сборке AsbWitsInf.dll
|
@ -1,13 +1,18 @@
|
||||
using System;
|
||||
|
||||
namespace AsbCloudApp.Data.WITS
|
||||
{
|
||||
/// <summary>
|
||||
/// This is base class for all WITS-0 records
|
||||
/// </summary>
|
||||
public abstract class RecordBaseDto
|
||||
public abstract class RecordBaseDto: ITelemetryData
|
||||
{
|
||||
public int Id { get; set; }
|
||||
|
||||
|
||||
public int IdTelemetry { get; set; }
|
||||
|
||||
public DateTime DateTime { get; set; }
|
||||
|
||||
public int TimeStamp { get; set; }
|
||||
|
||||
/// <summary>
|
||||
@ -83,7 +88,7 @@ namespace AsbCloudApp.Data.WITS
|
||||
/// ValueType = "L"
|
||||
/// </summary>
|
||||
|
||||
public int? Date { get; set; }
|
||||
public int? Date_ { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// RecordId = 1,
|
||||
@ -114,6 +119,5 @@ namespace AsbCloudApp.Data.WITS
|
||||
/// </summary>
|
||||
|
||||
public short? Actcod { get; set; }
|
||||
|
||||
}
|
||||
}
|
@ -1,4 +1,4 @@
|
||||
using AsbCloudApp.Data;
|
||||
using AsbCloudApp.Data.SAUB;
|
||||
using System.Collections.Generic;
|
||||
using System.Threading;
|
||||
using System.Threading.Tasks;
|
||||
|
@ -1,4 +1,5 @@
|
||||
using AsbCloudApp.Data;
|
||||
using AsbCloudApp.Data.SAUB;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Threading;
|
||||
|
@ -1,4 +1,5 @@
|
||||
using AsbCloudApp.Data;
|
||||
using AsbCloudApp.Data.SAUB;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Threading;
|
||||
|
@ -1,4 +1,4 @@
|
||||
using AsbCloudApp.Data;
|
||||
using AsbCloudApp.Data.SAUB;
|
||||
using System.Collections.Generic;
|
||||
|
||||
namespace AsbCloudApp.Services
|
||||
|
@ -1,11 +1,16 @@
|
||||
using System.Collections.Generic;
|
||||
using AsbCloudApp.Data;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Threading;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace AsbCloudApp.Services
|
||||
{
|
||||
public interface IWitsRepository
|
||||
public interface IWitsRecordRepository<TDto>
|
||||
where TDto: ITelemetryData
|
||||
{
|
||||
Task SaveDataAsync<TDto>(string uid, IEnumerable<TDto> dtos, CancellationToken token);
|
||||
Task SaveDataAsync(int idTelemetry, IEnumerable<TDto> dtos, CancellationToken token);
|
||||
Task<IEnumerable<TDto>> GetAsync(int idTelemetry, DateTime begin, DateTime end, CancellationToken token);
|
||||
Task<(DateTime begin, DateTime end, int count)?> GetStatAsync(int idTelemetry, CancellationToken token);
|
||||
}
|
||||
}
|
@ -1,5 +1,6 @@
|
||||
using System.ComponentModel.DataAnnotations;
|
||||
using System.ComponentModel.DataAnnotations.Schema;
|
||||
#nullable enable
|
||||
|
||||
namespace AsbCloudDb.Model.WITS
|
||||
{
|
||||
|
@ -14,6 +14,7 @@ using System;
|
||||
using FluentValidation;
|
||||
using FluentValidation.AspNetCore;
|
||||
using AsbCloudInfrastructure.Services.DrillingProgram;
|
||||
using AsbCloudApp.Data.SAUB;
|
||||
|
||||
namespace AsbCloudInfrastructure
|
||||
{
|
||||
@ -54,6 +55,7 @@ namespace AsbCloudInfrastructure
|
||||
|
||||
services.AddHostedService<TelemetryAnalyticsBackgroundService>();// replace by BackgroundWorkerService
|
||||
|
||||
services.AddSingleton(new WitsInfoService());
|
||||
services.AddSingleton(new CacheDb());
|
||||
services.AddSingleton<ITelemetryTracker, TelemetryTracker>();
|
||||
services.AddSingleton<IRequerstTrackerService, RequestTrackerService>();
|
||||
@ -96,6 +98,14 @@ namespace AsbCloudInfrastructure
|
||||
services.AddTransient<ITelemetryDataService<TelemetryDataSaubDto>, TelemetryDataSaubService>();
|
||||
services.AddTransient<ITelemetryDataService<TelemetryDataSpinDto>, TelemetryDataSpinService>();
|
||||
|
||||
// Wits
|
||||
services.AddTransient<IWitsRecordRepository<AsbCloudApp.Data.WITS.Record1Dto>, WitsRecordRepository<AsbCloudApp.Data.WITS.Record1Dto, AsbCloudDb.Model.WITS.Record1>>();
|
||||
services.AddTransient<IWitsRecordRepository<AsbCloudApp.Data.WITS.Record7Dto>, WitsRecordRepository<AsbCloudApp.Data.WITS.Record7Dto, AsbCloudDb.Model.WITS.Record7>>();
|
||||
services.AddTransient<IWitsRecordRepository<AsbCloudApp.Data.WITS.Record8Dto>, WitsRecordRepository<AsbCloudApp.Data.WITS.Record8Dto, AsbCloudDb.Model.WITS.Record8>>();
|
||||
services.AddTransient<IWitsRecordRepository<AsbCloudApp.Data.WITS.Record50Dto>, WitsRecordRepository<AsbCloudApp.Data.WITS.Record50Dto, AsbCloudDb.Model.WITS.Record50>>();
|
||||
services.AddTransient<IWitsRecordRepository<AsbCloudApp.Data.WITS.Record60Dto>, WitsRecordRepository<AsbCloudApp.Data.WITS.Record60Dto, AsbCloudDb.Model.WITS.Record60>>();
|
||||
services.AddTransient<IWitsRecordRepository<AsbCloudApp.Data.WITS.Record61Dto>, WitsRecordRepository<AsbCloudApp.Data.WITS.Record61Dto, AsbCloudDb.Model.WITS.Record61>>();
|
||||
|
||||
services.AddValidators();
|
||||
|
||||
return services;
|
||||
|
@ -1,4 +1,4 @@
|
||||
using AsbCloudApp.Data;
|
||||
using AsbCloudApp.Data.SAUB;
|
||||
using AsbCloudApp.Services;
|
||||
using AsbCloudDb.Model;
|
||||
using AsbCloudInfrastructure.Services.Cache;
|
||||
|
@ -1,4 +1,5 @@
|
||||
using AsbCloudApp.Data;
|
||||
using AsbCloudApp.Data.SAUB;
|
||||
using AsbCloudApp.Services;
|
||||
using AsbCloudDb.Model;
|
||||
using AsbCloudInfrastructure.Services.Cache;
|
||||
|
@ -40,16 +40,16 @@ namespace AsbCloudInfrastructure.Services
|
||||
if (dtos == default || !dtos.Any())
|
||||
return 0;
|
||||
|
||||
var dtosList = dtos.OrderBy(d => d.Date).ToList();
|
||||
var dtosList = dtos.OrderBy(d => d.DateTime).ToList();
|
||||
|
||||
var dtoMinDate = dtosList.First().Date;
|
||||
var dtoMaxDate = dtosList.Last().Date;
|
||||
var dtoMinDate = dtosList.First().DateTime;
|
||||
var dtoMaxDate = dtosList.Last().DateTime;
|
||||
|
||||
if (dtosList.Count > 1)
|
||||
{
|
||||
var duplicates = new List<TDto>(8);
|
||||
for (int i = 1; i < dtosList.Count; i++)
|
||||
if (dtosList[i].Date - dtosList[i-1].Date < TimeSpan.FromMilliseconds(100))
|
||||
if (dtosList[i].DateTime - dtosList[i-1].DateTime < TimeSpan.FromMilliseconds(100))
|
||||
duplicates.Add(dtosList[i - 1]);
|
||||
foreach (var duplicate in duplicates)
|
||||
dtosList.Remove(duplicate);
|
||||
|
@ -1,4 +1,4 @@
|
||||
using AsbCloudApp.Data;
|
||||
using AsbCloudApp.Data.SAUB;
|
||||
using AsbCloudApp.Services;
|
||||
using AsbCloudDb.Model;
|
||||
using AsbCloudInfrastructure.Services.Cache;
|
||||
@ -21,7 +21,7 @@ namespace AsbCloudInfrastructure.Services
|
||||
var telemetryUser = cacheTelemetryUsers?
|
||||
.FirstOrDefault(u => u.IdTelemetry == src.IdTelemetry && (u.Name == src.User || u.Surname == src.User));
|
||||
entity.IdUser = telemetryUser?.IdUser;
|
||||
entity.DateTime = src.Date.ToUtcDateTimeOffset(timezoneOffset);
|
||||
entity.DateTime = src.DateTime.ToUtcDateTimeOffset(timezoneOffset);
|
||||
return entity;
|
||||
}
|
||||
|
||||
@ -31,7 +31,7 @@ namespace AsbCloudInfrastructure.Services
|
||||
var telemetryUser = cacheTelemetryUsers?
|
||||
.FirstOrDefault(u => u.IdTelemetry == src.IdTelemetry && u.IdUser == src.IdUser);
|
||||
dto.User = telemetryUser?.MakeDisplayName();
|
||||
dto.Date = src.DateTime.ToRemoteDateTime(timezoneOffset);
|
||||
dto.DateTime = src.DateTime.ToRemoteDateTime(timezoneOffset);
|
||||
return dto;
|
||||
}
|
||||
}
|
||||
|
@ -1,4 +1,4 @@
|
||||
using AsbCloudApp.Data;
|
||||
using AsbCloudApp.Data.SAUB;
|
||||
using AsbCloudApp.Services;
|
||||
using AsbCloudDb.Model;
|
||||
using AsbCloudInfrastructure.Services.Cache;
|
||||
@ -18,14 +18,14 @@ namespace AsbCloudInfrastructure.Services
|
||||
public override TelemetryDataSpin Convert(TelemetryDataSpinDto src, double timezoneOffset)
|
||||
{
|
||||
var entity = src.Adapt<TelemetryDataSpin>();
|
||||
entity.DateTime = src.Date.ToUtcDateTimeOffset(timezoneOffset);
|
||||
entity.DateTime = src.DateTime.ToUtcDateTimeOffset(timezoneOffset);
|
||||
return entity;
|
||||
}
|
||||
|
||||
public override TelemetryDataSpinDto Convert(TelemetryDataSpin src, double timezoneOffset)
|
||||
{
|
||||
var dto = src.Adapt<TelemetryDataSpinDto>();
|
||||
dto.Date = src.DateTime.ToRemoteDateTime(timezoneOffset);
|
||||
dto.DateTime = src.DateTime.ToRemoteDateTime(timezoneOffset);
|
||||
return dto;
|
||||
}
|
||||
}
|
||||
|
@ -10,6 +10,7 @@ using System;
|
||||
using System.Threading;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using AsbCloudDb;
|
||||
using AsbCloudApp.Data.SAUB;
|
||||
|
||||
namespace AsbCloudInfrastructure.Services
|
||||
{
|
||||
|
@ -1,5 +1,5 @@
|
||||
using AsbCloudApp.Comparators;
|
||||
using AsbCloudApp.Data;
|
||||
using AsbCloudApp.Data.SAUB;
|
||||
using AsbCloudApp.Services;
|
||||
using AsbCloudDb.Model;
|
||||
using AsbCloudInfrastructure.Services.Cache;
|
||||
|
34
AsbCloudInfrastructure/Services/WitsInfoService.cs
Normal file
34
AsbCloudInfrastructure/Services/WitsInfoService.cs
Normal file
@ -0,0 +1,34 @@
|
||||
using AsbWitsInfo;
|
||||
using System.Collections.Generic;
|
||||
|
||||
namespace AsbCloudInfrastructure.Services
|
||||
{
|
||||
public class WitsInfoService
|
||||
{
|
||||
private readonly InfoService witsInfoService;
|
||||
public WitsInfoService(IEnumerable<ItemInfo>? customItems = null, IEnumerable<RecordInfo>? customRecords = null)
|
||||
{
|
||||
witsInfoService = new InfoService(customItems, customRecords);
|
||||
}
|
||||
|
||||
public object GetItems(int idRecord = -1)
|
||||
{
|
||||
object items;
|
||||
if(idRecord > 0)
|
||||
items = witsInfoService.ItemInfoStore.Where(i => i.RecordId == idRecord);
|
||||
else
|
||||
items = witsInfoService.ItemInfoStore.Where(i => true);
|
||||
return items;
|
||||
}
|
||||
|
||||
public object GetRecords(int idRecord = -1)
|
||||
{
|
||||
object items;
|
||||
if (idRecord > 0)
|
||||
items = witsInfoService.RecordInfoStore.Where(i => i.RecordId == idRecord);
|
||||
else
|
||||
items = witsInfoService.RecordInfoStore.Where(i => true);
|
||||
return items;
|
||||
}
|
||||
}
|
||||
}
|
90
AsbCloudInfrastructure/Services/WitsRecordRepository.cs
Normal file
90
AsbCloudInfrastructure/Services/WitsRecordRepository.cs
Normal file
@ -0,0 +1,90 @@
|
||||
using AsbCloudApp.Services;
|
||||
using AsbCloudDb.Model;
|
||||
using Mapster;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Threading;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace AsbCloudInfrastructure.Services
|
||||
{
|
||||
public class WitsRecordRepository<TDto, TEntity> : IWitsRecordRepository<TDto>
|
||||
where TEntity : class, ITelemetryData
|
||||
where TDto: AsbCloudApp.Data.ITelemetryData
|
||||
{
|
||||
private readonly DbSet<TEntity> dbset;
|
||||
private readonly IAsbCloudDbContext db;
|
||||
private readonly ITelemetryService telemetryService;
|
||||
|
||||
public WitsRecordRepository(IAsbCloudDbContext db, ITelemetryService telemetryService)
|
||||
{
|
||||
dbset = db.Set<TEntity>();
|
||||
this.db = db;
|
||||
this.telemetryService = telemetryService;
|
||||
}
|
||||
|
||||
public async Task<(DateTime begin, DateTime end, int count)?> GetStatAsync(int idTelemetry, CancellationToken token)
|
||||
{
|
||||
var timezoneHours = telemetryService.GetTimezone(idTelemetry).Hours;
|
||||
var stat = await dbset.Where(d => d.IdTelemetry == idTelemetry)
|
||||
.GroupBy(d => d.IdTelemetry)
|
||||
.Select(g => new Tuple<DateTimeOffset, DateTimeOffset, int>(g.Min(d => d.DateTime), g.Max(d => d.DateTime), g.Count()))
|
||||
.FirstOrDefaultAsync(token);
|
||||
|
||||
if (stat is null || stat.Item3 == 0)
|
||||
return null;
|
||||
|
||||
return (
|
||||
stat.Item1.ToRemoteDateTime(timezoneHours),
|
||||
stat.Item2.ToRemoteDateTime(timezoneHours),
|
||||
stat.Item3);
|
||||
}
|
||||
|
||||
public async Task<IEnumerable<TDto>> GetAsync(int idTelemetry, DateTime begin, DateTime end, CancellationToken token)
|
||||
{
|
||||
var timezoneHours = telemetryService.GetTimezone(idTelemetry).Hours;
|
||||
var query = dbset
|
||||
.Where(d => d.IdTelemetry == idTelemetry)
|
||||
.Where(d => d.DateTime >= begin)
|
||||
.Where(d => d.DateTime <= end)
|
||||
.AsNoTracking();
|
||||
var data = await query.ToListAsync(token);
|
||||
return data.Select(d => Convert(d, timezoneHours));
|
||||
}
|
||||
|
||||
public Task SaveDataAsync(int idTelemetry, IEnumerable<TDto> dtos, CancellationToken token)
|
||||
{
|
||||
if (dtos?.Any() != true)
|
||||
return Task.CompletedTask;
|
||||
|
||||
var timezoneHours = telemetryService.GetTimezone(idTelemetry).Hours;
|
||||
var entities = dtos.Select(dto => Convert(dto, idTelemetry, timezoneHours));
|
||||
|
||||
dbset.AddRange(entities);
|
||||
return db.SaveChangesAsync(token);
|
||||
}
|
||||
|
||||
private static TEntity Convert(TDto dto, int idTelemetry, double timezoneHours)
|
||||
{
|
||||
if (dto is null)
|
||||
return null;
|
||||
|
||||
var entity = dto.Adapt<TEntity>();
|
||||
entity.IdTelemetry = idTelemetry;
|
||||
entity.DateTime = dto.DateTime.ToUtcDateTimeOffset(timezoneHours);
|
||||
return entity;
|
||||
}
|
||||
|
||||
private static TDto Convert(TEntity entity, double timezoneHours)
|
||||
{
|
||||
if (entity is null)
|
||||
return default;
|
||||
|
||||
var data = entity.Adapt<TDto>();
|
||||
data.DateTime = entity.DateTime.ToRemoteDateTime(timezoneHours);
|
||||
return data;
|
||||
}
|
||||
}
|
||||
}
|
@ -1,4 +1,4 @@
|
||||
using AsbCloudApp.Data;
|
||||
using AsbCloudApp.Data.SAUB;
|
||||
using FluentValidation;
|
||||
|
||||
namespace AsbCloudInfrastructure.Validators
|
||||
|
@ -1,4 +1,4 @@
|
||||
using AsbCloudApp.Data;
|
||||
using AsbCloudApp.Data.SAUB;
|
||||
using AsbCloudApp.Services;
|
||||
using AsbCloudDb.Model;
|
||||
using AsbCloudWebApi.Controllers;
|
||||
|
@ -1,4 +1,3 @@
|
||||
using AsbCloudApp.Data;
|
||||
using AsbCloudDb.Model;
|
||||
using AsbCloudInfrastructure.Services.Cache;
|
||||
using AsbCloudInfrastructure.Services;
|
||||
@ -8,6 +7,7 @@ using System.Threading.Tasks;
|
||||
using AsbCloudApp.Services;
|
||||
using Moq;
|
||||
using Xunit;
|
||||
using AsbCloudApp.Data.SAUB;
|
||||
|
||||
namespace AsbCloudWebApi.Tests.ServicesTests;
|
||||
|
||||
|
@ -1,4 +1,5 @@
|
||||
using AsbCloudApp.Data;
|
||||
using AsbCloudApp.Data.SAUB;
|
||||
using AsbCloudApp.Services;
|
||||
using AsbCloudDb.Model;
|
||||
using AsbCloudInfrastructure.Services;
|
||||
@ -70,7 +71,7 @@ namespace AsbCloudWebApi.Tests.ServicesTests
|
||||
var newData = new List<TelemetryDataSaubDto>
|
||||
{
|
||||
new TelemetryDataSaubDto{
|
||||
Date = now,
|
||||
DateTime = now,
|
||||
AxialLoad = 1,
|
||||
MseState = 1,
|
||||
User = tuser,
|
||||
|
@ -1,4 +1,5 @@
|
||||
using AsbCloudApp.Data;
|
||||
using AsbCloudApp.Data.SAUB;
|
||||
using AsbCloudApp.Services;
|
||||
using AsbCloudWebApi.SignalR;
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
|
@ -1,4 +1,4 @@
|
||||
using AsbCloudApp.Data;
|
||||
using AsbCloudApp.Data.SAUB;
|
||||
using AsbCloudApp.Services;
|
||||
using AsbCloudWebApi.SignalR;
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
|
@ -1,4 +1,4 @@
|
||||
using AsbCloudApp.Data;
|
||||
using AsbCloudApp.Data.SAUB;
|
||||
using AsbCloudApp.Services;
|
||||
using AsbCloudWebApi.SignalR;
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
|
82
AsbCloudWebApi/Controllers/WITS/WitsControllerAbstract.cs
Normal file
82
AsbCloudWebApi/Controllers/WITS/WitsControllerAbstract.cs
Normal file
@ -0,0 +1,82 @@
|
||||
using AsbCloudApp.Data;
|
||||
using AsbCloudApp.Data.WITS;
|
||||
using AsbCloudApp.Services;
|
||||
using AsbCloudWebApi.SignalR;
|
||||
using Microsoft.AspNetCore.Authorization;
|
||||
using Microsoft.AspNetCore.Http;
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
using Microsoft.AspNetCore.SignalR;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Threading;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace AsbCloudWebApi.Controllers.WITS
|
||||
{
|
||||
[Route("api/[controller]")]
|
||||
[ApiController]
|
||||
public abstract class WitsControllerAbstract<TDto> : ControllerBase
|
||||
where TDto : ITelemetryData
|
||||
{
|
||||
private readonly ITelemetryService telemetryService;
|
||||
private readonly IHubContext<TelemetryHub> telemetryHubContext;
|
||||
protected abstract string SirnalRMethodGetDataName { get; }
|
||||
|
||||
public WitsControllerAbstract(
|
||||
ITelemetryService telemetryService,
|
||||
IHubContext<TelemetryHub> telemetryHubContext)
|
||||
{
|
||||
this.telemetryService = telemetryService;
|
||||
this.telemetryHubContext = telemetryHubContext;
|
||||
}
|
||||
|
||||
[HttpPost("{uid}")]
|
||||
[AllowAnonymous]
|
||||
public async virtual Task<IActionResult> PostDataAsync(
|
||||
string uid,
|
||||
[FromBody] IEnumerable<TDto> dtos,
|
||||
[FromServices] IWitsRecordRepository<TDto> witsRecordRepository,
|
||||
CancellationToken token = default)
|
||||
{
|
||||
var idTelemetry = telemetryService.GetOrCreateTelemetryIdByUid(uid);
|
||||
await witsRecordRepository.SaveDataAsync(idTelemetry, dtos, token).ConfigureAwait(false);
|
||||
var idWell = telemetryService.GetIdWellByTelemetryUid(uid);
|
||||
if (idWell != null && dtos.Any())
|
||||
_ = Task.Run(() => telemetryHubContext.Clients.Group($"well_{idWell}_wits")
|
||||
.SendAsync(SirnalRMethodGetDataName, dtos), CancellationToken.None);
|
||||
|
||||
return Ok();
|
||||
}
|
||||
|
||||
[HttpGet("{idWell}")]
|
||||
[ProducesResponseType(StatusCodes.Status200OK, Type = typeof(IEnumerable<RecordBaseDto>))]
|
||||
public async virtual Task<IActionResult> GetDataAsync(
|
||||
int idWell,
|
||||
DateTime begin,
|
||||
DateTime end,
|
||||
[FromServices] IWitsRecordRepository<TDto> witsRecordRepository,
|
||||
CancellationToken token)
|
||||
{
|
||||
var idTelemetry = telemetryService.GetIdTelemetryByIdWell(idWell);
|
||||
if (idTelemetry is null)
|
||||
return NoContent();
|
||||
var dtos = await witsRecordRepository.GetAsync((int)idTelemetry, begin, end, token);
|
||||
return Ok(dtos);
|
||||
}
|
||||
|
||||
[HttpGet("{idWell}/datesRange")]
|
||||
[ProducesResponseType(StatusCodes.Status200OK, Type = typeof((DateTime begin, DateTime end, int count)?))]
|
||||
public async virtual Task<IActionResult> GetDatesRangeAsync(
|
||||
int idWell,
|
||||
[FromServices] IWitsRecordRepository<TDto> witsRecordRepository,
|
||||
CancellationToken token)
|
||||
{
|
||||
var idTelemetry = telemetryService.GetIdTelemetryByIdWell(idWell);
|
||||
if (idTelemetry is null)
|
||||
return NoContent();
|
||||
var dtos = await witsRecordRepository.GetStatAsync((int)idTelemetry, token);
|
||||
return Ok(dtos);
|
||||
}
|
||||
}
|
||||
}
|
46
AsbCloudWebApi/Controllers/WITS/WitsInfoController.cs
Normal file
46
AsbCloudWebApi/Controllers/WITS/WitsInfoController.cs
Normal file
@ -0,0 +1,46 @@
|
||||
using AsbCloudInfrastructure.Services;
|
||||
using Microsoft.AspNetCore.Http;
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
|
||||
namespace AsbCloudWebApi.Controllers.WITS
|
||||
{
|
||||
[Route("api/[controller]")]
|
||||
[ApiController]
|
||||
public class WitsInfoController : ControllerBase
|
||||
{
|
||||
private readonly WitsInfoService witsInfoService;
|
||||
|
||||
public WitsInfoController(WitsInfoService witsInfoService)
|
||||
{
|
||||
this.witsInfoService = witsInfoService;
|
||||
}
|
||||
|
||||
[HttpGet("item")]
|
||||
public IActionResult GetItems()
|
||||
{
|
||||
var result = witsInfoService.GetItems();
|
||||
return Ok(result);
|
||||
}
|
||||
|
||||
[HttpGet("item/{idRecord}")]
|
||||
public IActionResult GetItems(int idRecord)
|
||||
{
|
||||
var result = witsInfoService.GetItems(idRecord);
|
||||
return Ok(result);
|
||||
}
|
||||
|
||||
[HttpGet("record")]
|
||||
public IActionResult GetRecordInfo()
|
||||
{
|
||||
var result = witsInfoService.GetRecords();
|
||||
return Ok(result);
|
||||
}
|
||||
|
||||
[HttpGet("record/{idRecord}")]
|
||||
public IActionResult GetRecordInfo(int idRecord)
|
||||
{
|
||||
var result = witsInfoService.GetRecords(idRecord);
|
||||
return Ok(result);
|
||||
}
|
||||
}
|
||||
}
|
21
AsbCloudWebApi/Controllers/WITS/WitsRecord1Controller.cs
Normal file
21
AsbCloudWebApi/Controllers/WITS/WitsRecord1Controller.cs
Normal file
@ -0,0 +1,21 @@
|
||||
using AsbCloudApp.Data.WITS;
|
||||
using AsbCloudApp.Services;
|
||||
using AsbCloudWebApi.SignalR;
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
using Microsoft.AspNetCore.SignalR;
|
||||
|
||||
namespace AsbCloudWebApi.Controllers.WITS
|
||||
{
|
||||
[Route("api/[controller]")]
|
||||
[ApiController]
|
||||
public class WitsRecord1Controller : WitsControllerAbstract<Record1Dto>
|
||||
{
|
||||
protected override string SirnalRMethodGetDataName => "ReceiveWitsRecord1";
|
||||
|
||||
public WitsRecord1Controller(
|
||||
ITelemetryService telemetryService,
|
||||
IHubContext<TelemetryHub> telemetryHubContext)
|
||||
: base(telemetryService, telemetryHubContext) { }
|
||||
|
||||
}
|
||||
}
|
19
AsbCloudWebApi/Controllers/WITS/WitsRecord50Controller.cs
Normal file
19
AsbCloudWebApi/Controllers/WITS/WitsRecord50Controller.cs
Normal file
@ -0,0 +1,19 @@
|
||||
using AsbCloudApp.Data.WITS;
|
||||
using AsbCloudApp.Services;
|
||||
using AsbCloudWebApi.SignalR;
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
using Microsoft.AspNetCore.SignalR;
|
||||
|
||||
namespace AsbCloudWebApi.Controllers.WITS
|
||||
{
|
||||
[Route("api/[controller]")]
|
||||
[ApiController]
|
||||
public class WitsRecord50Controller : WitsControllerAbstract<Record50Dto>
|
||||
{
|
||||
protected override string SirnalRMethodGetDataName => "ReceiveWitsRecord50";
|
||||
public WitsRecord50Controller(
|
||||
ITelemetryService telemetryService,
|
||||
IHubContext<TelemetryHub> telemetryHubContext)
|
||||
: base(telemetryService, telemetryHubContext) { }
|
||||
}
|
||||
}
|
19
AsbCloudWebApi/Controllers/WITS/WitsRecord60Controller.cs
Normal file
19
AsbCloudWebApi/Controllers/WITS/WitsRecord60Controller.cs
Normal file
@ -0,0 +1,19 @@
|
||||
using AsbCloudApp.Data.WITS;
|
||||
using AsbCloudApp.Services;
|
||||
using AsbCloudWebApi.SignalR;
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
using Microsoft.AspNetCore.SignalR;
|
||||
|
||||
namespace AsbCloudWebApi.Controllers.WITS
|
||||
{
|
||||
[Route("api/[controller]")]
|
||||
[ApiController]
|
||||
public class WitsRecord60Controller : WitsControllerAbstract<Record60Dto>
|
||||
{
|
||||
protected override string SirnalRMethodGetDataName => "ReceiveWitsRecord60";
|
||||
public WitsRecord60Controller(
|
||||
ITelemetryService telemetryService,
|
||||
IHubContext<TelemetryHub> telemetryHubContext)
|
||||
: base(telemetryService, telemetryHubContext) { }
|
||||
}
|
||||
}
|
19
AsbCloudWebApi/Controllers/WITS/WitsRecord61Controller.cs
Normal file
19
AsbCloudWebApi/Controllers/WITS/WitsRecord61Controller.cs
Normal file
@ -0,0 +1,19 @@
|
||||
using AsbCloudApp.Data.WITS;
|
||||
using AsbCloudApp.Services;
|
||||
using AsbCloudWebApi.SignalR;
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
using Microsoft.AspNetCore.SignalR;
|
||||
|
||||
namespace AsbCloudWebApi.Controllers.WITS
|
||||
{
|
||||
[Route("api/[controller]")]
|
||||
[ApiController]
|
||||
public class WitsRecord61Controller : WitsControllerAbstract<Record61Dto>
|
||||
{
|
||||
protected override string SirnalRMethodGetDataName => "ReceiveWitsRecord61";
|
||||
public WitsRecord61Controller(
|
||||
ITelemetryService telemetryService,
|
||||
IHubContext<TelemetryHub> telemetryHubContext)
|
||||
: base(telemetryService, telemetryHubContext) { }
|
||||
}
|
||||
}
|
19
AsbCloudWebApi/Controllers/WITS/WitsRecord7Controller.cs
Normal file
19
AsbCloudWebApi/Controllers/WITS/WitsRecord7Controller.cs
Normal file
@ -0,0 +1,19 @@
|
||||
using AsbCloudApp.Data.WITS;
|
||||
using AsbCloudApp.Services;
|
||||
using AsbCloudWebApi.SignalR;
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
using Microsoft.AspNetCore.SignalR;
|
||||
|
||||
namespace AsbCloudWebApi.Controllers.WITS
|
||||
{
|
||||
[Route("api/[controller]")]
|
||||
[ApiController]
|
||||
public class WitsRecord7Controller : WitsControllerAbstract<Record7Dto>
|
||||
{
|
||||
protected override string SirnalRMethodGetDataName => "ReceiveWitsRecord7";
|
||||
public WitsRecord7Controller(
|
||||
ITelemetryService telemetryService,
|
||||
IHubContext<TelemetryHub> telemetryHubContext)
|
||||
: base(telemetryService, telemetryHubContext) { }
|
||||
}
|
||||
}
|
19
AsbCloudWebApi/Controllers/WITS/WitsRecord8Controller.cs
Normal file
19
AsbCloudWebApi/Controllers/WITS/WitsRecord8Controller.cs
Normal file
@ -0,0 +1,19 @@
|
||||
using AsbCloudApp.Data.WITS;
|
||||
using AsbCloudApp.Services;
|
||||
using AsbCloudWebApi.SignalR;
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
using Microsoft.AspNetCore.SignalR;
|
||||
|
||||
namespace AsbCloudWebApi.Controllers.WITS
|
||||
{
|
||||
[Route("api/[controller]")]
|
||||
[ApiController]
|
||||
public class WitsRecord8Controller : WitsControllerAbstract<Record8Dto>
|
||||
{
|
||||
protected override string SirnalRMethodGetDataName => "ReceiveWitsRecord8";
|
||||
public WitsRecord8Controller(
|
||||
ITelemetryService telemetryService,
|
||||
IHubContext<TelemetryHub> telemetryHubContext)
|
||||
: base(telemetryService, telemetryHubContext) { }
|
||||
}
|
||||
}
|
@ -1,63 +0,0 @@
|
||||
using AsbCloudApp.Services;
|
||||
using AsbCloudWebApi.SignalR;
|
||||
using Microsoft.AspNetCore.Authorization;
|
||||
using Microsoft.AspNetCore.Http;
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
using Microsoft.AspNetCore.SignalR;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Threading;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace AsbCloudWebApi.Controllers
|
||||
{
|
||||
[Route("api/telemetry/{uid}/wits")]
|
||||
[ApiController]
|
||||
public class WitsController : ControllerBase
|
||||
{
|
||||
private readonly IWitsRepository witsService;
|
||||
private readonly ITelemetryService telemetryService;
|
||||
private readonly IHubContext<TelemetryHub> telemetryHubContext;
|
||||
|
||||
public WitsController(
|
||||
IWitsRepository witsService,
|
||||
ITelemetryService telemetryService,
|
||||
IHubContext<TelemetryHub> telemetryHubContext)
|
||||
{
|
||||
this.witsService = witsService;
|
||||
this.telemetryService = telemetryService;
|
||||
this.telemetryHubContext = telemetryHubContext;
|
||||
}
|
||||
|
||||
//[HttpPost("record1")]
|
||||
//[AllowAnonymous]
|
||||
//public virtual async Task<IActionResult> PostDataAsync(string uid, [FromBody] IEnumerable<TDto> dtos,
|
||||
// CancellationToken token = default)
|
||||
//{
|
||||
// await telemetryDataService.UpdateDataAsync(uid, dtos, token).ConfigureAwait(false);
|
||||
|
||||
// var idWell = telemetryService.GetIdWellByTelemetryUid(uid);
|
||||
// if (idWell != null && dtos.Any())
|
||||
// _ = Task.Run(() => telemetryHubContext.Clients.Group($"well_{idWell}")
|
||||
// .SendAsync(SirnalRMethodGetDataName, dtos), CancellationToken.None);
|
||||
|
||||
// return Ok();
|
||||
//}
|
||||
|
||||
|
||||
//private async Task<IActionResult> PostDataAsync<TDto>(
|
||||
// string uid,
|
||||
// IEnumerable<TDto> dtos,
|
||||
// CancellationToken token = default)
|
||||
//{
|
||||
// //await witsService.SaveDataAsync(uid, dtos, token).ConfigureAwait(false);
|
||||
|
||||
// var idWell = telemetryService.GetIdWellByTelemetryUid(uid);
|
||||
// if (idWell != null && dtos.Any())
|
||||
// _ = Task.Run(() => telemetryHubContext.Clients.Group($"well_{idWell}")
|
||||
// .SendAsync(SirnalRMethodGetDataName, dtos), CancellationToken.None);
|
||||
|
||||
// return Ok();
|
||||
//}
|
||||
}
|
||||
}
|
@ -1,4 +1,4 @@
|
||||
using AsbCloudApp.Data;
|
||||
using AsbCloudApp.Data.SAUB;
|
||||
using ProtoBuf.Meta;
|
||||
|
||||
namespace AsbCloudWebApi
|
||||
@ -18,7 +18,7 @@ namespace AsbCloudWebApi
|
||||
return;
|
||||
RuntimeTypeModel.Default.Add(type, false)
|
||||
.Add(1, nameof(TelemetryDataSpinDto.IdTelemetry))
|
||||
.Add(2, nameof(TelemetryDataSpinDto.Date))
|
||||
.Add(2, nameof(TelemetryDataSpinDto.DateTime))
|
||||
.Add(3, nameof(TelemetryDataSpinDto.TopDriveSpeed))
|
||||
.Add(4, nameof(TelemetryDataSpinDto.TopDriveSpeedMin))
|
||||
.Add(5, nameof(TelemetryDataSpinDto.TopDriveSpeedMax))
|
||||
@ -91,7 +91,7 @@ namespace AsbCloudWebApi
|
||||
return;
|
||||
RuntimeTypeModel.Default.Add(type, false)
|
||||
.Add(1, nameof(TelemetryDataSaubDto.IdTelemetry))
|
||||
.Add(2, nameof(TelemetryDataSaubDto.Date))
|
||||
.Add(2, nameof(TelemetryDataSaubDto.DateTime))
|
||||
.Add(3, nameof(TelemetryDataSaubDto.Mode))
|
||||
.Add(4, nameof(TelemetryDataSaubDto.User))
|
||||
.Add(5, nameof(TelemetryDataSaubDto.WellDepth))
|
||||
|
@ -6,6 +6,7 @@ using System.Threading.Tasks;
|
||||
using System.Text;
|
||||
using System.Text.Json;
|
||||
using AsbCloudApp.Data;
|
||||
using AsbCloudApp.Data.SAUB;
|
||||
|
||||
namespace ConsoleApp1
|
||||
{
|
||||
@ -75,7 +76,7 @@ namespace ConsoleApp1
|
||||
{
|
||||
var dto = new TelemetryDataSaubDto
|
||||
{
|
||||
Date = date == default ? DateTime.Now : date,
|
||||
DateTime = date == default ? DateTime.Now : date,
|
||||
User = "Вупсень",
|
||||
Mode = 1, //ротор
|
||||
IdFeedRegulator = 1,
|
||||
|
Loading…
Reference in New Issue
Block a user