forked from ddrilling/AsbCloudServer
- В SubsystemStatDto свойство UsedTimeHours double. TimeSpan.
- В SubsystemDto свойство Subsystem переименовано в SubsystemName - миграция для заполнения Subsystem - метод bsystemOperationTimeService.GetSubsystemByIdWellAsync перенесен в SubsystemService.
This commit is contained in:
parent
62384b5673
commit
20f79f461f
@ -13,11 +13,11 @@ namespace AsbCloudApp.Data.Subsystems
|
||||
/// <summary>
|
||||
/// Название подсистемы
|
||||
/// </summary>
|
||||
public string Subsystem { get; set; }
|
||||
public string SubsystemName { get; set; }
|
||||
/// <summary>
|
||||
/// наработка подсистемы
|
||||
/// </summary>
|
||||
public TimeSpan UsedTimeHours { get; set; }
|
||||
public double UsedTimeHours { get; set; }
|
||||
/// <summary>
|
||||
/// коэффициент использования
|
||||
/// </summary>
|
||||
|
@ -11,12 +11,10 @@ namespace AsbCloudApp.Services.Subsystems
|
||||
{
|
||||
#nullable enable
|
||||
public interface ISubsystemOperationTimeService
|
||||
{
|
||||
Task<IEnumerable<SubsystemDto>?> GetSubsystemAsync(int? idWell, CancellationToken token);
|
||||
{
|
||||
Task<IEnumerable<SubsystemStatDto>?> GetStatAsync(SubsystemOperationTimeRequest request, CancellationToken token);
|
||||
Task<int> DeleteAsync(SubsystemOperationTimeRequest request, CancellationToken token);
|
||||
Task<IEnumerable<SubsystemOperationTimeDto>?> GetOperationTimeAsync(SubsystemOperationTimeRequest request, CancellationToken token);
|
||||
|
||||
Task<IEnumerable<SubsystemOperationTimeDto>?> GetOperationTimeAsync(SubsystemOperationTimeRequest request, CancellationToken token);
|
||||
}
|
||||
#nullable disable
|
||||
}
|
||||
|
@ -1,6 +1,14 @@
|
||||
namespace AsbCloudApp.Services.Subsystems
|
||||
using AsbCloudApp.Data.Subsystems;
|
||||
using System.Collections.Generic;
|
||||
using System.Threading;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace AsbCloudApp.Services.Subsystems
|
||||
{
|
||||
internal interface ISubsystemService
|
||||
#nullable enable
|
||||
public interface ISubsystemService
|
||||
{
|
||||
Task<IEnumerable<SubsystemDto>?> GetSubsystemAsync(int? idWell, CancellationToken token);
|
||||
}
|
||||
#nullable disable
|
||||
}
|
||||
|
6469
AsbCloudDb/Migrations/20220815093950_AddDataDefault_SubsystemFiller.Designer.cs
generated
Normal file
6469
AsbCloudDb/Migrations/20220815093950_AddDataDefault_SubsystemFiller.Designer.cs
generated
Normal file
File diff suppressed because it is too large
Load Diff
@ -0,0 +1,104 @@
|
||||
using Microsoft.EntityFrameworkCore.Migrations;
|
||||
|
||||
#nullable disable
|
||||
|
||||
namespace AsbCloudDb.Migrations
|
||||
{
|
||||
public partial class AddDataDefault_SubsystemFiller : Migration
|
||||
{
|
||||
protected override void Up(MigrationBuilder migrationBuilder)
|
||||
{
|
||||
migrationBuilder.AlterColumn<string>(
|
||||
name: "name",
|
||||
table: "t_subsystem",
|
||||
type: "character varying(255)",
|
||||
maxLength: 255,
|
||||
nullable: false,
|
||||
defaultValue: "",
|
||||
oldClrType: typeof(string),
|
||||
oldType: "character varying(255)",
|
||||
oldMaxLength: 255,
|
||||
oldNullable: true);
|
||||
|
||||
migrationBuilder.InsertData(
|
||||
table: "t_subsystem",
|
||||
columns: new[] { "id", "description", "name" },
|
||||
values: new object[,]
|
||||
{
|
||||
{ 1, "Ручной", "Ручной" },
|
||||
{ 2, "Бурение в роторе", "Бурение в роторе" },
|
||||
{ 3, "Проработка", "Проработка" },
|
||||
{ 4, "Бурение в слайде", "Бурение в слайде" },
|
||||
{ 5, "Спуск СПО", "Спуск СПО" },
|
||||
{ 6, "Подъем СПО", "Подъем СПО" },
|
||||
{ 7, "Подъем с проработкой", "Подъем с проработкой" },
|
||||
{ 11, "Блокировка", "Блокировка" },
|
||||
{ 65536, "Spin master", "Spin master" },
|
||||
{ 65537, "Torque master", "Torque master" }
|
||||
});
|
||||
}
|
||||
|
||||
protected override void Down(MigrationBuilder migrationBuilder)
|
||||
{
|
||||
migrationBuilder.DeleteData(
|
||||
table: "t_subsystem",
|
||||
keyColumn: "id",
|
||||
keyValue: 1);
|
||||
|
||||
migrationBuilder.DeleteData(
|
||||
table: "t_subsystem",
|
||||
keyColumn: "id",
|
||||
keyValue: 2);
|
||||
|
||||
migrationBuilder.DeleteData(
|
||||
table: "t_subsystem",
|
||||
keyColumn: "id",
|
||||
keyValue: 3);
|
||||
|
||||
migrationBuilder.DeleteData(
|
||||
table: "t_subsystem",
|
||||
keyColumn: "id",
|
||||
keyValue: 4);
|
||||
|
||||
migrationBuilder.DeleteData(
|
||||
table: "t_subsystem",
|
||||
keyColumn: "id",
|
||||
keyValue: 5);
|
||||
|
||||
migrationBuilder.DeleteData(
|
||||
table: "t_subsystem",
|
||||
keyColumn: "id",
|
||||
keyValue: 6);
|
||||
|
||||
migrationBuilder.DeleteData(
|
||||
table: "t_subsystem",
|
||||
keyColumn: "id",
|
||||
keyValue: 7);
|
||||
|
||||
migrationBuilder.DeleteData(
|
||||
table: "t_subsystem",
|
||||
keyColumn: "id",
|
||||
keyValue: 11);
|
||||
|
||||
migrationBuilder.DeleteData(
|
||||
table: "t_subsystem",
|
||||
keyColumn: "id",
|
||||
keyValue: 65536);
|
||||
|
||||
migrationBuilder.DeleteData(
|
||||
table: "t_subsystem",
|
||||
keyColumn: "id",
|
||||
keyValue: 65537);
|
||||
|
||||
migrationBuilder.AlterColumn<string>(
|
||||
name: "name",
|
||||
table: "t_subsystem",
|
||||
type: "character varying(255)",
|
||||
maxLength: 255,
|
||||
nullable: true,
|
||||
oldClrType: typeof(string),
|
||||
oldType: "character varying(255)",
|
||||
oldMaxLength: 255);
|
||||
}
|
||||
}
|
||||
}
|
@ -2779,6 +2779,7 @@ namespace AsbCloudDb.Migrations
|
||||
.HasColumnName("description");
|
||||
|
||||
b.Property<string>("Name")
|
||||
.IsRequired()
|
||||
.HasMaxLength(255)
|
||||
.HasColumnType("character varying(255)")
|
||||
.HasColumnName("name");
|
||||
@ -2788,6 +2789,68 @@ namespace AsbCloudDb.Migrations
|
||||
b.ToTable("t_subsystem");
|
||||
|
||||
b.HasComment("Описание подсистем");
|
||||
|
||||
b.HasData(
|
||||
new
|
||||
{
|
||||
Id = 1,
|
||||
Description = "Ручной",
|
||||
Name = "Ручной"
|
||||
},
|
||||
new
|
||||
{
|
||||
Id = 2,
|
||||
Description = "Бурение в роторе",
|
||||
Name = "Бурение в роторе"
|
||||
},
|
||||
new
|
||||
{
|
||||
Id = 3,
|
||||
Description = "Проработка",
|
||||
Name = "Проработка"
|
||||
},
|
||||
new
|
||||
{
|
||||
Id = 4,
|
||||
Description = "Бурение в слайде",
|
||||
Name = "Бурение в слайде"
|
||||
},
|
||||
new
|
||||
{
|
||||
Id = 5,
|
||||
Description = "Спуск СПО",
|
||||
Name = "Спуск СПО"
|
||||
},
|
||||
new
|
||||
{
|
||||
Id = 6,
|
||||
Description = "Подъем СПО",
|
||||
Name = "Подъем СПО"
|
||||
},
|
||||
new
|
||||
{
|
||||
Id = 7,
|
||||
Description = "Подъем с проработкой",
|
||||
Name = "Подъем с проработкой"
|
||||
},
|
||||
new
|
||||
{
|
||||
Id = 11,
|
||||
Description = "Блокировка",
|
||||
Name = "Блокировка"
|
||||
},
|
||||
new
|
||||
{
|
||||
Id = 65536,
|
||||
Description = "Spin master",
|
||||
Name = "Spin master"
|
||||
},
|
||||
new
|
||||
{
|
||||
Id = 65537,
|
||||
Description = "Torque master",
|
||||
Name = "Torque master"
|
||||
});
|
||||
});
|
||||
|
||||
modelBuilder.Entity("AsbCloudDb.Model.Subsystems.SubsystemOperationTime", b =>
|
||||
@ -6023,7 +6086,7 @@ namespace AsbCloudDb.Migrations
|
||||
modelBuilder.Entity("AsbCloudDb.Model.Subsystems.SubsystemOperationTime", b =>
|
||||
{
|
||||
b.HasOne("AsbCloudDb.Model.Subsystems.Subsystem", "Subsystem")
|
||||
.WithMany("SubsystemOperationTimes")
|
||||
.WithMany()
|
||||
.HasForeignKey("IdSubsystem")
|
||||
.OnDelete(DeleteBehavior.Cascade)
|
||||
.IsRequired();
|
||||
@ -6339,11 +6402,6 @@ namespace AsbCloudDb.Migrations
|
||||
b.Navigation("RelationUserRolePermissions");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("AsbCloudDb.Model.Subsystems.Subsystem", b =>
|
||||
{
|
||||
b.Navigation("SubsystemOperationTimes");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("AsbCloudDb.Model.Telemetry", b =>
|
||||
{
|
||||
b.Navigation("DataSaub");
|
||||
|
@ -151,6 +151,7 @@ namespace AsbCloudInfrastructure
|
||||
.Include(c => c.Deposit))); // может быть включен в сервис ClusterService
|
||||
// Subsystem service
|
||||
services.AddTransient<ICrudService<SubsystemDto>, CrudCacheServiceBase<SubsystemDto, Subsystem>>();
|
||||
services.AddTransient<ISubsystemService, SubsystemService>();
|
||||
|
||||
services.AddTransient<ICrudService<PermissionDto>, CrudCacheServiceBase<PermissionDto, Permission>>();
|
||||
|
||||
|
@ -1,15 +0,0 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace AsbCloudInfrastructure.Services.Subsystems
|
||||
{
|
||||
internal class OperationTimeData
|
||||
{
|
||||
public DateTimeOffset DateTime { get; internal set; }
|
||||
public short? Mode { get; internal set; }
|
||||
public float? Depth { get; internal set; }
|
||||
}
|
||||
}
|
@ -28,38 +28,7 @@ namespace AsbCloudInfrastructure.Services.Subsystems
|
||||
this.db = db;
|
||||
this.wellService = wellService;
|
||||
this.subsystemService = subsystemService;
|
||||
}
|
||||
|
||||
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 db.SubsystemOperationTimes
|
||||
.Include(e => e.Subsystem)
|
||||
.AsNoTracking()
|
||||
.Where(o => o.IdTelemetry == well.IdTelemetry)
|
||||
.DistinctBy(o => o.IdSubsystem)
|
||||
.Select(d => new SubsystemDto
|
||||
{
|
||||
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 subsystemService.GetAllAsync(token);
|
||||
return subsystem;
|
||||
}
|
||||
}
|
||||
public async Task<int> DeleteAsync(SubsystemOperationTimeRequest request, CancellationToken token)
|
||||
{
|
||||
var well = await wellService.GetOrDefaultAsync(request.IdWell, token);
|
||||
@ -143,8 +112,8 @@ namespace AsbCloudInfrastructure.Services.Subsystems
|
||||
var subsystemStat = new SubsystemStatDto()
|
||||
{
|
||||
IdSubsystem = idSubsystem,
|
||||
Subsystem = subsystemService.GetOrDefault(idSubsystem)?.Name ?? "unknown",
|
||||
UsedTimeHours = TimeSpan.FromHours(periodGroup),
|
||||
SubsystemName = subsystemService.GetOrDefault(idSubsystem)?.Name ?? "unknown",
|
||||
UsedTimeHours =periodGroup,
|
||||
KUsage = 1d*periodGroup / periodRequest,
|
||||
K2 = 1d*periodGroup / periodGroupTotal,
|
||||
};
|
||||
|
@ -1,14 +1,62 @@
|
||||
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
|
||||
{
|
||||
internal class SubsystemService : CrudCacheServiceBase<SubsystemDto, Subsystem>
|
||||
{
|
||||
public SubsystemService(IAsbCloudDbContext dbContext) : base(dbContext)
|
||||
#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)
|
||||
{
|
||||
var dto = subsystem.Adapt<SubsystemDto>();
|
||||
return dto;
|
||||
}
|
||||
}
|
||||
#nullable disable
|
||||
}
|
||||
|
@ -21,10 +21,14 @@ namespace AsbCloudWebApi.Controllers.Subsystems
|
||||
{
|
||||
private readonly ISubsystemOperationTimeService subsystemOperationTimeService;
|
||||
private readonly IWellService wellService;
|
||||
public SubsystemOperationTimeController(ISubsystemOperationTimeService subsystemOperationTimeService, IWellService wellService)
|
||||
private readonly ICrudService<SubsystemDto> subsystemServiceCrud;
|
||||
private readonly ISubsystemService subsystemService;
|
||||
public SubsystemOperationTimeController(ISubsystemOperationTimeService subsystemOperationTimeService, IWellService wellService, ICrudService<SubsystemDto> subsystemServiceCrud, ISubsystemService subsystemService)
|
||||
{
|
||||
this.subsystemOperationTimeService = subsystemOperationTimeService;
|
||||
this.subsystemOperationTimeService = subsystemOperationTimeService;
|
||||
this.wellService = wellService;
|
||||
this.subsystemServiceCrud = subsystemServiceCrud;
|
||||
this.subsystemService = subsystemService;
|
||||
}
|
||||
/// <summary>
|
||||
/// получить статистику
|
||||
@ -48,9 +52,8 @@ namespace AsbCloudWebApi.Controllers.Subsystems
|
||||
{
|
||||
if (idWell.HasValue)
|
||||
if (!await UserHasAccesToWellAsync(idWell.Value, token))
|
||||
return Forbid();
|
||||
|
||||
var result = await subsystemOperationTimeService.GetSubsystemAsync(idWell, token);
|
||||
return Forbid();
|
||||
var result = await subsystemService.GetSubsystemAsync(idWell, token);
|
||||
return Ok(result);
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user