forked from ddrilling/AsbCloudServer
merge from dev
This commit is contained in:
commit
e8a71477e6
@ -1,9 +1,9 @@
|
|||||||
using AsbCloudApp.Data;
|
using AsbCloudApp.Data;
|
||||||
|
using AsbCloudApp.Data.WellOperation;
|
||||||
|
using AsbCloudApp.Requests;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using System.Threading;
|
using System.Threading;
|
||||||
using System.Threading.Tasks;
|
using System.Threading.Tasks;
|
||||||
using AsbCloudApp.Data.WellOperation;
|
|
||||||
using AsbCloudApp.Requests;
|
|
||||||
|
|
||||||
namespace AsbCloudApp.Repositories
|
namespace AsbCloudApp.Repositories
|
||||||
{
|
{
|
||||||
@ -17,8 +17,8 @@ namespace AsbCloudApp.Repositories
|
|||||||
/// </summary>
|
/// </summary>
|
||||||
/// <returns></returns>
|
/// <returns></returns>
|
||||||
IEnumerable<WellSectionTypeDto> GetSectionTypes();
|
IEnumerable<WellSectionTypeDto> GetSectionTypes();
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Получить страницу списка операций
|
/// Получить страницу списка операций
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="request"></param>
|
/// <param name="request"></param>
|
||||||
@ -26,7 +26,7 @@ namespace AsbCloudApp.Repositories
|
|||||||
/// <returns></returns>
|
/// <returns></returns>
|
||||||
Task<IEnumerable<WellOperationDto>> GetAsync(WellOperationRequest request, CancellationToken token);
|
Task<IEnumerable<WellOperationDto>> GetAsync(WellOperationRequest request, CancellationToken token);
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Получить страницу списка операций
|
/// Получить страницу списка операций
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="request"></param>
|
/// <param name="request"></param>
|
||||||
@ -34,7 +34,7 @@ namespace AsbCloudApp.Repositories
|
|||||||
/// <returns></returns>
|
/// <returns></returns>
|
||||||
Task<PaginationContainer<WellOperationDto>> GetPageAsync(WellOperationRequest request, CancellationToken token);
|
Task<PaginationContainer<WellOperationDto>> GetPageAsync(WellOperationRequest request, CancellationToken token);
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Получить статистику операции по скважине с группировкой по категориям
|
/// Получить статистику операции по скважине с группировкой по категориям
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="request"></param>
|
/// <param name="request"></param>
|
||||||
@ -42,14 +42,14 @@ namespace AsbCloudApp.Repositories
|
|||||||
/// <returns></returns>
|
/// <returns></returns>
|
||||||
Task<IEnumerable<WellGroupOpertionDto>> GetGroupOperationsStatAsync(WellOperationRequest request, CancellationToken token);
|
Task<IEnumerable<WellGroupOpertionDto>> GetGroupOperationsStatAsync(WellOperationRequest request, CancellationToken token);
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Добавить несколько операций
|
/// Добавить несколько операций
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="dtos"></param>
|
/// <param name="dtos"></param>
|
||||||
/// <param name="deleteBeforeInsert"></param>
|
/// <param name="deleteBeforeInsert"></param>
|
||||||
/// <param name="token"></param>
|
/// <param name="token"></param>
|
||||||
/// <returns></returns>
|
/// <returns></returns>
|
||||||
Task<int> InsertRangeAsync(IEnumerable<WellOperationDto> dtos, bool deleteBeforeInsert, CancellationToken token);
|
Task<int> InsertRangeAsync(IEnumerable<WellOperationDto> dtos, bool deleteBeforeInsert, CancellationToken token);
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Обновить существующую операцию
|
/// Обновить существующую операцию
|
||||||
@ -75,13 +75,20 @@ namespace AsbCloudApp.Repositories
|
|||||||
/// <returns></returns>
|
/// <returns></returns>
|
||||||
Task<IEnumerable<SectionByOperationsDto>> GetSectionsAsync(IEnumerable<int> idsWells, CancellationToken token);
|
Task<IEnumerable<SectionByOperationsDto>> GetSectionsAsync(IEnumerable<int> idsWells, CancellationToken token);
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Получить диапазон дат выполнения операций
|
/// Получить диапазон дат выполнения операций
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="idWell"></param>
|
/// <param name="idWell"></param>
|
||||||
/// <param name="idType"></param>
|
/// <param name="idType"></param>
|
||||||
/// <param name="cancellationToken"></param>
|
/// <param name="cancellationToken"></param>
|
||||||
/// <returns></returns>
|
/// <returns></returns>
|
||||||
Task<DatesRangeDto?> GetDatesRangeAsync(int idWell, int idType, CancellationToken cancellationToken);
|
Task<DatesRangeDto?> GetDatesRangeAsync(int idWell, int idType, CancellationToken cancellationToken);
|
||||||
}
|
|
||||||
|
/// <summary>
|
||||||
|
/// Возвращает первую и последнюю фактическую операцию
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="idWell"></param>
|
||||||
|
/// <returns></returns>
|
||||||
|
(WellOperationDto First, WellOperationDto Last)? GetFirstAndLastFact(int idWell);
|
||||||
|
}
|
||||||
}
|
}
|
@ -16,12 +16,12 @@ namespace AsbCloudInfrastructure.Repository
|
|||||||
public class DepositRepository : IDepositRepository
|
public class DepositRepository : IDepositRepository
|
||||||
{
|
{
|
||||||
private readonly IAsbCloudDbContext db;
|
private readonly IAsbCloudDbContext db;
|
||||||
private readonly IWellService wellService;
|
private readonly ITelemetryService telemetryService;
|
||||||
|
|
||||||
public DepositRepository(IAsbCloudDbContext db, IWellService wellService)
|
public DepositRepository(IAsbCloudDbContext db, ITelemetryService telemetryService)
|
||||||
{
|
{
|
||||||
this.db = db;
|
this.db = db;
|
||||||
this.wellService = wellService;
|
this.telemetryService = telemetryService;
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <inheritdoc/>
|
/// <inheritdoc/>
|
||||||
@ -112,8 +112,12 @@ namespace AsbCloudInfrastructure.Repository
|
|||||||
{
|
{
|
||||||
var dto = well.Adapt<WellDto>();
|
var dto = well.Adapt<WellDto>();
|
||||||
dto.WellType = well.WellType.Caption;
|
dto.WellType = well.WellType.Caption;
|
||||||
dto.LastTelemetryDate = wellService.GetLastTelemetryDate(well.Id)
|
|
||||||
.ToOffset(TimeSpan.FromHours(well.Timezone.Hours));
|
dto.LastTelemetryDate = DateTimeOffset.MinValue;
|
||||||
|
|
||||||
|
if (well.IdTelemetry != null)
|
||||||
|
dto.LastTelemetryDate = telemetryService.GetDatesRange(well.IdTelemetry.Value).To;
|
||||||
|
|
||||||
dto.Cluster = gCluster.Key.Caption;
|
dto.Cluster = gCluster.Key.Caption;
|
||||||
dto.Deposit = gDeposit.Key.Caption;
|
dto.Deposit = gDeposit.Key.Caption;
|
||||||
return dto;
|
return dto;
|
||||||
|
@ -20,6 +20,7 @@ namespace AsbCloudInfrastructure.Repository;
|
|||||||
public class WellOperationRepository : CrudRepositoryBase<WellOperationDto, WellOperation>,
|
public class WellOperationRepository : CrudRepositoryBase<WellOperationDto, WellOperation>,
|
||||||
IWellOperationRepository
|
IWellOperationRepository
|
||||||
{
|
{
|
||||||
|
private const string cacheKeyWellOperations = "FirstAndLastFactWellsOperations";
|
||||||
private readonly IMemoryCache memoryCache;
|
private readonly IMemoryCache memoryCache;
|
||||||
private readonly IWellOperationCategoryRepository wellOperationCategoryRepository;
|
private readonly IWellOperationCategoryRepository wellOperationCategoryRepository;
|
||||||
private readonly IWellService wellService;
|
private readonly IWellService wellService;
|
||||||
@ -54,15 +55,15 @@ public class WellOperationRepository : CrudRepositoryBase<WellOperationDto, Well
|
|||||||
|
|
||||||
public async Task<PaginationContainer<WellOperationDto>> GetPageAsync(WellOperationRequest request, CancellationToken token)
|
public async Task<PaginationContainer<WellOperationDto>> GetPageAsync(WellOperationRequest request, CancellationToken token)
|
||||||
{
|
{
|
||||||
var skip = request.Skip ?? 0;
|
request.Skip = request.Skip ?? 0;
|
||||||
var take = request.Take ?? 32;
|
request.Take = request.Take ?? 32;
|
||||||
|
|
||||||
var (items, count) = await GetWithDaysAndNpvAsync(request, token);
|
var (items, count) = await GetWithDaysAndNpvAsync(request, token);
|
||||||
|
|
||||||
var paginationContainer = new PaginationContainer<WellOperationDto>
|
var paginationContainer = new PaginationContainer<WellOperationDto>
|
||||||
{
|
{
|
||||||
Skip = skip,
|
Skip = request.Skip!.Value,
|
||||||
Take = take,
|
Take = request.Take!.Value,
|
||||||
Count = count,
|
Count = count,
|
||||||
Items = items
|
Items = items
|
||||||
};
|
};
|
||||||
@ -167,11 +168,17 @@ public class WellOperationRepository : CrudRepositoryBase<WellOperationDto, Well
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public override Task<int> UpdateRangeAsync(IEnumerable<WellOperationDto> dtos, CancellationToken token)
|
public override async Task<int> UpdateRangeAsync(IEnumerable<WellOperationDto> dtos, CancellationToken token)
|
||||||
{
|
{
|
||||||
EnsureValidWellOperations(dtos);
|
EnsureValidWellOperations(dtos);
|
||||||
|
|
||||||
return base.UpdateRangeAsync(dtos, token);
|
var result = await base.UpdateRangeAsync(dtos, token);
|
||||||
|
|
||||||
|
if (result > 0)
|
||||||
|
memoryCache.Remove(cacheKeyWellOperations);
|
||||||
|
|
||||||
|
return result;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private static void EnsureValidWellOperations(IEnumerable<WellOperationDto> dtos)
|
private static void EnsureValidWellOperations(IEnumerable<WellOperationDto> dtos)
|
||||||
@ -194,9 +201,6 @@ public class WellOperationRepository : CrudRepositoryBase<WellOperationDto, Well
|
|||||||
|
|
||||||
private async Task<(IEnumerable<WellOperationDto> items, int count)> GetWithDaysAndNpvAsync(WellOperationRequest request, CancellationToken token)
|
private async Task<(IEnumerable<WellOperationDto> items, int count)> GetWithDaysAndNpvAsync(WellOperationRequest request, CancellationToken token)
|
||||||
{
|
{
|
||||||
var skip = request.Skip ?? 0;
|
|
||||||
var take = request.Take ?? 32;
|
|
||||||
|
|
||||||
var entities = await GetByIdsWells(request.IdsWell, token);
|
var entities = await GetByIdsWells(request.IdsWell, token);
|
||||||
var groupedByWellAndType = entities
|
var groupedByWellAndType = entities
|
||||||
.GroupBy(e => new { e.IdWell, e.IdType });
|
.GroupBy(e => new { e.IdWell, e.IdType });
|
||||||
@ -214,11 +218,14 @@ public class WellOperationRepository : CrudRepositoryBase<WellOperationDto, Well
|
|||||||
|
|
||||||
IEnumerable<WellOperation> filteredWellOperations = FilterByRequest(wellOperationsWithType.AsQueryable(), request);
|
IEnumerable<WellOperation> filteredWellOperations = FilterByRequest(wellOperationsWithType.AsQueryable(), request);
|
||||||
|
|
||||||
var filteredWellOperationsPart = filteredWellOperations
|
count += filteredWellOperations.Count();
|
||||||
.Skip(skip)
|
|
||||||
.Take(take);
|
|
||||||
|
|
||||||
var dtos = filteredWellOperationsPart
|
if (request.Skip != null)
|
||||||
|
filteredWellOperations = filteredWellOperations.Skip((int)request.Skip);
|
||||||
|
if (request.Take != null)
|
||||||
|
filteredWellOperations = filteredWellOperations.Take((int)request.Take);
|
||||||
|
|
||||||
|
var dtos = filteredWellOperations
|
||||||
.Select(entity =>
|
.Select(entity =>
|
||||||
{
|
{
|
||||||
var dto = Convert(entity);
|
var dto = Convert(entity);
|
||||||
@ -230,7 +237,6 @@ public class WellOperationRepository : CrudRepositoryBase<WellOperationDto, Well
|
|||||||
});
|
});
|
||||||
|
|
||||||
result.AddRange(dtos);
|
result.AddRange(dtos);
|
||||||
count += filteredWellOperations.Count();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return (result, count);
|
return (result, count);
|
||||||
@ -367,6 +373,53 @@ public class WellOperationRepository : CrudRepositoryBase<WellOperationDto, Well
|
|||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public (WellOperationDto First, WellOperationDto Last)? GetFirstAndLastFact(int idWell)
|
||||||
|
{
|
||||||
|
var cachedDictionary = memoryCache.GetOrCreate(cacheKeyWellOperations, (entry) =>
|
||||||
|
{
|
||||||
|
entry.AbsoluteExpirationRelativeToNow = TimeSpan.FromMinutes(5);
|
||||||
|
var query = dbContext.Set<WellOperation>()
|
||||||
|
.Where(o => o.IdType == WellOperation.IdOperationTypeFact)
|
||||||
|
.GroupBy(o => o.IdWell)
|
||||||
|
.Select(group => new
|
||||||
|
{
|
||||||
|
IdWell = group.Key,
|
||||||
|
FirstFact = group.OrderBy(o => o.DateStart).First(),
|
||||||
|
LastFact = group.OrderBy(o => o.DateStart).Last(),
|
||||||
|
});
|
||||||
|
|
||||||
|
var entities = query.ToArray();
|
||||||
|
|
||||||
|
var dictionary = entities.ToDictionary(s => s.IdWell, s => (Convert(s.FirstFact), Convert(s.LastFact)));
|
||||||
|
entry.Value = dictionary;
|
||||||
|
|
||||||
|
return dictionary;
|
||||||
|
|
||||||
|
})!;
|
||||||
|
|
||||||
|
var firstAndLast = cachedDictionary.GetValueOrDefault(idWell);
|
||||||
|
return firstAndLast;
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
public override async Task<int> DeleteAsync(int id, CancellationToken token)
|
||||||
|
{
|
||||||
|
var result = await base.DeleteAsync(id, token);
|
||||||
|
if (result > 0)
|
||||||
|
memoryCache.Remove(cacheKeyWellOperations);
|
||||||
|
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
|
public override async Task<int> DeleteRangeAsync(IEnumerable<int> ids, CancellationToken token)
|
||||||
|
{
|
||||||
|
var result = await base.DeleteRangeAsync(ids, token);
|
||||||
|
if (result > 0)
|
||||||
|
memoryCache.Remove(cacheKeyWellOperations);
|
||||||
|
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
protected override WellOperation Convert(WellOperationDto src)
|
protected override WellOperation Convert(WellOperationDto src)
|
||||||
{
|
{
|
||||||
var entity = src.Adapt<WellOperation>();
|
var entity = src.Adapt<WellOperation>();
|
||||||
|
@ -142,14 +142,13 @@ namespace AsbCloudInfrastructure.Services.SAUB
|
|||||||
return Task.CompletedTask;
|
return Task.CompletedTask;
|
||||||
|
|
||||||
var telemetry = telemetryService.GetOrCreateTelemetryByUid(uid);
|
var telemetry = telemetryService.GetOrCreateTelemetryByUid(uid);
|
||||||
var timezone = telemetryService.GetTimezone(telemetry.Id);
|
|
||||||
|
|
||||||
foreach (var dto in dtos)
|
foreach (var dto in dtos)
|
||||||
{
|
{
|
||||||
var entity = dto.Adapt<TelemetryMessage>();
|
var entity = dto.Adapt<TelemetryMessage>();
|
||||||
entity.Id = 0;
|
entity.Id = 0;
|
||||||
entity.IdTelemetry = telemetry.Id;
|
entity.IdTelemetry = telemetry.Id;
|
||||||
entity.DateTime = dto.Date.ToOffset(TimeSpan.FromHours(timezone.Hours));
|
entity.DateTime = dto.Date.ToUniversalTime();
|
||||||
db.TelemetryMessages.Add(entity);
|
db.TelemetryMessages.Add(entity);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -37,7 +37,8 @@ public class WellInfoService
|
|||||||
var telemetryDataSaubCache = services.GetRequiredService<ITelemetryDataCache<TelemetryDataSaubDto>>();
|
var telemetryDataSaubCache = services.GetRequiredService<ITelemetryDataCache<TelemetryDataSaubDto>>();
|
||||||
var messageHub = services.GetRequiredService<IIntegrationEventHandler<UpdateWellInfoEvent>>();
|
var messageHub = services.GetRequiredService<IIntegrationEventHandler<UpdateWellInfoEvent>>();
|
||||||
|
|
||||||
var wells = await wellService.GetAllAsync(token);
|
var entries = await wellService.GetAllAsync(token);
|
||||||
|
var wells = entries.ToList();
|
||||||
var activeWells = wells.Where(well => well.IdState == 1);
|
var activeWells = wells.Where(well => well.IdState == 1);
|
||||||
|
|
||||||
var wellsIds = activeWells.Select(w => w.Id);
|
var wellsIds = activeWells.Select(w => w.Id);
|
||||||
|
@ -42,7 +42,7 @@ public class WellOperationExport<TTemplate> : ExcelExportService<WellOperationDt
|
|||||||
{
|
{
|
||||||
var request = new WellOperationRequest(new[] { options.IdWell })
|
var request = new WellOperationRequest(new[] { options.IdWell })
|
||||||
{
|
{
|
||||||
OperationType = options.IdType
|
OperationType = options.IdType,
|
||||||
};
|
};
|
||||||
|
|
||||||
return wellOperationRepository.GetAsync(request, token);
|
return wellOperationRepository.GetAsync(request, token);
|
||||||
|
@ -116,12 +116,12 @@ namespace AsbCloudInfrastructure.Services
|
|||||||
|
|
||||||
if (well is null)
|
if (well is null)
|
||||||
return null;
|
return null;
|
||||||
|
|
||||||
var wellInfo = wellInfoService.FirstOrDefault(well => well.Id == idWell);
|
var wellInfo = wellInfoService.FirstOrDefault(well => well.Id == idWell);
|
||||||
|
|
||||||
if (wellInfo is null)
|
if (wellInfo is null)
|
||||||
return well.Adapt<WellMapInfoWithTelemetryStat>();
|
return well.Adapt<WellMapInfoWithTelemetryStat>();
|
||||||
|
|
||||||
wellInfo.IdState = well.IdState;
|
wellInfo.IdState = well.IdState;
|
||||||
return wellInfo;
|
return wellInfo;
|
||||||
}
|
}
|
||||||
@ -153,7 +153,7 @@ namespace AsbCloudInfrastructure.Services
|
|||||||
{
|
{
|
||||||
if (IsTelemetryAssignedToDifferentWell(dto))
|
if (IsTelemetryAssignedToDifferentWell(dto))
|
||||||
throw new ArgumentInvalidException(nameof(dto), "Телеметрия уже была привязана к другой скважине.");
|
throw new ArgumentInvalidException(nameof(dto), "Телеметрия уже была привязана к другой скважине.");
|
||||||
|
|
||||||
if (dto.Id != 0 && (await GetCacheAsync(token)).Any(w => w.Id == dto.Id))
|
if (dto.Id != 0 && (await GetCacheAsync(token)).Any(w => w.Id == dto.Id))
|
||||||
throw new ArgumentInvalidException(nameof(dto), $"Нельзя повторно добавить скважину с id: {dto.Id}");
|
throw new ArgumentInvalidException(nameof(dto), $"Нельзя повторно добавить скважину с id: {dto.Id}");
|
||||||
|
|
||||||
@ -177,12 +177,12 @@ namespace AsbCloudInfrastructure.Services
|
|||||||
throw new NotImplementedException();
|
throw new NotImplementedException();
|
||||||
}
|
}
|
||||||
|
|
||||||
public override async Task<int> UpdateAsync(WellDto dto,
|
public override async Task<int> UpdateAsync(WellDto dto,
|
||||||
CancellationToken token)
|
CancellationToken token)
|
||||||
{
|
{
|
||||||
if (IsTelemetryAssignedToDifferentWell(dto))
|
if (IsTelemetryAssignedToDifferentWell(dto))
|
||||||
throw new ArgumentInvalidException(nameof(dto), "Телеметрия уже была привязана к другой скважине.");
|
throw new ArgumentInvalidException(nameof(dto), "Телеметрия уже была привязана к другой скважине.");
|
||||||
|
|
||||||
var oldRelations = (await GetCacheRelationCompanyWellAsync(token))
|
var oldRelations = (await GetCacheRelationCompanyWellAsync(token))
|
||||||
.Where(r => r.IdWell == dto.Id).ToArray();
|
.Where(r => r.IdWell == dto.Id).ToArray();
|
||||||
|
|
||||||
@ -192,16 +192,16 @@ namespace AsbCloudInfrastructure.Services
|
|||||||
dbContext.RelationCompaniesWells
|
dbContext.RelationCompaniesWells
|
||||||
.RemoveRange(dbContext.RelationCompaniesWells
|
.RemoveRange(dbContext.RelationCompaniesWells
|
||||||
.Where(r => r.IdWell == dto.Id));
|
.Where(r => r.IdWell == dto.Id));
|
||||||
|
|
||||||
DropCacheRelationCompanyWell();
|
DropCacheRelationCompanyWell();
|
||||||
|
|
||||||
var newRelations = dto.Companies
|
var newRelations = dto.Companies
|
||||||
.Select(c => new RelationCompanyWell
|
.Select(c => new RelationCompanyWell
|
||||||
{
|
{
|
||||||
IdWell = dto.Id,
|
IdWell = dto.Id,
|
||||||
IdCompany = c.Id
|
IdCompany = c.Id
|
||||||
});
|
});
|
||||||
|
|
||||||
dbContext.RelationCompaniesWells.AddRange(newRelations);
|
dbContext.RelationCompaniesWells.AddRange(newRelations);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -215,7 +215,7 @@ namespace AsbCloudInfrastructure.Services
|
|||||||
|
|
||||||
public async Task<string> GetWellCaptionByIdAsync(int idWell, CancellationToken token)
|
public async Task<string> GetWellCaptionByIdAsync(int idWell, CancellationToken token)
|
||||||
{
|
{
|
||||||
var entity = await GetOrDefaultAsync(idWell, token).ConfigureAwait(false);
|
var entity = await GetOrDefaultAsync(idWell, token).ConfigureAwait(false);
|
||||||
return entity!.Caption;
|
return entity!.Caption;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -272,10 +272,9 @@ namespace AsbCloudInfrastructure.Services
|
|||||||
|
|
||||||
if (entity.Timezone is null)
|
if (entity.Timezone is null)
|
||||||
dto.Timezone = GetTimezone(entity.Id);
|
dto.Timezone = GetTimezone(entity.Id);
|
||||||
|
|
||||||
dto.StartDate = dbContext.WellOperations.Where(e => e.IdType == WellOperation.IdOperationTypeFact)
|
dto.StartDate = wellOperationRepository
|
||||||
.AsNoTracking()
|
.GetFirstAndLastFact(entity.Id)?.First?.DateStart;
|
||||||
.MinOrDefault(e => e.DateStart)?.ToRemoteDateTime(dto.Timezone.Hours);
|
|
||||||
dto.WellType = entity.WellType.Caption;
|
dto.WellType = entity.WellType.Caption;
|
||||||
dto.Cluster = entity.Cluster.Caption;
|
dto.Cluster = entity.Cluster.Caption;
|
||||||
dto.Deposit = entity.Cluster.Deposit.Caption;
|
dto.Deposit = entity.Cluster.Deposit.Caption;
|
||||||
|
@ -0,0 +1,23 @@
|
|||||||
|
using AsbCloudApp.Data.SAUB;
|
||||||
|
using Refit;
|
||||||
|
|
||||||
|
namespace AsbCloudWebApi.IntegrationTests.Clients;
|
||||||
|
public interface ITelemetryControllerClient
|
||||||
|
{
|
||||||
|
private const string BaseRoute = "/api/telemetry";
|
||||||
|
|
||||||
|
[Get($"{BaseRoute}/Active")]
|
||||||
|
Task<IApiResponse> GetTelemetriesInfoByLastData(CancellationToken token);
|
||||||
|
|
||||||
|
[Post($"{BaseRoute}/{{uid}}/info")]
|
||||||
|
Task<IApiResponse> PostInfoAsync(string uid, [Body] TelemetryInfoDto info, CancellationToken token);
|
||||||
|
|
||||||
|
[Post($"{BaseRoute}/{{uid}}/message")]
|
||||||
|
Task<IApiResponse> PostMessagesAsync(string uid, [Body] IEnumerable<TelemetryMessageDto> dtos, CancellationToken token);
|
||||||
|
|
||||||
|
[Post($"{BaseRoute}/{{uid}}/event")]
|
||||||
|
Task<IApiResponse> PostEventsAsync(string uid, [Body] IEnumerable<EventDto> dtos, CancellationToken token);
|
||||||
|
|
||||||
|
[Post($"{BaseRoute}/{{uid}}/user")]
|
||||||
|
Task<IApiResponse> PostUsersAsync(string uid, [Body] IEnumerable<TelemetryUserDto> dtos, CancellationToken token);
|
||||||
|
}
|
@ -0,0 +1,109 @@
|
|||||||
|
using AsbCloudApp.Data.SAUB;
|
||||||
|
using AsbCloudDb.Model;
|
||||||
|
using AsbCloudWebApi.IntegrationTests.Clients;
|
||||||
|
using Xunit;
|
||||||
|
|
||||||
|
namespace AsbCloudWebApi.IntegrationTests.Controllers;
|
||||||
|
public class TelemetryControllerTest : BaseIntegrationTest
|
||||||
|
{
|
||||||
|
private ITelemetryControllerClient client;
|
||||||
|
static readonly string uid = DateTime.UtcNow.ToString("yyyyMMdd_HHmmssfff");
|
||||||
|
|
||||||
|
private static readonly SimpleTimezone timezone = new() {TimezoneId = "a", Hours = 5 };
|
||||||
|
private static readonly Telemetry telemetry = new Telemetry() {Id = 1, RemoteUid = uid, TimeZone = timezone, Info = new() };
|
||||||
|
private readonly IEnumerable<EventDto> events = [new() { Id = 1, EventType = 1, IdCategory = 1, IdSound = 1, Message = "there is no spoon {tag1}", Tag = "tag1" }];
|
||||||
|
private readonly IEnumerable<TelemetryUserDto> users = [new TelemetryUserDto() { Id = 1, Level = 0, Name = "Neo", Patronymic = "Kianovich", Surname = "Theone" }];
|
||||||
|
private readonly IEnumerable<TelemetryMessageDto> messages = [new TelemetryMessageDto() { Id = 100, IdEvent = 1, WellDepth = 5, Date = DateTimeOffset.Now.ToOffset(TimeSpan.FromHours(5)), Arg0 = "3.14", IdTelemetryUser = 1 }];
|
||||||
|
private readonly IEnumerable<TelemetryDataSaub> telemetryDataSaubEntities = [new TelemetryDataSaub()
|
||||||
|
{
|
||||||
|
IdTelemetry = telemetry.Id,
|
||||||
|
DateTime = DateTimeOffset.UtcNow,
|
||||||
|
AxialLoad = 2,
|
||||||
|
WellDepth = 5,
|
||||||
|
BitDepth = 5,
|
||||||
|
BlockPosition = 5,
|
||||||
|
BlockSpeed = 5,
|
||||||
|
}];
|
||||||
|
|
||||||
|
public TelemetryControllerTest(WebAppFactoryFixture factory)
|
||||||
|
: base(factory)
|
||||||
|
{
|
||||||
|
client = factory.GetAuthorizedHttpClient<ITelemetryControllerClient>(string.Empty);
|
||||||
|
}
|
||||||
|
|
||||||
|
[Fact]
|
||||||
|
public async Task GetTelemetriesInfoByLastData()
|
||||||
|
{
|
||||||
|
// Arrange
|
||||||
|
dbContext.CleanupDbSet<Telemetry>();
|
||||||
|
dbContext.Set<Telemetry>().Add(telemetry);
|
||||||
|
dbContext.Set<TelemetryDataSaub>().AddRange(telemetryDataSaubEntities);
|
||||||
|
dbContext.SaveChanges();
|
||||||
|
|
||||||
|
// Act
|
||||||
|
var response = await client.GetTelemetriesInfoByLastData(CancellationToken.None);
|
||||||
|
|
||||||
|
// Assert
|
||||||
|
Assert.Equal(System.Net.HttpStatusCode.OK, response.StatusCode);
|
||||||
|
}
|
||||||
|
|
||||||
|
[Fact]
|
||||||
|
public async Task PostUsersAsync()
|
||||||
|
{
|
||||||
|
// arrange
|
||||||
|
dbContext.CleanupDbSet<Telemetry>();
|
||||||
|
|
||||||
|
// act
|
||||||
|
var response = await client.PostUsersAsync(uid, users, CancellationToken.None);
|
||||||
|
|
||||||
|
// Assert
|
||||||
|
Assert.Equal(System.Net.HttpStatusCode.OK, response.StatusCode);
|
||||||
|
var telemetriesCount = dbContext.Set<Telemetry>().Count();
|
||||||
|
var telemetryUserCount = dbContext.Set<TelemetryUser>().Count();
|
||||||
|
|
||||||
|
Assert.Equal(1, telemetriesCount);
|
||||||
|
Assert.Equal(1, telemetryUserCount);
|
||||||
|
}
|
||||||
|
|
||||||
|
[Fact]
|
||||||
|
public async Task PostEventsAsync()
|
||||||
|
{
|
||||||
|
// arrange
|
||||||
|
dbContext.CleanupDbSet<Telemetry>();
|
||||||
|
|
||||||
|
// act
|
||||||
|
var response = await client.PostEventsAsync(uid, events, CancellationToken.None);
|
||||||
|
|
||||||
|
// Assert
|
||||||
|
Assert.Equal(System.Net.HttpStatusCode.OK, response.StatusCode);
|
||||||
|
var telemetriesCount = dbContext.Set<Telemetry>().Count();
|
||||||
|
var telemetryEventCount = dbContext.Set<TelemetryEvent>().Count();
|
||||||
|
|
||||||
|
Assert.Equal(1, telemetriesCount);
|
||||||
|
Assert.Equal(1, telemetryEventCount);
|
||||||
|
}
|
||||||
|
|
||||||
|
[Fact]
|
||||||
|
public async Task PostMessagesAsync()
|
||||||
|
{
|
||||||
|
// arrange
|
||||||
|
dbContext.CleanupDbSet<Telemetry>();
|
||||||
|
|
||||||
|
// act
|
||||||
|
_ = await client.PostEventsAsync(uid, events, CancellationToken.None);
|
||||||
|
_ = await client.PostUsersAsync(uid, users, CancellationToken.None);
|
||||||
|
var response = await client.PostMessagesAsync(uid, messages, CancellationToken.None);
|
||||||
|
|
||||||
|
// Assert
|
||||||
|
Assert.Equal(System.Net.HttpStatusCode.OK, response.StatusCode);
|
||||||
|
var telemetriesCount = dbContext.Set<Telemetry>().Count();
|
||||||
|
var telemetryEventCount = dbContext.Set<TelemetryEvent>().Count();
|
||||||
|
var telemetryUserCount = dbContext.Set<TelemetryUser>().Count();
|
||||||
|
var telemetryMessageCount = dbContext.Set<TelemetryMessage>().Count();
|
||||||
|
|
||||||
|
Assert.Equal(1, telemetriesCount);
|
||||||
|
Assert.Equal(1, telemetryEventCount);
|
||||||
|
Assert.Equal(1, telemetryUserCount);
|
||||||
|
Assert.Equal(1, telemetryMessageCount);
|
||||||
|
}
|
||||||
|
}
|
@ -21,7 +21,7 @@ public class WorkTest
|
|||||||
((ISupportRequiredService)serviceProviderMock).GetRequiredService(typeof(IServiceScopeFactory)).Returns(serviceScopeFactoryMock);
|
((ISupportRequiredService)serviceProviderMock).GetRequiredService(typeof(IServiceScopeFactory)).Returns(serviceScopeFactoryMock);
|
||||||
}
|
}
|
||||||
|
|
||||||
[Fact]
|
[Fact, MethodImpl(MethodImplOptions.NoOptimization)]
|
||||||
public async Task Start_ShouldReturn_Success()
|
public async Task Start_ShouldReturn_Success()
|
||||||
{
|
{
|
||||||
//arrange
|
//arrange
|
||||||
@ -50,7 +50,7 @@ public class WorkTest
|
|||||||
Assert.InRange(lastState.ExecutionTime, TimeSpan.Zero, executionTime);
|
Assert.InRange(lastState.ExecutionTime, TimeSpan.Zero, executionTime);
|
||||||
}
|
}
|
||||||
|
|
||||||
[Fact]
|
[Fact, MethodImpl(MethodImplOptions.NoOptimization)]
|
||||||
public async Task ExecutionWork_Invokes_Callback()
|
public async Task ExecutionWork_Invokes_Callback()
|
||||||
{
|
{
|
||||||
//arrange
|
//arrange
|
||||||
|
Loading…
Reference in New Issue
Block a user