Сортировка операций в сетевойм графике

This commit is contained in:
Olga Nemt 2023-06-07 12:45:44 +05:00
parent 828e38a70e
commit 4bc299dd77
2 changed files with 7 additions and 126 deletions

View File

@ -24,13 +24,6 @@ namespace AsbCloudInfrastructure.Services.WellOperationService
const string sheetNameTvd = "ГГД";
const int maxChartsToWrap = 88;
private enum sheduleMode
{
plan,
fact,
predict
};
public ScheduleReportService(IOperationsStatService operationsStatService, IWellService wellService)
{
this.operationsStatService = operationsStatService;
@ -66,50 +59,39 @@ namespace AsbCloudInfrastructure.Services.WellOperationService
.Select(t => t.Plan!)
.OrderBy(t => t.DateStart)
.ToList();
FillCurrentScheduleSheetToWorkbook(workbook, plans, well, sheduleMode.plan);
FillCurrentScheduleSheetToWorkbook(workbook, plans, sheetNameSchedulePlan);
var facts = tvd
.Where(t => t.Fact is not null)
.Select(t => t.Fact!)
.OrderBy(t => t.DateStart)
.ToList();
FillCurrentScheduleSheetToWorkbook(workbook, facts, well, sheduleMode.fact);
FillCurrentScheduleSheetToWorkbook(workbook, facts, sheetNameScheduleFact);
var predictions = tvd
.Where(t => t.Predict is not null)
.Select(t => t.Predict!)
.OrderBy(t => t.DateStart)
.ToList();
FillCurrentScheduleSheetToWorkbook(workbook, predictions, well, sheduleMode.predict);
FillCurrentScheduleSheetToWorkbook(workbook, predictions, sheetNameSchedulePrediction);
}
private static void FillCurrentScheduleSheetToWorkbook(XLWorkbook workbook, List<WellOperationDto> tvdList, WellDto well, sheduleMode mode)
private static void FillCurrentScheduleSheetToWorkbook(XLWorkbook workbook, List<WellOperationDto> tvdList, string sheetName)
{
var sheetName = GetSheetName(mode);
var sheet = workbook.Worksheets.FirstOrDefault(ws => ws.Name == sheetName);
if (sheet is null)
return;
const int headerRowsCount = 6;
const int rowTitle = 3;
const int columnRowNumber = 2;
const int columnCaption = 3;
const int columnWellDepthStart = 4;
const int columnWellDepthEnd = 5;
const int columnDeltaWellDepthPerDay = 6;
const int columnDuration = 7;
const int columnDateStart = 8;
const int columnDateEnd = 9;
const int columnGuilty = 10;
const int columnNpt = 11;
var subTitle = $"на строительство скважины №{well.Caption}, куст: {well.Cluster}, м/р: {well.Deposit}";
sheet.Row(rowTitle).Cell(3).Value = subTitle;
DateTime lastFactDate = default;
var lastFactI = 0;
const int columnDuration = 6;
const int columnDateStart = 7;
const int columnDateEnd = 8;
int i = 0;
for (; i < tvdList.Count; i++)
@ -118,111 +100,15 @@ namespace AsbCloudInfrastructure.Services.WellOperationService
if (tvdItem is null)
continue;
if (i == 86)
{
;
}
var row = sheet.Row(1 + i + headerRowsCount);
SetCell(row, columnRowNumber, $"{1 + i}");
SetCell(row, columnCaption, $"{tvdItem.CategoryName} {tvdItem.CategoryInfo}".Trim());
SetCell(row, columnWellDepthStart, tvdItem.DepthStart);
SetCell(row, columnWellDepthEnd, tvdItem.DepthEnd);
SetCell(row, columnDeltaWellDepthPerDay, null);
if (mode == sheduleMode.fact)
{
var fact = tvdItem;
if (lastFactDate == default)
lastFactDate = fact.DateStart;
if (i > 0 && fact.DateStart.DayOfYear != lastFactDate.DayOfYear)
{
var daylyOperations = tvdList
.Where(t => t.DateStart >= lastFactDate && t.DateStart < fact.DateStart);
if (daylyOperations.Any())
{
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, columnDuration, tvdItem.DurationHours);
SetCell(row, columnDateStart, tvdItem.DateStart);
SetCell(row, columnDateEnd, tvdItem.DateStart.AddHours(tvdItem.DurationHours));
if (mode == sheduleMode.fact && WellOperationCategory.NonProductiveTimeSubIds.Contains(tvdItem.IdCategory))
{
SetCell(row, columnGuilty, tvdItem.Comment);
SetCell(row, columnNpt, tvdItem.DurationHours);
row.Row(columnRowNumber, columnNpt).Style.Fill.BackgroundColor = XLColor.Red;
}
else
{
SetCell(row, columnGuilty, null);
SetCell(row, columnNpt, null);
}
}
var rowNumSummary = 1 + i + headerRowsCount;
var rowNumStart = 1 + headerRowsCount;
var rowNumEnd = i + headerRowsCount;
string MakeRangeFunction(string funcName, int column)
=> $"={funcName}({GetColunmLetter(column)}{rowNumStart}:{GetColunmLetter(column)}{rowNumEnd})";
IXLCell AddRangeFormula(IXLRow row, string funcName, int column)
{
var cell = row.Cell(column);
cell.FormulaA1 = MakeRangeFunction(funcName, column);
return cell;
}
var rowSummary = sheet.Row(rowNumSummary);
rowSummary.Style.Font.Bold = true;
rowSummary.Cell(columnCaption).Value = "Итого:";
AddRangeFormula(rowSummary, "sum", columnDeltaWellDepthPerDay);
AddRangeFormula(rowSummary, "sum", columnDuration);
var cell = AddRangeFormula(rowSummary, "max", columnDateEnd);
SetDateTime(cell);
SetDateTime(cell);
AddRangeFormula(rowSummary, "sum", columnNpt);
SetBorder(rowSummary.Cells(true).Style);
var rowSummary2 = sheet.Row(rowNumSummary + 1);
rowSummary2.DataType = XLDataType.Number;
rowSummary2.Style.NumberFormat.Format = "0,00";
rowSummary2.Cell(columnCaption).Value = "в сутках:";
rowSummary2.Cell(columnDuration).FormulaA1 = $"={GetColunmLetter(columnDuration)}{rowNumSummary}/24";
SetNumber(rowSummary2.Cell(columnDuration));
rowSummary2.Cell(columnNpt).FormulaA1 = $"={GetColunmLetter(columnNpt)}{rowNumSummary}/24";
SetNumber(rowSummary2.Cell(columnNpt));
SetBorder(rowSummary2.Cells(true).Style);
}
private static string GetSheetName(sheduleMode mode)
{
switch (mode)
{
case sheduleMode.plan:
return sheetNameSchedulePlan;
case sheduleMode.fact:
return sheetNameScheduleFact;
case sheduleMode.predict:
return sheetNameSchedulePrediction;
default:
return sheetNameSchedule;
}
}
@ -278,11 +164,6 @@ namespace AsbCloudInfrastructure.Services.WellOperationService
var row = sheet.Row(1 + i + headerRowsCount);
if (i == 86)
{
;
}
SetCell(row, columnRowNumber, $"{1 + i}");
SetCell(row, columnCaption, $"{operation.CategoryName} {operation.CategoryInfo}".Trim());