forked from ddrilling/AsbCloudServer
Переписан метод GetTimezone (метод больше не маппит в dto)
This commit is contained in:
parent
e2cd8cbfd2
commit
626c3cb238
@ -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;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -270,10 +270,7 @@ namespace AsbCloudInfrastructure.Services
|
|||||||
{
|
{
|
||||||
var dto = base.Convert(entity);
|
var dto = base.Convert(entity);
|
||||||
|
|
||||||
if (entity.Timezone is null)
|
dto.StartDate = wellOperationRepository.FirstOperationDate(entity.Id);
|
||||||
dto.Timezone = GetTimezone(entity.Id);
|
|
||||||
|
|
||||||
dto.StartDate = wellOperationRepository.FirstOperationDate(entity.Id)?.ToOffset(TimeSpan.FromHours(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;
|
||||||
@ -296,47 +293,10 @@ namespace AsbCloudInfrastructure.Services
|
|||||||
|
|
||||||
public SimpleTimezoneDto GetTimezone(int idWell)
|
public SimpleTimezoneDto GetTimezone(int idWell)
|
||||||
{
|
{
|
||||||
var well = GetOrDefault(idWell)
|
var cache = GetCache();
|
||||||
|
var cacheItem = cache.FirstOrDefault(d => d.Id == idWell)
|
||||||
?? throw new ArgumentInvalidException(nameof(idWell), $"idWell: {idWell} does not exist.");
|
?? throw new ArgumentInvalidException(nameof(idWell), $"idWell: {idWell} does not exist.");
|
||||||
return GetTimezone(well);
|
return cacheItem.Timezone.Adapt<SimpleTimezoneDto>();
|
||||||
}
|
|
||||||
|
|
||||||
private SimpleTimezoneDto GetTimezone(WellDto wellDto)
|
|
||||||
{
|
|
||||||
if (wellDto.Timezone is not null)
|
|
||||||
return wellDto.Timezone;
|
|
||||||
|
|
||||||
if (wellDto.Telemetry is not null)
|
|
||||||
{
|
|
||||||
var timezone = telemetryService.GetTimezone(wellDto.Telemetry.Id);
|
|
||||||
if (timezone is not null)
|
|
||||||
return timezone;
|
|
||||||
}
|
|
||||||
|
|
||||||
var well = GetQuery().FirstOrDefault(w => w.Id == wellDto.Id);
|
|
||||||
|
|
||||||
if (well is not null)
|
|
||||||
{
|
|
||||||
var point = GetCoordinates(well);
|
|
||||||
if (point is not null)
|
|
||||||
{
|
|
||||||
if (point.Timezone is not null)
|
|
||||||
{
|
|
||||||
return point.Timezone.Adapt<SimpleTimezoneDto>();
|
|
||||||
}
|
|
||||||
|
|
||||||
if (point.Latitude is not null & point.Longitude is not null)
|
|
||||||
{
|
|
||||||
var timezone = timezoneService.GetOrDefaultByCoordinates(point.Latitude!.Value, point.Longitude!.Value);
|
|
||||||
if (timezone is not null)
|
|
||||||
{
|
|
||||||
return timezone;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
throw new Exception($"Can't find timezone for well {wellDto.Caption} id: {wellDto.Id}");
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private bool IsTelemetryAssignedToDifferentWell(WellDto wellDto)
|
private bool IsTelemetryAssignedToDifferentWell(WellDto wellDto)
|
||||||
@ -349,7 +309,7 @@ namespace AsbCloudInfrastructure.Services
|
|||||||
|
|
||||||
if (existingWellWithAssignedTelemetry is null)
|
if (existingWellWithAssignedTelemetry is null)
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
return existingWellWithAssignedTelemetry.Id != wellDto.Id;
|
return existingWellWithAssignedTelemetry.Id != wellDto.Id;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user