From cb52ff0fd9fdf3ebfbde2314539998f3fedd9854 Mon Sep 17 00:00:00 2001
From: king <18310653075@163.com>
Date: 星期二, 10 九月 2024 10:16:46 +0800
Subject: [PATCH] Merge branch 'develop'

---
 src/tabviews/zshare/topSearch/index.jsx |  210 +++++++++++++++++++++++++++++++++++++++++----------
 1 files changed, 167 insertions(+), 43 deletions(-)

diff --git a/src/tabviews/zshare/topSearch/index.jsx b/src/tabviews/zshare/topSearch/index.jsx
index 032ca25..3f19a86 100644
--- a/src/tabviews/zshare/topSearch/index.jsx
+++ b/src/tabviews/zshare/topSearch/index.jsx
@@ -48,6 +48,8 @@
     let fieldMap = new Map()
     let mainItems = []  // 浜戠鎴栧崟鐐规暟鎹�
     let localItems = [] // 鏈湴鏁版嵁
+    let backMItems = [] // 浜戠鎴栧崟鐐规暟鎹�
+    let backLItems = [] // 鏈湴鏁版嵁
     let deForms = []    // 娴嬭瘯绯荤粺锛屽崟涓姹�
     let advanceValues = []
     let linkFields = {}
@@ -55,6 +57,22 @@
     let forbid = false // header涓笉璁剧疆楂樼骇鎼滅储
     let _setting = {showAdv: false, show: false, style: null}
     let BID = this.props.BID
