Правки по ревью

This commit is contained in:
Olga Nemt 2023-10-03 15:32:58 +05:00
parent 3b8b3e38f0
commit 2b400012c6
6 changed files with 37 additions and 46 deletions

View File

@ -39,6 +39,6 @@ namespace AsbCloudApp.Data
/// <summary> /// <summary>
/// Проходка, м. /// Проходка, м.
/// </summary> /// </summary>
public double SlipsDepth { get; set; } public double SectionDepth { get; set; }
} }
} }

View File

@ -9,14 +9,14 @@ namespace AsbCloudApp.Requests
{ {
/// <summary> /// <summary>
/// Дата начала операции /// Дата начала операции в UTC
/// </summary> /// </summary>
public DateTime? DateStart { get; set; } public DateTime? DateStartUTC { get; set; }
/// <summary> /// <summary>
/// Дата окончания операции /// Дата окончания операции в UTC
/// </summary> /// </summary>
public DateTime? DateEnd { get; set; } public DateTime? DateEndUTC { get; set; }
/// <summary> /// <summary>

View File

@ -5,12 +5,12 @@ using System.Collections.Generic;
using System.Threading; using System.Threading;
using System.Threading.Tasks; using System.Threading.Tasks;
namespace AsbCloudApp.Repositories namespace AsbCloudApp.Services
{ {
/// <summary> /// <summary>
/// Сервис для получения аналитики удержания в клиньях /// Сервис для получения аналитики удержания в клиньях
/// </summary> /// </summary>
public interface ISlipsStatRepository public interface ISlipsStatService
{ {
/// <summary> /// <summary>
/// Получение записей для построения аналитики удержания в клиньях /// Получение записей для построения аналитики удержания в клиньях

View File

@ -28,6 +28,8 @@ using AsbCloudApp.Services.AutoGeneratedDailyReports;
using AsbCloudApp.Services.Notifications; using AsbCloudApp.Services.Notifications;
using AsbCloudDb.Model.Manuals; using AsbCloudDb.Model.Manuals;
using AsbCloudInfrastructure.Services.AutoGeneratedDailyReports; using AsbCloudInfrastructure.Services.AutoGeneratedDailyReports;
using AsbCloudApp.Services.WellOperationImport;
using AsbCloudInfrastructure.Services.WellOperationImport;
namespace AsbCloudInfrastructure namespace AsbCloudInfrastructure
{ {
@ -199,7 +201,7 @@ namespace AsbCloudInfrastructure
services.AddTransient<ITrajectoryPlanRepository, TrajectoryPlanRepository>(); services.AddTransient<ITrajectoryPlanRepository, TrajectoryPlanRepository>();
services.AddTransient<ITrajectoryFactRepository, TrajectoryFactRepository>(); services.AddTransient<ITrajectoryFactRepository, TrajectoryFactRepository>();
services.AddTransient<IFaqRepository, FaqRepository>(); services.AddTransient<IFaqRepository, FaqRepository>();
services.AddTransient<ISlipsStatRepository, SlipsStatRepository>(); services.AddTransient<ISlipsStatService, SlipsStatService>();
services.AddTransient<IWellContactService, WellContactService>(); services.AddTransient<IWellContactService, WellContactService>();
services.AddTransient<ICrudRepository<WellSectionTypeDto>, CrudCacheRepositoryBase<WellSectionTypeDto, services.AddTransient<ICrudRepository<WellSectionTypeDto>, CrudCacheRepositoryBase<WellSectionTypeDto,
WellSectionType>>(); WellSectionType>>();

View File

@ -1,6 +1,6 @@
using AsbCloudApp.Data; using AsbCloudApp.Data;
using AsbCloudApp.Repositories;
using AsbCloudApp.Requests; using AsbCloudApp.Requests;
using AsbCloudApp.Services;
using AsbCloudDb.Model; using AsbCloudDb.Model;
using Microsoft.EntityFrameworkCore; using Microsoft.EntityFrameworkCore;
using System; using System;
@ -9,32 +9,32 @@ using System.Linq;
using System.Threading; using System.Threading;
using System.Threading.Tasks; using System.Threading.Tasks;
namespace AsbCloudInfrastructure.Repository namespace AsbCloudInfrastructure.Services
{ {
public class SlipsStatRepository : ISlipsStatRepository public class SlipsStatService : ISlipsStatService
{ {
private readonly IAsbCloudDbContext db; private readonly IAsbCloudDbContext db;
public SlipsStatRepository(IAsbCloudDbContext db) public SlipsStatService(IAsbCloudDbContext db)
{ {
this.db = db; this.db = db;
} }
public async Task<IEnumerable<SlipsStatDto>> GetAllAsync(OperationStatRequest request, CancellationToken token) public async Task<IEnumerable<SlipsStatDto>> GetAllAsync(OperationStatRequest request, CancellationToken token)
{ {
if (request.DateStart.HasValue) if (request.DateStartUTC.HasValue)
request.DateStart = DateTime.SpecifyKind(request.DateStart.Value, DateTimeKind.Utc); request.DateStartUTC = DateTime.SpecifyKind(request.DateStartUTC.Value, DateTimeKind.Utc);
if (request.DateEnd.HasValue) if (request.DateEndUTC.HasValue)
request.DateEnd = DateTime.SpecifyKind(request.DateEnd.Value, DateTimeKind.Utc); request.DateEndUTC = DateTime.SpecifyKind(request.DateEndUTC.Value, DateTimeKind.Utc);
var schedulesQuery = db.Schedule var schedulesQuery = db.Schedule
.Include(s => s.Well) .Include(s => s.Well)
.Include(s => s.Driller) .Include(s => s.Driller)
.AsNoTracking(); .AsNoTracking();
if (request.DateStart.HasValue && request.DateEnd.HasValue) if (request.DateStartUTC.HasValue && request.DateEndUTC.HasValue)
schedulesQuery = schedulesQuery. 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); var schedules = await schedulesQuery.ToArrayAsync(token);
@ -55,9 +55,9 @@ namespace AsbCloudInfrastructure.Repository
.Include(o => o.WellSectionType) .Include(o => o.WellSectionType)
.AsNoTracking(); .AsNoTracking();
if (request.DateStart.HasValue && request.DateEnd.HasValue) if (request.DateStartUTC.HasValue && request.DateEndUTC.HasValue)
factWellOperationsQuery = factWellOperationsQuery 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); var factWellOperations = await factWellOperationsQuery.ToArrayAsync(token);
@ -69,7 +69,7 @@ namespace AsbCloudInfrastructure.Repository
g.Key.IdWellSectionType, g.Key.IdWellSectionType,
DepthStart = g.Min(o => o.DepthStart), DepthStart = g.Min(o => o.DepthStart),
DepthEnd = g.Max(o => o.DepthEnd), DepthEnd = g.Max(o => o.DepthEnd),
g.FirstOrDefault()!.WellSectionType.Caption g.First().WellSectionType.Caption
}); });
var detectedOperationsQuery = db.DetectedOperations var detectedOperationsQuery = db.DetectedOperations
@ -77,33 +77,22 @@ namespace AsbCloudInfrastructure.Repository
.Where(o => o.IdCategory == WellOperationCategory.IdSlipsTime) .Where(o => o.IdCategory == WellOperationCategory.IdSlipsTime)
.AsNoTracking(); .AsNoTracking();
if (request.DateStart.HasValue && request.DateEnd.HasValue) if (request.DateStartUTC.HasValue && request.DateEndUTC.HasValue)
detectedOperationsQuery = detectedOperationsQuery detectedOperationsQuery = detectedOperationsQuery
.Where(o => o.DateStart < request.DateEnd) .Where(o => o.DateStart < request.DateEndUTC)
.Where(o => o.DateEnd > request.DateStart); .Where(o => o.DateEnd > request.DateStartUTC);
TimeSpan? durationMinutesMin = request.DurationMinutesMin.HasValue if (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)
{ {
var durationMinutesMin = new TimeSpan(0, request.DurationMinutesMin.Value, 0);
detectedOperationsQuery = detectedOperationsQuery detectedOperationsQuery = detectedOperationsQuery
.Where(o => o.DateEnd - o.DateStart >= durationMinutesMin.Value .Where(o => o.DateEnd - o.DateStart >= durationMinutesMin);
&& o.DateEnd - o.DateStart <= durationMinutesMax.Value);
} }
else if (durationMinutesMin.HasValue && !durationMinutesMax.HasValue) if (request.DurationMinutesMax.HasValue)
{ {
var durationMinutesMax = new TimeSpan(0, request.DurationMinutesMax.Value, 0);
detectedOperationsQuery = detectedOperationsQuery detectedOperationsQuery = detectedOperationsQuery
.Where(o => o.DateEnd - o.DateStart >= durationMinutesMin.Value); .Where(o => o.DateEnd - o.DateStart <= durationMinutesMax);
}
else if (!durationMinutesMin.HasValue && durationMinutesMax.HasValue)
{
detectedOperationsQuery = detectedOperationsQuery
.Where(o => o.DateEnd - o.DateStart <= durationMinutesMax.Value);
} }
var detectedOperations = await detectedOperationsQuery var detectedOperations = await detectedOperationsQuery
@ -159,11 +148,11 @@ namespace AsbCloudInfrastructure.Repository
SlipsCount = group.Count(), SlipsCount = group.Count(),
SlipsTimeInMinutes = group SlipsTimeInMinutes = group
.Sum(y => (y.Operation.DateEnd - y.Operation.DateStart).TotalMinutes), .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.Id == group.Key.Id)
.Where(o => o.Key.IdWellSectionType == group.Key.IdWellSectionType) .Where(o => o.Key.IdWellSectionType == group.Key.IdWellSectionType)
.Sum(o => o.Max(op => op.Operation.DepthEnd) - o.Min(op => op.Operation.DepthStart)), .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(), WellCount = group.GroupBy(g => g.IdWell).Count(),
}); });

View File

@ -1,7 +1,7 @@
using AsbCloudApp.Data; using AsbCloudApp.Data;
using AsbCloudApp.Exceptions; using AsbCloudApp.Exceptions;
using AsbCloudApp.Repositories;
using AsbCloudApp.Requests; using AsbCloudApp.Requests;
using AsbCloudApp.Services;
using AsbCloudDb.Model; using AsbCloudDb.Model;
using Microsoft.AspNetCore.Authorization; using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Mvc; using Microsoft.AspNetCore.Mvc;
@ -20,9 +20,9 @@ namespace AsbCloudWebApi.Controllers
[Authorize] [Authorize]
public class SlipsStatController : ControllerBase public class SlipsStatController : ControllerBase
{ {
private readonly ISlipsStatRepository slipsAnalyticsService; private readonly ISlipsStatService slipsAnalyticsService;
public SlipsStatController(ISlipsStatRepository slipsAnalyticsService) public SlipsStatController(ISlipsStatService slipsAnalyticsService)
{ {
this.slipsAnalyticsService = slipsAnalyticsService; this.slipsAnalyticsService = slipsAnalyticsService;
} }