forked from ddrilling/AsbCloudServer
Merge branch 'dev' into fix/create-workers
This commit is contained in:
commit
1a3eac9060
@ -20,12 +20,12 @@ namespace AsbCloudApp.Requests
|
|||||||
/// Список id телеметрий
|
/// Список id телеметрий
|
||||||
/// пустой список - нет фильтрации
|
/// пустой список - нет фильтрации
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public IEnumerable<int> IdsTelemetries { get; set; } = Enumerable.Empty<int>();
|
public IEnumerable<int> IdsTelemetries { get; set; } = Array.Empty<int>();
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// категории операций
|
/// категории операций
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public IEnumerable<int> IdsCategories { get; set; } = Enumerable.Empty<int>();
|
public IEnumerable<int> IdsCategories { get; set; } = Array.Empty<int>();
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Больше или равно дате
|
/// Больше или равно дате
|
||||||
@ -50,7 +50,7 @@ namespace AsbCloudApp.Requests
|
|||||||
/// <summary>
|
/// <summary>
|
||||||
/// Фильтр по пользователю панели
|
/// Фильтр по пользователю панели
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public int? EqIdTelemetryUser { get; set; }
|
public int? IdTelemetryUser { get; set; }
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -199,8 +199,8 @@ namespace AsbCloudInfrastructure.Services.DetectOperations
|
|||||||
if (request.LeDepth is not null)
|
if (request.LeDepth is not null)
|
||||||
query = query.Where(o => o.DepthEnd <= request.LeDepth);
|
query = query.Where(o => o.DepthEnd <= request.LeDepth);
|
||||||
|
|
||||||
if (request.EqIdTelemetryUser is not null)
|
if (request.IdTelemetryUser is not null)
|
||||||
query = query.Where(o => o.IdUsersAtStart == request.EqIdTelemetryUser);
|
query = query.Where(o => o.IdUsersAtStart == request.IdTelemetryUser);
|
||||||
}
|
}
|
||||||
|
|
||||||
return query;
|
return query;
|
||||||
|
Binary file not shown.
@ -10,7 +10,6 @@ using System.Linq;
|
|||||||
using System.Threading;
|
using System.Threading;
|
||||||
using System.Threading.Tasks;
|
using System.Threading.Tasks;
|
||||||
using AsbCloudApp.Data.SAUB;
|
using AsbCloudApp.Data.SAUB;
|
||||||
using AsbCloudInfrastructure.Services.SAUB;
|
|
||||||
using AsbCloudApp.Repositories;
|
using AsbCloudApp.Repositories;
|
||||||
|
|
||||||
namespace AsbCloudInfrastructure.Services.WellOperationService;
|
namespace AsbCloudInfrastructure.Services.WellOperationService;
|
||||||
@ -219,7 +218,7 @@ public class OperationsStatService : IOperationsStatService
|
|||||||
|
|
||||||
var factEnd = lastCorrespondingFactOperation.DateStart.AddHours(lastCorrespondingFactOperation.DurationHours);
|
var factEnd = lastCorrespondingFactOperation.DateStart.AddHours(lastCorrespondingFactOperation.DurationHours);
|
||||||
var planEnd = lastCorrespondingPlanOperation.DateStart.AddHours(lastCorrespondingPlanOperation.DurationHours);
|
var planEnd = lastCorrespondingPlanOperation.DateStart.AddHours(lastCorrespondingPlanOperation.DurationHours);
|
||||||
var lagDays = (planEnd - factEnd).TotalDays;
|
var lagDays = (factEnd - planEnd).TotalDays;
|
||||||
|
|
||||||
return lagDays;
|
return lagDays;
|
||||||
}
|
}
|
||||||
|
47
AsbCloudWebApi.Tests/ReflectionExtensions.cs
Normal file
47
AsbCloudWebApi.Tests/ReflectionExtensions.cs
Normal file
@ -0,0 +1,47 @@
|
|||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Linq;
|
||||||
|
using System.Text;
|
||||||
|
using System.Threading.Tasks;
|
||||||
|
|
||||||
|
namespace AsbCloudWebApi.Tests
|
||||||
|
{
|
||||||
|
public static class ReflectionExtensions
|
||||||
|
{
|
||||||
|
private static readonly Dictionary<Type, object> _commonTypeDictionary = new()
|
||||||
|
{
|
||||||
|
{ typeof(int), default(int) },
|
||||||
|
{ typeof(Guid), default(Guid) },
|
||||||
|
{ typeof(DateOnly), default(DateOnly) },
|
||||||
|
{ typeof(DateTime), default(DateTime) },
|
||||||
|
{ typeof(DateTimeOffset), default(DateTimeOffset) },
|
||||||
|
{ typeof(TimeOnly), default(TimeOnly) },
|
||||||
|
{ typeof(long), default(long) },
|
||||||
|
{ typeof(bool), default(bool) },
|
||||||
|
{ typeof(double), default(double) },
|
||||||
|
{ typeof(short), default(short) },
|
||||||
|
{ typeof(float), default(float) },
|
||||||
|
{ typeof(byte), default(byte) },
|
||||||
|
{ typeof(char), default(char) },
|
||||||
|
{ typeof(uint), default(uint) },
|
||||||
|
{ typeof(ushort), default(ushort) },
|
||||||
|
{ typeof(ulong), default(ulong) },
|
||||||
|
{ typeof(sbyte), default(sbyte) }
|
||||||
|
};
|
||||||
|
|
||||||
|
public static object? GetDefaultValue(this Type type)
|
||||||
|
{
|
||||||
|
if (!type.IsValueType)
|
||||||
|
{
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
return _commonTypeDictionary.TryGetValue(type, out var value)
|
||||||
|
? value
|
||||||
|
: Activator.CreateInstance(type);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static bool IsDefaultValue(this Type type, object? value)
|
||||||
|
=> (value?.Equals(type.GetDefaultValue()) != false);
|
||||||
|
}
|
||||||
|
}
|
@ -8,11 +8,16 @@ using AsbCloudDb.Model;
|
|||||||
using AsbCloudInfrastructure.Services.WellOperationImport;
|
using AsbCloudInfrastructure.Services.WellOperationImport;
|
||||||
using AsbCloudInfrastructure.Services.WellOperationImport.FileParser;
|
using AsbCloudInfrastructure.Services.WellOperationImport.FileParser;
|
||||||
using NSubstitute;
|
using NSubstitute;
|
||||||
|
using SignalRSwaggerGen.Enums;
|
||||||
using System;
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Linq;
|
||||||
|
using System.Reflection;
|
||||||
using System.Text.Json;
|
using System.Text.Json;
|
||||||
using System.Threading;
|
using System.Threading;
|
||||||
using System.Threading.Tasks;
|
using System.Threading.Tasks;
|
||||||
using Xunit;
|
using Xunit;
|
||||||
|
using Xunit.Abstractions;
|
||||||
|
|
||||||
namespace AsbCloudWebApi.Tests.UnitTests.Services.WellOperationExport
|
namespace AsbCloudWebApi.Tests.UnitTests.Services.WellOperationExport
|
||||||
{
|
{
|
||||||
@ -27,31 +32,36 @@ namespace AsbCloudWebApi.Tests.UnitTests.Services.WellOperationExport
|
|||||||
private WellOperationImportService wellOperationImportService;
|
private WellOperationImportService wellOperationImportService;
|
||||||
private IWellOperationExcelParser<WellOperationImportDefaultOptionsDto> wellOperationDefaultExcelParser;
|
private IWellOperationExcelParser<WellOperationImportDefaultOptionsDto> wellOperationDefaultExcelParser;
|
||||||
|
|
||||||
|
|
||||||
private readonly WellOperationDto[] operations = new WellOperationDto[2] {
|
private readonly WellOperationDto[] operations = new WellOperationDto[2] {
|
||||||
new WellOperationDto() {
|
new WellOperationDto() {
|
||||||
|
Id = 5,
|
||||||
IdWell = idWell,
|
IdWell = idWell,
|
||||||
IdUser = 1,
|
IdUser = 1,
|
||||||
IdType = 0,
|
IdType = 0,
|
||||||
IdWellSectionType = 1,
|
IdWellSectionType = 1,
|
||||||
|
WellSectionTypeName = "1",
|
||||||
IdCategory = 1,
|
IdCategory = 1,
|
||||||
CategoryInfo = "1",
|
CategoryName = "1",
|
||||||
|
CategoryInfo = "CategoryInfo 1",
|
||||||
DepthStart = 10,
|
DepthStart = 10,
|
||||||
DepthEnd = 20,
|
DepthEnd = 20,
|
||||||
DateStart = getDate(days: 0),
|
DateStart = GetDate(days: 0),
|
||||||
DurationHours = 10,
|
DurationHours = 10,
|
||||||
Comment = "Комментарий 1",
|
Comment = "Комментарий 1",
|
||||||
},
|
},
|
||||||
new WellOperationDto() {
|
new WellOperationDto() {
|
||||||
|
Id = 6,
|
||||||
IdWell = idWell,
|
IdWell = idWell,
|
||||||
IdUser = 1,
|
IdUser = 1,
|
||||||
IdType = 0,
|
IdType = 0,
|
||||||
IdWellSectionType = 2,
|
IdWellSectionType = 2,
|
||||||
|
WellSectionTypeName = "2",
|
||||||
IdCategory = 2,
|
IdCategory = 2,
|
||||||
CategoryInfo = "2",
|
CategoryName = "2",
|
||||||
|
CategoryInfo = "CategoryInfo 2",
|
||||||
DepthStart = 20,
|
DepthStart = 20,
|
||||||
DepthEnd = 30,
|
DepthEnd = 30,
|
||||||
DateStart = getDate(days: 1),
|
DateStart = GetDate(days: 1),
|
||||||
DurationHours = 20,
|
DurationHours = 20,
|
||||||
Comment = "Комментарий 2",
|
Comment = "Комментарий 2",
|
||||||
}
|
}
|
||||||
@ -92,14 +102,15 @@ namespace AsbCloudWebApi.Tests.UnitTests.Services.WellOperationExport
|
|||||||
Name = "2"
|
Name = "2"
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
private readonly ITestOutputHelper output;
|
||||||
|
|
||||||
private static DateTime getDate(int days)
|
private static DateTime GetDate(int days)
|
||||||
{
|
{
|
||||||
var date = DateTime.Now.AddDays(days);
|
var date = DateTime.Now.AddDays(days);
|
||||||
return new DateTime(date.Year, date.Month, date.Day, date.Hour, date.Minute, date.Second);
|
return new DateTime(date.Year, date.Month, date.Day, date.Hour, date.Minute, date.Second);
|
||||||
}
|
}
|
||||||
|
|
||||||
public WellOperationExportServiceTest()
|
public WellOperationExportServiceTest(ITestOutputHelper output)
|
||||||
{
|
{
|
||||||
wellService = Substitute.For<IWellService>();
|
wellService = Substitute.For<IWellService>();
|
||||||
wellOperationRepository = Substitute.For<IWellOperationRepository>();
|
wellOperationRepository = Substitute.For<IWellOperationRepository>();
|
||||||
@ -108,6 +119,7 @@ namespace AsbCloudWebApi.Tests.UnitTests.Services.WellOperationExport
|
|||||||
|
|
||||||
wellOperationImportService = new WellOperationImportService(wellOperationRepository);
|
wellOperationImportService = new WellOperationImportService(wellOperationRepository);
|
||||||
wellOperationDefaultExcelParser = new WellOperationDefaultExcelParser();
|
wellOperationDefaultExcelParser = new WellOperationDefaultExcelParser();
|
||||||
|
this.output = output;
|
||||||
}
|
}
|
||||||
|
|
||||||
[Fact]
|
[Fact]
|
||||||
@ -136,6 +148,53 @@ namespace AsbCloudWebApi.Tests.UnitTests.Services.WellOperationExport
|
|||||||
|
|
||||||
Assert.Equal(expected, actual);
|
Assert.Equal(expected, actual);
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
|
[Fact]
|
||||||
|
public void TestDataContainsNotDefaultProps()
|
||||||
|
{
|
||||||
|
var initOk = true;
|
||||||
|
for (int i = 0; i < operations.Length; i++)
|
||||||
|
{
|
||||||
|
var operation = operations[i];
|
||||||
|
var propsWithDefault = GetPropsWithDefaultValue(operation,
|
||||||
|
nameof(WellOperationDto.Id),
|
||||||
|
nameof(WellOperationDto.IdType),
|
||||||
|
nameof(WellOperationDto.IdPlan),
|
||||||
|
nameof(WellOperationDto.IdParentCategory),
|
||||||
|
nameof(WellOperationDto.Day),
|
||||||
|
nameof(WellOperationDto.NptHours),
|
||||||
|
nameof(WellOperationDto.UserName),
|
||||||
|
nameof(WellOperationDto.LastUpdateDate)
|
||||||
|
)
|
||||||
|
.ToArray();
|
||||||
|
|
||||||
|
if (propsWithDefault.Any())
|
||||||
|
{
|
||||||
|
initOk = false;
|
||||||
|
foreach (var propertyName in propsWithDefault)
|
||||||
|
output.WriteLine($"{nameof(operations)}[{i}].{propertyName} is default");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
Assert.True(initOk);
|
||||||
|
}
|
||||||
|
|
||||||
|
private static IEnumerable<string> GetPropsWithDefaultValue<T>(T dto, params string[] excludeProps)
|
||||||
|
{
|
||||||
|
IEnumerable<PropertyInfo> props = typeof(T).GetProperties(
|
||||||
|
BindingFlags.Public
|
||||||
|
| BindingFlags.Instance);
|
||||||
|
|
||||||
|
props = props
|
||||||
|
.Where(prop=>prop.CanWrite)
|
||||||
|
.Where(prop => !excludeProps.Contains(prop.Name));
|
||||||
|
|
||||||
|
foreach (var prop in props)
|
||||||
|
{
|
||||||
|
var value = prop.GetValue(dto);
|
||||||
|
if (prop.PropertyType.IsDefaultValue(value))
|
||||||
|
yield return prop.Name;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -45,7 +45,6 @@ namespace AsbCloudWebApi.Controllers.SAUB
|
|||||||
/// <param name = "token" >Токен завершения задачи</param>
|
/// <param name = "token" >Токен завершения задачи</param>
|
||||||
/// <returns></returns>
|
/// <returns></returns>
|
||||||
[HttpGet("{idWell}")]
|
[HttpGet("{idWell}")]
|
||||||
[Permission]
|
|
||||||
public async Task<ActionResult<IEnumerable<WitsRecordDto>>> GetDataAsync([Required] int idWell,
|
public async Task<ActionResult<IEnumerable<WitsRecordDto>>> GetDataAsync([Required] int idWell,
|
||||||
[FromQuery] GtrWithGetDataRequest request,
|
[FromQuery] GtrWithGetDataRequest request,
|
||||||
CancellationToken token)
|
CancellationToken token)
|
||||||
@ -75,7 +74,6 @@ namespace AsbCloudWebApi.Controllers.SAUB
|
|||||||
/// <param name="token"></param>
|
/// <param name="token"></param>
|
||||||
/// <returns></returns>
|
/// <returns></returns>
|
||||||
[HttpGet("{idWell}/{idRecord}")]
|
[HttpGet("{idWell}/{idRecord}")]
|
||||||
[Permission]
|
|
||||||
public async Task<ActionResult<IEnumerable<WitsItemRecordDto>>> GetLastDataByRecordIdAsync(int idWell, int idRecord, CancellationToken token)
|
public async Task<ActionResult<IEnumerable<WitsItemRecordDto>>> GetLastDataByRecordIdAsync(int idWell, int idRecord, CancellationToken token)
|
||||||
{
|
{
|
||||||
int? idCompany = User.GetCompanyId();
|
int? idCompany = User.GetCompanyId();
|
||||||
|
@ -403,7 +403,8 @@ namespace AsbCloudWebApi.Controllers
|
|||||||
/// <summary>
|
/// <summary>
|
||||||
/// Импорт операций из excel (xlsx) файла. ГПНХ (Хантос)
|
/// Импорт операций из excel (xlsx) файла. ГПНХ (Хантос)
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="idWell">id скважины</param>
|
/// <param name="idWell">Id скважины</param>
|
||||||
|
/// <param name="options">Параметры парсинга</param>
|
||||||
/// <param name="files">Коллекция из одного файла xlsx</param>
|
/// <param name="files">Коллекция из одного файла xlsx</param>
|
||||||
/// <param name="cancellationToken"></param>
|
/// <param name="cancellationToken"></param>
|
||||||
/// <returns></returns>
|
/// <returns></returns>
|
||||||
@ -412,14 +413,12 @@ namespace AsbCloudWebApi.Controllers
|
|||||||
[ProducesResponseType(typeof(ValidationProblemDetails), StatusCodes.Status400BadRequest)]
|
[ProducesResponseType(typeof(ValidationProblemDetails), StatusCodes.Status400BadRequest)]
|
||||||
[Permission]
|
[Permission]
|
||||||
public Task<IActionResult> ImportPlanGazpromKhantosExcelFileAsync(int idWell,
|
public Task<IActionResult> ImportPlanGazpromKhantosExcelFileAsync(int idWell,
|
||||||
|
[FromQuery] WellOperationImportGazpromKhantosOptionsDto options,
|
||||||
[FromForm] IFormFileCollection files,
|
[FromForm] IFormFileCollection files,
|
||||||
CancellationToken cancellationToken)
|
CancellationToken cancellationToken)
|
||||||
{
|
{
|
||||||
var options = new WellOperationImportGazpromKhantosOptionsDto
|
options.IdType = WellOperation.IdOperationTypePlan;
|
||||||
{
|
|
||||||
IdType = WellOperation.IdOperationTypePlan
|
|
||||||
};
|
|
||||||
|
|
||||||
return ImportExcelFileAsync(idWell, files, options,
|
return ImportExcelFileAsync(idWell, files, options,
|
||||||
(stream, _) => wellOperationGazpromKhantosExcelParser.Parse(stream, options),
|
(stream, _) => wellOperationGazpromKhantosExcelParser.Parse(stream, options),
|
||||||
null,
|
null,
|
||||||
|
Loading…
Reference in New Issue
Block a user