forked from ddrilling/AsbCloudServer
54 lines
1.9 KiB
C#
54 lines
1.9 KiB
C#
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 System.Collections.Generic;
|
|
using System.Linq;
|
|
using System.Threading;
|
|
using System.Threading.Tasks;
|
|
|
|
namespace AsbCloudInfrastructure.Services.Subsystems
|
|
{
|
|
#nullable enable
|
|
internal class SubsystemService : CrudCacheServiceBase<SubsystemDto, Subsystem>, ISubsystemService
|
|
{
|
|
private readonly IWellService wellService;
|
|
public SubsystemService(IAsbCloudDbContext dbContext, IWellService wellService) : base(dbContext)
|
|
{
|
|
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;
|
|
}
|
|
}
|
|
#nullable disable
|
|
}
|