DD.WellWorkover.Cloud/AsbCloudInfrastructure/Repository/ProcessMapRepository.cs

96 lines
3.4 KiB
C#

using AsbCloudApp.Data;
using AsbCloudApp.Services;
using AsbCloudDb.Model;
using Mapster;
using Microsoft.EntityFrameworkCore;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading;
using System.Threading.Tasks;
namespace AsbCloudInfrastructure.Repository
{
public class ProcessMapRepository : CrudWellRelatedServiceBase<ProcessMapDto, ProcessMap>,
IDrillFlowChartRepository
{
private readonly IWellService wellService;
public ProcessMapRepository(IAsbCloudDbContext context, IWellService wellService)
: base(context)
{
this.wellService = wellService;
}
public async Task<IEnumerable<ProcessMapDto>> GetAllAsync(int idWell,
DateTime updateFrom, CancellationToken token = default)
{
var timezone = wellService.GetTimezone(idWell);
var updateFromUtc = updateFrom.ToUtcDateTimeOffset(timezone.Hours);
var entities = await GetQuery()
.Where(e => e.IdWell == idWell)
.Where(e => e.LastUpdate == updateFromUtc)
.OrderBy(e => e.DepthStart)
.ThenBy(e => e.Id)
.ToListAsync(token)
.ConfigureAwait(false);
var dtos = entities.Select(entity =>
{
var dto = entity.Adapt<ProcessMapDto>();
dto.LastUpdate = entity.LastUpdate.ToRemoteDateTime(timezone.Hours);
return dto;
});
return dtos;
}
public override async Task<int> InsertAsync(ProcessMapDto dto,
CancellationToken token = default)
{
dto.LastUpdate = DateTime.UtcNow;
var result = await base.InsertAsync(dto, token);
return result;
}
public override async Task<int> UpdateAsync(ProcessMapDto dto,
CancellationToken token = default)
{
dto.LastUpdate = DateTime.UtcNow;
var result = await base.UpdateAsync(dto, token);
return result;
}
protected override ProcessMapDto Convert(ProcessMap entity)
{
return new ProcessMapDto {
Id = entity.Id,
IdWell = entity.IdWell,
LastUpdate = entity.LastUpdate,
Section = entity.Section,
DepthEnd = entity.DepthEnd,
DepthStart = entity.DepthStart,
AxialLoad = new PlanFactDto {
Fact = entity.AxialLoadFact,
Plan = entity.AxialLoadPlan
},
Flow = new PlanFactDto {
Fact = entity.FlowFact,
Plan = entity.FlowPlan
},
Pressure = new PlanFactDto {
Fact = entity.FlowFact,
Plan = entity.FlowPlan
},
RotorSpeed = new PlanFactDto {
Fact = entity.RotorSpeedFact,
Plan = entity.RotorSpeedPlan
},
RotorTorque = new PlanFactDto {
Fact= entity.RotorTorqueFact,
Plan = entity.RotorTorquePlan
},
MechanicalSpeedPlan = entity.MechanicalSpeedPlan
};
}
}
}