From dfb7b774d9934f4f5b3edf1a39bf73be9c90c55d Mon Sep 17 00:00:00 2001 From: king <18310653075@163.com> Date: 星期五, 13 十一月 2020 15:44:57 +0800 Subject: [PATCH] 移出数据表 --- src/utils/utils-datamanage.js | 144 +++++++++++++++++++++++++++++++++++++++++++++-- 1 files changed, 136 insertions(+), 8 deletions(-) diff --git a/src/utils/utils-datamanage.js b/src/utils/utils-datamanage.js index d20a826..d214736 100644 --- a/src/utils/utils-datamanage.js +++ b/src/utils/utils-datamanage.js @@ -6,7 +6,6 @@ /** * @description 鏁版嵁婧愬悕绉帮紝鐢ㄤ簬缁熶竴鏌ヨ * @param {Object} setting 鏁版嵁婧愯缃� - * @param {String} customScript 鑷畾涔夎剼鏈� * @param {String} arrFields 鏌ヨ瀛楁 * @param {Array} search 鎼滅储鏉′欢 * @param {String} orderBy 鎺掑簭鏂瑰紡 @@ -17,11 +16,11 @@ * @param {Boolean} dataManager 鏁版嵁鏉冮檺 * @return {Object} param */ - static getQueryDataParams (setting, customScript, arrFields, search = [], orderBy = '', pageIndex = 1, pageSize = 10, BID, menuType, dataManager) { + static getQueryDataParams (setting, arrFields, search = [], orderBy = '', pageIndex = 1, pageSize = 10, BID, menuType, dataManager) { let param = null if (setting.interType === 'system' || (setting.interType === 'inner' && !setting.innerFunc)) { - param = this.getDefaultQueryParam(setting, customScript, arrFields, search, orderBy, pageIndex, pageSize, menuType) + param = this.getDefaultQueryParam(setting, arrFields, search, orderBy, pageIndex, pageSize, menuType) } else { param = this.getCustomQueryParam(setting, search, orderBy, pageIndex, pageSize, menuType) } @@ -80,20 +79,33 @@ /** * @description 鑾峰彇绯荤粺瀛樺偍杩囩▼ sPC_Get_TableData 鐨勫弬鏁� */ - static getDefaultQueryParam (setting, customScript, arrFields, search, orderBy, pageIndex, pageSize, menuType) { + static getDefaultQueryParam (setting, arrFields, search, orderBy, pageIndex, pageSize, menuType) { let param = { func: 'sPC_Get_TableData', obj_name: 'data', arr_field: arrFields, default_sql: setting.execute ? 'true' : 'false' } - + let _dataresource = setting.dataresource - let _customScript = customScript + let _customScript = '' + + if (setting.customScript) { + _customScript = `declare @ErrorCode nvarchar(50),@retmsg nvarchar(4000) select @ErrorCode='',@retmsg ='' + ${setting.customScript} + ` + } 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 { @@ -102,6 +114,12 @@ } }) regoptions.push({ + reg: new RegExp('@userName@', 'ig'), + value: userName + }, { + reg: new RegExp('@fullName@', 'ig'), + value: fullName + }, { reg: new RegExp('@orderBy@', 'ig'), value: orderBy }, { @@ -168,12 +186,122 @@ param.custom_script = Utils.formatOptions(_customScript) param.LText = Utils.formatOptions(LText) - param.timestamp = moment().format('YYYY-MM-DD HH:mm:ss') + '.000' + param.timestamp = moment().format('YYYY-MM-DD HH:mm:ss') param.secretkey = Utils.encrypt(param.LText, param.timestamp) param.DateCount = Utils.formatOptions(DateCount) if (menuType === 'HS') { // 浜戠鏁版嵁楠岃瘉 - param.open_key = Utils.encrypt(param.secretkey, param.timestamp, true) + param.open_key = Utils.encryptOpenKey(param.secretkey, param.timestamp) + } + + return param + } + + /** + * @description 鑾峰彇绯荤粺瀛樺偍杩囩▼ sPC_Get_TableData 鍚堣鍊肩殑鍙傛暟 + */ + static getStatQueryDataParams (setting, statFields, search, orderBy, BID, menuType, dataManager) { + let param = { + func: 'sPC_Get_TableData', + obj_name: 'data', + arr_field: statFields.map(col => col.field).join(','), + default_sql: setting.execute ? 'true' : 'false' + } + + let _dataresource = setting.dataresource + let _customScript = '' + + if (setting.customScript) { + _customScript = `declare @ErrorCode nvarchar(50),@retmsg nvarchar(4000) select @ErrorCode='',@retmsg ='' + ${setting.customScript} + ` + } + + 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'), + value: `'${item.value}'` + } + }) + regoptions.push({ + reg: new RegExp('@userName@', 'ig'), + value: userName + }, { + reg: new RegExp('@fullName@', 'ig'), + value: fullName + }, { + reg: new RegExp('@orderBy@', 'ig'), + value: orderBy + }, { + reg: new RegExp('@pageSize@', 'ig'), + value: 999999 + }, { + reg: new RegExp('@pageIndex@', 'ig'), + value: 1 + }) + } + + let _search = Utils.joinMainSearchkey(search) + if (_search) { + _search = 'where ' + _search + } + + if (setting.queryType === 'statistics') { // 缁熻鏁版嵁婧愶紝鍐呭鏇挎崲 + regoptions.forEach(item => { + _dataresource = _dataresource.replace(item.reg, item.value) + }) + } + + if (_customScript) { + regoptions.forEach(item => { + _customScript = _customScript.replace(item.reg, item.value) + }) + } + + let LText = ` select ${statFields.map(col => `isnull(sum(${col.field}),0) as ${col.field}`).join(',')} from ${_dataresource} ${_search} ` + + if (_customScript) { + LText = `${LText} + aaa: + if @ErrorCode!='' + insert into tmp_err_retmsg (ID, ErrorCode, retmsg, CreateUserID) select @time_id@,@ErrorCode, @retmsg,@UserID@ + ` + } + + // 娴嬭瘯绯荤粺鎵撳嵃鏌ヨ璇彞 + if ((options.sysType === 'local' && !window.GLOB.systemType) || window.debugger === true) { + _customScript && console.log(`${LText ? '' : '/*涓嶆墽琛岄粯璁ql*/\n'}${_customScript}`) + LText && console.log(LText) + } + + param.custom_script = Utils.formatOptions(_customScript) + param.LText = Utils.formatOptions(LText) + param.timestamp = moment().format('YYYY-MM-DD HH:mm:ss') + param.secretkey = Utils.encrypt(param.LText, param.timestamp) + param.DateCount = '' + + if (menuType === 'HS') { // 浜戠鏁版嵁楠岃瘉 + param.open_key = Utils.encryptOpenKey(param.secretkey, param.timestamp) + } + + if (BID) { + param.BID = BID + } + + // 鏁版嵁绠$悊鏉冮檺 + if (dataManager) { + param.dataM = 'Y' } return param -- Gitblit v1.8.0