2021-07-21 15:29:19 +05:00
|
|
|
|
using AsbCloudApp.Comparators;
|
2022-04-08 13:10:06 +05:00
|
|
|
|
using AsbCloudApp.Data.SAUB;
|
2021-04-23 10:21:25 +05:00
|
|
|
|
using AsbCloudApp.Services;
|
|
|
|
|
using AsbCloudDb.Model;
|
|
|
|
|
using AsbCloudInfrastructure.Services.Cache;
|
|
|
|
|
using System.Collections.Generic;
|
|
|
|
|
using System.Linq;
|
|
|
|
|
|
|
|
|
|
namespace AsbCloudInfrastructure.Services
|
|
|
|
|
{
|
|
|
|
|
public class TelemetryUserService : ITelemetryUserService
|
|
|
|
|
{
|
|
|
|
|
private readonly ITelemetryService telemetryService;
|
2021-07-16 09:15:10 +05:00
|
|
|
|
private readonly CacheTable<TelemetryUser> cacheTelemetryUsers;
|
2021-04-23 10:21:25 +05:00
|
|
|
|
|
|
|
|
|
public TelemetryUserService(IAsbCloudDbContext db, CacheDb cacheDb, ITelemetryService telemetryService)
|
|
|
|
|
{
|
|
|
|
|
this.telemetryService = telemetryService;
|
2021-07-16 09:15:10 +05:00
|
|
|
|
cacheTelemetryUsers = cacheDb.GetCachedTable<TelemetryUser>((AsbCloudDbContext)db);
|
2021-04-23 10:21:25 +05:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public void Upsert(string uid, IEnumerable<TelemetryUserDto> dtos)
|
|
|
|
|
{
|
2021-05-20 11:17:55 +05:00
|
|
|
|
if (!dtos.Any())
|
2021-04-23 10:21:25 +05:00
|
|
|
|
return;
|
|
|
|
|
|
2021-12-07 18:27:52 +05:00
|
|
|
|
var telemetryId = telemetryService.GetOrCreateTelemetryIdByUid(uid);
|
2021-04-23 10:21:25 +05:00
|
|
|
|
|
2021-07-16 09:15:10 +05:00
|
|
|
|
var entities = dtos.Distinct(new TelemetryUserDtoComparer()).Select(dto => new TelemetryUser
|
2021-04-23 10:21:25 +05:00
|
|
|
|
{
|
2021-07-16 09:15:10 +05:00
|
|
|
|
IdUser = dto.Id,
|
|
|
|
|
IdTelemetry = telemetryId,
|
|
|
|
|
Level = dto.Level,
|
|
|
|
|
Name = dto.Name,
|
|
|
|
|
Patronymic = dto.Patronymic,
|
|
|
|
|
Surname = dto.Surname,
|
|
|
|
|
});
|
|
|
|
|
cacheTelemetryUsers.Upsert(entities);
|
2021-04-23 10:21:25 +05:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|