forked from ddrilling/AsbCloudServer
Унификация дат для DailyReport + всё, что пришлось исправить, чтобы проект собрался
This commit is contained in:
parent
9723ee3b9e
commit
616cb242d6
@ -74,7 +74,7 @@ public class DailyReportDto : IId,
|
||||
/// <summary>
|
||||
/// Дата последнего обновления
|
||||
/// </summary>
|
||||
public DateTime? DateLastUpdate { get; set; }
|
||||
public DateTimeOffset? DateLastUpdate { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Блок фактической траектории
|
||||
|
@ -12,12 +12,12 @@ namespace AsbCloudApp.Data
|
||||
/// Дата начала диапазона
|
||||
/// </summary>
|
||||
[Required]
|
||||
public DateTime From { get; set; }
|
||||
public DateTimeOffset From { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Дата окончания диапазона
|
||||
/// </summary>
|
||||
[Required]
|
||||
public DateTime To { get; set; }
|
||||
public DateTimeOffset To { get; set; }
|
||||
}
|
||||
}
|
||||
|
@ -42,7 +42,7 @@ namespace AsbCloudApp.Data
|
||||
/// дата прихода последней телеметрии
|
||||
/// </summary>
|
||||
[Required]
|
||||
public DateTime LastTelemetryDate { get; set; }
|
||||
public DateTimeOffset LastTelemetryDate { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Статистика по секциям
|
||||
|
@ -72,7 +72,7 @@ namespace AsbCloudApp.Data
|
||||
/// <summary>
|
||||
/// Дата/время кода приходили данные последний раз
|
||||
/// </summary>
|
||||
public DateTime LastTelemetryDate { get; set; }
|
||||
public DateTimeOffset LastTelemetryDate { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// ID телеметрии
|
||||
|
@ -72,7 +72,7 @@ namespace AsbCloudApp.Services
|
||||
/// </summary>
|
||||
/// <param name="idWell"></param>
|
||||
/// <returns></returns>
|
||||
DateTime GetLastTelemetryDate(int idWell);
|
||||
DateTimeOffset GetLastTelemetryDate(int idWell);
|
||||
|
||||
//TODO: выяснить и удалить отсюда
|
||||
/// <summary>
|
||||
|
@ -282,7 +282,7 @@ namespace AsbCloudDb.Migrations
|
||||
.HasColumnName("date")
|
||||
.HasComment("Дата формирования отчёта");
|
||||
|
||||
b.Property<DateTime?>("DateLastUpdate")
|
||||
b.Property<DateTimeOffset?>("DateLastUpdate")
|
||||
.HasColumnType("timestamp with time zone")
|
||||
.HasColumnName("date_last_update")
|
||||
.HasComment("Дата последнего обновления");
|
||||
|
@ -18,7 +18,7 @@ public class DailyReport : IId
|
||||
public int IdWell { get; set; }
|
||||
|
||||
[Column("date_last_update", TypeName = "timestamp with time zone"), Comment("Дата последнего обновления")]
|
||||
public DateTime? DateLastUpdate { get; set; }
|
||||
public DateTimeOffset? DateLastUpdate { get; set; }
|
||||
|
||||
[Column("date", TypeName = "date"), Comment("Дата формирования отчёта")]
|
||||
public DateOnly Date { get; set; }
|
||||
|
@ -1,80 +1,85 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Threading;
|
||||
using System.Threading.Tasks;
|
||||
using AsbCloudApp.Data.DailyReport;
|
||||
using AsbCloudApp.Data.DailyReport.Blocks.Sign;
|
||||
using AsbCloudApp.Data.DailyReport.Blocks.Subsystems;
|
||||
using AsbCloudApp.Data.DailyReport.Blocks.TimeBalance;
|
||||
using AsbCloudApp.Repositories;
|
||||
using AsbCloudApp.Requests;
|
||||
using AsbCloudApp.Services;
|
||||
using AsbCloudDb;
|
||||
using AsbCloudDb.Model;
|
||||
using AsbCloudDb.Model.DailyReports;
|
||||
using Mapster;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Threading;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace AsbCloudInfrastructure.Repository;
|
||||
|
||||
public class DailyReportRepository : CrudRepositoryBase<DailyReportDto, DailyReport>,
|
||||
IDailyReportRepository
|
||||
IDailyReportRepository
|
||||
{
|
||||
public DailyReportRepository(IAsbCloudDbContext dbContext)
|
||||
: base(dbContext)
|
||||
{
|
||||
}
|
||||
private IWellService wellService;
|
||||
|
||||
public async Task<IEnumerable<DailyReportDto>> GetAsync(int idWell, FileReportRequest request, CancellationToken cancellationToken)
|
||||
{
|
||||
var skip = request.Skip ?? 0;
|
||||
var take = request.Take ?? 10;
|
||||
public DailyReportRepository(IAsbCloudDbContext dbContext, IWellService wellService)
|
||||
: base(dbContext)
|
||||
{
|
||||
this.wellService = wellService;
|
||||
}
|
||||
|
||||
var query = GetQuery().Where(d => d.IdWell == idWell);
|
||||
public async Task<IEnumerable<DailyReportDto>> GetAsync(int idWell, FileReportRequest request, CancellationToken cancellationToken)
|
||||
{
|
||||
var skip = request.Skip ?? 0;
|
||||
var take = request.Take ?? 10;
|
||||
|
||||
if (request.GeDate.HasValue)
|
||||
query = query.Where(d => d.Date >= request.GeDate.Value);
|
||||
|
||||
if (request.LeDate.HasValue)
|
||||
query = query.Where(d => d.Date <= request.LeDate.Value);
|
||||
var query = GetQuery().Where(d => d.IdWell == idWell);
|
||||
|
||||
query = request.SortFields?.Any() == true ?
|
||||
query.SortBy(request.SortFields) :
|
||||
query.OrderBy(d => d.Date);
|
||||
if (request.GeDate.HasValue)
|
||||
query = query.Where(d => d.Date >= request.GeDate.Value);
|
||||
|
||||
var entities = await query
|
||||
.Skip(skip)
|
||||
.Take(take)
|
||||
.AsNoTracking()
|
||||
.ToArrayAsync(cancellationToken);
|
||||
if (request.LeDate.HasValue)
|
||||
query = query.Where(d => d.Date <= request.LeDate.Value);
|
||||
|
||||
var dtos = entities.Select(Convert);
|
||||
query = request.SortFields?.Any() == true ?
|
||||
query.SortBy(request.SortFields) :
|
||||
query.OrderBy(d => d.Date);
|
||||
|
||||
return dtos;
|
||||
}
|
||||
var entities = await query
|
||||
.Skip(skip)
|
||||
.Take(take)
|
||||
.AsNoTracking()
|
||||
.ToArrayAsync(cancellationToken);
|
||||
|
||||
public async Task<DailyReportDto?> GetOrDefaultAsync(int idWell, DateOnly date, CancellationToken cancellationToken)
|
||||
{
|
||||
var entity = await GetQuery()
|
||||
.AsNoTracking()
|
||||
.SingleOrDefaultAsync(d => d.IdWell == idWell && d.Date == date, cancellationToken);
|
||||
var timezoneOffset = wellService.GetTimezone(idWell).Offset;
|
||||
var dtos = entities.Select(entity => Convert(entity, timezoneOffset));
|
||||
|
||||
return entity is null ? null : Convert(entity);
|
||||
}
|
||||
return dtos;
|
||||
}
|
||||
|
||||
protected override DailyReportDto Convert(DailyReport src)
|
||||
{
|
||||
var dto = new DailyReportDto
|
||||
{
|
||||
Id = src.Id,
|
||||
IdWell = src.IdWell,
|
||||
DateLastUpdate = src.DateLastUpdate,
|
||||
Date = src.Date,
|
||||
SignBlock = src.SignBlock?.Adapt<SignBlockDto>(),
|
||||
TimeBalanceBlock = src.TimeBalanceBlock?.Adapt<TimeBalanceBlockDto>(),
|
||||
SubsystemBlock = src.SubsystemBlock?.Adapt<SubsystemBlockDto>()
|
||||
};
|
||||
|
||||
return dto;
|
||||
}
|
||||
public async Task<DailyReportDto?> GetOrDefaultAsync(int idWell, DateOnly date, CancellationToken cancellationToken)
|
||||
{
|
||||
var entity = await GetQuery()
|
||||
.AsNoTracking()
|
||||
.SingleOrDefaultAsync(d => d.IdWell == idWell && d.Date == date, cancellationToken);
|
||||
|
||||
return entity is null ? null : Convert(entity);
|
||||
}
|
||||
|
||||
protected DailyReportDto Convert(DailyReport src, TimeSpan timezoneOffset)
|
||||
{
|
||||
var dto = new DailyReportDto
|
||||
{
|
||||
Id = src.Id,
|
||||
IdWell = src.IdWell,
|
||||
DateLastUpdate = src.DateLastUpdate?.ToOffset(timezoneOffset),
|
||||
Date = src.Date,
|
||||
SignBlock = src.SignBlock?.Adapt<SignBlockDto>(),
|
||||
TimeBalanceBlock = src.TimeBalanceBlock?.Adapt<TimeBalanceBlockDto>(),
|
||||
SubsystemBlock = src.SubsystemBlock?.Adapt<SubsystemBlockDto>()
|
||||
};
|
||||
|
||||
return dto;
|
||||
}
|
||||
}
|
@ -4,6 +4,7 @@ using AsbCloudApp.Services;
|
||||
using AsbCloudDb.Model;
|
||||
using Mapster;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Threading;
|
||||
@ -111,7 +112,8 @@ namespace AsbCloudInfrastructure.Repository
|
||||
{
|
||||
var dto = well.Adapt<WellDto>();
|
||||
dto.WellType = well.WellType.Caption;
|
||||
dto.LastTelemetryDate = wellService.GetLastTelemetryDate(well.Id);
|
||||
dto.LastTelemetryDate = wellService.GetLastTelemetryDate(well.Id)
|
||||
.ToOffset(TimeSpan.FromHours(well.Timezone.Hours));
|
||||
dto.Cluster = gCluster.Key.Caption;
|
||||
dto.Deposit = gDeposit.Key.Caption;
|
||||
return dto;
|
||||
|
@ -177,8 +177,8 @@ public class WellOperationRepository : IWellOperationRepository
|
||||
|
||||
return new DatesRangeDto
|
||||
{
|
||||
From = minDate.ToRemoteDateTime(timezone.Hours),
|
||||
To = maxDate.ToRemoteDateTime(timezone.Hours)
|
||||
From = minDate.ToOffset(timezone.Offset),
|
||||
To = maxDate.ToOffset(timezone.Offset)
|
||||
};
|
||||
}
|
||||
|
||||
@ -197,12 +197,12 @@ public class WellOperationRepository : IWellOperationRepository
|
||||
WellOperationRequest request,
|
||||
CancellationToken token)
|
||||
{
|
||||
var query = BuildQuery(request)
|
||||
var query = BuildQuery(request)
|
||||
.AsNoTracking();
|
||||
|
||||
var dtos = await query.ToArrayAsync(token);
|
||||
var dtos = await query.ToArrayAsync(token);
|
||||
|
||||
return dtos.Select(Convert);
|
||||
return dtos.Select(Convert);
|
||||
}
|
||||
|
||||
public async Task<IEnumerable<WellOperationDataDto>> GetAsync(
|
||||
@ -413,14 +413,14 @@ public class WellOperationRepository : IWellOperationRepository
|
||||
|
||||
if (request.GeDate.HasValue)
|
||||
{
|
||||
//var geDateOffset = request.GeDate.Value.ToUtcDateTimeOffset(timeZoneOffset);
|
||||
query = query.Where(e => e.DateStart >= request.GeDate);
|
||||
var geDateOffset = request.GeDate.Value.ToUniversalTime();
|
||||
query = query.Where(e => e.DateStart >= geDateOffset);
|
||||
}
|
||||
|
||||
if (request.LeDate.HasValue)
|
||||
{
|
||||
//var leDateOffset = request.LeDate.Value.ToUtcDateTimeOffset(timeZoneOffset);
|
||||
query = query.Where(e => e.DateStart <= request.LeDate);
|
||||
var leDateOffset = request.LeDate.Value.ToUniversalTime();
|
||||
query = query.Where(e => e.DateStart <= leDateOffset);
|
||||
}
|
||||
|
||||
var currentWellOperations = db.WellOperations
|
||||
|
@ -83,7 +83,7 @@ public class DailyReportService : IDailyReportService
|
||||
editableBlock.IdUser = idUser;
|
||||
editableBlock.LastUpdateDate = DateTime.UtcNow;
|
||||
|
||||
dailyReport.DateLastUpdate = DateTime.UtcNow;
|
||||
dailyReport.DateLastUpdate = DateTimeOffset.UtcNow;
|
||||
|
||||
if (dailyReport.Id == 0)
|
||||
return await dailyReportRepository.InsertAsync(dailyReport, cancellationToken);
|
||||
@ -158,28 +158,27 @@ public class DailyReportService : IDailyReportService
|
||||
return result;
|
||||
|
||||
var dailyReports = new List<DailyReportDto>();
|
||||
|
||||
if (request.GeDate.HasValue)
|
||||
{
|
||||
var startDate = new DateTime(request.GeDate.Value.Year, request.GeDate.Value.Month,
|
||||
request.GeDate.Value.Day);
|
||||
TimeSpan offset = wellService.GetTimezone(idWell).Offset;
|
||||
|
||||
if (startDate.Date >= datesRange.From.Date)
|
||||
if (request.GeDate.HasValue)
|
||||
{
|
||||
var startDate = new DateTimeOffset(request.GeDate.Value, TimeOnly.MinValue, offset);
|
||||
|
||||
if (startDate >= datesRange.From)
|
||||
datesRange.From = startDate;
|
||||
}
|
||||
|
||||
if (request.LeDate.HasValue)
|
||||
{
|
||||
var finishDate = new DateTime(request.LeDate.Value.Year, request.LeDate.Value.Month,
|
||||
request.LeDate.Value.Day);
|
||||
var finishDate = new DateTimeOffset(request.LeDate.Value, TimeOnly.MinValue, offset);
|
||||
|
||||
if (finishDate.Date <= datesRange.To.Date)
|
||||
if (finishDate <= datesRange.To)
|
||||
datesRange.To = finishDate;
|
||||
}
|
||||
|
||||
if (datesRange.From.AddDays(result.Skip) <= datesRange.To)
|
||||
result.Count = (int)(Math.Ceiling((datesRange.To - DateTime.UnixEpoch).TotalDays) -
|
||||
Math.Floor((datesRange.From - DateTime.UnixEpoch).TotalDays)) + 1;
|
||||
result.Count = (int)(Math.Ceiling((datesRange.To - DateTimeOffset.UnixEpoch).TotalDays) -
|
||||
Math.Floor((datesRange.From - DateTimeOffset.UnixEpoch).TotalDays)) + 1;
|
||||
|
||||
var existingDailyReports = await dailyReportRepository.GetAsync(idWell, request, cancellationToken);
|
||||
|
||||
@ -200,16 +199,16 @@ 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);
|
||||
AddDailyReport(dateDailyReport);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
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);
|
||||
}
|
||||
@ -243,7 +242,7 @@ public class DailyReportService : IDailyReportService
|
||||
public async Task<DatesRangeDto?> GetDatesRangeAsync(int idWell, CancellationToken cancellationToken)
|
||||
{
|
||||
var timezone = wellService.GetTimezone(idWell);
|
||||
var currentDate = DateTimeOffset.UtcNow.ToRemoteDateTime(timezone.Hours);
|
||||
var currentDate = DateTimeOffset.UtcNow.ToOffset(TimeSpan.FromHours(timezone.Hours));
|
||||
|
||||
var factOperationDatesRange = await wellOperationRepository.GetDatesRangeAsync(idWell, WellOperation.IdOperationTypeFact,
|
||||
cancellationToken);
|
||||
@ -251,15 +250,13 @@ public class DailyReportService : IDailyReportService
|
||||
if (factOperationDatesRange is null)
|
||||
return null;
|
||||
|
||||
var from = (factOperationDatesRange.From.AddDays(1) <= DateTime.UtcNow ?
|
||||
var from = (factOperationDatesRange.From.AddDays(1) <= DateTimeOffset.UtcNow.ToOffset(TimeSpan.FromHours(timezone.Hours)) ?
|
||||
factOperationDatesRange.From :
|
||||
currentDate.AddDays(-1))
|
||||
.Date;
|
||||
currentDate.AddDays(-1));
|
||||
|
||||
var to = (factOperationDatesRange.To.AddDays(1) <= DateTime.UtcNow ?
|
||||
var to = (factOperationDatesRange.To.AddDays(1) <= DateTimeOffset.UtcNow.ToOffset(TimeSpan.FromHours(timezone.Hours)) ?
|
||||
factOperationDatesRange.To :
|
||||
currentDate.AddDays(-1))
|
||||
.Date;
|
||||
currentDate.AddDays(-1));
|
||||
|
||||
return new DatesRangeDto
|
||||
{
|
||||
@ -417,9 +414,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.ToUniversalTime().DateTime);
|
||||
var to = DateOnly.FromDateTime(datesRange.To.ToUniversalTime().DateTime);
|
||||
|
||||
return dateDailyReport >= from && dateDailyReport <= to;
|
||||
}
|
||||
|
@ -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.ToOffset(timezone.Offset) ?? DateTimeOffset.UtcNow)
|
||||
.AddSeconds(-intervalSec);
|
||||
}
|
||||
else
|
||||
|
@ -145,6 +145,8 @@ public class OperationsStatService : IOperationsStatService
|
||||
|
||||
private async Task<StatWellDto> CalcWellStatAsync(Well well, CancellationToken token)
|
||||
{
|
||||
var timezone = wellService.GetTimezone(well.Id);
|
||||
|
||||
var wellType = (await memoryCache
|
||||
.GetOrCreateBasicAsync(db.Set<WellType>(), token))
|
||||
.FirstOrDefault(t => t.Id == well.IdWellType);
|
||||
@ -155,7 +157,7 @@ public class OperationsStatService : IOperationsStatService
|
||||
WellType = wellType?.Caption ?? "",
|
||||
IdState = well.IdState,
|
||||
State = wellService.GetStateText(well.IdState),
|
||||
LastTelemetryDate = wellService.GetLastTelemetryDate(well.Id),
|
||||
LastTelemetryDate = wellService.GetLastTelemetryDate(well.Id).ToOffset(timezone.Offset),
|
||||
Companies = await wellService.GetCompaniesAsync(well.Id, token)
|
||||
};
|
||||
|
||||
@ -169,9 +171,8 @@ public class OperationsStatService : IOperationsStatService
|
||||
if (!wellOperations.Any())
|
||||
return statWellDto;
|
||||
|
||||
var timezoneOffsetH = wellService.GetTimezone(well.Id).Hours;
|
||||
statWellDto.Sections = CalcSectionsStats(wellOperations, timezoneOffsetH);
|
||||
statWellDto.Total = GetStatTotal(wellOperations, well.IdState, timezoneOffsetH);
|
||||
statWellDto.Sections = CalcSectionsStats(wellOperations, timezone.Hours);
|
||||
statWellDto.Total = GetStatTotal(wellOperations, well.IdState, timezone.Hours);
|
||||
statWellDto.TvdLagDays = CalcTvdLagDays(wellOperations);
|
||||
statWellDto.TvdDrillingDays = CalcDrillingDays(wellOperations);
|
||||
|
||||
|
@ -63,12 +63,12 @@ namespace AsbCloudInfrastructure.Services
|
||||
private void DropCacheRelationCompanyWell()
|
||||
=> memoryCache.DropBasic<RelationCompanyWell>();
|
||||
|
||||
public DateTime GetLastTelemetryDate(int idWell)
|
||||
public DateTimeOffset GetLastTelemetryDate(int idWell)
|
||||
{
|
||||
var well = GetOrDefault(idWell);
|
||||
|
||||
if (well?.IdTelemetry is null)
|
||||
return DateTime.MinValue;
|
||||
return DateTimeOffset.MinValue;
|
||||
|
||||
var datesRange = telemetryService.GetDatesRange(well.IdTelemetry.Value);
|
||||
return datesRange.To;
|
||||
@ -278,7 +278,7 @@ namespace AsbCloudInfrastructure.Services
|
||||
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.ToOffset(dto.Timezone.Offset);
|
||||
dto.Companies = entity.RelationCompaniesWells
|
||||
.Select(r => Convert(r.Company))
|
||||
.ToList();
|
||||
|
@ -21,7 +21,7 @@ public class WellboreServiceTest
|
||||
Id = 1,
|
||||
IdState = 1,
|
||||
IdTelemetry = 1,
|
||||
LastTelemetryDate = DateTime.Now,
|
||||
LastTelemetryDate = DateTimeOffset.Now,
|
||||
Caption = "well 1"
|
||||
};
|
||||
|
||||
@ -30,7 +30,7 @@ public class WellboreServiceTest
|
||||
Id = 2,
|
||||
IdState = 1,
|
||||
IdTelemetry = 100,
|
||||
LastTelemetryDate = DateTime.Now,
|
||||
LastTelemetryDate = DateTimeOffset.Now,
|
||||
Caption = "well 2"
|
||||
};
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user