2022-07-14 03:47:11 +05:00
|
|
|
|
using AsbCloudApp.Data.Subsystems;
|
2022-08-15 15:08:17 +05:00
|
|
|
|
using AsbCloudApp.Services;
|
|
|
|
|
using AsbCloudApp.Services.Subsystems;
|
2022-07-14 03:47:11 +05:00
|
|
|
|
using AsbCloudDb.Model;
|
|
|
|
|
using AsbCloudDb.Model.Subsystems;
|
|
|
|
|
using AsbCloudInfrastructure.Repository;
|
2022-08-15 15:08:17 +05:00
|
|
|
|
using Mapster;
|
|
|
|
|
using Microsoft.EntityFrameworkCore;
|
2022-11-17 16:09:51 +05:00
|
|
|
|
using Microsoft.Extensions.Caching.Memory;
|
2022-08-15 15:08:17 +05:00
|
|
|
|
using System.Collections.Generic;
|
|
|
|
|
using System.Linq;
|
|
|
|
|
using System.Threading;
|
|
|
|
|
using System.Threading.Tasks;
|
2022-07-14 03:47:11 +05:00
|
|
|
|
|
|
|
|
|
namespace AsbCloudInfrastructure.Services.Subsystems
|
|
|
|
|
{
|
2022-08-15 15:08:17 +05:00
|
|
|
|
#nullable enable
|
2022-12-01 15:56:11 +05:00
|
|
|
|
internal class SubsystemService : CrudCacheRepositoryBase<SubsystemDto, Subsystem>, ISubsystemService
|
2022-08-15 15:08:17 +05:00
|
|
|
|
{
|
|
|
|
|
private readonly IWellService wellService;
|
2022-11-17 16:09:51 +05:00
|
|
|
|
public SubsystemService(IAsbCloudDbContext dbContext, IMemoryCache memoryCache, IWellService wellService) : base(dbContext, memoryCache)
|
2022-08-15 15:08:17 +05:00
|
|
|
|
{
|
|
|
|
|
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;
|
2022-09-07 18:01:39 +05:00
|
|
|
|
var entities = await dbContext.SubsystemOperationTimes
|
2022-08-15 15:08:17 +05:00
|
|
|
|
.Include(e => e.Subsystem)
|
|
|
|
|
.AsNoTracking()
|
|
|
|
|
.Where(o => o.IdTelemetry == well.IdTelemetry)
|
2022-09-07 18:01:39 +05:00
|
|
|
|
.Select(o => o.Subsystem)
|
|
|
|
|
.Distinct()
|
|
|
|
|
.ToArrayAsync(token);
|
|
|
|
|
var dtos = entities.Select(e => e.Adapt<SubsystemDto>());
|
|
|
|
|
return dtos;
|
2022-08-15 15:08:17 +05:00
|
|
|
|
}
|
2022-09-07 18:01:39 +05:00
|
|
|
|
|
2022-08-15 15:08:17 +05:00
|
|
|
|
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;
|
|
|
|
|
}
|
2022-07-14 03:47:11 +05:00
|
|
|
|
}
|
2022-08-15 15:08:17 +05:00
|
|
|
|
#nullable disable
|
2022-07-14 03:47:11 +05:00
|
|
|
|
}
|