forked from ddrilling/AsbCloudServer
CS2-53: Added WellOperations Controller, Service, Dtos and Models
This commit is contained in:
parent
e1310be988
commit
d7e0eace47
11
AsbCloudApp/Data/WellOperationCategoryDto.cs
Normal file
11
AsbCloudApp/Data/WellOperationCategoryDto.cs
Normal file
@ -0,0 +1,11 @@
|
|||||||
|
namespace AsbCloudApp.Data
|
||||||
|
{
|
||||||
|
public class WellOperationCategoryDto
|
||||||
|
{
|
||||||
|
public int Id { get; set; }
|
||||||
|
|
||||||
|
public string Name { get; set; }
|
||||||
|
|
||||||
|
public int Code { get; set; }
|
||||||
|
}
|
||||||
|
}
|
@ -6,21 +6,25 @@ namespace AsbCloudApp.Data
|
|||||||
{
|
{
|
||||||
public int Id { get; set; }
|
public int Id { get; set; }
|
||||||
|
|
||||||
public int IdSection { get; set; }
|
public int IdWell { get; set; }
|
||||||
|
|
||||||
public int IdCategory { get; set; }
|
public int IdWellSectionType { get; set; }
|
||||||
|
|
||||||
|
public string WellSectionTypeName { get; set; }
|
||||||
|
|
||||||
|
public int IdOperationCategory { get; set; }
|
||||||
|
|
||||||
public string CategoryName { get; set; }
|
public string CategoryName { get; set; }
|
||||||
|
|
||||||
public string Type { get; set; }
|
public string Type { get; set; }
|
||||||
|
|
||||||
public string WellDepth { get; set; }
|
public double WellDepth { get; set; }
|
||||||
|
|
||||||
public DateTime StartDate { get; set; }
|
public DateTime StartDate { get; set; }
|
||||||
|
|
||||||
public double Duration { get; set; }
|
public double DurationHours { get; set; }
|
||||||
|
|
||||||
public string Data { get; set; }
|
public string Info { get; set; }
|
||||||
|
|
||||||
public string Comment { get; set; }
|
public string Comment { get; set; }
|
||||||
}
|
}
|
||||||
|
@ -1,4 +1,5 @@
|
|||||||
using System.Threading;
|
using System.Collections.Generic;
|
||||||
|
using System.Threading;
|
||||||
using System.Threading.Tasks;
|
using System.Threading.Tasks;
|
||||||
using AsbCloudApp.Data;
|
using AsbCloudApp.Data;
|
||||||
|
|
||||||
@ -7,7 +8,22 @@ namespace AsbCloudApp.Services
|
|||||||
{
|
{
|
||||||
public interface IWellOperationService
|
public interface IWellOperationService
|
||||||
{
|
{
|
||||||
|
IEnumerable<WellOperationCategoryDto> GetTypes();
|
||||||
|
|
||||||
Task<PaginationContainer<WellOperationDto>> GetAllByWellIdAsync(int idWell,
|
Task<PaginationContainer<WellOperationDto>> GetAllByWellIdAsync(int idWell,
|
||||||
int skip = 0, int take = 32, CancellationToken token = default);
|
int skip = 0, int take = 32, CancellationToken token = default);
|
||||||
|
|
||||||
|
Task<WellOperationDto> GetAsync(int id, CancellationToken token);
|
||||||
|
|
||||||
|
Task<int> InsertAsync(WellOperationDto wellOperationDto,
|
||||||
|
int idWell, CancellationToken token);
|
||||||
|
|
||||||
|
Task<int> InsertRangeAsync(int idWell,
|
||||||
|
IEnumerable<WellOperationDto> wellOperationDtos, CancellationToken token);
|
||||||
|
|
||||||
|
Task<int> UpdateAsync(int idWell, int idSection, WellOperationDto item,
|
||||||
|
CancellationToken token);
|
||||||
|
|
||||||
|
Task<int> DeleteAsync(IEnumerable<int> ids, CancellationToken token);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -27,7 +27,7 @@ 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<OperationCategory> TelemetryOperations { get; set; }
|
public virtual DbSet<WellOperationCategory> 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; }
|
||||||
@ -204,26 +204,26 @@ namespace AsbCloudDb.Model
|
|||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
modelBuilder.Entity<OperationCategory>(entity =>
|
modelBuilder.Entity<WellOperationCategory>(entity =>
|
||||||
{
|
{
|
||||||
entity.HasData(new List<OperationCategory> {
|
entity.HasData(new List<WellOperationCategory> {
|
||||||
new OperationCategory {Id = 1, OperationType = 0, Name = "Невозможно определить операцию"},
|
new WellOperationCategory {Id = 1, Name = "Невозможно определить операцию", Code = 0},
|
||||||
new OperationCategory {Id = 2, OperationType = 0, Name = "Роторное бурение" },
|
new WellOperationCategory {Id = 2, Name = "Роторное бурение", Code = 0 },
|
||||||
new OperationCategory {Id = 3, OperationType = 0, Name = "Слайдирование" },
|
new WellOperationCategory {Id = 3, Name = "Слайдирование", Code = 0 },
|
||||||
new OperationCategory {Id = 4, OperationType = 0, Name = "Подъем с проработкой" },
|
new WellOperationCategory {Id = 4, Name = "Подъем с проработкой", Code = 0 },
|
||||||
new OperationCategory {Id = 5, OperationType = 0, Name = "Спуск с проработкой" },
|
new WellOperationCategory {Id = 5, Name = "Спуск с проработкой", Code = 0 },
|
||||||
new OperationCategory {Id = 6, OperationType = 0, Name = "Подъем с промывкой" },
|
new WellOperationCategory {Id = 6, Name = "Подъем с промывкой", Code = 0 },
|
||||||
new OperationCategory {Id = 7, OperationType = 0, Name = "Спуск с промывкой" },
|
new WellOperationCategory {Id = 7, Name = "Спуск с промывкой", Code = 0 },
|
||||||
new OperationCategory {Id = 8, OperationType = 0, Name = "Спуск в скважину" },
|
new WellOperationCategory {Id = 8, Name = "Спуск в скважину", Code = 0 },
|
||||||
new OperationCategory {Id = 9, OperationType = 0, Name = "Спуск с вращением" },
|
new WellOperationCategory {Id = 9, Name = "Спуск с вращением", Code = 0 },
|
||||||
new OperationCategory {Id = 10, OperationType = 0, Name = "Подъем из скважины" },
|
new WellOperationCategory {Id = 10, Name = "Подъем из скважины", Code = 0 },
|
||||||
new OperationCategory {Id = 11, OperationType = 0, Name = "Подъем с вращением" },
|
new WellOperationCategory {Id = 11, Name = "Подъем с вращением", Code = 0 },
|
||||||
new OperationCategory {Id = 12, OperationType = 0, Name = "Промывка в покое" },
|
new WellOperationCategory {Id = 12, Name = "Промывка в покое", Code = 0 },
|
||||||
new OperationCategory {Id = 13, OperationType = 0, Name = "Промывка с вращением" },
|
new WellOperationCategory {Id = 13, Name = "Промывка с вращением", Code = 0 },
|
||||||
new OperationCategory {Id = 14, OperationType = 0, Name = "Удержание в клиньях" },
|
new WellOperationCategory {Id = 14, Name = "Удержание в клиньях", Code = 0 },
|
||||||
new OperationCategory {Id = 15, OperationType = 0, Name = "Неподвижное состояние" },
|
new WellOperationCategory {Id = 15, Name = "Неподвижное состояние", Code = 0 },
|
||||||
new OperationCategory {Id = 16, OperationType = 0, Name = "Вращение без циркуляции" },
|
new WellOperationCategory {Id = 16, Name = "Вращение без циркуляции", Code = 0 },
|
||||||
new OperationCategory {Id = 17, OperationType = 0, Name = "На поверхности" }
|
new WellOperationCategory {Id = 17, Name = "На поверхности", Code = 0 }
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
@ -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<OperationCategory> TelemetryOperations { get; set; }
|
DbSet<WellOperationCategory> 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; }
|
||||||
|
@ -28,8 +28,8 @@ namespace AsbCloudDb.Model
|
|||||||
|
|
||||||
[JsonIgnore]
|
[JsonIgnore]
|
||||||
[ForeignKey(nameof(IdOperation))]
|
[ForeignKey(nameof(IdOperation))]
|
||||||
[InverseProperty(nameof(Model.OperationCategory.Analysis))]
|
[InverseProperty(nameof(Model.WellOperationCategory.Analysis))]
|
||||||
public virtual OperationCategory Operation { get; set; }
|
public virtual WellOperationCategory Operation { get; set; }
|
||||||
|
|
||||||
|
|
||||||
[Column("unix_date", TypeName = "bigint"), Comment("Unix timestamp для Linq запросов с вычислением дат")]
|
[Column("unix_date", TypeName = "bigint"), Comment("Unix timestamp для Linq запросов с вычислением дат")]
|
||||||
|
@ -20,7 +20,7 @@ namespace AsbCloudDb.Model
|
|||||||
public int IdWellSectionType { get; set; }
|
public int IdWellSectionType { get; set; }
|
||||||
|
|
||||||
[Column("id_category"), Comment("Id категории операции")]
|
[Column("id_category"), Comment("Id категории операции")]
|
||||||
public int IdCategory { get; set; }
|
public int IdOperationCategory { get; set; }
|
||||||
|
|
||||||
[Column("type"), Comment("План или Факт")]
|
[Column("type"), Comment("План или Факт")]
|
||||||
public string Type { get; set; }
|
public string Type { get; set; }
|
||||||
@ -49,7 +49,7 @@ namespace AsbCloudDb.Model
|
|||||||
public virtual WellSectionType WellSectionType { get; set; }
|
public virtual WellSectionType WellSectionType { get; set; }
|
||||||
|
|
||||||
[JsonIgnore]
|
[JsonIgnore]
|
||||||
[ForeignKey(nameof(IdCategory))]
|
[ForeignKey(nameof(IdOperationCategory))]
|
||||||
public virtual OperationCategory OperationCategory { get; set; }
|
public virtual WellOperationCategory OperationCategory { get; set; }
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -6,16 +6,13 @@ using System.ComponentModel.DataAnnotations.Schema;
|
|||||||
namespace AsbCloudDb.Model
|
namespace AsbCloudDb.Model
|
||||||
{
|
{
|
||||||
[Table("t_operation"), Comment("Справочник операций на скважине")]
|
[Table("t_operation"), Comment("Справочник операций на скважине")]
|
||||||
public class OperationCategory
|
public class WellOperationCategory
|
||||||
{
|
{
|
||||||
[Key]
|
[Key]
|
||||||
[Column("id")]
|
[Column("id")]
|
||||||
public int Id { get; set; }
|
public int Id { get; set; }
|
||||||
|
|
||||||
[Column("type"), Comment("Тип операции (авто/ручной ввод)")]
|
[Column("name"), Comment("Название категории операции")]
|
||||||
public int OperationType { get; set; }
|
|
||||||
|
|
||||||
[Column("name"), Comment("Название операции")]
|
|
||||||
public string Name { get; set; }
|
public string Name { get; set; }
|
||||||
|
|
||||||
[Column("code"), Comment("Код операции")]
|
[Column("code"), Comment("Код операции")]
|
@ -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<OperationCategory> cacheOperations;
|
private readonly CacheTable<WellOperationCategory> cacheOperations;
|
||||||
private readonly TelemetryOperationDetectorService operationDetectorService;
|
private readonly TelemetryOperationDetectorService operationDetectorService;
|
||||||
private readonly IEnumerable<OperationCategory> operations;
|
private readonly IEnumerable<WellOperationCategory> operations;
|
||||||
|
|
||||||
public TelemetryAnalyticsService(IAsbCloudDbContext db, ITelemetryService telemetryService,
|
public TelemetryAnalyticsService(IAsbCloudDbContext db, ITelemetryService telemetryService,
|
||||||
ISaubDataCache saubDataCache, CacheDb cacheDb)
|
ISaubDataCache saubDataCache, CacheDb cacheDb)
|
||||||
@ -27,8 +27,8 @@ namespace AsbCloudInfrastructure.Services
|
|||||||
this.db = db;
|
this.db = db;
|
||||||
this.telemetryService = telemetryService;
|
this.telemetryService = telemetryService;
|
||||||
this.saubDataCache = saubDataCache;
|
this.saubDataCache = saubDataCache;
|
||||||
cacheOperations = cacheDb.GetCachedTable<OperationCategory>((AsbCloudDbContext)db);
|
cacheOperations = cacheDb.GetCachedTable<WellOperationCategory>((AsbCloudDbContext)db);
|
||||||
operations = cacheOperations.Where(c => true);
|
operations = cacheOperations.Where();
|
||||||
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 OperationCategory Operation { get; set; }
|
public WellOperationCategory 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<OperationCategory> operations)
|
public TelemetryOperationDetectorService(IEnumerable<WellOperationCategory> operations)
|
||||||
{
|
{
|
||||||
detectors = new List<TelemetryOperationDetector>()
|
detectors = new List<TelemetryOperationDetector>()
|
||||||
{
|
{
|
||||||
@ -180,8 +180,8 @@ namespace AsbCloudInfrastructure.Services
|
|||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
public OperationCategory DetectOperation(TelemetryAnalysisDto data) =>
|
public WellOperationCategory 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 OperationCategory { Id = 1, Name = "Невозможно определить операцию" };
|
?? new WellOperationCategory { Id = 1, Name = "Невозможно определить операцию" };
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1,4 +1,5 @@
|
|||||||
using System.Linq;
|
using System.Collections.Generic;
|
||||||
|
using System.Linq;
|
||||||
using System.Threading;
|
using System.Threading;
|
||||||
using System.Threading.Tasks;
|
using System.Threading.Tasks;
|
||||||
using Microsoft.EntityFrameworkCore;
|
using Microsoft.EntityFrameworkCore;
|
||||||
@ -13,21 +14,34 @@ namespace AsbCloudInfrastructure.Services
|
|||||||
public class WellOperationService : IWellOperationService
|
public class WellOperationService : IWellOperationService
|
||||||
{
|
{
|
||||||
private readonly IAsbCloudDbContext context;
|
private readonly IAsbCloudDbContext context;
|
||||||
private readonly DbSet<WellOperation> dbSet;
|
private readonly CacheTable<WellOperationCategory> cachedOperationTypes;
|
||||||
private readonly CacheTable<OperationCategory> cachedOperationTypes;
|
|
||||||
|
|
||||||
public WellOperationService(IAsbCloudDbContext context, Cache.CacheDb cache)
|
public WellOperationService(IAsbCloudDbContext context, Cache.CacheDb cache)
|
||||||
{
|
{
|
||||||
this.context = context;
|
this.context = context;
|
||||||
dbSet = context.Set<WellOperation>();
|
cachedOperationTypes = cache.GetCachedTable<WellOperationCategory>((DbContext)context);
|
||||||
cachedOperationTypes = cache.GetCachedTable<OperationCategory>((DbContext)context);
|
}
|
||||||
|
|
||||||
|
public IEnumerable<WellOperationCategoryDto> GetTypes()
|
||||||
|
{
|
||||||
|
var operationTypes = cachedOperationTypes.Where().Distinct();
|
||||||
|
var result = new List<WellOperationCategoryDto>();
|
||||||
|
|
||||||
|
foreach(var op in operationTypes)
|
||||||
|
{
|
||||||
|
var dto = op.Adapt<WellOperationCategoryDto>();
|
||||||
|
result.Add(dto);
|
||||||
|
}
|
||||||
|
|
||||||
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
public async Task<PaginationContainer<WellOperationDto>> GetAllByWellIdAsync(int idWell,
|
public async Task<PaginationContainer<WellOperationDto>> GetAllByWellIdAsync(int idWell,
|
||||||
int skip = 0, int take = 32, CancellationToken token = default)
|
int skip = 0, int take = 32, CancellationToken token = default)
|
||||||
{
|
{
|
||||||
var query = dbSet
|
var query = context.WellOperations
|
||||||
.Include(s => s.WellSectionType)
|
.Include(s => s.WellSectionType)
|
||||||
|
.Include(s => s.OperationCategory)
|
||||||
.Where(s => s.IdWell == idWell)
|
.Where(s => s.IdWell == idWell)
|
||||||
.AsNoTracking();
|
.AsNoTracking();
|
||||||
|
|
||||||
@ -46,16 +60,77 @@ namespace AsbCloudInfrastructure.Services
|
|||||||
|
|
||||||
query = query.Take(take);
|
query = query.Take(take);
|
||||||
|
|
||||||
var entities = await query.Take(take).ToListAsync(token).ConfigureAwait(false);
|
var entities = await query.Take(take)
|
||||||
|
.ToListAsync(token).ConfigureAwait(false);
|
||||||
|
|
||||||
foreach (var item in entities)
|
foreach (var item in entities)
|
||||||
{
|
{
|
||||||
var dto = item.Adapt<WellOperationDto>();
|
var dto = item.Adapt<WellOperationDto>();
|
||||||
//dto.SectionType = item.WellSectionType.Caption;
|
dto.WellSectionTypeName = item.WellSectionType.Caption;
|
||||||
|
dto.CategoryName = item.OperationCategory.Name;
|
||||||
result.Items.Add(dto);
|
result.Items.Add(dto);
|
||||||
}
|
}
|
||||||
|
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public async Task<WellOperationDto> GetAsync(int id,
|
||||||
|
CancellationToken token = default)
|
||||||
|
{
|
||||||
|
var entity = await context.WellOperations
|
||||||
|
.Include(s => s.WellSectionType)
|
||||||
|
.Include(s => s.OperationCategory)
|
||||||
|
.FirstOrDefaultAsync(e => e.Id == id, token)
|
||||||
|
.ConfigureAwait(false);
|
||||||
|
|
||||||
|
if (entity is null)
|
||||||
|
return null;
|
||||||
|
|
||||||
|
var dto = entity.Adapt<WellOperationDto>();
|
||||||
|
dto.WellSectionTypeName = entity.WellSectionType.Caption;
|
||||||
|
dto.CategoryName = entity.OperationCategory.Name;
|
||||||
|
return dto;
|
||||||
|
}
|
||||||
|
|
||||||
|
public async Task<int> InsertAsync(WellOperationDto wellOperationDto,
|
||||||
|
int idWell, CancellationToken token = default)
|
||||||
|
{
|
||||||
|
var entity = wellOperationDto.Adapt<WellOperation>();
|
||||||
|
context.WellOperations.Add(entity);
|
||||||
|
return await context.SaveChangesAsync(token)
|
||||||
|
.ConfigureAwait(false);
|
||||||
|
}
|
||||||
|
|
||||||
|
public async Task<int> InsertRangeAsync(int idWell,
|
||||||
|
IEnumerable<WellOperationDto> wellOperationDtos,
|
||||||
|
CancellationToken token = default)
|
||||||
|
{
|
||||||
|
foreach(var operationDto in wellOperationDtos)
|
||||||
|
{
|
||||||
|
var entity = operationDto.Adapt<WellOperation>();
|
||||||
|
context.WellOperations.Add(entity);
|
||||||
|
}
|
||||||
|
|
||||||
|
return await context.SaveChangesAsync(token)
|
||||||
|
.ConfigureAwait(false);
|
||||||
|
}
|
||||||
|
|
||||||
|
public async Task<int> UpdateAsync(int idWell, int idSection,
|
||||||
|
WellOperationDto item, CancellationToken token = default)
|
||||||
|
{
|
||||||
|
var entity = item.Adapt<WellOperation>();
|
||||||
|
context.WellOperations.Update(entity);
|
||||||
|
return await context.SaveChangesAsync(token)
|
||||||
|
.ConfigureAwait(false);
|
||||||
|
}
|
||||||
|
|
||||||
|
public async Task<int> DeleteAsync(IEnumerable<int> ids,
|
||||||
|
CancellationToken token = default)
|
||||||
|
{
|
||||||
|
var entities = context.WellOperations.Where(e => ids.Contains(e.Id));
|
||||||
|
context.WellOperations.RemoveRange(entities);
|
||||||
|
return await context.SaveChangesAsync(token)
|
||||||
|
.ConfigureAwait(false);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1,4 +1,5 @@
|
|||||||
using System.Threading;
|
using System.Collections.Generic;
|
||||||
|
using System.Threading;
|
||||||
using System.Threading.Tasks;
|
using System.Threading.Tasks;
|
||||||
using AsbCloudApp.Data;
|
using AsbCloudApp.Data;
|
||||||
using AsbCloudApp.Services;
|
using AsbCloudApp.Services;
|
||||||
@ -8,9 +9,9 @@ using Microsoft.AspNetCore.Authorization;
|
|||||||
namespace AsbCloudWebApi.Controllers
|
namespace AsbCloudWebApi.Controllers
|
||||||
{
|
{
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Контроллер операций на скважине
|
/// Контроллер вручную внесенных операций на скважине
|
||||||
/// </summary>
|
/// </summary>
|
||||||
[Route("api/wellOperation")]
|
[Route("api/wellOperations")]
|
||||||
[ApiController]
|
[ApiController]
|
||||||
[Authorize]
|
[Authorize]
|
||||||
public class WellOperationController : ControllerBase
|
public class WellOperationController : ControllerBase
|
||||||
@ -24,8 +25,29 @@ namespace AsbCloudWebApi.Controllers
|
|||||||
this.wellService = wellService;
|
this.wellService = wellService;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Возвращает список имен типов операций на скважине
|
||||||
|
/// </summary>
|
||||||
|
/// <returns></returns>
|
||||||
[HttpGet]
|
[HttpGet]
|
||||||
[ProducesResponseType(typeof(PaginationContainer<WellSectionDto>), (int)System.Net.HttpStatusCode.OK)]
|
[Route("types")]
|
||||||
|
[ProducesResponseType(typeof(IEnumerable<string>), (int)System.Net.HttpStatusCode.OK)]
|
||||||
|
public IActionResult GetTypesAsync()
|
||||||
|
{
|
||||||
|
var result = operationService.GetTypes();
|
||||||
|
return Ok(result);
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Возвращает весь список операций на скважине
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="idWell">id скважины</param>
|
||||||
|
/// <param name="skip">Для пагинации кол-во записей пропустить</param>
|
||||||
|
/// <param name="take">Для пагинации кол-во записей</param>
|
||||||
|
/// <param name="token">Токен отмены задачи</param>
|
||||||
|
/// <returns>Список операций на скважине</returns>
|
||||||
|
[HttpGet]
|
||||||
|
[ProducesResponseType(typeof(PaginationContainer<WellOperationDto>), (int)System.Net.HttpStatusCode.OK)]
|
||||||
public async Task<IActionResult> GetAllAsync(int idWell, int skip = 0, int take = 32,
|
public async Task<IActionResult> GetAllAsync(int idWell, int skip = 0, int take = 32,
|
||||||
CancellationToken token = default)
|
CancellationToken token = default)
|
||||||
{
|
{
|
||||||
@ -36,6 +58,88 @@ namespace AsbCloudWebApi.Controllers
|
|||||||
return Ok(result);
|
return Ok(result);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Возвращает нужную операцию на скважине
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="idWell">id скважины</param>
|
||||||
|
/// <param name="idOperation">id нужной операции</param>
|
||||||
|
/// <param name="token">Токен отмены задачи</param>
|
||||||
|
/// <returns>Нужную операцию на скважине</returns>
|
||||||
|
[HttpGet]
|
||||||
|
[Route("{idOperation}")]
|
||||||
|
[ProducesResponseType(typeof(WellOperationDto), (int)System.Net.HttpStatusCode.OK)]
|
||||||
|
public async Task<IActionResult> GetAsync(int idWell, int idOperation,
|
||||||
|
CancellationToken token = default)
|
||||||
|
{
|
||||||
|
if (!await CanUserAccessToWellAsync(idWell, token).ConfigureAwait(false))
|
||||||
|
return Forbid();
|
||||||
|
|
||||||
|
var result = await operationService.GetAsync(idOperation, token).ConfigureAwait(false);
|
||||||
|
return Ok(result);
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Добавляет новые операции на скважине
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="idWell">id скважины</param>
|
||||||
|
/// <param name="values">Данные о добавляемых операциях</param>
|
||||||
|
/// <param name="token">Токен отмены задачи</param>
|
||||||
|
/// <returns>Количество добавленых в БД строк</returns>
|
||||||
|
[HttpPost]
|
||||||
|
[ProducesResponseType(typeof(IEnumerable<WellOperationDto>), (int)System.Net.HttpStatusCode.OK)]
|
||||||
|
public async Task<IActionResult> InsertRangeAsync(int idWell, [FromBody] IEnumerable<WellOperationDto> values,
|
||||||
|
CancellationToken token = default)
|
||||||
|
{
|
||||||
|
if (!await CanUserAccessToWellAsync(idWell, token).ConfigureAwait(false))
|
||||||
|
return Forbid();
|
||||||
|
|
||||||
|
var result = await operationService.InsertRangeAsync(idWell, values, token)
|
||||||
|
.ConfigureAwait(false);
|
||||||
|
return Ok(result);
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Обновляет выбранную операцию на скважине
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="idWell">id скважины</param>
|
||||||
|
/// <param name="idOperation">id выбраной операции</param>
|
||||||
|
/// <param name="value">Новые данные для выбраной операции</param>
|
||||||
|
/// <param name="token">Токен отмены задачи</param>
|
||||||
|
/// <returns>Количество обновленных в БД строк</returns>
|
||||||
|
[HttpPut("{idOperation}")]
|
||||||
|
[ProducesResponseType(typeof(WellOperationDto), (int)System.Net.HttpStatusCode.OK)]
|
||||||
|
public async Task<IActionResult> UpdateAsync(int idWell, int idOperation,
|
||||||
|
[FromBody] WellOperationDto value, CancellationToken token = default)
|
||||||
|
{
|
||||||
|
if (!await CanUserAccessToWellAsync(idWell, token).ConfigureAwait(false))
|
||||||
|
return Forbid();
|
||||||
|
|
||||||
|
var result = await operationService.UpdateAsync(idWell, idOperation, value, token)
|
||||||
|
.ConfigureAwait(false);
|
||||||
|
return Ok(result);
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Удаляет выбраную операцию на скважине
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="idWell">id скважины</param>
|
||||||
|
/// <param name="idOperation">id выбраной операции</param>
|
||||||
|
/// <param name="token">Токен отмены задачи</param>
|
||||||
|
/// <returns>Количество удаленных из БД строк</returns>
|
||||||
|
[HttpDelete("{idOperation}")]
|
||||||
|
[ProducesResponseType(typeof(int), (int)System.Net.HttpStatusCode.OK)]
|
||||||
|
public async Task<IActionResult> DeleteAsync(int idWell, int idOperation, CancellationToken token = default)
|
||||||
|
{
|
||||||
|
if (!await CanUserAccessToWellAsync(idWell,
|
||||||
|
token).ConfigureAwait(false))
|
||||||
|
return Forbid();
|
||||||
|
|
||||||
|
var result = await operationService.DeleteAsync(new int[] { idOperation }, token)
|
||||||
|
.ConfigureAwait(false);
|
||||||
|
|
||||||
|
return Ok(result);
|
||||||
|
}
|
||||||
|
|
||||||
private async Task<bool> CanUserAccessToWellAsync(int idWell, CancellationToken token = default)
|
private async Task<bool> CanUserAccessToWellAsync(int idWell, CancellationToken token = default)
|
||||||
{
|
{
|
||||||
int? idCompany = User.GetCompanyId();
|
int? idCompany = User.GetCompanyId();
|
||||||
|
Loading…
Reference in New Issue
Block a user