陈清红
2025-04-14 880f3c0257eeb8c37761d484258fdd102a369a19
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
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
Quintiq file version 2.0
#parent: #root
StaticMethod Archive (
  const MacroPlan macroPlan,
  Archive archive
)
{
  TextBody:
  [*
    // Akari Oct-23-2024 (created)
    archiveShiftPlanCells := selectset( archive,ArchiveShiftPlanRow.ArchiveShiftPlanCell,cell,true );
    archiveShiftPlanCellIndexTree := NamedValueTree::Create();
    for( i := 0; i < archiveShiftPlanCells.Size(); i++ ){
      archiveShiftPlanCell := archiveShiftPlanCells.Element( i );
      archiveShiftPlanRow := archiveShiftPlanCell.ArchiveShiftPlanRow();
      archiveShiftPlanColumn := archiveShiftPlanCell.ArchiveShiftPlanColumn();
      
      archiveShiftPlanRowKey := archiveShiftPlanRow.UnitID();
      archiveShiftPlanColumnKey := archiveShiftPlanColumn.StartDate().AsQUILL();
      archiveShiftPlanCellKey := archiveShiftPlanRowKey + archiveShiftPlanColumnKey;
      archiveShiftPlanCellHandle := archiveShiftPlanCellIndexTree.GetHandle( archiveShiftPlanCellKey );
      
      archiveShiftPlanCellIndexTree.Root().AddChild( archiveShiftPlanCellHandle,i );
    }
    
    archiveShiftPlanRows := selectset( archive,ArchiveShiftPlanRow,row,true );
    archiveShiftPlanRowIndexTree := NamedValueTree::Create();
    for( i := 0; i < archiveShiftPlanRows.Size(); i++ ){
      archiveShiftPlanRow := archiveShiftPlanRows.Element( i );
      archiveShiftPlanRowKey := archiveShiftPlanRow.UnitID();
      archiveShiftPlanRowHandle := archiveShiftPlanRowIndexTree.GetHandle( archiveShiftPlanRowKey );
      archiveShiftPlanRowIndexTree.Root().AddChild( archiveShiftPlanRowHandle,i );
    }
    
    archiveShiftPlanColumns := selectset( archive,ArchiveShiftPlanColumn,row,true );
    archiveShiftPlanColumnIndexTree := NamedValueTree::Create();
    for( i := 0; i < archiveShiftPlanColumns.Size(); i++ ){
      archiveShiftPlanColumn := archiveShiftPlanColumns.Element( i );
      archiveShiftPlanColumnKey := archiveShiftPlanColumn.StartDate().AsQUILL();
      archiveShiftPlanColumnHandle := archiveShiftPlanColumnIndexTree.GetHandle( archiveShiftPlanColumnKey );
      archiveShiftPlanColumnIndexTree.Root().AddChild( archiveShiftPlanColumnHandle,i );
    }
    
    traverse( macroPlan,Unit.UnitPeriod.astype( UnitPeriodTime ).ShiftPlan,shiftPlanCell,shiftPlanCell.UnitPeriodTime().Period_MP().StartDate() >= macroPlan.StartOfPlanning().Date() ){
      shiftPlanRow := shiftPlanCell.UnitPeriodTime().Unit();
      shiftPlanColumn := shiftPlanCell.UnitPeriodTime().Period_MP();
      shiftPlanRowKey := shiftPlanRow.ID();
      shiftPlanColumnKey := shiftPlanColumn.StartDate().AsQUILL();
      shiftPlanCellKey := shiftPlanRowKey + shiftPlanColumnKey;
      
      archiveShiftPlanCell := null( ArchiveShiftPlanCell );
      archiveShiftPlanCellHandle := archiveShiftPlanCellIndexTree.GetHandle( shiftPlanCellKey );
      archiveShiftPlanCellIndex := guard( archiveShiftPlanCellIndexTree.Root().Child( archiveShiftPlanCellHandle ),null( NamedValue ) );
      if( isnull( archiveShiftPlanCellIndex )){
        factory := LocalTool::GetFactoryByUnit( shiftPlanCell.UnitPeriodTime().Unit() );
        
        archiveShiftPlanRow := null( ArchiveShiftPlanRow );
        archiveShiftPlanRowHandle := archiveShiftPlanRowIndexTree.GetHandle( shiftPlanRowKey );
        archiveShiftPlanRowIndex := guard( archiveShiftPlanRowIndexTree.Root().Child( archiveShiftPlanRowHandle ),null( NamedValue ));
        if( isnull( archiveShiftPlanRowIndex )){
          archiveShiftPlanRow := archive.ArchiveShiftPlanRow( relnew,UnitID := shiftPlanRow.ID() );
          archiveShiftPlanRows.Add( archiveShiftPlanRow );
          archiveShiftPlanRowIndexTree.Root().AddChild( archiveShiftPlanRowHandle,archiveShiftPlanRows.Size() - 1 );
        }else{
          archiveShiftPlanRow := archiveShiftPlanRows.Element( archiveShiftPlanRowIndex.GetValueAsNumber() );
        }
        
        archiveShiftPlanRow.FactoryName( factory.ID() );
        
        archiveShiftPlanColumn := null( ArchiveShiftPlanColumn );
        archiveShiftPlanColumnHandle := archiveShiftPlanColumnIndexTree.GetHandle( shiftPlanColumnKey );
        archiveShiftPlanColumnIndex := guard( archiveShiftPlanColumnIndexTree.Root().Child( archiveShiftPlanColumnHandle ),null( NamedValue ));
        if( isnull( archiveShiftPlanColumnIndex )){
          archiveShiftPlanColumn := archive.ArchiveShiftPlanColumn( relnew,StartDate := shiftPlanColumn.StartDate() );
          archiveShiftPlanColumns.Add( archiveShiftPlanColumn );
          archiveShiftPlanColumnIndexTree.Root().AddChild( archiveShiftPlanColumnHandle,archiveShiftPlanColumns.Size() - 1 );
        }else{
          archiveShiftPlanColumn := archiveShiftPlanColumns.Element( archiveShiftPlanColumnIndex.GetValueAsNumber() ); 
        }
        
        archiveShiftPlanCell := archiveShiftPlanRow.ArchiveShiftPlanCell( relnew,ArchiveShiftPlanColumn := archiveShiftPlanColumn );
        archiveShiftPlanCells.Add( archiveShiftPlanCell );
        archiveShiftPlanCellIndexTree.Root().AddChild( archiveShiftPlanCellHandle,archiveShiftPlanCells.Size() - 1 );
      }else{
        archiveShiftPlanCell := archiveShiftPlanCells.Element( archiveShiftPlanCellIndex.GetValueAsNumber());
      }
      
      archiveShiftPlanCell.EventType( shiftPlanCell.EventType());
      archiveShiftPlanCell.IsHoliday( shiftPlanCell.IsHoliday() );
      archiveShiftPlanCell.Outcome( shiftPlanCell.Outcome() );
      archiveShiftPlanCell.Remark( shiftPlanCell.Remark() );
      archiveShiftPlanCell.MacroPlanName( shiftPlanCell.UnitPeriodTime().MacroPlan().MDSMacroPlan().Description() );
      archiveShiftPlanCell.MacroPlanMDSID( shiftPlanCell.UnitPeriodTime().MacroPlan().MDSID() );
    }
  *]
}