2022-12-05 12:39:25 +05:00
|
|
|
using AsbCloudApp.Data;
|
2022-12-27 14:30:52 +05:00
|
|
|
using AsbCloudApp.Data.ProcessMap;
|
2023-01-26 15:37:46 +05:00
|
|
|
using AsbCloudApp.Requests;
|
2022-12-05 12:39:25 +05:00
|
|
|
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
|
|
|
|
{
|
2022-12-07 12:20:24 +05:00
|
|
|
#nullable enable
|
2022-12-07 15:04:36 +05:00
|
|
|
public class ProcessMapRepository : CrudWellRelatedRepositoryBase<ProcessMapDto, ProcessMap>,
|
2022-12-07 08:47:41 +05:00
|
|
|
IProcessMapRepository
|
2022-12-05 12:39:25 +05:00
|
|
|
{
|
|
|
|
private readonly IWellService wellService;
|
|
|
|
|
|
|
|
public ProcessMapRepository(IAsbCloudDbContext context, IWellService wellService)
|
2022-12-07 08:47:41 +05:00
|
|
|
: base(context, dbSet =>
|
|
|
|
dbSet.Include(x => x.Well)
|
|
|
|
.Include(x => x.WellSectionType)
|
|
|
|
)
|
2022-12-05 12:39:25 +05:00
|
|
|
{
|
|
|
|
this.wellService = wellService;
|
|
|
|
}
|
|
|
|
|
|
|
|
public async Task<IEnumerable<ProcessMapDto>> GetAllAsync(int idWell,
|
2022-12-07 10:52:35 +05:00
|
|
|
DateTime? updateFrom, CancellationToken token)
|
2022-12-05 12:39:25 +05:00
|
|
|
{
|
2022-12-07 10:52:35 +05:00
|
|
|
var entities = await BuildQuery(idWell, updateFrom)
|
2022-12-05 12:39:25 +05:00
|
|
|
.OrderBy(e => e.DepthStart)
|
|
|
|
.ThenBy(e => e.Id)
|
|
|
|
.ToListAsync(token)
|
|
|
|
.ConfigureAwait(false);
|
|
|
|
|
2022-12-07 10:52:35 +05:00
|
|
|
var dtos = entities.Select(Convert);
|
2022-12-05 12:39:25 +05:00
|
|
|
return dtos;
|
|
|
|
}
|
|
|
|
|
2023-01-26 15:37:46 +05:00
|
|
|
public async Task<IEnumerable<ProcessMapDto>?> GetByRequesProcessMaplAsync(WellCompositeRequest request, CancellationToken token)
|
|
|
|
{
|
2023-01-30 10:52:12 +05:00
|
|
|
var query = GetQuery().Where(e => request.IdWells.Contains(e.IdWell));
|
|
|
|
if (request.IdWellSectionTypes is not null)
|
2023-01-26 15:37:46 +05:00
|
|
|
{
|
2023-01-30 10:52:12 +05:00
|
|
|
query.Where(e => request.IdWellSectionTypes.Contains(e.IdWellSectionType));
|
2023-01-26 15:37:46 +05:00
|
|
|
}
|
|
|
|
|
|
|
|
var entities = await query
|
|
|
|
.ToListAsync(token);
|
|
|
|
var dtos = entities.Select(Convert).ToList();
|
|
|
|
return dtos;
|
|
|
|
}
|
|
|
|
|
2022-12-05 12:39:25 +05:00
|
|
|
public override async Task<int> InsertAsync(ProcessMapDto dto,
|
2022-12-07 10:52:35 +05:00
|
|
|
CancellationToken token)
|
2022-12-05 12:39:25 +05:00
|
|
|
{
|
|
|
|
dto.LastUpdate = DateTime.UtcNow;
|
|
|
|
var result = await base.InsertAsync(dto, token);
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
|
|
|
public override async Task<int> UpdateAsync(ProcessMapDto dto,
|
2022-12-07 10:52:35 +05:00
|
|
|
CancellationToken token)
|
2022-12-05 12:39:25 +05:00
|
|
|
{
|
|
|
|
dto.LastUpdate = DateTime.UtcNow;
|
|
|
|
var result = await base.UpdateAsync(dto, token);
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
2022-12-07 10:52:35 +05:00
|
|
|
|
|
|
|
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;
|
|
|
|
}
|
2022-12-05 12:39:25 +05:00
|
|
|
protected override ProcessMapDto Convert(ProcessMap entity)
|
|
|
|
{
|
2022-12-07 08:47:41 +05:00
|
|
|
var dto = entity.Adapt<ProcessMapDto>();
|
|
|
|
dto.LastUpdate = entity.LastUpdate.ToRemoteDateTime(entity.Well.Timezone.Hours);
|
|
|
|
dto.AxialLoad = new PlanFactDto
|
|
|
|
{
|
|
|
|
Fact = entity.AxialLoadFact,
|
|
|
|
Plan = entity.AxialLoadPlan
|
|
|
|
};
|
|
|
|
dto.Flow = new PlanFactDto
|
|
|
|
{
|
|
|
|
Fact = entity.FlowFact,
|
|
|
|
Plan = entity.FlowPlan
|
|
|
|
};
|
|
|
|
dto.Pressure = new PlanFactDto
|
|
|
|
{
|
2022-12-14 09:10:01 +05:00
|
|
|
Fact = entity.PressureFact,
|
|
|
|
Plan = entity.PressurePlan
|
2022-12-07 08:47:41 +05:00
|
|
|
};
|
|
|
|
dto.TopDriveSpeed = new PlanFactDto
|
|
|
|
{
|
|
|
|
Fact = entity.TopDriveSpeedFact,
|
|
|
|
Plan = entity.TopDriveSpeedPlan
|
|
|
|
};
|
|
|
|
dto.TopDriveTorque = new PlanFactDto
|
|
|
|
{
|
|
|
|
Fact = entity.TopDriveTorqueFact,
|
|
|
|
Plan = entity.TopDriveTorquePlan
|
2022-12-05 12:39:25 +05:00
|
|
|
};
|
2022-12-07 08:47:41 +05:00
|
|
|
return dto;
|
2022-12-05 12:39:25 +05:00
|
|
|
}
|
2022-12-14 09:10:01 +05:00
|
|
|
|
|
|
|
protected override ProcessMap Convert(ProcessMapDto dto)
|
|
|
|
{
|
|
|
|
var entity = dto.Adapt<ProcessMap>();
|
|
|
|
entity.AxialLoadPlan = dto.AxialLoad.Plan;
|
|
|
|
entity.AxialLoadFact = dto.AxialLoad.Fact;
|
|
|
|
|
|
|
|
entity.FlowPlan = dto.Flow.Plan;
|
|
|
|
entity.FlowFact = dto.Flow.Fact;
|
|
|
|
|
|
|
|
entity.PressurePlan = dto.Pressure.Plan;
|
|
|
|
entity.PressureFact = dto.Pressure.Fact;
|
|
|
|
|
|
|
|
entity.TopDriveSpeedPlan = dto.TopDriveSpeed.Plan;
|
|
|
|
entity.TopDriveSpeedFact = dto.TopDriveSpeed.Fact;
|
|
|
|
|
|
|
|
entity.TopDriveTorquePlan = dto.TopDriveTorque.Plan;
|
|
|
|
entity.TopDriveTorqueFact = dto.TopDriveTorque.Fact;
|
|
|
|
|
|
|
|
return entity;
|
|
|
|
}
|
2022-12-05 12:39:25 +05:00
|
|
|
}
|
2022-12-07 12:20:24 +05:00
|
|
|
#nullable disable
|
2022-12-05 12:39:25 +05:00
|
|
|
}
|