xiaoding721
2024-10-28 52bd9a90e6e31eb2c458447fd7fec4e8f99a0fe7
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
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
Quintiq file version 2.0
#parent: #root
StaticMethod Dispatch (
  Date startDate,
  Date endDate,
  const NewOfflinePlanTable offlinePlan,
  RecycleBin owner
)
{
  TextBody:
  [*
    // Akari Sep-4-2024 (created)
    owner.DispatchShiftSchedulingLine( relflush );
    macroPlan := offlinePlan.MacroPlan();
    now := DateTime::Now();
    
    shiftPatterns := selectset( macroPlan,ShiftPattern,object,true );
    shiftPatternIndexTree := NamedValueTree::Create();
    for( i := 0; i < shiftPatterns.Size(); i++){
      shiftPattern := shiftPatterns.Element( i );
      shiftPatternHandle := shiftPatternIndexTree.GetHandle( shiftPattern.Name() );
      shiftPatternIndexTree.Root().AddChild( shiftPatternHandle,i );
    }
    
    units := selectset( macroPlan,Unit,object, true );
    unitIndexTree := NamedValueTree::Create();
    for( i := 0; i < units.Size(); i++){
      unit := units.Element( i );
      unitHandle := unitIndexTree.GetHandle( unit.Name() );
      unitIndexTree.Root().AddChild( unitHandle,i );
    }
    
    lines := construct( DispatchShiftSchedulingLines );
    lineIndexTree := NamedValueTree::Create();
    
    products := construct( DispatchShiftSchedulingProducts );
    productIndexTree := NamedValueTree::Create();
    
    //productionDetails := construct( DispatchShiftSchedulingDetails );
    //productionDetailIndexTree := NamedValueTree::Create();
    traverse( offlinePlan,NewOfflinePlanRow,row ){
      line := null( DispatchShiftSchedulingLine );
      factory := constnull( Unit );
      {
        unitHandle := unitIndexTree.GetHandle( row.ProductionLine() );
        unitIndex := guard( unitIndexTree.Root().Child( unitHandle ), null( NamedValue ));
        if( not isnull( unitIndex )){
          unit := units.Element( unitIndex.GetValueAsNumber() );
          temp1 := unit;
          temp2 := unit.Parent();
          while( not isnull( temp1.Parent())){
            temp2 := temp1;
            temp1 := temp1.Parent();
          }
          factory := temp2;
        }
        
        lineHandle := lineIndexTree.GetHandle( row.ProductionLine() );
        lineIndex := guard( lineIndexTree.Root().Child( lineHandle ),null( NamedValue ));
        if( isnull( lineIndex )){
          line := owner.DispatchShiftSchedulingLine( relnew,ID := IDHolder::GetGUID(),LineID := row.ProductionLine() );
          line.FactoryName( factory.Name() );
          line.InterfaceTime( now );
          line.VersionName( macroPlan.MDSMacroPlan().Description() );
          lines.Add( line );
          lineIndexTree.Root().AddChild( lineHandle,lines.Size() - 1 );
        }else{
          line := lines.Element( lineIndex.GetValueAsNumber() ); 
        }
      }
      
      traverse( row,NewOfflinePlanCell,cell, startDate <= cell.NewOfflinePlanColumn().StartDate() and endDate >= cell.NewOfflinePlanColumn().EndDate()){
        product := null( DispatchShiftSchedulingProduct );
        {
          productHandle := productIndexTree.GetHandle( row.ProductionLine() + row.ProductID() + cell.NewOfflinePlanColumn().StartDate().AsQUILL() );
          productIndex := guard( productIndexTree.Root().Child( productHandle ),null( NamedValue ));
          if( isnull( productIndex )){
            product := line.DispatchShiftSchedulingProduct( relnew,ProductID := row.ProductID() );
            product.ProductionQuantity( cell.Quantity() );
            line.ShiftDate( cell.NewOfflinePlanColumn().StartDate() );
            line.ShiftName( cell.ShiftPatternName() );
            products.Add( product );
            productIndexTree.Root().AddChild( productHandle,products.Size() - 1 );
          }else{
            product := products.Element( productIndex.GetValueAsNumber() ); 
          }
        }
      }
    }
    
    traverse( lines,Elements,line ){
      line.CalculateLineQuantity();
      
      // 1000
      lineQuantity := line.LineQuantity();
      
      tempProducts := selectsortedset( line,DispatchShiftSchedulingProduct,object,object.ProductionQuantity() );
      
      if( line.ShiftName() = "3" ){
        singleShiftVolume1 := lineQuantity / 3;
        singleShiftVolume2 := lineQuantity / 3;
        singleShiftVolume3 := lineQuantity / 3;
        traverse( tempProducts,Elements,product ){
          productionQuantity := product.ProductionQuantity();
          
          if( singleShiftVolume1 > 0 and productionQuantity > 0){
            tempProductQuantity := singleShiftVolume1 - productionQuantity;
            detail := product.DispatchShiftSchedulingDetail( relnew,ShiftVolume := ifexpr( tempProductQuantity > 0 ,productionQuantity,singleShiftVolume1 ) ,SingleShiftName := "白班");
            singleShiftVolume1 := singleShiftVolume1 - productionQuantity;
            productionQuantity := productionQuantity - detail.ShiftVolume();
          }else if(singleShiftVolume2 > 0 and productionQuantity > 0){
            tempProductQuantity := singleShiftVolume2 - productionQuantity;
            detail := product.DispatchShiftSchedulingDetail( relnew,ShiftVolume := ifexpr( tempProductQuantity > 0 ,productionQuantity,singleShiftVolume2 ) ,SingleShiftName := "二班");
            singleShiftVolume2 := singleShiftVolume2 - productionQuantity;
            productionQuantity := productionQuantity - detail.ShiftVolume();
          }else if(singleShiftVolume3 > 0 and productionQuantity > 0){
            tempProductQuantity := singleShiftVolume3 - productionQuantity;
            detail := product.DispatchShiftSchedulingDetail( relnew,ShiftVolume := ifexpr( tempProductQuantity > 0 ,productionQuantity,singleShiftVolume3 ) ,SingleShiftName := "二班");
            singleShiftVolume3 := singleShiftVolume3 - productionQuantity;
            productionQuantity := productionQuantity - detail.ShiftVolume();
          }
        }
        
      }else if( line.ShiftName() = "2" ){
        // 500
        singleShiftVolume1 := lineQuantity / 2;
        singleShiftVolume2 := lineQuantity / 2;
        traverse( tempProducts,Elements,product ){
          productionQuantity := product.ProductionQuantity();
          
          if( singleShiftVolume1 > 0 and productionQuantity > 0){
            tempProductQuantity := singleShiftVolume1 - productionQuantity;
            detail := product.DispatchShiftSchedulingDetail( relnew,ShiftVolume := ifexpr( tempProductQuantity > 0 ,productionQuantity,singleShiftVolume1 ) ,SingleShiftName := "白班");
            singleShiftVolume1 := singleShiftVolume1 - productionQuantity;
            productionQuantity := productionQuantity - detail.ShiftVolume();
          }else if(singleShiftVolume2 > 0 and productionQuantity > 0){
            tempProductQuantity := singleShiftVolume2 - productionQuantity;
            detail := product.DispatchShiftSchedulingDetail( relnew,ShiftVolume := ifexpr( tempProductQuantity > 0 ,productionQuantity,singleShiftVolume1 ) ,SingleShiftName := "二班");
            singleShiftVolume2 := singleShiftVolume2 - productionQuantity;
            productionQuantity := productionQuantity - detail.ShiftVolume();
          }
        }
        
      }else if( line.ShiftName() = "1" ){
        singleShiftVolume1 := lineQuantity / 1;
        traverse( tempProducts,Elements,product ){
          productionQuantity := product.ProductionQuantity();
          if( singleShiftVolume1 > 0 and productionQuantity > 0){
            tempProductQuantity := singleShiftVolume1 - productionQuantity;
            detail := product.DispatchShiftSchedulingDetail( relnew,ShiftVolume := ifexpr( tempProductQuantity > 0 ,productionQuantity,singleShiftVolume1 ) ,SingleShiftName := "白班");
            singleShiftVolume1 := singleShiftVolume1 - productionQuantity;
            productionQuantity := productionQuantity - detail.ShiftVolume();
          }
        }
        
      }else{
        // singleShiftVolume := lineQuantity / 1;
      }
    }
    
    //traverse( offlinePlan,NewOfflinePlanRow,row ){
    //  productID := row.ProductID();
    //  productLine := row.ProductionLine();
    //  factory := constnull( Unit );
    //  {
    //    unitHandle := unitIndexTree.GetHandle( productLine );
    //    unitIndex := guard( unitIndexTree.Root().Child( unitHandle ), null( NamedValue ));
    //    if( not isnull( unitIndex )){
    //      unit := units.Element( unitIndex.GetValueAsNumber() );
    //      temp1 := unit;
    //      temp2 := unit.Parent();
    //      while( not isnull( temp1.Parent())){
    //        temp2 := temp1;
    //        temp1 := temp1.Parent();
    //      }
    //      factory := temp2;
    //    }
    //  }
    //  traverse( row,NewOfflinePlanCell,cell, startDate <= cell.NewOfflinePlanColumn().StartDate() and endDate >= cell.NewOfflinePlanColumn().EndDate()){
    //    productLinesQuantityHandle := productLinesQuantityNameValueTree.GetHandle( row.ProductionLine() + cell.NewOfflinePlanColumn().StartDate().AsQUILL() );
    //    productLinesQuantity := guard( productLinesQuantityNameValueTree.Root().Child( productLinesQuantityHandle ).GetValueAsReal(),0.0 );
    //    
    //    shiftDate := cell.NewOfflinePlanColumn().StartDate();
    //    shiftName := cell.ShiftPatternName();
    //    shiftVolume := cell.Quantity();
    //    shiftDayTime := constnull( ShiftDayTime );
    //    {
    //      shiftPatternHandle := shiftPatternIndexTree.GetHandle( shiftName );
    //      shiftPatternIndex := guard( shiftPatternIndexTree.Root().Child( shiftPatternHandle ),null( NamedValue ));
    //      if( not isnull( shiftPatternIndex )){
    //        shiftPattern := shiftPatterns.Element( shiftPatternIndex.GetValueAsNumber() );
    //        shiftDayTime := select( shiftPattern,ShiftDayTime,object,true );
    //      }
    //    }
    //    if( shiftVolume <> 0 ){
    //      shiftSchedulingInformations := DispatchShiftSchedulingLine::SplitShifts( owner,shiftName,shiftVolume,productLinesQuantity );
    //    
    //    traverse( shiftSchedulingInformations,Elements,shiftSchedulingInformation ){
    //      shiftSchedulingInformation.InterfaceTime( now );
    //      shiftSchedulingInformation.VersionName( macroPlan.MDSMacroPlan().Description() );
    //      shiftSchedulingInformation.Product( productID );
    //      shiftSchedulingInformation.ProductLine( productLine );
    //      shiftSchedulingInformation.ShiftDate( shiftDate );
    ////      shiftSchedulingInformation.InterfaceTime( now );
    ////      shiftSchedulingInformation.InterfaceTime( now );
    ////      shiftSchedulingInformation.InterfaceTime( now );
    ////      shiftSchedulingInformation.InterfaceTime( now );
    //      
    //      
    //      if( not isnull( shiftDayTime )){
    //        shiftSchedulingInformation.ShiftStartDate( shiftDayTime.StartDateTime() );
    //        shiftSchedulingInformation.ShiftEndDate( shiftDayTime.EndDateTIme() );
    //      }
    //      if( not isnull( factory )){
    //        shiftSchedulingInformation.FactoryName( factory.Name() );
    //      }
    //    }
    //    }
    //  }
    //}
  *]
}