forked from ddrilling/AsbCloudServer
remove ISubsystemService (not used)
This commit is contained in:
parent
dd99497e75
commit
75e7093af8
@ -1,23 +0,0 @@
|
||||
using AsbCloudApp.Data.Subsystems;
|
||||
using System.Collections.Generic;
|
||||
using System.Threading;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace AsbCloudApp.Services.Subsystems
|
||||
{
|
||||
// TODO: move this to repositories
|
||||
|
||||
/// <summary>
|
||||
/// репозиторий получения подсистем
|
||||
/// </summary>
|
||||
public interface ISubsystemService
|
||||
{
|
||||
/// <summary>
|
||||
/// получение списка подсистем. Если скважина указана, то получим только использованные в скважине подсистемы.
|
||||
/// </summary>
|
||||
/// <param name="idWell"></param>
|
||||
/// <param name="token"></param>
|
||||
/// <returns></returns>
|
||||
Task<IEnumerable<SubsystemDto>?> GetSubsystemAsync(int? idWell, CancellationToken token);
|
||||
}
|
||||
}
|
@ -267,11 +267,9 @@ namespace AsbCloudInfrastructure
|
||||
services.AddTransient<IWellContactService, WellContactService>();
|
||||
services.AddTransient<ICrudRepository<WellSectionTypeDto>, CrudCacheRepositoryBase<WellSectionTypeDto,
|
||||
WellSectionType>>();
|
||||
|
||||
// Subsystem service
|
||||
|
||||
services.AddTransient<ICrudRepository<SubsystemDto>, CrudCacheRepositoryBase<SubsystemDto, Subsystem>>();
|
||||
services.AddTransient<ISubsystemService, SubsystemService>();
|
||||
|
||||
|
||||
services.AddTransient<ICrudRepository<PermissionDto>, CrudCacheRepositoryBase<PermissionDto, Permission>>();
|
||||
|
||||
// TelemetryData services
|
||||
|
@ -1,54 +0,0 @@
|
||||
using AsbCloudApp.Data.Subsystems;
|
||||
using AsbCloudApp.Services;
|
||||
using AsbCloudApp.Services.Subsystems;
|
||||
using AsbCloudDb.Model;
|
||||
using AsbCloudDb.Model.Subsystems;
|
||||
using AsbCloudInfrastructure.Repository;
|
||||
using Mapster;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using Microsoft.Extensions.Caching.Memory;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Threading;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace AsbCloudInfrastructure.Services.Subsystems
|
||||
{
|
||||
|
||||
internal class SubsystemService : CrudCacheRepositoryBase<SubsystemDto, Subsystem>, ISubsystemService
|
||||
{
|
||||
private readonly IWellService wellService;
|
||||
public SubsystemService(IAsbCloudDbContext dbContext, IMemoryCache memoryCache, IWellService wellService) : base(dbContext, memoryCache)
|
||||
{
|
||||
this.wellService = wellService;
|
||||
}
|
||||
|
||||
private async Task<IEnumerable<SubsystemDto>?> GetSubsystemByIdWellAsync(int idWell, CancellationToken token)
|
||||
{
|
||||
var well = await wellService.GetOrDefaultAsync(idWell, token);
|
||||
if (well?.IdTelemetry is null || well.Timezone is null)
|
||||
return null;
|
||||
var entities = await dbContext.SubsystemOperationTimes
|
||||
.Include(e => e.Subsystem)
|
||||
.AsNoTracking()
|
||||
.Where(o => o.IdTelemetry == well.IdTelemetry)
|
||||
.Select(o => o.Subsystem)
|
||||
.Distinct()
|
||||
.ToArrayAsync(token);
|
||||
var dtos = entities.Select(e => e.Adapt<SubsystemDto>());
|
||||
return dtos;
|
||||
}
|
||||
|
||||
public async Task<IEnumerable<SubsystemDto>?> GetSubsystemAsync(int? idWell, CancellationToken token)
|
||||
{
|
||||
if (idWell.HasValue)
|
||||
{
|
||||
var subsystemWell = await GetSubsystemByIdWellAsync(idWell.Value, token);
|
||||
return subsystemWell;
|
||||
}
|
||||
var subsystem = await GetAllAsync(token);
|
||||
return subsystem;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
@ -24,7 +24,6 @@ namespace AsbCloudWebApi.Controllers.Subsystems
|
||||
private readonly ISubsystemOperationTimeService subsystemOperationTimeService;
|
||||
private readonly ITelemetryDataSaubService telemetryDataSaubService;
|
||||
private readonly IWellService wellService;
|
||||
private readonly ISubsystemService subsystemService;
|
||||
|
||||
private readonly Dictionary<int, string> subsystemNames = new()
|
||||
{
|
||||
@ -36,12 +35,10 @@ namespace AsbCloudWebApi.Controllers.Subsystems
|
||||
public SubsystemOperationTimeController(
|
||||
ISubsystemOperationTimeService subsystemOperationTimeService,
|
||||
IWellService wellService,
|
||||
ISubsystemService subsystemService,
|
||||
ITelemetryDataSaubService telemetryDataSaubService)
|
||||
{
|
||||
this.subsystemOperationTimeService = subsystemOperationTimeService;
|
||||
this.wellService = wellService;
|
||||
this.subsystemService = subsystemService;
|
||||
this.telemetryDataSaubService = telemetryDataSaubService;
|
||||
}
|
||||
/// <summary>
|
||||
@ -52,7 +49,7 @@ namespace AsbCloudWebApi.Controllers.Subsystems
|
||||
[ProducesResponseType(typeof(ValidationProblemDetails), (int)System.Net.HttpStatusCode.BadRequest)]
|
||||
public async Task<IActionResult> GetStatAsync([FromQuery] SubsystemOperationTimeRequest request, CancellationToken token)
|
||||
{
|
||||
if (!await UserHasAccesToWellAsync(request.IdWell, token))
|
||||
if (!await UserHasAccessToWellAsync(request.IdWell, token))
|
||||
return Forbid();
|
||||
var subsystemResult = await subsystemOperationTimeService.GetStatAsync(request, token);
|
||||
return Ok(subsystemResult);
|
||||
@ -65,7 +62,7 @@ namespace AsbCloudWebApi.Controllers.Subsystems
|
||||
[ProducesResponseType(typeof(DatesRangeDto), (int)System.Net.HttpStatusCode.OK)]
|
||||
public async Task<IActionResult> GetStatDateRangeAsync([FromRoute] int idWell, CancellationToken token)
|
||||
{
|
||||
if (!await UserHasAccesToWellAsync(idWell, token))
|
||||
if (!await UserHasAccessToWellAsync(idWell, token))
|
||||
return Forbid();
|
||||
|
||||
var dateRange = telemetryDataSaubService.GetRange(idWell);
|
||||
@ -91,20 +88,6 @@ namespace AsbCloudWebApi.Controllers.Subsystems
|
||||
return Ok(subsystemResult);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// получить список подсистем общий.
|
||||
/// </summary>
|
||||
[HttpGet("subsystem")]
|
||||
[ProducesResponseType(typeof(IEnumerable<SubsystemDto>), (int)System.Net.HttpStatusCode.OK)]
|
||||
public async Task<IActionResult> GetSubsystemAsync([FromQuery] int? idWell, CancellationToken token)
|
||||
{
|
||||
if (idWell.HasValue)
|
||||
if (!await UserHasAccesToWellAsync(idWell.Value, token))
|
||||
return Forbid();
|
||||
var result = await subsystemService.GetSubsystemAsync(idWell, token);
|
||||
return Ok(result);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// получить доступный диапазон дат наработки подсистемы.
|
||||
/// </summary>
|
||||
@ -112,7 +95,7 @@ namespace AsbCloudWebApi.Controllers.Subsystems
|
||||
[ProducesResponseType(typeof(DatesRangeDto), (int)System.Net.HttpStatusCode.OK)]
|
||||
public async Task<IActionResult> GetDateRangeOperationTimeAsync([FromQuery] SubsystemOperationTimeRequest request, CancellationToken token)
|
||||
{
|
||||
if (!await UserHasAccesToWellAsync(request.IdWell, token))
|
||||
if (!await UserHasAccessToWellAsync(request.IdWell, token))
|
||||
return Forbid();
|
||||
var result = await subsystemOperationTimeService.GetDateRangeOperationTimeAsync(request, token);
|
||||
return Ok(result);
|
||||
@ -128,7 +111,7 @@ namespace AsbCloudWebApi.Controllers.Subsystems
|
||||
[FromQuery] SubsystemOperationTimeRequest request,
|
||||
CancellationToken token)
|
||||
{
|
||||
if (!await UserHasAccesToWellAsync(request.IdWell, token))
|
||||
if (!await UserHasAccessToWellAsync(request.IdWell, token))
|
||||
return Forbid();
|
||||
|
||||
var result = await subsystemOperationTimeService.GetOperationTimeAsync(request, token);
|
||||
@ -149,7 +132,7 @@ namespace AsbCloudWebApi.Controllers.Subsystems
|
||||
[FromQuery] SubsystemOperationTimeRequest request,
|
||||
CancellationToken token)
|
||||
{
|
||||
if (!await UserHasAccesToWellAsync(request.IdWell, token))
|
||||
if (!await UserHasAccessToWellAsync(request.IdWell, token))
|
||||
return Forbid();
|
||||
var result = await subsystemOperationTimeService.DeleteAsync(request, token);
|
||||
return Ok(result);
|
||||
@ -166,7 +149,7 @@ namespace AsbCloudWebApi.Controllers.Subsystems
|
||||
return Ok(subsystemNames);
|
||||
}
|
||||
|
||||
protected async Task<bool> UserHasAccesToWellAsync(int idWell, CancellationToken token)
|
||||
protected async Task<bool> UserHasAccessToWellAsync(int idWell, CancellationToken token)
|
||||
{
|
||||
var idCompany = User.GetCompanyId();
|
||||
if (idCompany is not null &&
|
||||
|
Loading…
Reference in New Issue
Block a user