forked from ddrilling/AsbCloudServer
Merge branch 'dev' into Task/8543610
This commit is contained in:
commit
8b80fff126
@ -1,11 +1,14 @@
|
||||
using AsbCloudApp.Data.ProcessMap;
|
||||
using AsbCloudApp.Requests;
|
||||
using AsbCloudApp.Services;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Threading;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace AsbCloudApp.Services
|
||||
namespace AsbCloudApp.Repositories
|
||||
{
|
||||
#nullable enable
|
||||
/// <summary>
|
||||
/// ÐÒÊ
|
||||
/// </summary>
|
||||
@ -20,5 +23,14 @@ namespace AsbCloudApp.Services
|
||||
/// <returns></returns>
|
||||
Task<IEnumerable<ProcessMapDto>> GetAllAsync(int idWell,
|
||||
DateTime? updateFrom, CancellationToken token = default);
|
||||
|
||||
/// <summary>
|
||||
/// Ïîëó÷èòü ïàðàìåòðû áóðåíèÿ
|
||||
/// </summary>
|
||||
/// <param name="requests"></param>
|
||||
/// <param name="token"></param>
|
||||
/// <returns></returns>
|
||||
Task<IEnumerable<ProcessMapDto>> GetProcessMapAsync(IEnumerable<ProcessMapRequest> requests, CancellationToken token);
|
||||
}
|
||||
#nullable disable
|
||||
}
|
@ -1,4 +1,5 @@
|
||||
using AsbCloudApp.Data;
|
||||
using AsbCloudApp.Data.ProcessMap;
|
||||
using System.Collections.Generic;
|
||||
using System.Threading;
|
||||
using System.Threading.Tasks;
|
||||
@ -27,6 +28,14 @@ namespace AsbCloudApp.Repositories
|
||||
/// <param name="token"></param>
|
||||
/// <returns></returns>
|
||||
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
|
||||
}
|
||||
|
66
AsbCloudApp/Requests/MessageRequest.cs
Normal file
66
AsbCloudApp/Requests/MessageRequest.cs
Normal file
@ -0,0 +1,66 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
|
||||
namespace AsbCloudApp.Requests
|
||||
{
|
||||
#nullable enable
|
||||
/// <summary>
|
||||
/// параметры для запроса списка сообщений
|
||||
/// </summary>
|
||||
public class MessageRequestBase : RequestBase
|
||||
{
|
||||
/// <summary>
|
||||
/// категория
|
||||
/// </summary>
|
||||
public IEnumerable<int>? Categoryids { get; set; }
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// начальная дата
|
||||
/// </summary>
|
||||
public DateTime? Begin { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// конечная дата
|
||||
/// </summary>
|
||||
public DateTime? End { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// строка поиска
|
||||
/// </summary>
|
||||
public string? SearchString { get; set; }
|
||||
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// параметры для запроса списка сообщений (с id скважины)
|
||||
/// </summary>
|
||||
public class MessageRequest : MessageRequestBase
|
||||
{
|
||||
|
||||
/// <summary>
|
||||
/// id скважины
|
||||
/// </summary>
|
||||
public int IdWell { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// параметры для запроса списка сообщений (с id скважины)
|
||||
/// </summary>
|
||||
/// <param name="request"></param>
|
||||
/// <param name="idWell"></param>
|
||||
public MessageRequest(MessageRequestBase request, int idWell)
|
||||
{
|
||||
this.IdWell = idWell;
|
||||
|
||||
this.Categoryids = request.Categoryids;
|
||||
this.Begin = request.Begin;
|
||||
this.End = request.End;
|
||||
this.SearchString = request.SearchString;
|
||||
|
||||
this.Skip = request.Skip;
|
||||
this.Take = request.Take;
|
||||
this.SortFields = request.SortFields;
|
||||
}
|
||||
|
||||
}
|
||||
}
|
28
AsbCloudApp/Requests/ProcessMapRequest.cs
Normal file
28
AsbCloudApp/Requests/ProcessMapRequest.cs
Normal file
@ -0,0 +1,28 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
|
||||
namespace AsbCloudApp.Requests
|
||||
{
|
||||
#nullable enable
|
||||
/// <summary>
|
||||
/// Параметры для запроса получения РТК
|
||||
/// </summary>
|
||||
public class ProcessMapRequest
|
||||
{
|
||||
/// <summary>
|
||||
/// Идентификатор скважины
|
||||
/// </summary>
|
||||
public int IdWell { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Тип секции
|
||||
/// </summary>
|
||||
public int? IdWellSectionType { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Дата обновления
|
||||
/// </summary>
|
||||
public DateTime? UpdateFrom { get; set; }
|
||||
}
|
||||
#nullable disable
|
||||
}
|
@ -1,5 +1,6 @@
|
||||
using AsbCloudApp.Data;
|
||||
using AsbCloudApp.Data.SAUB;
|
||||
using AsbCloudApp.Requests;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Threading;
|
||||
@ -15,20 +16,10 @@ namespace AsbCloudApp.Services
|
||||
/// <summary>
|
||||
/// Получить сообщения по параметрам
|
||||
/// </summary>
|
||||
/// <param name="idWell"></param>
|
||||
/// <param name="categoryids"></param>
|
||||
/// <param name="begin"></param>
|
||||
/// <param name="end"></param>
|
||||
/// <param name="searchString"></param>
|
||||
/// <param name="skip"></param>
|
||||
/// <param name="take"></param>
|
||||
/// <param name="request"></param>
|
||||
/// <param name="token"></param>
|
||||
/// <returns></returns>
|
||||
Task<PaginationContainer<MessageDto>> GetMessagesAsync(int idWell,
|
||||
IEnumerable<int> categoryids = default, DateTime begin = default,
|
||||
DateTime end = default, string searchString = default,
|
||||
int skip = 0, int take = 32,
|
||||
CancellationToken token = default);
|
||||
Task<PaginationContainer<MessageDto>> GetMessagesAsync(MessageRequest request, CancellationToken token);
|
||||
|
||||
/// <summary>
|
||||
/// Метод для сохранения сообщения от панели
|
||||
|
@ -1,6 +1,5 @@
|
||||
using AsbCloudApp.Data.ProcessMap;
|
||||
using System.Collections.Generic;
|
||||
using System.IO;
|
||||
using System.Threading;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
|
6981
AsbCloudDb/Migrations/20230203040530_Add_permissions_for_ProcessMap.Designer.cs
generated
Normal file
6981
AsbCloudDb/Migrations/20230203040530_Add_permissions_for_ProcessMap.Designer.cs
generated
Normal file
File diff suppressed because it is too large
Load Diff
@ -0,0 +1,40 @@
|
||||
using Microsoft.EntityFrameworkCore.Migrations;
|
||||
|
||||
#nullable disable
|
||||
|
||||
namespace AsbCloudDb.Migrations
|
||||
{
|
||||
public partial class Add_permissions_for_ProcessMap : Migration
|
||||
{
|
||||
protected override void Up(MigrationBuilder migrationBuilder)
|
||||
{
|
||||
migrationBuilder.InsertData(
|
||||
table: "t_permission",
|
||||
columns: new[] { "id", "description", "name" },
|
||||
values: new object[,]
|
||||
{
|
||||
{ 513, "Разрешение просматривать РТК", "ProcessMap.get" },
|
||||
{ 514, "Разрешение редактировать РТК", "ProcessMap.edit" },
|
||||
{ 515, "Разрешение удалять РТК", "ProcessMap.delete" }
|
||||
});
|
||||
}
|
||||
|
||||
protected override void Down(MigrationBuilder migrationBuilder)
|
||||
{
|
||||
migrationBuilder.DeleteData(
|
||||
table: "t_permission",
|
||||
keyColumn: "id",
|
||||
keyValue: 513);
|
||||
|
||||
migrationBuilder.DeleteData(
|
||||
table: "t_permission",
|
||||
keyColumn: "id",
|
||||
keyValue: 514);
|
||||
|
||||
migrationBuilder.DeleteData(
|
||||
table: "t_permission",
|
||||
keyColumn: "id",
|
||||
keyValue: 515);
|
||||
}
|
||||
}
|
||||
}
|
@ -1783,6 +1783,24 @@ namespace AsbCloudDb.Migrations
|
||||
Id = 512,
|
||||
Description = "Разрешение удалять плановая траектория",
|
||||
Name = "PlannedTrajectory.delete"
|
||||
},
|
||||
new
|
||||
{
|
||||
Id = 513,
|
||||
Description = "Разрешение просматривать РТК",
|
||||
Name = "ProcessMap.get"
|
||||
},
|
||||
new
|
||||
{
|
||||
Id = 514,
|
||||
Description = "Разрешение редактировать РТК",
|
||||
Name = "ProcessMap.edit"
|
||||
},
|
||||
new
|
||||
{
|
||||
Id = 515,
|
||||
Description = "Разрешение удалять РТК",
|
||||
Name = "ProcessMap.delete"
|
||||
});
|
||||
});
|
||||
|
||||
|
@ -141,6 +141,10 @@
|
||||
new (){ Id = 510, Name="PlannedTrajectory.get", Description="Разрешение просматривать плановая траектория"},
|
||||
new (){ Id = 511, Name="PlannedTrajectory.edit", Description="Разрешение редактировать плановая траектория"},
|
||||
new (){ Id = 512, Name="PlannedTrajectory.delete", Description="Разрешение удалять плановая траектория"},
|
||||
|
||||
new (){ Id = 513, Name="ProcessMap.get", Description="Разрешение просматривать РТК"},
|
||||
new (){ Id = 514, Name="ProcessMap.edit", Description="Разрешение редактировать РТК"},
|
||||
new (){ Id = 515, Name="ProcessMap.delete", Description="Разрешение удалять РТК"},
|
||||
};
|
||||
}
|
||||
}
|
||||
|
80
AsbCloudInfrastructure/PredicateBuilder.cs
Normal file
80
AsbCloudInfrastructure/PredicateBuilder.cs
Normal file
@ -0,0 +1,80 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Linq.Expressions;
|
||||
|
||||
namespace AsbCloudInfrastructure
|
||||
{
|
||||
#nullable enable
|
||||
/// <summary>
|
||||
/// stolen from https://github.com/lotosbin/BinbinPredicateBuilder
|
||||
/// </summary>
|
||||
public static class PredicateBuilder
|
||||
{
|
||||
/// <summary>
|
||||
/// Combines the first predicate with the second using the logical "and".
|
||||
/// </summary>
|
||||
public static Expression<Func<T, bool>> And<T>(this Expression<Func<T, bool>> first, Expression<Func<T, bool>> second)
|
||||
{
|
||||
return first.Compose(second, Expression.AndAlso);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Combines the first predicate with the second using the logical "or".
|
||||
/// </summary>
|
||||
public static Expression<Func<T, bool>> Or<T>(this Expression<Func<T, bool>> first, Expression<Func<T, bool>> second)
|
||||
{
|
||||
return first.Compose(second, Expression.OrElse);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Negates the predicate.
|
||||
/// </summary>
|
||||
public static Expression<Func<T, bool>> Not<T>(this Expression<Func<T, bool>> expression)
|
||||
{
|
||||
var negated = Expression.Not(expression.Body);
|
||||
return Expression.Lambda<Func<T, bool>>(negated, expression.Parameters);
|
||||
}
|
||||
|
||||
private static Expression<T> Compose<T>(this Expression<T> first, Expression<T> second, Func<Expression, Expression, Expression> merge)
|
||||
{
|
||||
var map = first.Parameters
|
||||
.Select((f, i) => new { f, s = second.Parameters[i] })
|
||||
.ToDictionary(p => p.s, p => p.f);
|
||||
|
||||
var tryReplaceParametr = (Expression node) =>
|
||||
{
|
||||
if (node is ParameterExpression parameter)
|
||||
if (map.TryGetValue(parameter, out ParameterExpression? replacement))
|
||||
return replacement;
|
||||
return node;
|
||||
};
|
||||
|
||||
var secondBody = ParameterRebinder.ReplaceParameters(map, second.Body);
|
||||
return Expression.Lambda<T>(merge(first.Body, secondBody), first.Parameters);
|
||||
}
|
||||
|
||||
class ParameterRebinder : ExpressionVisitor
|
||||
{
|
||||
private readonly Dictionary<ParameterExpression, ParameterExpression> map;
|
||||
|
||||
private ParameterRebinder(Dictionary<ParameterExpression, ParameterExpression> map)
|
||||
{
|
||||
this.map = map;
|
||||
}
|
||||
|
||||
public static Expression ReplaceParameters(Dictionary<ParameterExpression, ParameterExpression> map, Expression exp)
|
||||
{
|
||||
return new ParameterRebinder(map).Visit(exp);
|
||||
}
|
||||
|
||||
protected override Expression VisitParameter(ParameterExpression parametr)
|
||||
{
|
||||
if (map.TryGetValue(parametr, out ParameterExpression? replacement))
|
||||
parametr = replacement;
|
||||
return parametr;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
#nullable disable
|
@ -1,12 +1,17 @@
|
||||
using AsbCloudApp.Data;
|
||||
using AsbCloudApp.Data.ProcessMap;
|
||||
using AsbCloudApp.Repositories;
|
||||
using AsbCloudApp.Requests;
|
||||
using AsbCloudApp.Services;
|
||||
using AsbCloudDb.Model;
|
||||
using DocumentFormat.OpenXml.Spreadsheet;
|
||||
using Mapster;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using Org.BouncyCastle.Asn1.Ocsp;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Linq.Expressions;
|
||||
using System.Threading;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
@ -30,7 +35,15 @@ namespace AsbCloudInfrastructure.Repository
|
||||
public async Task<IEnumerable<ProcessMapDto>> GetAllAsync(int idWell,
|
||||
DateTime? updateFrom, CancellationToken token)
|
||||
{
|
||||
var entities = await BuildQuery(idWell, updateFrom)
|
||||
var requests = new[]
|
||||
{
|
||||
new ProcessMapRequest {
|
||||
IdWell = idWell,
|
||||
UpdateFrom = updateFrom
|
||||
}
|
||||
};
|
||||
|
||||
var entities = await BuildQuery(requests)
|
||||
.OrderBy(e => e.DepthStart)
|
||||
.ThenBy(e => e.Id)
|
||||
.ToListAsync(token)
|
||||
@ -40,6 +53,15 @@ namespace AsbCloudInfrastructure.Repository
|
||||
return dtos;
|
||||
}
|
||||
|
||||
public async Task<IEnumerable<ProcessMapDto>> GetProcessMapAsync(IEnumerable<ProcessMapRequest> requests, CancellationToken token)
|
||||
{
|
||||
var entities = await BuildQuery(requests)
|
||||
.ToListAsync(token)
|
||||
.ConfigureAwait(false);
|
||||
var dtos = entities.Select(Convert).ToList();
|
||||
return dtos;
|
||||
}
|
||||
|
||||
public override async Task<int> InsertAsync(ProcessMapDto dto,
|
||||
CancellationToken token)
|
||||
{
|
||||
@ -56,18 +78,31 @@ namespace AsbCloudInfrastructure.Repository
|
||||
return result;
|
||||
}
|
||||
|
||||
|
||||
private IQueryable<ProcessMap> BuildQuery(int idWell, DateTime? updateFrom)
|
||||
private IQueryable<ProcessMap> BuildQuery(IEnumerable<ProcessMapRequest> requests)
|
||||
{
|
||||
var query = GetQuery().Where(e => e.IdWell == idWell);
|
||||
|
||||
if (updateFrom is not null)
|
||||
var query = GetQuery();
|
||||
if (requests.Any())
|
||||
{
|
||||
var timezone = wellService.GetTimezone(idWell);
|
||||
var updateFromUtc = updateFrom?.ToUtcDateTimeOffset(timezone.Hours);
|
||||
query.Where(e => e.LastUpdate >= updateFromUtc);
|
||||
}
|
||||
Expression<Func<ProcessMap, bool>> predicate = map => false;
|
||||
foreach (var request in requests)
|
||||
{
|
||||
Expression<Func<ProcessMap, bool>> predicate2 = map => map.IdWell == request.IdWell;
|
||||
|
||||
if (request.IdWellSectionType is not null)
|
||||
predicate2 = predicate2.And(map => map.IdWellSectionType == request.IdWellSectionType);
|
||||
|
||||
if (request.UpdateFrom is not null)
|
||||
{
|
||||
var timezone = wellService.GetTimezone(request.IdWell);
|
||||
var updateFromUtc = request.UpdateFrom?.ToUtcDateTimeOffset(timezone.Hours);
|
||||
predicate2 = predicate2.And(map => map.LastUpdate >= updateFromUtc);
|
||||
}
|
||||
|
||||
predicate = predicate.Or(predicate2);
|
||||
}
|
||||
query = query.Where(predicate);
|
||||
|
||||
}
|
||||
return query;
|
||||
}
|
||||
protected override ProcessMapDto Convert(ProcessMap entity)
|
||||
|
@ -1,8 +1,11 @@
|
||||
using AsbCloudApp.Data;
|
||||
using AsbCloudApp.Data.ProcessMap;
|
||||
using AsbCloudApp.Repositories;
|
||||
using AsbCloudApp.Requests;
|
||||
using AsbCloudDb.Model;
|
||||
using Mapster;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Threading;
|
||||
@ -14,10 +17,12 @@ namespace AsbCloudInfrastructure.Repository
|
||||
public class WellCompositeRepository : IWellCompositeRepository
|
||||
{
|
||||
private readonly IAsbCloudDbContext db;
|
||||
private readonly IProcessMapRepository processMapRepository;
|
||||
|
||||
public WellCompositeRepository(IAsbCloudDbContext db)
|
||||
public WellCompositeRepository(IAsbCloudDbContext db, IProcessMapRepository processMapRepository)
|
||||
{
|
||||
this.db = db;
|
||||
this.processMapRepository = processMapRepository;
|
||||
}
|
||||
|
||||
/// <inheritdoc/>
|
||||
@ -44,6 +49,51 @@ namespace AsbCloudInfrastructure.Repository
|
||||
return db.SaveChangesAsync(token);
|
||||
}
|
||||
|
||||
/// <inheritdoc/>
|
||||
public async Task<IEnumerable<ProcessMapDto>> GetCompositeProcessMap(int idWell, CancellationToken token)
|
||||
{
|
||||
var dtos = await GetAsync(idWell, token);
|
||||
|
||||
var requests = dtos.Select(x => new ProcessMapRequest {
|
||||
IdWell = x.IdWellSrc,
|
||||
IdWellSectionType = x.IdWellSectionType
|
||||
});
|
||||
|
||||
var processMap = await processMapRepository.GetProcessMapAsync(requests, token);
|
||||
|
||||
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
|
||||
});
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
private static WellComposite Convert(int idWell, WellCompositeDto dto)
|
||||
{
|
||||
var entity = dto.Adapt<WellComposite>();
|
||||
|
@ -43,6 +43,7 @@ namespace AsbCloudInfrastructure.Services.ProcessMap
|
||||
this.subsystemOperationTimeService = subsystemOperationTimeService;
|
||||
}
|
||||
|
||||
/// <inheritdoc/>
|
||||
public async Task<IEnumerable<ProcessMapReportDto>> GetProcessMapAsync(int idWell, CancellationToken token)
|
||||
{
|
||||
var well = wellService.GetOrDefault(idWell)
|
||||
|
@ -1,6 +1,8 @@
|
||||
using AsbCloudApp.Data;
|
||||
using AsbCloudApp.Data.SAUB;
|
||||
using AsbCloudApp.Requests;
|
||||
using AsbCloudApp.Services;
|
||||
using AsbCloudDb;
|
||||
using AsbCloudDb.Model;
|
||||
using AsbCloudInfrastructure.EfCache;
|
||||
using Mapster;
|
||||
@ -11,6 +13,7 @@ using System.Linq;
|
||||
using System.Threading;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
#nullable enable
|
||||
namespace AsbCloudInfrastructure.Services.SAUB
|
||||
{
|
||||
public class MessageService : IMessageService
|
||||
@ -24,41 +27,39 @@ namespace AsbCloudInfrastructure.Services.SAUB
|
||||
this.telemetryService = telemetryService;
|
||||
}
|
||||
|
||||
public async Task<PaginationContainer<MessageDto>> GetMessagesAsync(
|
||||
int idWell,
|
||||
IEnumerable<int> categoryids = default,
|
||||
DateTime begin = default,
|
||||
DateTime end = default,
|
||||
string searchString = default,
|
||||
int skip = 0,
|
||||
int take = 32,
|
||||
CancellationToken token = default)
|
||||
public async Task<PaginationContainer<MessageDto>> GetMessagesAsync(MessageRequest request, CancellationToken token)
|
||||
{
|
||||
var idTelemetry = telemetryService.GetOrDefaultIdTelemetryByIdWell(idWell);
|
||||
var result = new PaginationContainer<MessageDto>
|
||||
{
|
||||
Skip = request.Skip ?? 0,
|
||||
Take = request.Take ?? 32,
|
||||
};
|
||||
|
||||
var idTelemetry = telemetryService.GetOrDefaultIdTelemetryByIdWell(request.IdWell);
|
||||
if (idTelemetry is null)
|
||||
return null;
|
||||
return result;
|
||||
|
||||
var allEvents = await db.TelemetryEvents.FromCacheAsync(token);
|
||||
var events = allEvents.Where(e => e.IdTelemetry == idTelemetry);
|
||||
|
||||
if (!events.Any())
|
||||
return null;
|
||||
return result;
|
||||
|
||||
var query = db.TelemetryMessages.Where(m => m.IdTelemetry == idTelemetry)
|
||||
.OrderBy(m => m.DateTime).AsNoTracking();
|
||||
|
||||
if (categoryids?.Any() == true || !string.IsNullOrEmpty(searchString))
|
||||
if (request.Categoryids?.Any() == true || !string.IsNullOrEmpty(request.SearchString))
|
||||
{
|
||||
if (!string.IsNullOrEmpty(searchString))
|
||||
events = events.Where(e => e.MessageTemplate.Contains(searchString, StringComparison.OrdinalIgnoreCase));
|
||||
if (!string.IsNullOrEmpty(request.SearchString))
|
||||
events = events.Where(e => e.MessageTemplate.Contains(request.SearchString, StringComparison.OrdinalIgnoreCase));
|
||||
|
||||
if (categoryids?.Any() == true)
|
||||
events = events.Where(e => categoryids.ToList().Contains(e.IdCategory));
|
||||
if (request.Categoryids?.Any() == true)
|
||||
events = events.Where(e => request.Categoryids.ToList().Contains(e.IdCategory));
|
||||
|
||||
var eventIds = events.Select(e => e.IdEvent);
|
||||
|
||||
if (!eventIds.Any())
|
||||
return null;
|
||||
return result;
|
||||
|
||||
query = query.Where(m => eventIds.Contains(m.IdEvent));
|
||||
}
|
||||
@ -67,30 +68,27 @@ namespace AsbCloudInfrastructure.Services.SAUB
|
||||
|
||||
var timezone = telemetryService.GetTimezone(idTelemetry ?? default);
|
||||
|
||||
if (begin != default)
|
||||
if (request.Begin is not null)
|
||||
{
|
||||
var beginUtc = begin.ToUtcDateTimeOffset(timezone.Hours);
|
||||
var beginUtc = request.Begin.Value.ToUtcDateTimeOffset(timezone.Hours);
|
||||
query = query.Where(m => m.DateTime >= beginUtc);
|
||||
}
|
||||
|
||||
if (end != default)
|
||||
if (request.End is not null)
|
||||
{
|
||||
var endUtc = end.ToUtcDateTimeOffset(timezone.Hours);
|
||||
var endUtc = request.End.Value.ToUtcDateTimeOffset(timezone.Hours);
|
||||
query = query.Where(m => m.DateTime <= endUtc);
|
||||
}
|
||||
|
||||
var result = new PaginationContainer<MessageDto>
|
||||
result.Count = query.Count();
|
||||
|
||||
if (request.SortFields?.Any() == true)
|
||||
{
|
||||
Skip = skip,
|
||||
Take = take,
|
||||
Count = query.Count()
|
||||
};
|
||||
|
||||
if (skip > 0)
|
||||
query = query.Skip(skip);
|
||||
|
||||
var messagesList = await query.Take(take).AsNoTracking()
|
||||
.ToListAsync(token).ConfigureAwait(false);
|
||||
query = query.SortBy(request.SortFields);
|
||||
}
|
||||
var messagesList = await query.Skip(result.Skip)
|
||||
.Take(result.Take).AsNoTracking()
|
||||
.ToListAsync(token).ConfigureAwait(false);
|
||||
|
||||
if (messagesList.Count == 0)
|
||||
return result;
|
||||
@ -98,6 +96,9 @@ namespace AsbCloudInfrastructure.Services.SAUB
|
||||
var allUsers = await db.TelemetryUsers.FromCacheAsync(token);
|
||||
var users = allUsers.Where(u => u.IdTelemetry == idTelemetry);
|
||||
|
||||
var eventsDict = events.ToDictionary(x=>x.IdEvent, x => x);
|
||||
var usersDict = users.ToDictionary(x => x.IdUser, x => x);
|
||||
|
||||
foreach (var message in messagesList)
|
||||
{
|
||||
var messageDto = new MessageDto
|
||||
@ -110,17 +111,15 @@ namespace AsbCloudInfrastructure.Services.SAUB
|
||||
|
||||
if (message.IdTelemetryUser is not null)
|
||||
{
|
||||
if (users.Any())
|
||||
if (usersDict.TryGetValue((int)message.IdTelemetryUser, out TelemetryUser? user))
|
||||
{
|
||||
var user = users.FirstOrDefault(u => u.IdUser == message.IdTelemetryUser);
|
||||
messageDto.User = user.MakeDisplayName();
|
||||
}
|
||||
else
|
||||
messageDto.User = message.IdTelemetryUser.ToString();
|
||||
}
|
||||
|
||||
var e = events.FirstOrDefault(e => e.IdEvent == message.IdEvent);
|
||||
if (e != null)
|
||||
if (eventsDict.TryGetValue(message.IdEvent, out TelemetryEvent? e))
|
||||
{
|
||||
messageDto.CategoryId = e.IdCategory;
|
||||
messageDto.Message = e.MakeMessageText(message);
|
||||
@ -136,7 +135,7 @@ namespace AsbCloudInfrastructure.Services.SAUB
|
||||
CancellationToken token = default)
|
||||
{
|
||||
if (!dtos.Any())
|
||||
return null;
|
||||
return Task.CompletedTask;
|
||||
|
||||
var telemetryId = telemetryService.GetOrCreateTelemetryIdByUid(uid);
|
||||
var timezone = telemetryService.GetTimezone(telemetryId);
|
||||
@ -154,3 +153,4 @@ namespace AsbCloudInfrastructure.Services.SAUB
|
||||
}
|
||||
}
|
||||
}
|
||||
#nullable disable
|
||||
|
@ -1,4 +1,5 @@
|
||||
using AsbCloudApp.Data.ProcessMap;
|
||||
using AsbCloudApp.Repositories;
|
||||
using AsbCloudApp.Services;
|
||||
using Microsoft.AspNetCore.Authorization;
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
|
@ -1,4 +1,5 @@
|
||||
using AsbCloudApp.Data;
|
||||
using AsbCloudApp.Requests;
|
||||
using AsbCloudApp.Services;
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
using System;
|
||||
@ -28,29 +29,30 @@ namespace AsbCloudWebApi.Controllers.SAUB
|
||||
/// Выдает список сообщений по скважине
|
||||
/// </summary>
|
||||
/// <param name="idWell">id скважины</param>
|
||||
/// <param name="categoryids">список категорий</param>
|
||||
/// <param name="begin">дата начала</param>
|
||||
/// <param name="end">окончание</param>
|
||||
/// <param name="skip">для пагинации кол-во записей пропустить</param>
|
||||
/// <param name="take">для пагинации кол-во записей </param>
|
||||
/// <param name="searchString"> Строка поиска </param>
|
||||
/// <param name="request">Параметры запроса</param>
|
||||
/// <param name="token">Токен для отмены задачи</param>
|
||||
/// <returns>список сообщений по скважине</returns>
|
||||
[HttpGet]
|
||||
[Permission]
|
||||
[ProducesResponseType(typeof(PaginationContainer<MessageDto>), (int)System.Net.HttpStatusCode.OK)]
|
||||
public async Task<IActionResult> GetMessagesAsync(int idWell, int skip = 0, int take = 32,
|
||||
[FromQuery] IEnumerable<int> categoryids = default,
|
||||
DateTime begin = default, DateTime end = default,
|
||||
string searchString = default,
|
||||
CancellationToken token = default)
|
||||
public async Task<IActionResult> GetMessagesAsync(
|
||||
[FromRoute] int idWell,
|
||||
[FromQuery] MessageRequestBase request,
|
||||
CancellationToken token = default)
|
||||
{
|
||||
if (take > 1024)
|
||||
|
||||
if (!await UserHasAccesToWellAsync(idWell, token))
|
||||
return Forbid();
|
||||
|
||||
if (request.Take > 1024)
|
||||
return BadRequest("limit mast be less then 1024");
|
||||
|
||||
var result = await messageService.GetMessagesAsync(idWell,
|
||||
categoryids, begin, end, searchString,
|
||||
skip, take, token).ConfigureAwait(false);
|
||||
var requestToService = new MessageRequest(request, idWell);
|
||||
|
||||
var result = await messageService.GetMessagesAsync(
|
||||
requestToService,
|
||||
token)
|
||||
.ConfigureAwait(false);
|
||||
|
||||
if (result is null || result.Count == 0)
|
||||
return NoContent();
|
||||
@ -85,5 +87,15 @@ namespace AsbCloudWebApi.Controllers.SAUB
|
||||
|
||||
return Ok(wellMessagesDatesRange);
|
||||
}
|
||||
|
||||
protected async Task<bool> UserHasAccesToWellAsync(int idWell, CancellationToken token)
|
||||
{
|
||||
var idCompany = User.GetCompanyId();
|
||||
if (idCompany is not null &&
|
||||
await wellService.IsCompanyInvolvedInWellAsync((int)idCompany, idWell, token)
|
||||
.ConfigureAwait(false))
|
||||
return true;
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -1,4 +1,5 @@
|
||||
using AsbCloudApp.Data;
|
||||
using AsbCloudApp.Data.ProcessMap;
|
||||
using AsbCloudApp.Repositories;
|
||||
using AsbCloudApp.Services;
|
||||
using Microsoft.AspNetCore.Authorization;
|
||||
@ -21,7 +22,8 @@ namespace AsbCloudWebApi.Controllers
|
||||
private readonly IWellCompositeRepository wellCompositeRepository;
|
||||
private readonly IWellService wellService;
|
||||
|
||||
public WellCompositeController(IWellCompositeRepository wellCompositeRepository, IWellService wellService)
|
||||
public WellCompositeController(IWellCompositeRepository wellCompositeRepository,
|
||||
IWellService wellService)
|
||||
{
|
||||
this.wellCompositeRepository = wellCompositeRepository;
|
||||
this.wellService = wellService;
|
||||
@ -63,6 +65,24 @@ namespace AsbCloudWebApi.Controllers
|
||||
return Ok(result);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Получение РТК по композитной скважине
|
||||
/// </summary>
|
||||
/// <param name="idWell"></param>
|
||||
/// <param name="token"></param>
|
||||
/// <returns></returns>
|
||||
[HttpGet("getCompositeProcessMap")]
|
||||
[Permission]
|
||||
[ProducesResponseType(typeof(IEnumerable<ProcessMapDto>), (int)System.Net.HttpStatusCode.OK)]
|
||||
public async Task<IActionResult> GetCompositeProcessMap(int idWell, CancellationToken token = default)
|
||||
{
|
||||
if (!await CanUserAccessToWellAsync(idWell, token).ConfigureAwait(false))
|
||||
return Forbid();
|
||||
|
||||
var result = await wellCompositeRepository.GetCompositeProcessMap(idWell, token).ConfigureAwait(false);
|
||||
return Ok(result);
|
||||
}
|
||||
|
||||
private async Task<bool> CanUserAccessToWellAsync(int idWell, CancellationToken token = default)
|
||||
{
|
||||
int? idCompany = User.GetCompanyId();
|
||||
|
Loading…
Reference in New Issue
Block a user