remove ISubsystemService (not used)

This commit is contained in:
ngfrolov 2023-11-28 16:57:01 +05:00
parent dd99497e75
commit 75e7093af8
Signed by untrusted user who does not match committer: ng.frolov
GPG Key ID: E99907A0357B29A7
4 changed files with 8 additions and 104 deletions

View File

@ -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);
}
}

View File

@ -267,11 +267,9 @@ namespace AsbCloudInfrastructure
services.AddTransient<IWellContactService, WellContactService>(); services.AddTransient<IWellContactService, WellContactService>();
services.AddTransient<ICrudRepository<WellSectionTypeDto>, CrudCacheRepositoryBase<WellSectionTypeDto, services.AddTransient<ICrudRepository<WellSectionTypeDto>, CrudCacheRepositoryBase<WellSectionTypeDto,
WellSectionType>>(); WellSectionType>>();
// Subsystem service
services.AddTransient<ICrudRepository<SubsystemDto>, CrudCacheRepositoryBase<SubsystemDto, Subsystem>>(); services.AddTransient<ICrudRepository<SubsystemDto>, CrudCacheRepositoryBase<SubsystemDto, Subsystem>>();
services.AddTransient<ISubsystemService, SubsystemService>();
services.AddTransient<ICrudRepository<PermissionDto>, CrudCacheRepositoryBase<PermissionDto, Permission>>(); services.AddTransient<ICrudRepository<PermissionDto>, CrudCacheRepositoryBase<PermissionDto, Permission>>();
// TelemetryData services // TelemetryData services

View File

@ -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;
}
}
}

View File

