forked from ddrilling/AsbCloudServer
Fixed WellDto creation in WellService (fixed LastTelemetryDate field)
This commit is contained in:
parent
d19a62c041
commit
5b82229a94
@ -16,8 +16,7 @@ namespace AsbCloudApp.Services
|
|||||||
int? GetIdTelemetryByIdWell(int idWell);
|
int? GetIdTelemetryByIdWell(int idWell);
|
||||||
int Merge(IEnumerable<int> telemetryIds);
|
int Merge(IEnumerable<int> telemetryIds);
|
||||||
IEnumerable<(string Key, int[] Ids)> GetRedundentRemoteUids();
|
IEnumerable<(string Key, int[] Ids)> GetRedundentRemoteUids();
|
||||||
Task<IEnumerable<WellDto>> GetTransmittingWellsAsync(int idCompany,
|
IEnumerable<TelemetryDto> GetTransmittingTelemetriesAsync(int idCompany);
|
||||||
CancellationToken token);
|
|
||||||
DateTime GetLastTelemetryDate(string telemetryUid);
|
DateTime GetLastTelemetryDate(string telemetryUid);
|
||||||
DateTime GetLastTelemetryDate(int telemetryId);
|
DateTime GetLastTelemetryDate(int telemetryId);
|
||||||
}
|
}
|
||||||
|
@ -5,10 +5,7 @@ using AsbCloudInfrastructure.Services.Cache;
|
|||||||
using Mapster;
|
using Mapster;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
using System.Threading;
|
|
||||||
using System.Threading.Tasks;
|
|
||||||
using System;
|
using System;
|
||||||
using System.Diagnostics;
|
|
||||||
using Microsoft.EntityFrameworkCore;
|
using Microsoft.EntityFrameworkCore;
|
||||||
|
|
||||||
namespace AsbCloudInfrastructure.Services
|
namespace AsbCloudInfrastructure.Services
|
||||||
@ -29,25 +26,18 @@ namespace AsbCloudInfrastructure.Services
|
|||||||
this.telemetryTracker = telemetryTracker;
|
this.telemetryTracker = telemetryTracker;
|
||||||
}
|
}
|
||||||
|
|
||||||
public async Task<IEnumerable<WellDto>> GetTransmittingWellsAsync(int idCompany, CancellationToken token)
|
public IEnumerable<TelemetryDto> GetTransmittingTelemetriesAsync(int idCompany)
|
||||||
{
|
{
|
||||||
var wells = new List<Well>();
|
var telemetryDtos = new List<TelemetryDto>();
|
||||||
IEnumerable<string> activeTelemetriesUids = telemetryTracker.GetTransmittingTelemetryUids();
|
IEnumerable<string> activeTelemetriesUids = telemetryTracker.GetTransmittingTelemetryUids();
|
||||||
if (activeTelemetriesUids.Any())
|
if (activeTelemetriesUids.Any())
|
||||||
{
|
{
|
||||||
wells = await db.GetWellsForCompany(idCompany)
|
var telemetries = cacheTelemetry
|
||||||
.Where(w => activeTelemetriesUids.Contains(w.Telemetry.RemoteUid))
|
.Where(t => activeTelemetriesUids.Contains(t.RemoteUid));
|
||||||
.AsNoTracking()
|
telemetryDtos = telemetries.Adapt<TelemetryDto>().ToList();
|
||||||
.ToListAsync(token)
|
|
||||||
.ConfigureAwait(false);
|
|
||||||
}
|
}
|
||||||
return wells.Select(w => new WellDto
|
|
||||||
{
|
return telemetryDtos;
|
||||||
Id = w.Id,
|
|
||||||
Caption = w.Caption,
|
|
||||||
Cluster = w.Cluster.Caption,
|
|
||||||
Deposit = w.Cluster.Deposit.Caption,
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public void SaveRequestDate(string uid) =>
|
public void SaveRequestDate(string uid) =>
|
||||||
|
@ -29,30 +29,38 @@ namespace AsbCloudInfrastructure.Services
|
|||||||
|
|
||||||
public DateTime GetLastTelemetryDate(int idWell)
|
public DateTime GetLastTelemetryDate(int idWell)
|
||||||
{
|
{
|
||||||
var lastTelemetryDate = DateTime.MinValue;
|
var defaultDate = DateTime.MinValue;
|
||||||
var well = cacheWells.FirstOrDefault(w => w.Id == idWell);
|
var well = cacheWells.FirstOrDefault(w => w.Id == idWell);
|
||||||
|
|
||||||
if (well is null || well.IdTelemetry is null)
|
if (well?.IdTelemetry is null)
|
||||||
return lastTelemetryDate;
|
return defaultDate;
|
||||||
|
|
||||||
lastTelemetryDate = telemetryService.GetLastTelemetryDate(well.IdTelemetry??0);
|
var lastTelemetry = db.TelemetryDataSaub
|
||||||
return lastTelemetryDate;
|
.FirstOrDefault(t => t.Id == well.IdTelemetry);
|
||||||
|
return lastTelemetry?.Date ?? defaultDate;
|
||||||
}
|
}
|
||||||
|
|
||||||
public async Task<IEnumerable<WellDto>> GetTransmittingWellsAsync(int idCompany,
|
public async Task<IEnumerable<WellDto>> GetTransmittingWellsAsync(int idCompany,
|
||||||
CancellationToken token) =>
|
CancellationToken token)
|
||||||
await telemetryService.GetTransmittingWellsAsync(idCompany, token);
|
{
|
||||||
|
var activeTelemetryIds = telemetryService.GetTransmittingTelemetriesAsync(idCompany)
|
||||||
|
.Select(t => t.Id);
|
||||||
|
|
||||||
|
var wells = await (from w in db.GetWellsForCompany(idCompany)
|
||||||
|
where w.IdTelemetry != null &&
|
||||||
|
activeTelemetryIds.Contains((int)w.IdTelemetry)
|
||||||
|
select w)
|
||||||
|
.AsNoTracking()
|
||||||
|
.ToListAsync(token)
|
||||||
|
.ConfigureAwait(false);
|
||||||
|
|
||||||
|
return wells.Select(Convert);
|
||||||
|
}
|
||||||
|
|
||||||
public async Task<IEnumerable<WellDto>> GetWellsByCompanyAsync(int idCompany, CancellationToken token)
|
public async Task<IEnumerable<WellDto>> GetWellsByCompanyAsync(int idCompany, CancellationToken token)
|
||||||
{
|
{
|
||||||
var wells = await db.GetWellsForCompany(idCompany).ToListAsync(token);
|
var wells = await db.GetWellsForCompany(idCompany).ToListAsync(token);
|
||||||
return wells.Select(w => new WellDto
|
return wells.Select(Convert);
|
||||||
{
|
|
||||||
Id = w.Id,
|
|
||||||
Caption = w.Caption,
|
|
||||||
Cluster = w.Cluster.Caption,
|
|
||||||
Deposit = w.Cluster.Deposit.Caption,
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public async Task<int?> UpdateWellAsync(int idWell, WellParamsDto dto,
|
public async Task<int?> UpdateWellAsync(int idWell, WellParamsDto dto,
|
||||||
@ -97,20 +105,17 @@ namespace AsbCloudInfrastructure.Services
|
|||||||
.FirstOrDefaultAsync(w => w.Id == idWell, token)
|
.FirstOrDefaultAsync(w => w.Id == idWell, token)
|
||||||
.ConfigureAwait(false);
|
.ConfigureAwait(false);
|
||||||
|
|
||||||
var dto = entity.Adapt<WellDto>();
|
if (entity is null)
|
||||||
|
return null;
|
||||||
if (dto is null)
|
|
||||||
return dto;
|
|
||||||
|
|
||||||
dto.Cluster = entity.Cluster?.Caption;
|
var dto = Convert(entity);
|
||||||
dto.Deposit = entity.Cluster?.Deposit?.Caption;
|
|
||||||
|
|
||||||
return dto;
|
return dto;
|
||||||
}
|
}
|
||||||
public async Task<string> GetWellCaptionByIdAsync(int idWell, CancellationToken token)
|
public async Task<string> GetWellCaptionByIdAsync(int idWell, CancellationToken token)
|
||||||
{
|
{
|
||||||
var entity = await cacheWells.FirstOrDefaultAsync(w => w.Id == idWell, token).ConfigureAwait(false);
|
var entity = await cacheWells.FirstOrDefaultAsync(w => w.Id == idWell, token).ConfigureAwait(false);
|
||||||
var dto = entity.Adapt<WellDto>();
|
var dto = Convert(entity);
|
||||||
return dto.Caption;
|
return dto.Caption;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -134,5 +139,17 @@ namespace AsbCloudInfrastructure.Services
|
|||||||
_ => "Незвестно",
|
_ => "Незвестно",
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private WellDto Convert(Well well)
|
||||||
|
{
|
||||||
|
return new WellDto
|
||||||
|
{
|
||||||
|
Id = well.Id,
|
||||||
|
Caption = well.Caption,
|
||||||
|
Cluster = well.Cluster.Caption,
|
||||||
|
Deposit = well.Cluster.Deposit.Caption,
|
||||||
|
LastTelemetryDate = GetLastTelemetryDate(well.Id)
|
||||||
|
};
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user