forked from ddrilling/AsbCloudServer
Merge branch 'dev' into feature/#28093751-process-map-plan-drilling-dto
This commit is contained in:
commit
adf511240d
@ -2,7 +2,6 @@
|
||||
using AsbCloudApp.Requests;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.ComponentModel.DataAnnotations;
|
||||
using System.Threading;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
@ -13,14 +12,6 @@ namespace AsbCloudApp.Repositories
|
||||
/// </summary>
|
||||
public interface IWellOperationRepository
|
||||
{
|
||||
//TODO: replace all references
|
||||
/// <summary>
|
||||
/// список названий операций
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
[Obsolete("use IWellOperationCategoryRepository.GetCategories(bool includeParents)")]
|
||||
IEnumerable<WellOperationCategoryDto> GetCategories(bool includeParents);
|
||||
|
||||
/// <summary>
|
||||
/// Список секций
|
||||
/// </summary>
|
||||
|
@ -11,7 +11,7 @@ public class GetStatRequest: RequestBase
|
||||
/// <summary>
|
||||
/// id ñêâàæèí
|
||||
/// </summary>
|
||||
public IEnumerable<int> IdsWells { get; set; } = Enumerable.Empty<int>();
|
||||
public IEnumerable<int> IdsWells { get; set; } = new List<int>();
|
||||
|
||||
/// <summary>
|
||||
/// id Áóðèëüùèêà
|
||||
|
@ -52,6 +52,10 @@ namespace AsbCloudInfrastructure
|
||||
{
|
||||
public static void MapsterSetup()
|
||||
{
|
||||
TypeAdapterConfig.GlobalSettings.Default.Config
|
||||
.ForType<ScheduleDto, Schedule>()
|
||||
.Ignore(source => source.Driller);
|
||||
|
||||
TypeAdapterConfig.GlobalSettings.Default.Config
|
||||
.ForType<DateTimeOffset, DateTime>()
|
||||
.MapWith((source) => source.DateTime);
|
||||
|
@ -23,7 +23,6 @@ namespace AsbCloudInfrastructure.Repository;
|
||||
public class WellOperationRepository : IWellOperationRepository
|
||||
{
|
||||
private const string KeyCacheSections = "OperationsBySectionSummarties";
|
||||
private const int Gap = 90;
|
||||
|
||||
private readonly IAsbCloudDbContext db;
|
||||
private readonly IMemoryCache memoryCache;
|
||||
@ -38,13 +37,6 @@ public class WellOperationRepository : IWellOperationRepository
|
||||
this.wellOperationCategoryRepository = wellOperationCategoryRepository;
|
||||
}
|
||||
|
||||
/// <inheritdoc/>
|
||||
public IEnumerable<WellOperationCategoryDto> GetCategories(bool includeParents)
|
||||
{
|
||||
return wellOperationCategoryRepository.Get(includeParents);
|
||||
}
|
||||
|
||||
/// <inheritdoc/>
|
||||
public IEnumerable<WellSectionTypeDto> GetSectionTypes() =>
|
||||
memoryCache
|
||||
.GetOrCreateBasic(db.Set<WellSectionType>())
|
||||
@ -272,7 +264,7 @@ public class WellOperationRepository : IWellOperationRepository
|
||||
DurationDepth = o.DepthEnd - o.DepthStart
|
||||
})
|
||||
.ToListAsync(token);
|
||||
var parentRelationDictionary = GetCategories(true)
|
||||
var parentRelationDictionary = wellOperationCategoryRepository.Get(true)
|
||||
.ToDictionary(c => c.Id, c => new
|
||||
{
|
||||
c.Name,
|
||||
|
@ -6,7 +6,6 @@ using System.Threading.Tasks;
|
||||
using AsbCloudApp.Data;
|
||||
using AsbCloudApp.Repositories;
|
||||
using AsbCloudApp.Requests;
|
||||
using AsbCloudApp.Services;
|
||||
using AsbCloudApp.Services.WellOperationImport;
|
||||
using AsbCloudInfrastructure.Services.WellOperationImport.Constants;
|
||||
using ClosedXML.Excel;
|
||||
@ -15,18 +14,18 @@ namespace AsbCloudInfrastructure.Services.WellOperationImport;
|
||||
|
||||
public class WellOperationExportService : IWellOperationExportService
|
||||
{
|
||||
//TODO: удалить неиспользуемую зависимость
|
||||
private readonly IWellOperationRepository wellOperationRepository;
|
||||
private readonly IWellService wellService;
|
||||
private readonly IWellOperationImportTemplateService wellOperationImportTemplateService;
|
||||
private readonly IWellOperationCategoryRepository wellOperationCategoryRepository;
|
||||
|
||||
public WellOperationExportService(IWellOperationRepository wellOperationRepository,
|
||||
IWellService wellService,
|
||||
IWellOperationImportTemplateService wellOperationImportTemplateService)
|
||||
public WellOperationExportService(
|
||||
IWellOperationRepository wellOperationRepository,
|
||||
IWellOperationImportTemplateService wellOperationImportTemplateService,
|
||||
IWellOperationCategoryRepository wellOperationCategoryRepository)
|
||||
{
|
||||
this.wellOperationRepository = wellOperationRepository;
|
||||
this.wellService = wellService;
|
||||
this.wellOperationImportTemplateService = wellOperationImportTemplateService;
|
||||
this.wellOperationCategoryRepository = wellOperationCategoryRepository;
|
||||
}
|
||||
|
||||
public async Task<Stream> ExportAsync(int idWell, CancellationToken cancellationToken)
|
||||
@ -76,7 +75,7 @@ public class WellOperationExportService : IWellOperationExportService
|
||||
var operationsToArray = operations.ToArray();
|
||||
|
||||
var sections = wellOperationRepository.GetSectionTypes();
|
||||
var categories = wellOperationRepository.GetCategories(false);
|
||||
var categories = wellOperationCategoryRepository.Get(false);
|
||||
|
||||
for (int i = 0; i < operationsToArray.Length; i++)
|
||||
{
|
||||
|
@ -14,16 +14,20 @@ public class WellOperationImportService : IWellOperationImportService
|
||||
{
|
||||
private readonly IWellService wellService;
|
||||
private readonly IWellOperationRepository wellOperationRepository;
|
||||
|
||||
private readonly IWellOperationCategoryRepository wellOperationCategoryRepository;
|
||||
private static readonly DateTime dateLimitMin = new(2001, 1, 1, 0, 0, 0);
|
||||
private static readonly DateTime dateLimitMax = new(2099, 1, 1, 0, 0, 0);
|
||||
private static readonly TimeSpan drillingDurationLimitMax = TimeSpan.FromDays(366);
|
||||
|
||||
public WellOperationImportService(IWellService wellService,
|
||||
IWellOperationRepository wellOperationRepository)
|
||||
public WellOperationImportService(
|
||||
IWellService wellService,
|
||||
IWellOperationRepository wellOperationRepository,
|
||||
IWellOperationCategoryRepository wellOperationCategoryRepository
|
||||
)
|
||||
{
|
||||
this.wellService = wellService;
|
||||
this.wellOperationRepository = wellOperationRepository;
|
||||
this.wellOperationCategoryRepository = wellOperationCategoryRepository;
|
||||
}
|
||||
|
||||
public IEnumerable<WellOperationDto> Import(int idWell, int idUser, int idType, SheetDto sheet)
|
||||
@ -31,7 +35,7 @@ public class WellOperationImportService : IWellOperationImportService
|
||||
var validationErrors = new List<string>();
|
||||
|
||||
var sections = wellOperationRepository.GetSectionTypes();
|
||||
var categories = wellOperationRepository.GetCategories(false);
|
||||
var categories = wellOperationCategoryRepository.Get(false);
|
||||
|
||||
var wellOperations = new List<WellOperationDto>();
|
||||
|
||||
@ -83,7 +87,9 @@ public class WellOperationImportService : IWellOperationImportService
|
||||
IdUser = idUser,
|
||||
IdType = idType,
|
||||
IdWellSectionType = section.Id,
|
||||
WellSectionTypeName = section.Caption,
|
||||
IdCategory = category.Id,
|
||||
CategoryName = category.Name,
|
||||
CategoryInfo = row.CategoryInfo,
|
||||
DepthStart = row.DepthStart,
|
||||
DepthEnd = row.DepthEnd,
|
||||
|
@ -5,6 +5,7 @@ using AsbCloudApp.Requests;
|
||||
using AsbCloudApp.Services;
|
||||
using AsbCloudApp.Services.WellOperationImport;
|
||||
using AsbCloudDb.Model;
|
||||
using AsbCloudInfrastructure.Repository;
|
||||
using AsbCloudInfrastructure.Services.WellOperationImport;
|
||||
using AsbCloudInfrastructure.Services.WellOperationImport.FileParser;
|
||||
using NSubstitute;
|
||||
@ -27,6 +28,7 @@ namespace AsbCloudWebApi.Tests.Services.WellOperationExport
|
||||
|
||||
private IWellService wellService;
|
||||
private IWellOperationRepository wellOperationRepository;
|
||||
private IWellOperationCategoryRepository wellOperationCategoryRepository;
|
||||
private IWellOperationImportTemplateService wellOperationImportTemplateService;
|
||||
private WellOperationExportService wellOperationExportService;
|
||||
private WellOperationImportService wellOperationImportService;
|
||||
@ -114,46 +116,46 @@ namespace AsbCloudWebApi.Tests.Services.WellOperationExport
|
||||
{
|
||||
wellService = Substitute.For<IWellService>();
|
||||
wellOperationRepository = Substitute.For<IWellOperationRepository>();
|
||||
wellOperationCategoryRepository = Substitute.For<IWellOperationCategoryRepository>();
|
||||
wellOperationImportTemplateService = new WellOperationImportTemplateService();
|
||||
wellOperationExportService = new WellOperationExportService(wellOperationRepository, wellService, wellOperationImportTemplateService);
|
||||
wellOperationExportService = new WellOperationExportService(wellOperationRepository, wellService, wellOperationImportTemplateService, wellOperationCategoryRepository);
|
||||
|
||||
wellOperationImportService = new WellOperationImportService(wellService, wellOperationRepository);
|
||||
wellOperationImportService = new WellOperationImportService(wellService, wellOperationRepository, wellOperationCategoryRepository);
|
||||
wellOperationDefaultExcelParser = new WellOperationDefaultExcelParser();
|
||||
this.output = output;
|
||||
}
|
||||
|
||||
#warning Test Check_Exported_WellOperations_With_Operations_In_Db Fails and commented for debug deployment task
|
||||
//[Fact]
|
||||
//public async Task Check_Exported_WellOperations_With_Operations_In_Db()
|
||||
//{
|
||||
// wellService.GetTimezone(idWell).Returns(new SimpleTimezoneDto()
|
||||
// {
|
||||
// Hours = 5
|
||||
// });
|
||||
[Fact]
|
||||
public async Task Check_Exported_WellOperations_With_Operations_In_Db()
|
||||
{
|
||||
wellService.GetTimezone(idWell).Returns(new SimpleTimezoneDto()
|
||||
{
|
||||
Hours = 5
|
||||
});
|
||||
|
||||
// var localOperations = operations.ToArray();
|
||||
// foreach (var operation in localOperations)
|
||||
// operation.Id = 0;
|
||||
var localOperations = operations.ToArray();
|
||||
foreach (var operation in localOperations)
|
||||
operation.Id = 0;
|
||||
|
||||
// wellOperationRepository.GetAsync(Arg.Any<WellOperationRequest>(), Arg.Any<CancellationToken>())
|
||||
// .ReturnsForAnyArgs(localOperations);
|
||||
// wellOperationRepository.GetSectionTypes().Returns(sectionTypes);
|
||||
// wellOperationRepository.GetCategories(false).Returns(categories);
|
||||
wellOperationRepository.GetAsync(Arg.Any<WellOperationRequest>(), Arg.Any<CancellationToken>())
|
||||
.ReturnsForAnyArgs(localOperations);
|
||||
wellOperationRepository.GetSectionTypes().Returns(sectionTypes);
|
||||
wellOperationCategoryRepository.Get(false).Returns(categories);
|
||||
|
||||
// var stream = await wellOperationExportService.ExportAsync(idWell, CancellationToken.None);
|
||||
var stream = await wellOperationExportService.ExportAsync(idWell, CancellationToken.None);
|
||||
|
||||
// var options = new WellOperationImportDefaultOptionsDto
|
||||
// {
|
||||
// IdType = WellOperation.IdOperationTypePlan
|
||||
// };
|
||||
// var sheet = wellOperationDefaultExcelParser.Parse(stream, options);
|
||||
// var result = wellOperationImportService.Import(idWell, 1, options.IdType, sheet);
|
||||
var options = new WellOperationImportDefaultOptionsDto
|
||||
{
|
||||
IdType = WellOperation.IdOperationTypePlan
|
||||
};
|
||||
var sheet = wellOperationDefaultExcelParser.Parse(stream, options);
|
||||
var result = wellOperationImportService.Import(idWell, 1, options.IdType, sheet);
|
||||
|
||||
// var expected = JsonSerializer.Serialize(localOperations);
|
||||
// var actual = JsonSerializer.Serialize(result);
|
||||
var expected = JsonSerializer.Serialize(localOperations);
|
||||
var actual = JsonSerializer.Serialize(result);
|
||||
|
||||
// Assert.Equal(expected, actual);
|
||||
//}
|
||||
Assert.Equal(expected, actual);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void TestDataContainsNotDefaultProps()
|
||||
|
@ -65,7 +65,7 @@ namespace AsbCloudWebApi.Controllers.Subsystems
|
||||
|
||||
[HttpGet("drillerDetectedOperationStat")]
|
||||
[ProducesResponseType(typeof(IEnumerable<DrillerDetectedOperationStatDto>), (int)System.Net.HttpStatusCode.OK)]
|
||||
public async Task<IActionResult> GetByWellsAsync(GetStatRequest request,
|
||||
public async Task<IActionResult> GetByWellsAsync([FromQuery] GetStatRequest request,
|
||||
CancellationToken token)
|
||||
{
|
||||
if (!request.IdsWells.Any())
|
||||
|
@ -35,6 +35,7 @@ namespace AsbCloudWebApi.Controllers
|
||||
private readonly IWellOperationExportService wellOperationExportService;
|
||||
private readonly IWellOperationImportTemplateService wellOperationImportTemplateService;
|
||||
private readonly IWellOperationImportService wellOperationImportService;
|
||||
private readonly IWellOperationCategoryRepository wellOperationCategoryRepository;
|
||||
private readonly IWellOperationExcelParser<WellOperationImportDefaultOptionsDto> wellOperationDefaultExcelParser;
|
||||
private readonly IWellOperationExcelParser<WellOperationImportGazpromKhantosOptionsDto> wellOperationGazpromKhantosExcelParser;
|
||||
private readonly IUserRepository userRepository;
|
||||
@ -44,6 +45,7 @@ namespace AsbCloudWebApi.Controllers
|
||||
IWellOperationImportTemplateService wellOperationImportTemplateService,
|
||||
IWellOperationExportService wellOperationExportService,
|
||||
IWellOperationImportService wellOperationImportService,
|
||||
IWellOperationCategoryRepository wellOperationCategoryRepository,
|
||||
IWellOperationExcelParser<WellOperationImportDefaultOptionsDto> wellOperationDefaultExcelParser,
|
||||
IWellOperationExcelParser<WellOperationImportGazpromKhantosOptionsDto> wellOperationGazpromKhantosExcelParser,
|
||||
IUserRepository userRepository)
|
||||
@ -53,6 +55,7 @@ namespace AsbCloudWebApi.Controllers
|
||||
this.wellOperationImportTemplateService = wellOperationImportTemplateService;
|
||||
this.wellOperationExportService = wellOperationExportService;
|
||||
this.wellOperationImportService = wellOperationImportService;
|
||||
this.wellOperationCategoryRepository = wellOperationCategoryRepository;
|
||||
this.wellOperationDefaultExcelParser = wellOperationDefaultExcelParser;
|
||||
this.wellOperationGazpromKhantosExcelParser = wellOperationGazpromKhantosExcelParser;
|
||||
this.userRepository = userRepository;
|
||||
@ -81,7 +84,7 @@ namespace AsbCloudWebApi.Controllers
|
||||
[ProducesResponseType(typeof(IEnumerable<WellOperationCategoryDto>), (int)System.Net.HttpStatusCode.OK)]
|
||||
public IActionResult GetCategories(bool includeParents = true)
|
||||
{
|
||||
var result = operationRepository.GetCategories(includeParents);
|
||||
var result = wellOperationCategoryRepository.Get(includeParents);
|
||||
return Ok(result);
|
||||
}
|
||||
|
||||
@ -163,7 +166,7 @@ namespace AsbCloudWebApi.Controllers
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Статистика операций по скважине, группированая по категориям
|
||||
/// Статистика операций по скважине, группированная по категориям
|
||||
/// </summary>
|
||||
/// <param name="idWell">id скважины</param>
|
||||
/// <param name="request"></param>
|
||||
|
Loading…
Reference in New Issue
Block a user