ShuanghongS 4 هفته پیش
والد
کامیت
06b569655c
1فایلهای تغییر یافته به همراه41 افزوده شده و 46 حذف شده
  1. 41 46
      service/destination_delivery.class.php

+ 41 - 46
service/destination_delivery.class.php

@@ -1408,58 +1408,53 @@ class destination_delivery {
                                                 OR 
                                                 recommended_delivery_to_date is null)";
 
-        $sql = "with oo as(
-                select  oo.serial_no,
-                    oo.h_bol,
-                    oo.m_bol,
-                    oo.service,
-                    oo.po_no,
-                    oo.transport_mode,
-                    oo.qty,
-                    oo.qty_uom,
-                    oo.piece_count,
-                    oo.cbm,
-                    oo.vessel,
-                    oo.voyage,
-                    oo.carrier,
-                    oo.fport_of_loading_un,
-                    oo.mport_of_discharge_un,
-                    oo.eta,
-                    oo.ata,
-                    oo.etd,
-                    oo.atd,
-                    oo.shipper,
-                    oo.consignee_id,
-                    oo.consignee,
-                    oo.booking_no,
-                    oo.agent,
-                    oo.order_from
-                from public.kln_ocean oo ". $sqlWhere ."
-            ),
-            -- 2. 预解析station字段
-            station_list AS (
-                SELECT 
-                    serial_no, 
-                    country, 
-                    kln_pic,
-                    booking_window,
-                    booking_window_date_start,
-                    booking_window_date_end,
-                    recommended_delivery,
-                    unnest(string_to_array(station, ',')) as station_code
-                FROM public.kln_destination_delivery_config
-            ),
+        $sql = "with 
             ooc as (
                 select oo.*,
                     dc.serial_no as dc_serial_no,
                     dc.country as dc_country,
                     dc.kln_pic as dc_kln_pic,
                     dc.recommended_delivery as dc_recommended_delivery
-                from station_list dc
-                    Inner Join oo
-                        on oo.agent = dc.station_code
-                    where  1=1 and 
-                        case when dc.booking_window = 'Restrictions_ETD_ATD' and COALESCE(dc.booking_window_date_start,'')<>'' and 	COALESCE(dc.booking_window_date_end,'')<>''
+                from (select oo.serial_no,
+                            oo.h_bol,
+                            oo.m_bol,
+                            oo.service,
+                            oo.po_no,
+                            oo.transport_mode,
+                            oo.qty,
+                            oo.qty_uom,
+                            oo.piece_count,
+                            oo.cbm,
+                            oo.vessel,
+                            oo.voyage,
+                            oo.carrier,
+                            oo.fport_of_loading_un,
+                            oo.mport_of_discharge_un,
+                            oo.eta,
+                            oo.ata,
+                            oo.etd,
+                            oo.atd,
+                            oo.shipper,
+                            oo.consignee_id,
+                            oo.consignee,
+                            oo.booking_no,
+                            oo.agent,
+                            oo.order_from 
+                        from public.kln_ocean oo ". $sqlWhere ."
+                    ) oo
+                    INNER JOIN (
+                        SELECT 
+                            serial_no, 
+                            country, 
+                            kln_pic,
+                            booking_window,
+                            booking_window_date_start,
+                            booking_window_date_end,
+                            recommended_delivery,
+                            unnest(string_to_array(station, ',')) as station_code
+                        FROM public.kln_destination_delivery_config 
+                    )dc on oo.agent = dc.station_code
+                    where case when dc.booking_window = 'Restrictions_ETD_ATD' and COALESCE(dc.booking_window_date_start,'')<>'' and 	COALESCE(dc.booking_window_date_end,'')<>''
                                 then COALESCE(atd, etd) >= (NOW() - (dc.booking_window_date_start ||' days')::INTERVAL)::date and  COALESCE(atd, etd) <= (NOW() + (dc.booking_window_date_end ||' days')::INTERVAL)::date
                             when dc.booking_window = 'Restrictions_ETA_ATA' and COALESCE(dc.booking_window_date_start,'')<>'' and 	COALESCE(dc.booking_window_date_end,'')<>''
                                 then COALESCE(ata, eta) >= (NOW() - (dc.booking_window_date_start ||' days')::INTERVAL)::date and  COALESCE(ata, eta) <= (NOW() + (dc.booking_window_date_end ||' days')::INTERVAL)::date