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;
|
2022-06-10 17:36:03 +05:00
|
|
|
|
using AsbCloudDb;
|
2021-04-23 10:21:25 +05:00
|
|
|
|
using AsbCloudDb.Model;
|
2022-06-10 17:36:03 +05:00
|
|
|
|
using AsbCloudInfrastructure.EfCache;
|
2021-04-23 10:21:25 +05:00
|
|
|
|
using System.Collections.Generic;
|
|
|
|
|
using System.Linq;
|
2022-06-10 17:36:03 +05:00
|
|
|
|
using System.Threading;
|
|
|
|
|
using System.Threading.Tasks;
|
2021-04-23 10:21:25 +05:00
|
|
|
|
|
2022-04-11 18:00:34 +05:00
|
|
|
|
namespace AsbCloudInfrastructure.Services.SAUB
|
2021-04-23 10:21:25 +05:00
|
|
|
|
{
|
|
|
|
|
public class TelemetryUserService : ITelemetryUserService
|
|
|
|
|
{
|
2022-06-10 17:36:03 +05:00
|
|
|
|
private readonly IAsbCloudDbContext db;
|
2021-04-23 10:21:25 +05:00
|
|
|
|
private readonly ITelemetryService telemetryService;
|
|
|
|
|
|
2022-06-10 17:36:03 +05:00
|
|
|
|
public TelemetryUserService(IAsbCloudDbContext db, ITelemetryService telemetryService)
|
2021-04-23 10:21:25 +05:00
|
|
|
|
{
|
2022-06-10 17:36:03 +05:00
|
|
|
|
this.db = db;
|
2021-04-23 10:21:25 +05:00
|
|
|
|
this.telemetryService = telemetryService;
|
|
|
|
|
}
|
|
|
|
|
|
2022-06-10 17:36:03 +05:00
|
|
|
|
public async Task UpsertAsync(string uid, IEnumerable<TelemetryUserDto> dtos, CancellationToken token = default)
|
2021-04-23 10:21:25 +05:00
|
|
|
|
{
|
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,
|
|
|
|
|
});
|
2022-06-10 17:36:03 +05:00
|
|
|
|
var result = await db.Database.ExecInsertOrUpdateAsync(db.TelemetryUsers, entities, token);
|
|
|
|
|
db.TelemetryUsers.DropCache();
|
2021-04-23 10:21:25 +05:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|