forked from ddrilling/AsbCloudServer
#7987467 fix
This commit is contained in:
parent
9c9d01d24a
commit
102288f9e5
@ -1,7 +1,4 @@
|
|||||||
using Microsoft.EntityFrameworkCore.Metadata.Internal;
|
using System;
|
||||||
using System;
|
|
||||||
using System.ComponentModel.DataAnnotations.Schema;
|
|
||||||
using System.Linq;
|
|
||||||
|
|
||||||
namespace AsbCloudApp.Data
|
namespace AsbCloudApp.Data
|
||||||
{
|
{
|
||||||
|
@ -67,11 +67,11 @@ namespace AsbCloudDb.Model
|
|||||||
|
|
||||||
[JsonIgnore]
|
[JsonIgnore]
|
||||||
[ForeignKey(nameof(IdWell))]
|
[ForeignKey(nameof(IdWell))]
|
||||||
public virtual Well? Well { get; set; } = null!;
|
public virtual Well Well { get; set; } = null!;
|
||||||
|
|
||||||
[JsonIgnore]
|
[JsonIgnore]
|
||||||
[ForeignKey(nameof(IdWellSectionType))]
|
[ForeignKey(nameof(IdWellSectionType))]
|
||||||
public virtual WellSectionType? WellSectionType { get; set; } = null!;
|
public virtual WellSectionType WellSectionType { get; set; } = null!;
|
||||||
}
|
}
|
||||||
#nullable disable
|
#nullable disable
|
||||||
}
|
}
|
||||||
|
@ -26,29 +26,20 @@ namespace AsbCloudInfrastructure.Repository
|
|||||||
}
|
}
|
||||||
|
|
||||||
public async Task<IEnumerable<ProcessMapDto>> GetAllAsync(int idWell,
|
public async Task<IEnumerable<ProcessMapDto>> GetAllAsync(int idWell,
|
||||||
DateTime? updateFrom, CancellationToken token = default)
|
DateTime? updateFrom, CancellationToken token)
|
||||||
{
|
{
|
||||||
var timezone = wellService.GetTimezone(idWell);
|
var entities = await BuildQuery(idWell, updateFrom)
|
||||||
var updateFromUtc = updateFrom?.ToUtcDateTimeOffset(timezone.Hours);
|
|
||||||
var entities = await GetQuery()
|
|
||||||
.Where(e => e.IdWell == idWell)
|
|
||||||
.Where(e => e.LastUpdate >= updateFromUtc)
|
|
||||||
.OrderBy(e => e.DepthStart)
|
.OrderBy(e => e.DepthStart)
|
||||||
.ThenBy(e => e.Id)
|
.ThenBy(e => e.Id)
|
||||||
.ToListAsync(token)
|
.ToListAsync(token)
|
||||||
.ConfigureAwait(false);
|
.ConfigureAwait(false);
|
||||||
|
|
||||||
var dtos = entities.Select(entity =>
|
var dtos = entities.Select(Convert);
|
||||||
{
|
|
||||||
var dto = entity.Adapt<ProcessMapDto>();
|
|
||||||
dto.LastUpdate = entity.LastUpdate.ToRemoteDateTime(timezone.Hours);
|
|
||||||
return dto;
|
|
||||||
});
|
|
||||||
return dtos;
|
return dtos;
|
||||||
}
|
}
|
||||||
|
|
||||||
public override async Task<int> InsertAsync(ProcessMapDto dto,
|
public override async Task<int> InsertAsync(ProcessMapDto dto,
|
||||||
CancellationToken token = default)
|
CancellationToken token)
|
||||||
{
|
{
|
||||||
dto.LastUpdate = DateTime.UtcNow;
|
dto.LastUpdate = DateTime.UtcNow;
|
||||||
var result = await base.InsertAsync(dto, token);
|
var result = await base.InsertAsync(dto, token);
|
||||||
@ -56,13 +47,27 @@ namespace AsbCloudInfrastructure.Repository
|
|||||||
}
|
}
|
||||||
|
|
||||||
public override async Task<int> UpdateAsync(ProcessMapDto dto,
|
public override async Task<int> UpdateAsync(ProcessMapDto dto,
|
||||||
CancellationToken token = default)
|
CancellationToken token)
|
||||||
{
|
{
|
||||||
dto.LastUpdate = DateTime.UtcNow;
|
dto.LastUpdate = DateTime.UtcNow;
|
||||||
var result = await base.UpdateAsync(dto, token);
|
var result = await base.UpdateAsync(dto, token);
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
private IQueryable<ProcessMap> BuildQuery(int idWell, DateTime? updateFrom)
|
||||||
|
{
|
||||||
|
var query = GetQuery().Where(e => e.IdWell == idWell);
|
||||||
|
|
||||||
|
if (updateFrom is not null)
|
||||||
|
{
|
||||||
|
var timezone = wellService.GetTimezone(idWell);
|
||||||
|
var updateFromUtc = updateFrom?.ToUtcDateTimeOffset(timezone.Hours);
|
||||||
|
query.Where(e => e.LastUpdate >= updateFromUtc);
|
||||||
|
}
|
||||||
|
|
||||||
|
return query;
|
||||||
|
}
|
||||||
protected override ProcessMapDto Convert(ProcessMap entity)
|
protected override ProcessMapDto Convert(ProcessMap entity)
|
||||||
{
|
{
|
||||||
var dto = entity.Adapt<ProcessMapDto>();
|
var dto = entity.Adapt<ProcessMapDto>();
|
||||||
|
@ -9,6 +9,7 @@ using System.Threading.Tasks;
|
|||||||
|
|
||||||
namespace AsbCloudWebApi.Controllers
|
namespace AsbCloudWebApi.Controllers
|
||||||
{
|
{
|
||||||
|
#nullable enable
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// РТК
|
/// РТК
|
||||||
/// </summary>
|
/// </summary>
|
||||||
@ -37,7 +38,7 @@ namespace AsbCloudWebApi.Controllers
|
|||||||
[Route("/api/telemetry/{uid}/drillFlowChart")]
|
[Route("/api/telemetry/{uid}/drillFlowChart")]
|
||||||
[AllowAnonymous]
|
[AllowAnonymous]
|
||||||
[ProducesResponseType(typeof(IEnumerable<ProcessMapDto>), (int)System.Net.HttpStatusCode.OK)]
|
[ProducesResponseType(typeof(IEnumerable<ProcessMapDto>), (int)System.Net.HttpStatusCode.OK)]
|
||||||
public async Task<IActionResult> GetByTelemetryAsync(string uid, DateTime updateFrom = default, CancellationToken token = default)
|
public async Task<IActionResult> GetByTelemetryAsync(string uid, DateTime updateFrom, CancellationToken token)
|
||||||
{
|
{
|
||||||
var idWell = telemetryService.GetIdWellByTelemetryUid(uid);
|
var idWell = telemetryService.GetIdWellByTelemetryUid(uid);
|
||||||
if (idWell is null)
|
if (idWell is null)
|
||||||
@ -88,4 +89,5 @@ namespace AsbCloudWebApi.Controllers
|
|||||||
return await base.InsertAsync(value, token);
|
return await base.InsertAsync(value, token);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
#nullable disable
|
||||||
}
|
}
|
Loading…
Reference in New Issue
Block a user