From c10fc10d5fd307a7b334bcde6af5c1175aaa0410 Mon Sep 17 00:00:00 2001
From: king <18310653075@163.com>
Date: 星期三, 28 八月 2024 17:47:28 +0800
Subject: [PATCH] 2024-08-28

---
 src/utils/utils-datamanage.js |  488 +++++++++++++++++++++++++++++++++++++++++++----------
 1 files changed, 393 insertions(+), 95 deletions(-)

diff --git a/src/utils/utils-datamanage.js b/src/utils/utils-datamanage.js
index be72648..aff2f1e 100644
--- a/src/utils/utils-datamanage.js
+++ b/src/utils/utils-datamanage.js
@@ -1,23 +1,24 @@
 import md5 from 'md5'
 import moment from 'moment'
+import { notification, Modal } from 'antd'
+
+import MKEmitter from '@/utils/events.js'
 import Utils from './utils.js'
 
 export default class DataUtils {
   /**
-   * @description 鏁版嵁婧愬悕绉帮紝鐢ㄤ簬缁熶竴鏌ヨ
-   * @param {Object}   setting      鏁版嵁婧愯缃�
-   * @param {Array}    search       鎼滅储鏉′欢
-   * @param {String}   orderBy      鎺掑簭鏂瑰紡
-   * @param {Number}   pageIndex    椤电爜
-   * @param {Number}   pageSize     姣忛〉鏁伴噺
-   * @param {String}   BID          涓婄骇ID
-   * @return {Object}  param
+   * @description 鏁版嵁婧愮粺涓�鏌ヨ
    */
   static getQueryDataParams (setting, search = [], orderBy = '', pageIndex = 1, pageSize = 10, BID, id, year) {
     let param = null
 
     if (setting.interType === 'system') {
-      param = this.getDefaultQueryParam(setting, search, orderBy, pageIndex, pageSize, id, BID, year)
+      if (window.backend && window.GLOB.CacheData.has('sql_' + setting.uuid) && !window.GLOB.mkHS) {
+        param = this.getDefaultQueryParam(setting, search, orderBy, pageIndex, pageSize, id, BID, year)
+        this.getBackendQueryParam(setting, search, orderBy, pageIndex, pageSize, id, BID, year)
+      } else {
+        param = this.getDefaultQueryParam(setting, search, orderBy, pageIndex, pageSize, id, BID, year)
+      }
     } else {
       param = this.getCustomQueryParam(setting, search, orderBy, pageIndex, pageSize, id, year)
     }
@@ -52,38 +53,43 @@
       param.mk_year = year
     }
 
+    if (setting.hasExtend) {
+      param.mk_time = setting.extendTime
+    }
+
     if (setting.interType === 'inner') {
       param.func = setting.innerFunc
+
+      if (setting.recordUser === 'true') {
+        param.username = sessionStorage.getItem('User_Name') || ''
+        param.fullname = sessionStorage.getItem('Full_Name') || ''
+      }
     } else {
-      if (window.GLOB.mkHS) {
-        if (setting.sysInterface === 'true' && window.GLOB.cloudServiceApi) {
-          param.rduri = window.GLOB.cloudServiceApi
-          param.userid = sessionStorage.getItem('CloudUserID') || ''
-          param.LoginUID = sessionStorage.getItem('CloudLoginUID') || ''
-        } else if (setting.sysInterface !== 'true') {
+      if (setting.sysInterface === 'true') {
+        if (window.GLOB.mainSystemApi) {
+          param.rduri = window.GLOB.mainSystemApi
+        }
+      } else if (setting.sysInterface === 'external') {
+        if (window.GLOB.systemType === 'production') {
+          param.$token = setting.exProInterface || ''
+        } else {
+          param.$token = setting.exInterface || ''
+        }
+      } else if (setting.sysInterface === 'custom') {
+        if (window.GLOB.systemType === 'production') {
+          param.rduri = setting.proInterface
+        } else {
           param.rduri = setting.interface
         }
       } else {
-        if (setting.sysInterface === 'true') {
-          if (window.GLOB.mainSystemApi) {
-            param.rduri = window.GLOB.mainSystemApi
-          }
-        } else if (setting.sysInterface === 'external') {
-          if (window.GLOB.systemType === 'production') {
-            param.$token = setting.exProInterface || ''
-          } else {
-            param.$token = setting.exInterface || ''
-          }
+        if (window.GLOB.systemType === 'production' && setting.proInterface) {
+          param.rduri = setting.proInterface
         } else {
-          if (window.GLOB.systemType === 'production' && setting.proInterface) {
-            param.rduri = setting.proInterface
-          } else {
-            param.rduri = setting.interface
-          }
-          let host = window.GLOB.baseurl.replace(/http(s):\/\//, '')
-          if (param.rduri.indexOf(host) === -1 && /\/dostars/.test(param.rduri)) {
-            param.$login = true
-          }
+          param.rduri = setting.interface
+        }
+        let host = window.GLOB.baseurl.replace(/http(s):\/\//, '')
+        if (param.rduri.indexOf(host) === -1 && /\/dostars/.test(param.rduri)) {
+          param.$login = true
         }
       }
 
@@ -102,7 +108,7 @@
     let param = {
       func: 'sPC_Get_TableData',
       obj_name: 'data',
-      exec_type: 'y',
+      exec_type: window.GLOB.execType || 'y',
       arr_field: setting.arr_field,
       default_sql: setting.execute ? 'true' : 'false'
     }
@@ -141,20 +147,24 @@
       { reg: /@orderBy@/ig, value: orderBy },
       { reg: /@pageSize@/ig, value: setting.laypage ? pageSize : '9999' },
       { reg: /@pageIndex@/ig, value: pageIndex},
-      { reg: /@select\$|\$select@/ig, value: ''},
-      { reg: /\$sum@/ig, value: '/*'},
-      { reg: /@sum\$/ig, value: '*/'},
+      // { reg: /@select\$|\$select@/ig, value: ''},
+      // { reg: /\$sum@/ig, value: '/*'},
+      // { reg: /@sum\$/ig, value: '*/'},
       { reg: /@ID@/ig, value: `'${id || ''}'`},
       { reg: /@BID@/ig, value: `'${BID || ''}'`},
       { reg: /@LoginUID@/ig, value: `'${sessionStorage.getItem('LoginUID') || ''}'`},
       { reg: /@SessionUid@/ig, value: `'${localStorage.getItem('SessionUid') || ''}'`},
       { reg: /@UserID@/ig, value: `'${sessionStorage.getItem('UserID') || ''}'`},
       { reg: /@Appkey@/ig, value: `'${window.GLOB.appkey || ''}'`},
+      { reg: /@lang@/ig, value: `'${sessionStorage.getItem('lang')}'`},
       { reg: /@typename@/ig, value: `'admin'`},
     )
 
+    if (setting.hasExtend) {
+      regoptions.push({ reg: /@mk_time@/ig, value: `'${setting.extendTime}'` })
+    }
     if (setting.$re_year) {
-      regoptions.push({ reg: /@mk_year@/ig, value: year })
+      regoptions.push({ reg: /@mk_year@/ig, value: `'${year}'` })
     }
 
     regoptions.forEach(item => {
@@ -201,26 +211,37 @@
     let arr_field = setting.all_field || setting.arr_field
 
     if (_dataresource) {
-      if (setting.laypage && orderBy) {
-        if (setting.custompage) {
-          LText = `/*system_query*/select ${arr_field} from ${_dataresource} ${_search} `
+      if (setting.custompage) {
+        LText = `/*system_query*/select ${arr_field} from ${_dataresource} ${_search} `
+      } else if (setting.laypage && orderBy) {
+        LText = `/*system_query*/select top ${pageSize} ${arr_field} from (select ${arr_field} ,ROW_NUMBER() over(order by ${orderBy}) as rows from ${_dataresource} ${_search}) tmptable where rows > ${pageSize * (pageIndex - 1)} order by tmptable.rows `
+        if (setting.sub_field) {
+          DateCount = `/*system_query*/select count(1) as total from (select distinct ${setting.primaryKey} from ${_dataresource} ${_search})a`
         } else {
-          LText = `/*system_query*/select top ${pageSize} ${arr_field} from (select ${arr_field} ,ROW_NUMBER() over(order by ${orderBy}) as rows from ${_dataresource} ${_search}) tmptable where rows > ${pageSize * (pageIndex - 1)} order by tmptable.rows `
-          if (setting.sub_field) {
-            DateCount = `/*system_query*/select count(1) as total from (select distinct ${setting.primaryKey} from ${_dataresource} ${_search})a`
-          } else {
-            DateCount = `/*system_query*/select count(1) as total from ${_dataresource} ${_search}`
-          }
+          DateCount = `/*system_query*/select count(1) as total from ${_dataresource} ${_search}`
+        }
+      } else if (setting.$top) {
+        if (orderBy) {
+          LText = `/*system_query*/select top 1 ${arr_field} from ${_dataresource} ${_search} order by ${orderBy} `
+        } else {
+          LText = `/*system_query*/select top 1 ${arr_field} from ${_dataresource} ${_search}  `
         }
       } else if (orderBy) {
-        LText = `/*system_query*/select ${arr_field} from (select ${arr_field} ,ROW_NUMBER() over(order by ${orderBy}) as rows from ${_dataresource} ${_search}) tmptable order by tmptable.rows `
+        LText = `/*system_query*/select ${arr_field} from ${_dataresource} ${_search} order by ${orderBy} `
       } else {
         LText = `/*system_query*/select ${arr_field} from ${_dataresource} ${_search}  `
       }
     }
 
     if (_customScript) {
-      if (LText) {
+      if (DateCount) {
+        DateCount = `${DateCount}
+          ${_tailScript}
+          aaa:
+          if @ErrorCode!=''
+            insert into tmp_err_retmsg (ID, ErrorCode, retmsg, CreateUserID) select @time_id@,@ErrorCode, @retmsg,'${sessionStorage.getItem('UserID') || ''}' 
+        `
+      } else if (LText) {
         LText = `${LText}
           ${_tailScript}
           aaa:
@@ -235,6 +256,17 @@
             insert into tmp_err_retmsg (ID, ErrorCode, retmsg, CreateUserID) select @time_id@,@ErrorCode, @retmsg,'${sessionStorage.getItem('UserID') || ''}' 
         `
       }
+    } else if (_tailScript && DateCount) {
+      LText = `declare @ErrorCode nvarchar(50),@retmsg nvarchar(4000),@UserName nvarchar(50),@FullName nvarchar(50),@RoleID nvarchar(512),@mk_departmentcode nvarchar(512),@mk_organization nvarchar(512),@mk_user_type nvarchar(20),@mk_nation nvarchar(50),@mk_province nvarchar(50),@mk_city nvarchar(50),@mk_district nvarchar(50),@mk_address nvarchar(100)
+        Select @ErrorCode='',@retmsg ='',@UserName='${userName}', @FullName='${fullName}', @RoleID='${RoleID}', @mk_departmentcode='${departmentcode}', @mk_organization='${organization}', @mk_user_type='${mk_user_type}', @mk_nation='${nation}', @mk_province='${province}', @mk_city='${city}', @mk_district='${district}', @mk_address='${address}'
+        ${LText}
+      `
+      DateCount = `${DateCount}
+        ${_tailScript}
+        aaa:
+        if @ErrorCode!=''
+          insert into tmp_err_retmsg (ID, ErrorCode, retmsg, CreateUserID) select @time_id@,@ErrorCode, @retmsg,'${sessionStorage.getItem('UserID') || ''}' 
+      `
     } else if (_tailScript) {
       LText = `declare @ErrorCode nvarchar(50),@retmsg nvarchar(4000),@UserName nvarchar(50),@FullName nvarchar(50),@RoleID nvarchar(512),@mk_departmentcode nvarchar(512),@mk_organization nvarchar(512),@mk_user_type nvarchar(20),@mk_nation nvarchar(50),@mk_province nvarchar(50),@mk_city nvarchar(50),@mk_district nvarchar(50),@mk_address nvarchar(100)
         Select @ErrorCode='',@retmsg ='',@UserName='${userName}', @FullName='${fullName}', @RoleID='${RoleID}', @mk_departmentcode='${departmentcode}', @mk_organization='${organization}', @mk_user_type='${mk_user_type}', @mk_nation='${nation}', @mk_province='${province}', @mk_city='${city}', @mk_district='${district}', @mk_address='${address}'
@@ -253,17 +285,18 @@
 
     // 娴嬭瘯绯荤粺鎵撳嵃鏌ヨ璇彞
     if (window.GLOB.debugger === true) {
-      _customScript && console.info(`${setting.$name ? `/*${setting.$name} 鑷畾涔夎剼鏈�*/\n` : ''}${LText ? '' : '/*涓嶆墽琛岄粯璁ql*/\n'}${_customScript}`)
-      LText && console.info(`${setting.$name ? `/*${setting.$name} 鏁版嵁婧�*/\n` : ''}` + LText.replace(/\n\s{8}/ig, '\n'))
+      _customScript && window.mkInfo(`${setting.$name ? `/*${setting.$name} 鑷畾涔夎剼鏈�*/\n` : ''}${LText ? '' : '/*涓嶆墽琛岄粯璁ql*/\n'}${_customScript}`)
+      LText && window.mkInfo(`${setting.$name ? `/*${setting.$name} 鏁版嵁婧�*/\n` : ''}` + LText.replace(/\n\s{8}/ig, '\n'))
+      DateCount && window.mkInfo(`${setting.$name ? `/*${setting.$name} 鎬绘暟鏌ヨ*/\n` : ''}` + DateCount.replace(/\n\s{8}/ig, '\n'))
     }
 
     if (setting.$name) {
       param.menuname = setting.$name
     }
 
-    param.custom_script = Utils.formatOptions(_customScript)
-    param.LText = Utils.formatOptions(LText)
-    param.DateCount = Utils.formatOptions(DateCount)
+    param.custom_script = Utils.formatOptions(_customScript, param.exec_type)
+    param.LText = Utils.formatOptions(LText, param.exec_type)
+    param.DateCount = Utils.formatOptions(DateCount, param.exec_type)
 
     if (setting.sub_field) {
       param.sub_name = setting.subdata
@@ -272,9 +305,9 @@
       param.sub_field = setting.sub_field
     }
 
-    // exec_type: 'y' 瑙g爜瀛楁锛歀Text銆丩Text1銆丩Text2銆乧ustom_script銆丏ateCount
+    // exec_type 瑙g爜瀛楁锛歀Text銆丩Text1銆丩Text2銆乧ustom_script銆丏ateCount
 
-    param.timestamp = moment().format('YYYY-MM-DD HH:mm:ss')
+    param.timestamp = moment().format('YYYY-MM-DD HH:mm:ss.SSS')
     param.secretkey = Utils.encrypt('', param.timestamp)
 
     param.username = userName
@@ -288,11 +321,244 @@
       param.open_key = Utils.encryptOpenKey(param.secretkey, param.timestamp)
 
       // special HS鑷畾涔夊嚱鏁版煡璇�
-      if (setting.tableName === 's_custom_script' && window.GLOB.cloudServiceApi) {
-        param.rduri = window.GLOB.cloudServiceApi
-        param.userid = sessionStorage.getItem('CloudUserID') || ''
-        param.LoginUID = sessionStorage.getItem('CloudLoginUID') || ''
+      if (setting.tableName === 's_custom_script' && window.GLOB.mainSystemApi) {
+        param.rduri = window.GLOB.mainSystemApi
       }
+    } else if (window.GLOB.forcedUpdate) {
+      param.s_version_up = 'true'
+    }
+
+    if (setting.database === 'sso' && window.GLOB.mainSystemApi) {
+      param.rduri = window.GLOB.mainSystemApi
+    }
+
+    return param
+  }
+
+  /**
+   * @description 鑾峰彇绯荤粺瀛樺偍杩囩▼鐨勫弬鏁�
+   */
+  static getBackendQueryParam (setting, search, orderBy, pageIndex, pageSize, id, BID, year) {
+    let item = window.GLOB.CacheData.get('sql_' + setting.uuid)
+
+    let param = {}
+
+    let searchKeys = null
+    if (setting.dataresource) {
+      searchKeys = []
+
+      if (search.length) {
+        searchKeys = Utils.getSearchkeys(search)
+      }
+
+      if (id) {
+        if (/^excel:/.test(id)) {
+          id = id.replace(/^excel:/, '')
+          searchKeys.push({
+            key: setting.primaryKey || 'ID',
+            match: 'in',
+            type: 'text_in',
+            value: id
+          })
+        } else {
+          searchKeys.push({
+            key: setting.primaryKey || 'ID',
+            match: '=',
+            type: 'text',
+            value: id
+          })
+        }
+      }
+    }
+
+    let values = {
+      userid: sessionStorage.getItem('UserID') || '',
+      time_id: Utils.getguid(),
+      username: sessionStorage.getItem('User_Name') || '',
+      fullname: sessionStorage.getItem('Full_Name') || '',
+      roleid: sessionStorage.getItem('role_id') || '',
+      mk_departmentcode: sessionStorage.getItem('departmentcode') || '',
+      mk_organization: sessionStorage.getItem('organization') || '',
+      mk_user_type: sessionStorage.getItem('mk_user_type') || '',
+      mk_nation: sessionStorage.getItem('nation') || '',
+      mk_province: sessionStorage.getItem('province') || '',
+      mk_city: sessionStorage.getItem('city') || '',
+      mk_district: sessionStorage.getItem('district') || '',
+      mk_address: sessionStorage.getItem('address') || '',
+      orderby: orderBy,
+      pagesize: setting.laypage ? pageSize : '9999',
+      pageindex: pageIndex,
+      id: id || '',
+      bid: BID || '',
+      loginuid: sessionStorage.getItem('LoginUID') || '',
+      sessionuid: localStorage.getItem('SessionUid') || '',
+      appkey: window.GLOB.appkey || '',
+      lang: sessionStorage.getItem('lang'),
+      typename: 'admin',
+      datam: sessionStorage.getItem('dataM') === 'true' ? 'Y' : '',
+      datam_begin: sessionStorage.getItem('dataM') === 'true' ? 'Y' : '',
+      datam_end: sessionStorage.getItem('dataM') === 'true' ? 'Y' : '',
+      // datam_begin: sessionStorage.getItem('dataM') === 'true' ? '/*' : '',
+      // datam_end: sessionStorage.getItem('dataM') === 'true' ? '*/' : '',
+      mk_obj_name: 'data'
+    }
+
+    if (setting.hasExtend) {
+      values.mk_time = setting.extendTime
+    }
+    if (setting.$re_year) {
+      values.mk_year = year
+    }
+    if (window.GLOB.externalDatabase !== null) {
+      values.db = window.GLOB.externalDatabase
+    }
+    if (item.works_flow_code) {
+      values.works_flow_code = item.works_flow_code
+    }
+
+    item.urlkeys.forEach(key => {
+      values[key] = item.urlparam[key]
+    })
+
+    let allSearch = Utils.getAllSearchOptions(search)
+
+    allSearch.forEach(cell => {
+      values[cell.key.toLowerCase()] = cell.value
+    })
+
+    let list = []
+
+    if (searchKeys) {
+      list.push({
+        key: 'mk_search',
+        value: searchKeys
+      })
+    }
+
+    let sql = item.sql
+
+    item.reps.forEach(n => {
+      let key = n.toLowerCase()
+      if (values.hasOwnProperty(key)) {
+        list.push({
+          key: n,
+          value: values[key]
+        })
+      }
+    })
+
+    // let list = [
+    //   {
+    //     key: "mk_search",
+    //     value: [
+    //       { key: "nvarchar1,nvarchar3", match: "like", type: "text_or", value: "www" },
+    //       { key: "int2", match: ">=", type: "number", value: "0" },
+    //       { key: "int2", match: "<=", type: "number", value: "50" }
+    //     ]
+    //   },
+    //   { key: "mk_obj_name", value: "data" },
+    //   { key: "pageSize", value: 10 },
+    //   { key: "orderBy", value: "ID desc" },
+    //   { key: "pageIndex", value: 1 },
+    //   {
+    //     key: 'mk_excel_data',
+    //     value: [[`'1'`, `'2'`, `'3'`, `'4'`, `'5'`], [`'6'`, `'7'`, `'8'`, `'9'`, `'10'`]]
+    //   },
+    //   {
+    //     key: 'mk_outer_params',
+    //     value: [
+    //       {
+    //         tb: '#tb1',
+    //         keys: ['[nvarchar1]', '[nvarchar2]', '[nvarchar3]', '[mk_level]','[mk_id]','[mk_bid]'],
+    //         values: [[`'1'`, `'2'`, `'3'`, `'4'`, `'5'`, `'6'`], [`'7'`, `'8'`, `'9'`, `'10'`, `'11'`, `'12'`]]
+    //       },
+    //       {
+    //         tb: '@tb2',
+    //         keys: ['[field1]', '[field2]', '[field3]', '[mk_level]','[mk_id]','[mk_bid]'],
+    //         values: [[`'1'`, `'2'`, `'3'`, `'4'`, `'5'`, `'6'`], [`'7'`, `'8'`, `'9'`, `'10'`, `'11'`, `'12'`]]
+    //       }
+    //     ]
+    //   },
+    // ]
+
+    list.forEach(cell => {
+      if (cell.key === 'mk_outer_params') {
+        let mk_outer_params = []
+        cell.value.forEach(n => {
+          mk_outer_params.push(` Insert into ${n.tb} (${n.keys.join(',')}) `)
+          let vals = []
+          n.values.forEach(m => {
+            vals.push(` Select ${m.join(',')} `)
+          })
+          mk_outer_params.push(vals.join(' Union all '))
+        })
+        mk_outer_params = mk_outer_params.join('')
+        sql = sql.replace(/@mk_outer_params@/ig, mk_outer_params)
+      } else if (cell.key === 'mk_excel_data') {
+        let mk_excel_data = []
+        cell.value.forEach(n => {
+          mk_excel_data.push(`Select ${n.join(',')}`)
+        })
+        mk_excel_data = mk_excel_data.join(' Union all ')
+        sql = sql.replace(/@mk_excel_data@/ig, mk_excel_data)
+      } else if (cell.key === 'datam_begin' || cell.key === 'mk_check_begin') {
+        if (cell.value === 'Y') {
+          sql = sql.replace(new RegExp('@' + cell.key + '@', 'ig'), '/*')
+        } else {
+          sql = sql.replace(new RegExp('@' + cell.key + '@', 'ig'), '')
+        }
+      } else if (cell.key === 'datam_end' || cell.key === 'mk_check_end') {
+        if (cell.value === 'Y') {
+          sql = sql.replace(new RegExp('@' + cell.key + '@', 'ig'), '*/')
+        } else {
+          sql = sql.replace(new RegExp('@' + cell.key + '@', 'ig'), '')
+        }
+      } else if (cell.key === 'mk_search') {
+        let mk_search = []
+
+        cell.value.forEach(n => {
+          let str = n.match === 'like' || n.match === 'not like' ? '%' : ''
+          if (n.type === 'text_or') {
+            let vals = n.key.split(',').map(key => {
+              return `${key} ${n.match} '${str}${n.value}${str}'`
+            })
+
+            mk_search.push(`(${vals.join(' OR ')})`)
+          } else if (n.type === 'text_multi') {
+            mk_search.push(`'${n.value}' ${n.match} '%'+${n.key}+'%'`)
+          } else if (n.type === 'number') {
+            mk_search.push(`${n.key} ${n.match} ${n.value}`)
+          } else if (n.type === 'text_in') {
+            mk_search.push(`${n.key} in (select ID from dbo.SplitComma('${n.value}'))`)
+          } else {
+            mk_search.push(`${n.key} ${n.match} '${str}${n.value}${str}'`)
+          }
+        })
+
+        if (mk_search.length === 0) {
+          mk_search = ''
+        } else {
+          mk_search = 'where ' + mk_search.join(' AND ')
+        }
+
+        sql = sql.replace(/@mk_search@/ig, mk_search)
+      } else {
+        sql = sql.replace(new RegExp('@' + cell.key + '@', 'ig'), cell.value)
+      }
+    })
+
+    param.list = [
+      {
+        id: item.v_id,
+        regExps: list,
+        menuname: setting.$name || '',
+        s_debug_type: window.GLOB.probation ? 'Y' : '',
+        // md5_id: window.GLOB.probation ? md5(JSON.stringify(list)) : '',
+      }
+    ]
+
+    if (setting.database === 'sso' && window.GLOB.mainSystemApi) {
+      param.rduri = window.GLOB.mainSystemApi
     }
 
     return param
@@ -305,7 +571,7 @@
     let param = {
       func: 'sPC_Get_TableData',
       obj_name: 'data',
-      exec_type: 'y',
+      exec_type: window.GLOB.execType || 'y',
       arr_field: statFields.map(col => col.field).join(','),
       default_sql: setting.execute ? 'true' : 'false'
     }
@@ -343,15 +609,16 @@
       { reg: /@orderBy@/ig, value: orderBy },
       { reg: /@pageSize@/ig, value: 999999 },
       { reg: /@pageIndex@/ig, value: 1},
-      { reg: /\$select@/ig, value: '/*'},
-      { reg: /@select\$/ig, value: '*/'},
-      { reg: /@sum\$|\$sum@/ig, value: ''},
+      // { reg: /\$select@/ig, value: '/*'},
+      // { reg: /@select\$/ig, value: '*/'},
+      // { reg: /@sum\$|\$sum@/ig, value: ''},
       { reg: /@ID@/ig, value: `''`},
       { reg: /@BID@/ig, value: `'${BID || ''}'`},
       { reg: /@LoginUID@/ig, value: `'${sessionStorage.getItem('LoginUID') || ''}'`},
       { reg: /@SessionUid@/ig, value: `'${localStorage.getItem('SessionUid') || ''}'`},
       { reg: /@UserID@/ig, value: `'${sessionStorage.getItem('UserID') || ''}'`},
       { reg: /@Appkey@/ig, value: `'${window.GLOB.appkey || ''}'`},
+      { reg: /@lang@/ig, value: `'${sessionStorage.getItem('lang')}'`},
       { reg: /@typename@/ig, value: `'admin'`},
     )
 
@@ -386,16 +653,16 @@
 
     // 娴嬭瘯绯荤粺鎵撳嵃鏌ヨ璇彞
     if (window.GLOB.debugger === true) {
-      _customScript &&  console.info(`${setting.$name ? `/*${setting.$name} 鑷畾涔夎剼鏈� 缁熻鏌ヨ*/\n` : ''}${LText ? '' : '/*涓嶆墽琛岄粯璁ql*/\n'}${_customScript}`)
-      LText &&  console.info(`${setting.$name ? `/*${setting.$name} 鏁版嵁婧� 缁熻鏌ヨ*/\n` : ''}` + LText.replace(/\n\s{8}/ig, '\n'))
+      _customScript && window.mkInfo(`${setting.$name ? `/*${setting.$name} 鑷畾涔夎剼鏈� 缁熻鏌ヨ*/\n` : ''}${LText ? '' : '/*涓嶆墽琛岄粯璁ql*/\n'}${_customScript}`)
+      LText && window.mkInfo(`${setting.$name ? `/*${setting.$name} 鏁版嵁婧� 缁熻鏌ヨ*/\n` : ''}` + LText.replace(/\n\s{8}/ig, '\n'))
     }
 
     if (setting.$name) {
       param.menuname = setting.$name
     }
     
-    param.custom_script = Utils.formatOptions(_customScript)
-    param.LText = Utils.formatOptions(LText)
+    param.custom_script = Utils.formatOptions(_customScript, param.exec_type)
+    param.LText = Utils.formatOptions(LText, param.exec_type)
     param.DateCount = ''
 
     param.timestamp = moment().format('YYYY-MM-DD HH:mm:ss')
@@ -418,6 +685,46 @@
     }
 
     return param
+  }
+
+  /**
+   * @description 鏁版嵁鑾峰彇鎴愬姛
+   */
+  static querySuccess (result) {
+    if (!result.message) return
+
+    if (result.ErrCode === 'Y') {
+      Modal.success({
+        title: result.message
+      })
+    } else if (result.ErrCode === 'S') {
+      notification.success({
+        top: 92,
+        message: result.message,
+        duration: 2
+      })
+    }
+  }
+
+  /**
+   * @description 鏁版嵁鑾峰彇澶辫触
+   */
+  static queryFail (result) {
+    if (!result.message && result.ErrCode !== 'version_up') return
+    
+    if (result.ErrCode === 'N') {
+      Modal.error({
+        title: result.message,
+      })
+    } else if (result.ErrCode === 'version_up') {
+      MKEmitter.emit('reloadTabs')
+    } else if (result.ErrCode !== '-2') {
+      notification.error({
+        top: 92,
+        message: result.message,
+        duration: 10
+      })
+    }
   }
 }
 
@@ -443,21 +750,20 @@
     _customScript = _customScript.replace(item.reg, item.value)
   })
 
-  // _dataresource = _dataresource.replace(/@select\$|\$select@/ig, '')
-  // _customScript = _customScript.replace(/@select\$|\$select@/ig, '')
-  // _dataresource = _dataresource.replace(/\$sum@/ig, '/*')
-  // _dataresource = _dataresource.replace(/@sum\$/ig, '*/')
-  // _customScript = _customScript.replace(/\$sum@/ig, '/*')
-  // _customScript = _customScript.replace(/@sum\$/ig, '*/')
-
   let _search = ''
   if (setting.queryType !== 'statistics' && _dataresource) {
     _search = Utils.joinMainSearchkey(searchlist)
     _search = _search ? 'where ' + _search : ''
   }
 
-  if (setting.order && _dataresource) {
-    _dataresource = `select top 1000 ${setting.arr_field} from (select ${setting.arr_field} ,ROW_NUMBER() over(order by ${setting.order}) as rows from ${_dataresource} ${_search}) tmptable order by tmptable.rows `
+  if (setting.$top) {
+    if (setting.order && _dataresource) {
+      _dataresource = `select top 1 ${setting.arr_field} from ${_dataresource} ${_search} order by ${setting.order} `
+    } else if (_dataresource) {
+      _dataresource = `select top 1 ${setting.arr_field} from ${_dataresource} ${_search} `
+    }
+  } else if (setting.order && _dataresource) {
+    _dataresource = `select top 1000 ${setting.arr_field} from ${_dataresource} ${_search} order by ${setting.order} `
   } else if (_dataresource) {
     _dataresource = `select top 1000 ${setting.arr_field} from ${_dataresource} ${_search} `
   }
@@ -492,14 +798,12 @@
     primaryKey: setting.primaryKey || '',
     foreign_key: '',
     sql: _dataresource,
-    script: _customScript,
-    // transaction: setting.transaction === 'true'
+    script: _customScript
   }
 }
 
 /**
  * @description 鐢熸垚sPC_Get_structured_data璇锋眰鍙傛暟
- * 1銆佹妸澶ф帴鍙PC_Get_structured_data鐨刲text鎷嗘垚涓変唤锛岀涓�娈碉細@LText1锛岀浜屾@LText锛岀涓夋@LText2
  */
 export function getStructuredParams (params, config, BID) {
   let LText_field = []
@@ -514,6 +818,7 @@
     { reg: /@SessionUid@/ig, value: `'${localStorage.getItem('SessionUid') || ''}'`},
     { reg: /@UserID@/ig, value: `'${sessionStorage.getItem('UserID') || ''}'`},
     { reg: /@Appkey@/ig, value: `'${window.GLOB.appkey || ''}'`},
+    { reg: /@lang@/ig, value: `'${sessionStorage.getItem('lang')}'`},
     { reg: /@typename@/ig, value: `'admin'`},
   ]
 
@@ -535,8 +840,8 @@
 
     // 娴嬭瘯绯荤粺鎵撳嵃鏌ヨ璇彞
     if (window.GLOB.debugger === true) {
-      _script && console.info(`${item.$name ? `/*${item.$name} 鑷畾涔夎剼鏈紙鍚屾鏌ヨ锛�*/\n` : ''}${_sql ? '' : '/*涓嶆墽琛岄粯璁ql*/\n'}${_script}`)
-      _sql && console.info(`${item.$name ? `/*${item.$name} 鏁版嵁婧愶紙鍚屾鏌ヨ锛�*/\n` : ''}` + _sql)
+      _script && window.mkInfo(`${item.$name ? `/*${item.$name} 鑷畾涔夎剼鏈紙鍚屾鏌ヨ锛�*/\n` : ''}${_sql ? '' : '/*涓嶆墽琛岄粯璁ql*/\n'}${_script}`)
+      _sql && window.mkInfo(`${item.$name ? `/*${item.$name} 鏁版嵁婧愶紙鍚屾鏌ヨ锛�*/\n` : ''}` + _sql)
     }
 
     item.columns.forEach(cell => {
@@ -547,23 +852,16 @@
 
   let param = {
     func: 'sPC_Get_structured_data',
-    LText: _LText.join(' union all '),
-    LText_field: LText_field.join(' union all '),
     BID: BID,
     username: sessionStorage.getItem('User_Name') || '',
     fullName: sessionStorage.getItem('Full_Name') || ''
   }
 
-  if (config.MenuName) {
-    param.menuname = config.MenuName
-  }
+  param.menuname = config.MenuName || config.$menuname || ''
 
-  let { LText, LText1, LText2 } = Utils.sPCInUpDeFormatOptions(param.LText)
-
-  param.LText1 = LText1
-  param.LText = LText
-  param.LText2 = LText2
-  param.LText_field = Utils.formatOptions(param.LText_field)
+  param.exec_type = window.GLOB.execType || 'y'
+  param.LText = Utils.formatOptions(_LText.join(' union all '), param.exec_type)
+  param.custom_script = Utils.formatOptions(LText_field.join(' union all '), param.exec_type)
 
   if (config.cacheUseful === 'true') {
     param.time_type = config.timeUnit
@@ -575,7 +873,7 @@
   }
 
   param.timestamp = moment().format('YYYY-MM-DD HH:mm:ss')
-  param.secretkey = Utils.encrypt(param.LText, param.timestamp)
+  param.secretkey = Utils.encrypt('', param.timestamp)
 
   return param
 }
\ No newline at end of file

--
Gitblit v1.8.0