|
@@ -4783,10 +4783,10 @@ class common {
|
|
|
{
|
|
{
|
|
|
$FIELD_TABLE_MAP = [
|
|
$FIELD_TABLE_MAP = [
|
|
|
// 主表 oo (kln_ocean)
|
|
// 主表 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'],
|
|
'Container No. (House)' => ['oo'],
|
|
|
'Shipment PO No.' => ['oo', 'oe'], // 可能来自 oe.import_po_no
|
|
'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);
|
|
$needOceanExtend = in_array('oe', $requiredTables) || in_array('Last Mile Delivery', $filterFieldAliases);
|
|
|
$needCO2 = in_array('co2_r', $requiredTables);
|
|
$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'){
|
|
if($level == 'Container Level'){
|
|
|
$needContainerData = true;
|
|
$needContainerData = true;
|
|
@@ -4859,41 +4864,59 @@ class common {
|
|
|
$needItemData = true;
|
|
$needItemData = true;
|
|
|
$needContainerData = 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 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_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_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_iffarr is not null and m_iffdel is null) THEN 'Arrived'::text
|
|
|
WHEN (m_iffdel is not null) THEN 'Completed'::text
|
|
WHEN (m_iffdel is not null) THEN 'Completed'::text
|
|
|
ELSE 'Created'
|
|
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 = 'sea' THEN 'Ocean Freight'::text
|
|
|
WHEN transport_mode_extend = 'air' THEN 'Air Freight'::text
|
|
WHEN transport_mode_extend = 'air' THEN 'Air Freight'::text
|
|
|
WHEN transport_mode_extend = 'rail' THEN 'Rail Freight'::text
|
|
WHEN transport_mode_extend = 'rail' THEN 'Rail Freight'::text
|
|
|
WHEN transport_mode_extend = 'road' THEN 'Road Freight'::text
|
|
WHEN transport_mode_extend = 'road' THEN 'Road Freight'::text
|
|
|
ELSE ''
|
|
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 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
|
|
WHEN NULLIF(TRIM(oo.voyage), '') IS NOT NULL AND NULLIF(TRIM(oo.f_voyage), '') IS NOT NULL
|
|
|
THEN oo.f_voyage || '/' || oo.voyage
|
|
THEN oo.f_voyage || '/' || oo.voyage
|
|
|
WHEN NULLIF(TRIM(oo.voyage), '') IS NOT NULL
|
|
WHEN NULLIF(TRIM(oo.voyage), '') IS NOT NULL
|
|
|
THEN oo.voyage
|
|
THEN oo.voyage
|
|
|
ELSE oo.f_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 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
|
|
WHEN NULLIF(TRIM(oo.vessel), '') IS NOT NULL AND NULLIF(TRIM(oo.f_vessel), '') IS NOT NULL
|
|
|
THEN oo.f_vessel || '/' || oo.vessel
|
|
THEN oo.f_vessel || '/' || oo.vessel
|
|
|
WHEN NULLIF(TRIM(oo.vessel), '') IS NOT NULL
|
|
WHEN NULLIF(TRIM(oo.vessel), '') IS NOT NULL
|
|
|
THEN oo.vessel
|
|
THEN oo.vessel
|
|
|
ELSE oo.f_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
|
|
// 如果不需要容器/项数据,直接 COUNT
|