ShuanghongS hai 1 día
pai
achega
3e65f980e8

+ 40 - 8
service/login.class.php

@@ -394,9 +394,17 @@ class login {
                     }
 
                     if (!empty($online_user['docdownload']))
-                        $sql = "select  string_agg(standard, ';') as standard,string_agg(serial_no, ';') as serial_no, string_agg(m_h, ';') as m_h, display_name from ra_online_file_format where lower(serial_no) " . common::getInNotInSql($online_user['docdownload']) . " and active = true group by display_name order by min(id)";
+                        $sql = "select  jsonb_agg(to_jsonb(ra_online_file_format)) as file_data,
+                                        string_agg(standard, ';') as standard,
+                                        string_agg(serial_no, ';') as serial_no, 
+                                        string_agg(m_h, ';') as m_h, display_name 
+                                    from ra_online_file_format where lower(serial_no) " . common::getInNotInSql($online_user['docdownload']) . " and active = true group by display_name order by min(id)";
                     else {
-                        $sql = "select  string_agg(standard, ';') as standard,string_agg(serial_no, ';') as serial_no, string_agg(m_h, ';') as m_h, display_name from ra_online_file_format where active = true";
+                        $sql = "select  jsonb_agg(to_jsonb(ra_online_file_format)) as file_data,
+                                        string_agg(standard, ';') as standard,
+                                        string_agg(serial_no, ';') as serial_no,
+                                        string_agg(m_h, ';') as m_h, display_name 
+                                        from ra_online_file_format where active = true";
                         if (strtolower($online_user['user_type']) == "customer")
                             $sql .= " and client_display = true";
                         $sql .= " group by display_name order by min(id)";
@@ -404,9 +412,17 @@ class login {
                     $online_user['view_doc_type'] = common::excuteListSql($sql);
 
                     if (!empty($online_user['view_air_file_format']))
-                        $sql = "select  string_agg(standard, ';') as standard,string_agg(serial_no, ';') as serial_no, string_agg(m_h, ';') as m_h, display_name from air_file_format where lower(serial_no) " . common::getInNotInSql($online_user['view_air_file_format']) . " and active = true group by display_name order by min(id)";
+                        $sql = "select  jsonb_agg(to_jsonb(air_file_format)) as file_data,
+                                        string_agg(standard, ';') as standard,
+                                        string_agg(serial_no, ';') as serial_no, 
+                                        string_agg(m_h, ';') as m_h, display_name 
+                                    from air_file_format where lower(serial_no) " . common::getInNotInSql($online_user['view_air_file_format']) . " and active = true group by display_name order by min(id)";
                     else {
-                        $sql = "select  string_agg(standard, ';') as standard,string_agg(serial_no, ';') as serial_no, string_agg(m_h, ';') as m_h, display_name from air_file_format where active = true";
+                        $sql = "select  jsonb_agg(to_jsonb(air_file_format)) as file_data,
+                                        string_agg(standard, ';') as standard,
+                                        string_agg(serial_no, ';') as serial_no,
+                                        string_agg(m_h, ';') as m_h, display_name 
+                                    from air_file_format where active = true";
                         if (strtolower($online_user['user_type']) == "customer")
                             $sql .= " and client_display = true";
                         $sql .= " group by display_name order by min(id)";
@@ -457,9 +473,17 @@ class login {
                         }
 
                         if (!empty($ttdd['docdownload'])) {
-                            $sql = "select  string_agg(standard, ';') as standard,string_agg(serial_no, ';') as serial_no, string_agg(m_h, ';') as m_h, display_name from " . $sv['schemas_name'] . ".ra_online_file_format where lower(serial_no) " . common::getInNotInSql($ttdd['docdownload']) . " and active = true group by display_name order by min(id)";
+                            $sql = "select  jsonb_agg(to_jsonb(ra_online_file_format)) as file_data, 
+                                            string_agg(standard, ';') as standard,
+                                            string_agg(serial_no, ';') as serial_no,
+                                            string_agg(m_h, ';') as m_h, display_name 
+                                        from " . $sv['schemas_name'] . ".ra_online_file_format where lower(serial_no) " . common::getInNotInSql($ttdd['docdownload']) . " and active = true group by display_name order by min(id)";
                         } else {
-                            $sql = "select  string_agg(standard, ';') as standard,string_agg(serial_no, ';') as serial_no, string_agg(m_h, ';') as m_h, display_name from " . $sv['schemas_name'] . ".ra_online_file_format where active = true";
+                            $sql = "select  jsonb_agg(to_jsonb(ra_online_file_format)) as file_data,
+                                            string_agg(standard, ';') as standard,
+                                            string_agg(serial_no, ';') as serial_no,
+                                            string_agg(m_h, ';') as m_h, display_name 
+                                        from " . $sv['schemas_name'] . ".ra_online_file_format where active = true";
                             if (strtolower($ttdd['user_type']) == "customer")
                                 $sql .= " and client_display = true";
                             $sql .= " group by display_name order by min(id)";
@@ -467,9 +491,17 @@ class login {
                         $ttdd['view_doc_type'] = common::excuteListSql($sql);
 
                         if (!empty($ttdd['view_air_file_format'])) {
-                            $sql = "select  string_agg(standard, ';') as standard,string_agg(serial_no, ';') as serial_no, string_agg(m_h, ';') as m_h, display_name from " . $sv['schemas_name'] . ".air_file_format where lower(serial_no) " . common::getInNotInSql($ttdd['view_air_file_format']) . " and active = true group by display_name order by min(id)";
+                            $sql = "select  jsonb_agg(to_jsonb(air_file_format)) as file_data,
+                                            string_agg(standard, ';') as standard,
+                                            string_agg(serial_no, ';') as serial_no,
+                                            string_agg(m_h, ';') as m_h, display_name 
+                                        from " . $sv['schemas_name'] . ".air_file_format where lower(serial_no) " . common::getInNotInSql($ttdd['view_air_file_format']) . " and active = true group by display_name order by min(id)";
                         } else {
-                            $sql = "select  string_agg(standard, ';') as standard, string_agg(serial_no, ';') as serial_no, string_agg(m_h, ';') as m_h, display_name from " . $sv['schemas_name'] . ".air_file_format where active = true";
+                            $sql = "select  jsonb_agg(to_jsonb(air_file_format)) as file_data,
+                                            string_agg(standard, ';') as standard,
+                                            string_agg(serial_no, ';') as serial_no,
+                                            string_agg(m_h, ';') as m_h, display_name 
+                                        from " . $sv['schemas_name'] . ".air_file_format where active = true";
                             if (strtolower($ttdd['user_type']) == "customer")
                                 $sql .= " and client_display = true";
                             $sql .= " group by display_name order by min(id)";

+ 197 - 36
service/multilingual.class.php

@@ -42,7 +42,7 @@ class multilingual{
             if (empty($langkey) || strtoupper($langkey) == "ALL") {
                 // 如果没传或传 ALL,直接查询所有激活语言的 ID
                 // 优化点:直接查 id,不需要先查 key 再查 id
-                $langSql = "SELECT id FROM kln_i18n_languages"; 
+                $langSql = "SELECT id FROM public.kln_i18n_languages"; 
                 $langRows = common::excuteListSql($langSql);
                 if ($langRows) {
                     $langIds = array_column($langRows, 'id');
@@ -61,7 +61,7 @@ class multilingual{
                 if (!empty($safeLangs)) {
                     // 拼接 IN 条件:('english', 'french')
                     $inClause = implode(',', $safeLangs);
-                    $langSql = "SELECT id FROM kln_i18n_languages WHERE lang_key IN ($inClause)";
+                    $langSql = "SELECT id FROM public.kln_i18n_languages WHERE lang_key IN ($inClause)";
                     $langRows = common::excuteListSql($langSql);
                     if ($langRows) {
                         $langIds = array_column($langRows, 'id');
@@ -95,10 +95,85 @@ class multilingual{
             $this->_multilingual_save($multilingual_param);
         }
 
+        /*
+         * multilingual_save
+         */
+        if ($operate == "multilingual_save_all") {
+            $multilingual_param = $_POST['multilingual_param'];
+            $this->_multilingual_save_oneself($multilingual_param);
+        }
+
         if ($operate == "load_all_pages_by_lang") {
             $langkey = common::check_input($_POST['langkey']);
             $this->_loadAllPagesByLang($langkey);
         }
+
+        if ($operate == "edi_doc_type"){
+            $json = common::excuteOneSql("select data from public.kln_i18n_pages_init where id = 3");
+            $data = json_decode($json,true);
+
+            $successCount = 0;
+            $errorCount = 0;
+            foreach ($data['data'] as $row) {
+                try {
+                    $code = isset($row['code']) ? "'" . common::check_input($row['code']) . "'" : "NULL";
+                    $name = isset($row['name']) ? "'" . common::check_input($row['name']) . "'" : "NULL";
+                    $description = isset($row['description']) ? "'" . common::check_input($row['description']) . "'" : "NULL";
+                    $version_policy = isset($row['versionPolicy']) ? "'" . common::check_input($row['versionPolicy']) . "'" : "NULL";
+                    
+                    // 处理 "1"/"0" 字符串或数字
+                    $visible_to_customer = isset($row['visibleToCustomer']) ? "'" . common::check_input($row['visibleToCustomer']) . "'" : "NULL";
+                    $can_delete = isset($row['canDelete']) ? "'" . common::check_input($row['canDelete']) . "'" : "NULL";
+                    $to_destination = isset($row['toDestination']) ? intval($row['toDestination']) : "NULL";
+                    
+                    $maximum_file_size = isset($row['maximumFileSize']) ? floatval($row['maximumFileSize']) : "NULL";
+                    
+                    $supported_suffixes = isset($row['supportedSuffixes']) ? "'" . common::check_input($row['supportedSuffixes']) . "'" : "NULL";
+                    $biz_type = isset($row['bizType']) ? "'" . common::check_input($row['bizType']) . "'" : "NULL";
+                    $shipment_type = isset($row['shipmentType']) ? "'" . common::check_input($row['shipmentType']) . "'" : "NULL";
+                    $field_code = isset($row['fieldCode']) ? "'" . common::check_input($row['fieldCode']) . "'" : "NULL";
+                    
+                    $rule_exp = isset($row['ruleExp']) ? "'" . common::check_input($row['ruleExp']) . "'" : "NULL";
+                    
+                    $old_code = isset($row['oldCode']) ? "'" . common::check_input($row['oldCode']) . "'" : "NULL";
+                    $old_name = isset($row['oldName']) ? "'" . common::check_input($row['oldName']) . "'" : "NULL";
+                    
+                    $biz_cate = isset($row['bizCate']) ? "'" . common::check_input($row['bizCate']) . "'" : "NULL";
+                    $is_old = isset($row['isOld']) ? "'" . common::check_input($row['isOld']) . "'" : "NULL";
+                    $is_business = isset($row['isBusiness']) ? "'" . common::check_input($row['isBusiness']) . "'" : "NULL";
+                    
+                    $upload_file_name_rule_suffix = isset($row['uploadFileNameRuleSuffix']) ? "'" . common::check_input($row['uploadFileNameRuleSuffix']) . "'" : "NULL";
+                    
+                    $customer_upload = isset($row['customerUpload']) ? "'" . common::check_input($row['customerUpload']) . "'" : "NULL";
+                    
+                    // 处理 null 值 (数据库 NULL)
+                    $notify_station = isset($row['notifyStation']) ? "'" . common::check_input($row['notifyStation']) . "'" : "NULL";
+                    $auto_sync_to_station = isset($row['autoSyncToStation']) ? "'" . common::check_input($row['autoSyncToStation']) . "'" : "NULL";
+
+                    // --- 拼接 SQL 语句 ---
+                    // 注意:表名使用双引号 "document_codes" 以确保大小写敏感(如果表名是小写 codes 可能不需要,但为了保险)
+                    $insertSQL = "INSERT INTO doc_type (
+                        code, name, description, version_policy, visible_to_customer, 
+                        can_delete, to_destination, maximum_file_size, supported_suffixes, 
+                        biz_type, shipment_type, field_code, rule_exp, old_code, 
+                        old_name, biz_cate, is_old, is_business, upload_file_name_rule_suffix, 
+                        customer_upload, notify_station, auto_sync_to_station
+                    ) VALUES (
+                        $code, $name, $description, $version_policy, $visible_to_customer,
+                        $can_delete, $to_destination, $maximum_file_size, $supported_suffixes,
+                        $biz_type, $shipment_type, $field_code, $rule_exp, $old_code,
+                        $old_name, $biz_cate, $is_old, $is_business, $upload_file_name_rule_suffix,
+                        $customer_upload, $notify_station, $auto_sync_to_station
+                    )";   
+                    common::excuteUpdateSql($insertSQL);
+                    $successCount++;
+                } catch (PDOException $e) {
+                    echo "插入失败 (Code: {$row['code']}): " . $e->getMessage() . "\n";
+                    $errorCount++;
+                }
+            }
+            echo "数据处理完成。\n成功插入: $successCount 条\n失败: $errorCount 条\n";
+        }
     }
 
     private function _multilingual_init() {
@@ -141,36 +216,36 @@ class multilingual{
         global $db; 
         $db->StartTrans();
         try {
-            // 第一步:处理页面表 (kln_i18n_pages)
+            // 第一步:处理页面表 (public.kln_i18n_pages)
             $pageId = null;
 
             // --- 模式判断:如果是覆盖模式,先删除旧数据 ---
             if ($mode === 'replace') {
-                // 1. 先删子表 (kln_i18n_keys)
-                $kikSqlDelete = "DELETE FROM kln_i18n_keys WHERE page_id IN (SELECT id FROM kln_i18n_pages WHERE page_key = '$pageKey')";
+                // 1. 先删子表 (public.kln_i18n_keys)
+                $kikSqlDelete = "DELETE FROM public.kln_i18n_keys WHERE page_id IN (SELECT id FROM public.kln_i18n_pages WHERE page_key = '$pageKey')";
                 $db->Execute($kikSqlDelete) or ( (!$db->ErrorMsg()) or error_log(common::dbLog($db, $kikSqlDelete), 0));
 
-                // 2. 再删主表 (kln_i18n_pages) - 虽然上面删了子表,这里为了保险或者重置页面信息也可以删,
-                $delPageSql = "DELETE FROM kln_i18n_pages WHERE page_key = '$pageKey'";
+                // 2. 再删主表 (public.kln_i18n_pages) - 虽然上面删了子表,这里为了保险或者重置页面信息也可以删,
+                $delPageSql = "DELETE FROM public.kln_i18n_pages WHERE page_key = '$pageKey'";
                 $db->Execute($delPageSql) or ( (!$db->ErrorMsg()) or error_log(common::dbLog($db, $delPageSql), 0));
             }
 
             // --- 查询页面是否存在 ---
-            $checkPageSql = "SELECT id FROM kln_i18n_pages WHERE page_key = '$pageKey'";
+            $checkPageSql = "SELECT id FROM public.kln_i18n_pages WHERE page_key = '$pageKey'";
             $checkPageRes =  $db->GetRow($checkPageSql) or ( (!$db->ErrorMsg()) or error_log(common::dbLog($db, $checkPageSql), 0));
             
             if (!empty($checkPageRes)) {
                 // 存在 -> 更新
                 $pageId = $checkPageRes['id'];
-                $updatePageSql = "UPDATE kln_i18n_pages SET unverified_number = $unverifiedNumber WHERE id = $pageId";
+                $updatePageSql = "UPDATE public.kln_i18n_pages SET unverified_number = $unverifiedNumber WHERE id = $pageId";
                 $db->Execute($updatePageSql) or ( (!$db->ErrorMsg()) or error_log(common::dbLog($db, $updatePageSql), 0));
             } else {
                 // 不存在 -> 插入
-                $insertPageSql = "INSERT INTO kln_i18n_pages (page_key, unverified_number, description) VALUES ('$pageKey', $unverifiedNumber, '')";
+                $insertPageSql = "INSERT INTO public.kln_i18n_pages (page_key, unverified_number, description) VALUES ('$pageKey', $unverifiedNumber, '')";
                 $db->Execute($insertPageSql) or ( (!$db->ErrorMsg()) or error_log(common::dbLog($db, $insertPageSql), 0));
                 
                 // 获取新生成的 ID (PostgreSQL)
-                $seqSql = "SELECT currval('kln_i18n_pages_id_seq')";
+                $seqSql = "SELECT currval('public.kln_i18n_pages_id_seq')";
                 $pageIdRow = $db->GetRow($seqSql) or ( (!$db->ErrorMsg()) or error_log(common::dbLog($db, $seqSql), 0));
                 $pageId = $pageIdRow['currval'];
             }
@@ -187,43 +262,43 @@ class multilingual{
                         $statusKey = common::check_input($jsonKey . 'Status');
                         $status = isset($item[$statusKey]) ? intval($item[$statusKey]) : 0;
 
-                        // --- 1. 处理语言表 (kln_i18n_languages) ---
+                        // --- 1. 处理语言表 (public.kln_i18n_languages) ---
                         $langKey = common::check_input($jsonKey); 
                         $langName = common::check_input($langInfo['name']);
                         $localeCode = common::check_input($langInfo['code']);
 
                         // 查询语言是否存在
-                        $checkLangSql = "SELECT id FROM kln_i18n_languages WHERE lang_key = '$langKey'";
+                        $checkLangSql = "SELECT id FROM public.kln_i18n_languages WHERE lang_key = '$langKey'";
                         $checkLangRes = $db->GetRow($checkLangSql) or ( (!$db->ErrorMsg()) or error_log(common::dbLog($db, $checkLangSql), 0));
 
                         if (!empty($checkLangRes)) {
                             // 存在 -> 更新
                             $langId = $checkLangRes['id'];
-                            $updateLangSql = "UPDATE kln_i18n_languages SET lang_name = '$langName', locale_code = '$localeCode' WHERE id = $langId";
+                            $updateLangSql = "UPDATE public.kln_i18n_languages SET lang_name = '$langName', locale_code = '$localeCode' WHERE id = $langId";
                             $db->Execute($updateLangSql) or ( (!$db->ErrorMsg()) or error_log(common::dbLog($db, $updateLangSql), 0));
                         } else {
                             // 不存在 -> 插入
-                            $insertLangSql = "INSERT INTO kln_i18n_languages (lang_key, lang_name, locale_code, is_active) VALUES ('$langKey', '$langName', '$localeCode', true)";
+                            $insertLangSql = "INSERT INTO public.kln_i18n_languages (lang_key, lang_name, locale_code, is_active) VALUES ('$langKey', '$langName', '$localeCode', true)";
                             $db->Execute($insertLangSql) or ( (!$db->ErrorMsg()) or error_log(common::dbLog($db, $updateLangSql), 0));
                             
                             // 获取 ID
-                            $seqLangSql = "SELECT currval('kln_i18n_languages_id_seq')";
+                            $seqLangSql = "SELECT currval('public.kln_i18n_languages_id_seq')";
                             $langIdRow = $db->GetRow($seqLangSql) or ( (!$db->ErrorMsg()) or error_log(common::dbLog($db, $seqLangSql), 0));
                             $langId = $langIdRow['currval'];
                         }
 
-                        // --- 2. 处理词条表 (kln_i18n_keys) ---
+                        // --- 2. 处理词条表 (public.kln_i18n_keys) ---
                         // 查询词条是否存在
-                        $checkKeySql = "SELECT id FROM kln_i18n_keys WHERE page_id = $pageId AND lang_id = $langId AND trans_key = '$transKey'";
+                        $checkKeySql = "SELECT id FROM public.kln_i18n_keys WHERE page_id = $pageId AND lang_id = $langId AND trans_key = '$transKey'";
                         $checkKeyRes = $db->GetRow($checkKeySql) or ( (!$db->ErrorMsg()) or error_log(common::dbLog($db, $checkKeySql), 0));
 
                         if (!empty($checkKeyRes)) {
                             // 存在 -> 更新
-                            $updateKeySql = "UPDATE kln_i18n_keys SET trans_value = '$transValue', orgin_value = '$originValue', status = $status WHERE id = " . $checkKeyRes['id'];
+                            $updateKeySql = "UPDATE public.kln_i18n_keys SET trans_value = '$transValue', orgin_value = '$originValue', status = $status WHERE id = " . $checkKeyRes['id'];
                             $db->Execute($updateKeySql) or ( (!$db->ErrorMsg()) or error_log(common::dbLog($db, $updateKeySql), 0));
                         } else {
                             // 不存在 -> 插入
-                            $insertKeySql = "INSERT INTO kln_i18n_keys (page_id, lang_id, trans_key, trans_value, orgin_value, status) VALUES ($pageId, $langId, '$transKey', '$transValue', '$originValue', $status)";
+                            $insertKeySql = "INSERT INTO public.kln_i18n_keys (page_id, lang_id, trans_key, trans_value, orgin_value, status) VALUES ($pageId, $langId, '$transKey', '$transValue', '$originValue', $status)";
                             $db->Execute($insertKeySql) or ( (!$db->ErrorMsg()) or error_log(common::dbLog($db, $insertKeySql), 0));
                         }
                     }
@@ -259,7 +334,7 @@ class multilingual{
         // 1. 统一处理 $pageIds 数组
         if (empty($pageKey) || strtoupper($pageKey) == "ALL") {
             // 如果没传或传 ALL,直接查询所有页面的 ID
-            $pageSql = "SELECT id FROM kln_i18n_pages";
+            $pageSql = "SELECT id FROM public.kln_i18n_pages";
             $pageRows = common::excuteListSql($pageSql);
             
             if ($pageRows) {
@@ -279,7 +354,7 @@ class multilingual{
             if (!empty($safePages)) {
                 $inClause = implode(',', $safePages);
                 // 优化点:一次查询获取所有匹配的 ID 和 unverified_number
-                $pageSql = "SELECT id, unverified_number FROM kln_i18n_pages WHERE page_key IN ($inClause)";
+                $pageSql = "SELECT id, unverified_number FROM public.kln_i18n_pages WHERE page_key IN ($inClause)";
                 $pageRows = common::excuteListSql($pageSql);
                 
                 if ($pageRows) {
@@ -299,7 +374,7 @@ class multilingual{
         if (empty($langkey) || strtoupper($langkey) == "ALL") {
             // 如果没传或传 ALL,直接查询所有激活语言的 ID
             // 优化点:直接查 id,不需要先查 key 再查 id
-            $langSql = "SELECT id FROM kln_i18n_languages"; 
+            $langSql = "SELECT id FROM public.kln_i18n_languages"; 
             $langRows = common::excuteListSql($langSql);
                 
             if ($langRows) {
@@ -319,7 +394,7 @@ class multilingual{
             if (!empty($safeLangs)) {
                 // 拼接 IN 条件:('english', 'french')
                 $inClause = implode(',', $safeLangs);
-                $langSql = "SELECT id FROM kln_i18n_languages WHERE lang_key IN ($inClause)";
+                $langSql = "SELECT id FROM public.kln_i18n_languages WHERE lang_key IN ($inClause)";
                 $langRows = common::excuteListSql($langSql);
                 if ($langRows) {
                     $langIds = array_column($langRows, 'id');
@@ -335,9 +410,9 @@ class multilingual{
                     k.orgin_value,
                     l.lang_key,
                     p.page_key AS key_page
-                FROM kln_i18n_keys k
-                JOIN kln_i18n_languages l ON k.lang_id = l.id
-                JOIN kln_i18n_pages p ON k.page_id = p.id
+                FROM public.kln_i18n_keys k
+                JOIN public.kln_i18n_languages l ON k.lang_id = l.id
+                JOIN public.kln_i18n_pages p ON k.page_id = p.id
                 WHERE k.page_id IN (" . implode(',', $pageIds) . ")
                 AND k.lang_id IN (" . implode(',', $langIds) . ")
                 ORDER BY k.trans_key, p.page_key";
@@ -417,20 +492,20 @@ class multilingual{
                 $status = $param['status'];
                 
                 // 查询页面ID
-                $pageSql = "SELECT id FROM kln_i18n_pages WHERE page_key = '".$pageKey."'";
+                $pageSql = "SELECT id FROM public.kln_i18n_pages WHERE page_key = '".$pageKey."'";
                 $pageId = $db->GetOne($pageSql);
                 if (!$pageId) {
                     throw new Exception("Page not found: " . $pageKey);
                 }
                 
                 // 查询语言ID
-                $langSql = "SELECT id FROM kln_i18n_languages WHERE lang_key = '".$langKey."'";
+                $langSql = "SELECT id FROM public.kln_i18n_languages WHERE lang_key = '".$langKey."'";
                 $langId = $db->GetOne($langSql);
                 if (!$langId) {
                     throw new Exception("Language not found: " . $langKey);
                 }
                 // 更新翻译状态
-                $updateTransSql = "UPDATE kln_i18n_keys SET status = $status, trans_value = '$trans_value' ".
+                $updateTransSql = "UPDATE public.kln_i18n_keys SET status = $status, trans_value = '$trans_value' ".
                                 " WHERE page_id = " . $pageId . 
                                 " AND lang_id = " . $langId . 
                                 " AND trans_key = '".$transKey."'";
@@ -450,6 +525,92 @@ class multilingual{
         exit();
     }
 
+     /**
+     * 保存多语言数据 (自己使用,包含跟多字段的编辑和添加)
+     * 
+     * @param array $multilingual_param 页面未审核数量参数,格式:[{unverifiedNumber: 3, page: 'login'}, ...]
+     * @param array $multilingual_trans_param 翻译状态参数,格式:[{page: 'login', lang: 'traditionalChinese', trans_key: 'username', status: 1}, ...]
+     * @return bool 是否保存成功
+     */
+    public function _multilingual_save_oneself($multilingual_param) {
+        global $db;
+        try {
+            // 开启事务确保数据一致性
+            $db->StartTrans();
+            //2. 处理翻译词条状态更新
+            foreach ($multilingual_param as $param) {
+                $pageKey = common::check_input($param['page']);
+                $langKey = common::check_input($param['lang']);
+                $transKey = common::check_input($param['trans_key']);
+                $trans_value = common::check_input($param['trans_value']);
+                $status = $param['status'];
+                
+                // 查询页面ID
+                $pageSql = "SELECT id FROM public.kln_i18n_pages WHERE page_key = '".$pageKey."'";
+                $pageId = $db->GetOne($pageSql);
+                if (!$pageId) {
+                    throw new Exception("Page not found: " . $pageKey);
+                }
+                
+                // 查询语言ID
+                $langSql = "SELECT id FROM public.kln_i18n_languages WHERE lang_key = '".$langKey."'";
+                $langId = $db->GetOne($langSql);
+                if (!$langId) {
+                    throw new Exception("Language not found: " . $langKey);
+                }
+
+                if( $langId == 'originEnglish'){
+                    $ii8_Sql = "SELECT id FROM public.kln_i18n_keys WHERE  page_id = " . $pageId . "  AND trans_key = '".$transKey."'";
+                    $ii8 = $db->GetOne($ii8_Sql);
+                    if (!$ii8) {
+                        $langAllSql = "SELECT id FROM public.kln_i18n_languages";
+                        $langAllId = $db->GetAll($langAllSql);
+                        foreach($langAllId as $_langAllId){
+                            // 不存在 -> 插入
+                            $insertKeySql = "INSERT INTO public.kln_i18n_keys (page_id, lang_id, trans_key, trans_value, status) 
+                                    VALUES ($pageId, ".$_langAllId['id'].", '$transKey', '$trans_value', 0)";
+                            $db->Execute($insertKeySql);
+                        }
+                    }else{
+                        // 更新翻译状态
+                        $updateTransSql = "UPDATE public.kln_i18n_keys SET status = 0, orgin_value = '$trans_value' ".
+                                        " WHERE page_id = " . $pageId . 
+                                        " AND trans_key = '".$transKey."'";
+                        $db->Execute($updateTransSql);
+                    }
+                } else {
+                    $ii8_Sql = "SELECT id FROM public.kln_i18n_keys WHERE  page_id = " . $pageId . " AND lang_id = ".$langId." AND trans_key = '".$transKey."'";
+                    $ii8 = $db->GetOne($ii8_Sql);
+                    if (!$ii8) {
+                        // 不存在 -> 插入
+                        $insertKeySql = "INSERT INTO public.kln_i18n_keys (page_id, lang_id, trans_key, trans_value, status) 
+                                VALUES ($pageId, $langId, '$transKey', '$trans_value', $status)";
+                        $db->Execute($insertKeySql);
+                    
+                    }else{
+                        // 更新翻译状态
+                        $updateTransSql = "UPDATE public.kln_i18n_keys SET status = $status, trans_value = '$trans_value' ".
+                                        " WHERE page_id = " . $pageId . 
+                                        " AND lang_id = " . $langId . 
+                                        " AND trans_key = '".$transKey."'";
+                        $db->Execute($updateTransSql);
+                    }
+                }
+            }
+        } catch (Exception $e) {
+            // 捕获异常,标记错误,以便回滚
+            error_log("Exception in multilingual_save: " . $e->getMessage());
+        }
+        // 结束事务
+        if ($db->CompleteTrans() === FALSE) {
+            $msg = 'Save Error';
+        } else {
+            $msg = 'Save Success';
+        }
+        common::echo_json_encode(200, $msg);
+        exit();
+    }
+
 
     /**
      *  load page info
@@ -463,7 +624,7 @@ class multilingual{
                         page_id,
                         trans_key,
                         BOOL_OR(status = 0) AS all_unverified
-                    FROM kln_i18n_keys
+                    FROM public.kln_i18n_keys
                     WHERE lang_id IN (" . implode(',', $langIds) . ")
                     GROUP BY page_id, trans_key
                 ) AS subquery
@@ -502,8 +663,8 @@ class multilingual{
         $langSql = "SELECT 
             l.lang_key, 
             COUNT(k.id) AS unverified_count
-        FROM kln_i18n_languages l
-        LEFT JOIN kln_i18n_keys k ON l.id = k.lang_id 
+        FROM public.kln_i18n_languages l
+        LEFT JOIN public.kln_i18n_keys k ON l.id = k.lang_id 
             $page_id_sql  
             AND k.status = 0    
         WHERE 
@@ -539,7 +700,7 @@ class multilingual{
         }
         try {
             // 2. 查询指定语言的 ID
-            $langSql = "SELECT id FROM kln_i18n_languages WHERE lang_key = ? AND is_active = TRUE limit 1";
+            $langSql = "SELECT id FROM public.kln_i18n_languages WHERE lang_key = ? AND is_active = TRUE limit 1";
             $langObj = common::excuteObjectPrepareSql($langSql,array($langKey));
             
             if (empty($langObj)) {
@@ -549,7 +710,7 @@ class multilingual{
             $langId = $langObj['id'];
 
             // 3. 查询所有激活的页面
-            $pageSql = "SELECT id, page_key FROM kln_i18n_pages WHERE 1=1";
+            $pageSql = "SELECT id, page_key FROM public.kln_i18n_pages WHERE 1=1";
             $pageRows = common::excuteListSql($pageSql);
             
             // 4. 构建页面 ID 列表,用于后续查询
@@ -562,7 +723,7 @@ class multilingual{
             // 5. 查询该语言下所有页面的所有翻译词条
             $inClause = implode(',', $pageIds);
             $transSql = "SELECT page_id, trans_key, trans_value 
-                        FROM kln_i18n_keys 
+                        FROM public.kln_i18n_keys 
                         WHERE lang_id = $langId
                         AND page_id IN ($inClause)"; 
             

+ 33 - 12
service/ocean_order.class.php

@@ -1425,19 +1425,29 @@ class ocean_order {
 
         $document_data = array();
         $document = _getViewDocType($_REQUEST["_schemas"]);
-        if($ocean['source_user'] == 'K5' || $ocean['source_user'] == 'KSMART_AIR2'){
+
+        $Enable_New_DMS = common::excuteOneSql("select item_value from config where item = 'Enable_New_DMS'");
+        if ($ocean['source_user'] == 'K5' || $ocean['source_user'] == 'KSMART_AIR2' || $Enable_New_DMS == "True"){
             //DMS的接口 K5和KSMART AIR的文檔數
             if (!empty($document)) {
                 $docTypes = array();
+                $docTypesAllInfo = array();
                 foreach ($document as $v) {
-                    $_docTypes = $v['standard'];
-                    $_docTypes = explode(";", $_docTypes);
-                    foreach ($_docTypes as $k => $_type) {
-                        $docTypes[] = $_type;
+                    $_file_data = $v['file_data'];
+                    $_file_data = json_decode($_file_data,true);
+                    foreach ($_file_data as $k => $_type) {
+                        if(!empty($_type['document_type_new_code'])){
+                            $docTypes[] = $_type['document_type_new_code'];
+                            $docTypesAllInfo[] = $_type;
+                        }
                     }
                 }
+                //$ocean['h_bol'] = "ABCNA1008776";
                 $jsonResponse = dms_edoc::getEdocFile($ocean['h_bol'],$docTypes,'ocean');
                 $file_arr = json_decode($jsonResponse, true);
+
+                 //处理 appearance S M
+                $file_arr = common::deal_dms_file($file_arr,$docTypesAllInfo);
                 foreach($file_arr as $f){
                     $temp_f = array("url"=>"main_new_version.php?action=ocean_order&operate=download&url=".common::deCode("dms", 'E')."&filename=".common::deCode($f['fileName'], 'E')."&outId=".$f['outId'],
                             "file_name" => $f['fileName'],
@@ -1616,26 +1626,37 @@ class ocean_order {
         $Milestones = common::getMilestonesInfo('tracking',$air,"air",$_schemas);
 
         //页面固定写死的信息
+        $page = common::getPageMapping("Ocean_Container");   
         $document_column = array();
-        $document_column[] = array("title" =>"File Type","field" =>"file_type","formatter" =>"","type" =>"normal");
-        $document_column[] = array("title" =>"File","field" =>"file","formatter" =>"","type" =>"normal");
+        $document_column[] = array("title" =>"File Type","cleaned_field_name"=>$page .'.file_type',"field" =>"file_type","formatter" =>"","type" =>"normal");
+        $document_column[] = array("title" =>"File","cleaned_field_name"=>$page .'.file',"field" =>"file","formatter" =>"","type" =>"normal");
 
         $document_data = array();
 
         $document = _getAirViewDocType($_REQUEST["_schemas"]);
-        if($air['source_user'] == 'K5' || $air['source_user'] == 'KSMART_AIR2'){
+
+        $Enable_New_DMS = common::excuteOneSql("select item_value from config where item = 'Enable_New_DMS'");
+        if($air['source_user'] == 'K5' || $air['source_user'] == 'KSMART_AIR2' || $Enable_New_DMS == "True"){
             //DMS的接口 K5和KSMART AIR的文檔數
             if (!empty($document)) {
                 $docTypes = array();
+                $docTypesAllInfo = array();
                 foreach ($document as $v) {
-                    $_docTypes = $v['standard'];
-                    $_docTypes = explode(";", $_docTypes);
-                    foreach ($_docTypes as $k => $_type) {
-                        $docTypes[] = $_type;
+                    $_file_data = $v['file_data'];
+                    $_file_data = json_decode($_file_data,true);
+                    foreach ($_file_data as $k => $_type) {
+                        if(!empty($_type['document_type_new_code'])){
+                            $docTypes[] = $_type['document_type_new_code'];
+                            $docTypesAllInfo[] = $_type;
+                        }
                     }
                 }
+                //$air['_h_bol'] = "ABCNA1008776";
                 $jsonResponse = dms_edoc::getEdocFile($air['_h_bol'],$docTypes,'air');
                 $file_arr = json_decode($jsonResponse, true);
+                //处理 appearance S M
+                $file_arr = common::deal_dms_file($file_arr,$docTypesAllInfo);
+
                 foreach($file_arr as $f){
                     $temp_f = array("url"=>"main_new_version.php?action=ocean_order&operate=download&url=".common::deCode("dms", 'E')."&filename = ".common::deCode($f['fileName'], 'E')."&outId=".$f['outId'],
                             "file_name" => $f['fileName'],

+ 25 - 0
utils/common.class.php

@@ -5444,5 +5444,30 @@ class common {
             'destination_delivery_shipment_search'=>'destinationDelivery'];
         return $pagemapping[$key];
     }
+
+    public static function deal_dms_file($data,$docTypesAllInfo){
+        $result = [];
+        $appearanceMap = [];
+        foreach ($docTypesAllInfo as $map) {
+            $appearanceMap[$map['document_type_new_code']] = $map['appearance'];
+        }
+        foreach ($data as $item) {
+            $docType = $item['docType'];
+            $appearance = $appearanceMap[$docType]; 
+            if ($appearance == 'S') {
+                // 如果是'S',只保留 uploadDate 最新的那条
+                $currentDate = strtotime($item['uploadDate']); // 将时间字符串转为时间戳方便比较
+                if (!isset($result[$docType]) || $currentDate > strtotime($result[$docType]['uploadDate'])) {
+                    $result[$docType] = $item;
+                }
+            } else {
+                $result[] = $item;
+            }
+        }
+
+        // 5. 格式化最终结果
+        $finalData = array_values($result);
+        return $finalData;
+    }
 }
 ?>

+ 22 - 19
utils/dms_edoc.class.php

@@ -191,19 +191,19 @@ class dms_edoc {
             $result = null;
 
             //old code => Doc_Code
-            $mapping = $oceanAir == "ocean" ? self::$oceanMapping : self::$airMapping;
-            $resultDocTypes = array_values(array_filter(
-                array_map(
-                    fn($type) => $mapping[$type] ?? null,
-                    $docTypes
-                ),
-                fn($mapped) => !empty($mapped) // 过滤 null 和空字符串
-            ));
+            //$mapping = $oceanAir == "ocean" ? self::$oceanMapping : self::$airMapping;
+            //$resultDocTypes = array_values(array_filter(
+            //    array_map(
+            //        fn($type) => $mapping[$type] ?? null,
+            //        $docTypes
+            //    ),
+            //    fn($mapped) => !empty($mapped) // 过滤 null 和空字符串
+            //));
 
             $data = [
                 'fromStation' => '',
                 'hbol'        => $hbol,
-                'docTypes'    => $resultDocTypes
+                'docTypes'    => $docTypes
             ];
             // $data = [
             //     'fromStation' => '',
@@ -211,12 +211,13 @@ class dms_edoc {
             //     'docTypes'    => ["WO"]
             // ];
 
-            $accessTokenUrl = 'http://dms.kln.com/keycloak/realms/dsms-realm/protocol/openid-connect/token';
+            $accessTokenUrl = 'https://login.microsoftonline.com/bf568a79-7f40-44de-a9cd-842784ac899b/oauth2/v2.0/token';
             //prod 账号
             $grant_type = 'client_credentials';
-            $client_id = 'online';
-            $client_secret = 'ouuRZ8QbIrcqKZi0NBJLt7PUEiRr5uXd';
-            $accessToken = dms_edoc::getAccessToken($accessTokenUrl,$grant_type,$client_id,$client_secret);
+            $client_id = '9ac6e294-12a2-421e-b139-fe748fd4e901';
+            $client_secret = 'l_V8Q~D5zBLyIQ2XmsUfzOFYHVlQFx_~oX~NKarL';
+            $scope = 'api://d2c3017f-3308-49b2-bd5d-eb210e6a9313/.default';
+            $accessToken = dms_edoc::getAccessToken($accessTokenUrl,$grant_type,$client_id,$client_secret,$scope);
             if ($accessToken === null) {
                 throw new Exception("Failed to obtain access token");
             }
@@ -238,12 +239,13 @@ class dms_edoc {
             $result = null;
             $data = ['outId' => $outId];
 
-            $accessTokenUrl = 'http://dms.kln.com/keycloak/realms/dsms-realm/protocol/openid-connect/token';
+            $accessTokenUrl = 'https://login.microsoftonline.com/bf568a79-7f40-44de-a9cd-842784ac899b/oauth2/v2.0/token';
             //prod 账号
             $grant_type = 'client_credentials';
-            $client_id = 'online';
-            $client_secret = 'ouuRZ8QbIrcqKZi0NBJLt7PUEiRr5uXd';
-            $accessToken = dms_edoc::getAccessToken($accessTokenUrl,$grant_type,$client_id,$client_secret);
+            $client_id = '9ac6e294-12a2-421e-b139-fe748fd4e901';
+            $client_secret = 'l_V8Q~D5zBLyIQ2XmsUfzOFYHVlQFx_~oX~NKarL';
+            $scope = 'api://d2c3017f-3308-49b2-bd5d-eb210e6a9313/.default';
+            $accessToken = dms_edoc::getAccessToken($accessTokenUrl,$grant_type,$client_id,$client_secret,$scope);
             if ($accessToken === null) {
                 throw new Exception("Failed to obtain access token");
             }
@@ -255,7 +257,7 @@ class dms_edoc {
         }
     }
 
-    public static function getAccessToken($accessTokenUrl,$grant_type,$client_id,$client_secret){
+    public static function getAccessToken($accessTokenUrl,$grant_type,$client_id,$client_secret,$scope){
         //还是需要这个,如果在一个请求里多次调用这个方法的话,就可以用缓存的
         if (self::$cachedToken !== null && time() * 1000 < self::$tokenExpiryTime) {
             return self::$cachedToken;
@@ -264,7 +266,8 @@ class dms_edoc {
         $postData = http_build_query([
             'grant_type' => $grant_type,
             'client_id' => $client_id,
-            'client_secret' => $client_secret
+            'client_secret' => $client_secret,
+            'scope' => $scope
         ]);
 
         $headers = [