This commit is contained in:
ai.astrakhantsev 2023-01-26 15:37:46 +05:00
parent ccbc499754
commit ecdade0913
8 changed files with 127 additions and 58 deletions

View File

@ -1,4 +1,5 @@
using AsbCloudApp.Data; using AsbCloudApp.Data;
using AsbCloudApp.Data.ProcessMap;
using System.Collections.Generic; using System.Collections.Generic;
using System.Threading; using System.Threading;
using System.Threading.Tasks; using System.Threading.Tasks;
@ -27,6 +28,14 @@ namespace AsbCloudApp.Repositories
/// <param name="token"></param> /// <param name="token"></param>
/// <returns></returns> /// <returns></returns>
Task<int> SaveAsync(int idWell, IEnumerable<WellCompositeDto> wellComposites, CancellationToken token); Task<int> SaveAsync(int idWell, IEnumerable<WellCompositeDto> wellComposites, CancellationToken token);
/// <summary>
/// Получение РТК по композитной скважине
/// </summary>
/// <param name="idWell"></param>
/// <param name="token"></param>
/// <returns></returns>
Task<IEnumerable<ProcessMapDto>> GetCompositeProcessMap(int idWell, CancellationToken token);
} }
#nullable disable #nullable disable
} }

View File

@ -0,0 +1,20 @@
namespace AsbCloudApp.Requests
{
#nullable enable
/// <summary>
/// Параметры для запроса получения РТК
/// </summary>
public class WellCompositeRequest
{
/// <summary>
/// Идентификатор скважины
/// </summary>
public int IdWell { get; set; }
/// <summary>
/// Тип секции
/// </summary>
public int? IdWellSectionType { get; set; }
}
#nullable disable
}

View File

@ -1,4 +1,5 @@
using AsbCloudApp.Data.ProcessMap; using AsbCloudApp.Data.ProcessMap;
using AsbCloudApp.Requests;
using System; using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.Threading; using System.Threading;
@ -6,6 +7,7 @@ using System.Threading.Tasks;
namespace AsbCloudApp.Services namespace AsbCloudApp.Services
{ {
#nullable enable
/// <summary> /// <summary>
/// ÐÒÊ /// ÐÒÊ
/// </summary> /// </summary>
@ -20,5 +22,14 @@ namespace AsbCloudApp.Services
/// <returns></returns> /// <returns></returns>
Task<IEnumerable<ProcessMapDto>> GetAllAsync(int idWell, Task<IEnumerable<ProcessMapDto>> GetAllAsync(int idWell,
DateTime? updateFrom, CancellationToken token = default); DateTime? updateFrom, CancellationToken token = default);
/// <summary>
/// Ïîëó÷èòü ïàðàìåòðû áóðåíèÿ
/// </summary>
/// <param name="request"></param>
/// <param name="token"></param>
/// <returns></returns>
Task<IEnumerable<ProcessMapDto>?> GetByRequesProcessMaplAsync(WellCompositeRequest request, CancellationToken token);
} }
#nullable disable
} }

View File

@ -20,14 +20,6 @@ namespace AsbCloudApp.Services
/// <param name="token"></param> /// <param name="token"></param>
/// <returns></returns> /// <returns></returns>
Task<IEnumerable<ProcessMapReportDto>> GetProcessMapAsync(int idWell, CancellationToken token); Task<IEnumerable<ProcessMapReportDto>> GetProcessMapAsync(int idWell, CancellationToken token);
/// <summary>
/// Получение РТК по композитной скважине
/// </summary>
/// <param name="dtos"></param>
/// <param name="token"></param>
/// <returns></returns>
Task<IEnumerable<ProcessMapDto>> GetCompositeData(int idWell, CancellationToken token);
} }
#nullable disable #nullable disable
} }

View File

