ShuanghongS 5 月之前
父節點
當前提交
97c42b46d2
共有 4 個文件被更改,包括 200 次插入3 次删除
  1. 1 0
      service/robot.class.php
  2. 29 3
      service/tools.class.php
  3. 153 0
      utils/common.class.php
  4. 17 0
      utils/utils.class.php

+ 1 - 0
service/robot.class.php

@@ -677,6 +677,7 @@ class robot{
             $sqlWhere = '  ' . common::searchExtendHand_KLN("ocean", $_SESSION["ONLINE_USER"]);
             $sql = str_replace('<{ExtendHand_KLN}>', $sqlWhere, $sql);
             $rss = common::excuteListSql($sql);
+            $rss = common::dealDataWithFaq($faq,$rss);
             
             //XLSXWriter输出
             $writer = new XLSXWriter();

+ 29 - 3
service/tools.class.php

@@ -1778,8 +1778,22 @@ class tools {
         if (!empty($_REQUEST['info_type']) && $_REQUEST['info_type'] == 'true'){
             $sql_where .= " and ni.is_send_message is null";
         }
+        if (!empty($_REQUEST['info_type']) && $_REQUEST['info_type'] == 'false'){
+            $sql_where .= " and ni.is_send_message is not null";
+        }
         $more_param = common::getInNotInSqlForSearch($notifiation_type);
 
+        $cp = common::check_input($_REQUEST['cp']); //current_page
+        $ps = common::check_input($_REQUEST['ps']); //ps
+        if (empty($ps)){
+            $ps = 20;
+        }
+        if (empty($cp)){
+            $cp = 1;
+        }
+        //$limit_param = " limit " . $ps . " offset " . ($cp - 1) * $ps;
+        $limit_param = " ";
+
         $sql = "WITH base_data AS (
                     SELECT 
                         id,
@@ -1896,7 +1910,7 @@ class tools {
                         arrival_count,
                         etd_count,
                         eta_count
-                    FROM daily_weekly_summary order by insert_date desc
+                    FROM daily_weekly_summary order by insert_date desc ".$limit_param."
                 )
                 select *
                  from  (select ni.*,
@@ -1943,7 +1957,7 @@ class tools {
 
                     ccc.order_from,ccc.h_bol,ccc.transport_mode,ccc.m_bol,eee.*
                 from public.kln_notifiation_info ni
-                        inner join LATERAL (select oo.h_bol,oo.transport_mode,oo.order_from,oo.m_bol 
+                        left join LATERAL (select oo.h_bol,oo.transport_mode,oo.order_from,oo.m_bol 
                             from public.kln_ocean oo 
                             where oo.serial_no = ni.serial_no limit 1) ccc on true
                         inner join LATERAL (select id,total_count,departure_count,arrival_count,etd_count,eta_count
@@ -2004,6 +2018,18 @@ class tools {
         }
         
         $more_param = common::getInNotInSqlForSearch($notifiation_type);
+
+        $cp = common::check_input($_REQUEST['cp']); //current_page
+        $ps = common::check_input($_REQUEST['ps']); //ps
+        if (empty($ps)){
+            $ps = 20;
+        }
+        if (empty($cp)){
+            $cp = 1;
+        }
+        //$limit_param = " limit " . $ps . " offset " . ($cp - 1) * $ps;
+        $limit_param = " ";
+
         $sql = "select *
                  from  (select ni.*,
                  ROW_NUMBER() OVER (
@@ -2066,7 +2092,7 @@ class tools {
                         and ni.insert_date > NOW() - INTERVAL '1 year' 
                         and lower(ni.notifiation_type) in ($more_param)
                     ".$sql_where." and ni.notifications_method = true order by ni.insert_date desc) aa 
-                WHERE rn = 1 ORDER BY insert_date DESC";
+                WHERE rn = 1 ORDER BY insert_date DESC " .$limit_param;
         error_log($sql);
 
         $retData = common::excuteListSql($sql);

+ 153 - 0
utils/common.class.php

@@ -2665,6 +2665,56 @@ class common {
             $reference = utils::replacementsFixed($total,$reference,array("Download_Complete"));
         }
 
+         if($fixedChat["fixed_faq"] == "Show shipments delayed in the last 30 days."){
+            $reference = $fixedChat["answer_style"];
+            $sql = $fixedChat["fixed_sql"];
+            if($_POST['is_demo'] == 't'){
+                $sql = utils::getDmoeSqlForAi($fixedChat["fixed_faq"]);
+            }
+            $sqlArr = explode(";", $sql);
+            $sqlCount = $sqlArr[0];
+            //拼接用户权限
+            $sqlWhere = '  ' . common::searchExtendHand_KLN("ocean", $_SESSION["ONLINE_USER"]);
+            $sqlCount = str_replace('<{ExtendHand_KLN}>', $sqlWhere, $sqlCount);
+            error_log("countSql:".$sqlCount);
+            $count = common::excuteOneSql($sqlCount);
+            //替换总数
+            $total = array("total" =>$count);
+            $reference = utils::replacementsFixed($total,$reference,array("total"));
+
+            $sqlDetail = $sqlArr[1];
+            //拼接用户权限
+            $sqlDetail = str_replace('<{ExtendHand_KLN}>', $sqlWhere, $sqlDetail);
+            error_log("detail:".$sqlDetail);
+            $data = common::excuteListSql($sqlDetail);
+
+            $refer_data =array();    
+            foreach($data as $key =>$d){
+                $temp = array();
+                $temp['h_bol'] = $d['h_bol'];
+                $temp['place_of_receipt_exp'] = $d['place_of_receipt_exp'];
+                $temp['place_of_delivery_exp'] = $d['place_of_delivery_exp'];
+                $temp['log_type'] = $d['log_type'];
+                $temp['planned_time'] = common::dealDateTime($d['event_old_date'],$d['event_old_time'],'',"m/d/Y");
+                $temp['actual_time'] = common::dealDateTime($d['event_date'],$d['event_time'],'',"m/d/Y");
+                $temp['duration'] = $d['duration'] <= 0 ? '< 1 Days' : $d['duration'].' Days';
+
+                $serial_no = common::deCode($d['serial_no'], 'E');
+                $httpUrl = SERVER_Vue_PAHT."tracking/detail?a=".$serial_no."&_schemas=".$d["order_from"];
+                $temp['action'] = '<a href="'.$httpUrl.'" target="_blank">Details</a> <a href="'.SERVER_Vue_PAHT.'SystemSettings" target="_blank">Notify</a>';
+                $refer_data[] = $temp;
+            }
+            $reference = utils::replacementsFixedMultilineForFixed($refer_data,$reference,$fixedChat['table_format_tr']);
+
+            $total = array("Download_Complete" =>"");
+            if ($count > 10){
+                $httpUrl = SERVER_PAHT."main_new_version.php?action=robot_chat&operate=download&faq=". common::deCode($fixedChat["fixed_faq"]);
+                $download_complete = '- Due to page limitations, only the first 10 records are currently displayed. If you need the complete data, please click the <a href="'.$httpUrl.'" target="_blank">Download Complete</a> button.';
+                $total = array("Download_Complete" =>$download_complete);
+            }
+            $reference = utils::replacementsFixed($total,$reference,array("Download_Complete"));
+        }
+
         if($fixedChat["fixed_faq"] == "List shipments with milestone updates in the last 7 days."){
             $reference = $fixedChat["answer_style"];
             $sql = $fixedChat["fixed_sql"];
@@ -3108,6 +3158,20 @@ class common {
             $columns[] = array("display_name" => "Cargo Type","database_column_name"=>"cargo_type");
         }
 
+        if($faq == "Show shipments delayed in the last 30 days."){
+            // | HBL/HAWB No. | Origin           | Destination      | Latest Milestone | ETA       | Cargo Type    | Actions          |
+            // |--------------|------------------|------------------|------------------|-----------|---------------|------------------|
+            // | {{h_bol}} | {{place_of_receipt_exp}} | {{place_of_delivery_exp}} | {{description}} | {{eta}} | {{cargo_type}} | {{action}} |
+            $columns = array();
+            $columns[] = array("display_name" => "HBL/HAWB No.","database_column_name"=>"h_bol");
+            $columns[] = array("display_name" => "Origin","database_column_name"=>"place_of_receipt_exp");
+            $columns[] = array("display_name" => "Destination","database_column_name"=>"place_of_delivery_exp");
+            $columns[] = array("display_name" => "Delayed Type","database_column_name"=>"log_type");
+            $columns[] = array("display_name" => "Planned Date","database_column_name"=>"planned_time");
+            $columns[] = array("display_name" => "Actual/Revised Date","database_column_name"=>"actual_time");
+            $columns[] = array("display_name" => "Delay Duration","database_column_name"=>"duration");
+        }
+
         if($faq == "List shipments with milestone updates in the last 7 days."){
             // | HBL/HAWB No. | Latest Milestone           | Time                         | Location                  | Actions          |
             // |--------------|----------------------------|------------------------------|---------------------------|------------------|
@@ -3172,5 +3236,94 @@ class common {
         }
         return $columns;
     }
+
+    /**
+     * 处理数据问题
+    */
+    public static function dealDataWithFaq($faq,$data){
+        $refer_data  = array();
+        //返回格式相同的放到一起处理
+        if($faq == "Shipments arriving in the next 7 days."){
+            $refer_data = $data;
+        }
+
+        if($faq == "Show shipments delayed in the last 30 days."){
+            foreach($data as $key =>$d){
+                $temp = array();
+                $temp['h_bol'] = $d['h_bol'];
+                $temp['place_of_receipt_exp'] = $d['place_of_receipt_exp'];
+                $temp['place_of_delivery_exp'] = $d['place_of_delivery_exp'];
+                $temp['log_type'] = $d['log_type'];
+                $temp['planned_time'] = common::dealDateTime($d['event_old_date'],$d['event_old_time'],'',"m/d/Y");
+                $temp['actual_time'] = common::dealDateTime($d['event_date'],$d['event_time'],'',"m/d/Y");
+                $temp['duration'] = $d['duration'] <= 0 ? '< 1 Days' : $d['duration'].' Days';
+                $refer_data[] = $temp;
+            }
+        }
+
+        if($faq == "List shipments with milestone updates in the last 7 days."){
+           foreach($data as $key =>$d){
+                $temp = array();
+                $temp['h_bol'] = $d['h_bol'];
+                $temp['description'] = $d['description'];
+                $temp['update_date'] = common::dealDateTime($d['update_date'],"",$d['timezone'],"m/d/Y H:i:s");
+                $temp['locations'] = $d['locations'];
+                $refer_data[] = $temp;
+            }
+        }
+
+        if($faq == "What is the current status of my active shipments?"){
+           foreach($data as $key => $val){
+                $temp = array();
+                $temp['h_bol'] = $d['h_bol'];
+                $temp['place_of_receipt_exp'] = $d['place_of_receipt_exp'];
+                $temp['place_of_delivery_exp'] = $d['place_of_delivery_exp'];
+                $temp['description'] = $d['description'];
+                $temp['time'] = common::dealDateTime($d['act_date'],$d['act_time'],$d['timezone'],"m/d/Y");
+                $temp['locations'] = $d['locations'];
+                $temp['cargo_type'] = $d['cargo_type'];
+                $refer_data[] = $temp;
+            }
+        }
+
+        if($faq == "List shipments with container status updates in the last 7 days."){
+            foreach($data as $key =>$d){
+                $temp = array();
+                $temp['container_no'] = $d['container_no'];
+                $temp['description'] = $d['description'];
+                $temp['time'] = common::dealDateTime($d['eventdate'],$d['eventtime'],$d['timezone'],"m/d/Y");
+                $temp['uncity'] = $d['uncity'];
+                $refer_data[] = $temp;
+            }
+        }
+
+        if($faq == "Today's shipments summary."){
+            foreach($data as $key =>$d){
+                $temp = array();
+                $temp['h_bol'] = $d['h_bol'];
+                $temp['transport_mode'] = $d['transport_mode'];
+                $temp['place_of_receipt_exp'] = $d['place_of_receipt_exp'];
+                $temp['place_of_delivery_exp'] = $d['place_of_delivery_exp'];
+                $temp['action_type'] = $d['action_type'];
+                $temp['time'] = common::dealDateTime($d['act_date'],$d['act_time'],$d['timezone'],"m/d/Y");
+                $temp['locations'] = $d['locations'];
+                $refer_data[] = $temp;
+            }
+        }
+
+        if($faq == "Sort my active shipments by earliest arrival date."){
+            foreach($data as $key =>$d){
+                $temp = array();
+                $temp['eta'] = $d['eta'];
+                $temp['h_bol'] = $d['h_bol'];
+                $temp['transport_mode'] = $d['transport_mode'];
+                $temp['place_of_receipt_exp'] = $d['place_of_receipt_exp'];
+                $temp['place_of_delivery_exp'] = $d['place_of_delivery_exp'];
+                $temp['day_to_arr'] = $d['day_to_arr'];
+                $refer_data[] = $temp;
+            }
+        }
+        return $refer_data;
+    }
 }
 ?>

+ 17 - 0
utils/utils.class.php

@@ -1094,6 +1094,23 @@ class utils {
 
     public static function getDmoeSqlForAi($type){
         $data= array();
+        $data["Show shipments delayed in the last 30 days."] = "select count(*)
+            from public.kln_record kr
+                inner join LATERAL (select h_bol from public.kln_ocean oo where oo.serial_no = kr.serial_no and <{ExtendHand_KLN}>  ) m on true
+            where kr.log_type like '%Delay' 
+            and kr.log_time >= CURRENT_DATE - INTERVAL '30 day'	
+            and kr.event_date is not null and kr.event_old_date is not null
+            and (kr.event_date||' '||COALESCE(kr.event_time,'00:00'))::timestamp >= (kr.event_old_date||' '||COALESCE(kr.event_old_time,'00:00'))::timestamp;select oo.h_bol,oo.place_of_receipt_exp,oo.place_of_delivery_exp,oo.serial_no,oo.order_from,
+            kr.log_type,kr.event_old_date, kr.event_old_time,kr.event_date, kr.event_time,
+                (EXTRACT(DAY FROM ((event_date||' '||COALESCE(event_time,'00:00'))::timestamp - (event_old_date||' '||COALESCE(event_old_time,'00:00'))::timestamp))) as duration
+            from public.kln_record kr
+                inner join LATERAL (select h_bol, place_of_receipt_exp, place_of_delivery_exp,serial_no,order_from
+                            from public.kln_ocean oo where oo.serial_no = kr.serial_no and <{ExtendHand_KLN}>  ) oo on true
+            where kr.log_type like '%Delay' 
+            and kr.log_time >= CURRENT_DATE - INTERVAL '30 day'	
+            and kr.event_date is not null and kr.event_old_date is not null
+            and (kr.event_date||' '||COALESCE(kr.event_time,'00:00'))::timestamp >= (kr.event_old_date||' '||COALESCE(kr.event_old_time,'00:00'))::timestamp
+            order by kr.log_time  desc limit 10";
         $data["Shipments arriving in the next 7 days."] =  "select count(*)
          from (
          	SELECT  oo.serial_no,h_bol, place_of_receipt_exp, place_of_delivery_exp,m.description,eta,order_from, o.cargo_type