From 2c8d3e38df0004e30ea6208d17cf84c1e68989bb Mon Sep 17 00:00:00 2001
From: lihongji <3117313295@qq.com>
Date: 星期日, 13 十月 2024 19:24:34 +0800
Subject: [PATCH] 下线计划优化

---
 _Main/BL/Type_NewOfflinePlanCell/StaticMethod_RefreshOfflinePlan.qbl |  115 +++++++++++++++++++++++++++++++++++++++++++++------------
 1 files changed, 91 insertions(+), 24 deletions(-)

diff --git a/_Main/BL/Type_NewOfflinePlanCell/StaticMethod_RefreshOfflinePlan.qbl b/_Main/BL/Type_NewOfflinePlanCell/StaticMethod_RefreshOfflinePlan.qbl
index 1d7eafb..a018b69 100644
--- a/_Main/BL/Type_NewOfflinePlanCell/StaticMethod_RefreshOfflinePlan.qbl
+++ b/_Main/BL/Type_NewOfflinePlanCell/StaticMethod_RefreshOfflinePlan.qbl
@@ -8,7 +8,15 @@
   [*
     macroPlan.NewOfflinePlanTable( relflush );
     
-    nopt := macroPlan.NewOfflinePlanTable( relnew, SaveDateTime := DateTime::ActualTime() );
+    nopt         := macroPlan.NewOfflinePlanTable( relnew, SaveDateTime := DateTime::ActualTime() );
+    
+    // 璁″垝寮�濮嬫椂闂�
+    planningDate := macroPlan.StartOfPlanning().Date() 
+    
+    // 鍒濆鍖栦笅绾胯鍒掑垪
+    traverse ( macroPlan, Period_MP, pmp, pmp.IsPlanning() and not pmp.IsHistorical() ) {
+      nopt.NewOfflinePlanColumn( relnew, StartDate := pmp.StartDate(), EndDate := pmp.EndDate() );
+    }
     
     // 鐢熸垚涓嬬嚎璁″垝琛ㄣ�愪竴鏉′骇绾垮湪鍚屼竴澶╀笉浼氫骇鐢熶袱娆$浉鍚屼骇鍝佺殑鍛ㄦ湡浠诲姟銆�
     traverse ( macroPlan, Unit, u, u.HasCapacityTypeTime() 
@@ -48,32 +56,10 @@
             detaileNOPCell := detailedNOPR.NewOfflinePlanCell( relnew, 
                                                                Quantity          := ns.Quantity().Round( 0 ), 
                                                                InventoryWeight   := pispippl.InventoryLevelEnd() - pispippl.MinInventoryLevel(),
-                                                               ShiftPatternName  := guard( sdt.Name(), "" ),
+                                                               ShiftPatternName  := guard( sp.Name(), "" ),
                                                                ShiftPatternStart := guard( sdt.StartDateTime().Format( "H:m" ), "" ),
                                                                ShiftPatternEnd   := guard( sdt.EndDateTIme().Format( "H:m" ), "" ) );
             detaileNOPCell.NewOfflinePlanColumn( relset, nopc );
-          }
-        }
-      }
-      
-      // 璁剧疆鐢熶骇椤哄簭銆愬涓嬬嚎璁″垝鏄庣粏鐢熸晥銆�
-      
-      
-      // 銆愮敓鎴愬悎璁′笅绾胯鍒掋��
-      totalNOPR   := nopt.NewOfflinePlanRow( relnew, ProductID := "All", ProductionLine := u.ID(), Type := "2" );
-      detailNOPRs := selectset( nopt, NewOfflinePlanRow, tempNOPR, tempNOPR.ProductionLine() = u.ID() and tempNOPR.Type() = "1" );
-      traverse ( detailNOPRs, Elements, detailNOPR ) {
-        traverse ( detailNOPR, NewOfflinePlanCell, detailNOPCell ) {
-          // 鐢熶骇涓嬬嚎璁″垝銆愪骇绾垮悎璁°�戝崟鍏冩牸
-          totalNOPRCell   := select( totalNOPR, NewOfflinePlanCell, tempNOPCell, tempNOPCell.NewOfflinePlanColumn() = detailNOPCell.NewOfflinePlanColumn() );
-          if ( isnull( totalNOPRCell ) ) {
-            totalNOPRCell := totalNOPR.NewOfflinePlanCell( relnew );
-            totalNOPRCell.NewOfflinePlanColumn( relset, detailNOPCell.NewOfflinePlanColumn() ); // 璁剧疆鍒�
-            // 灏嗘槑缁嗗崟鍏冩牸鍏宠仈鍒板悎璁″崟鍏冩牸
-            totalNOPRCell.Detailed( relinsert, detailNOPCell );
-          } else {
-            // 灏嗘槑缁嗗崟鍏冩牸鍏宠仈鍒板悎璁″崟鍏冩牸
-            totalNOPRCell.Detailed( relinsert, detailNOPCell );
           }
         }
       }
@@ -88,6 +74,87 @@
           }
         }
       }
