Рефакторинг DTO ГГД. Фикс репозитория

This commit is contained in:
Степанов Дмитрий 2024-03-22 07:29:01 +03:00
parent 88c928cd5d
commit 151e481a98
14 changed files with 66 additions and 55 deletions

View File

@ -6,7 +6,8 @@ namespace AsbCloudApp.Data.WellOperation;
public class WellOperationDto : ItemInfoDto,
IId,
IWellRelated
IWellRelated,
IValidatableObject
{
/// <inheritdoc/>
[Required]

View File

@ -1,4 +1,4 @@
using System;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading;
@ -176,10 +176,10 @@ public class WellOperationRepository : CrudRepositoryBase<WellOperationDto, Well
private IQueryable<WellOperation> BuildQuery(WellOperationRequest request)
{
var currentWellOperations = GetQuery()
.Where(e => request.IdsWell != null && request.IdsWell.Contains(e.Id));
.Where(e => request.IdsWell != null && request.IdsWell.Contains(e.IdWell));
var query = GetQuery()
.Where(e => request.IdsWell != null && request.IdsWell.Contains(e.Id))
.Where(e => request.IdsWell != null && request.IdsWell.Contains(e.IdWell))
.Select(o => new WellOperation
{
Id = o.Id,

View File

@ -13,6 +13,7 @@ using AsbCloudApp.Data.DailyReport.Blocks.Sign;
using AsbCloudApp.Data.DailyReport.Blocks.Subsystems;
using AsbCloudApp.Data.DailyReport.Blocks.TimeBalance;
using AsbCloudApp.Data.DailyReport.Blocks.WellOperation;
using AsbCloudApp.Data.WellOperation;
using AsbCloudApp.Requests;
using AsbCloudApp.Services.DailyReport;
using AsbCloudApp.Services.ProcessMaps.WellDrilling;
@ -107,14 +108,14 @@ public class DailyReportService : IDailyReportService
};
var geDate = dailyReport.Date.ToDateTime(TimeOnly.MinValue, DateTimeKind.Unspecified);
var ltDate = dailyReport.Date.AddDays(1).ToDateTime(TimeOnly.MinValue, DateTimeKind.Unspecified);
var leDate = dailyReport.Date.AddDays(1).ToDateTime(TimeOnly.MinValue, DateTimeKind.Unspecified);
var factOperationRequest = new WellOperationRequest
{
IdWell = idWell,
IdsWell = new []{ idWell },
OperationType = WellOperation.IdOperationTypeFact,
GeDate = geDate,
LtDate = ltDate
LeDate = leDate
};
var factWellOperations = (await wellOperationRepository.GetAsync(factOperationRequest, cancellationToken))
@ -184,14 +185,14 @@ public class DailyReportService : IDailyReportService
var existingDailyReports = await dailyReportRepository.GetAsync(idWell, request, cancellationToken);
var geDateFactWellOperation = datesRange.From.AddDays(result.Skip);
var ltDateFactWellOperation = geDateFactWellOperation.AddDays(result.Take);
var leDateFactWellOperation = geDateFactWellOperation.AddDays(result.Take);
var factWellOperationRequest = new WellOperationRequest
{
IdWell = idWell,
IdsWell = new[] { idWell },
OperationType = WellOperation.IdOperationTypeFact,
GeDate = geDateFactWellOperation,
LtDate = ltDateFactWellOperation
LeDate = leDateFactWellOperation
};
var factWellOperations = await wellOperationRepository.GetAsync(factWellOperationRequest, cancellationToken);
@ -200,7 +201,7 @@ public class DailyReportService : IDailyReportService
{
for (var day = result.Skip; day - result.Skip < result.Take && datesRange.To.AddDays(-day) >= datesRange.From; day++)
{
var dateDailyReport = DateOnly.FromDateTime(datesRange.To.AddDays(-day));
var dateDailyReport = DateOnly.FromDateTime(datesRange.To.AddDays(-day).DateTime);
AddDailyReport(dateDailyReport);
}
@ -209,7 +210,7 @@ public class DailyReportService : IDailyReportService
{
for (var day = result.Skip; day - result.Skip < result.Take && datesRange.From.AddDays(day) <= datesRange.To; day++)
{
var dateDailyReport = DateOnly.FromDateTime(datesRange.From.AddDays(day));
var dateDailyReport = DateOnly.FromDateTime(datesRange.From.AddDays(day).DateTime);
AddDailyReport(dateDailyReport);
}
@ -401,7 +402,7 @@ public class DailyReportService : IDailyReportService
WellOperations = factWellOperations.GroupBy(o => o.IdCategory)
.Select(g => new WellOperationRecordDto
{
CategoryName = g.First().CategoryName,
CategoryName = g.First().OperationCategoryName,
DurationHours = g.Sum(o => o.DurationHours)
}),
@ -418,8 +419,8 @@ public class DailyReportService : IDailyReportService
if (datesRange is null)
return false;
var from = DateOnly.FromDateTime(datesRange.From);
var to = DateOnly.FromDateTime(datesRange.To);
var from = DateOnly.FromDateTime(datesRange.From.DateTime);
var to = DateOnly.FromDateTime(datesRange.To.DateTime);
return dateDailyReport >= from && dateDailyReport <= to;
}

View File

@ -13,6 +13,7 @@ using Microsoft.AspNetCore.Http.Extensions;
using AsbCloudApp.Exceptions;
using AsbCloudApp.Services;
using AsbCloudApp.Data;
using AsbCloudApp.Data.WellOperation;
using AsbCloudInfrastructure.Services.DetectOperations.Detectors;
namespace AsbCloudInfrastructure.Services.DetectOperations;

View File

@ -10,6 +10,7 @@ using System.Collections.Generic;
using System.Linq;
using System.Threading;
using System.Threading.Tasks;
using AsbCloudApp.Data.WellOperation;
using AsbCloudInfrastructure.Services.DetectOperations.Detectors;
namespace AsbCloudInfrastructure.Services.DetectOperations;

View File

@ -102,7 +102,7 @@ namespace AsbCloudInfrastructure.Services.SAUB
if (dateBegin == default)
{
var dateRange = telemetryDataCache.GetOrDefaultDataDateRange(telemetry.Id);
dateBeginUtc = (dateRange?.To.ToUtcDateTimeOffset(timezone.Hours) ?? DateTime.UtcNow)
dateBeginUtc = (dateRange?.To.UtcDateTime ?? DateTime.UtcNow)
.AddSeconds(-intervalSec);
}
else

View File

@ -8,6 +8,7 @@ using System.Collections.Generic;
using System.Linq;
using System.Threading;
using System.Threading.Tasks;
using AsbCloudApp.Data.WellOperation;
namespace AsbCloudInfrastructure.Services
{
@ -133,7 +134,7 @@ namespace AsbCloudInfrastructure.Services
this.wellOperationRepository = wellOperationRepository;
}
public async Task<List<Dictionary<int, WellOperationDataDto>>> GetAsync(IEnumerable<int> idsWells, CancellationToken token)
public async Task<IEnumerable<Dictionary<int, WellOperationDto>>> GetAsync(IEnumerable<int> idsWells, CancellationToken token)
{
var sections = await wellSectionTypeRepository.GetAllAsync(token);
var sectionsDict = sections.ToDictionary(s => s.Id, s => s.Caption);
@ -144,7 +145,7 @@ namespace AsbCloudInfrastructure.Services
var idsWellSectionTypes = WellSectionTypesWithCategories.Select(t => t.IdSectionType).Distinct();
var usedCategories = WellSectionTypesWithCategories.Select(c => c.IdCategory).Distinct();
var wellOperationRequest = new WellsOperationRequest()
var wellOperationRequest = new WellOperationRequest
{
IdsWell = idsWells,
OperationCategoryIds = usedCategories,
@ -155,7 +156,7 @@ namespace AsbCloudInfrastructure.Services
var renamedOperations = operations.Select(o => UpdateIdWellSectionAndIdCategory(o, sectionsDict, categoriesDict));
var wellOperationsWithComposite = new List<Dictionary<int, WellOperationDataDto>>();
var wellOperationsWithComposite = new List<Dictionary<int, WellOperationDto>>();
var compositeDepth = 0d;
foreach ((int IdSection, int IdCategory) in WellSectionTypesWithCategories)
{
@ -168,7 +169,7 @@ namespace AsbCloudInfrastructure.Services
var groupedByWell = filteredByTemplate.GroupBy(o => o.IdWell);
var aggreagtedByWell = groupedByWell.Select(g => new WellOperationDataDto
var aggreagtedByWell = groupedByWell.Select(g => new WellOperationDto
{
IdCategory = IdCategory,
IdWell = g.Key,
@ -197,15 +198,15 @@ namespace AsbCloudInfrastructure.Services
return wellOperationsWithComposite;
}
private static WellOperationDataDto UpdateIdWellSectionAndIdCategory(
WellOperationDataDto dto,
Dictionary<int, string> sectionTypes,
Dictionary<int, string> operationCategories)
private static WellOperationDto UpdateIdWellSectionAndIdCategory(
WellOperationDto dto,
IDictionary<int, string> sectionTypes,
IDictionary<int, string> operationCategories)
{
if (dto.IdWellSectionType == wellSectionTransportTable)
{
dto.IdWellSectionType = wellSectionProductionString;
dto.WellSectionTypeCaption = sectionTypes[dto.IdWellSectionType] ?? string.Empty;
dto.WellSectionTypeCaption = sectionTypes[dto.IdWellSectionType];
}
if ((SettingsForSectionCategoryChange.TryGetValue((dto.IdWellSectionType, dto.IdCategory), out int newIdCategory)))

View File

@ -10,6 +10,7 @@ using System.Linq;
using System.Threading;
using System.Threading.Tasks;
using AsbCloudApp.Data.SAUB;
using AsbCloudApp.Data.WellOperation;
using AsbCloudApp.Repositories;
namespace AsbCloudInfrastructure.Services.WellOperationService;
@ -552,8 +553,8 @@ public class OperationsStatService : IOperationsStatService
private static WellOperationDto Convert(WellOperation source, double tzOffsetHours)
{
var destination = source.Adapt<WellOperationDto>();
destination.CategoryName = source.OperationCategory?.Name;
destination.WellSectionTypeName = source.WellSectionType?.Caption;
destination.OperationCategoryName = source.OperationCategory.Name;
destination.WellSectionTypeCaption = source.WellSectionType.Caption;
destination.DateStart = source.DateStart.ToRemoteDateTime(tzOffsetHours);
return destination;
}

View File

@ -47,7 +47,7 @@ namespace AsbCloudInfrastructure.Services
this.telemetryService = telemetryService;
this.timezoneService = timezoneService;
this.wellInfoService = wellInfoService;
this.wellOperationRepository = new WellOperationRepository(db, memoryCache, this, wellOperationCategoryRepository);
wellOperationRepository = new WellOperationRepository(db, memoryCache, wellOperationCategoryRepository, this);
companyTypesService = new CrudCacheRepositoryBase<CompanyTypeDto, CompanyType>(dbContext, memoryCache);
}
@ -71,7 +71,7 @@ namespace AsbCloudInfrastructure.Services
return DateTime.MinValue;
var datesRange = telemetryService.GetDatesRange(well.IdTelemetry.Value);
return datesRange.To;
return datesRange.To.DateTime;
}
/// <inheritdoc/>
@ -273,12 +273,13 @@ namespace AsbCloudInfrastructure.Services
if (entity.Timezone is null)
dto.Timezone = GetTimezone(entity.Id);
dto.StartDate = wellOperationRepository.FirstOperationDate(entity.Id)?.ToRemoteDateTime(dto.Timezone.Hours);
//TODO: фикс
//dto.StartDate = wellOperationRepository.GetDatesRangeAsync(entity.Id, ).FirstOperationDate(entity.Id)?.ToRemoteDateTime(dto.Timezone.Hours);
dto.WellType = entity.WellType.Caption;
dto.Cluster = entity.Cluster.Caption;
dto.Deposit = entity.Cluster.Deposit.Caption;
if (entity.IdTelemetry is not null)
dto.LastTelemetryDate = telemetryService.GetDatesRange(entity.IdTelemetry.Value).To;
dto.LastTelemetryDate = telemetryService.GetDatesRange(entity.IdTelemetry.Value).To.DateTime;
dto.Companies = entity.RelationCompaniesWells
.Select(r => Convert(r.Company))
.ToList();

View File

@ -19,6 +19,7 @@ using System.Collections.Generic;
using System.Linq;
using System.Threading;
using System.Threading.Tasks;
using AsbCloudApp.Data.WellOperation;
using Xunit;
namespace AsbCloudWebApi.Tests.Services;
@ -154,7 +155,7 @@ public class DailyReportServiceTest
IdWell = idWell,
IdParentCategory = 4001,
IdWellSectionType = 1,
CategoryName = "Механическое. бурение",
OperationCategoryName = "Механическое. бурение",
DateStart = new DateTime(2023, 10, 26),
DepthStart = 80,
DepthEnd = 150,
@ -164,7 +165,7 @@ public class DailyReportServiceTest
private readonly WellOperationDto fakeLastFactWellOperation = new()
{
IdWell = idWell,
CategoryName = "Механическое. бурение",
OperationCategoryName = "Механическое. бурение",
IdWellSectionType = 1,
IdParentCategory = 4001,
DateStart = new DateTime(2023, 10, 26),

View File

@ -15,6 +15,7 @@ using System.Threading.Tasks;
using Xunit;
using AsbCloudApp.Repositories;
using AsbCloudApp.Data;
using AsbCloudApp.Data.WellOperation;
using AsbCloudApp.Services;
namespace AsbCloudWebApi.Tests.Services.WellCompositeOperation
@ -50,9 +51,9 @@ namespace AsbCloudWebApi.Tests.Services.WellCompositeOperation
new() {Id = 31, Caption = "Техническая колонна", Order = 2}
};
private readonly static IEnumerable<WellOperationDataDto> wellOperations1 = new List<WellOperationDataDto>()
private readonly static IEnumerable<WellOperationDto> wellOperations1 = new List<WellOperationDto>()
{
new WellOperationDataDto()
new()
{
DepthStart = 50,
DurationHours = 1,
@ -62,7 +63,7 @@ namespace AsbCloudWebApi.Tests.Services.WellCompositeOperation
OperationCategoryName = "Шаблонирование перед спуском",
WellSectionTypeCaption = "Направление"
},
new WellOperationDataDto()
new()
{
DepthStart = 84,
DurationHours = 1,
@ -74,9 +75,9 @@ namespace AsbCloudWebApi.Tests.Services.WellCompositeOperation
}
};
private readonly static IEnumerable<WellOperationDataDto> wellOperations2 = new List<WellOperationDataDto>()
private readonly static IEnumerable<WellOperationDto> wellOperations2 = new List<WellOperationDto>()
{
new WellOperationDataDto()
new()
{
DepthStart = 10,
DurationHours = 1.5,
@ -86,7 +87,7 @@ namespace AsbCloudWebApi.Tests.Services.WellCompositeOperation
OperationCategoryName = "Бурение ротором",
WellSectionTypeCaption = "Направление"
},
new WellOperationDataDto()
new()
{
DepthStart = 20,
DurationHours = 3.5,
@ -98,9 +99,9 @@ namespace AsbCloudWebApi.Tests.Services.WellCompositeOperation
}
};
private readonly static IEnumerable<WellOperationDataDto> wellOperations3 = new List<WellOperationDataDto>()
private readonly static IEnumerable<WellOperationDto> wellOperations3 = new List<WellOperationDto>()
{
new WellOperationDataDto()
new()
{
DepthStart = 1372,
DurationHours = 3,
@ -110,7 +111,7 @@ namespace AsbCloudWebApi.Tests.Services.WellCompositeOperation
OperationCategoryName = "Промывка",
WellSectionTypeCaption = "Кондуктор"
},
new WellOperationDataDto()
new()
{
DepthStart = 1435,
DurationHours = 4,
@ -122,9 +123,9 @@ namespace AsbCloudWebApi.Tests.Services.WellCompositeOperation
}
};
private readonly static IEnumerable<WellOperationDataDto> wellOperations4 = new List<WellOperationDataDto>()
private readonly static IEnumerable<WellOperationDto> wellOperations4 = new List<WellOperationDto>()
{
new WellOperationDataDto()
new()
{
DepthStart = 1000,
DurationHours = 10,
@ -134,7 +135,7 @@ namespace AsbCloudWebApi.Tests.Services.WellCompositeOperation
OperationCategoryName = "Подъем инструмента",
WellSectionTypeCaption = "Техническая колонна"
},
new WellOperationDataDto()
new()
{
DepthStart = 500,
DurationHours = 5,
@ -144,7 +145,7 @@ namespace AsbCloudWebApi.Tests.Services.WellCompositeOperation
OperationCategoryName = "Проработка принудительная",
WellSectionTypeCaption = "Техническая колонна"
},
new WellOperationDataDto()
new()
{
DepthStart = 600,
DurationHours = 5,
@ -181,7 +182,7 @@ namespace AsbCloudWebApi.Tests.Services.WellCompositeOperation
public async Task GetAsync_return_composite_and_others_with_category_5013()
{
// arrange
wellOperationRepository.GetAsync(Arg.Any<WellsOperationRequest>(), Arg.Any<CancellationToken>())
wellOperationRepository.GetAsync(Arg.Any<WellOperationRequest>(), Arg.Any<CancellationToken>())
.Returns(wellOperations1);
var idsWell = new List<int>() { 55, 64 };
@ -216,7 +217,7 @@ namespace AsbCloudWebApi.Tests.Services.WellCompositeOperation
public async Task GetAsync_return_composite_with_minimum_depth_start()
{
// arrange
wellOperationRepository.GetAsync(Arg.Any<WellsOperationRequest>(), Arg.Any<CancellationToken>())
wellOperationRepository.GetAsync(Arg.Any<WellOperationRequest>(), Arg.Any<CancellationToken>())
.Returns(wellOperations2);
var idsWell = new List<int>() { 55, 64 };
@ -242,7 +243,7 @@ namespace AsbCloudWebApi.Tests.Services.WellCompositeOperation
public async Task GetAsync_return_data3()
{
// arrange
wellOperationRepository.GetAsync(Arg.Any<WellsOperationRequest>(), Arg.Any<CancellationToken>())
wellOperationRepository.GetAsync(Arg.Any<WellOperationRequest>(), Arg.Any<CancellationToken>())
.Returns(wellOperations3);
var idsWell = new List<int>() { 55, 64 };
@ -272,7 +273,7 @@ namespace AsbCloudWebApi.Tests.Services.WellCompositeOperation
public async Task GetAsync_return_data4()
{
// arrange
wellOperationRepository.GetAsync(Arg.Any<WellsOperationRequest>(), Arg.Any<CancellationToken>())
wellOperationRepository.GetAsync(Arg.Any<WellOperationRequest>(), Arg.Any<CancellationToken>())
.Returns(wellOperations4);
var idsWell = new List<int>() { 55, 64 };
@ -312,13 +313,13 @@ namespace AsbCloudWebApi.Tests.Services.WellCompositeOperation
public async Task GetAsync_return_data5()
{
// arrange
var wellOperations = new List<WellOperationDataDto>();
var wellOperations = new List<WellOperationDto>();
wellOperations.AddRange(wellOperations1);
wellOperations.AddRange(wellOperations2);
wellOperations.AddRange(wellOperations3);
wellOperations.AddRange(wellOperations4);
wellOperationRepository.GetAsync(Arg.Any<WellsOperationRequest>(), Arg.Any<CancellationToken>())
wellOperationRepository.GetAsync(Arg.Any<WellOperationRequest>(), Arg.Any<CancellationToken>())
.Returns(wellOperations);
var idsWell = new List<int>() { 55, 64 };

View File

@ -6,6 +6,7 @@ using System.Collections.Generic;
using System.Linq;
using System.Threading;
using System.Threading.Tasks;
using AsbCloudApp.Data.WellOperation;
namespace AsbCloudWebApi.Controllers
{

View File

@ -1,5 +1,4 @@
using AsbCloudApp.Data;
using AsbCloudApp.Data.DetectedOperation;
using AsbCloudApp.Data.DetectedOperation;
using AsbCloudApp.Requests;
using AsbCloudApp.Services;
using Microsoft.AspNetCore.Authorization;
@ -7,6 +6,7 @@ using Microsoft.AspNetCore.Mvc;
using System.Collections.Generic;
using System.Threading;
using System.Threading.Tasks;
using AsbCloudApp.Data.WellOperation;
using AsbCloudInfrastructure.Services.DetectOperations;
using Microsoft.AspNetCore.Http;

View File

@ -5,6 +5,7 @@ using Microsoft.AspNetCore.Mvc;
using System.Collections.Generic;
using System.Threading;
using System.Threading.Tasks;
using AsbCloudApp.Data.WellOperation;
namespace AsbCloudWebApi.Controllers
{
@ -24,7 +25,7 @@ namespace AsbCloudWebApi.Controllers
}
[HttpGet]
[ProducesResponseType(typeof(IList<IDictionary<int, WellOperationDataDto>>), (int)System.Net.HttpStatusCode.OK)]
[ProducesResponseType(typeof(IList<IDictionary<int, WellOperationDto>>), (int)System.Net.HttpStatusCode.OK)]
public async Task<IActionResult> GetAsync([FromQuery] IEnumerable<int> idsWells, CancellationToken token)
{
foreach (var idWell in idsWells)