From f1de76007e7834e17d87712e3342efd84876c200 Mon Sep 17 00:00:00 2001
From: lihongji <3117313295@qq.com>
Date: 星期六, 12 十月 2024 16:32:16 +0800
Subject: [PATCH] Merge remote-tracking branch 'origin/dev' into dev

---
 _Main/BL/Type_DispatchShiftPlan/StaticMethod_Dispatch.qbl |   50 +++++++++++++++++++++++++++++++++++---------------
 1 files changed, 35 insertions(+), 15 deletions(-)

diff --git a/_Main/BL/Type_DispatchShiftPlan/StaticMethod_Dispatch.qbl b/_Main/BL/Type_DispatchShiftPlan/StaticMethod_Dispatch.qbl
index 35bca5a..5d69146 100644
--- a/_Main/BL/Type_DispatchShiftPlan/StaticMethod_Dispatch.qbl
+++ b/_Main/BL/Type_DispatchShiftPlan/StaticMethod_Dispatch.qbl
@@ -2,19 +2,27 @@
 #parent: #root
 StaticMethod Dispatch (
   const MacroPlan macroPlan,
-  RecycleBin owner,
+  Archive owner,
   String versionFlag
 )
 {
   TextBody:
   [*
     // Akari Aug-21-2024 (created)
-    owner.DispatchShiftPlan( relflush );
+    // owner.DispatchShiftPlan( relflush );
     // owner.RB_DispatchShiftPlanBroker().Source().FlatQuery( "truncate table A_DispatchShiftPlan" );
+    
+    dispatchShiftPlans := selectset( owner,DispatchShiftPlan,dispatchShiftPlan,true );
+    dispatchShiftPlanIndexTree := NamedValueTree::Create();
+    for( i := 0 ; i < dispatchShiftPlans.Size() ; i++){
+      dispatchShiftPlan := dispatchShiftPlans.Element( i );
+      dispatchShiftPlanHandle := dispatchShiftPlanIndexTree.GetHandle( dispatchShiftPlan.FactoryName() + dispatchShiftPlan.ProductLine() + dispatchShiftPlan.ShiftDate().AsQUILL() );
+      dispatchShiftPlanIndexTree.Root().AddChild( dispatchShiftPlanHandle,i );
+    }
     
     now := DateTime::Now();
     macroPlanName := macroPlan.MDSMacroPlan().Description();
-    traverse( macroPlan,Unit.UnitPeriod.astype( UnitPeriodTime ).ShiftPlan,shiftPlan ){
+    traverse( macroPlan,Unit.UnitPeriod.astype( UnitPeriodTime ).ShiftPlan,shiftPlan ,shiftPlan.UnitPeriodTime().Period_MP().StartDate() >= macroPlan.StartOfPlanning().Date()){
        factory := shiftPlan.UnitPeriodTime().Unit();
        while( factory.HasParent() ){
          temp1 := factory;
@@ -23,19 +31,31 @@
            factory := temp1;
          }
        }
-      
-       owner.DispatchShiftPlan( relnew,ID := OS:: GenerateGUIDAsString(),
-                                ProductLine := shiftPlan.UnitPeriodTime().Unit().ID(),
-                                ShiftDate := shiftPlan.UnitPeriodTime().Period_MP().StartDate(),
-                                Tips := shiftPlan.Remark(),
-                                VersionName := macroPlanName,
-                                VersionFlag := versionFlag,
-                                FactoryName := factory.ID(),
-                                InterfaceTime := now
-                                );
-                                
+       productLine :=  shiftPlan.UnitPeriodTime().Unit().ID();
+       shiftDate := shiftPlan.UnitPeriodTime().Period_MP().StartDate();
+       factoryName := factory.ID();
+       
+       dispatchShiftPlanHandle := dispatchShiftPlanIndexTree.GetHandle( factoryName + productLine + shiftDate.AsQUILL() );
+       dispatchShiftPlanIndex := guard( dispatchShiftPlanIndexTree.Root().Child( dispatchShiftPlanHandle ),null( NamedValue ));
+       if( not isnull( dispatchShiftPlanIndex )){
+         dispatchShiftPlan := dispatchShiftPlans.Element( dispatchShiftPlanIndex.GetValueAsNumber() );
+         dispatchShiftPlan.Tips( shiftPlan.Remark() );
+         dispatchShiftPlan.VersionName( macroPlanName );
+         dispatchShiftPlan.VersionFlag( versionFlag );
+         dispatchShiftPlan.InterfaceTime( now );
+       }else{
+         owner.DispatchShiftPlan( relnew,ID := OS:: GenerateGUIDAsString(),
+                                  ProductLine := productLine,
+                                  FactoryName := factory.ID(),
+                                  
+                                  ShiftDate := shiftDate,
+                                  Tips := shiftPlan.Remark(),
+                                  VersionName := macroPlanName,
+                                  VersionFlag := versionFlag,
+                                  InterfaceTime := now );
+       }
     }
     
-    owner.RB_DispatchShiftPlanBroker().AsyncExecute();
+    // owner.RB_DispatchShiftPlanBroker().AsyncExecute();
   *]
 }

--
Gitblit v1.9.3