@ -1,5 +1,6 @@
using AsbCloudApp.Data; using AsbCloudApp.Data;
using AsbCloudApp.Data.ProcessMap; using AsbCloudApp.Data.ProcessMap;
using AsbCloudApp.Requests;
using AsbCloudApp.Services; using AsbCloudApp.Services;
using AsbCloudDb.Model; using AsbCloudDb.Model;
using Mapster; using Mapster;
@ -40,6 +41,20 @@ namespace AsbCloudInfrastructure.Repository
return dtos; return dtos;
} }
public async Task<IEnumerable<ProcessMapDto>?> GetByRequesProcessMaplAsync(WellCompositeRequest request, CancellationToken token)
{
var query = GetQuery().Where(e => e.IdWell == request.IdWell);
if (request.IdWellSectionType is not null)
{
query.Where(e => e.IdWellSectionType == request.IdWellSectionType);
}
var entities = await query
.ToListAsync(token);
var dtos = entities.Select(Convert).ToList();
return dtos;
}
public override async Task<int> InsertAsync(ProcessMapDto dto, public override async Task<int> InsertAsync(ProcessMapDto dto,
CancellationToken token) CancellationToken token)
{ {

View File

@ -1,8 +1,12 @@
using AsbCloudApp.Data; using AsbCloudApp.Data;
using AsbCloudApp.Data.ProcessMap;
using AsbCloudApp.Repositories; using AsbCloudApp.Repositories;
using AsbCloudApp.Requests;
using AsbCloudApp.Services;
using AsbCloudDb.Model; using AsbCloudDb.Model;
using Mapster; using Mapster;
using Microsoft.EntityFrameworkCore; using Microsoft.EntityFrameworkCore;
using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.Linq; using System.Linq;
using System.Threading; using System.Threading;
@ -14,10 +18,12 @@ namespace AsbCloudInfrastructure.Repository
public class WellCompositeRepository : IWellCompositeRepository public class WellCompositeRepository : IWellCompositeRepository
{ {
private readonly IAsbCloudDbContext db; private readonly IAsbCloudDbContext db;
private readonly IProcessMapRepository processMapRepository;
public WellCompositeRepository(IAsbCloudDbContext db) public WellCompositeRepository(IAsbCloudDbContext db, IProcessMapRepository processMapRepository)
{ {
this.db = db; this.db = db;
this.processMapRepository = processMapRepository;
} }
/// <inheritdoc/> /// <inheritdoc/>
@ -44,6 +50,57 @@ namespace AsbCloudInfrastructure.Repository
return db.SaveChangesAsync(token); return db.SaveChangesAsync(token);
} }
/// <inheritdoc/>
public async Task<IEnumerable<ProcessMapDto>> GetCompositeProcessMap(int idWell, CancellationToken token)
{
var result = new List<ProcessMapDto>();
var dtos = await GetAsync(idWell, token);
foreach (var dto in dtos)
{
var processMaps = (await processMapRepository.GetByRequesProcessMaplAsync(new WellCompositeRequest
{
IdWell = dto.IdWellSrc,
IdWellSectionType = dto.IdWellSectionType
}
, token))?
.Where(x => x.IdWellSectionType == dto.IdWellSectionType)
.Select(x => new ProcessMapDto
{
IdWell = dto.IdWell,
IdWellSectionType = dto.IdWellSectionType,
RopPlan = x.RopPlan,
DepthStart = x.DepthStart,
DepthEnd = x.DepthEnd,
AxialLoad = new PlanFactDto
{
Plan = x.AxialLoad.Fact ?? 0
},
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
});
if (processMaps is not null)
result.AddRange(processMaps);
}
return result;
}
private static WellComposite Convert(int idWell, WellCompositeDto dto) private static WellComposite Convert(int idWell, WellCompositeDto dto)
{ {
var entity = dto.Adapt<WellComposite>(); var entity = dto.Adapt<WellComposite>();

View File

@ -46,6 +46,7 @@ namespace AsbCloudInfrastructure.Services.ProcessMap
this.wellCompositeRepository = wellCompositeRepository; this.wellCompositeRepository = wellCompositeRepository;
} }
/// <inheritdoc/>
public async Task<IEnumerable<ProcessMapReportDto>> GetProcessMapAsync(int idWell, CancellationToken token) public async Task<IEnumerable<ProcessMapReportDto>> GetProcessMapAsync(int idWell, CancellationToken token)
{ {
var well = wellService.GetOrDefault(idWell) var well = wellService.GetOrDefault(idWell)
@ -71,48 +72,6 @@ namespace AsbCloudInfrastructure.Services.ProcessMap
return result; return result;
} }
public async Task<IEnumerable<ProcessMapDto>> GetCompositeData(int idWell, CancellationToken token)
{
var result = new List<ProcessMapDto>();
var dtos = await wellCompositeRepository.GetAsync(idWell, token);
foreach (var dto in dtos)
{
var processMaps = (await processMapRepository.GetByIdWellAsync(dto.IdWellSrc, token))!.
Where(x => x.IdWellSectionType == dto.IdWellSectionType).
Select(x => new ProcessMapDto {
IdWell = dto.IdWell,
IdWellSectionType = dto.IdWellSectionType,
RopPlan = x.RopPlan,
DepthStart = x.DepthStart,
DepthEnd = x.DepthEnd,
AxialLoad = new PlanFactDto
{
Plan = x.AxialLoad.Fact ?? 0
},
Flow = new PlanFactDto
{
Plan = x.Flow.Fact ?? 0
},
Pressure = new PlanFactDto
{
Plan = x.Pressure.Fact ?? 0
},
TopDriveSpeed = new PlanFactDto
{
Plan = x.TopDriveSpeed.Fact ?? 0
},
TopDriveTorque = new PlanFactDto
{
Plan = x.TopDriveTorque.Fact ?? 0
},
LastUpdate = DateTime.UtcNow
});
result.AddRange(processMaps);
}
return result;
}
private Task<IEnumerable<SubsystemOperationTimeDto>?> GetOperationTimeAsync(int idWell, CancellationToken token) private Task<IEnumerable<SubsystemOperationTimeDto>?> GetOperationTimeAsync(int idWell, CancellationToken token)
{ {
var request = new SubsystemOperationTimeRequest var request = new SubsystemOperationTimeRequest

View File

@ -21,15 +21,12 @@ namespace AsbCloudWebApi.Controllers
{ {
private readonly IWellCompositeRepository wellCompositeRepository; private readonly IWellCompositeRepository wellCompositeRepository;
private readonly IWellService wellService; private readonly IWellService wellService;
private readonly IProcessMapService processMapService;
public WellCompositeController(IWellCompositeRepository wellCompositeRepository, public WellCompositeController(IWellCompositeRepository wellCompositeRepository,
IWellService wellService, IWellService wellService)
IProcessMapService processMapService)
{ {
this.wellCompositeRepository = wellCompositeRepository; this.wellCompositeRepository = wellCompositeRepository;
this.wellService = wellService; this.wellService = wellService;
this.processMapService = processMapService;
} }
/// <summary> /// <summary>
@ -68,12 +65,21 @@ namespace AsbCloudWebApi.Controllers
return Ok(result); return Ok(result);
} }
[HttpGet("getCompositeData")] /// <summary>
/// Получение РТК по композитной скважине
/// </summary>
/// <param name="idWell"></param>
/// <param name="token"></param>
/// <returns></returns>
[HttpGet("getCompositeProcessMap")]
[Permission] [Permission]
[ProducesResponseType(typeof(IEnumerable<ProcessMapDto>), (int)System.Net.HttpStatusCode.OK)] [ProducesResponseType(typeof(IEnumerable<ProcessMapDto>), (int)System.Net.HttpStatusCode.OK)]
public async Task<IActionResult> GetCompositeData(int idWell, CancellationToken token = default) public async Task<IActionResult> GetCompositeProcessMap(int idWell, CancellationToken token = default)
{ {
var result = await processMapService.GetCompositeData(idWell, token).ConfigureAwait(false); if (!await CanUserAccessToWellAsync(idWell, token).ConfigureAwait(false))
return Forbid();
var result = await wellCompositeRepository.GetCompositeProcessMap(idWell, token).ConfigureAwait(false);
return Ok(result); return Ok(result);
} }