forked from ddrilling/AsbCloudServer
#7963103 fixes
This commit is contained in:
parent
60a80745a9
commit
5948a762ba
@ -11,7 +11,7 @@ namespace AsbCloudApp.Data.SAUB
|
||||
/// <summary>
|
||||
/// отметка времени
|
||||
/// </summary>
|
||||
public DateTimeOffset DateTime { get; set; }
|
||||
public DateTime DateTime { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Наработка талевого каната с момента перетяжки каната, т*км
|
||||
|
@ -28,7 +28,7 @@ namespace AsbCloudApp.Repositories
|
||||
/// <param name="token"></param>
|
||||
/// <param name="wellInfo"></param>
|
||||
/// <returns></returns>
|
||||
Task<TelemetryWirelineRunOutDto?> GetValueOrDefaultAsync(int idWell, CancellationToken token);
|
||||
Task<TelemetryWirelineRunOutDto?> GetOrDefaultAsync(int idWell, CancellationToken token);
|
||||
|
||||
/// <summary>
|
||||
/// Возвращает данные по всем скважинам
|
||||
|
@ -13,7 +13,7 @@ namespace AsbCloudDb.Model
|
||||
public int IdTelemetry { get; set; }
|
||||
|
||||
[Column("date_time"), Comment("Отметка времени")]
|
||||
public DateTime DateTime { get; set; }
|
||||
public DateTimeOffset DateTime { get; set; }
|
||||
|
||||
[Column("hauling"), Comment("Наработка талевого каната с момента перетяжки каната, т*км")]
|
||||
public float Hauling { get; set; }
|
||||
|
@ -4,6 +4,12 @@ namespace AsbCloudInfrastructure
|
||||
{
|
||||
public static class DateTimeExtentions
|
||||
{
|
||||
/// <summary>
|
||||
/// Приветсти к UTC из времени куста
|
||||
/// </summary>
|
||||
/// <param name="date"></param>
|
||||
/// <param name="remoteTimezoneOffsetHours"></param>
|
||||
/// <returns></returns>
|
||||
public static DateTimeOffset ToUtcDateTimeOffset(this DateTime date, double remoteTimezoneOffsetHours)
|
||||
{
|
||||
if (date == default)
|
||||
@ -18,6 +24,12 @@ namespace AsbCloudInfrastructure
|
||||
return new DateTimeOffset(dateUtc);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Привести ко времени куста из utc
|
||||
/// </summary>
|
||||
/// <param name="date"></param>
|
||||
/// <param name="remoteTimezoneOffsetHours"></param>
|
||||
/// <returns></returns>
|
||||
public static DateTime ToRemoteDateTime(this DateTimeOffset date, double remoteTimezoneOffsetHours)
|
||||
{
|
||||
if (date == default)
|
||||
|
@ -4,7 +4,7 @@ using AsbCloudApp.Repositories;
|
||||
using AsbCloudApp.Services;
|
||||
using AsbCloudDb;
|
||||
using AsbCloudDb.Model;
|
||||
using DocumentFormat.OpenXml.Spreadsheet;
|
||||
using AsbCloudInfrastructure.Services.SAUB;
|
||||
using Mapster;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using System.Collections.Generic;
|
||||
@ -34,29 +34,34 @@ namespace AsbCloudInfrastructure.Repository
|
||||
public async Task<int> AddOrUpdateAsync(string uid, TelemetryWirelineRunOutDto dto, CancellationToken token)
|
||||
{
|
||||
var idTelemetry = telemetryService.GetOrCreateTelemetryIdByUid(uid);
|
||||
var entity = Convert(idTelemetry, dto);
|
||||
var timezoneOffset = telemetryService.GetTimezone(idTelemetry).Hours;
|
||||
var entity = Convert(idTelemetry, dto, timezoneOffset);
|
||||
|
||||
var updatingItem = context.TelemetryWirelineRunOut
|
||||
.Where(x => x.IdTelemetry == idTelemetry)
|
||||
.AsNoTracking()
|
||||
.FirstOrDefault();
|
||||
|
||||
if (updatingItem is null)
|
||||
context.TelemetryWirelineRunOut.Add(entity);
|
||||
else
|
||||
context.TelemetryWirelineRunOut.Upsert(entity);
|
||||
context.TelemetryWirelineRunOut.Update(entity);
|
||||
|
||||
return await context.SaveChangesAsync(token);
|
||||
}
|
||||
|
||||
/// <inheritdoc/>
|
||||
public async Task<TelemetryWirelineRunOutDto?> GetValueOrDefaultAsync(int idWell, CancellationToken token)
|
||||
public async Task<TelemetryWirelineRunOutDto?> GetOrDefaultAsync(int idWell, CancellationToken token)
|
||||
{
|
||||
var well = await wellService.GetOrDefaultAsync(idWell, token).ConfigureAwait(false);
|
||||
if (well is null)
|
||||
return null;
|
||||
|
||||
var idTelemetry = telemetryService.GetOrDefaultIdTelemetryByIdWell(idWell);
|
||||
return await GetOrDefaultAsync(well, token);
|
||||
}
|
||||
|
||||
private async Task<TelemetryWirelineRunOutDto?> GetOrDefaultAsync(WellDto well, CancellationToken token)
|
||||
{
|
||||
var idTelemetry = telemetryService.GetOrDefaultIdTelemetryByIdWell(well.Id);
|
||||
if (idTelemetry is null)
|
||||
return null;
|
||||
|
||||
@ -69,26 +74,20 @@ namespace AsbCloudInfrastructure.Repository
|
||||
if (entity is null)
|
||||
return null;
|
||||
|
||||
var timezone = telemetryService.GetTimezone((int)idTelemetry);
|
||||
return Convert(entity, well, timezone.Hours);
|
||||
var timezoneHours = well.Timezone.Hours;
|
||||
return Convert(entity, well, timezoneHours);
|
||||
}
|
||||
|
||||
/// <inheritdoc/>
|
||||
public async Task<IEnumerable<TelemetryWirelineRunOutDto>> GetAllAsync(int idCompany, CancellationToken token)
|
||||
{
|
||||
var result = new List<TelemetryWirelineRunOutDto>();
|
||||
var wells = await wellService.GetAllAsync(token)
|
||||
var wells = await wellService.GetWellsByCompanyAsync(idCompany, token)
|
||||
.ConfigureAwait(false);
|
||||
|
||||
var result = new List<TelemetryWirelineRunOutDto>(wells.Count());
|
||||
foreach (var well in wells)
|
||||
{
|
||||
bool isCompanyOwnsWell = await wellService.IsCompanyInvolvedInWellAsync(idCompany, well.Id, token)
|
||||
.ConfigureAwait(false);
|
||||
|
||||
if (!isCompanyOwnsWell)
|
||||
continue;
|
||||
|
||||
var dto = await GetValueOrDefaultAsync(well.Id, token);
|
||||
var dto = await GetOrDefaultAsync(well, token);
|
||||
if (dto is not null)
|
||||
result.Add(dto);
|
||||
}
|
||||
@ -96,17 +95,18 @@ namespace AsbCloudInfrastructure.Repository
|
||||
return result;
|
||||
}
|
||||
|
||||
private static TelemetryWirelineRunOut Convert(int idTelemetry, TelemetryWirelineRunOutDto dto)
|
||||
private static TelemetryWirelineRunOut Convert(int idTelemetry, TelemetryWirelineRunOutDto dto, double timezoneOffset)
|
||||
{
|
||||
var entity = dto.Adapt<TelemetryWirelineRunOut>();
|
||||
entity.IdTelemetry = idTelemetry;
|
||||
entity.DateTime = entity.DateTime.ToUniversalTime();
|
||||
entity.DateTime = dto.DateTime.ToUtcDateTimeOffset(timezoneOffset);
|
||||
return entity;
|
||||
}
|
||||
|
||||
private static TelemetryWirelineRunOutDto Convert(TelemetryWirelineRunOut entity, WellDto well, double timezoneOffset)
|
||||
{
|
||||
var dto = entity.Adapt<TelemetryWirelineRunOutDto>();
|
||||
dto.DateTime = entity.DateTime.ToUtcDateTimeOffset(timezoneOffset);
|
||||
dto.DateTime = entity.DateTime.ToRemoteDateTime(timezoneOffset);
|
||||
dto.WellInfo = well;
|
||||
return dto;
|
||||
}
|
||||
|
@ -11,6 +11,7 @@ using AsbCloudApp.Repositories;
|
||||
|
||||
namespace AsbCloudWebApi.Controllers.SAUB
|
||||
{
|
||||
#nullable enable
|
||||
/// <summary>
|
||||
/// Наработка талевого каната
|
||||
/// </summary>
|
||||
@ -86,7 +87,7 @@ namespace AsbCloudWebApi.Controllers.SAUB
|
||||
if (!isCompanyOwnsWell)
|
||||
return Forbid();
|
||||
|
||||
var dto = await repository.GetValueOrDefaultAsync(idWell, token);
|
||||
var dto = await repository.GetOrDefaultAsync(idWell, token);
|
||||
|
||||
if (dto is null)
|
||||
return NoContent();
|
||||
@ -103,6 +104,7 @@ namespace AsbCloudWebApi.Controllers.SAUB
|
||||
var dtos = await repository.GetAllAsync((int)idCompany, token);
|
||||
return Ok(dtos);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
#nullable disable
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user