ShuanghongS 1 ماه پیش
والد
کامیت
577f0d4245
1فایلهای تغییر یافته به همراه39 افزوده شده و 16 حذف شده
  1. 39 16
      utils/common.class.php

+ 39 - 16
utils/common.class.php

@@ -4783,10 +4783,10 @@ class common {
     {
         $FIELD_TABLE_MAP = [
         // 主表 oo (kln_ocean)
-        'Status'                     => ['oo'],
-        'Transportation Mode'        => ['oo'],
-        'Voyage/Flight'              => ['oo'],
-        'Vessel/Airline'             => ['oo'],
+        'Status'                     => ['oo','new_status'],
+        'Transportation Mode'        => ['oo','new_transport_mode_extend'],
+        'Voyage/Flight'              => ['oo','_voyage'],
+        'Vessel/Airline'             => ['oo','_vessel'],
         'Container No. (House)'      => ['oo'],
         'Shipment PO No.'            => ['oo', 'oe'], // 可能来自 oe.import_po_no
 
@@ -4852,6 +4852,11 @@ class common {
         $needOceanExtend   = in_array('oe', $requiredTables) || in_array('Last Mile Delivery', $filterFieldAliases);
         $needCO2           = in_array('co2_r', $requiredTables);
 
+        $needNewStatus     = in_array('new_status', $requiredTables);
+        $needMode     = in_array('new_transport_mode_extend', $requiredTables);
+        $needVoyage     = in_array('_voyage', $requiredTables);
+        $needVessel     = in_array('_vessel', $requiredTables);
+
         //在根据层级分配是否需要字段
         if($level == 'Container Level'){
             $needContainerData = true;
@@ -4859,41 +4864,59 @@ class common {
             $needItemData = true;
             $needContainerData = true;
         }
-
-        // --- CTE: oo (主表) ---
-        $sql = "
-        with oo as (
-            SELECT CASE
+        
+        $needNewStatusSQL = " ";
+        if ($needNewStatus) {
+            $needNewStatusSQL = "CASE
                         WHEN (m_iffcpu is null and m_iffrec is null and m_iffdep is null and m_iffarr is null and m_iffdel is null) THEN 'Created'::text
                         WHEN ((m_iffcpu is not null or m_iffrec is not null) and m_iffdep is null and m_iffarr is null and m_iffdel is null) THEN 'Cargo Received'::text
                         WHEN (m_iffdep is not null and m_iffarr is null and m_iffdel is null) THEN 'Departed'::text
                         WHEN (m_iffarr is not null and m_iffdel is null) THEN 'Arrived'::text
                         WHEN (m_iffdel is not null) THEN 'Completed'::text
                         ELSE 'Created'
-                    END AS new_status,
-                    CASE
+                    END AS new_status, ";
+        }
+
+        $needModeSQL = " ";
+        if ($needMode) {
+            $needModeSQL = "CASE
                         WHEN transport_mode_extend = 'sea' THEN 'Ocean Freight'::text
                         WHEN transport_mode_extend = 'air' THEN 'Air Freight'::text
                         WHEN transport_mode_extend = 'rail' THEN 'Rail Freight'::text
                         WHEN transport_mode_extend = 'road' THEN 'Road Freight'::text
                         ELSE ''
-                    END AS new_transport_mode_extend,
-                    CASE
+                    END AS new_transport_mode_extend, ";
+        }
+
+        $needVoyageSQL = " ";
+        if ($needVoyage) {
+            $needVoyageSQL = "CASE
                         WHEN oo.voyage IS NOT DISTINCT FROM oo.f_voyage THEN oo.voyage
                         WHEN NULLIF(TRIM(oo.voyage), '') IS NOT NULL AND NULLIF(TRIM(oo.f_voyage), '') IS NOT NULL
                             THEN oo.f_voyage || '/' || oo.voyage
                         WHEN NULLIF(TRIM(oo.voyage), '') IS NOT NULL
                             THEN oo.voyage
                         ELSE oo.f_voyage
-                    END AS _voyage,
-                    CASE
+                    END AS _voyage, ";
+        }
+
+        $needVesselSQL = " ";
+        if ($needVessel) {
+            $needVesselSQL = "CASE
                         WHEN oo.vessel IS NOT DISTINCT FROM oo.f_vessel THEN oo.vessel
                         WHEN NULLIF(TRIM(oo.vessel), '') IS NOT NULL AND NULLIF(TRIM(oo.f_vessel), '') IS NOT NULL
                             THEN oo.f_vessel || '/' || oo.vessel
                         WHEN NULLIF(TRIM(oo.vessel), '') IS NOT NULL
                             THEN oo.vessel
                         ELSE oo.f_vessel
-                    END AS _vessel, * FROM public.kln_ocean oo  <{klnOceanSearchKLN}>
+                    END AS _vessel, ";
+        }
+
+
+        // --- CTE: oo (主表) ---
+        $sql = "
+        with oo as (
+            SELECT {$needNewStatusSQL} {$needModeSQL} {$needVoyageSQL} {$needVesselSQL}  * FROM public.kln_ocean oo  <{klnOceanSearchKLN}>
         )";
 
         // 如果不需要容器/项数据,直接 COUNT