diff --git a/AsbCloudApp/Data/SlipsStatDto.cs b/AsbCloudApp/Data/SlipsStatDto.cs index 05843a92..dba3228b 100644 --- a/AsbCloudApp/Data/SlipsStatDto.cs +++ b/AsbCloudApp/Data/SlipsStatDto.cs @@ -39,6 +39,6 @@ namespace AsbCloudApp.Data /// /// Проходка, м. /// - public double SlipsDepth { get; set; } + public double SectionDepth { get; set; } } } diff --git a/AsbCloudApp/Requests/OperationStatRequest.cs b/AsbCloudApp/Requests/OperationStatRequest.cs index 8ab9243e..cda26690 100644 --- a/AsbCloudApp/Requests/OperationStatRequest.cs +++ b/AsbCloudApp/Requests/OperationStatRequest.cs @@ -9,14 +9,14 @@ namespace AsbCloudApp.Requests { /// - /// Дата начала операции + /// Дата начала операции в UTC /// - public DateTime? DateStart { get; set; } + public DateTime? DateStartUTC { get; set; } /// - /// Дата окончания операции + /// Дата окончания операции в UTC /// - public DateTime? DateEnd { get; set; } + public DateTime? DateEndUTC { get; set; } /// diff --git a/AsbCloudApp/Repositories/ISlipsStatRepository.cs b/AsbCloudApp/Services/ISlipsStatService.cs similarity index 90% rename from AsbCloudApp/Repositories/ISlipsStatRepository.cs rename to AsbCloudApp/Services/ISlipsStatService.cs index 6561b0b6..55dd0c0a 100644 --- a/AsbCloudApp/Repositories/ISlipsStatRepository.cs +++ b/AsbCloudApp/Services/ISlipsStatService.cs @@ -5,12 +5,12 @@ using System.Collections.Generic; using System.Threading; using System.Threading.Tasks; -namespace AsbCloudApp.Repositories +namespace AsbCloudApp.Services { /// /// Сервис для получения аналитики удержания в клиньях /// - public interface ISlipsStatRepository + public interface ISlipsStatService { /// /// Получение записей для построения аналитики удержания в клиньях diff --git a/AsbCloudInfrastructure/DependencyInjection.cs b/AsbCloudInfrastructure/DependencyInjection.cs index d499ef02..e2c60158 100644 --- a/AsbCloudInfrastructure/DependencyInjection.cs +++ b/AsbCloudInfrastructure/DependencyInjection.cs @@ -28,6 +28,8 @@ using AsbCloudApp.Services.AutoGeneratedDailyReports; using AsbCloudApp.Services.Notifications; using AsbCloudDb.Model.Manuals; using AsbCloudInfrastructure.Services.AutoGeneratedDailyReports; +using AsbCloudApp.Services.WellOperationImport; +using AsbCloudInfrastructure.Services.WellOperationImport; namespace AsbCloudInfrastructure { @@ -199,7 +201,7 @@ namespace AsbCloudInfrastructure services.AddTransient(); services.AddTransient(); services.AddTransient(); - services.AddTransient(); + services.AddTransient(); services.AddTransient(); services.AddTransient, CrudCacheRepositoryBase>(); diff --git a/AsbCloudInfrastructure/Repository/SlipsStatRepository.cs b/AsbCloudInfrastructure/Services/SlipsStatService.cs similarity index 73% rename from AsbCloudInfrastructure/Repository/SlipsStatRepository.cs rename to AsbCloudInfrastructure/Services/SlipsStatService.cs index 4ca96b95..56e422dd 100644 --- a/AsbCloudInfrastructure/Repository/SlipsStatRepository.cs +++ b/AsbCloudInfrastructure/Services/SlipsStatService.cs @@ -1,6 +1,6 @@ using AsbCloudApp.Data; -using AsbCloudApp.Repositories; using AsbCloudApp.Requests; +using AsbCloudApp.Services; using AsbCloudDb.Model; using Microsoft.EntityFrameworkCore; using System; @@ -9,32 +9,32 @@ using System.Linq; using System.Threading; using System.Threading.Tasks; -namespace AsbCloudInfrastructure.Repository +namespace AsbCloudInfrastructure.Services { - public class SlipsStatRepository : ISlipsStatRepository + public class SlipsStatService : ISlipsStatService { private readonly IAsbCloudDbContext db; - public SlipsStatRepository(IAsbCloudDbContext db) + public SlipsStatService(IAsbCloudDbContext db) { this.db = db; } public async Task> GetAllAsync(OperationStatRequest request, CancellationToken token) { - if (request.DateStart.HasValue) - request.DateStart = DateTime.SpecifyKind(request.DateStart.Value, DateTimeKind.Utc); + if (request.DateStartUTC.HasValue) + request.DateStartUTC = DateTime.SpecifyKind(request.DateStartUTC.Value, DateTimeKind.Utc); - if (request.DateEnd.HasValue) - request.DateEnd = DateTime.SpecifyKind(request.DateEnd.Value, DateTimeKind.Utc); + if (request.DateEndUTC.HasValue) + request.DateEndUTC = DateTime.SpecifyKind(request.DateEndUTC.Value, DateTimeKind.Utc); var schedulesQuery = db.Schedule .Include(s => s.Well) .Include(s => s.Driller) .AsNoTracking(); - if (request.DateStart.HasValue && request.DateEnd.HasValue) + if (request.DateStartUTC.HasValue && request.DateEndUTC.HasValue) schedulesQuery = schedulesQuery. - Where(s => s.DrillStart >= request.DateStart && s.DrillEnd <= request.DateEnd); + Where(s => s.DrillStart >= request.DateStartUTC && s.DrillEnd <= request.DateEndUTC); var schedules = await schedulesQuery.ToArrayAsync(token); @@ -55,9 +55,9 @@ namespace AsbCloudInfrastructure.Repository .Include(o => o.WellSectionType) .AsNoTracking(); - if (request.DateStart.HasValue && request.DateEnd.HasValue) + if (request.DateStartUTC.HasValue && request.DateEndUTC.HasValue) factWellOperationsQuery = factWellOperationsQuery - .Where(o => o.DateStart.AddHours(o.DurationHours) > request.DateStart && o.DateStart < request.DateEnd); + .Where(o => o.DateStart.AddHours(o.DurationHours) > request.DateStartUTC && o.DateStart < request.DateEndUTC); var factWellOperations = await factWellOperationsQuery.ToArrayAsync(token); @@ -69,7 +69,7 @@ namespace AsbCloudInfrastructure.Repository g.Key.IdWellSectionType, DepthStart = g.Min(o => o.DepthStart), DepthEnd = g.Max(o => o.DepthEnd), - g.FirstOrDefault()!.WellSectionType.Caption + g.First().WellSectionType.Caption }); var detectedOperationsQuery = db.DetectedOperations @@ -77,33 +77,22 @@ namespace AsbCloudInfrastructure.Repository .Where(o => o.IdCategory == WellOperationCategory.IdSlipsTime) .AsNoTracking(); - if (request.DateStart.HasValue && request.DateEnd.HasValue) + if (request.DateStartUTC.HasValue && request.DateEndUTC.HasValue) detectedOperationsQuery = detectedOperationsQuery - .Where(o => o.DateStart < request.DateEnd) - .Where(o => o.DateEnd > request.DateStart); + .Where(o => o.DateStart < request.DateEndUTC) + .Where(o => o.DateEnd > request.DateStartUTC); - TimeSpan? durationMinutesMin = request.DurationMinutesMin.HasValue - ? new TimeSpan(0, request.DurationMinutesMin.Value, 0) - : null; - TimeSpan? durationMinutesMax = request.DurationMinutesMax.HasValue - ? new TimeSpan(0, request.DurationMinutesMax.Value, 0) - : null; - - if (durationMinutesMin.HasValue && durationMinutesMax.HasValue) + if (request.DurationMinutesMin.HasValue) { + var durationMinutesMin = new TimeSpan(0, request.DurationMinutesMin.Value, 0); detectedOperationsQuery = detectedOperationsQuery - .Where(o => o.DateEnd - o.DateStart >= durationMinutesMin.Value - && o.DateEnd - o.DateStart <= durationMinutesMax.Value); + .Where(o => o.DateEnd - o.DateStart >= durationMinutesMin); } - else if (durationMinutesMin.HasValue && !durationMinutesMax.HasValue) + if (request.DurationMinutesMax.HasValue) { + var durationMinutesMax = new TimeSpan(0, request.DurationMinutesMax.Value, 0); detectedOperationsQuery = detectedOperationsQuery - .Where(o => o.DateEnd - o.DateStart >= durationMinutesMin.Value); - } - else if (!durationMinutesMin.HasValue && durationMinutesMax.HasValue) - { - detectedOperationsQuery = detectedOperationsQuery - .Where(o => o.DateEnd - o.DateStart <= durationMinutesMax.Value); + .Where(o => o.DateEnd - o.DateStart <= durationMinutesMax); } var detectedOperations = await detectedOperationsQuery @@ -159,11 +148,11 @@ namespace AsbCloudInfrastructure.Repository SlipsCount = group.Count(), SlipsTimeInMinutes = group .Sum(y => (y.Operation.DateEnd - y.Operation.DateStart).TotalMinutes), - SlipsDepth = factWellOperationsGroupedByDrillerAndSection + SectionDepth = factWellOperationsGroupedByDrillerAndSection .Where(o => o.Key.Id == group.Key.Id) .Where(o => o.Key.IdWellSectionType == group.Key.IdWellSectionType) .Sum(o => o.Max(op => op.Operation.DepthEnd) - o.Min(op => op.Operation.DepthStart)), - SectionCaption = group.First().Section!.Caption, + SectionCaption = group.First().Section.Caption, WellCount = group.GroupBy(g => g.IdWell).Count(), }); diff --git a/AsbCloudWebApi/Controllers/SlipsStatController.cs b/AsbCloudWebApi/Controllers/SlipsStatController.cs index fe0c7222..124622a3 100644 --- a/AsbCloudWebApi/Controllers/SlipsStatController.cs +++ b/AsbCloudWebApi/Controllers/SlipsStatController.cs @@ -1,7 +1,7 @@ using AsbCloudApp.Data; using AsbCloudApp.Exceptions; -using AsbCloudApp.Repositories; using AsbCloudApp.Requests; +using AsbCloudApp.Services; using AsbCloudDb.Model; using Microsoft.AspNetCore.Authorization; using Microsoft.AspNetCore.Mvc; @@ -20,9 +20,9 @@ namespace AsbCloudWebApi.Controllers [Authorize] public class SlipsStatController : ControllerBase { - private readonly ISlipsStatRepository slipsAnalyticsService; + private readonly ISlipsStatService slipsAnalyticsService; - public SlipsStatController(ISlipsStatRepository slipsAnalyticsService) + public SlipsStatController(ISlipsStatService slipsAnalyticsService) { this.slipsAnalyticsService = slipsAnalyticsService; }