ShuanghongS 6 місяців тому
батько
коміт
c2a2947ea9
3 змінених файлів з 120 додано та 46 видалено
  1. 5 3
      main_new_version.php
  2. 33 2
      service/robot.class.php
  3. 82 41
      utils/utils.class.php

+ 5 - 3
main_new_version.php

@@ -104,13 +104,15 @@ switch ($action) {
             $systemManagement = array("index"=>"$index","label"=>"System Management","icon"=>"icon_system__management_fill_b","type"=>"list"); 
             $children  = array(); 
             $children[] = array("index" =>$index.'-1',"label" =>"System Message","path"=>"/system-message");
-            $children[] = array("index" =>$index.'-2',"label" =>"System Settings","path"=>"/SystemSettings");  
+            $children[] = array("index" =>$index.'-2',"label" =>"System Settings","path"=>"/SystemSettings"); 
+            $children[] = array("index" =>$index.'-3',"label" =>"Chat Log","path"=>"/chat-log");
+            $children[] = array("index" =>$index.'-4',"label" =>"AI API Log","path"=>"/ai-api-log");  
             //只有chud的账户可以看日志记录
             if(strtolower(_getLoginName()) == "chud" 
                 || strtolower(_getLoginName()) == strtolower("IT.Andywu") 
                 || strtolower(_getLoginName()) == "ra.admin"){
-                    $children[] = array("index" =>$index.'-3',"label" =>"Operation Log","path"=>"/Operationlog");
-                    $children[] = array("index" =>$index.'-4',"label" =>"Prompt Configuration","path"=>"/PromptConfiguration");  
+                    $children[] = array("index" =>$index.'-5',"label" =>"Operation Log","path"=>"/Operationlog");
+                    $children[] = array("index" =>$index.'-6',"label" =>"Prompt Configuration","path"=>"/PromptConfiguration");  
             }
             $systemManagement["children"] = $children;
             if (!empty($children)){

+ 33 - 2
service/robot.class.php

@@ -595,7 +595,7 @@ class robot{
             $fixed_faq = common::check_input($_POST['fixed_faq']);
             //claude  deepseek  根據賬號信息判断
             $model = common::getUserCountry();
-            $model = "deepseek"; 
+            //$model = "deepseek"; 
 
             //获取自然序列
             $sequence = common::getChatAiSequence();
@@ -671,8 +671,39 @@ class robot{
         if($operate == "download"){
             $faq = common::deCode($_GET['faq'], 'D');
             $sql = common::getFaqSql($faq);
-            $column = common::getFaqColumnSql($faq);
+            $columns = common::getFaqColumnSql($faq);
+            $rss = common::excuteListSql($sql);
             
+            //XLSXWriter输出
+            // $writer = new XLSXWriter();
+            // $sheetName = date('mdy');
+
+            // foreach ($rss as $k => $v) {
+            //     $column = array();
+            //     $value_temp = array();
+            //     foreach($columns as $col){
+            //         $value_temp[] = $v[$col['database_column_name']];
+            //         if($k == 0){
+            //             $column[] =  $col['display_name'];
+            //         }
+            //     }
+            //     if($k == 0){
+            //         //输出column
+            //         $writer->writeSheetRow($sheetName, $column);
+            //     }
+            //     $writer->writeSheetRow($sheetName, $value_temp, []);
+            // }
+            // $outfile = "Complete Data_" .date("Y-m-d H:i:s") . ".xlsx";
+            // if (file_exists($outfile)) {
+            //     $outfile = "Complete Data_" .date("Y-m-d H:i:s") . "_". md5(uniqid(rand(), true)) . ".xlsx";
+            // }
+            // ob_end_clean();
+            // header('Content-Type: application/vnd.ms-excel');
+            // header("Expires: 0");
+            // header("Cache-Control: must-revalidate, post-check=0, pre-check=0");
+            // header("Pragma: can-cache");
+            // header('Content-Disposition:attachment;filename="' . $outfile . '"');
+            // $writer->writetostdout();
         }
 
 

+ 82 - 41
utils/utils.class.php

@@ -1112,7 +1112,7 @@ class utils {
          					and a.serial_no = oo.serial_no
          					and a.act_date is not null 
          				order by s.sno desc limit 1) m on true
-         	WHERE  <{ExtendHand_KLN}> and  oo.transport_mode = 'sea' and order_from = 'public' and m.code <> ''  limit 20
+         	WHERE  <{ExtendHand_KLN}> and  oo.transport_mode = 'sea' and order_from = 'public' and m.code <> ''  limit 10
          ) t;select serial_no,h_bol,place_of_receipt_exp,place_of_delivery_exp,description,eta,order_from,cargo_type 
          from (
          	SELECT  oo.serial_no,h_bol, place_of_receipt_exp, place_of_delivery_exp,m.description,eta,order_from, o.cargo_type
@@ -1131,47 +1131,88 @@ class utils {
          ) t order by eta";
 
         $data["List shipments with milestone updates in the last 7 days."] =  "select count(*)
-                            from (
-                            select serial_no,order_from,h_bol,description,to_char(update_date,'Mon DD') as update_date_format,update_date,
-                                    COALESCE(jsonb_data->>'milestone','')::jsonb->>'timezone' as timezone,
-                                    COALESCE(jsonb_data->>'milestone','')::jsonb->>'locations' as locations 
-                            from (SELECT oo.serial_no,oo.order_from,oo.h_bol,s.description,a.update_date,public.getTimeAndLocationForKln(oo.serial_no,a.code,''::text)::jsonb as jsonb_data
-                                    from public.ocean_milestone a 
-                                        inner join public.customer_service_milestone_sno s on a.code = s.code 
-                                        inner join public.kln_ocean oo on oo.serial_no = a.serial_no 
-                                    where s.type = 'sea' 
-                                        and a.act_date is not null
-                                        and a.update_date is not null
-                                        and a.update_date > '2025-04-06') po
-                            )t;select serial_no,order_from,h_bol, description,update_date_format,update_date,timezone,locations
-                            from (
-                            select serial_no,order_from,h_bol,description,to_char(update_date,'Mon DD') as update_date_format,update_date,
-                                    COALESCE(jsonb_data->>'milestone','')::jsonb->>'timezone' as timezone,
-                                    COALESCE(jsonb_data->>'milestone','')::jsonb->>'locations' as locations 
-                            from (SELECT oo.serial_no,oo.order_from,oo.h_bol,s.description,a.update_date,public.getTimeAndLocationForKln(oo.serial_no,a.code,''::text)::jsonb as jsonb_data
-                                    from public.ocean_milestone a 
-                                        inner join public.customer_service_milestone_sno s on a.code = s.code 
-                                        inner join public.kln_ocean oo on oo.serial_no = a.serial_no 
-                                    where s.type = 'sea' 
-                                        and a.act_date is not null
-                                        and a.update_date is not null
-                                        and a.update_date > '2025-04-06') po
-                            )t;select aa.update_date_format, COUNT(*) AS total_count
+            from (
+            select serial_no
+            from (SELECT oo.serial_no from public.ocean_milestone a 
+                        inner join public.customer_service_milestone_sno s on a.code = s.code 
+                        inner join public.kln_ocean oo on oo.serial_no = a.serial_no and (<{ExtendHand_KLN}>)
+                    where s.type = 'sea' 
+                        and a.act_date is not null
+                        and COALESCE(a.update_date, a.create_date) >= CURRENT_DATE - INTERVAL '7 days') po
+            union all 
+            select serial_no
+            from (SELECT oo.serial_no from public.air_milestone a 
+                        inner join public.customer_service_milestone_sno s on a.code = s.code 
+                        inner join public.kln_ocean oo on oo.serial_no = a.serial_no and (<{ExtendHand_KLN}>)
+                    where s.type = 'air' 
+                        and a.act_date is not null
+                        and COALESCE(a.update_date, a.create_date) >= CURRENT_DATE - INTERVAL '7 days') pa
+            union all 
+            select serial_no
+            from (SELECT oo.serial_no from sfs.air_milestone a 
+                        inner join public.customer_service_milestone_sno s on a.code = s.code 
+                        inner join public.kln_ocean oo on oo.serial_no = a.serial_no and (<{ExtendHand_KLN}>)
+                    where s.type = 'air' 
+                        and a.act_date is not null
+                        and COALESCE(a.update_date, a.create_date) >= CURRENT_DATE - INTERVAL '7 days') sa
+            )t;select serial_no,order_from,h_bol, description,update_date_format,update_date,
+                    COALESCE(m.jsonb_data->>'milestone','')::jsonb->>'timezone' as timezone,
+                    COALESCE(m.jsonb_data->>'milestone','')::jsonb->>'locations' as locations 
+            from (
+            select serial_no,order_from,h_bol,description,to_char(update_date,'Mon DD') as update_date_format,update_date,code
+            from (SELECT oo.serial_no,oo.order_from,oo.h_bol,s.description,COALESCE(a.update_date, a.create_date) as update_date,a.code
+                    from public.ocean_milestone a 
+                        inner join public.customer_service_milestone_sno s on a.code = s.code 
+                        inner join public.kln_ocean oo on oo.serial_no = a.serial_no and (<{ExtendHand_KLN}>)
+                    where s.type = 'sea' 
+                        and a.act_date is not null
+                        and COALESCE(a.update_date, a.create_date) >= CURRENT_DATE - INTERVAL '7 days') po
+            union all 
+            select serial_no,order_from,h_bol,description,to_char(update_date,'Mon DD')as update_date_format,update_date,code
+            from (SELECT oo.serial_no,oo.order_from,oo.h_bol,s.description,COALESCE(a.update_date, a.create_date) as update_date,a.code
+                    from public.air_milestone a 
+                        inner join public.customer_service_milestone_sno s on a.code = s.code 
+                        inner join public.kln_ocean oo on oo.serial_no = a.serial_no and (<{ExtendHand_KLN}>)
+                    where s.type = 'air' 
+                        and a.act_date is not null
+                        and COALESCE(a.update_date, a.create_date) >= CURRENT_DATE - INTERVAL '7 days') pa
+            union all 
+            select serial_no,order_from,h_bol,description,to_char(update_date,'Mon DD')as update_date_format,update_date,code
+            from (SELECT oo.serial_no,oo.order_from,oo.h_bol,s.description,COALESCE(a.update_date, a.create_date) as update_date,a.code
+                    from sfs.air_milestone a 
+                        inner join public.customer_service_milestone_sno s on a.code = s.code 
+                        inner join public.kln_ocean oo on oo.serial_no = a.serial_no and (<{ExtendHand_KLN}>)
+                    where s.type = 'air' 
+                        and a.act_date is not null
+                        and COALESCE(a.update_date, a.create_date) >= CURRENT_DATE - INTERVAL '7 days') sa
+            )t  left join LATERAL (select public.getTimeAndLocationForKln(serial_no,code,''::text)::jsonb as jsonb_data) m on true 
+            order by update_date limit 10;select aa.update_date_format, COUNT(*) AS total_count
+            from (
+                select DISTINCT ON (h_bol) h_bol, update_date_format
                 from (
-                    select DISTINCT ON (h_bol) h_bol, update_date_format
-                    from (
-                    select serial_no,order_from,h_bol,description,to_char(update_date,'Mon DD') as update_date_format,update_date
-                    from (SELECT oo.serial_no,oo.order_from,oo.h_bol,s.description,a.update_date
-                            from public.ocean_milestone a 
-                                inner join public.customer_service_milestone_sno s on a.code = s.code 
-                                inner join public.kln_ocean oo on oo.serial_no = a.serial_no 
-                            where s.type = 'sea' 
-                                and a.act_date is not null
-                                and a.update_date > '2025-04-06') po
-
-                    )t order by h_bol
-                ) aa
-                group by aa.update_date_format order by aa.update_date_format ";
+                select h_bol,to_char(update_date,'Mon DD') as update_date_format
+                from (SELECT oo.h_bol,COALESCE(a.update_date, a.create_date) as update_date
+                        from public.ocean_milestone a 
+                            inner join public.kln_ocean oo on oo.serial_no = a.serial_no and (<{ExtendHand_KLN}>)
+                        where a.act_date is not null
+                            and COALESCE(a.update_date, a.create_date) >= CURRENT_DATE - INTERVAL '7 days') po
+                union all 
+                select h_bol,to_char(update_date,'Mon DD') as update_date_format
+                from (SELECT oo.h_bol,COALESCE(a.update_date, a.create_date) as update_date
+                        from public.air_milestone a 
+                            inner join public.kln_ocean oo on oo.serial_no = a.serial_no and (<{ExtendHand_KLN}>)
+                        where a.act_date is not null
+                            and COALESCE(a.update_date, a.create_date) >= CURRENT_DATE - INTERVAL '7 days') pa
+                union all 
+                select h_bol,to_char(update_date,'Mon DD') as update_date_format
+                from (SELECT oo.h_bol,COALESCE(a.update_date, a.create_date) as update_date
+                        from sfs.air_milestone a 
+                            inner join public.kln_ocean oo on oo.serial_no = a.serial_no and (<{ExtendHand_KLN}>)
+                        where a.act_date is not null
+                            and COALESCE(a.update_date, a.create_date) >= CURRENT_DATE - INTERVAL '7 days') sa
+                )t order by h_bol
+            ) aa
+            group by aa.update_date_format order by aa.update_date_format ";
         $data["What is the current status of my active shipments?"] ="SELECT count(*)
                 FROM public.kln_ocean oo
                 WHERE  <{ExtendHand_KLN}> and ((oo.ata is not null and oo.ata >= CURRENT_DATE - INTERVAL '3 months' AND oo.ata < CURRENT_DATE)