| Quintiq file version 2.0 | 
| #parent: #root | 
| StaticMethod PostLayingProcessing ( | 
|   MacroPlan macroPlan | 
| ) | 
| { | 
|   Description: '铺线后续处理' | 
|   TextBody: | 
|   [* | 
|     // 所有上线计划产线 | 
|     pls    := selectuniquevalues( macroPlan, NewAssemblyOnlinePlanRow, tempNAOPR, true, tempNAOPR.ProductionLine() ); | 
|      | 
|     // 是否执行处理标志 | 
|     isFlag := true; | 
|      | 
|     traverse ( pls, Elements, pl | 
|     //           , pl = "DL ZKM"  | 
|               ) {               | 
|       traverse ( macroPlan, NewAssemblyOnlinePlanColumn, naopc | 
|     //             , naopc.StartDate() <= Date::Construct( 2025, 1, 11 ) | 
|                 ) { | 
|         // 需要处理的数量 | 
|         targetQuantity := ifexpr( pl = "CC MoMo", guard( macroPlan.AssemblyOnlineQuantity().CCMoMo(), 0 ), | 
|                                   ifexpr( pl = "DL MoMo", guard( macroPlan.AssemblyOnlineQuantity().DLMoMo(), 0 ), guard( macroPlan.AssemblyOnlineQuantity().DLZKM(), 0 ) ) | 
|                                  ); | 
|          | 
|         currentCells := selectset( naopc, NewAssemblyOnlinePlanCell, tempNAOPCell, tempNAOPCell.NewAssemblyOnlinePlanRow().ProductionLine() = pl and tempNAOPCell.Quantity() > 0 ); | 
|         isFlag       := ifexpr( exists( currentCells, Elements, tempNAOPCell, tempNAOPCell.LineLayingOrEmptying() = "铺线" ), true,  | 
|                                 ifexpr( exists( currentCells, Elements, tempNAOPCell, tempNAOPCell.LineLayingOrEmptying() = "拉空" ), false, isFlag ) ); | 
|     //    info( "日期:", naopc.StartDate().Format( "Y-M2-D2" ), "   是否处理:", isFlag, "    当前单元格数量:", currentCells.Size(), "----------------------------" ); | 
|          | 
|         // 处理铺线后的逻辑 | 
|         if ( isFlag and currentCells.Size() > 0 ) { | 
|           targetNAOPC := minselect( macroPlan, NewAssemblyOnlinePlanColumn, tempNAOPC,  | 
|                                     exists( tempNAOPC, NewAssemblyOnlinePlanCell, tempNAOPCell, tempNAOPCell.NewAssemblyOnlinePlanRow().ProductionLine() = pl and tempNAOPCell.OrderNr() > 0, tempNAOPCell.Quantity() > 0 ) and | 
|                                     tempNAOPC.StartDate() > naopc.StartDate(), tempNAOPC.StartDate() ); | 
|            | 
|           if ( not isnull( targetNAOPC ) ) { | 
|     //        info( "最小列时间:", targetNAOPC.StartDate().Format( "Y-M2-D2" ) ); | 
|             targetCells   := selectset( targetNAOPC, NewAssemblyOnlinePlanCell, tempNAOPCell, tempNAOPCell.NewAssemblyOnlinePlanRow().ProductionLine() = pl ); | 
|              | 
|             // 目标单元格 | 
|             targetCell    := minselect( targetCells, Elements, tempNAOPCell, tempNAOPCell.OrderNr() > 0 and tempNAOPCell.Quantity() > 0, tempNAOPCell.OrderNr() ); | 
|             finalQuantity := minvalue( targetQuantity, targetCell.Quantity() ); | 
|             currentCell   := select( naopc, NewAssemblyOnlinePlanCell, tempNAOPCell, tempNAOPCell.NewAssemblyOnlinePlanRow() = targetCell.NewAssemblyOnlinePlanRow() ); | 
|              | 
|             while ( targetQuantity > 0 and finalQuantity > 0 ) { | 
|               targetCell.Quantity( targetCell.Quantity() - finalQuantity ); | 
|               currentCell.Quantity( currentCell.Quantity() + finalQuantity ); | 
|               if ( currentCell.OrderNr() <= 0 ) { | 
|                 orderNr := maxselect( naopc, NewAssemblyOnlinePlanCell, tempNAOPCell,  | 
|                                       tempNAOPCell.NewAssemblyOnlinePlanRow().ProductionLine() = pl and tempNAOPCell.Quantity() > 0,  | 
|                                       tempNAOPCell.OrderNr() ).OrderNr() + 1; | 
|     //            info( orderNr ); | 
|                 currentCell.OrderNr( orderNr ); | 
|                 currentCell.Order( "#" + orderNr.Format( "N(LPad0(2))" ) ); | 
|               } | 
|                | 
|               targetQuantity := targetQuantity - [Number]finalQuantity; | 
|               targetCell    := minselect( targetCells, Elements, tempNAOPCell, tempNAOPCell.OrderNr() > 0 and tempNAOPCell.Quantity() > 0, tempNAOPCell.OrderNr() ); | 
|               finalQuantity := minvalue( targetQuantity, targetCell.Quantity() ); | 
|               currentCell   := select( naopc, NewAssemblyOnlinePlanCell, tempNAOPCell, tempNAOPCell.NewAssemblyOnlinePlanRow() = targetCell.NewAssemblyOnlinePlanRow() ); | 
|             } | 
|           } | 
|         } | 
|       } | 
|     } | 
|   *] | 
| } |