@ -24,7 +24,6 @@ namespace AsbCloudWebApi.Controllers.Subsystems
private readonly ISubsystemOperationTimeService subsystemOperationTimeService; private readonly ISubsystemOperationTimeService subsystemOperationTimeService;
private readonly ITelemetryDataSaubService telemetryDataSaubService; private readonly ITelemetryDataSaubService telemetryDataSaubService;
private readonly IWellService wellService; private readonly IWellService wellService;
private readonly ISubsystemService subsystemService;
private readonly Dictionary<int, string> subsystemNames = new() private readonly Dictionary<int, string> subsystemNames = new()
{ {
@ -36,12 +35,10 @@ namespace AsbCloudWebApi.Controllers.Subsystems
public SubsystemOperationTimeController( public SubsystemOperationTimeController(
ISubsystemOperationTimeService subsystemOperationTimeService, ISubsystemOperationTimeService subsystemOperationTimeService,
IWellService wellService, IWellService wellService,
ISubsystemService subsystemService,
ITelemetryDataSaubService telemetryDataSaubService) ITelemetryDataSaubService telemetryDataSaubService)
{ {
this.subsystemOperationTimeService = subsystemOperationTimeService; this.subsystemOperationTimeService = subsystemOperationTimeService;
this.wellService = wellService; this.wellService = wellService;
this.subsystemService = subsystemService;
this.telemetryDataSaubService = telemetryDataSaubService; this.telemetryDataSaubService = telemetryDataSaubService;
} }
/// <summary> /// <summary>
@ -52,7 +49,7 @@ namespace AsbCloudWebApi.Controllers.Subsystems
[ProducesResponseType(typeof(ValidationProblemDetails), (int)System.Net.HttpStatusCode.BadRequest)] [ProducesResponseType(typeof(ValidationProblemDetails), (int)System.Net.HttpStatusCode.BadRequest)]
public async Task<IActionResult> GetStatAsync([FromQuery] SubsystemOperationTimeRequest request, CancellationToken token) public async Task<IActionResult> GetStatAsync([FromQuery] SubsystemOperationTimeRequest request, CancellationToken token)
{ {
if (!await UserHasAccesToWellAsync(request.IdWell, token)) if (!await UserHasAccessToWellAsync(request.IdWell, token))
return Forbid(); return Forbid();
var subsystemResult = await subsystemOperationTimeService.GetStatAsync(request, token); var subsystemResult = await subsystemOperationTimeService.GetStatAsync(request, token);
return Ok(subsystemResult); return Ok(subsystemResult);
@ -65,7 +62,7 @@ namespace AsbCloudWebApi.Controllers.Subsystems
[ProducesResponseType(typeof(DatesRangeDto), (int)System.Net.HttpStatusCode.OK)] [ProducesResponseType(typeof(DatesRangeDto), (int)System.Net.HttpStatusCode.OK)]
public async Task<IActionResult> GetStatDateRangeAsync([FromRoute] int idWell, CancellationToken token) public async Task<IActionResult> GetStatDateRangeAsync([FromRoute] int idWell, CancellationToken token)
{ {
if (!await UserHasAccesToWellAsync(idWell, token)) if (!await UserHasAccessToWellAsync(idWell, token))
return Forbid(); return Forbid();
var dateRange = telemetryDataSaubService.GetRange(idWell); var dateRange = telemetryDataSaubService.GetRange(idWell);
@ -91,20 +88,6 @@ namespace AsbCloudWebApi.Controllers.Subsystems
return Ok(subsystemResult); 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>
/// получить доступный диапазон дат наработки подсистемы. /// получить доступный диапазон дат наработки подсистемы.
/// </summary> /// </summary>
@ -112,7 +95,7 @@ namespace AsbCloudWebApi.Controllers.Subsystems
[ProducesResponseType(typeof(DatesRangeDto), (int)System.Net.HttpStatusCode.OK)] [ProducesResponseType(typeof(DatesRangeDto), (int)System.Net.HttpStatusCode.OK)]
public async Task<IActionResult> GetDateRangeOperationTimeAsync([FromQuery] SubsystemOperationTimeRequest request, CancellationToken token) public async Task<IActionResult> GetDateRangeOperationTimeAsync([FromQuery] SubsystemOperationTimeRequest request, CancellationToken token)
{ {
if (!await UserHasAccesToWellAsync(request.IdWell, token)) if (!await UserHasAccessToWellAsync(request.IdWell, token))
return Forbid(); return Forbid();
var result = await subsystemOperationTimeService.GetDateRangeOperationTimeAsync(request, token); var result = await subsystemOperationTimeService.GetDateRangeOperationTimeAsync(request, token);
return Ok(result); return Ok(result);
@ -128,7 +111,7 @@ namespace AsbCloudWebApi.Controllers.Subsystems
[FromQuery] SubsystemOperationTimeRequest request, [FromQuery] SubsystemOperationTimeRequest request,
CancellationToken token) CancellationToken token)
{ {
if (!await UserHasAccesToWellAsync(request.IdWell, token)) if (!await UserHasAccessToWellAsync(request.IdWell, token))
return Forbid(); return Forbid();
var result = await subsystemOperationTimeService.GetOperationTimeAsync(request, token); var result = await subsystemOperationTimeService.GetOperationTimeAsync(request, token);
@ -149,7 +132,7 @@ namespace AsbCloudWebApi.Controllers.Subsystems
[FromQuery] SubsystemOperationTimeRequest request, [FromQuery] SubsystemOperationTimeRequest request,
CancellationToken token) CancellationToken token)
{ {
if (!await UserHasAccesToWellAsync(request.IdWell, token)) if (!await UserHasAccessToWellAsync(request.IdWell, token))
return Forbid(); return Forbid();
var result = await subsystemOperationTimeService.DeleteAsync(request, token); var result = await subsystemOperationTimeService.DeleteAsync(request, token);
return Ok(result); return Ok(result);
@ -166,7 +149,7 @@ namespace AsbCloudWebApi.Controllers.Subsystems
return Ok(subsystemNames); 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(); var idCompany = User.GetCompanyId();
if (idCompany is not null && if (idCompany is not null &&