From f71bb7d6a8907b9219f39361725e94c28259bd61 Mon Sep 17 00:00:00 2001 From: king <18310653075@163.com> Date: 星期二, 06 四月 2021 18:01:00 +0800 Subject: [PATCH] 2021-04-06 --- src/utils/utils-datamanage.js | 141 +++++++++++++++++++++++++++++++++++++--------- 1 files changed, 113 insertions(+), 28 deletions(-) diff --git a/src/utils/utils-datamanage.js b/src/utils/utils-datamanage.js index a8e6dbc..f684846 100644 --- a/src/utils/utils-datamanage.js +++ b/src/utils/utils-datamanage.js @@ -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,8 +102,8 @@ 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} ` } @@ -110,14 +111,6 @@ 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,11 +118,14 @@ } }) regoptions.push({ + reg: new RegExp('@login_city@', 'ig'), + value: `'${city}'` + }, { reg: new RegExp('@userName@', 'ig'), - value: userName + value: `'${userName}'` }, { reg: new RegExp('@fullName@', 'ig'), - value: fullName + value: `'${fullName}'` }, { reg: new RegExp('@orderBy@', 'ig'), value: orderBy @@ -202,6 +198,8 @@ 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,9 +224,18 @@ 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} ` } @@ -236,13 +243,6 @@ 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,11 +251,14 @@ } }) regoptions.push({ + reg: new RegExp('@login_city@', 'ig'), + value: `'${city}'` + }, { reg: new RegExp('@userName@', 'ig'), - value: userName + value: `'${userName}'` }, { reg: new RegExp('@fullName@', 'ig'), - value: fullName + value: `'${fullName}'` }, { reg: new RegExp('@orderBy@', 'ig'), value: orderBy @@ -366,6 +369,7 @@ 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') || '' @@ -380,8 +384,8 @@ if (sql) { sql = `/*鍓嶇疆鑴氭湰*/ - declare @ErrorCode nvarchar(50),@retmsg nvarchar(4000),@UserName nvarchar(50),@FullName nvarchar(50) - Select @ErrorCode='',@retmsg ='',@UserName='${userName}', @FullName='${fullName}' + 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!='' @@ -396,11 +400,14 @@ } }) regoptions.push({ + reg: new RegExp('@login_city@', 'ig'), + value: `'${city}'` + }, { reg: new RegExp('@userName@', 'ig'), - value: userName + value: `'${userName}'` }, { reg: new RegExp('@fullName@', 'ig'), - value: fullName + value: `'${fullName}'` }) regoptions.forEach(item => { @@ -441,8 +448,18 @@ func: 'sPC_TableData_InUpDe', exec_type: 'y', } - let _prevCustomScript = `declare @ErrorCode nvarchar(50),@retmsg nvarchar(4000) - Select @ErrorCode='',@retmsg='' + + 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 = ` @@ -490,4 +507,72 @@ 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 { + 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