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;
|
|
|
|
|
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
|
|
|
|
|
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 wellSubsystem = await dbContext.SubsystemOperationTimes
|
|
|
|
|
.Include(e => e.Subsystem)
|
|
|
|
|
.AsNoTracking()
|
|
|
|
|
.Where(o => o.IdTelemetry == well.IdTelemetry)
|
|
|
|
|
.DistinctBy(o => o.IdSubsystem)
|
|
|
|
|
.Select(d => Convert( new ()
|
|
|
|
|
{
|
|
|
|
|
Id = d.Subsystem.Id,
|
|
|
|
|
Name = d.Subsystem.Name,
|
|
|
|
|
Description = d.Subsystem.Description,
|
|
|
|
|
|
|
|
|
|
}))
|
|
|
|
|
.ToListAsync(token);
|
|
|
|
|
return wellSubsystem;
|
|
|
|
|
}
|
|
|
|
|
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;
|
|
|
|
|
}
|
|
|
|
|
new private static SubsystemDto Convert(Subsystem subsystem)
|
2022-07-14 03:47:11 +05:00
|
|
|
|
{
|
2022-08-15 15:08:17 +05:00
|
|
|
|
var dto = subsystem.Adapt<SubsystemDto>();
|
|
|
|
|
return dto;
|
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
|
|
|
|
}
|