forked from ddrilling/AsbCloudServer
CS2-53: Added basics of WellOperation controller, service, model and dto
This commit is contained in:
parent
1956eafb32
commit
bc1bcb2ee2
@ -1,18 +1,27 @@
|
|||||||
namespace AsbCloudApp.Data
|
using System;
|
||||||
|
|
||||||
|
namespace AsbCloudApp.Data
|
||||||
{
|
{
|
||||||
public class WellOperationDto : IId
|
public class WellOperationDto : IId
|
||||||
{
|
{
|
||||||
public int Id { get; set; }
|
public int Id { get; set; }
|
||||||
|
|
||||||
public int IdWell { get; set; }
|
public int IdSection { get; set; }
|
||||||
|
|
||||||
public string Caption { get; set; }
|
public int IdCategory { get; set; }
|
||||||
|
|
||||||
public string Description { get; set; }
|
public string CategoryName { get; set; }
|
||||||
|
|
||||||
public double CasingSection { get; set; }
|
public string Type { get; set; }
|
||||||
|
|
||||||
public double WellDepth { get; set; }
|
public string WellDepth { get; set; }
|
||||||
|
|
||||||
|
public DateTime StartDate { get; set; }
|
||||||
|
|
||||||
|
public double Duration { get; set; }
|
||||||
|
|
||||||
|
public string Data { get; set; }
|
||||||
|
|
||||||
|
public string Comment { get; set; }
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
13
AsbCloudApp/Services/IWellOperationService.cs
Normal file
13
AsbCloudApp/Services/IWellOperationService.cs
Normal file
@ -0,0 +1,13 @@
|
|||||||
|
using System.Threading;
|
||||||
|
using System.Threading.Tasks;
|
||||||
|
using AsbCloudApp.Data;
|
||||||
|
|
||||||
|
|
||||||
|
namespace AsbCloudApp.Services
|
||||||
|
{
|
||||||
|
public interface IWellOperationService
|
||||||
|
{
|
||||||
|
Task<PaginationContainer<WellOperationDto>> GetAllByWellIdAsync(int idWell,
|
||||||
|
int skip = 0, int take = 32, CancellationToken token = default);
|
||||||
|
}
|
||||||
|
}
|
@ -27,14 +27,13 @@ namespace AsbCloudDb.Model
|
|||||||
public virtual DbSet<TelemetryEvent> TelemetryEvents { get; set; }
|
public virtual DbSet<TelemetryEvent> TelemetryEvents { get; set; }
|
||||||
public virtual DbSet<TelemetryMessage> TelemetryMessages { get; set; }
|
public virtual DbSet<TelemetryMessage> TelemetryMessages { get; set; }
|
||||||
public virtual DbSet<TelemetryUser> TelemetryUsers { get; set; }
|
public virtual DbSet<TelemetryUser> TelemetryUsers { get; set; }
|
||||||
public virtual DbSet<Operation> TelemetryOperations { get; set; }
|
public virtual DbSet<OperationCategory> TelemetryOperations { get; set; }
|
||||||
public virtual DbSet<TelemetryAnalysis> TelemetryAnalysis { get; set; }
|
public virtual DbSet<TelemetryAnalysis> TelemetryAnalysis { get; set; }
|
||||||
public virtual DbSet<WellSection> WellSections { get; set; }
|
public virtual DbSet<WellSection> WellSections { get; set; }
|
||||||
public virtual DbSet<WellSectionType> WellSectionTypes { get; set; }
|
public virtual DbSet<WellSectionType> WellSectionTypes { get; set; }
|
||||||
public virtual DbSet<WellOperation> WellOperations { get; set; }
|
public virtual DbSet<WellOperation> WellOperations { get; set; }
|
||||||
public virtual DbSet<WellType> WellTypes { get; set; }
|
public virtual DbSet<WellType> WellTypes { get; set; }
|
||||||
public virtual DbSet<LastData> LastData { get; set; }
|
public virtual DbSet<LastData> LastData { get; set; }
|
||||||
public virtual DbSet<TvdData> TvdData { get; set; }
|
|
||||||
|
|
||||||
//var options = new DbContextOptionsBuilder<AsbCloudDbContext>()
|
//var options = new DbContextOptionsBuilder<AsbCloudDbContext>()
|
||||||
// .UseNpgsql("Host=localhost;Database=postgres;Username=postgres;Password=q;Persist Security Info=True")
|
// .UseNpgsql("Host=localhost;Database=postgres;Username=postgres;Password=q;Persist Security Info=True")
|
||||||
@ -164,10 +163,10 @@ namespace AsbCloudDb.Model
|
|||||||
.HasConstraintName("t_relation_company_well_t_company_id_fk");
|
.HasConstraintName("t_relation_company_well_t_company_id_fk");
|
||||||
});
|
});
|
||||||
|
|
||||||
modelBuilder.Entity<TvdData>(entity =>
|
modelBuilder.Entity<WellOperation>(entity =>
|
||||||
{
|
{
|
||||||
entity.HasIndex(d => d.Depth);
|
entity.HasIndex(d => d.WellDepth);
|
||||||
entity.HasIndex(d => d.Date);
|
entity.HasIndex(d => d.StartDate);
|
||||||
});
|
});
|
||||||
|
|
||||||
FillData(modelBuilder);
|
FillData(modelBuilder);
|
||||||
@ -205,26 +204,26 @@ namespace AsbCloudDb.Model
|
|||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
modelBuilder.Entity<Operation>(entity =>
|
modelBuilder.Entity<OperationCategory>(entity =>
|
||||||
{
|
{
|
||||||
entity.HasData(new List<Operation> {
|
entity.HasData(new List<OperationCategory> {
|
||||||
new Operation {Id = 1, OperationType = 0, Name = "Невозможно определить операцию"},
|
new OperationCategory {Id = 1, OperationType = 0, Name = "Невозможно определить операцию"},
|
||||||
new Operation {Id = 2, OperationType = 0, Name = "Роторное бурение" },
|
new OperationCategory {Id = 2, OperationType = 0, Name = "Роторное бурение" },
|
||||||
new Operation {Id = 3, OperationType = 0, Name = "Слайдирование" },
|
new OperationCategory {Id = 3, OperationType = 0, Name = "Слайдирование" },
|
||||||
new Operation {Id = 4, OperationType = 0, Name = "Подъем с проработкой" },
|
new OperationCategory {Id = 4, OperationType = 0, Name = "Подъем с проработкой" },
|
||||||
new Operation {Id = 5, OperationType = 0, Name = "Спуск с проработкой" },
|
new OperationCategory {Id = 5, OperationType = 0, Name = "Спуск с проработкой" },
|
||||||
new Operation {Id = 6, OperationType = 0, Name = "Подъем с промывкой" },
|
new OperationCategory {Id = 6, OperationType = 0, Name = "Подъем с промывкой" },
|
||||||
new Operation {Id = 7, OperationType = 0, Name = "Спуск с промывкой" },
|
new OperationCategory {Id = 7, OperationType = 0, Name = "Спуск с промывкой" },
|
||||||
new Operation {Id = 8, OperationType = 0, Name = "Спуск в скважину" },
|
new OperationCategory {Id = 8, OperationType = 0, Name = "Спуск в скважину" },
|
||||||
new Operation {Id = 9, OperationType = 0, Name = "Спуск с вращением" },
|
new OperationCategory {Id = 9, OperationType = 0, Name = "Спуск с вращением" },
|
||||||
new Operation {Id = 10, OperationType = 0, Name = "Подъем из скважины" },
|
new OperationCategory {Id = 10, OperationType = 0, Name = "Подъем из скважины" },
|
||||||
new Operation {Id = 11, OperationType = 0, Name = "Подъем с вращением" },
|
new OperationCategory {Id = 11, OperationType = 0, Name = "Подъем с вращением" },
|
||||||
new Operation {Id = 12, OperationType = 0, Name = "Промывка в покое" },
|
new OperationCategory {Id = 12, OperationType = 0, Name = "Промывка в покое" },
|
||||||
new Operation {Id = 13, OperationType = 0, Name = "Промывка с вращением" },
|
new OperationCategory {Id = 13, OperationType = 0, Name = "Промывка с вращением" },
|
||||||
new Operation {Id = 14, OperationType = 0, Name = "Удержание в клиньях" },
|
new OperationCategory {Id = 14, OperationType = 0, Name = "Удержание в клиньях" },
|
||||||
new Operation {Id = 15, OperationType = 0, Name = "Неподвижное состояние" },
|
new OperationCategory {Id = 15, OperationType = 0, Name = "Неподвижное состояние" },
|
||||||
new Operation {Id = 16, OperationType = 0, Name = "Вращение без циркуляции" },
|
new OperationCategory {Id = 16, OperationType = 0, Name = "Вращение без циркуляции" },
|
||||||
new Operation {Id = 17, OperationType = 0, Name = "На поверхности" }
|
new OperationCategory {Id = 17, OperationType = 0, Name = "На поверхности" }
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
@ -22,7 +22,7 @@ namespace AsbCloudDb.Model
|
|||||||
DbSet<FileCategory> FileCategories { get; set; }
|
DbSet<FileCategory> FileCategories { get; set; }
|
||||||
DbSet<Telemetry> Telemetries { get; set; }
|
DbSet<Telemetry> Telemetries { get; set; }
|
||||||
DbSet<TelemetryUser> TelemetryUsers { get; set; }
|
DbSet<TelemetryUser> TelemetryUsers { get; set; }
|
||||||
DbSet<Operation> TelemetryOperations { get; set; }
|
DbSet<OperationCategory> TelemetryOperations { get; set; }
|
||||||
DbSet<TelemetryAnalysis> TelemetryAnalysis { get; set; }
|
DbSet<TelemetryAnalysis> TelemetryAnalysis { get; set; }
|
||||||
DbSet<Well> Wells { get; set; }
|
DbSet<Well> Wells { get; set; }
|
||||||
DbSet<WellSection> WellSections { get; set; }
|
DbSet<WellSection> WellSections { get; set; }
|
||||||
@ -30,7 +30,6 @@ namespace AsbCloudDb.Model
|
|||||||
DbSet<WellOperation> WellOperations { get; set; }
|
DbSet<WellOperation> WellOperations { get; set; }
|
||||||
DbSet<WellType> WellTypes { get; set; }
|
DbSet<WellType> WellTypes { get; set; }
|
||||||
DbSet<LastData> LastData { get; set; }
|
DbSet<LastData> LastData { get; set; }
|
||||||
DbSet<TvdData> TvdData { get; set; }
|
|
||||||
|
|
||||||
int SaveChanges();
|
int SaveChanges();
|
||||||
int SaveChanges(bool acceptAllChangesOnSuccess);
|
int SaveChanges(bool acceptAllChangesOnSuccess);
|
||||||
|
@ -6,7 +6,7 @@ using System.ComponentModel.DataAnnotations.Schema;
|
|||||||
namespace AsbCloudDb.Model
|
namespace AsbCloudDb.Model
|
||||||
{
|
{
|
||||||
[Table("t_operations"), Comment("Справочник операций на скважине")]
|
[Table("t_operations"), Comment("Справочник операций на скважине")]
|
||||||
public class Operation
|
public class OperationCategory
|
||||||
{
|
{
|
||||||
[Key]
|
[Key]
|
||||||
[Column("id")]
|
[Column("id")]
|
@ -28,8 +28,8 @@ namespace AsbCloudDb.Model
|
|||||||
|
|
||||||
[JsonIgnore]
|
[JsonIgnore]
|
||||||
[ForeignKey(nameof(IdOperation))]
|
[ForeignKey(nameof(IdOperation))]
|
||||||
[InverseProperty(nameof(Model.Operation.Analysis))]
|
[InverseProperty(nameof(Model.OperationCategory.Analysis))]
|
||||||
public virtual Operation Operation { get; set; }
|
public virtual OperationCategory Operation { get; set; }
|
||||||
|
|
||||||
|
|
||||||
[Column("unix_date", TypeName = "bigint"), Comment("Unix timestamp для Linq запросов с вычислением дат")]
|
[Column("unix_date", TypeName = "bigint"), Comment("Unix timestamp для Linq запросов с вычислением дат")]
|
||||||
|
@ -1,48 +0,0 @@
|
|||||||
using System;
|
|
||||||
using Microsoft.EntityFrameworkCore;
|
|
||||||
using System.ComponentModel.DataAnnotations;
|
|
||||||
using System.ComponentModel.DataAnnotations.Schema;
|
|
||||||
using System.Text.Json.Serialization;
|
|
||||||
|
|
||||||
namespace AsbCloudDb.Model
|
|
||||||
{
|
|
||||||
[Table("t_tvd_data"), Comment("Данные для графика глубина-день")]
|
|
||||||
public class TvdData
|
|
||||||
{
|
|
||||||
[Key]
|
|
||||||
[Column("id")]
|
|
||||||
public int Id { get; set; }
|
|
||||||
|
|
||||||
[Column("id_section"), Comment("Id секции скважины")]
|
|
||||||
public int IdSection { get; set; }
|
|
||||||
|
|
||||||
[Column("id_category"), Comment("Id категории операции")]
|
|
||||||
public int IdCategory { get; set; }
|
|
||||||
|
|
||||||
[Column("type"), Comment("План или Факт")]
|
|
||||||
public string Type { get; set; }
|
|
||||||
|
|
||||||
[Column("depth"), Comment("Глубина, на которой производилась операция")]
|
|
||||||
public string Depth { get; set; }
|
|
||||||
|
|
||||||
[Column("date"), Comment("Дата операции")]
|
|
||||||
public DateTime Date { get; set; }
|
|
||||||
|
|
||||||
[Column("duration_hours"), Comment("Продолжительность в часах")]
|
|
||||||
public double Duration { get; set; }
|
|
||||||
|
|
||||||
[Column("data"), Comment("Данные по операции")]
|
|
||||||
public string Data { get; set; }
|
|
||||||
|
|
||||||
[Column("comment"), Comment("Комментарий")]
|
|
||||||
public string Comment { get; set; }
|
|
||||||
|
|
||||||
[JsonIgnore]
|
|
||||||
[ForeignKey(nameof(IdSection))]
|
|
||||||
public virtual WellSection WellSection { get; set; }
|
|
||||||
|
|
||||||
[JsonIgnore]
|
|
||||||
[ForeignKey(nameof(IdCategory))]
|
|
||||||
public virtual Operation Operation { get; set; }
|
|
||||||
}
|
|
||||||
}
|
|
@ -1,36 +1,51 @@
|
|||||||
using Microsoft.EntityFrameworkCore;
|
using System;
|
||||||
|
using Microsoft.EntityFrameworkCore;
|
||||||
using System.ComponentModel.DataAnnotations;
|
using System.ComponentModel.DataAnnotations;
|
||||||
using System.ComponentModel.DataAnnotations.Schema;
|
using System.ComponentModel.DataAnnotations.Schema;
|
||||||
using System.Text.Json.Serialization;
|
using System.Text.Json.Serialization;
|
||||||
|
|
||||||
#nullable disable
|
|
||||||
|
|
||||||
namespace AsbCloudDb.Model
|
namespace AsbCloudDb.Model
|
||||||
{
|
{
|
||||||
[Table("t_well_operation"), Comment("Операции по скважине")]
|
[Table("t_well_operations"), Comment("Данные по операциям на скважине")]
|
||||||
public class WellOperation: IId, IIdWell
|
public class WellOperation
|
||||||
{
|
{
|
||||||
[Key]
|
[Key]
|
||||||
[Column("id")]
|
[Column("id")]
|
||||||
public int Id { get; set; }
|
public int Id { get; set; }
|
||||||
|
|
||||||
[Column("id_well")]
|
[Column("id_well"), Comment("Id скважины")]
|
||||||
public int IdWell { get; set; }
|
public int IdWell { get; set; }
|
||||||
|
|
||||||
[Column("caption")]
|
[Column("id_section"), Comment("Id секции скважины")]
|
||||||
public string Caption { get; set; }
|
public int IdSection { get; set; }
|
||||||
|
|
||||||
[Column("description")]
|
[Column("id_category"), Comment("Id категории операции")]
|
||||||
public string Description { get; set; }
|
public int IdCategory { get; set; }
|
||||||
|
|
||||||
[Column("casing_section")]
|
[Column("type"), Comment("План или Факт")]
|
||||||
public double CasingSection { get; set; }
|
public string Type { get; set; }
|
||||||
|
|
||||||
[Column("well_depth")]
|
[Column("depth"), Comment("Глубина, на которой производилась операция")]
|
||||||
public double WellDepth { get; set; }
|
public string WellDepth { get; set; }
|
||||||
|
|
||||||
|
[Column("date"), Comment("Дата начала операции")]
|
||||||
|
public DateTime StartDate { get; set; }
|
||||||
|
|
||||||
|
[Column("duration_hours"), Comment("Продолжительность в часах")]
|
||||||
|
public double Duration { get; set; }
|
||||||
|
|
||||||
|
[Column("data"), Comment("Данные по операции")]
|
||||||
|
public string Data { get; set; }
|
||||||
|
|
||||||
|
[Column("comment"), Comment("Комментарий")]
|
||||||
|
public string Comment { get; set; }
|
||||||
|
|
||||||
[JsonIgnore]
|
[JsonIgnore]
|
||||||
[ForeignKey(nameof(IdWell))]
|
[ForeignKey(nameof(IdSection))]
|
||||||
public virtual Well Well { get; set; }
|
public virtual WellSection WellSection { get; set; }
|
||||||
|
|
||||||
|
[JsonIgnore]
|
||||||
|
[ForeignKey(nameof(IdCategory))]
|
||||||
|
public virtual OperationCategory OperationCategory { get; set; }
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -37,6 +37,7 @@ namespace AsbCloudInfrastructure
|
|||||||
services.AddTransient<ITelemetryAnalyticsService, TelemetryAnalyticsService>();
|
services.AddTransient<ITelemetryAnalyticsService, TelemetryAnalyticsService>();
|
||||||
services.AddTransient<IFileService, FileService>();
|
services.AddTransient<IFileService, FileService>();
|
||||||
services.AddTransient<IWellSectionService, WellSectionService>();
|
services.AddTransient<IWellSectionService, WellSectionService>();
|
||||||
|
services.AddTransient<IWellOperationService, WellOperationService>();
|
||||||
|
|
||||||
services.AddTransient<ILastDataService<FluidDataDto>, LastDataService<FluidDataDto, FluidData>>();
|
services.AddTransient<ILastDataService<FluidDataDto>, LastDataService<FluidDataDto, FluidData>>();
|
||||||
services.AddTransient<ILastDataService<MudDiagramDataDto>, LastDataService<MudDiagramDataDto, MudDiagramData>>();
|
services.AddTransient<ILastDataService<MudDiagramDataDto>, LastDataService<MudDiagramDataDto, MudDiagramData>>();
|
||||||
|
@ -17,9 +17,9 @@ namespace AsbCloudInfrastructure.Services
|
|||||||
private readonly IAsbCloudDbContext db;
|
private readonly IAsbCloudDbContext db;
|
||||||
private readonly ITelemetryService telemetryService;
|
private readonly ITelemetryService telemetryService;
|
||||||
private readonly ISaubDataCache saubDataCache;
|
private readonly ISaubDataCache saubDataCache;
|
||||||
private readonly CacheTable<Operation> cacheOperations;
|
private readonly CacheTable<OperationCategory> cacheOperations;
|
||||||
private readonly TelemetryOperationDetectorService operationDetectorService;
|
private readonly TelemetryOperationDetectorService operationDetectorService;
|
||||||
private readonly IEnumerable<Operation> operations;
|
private readonly IEnumerable<OperationCategory> operations;
|
||||||
|
|
||||||
public TelemetryAnalyticsService(IAsbCloudDbContext db, ITelemetryService telemetryService,
|
public TelemetryAnalyticsService(IAsbCloudDbContext db, ITelemetryService telemetryService,
|
||||||
ISaubDataCache saubDataCache, CacheDb cacheDb)
|
ISaubDataCache saubDataCache, CacheDb cacheDb)
|
||||||
@ -27,7 +27,7 @@ namespace AsbCloudInfrastructure.Services
|
|||||||
this.db = db;
|
this.db = db;
|
||||||
this.telemetryService = telemetryService;
|
this.telemetryService = telemetryService;
|
||||||
this.saubDataCache = saubDataCache;
|
this.saubDataCache = saubDataCache;
|
||||||
cacheOperations = cacheDb.GetCachedTable<Operation>((AsbCloudDbContext)db);
|
cacheOperations = cacheDb.GetCachedTable<OperationCategory>((AsbCloudDbContext)db);
|
||||||
operations = cacheOperations.Select(c => true);
|
operations = cacheOperations.Select(c => true);
|
||||||
operationDetectorService = new TelemetryOperationDetectorService(operations);
|
operationDetectorService = new TelemetryOperationDetectorService(operations);
|
||||||
}
|
}
|
||||||
|
@ -7,7 +7,7 @@ namespace AsbCloudInfrastructure.Services
|
|||||||
public class TelemetryOperationDetector
|
public class TelemetryOperationDetector
|
||||||
{
|
{
|
||||||
public int Order { get; set; }
|
public int Order { get; set; }
|
||||||
public Operation Operation { get; set; }
|
public OperationCategory Operation { get; set; }
|
||||||
public Func<TelemetryAnalysisDto, bool> Detect { get; set; }
|
public Func<TelemetryAnalysisDto, bool> Detect { get; set; }
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -9,7 +9,7 @@ namespace AsbCloudInfrastructure.Services
|
|||||||
{
|
{
|
||||||
private readonly IEnumerable<TelemetryOperationDetector> detectors;
|
private readonly IEnumerable<TelemetryOperationDetector> detectors;
|
||||||
|
|
||||||
public TelemetryOperationDetectorService(IEnumerable<Operation> operations)
|
public TelemetryOperationDetectorService(IEnumerable<OperationCategory> operations)
|
||||||
{
|
{
|
||||||
detectors = new List<TelemetryOperationDetector>()
|
detectors = new List<TelemetryOperationDetector>()
|
||||||
{
|
{
|
||||||
@ -180,8 +180,8 @@ namespace AsbCloudInfrastructure.Services
|
|||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
public Operation DetectOperation(TelemetryAnalysisDto data) =>
|
public OperationCategory DetectOperation(TelemetryAnalysisDto data) =>
|
||||||
detectors.OrderBy(d => d.Order).First(o => o.Detect(data)).Operation
|
detectors.OrderBy(d => d.Order).First(o => o.Detect(data)).Operation
|
||||||
?? new Operation { Id = 1, Name = "Невозможно определить операцию" };
|
?? new OperationCategory { Id = 1, Name = "Невозможно определить операцию" };
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
61
AsbCloudInfrastructure/Services/WellOperationService.cs
Normal file
61
AsbCloudInfrastructure/Services/WellOperationService.cs
Normal file
@ -0,0 +1,61 @@
|
|||||||
|
using System.Linq;
|
||||||
|
using System.Threading;
|
||||||
|
using System.Threading.Tasks;
|
||||||
|
using Microsoft.EntityFrameworkCore;
|
||||||
|
using AsbCloudApp.Data;
|
||||||
|
using AsbCloudApp.Services;
|
||||||
|
using AsbCloudDb.Model;
|
||||||
|
using AsbCloudInfrastructure.Services.Cache;
|
||||||
|
using Mapster;
|
||||||
|
|
||||||
|
namespace AsbCloudInfrastructure.Services
|
||||||
|
{
|
||||||
|
public class WellOperationService : IWellOperationService
|
||||||
|
{
|
||||||
|
private readonly IAsbCloudDbContext context;
|
||||||
|
private readonly DbSet<WellOperation> dbSet;
|
||||||
|
private readonly CacheTable<OperationCategory> cachedOperationTypes;
|
||||||
|
|
||||||
|
public WellOperationService(IAsbCloudDbContext context, Cache.CacheDb cache)
|
||||||
|
{
|
||||||
|
this.context = context;
|
||||||
|
dbSet = context.Set<WellOperation>();
|
||||||
|
cachedOperationTypes = cache.GetCachedTable<OperationCategory>((DbContext)context);
|
||||||
|
}
|
||||||
|
|
||||||
|
public async Task<PaginationContainer<WellOperationDto>> GetAllByWellIdAsync(int idWell,
|
||||||
|
int skip = 0, int take = 32, CancellationToken token = default)
|
||||||
|
{
|
||||||
|
var query = dbSet
|
||||||
|
.Include(s => s.WellSection)
|
||||||
|
.Where(s => s.WellSection.IdWell == idWell)
|
||||||
|
.AsNoTracking();
|
||||||
|
|
||||||
|
var result = new PaginationContainer<WellOperationDto>
|
||||||
|
{
|
||||||
|
Skip = skip,
|
||||||
|
Take = take,
|
||||||
|
Count = await query.CountAsync(token).ConfigureAwait(false),
|
||||||
|
};
|
||||||
|
|
||||||
|
query = query
|
||||||
|
.OrderBy(e => e.WellDepth);
|
||||||
|
|
||||||
|
if (skip > 0)
|
||||||
|
query = query.Skip(skip);
|
||||||
|
|
||||||
|
query = query.Take(take);
|
||||||
|
|
||||||
|
var entities = await query.Take(take).ToListAsync(token).ConfigureAwait(false);
|
||||||
|
|
||||||
|
foreach (var item in entities)
|
||||||
|
{
|
||||||
|
var dto = item.Adapt<WellOperationDto>();
|
||||||
|
//dto.SectionType = item.WellSectionType.Caption;
|
||||||
|
result.Items.Add(dto);
|
||||||
|
}
|
||||||
|
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
46
AsbCloudWebApi/Controllers/WellOperationController.cs
Normal file
46
AsbCloudWebApi/Controllers/WellOperationController.cs
Normal file
@ -0,0 +1,46 @@
|
|||||||
|
using System.Threading;
|
||||||
|
using System.Threading.Tasks;
|
||||||
|
using AsbCloudApp.Data;
|
||||||
|
using AsbCloudApp.Services;
|
||||||
|
using Microsoft.AspNetCore.Mvc;
|
||||||
|
using Microsoft.AspNetCore.Authorization;
|
||||||
|
|
||||||
|
namespace AsbCloudWebApi.Controllers
|
||||||
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// Контроллер операций на скважине
|
||||||
|
/// </summary>
|
||||||
|
[Route("api/wellOperation")]
|
||||||
|
[ApiController]
|
||||||
|
[Authorize]
|
||||||
|
public class WellOperationController : ControllerBase
|
||||||
|
{
|
||||||
|
private readonly IWellOperationService operationService;
|
||||||
|
private readonly IWellService wellService;
|
||||||
|
|
||||||
|
public WellOperationController(IWellOperationService operationService, IWellService wellService)
|
||||||
|
{
|
||||||
|
this.operationService = operationService;
|
||||||
|
this.wellService = wellService;
|
||||||
|
}
|
||||||
|
|
||||||
|
[HttpGet]
|
||||||
|
[ProducesResponseType(typeof(PaginationContainer<WellSectionDto>), (int)System.Net.HttpStatusCode.OK)]
|
||||||
|
public async Task<IActionResult> GetAllAsync(int idWell, int skip = 0, int take = 32,
|
||||||
|
CancellationToken token = default)
|
||||||
|
{
|
||||||
|
if (!await CanUserAccessToWellAsync(idWell, token).ConfigureAwait(false))
|
||||||
|
return Forbid();
|
||||||
|
|
||||||
|
var result = await operationService.GetAllByWellIdAsync(idWell, skip, take, token).ConfigureAwait(false);
|
||||||
|
return Ok(result);
|
||||||
|
}
|
||||||
|
|
||||||
|
private async Task<bool> CanUserAccessToWellAsync(int idWell, CancellationToken token = default)
|
||||||
|
{
|
||||||
|
int? idCompany = User.GetCompanyId();
|
||||||
|
return idCompany is not null && await wellService.IsCompanyInvolvedInWellAsync((int)idCompany,
|
||||||
|
idWell, token).ConfigureAwait(false);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in New Issue
Block a user