lazhen
2024-12-03 212864834f7727ba09b5ece6e9b71e69e182d228
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
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
Quintiq file version 2.0
#parent: #root
StaticMethod GenerateDispatchData (
  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 ,not row.ProductionLine().ToUpper().LikeUserLocale( "MOMO" )){
      line := null( DispatchShiftSchedulingLine );
      factory := constnull( Unit );
      unit := constnull( Unit );
      {
        unitHandle := unitIndexTree.GetHandle( row.ProductionLine() );
        unitIndex := guard( unitIndexTree.Root().Child( unitHandle ), null( NamedValue ));
        if( not isnull( unitIndex )){
          unit := units.Element( unitIndex.GetValueAsNumber() );
          factory := LocalTool::GetFactoryByUnit( unit );
        }
      }
      
      traverse( row,NewOfflinePlanCell,cell, startDate <= cell.NewOfflinePlanColumn().StartDate() and endDate >= cell.NewOfflinePlanColumn().EndDate()){
        product := null( DispatchShiftSchedulingProduct );
        tips := "";
        if( not isnull( unit )){
          tips := ShiftPlan::CalculateRemark( unit,cell.NewOfflinePlanColumn().StartDate(),cell.NewOfflinePlanColumn().EndDate() );
        }
        {
          lineKey := row.ProductionLine() + cell.NewOfflinePlanColumn().StartDate().AsQUILL();
          lineHandle := lineIndexTree.GetHandle( lineKey );
          lineIndex := guard( lineIndexTree.Root().Child( lineHandle ),null( NamedValue ));
          if( isnull( lineIndex )){
            line := owner.DispatchShiftSchedulingLine( relnew,ID := IDHolder::GetGUID(),LineName := row.ProductionLine(),ShiftDate := cell.NewOfflinePlanColumn().StartDate(),Tips := tips );
            line.FactoryName( factory.Name() );
            line.InterfaceTime( now );
            line.VersionName( macroPlan.MDSMacroPlan().Description() );
            line.ShiftName( cell.ShiftPatternName() );
            lines.Add( line );
            lineIndexTree.Root().AddChild( lineHandle,lines.Size() - 1 );
          }else{
            line := lines.Element( lineIndex.GetValueAsNumber() ); 
          }
          
          productHandle := productIndexTree.GetHandle( lineKey + row.ProductID() );
          productIndex := guard( productIndexTree.Root().Child( productHandle ),null( NamedValue ));
          if( isnull( productIndex )){
            product := line.DispatchShiftSchedulingProduct( relnew,ProductID := row.ProductID() );
            product.ProductionQuantity( cell.Quantity() );
            products.Add( product );
            productIndexTree.Root().AddChild( productHandle,products.Size() - 1 );
          }else{
            product := products.Element( productIndex.GetValueAsNumber() ); 
          }
        }
      }
    }
    
    traverse( macroPlan,NewAssemblyOnlinePlanRow,row , row.ProductionLine().ToUpper().LikeUserLocale( "MOMO" )){
      line := null( DispatchShiftSchedulingLine );
      factory := constnull( Unit );
      unit := 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;
        }
      }
      
      traverse( row,NewAssemblyOnlinePlanCell,cell, startDate <= cell.NewAssemblyOnlinePlanColumn().StartDate() and endDate >= cell.NewAssemblyOnlinePlanColumn().EndDate()){
        product := null( DispatchShiftSchedulingProduct );
        tips := "";
        if( not isnull( unit )){
          tips := ShiftPlan::CalculateRemark( unit,cell.NewAssemblyOnlinePlanColumn().StartDate(),cell.NewAssemblyOnlinePlanColumn().EndDate() );
        }
        {
          lineKey := row.ProductionLine() + cell.NewAssemblyOnlinePlanColumn().StartDate().AsQUILL();
          lineHandle := lineIndexTree.GetHandle( lineKey );
          lineIndex := guard( lineIndexTree.Root().Child( lineHandle ),null( NamedValue ));
          if( isnull( lineIndex )){
            line := owner.DispatchShiftSchedulingLine( relnew,ID := IDHolder::GetGUID(),LineName := row.ProductionLine(),ShiftDate := cell.NewAssemblyOnlinePlanColumn().StartDate(),Tips := tips );
            line.FactoryName( factory.Name() );
            line.InterfaceTime( now );
            line.VersionName( macroPlan.MDSMacroPlan().Description() );
            line.ShiftName( cell.ShiftPatternName() );
            lines.Add( line );
            lineIndexTree.Root().AddChild( lineHandle,lines.Size() - 1 );
          }else{
            line := lines.Element( lineIndex.GetValueAsNumber() ); 
          }
          
          productHandle := productIndexTree.GetHandle( lineKey + row.ProductID() );
          productIndex := guard( productIndexTree.Root().Child( productHandle ),null( NamedValue ));
          if( isnull( productIndex )){
            product := line.DispatchShiftSchedulingProduct( relnew,ProductID := row.ProductID() );
            product.ProductionQuantity( cell.Quantity() );
            products.Add( product );
            productIndexTree.Root().AddChild( productHandle,products.Size() - 1 );
          }else{
            product := products.Element( productIndex.GetValueAsNumber() ); 
          }
        }
      }
    }
    
    traverse( lines,Elements,line ){
      line.CalcLineQuantity();
      
      unit := constnull( Unit );
      {
        unitHandle := unitIndexTree.GetHandle( line.LineName() );
        unitIndex := guard( unitIndexTree.Root().Child( unitHandle ), null( NamedValue ));
        if( not isnull( unitIndex )){
          unit := units.Element( unitIndex.GetValueAsNumber() );
        }
      }
      
      // 481
      lineQuantity := line.LineQuantity();
      
      tempProducts := selectsortedset( line,DispatchShiftSchedulingProduct,object,object.ProductionQuantity() );
      
      if( line.ShiftName() = "3" ){
        
        singleShiftVolume1 := 0.0;
        singleShiftVolume2 := 0.0;
        singleShiftVolume3 := 0.0;
        
        singleShiftConfig := select( unit,SingleShiftConfig,config,config.ShiftName() = "3" );
        if( not isnull( singleShiftConfig ) ){
          if( line.Tips().LikeUserLocale( "保养" )){
            singleShiftVolume1 := 0.0;
            singleShiftVolume2 := singleShiftConfig.SecondSingleShiftQuantity();
            singleShiftVolume3 := singleShiftConfig.ThirdSingleShiftQuantity();
          }else{
            singleShiftVolume1 := singleShiftConfig.FirstSingleShiftQuantity();
            singleShiftVolume2 := singleShiftConfig.SecondSingleShiftQuantity();
            singleShiftVolume3 := singleShiftConfig.ThirdSingleShiftQuantity();
          }
        }else{
          if( line.Tips().LikeUserLocale( "保养" )){
            singleShiftVolume1 := 0.0;
            singleShiftVolume2 := lineQuantity / 2;
            singleShiftVolume3 := lineQuantity / 2;
          }else{
            singleShiftVolume1 := lineQuantity / 3;
            singleShiftVolume2 := lineQuantity / 3;
            singleShiftVolume3 := lineQuantity / 3;
          }
        }
        
        for( i := tempProducts.Size() - 1;i >= 0; i-- ){
          product := tempProducts.Element( i );
          productionQuantity := product.ProductionQuantity();
          
          if( line.Tips().LikeUserLocale( "保养" ) and productionQuantity > 0){
            product.DispatchShiftSchedulingDetail( relnew,ShiftVolume := 0 ,SingleShiftName := "白班");
          }
          
          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();
          }
          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();
          }
          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") or (line.ShiftName() = "9+9") or (line.ShiftName() = "10+10") or (line.ShiftName() = "11+11") ){
        // 240.5
        singleShiftVolume1 := 0.0;
        singleShiftVolume2 := 0.0;
        
        singleShiftConfig := select( unit,SingleShiftConfig,config,config.ShiftName() = line.ShiftName() );
        if( not isnull( singleShiftConfig )){
          if( line.Tips().LikeUserLocale( "保养" )){
            singleShiftVolume1 := 0.0;
            singleShiftVolume2 := singleShiftConfig.SecondSingleShiftQuantity();
          }else{
            singleShiftVolume1 := singleShiftConfig.FirstSingleShiftQuantity();
            singleShiftVolume2 := singleShiftConfig.SecondSingleShiftQuantity();
          }
        }else{
          if( line.Tips().LikeUserLocale( "保养" )){
            singleShiftVolume1 := 0.0;
            singleShiftVolume2 := lineQuantity;
          }else{
            singleShiftVolume1 := lineQuantity / 2;
            singleShiftVolume2 := lineQuantity / 2;
          }
        }
    
        for( i := tempProducts.Size() - 1;i >= 0; i-- ){
          product := tempProducts.Element( i );
          productionQuantity := product.ProductionQuantity();
          
          if( line.Tips().LikeUserLocale( "保养" ) and productionQuantity > 0){
            product.DispatchShiftSchedulingDetail( relnew,ShiftVolume := 0 ,SingleShiftName := "白班");
          }
          
          if( singleShiftVolume1 > 0 and productionQuantity > 0){
            // -47.5
            tempProductQuantity := singleShiftVolume1 - productionQuantity;
            detail := product.DispatchShiftSchedulingDetail( relnew,ShiftVolume := ifexpr( tempProductQuantity > 0 ,productionQuantity,singleShiftVolume1 ) ,SingleShiftName := "白班");
            singleShiftVolume1 := singleShiftVolume1 - productionQuantity;
            productionQuantity := productionQuantity - detail.ShiftVolume();
          }
          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( line.ShiftName() = "1" ){
        singleShiftVolume1 := lineQuantity;
        
        for( i := tempProducts.Size() - 1;i >= 0; i-- ){
          product := tempProducts.Element( i );
          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{
        info( "不支持的班次名称【" + line.ShiftName() + "】");
      }
    }
    
    traverse( lines,Elements.DispatchShiftSchedulingProduct.DispatchShiftSchedulingDetail,detail ){
      detail.ShiftVolume( detail.ShiftVolume() ); 
    }
    
    info( "Success" );
  *]
}