forked from ddrilling/AsbCloudServer
корректировка контроллеров и сервисов
This commit is contained in:
parent
7f4b434a8c
commit
421c706ca1
@ -6,6 +6,10 @@
|
|||||||
<Nullable>disable</Nullable>
|
<Nullable>disable</Nullable>
|
||||||
</PropertyGroup>
|
</PropertyGroup>
|
||||||
|
|
||||||
|
<ItemGroup>
|
||||||
|
<Compile Include="..\AsbCloudWebApi\DependencyInjection.cs" Link="DependencyInjection.cs" />
|
||||||
|
</ItemGroup>
|
||||||
|
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
<PackageReference Include="System.Linq" Version="4.3.0" />
|
<PackageReference Include="System.Linq" Version="4.3.0" />
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
|
15
AsbCloudApp/Requests/SubsystemOperationTimeRequest.cs
Normal file
15
AsbCloudApp/Requests/SubsystemOperationTimeRequest.cs
Normal file
@ -0,0 +1,15 @@
|
|||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Linq;
|
||||||
|
using System.Text;
|
||||||
|
using System.Threading.Tasks;
|
||||||
|
|
||||||
|
namespace AsbCloudApp.Requests
|
||||||
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// класс с фильтрами для запроса
|
||||||
|
/// </summary>
|
||||||
|
public class SubsystemOperationTimeRequest: RequestBase
|
||||||
|
{
|
||||||
|
}
|
||||||
|
}
|
@ -1,12 +1,20 @@
|
|||||||
using System;
|
using AsbCloudApp.Data.Subsystems;
|
||||||
|
using AsbCloudApp.Requests;
|
||||||
|
using System;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
using System.Text;
|
using System.Text;
|
||||||
|
using System.Threading;
|
||||||
using System.Threading.Tasks;
|
using System.Threading.Tasks;
|
||||||
|
|
||||||
namespace AsbCloudApp.Services.Subsystems
|
namespace AsbCloudApp.Services.Subsystems
|
||||||
{
|
{
|
||||||
public interface ISubsystemOperationTimeService
|
public interface ISubsystemOperationTimeService
|
||||||
{
|
{
|
||||||
|
Task<IEnumerable<SubsystemDto>> GetSubsystemAsync(int? idWell, CancellationToken token);
|
||||||
|
Task<IEnumerable<SubsystemStatisticsDto>> GetStatisticAsync(SubsystemOperationTimeRequest request, CancellationToken token);
|
||||||
|
Task<int> DeleteAsync(SubsystemOperationTimeRequest request, CancellationToken token);
|
||||||
|
Task<IEnumerable<SubsystemOperationTimeDto>> GetOperationTimeAsync(SubsystemOperationTimeRequest request, CancellationToken token);
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1,16 +0,0 @@
|
|||||||
using AsbCloudApp.Data.Subsystems;
|
|
||||||
using System;
|
|
||||||
using System.Collections.Generic;
|
|
||||||
using System.Threading;
|
|
||||||
using System.Threading.Tasks;
|
|
||||||
|
|
||||||
namespace AsbCloudApp.Services.Subsystems
|
|
||||||
{
|
|
||||||
public interface ISubsystemStatisticsService
|
|
||||||
{
|
|
||||||
Task<IEnumerable<SubsystemStatisticsDto>> GetStatisticsAsync(CancellationToken token);
|
|
||||||
Task<IEnumerable<SubsystemStatisticsDto>> GetPeriodStatisticsAsync(DateTime periodBegin,
|
|
||||||
DateTime periodEnd,
|
|
||||||
CancellationToken token = default);
|
|
||||||
}
|
|
||||||
}
|
|
@ -481,6 +481,11 @@ namespace AsbCloudDb.Model
|
|||||||
new Permission{ Id = 124, Name="AdminWell.delete", Description="Разрешение удалять админ. Скважины"},
|
new Permission{ Id = 124, Name="AdminWell.delete", Description="Разрешение удалять админ. Скважины"},
|
||||||
new Permission{ Id = 125, Name="AdminWell.edit", Description="Разрешение редактировать админ. Скважины"},
|
new Permission{ Id = 125, Name="AdminWell.edit", Description="Разрешение редактировать админ. Скважины"},
|
||||||
new Permission{ Id = 126, Name="AdminWell.get", Description="Разрешение просматривать админ. Скважины"},
|
new Permission{ Id = 126, Name="AdminWell.get", Description="Разрешение просматривать админ. Скважины"},
|
||||||
|
|
||||||
|
new Permission{ Id = 127, Name="AdminSubsytem.delete", Description="Разрешение удалять админ. Подсистемы"},
|
||||||
|
new Permission{ Id = 128, Name="AdminSubsytem.edit", Description="Разрешение редактировать админ. Подсистемы"},
|
||||||
|
new Permission{ Id = 129, Name="AdminSubsytem.get", Description="Разрешение просматривать админ. Подсистемы"},
|
||||||
|
|
||||||
new Permission{ Id = 200, Name="Auth.edit", Description="Разрешение редактировать 0"},
|
new Permission{ Id = 200, Name="Auth.edit", Description="Разрешение редактировать 0"},
|
||||||
new Permission{ Id = 201, Name="Auth.get", Description="Разрешение просматривать 0"},
|
new Permission{ Id = 201, Name="Auth.get", Description="Разрешение просматривать 0"},
|
||||||
new Permission{ Id = 202, Name="Cluster.get", Description="Разрешение просматривать Кусты"},
|
new Permission{ Id = 202, Name="Cluster.get", Description="Разрешение просматривать Кусты"},
|
||||||
|
@ -1,7 +1,10 @@
|
|||||||
using Microsoft.Extensions.Configuration;
|
using AsbCloudDb.Model;
|
||||||
|
using Microsoft.EntityFrameworkCore;
|
||||||
|
using Microsoft.Extensions.Configuration;
|
||||||
using Microsoft.Extensions.Hosting;
|
using Microsoft.Extensions.Hosting;
|
||||||
using System;
|
using System;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
|
using System.Diagnostics;
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
using System.Text;
|
using System.Text;
|
||||||
using System.Threading;
|
using System.Threading;
|
||||||
@ -16,9 +19,33 @@ namespace AsbCloudInfrastructure.Services.Subsystems
|
|||||||
{
|
{
|
||||||
connectionString = configuration.GetConnectionString("DefaultConnection");
|
connectionString = configuration.GetConnectionString("DefaultConnection");
|
||||||
}
|
}
|
||||||
protected override Task ExecuteAsync(CancellationToken token)
|
protected override async Task ExecuteAsync(CancellationToken token)
|
||||||
{
|
{
|
||||||
throw new NotImplementedException();
|
var timeToStartAnalysis = DateTime.Now;
|
||||||
|
var options = new DbContextOptionsBuilder<AsbCloudDbContext>()
|
||||||
|
.UseNpgsql(connectionString)
|
||||||
|
.Options;
|
||||||
|
|
||||||
|
while (!token.IsCancellationRequested)
|
||||||
|
{
|
||||||
|
if (DateTime.Now > timeToStartAnalysis)
|
||||||
|
{
|
||||||
|
timeToStartAnalysis = DateTime.Now + TimeSpan.FromHours(1);
|
||||||
|
try
|
||||||
|
{
|
||||||
|
|
||||||
|
}
|
||||||
|
catch (Exception ex)
|
||||||
|
{
|
||||||
|
Trace.TraceError(ex.Message);
|
||||||
|
}
|
||||||
|
//GC.Collect();
|
||||||
|
}
|
||||||
|
|
||||||
|
var ms = (int)(timeToStartAnalysis - DateTime.Now).TotalMilliseconds;
|
||||||
|
ms = ms > 100 ? ms : 100;
|
||||||
|
await Task.Delay(ms, token).ConfigureAwait(false);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1,8 +1,11 @@
|
|||||||
using AsbCloudApp.Services.Subsystems;
|
using AsbCloudApp.Data.Subsystems;
|
||||||
|
using AsbCloudApp.Requests;
|
||||||
|
using AsbCloudApp.Services;
|
||||||
|
using AsbCloudApp.Services.Subsystems;
|
||||||
|
using AsbCloudDb.Model;
|
||||||
using System;
|
using System;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using System.Linq;
|
using System.Threading;
|
||||||
using System.Text;
|
|
||||||
using System.Threading.Tasks;
|
using System.Threading.Tasks;
|
||||||
|
|
||||||
namespace AsbCloudInfrastructure.Services.Subsystems
|
namespace AsbCloudInfrastructure.Services.Subsystems
|
||||||
@ -10,5 +13,62 @@ namespace AsbCloudInfrastructure.Services.Subsystems
|
|||||||
internal class SubsystemOperationTimeService : ISubsystemOperationTimeService
|
internal class SubsystemOperationTimeService : ISubsystemOperationTimeService
|
||||||
{
|
{
|
||||||
|
|
||||||
|
private readonly IAsbCloudDbContext db;
|
||||||
|
private readonly IWellService wellService;
|
||||||
|
|
||||||
|
public SubsystemOperationTimeService(IAsbCloudDbContext db, IWellService wellService)
|
||||||
|
{
|
||||||
|
this.db = db;
|
||||||
|
this.wellService = wellService;
|
||||||
|
}
|
||||||
|
|
||||||
|
public async Task<IEnumerable<SubsystemDto>> GetSubsystemAsync(int? idWell, CancellationToken token)
|
||||||
|
{
|
||||||
|
var result = new List<SubsystemDto>() {
|
||||||
|
new SubsystemDto()
|
||||||
|
{
|
||||||
|
Id = 1,
|
||||||
|
Name = "test1",
|
||||||
|
Description = "test desription1"
|
||||||
|
},
|
||||||
|
new SubsystemDto()
|
||||||
|
{
|
||||||
|
Id = 2,
|
||||||
|
Name = "test2",
|
||||||
|
Description = "test desription2"
|
||||||
|
},
|
||||||
|
new SubsystemDto()
|
||||||
|
{
|
||||||
|
Id = 3,
|
||||||
|
Name = "test3",
|
||||||
|
Description = "test desription3"
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
return result;
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
public async Task<int> DeleteAsync(SubsystemOperationTimeRequest request, CancellationToken token)
|
||||||
|
{
|
||||||
|
throw new NotImplementedException();
|
||||||
|
}
|
||||||
|
|
||||||
|
public Task<IEnumerable<SubsystemOperationTimeDto>> GetOperationTimeAsync(SubsystemOperationTimeRequest request, CancellationToken token)
|
||||||
|
{
|
||||||
|
throw new NotImplementedException();
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
Task<IEnumerable<SubsystemStatisticsDto>> ISubsystemOperationTimeService.GetStatisticAsync(SubsystemOperationTimeRequest request, CancellationToken token)
|
||||||
|
{
|
||||||
|
throw new NotImplementedException();
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1,30 +0,0 @@
|
|||||||
using AsbCloudApp.Data.Subsystems;
|
|
||||||
using AsbCloudApp.Services.Subsystems;
|
|
||||||
using AsbCloudDb.Model;
|
|
||||||
using System;
|
|
||||||
using System.Collections.Generic;
|
|
||||||
using System.Threading;
|
|
||||||
using System.Threading.Tasks;
|
|
||||||
|
|
||||||
namespace AsbCloudInfrastructure.Services.Subsystems
|
|
||||||
{
|
|
||||||
internal class SubsystemStatisticService : ISubsystemStatisticsService
|
|
||||||
{
|
|
||||||
|
|
||||||
private readonly IAsbCloudDbContext db;
|
|
||||||
|
|
||||||
public SubsystemStatisticService(IAsbCloudDbContext db)
|
|
||||||
{
|
|
||||||
this.db = db;
|
|
||||||
}
|
|
||||||
public Task<IEnumerable<SubsystemStatisticsDto>> GetPeriodStatisticsAsync(DateTime periodBegin, DateTime periodEnd, CancellationToken token = default)
|
|
||||||
{
|
|
||||||
throw new NotImplementedException();
|
|
||||||
}
|
|
||||||
|
|
||||||
public Task<IEnumerable<SubsystemStatisticsDto>> GetStatisticsAsync(CancellationToken token)
|
|
||||||
{
|
|
||||||
throw new NotImplementedException();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
@ -1,5 +1,7 @@
|
|||||||
using AsbCloudApp.Data.Subsystems;
|
using AsbCloudApp.Data.Subsystems;
|
||||||
|
using AsbCloudApp.Requests;
|
||||||
using AsbCloudApp.Services;
|
using AsbCloudApp.Services;
|
||||||
|
using AsbCloudApp.Services.Subsystems;
|
||||||
using Microsoft.AspNetCore.Authorization;
|
using Microsoft.AspNetCore.Authorization;
|
||||||
using Microsoft.AspNetCore.Http;
|
using Microsoft.AspNetCore.Http;
|
||||||
using Microsoft.AspNetCore.Mvc;
|
using Microsoft.AspNetCore.Mvc;
|
||||||
@ -9,14 +11,101 @@ using System.Threading.Tasks;
|
|||||||
|
|
||||||
namespace AsbCloudWebApi.Controllers.Subsystems
|
namespace AsbCloudWebApi.Controllers.Subsystems
|
||||||
{
|
{
|
||||||
|
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Наработка подсистем
|
/// Наработка подсистем
|
||||||
/// </summary>
|
/// </summary>
|
||||||
[Route("api/[OperatingTimeSubsystem]")]
|
[Route("api/[controller]")]
|
||||||
[ApiController]
|
[ApiController]
|
||||||
[Authorize]
|
[Authorize]
|
||||||
|
|
||||||
public class OperatingTimeSubsystemController : ControllerBase
|
public class OperatingTimeSubsystemController : ControllerBase
|
||||||
{
|
{
|
||||||
|
private readonly ISubsystemOperationTimeService subsystemOperationTimeService;
|
||||||
|
private readonly IWellService wellService;
|
||||||
|
|
||||||
|
public OperatingTimeSubsystemController(ISubsystemOperationTimeService subsystemOperationTimeService, IWellService wellService)
|
||||||
|
{
|
||||||
|
this.subsystemOperationTimeService = subsystemOperationTimeService;
|
||||||
|
this.wellService = wellService;
|
||||||
|
}
|
||||||
|
/// <summary>
|
||||||
|
/// получить статистику
|
||||||
|
/// </summary>
|
||||||
|
[HttpGet("statistic")]
|
||||||
|
[ProducesResponseType(typeof(IEnumerable<SubsystemStatisticsDto>), (int)System.Net.HttpStatusCode.OK)]
|
||||||
|
public async Task<IActionResult> GetStatisticsAsync(CancellationToken token = default)
|
||||||
|
{
|
||||||
|
var subsystemResult = new List<SubsystemStatisticsDto>()
|
||||||
|
{
|
||||||
|
new SubsystemStatisticsDto(){
|
||||||
|
IdSubsystem = 1,
|
||||||
|
Subsystem = "test1",
|
||||||
|
UsedTime = System.DateTime.Now,
|
||||||
|
K2 = System.TimeSpan.MinValue,
|
||||||
|
KUsage = System.TimeSpan.MinValue
|
||||||
|
|
||||||
|
},
|
||||||
|
new SubsystemStatisticsDto(){
|
||||||
|
IdSubsystem = 2,
|
||||||
|
Subsystem = "test2",
|
||||||
|
UsedTime = System.DateTime.Now,
|
||||||
|
K2 = System.TimeSpan.Zero,
|
||||||
|
KUsage = System.TimeSpan.Zero
|
||||||
|
},
|
||||||
|
new SubsystemStatisticsDto(){
|
||||||
|
IdSubsystem = 3,
|
||||||
|
Subsystem = "test3",
|
||||||
|
UsedTime = System.DateTime.Now,
|
||||||
|
K2 = System.TimeSpan.MaxValue,
|
||||||
|
KUsage = System.TimeSpan.MaxValue
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
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 = default)
|
||||||
|
{
|
||||||
|
var result = await subsystemOperationTimeService.GetSubsystemAsync(idWell, token);
|
||||||
|
return Ok(result);
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// получить список наработок подсистем
|
||||||
|
/// </summary>
|
||||||
|
[HttpGet("operationTime")]
|
||||||
|
[ProducesResponseType(typeof(IEnumerable<SubsystemOperationTimeDto>), (int)System.Net.HttpStatusCode.OK)]
|
||||||
|
public async Task<IActionResult> GetOperationTimeAsync(
|
||||||
|
[FromQuery] SubsystemOperationTimeRequest request,
|
||||||
|
CancellationToken token = default)
|
||||||
|
{
|
||||||
|
|
||||||
|
var result = await subsystemOperationTimeService.GetOperationTimeAsync(request, token);
|
||||||
|
return Ok(result);
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Удалить наработки.
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="request"></param>
|
||||||
|
/// <param name="token"></param>
|
||||||
|
/// <returns></returns>
|
||||||
|
[HttpDelete]
|
||||||
|
[Permission]
|
||||||
|
[ProducesResponseType(typeof(int), (int)System.Net.HttpStatusCode.OK)]
|
||||||
|
public async Task<IActionResult> DeleteAsync(
|
||||||
|
[FromQuery] SubsystemOperationTimeRequest request,
|
||||||
|
CancellationToken token)
|
||||||
|
{
|
||||||
|
var result = await subsystemOperationTimeService.DeleteAsync(request, token);
|
||||||
|
return Ok(result);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1,94 +0,0 @@
|
|||||||
using AsbCloudApp.Data.Subsystems;
|
|
||||||
using Microsoft.AspNetCore.Authorization;
|
|
||||||
using Microsoft.AspNetCore.Http;
|
|
||||||
using Microsoft.AspNetCore.Mvc;
|
|
||||||
using System;
|
|
||||||
using System.Collections.Generic;
|
|
||||||
using System.Threading;
|
|
||||||
using System.Threading.Tasks;
|
|
||||||
|
|
||||||
namespace AsbCloudWebApi.Controllers.Subsystems
|
|
||||||
{
|
|
||||||
/// <summary>
|
|
||||||
/// Статистика наработки подсистем
|
|
||||||
/// </summary>
|
|
||||||
[Route("api/statisticsSubsystem")]
|
|
||||||
[ApiController]
|
|
||||||
[Authorize]
|
|
||||||
public class StatisticSubsystemsController : ControllerBase
|
|
||||||
{
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// получить без временного периода в запросе.
|
|
||||||
/// </summary>
|
|
||||||
[HttpGet]
|
|
||||||
[ProducesResponseType(typeof(IEnumerable<SubsystemStatisticsDto>), (int)System.Net.HttpStatusCode.OK)]
|
|
||||||
public async Task<IActionResult> GetStatisticsAsync(CancellationToken token = default)
|
|
||||||
{
|
|
||||||
var subsystemResult = new List<SubsystemStatisticsDto>()
|
|
||||||
{
|
|
||||||
new SubsystemStatisticsDto(){
|
|
||||||
IdSubsystem = 1,
|
|
||||||
Subsystem = "test1",
|
|
||||||
UsedTime = System.DateTime.Now,
|
|
||||||
K2 = System.TimeSpan.MinValue,
|
|
||||||
KUsage = System.TimeSpan.MinValue
|
|
||||||
|
|
||||||
},
|
|
||||||
new SubsystemStatisticsDto(){
|
|
||||||
IdSubsystem = 2,
|
|
||||||
Subsystem = "test2",
|
|
||||||
UsedTime = System.DateTime.Now,
|
|
||||||
K2 = System.TimeSpan.Zero,
|
|
||||||
KUsage = System.TimeSpan.Zero
|
|
||||||
},
|
|
||||||
new SubsystemStatisticsDto(){
|
|
||||||
IdSubsystem = 3,
|
|
||||||
Subsystem = "test3",
|
|
||||||
UsedTime = System.DateTime.Now,
|
|
||||||
K2 = System.TimeSpan.MaxValue,
|
|
||||||
KUsage = System.TimeSpan.MaxValue
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
return Ok(subsystemResult);
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
//[HttpGet]
|
|
||||||
//[ProducesResponseType(typeof(IEnumerable<SubsystemStatisticsDto>), (int)System.Net.HttpStatusCode.OK)]
|
|
||||||
//public async Task<IActionResult> GetStatisticsPeriodAsync(CancellationToken token = default, DateTime dateBegin , DateTime dateEnd)
|
|
||||||
//{
|
|
||||||
// var subsystemResult = new List<SubsystemStatisticsDto>()
|
|
||||||
// {
|
|
||||||
// new SubsystemStatisticsDto(){
|
|
||||||
// IdSubsystem = 1,
|
|
||||||
// Subsystem = "test1",
|
|
||||||
// UsedTime = System.DateTime.Now,
|
|
||||||
// K2 = System.TimeSpan.MinValue,
|
|
||||||
// KUsage = System.TimeSpan.MinValue
|
|
||||||
|
|
||||||
// },
|
|
||||||
// new SubsystemStatisticsDto(){
|
|
||||||
// IdSubsystem = 2,
|
|
||||||
// Subsystem = "test2",
|
|
||||||
// UsedTime = System.DateTime.Now,
|
|
||||||
// K2 = System.TimeSpan.Zero,
|
|
||||||
// KUsage = System.TimeSpan.Zero
|
|
||||||
// },
|
|
||||||
// new SubsystemStatisticsDto(){
|
|
||||||
// IdSubsystem = 3,
|
|
||||||
// Subsystem = "test3",
|
|
||||||
// UsedTime = System.DateTime.Now,
|
|
||||||
// K2 = System.TimeSpan.MaxValue,
|
|
||||||
// KUsage = System.TimeSpan.MaxValue
|
|
||||||
// }
|
|
||||||
// };
|
|
||||||
|
|
||||||
// return Ok(subsystemResult);
|
|
||||||
//}
|
|
||||||
|
|
||||||
|
|
||||||
}
|
|
||||||
}
|
|
Loading…
Reference in New Issue
Block a user