+    let sysvals = {}
+
+    if (window.backend) {
+      sysvals = {
+        mk_departmentcode: sessionStorage.getItem('departmentcode') || '',
+        mk_organization: sessionStorage.getItem('organization') || '',
+        mk_user_type: sessionStorage.getItem('mk_user_type') || '',
+        bid: BID || '',
+        datam: sessionStorage.getItem('dataM') === 'true' ? 'Y' : '',
+        datam_begin: sessionStorage.getItem('dataM') === 'true' ? 'Y' : '',
+        datam_end: sessionStorage.getItem('dataM') === 'true' ? 'Y' : '',
+      }
+      if (window.GLOB.externalDatabase !== null) {
+        sysvals.db = window.GLOB.externalDatabase
+      }
+    }
     
     if (config.wrap) {
       _setting.show = config.wrap.show !== 'false'
@@ -188,43 +206,77 @@
 
         // 鏁版嵁婧愭煡璇㈣鍙�
         if (item.resourceType === '1' && item.dataSource) {
-          let _option = Utils.getSelectQueryOptions(item)
-          let _declare = `Declare @mk_departmentcode nvarchar(512),@mk_organization nvarchar(512),@mk_user_type nvarchar(20)  select @mk_departmentcode='${sessionStorage.getItem('departmentcode') || ''}',@mk_organization='${sessionStorage.getItem('organization') || ''}',@mk_user_type='${sessionStorage.getItem('mk_user_type') || ''}'\n`
+          if (window.backend && window.GLOB.CacheData.has('sql_' + item.uuid)) {
+            let ex = window.GLOB.CacheData.get('sql_' + item.uuid)
+            let exps = []
 
-          let exec = true
-          if (item.checkBid) {
-            item.sql = _declare + _option.sql
-            item.arr_field = _option.field
+            ex.reps.forEach(n => {
+              let key = n.toLowerCase()
+              if (sysvals.hasOwnProperty(key)) {
+                exps.push({
+                  key: n,
+                  value: sysvals[key]
+                })
+              }
+            })
 
-            exec = !!BID
-          }
+            let cell = {
+              id: ex.id,
+              exps: exps,
+              menuname: item.label + '锛堟悳绱級',
+              md5_id: ''
+            }
+            if (item.checkBid) {
+              item.sqlId = ex.id
+              item.exps = exps
+            }
 
-          if (exec) {
-            let _sql = _option.sql.replace(/@BID@/ig, `'${BID || ''}'`)
+            if (item.checkBid && !BID) {
+
+            } else if (item.database === 'sso' && window.GLOB.mainSystemApi) {
+              backMItems.push(cell)
+            } else {
+              backLItems.push(cell)
+            }
+          } else {
+            let _option = Utils.getSelectQueryOptions(item)
+            let _declare = `Declare @mk_departmentcode nvarchar(512),@mk_organization nvarchar(512),@mk_user_type nvarchar(20)  select @mk_departmentcode='${sessionStorage.getItem('departmentcode') || ''}',@mk_organization='${sessionStorage.getItem('organization') || ''}',@mk_user_type='${sessionStorage.getItem('mk_user_type') || ''}'\n`
   
-            if (window.GLOB.debugger === true) {
-              window.mkInfo(_declare + _sql)
+            let exec = true
+            if (item.checkBid) {
+              item.sql = _declare + _option.sql
+              item.arr_field = _option.field
+  
+              exec = !!BID
             }
   
-            // 娴嬭瘯绯荤粺鍗曚釜璇锋眰
-            if (!window.GLOB.mkHS && window.GLOB.sysType === 'local' && !window.GLOB.systemType) {
-              deForms.push({
-                ...item,
-                arr_field: _option.field,
-                data_sql: Utils.formatOptions(_declare + _sql, window.GLOB.execType)
-              })
-            } else { // 鍚堝苟璇锋眰锛屽尯鍒嗘湰鍦板強绯荤粺
-              _sql = _sql.replace(/%/ig, ' mpercent ')
-              if (item.database === 'sso') {
-                if (mainItems.length === 0) {
-                  _sql = _declare + _sql
+            if (exec) {
+              let _sql = _option.sql.replace(/@BID@/ig, `'${BID || ''}'`)
+    
+              if (window.GLOB.debugger === true) {
+                window.mkInfo(_declare + _sql)
+              }
+    
+              // 娴嬭瘯绯荤粺鍗曚釜璇锋眰
+              if (!window.GLOB.mkHS && window.GLOB.sysType === 'local' && !window.GLOB.systemType) {
+                deForms.push({
+                  ...item,
+                  arr_field: _option.field,
+                  data_sql: Utils.formatOptions(_declare + _sql, window.GLOB.execType)
+                })
+              } else { // 鍚堝苟璇锋眰锛屽尯鍒嗘湰鍦板強绯荤粺
+                _sql = _sql.replace(/%/ig, ' mpercent ')
+                if (item.database === 'sso') {
+                  if (mainItems.length === 0) {
+                    _sql = _declare + _sql
+                  }
+                  mainItems.push(`select '${item.field}' as obj_name,'${_option.field}' as arr_field,'${window.btoa(window.encodeURIComponent(_sql))}' as LText`)
+                } else {
+                  if (localItems.length === 0) {
+                    _sql = _declare + _sql
+                  }
+                  localItems.push(`select '${item.field}' as obj_name,'${_option.field}' as arr_field,'${window.btoa(window.encodeURIComponent(_sql))}' as LText`)
                 }
-                mainItems.push(`select '${item.field}' as obj_name,'${_option.field}' as arr_field,'${window.btoa(window.encodeURIComponent(_sql))}' as LText`)
-              } else {
-                if (localItems.length === 0) {
-                  _sql = _declare + _sql
-                }
-                localItems.push(`select '${item.field}' as obj_name,'${_option.field}' as arr_field,'${window.btoa(window.encodeURIComponent(_sql))}' as LText`)
               }
             }
           }
@@ -296,7 +348,9 @@
       advanceValues,
       searchlist: _list
     }, () => {
-      if (!window.GLOB.mkHS && window.GLOB.sysType === 'local' && window.GLOB.systemType !== 'production') {
+      if (window.backend && (backMItems.length > 0 || backLItems.length > 0)) {
+        this.improveBackSearch(backMItems, backLItems, false)
+      } else if (!window.GLOB.mkHS && window.GLOB.sysType === 'local' && window.GLOB.systemType !== 'production') {
         this.improveSimpleSearch(deForms, false, null, BID)
       } else if (mainItems.length > 0 || localItems.length > 0) {
         this.improveSearch(mainItems, localItems, BID)
@@ -337,19 +391,41 @@
 
   resetOptions = (BID) => {
     let deForms = []
+    let backMItems = [] // 浜戠鎴栧崟鐐规暟鎹�
+    let backLItems = [] // 鏈湴鏁版嵁
     let searchlist = fromJS(this.state.searchlist).toJS().map(item => {
       if (item.checkBid) {
-        let sql = item.sql.replace(/@BID@/ig, `'${BID || ''}'`)
-  
-        if (window.GLOB.debugger === true) {
-          window.mkInfo(sql)
-        }
+        if (window.backend && item.sqlId) {
+          let cell = {
+            id: item.sqlId,
+            menuname: item.label + '锛堟悳绱級',
+            md5_id: '',
+            exps: item.exps.map(n => {
+              if (n.key === 'BID') {
+                n.value = BID
+              }
+              return n
+            })
+          }
 
-        deForms.push({
-          ...item,
-          arr_field: item.arr_field,
-          data_sql: Utils.formatOptions(sql, window.GLOB.execType)
-        })
+          if (item.database === 'sso' && window.GLOB.mainSystemApi) {
+            backMItems.push(cell)
+          } else {
+            backLItems.push(cell)
+          }
+        } else {
+          let sql = item.sql.replace(/@BID@/ig, `'${BID || ''}'`)
+    
+          if (window.GLOB.debugger === true) {
+            window.mkInfo(sql)
+          }
+  
+          deForms.push({
+            ...item,
+            arr_field: item.arr_field,
+            data_sql: Utils.formatOptions(sql, window.GLOB.execType)
+          })
+        }
       } else if (item.checkShift) {
         let d = ''
         if (window.GLOB.CacheData.has(item.$supId)) {
@@ -387,7 +463,9 @@
       return item
     })
 
-    if (deForms.length > 0) {
+    if (window.backend && (backMItems.length > 0 || backLItems.length > 0)) {
+      this.improveBackSearch(backMItems, backLItems, true, searchlist)
+    } else if (deForms.length > 0) {
       this.improveSimpleSearch(deForms, true, searchlist, BID)
     } else {
       this.setState({
@@ -532,6 +610,52 @@
       delete result.status
 
       this.resetSearch(result, false)
+    })
+  }
+
+  // 鏌ヨ涓嬫媺鑿滃崟
+  improveBackSearch = (mainItems, localItems, trigger, searchlist) => {
+    let deffers = []
+    
+    if (localItems.length) {
+      deffers.push({
+        $backend: true,
+        data: localItems
+      })
+    }
+
+    if (mainItems.length) {
+      deffers.push({
+        $backend: true,
+        data: mainItems,
+        rduri: window.GLOB.mainSystemApi
+      })
+    }
+
+    deffers = deffers.map(item => {
+      return new Promise(resolve => {
+        Api.getSystemCacheConfig(item).then(res => {
+          if (!res.status) {
+            notification.warning({
+              top: 92,
+              message: res.message,
+              duration: 5
+            })
+          }
+          resolve(res)
+        })
+      })
+    })
+
+    Promise.all(deffers).then(response => {
+      let result = {...response[0], ...(response[1] || {})}
+
+      delete result.ErrCode
+      delete result.ErrMesg
+      delete result.message
+      delete result.status
+
+      this.resetSearch(result, trigger, searchlist)
     })
   }
 
@@ -1049,7 +1173,7 @@
         }
 
         if (typeof(val) === 'string') {
-          val = val.replace(/(^\s*|\s*$)/ig, '')
+          val = val.replace(/(^\s+|\s+$)/ig, '').replace(/\t+|\v+/g, '')
         }
 
         search.push({

--
Gitblit v1.8.0