forked from ddrilling/AsbCloudServer
49 lines
1.8 KiB
C#
49 lines
1.8 KiB
C#
using AsbCloudApp.Data.SAUB;
|
|
using AsbCloudApp.Services;
|
|
using AsbCloudDb.Model;
|
|
using Mapster;
|
|
using System.Linq;
|
|
|
|
namespace AsbCloudInfrastructure.Services.SAUB
|
|
{
|
|
#nullable enable
|
|
public class TelemetryDataSaubService : TelemetryDataBaseService<TelemetryDataSaubDto, TelemetryDataSaub>
|
|
{
|
|
private readonly ITelemetryUserService telemetryUserService;
|
|
|
|
public TelemetryDataSaubService(
|
|
IAsbCloudDbContext db,
|
|
ITelemetryService telemetryService,
|
|
ITelemetryUserService telemetryUserService,
|
|
TelemetryDataCache<TelemetryDataSaubDto> telemetryDataCache)
|
|
: base(db, telemetryService, telemetryDataCache)
|
|
{
|
|
this.telemetryUserService = telemetryUserService;
|
|
}
|
|
|
|
public override TelemetryDataSaub Convert(TelemetryDataSaubDto src, double timezoneOffset)
|
|
{
|
|
var entity = src.Adapt<TelemetryDataSaub>();
|
|
var telemetryUser = telemetryUserService
|
|
.GetUsers(src.IdTelemetry, u => (u.Name == src.User || u.Surname == src.User))
|
|
.FirstOrDefault();
|
|
entity.IdUser = telemetryUser?.Id;
|
|
entity.DateTime = src.DateTime.ToUtcDateTimeOffset(timezoneOffset);
|
|
return entity;
|
|
}
|
|
|
|
public override TelemetryDataSaubDto Convert(TelemetryDataSaub src, double timezoneOffset)
|
|
{
|
|
var dto = src.Adapt<TelemetryDataSaubDto>();
|
|
var telemetryUser = telemetryUserService.GetOrDefault(src.IdTelemetry, src.IdUser??int.MinValue);
|
|
dto.User = telemetryUser?.MakeDisplayName();
|
|
dto.DateTime = src.DateTime.ToRemoteDateTime(timezoneOffset);
|
|
dto.BitDepth = src.BitDepth <= src.WellDepth
|
|
? src.BitDepth
|
|
: src.WellDepth;
|
|
return dto;
|
|
}
|
|
}
|
|
#nullable disable
|
|
}
|