+      
+      // 銆愮敓鎴愬悎璁′笅绾胯鍒掋��
+      totalNOPR   := nopt.NewOfflinePlanRow( relnew, ProductID := "All", ProductionLine := u.ID(), Type := "2" );
+      detailNOPRs := selectset( nopt, NewOfflinePlanRow, tempNOPR, tempNOPR.ProductionLine() = u.ID() and tempNOPR.Type() = "1" );
+      traverse ( detailNOPRs, Elements, detailNOPR ) {
+        shiftPatternNOPCell := select( detailNOPR, NewOfflinePlanCell, tempNOPCell, tempNOPCell.ShiftPatternName() <> "" );
+        traverse ( detailNOPR, NewOfflinePlanCell, detailNOPCell ) {
+          // 鐢熶骇涓嬬嚎璁″垝銆愪骇绾垮悎璁°�戝崟鍏冩牸
+          totalNOPRCell   := select( totalNOPR, NewOfflinePlanCell, tempNOPCell, tempNOPCell.NewOfflinePlanColumn() = detailNOPCell.NewOfflinePlanColumn() );
+          if ( isnull( totalNOPRCell ) ) {
+            totalNOPRCell := totalNOPR.NewOfflinePlanCell( relnew, 
+                                                           ShiftPatternName  := shiftPatternNOPCell.ShiftPatternName(),
+                                                           ShiftPatternStart := shiftPatternNOPCell.ShiftPatternStart(),
+                                                           ShiftPatternEnd   := shiftPatternNOPCell.ShiftPatternEnd() );
+            totalNOPRCell.NewOfflinePlanColumn( relset, detailNOPCell.NewOfflinePlanColumn() ); // 璁剧疆鍒�
+            // 灏嗘槑缁嗗崟鍏冩牸鍏宠仈鍒板悎璁″崟鍏冩牸
+            totalNOPRCell.Detailed( relinsert, detailNOPCell );
+          } else {
+            // 灏嗘槑缁嗗崟鍏冩牸鍏宠仈鍒板悎璁″崟鍏冩牸
+            totalNOPRCell.Detailed( relinsert, detailNOPCell );
+          }
+        }
+      }
+      
+      // 璁剧疆鐢熶骇椤哄簭銆愬涓嬬嚎璁″垝鏄庣粏鐢熸晥銆�
+      indexColumn    := select( nopt, NewOfflinePlanColumn, tempNOPC, tempNOPC.StartDate() = planningDate );
+      previousColumn := indexColumn.PreviousNOPColumn();
+      nextColumn     := indexColumn.NextNOPColumn();
+      while ( not isnull( indexColumn.NextNOPColumn() )
+    //          and indexColumn.ColumnDate() <= Date::Construct( 2020, 4, 1 ) // 娴嬭瘯瀹為檯鍦烘櫙鏃跺彲浠ヨ繃婊�
+             ) 
+      {
+        orderNr     := 1;
+        nopcells    := selectsortedset( indexColumn, NewOfflinePlanCell, tempNOPCell, tempNOPCell.FindProductionLineAndType( u.ID(), "1" ), tempNOPCell.InventoryWeight() );
+        initialSize := nopcells.Size();
+    //    info( "璁″垝寮�濮嬫椂闂达細", planningDate.Format( "Y-M2-D2" ), "    绱㈠紩鏃堕棿锛�", indexColumn.StartDate().Format( "Y-M2-D2" ), "    涓暟锛�", nopcells.Size() );
+        
+        if ( nopcells.Size() > 0 ) {
+        
+          // 鍒ゅ畾1
+          previousOPCell := maxselect( previousColumn, NewOfflinePlanCell, tempNOPCell, tempNOPCell.FindProductionLineAndType( u.ID(), "1" ), tempNOPCell.OrderNr() );
+          if ( isnull( previousOPCell ) or indexColumn.StartDate() = planningDate ) {
+            nopcell := nopcells.Element( 0 );
+            nopcell.Order( "#" + orderNr.Format( "N(LPad0(2))" ) );
+            nopcell.OrderNr( orderNr );
+            orderNr++;
+            nopcells.Remove( nopcell );
+          } else {
+            nopcell := select( nopcells, Elements, tempNOPCell, tempNOPCell.NewOfflinePlanRow().ProductID() =  previousOPCell.NewOfflinePlanRow().ProductID() );
+            if ( not isnull( nopcell ) ) {
+              nopcell.Order( "#" + orderNr.Format( "N(LPad0(2))" ) );
+              nopcell.OrderNr( orderNr );
+              orderNr++;
+              nopcells.Remove( nopcell );
+            }
+          }
+          
+          // 鍒ゅ畾2
+          nextNOPCells := selectset( nopcells, Elements, tempOPC,
+                                     exists( nextColumn, NewOfflinePlanCell, nextOPCell, nextOPCell.FindProductionLineAndType( u.ID(), "1" ) and 
+                                             nextOPCell.NewOfflinePlanRow().ProductID() = tempOPC.NewOfflinePlanRow().ProductID() ) ); // 鎵句笅涓�鍒楁槸鍚︽湁褰撳墠鍒楃敓浜х殑浜у搧
+          if ( nextNOPCells.Size() = 1 ) {
+            nopcell := nextNOPCells.Element( 0 );
+            nopcell.Order( "#" + initialSize.Format( "N(LPad0(2))" ) );
+            nopcell.OrderNr( initialSize );
+            nopcells.Remove( nopcell );
+          }
+          
+          // 鍒ゅ畾3
+          traverse ( nopcells, Elements, opcell ) {
+            opcell.Order( "#" + orderNr.Format( "N(LPad0(2))" ) );
+            opcell.OrderNr( orderNr );
+            orderNr++;
+            nopcells.Remove( opcell );
+          }
+        }
+        
+        indexColumn    := indexColumn.NextNOPColumn();
+        previousColumn := indexColumn.PreviousNOPColumn();
+        nextColumn     := indexColumn.NextNOPColumn();
+      }
     }
   *]
 }

--
Gitblit v1.9.3