From 48ce218f5329dd9a3e2ba8851b101a5b85f8aab4 Mon Sep 17 00:00:00 2001
From: hongjli <3117313295@qq.com>
Date: 星期一, 25 九月 2023 15:54:18 +0800
Subject: [PATCH] 产能分配结果优化

---
 _Main/BL/Type_CapacityAllocationResults/StaticMethod_IterativeGeneration2.qbl |   78 +++++++++++++++++++++++++++++++++-----
 1 files changed, 67 insertions(+), 11 deletions(-)

diff --git a/_Main/BL/Type_CapacityAllocationResults/StaticMethod_IterativeGeneration2.qbl b/_Main/BL/Type_CapacityAllocationResults/StaticMethod_IterativeGeneration2.qbl
index 37b0364..3f70ca5 100644
--- a/_Main/BL/Type_CapacityAllocationResults/StaticMethod_IterativeGeneration2.qbl
+++ b/_Main/BL/Type_CapacityAllocationResults/StaticMethod_IterativeGeneration2.qbl
@@ -1,37 +1,93 @@
 Quintiq file version 2.0
 #parent: #root
 StaticMethod IterativeGeneration2 (
+  GlobalOTDTable globalOTDTable,
   ProductInStockingPoint_MP pisp,
   Date targetDate,
-  CapacityAllocationResultsRuleConfiguration carrcs,
+  CapacityAllocationResultsRuleConfigurations carrcs,
   Number numberOfLayers,
-  Real firstLevelSupply
+  NewSupply firstLevelSupply,
+  Real currentLayerDependentDemandQuantity
 )
 {
   TextBody:
   [*
     numberOfLayers++;
-    info( "灞傛暟锛�", numberOfLayers, "    鐩爣鏃堕棿锛�", targetDate.Format( "Y-M2-D2" ) );
-    
+    info( "鐩爣鏃堕棿锛�", targetDate.Format( "Y-M2-D2" ) );
+    info( pisp.Name() );
     traverse ( pisp, ProductInStockingPointInPeriodPlanning.astype( ProductInStockingPointInPeriodPlanningLeaf ), pispippl, pispippl.Start().Date() = targetDate ) {
       traverse ( pispippl, NewSupply, ns, ns.Quantity() > 0 ) {
-        info( "褰撳墠渚涘簲鐨刾isp锛�", ns.ProductInStockingPointInPeriodPlanningLeaf().ProductInStockingPoint_MP().Name() );
         if ( numberOfLayers = 1 ) {
-          firstLevelSupply := ns.Quantity();
+          firstLevelSupply := ns;
         }
         
-        if ( guard( ns.PeriodTask_MP().astype( PeriodTaskOperation ).DependentDemand( relsize ) > 0, false ) ) {
-          traverse ( ns, PeriodTask_MP.astype( PeriodTaskOperation ).DependentDemand, dd ) { 
-            CapacityAllocationResults::IterativeGeneration2( dd.ProductInStockingPointInPeriodPlanningLeaf().ProductInStockingPoint_MP(),
+        ontype( ns.PeriodTask_MP() ) {
+          PeriodTaskOperation as pto : {
+            info( "Operation鍛ㄦ湡浠诲姟..." );     
+            traverse ( ns, PeriodTask_MP.astype( PeriodTaskOperation ).DependentDemand, dd ) {
+              currentLayerDependentDemandQuantity := currentLayerDependentDemandQuantity                     * 
+                                                     ns.ProcessOutput().astype( OperationOutput ).Quantity() *
+                                                     dd.ProcessInput().astype( OperationInput ).Quantity();
+              info( "灞傛暟锛�", numberOfLayers, "    褰撳墠渚涘簲鐨刾isp锛�", ns.ProductInStockingPointInPeriodPlanningLeaf().ProductInStockingPoint_MP().Name(), "    鎬讳緵搴斿�硷細", ns.Quantity(), "    闇�瑕佷緵搴斿�硷細", currentLayerDependentDemandQuantity,
+                    "    褰撳墠闇�姹俻isp锛�", dd.ProductInStockingPointInPeriodPlanningLeaf().ProductInStockingPoint_MP().Name(), "    闇�姹傚�硷細", currentLayerDependentDemandQuantity );
+              info( "-----------------------------------------------------------------------------------------------------------------" );
+              CapacityAllocationResults::IterativeGeneration2( globalOTDTable,
+                                                               dd.ProductInStockingPointInPeriodPlanningLeaf().ProductInStockingPoint_MP(),
+                                                               targetDate,
+                                                               carrcs,
+                                                               numberOfLayers,
+                                                               firstLevelSupply,
+                                                               currentLayerDependentDemandQuantity
+                                                              );
+            }
+            carrc := select( carrcs, Elements, carrc, carrc.PanelMaterialCode() = ns.ProductInStockingPointInPeriodPlanningLeaf().ProductInStockingPoint_MP().ProductID() );
+            if ( not isnull( carrc ) ) {
+              info( "鎵惧埌闈㈡澘鐗╂枡..." );
+              globalOTDTable.CapacityAllocationResults( relnew,
+                                                        PanelBase             := pto.Operation().UnitID(),
+                                                        PanelMaterialCode     := ns.ProductInStockingPointInPeriodPlanningLeaf().ProductInStockingPoint_MP().ProductID(),
+                                                        NumberOfPanels        := currentLayerDependentDemandQuantity,
+                                                        PanelMeasurementUnit  := ns.ProductInStockingPointInPeriodPlanningLeaf().ProductInStockingPoint_MP().UnitOfMeasureName(),
+                                                        ModuleMaterialCode    := firstLevelSupply.ProductInStockingPointInPeriodPlanningLeaf().ProductInStockingPoint_MP().ProductID(),
+                                                        NumberOfModules       := firstLevelSupply.Quantity(),
+                                                        ModuleMeasurementUnit := firstLevelSupply.ProductInStockingPointInPeriodPlanningLeaf().ProductInStockingPoint_MP().UnitOfMeasureName(),
+                                                        ModuleBase            := guard( firstLevelSupply.PeriodTask_MP().astype( PeriodTaskOperation ).Operation().UnitID(), "杞﹂亾杩愯緭" ),
+                                                        Division              := carrc.Division(),
+                                                        RequirementDate       := ns.Start().Date(),
+                                                        Date                  := ns.Start().Date(),
+                                                        Description           := "",
+                                                        ID                    := OS::GenerateGUIDAsString(),
+                                                        ProductID             := ns.ProductInStockingPointInPeriodPlanningLeaf().ProductInStockingPoint_MP().ProductID(),
+                                                        StockingPointID       := "",
+                                                        UserQuantity          := currentLayerDependentDemandQuantity,
+                                                        ManufacturedDate      := Date::MinDate()
+                                                       );
+                                                        
+            }
+            info( "-----------------------------------------------------------------------------------------------------------------" );
+          }
+          
+          PeriodTaskLaneLeg as ptll : {
+            targetDependentDemand := select( ptll, DependentDemand, dd, dd.ProductInStockingPointInPeriodPlanningLeaf().ProductInStockingPoint_MP().ProductID() = ns.ProductInStockingPointInPeriodPlanningLeaf().ProductInStockingPoint_MP().ProductID() );
+            currentLayerDependentDemandQuantity := ifexpr( numberOfLayers = 1, targetDependentDemand.Quantity(), currentLayerDependentDemandQuantity );
+            info( "灞傛暟锛�", numberOfLayers,"    褰撳墠渚涘簲鐨刾isp锛�", ns.ProductInStockingPointInPeriodPlanningLeaf().ProductInStockingPoint_MP().Name(), "    鎬讳緵搴斿�硷細", ns.Quantity(), "    闇�瑕佷緵搴斿�硷細", currentLayerDependentDemandQuantity,
+                  "    褰撳墠闇�姹俻isp锛�", targetDependentDemand.ProductInStockingPointInPeriodPlanningLeaf().ProductInStockingPoint_MP().Name(), "    闇�姹傚�硷細", currentLayerDependentDemandQuantity );
+            info( "LaneLeg鍛ㄦ湡浠诲姟..." );
+            info( "-----------------------------------------------------------------------------------------------------------------" );
+            CapacityAllocationResults::IterativeGeneration2( globalOTDTable,
+                                                             targetDependentDemand.ProductInStockingPointInPeriodPlanningLeaf().ProductInStockingPoint_MP(),
                                                              targetDate,
                                                              carrcs,
                                                              numberOfLayers,
-                                                             firstLevelSupply
+                                                             firstLevelSupply,
+                                                             currentLayerDependentDemandQuantity
                                                             );
           }
         }
         
-        firstLevelSupply := 0.0;
+        if ( numberOfLayers = 1 ) {
+          firstLevelSupply := null( NewSupply );
+        }
       }
     }
   *]

--
Gitblit v1.9.3