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

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>
public double SlipsDepth { get; set; }
public double SectionDepth { get; set; }
}
}

View File

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

View File

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

View File

@ -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<ITrajectoryPlanRepository, TrajectoryPlanRepository>();
services.AddTransient<ITrajectoryFactRepository, TrajectoryFactRepository>();
services.AddTransient<IFaqRepository, FaqRepository>();
services.AddTransient<ISlipsStatRepository, SlipsStatRepository>();
services.AddTransient<ISlipsStatService, SlipsStatService>();
services.AddTransient<IWellContactService, WellContactService>();
services.AddTransient<ICrudRepository<WellSectionTypeDto>, CrudCacheRepositoryBase<WellSectionTypeDto,
WellSectionType>>();

View File

@ -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<IEnumerable<SlipsStatDto>> 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(),
});

View File

@ -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;
}