Merge branch 'dev' into feature/initial_screen

This commit is contained in:
on.nemtina 2023-08-21 17:20:23 +05:00
commit 44b88b4242
9 changed files with 113 additions and 46 deletions

View File

@ -87,10 +87,5 @@ namespace AsbCloudApp.Data.ProcessMap
/// Плановый процент использования spin master
/// </summary>
public double UsageSpin { get; set; }
/// <summary>
/// DTO типа секции
/// </summary>
public WellSectionTypeDto WellSectionType { get; set; } = null!;
}
}

View File

@ -5,6 +5,23 @@ using System.Linq;
namespace AsbCloudApp.Data
{
/// <summary>
/// базовая информация о скважине
/// </summary>
public class WellWithTimezoneDto : WellInfoDto
{
/// <inheritdoc/>
[Required]
public SimpleTimezoneDto Timezone { get; set; } = null!;
/// <summary>
/// 0 - неизвестно,
/// 1 - в работе,
/// 2 - завершена
/// </summary>
public int IdState { get; set; }
}
/// <summary>
/// Скважина
/// </summary>

View File

@ -7,41 +7,18 @@ namespace AsbCloudApp.Data;
/// </summary>
public class WellboreDto
{
/// <summary>
/// Идентификатор
/// </summary>
public int Id { get; set; }
public WellWithTimezoneDto Well { get; set; }
/// <summary>
/// Идентификатор
/// </summary>
public int Id { get; set; }
/// <summary>
/// Название
/// </summary>
public string Name { get; set; } = null!;
/// <summary>
/// Идентификатор скважины
/// </summary>
public int IdWell { get; set; }
/// <summary>
/// Состояние скважины
/// </summary>
public int IdWellState { get; set; }
/// <summary>
/// Идентификатор телеметрии
/// </summary>
public int? IdWellTelemetry { get; set; }
/// <summary>
/// Временная зона скважины
/// </summary>
public SimpleTimezoneDto? WellTimezone { get; set; }
/// <summary>
/// Название скважины
/// </summary>
public string WellName { get; set; } = null!;
/// <summary>
/// Начальная глубина ствола
/// </summary>

View File

@ -26,6 +26,16 @@ namespace AsbCloudApp.Services
DateTime dateBegin = default, double intervalSec = 600d,
int approxPointsCount = 1024, CancellationToken token = default);
/// <summary>
/// Получение статистики за период
/// </summary>
/// <param name="idWell"></param>
/// <param name="start"></param>
/// <param name="end"></param>
/// <param name="token"></param>
/// <returns></returns>
Task<DatesRangeDto?> GetRangeAsync(int idWell, DateTimeOffset start, DateTimeOffset end, CancellationToken token);
/// <summary>
/// добавить/изменить данные тех. процесса (используется панелью)
/// </summary>

View File

@ -75,6 +75,8 @@ public class ProcessMapPlanImportService : IProcessMapPlanImportService
public async Task<Stream> ExportAsync(int idWell, CancellationToken cancellationToken)
{
sections = (await wellSectionTypeRepository.GetAllAsync(cancellationToken)).ToArray();
var processMapPlans = (await processMapPlanRepository.GetByIdWellAsync(idWell,
cancellationToken)).ToArray();
@ -120,7 +122,7 @@ public class ProcessMapPlanImportService : IProcessMapPlanImportService
private void AddToRow(IXLRow row, ProcessMapPlanDto processMap)
{
row.Cell(columnWellSectionType).Value = processMap.WellSectionType.Caption;
row.Cell(columnWellSectionType).Value = sections.First(x => x.Id == processMap.IdWellSectionType).Caption;
row.Cell(columnMode).Value = GetModeCaption(processMap.IdMode);
row.Cell(columnDepthStart).Value = processMap.DepthStart;
row.Cell(columnDepthEnd).Value = processMap.DepthEnd;

View File

@ -1,4 +1,5 @@
using AsbCloudApp.Services;
using AsbCloudApp.Data;
using AsbCloudApp.Services;
using AsbCloudDb;
using AsbCloudDb.Model;
using Microsoft.EntityFrameworkCore;
@ -13,7 +14,7 @@ namespace AsbCloudInfrastructure.Services.SAUB
{
public abstract class TelemetryDataBaseService<TDto, TEntity> : ITelemetryDataService<TDto>
where TDto : AsbCloudApp.Data.ITelemetryData
where TEntity : class, ITelemetryData
where TEntity : class, AsbCloudDb.Model.ITelemetryData
{
protected readonly IAsbCloudDbContext db;
protected readonly ITelemetryService telemetryService;
@ -146,6 +147,44 @@ namespace AsbCloudInfrastructure.Services.SAUB
return dtos;
}
/// <inheritdoc/>
public virtual async Task<DatesRangeDto?> GetRangeAsync(
int idWell,
DateTimeOffset start,
DateTimeOffset end,
CancellationToken token)
{
var telemetry = telemetryService.GetOrDefaultTelemetryByIdWell(idWell);
if (telemetry is null)
return default;
var timezone = telemetryService.GetTimezone(telemetry.Id);
var startUtc = start.ToOffset(TimeSpan.Zero);
var endUtc = end.ToOffset(TimeSpan.Zero);
var dbSet = db.Set<TEntity>();
var query = dbSet
.Where(i => i.IdTelemetry == telemetry.Id)
.Where(i => i.DateTime >= startUtc)
.Where(i => i.DateTime <= endUtc)
.GroupBy(i => i.IdTelemetry)
.Select(g => new
{
DateStart = g.Min(i => i.DateTime),
DateEnd = g.Max(i => i.DateTime),
});
var data = await query.FirstOrDefaultAsync(token);
if (data is null)
return default;
return new DatesRangeDto
{
From = data.DateStart.ToRemoteDateTime(timezone.Hours),
To = data.DateEnd.ToRemoteDateTime(timezone.Hours),
};
}
public abstract TDto Convert(TEntity src, double timezoneOffset);
public abstract TEntity Convert(TDto src, double timezoneOffset);

View File

@ -7,6 +7,7 @@ using AsbCloudApp.Repositories;
using AsbCloudApp.Requests;
using AsbCloudApp.Services;
using AsbCloudDb.Model;
using Mapster;
namespace AsbCloudInfrastructure.Services;
@ -55,13 +56,8 @@ public class WellboreService : IWellboreService
var groupedOperations = wellOperations.GroupBy(o => o.IdWellSectionType);
var wellWellbores = groupedOperations.Select(group => new WellboreDto {
Id = group.Key,
IdWell = well.Id,
IdWellState = well.IdState,
IdWellTelemetry = well.IdTelemetry,
Name = sections[group.Key].Caption,
WellName = well.Caption,
WellTimezone = well.Timezone,
Well = well.Adapt<WellWithTimezoneDto>(),
DateStart = group.Min(operation => operation.DateStart),
DateEnd = group.Max(operation => operation.DateStart.AddHours(operation.DurationHours)),
DepthStart = group.Min(operation => operation.DepthStart),
@ -71,7 +67,7 @@ public class WellboreService : IWellboreService
}
return wellbores
.OrderBy(w =>w.IdWell).ThenBy(w=>w.Id)
.OrderBy(w => w.Well.Id).ThenBy(w => w.Id)
.Skip(skip).Take(take);
}

View File

@ -6,6 +6,7 @@ using Microsoft.AspNetCore.Mvc;
using Microsoft.AspNetCore.SignalR;
using System;
using System.Collections.Generic;
using System.ComponentModel.DataAnnotations;
using System.Linq;
using System.Threading;
using System.Threading.Tasks;
@ -95,6 +96,37 @@ namespace AsbCloudWebApi.Controllers.SAUB
return Ok(content);
}
/// <summary>
/// Возвращает диапазон дат за которые есть телеметрия за период времени
/// </summary>
/// <param name="idWell"></param>
/// <param name="start"></param>
/// <param name="end"></param>
/// <param name="token"></param>
/// <returns></returns>
[HttpGet("{idWell}/dateRange")]
public virtual async Task<ActionResult<DatesRangeDto?>> GetRangeAsync(
[FromRoute] int idWell,
[Required] DateTimeOffset start,
[Required] DateTimeOffset end,
CancellationToken token)
{
int? idCompany = User.GetCompanyId();
if (idCompany is null)
return Forbid();
bool isCompanyOwnsWell = await wellService.IsCompanyInvolvedInWellAsync((int)idCompany,
idWell, token).ConfigureAwait(false);
if (!isCompanyOwnsWell)
return Forbid();
var content = await telemetryDataService.GetRangeAsync(idWell, start, end, token);
return Ok(content);
}
/// <summary>
/// Возвращает диапазон дат сохраненных данных.
/// </summary>

View File

@ -6,7 +6,6 @@ using AsbCloudApp.Data;
using AsbCloudApp.Exceptions;
using AsbCloudApp.Requests;
using AsbCloudApp.Services;
using AsbCloudDb.Model;
using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc;
@ -18,7 +17,7 @@ namespace AsbCloudWebApi.Controllers;
/// </summary>
[Authorize]
[ApiController]
[Route("api/well/[controller]")]
[Route("api/[controller]")]
public class WellboreController : ControllerBase
{
private readonly IWellboreService wellboreService;