forked from ddrilling/AsbCloudServer
Fix ScheduleReportService correct deltaDepth
This commit is contained in:
parent
3f2a7406d2
commit
b12c3efffc
@ -16,7 +16,7 @@ namespace AsbCloudInfrastructure.Services.WellOperationService
|
|||||||
private readonly IWellService wellService;
|
private readonly IWellService wellService;
|
||||||
const string sheetNameSchedule = "Сетевой график";
|
const string sheetNameSchedule = "Сетевой график";
|
||||||
const string sheetNameTvd = "ГГД";
|
const string sheetNameTvd = "ГГД";
|
||||||
const int maxChartsToWrap = 89;
|
const int maxChartsToWrap = 88;
|
||||||
|
|
||||||
public ScheduleReportService(IOperationsStatService operationsStatService, IWellService wellService)
|
public ScheduleReportService(IOperationsStatService operationsStatService, IWellService wellService)
|
||||||
{
|
{
|
||||||
@ -43,7 +43,7 @@ namespace AsbCloudInfrastructure.Services.WellOperationService
|
|||||||
return memoryStream;
|
return memoryStream;
|
||||||
}
|
}
|
||||||
|
|
||||||
private void FillScheduleSheetToWorkbook(XLWorkbook workbook, IEnumerable<PlanFactPredictBase<WellOperationDto>> tvd, WellDto well)
|
private static void FillScheduleSheetToWorkbook(XLWorkbook workbook, IEnumerable<PlanFactPredictBase<WellOperationDto>> tvd, WellDto well)
|
||||||
{
|
{
|
||||||
var sheet = workbook.Worksheets.FirstOrDefault(ws => ws.Name == sheetNameSchedule);
|
var sheet = workbook.Worksheets.FirstOrDefault(ws => ws.Name == sheetNameSchedule);
|
||||||
if (sheet is null)
|
if (sheet is null)
|
||||||
@ -54,25 +54,36 @@ namespace AsbCloudInfrastructure.Services.WellOperationService
|
|||||||
|
|
||||||
const int columnRowNumber = 2;
|
const int columnRowNumber = 2;
|
||||||
const int columnCaption = 3;
|
const int columnCaption = 3;
|
||||||
const int columnWellDepthPlan = 4;
|
const int columnWellDepthStartPlan = 4;
|
||||||
const int columnWellDepthFact = 5;
|
const int columnWellDepthStartFact = 5;
|
||||||
const int columnWellDepthPredict = 6;
|
const int columnWellDepthStartPredict = 6;
|
||||||
const int columnDeltaWellDepthPerDay = 7;
|
const int columnWellDepthEndPlan = 7;
|
||||||
const int columnDurationPlan = 8;
|
const int columnWellDepthEndFact = 8;
|
||||||
const int columnDurationFact = 9;
|
const int columnWellDepthEndPredict = 9;
|
||||||
const int columnDurationPredict = 10;
|
const int columnDeltaWellDepthPerDay = 10;
|
||||||
const int columnDateEndPlan = 11;
|
const int columnDurationPlan = 11;
|
||||||
const int columnDateEndFact = 12;
|
const int columnDurationFact = 12;
|
||||||
const int columnDateEndPredict = 13;
|
const int columnDurationPredict = 13;
|
||||||
const int columnGuilty = 14;
|
const int columnDateStartPlan = 14;
|
||||||
const int columnNpt = 15;
|
const int columnDateStartFact = 15;
|
||||||
|
const int columnDateStartPredict = 16;
|
||||||
|
const int columnDateEndPlan = 17;
|
||||||
|
const int columnDateEndFact = 18;
|
||||||
|
const int columnDateEndPredict = 19;
|
||||||
|
const int columnGuilty = 20;
|
||||||
|
const int columnNpt = 21;
|
||||||
|
|
||||||
var subTitle = $"на строительство скважины №{well.Caption}, куст: {well.Cluster}, м/р: {well.Deposit}";
|
var subTitle = $"на строительство скважины №{well.Caption}, куст: {well.Cluster}, м/р: {well.Deposit}";
|
||||||
sheet.Row(rowTitle).Cell(3).Value = subTitle;
|
sheet.Row(rowTitle).Cell(3).Value = subTitle;
|
||||||
|
|
||||||
var tvdList = tvd.ToList();
|
var tvdList = tvd.ToList();
|
||||||
double dayStartDepth = 0d;
|
var facts = tvd
|
||||||
double dayNum = 0;
|
.Where(t=>t.Fact is not null)
|
||||||
|
.Select(t=>t.Fact)
|
||||||
|
.ToList();
|
||||||
|
|
||||||
|
DateTime lastFactDate = default;
|
||||||
|
var lastFactI = 0;
|
||||||
|
|
||||||
int i = 0;
|
int i = 0;
|
||||||
for (; i < tvdList.Count; i++)
|
for (; i < tvdList.Count; i++)
|
||||||
@ -86,33 +97,46 @@ namespace AsbCloudInfrastructure.Services.WellOperationService
|
|||||||
|
|
||||||
SetCell(row, columnRowNumber, $"{1 + i}");
|
SetCell(row, columnRowNumber, $"{1 + i}");
|
||||||
SetCell(row, columnCaption, $"{operation.CategoryName} {operation.CategoryInfo}".Trim());
|
SetCell(row, columnCaption, $"{operation.CategoryName} {operation.CategoryInfo}".Trim());
|
||||||
SetCell(row, columnWellDepthPlan, tvdItem.Plan?.DepthEnd);
|
|
||||||
SetCell(row, columnWellDepthFact, tvdItem.Fact?.DepthEnd);
|
SetCell(row, columnWellDepthStartPlan, tvdItem.Plan?.DepthStart);
|
||||||
SetCell(row, columnWellDepthPredict, tvdItem.Predict?.DepthEnd);
|
SetCell(row, columnWellDepthStartFact, tvdItem.Fact?.DepthStart);
|
||||||
|
SetCell(row, columnWellDepthStartPredict, tvdItem.Predict?.DepthStart);
|
||||||
|
|
||||||
|
SetCell(row, columnWellDepthEndPlan, tvdItem.Plan?.DepthEnd);
|
||||||
|
SetCell(row, columnWellDepthEndFact, tvdItem.Fact?.DepthEnd);
|
||||||
|
SetCell(row, columnWellDepthEndPredict, tvdItem.Predict?.DepthEnd);
|
||||||
|
|
||||||
SetCell(row, columnDeltaWellDepthPerDay, null);
|
SetCell(row, columnDeltaWellDepthPerDay, null);
|
||||||
if (tvdItem.Fact is not null)
|
if (tvdItem.Fact is not null)
|
||||||
{
|
{
|
||||||
if (dayStartDepth == 0d)
|
var fact = tvdItem.Fact;
|
||||||
{
|
if (lastFactDate == default)
|
||||||
dayStartDepth = tvdItem.Fact.DepthStart;
|
lastFactDate = fact.DateStart;
|
||||||
dayNum = tvdItem.Fact.DateStart.DayOfYear;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (i > 0 && tvdItem.Fact.DateStart.DayOfYear > dayNum)
|
if (i > 0 && fact.DateStart.DayOfYear != lastFactDate.DayOfYear)
|
||||||
{
|
{
|
||||||
double? delta = tvdItem.Fact.DepthStart - dayStartDepth;
|
var daylyOperations = facts
|
||||||
delta = delta > 0 ? delta : null;
|
.Where(t => t.DateStart >= lastFactDate && t.DateStart < fact.DateStart);
|
||||||
SetCell(sheet.Row(0 + i + headerRowsCount), columnDeltaWellDepthPerDay, delta);
|
if (daylyOperations.Any())
|
||||||
dayStartDepth = tvdItem.Fact.DepthStart;
|
{
|
||||||
dayNum = tvdItem.Fact.DateStart.DayOfYear;
|
var depthDayStart = daylyOperations.Min(o => o.DepthStart);
|
||||||
|
var depthDayEnd = daylyOperations.Max(o => o.DepthEnd);
|
||||||
|
var delta = depthDayEnd - depthDayStart;
|
||||||
|
SetCell(sheet.Row(1 + lastFactI + headerRowsCount), columnDeltaWellDepthPerDay, delta);
|
||||||
|
lastFactDate = fact.DateStart;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
lastFactI = i;
|
||||||
}
|
}
|
||||||
|
|
||||||
SetCell(row, columnDurationPlan, tvdItem.Plan?.DurationHours);
|
SetCell(row, columnDurationPlan, tvdItem.Plan?.DurationHours);
|
||||||
SetCell(row, columnDurationFact, tvdItem.Fact?.DurationHours);
|
SetCell(row, columnDurationFact, tvdItem.Fact?.DurationHours);
|
||||||
SetCell(row, columnDurationPredict, tvdItem.Predict?.DurationHours);
|
SetCell(row, columnDurationPredict, tvdItem.Predict?.DurationHours);
|
||||||
|
|
||||||
|
SetCell(row, columnDateStartPlan, tvdItem.Plan?.DateStart);
|
||||||
|
SetCell(row, columnDateStartFact, tvdItem.Fact?.DateStart);
|
||||||
|
SetCell(row, columnDateStartPredict, tvdItem.Predict?.DateStart);
|
||||||
|
|
||||||
SetCell(row, columnDateEndPlan, tvdItem.Plan?.DateStart.AddHours(tvdItem.Plan?.DurationHours ?? 0));
|
SetCell(row, columnDateEndPlan, tvdItem.Plan?.DateStart.AddHours(tvdItem.Plan?.DurationHours ?? 0));
|
||||||
SetCell(row, columnDateEndFact, tvdItem.Fact?.DateStart.AddHours(tvdItem.Fact?.DurationHours ?? 0));
|
SetCell(row, columnDateEndFact, tvdItem.Fact?.DateStart.AddHours(tvdItem.Fact?.DurationHours ?? 0));
|
||||||
SetCell(row, columnDateEndPredict, tvdItem.Predict?.DateStart.AddHours(tvdItem.Predict?.DurationHours ?? 0));
|
SetCell(row, columnDateEndPredict, tvdItem.Predict?.DateStart.AddHours(tvdItem.Predict?.DurationHours ?? 0));
|
||||||
@ -171,7 +195,7 @@ namespace AsbCloudInfrastructure.Services.WellOperationService
|
|||||||
SetBorder(rowSummary2.Cells(true).Style);
|
SetBorder(rowSummary2.Cells(true).Style);
|
||||||
}
|
}
|
||||||
|
|
||||||
private void FillTvdSheetToWorkbook(XLWorkbook workbook, IEnumerable<PlanFactPredictBase<WellOperationDto>> tvd, WellDto well)
|
private static void FillTvdSheetToWorkbook(XLWorkbook workbook, IEnumerable<PlanFactPredictBase<WellOperationDto>> tvd, WellDto well)
|
||||||
{
|
{
|
||||||
var sheet = workbook.Worksheets.FirstOrDefault(ws => ws.Name == sheetNameTvd);
|
var sheet = workbook.Worksheets.FirstOrDefault(ws => ws.Name == sheetNameTvd);
|
||||||
if (sheet is null)
|
if (sheet is null)
|
||||||
@ -206,7 +230,7 @@ namespace AsbCloudInfrastructure.Services.WellOperationService
|
|||||||
var factLast = Fact.LastOrDefault();
|
var factLast = Fact.LastOrDefault();
|
||||||
var predictLast = Predict.LastOrDefault();
|
var predictLast = Predict.LastOrDefault();
|
||||||
|
|
||||||
DateTime GetEndDate(WellOperationDto operation)
|
static DateTime GetEndDate(WellOperationDto operation)
|
||||||
=> operation is not null
|
=> operation is not null
|
||||||
? operation.DateStart.AddHours(operation.DurationHours)
|
? operation.DateStart.AddHours(operation.DurationHours)
|
||||||
: default;
|
: default;
|
||||||
@ -232,7 +256,7 @@ namespace AsbCloudInfrastructure.Services.WellOperationService
|
|||||||
SetCell(sheet.Row(rowTopStatTitle + 1), colTopStatvalue - 1, "+")
|
SetCell(sheet.Row(rowTopStatTitle + 1), colTopStatvalue - 1, "+")
|
||||||
.Style.Font.SetFontColor(XLColor.Green);
|
.Style.Font.SetFontColor(XLColor.Green);
|
||||||
else
|
else
|
||||||
SetCell(sheet.Row(rowTopStatTitle + 1), colTopStatvalue - 1, "-")
|
SetCell(sheet.Row(rowTopStatTitle + 1), colTopStatvalue - 1, "—")
|
||||||
.Style.Font.SetFontColor(XLColor.Red);
|
.Style.Font.SetFontColor(XLColor.Red);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -287,7 +311,7 @@ namespace AsbCloudInfrastructure.Services.WellOperationService
|
|||||||
if (value is string valueString && valueString.Length > maxChartsToWrap)
|
if (value is string valueString && valueString.Length > maxChartsToWrap)
|
||||||
{
|
{
|
||||||
var baseHeight = row.Height;
|
var baseHeight = row.Height;
|
||||||
row.Height = Math.Ceiling(0.85d * valueString.Length / maxChartsToWrap) * baseHeight;
|
row.Height = 0.82d * baseHeight * Math.Ceiling(1d + valueString.Length / maxChartsToWrap);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (value is DateTime)
|
if (value is DateTime)
|
||||||
|
Binary file not shown.
@ -46,7 +46,7 @@ namespace AsbCloudWebApi.Tests.ServicesTests
|
|||||||
new User { Id = 3005, IdCompany = 3003, Login = "wrong 2", Email = "aa@aa.aa", IdState = 2 },
|
new User { Id = 3005, IdCompany = 3003, Login = "wrong 2", Email = "aa@aa.aa", IdState = 2 },
|
||||||
};
|
};
|
||||||
|
|
||||||
private static readonly FileInfo file1001 = new FileInfo
|
private static readonly FileInfo file1001 = new ()
|
||||||
{
|
{
|
||||||
Id = 3001,
|
Id = 3001,
|
||||||
IdWell = idWell,
|
IdWell = idWell,
|
||||||
@ -58,7 +58,7 @@ namespace AsbCloudWebApi.Tests.ServicesTests
|
|||||||
UploadDate = System.DateTimeOffset.UtcNow,
|
UploadDate = System.DateTimeOffset.UtcNow,
|
||||||
};
|
};
|
||||||
|
|
||||||
private static readonly FileInfo file1002 = new FileInfo
|
private static readonly FileInfo file1002 = new ()
|
||||||
{
|
{
|
||||||
Id = 3002,
|
Id = 3002,
|
||||||
IdWell = idWell,
|
IdWell = idWell,
|
||||||
|
@ -67,7 +67,7 @@ namespace ConsoleApp1
|
|||||||
var wellService = new WellService(db, cacheDb, telemetryService, timeZoneService);
|
var wellService = new WellService(db, cacheDb, telemetryService, timeZoneService);
|
||||||
var operationService = new OperationsStatService(db, cacheDb, wellService);
|
var operationService = new OperationsStatService(db, cacheDb, wellService);
|
||||||
var scheduleReportService = new ScheduleReportService(operationService, wellService);
|
var scheduleReportService = new ScheduleReportService(operationService, wellService);
|
||||||
var stream = scheduleReportService.MakeReportAsync(4).Result;
|
var stream = scheduleReportService.MakeReportAsync(44).Result;
|
||||||
var outStream = System.IO.File.OpenWrite(@"c:\temp\1.xlsx");
|
var outStream = System.IO.File.OpenWrite(@"c:\temp\1.xlsx");
|
||||||
stream.CopyTo(outStream);
|
stream.CopyTo(outStream);
|
||||||
outStream.Flush();
|
outStream.Flush();
|
||||||
|
Loading…
Reference in New Issue
Block a user