hongjli
2025-01-14 386cb9a858f89d881acea3fd3a0d7c65945542ef
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
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, guard( targetCell.Quantity(), 0.0 ) );
              currentCell   := select( naopc, NewAssemblyOnlinePlanCell, tempNAOPCell, 
                                       guard( tempNAOPCell.NewAssemblyOnlinePlanRow() = targetCell.NewAssemblyOnlinePlanRow(), false ) );
            }
          }
        }
      }
    }
  *]
}