Added last received telemetry date in WellDto

This commit is contained in:
KharchenkoVladimir 2021-10-15 15:35:18 +05:00
parent 02f344569e
commit 3a6f5e7f5e
4 changed files with 30 additions and 4 deletions

View File

@ -1,4 +1,6 @@
namespace AsbCloudApp.Data using System;
namespace AsbCloudApp.Data
{ {
public class WellDto : WellInfoDto, IMapPoint, IId public class WellDto : WellInfoDto, IMapPoint, IId
@ -7,6 +9,7 @@
public double? Latitude { get; set; } public double? Latitude { get; set; }
public double? Longitude { get; set; } public double? Longitude { get; set; }
public string WellType { get; set; } public string WellType { get; set; }
public DateTime LastTelemetryDate { get; set; }
public TelemetryDto Telemetry { get; set; } public TelemetryDto Telemetry { get; set; }
} }
} }

View File

@ -1,4 +1,5 @@
using AsbCloudApp.Data; using AsbCloudApp.Data;
using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.Threading; using System.Threading;
using System.Threading.Tasks; using System.Threading.Tasks;
@ -7,6 +8,8 @@ namespace AsbCloudApp.Services
{ {
public interface ITelemetryService public interface ITelemetryService
{ {
void SaveRequestDate(string uid);
DateTime GetLastTelemetryDateByWellId(int idWell);
int? GetidWellByTelemetryUid(string uid); int? GetidWellByTelemetryUid(string uid);
int GetOrCreateTemetryIdByUid(string uid); int GetOrCreateTemetryIdByUid(string uid);
double GetTimezoneOffsetByTelemetryId(int idTelemetry); double GetTimezoneOffsetByTelemetryId(int idTelemetry);
@ -16,6 +19,5 @@ namespace AsbCloudApp.Services
IEnumerable<(string Key, int[] Ids)> GetRedundentRemoteUids(); IEnumerable<(string Key, int[] Ids)> GetRedundentRemoteUids();
Task<IEnumerable<WellDto>> GetTransmittingWellsAsync(int idCompany, Task<IEnumerable<WellDto>> GetTransmittingWellsAsync(int idCompany,
CancellationToken token); CancellationToken token);
void SaveRequestDate(string uid);
} }
} }

View File

@ -13,10 +13,12 @@ namespace AsbCloudInfrastructure.Services
public class ClusterService : IClusterService public class ClusterService : IClusterService
{ {
private readonly IAsbCloudDbContext db; private readonly IAsbCloudDbContext db;
private readonly ITelemetryService telemetryService;
public ClusterService(IAsbCloudDbContext db) public ClusterService(IAsbCloudDbContext db, ITelemetryService telemetryService)
{ {
this.db = db; this.db = db;
this.telemetryService = telemetryService;
} }
public async Task<IEnumerable<DepositDto>> GetDepositsAsync(int idCompany, public async Task<IEnumerable<DepositDto>> GetDepositsAsync(int idCompany,
@ -142,6 +144,7 @@ namespace AsbCloudInfrastructure.Services
Latitude = well.Latitude, Latitude = well.Latitude,
Longitude = well.Longitude, Longitude = well.Longitude,
WellType = well.WellType?.Caption, WellType = well.WellType?.Caption,
LastTelemetryDate = telemetryService.GetLastTelemetryDateByWellId(well.Id),
Cluster = gCluster.Key.Caption, Cluster = gCluster.Key.Caption,
Deposit = gDeposit.Key.Caption, Deposit = gDeposit.Key.Caption,
}), }),

View File

@ -8,6 +8,7 @@ using System.Linq;
using System.Threading; using System.Threading;
using System.Threading.Tasks; using System.Threading.Tasks;
using System; using System;
using System.Diagnostics;
using Microsoft.EntityFrameworkCore; using Microsoft.EntityFrameworkCore;
namespace AsbCloudInfrastructure.Services namespace AsbCloudInfrastructure.Services
@ -52,6 +53,23 @@ namespace AsbCloudInfrastructure.Services
public void SaveRequestDate(string uid) => public void SaveRequestDate(string uid) =>
telemetryTracker.SaveRequestDate(uid); telemetryTracker.SaveRequestDate(uid);
public DateTime GetLastTelemetryDateByWellId(int idWell)
{
try
{
var telemetryId = GetIdTelemetryByIdWell(idWell);
var uid = cacheTelemetry.FirstOrDefault(t => t.Id == telemetryId).RemoteUid;
var lastTelemetryDate = telemetryTracker.GetLastTelemetryDateByUid(uid);
return lastTelemetryDate;
}
catch(Exception ex)
{
Trace.TraceError(ex.Message);
Console.WriteLine(ex.Message);
return DateTime.MinValue;
}
}
public int GetOrCreateTemetryIdByUid(string uid) public int GetOrCreateTemetryIdByUid(string uid)
=> GetOrCreateTelemetryByUid(uid).Id; => GetOrCreateTelemetryByUid(uid).Id;