2022-04-08 13:10:06 +05:00
|
|
|
|
using AsbCloudApp.Data.SAUB;
|
2021-09-17 16:24:01 +05:00
|
|
|
|
using AsbCloudApp.Services;
|
|
|
|
|
using AsbCloudDb.Model;
|
|
|
|
|
using Mapster;
|
2022-10-06 13:49:20 +05:00
|
|
|
|
using System.Linq;
|
2021-09-17 16:24:01 +05:00
|
|
|
|
|
2022-04-11 18:00:34 +05:00
|
|
|
|
namespace AsbCloudInfrastructure.Services.SAUB
|
2021-09-17 16:24:01 +05:00
|
|
|
|
{
|
2022-11-18 12:58:53 +05:00
|
|
|
|
#nullable enable
|
2022-04-11 18:00:34 +05:00
|
|
|
|
public class TelemetryDataSaubService : TelemetryDataBaseService<TelemetryDataSaubDto, TelemetryDataSaub>
|
2021-09-17 16:24:01 +05:00
|
|
|
|
{
|
2022-11-18 12:58:53 +05:00
|
|
|
|
private readonly ITelemetryUserService telemetryUserService;
|
|
|
|
|
|
2021-09-17 16:24:01 +05:00
|
|
|
|
public TelemetryDataSaubService(
|
|
|
|
|
IAsbCloudDbContext db,
|
|
|
|
|
ITelemetryService telemetryService,
|
2022-11-18 12:58:53 +05:00
|
|
|
|
ITelemetryUserService telemetryUserService,
|
|
|
|
|
TelemetryDataCache<TelemetryDataSaubDto> telemetryDataCache)
|
|
|
|
|
: base(db, telemetryService, telemetryDataCache)
|
|
|
|
|
{
|
|
|
|
|
this.telemetryUserService = telemetryUserService;
|
|
|
|
|
}
|
2021-09-17 16:24:01 +05:00
|
|
|
|
|
2022-01-05 17:50:45 +05:00
|
|
|
|
public override TelemetryDataSaub Convert(TelemetryDataSaubDto src, double timezoneOffset)
|
2021-09-17 16:24:01 +05:00
|
|
|
|
{
|
|
|
|
|
var entity = src.Adapt<TelemetryDataSaub>();
|
2022-11-18 12:58:53 +05:00
|
|
|
|
var telemetryUser = telemetryUserService
|
|
|
|
|
.GetUsers(src.IdTelemetry, u => (u.Name == src.User || u.Surname == src.User))
|
|
|
|
|
.FirstOrDefault();
|
|
|
|
|
entity.IdUser = telemetryUser?.Id;
|
2022-04-08 13:10:06 +05:00
|
|
|
|
entity.DateTime = src.DateTime.ToUtcDateTimeOffset(timezoneOffset);
|
2021-09-17 16:24:01 +05:00
|
|
|
|
return entity;
|
|
|
|
|
}
|
|
|
|
|
|
2022-01-05 17:50:45 +05:00
|
|
|
|
public override TelemetryDataSaubDto Convert(TelemetryDataSaub src, double timezoneOffset)
|
2021-09-17 16:24:01 +05:00
|
|
|
|
{
|
|
|
|
|
var dto = src.Adapt<TelemetryDataSaubDto>();
|
2022-11-18 12:58:53 +05:00
|
|
|
|
var telemetryUser = telemetryUserService.GetOrDefault(src.IdTelemetry, src.IdUser??int.MinValue);
|
2021-09-23 10:53:48 +05:00
|
|
|
|
dto.User = telemetryUser?.MakeDisplayName();
|
2022-04-08 13:10:06 +05:00
|
|
|
|
dto.DateTime = src.DateTime.ToRemoteDateTime(timezoneOffset);
|
2022-11-25 15:26:45 +05:00
|
|
|
|
dto.BitDepth = src.BitDepth <= src.WellDepth
|
|
|
|
|
? src.BitDepth
|
|
|
|
|
: src.WellDepth;
|
2021-09-17 16:24:01 +05:00
|
|
|
|
return dto;
|
|
|
|
|
}
|
|
|
|
|
}
|
2022-11-18 12:58:53 +05:00
|
|
|
|
#nullable disable
|
2021-09-17 16:24:01 +05:00
|
|
|
|
}
|