add TimeBalanceDto in MakeDefaultDailyReportAsync

This commit is contained in:
a.chernyshev 2022-08-10 12:01:29 +05:00
parent d2b98d3a77
commit 1f9406c70d
4 changed files with 70 additions and 3 deletions

View File

@ -94,6 +94,26 @@
/// НПВ
/// </summary>
public string Npv { get; set; }
/// <summary>
/// Проработка перед наращиванием
/// </summary>
public string ElaborationBeforeBuilding { get; set; }
/// <summary>
/// Шаблонировка перед наращиванием
/// </summary>
public string TemplatingBeforeBuilding { get; set; }
/// <summary>
/// Промывка перед наращиванием
/// </summary>
public string FlushingBeforeBuilding { get; set; }
/// <summary>
/// Статический замер телесистемы
/// </summary>
public string StaticSurveying { get; set; }
}
}

View File

@ -16,6 +16,7 @@ namespace AsbCloudApp.Services
Task<int> DeleteAsync(DetectedOperationRequest request, CancellationToken token);
Task<IEnumerable<DetectedOperationStatDto>?> GetOperationsStatAsync(DetectedOperationRequest request, CancellationToken token);
Task<Stream> ExportAsync(IEnumerable<int> idsWells, CancellationToken token);
double GetSumValues(IEnumerable<DetectedOperationStatDto> detectedOperations, int idOperation);
}
#nullable disable
}

View File

@ -9,6 +9,8 @@ using AsbCloudApp.Services;
using AsbCloudDb.Model;
using System.Collections.Generic;
using AsbCloudApp.Data.DailyReport;
using AsbCloudApp.Requests;
using AsbCloudInfrastructure.Services.DetectOperations;
namespace AsbCloudInfrastructure.Services.DailyReport
{
@ -17,12 +19,14 @@ namespace AsbCloudInfrastructure.Services.DailyReport
{
private readonly IAsbCloudDbContext db;
private readonly IWellService wellService;
private readonly IDetectedOperationService detectedOperationService;
private readonly DailyReportMakerExcel dailyReportMaker = new DailyReportMakerExcel();
public DailyReportService(IAsbCloudDbContext db, IWellService wellService)
public DailyReportService(IAsbCloudDbContext db, IWellService wellService, IDetectedOperationService detectedOperationService)
{
this.db = db;
this.wellService = wellService;
this.detectedOperationService = detectedOperationService;
}
public async Task<IEnumerable<DailyReportDto>> GetListAsync(int idWell, DateTime? begin, DateTime? end, CancellationToken token)
@ -109,16 +113,36 @@ namespace AsbCloudInfrastructure.Services.DailyReport
private async Task<DailyReportDto> MakeDefaultDailyReportAsync(int idWell, DateTime date, CancellationToken token)
{
var well = await wellService.GetOrDefaultAsync(idWell, token);
var detectedOperations = await detectedOperationService.GetOperationsStatAsync(new DetectedOperationRequest
{
IdWell = idWell,
GtDate = date.Date,
LtDate = date.Date.AddDays(1)
}, token);
var dto = new DailyReportDto()
{
Head = new HeadDto()
{
ReportDate = date.Date,
WellName = well?.Caption ?? "",
ClusterName = well?.Cluster ?? ""
ClusterName = well?.Cluster ?? "",
},
TimeBalance = detectedOperations is null ? new TimeBalanceDto() { } : new TimeBalanceDto()
{
Drilling = $"{detectedOperationService.GetSumValues(detectedOperations, DetectedOperationService.IdOperationRotor) + detectedOperationService.GetSumValues(detectedOperations, DetectedOperationService.IdOperationSlide)}",
Flushing = detectedOperationService.GetSumValues(detectedOperations, DetectedOperationService.idOperationFlushing).ToString(),
Building = detectedOperationService.GetSumValues(detectedOperations, DetectedOperationService.IdOperationSlipsTime).ToString(),
Elaboration = detectedOperationService.GetSumValues(detectedOperations, DetectedOperationService.idOperationElaboration).ToString(),
ElaborationBeforeBuilding = detectedOperationService.GetSumValues(detectedOperations, DetectedOperationService.idOperationElaborationBeforeBuilding).ToString(),
TemplatingBeforeBuilding = detectedOperationService.GetSumValues(detectedOperations, DetectedOperationService.idOperationTemplatingBeforeBuilding).ToString(),
FlushingBeforeBuilding = detectedOperationService.GetSumValues(detectedOperations, DetectedOperationService.idOperationFlushingBeforeBuilding).ToString(),
StaticSurveying = detectedOperationService.GetSumValues(detectedOperations, DetectedOperationService.idOperationStaticSurveying).ToString(),
Gis = detectedOperationService.GetSumValues(detectedOperations, DetectedOperationService.idOperationGis).ToString(),
Ozc = detectedOperationService.GetSumValues(detectedOperations, DetectedOperationService.idOperationOzc).ToString(),
Cementing = detectedOperationService.GetSumValues(detectedOperations, DetectedOperationService.idOperationCementing).ToString(),
Npv = detectedOperationService.GetSumValues(detectedOperations, DetectedOperationService.idOperationNpv).ToString(),
}
};
return dto;
}

View File

@ -21,6 +21,19 @@ namespace AsbCloudInfrastructure.Services.DetectOperations
public const int IdOperationRotor = 1;
public const int IdOperationSlide = 3;
public const int IdOperationSlipsTime = 14;
public const int idOperationFlushing = 22;
public const int idOperationElaboration = 1022;
public const int idOperationRepair = 1031;
public const int idOperationGis = 1001;
public const int idOperationOzc = 1008;
public const int idOperationCementing = 1040;
public const int idOperationNpv = 1043;
public const int idOperationElaborationBeforeBuilding = 18;
public const int idOperationTemplatingBeforeBuilding = 19;
public const int idOperationFlushingBeforeBuilding = 20;
public const int idOperationStaticSurveying = 21;
private readonly IAsbCloudDbContext db;
private readonly IWellService wellService;
@ -283,6 +296,15 @@ namespace AsbCloudInfrastructure.Services.DetectOperations
return result;
}
public double GetSumValues(IEnumerable<DetectedOperationStatDto> detectedOperations, int idOperation)
{
var result = detectedOperations
.Where(o => o.IdCategory == idOperation)
.Select(o => o.MinutesTotal)
.Sum() / 60;
return Math.Round(result, 2);
}
public Task<Stream> ExportAsync(IEnumerable<int> idsWells, CancellationToken token)
{
var exportService = new DetectedOperationExportService(db, wellService);