CS2-119: Added Telemetry Timezone object and update timezone functionality

This commit is contained in:
KharchenkoVladimir 2021-11-16 13:14:31 +05:00
parent 212989b3b6
commit 88f9236b8a
9 changed files with 2868 additions and 7 deletions

View File

@ -0,0 +1,9 @@
namespace AsbCloudApp.Data
{
public class TelemetryTimeZoneDto
{
public double Hours { get; set; }
public string TimeZoneId { get; set; }
public bool IsOverride { get; set; }
}
}

View File

@ -11,7 +11,8 @@ namespace AsbCloudApp.Services
int? GetidWellByTelemetryUid(string uid);
int GetOrCreateTemetryIdByUid(string uid);
double GetTimezoneOffsetByTelemetryId(int idTelemetry);
void UpdateInfo(string uid, TelemetryInfoDto info);
Task UpdateInfoAsync(string uid, TelemetryInfoDto info, CancellationToken token);
Task UpdateTimeZoneAsync(string uid, TelemetryTimeZoneDto telemetryTimeZoneInfo, CancellationToken token);
int? GetIdTelemetryByIdWell(int idWell);
int Merge(IEnumerable<int> telemetryIds);
IEnumerable<(string Key, int[] Ids)> GetRedundentRemoteUids();

File diff suppressed because it is too large Load Diff

View File

@ -0,0 +1,25 @@
using AsbCloudDb.Model;
using Microsoft.EntityFrameworkCore.Migrations;
namespace AsbCloudDb.Migrations
{
public partial class Add_Telemetry_TimeZone : Migration
{
protected override void Up(MigrationBuilder migrationBuilder)
{
migrationBuilder.AddColumn<TelemetryTimeZone>(
name: "timezone",
table: "t_telemetry",
type: "jsonb",
nullable: true,
comment: "Смещение часового пояса от UTC");
}
protected override void Down(MigrationBuilder migrationBuilder)
{
migrationBuilder.DropColumn(
name: "timezone",
table: "t_telemetry");
}
}
}

View File

@ -768,6 +768,11 @@ namespace AsbCloudDb.Migrations
.HasColumnName("remote_uid")
.HasComment("Идентификатор передающего устройства. Может повторяться в списке, так как комплекты оборудования переезжают от скв. к скв.");
b.Property<TelemetryTimeZone>("TelemetryTimeZone")
.HasColumnType("jsonb")
.HasColumnName("timezone")
.HasComment("Смещение часового пояса от UTC");
b.HasKey("Id");
b.HasIndex(new[] { "RemoteUid" }, "t_telemetry_remote_uid_index");

View File

@ -1,5 +1,4 @@
using Microsoft.EntityFrameworkCore;
using System;
using System.Collections.Generic;
using System.ComponentModel.DataAnnotations;
using System.ComponentModel.DataAnnotations.Schema;
@ -27,6 +26,9 @@ namespace AsbCloudDb.Model
[Column("info", TypeName = "jsonb"), Comment("Информация с панели о скважине")]
public TelemetryInfo Info { get; set; }
[Column("timezone", TypeName = "jsonb"), Comment("Смещение часового пояса от UTC")]
public TelemetryTimeZone TelemetryTimeZone { get; set; }
[InverseProperty(nameof(Model.Well.Telemetry))]
public virtual Well Well { get; set; }

View File

@ -0,0 +1,9 @@
namespace AsbCloudDb.Model
{
public class TelemetryTimeZone
{
public double Hours { get; set; }
public string TimeZoneId { get; set; }
public bool IsOverride { get; set; }
}
}

View File

@ -5,7 +5,9 @@ using AsbCloudInfrastructure.Services.Cache;
using Mapster;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using System;
using System.Threading;
using Microsoft.EntityFrameworkCore;
namespace AsbCloudInfrastructure.Services
@ -69,11 +71,33 @@ namespace AsbCloudInfrastructure.Services
public double GetTimezoneOffsetByTelemetryId(int idTelemetry) =>
cacheTelemetry.FirstOrDefault(t => t.Id == idTelemetry).Info?.TimeZoneOffsetTotalHours ?? 0d;
public void UpdateInfo(string uid, TelemetryInfoDto info)
public async Task UpdateInfoAsync(string uid, TelemetryInfoDto info,
CancellationToken token)
{
var telemetry = GetOrCreateTelemetryByUid(uid);
telemetry.Info = info.Adapt<TelemetryInfo>();
cacheTelemetry.Upsert(telemetry);
var isTimeZoneToUpdate = telemetry.TelemetryTimeZone is null || telemetry.TelemetryTimeZone.IsOverride ||
(!telemetry.TelemetryTimeZone.IsOverride &&
telemetry.TelemetryTimeZone.Hours != info.TimeZoneOffsetTotalHours);
if (isTimeZoneToUpdate)
telemetry.TelemetryTimeZone = new TelemetryTimeZone()
{
Hours = info.TimeZoneOffsetTotalHours, // TODO: Добавить получение имени часового пояса
TimeZoneId = info.TimeZoneId
};
await cacheTelemetry.UpsertAsync(telemetry, token);
}
public async Task UpdateTimeZoneAsync(string uid, TelemetryTimeZoneDto timeZoneInfo,
CancellationToken token)
{
var telemetry = GetOrCreateTelemetryByUid(uid);
telemetry.TelemetryTimeZone = timeZoneInfo.Adapt<TelemetryTimeZone>();
await cacheTelemetry.UpsertAsync(telemetry, token);
}
public int? GetIdTelemetryByIdWell(int idWell)

View File

@ -42,13 +42,31 @@ namespace AsbCloudWebApi.Controllers
/// Принимает общую информацию по скважине
/// </summary>
/// <param name="uid">Уникальный идентификатор отправителя</param>
/// <param name="info">нформация об отправителе</param>
/// <param name="info">Информация об отправителе</param>
/// <param name="token">Токен отмены задачи</param>
/// <returns></returns>
[HttpPost]
[Route("{uid}/info")]
public IActionResult PostInfo(string uid, [FromBody] TelemetryInfoDto info)
public async Task<IActionResult> PostInfoAsync(string uid, [FromBody] TelemetryInfoDto info,
CancellationToken token = default)
{
telemetryService.UpdateInfo(uid, info);
await telemetryService.UpdateInfoAsync(uid, info, token);
return Ok();
}
/// <summary>
/// Обновляет часовой пояс скважины
/// </summary>
/// <param name="uid">Уникальный идентификатор отправителя</param>
/// <param name="timeZoneInfo">Информация о часовом поясе</param>
/// <param name="token">Токен отмены задачи</param>
/// <returns></returns>
[HttpPost]
[Route("{uid}/timeZone")]
public async Task<IActionResult> UpdateTimeZoneAsync(string uid, TelemetryTimeZoneDto timeZoneInfo,
CancellationToken token = default)
{
await telemetryService.UpdateTimeZoneAsync(uid, timeZoneInfo, token);
return Ok();
}