forked from ddrilling/AsbCloudServer
refactor DailyReportService.MakeTimeBalanceAsync(..);
fix naming;
This commit is contained in:
parent
12e70cb7c0
commit
25f5700814
@ -114,12 +114,7 @@ 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()
|
||||
@ -128,34 +123,46 @@ namespace AsbCloudInfrastructure.Services.DailyReport
|
||||
WellName = well?.Caption ?? "",
|
||||
ClusterName = well?.Cluster ?? "",
|
||||
},
|
||||
TimeBalance = detectedOperations is null ? new TimeBalanceDto() { } : GetTimeBalanceDto(detectedOperations),
|
||||
TimeBalance = await MakeTimeBalanceAsync(idWell, date, token),
|
||||
};
|
||||
return dto;
|
||||
}
|
||||
|
||||
private TimeBalanceDto GetTimeBalanceDto(IEnumerable<DetectedOperationStatDto> stat)
|
||||
private async Task<TimeBalanceDto> MakeTimeBalanceAsync(int idWell, DateTime date, CancellationToken token)
|
||||
{
|
||||
var dto = stat is null ? new TimeBalanceDto() { } : new TimeBalanceDto()
|
||||
var stat = await detectedOperationService.GetOperationsStatAsync(new DetectedOperationRequest
|
||||
{
|
||||
Drilling = $"{FormatOperationValue(stat.FirstOrDefault(x => x.IdCategory == DetectedOperationService.IdOperationRotor)) + FormatOperationValue(stat.FirstOrDefault(x => x.IdCategory == DetectedOperationService.IdOperationSlide))}",
|
||||
Flushing = FormatOperationValue(stat.FirstOrDefault(x => x.IdCategory == DetectedOperationService.idOperationFlushing)).ToString(),
|
||||
Building = FormatOperationValue(stat.FirstOrDefault(x => x.IdCategory == DetectedOperationService.IdOperationSlipsTime)).ToString(),
|
||||
Elaboration = FormatOperationValue(stat.FirstOrDefault(x => x.IdCategory == DetectedOperationService.idOperationElaboration)).ToString(),
|
||||
ElaborationBeforeBuilding = FormatOperationValue(stat.FirstOrDefault(x => x.IdCategory == DetectedOperationService.idOperationElaborationBeforeBuilding)).ToString(),
|
||||
TemplatingBeforeBuilding = FormatOperationValue(stat.FirstOrDefault(x => x.IdCategory == DetectedOperationService.idOperationTemplatingBeforeBuilding)).ToString(),
|
||||
FlushingBeforeBuilding = FormatOperationValue(stat.FirstOrDefault(x => x.IdCategory == DetectedOperationService.idOperationFlushingBeforeBuilding)).ToString(),
|
||||
StaticSurveying = FormatOperationValue(stat.FirstOrDefault(x => x.IdCategory == DetectedOperationService.idOperationStaticSurveying)).ToString(),
|
||||
Gis = FormatOperationValue(stat.FirstOrDefault(x => x.IdCategory == DetectedOperationService.idOperationGis)).ToString(),
|
||||
Ozc = FormatOperationValue(stat.FirstOrDefault(x => x.IdCategory == DetectedOperationService.idOperationOzc)).ToString(),
|
||||
Cementing = FormatOperationValue(stat.FirstOrDefault(x => x.IdCategory == DetectedOperationService.idOperationCementing)).ToString(),
|
||||
Npv = FormatOperationValue(stat.FirstOrDefault(x => x.IdCategory == DetectedOperationService.idOperationNpv)).ToString(),
|
||||
IdWell = idWell,
|
||||
GtDate = date.Date,
|
||||
LtDate = date.Date.AddDays(1)
|
||||
}, token);
|
||||
|
||||
if (stat is null)
|
||||
return new TimeBalanceDto();
|
||||
|
||||
var dto = new TimeBalanceDto()
|
||||
{
|
||||
Drilling = $"{GetHoursFromStat(stat, DetectedOperationService.IdOperationRotor, DetectedOperationService.IdOperationSlide):#0.00}",
|
||||
Flushing = $"{GetHoursFromStat(stat, DetectedOperationService.idOperationFlushing):#0.00}",
|
||||
Building = $"{GetHoursFromStat(stat, DetectedOperationService.IdOperationSlipsTime):#0.00}",
|
||||
Elaboration = $"{GetHoursFromStat(stat, DetectedOperationService.IdOperationElaboration):#0.00}",
|
||||
ElaborationBeforeBuilding = $"{GetHoursFromStat(stat, DetectedOperationService.IdOperationElaborationBeforeBuilding):#0.00}",
|
||||
TemplatingBeforeBuilding = $"{GetHoursFromStat(stat, DetectedOperationService.IdOperationTemplatingBeforeBuilding):#0.00}",
|
||||
FlushingBeforeBuilding = $"{GetHoursFromStat(stat, DetectedOperationService.IdOperationFlushingBeforeBuilding):#0.00}",
|
||||
StaticSurveying = $"{GetHoursFromStat(stat, DetectedOperationService.IdOperationStaticSurveying):#0.00}",
|
||||
Gis = $"{GetHoursFromStat(stat, DetectedOperationService.IdOperationGis):#0.00}",
|
||||
Ozc = $"{GetHoursFromStat(stat, DetectedOperationService.IdOperationOzc):#0.00}",
|
||||
Cementing = $"{GetHoursFromStat(stat, DetectedOperationService.IdOperationCementing):#0.00}",
|
||||
Npv = $"{GetHoursFromStat(stat, DetectedOperationService.IdOperationNpv):#0.00}",
|
||||
};
|
||||
return dto;
|
||||
}
|
||||
|
||||
private double FormatOperationValue(DetectedOperationStatDto? operationStat)
|
||||
private static double GetHoursFromStat(IEnumerable<DetectedOperationStatDto> stat, params int[] idCategories)
|
||||
{
|
||||
return operationStat is not null ? Math.Round(operationStat.MinutesTotal / 60, 2) : 0;
|
||||
var valueMinutes = stat.Where(o => idCategories.Contains(o.IdCategory))
|
||||
.Sum(o => o.MinutesTotal);
|
||||
return valueMinutes / 60d;
|
||||
}
|
||||
|
||||
private static DailyReportDto Convert(AsbCloudDb.Model.DailyReport.DailyReport entity)
|
||||
|
@ -22,18 +22,18 @@ namespace AsbCloudInfrastructure.Services.DetectOperations
|
||||
public const int IdOperationSlide = 3;
|
||||
public const int IdOperationSlipsTime = 14;
|
||||
public const int idOperationFlushing = 22;
|
||||
public const int idOperationElaboration = 1022;
|
||||
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 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;
|
||||
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;
|
||||
|
Loading…
Reference in New Issue
Block a user