From e543372cc70a19ff2630c79d8421c2c593e54e5f Mon Sep 17 00:00:00 2001
From: king <18310653075@163.com>
Date: 星期三, 02 六月 2021 17:15:21 +0800
Subject: [PATCH] 2021-06-02

---
 src/utils/utils-datamanage.js |  324 ++++++++++++++++++++++++++++++++++++++++++++++++------
 1 files changed, 288 insertions(+), 36 deletions(-)

diff --git a/src/utils/utils-datamanage.js b/src/utils/utils-datamanage.js
index a30cbeb..b995699 100644
--- a/src/utils/utils-datamanage.js
+++ b/src/utils/utils-datamanage.js
@@ -18,7 +18,7 @@
   static getQueryDataParams (setting, arrFields, search = [], orderBy = '', pageIndex = 1, pageSize = 10, BID, menuType, id) {
     let param = null
 
-    if (setting.interType === 'system' || (setting.interType === 'inner' && !setting.innerFunc)) {
+    if (setting.interType === 'system' || (setting.interType === 'custom' && setting.requestMode === 'system')) {
       param = this.getDefaultQueryParam(setting, arrFields, search, orderBy, pageIndex, pageSize, menuType, id)
     } else {
       param = this.getCustomQueryParam(setting, search, orderBy, pageIndex, pageSize, menuType, id)
@@ -52,7 +52,7 @@
       param.PageSize = pageSize
     }
 
-    if (setting.interType === 'inner') {
+    if (setting.interType === 'inner' || (setting.interType === 'custom' && setting.requestMode === 'inner')) {
       param.func = setting.innerFunc
     } else {
       if (menuType === 'HS') {
@@ -91,6 +91,7 @@
 
     let userName = sessionStorage.getItem('User_Name') || ''
     let fullName = sessionStorage.getItem('Full_Name') || ''
+    let city = sessionStorage.getItem('city') || ''
 
     if (sessionStorage.getItem('isEditState') === 'true') {
       userName = sessionStorage.getItem('CloudUserName') || ''
@@ -101,23 +102,22 @@
     let _customScript = ''
     
     if (setting.customScript) {
-      _customScript = `declare @ErrorCode nvarchar(50),@retmsg nvarchar(4000),@UserName nvarchar(50),@FullName nvarchar(50)
-        Select @ErrorCode='',@retmsg ='',@UserName='${userName}', @FullName='${fullName}'
+      _customScript = `declare @ErrorCode nvarchar(50),@retmsg nvarchar(4000),@UserName nvarchar(50),@FullName nvarchar(50),@login_city nvarchar(50)
+        Select @ErrorCode='',@retmsg ='',@UserName='${userName}', @FullName='${fullName}', @login_city='${city}'
         ${setting.customScript}
       `
     }
 
+    _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 regoptions = null
     if (setting.queryType === 'statistics' || _customScript) {
       let allSearch = Utils.getAllSearchOptions(search)
-      let userName = sessionStorage.getItem('User_Name') || ''
-      let fullName = sessionStorage.getItem('Full_Name') || ''
-
-      if (sessionStorage.getItem('isEditState') === 'true') {
-        userName = sessionStorage.getItem('CloudUserName') || ''
-        fullName = sessionStorage.getItem('CloudFullName') || ''
-      }
-
       regoptions = allSearch.map(item => {
         return {
           reg: new RegExp('@' + item.key + '@', 'ig'),
@@ -125,12 +125,6 @@
         }
       })
       regoptions.push({
-        reg: new RegExp('@userName@', 'ig'),
-        value: userName
-      }, {
-        reg: new RegExp('@fullName@', 'ig'),
-        value: fullName
-      }, {
         reg: new RegExp('@orderBy@', 'ig'),
         value: orderBy
       }, {
@@ -194,13 +188,15 @@
 
     // 娴嬭瘯绯荤粺鎵撳嵃鏌ヨ璇彞
     if ((options.sysType === 'local' && !window.GLOB.systemType) || window.debugger === true) {
-      _customScript &&  console.info(`${LText ? '' : '/*涓嶆墽琛岄粯璁ql*/\n'}${_customScript}`)
-      LText &&  console.info(LText)
+      _customScript &&  console.info(`${setting.$name ? `/*缁勪欢-${setting.$name} 鑷畾涔夎剼鏈�*/\n` : ''}${LText ? '' : '/*涓嶆墽琛岄粯璁ql*/\n'}${_customScript}`)
+      LText &&  console.info(`${setting.$name ? `/*缁勪欢-${setting.$name} 鏁版嵁婧�*/\n` : ''}` + LText)
     }
 
     param.custom_script = Utils.formatOptions(_customScript)
     param.LText = Utils.formatOptions(LText)
     param.DateCount = Utils.formatOptions(DateCount)
+
+    // exec_type: 'y' 瑙g爜瀛楁锛歀Text銆丩Text1銆丩Text2銆乧ustom_script銆丏ateCount
 
     param.timestamp = moment().format('YYYY-MM-DD HH:mm:ss')
     param.secretkey = Utils.encrypt('', param.timestamp)
@@ -226,23 +222,32 @@
     
     let _dataresource = setting.dataresource
     let _customScript = ''
+    let userName = sessionStorage.getItem('User_Name') || ''
+    let fullName = sessionStorage.getItem('Full_Name') || ''
+    let city = sessionStorage.getItem('city') || ''
+
+    if (sessionStorage.getItem('isEditState') === 'true') {
+      userName = sessionStorage.getItem('CloudUserName') || ''
+      fullName = sessionStorage.getItem('CloudFullName') || ''
+    }
     
     if (setting.customScript) {
-      _customScript = `declare @ErrorCode nvarchar(50),@retmsg nvarchar(4000) select @ErrorCode='',@retmsg =''
+      _customScript = `declare @ErrorCode nvarchar(50),@retmsg nvarchar(4000),@UserName nvarchar(50),@FullName nvarchar(50),@login_city nvarchar(50)
+        Select @ErrorCode='',@retmsg ='',@UserName='${userName}', @FullName='${fullName}', @login_city='${city}'
         ${setting.customScript}
       `
     }
 
+    _dataresource = _dataresource.replace(/@sum\$|\$sum@/ig, '')
+    _customScript = _customScript.replace(/@sum\$|\$sum@/ig, '')
+    _dataresource = _dataresource.replace(/\$select@/ig, '/*')
+    _dataresource = _dataresource.replace(/@select\$/ig, '*/')
+    _customScript = _customScript.replace(/\$select@/ig, '/*')
+    _customScript = _customScript.replace(/@select\$/ig, '*/')
+
     let regoptions = null
     if (setting.queryType === 'statistics' || _customScript) {
       let allSearch = Utils.getAllSearchOptions(search)
-      let userName = sessionStorage.getItem('User_Name') || ''
-      let fullName = sessionStorage.getItem('Full_Name') || ''
-
-      if (sessionStorage.getItem('isEditState') === 'true') {
-        userName = sessionStorage.getItem('CloudUserName') || ''
-        fullName = sessionStorage.getItem('CloudFullName') || ''
-      }
 
       regoptions = allSearch.map(item => {
         return {
@@ -251,12 +256,6 @@
         }
       })
       regoptions.push({
-        reg: new RegExp('@userName@', 'ig'),
-        value: userName
-      }, {
-        reg: new RegExp('@fullName@', 'ig'),
-        value: fullName
-      }, {
         reg: new RegExp('@orderBy@', 'ig'),
         value: orderBy
       }, {
@@ -277,6 +276,7 @@
       regoptions.forEach(item => {
         _dataresource = _dataresource.replace(item.reg, item.value)
       })
+      _search = ''
     }
 
     if (_customScript) {
@@ -297,8 +297,8 @@
 
     // 娴嬭瘯绯荤粺鎵撳嵃鏌ヨ璇彞
     if ((options.sysType === 'local' && !window.GLOB.systemType) || window.debugger === true) {
-      _customScript &&  console.info(`${LText ? '' : '/*涓嶆墽琛岄粯璁ql*/\n'}${_customScript}`)
-      LText &&  console.info(LText)
+      _customScript &&  console.info(`${setting.$name ? `/*缁勪欢-${setting.$name} 鑷畾涔夎剼鏈� 缁熻鏌ヨ*/\n` : ''}${LText ? '' : '/*涓嶆墽琛岄粯璁ql*/\n'}${_customScript}`)
+      LText &&  console.info(`${setting.$name ? `/*缁勪欢-${setting.$name} 鏁版嵁婧� 缁熻鏌ヨ*/\n` : ''}` + LText)
     }
     
     param.custom_script = Utils.formatOptions(_customScript)
@@ -323,4 +323,256 @@
 
     return param
   }
+
+  /**
+   * @description 鏁版嵁婧愬悕绉帮紝鐢ㄤ簬缁熶竴鏌ヨ
+   * @param {Object}   setting      鏁版嵁婧愯缃�
+   * @param {String}   arrFields    鏌ヨ瀛楁
+   * @param {Array}    search       鎼滅储鏉′欢
+   * @param {String}   orderBy      鎺掑簭鏂瑰紡
+   * @param {Number}   pageIndex    椤电爜
+   * @param {Number}   pageSize     姣忛〉鏁伴噺
+   * @param {String}   BID          涓婄骇ID
+   * @param {String}   menuType     鑿滃崟绫诲瀷锛屾櫘閫氳彍鍗曚笌HS
+   * @return {Object}  param
+   */
+  static getPrevQueryParams (setting, search = [], BID, menuType) {
+    let param = null
+
+    if (setting.procMode !== 'inner') {
+      param = this.getDefaultPrevQueryParam(setting, search, menuType)
+    } else {
+      param = Utils.formatCustomMainSearch(search)
+      param.func = setting.prevFunc || ''
+    }
+
+    if (BID) {
+      param.BID = BID
+    }
+
+    return param
+  }
+
+  /**
+   * @description 鑾峰彇绯荤粺鍓嶇疆鑴氭湰
+   */
+  static getDefaultPrevQueryParam (setting, search, menuType) {
+    let param = {
+      func: 'sPC_TableData_InUpDe',
+      exec_type: 'y',
+      script_type: 'Y'
+    }
+
+    let sql = ''
+    let userName = sessionStorage.getItem('User_Name') || ''
+    let fullName = sessionStorage.getItem('Full_Name') || ''
+    let city = sessionStorage.getItem('city') || ''
+
+    if (sessionStorage.getItem('isEditState') === 'true') {
+      userName = sessionStorage.getItem('CloudUserName') || ''
+      fullName = sessionStorage.getItem('CloudFullName') || ''
+    }
+
+    setting.preScripts.forEach(item => {
+      if (item.status === 'false') return
+      sql += `${item.sql}
+      `
+    })
+
+    if (sql) {
+      sql = `/*鍓嶇疆鑴氭湰*/
+        declare @ErrorCode nvarchar(50),@retmsg nvarchar(4000),@UserName nvarchar(50),@FullName nvarchar(50),@login_city nvarchar(50)
+        Select @ErrorCode='',@retmsg ='',@UserName='${userName}', @FullName='${fullName}', @login_city='${city}'
+        ${sql}
+        aaa:
+          if @ErrorCode!=''
+            insert into tmp_err_retmsg (ID, ErrorCode, retmsg, CreateUserID) select @time_id@,@ErrorCode, @retmsg,@UserID@
+      `
+
+      let allSearch = Utils.getAllSearchOptions(search)
+      let regoptions = allSearch.map(item => {
+        return {
+          reg: new RegExp('@' + item.key + '@', 'ig'),
+          value: `'${item.value}'`
+        }
+      })
+      regoptions.push({
+        reg: new RegExp('@login_city@', 'ig'),
+        value: `'${city}'`
+      }, {
+        reg: new RegExp('@userName@', 'ig'),
+        value: `'${userName}'`
+      }, {
+        reg: new RegExp('@fullName@', 'ig'),
+        value: `'${fullName}'`
+      })
+
+      regoptions.forEach(item => {
+        sql = sql.replace(item.reg, item.value)
+      })
+
+      // 娴嬭瘯绯荤粺鎵撳嵃鏌ヨ璇彞
+      if ((options.sysType === 'local' && !window.GLOB.systemType) || window.debugger === true) {
+        console.info(sql.replace(/\n\s{8}/ig, '\n'))
+      }
+    }
+
+    if (sessionStorage.getItem('dataM') === 'true') { // 鏁版嵁鏉冮檺
+      sql = sql.replace(/\$@/ig, '/*')
+      sql = sql.replace(/@\$/ig, '*/')
+    } else {
+      sql = sql.replace(/@\$|\$@/ig, '')
+    }
+
+    param.LText = Utils.formatOptions(sql)
+    param.timestamp = moment().format('YYYY-MM-DD HH:mm:ss')
+    param.secretkey = Utils.encrypt('', param.timestamp)
+
+    if (menuType === 'HS') { // 鍑芥暟 sPC_TableData_InUpDe 浜戠楠岃瘉
+      param.open_key = Utils.encryptOpenKey(param.secretkey, param.timestamp)
+    }
+
+    param.menuname = setting.MenuName || ''
+
+    return param
+  }
+
+  /**
+   * @description 鑾峰彇绯荤粺鍥炶皟鑴氭湰
+   */
+  static getCallBackQueryParams (setting, sql, errSql) {
+    let param = {
+      func: 'sPC_TableData_InUpDe',
+      exec_type: 'y',
+    }
+
+    let userName = sessionStorage.getItem('User_Name') || ''
+    let fullName = sessionStorage.getItem('Full_Name') || ''
+    let city = sessionStorage.getItem('city') || ''
+
+    if (sessionStorage.getItem('isEditState') === 'true') {
+      userName = sessionStorage.getItem('CloudUserName') || ''
+      fullName = sessionStorage.getItem('CloudFullName') || ''
+    }
+
+    let _prevCustomScript = `declare @ErrorCode nvarchar(50),@retmsg nvarchar(4000),@UserName nvarchar(50),@FullName nvarchar(50),@login_city nvarchar(50)
+        Select @ErrorCode='',@retmsg='',@UserName='${userName}', @FullName='${fullName}', @login_city='${city}'
+        ${errSql}
+    `
+    let _backCustomScript = `
+    `
+
+    setting.cbScripts.forEach(script => {
+      if (script.status === 'false') return
+
+      if (script.position === 'front') {
+        _prevCustomScript += `
+        /* 鑷畾涔夎剼鏈� */
+        ${script.sql}
+        `
+      } else {
+        _backCustomScript += `
+        /* 鑷畾涔夎剼鏈� */
+        ${script.sql}
+        `
+      }
+    })
+
+    _backCustomScript += `
+      aaa: select @ErrorCode as ErrorCode,@retmsg as retmsg`
+
+    sql = _prevCustomScript + sql
+    sql = sql + _backCustomScript
+
+    if ((window.GLOB.systemType !== 'production' && options.sysType !== 'cloud') || window.debugger === true) {
+      console.info(sql.replace(/\n\s{8}/ig, '\n'))
+    }
+
+    param.LText = sql
+    
+    if (sessionStorage.getItem('dataM') === 'true') { // 鏁版嵁鏉冮檺
+      param.LText = param.LText.replace(/\$@/ig, '/*')
+      param.LText = param.LText.replace(/@\$/ig, '*/')
+    } else {
+      param.LText = param.LText.replace(/@\$|\$@/ig, '')
+    }
+
+    param.timestamp = moment().format('YYYY-MM-DD HH:mm:ss')
+    param.secretkey = Utils.encrypt('', param.timestamp)
+    param.LText = Utils.formatOptions(param.LText)
+    param.menuname = setting.MenuName || ''
+
+    return param
+  }
+
+  /**
+   * @description 鑾峰彇鍥炶皟sql
+   */
+  static getCallBackSql (setting, result) {
+    let lines = []
+    let pre = setting.callbackType === 'script' ? '@' : ''
+
+    let getDefaultSql = (obj, tb, bid, level) => {
+      let keys = []
+      let vals = []
+      let subObjs = []
+      let id = Utils.getuuid()
+
+      delete obj.$$key
+
+      Object.keys(obj).forEach(key => {
+        let val = obj[key]
+        if (val === null || val === undefined) return
+        if (typeof(val) === 'object') {
+          if (Array.isArray(val)) {
+            val.forEach(item => {
+              if (typeof(item) !== 'object' || Array.isArray(item)) return
+              if (Object.keys(item).length > 0) {
+                item.$$key = tb + '_' + key
+                subObjs.push(item)
+              }
+            })
+          } else if (Object.keys(val).length > 0) {
+            val.$$key = tb + '_' + key
+            subObjs.push(val)
+          }
+        } else {
+          if (typeof(val) === 'string') {
+            val = val.replace(/'/ig, '"')
+          }
+          keys.push(key)
+          vals.push(`'${val}'`)
+        }
+      })
+
+      lines.push({
+        table: tb,
+        insert: `Insert into ${pre}${tb} (${keys.join(',')},mk_level,mk_id,mk_bid)`,
+        select: `Select ${vals.join(',')},'${level}','${id}','${bid}'`
+      })
+
+      subObjs.forEach(item => {
+        getDefaultSql(item, item.$$key, id, level + 1)
+      })
+    }
+    
+    getDefaultSql(result, setting.cbTable, '', 1)
+
+    let lineMap = new Map()
+    lines.forEach(line => {
+      if (lineMap.has(line.table)) {
+        let _line = lineMap.get(line.table)
+        _line.selects.push(line.select)
+        lineMap.set(line.table, _line)
+      } else {
+        lineMap.set(line.table, {
+          table: line.table,
+          insert: line.insert,
+          selects: [line.select]
+        })
+      }
+    })
+
+    return [...lineMap.values()]
+  }
 }
\ No newline at end of file

--
Gitblit v1.8.0