forked from ddrilling/AsbCloudServer
Формирование отчёта по скважине
This commit is contained in:
parent
cd5cc378f7
commit
75a0e3fb4b
16
AsbCloudApp/Data/WellReport/DrillingInfoDto.cs
Normal file
16
AsbCloudApp/Data/WellReport/DrillingInfoDto.cs
Normal file
@ -0,0 +1,16 @@
|
|||||||
|
using System.Collections.Generic;
|
||||||
|
|
||||||
|
namespace AsbCloudApp.Data.WellReport;
|
||||||
|
|
||||||
|
public class DrillingInfoDto
|
||||||
|
{
|
||||||
|
public DatesRangeDto Dates { get; set; } = null!;
|
||||||
|
|
||||||
|
public PlanFactDto<double> Days { get; set; } = null!;
|
||||||
|
|
||||||
|
public PlanFactDto<double> WellBoreDepth { get; set; }
|
||||||
|
|
||||||
|
public PlanFactDto<double?> VerticalDepth { get; set; }
|
||||||
|
|
||||||
|
//TODO: Срок строит. без НПВ факт (DE8)
|
||||||
|
}
|
18
AsbCloudApp/Data/WellReport/WellReportDto.cs
Normal file
18
AsbCloudApp/Data/WellReport/WellReportDto.cs
Normal file
@ -0,0 +1,18 @@
|
|||||||
|
using System.Collections.Generic;
|
||||||
|
using AsbCloudApp.Data.User;
|
||||||
|
|
||||||
|
namespace AsbCloudApp.Data.WellReport;
|
||||||
|
|
||||||
|
public class WellReportDto
|
||||||
|
{
|
||||||
|
public WellDto Well { get; set; }
|
||||||
|
|
||||||
|
public DrillingInfoDto DrillingInfo { get; set; }
|
||||||
|
|
||||||
|
public IEnumerable<ContactDto> Constacts { get; set; }
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Режим работы
|
||||||
|
/// </summary>
|
||||||
|
public IEnumerable<PlanFactDto<OperatingModeItemDto>> OperatingMode { get; set; }
|
||||||
|
}
|
@ -62,11 +62,13 @@ public interface IWellOperationRepository
|
|||||||
Task<DatesRangeDto?> GetDatesRangeAsync(int idWell, int idType, CancellationToken cancellationToken);
|
Task<DatesRangeDto?> GetDatesRangeAsync(int idWell, int idType, CancellationToken cancellationToken);
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Возвращает первую и последнюю фактическую операцию
|
/// Возвращает первую и последнюю операцию
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="idWell"></param>
|
/// <param name="idWell"></param>
|
||||||
|
/// <param name="idType"></param>
|
||||||
|
/// <param name="token"></param>
|
||||||
/// <returns></returns>
|
/// <returns></returns>
|
||||||
(WellOperationBaseDto First, WellOperationBaseDto Last)? GetFirstAndLastFact(int idWell);
|
Task<(WellOperationBaseDto First, WellOperationBaseDto Last)?> GetFirstAndLastAsync(int idWell, int idType, CancellationToken token);
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Получить список операций по запросу
|
/// Получить список операций по запросу
|
||||||
|
10
AsbCloudApp/Services/IWellReportService.cs
Normal file
10
AsbCloudApp/Services/IWellReportService.cs
Normal file
@ -0,0 +1,10 @@
|
|||||||
|
using System.Threading;
|
||||||
|
using System.Threading.Tasks;
|
||||||
|
using AsbCloudApp.Data.WellReport;
|
||||||
|
|
||||||
|
namespace AsbCloudApp.Services;
|
||||||
|
|
||||||
|
public interface IWellReportService
|
||||||
|
{
|
||||||
|
Task<WellReportDto> GetAsync(int idWell, CancellationToken token);
|
||||||
|
}
|
@ -195,13 +195,13 @@ public class WellOperationRepository : CrudRepositoryBase<WellOperationBaseDto,
|
|||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
public (WellOperationBaseDto First, WellOperationBaseDto Last)? GetFirstAndLastFact(int idWell)
|
public async Task<(WellOperationBaseDto First, WellOperationBaseDto Last)?> GetFirstAndLastAsync(int idWell, int idType, CancellationToken token)
|
||||||
{
|
{
|
||||||
var cachedDictionary = memoryCache.GetOrCreate(cacheKeyWellOperations, (entry) =>
|
var cachedDictionary = await memoryCache.GetOrCreateAsync(cacheKeyWellOperations, async (entry) =>
|
||||||
{
|
{
|
||||||
entry.AbsoluteExpirationRelativeToNow = TimeSpan.FromMinutes(5);
|
entry.AbsoluteExpirationRelativeToNow = TimeSpan.FromMinutes(5);
|
||||||
var query = dbContext.Set<WellOperation>()
|
var query = dbContext.Set<WellOperation>()
|
||||||
.Where(o => o.IdType == WellOperation.IdOperationTypeFact)
|
.Where(o => o.IdType == idType)
|
||||||
.GroupBy(o => o.IdWell)
|
.GroupBy(o => o.IdWell)
|
||||||
.Select(group => new
|
.Select(group => new
|
||||||
{
|
{
|
||||||
@ -210,18 +210,16 @@ public class WellOperationRepository : CrudRepositoryBase<WellOperationBaseDto,
|
|||||||
LastFact = group.OrderBy(o => o.DateStart).Last(),
|
LastFact = group.OrderBy(o => o.DateStart).Last(),
|
||||||
});
|
});
|
||||||
|
|
||||||
var entities = query.ToArray();
|
var entities = await query.ToArrayAsync(token);
|
||||||
|
|
||||||
var dictionary = entities.ToDictionary(s => s.IdWell, s => (Convert(s.FirstFact), Convert(s.LastFact)));
|
var dictionary = entities.ToDictionary(s => s.IdWell, s => (Convert(s.FirstFact), Convert(s.LastFact)));
|
||||||
entry.Value = dictionary;
|
entry.Value = dictionary;
|
||||||
|
|
||||||
return dictionary;
|
return dictionary;
|
||||||
|
|
||||||
})!;
|
})!;
|
||||||
|
|
||||||
var firstAndLast = cachedDictionary.GetValueOrDefault(idWell);
|
var firstAndLast = cachedDictionary?.GetValueOrDefault(idWell);
|
||||||
return firstAndLast;
|
return firstAndLast;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public override async Task<int> DeleteAsync(int id, CancellationToken token)
|
public override async Task<int> DeleteAsync(int id, CancellationToken token)
|
||||||
|
116
AsbCloudInfrastructure/Services/WellReport/WellReportService.cs
Normal file
116
AsbCloudInfrastructure/Services/WellReport/WellReportService.cs
Normal file
@ -0,0 +1,116 @@
|
|||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Linq;
|
||||||
|
using System.Threading;
|
||||||
|
using System.Threading.Tasks;
|
||||||
|
using AsbCloudApp.Data;
|
||||||
|
using AsbCloudApp.Data.Trajectory;
|
||||||
|
using AsbCloudApp.Data.WellOperation;
|
||||||
|
using AsbCloudApp.Data.WellReport;
|
||||||
|
using AsbCloudApp.Exceptions;
|
||||||
|
using AsbCloudApp.Repositories;
|
||||||
|
using AsbCloudApp.Requests;
|
||||||
|
using AsbCloudApp.Services;
|
||||||
|
using AsbCloudDb.Model;
|
||||||
|
|
||||||
|
namespace AsbCloudInfrastructure.Services.WellReport;
|
||||||
|
|
||||||
|
public class WellReportService : IWellReportService
|
||||||
|
{
|
||||||
|
private readonly IWellService wellService;
|
||||||
|
private readonly IWellOperationService wellOperationService;
|
||||||
|
private readonly IWellOperationRepository wellOperationRepository;
|
||||||
|
private readonly ITrajectoryRepository<TrajectoryGeoPlanDto> trajectoryPlanRepository;
|
||||||
|
private readonly ITrajectoryRepository<TrajectoryGeoFactDto> trajectoryFactRepository;
|
||||||
|
private readonly IWellContactService wellContactService;
|
||||||
|
|
||||||
|
public WellReportService()
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
public async Task<WellReportDto> GetAsync(int idWell, CancellationToken token)
|
||||||
|
{
|
||||||
|
var wellOperationRequest = new WellOperationRequest(new[] { idWell })
|
||||||
|
{
|
||||||
|
OperationType = WellOperation.IdOperationTypeFact
|
||||||
|
};
|
||||||
|
|
||||||
|
var factOperations = (await wellOperationService.GetAsync(wellOperationRequest, token))
|
||||||
|
.OrderBy(x => x.DateStart);
|
||||||
|
|
||||||
|
if (!factOperations.Any())
|
||||||
|
throw new ArgumentInvalidException(nameof(idWell), "Данные в ГГД факт отсутствуют");
|
||||||
|
|
||||||
|
wellOperationRequest.OperationType = WellOperation.IdOperationTypePlan;
|
||||||
|
|
||||||
|
var planOperations = (await wellOperationService.GetAsync(wellOperationRequest, token))
|
||||||
|
.OrderBy(x => x.DateStart);
|
||||||
|
|
||||||
|
if (!planOperations.Any())
|
||||||
|
throw new ArgumentInvalidException(nameof(idWell), "Данные ГГД план отсутствуют");
|
||||||
|
|
||||||
|
var wellContactRequest = new WellContactRequest()
|
||||||
|
{
|
||||||
|
IdsWells = new[] { idWell },
|
||||||
|
};
|
||||||
|
|
||||||
|
var well = await wellService.GetOrDefaultAsync(idWell, token)
|
||||||
|
?? throw new ArgumentInvalidException(nameof(idWell), "Скважина не найдена");
|
||||||
|
|
||||||
|
var drillingInfo = await GetDrillingInfoAsync(idWell, planOperations, factOperations, token);
|
||||||
|
|
||||||
|
var contacts = await wellContactService.GetAllAsync(wellContactRequest, token);
|
||||||
|
|
||||||
|
return new WellReportDto
|
||||||
|
{
|
||||||
|
Well = well,
|
||||||
|
DrillingInfo = drillingInfo,
|
||||||
|
Constacts = contacts,
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
private async Task<IEnumerable<PlanFactDto<OperatingModeItemDto>>> GetOperationModeAsync(int idWell,
|
||||||
|
IEnumerable<WellOperationDto> factWellOperations, CancellationToken token)
|
||||||
|
{
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
private async Task<DrillingInfoDto> GetDrillingInfoAsync(int idWell,
|
||||||
|
IEnumerable<WellOperationDto> planOperations,
|
||||||
|
IEnumerable<WellOperationDto> factOperations,
|
||||||
|
CancellationToken token)
|
||||||
|
{
|
||||||
|
var firstFactOperation = factOperations.First();
|
||||||
|
var lastFactOperation = factOperations.Last();
|
||||||
|
|
||||||
|
var lastPlanOperation = planOperations.Last();
|
||||||
|
|
||||||
|
var planTrajectories = await trajectoryPlanRepository.GetAsync(idWell, token);
|
||||||
|
var factTrajectories = await trajectoryFactRepository.GetAsync(idWell, token);
|
||||||
|
|
||||||
|
var drillingInfo = new DrillingInfoDto
|
||||||
|
{
|
||||||
|
Dates = new DatesRangeDto
|
||||||
|
{
|
||||||
|
From = firstFactOperation.DateStart,
|
||||||
|
To = lastPlanOperation.DateStart.AddHours(lastPlanOperation.DurationHours),
|
||||||
|
},
|
||||||
|
Days = new PlanFactDto<double>
|
||||||
|
{
|
||||||
|
Plan = lastPlanOperation.Day,
|
||||||
|
Fact = lastFactOperation.Day
|
||||||
|
},
|
||||||
|
WellBoreDepth = new PlanFactDto<double>
|
||||||
|
{
|
||||||
|
Plan = planOperations.Max(x => x.DepthEnd),
|
||||||
|
Fact = factOperations.Max(x => x.DepthEnd)
|
||||||
|
},
|
||||||
|
VerticalDepth = new PlanFactDto<double?>
|
||||||
|
{
|
||||||
|
Plan = planTrajectories.Max(x => x.VerticalDepth),
|
||||||
|
Fact = factTrajectories.Max(x => x.VerticalDepth)
|
||||||
|
},
|
||||||
|
};
|
||||||
|
|
||||||
|
return drillingInfo;
|
||||||
|
}
|
||||||
|
}
|
@ -274,7 +274,7 @@ public class WellService : CrudCacheRepositoryBase<WellDto, Well>, IWellService
|
|||||||
dto.Timezone = GetTimezone(entity.Id);
|
dto.Timezone = GetTimezone(entity.Id);
|
||||||
|
|
||||||
dto.StartDate = wellOperationRepository
|
dto.StartDate = wellOperationRepository
|
||||||
.GetFirstAndLastFact(entity.Id)?.First?.DateStart;
|
.GetFirstAndLast(entity.Id)?.First?.DateStart;
|
||||||
dto.WellType = entity.WellType.Caption;
|
dto.WellType = entity.WellType.Caption;
|
||||||
dto.Cluster = entity.Cluster.Caption;
|
dto.Cluster = entity.Cluster.Caption;
|
||||||
dto.Deposit = entity.Cluster.Deposit.Caption;
|
dto.Deposit = entity.Cluster.Deposit.Caption;
|
||||||
|
@ -8,6 +8,7 @@ using System.Collections.Generic;
|
|||||||
using System.ComponentModel.DataAnnotations;
|
using System.ComponentModel.DataAnnotations;
|
||||||
using System.Threading;
|
using System.Threading;
|
||||||
using System.Threading.Tasks;
|
using System.Threading.Tasks;
|
||||||
|
using Microsoft.AspNetCore.Http;
|
||||||
|
|
||||||
namespace AsbCloudWebApi.Controllers;
|
namespace AsbCloudWebApi.Controllers;
|
||||||
|
|
||||||
@ -149,4 +150,17 @@ public class WellController : ControllerBase
|
|||||||
return Ok(result);
|
return Ok(result);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Получить отчёт по скважине
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="idWell"></param>
|
||||||
|
/// <param name="token"></param>
|
||||||
|
/// <returns></returns>
|
||||||
|
[HttpGet("{idWell}/report")]
|
||||||
|
[ProducesResponseType(typeof(PhysicalFileResult), StatusCodes.Status200OK)]
|
||||||
|
public Task<IActionResult> GetReportAsync(int idWell, CancellationToken token)
|
||||||
|
{
|
||||||
|
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user