lihongji
2024-10-15 224bc6082b06f53755ee7e834d78e17f51cb0fa2
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
Quintiq file version 2.0
#parent: #root
StaticMethod Create (
  MacroPlan owner
) as MP_Table
{
  TextBody:
  [*
      // rislai Aug-6-2024 (created)
    table := select( owner,MP_Table,table,table.Name() = MP_Cell_ScheduleSummary::GetTableName() );
    if( not isnull( table )){
      table.Delete(); 
    }
    
    table := owner.MP_Table( relnew,Name := MP_Cell_ScheduleSummary::GetTableName());
    
    startDate := owner.StartOfPlanning().Date();
    
    endDate := maxselect( owner,Unit.UnitPeriod.astype( UnitPeriodTime ).Period_MP,period,period.TimeUnit() = Translations::MP_GlobalParameters_Day(),period.EndDate()).EndDate();
    
    columns := construct( MP_Columns );
    columnIndexTree := NamedValueTree::Create();
    for( i := startDate;i < endDate; i := i + 1){
      column := table.MP_Column( relnew,CustomDate := i );
      columnHandle := columnIndexTree.GetHandle( i.AsQUILL() );
      columns.Add( column );
      columnIndexTree.Root().AddChild( columnHandle,columns.Size() - 1 );
    }
    
    traverse( owner,Unit,unit,unit.HasCapacityTypeTime() and not unit.HasChild()){
      // unit.AsEntity().DisplayNameForSelection()
      row := table.MP_Row( relnew,CustomName := unit.ID(),Index := table.GetRowIndexCache() ); 
      throughput := guard( sum( unit,Operation,operation,operation.Throughput() ) / unit.Operation( relsize ) , 0 );
      
      unitPeriodTimes := selectset( unit,UnitPeriod.astype( UnitPeriodTime ),unitPeriodTime,
                                        unitPeriodTime.Period_MP().StartDate() >= startDate 
                                    and unitPeriodTime.Period_MP().EndDate() <= endDate 
                                    and unitPeriodTime.Period_MP().TimeUnit() = Translations::MP_GlobalParameters_Day());
      traverse( unitPeriodTimes,Elements,unitPeriodTime ){
        columnHandle := columnIndexTree.GetHandle( unitPeriodTime.Period_MP().StartDate().AsQUILL() );
        columnIndex := guard( columnIndexTree.Root().Child( columnHandle ),null( NamedValue ));
        if( not isnull( columnIndex )){
          // 当arrowedAvailableCapacity不为0,工作日 + 1
          arrowedAvailableCapacity := unitPeriodTime.TotalAvailableCapacity();
          zeroDuration := Duration::Construct( 0,0,0,0 );
          
          column := columns.Element( columnIndex.GetValueAsNumber() );
          
          dayOfWeek := column.CustomDate().DayOfWeek();
          workHours := select( unitPeriodTime,ShiftPattern.ShiftDay,shifDay,shifDay.Day_MP().ID() = dayOfWeek );
          capacity := 0.0;
          
          workDay := ifexpr( arrowedAvailableCapacity <> zeroDuration, 1,0 );
          if( not isnull( workHours )){
            capacity := workDay * throughput * workHours.Capacity().HoursAsReal()
          }
          
          isFirstWeekData := true;
          
          if( column.CustomDate() > startDate + 7 ){
            isFirstWeekData := false; 
          }
          
          row.MP_Cell( relnew,MP_Cell_ScheduleSummary,MP_Column := column,
                       IsFristWeekData := isFirstWeekData,
                       ShiftPattern := unitPeriodTime.ShiftPatternName(),
                       WorkingDay := workDay,
                       Capacity := capacity,
                       Output := 0 );
        }
      }
    }
    traverse( table,MP_Column,column,column.MP_Cell( relsize ) = 0 ){
      column.Delete(); 
    }
    return table;
  *]
}