diff --git a/AsbCloudApp/Data/ChangeLogAbstract.cs b/AsbCloudApp/Data/ChangeLogDto.cs
similarity index 93%
rename from AsbCloudApp/Data/ChangeLogAbstract.cs
rename to AsbCloudApp/Data/ChangeLogDto.cs
index 9e34c948..7d47be9c 100644
--- a/AsbCloudApp/Data/ChangeLogAbstract.cs
+++ b/AsbCloudApp/Data/ChangeLogDto.cs
@@ -6,12 +6,12 @@ namespace AsbCloudApp.Data;
///
/// Часть записи описывающая изменение
///
-public abstract class ChangeLogAbstract
+public class ChangeLogDto where T: IId
{
///
- /// ИД записи
+ /// Запись
///
- public int Id { get; set; }
+ public required T Item { get; set; }
///
/// Автор
diff --git a/AsbCloudApp/Data/ProcessMaps/ProcessMapPlanBaseDto.cs b/AsbCloudApp/Data/ProcessMaps/ProcessMapPlanBaseDto.cs
index c2ce713a..13eb6583 100644
--- a/AsbCloudApp/Data/ProcessMaps/ProcessMapPlanBaseDto.cs
+++ b/AsbCloudApp/Data/ProcessMaps/ProcessMapPlanBaseDto.cs
@@ -5,13 +5,18 @@ using System.ComponentModel.DataAnnotations;
namespace AsbCloudApp.Data.ProcessMaps;
///
-public abstract class ProcessMapPlanBaseDto : ChangeLogAbstract, IId, IWellRelated, IValidatableObject
+public abstract class ProcessMapPlanBaseDto : IId, IWellRelated, IValidatableObject
{
///
/// Id скважины
///
public int IdWell { get; set; }
+ ///
+ /// Id записи
+ ///
+ public int Id { get; set; }
+
///
/// Тип секции
///
diff --git a/AsbCloudApp/Extensions/ChangeLogExtensions.cs b/AsbCloudApp/Extensions/ChangeLogExtensions.cs
index 83f28fbe..c963201b 100644
--- a/AsbCloudApp/Extensions/ChangeLogExtensions.cs
+++ b/AsbCloudApp/Extensions/ChangeLogExtensions.cs
@@ -1,4 +1,5 @@
using AsbCloudApp.Data;
+using AsbCloudApp.Data.ProcessMaps;
using System;
using System.Collections.Generic;
using System.Linq;
@@ -19,8 +20,8 @@ namespace AsbCloudApp.Extensions
///
///
///
- public static IEnumerable WhereActualAtMoment(this IEnumerable items, DateTimeOffset moment)
- where T : ChangeLogAbstract
+ public static IEnumerable> WhereActualAtMoment(this IEnumerable> items, DateTimeOffset moment)
+ where T : IId
{
var actualItems = items
.Where(item => item.Creation <= moment)
diff --git a/AsbCloudApp/Repositories/IChangeLogQueryBuilder.cs b/AsbCloudApp/Repositories/IChangeLogQueryBuilder.cs
new file mode 100644
index 00000000..b7952c1a
--- /dev/null
+++ b/AsbCloudApp/Repositories/IChangeLogQueryBuilder.cs
@@ -0,0 +1,62 @@
+using AsbCloudApp.Data;
+using System;
+using System.Collections.Generic;
+using System.Threading;
+using System.Threading.Tasks;
+
+namespace AsbCloudApp.Repositories;
+
+///
+/// Интерфейс для работы с объектами, содержащими историю изменений
+///
+///
+///
+public interface IChangeLogQueryBuilder
+ where TDto : IId
+{
+ ///
+ /// Применение запроса
+ ///
+ /// Запрос
+ ///
+ IChangeLogQueryBuilderWithKnownTimezone ApplyRequest(TRequest request);
+
+ ///
+ /// Материализация записей
+ ///
+ ///
+ ///
+ ///
+ Task> GetData(TimeSpan offset, CancellationToken token);
+
+ ///
+ /// Материализация записей с историей
+ ///
+ ///
+ ///
+ ///
+ Task>> GetChangeLogData(TimeSpan offset, CancellationToken token);
+}
+
+///
+/// Интерфейс для работы с объектами, содержащими историю изменений. С известной временной зоной
+///
+///
+///
+public interface IChangeLogQueryBuilderWithKnownTimezone: IChangeLogQueryBuilder
+ where TDto : IId
+{
+ ///
+ /// Материализация записей. Временная зона определяется по запросу из последнего ApplyRequest
+ ///
+ ///
+ ///
+ Task> GetData(CancellationToken token);
+
+ ///
+ /// Материализация записей с историей. Временная зона определяется по запросу из последнего ApplyRequest
+ ///
+ ///
+ ///
+ Task>> GetChangeLogData(CancellationToken token);
+}
\ No newline at end of file
diff --git a/AsbCloudApp/Repositories/IChangeLogRepository.cs b/AsbCloudApp/Repositories/IChangeLogRepository.cs
index a8a5e635..bd8cbe85 100644
--- a/AsbCloudApp/Repositories/IChangeLogRepository.cs
+++ b/AsbCloudApp/Repositories/IChangeLogRepository.cs
@@ -1,9 +1,9 @@
-using System;
+using AsbCloudApp.Data;
+using AsbCloudApp.Requests;
+using System;
using System.Collections.Generic;
using System.Threading;
using System.Threading.Tasks;
-using AsbCloudApp.Data;
-using AsbCloudApp.Requests;
namespace AsbCloudApp.Repositories;
@@ -11,41 +11,40 @@ namespace AsbCloudApp.Repositories;
/// Репозиторий для записей с историей
///
public interface IChangeLogRepository
- where TDto : ChangeLogAbstract
- where TRequest : ChangeLogBaseRequest
+ where TDto : IId
{
- ///
- /// Добавление записей
- ///
- ///
- ///
- ///
- ///
- Task InsertRange(int idUser, IEnumerable dtos, CancellationToken token);
+ ///
+ /// Добавление записей
+ ///
+ /// пользователь, который добавляет
+ ///
+ ///
+ ///
+ Task InsertRange(int idUser, IEnumerable dtos, CancellationToken token);
- ///
- /// Редактирование записей
- ///
- ///
- ///
- ///
- ///
- Task UpdateRange(int idUser, IEnumerable dtos, CancellationToken token);
+ ///
+ /// Редактирование записей
+ ///
+ /// пользователь, который редактирует
+ ///
+ ///
+ ///
+ Task UpdateRange(int idUser, IEnumerable dtos, CancellationToken token);
///
/// Добавляет Dto у которых id == 0, изменяет dto у которых id != 0
///
- ///
+ /// пользователь, который редактирует или добавляет
///
///
///
Task UpdateOrInsertRange(int idUser, IEnumerable dtos, CancellationToken token);
///
- /// Добавление записей с удалением старых (для импорта)
+ /// Помечает записи как удаленные
///
- ///
- ///
+ /// пользователь, который чистит
+ /// Фильтр по свойствам конкретной сущности
///
///
Task Clear(int idUser, TRequest request, CancellationToken token);
@@ -61,13 +60,13 @@ public interface IChangeLogRepository
Task ClearAndInsertRange(int idUser, TRequest request, IEnumerable dtos, CancellationToken token);
///
- /// Удаление записей
+ /// Пометить записи как удаленные
///
///
///
///
///
- Task DeleteRange(int idUser, IEnumerable ids, CancellationToken token);
+ Task MarkAsDeleted(int idUser, IEnumerable ids, CancellationToken token);
///
/// Получение дат изменений записей
@@ -78,19 +77,26 @@ public interface IChangeLogRepository
Task> GetDatesChange(TRequest request, CancellationToken token);
///
- /// Получение журнала изменений
+ /// Получение измененных записей за определенную дату
///
///
- /// Фильтр по дате. Если null - вернет все
+ /// Фильтр по дате. Если null - вернет все записи, без привязки к дате
///
///
- Task> GetChangeLog(TRequest request, DateOnly? date, CancellationToken token);
+ Task>> GetChangeLogForDate(TRequest request, DateOnly? date, CancellationToken token);
///
- /// Получение записей по параметрам
+ /// Получение текущих сейчас записей по параметрам
///
///
///
///
- Task> Get(TRequest request, CancellationToken token);
+ Task> GetCurrent(TRequest request, CancellationToken token);
+
+ ///
+ /// Получение объекта, реализующего интерфейс IChangeLogRepositoryBuilder
+ /// для последующих вызовов методов фильтрации по запросам
+ ///
+ ///
+ IChangeLogQueryBuilder GetQueryBuilder(ChangeLogRequest request);
}
diff --git a/AsbCloudApp/Requests/ChangeLogBaseRequest.cs b/AsbCloudApp/Requests/ChangeLogBaseRequest.cs
deleted file mode 100644
index e70553b2..00000000
--- a/AsbCloudApp/Requests/ChangeLogBaseRequest.cs
+++ /dev/null
@@ -1,14 +0,0 @@
-using System;
-
-namespace AsbCloudApp.Requests;
-
-///
-/// Базовый запрос актуальных данных
-///
-public class ChangeLogBaseRequest
-{
- ///
- /// Дата/время на которую записи были актуальны. Если не задано, то возвращаются все данные без учета их актуальности
- ///
- public DateTimeOffset? Moment { get; set; }
-}
diff --git a/AsbCloudApp/Requests/ChangeLogRequest.cs b/AsbCloudApp/Requests/ChangeLogRequest.cs
new file mode 100644
index 00000000..4af94018
--- /dev/null
+++ b/AsbCloudApp/Requests/ChangeLogRequest.cs
@@ -0,0 +1,31 @@
+using System;
+
+namespace AsbCloudApp.Requests;
+
+///
+/// Запрос изменений
+///
+public class ChangeLogRequest
+{
+ ///
+ /// Дата/время на которую записи были актуальны. Если не задано, то возвращаются все данные без учета их актуальности
+ ///
+ public DateTimeOffset? Moment { get; set; }
+
+ ///
+ /// Конструктор
+ ///
+ public ChangeLogRequest()
+ {
+
+ }
+
+ ///
+ /// Копирующий конструктор
+ ///
+ ///
+ public ChangeLogRequest(ChangeLogRequest request)
+ {
+ Moment = request.Moment;
+ }
+}
diff --git a/AsbCloudApp/Requests/ProcessMapPlanBaseRequest.cs b/AsbCloudApp/Requests/ProcessMapPlanBaseRequest.cs
index 006c26e5..2b4cd30d 100644
--- a/AsbCloudApp/Requests/ProcessMapPlanBaseRequest.cs
+++ b/AsbCloudApp/Requests/ProcessMapPlanBaseRequest.cs
@@ -1,29 +1,39 @@
using System;
-using System.ComponentModel.DataAnnotations;
namespace AsbCloudApp.Requests;
///
/// Запрос для получения РТК план
///
-public class ProcessMapPlanBaseRequest: ChangeLogBaseRequest
+public class ProcessMapPlanBaseRequest
{
- ///
- /// Тип секции
- ///
- [Range(1, int.MaxValue, ErrorMessage = "Id секции - положительное число")]
- public int? IdWellSectionType { get; set; }
-
///
/// Вернуть данные, которые поменялись с указанной даты
///
public DateTimeOffset? UpdateFrom { get; set; }
+
+ ///
+ /// Конструктор
+ ///
+ public ProcessMapPlanBaseRequest()
+ {
+
+ }
+
+ ///
+ /// Копирующий конструктор
+ ///
+ /// Параметры запроса
+ public ProcessMapPlanBaseRequest(ProcessMapPlanBaseRequest request)
+ {
+ UpdateFrom = request.UpdateFrom;
+ }
}
///
/// Запрос для получения РТК план по скважине
///
-public class ProcessMapPlanBaseRequestWithWell: ProcessMapPlanBaseRequest
+public class ProcessMapPlanBaseRequestWithWell : ProcessMapPlanBaseRequest
{
///
/// Запрос для получения РТК план по скважине
@@ -40,11 +50,9 @@ public class ProcessMapPlanBaseRequestWithWell: ProcessMapPlanBaseRequest
///
///
public ProcessMapPlanBaseRequestWithWell(ProcessMapPlanBaseRequest request, int idWell)
+ : base(request)
{
- IdWell=idWell;
- IdWellSectionType=request.IdWellSectionType;
- UpdateFrom = request.UpdateFrom;
- Moment = request.Moment;
+ IdWell = idWell;
}
///
diff --git a/AsbCloudApp/Requests/ProcessMapPlanRequest.cs b/AsbCloudApp/Requests/ProcessMapPlanRequest.cs
deleted file mode 100644
index b3247ce2..00000000
--- a/AsbCloudApp/Requests/ProcessMapPlanRequest.cs
+++ /dev/null
@@ -1,24 +0,0 @@
-using System;
-
-namespace AsbCloudApp.Requests;
-
-///
-/// Запрос для получения РТК план
-///
-public class ProcessMapPlanRequest
-{
- ///
- /// Идентификатор скважины
- ///
- public int IdWell { get; set; }
-
- ///
- /// Тип секции
- ///
- public int? IdWellSectionType { get; set; }
-
- ///
- /// Дата обновления
- ///
- public DateTimeOffset? UpdateFrom { get; set; }
-}
\ No newline at end of file
diff --git a/AsbCloudDb/Model/ChangeLogAbstract.cs b/AsbCloudDb/Model/ChangeLogAbstract.cs
index d9bc74e0..6320c3dc 100644
--- a/AsbCloudDb/Model/ChangeLogAbstract.cs
+++ b/AsbCloudDb/Model/ChangeLogAbstract.cs
@@ -86,4 +86,10 @@ public abstract class ChangeLogAbstract
///
[Column("id_previous"), Comment("ИД состояния записи: \n0 - актуальная\n1 - замененная\n2 - удаленная")]
public int? IdPrevious { get; set; }
+
+ [ForeignKey(nameof(IdAuthor))]
+ public virtual User Author { get; set; } = null!;
+
+ [ForeignKey(nameof(IdEditor))]
+ public virtual User? Editor { get; set; }
}
diff --git a/AsbCloudDb/Model/ProcessMapPlan/ProcessMapPlanBase.cs b/AsbCloudDb/Model/ProcessMapPlan/ProcessMapPlanBase.cs
index 47c45dd1..912ce7c0 100644
--- a/AsbCloudDb/Model/ProcessMapPlan/ProcessMapPlanBase.cs
+++ b/AsbCloudDb/Model/ProcessMapPlan/ProcessMapPlanBase.cs
@@ -20,12 +20,6 @@ public abstract class ProcessMapPlanBase : ChangeLogAbstract, IId, IWellRelated
[ForeignKey(nameof(IdWell))]
public virtual Well Well { get; set; } = null!;
- [ForeignKey(nameof(IdAuthor))]
- public virtual User Author { get; set; } = null!;
-
- [ForeignKey(nameof(IdEditor))]
- public virtual User? Editor { get; set; } = null!;
-
[ForeignKey(nameof(IdWellSectionType))]
public virtual WellSectionType WellSectionType { get; set; } = null!;
}
\ No newline at end of file
diff --git a/AsbCloudInfrastructure/DependencyInjection.cs b/AsbCloudInfrastructure/DependencyInjection.cs
index 713f5614..aa8b63dd 100644
--- a/AsbCloudInfrastructure/DependencyInjection.cs
+++ b/AsbCloudInfrastructure/DependencyInjection.cs
@@ -1,22 +1,22 @@
using AsbCloudApp.Data;
using AsbCloudApp.Data.DailyReport.Blocks.TimeBalance;
+using AsbCloudApp.Data.DetectedOperation;
using AsbCloudApp.Data.DrillTestReport;
using AsbCloudApp.Data.Manuals;
using AsbCloudApp.Data.ProcessMaps;
using AsbCloudApp.Data.SAUB;
using AsbCloudApp.Data.Subsystems;
using AsbCloudApp.Data.Trajectory;
-using AsbCloudApp.Data.WellOperationImport.Options;
using AsbCloudApp.Repositories;
using AsbCloudApp.Requests;
using AsbCloudApp.Services;
using AsbCloudApp.Services.DailyReport;
using AsbCloudApp.Services.Notifications;
-using AsbCloudApp.Services.ProcessMaps;
using AsbCloudApp.Services.ProcessMaps.WellDrilling;
using AsbCloudDb.Model;
using AsbCloudDb.Model.DailyReports.Blocks.TimeBalance;
using AsbCloudDb.Model.Manuals;
+using AsbCloudDb.Model.ProcessMapPlan;
using AsbCloudDb.Model.ProcessMaps;
using AsbCloudDb.Model.Trajectory;
using AsbCloudDb.Model.WellSections;
@@ -27,14 +27,15 @@ using AsbCloudInfrastructure.Services.DailyReport;
using AsbCloudInfrastructure.Services.DetectOperations;
using AsbCloudInfrastructure.Services.DrillingProgram;
using AsbCloudInfrastructure.Services.DrillTestReport;
+using AsbCloudInfrastructure.Services.ProcessMapPlan.Export;
using AsbCloudInfrastructure.Services.ProcessMapPlan.Parser;
-using AsbCloudInfrastructure.Services.ProcessMaps;
using AsbCloudInfrastructure.Services.ProcessMaps.Report;
using AsbCloudInfrastructure.Services.SAUB;
using AsbCloudInfrastructure.Services.Subsystems;
using AsbCloudInfrastructure.Services.Trajectory;
using AsbCloudInfrastructure.Services.Trajectory.Export;
using AsbCloudInfrastructure.Services.Trajectory.Parser;
+using AsbCloudInfrastructure.Services.WellOperations.Factories;
using AsbCloudInfrastructure.Services.WellOperationService;
using Mapster;
using Microsoft.EntityFrameworkCore;
@@ -42,9 +43,6 @@ using Microsoft.Extensions.Caching.Memory;
using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.DependencyInjection;
using System;
-using AsbCloudApp.Data.DetectedOperation;
-using AsbCloudInfrastructure.Services.ProcessMapPlan.Export;
-using AsbCloudInfrastructure.Services.WellOperations.Factories;
namespace AsbCloudInfrastructure
{
@@ -56,15 +54,21 @@ namespace AsbCloudInfrastructure
.ForType()
.Ignore(source => source.Author)
.Ignore(source => source.Well);
-
+
TypeAdapterConfig.GlobalSettings.Default.Config
.ForType()
.Ignore(source => source.OperationCategory);
-
+
TypeAdapterConfig.GlobalSettings.Default.Config
.ForType()
.Ignore(source => source.Driller);
-
+
+#pragma warning disable CS8603 // Possible null reference return.
+ TypeAdapterConfig.GlobalSettings.Default.Config
+ .ForType()
+ .Ignore(dst => dst.Author, dst => dst.Editor);
+#pragma warning restore CS8603 // Possible null reference return.
+
TypeAdapterConfig.GlobalSettings.Default.Config
.ForType()
.MapWith((source) => source.DateTime);
@@ -127,6 +131,13 @@ namespace AsbCloudInfrastructure
{
Plan = src.WellDepthPlan
});
+
+ TypeAdapterConfig>.NewConfig()
+ .Include>()
+ .Map(dest => dest, src => new ChangeLogDto()
+ {
+ Item = src.Adapt()
+ });
}
public static IServiceCollection AddInfrastructure(this IServiceCollection services, IConfiguration configuration)
@@ -186,11 +197,11 @@ namespace AsbCloudInfrastructure
services.AddTransient<
IChangeLogRepository,
- ProcessMapPlanBaseRepository>();
+ ProcessMapPlanBaseRepository>();
services.AddTransient<
IChangeLogRepository,
- ProcessMapPlanBaseRepository>();
+ ProcessMapPlanBaseRepository>();
services.AddTransient();
@@ -293,7 +304,7 @@ namespace AsbCloudInfrastructure
services.AddTransient();
services.AddTransient();
services.AddTransient();
-
+
services.AddTransient();
services.AddTransient();
services.AddTransient();
@@ -303,7 +314,7 @@ namespace AsbCloudInfrastructure
services.AddTransient();
services.AddTransient();
-
+
return services;
}
}
diff --git a/AsbCloudInfrastructure/Repository/ChangeLogRepositoryAbstract.cs b/AsbCloudInfrastructure/Repository/ChangeLogRepositoryAbstract.cs
index 7a01f7df..054453e6 100644
--- a/AsbCloudInfrastructure/Repository/ChangeLogRepositoryAbstract.cs
+++ b/AsbCloudInfrastructure/Repository/ChangeLogRepositoryAbstract.cs
@@ -1,4 +1,5 @@
-using AsbCloudApp.Exceptions;
+using AsbCloudApp.Data;
+using AsbCloudApp.Exceptions;
using AsbCloudApp.Repositories;
using AsbCloudApp.Requests;
using AsbCloudDb.Model;
@@ -13,10 +14,9 @@ using System.Threading.Tasks;
namespace AsbCloudInfrastructure.Repository;
-public abstract class ChangeLogRepositoryAbstract : IChangeLogRepository
- where TDto : AsbCloudApp.Data.ChangeLogAbstract
+public abstract class ChangeLogRepositoryAbstract : IChangeLogRepository
+ where TDto : AsbCloudApp.Data.IId
where TEntity : ChangeLogAbstract
- where TRequest : ChangeLogBaseRequest
{
protected readonly IAsbCloudDbContext db;
@@ -25,6 +25,97 @@ public abstract class ChangeLogRepositoryAbstract : ICh
this.db = db;
}
+ private class ChangeLogQueryBuilder: IChangeLogQueryBuilder
+ {
+ protected readonly ChangeLogRepositoryAbstract Repository;
+ protected IQueryable Query;
+
+ public ChangeLogQueryBuilder(
+ ChangeLogRepositoryAbstract repository,
+ ChangeLogRequest request)
+ {
+ this.Repository = repository;
+ this.Query = repository.db.Set()
+ .Include(e => e.Author)
+ .Include(e => e.Editor);
+
+ if (request.Moment.HasValue)
+ {
+ var momentUtc = request.Moment.Value.ToUniversalTime();
+
+ this.Query = this.Query
+ .Where(e => e.Creation <= momentUtc)
+ .Where(e => e.Obsolete == null || e.Obsolete >= momentUtc);
+ }
+ }
+
+ public ChangeLogQueryBuilder(ChangeLogQueryBuilder builder)
+ {
+ Repository = builder.Repository;
+ Query = builder.Query;
+ }
+
+ public virtual IChangeLogQueryBuilderWithKnownTimezone ApplyRequest(TRequest request)
+ {
+ this.Query = Repository.BuildQuery(request, Query);
+ return new ChangeLogQueryBuilderWithKnownTimezone(this, request);
+ }
+
+ public async Task> GetData(TimeSpan offset, CancellationToken token)
+ {
+ var dtos = await this.Query.Select(e => Repository.Convert(e, offset))
+ .ToArrayAsync(token);
+ return dtos;
+ }
+
+ public async Task>> GetChangeLogData(TimeSpan offset, CancellationToken token)
+ {
+ var dtos = await this.Query.Select(e => Repository.ConvertChangeLogDto(e, offset))
+ .ToArrayAsync(token);
+ return dtos;
+ }
+ }
+
+ private class ChangeLogQueryBuilderWithKnownTimezone: ChangeLogQueryBuilder, IChangeLogQueryBuilderWithKnownTimezone
+ {
+ TRequest request;
+
+ public ChangeLogQueryBuilderWithKnownTimezone(
+ ChangeLogQueryBuilder parentBuilder,
+ TRequest request)
+ :base(parentBuilder)
+ {
+ this.request = request;
+ }
+
+ public override IChangeLogQueryBuilderWithKnownTimezone ApplyRequest(TRequest request)
+ {
+ Query = Repository.BuildQuery(request, Query);
+ this.request = request;
+ return this;
+ }
+
+ public async Task> GetData(CancellationToken token)
+ {
+ TimeSpan timezoneOffset = Repository.GetTimezoneOffset(request);
+ var dtos = await this.GetData(timezoneOffset, token);
+ return dtos;
+ }
+
+ public async Task>> GetChangeLogData(CancellationToken token)
+ {
+ TimeSpan timezoneOffset = Repository.GetTimezoneOffset(request);
+ var dtos = await this.GetChangeLogData(timezoneOffset, token);
+ return dtos;
+ }
+ }
+
+ public IChangeLogQueryBuilder GetQueryBuilder(ChangeLogRequest request)
+ {
+ var builder = new ChangeLogQueryBuilder(this, request);
+ return builder;
+ }
+
public async Task InsertRange(int idUser, IEnumerable dtos, CancellationToken token)
{
var result = 0;
@@ -133,6 +224,7 @@ public abstract class ChangeLogRepositoryAbstract : ICh
public async Task Clear(int idUser, TRequest request, CancellationToken token)
{
var updateTime = DateTimeOffset.UtcNow;
+
var query = BuildQuery(request);
query = query.Where(e => e.Obsolete == null);
@@ -168,7 +260,7 @@ public abstract class ChangeLogRepositoryAbstract : ICh
}
}
- public async Task DeleteRange(int idUser, IEnumerable ids, CancellationToken token)
+ public async Task MarkAsDeleted(int idUser, IEnumerable ids, CancellationToken token)
{
var updateTime = DateTimeOffset.UtcNow;
var query = db.Set()
@@ -217,7 +309,7 @@ public abstract class ChangeLogRepositoryAbstract : ICh
return datesOnly;
}
- public async Task> GetChangeLog(TRequest request, DateOnly? date, CancellationToken token)
+ public async Task>> GetChangeLogForDate(TRequest request, DateOnly? date, CancellationToken token)
{
var query = BuildQuery(request);
TimeSpan offset = GetTimezoneOffset(request);
@@ -233,53 +325,72 @@ public abstract class ChangeLogRepositoryAbstract : ICh
query = createdQuery.Union(editedQuery);
}
+ var dtos = await CreateChangeLogDto(query, offset, token);
+
+ return dtos;
+ }
+
+ public async Task>> CreateChangeLogDto(IQueryable query, TimeSpan offset, CancellationToken token)
+ {
var entities = await query
.OrderBy(e => e.Creation)
.ThenBy(e => e.Obsolete)
.ThenBy(e => e.Id)
.ToListAsync(token);
- var dtos = entities.Select(e => Convert(e, offset));
+ var dtos = entities.Select(e => ConvertChangeLogDto(e, offset));
return dtos;
}
- public async Task> Get(TRequest request, CancellationToken token)
+ public async Task> GetCurrent(TRequest request, CancellationToken token)
{
- var query = BuildQuery(request);
- var entities = await query
- .OrderBy(e => e.Creation)
- .ThenBy(e => e.Obsolete)
- .ThenBy(e => e.Id)
- .ToArrayAsync(token);
+ var changeLogRequest = new ChangeLogRequest()
+ {
+ Moment = new DateTimeOffset(3000, 1, 1, 0, 0, 0, TimeSpan.Zero)
+ };
+
+ var builder = GetQueryBuilder(changeLogRequest)
+ .ApplyRequest(request);
+ var dtos = await builder.GetData(token);
- TimeSpan offset = GetTimezoneOffset(request);
- var dtos = entities.Select(e => Convert(e, offset));
return dtos;
}
protected abstract TimeSpan GetTimezoneOffset(TRequest request);
- protected abstract IQueryable BuildQuery(TRequest request);
+ private IQueryable BuildQuery(TRequest request) =>
+ BuildQuery(request, db.Set()
+ .Include(e => e.Author)
+ .Include(e => e.Editor));
+
+ protected abstract IQueryable BuildQuery(TRequest request, IQueryable query);
protected virtual TEntity Convert(TDto dto)
{
var entity = dto.Adapt();
entity.Creation = entity.Creation.ToUniversalTime();
- if(entity.Obsolete.HasValue)
+ if (entity.Obsolete.HasValue)
entity.Obsolete = entity.Obsolete.Value.ToUniversalTime();
return entity;
}
+ protected virtual ChangeLogDto ConvertChangeLogDto(TEntity entity, TimeSpan offset)
+ {
+ var changeLogDto = entity.Adapt>();
+ changeLogDto.Creation = entity.Creation.ToOffset(offset);
+
+ if (entity.Obsolete.HasValue)
+ changeLogDto.Obsolete = entity.Obsolete.Value.ToOffset(offset);
+
+ changeLogDto.Item = Convert(entity, offset);
+ return changeLogDto;
+ }
+
protected virtual TDto Convert(TEntity entity, TimeSpan offset)
{
var dto = entity.Adapt();
- dto.Creation = entity.Creation.ToOffset(offset);
-
- if (entity.Obsolete.HasValue)
- dto.Obsolete = entity.Obsolete.Value.ToOffset(offset);
-
return dto;
}
@@ -303,4 +414,5 @@ public abstract class ChangeLogRepositoryAbstract : ICh
if (pgException.SqlState == PostgresErrorCodes.ForeignKeyViolation)
throw new ArgumentInvalidException("dtos", pgException.Message + "\r\n" + pgException.Detail);
}
+
}
diff --git a/AsbCloudInfrastructure/Repository/ProcessMapPlanBaseRepository.cs b/AsbCloudInfrastructure/Repository/ProcessMapPlanBaseRepository.cs
index b8662d35..26d58c40 100644
--- a/AsbCloudInfrastructure/Repository/ProcessMapPlanBaseRepository.cs
+++ b/AsbCloudInfrastructure/Repository/ProcessMapPlanBaseRepository.cs
@@ -9,45 +9,31 @@ using System.Linq;
namespace AsbCloudInfrastructure.Repository;
-public class ProcessMapPlanBaseRepository : ChangeLogRepositoryAbstract
+public class ProcessMapPlanBaseRepository : ChangeLogRepositoryAbstract
where TDto : ProcessMapPlanBaseDto
where TEntity : ProcessMapPlanBase
{
private readonly IWellService wellService;
- public ProcessMapPlanBaseRepository(IAsbCloudDbContext context, IWellService wellService)
+ public ProcessMapPlanBaseRepository(IAsbCloudDbContext context, IWellService wellService)
: base(context)
{
this.wellService = wellService;
}
- protected override IQueryable BuildQuery(ProcessMapPlanBaseRequestWithWell request)
+ protected override IQueryable BuildQuery(ProcessMapPlanBaseRequestWithWell request, IQueryable query)
{
- var query = db
- .Set()
- .Include(e => e.Author)
- .Include(e => e.Editor)
+ query = query
.Include(e => e.Well)
.Include(e => e.WellSectionType)
.Where(e => e.IdWell == request.IdWell);
- if (request.IdWellSectionType.HasValue)
- query = query.Where(e => e.IdWellSectionType == request.IdWellSectionType);
-
if (request.UpdateFrom.HasValue)
{
var from = request.UpdateFrom.Value.ToUniversalTime();
query = query.Where(e => e.Creation >= from || e.Obsolete >= from);
}
- if (request.Moment.HasValue)
- {
- var moment = request.Moment.Value.ToUniversalTime();
- query = query
- .Where(e => e.Creation <= moment)
- .Where(e => e.Obsolete == null || e.Obsolete >= moment);
- }
-
return query;
}
@@ -68,8 +54,6 @@ public class ProcessMapPlanBaseRepository : ChangeLogRepositoryAb
protected override TEntity Convert(TDto dto)
{
var entity = base.Convert(dto);
- entity.Author = null;
- entity.Editor = null;
return entity;
}
}
diff --git a/AsbCloudInfrastructure/Repository/WellCompositeRepository.cs b/AsbCloudInfrastructure/Repository/WellCompositeRepository.cs
index b4c3bae9..15ba5883 100644
--- a/AsbCloudInfrastructure/Repository/WellCompositeRepository.cs
+++ b/AsbCloudInfrastructure/Repository/WellCompositeRepository.cs
@@ -19,7 +19,7 @@ public class WellCompositeRepository : IWellCompositeRepository
private readonly IChangeLogRepository processMapPlanDrillingRepository;
public WellCompositeRepository(
- IAsbCloudDbContext db,
+ IAsbCloudDbContext db,
IChangeLogRepository processMapPlanDrillingRepository)
{
this.db = db;
@@ -51,17 +51,9 @@ public class WellCompositeRepository : IWellCompositeRepository
}
///
- public async Task> GetCompositeProcessMap(int idWell, CancellationToken token)
+ public Task> GetCompositeProcessMap(int idWell, CancellationToken token)
{
- var dtos = await GetAsync(idWell, token);
-
- var requests = dtos.Select(x => new ProcessMapPlanRequest {
- IdWell = x.IdWellSrc,
- IdWellSectionType = x.IdWellSectionType
- });
-
- //var result = await processMapPlanDrillingRepository.GetAsync(requests, token);
- return Enumerable.Empty();
+ throw new NotImplementedException();
}
private static WellComposite Convert(int idWell, WellCompositeDto dto)
diff --git a/AsbCloudInfrastructure/Services/DetectOperations/WorkOperationDetection.cs b/AsbCloudInfrastructure/Services/DetectOperations/WorkOperationDetection.cs
index d001471e..8a96f26c 100644
--- a/AsbCloudInfrastructure/Services/DetectOperations/WorkOperationDetection.cs
+++ b/AsbCloudInfrastructure/Services/DetectOperations/WorkOperationDetection.cs
@@ -43,7 +43,7 @@ public class WorkOperationDetection: Work
var telemetryId = telemetryIds[i];
var beginDate = lastDetectedDates.TryGetValue(telemetryId, out var date) ? date : (DateTimeOffset?)null;
-
+
onProgressCallback($"Start detecting telemetry: {telemetryId} from {beginDate}", i / telemetryIds.Length);
var detectedOperations = await detectedOperationService.DetectOperationsAsync(telemetryId, beginDate, token);
diff --git a/AsbCloudInfrastructure/Services/ProcessMapPlan/Export/ProcessMapPlanExportService.cs b/AsbCloudInfrastructure/Services/ProcessMapPlan/Export/ProcessMapPlanExportService.cs
index 07cc6a13..2b4de002 100644
--- a/AsbCloudInfrastructure/Services/ProcessMapPlan/Export/ProcessMapPlanExportService.cs
+++ b/AsbCloudInfrastructure/Services/ProcessMapPlan/Export/ProcessMapPlanExportService.cs
@@ -1,38 +1,34 @@
-using System;
-using System.Collections.Generic;
-using System.Threading;
-using System.Threading.Tasks;
-using AsbCloudApp.Data;
+using AsbCloudApp.Data.ProcessMaps;
using AsbCloudApp.Repositories;
using AsbCloudApp.Requests;
using AsbCloudApp.Requests.ExportOptions;
using AsbCloudApp.Services;
using AsbCloudInfrastructure.Services.ExcelServices;
+using System.Collections.Generic;
+using System.Threading;
+using System.Threading.Tasks;
namespace AsbCloudInfrastructure.Services.ProcessMapPlan.Export;
public abstract class ProcessMapPlanExportService : ExportExcelService
- where TDto : ChangeLogAbstract
+ where TDto : ProcessMapPlanBaseDto
{
- protected readonly IWellService wellService;
+ protected readonly IWellService wellService;
- private readonly IChangeLogRepository processMapPlanRepository;
+ private readonly IChangeLogRepository processMapPlanRepository;
- protected ProcessMapPlanExportService(IChangeLogRepository processMapPlanRepository,
- IWellService wellService)
- {
- this.processMapPlanRepository = processMapPlanRepository;
- this.wellService = wellService;
- }
-
- protected override async Task> GetDtosAsync(WellRelatedExportRequest options, CancellationToken token)
- {
- var request = new ProcessMapPlanBaseRequestWithWell(options.IdWell)
- {
- Moment = DateTimeOffset.UtcNow
- };
-
- var dtos = await processMapPlanRepository.Get(request, token);
- return dtos;
- }
+ protected ProcessMapPlanExportService(IChangeLogRepository processMapPlanRepository,
+ IWellService wellService)
+ {
+ this.processMapPlanRepository = processMapPlanRepository;
+ this.wellService = wellService;
+ }
+
+ protected override async Task> GetDtosAsync(WellRelatedExportRequest options, CancellationToken token)
+ {
+ var request = new ProcessMapPlanBaseRequestWithWell(options.IdWell);
+
+ var dtos = await processMapPlanRepository.GetCurrent(request, token);
+ return dtos;
+ }
}
\ No newline at end of file
diff --git a/AsbCloudInfrastructure/Services/ProcessMapPlan/Export/ProcessMapPlanReamExportService.cs b/AsbCloudInfrastructure/Services/ProcessMapPlan/Export/ProcessMapPlanReamExportService.cs
index c3dc5d69..c6b8495e 100644
--- a/AsbCloudInfrastructure/Services/ProcessMapPlan/Export/ProcessMapPlanReamExportService.cs
+++ b/AsbCloudInfrastructure/Services/ProcessMapPlan/Export/ProcessMapPlanReamExportService.cs
@@ -1,5 +1,3 @@
-using System.Threading;
-using System.Threading.Tasks;
using AsbCloudApp.Data.ProcessMaps;
using AsbCloudApp.Repositories;
using AsbCloudApp.Requests;
@@ -7,24 +5,26 @@ using AsbCloudApp.Requests.ExportOptions;
using AsbCloudApp.Services;
using AsbCloudInfrastructure.Services.ExcelServices.Templates;
using AsbCloudInfrastructure.Services.ExcelServices.Templates.ProcessMapPlanTemplates;
+using System.Threading;
+using System.Threading.Tasks;
namespace AsbCloudInfrastructure.Services.ProcessMapPlan.Export;
public class ProcessMapPlanReamExportService : ProcessMapPlanExportService
{
- protected override ITemplateParameters TemplateParameters => new ProcessMapPlanReamTemplate();
+ protected override ITemplateParameters TemplateParameters => new ProcessMapPlanReamTemplate();
- public ProcessMapPlanReamExportService(
- IChangeLogRepository processMapPlanRepository,
- IWellService wellService)
- : base(processMapPlanRepository, wellService)
- {
- }
-
- protected override async Task BuildFileNameAsync(WellRelatedExportRequest options, CancellationToken token)
- {
- var caption = await wellService.GetWellCaptionByIdAsync(options.IdWell, token);
+ public ProcessMapPlanReamExportService(
+ IChangeLogRepository processMapPlanRepository,
+ IWellService wellService)
+ : base(processMapPlanRepository, wellService)
+ {
+ }
- return $"{caption}_РТК_План_проработка.xlsx";
- }
+ protected override async Task BuildFileNameAsync(WellRelatedExportRequest options, CancellationToken token)
+ {
+ var caption = await wellService.GetWellCaptionByIdAsync(options.IdWell, token);
+
+ return $"{caption}_РТК_План_проработка.xlsx";
+ }
}
\ No newline at end of file
diff --git a/AsbCloudInfrastructure/Services/ProcessMaps/Report/ProcessMapReportDrillingService.cs b/AsbCloudInfrastructure/Services/ProcessMaps/Report/ProcessMapReportDrillingService.cs
index 313f76e7..18345122 100644
--- a/AsbCloudInfrastructure/Services/ProcessMaps/Report/ProcessMapReportDrillingService.cs
+++ b/AsbCloudInfrastructure/Services/ProcessMaps/Report/ProcessMapReportDrillingService.cs
@@ -1,6 +1,7 @@
using AsbCloudApp.Data;
using AsbCloudApp.Data.ProcessMaps;
using AsbCloudApp.Data.ProcessMaps.Report;
+using AsbCloudApp.Data.WellOperation;
using AsbCloudApp.Exceptions;
using AsbCloudApp.Extensions;
using AsbCloudApp.Repositories;
@@ -13,7 +14,6 @@ using System.Collections.Generic;
using System.Linq;
using System.Threading;
using System.Threading.Tasks;
-using AsbCloudApp.Data.WellOperation;
namespace AsbCloudInfrastructure.Services.ProcessMaps.Report;
@@ -48,13 +48,13 @@ public class ProcessMapReportDrillingService : IProcessMapReportDrillingService
return Enumerable.Empty();
var requestProcessMapPlan = new ProcessMapPlanBaseRequestWithWell(idWell);
- var processMapPlanWellDrillings = await processMapPlanBaseRepository.Get(requestProcessMapPlan, token);
+ var changeLogProcessMaps = await processMapPlanBaseRepository.GetChangeLogForDate(requestProcessMapPlan, null, token);
- if (!processMapPlanWellDrillings.Any())
+ if (!changeLogProcessMaps.Any())
return Enumerable.Empty();
- var geDepth = processMapPlanWellDrillings.Min(p => p.DepthStart);
- var leDepth = processMapPlanWellDrillings.Max(p => p.DepthEnd);
+ var geDepth = changeLogProcessMaps.Min(p => p.Item.DepthStart);
+ var leDepth = changeLogProcessMaps.Max(p => p.Item.DepthEnd);
var requestWellOperationFact = new WellOperationRequest(new[] { idWell })
{
@@ -85,10 +85,10 @@ public class ProcessMapReportDrillingService : IProcessMapReportDrillingService
var wellSectionTypes = wellOperationRepository.GetSectionTypes();
var result = CalcByIntervals(
- request,
- processMapPlanWellDrillings,
+ request,
+ changeLogProcessMaps,
dataSaubStats,
- orderedWellOperations,
+ orderedWellOperations,
wellOperationCategories,
wellSectionTypes);
@@ -97,7 +97,7 @@ public class ProcessMapReportDrillingService : IProcessMapReportDrillingService
private static IEnumerable CalcByIntervals(
DataSaubStatRequest request,
- IEnumerable processMapPlanWellDrillings,
+ IEnumerable> changeLogProcessMaps,
Span dataSaubStats,
IEnumerable wellOperations,
IEnumerable wellOperationCategories,
@@ -115,23 +115,24 @@ public class ProcessMapReportDrillingService : IProcessMapReportDrillingService
int GetSection(DataSaubStatDto data)
{
- if(lastFoundIndex < orderedWellOperations.Length - 1)
+ if (lastFoundIndex < orderedWellOperations.Length - 1)
{
lastFoundIndex = Array.FindIndex(orderedWellOperations, lastFoundIndex, o => o.DateStart > data.DateStart) - 1;
lastFoundIndex = lastFoundIndex < 0 ? orderedWellOperations.Length - 1 : lastFoundIndex;
}
-
+
var operation = orderedWellOperations[lastFoundIndex];
return operation.IdWellSectionType;
- }
+ }
- ProcessMapPlanDrillingDto? GetProcessMapPlan(int idWellSectionType, DataSaubStatDto data)
- => processMapPlanWellDrillings
- .Where(p => p.IdWellSectionType == idWellSectionType)
- .Where(p => p.DepthStart <= data.DepthStart)
- .Where(p => p.DepthEnd >= data.DepthStart)
- .Where(p => IsModeMatchOperationCategory(p.IdMode, data.IdCategory))
+ ProcessMapPlanDrillingDto? GetProcessMapPlan(int idWellSectionType, DataSaubStatDto data)
+ => changeLogProcessMaps
+ .Where(p => p.Item.IdWellSectionType == idWellSectionType)
+ .Where(p => p.Item.DepthStart <= data.DepthStart)
+ .Where(p => p.Item.DepthEnd >= data.DepthStart)
+ .Where(p => IsModeMatchOperationCategory(p.Item.IdMode, data.IdCategory))
.WhereActualAtMoment(data.DateStart)
+ .Select(p => p.Item)
.FirstOrDefault();
var idWellSectionType = GetSection(firstElemInInterval);
@@ -168,7 +169,7 @@ public class ProcessMapReportDrillingService : IProcessMapReportDrillingService
var elem = CalcStat(processMapPlan, span, wellOperationCategoryName, wellSectionType);
if (elem is not null)
- list.Add(elem);
+ list.Add(elem);
}
}
return list;
@@ -333,7 +334,7 @@ public class ProcessMapReportDrillingService : IProcessMapReportDrillingService
SetpointUsagePressure: sumDiffDepthByPressure * 100 / diffDepthTotal,
SetpointUsageAxialLoad: sumDiffDepthByAxialLoad * 100 / diffDepthTotal,
SetpointUsageRotorTorque: sumDiffDepthByRotorTorque * 100 / diffDepthTotal,
- SetpointUsageRopPlan: sumDiffDepthByRopPlan * 100/ diffDepthTotal,
+ SetpointUsageRopPlan: sumDiffDepthByRopPlan * 100 / diffDepthTotal,
DrilledTime: drilledTime
);
}
diff --git a/AsbCloudInfrastructure/Services/WellInfoService.cs b/AsbCloudInfrastructure/Services/WellInfoService.cs
index 9c407490..07bb6e39 100644
--- a/AsbCloudInfrastructure/Services/WellInfoService.cs
+++ b/AsbCloudInfrastructure/Services/WellInfoService.cs
@@ -43,14 +43,11 @@ public class WellInfoService
var wellsIds = activeWells.Select(w => w.Id);
- var processMapPlanWellDrillingRequests = wellsIds.Select(id => new ProcessMapPlanBaseRequestWithWell(id)
- {
- Moment = DateTimeOffset.UtcNow.AddDays(1)
- });
+ var processMapPlanWellDrillingRequests = wellsIds.Select(id => new ProcessMapPlanBaseRequestWithWell(id));
var processMapPlanWellDrillings = new List();
foreach (var processMapPlanWellDrillingRequest in processMapPlanWellDrillingRequests)
{
- var processMaps = await processMapPlanWellDrillingRepository.Get(processMapPlanWellDrillingRequest, token);
+ var processMaps = await processMapPlanWellDrillingRepository.GetCurrent(processMapPlanWellDrillingRequest, token);
processMapPlanWellDrillings.AddRange(processMaps);
}
@@ -100,14 +97,14 @@ public class WellInfoService
int? idSection = wellLastFactSection?.Id;
ProcessMapPlanDrillingDto? processMapPlanWellDrilling = null;
- if(idSection.HasValue && currentDepth.HasValue)
+ if (idSection.HasValue && currentDepth.HasValue)
{
processMapPlanWellDrilling = wellProcessMaps
.Where(p => p.IdWellSectionType == idSection)
.Where(p => p.DepthStart <= currentDepth.Value && p.DepthEnd >= currentDepth.Value)
.FirstOrDefault();
- }
- else if(currentDepth.HasValue)
+ }
+ else if (currentDepth.HasValue)
{
processMapPlanWellDrilling = wellProcessMaps.FirstOrDefault(p => p.DepthStart <= currentDepth.Value && p.DepthEnd >= currentDepth.Value);
}
diff --git a/AsbCloudInfrastructure/Startup.cs b/AsbCloudInfrastructure/Startup.cs
index 68c0d5b7..ab555c1c 100644
--- a/AsbCloudInfrastructure/Startup.cs
+++ b/AsbCloudInfrastructure/Startup.cs
@@ -31,10 +31,10 @@ namespace AsbCloudInfrastructure
var backgroundWorker = provider.GetRequiredService();
backgroundWorker.Add(TimeSpan.FromDays(1));
backgroundWorker.Add(TimeSpan.FromMinutes(30));
- backgroundWorker.Add(TimeSpan.FromMinutes(15));
- backgroundWorker.Add(TimeSpan.FromMinutes(15));
- backgroundWorker.Add(TimeSpan.FromMinutes(30));
- backgroundWorker.Add(MakeMemoryMonitoringWork(), TimeSpan.FromMinutes(1));
+ backgroundWorker.Add(TimeSpan.FromMinutes(0));
+ backgroundWorker.Add(TimeSpan.FromMinutes(0));
+ backgroundWorker.Add(TimeSpan.FromMinutes(0));
+ backgroundWorker.Add(MakeMemoryMonitoringWork(), TimeSpan.FromMinutes(0));
var notificationBackgroundWorker = provider.GetRequiredService();
}
diff --git a/AsbCloudWebApi.IntegrationTests/Clients/IProcessMapPlanDrillingClient.cs b/AsbCloudWebApi.IntegrationTests/Clients/IProcessMapPlanDrillingClient.cs
index 93ce768b..59e32900 100644
--- a/AsbCloudWebApi.IntegrationTests/Clients/IProcessMapPlanDrillingClient.cs
+++ b/AsbCloudWebApi.IntegrationTests/Clients/IProcessMapPlanDrillingClient.cs
@@ -5,15 +5,15 @@ using Refit;
namespace AsbCloudWebApi.IntegrationTests.Clients;
-public interface IProcessMapPlanDrillingClient
+public interface IProcessMapPlanDrillingClient where TDto : ProcessMapPlanBaseDto
{
private const string BaseRoute = "/api/well/{idWell}/ProcessMapPlanDrilling";
[Post(BaseRoute)]
- Task> InsertRange(int idWell, [Body] IEnumerable dtos);
+ Task> InsertRange(int idWell, [Body] IEnumerable dtos);
[Post($"{BaseRoute}/replace")]
- Task> ClearAndInsertRange(int idWell, [Body] IEnumerable dtos);
+ Task> ClearAndInsertRange(int idWell, [Body] IEnumerable dtos);
[Delete(BaseRoute)]
Task> DeleteRange(int idWell, [Body] IEnumerable ids);
@@ -22,18 +22,24 @@ public interface IProcessMapPlanDrillingClient
Task> Clear(int idWell);
[Get(BaseRoute)]
- Task>> Get(int idWell, ProcessMapPlanBaseRequest request);
+ Task>> Get(int idWell);
- [Get($"{BaseRoute}/changeLog")]
- Task>> GetChangeLog(int idWell, DateOnly? date);
+ [Get($"{BaseRoute}/changelogByMoment")]
+ Task>>> Get(int idWell, DateTimeOffset? moment);
+
+ [Get("/api/telemetry/{uid}/ProcessMapPlanDrilling")]
+ Task>>> Get(string uid, DateTimeOffset? updateFrom);
+
+ [Get($"{BaseRoute}/changeLogForDate")]
+ Task>> GetChangeLog(int idWell, DateOnly? date);
[Get($"{BaseRoute}/dates")]
Task>> GetDatesChange(int idWell);
[Put(BaseRoute)]
- Task> UpdateOrInsertRange(int idWell, IEnumerable dtos);
+ Task> UpdateOrInsertRange(int idWell, IEnumerable dtos);
[Multipart]
[Post(BaseRoute + "/parse")]
- Task>> Parse(int idWell, [AliasAs("file")] StreamPart stream);
+ Task>> Parse(int idWell, [AliasAs("file")] StreamPart stream);
}
diff --git a/AsbCloudWebApi.IntegrationTests/Controllers/ProcessMapPlan/ProcessMapPlanDrillingControllerTest.cs b/AsbCloudWebApi.IntegrationTests/Controllers/ProcessMapPlan/ProcessMapPlanDrillingControllerTest.cs
index 8199e785..a8c41977 100644
--- a/AsbCloudWebApi.IntegrationTests/Controllers/ProcessMapPlan/ProcessMapPlanDrillingControllerTest.cs
+++ b/AsbCloudWebApi.IntegrationTests/Controllers/ProcessMapPlan/ProcessMapPlanDrillingControllerTest.cs
@@ -12,20 +12,18 @@ using Xunit;
using AsbCloudApp.Data.ProcessMaps;
using AsbCloudDb.Model;
using AsbCloudApp.Data.User;
+using AsbCloudApp.Data;
namespace AsbCloudWebApi.IntegrationTests.Controllers.ProcessMapPlan;
-public class ProcessMapPlanDrillingControllerTest: BaseIntegrationTest
+public class ProcessMapPlanDrillingControllerTest : BaseIntegrationTest
{
private const int IdWell = 1;
-
- private readonly ProcessMapPlanDrillingDto dto = new (){
+
+ private readonly ProcessMapPlanDrillingDto dto = new()
+ {
Id = 0,
- Creation = new(),
- Obsolete = null,
- IdState = 0,
- IdPrevious = null,
-
+
IdWell = IdWell,
Section = "Кондуктор",
IdWellSectionType = 3,
@@ -48,7 +46,7 @@ public class ProcessMapPlanDrillingControllerTest: BaseIntegrationTest
UsageSpin = 14,
Comment = "это тестовая запись",
};
- private readonly ProcessMapPlanDrilling entity = new ()
+ private readonly ProcessMapPlanDrilling entity = new()
{
Id = 0,
IdAuthor = 1,
@@ -80,12 +78,12 @@ public class ProcessMapPlanDrillingControllerTest: BaseIntegrationTest
Comment = "это тестовая запись",
};
- private IProcessMapPlanDrillingClient client;
-
+ private IProcessMapPlanDrillingClient client;
+
public ProcessMapPlanDrillingControllerTest(WebAppFactoryFixture factory) : base(factory)
{
dbContext.CleanupDbSet();
- client = factory.GetAuthorizedHttpClient(string.Empty);
+ client = factory.GetAuthorizedHttpClient>(string.Empty);
}
[Fact]
@@ -96,7 +94,7 @@ public class ProcessMapPlanDrillingControllerTest: BaseIntegrationTest
//act
var response = await client.InsertRange(dto.IdWell, new[] { expected });
-
+
//assert
Assert.Equal(HttpStatusCode.OK, response.StatusCode);
Assert.Equal(1, response.Content);
@@ -110,17 +108,14 @@ public class ProcessMapPlanDrillingControllerTest: BaseIntegrationTest
Assert.NotNull(entity);
- var actual = entity.Adapt();
+ var actual = entity.Adapt>();
Assert.Equal(ProcessMapPlanBase.IdStateActual, actual.IdState);
var excludeProps = new[] {
nameof(ProcessMapPlanDrillingDto.Id),
- nameof(ProcessMapPlanDrillingDto.IdState),
- nameof(ProcessMapPlanDrillingDto.Author),
- nameof(ProcessMapPlanDrillingDto.Creation),
nameof(ProcessMapPlanDrillingDto.Section)
};
- MatchHelper.Match(expected, actual, excludeProps);
+ MatchHelper.Match(expected, actual.Item, excludeProps);
}
[Fact]
@@ -150,19 +145,19 @@ public class ProcessMapPlanDrillingControllerTest: BaseIntegrationTest
//assert
Assert.Equal(HttpStatusCode.BadRequest, response.StatusCode);
}
-
+
[Fact]
public async Task ClearAndInsertRange_returns_success()
{
// arrange
var dbset = dbContext.Set();
-
+
var entry = dbset.Add(entity);
dbContext.SaveChanges();
entry.State = EntityState.Detached;
var startTime = DateTimeOffset.UtcNow;
-
+
// act
var result = await client.ClearAndInsertRange(entity.IdWell, new ProcessMapPlanDrillingDto[] { dto });
@@ -221,7 +216,6 @@ public class ProcessMapPlanDrillingControllerTest: BaseIntegrationTest
dtoUpdate.TopDriveSpeedLimitMax++;
dtoUpdate.TopDriveTorquePlan++;
dtoUpdate.TopDriveTorqueLimitMax++;
- dtoUpdate.Author = user;
var dtoInsert = dtoUpdate.Adapt();
dtoInsert.Id = 0;
@@ -239,7 +233,6 @@ public class ProcessMapPlanDrillingControllerTest: BaseIntegrationTest
dtoInsert.TopDriveSpeedLimitMax++;
dtoInsert.TopDriveTorquePlan++;
dtoInsert.TopDriveTorqueLimitMax++;
- dtoInsert.Author = user;
// act
var result = await client.UpdateOrInsertRange(entity.IdWell, new ProcessMapPlanDrillingDto[] { dtoUpdate, dtoInsert });
@@ -283,13 +276,13 @@ public class ProcessMapPlanDrillingControllerTest: BaseIntegrationTest
{
//arrange
var dbset = dbContext.Set();
-
+
var entry = dbset.Add(entity);
dbContext.SaveChanges();
entry.State = EntityState.Detached;
var startTime = DateTimeOffset.UtcNow;
-
+
//act
var response = await client.DeleteRange(dto.IdWell, new[] { entry.Entity.Id });
@@ -346,7 +339,7 @@ public class ProcessMapPlanDrillingControllerTest: BaseIntegrationTest
{
//arrange
var dbset = dbContext.Set();
-
+
var entity2 = entity.Adapt();
entity2.Creation = entity.Creation.AddDays(1);
dbset.Add(entity);
@@ -367,40 +360,13 @@ public class ProcessMapPlanDrillingControllerTest: BaseIntegrationTest
Assert.Equal(2, response.Content.Count());
Assert.All(response.Content, d => dates.Contains(d));
}
-
- [Fact]
- public async Task Get_all_returns_success()
- {
- //arrange
- var dbset = dbContext.Set();
-
- dbset.Add(entity);
-
- var entityDeleted = entity.Adapt();
- entityDeleted.Creation = entity.Creation.AddDays(-1);
- entityDeleted.Obsolete = entity.Creation;
- entityDeleted.IdState = ProcessMapPlanBase.IdStateDeleted;
- entityDeleted.IdEditor = 1;
- dbset.Add(entityDeleted);
-
- dbContext.SaveChanges();
-
- //act
- var request = new ProcessMapPlanBaseRequest();
- var response = await client.Get(dto.IdWell, request);
-
- //assert
- Assert.Equal(HttpStatusCode.OK, response.StatusCode);
- Assert.NotNull(response.Content);
- Assert.Equal(2, response.Content.Count());
- }
[Fact]
public async Task Get_actual_returns_success()
{
//arrange
var dbset = dbContext.Set();
-
+
dbset.Add(entity);
var entityDeleted = entity.Adapt();
@@ -413,11 +379,7 @@ public class ProcessMapPlanDrillingControllerTest: BaseIntegrationTest
dbContext.SaveChanges();
- //act
- var request = new ProcessMapPlanBaseRequest {
- Moment = new DateTimeOffset(3000, 1, 1, 0, 0, 0, 0, TimeSpan.Zero)
- };
- var response = await client.Get(dto.IdWell, request);
+ var response = await client.Get(dto.IdWell);
//assert
Assert.Equal(HttpStatusCode.OK, response.StatusCode);
@@ -425,12 +387,12 @@ public class ProcessMapPlanDrillingControllerTest: BaseIntegrationTest
Assert.Single(response.Content);
var actual = response.Content.First()!;
-
+ Assert.NotNull(actual.Section);
+ Assert.NotEmpty(actual.Section);
+
var expected = entity.Adapt()!;
var excludeProps = new[] {
nameof(ProcessMapPlanDrillingDto.Id),
- nameof(ProcessMapPlanDrillingDto.Author),
- nameof(ProcessMapPlanDrillingDto.Creation),
};
MatchHelper.Match(expected, actual, excludeProps);
}
@@ -440,7 +402,7 @@ public class ProcessMapPlanDrillingControllerTest: BaseIntegrationTest
{
//arrange
var dbset = dbContext.Set();
-
+
var now = DateTimeOffset.UtcNow;
var entityDeleted = entity.Adapt();
entityDeleted.Creation = now;
@@ -461,11 +423,7 @@ public class ProcessMapPlanDrillingControllerTest: BaseIntegrationTest
dbContext.SaveChanges();
//act
- var request = new ProcessMapPlanBaseRequest
- {
- Moment = now.AddMinutes(0.5),
- };
- var response = await client.Get(dto.IdWell, request);
+ var response = await client.Get(dto.IdWell, now.AddMinutes(0.5));
//assert
Assert.Equal(HttpStatusCode.OK, response.StatusCode);
@@ -474,49 +432,33 @@ public class ProcessMapPlanDrillingControllerTest: BaseIntegrationTest
}
[Fact]
- public async Task Get_section_returns_success()
+ public async Task Get_by_updated_from_returns_success()
{
//arrange
var dbset = dbContext.Set();
-
dbset.Add(entity);
var entity2 = entity.Adapt();
- entity2.IdWellSectionType = 2;
- entity2.Comment = "IdWellSectionType = 2";
+ entity2.Obsolete = DateTimeOffset.UtcNow;
dbset.Add(entity2);
dbContext.SaveChanges();
//act
- var request = new ProcessMapPlanBaseRequest
- {
- IdWellSectionType = 2,
- };
- var response = await client.Get(dto.IdWell, request);
+ var response = await client.Get(Defaults.RemoteUid, DateTimeOffset.UtcNow.AddHours(-1));
//assert
Assert.Equal(HttpStatusCode.OK, response.StatusCode);
Assert.NotNull(response.Content);
- Assert.Single(response.Content);
-
- var actual = response.Content.First()!;
-
- var expected = entity2.Adapt()!;
- var excludeProps = new[] {
- nameof(ProcessMapPlanDrillingDto.Id),
- nameof(ProcessMapPlanDrillingDto.Author),
- nameof(ProcessMapPlanDrillingDto.Creation),
- };
- MatchHelper.Match(expected, actual, excludeProps);
+ Assert.Equal(2, response.Content.Count());
}
-
+
[Fact]
public async Task Get_updated_returns_success()
{
//arrange
var dbset = dbContext.Set();
-
+
dbset.Add(entity);
var entity2 = entity.Adapt();
@@ -540,7 +482,7 @@ public class ProcessMapPlanDrillingControllerTest: BaseIntegrationTest
{
UpdateFrom = updateFrom,
};
- var response = await client.Get(dto.IdWell, request);
+ var response = await client.Get(dto.IdWell);
//assert
Assert.Equal(HttpStatusCode.OK, response.StatusCode);
@@ -553,8 +495,6 @@ public class ProcessMapPlanDrillingControllerTest: BaseIntegrationTest
var expected = entity2.Adapt();
var excludeProps = new[] {
nameof(ProcessMapPlanDrillingDto.Id),
- nameof(ProcessMapPlanDrillingDto.Author),
- nameof(ProcessMapPlanDrillingDto.Creation),
};
MatchHelper.Match(expected, actual, excludeProps);
}
@@ -567,19 +507,19 @@ public class ProcessMapPlanDrillingControllerTest: BaseIntegrationTest
var stream = Assembly.GetExecutingAssembly().GetFileCopyStream(fileName);
var streamPart = new StreamPart(stream, fileName, "application/octet-stream");
-
+
//act
var response = await client.Parse(IdWell, streamPart);
-
+
//assert
Assert.Equal(HttpStatusCode.OK, response.StatusCode);
var parserResult = response.Content;
-
+
Assert.NotNull(parserResult);
Assert.Single(parserResult.Item);
Assert.True(parserResult.IsValid);
-
+
var row = parserResult.Item.First();
var dtoActual = row.Item;
@@ -595,23 +535,23 @@ public class ProcessMapPlanDrillingControllerTest: BaseIntegrationTest
//arrange
const string fileName = "ProcessMapPlanDrillingInvalid.xlsx";
var stream = Assembly.GetExecutingAssembly().GetFileCopyStream(fileName);
-
+
var streamPart = new StreamPart(stream, fileName, "application/octet-stream");
-
+
//act
var response = await client.Parse(IdWell, streamPart);
-
+
Assert.Equal(HttpStatusCode.OK, response.StatusCode);
-
+
var parserResult = response.Content;
-
+
Assert.NotNull(parserResult);
Assert.False(parserResult.IsValid);
Assert.Single(parserResult.Warnings);
Assert.Single(parserResult.Item);
-
+
var row = parserResult.Item.First();
-
+
Assert.False(row.IsValid);
Assert.Equal(2, row.Warnings.Count());
}
diff --git a/AsbCloudWebApi.IntegrationTests/Data/Defaults.cs b/AsbCloudWebApi.IntegrationTests/Data/Defaults.cs
index a3667662..c7d75880 100644
--- a/AsbCloudWebApi.IntegrationTests/Data/Defaults.cs
+++ b/AsbCloudWebApi.IntegrationTests/Data/Defaults.cs
@@ -11,6 +11,8 @@ namespace AsbCloudWebApi.IntegrationTests.Data
Hours = 1
};
+ public const string RemoteUid = "555-555-555";
+
public static Deposit[] Deposits => new Deposit[]
{
new()
@@ -39,7 +41,7 @@ namespace AsbCloudWebApi.IntegrationTests.Data
Timezone = Timezone,
Telemetry = new Telemetry
{
- RemoteUid = "555-555-555",
+ RemoteUid = RemoteUid,
TimeZone = Timezone
},
RelationCompaniesWells = new RelationCompanyWell[]
diff --git a/AsbCloudWebApi.Tests/Services/ProcessMaps/ProcessMapReportDataSaubStatServiceTest.cs b/AsbCloudWebApi.Tests/Services/ProcessMaps/ProcessMapReportDataSaubStatServiceTest.cs
index a5cba844..2e0f24c8 100644
--- a/AsbCloudWebApi.Tests/Services/ProcessMaps/ProcessMapReportDataSaubStatServiceTest.cs
+++ b/AsbCloudWebApi.Tests/Services/ProcessMaps/ProcessMapReportDataSaubStatServiceTest.cs
@@ -1,21 +1,17 @@
-using System;
-using System.Collections.Generic;
-using System.Linq;
-using System.Threading;
-using System.Threading.Tasks;
-using AsbCloudApp.Data;
+using AsbCloudApp.Data;
using AsbCloudApp.Data.ProcessMaps;
using AsbCloudApp.Data.WellOperation;
using AsbCloudApp.Repositories;
using AsbCloudApp.Requests;
using AsbCloudApp.Services;
using AsbCloudDb.Model;
-using AsbCloudInfrastructure.Repository;
-using AsbCloudInfrastructure.Services.ProcessMaps;
using AsbCloudInfrastructure.Services.ProcessMaps.Report;
-using DocumentFormat.OpenXml.Bibliography;
-using DocumentFormat.OpenXml.Spreadsheet;
using NSubstitute;
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Threading;
+using System.Threading.Tasks;
using Xunit;
namespace AsbCloudWebApi.Tests.Services.ProcessMaps;
@@ -24,27 +20,27 @@ public class ProcessMapReportDataSaubStatServiceTest
{
- private IWellService wellService
+ private IWellService wellService
= Substitute.For();
- private IChangeLogRepository processMapPlanBaseRepository
+ private IChangeLogRepository processMapPlanBaseRepository
= Substitute.For>();
- private IWellOperationRepository wellOperationRepository
+ private IWellOperationRepository wellOperationRepository
= Substitute.For();
- private IWellOperationCategoryRepository wellOperationCategoryRepository
+ private IWellOperationCategoryRepository wellOperationCategoryRepository
= Substitute.For();
- private IDataSaubStatRepository dataSaubStatRepository
+ private IDataSaubStatRepository dataSaubStatRepository
= Substitute.For();
private ProcessMapReportDrillingService service;
private readonly static SimpleTimezoneDto timezone = new() { Hours = 2 };
- private static readonly DateTimeOffset dateStart = new (2024, 01, 01, 00, 11, 11, timezone.Offset);
- private readonly static WellDto well = new()
- {
+ private static readonly DateTimeOffset dateStart = new(2024, 01, 01, 00, 11, 11, timezone.Offset);
+ private readonly static WellDto well = new()
+ {
Id = 1,
IdTelemetry = 1,
Timezone = timezone
@@ -52,7 +48,7 @@ public class ProcessMapReportDataSaubStatServiceTest
private readonly static IEnumerable processMapPlan = new List()
{
new() {
- DepthStart = 0,
+ DepthStart = 0,
DepthEnd = 100,
IdMode = 1,
IdWell = well.Id,
@@ -136,6 +132,12 @@ public class ProcessMapReportDataSaubStatServiceTest
Comment = "s",
},
};
+
+ private readonly static IEnumerable> processMapPlanChangeLog = processMapPlan.Select(p => new ChangeLogDto()
+ {
+ Item = p,
+ });
+
private readonly static IEnumerable operations = new List()
{
new()
@@ -253,15 +255,18 @@ public class ProcessMapReportDataSaubStatServiceTest
HasOscillation = false,
}
};
-
+
public ProcessMapReportDataSaubStatServiceTest()
{
wellService.GetOrDefaultAsync(Arg.Any(), Arg.Any())
.Returns(well);
- processMapPlanBaseRepository.Get(Arg.Any(), Arg.Any())
+ processMapPlanBaseRepository.GetCurrent(Arg.Any(), Arg.Any())
.Returns(processMapPlan);
+ processMapPlanBaseRepository.GetChangeLogForDate(Arg.Any(), null, Arg.Any())
+ .Returns(processMapPlanChangeLog);
+
wellOperationRepository.GetAsync(Arg.Any(), Arg.Any())
.Returns(operations);
diff --git a/AsbCloudWebApi/Controllers/ProcessMaps/ProcessMapPlanBaseController.cs b/AsbCloudWebApi/Controllers/ProcessMaps/ProcessMapPlanBaseController.cs
index f4df65cc..66b75bc0 100644
--- a/AsbCloudWebApi/Controllers/ProcessMaps/ProcessMapPlanBaseController.cs
+++ b/AsbCloudWebApi/Controllers/ProcessMaps/ProcessMapPlanBaseController.cs
@@ -1,23 +1,24 @@
-using AsbCloudApp.Repositories;
-using Microsoft.AspNetCore.Authorization;
-using Microsoft.AspNetCore.Mvc;
-using System.Collections.Generic;
-using System.Threading.Tasks;
-using System.Threading;
-using Microsoft.AspNetCore.Http;
-using AsbCloudApp.Exceptions;
-using AsbCloudApp.Requests;
-using System;
-using System.IO;
-using AsbCloudApp.Services;
-using System.Linq;
-using AsbCloudApp.Data;
-using AsbCloudApp.Requests.ParserOptions;
+using AsbCloudApp.Data;
using AsbCloudApp.Data.ProcessMaps;
-using System.ComponentModel.DataAnnotations;
+using AsbCloudApp.Exceptions;
+using AsbCloudApp.Repositories;
+using AsbCloudApp.Requests;
using AsbCloudApp.Requests.ExportOptions;
+using AsbCloudApp.Requests.ParserOptions;
+using AsbCloudApp.Services;
using AsbCloudApp.Services.Export;
using AsbCloudApp.Services.Parsers;
+using AsbCloudDb.Model.ProcessMapPlan;
+using Microsoft.AspNetCore.Authorization;
+using Microsoft.AspNetCore.Http;
+using Microsoft.AspNetCore.Mvc;
+using System;
+using System.Collections.Generic;
+using System.ComponentModel.DataAnnotations;
+using System.IO;
+using System.Linq;
+using System.Threading;
+using System.Threading.Tasks;
namespace AsbCloudWebApi.Controllers.ProcessMaps;
@@ -27,22 +28,26 @@ namespace AsbCloudWebApi.Controllers.ProcessMaps;
[ApiController]
[Route("api/well/{idWell}/[controller]")]
[Authorize]
-public abstract class ProcessMapPlanBaseController : ControllerBase
+public abstract class ProcessMapPlanBaseController : ControllerBase
+ where TEntity : ProcessMapPlanBase
where TDto : ProcessMapPlanBaseDto
{
private readonly IChangeLogRepository repository;
private readonly IWellService wellService;
private readonly IParserService parserService;
+ private readonly ITelemetryService telemetryService;
private readonly IExportService processMapPlanExportService;
protected ProcessMapPlanBaseController(IChangeLogRepository repository,
IWellService wellService,
IParserService parserService,
- IExportService processMapPlanExportService)
+ IExportService processMapPlanExportService,
+ ITelemetryService telemetryService)
{
this.repository = repository;
this.wellService = wellService;
this.parserService = parserService;
+ this.telemetryService = telemetryService;
this.processMapPlanExportService = processMapPlanExportService;
}
@@ -58,7 +63,7 @@ public abstract class ProcessMapPlanBaseController : ControllerBase
[HttpPost]
[ProducesResponseType(typeof(int), StatusCodes.Status200OK)]
[ProducesResponseType(typeof(ValidationProblemDetails), StatusCodes.Status400BadRequest)]
- public async Task InsertRange([FromRoute][Range(0,int.MaxValue)] int idWell, IEnumerable dtos, CancellationToken token)
+ public async Task InsertRange([FromRoute][Range(0, int.MaxValue)] int idWell, IEnumerable dtos, CancellationToken token)
{
var idUser = await AssertUserHasAccessToWell(idWell, token);
@@ -92,7 +97,7 @@ public abstract class ProcessMapPlanBaseController : ControllerBase
}
///
- /// Удаление
+ /// Пометить записи как удаленные
///
///
///
@@ -101,11 +106,11 @@ public abstract class ProcessMapPlanBaseController : ControllerBase
[HttpDelete]
[ProducesResponseType(typeof(int), StatusCodes.Status200OK)]
[ProducesResponseType(typeof(ValidationProblemDetails), StatusCodes.Status400BadRequest)]
- public async Task DeleteRange([FromRoute] int idWell, IEnumerable ids, CancellationToken token)
+ public async Task MarkAsDeleted([FromRoute] int idWell, IEnumerable ids, CancellationToken token)
{
var idUser = await AssertUserHasAccessToWell(idWell, token);
- var result = await repository.DeleteRange(idUser, ids, token);
+ var result = await repository.MarkAsDeleted(idUser, ids, token);
return Ok(result);
}
@@ -128,21 +133,78 @@ public abstract class ProcessMapPlanBaseController : ControllerBase
}
///
- /// Получение
+ /// Получение текущих записей по параметрам
///
///
- ///
///
///
[HttpGet]
[ProducesResponseType(StatusCodes.Status200OK)]
[ProducesResponseType(typeof(ValidationProblemDetails), StatusCodes.Status400BadRequest)]
- public async Task>> Get([FromRoute] int idWell, [FromQuery] ProcessMapPlanBaseRequest request, CancellationToken token)
+ public async Task>> GetCurrent([FromRoute] int idWell, CancellationToken token)
{
await AssertUserHasAccessToWell(idWell, token);
- var serviceRequest = new ProcessMapPlanBaseRequestWithWell(request, idWell);
- var result = await repository.Get(serviceRequest, token);
+ var serviceRequest = new ProcessMapPlanBaseRequestWithWell(idWell);
+
+ var result = await repository.GetCurrent(serviceRequest, token);
+ return Ok(result);
+ }
+
+ ///
+ /// Получение измененных записей за определенную дату по ключу скважины
+ ///
+ ///
+ ///
+ ///
+ ///
+ [HttpGet("changelogByMoment")]
+ [ProducesResponseType(StatusCodes.Status200OK)]
+ [ProducesResponseType(typeof(ValidationProblemDetails), StatusCodes.Status400BadRequest)]
+ public async Task>>> GetChangeLogByMoment([FromRoute] int idWell, DateTimeOffset? moment, CancellationToken token)
+ {
+ await AssertUserHasAccessToWell(idWell, token);
+
+ var dataRequest = new ProcessMapPlanBaseRequestWithWell(idWell);
+
+ var changeLogRequest = new ChangeLogRequest()
+ {
+ Moment = moment
+ };
+
+ var builder = repository
+ .GetQueryBuilder(changeLogRequest)
+ .ApplyRequest(dataRequest);
+
+ var dtos = await builder.GetChangeLogData(token);
+
+ return Ok(dtos);
+ }
+
+ ///
+ /// Получение записей за определенную дату по uid
+ ///
+ ///
+ ///
+ ///
+ ///
+ [AllowAnonymous]
+ [HttpGet("/api/telemetry/{uid}/[controller]")]
+ [ProducesResponseType(StatusCodes.Status200OK)]
+ [ProducesResponseType(typeof(ValidationProblemDetails), StatusCodes.Status400BadRequest)]
+ public async Task>>> GetByUid(string uid, DateTimeOffset? updateFrom, CancellationToken token)
+ {
+ var idWell = telemetryService.GetIdWellByTelemetryUid(uid) ?? -1;
+
+ if (idWell < 0)
+ return this.ValidationBadRequest(nameof(uid), "Скважина по uid не найдена");
+
+ var serviceRequest = new ProcessMapPlanBaseRequestWithWell(idWell)
+ {
+ UpdateFrom = updateFrom,
+ };
+
+ var result = await repository.GetChangeLogForDate(serviceRequest, null, token);
return Ok(result);
}
@@ -153,15 +215,15 @@ public abstract class ProcessMapPlanBaseController : ControllerBase
///
///
///
- [HttpGet("changeLog")]
+ [HttpGet("changeLogForDate")]
[ProducesResponseType(StatusCodes.Status200OK)]
[ProducesResponseType(typeof(ValidationProblemDetails), StatusCodes.Status400BadRequest)]
- public async Task>> GetChangeLog([FromRoute] int idWell, [FromQuery] DateOnly? date, CancellationToken token)
+ public async Task>>> GetChangeLogForDate([FromRoute] int idWell, [FromQuery] DateOnly? date, CancellationToken token)
{
await AssertUserHasAccessToWell(idWell, token);
var serviceRequest = new ProcessMapPlanBaseRequestWithWell(idWell);
- var result = await repository.GetChangeLog(serviceRequest, date, token);
+ var result = await repository.GetChangeLogForDate(serviceRequest, date, token);
return Ok(result);
}
@@ -197,7 +259,7 @@ public abstract class ProcessMapPlanBaseController : ControllerBase
{
if (!dtos.Any())
return NoContent();
-
+
var idUser = await AssertUserHasAccessToWell(idWell, token);
foreach (var dto in dtos)
@@ -218,7 +280,7 @@ public abstract class ProcessMapPlanBaseController : ControllerBase
[ProducesResponseType(StatusCodes.Status200OK)]
[ProducesResponseType(typeof(ValidationProblemDetails), StatusCodes.Status400BadRequest)]
public async Task>> Parse(int idWell,
- [Required] IFormFile file,
+ [Required] IFormFile file,
CancellationToken token)
{
await AssertUserHasAccessToWell(idWell, token);
@@ -229,7 +291,7 @@ public abstract class ProcessMapPlanBaseController : ControllerBase
{
var options = new WellRelatedParserRequest(idWell);
var dto = parserService.Parse(stream, options);
-
+
return Ok(dto);
}
catch (FileFormatException ex)
@@ -271,7 +333,7 @@ public abstract class ProcessMapPlanBaseController : ControllerBase
throw new ForbidException("Нет доступа к скважине");
return idUser;
}
-
+
///
/// Формируем excel файл с текущими строками РТК
///
diff --git a/AsbCloudWebApi/Controllers/ProcessMaps/ProcessMapPlanDrillingController.cs b/AsbCloudWebApi/Controllers/ProcessMaps/ProcessMapPlanDrillingController.cs
index 241be301..60d68436 100644
--- a/AsbCloudWebApi/Controllers/ProcessMaps/ProcessMapPlanDrillingController.cs
+++ b/AsbCloudWebApi/Controllers/ProcessMaps/ProcessMapPlanDrillingController.cs
@@ -2,6 +2,7 @@
using AsbCloudApp.Repositories;
using AsbCloudApp.Requests;
using AsbCloudApp.Services;
+using AsbCloudDb.Model.ProcessMaps;
using AsbCloudInfrastructure.Services.ProcessMapPlan.Export;
using AsbCloudInfrastructure.Services.ProcessMapPlan.Parser;
@@ -10,13 +11,14 @@ namespace AsbCloudWebApi.Controllers.ProcessMaps;
///
/// РТК план бурения
///
-public class ProcessMapPlanDrillingController : ProcessMapPlanBaseController
+public class ProcessMapPlanDrillingController : ProcessMapPlanBaseController
{
public ProcessMapPlanDrillingController(IChangeLogRepository repository,
IWellService wellService,
ProcessMapPlanDrillingParser parserService,
+ ITelemetryService telemetryService,
ProcessMapPlanDrillingExportService processMapPlanExportService)
- : base(repository, wellService, parserService, processMapPlanExportService)
+ : base(repository, wellService, parserService, processMapPlanExportService, telemetryService)
{
}
diff --git a/AsbCloudWebApi/Controllers/ProcessMaps/ProcessMapPlanReamController.cs b/AsbCloudWebApi/Controllers/ProcessMaps/ProcessMapPlanReamController.cs
index 9c103f06..2e9aeedf 100644
--- a/AsbCloudWebApi/Controllers/ProcessMaps/ProcessMapPlanReamController.cs
+++ b/AsbCloudWebApi/Controllers/ProcessMaps/ProcessMapPlanReamController.cs
@@ -2,6 +2,7 @@
using AsbCloudApp.Repositories;
using AsbCloudApp.Requests;
using AsbCloudApp.Services;
+using AsbCloudDb.Model.ProcessMaps;
using AsbCloudInfrastructure.Services.ProcessMapPlan.Export;
using AsbCloudInfrastructure.Services.ProcessMapPlan.Parser;
@@ -10,13 +11,14 @@ namespace AsbCloudWebApi.Controllers.ProcessMaps;
///
/// РТК план проработка
///
-public class ProcessMapPlanReamController : ProcessMapPlanBaseController
+public class ProcessMapPlanReamController : ProcessMapPlanBaseController