2021-10-12 12:17:46 +05:00
|
|
|
|
using AsbCloudApp.Data;
|
2023-01-26 15:37:46 +05:00
|
|
|
|
using AsbCloudApp.Data.ProcessMap;
|
2022-10-19 13:56:34 +05:00
|
|
|
|
using AsbCloudApp.Repositories;
|
2023-01-26 15:37:46 +05:00
|
|
|
|
using AsbCloudApp.Requests;
|
|
|
|
|
using AsbCloudApp.Services;
|
2021-10-12 12:17:46 +05:00
|
|
|
|
using AsbCloudDb.Model;
|
|
|
|
|
using Mapster;
|
|
|
|
|
using Microsoft.EntityFrameworkCore;
|
2023-01-26 15:37:46 +05:00
|
|
|
|
using System;
|
2021-10-12 12:17:46 +05:00
|
|
|
|
using System.Collections.Generic;
|
|
|
|
|
using System.Linq;
|
|
|
|
|
using System.Threading;
|
|
|
|
|
using System.Threading.Tasks;
|
|
|
|
|
|
2022-10-19 13:56:34 +05:00
|
|
|
|
namespace AsbCloudInfrastructure.Repository
|
2021-10-12 12:17:46 +05:00
|
|
|
|
{
|
2022-10-19 13:56:34 +05:00
|
|
|
|
#nullable enable
|
|
|
|
|
public class WellCompositeRepository : IWellCompositeRepository
|
2021-10-12 12:17:46 +05:00
|
|
|
|
{
|
2022-10-19 13:56:34 +05:00
|
|
|
|
private readonly IAsbCloudDbContext db;
|
2023-01-26 15:37:46 +05:00
|
|
|
|
private readonly IProcessMapRepository processMapRepository;
|
2021-10-12 12:17:46 +05:00
|
|
|
|
|
2023-01-26 15:37:46 +05:00
|
|
|
|
public WellCompositeRepository(IAsbCloudDbContext db, IProcessMapRepository processMapRepository)
|
2021-10-12 12:17:46 +05:00
|
|
|
|
{
|
2022-10-19 13:56:34 +05:00
|
|
|
|
this.db = db;
|
2023-01-26 15:37:46 +05:00
|
|
|
|
this.processMapRepository = processMapRepository;
|
2021-10-12 12:17:46 +05:00
|
|
|
|
}
|
|
|
|
|
|
2022-10-19 15:00:18 +05:00
|
|
|
|
/// <inheritdoc/>
|
2021-10-12 12:17:46 +05:00
|
|
|
|
public async Task<IEnumerable<WellCompositeDto>> GetAsync(int idWell, CancellationToken token)
|
|
|
|
|
{
|
2022-10-19 13:56:34 +05:00
|
|
|
|
var entities = await db.WellComposites
|
2021-10-12 12:17:46 +05:00
|
|
|
|
.Where(c => c.IdWell == idWell)
|
|
|
|
|
.AsNoTracking()
|
|
|
|
|
.ToListAsync(token)
|
|
|
|
|
.ConfigureAwait(false);
|
2022-06-06 15:43:47 +05:00
|
|
|
|
return entities.Select(Convert);
|
2021-10-12 12:17:46 +05:00
|
|
|
|
}
|
|
|
|
|
|
2022-10-19 15:00:18 +05:00
|
|
|
|
/// <inheritdoc/>
|
2021-10-12 12:17:46 +05:00
|
|
|
|
public Task<int> SaveAsync(int idWell, IEnumerable<WellCompositeDto> wellComposites, CancellationToken token)
|
|
|
|
|
{
|
2022-10-19 13:56:34 +05:00
|
|
|
|
db.WellComposites.RemoveRange(db.WellComposites
|
2021-10-12 12:17:46 +05:00
|
|
|
|
.Where(c => c.IdWell == idWell));
|
2021-10-14 14:46:20 +05:00
|
|
|
|
|
2021-10-12 12:17:46 +05:00
|
|
|
|
var entities = wellComposites
|
2022-06-06 15:43:47 +05:00
|
|
|
|
.Select(w => Convert(idWell, w));
|
2021-10-14 14:46:20 +05:00
|
|
|
|
|
2022-10-19 13:56:34 +05:00
|
|
|
|
db.WellComposites.AddRange(entities);
|
|
|
|
|
return db.SaveChangesAsync(token);
|
2021-10-12 12:17:46 +05:00
|
|
|
|
}
|
2022-06-06 15:43:47 +05:00
|
|
|
|
|
2023-01-26 15:37:46 +05:00
|
|
|
|
/// <inheritdoc/>
|
2023-01-30 10:52:12 +05:00
|
|
|
|
public async Task<IEnumerable<ProcessMapDto>?> GetCompositeProcessMap(int idWell, CancellationToken token)
|
2023-01-26 15:37:46 +05:00
|
|
|
|
{
|
|
|
|
|
var dtos = await GetAsync(idWell, token);
|
2023-02-02 11:04:53 +05:00
|
|
|
|
var request = new List<ProcessMapRequest>(dtos.Count());
|
|
|
|
|
foreach(var dto in dtos)
|
2023-02-02 10:32:53 +05:00
|
|
|
|
{
|
2023-02-02 11:04:53 +05:00
|
|
|
|
request.Add(new ProcessMapRequest
|
|
|
|
|
{
|
|
|
|
|
IdWell = dto.IdWellSrc,
|
|
|
|
|
IdWellSectionTypes = dto.IdWellSectionType
|
|
|
|
|
});
|
2023-02-02 10:32:53 +05:00
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
var processMap = (await processMapRepository.GetByRequesProcessMaplAsync(request, token));
|
2023-01-26 15:37:46 +05:00
|
|
|
|
|
2023-01-30 10:52:12 +05:00
|
|
|
|
var result = processMap?.Select(x => new ProcessMapDto
|
|
|
|
|
{
|
|
|
|
|
IdWell = x.IdWell,
|
|
|
|
|
IdWellSectionType = x.IdWellSectionType,
|
|
|
|
|
RopPlan = x.RopPlan,
|
|
|
|
|
DepthStart = x.DepthStart,
|
|
|
|
|
DepthEnd = x.DepthEnd,
|
|
|
|
|
AxialLoad = new PlanFactDto
|
|
|
|
|
{
|
|
|
|
|
Plan = x.AxialLoad.Fact ?? x.AxialLoad.Plan,
|
|
|
|
|
},
|
|
|
|
|
Flow = new PlanFactDto
|
|
|
|
|
{
|
|
|
|
|
Plan = x.Flow.Fact ?? x.Flow.Plan
|
|
|
|
|
},
|
|
|
|
|
Pressure = new PlanFactDto
|
|
|
|
|
{
|
|
|
|
|
Plan = x.Pressure.Fact ?? x.Pressure.Plan
|
|
|
|
|
},
|
|
|
|
|
TopDriveSpeed = new PlanFactDto
|
|
|
|
|
{
|
|
|
|
|
Plan = x.TopDriveSpeed.Fact ?? x.TopDriveSpeed.Plan
|
|
|
|
|
},
|
|
|
|
|
TopDriveTorque = new PlanFactDto
|
|
|
|
|
{
|
|
|
|
|
Plan = x.TopDriveTorque.Fact ?? x.TopDriveTorque.Plan
|
|
|
|
|
},
|
|
|
|
|
LastUpdate = DateTime.UtcNow
|
|
|
|
|
});
|
|
|
|
|
|
2023-01-26 15:37:46 +05:00
|
|
|
|
return result;
|
|
|
|
|
}
|
|
|
|
|
|
2022-10-19 15:00:18 +05:00
|
|
|
|
private static WellComposite Convert(int idWell, WellCompositeDto dto)
|
2022-06-06 15:43:47 +05:00
|
|
|
|
{
|
|
|
|
|
var entity = dto.Adapt<WellComposite>();
|
|
|
|
|
entity.IdWell = idWell;
|
|
|
|
|
return entity;
|
|
|
|
|
}
|
2022-10-19 15:00:18 +05:00
|
|
|
|
private static WellCompositeDto Convert(WellComposite entity)
|
2022-06-06 15:43:47 +05:00
|
|
|
|
{
|
|
|
|
|
var dto = entity.Adapt<WellCompositeDto>();
|
|
|
|
|
return dto;
|
|
|
|
|
}
|
2021-10-12 12:17:46 +05:00
|
|
|
|
}
|
2022-10-19 13:56:34 +05:00
|
|
|
|
#nullable disable
|
2021-10-12 12:17:46 +05:00
|
|
|
|
}
|