From d17368d4a5bdec6db2d8a85c7901cdb25cc59cd4 Mon Sep 17 00:00:00 2001
From: king <18310653075@163.com>
Date: 星期一, 11 十月 2021 15:16:25 +0800
Subject: [PATCH] 2021-10-11
---
src/utils/utils-datamanage.js | 341 +++++++++++++++++++++++++++++++++++++++++++++++++-------
1 files changed, 298 insertions(+), 43 deletions(-)
diff --git a/src/utils/utils-datamanage.js b/src/utils/utils-datamanage.js
index a8e6dbc..dc9d801 100644
--- a/src/utils/utils-datamanage.js
+++ b/src/utils/utils-datamanage.js
@@ -1,3 +1,4 @@
+import md5 from 'md5'
import moment from 'moment'
import options from '@/store/options.js'
import Utils from './utils.js'
@@ -65,7 +66,7 @@
if (setting.sysInterface === 'true' && window.GLOB.mainSystemApi) {
param.rduri = window.GLOB.mainSystemApi
} else if (setting.sysInterface !== 'true') {
- param.rduri = setting.interface
+ param.rduri = window.GLOB.systemType === 'production' ? (setting.proInterface || setting.interface) : setting.interface
}
}
@@ -89,8 +90,16 @@
default_sql: setting.execute ? 'true' : 'false'
}
+ if (setting.transaction === 'true') {
+ param.func = 'sPC_Get_TableData_try'
+ }
+
let userName = sessionStorage.getItem('User_Name') || ''
let fullName = sessionStorage.getItem('Full_Name') || ''
+ let RoleID = sessionStorage.getItem('role_id') || ''
+ let departmentcode = sessionStorage.getItem('departmentcode') || ''
+ let organization = sessionStorage.getItem('organization') || ''
+ let city = sessionStorage.getItem('city') || ''
if (sessionStorage.getItem('isEditState') === 'true') {
userName = sessionStorage.getItem('CloudUserName') || ''
@@ -101,23 +110,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),@RoleID nvarchar(512),@departmentcode nvarchar(50),@organization nvarchar(50),@login_city nvarchar(50)
+ Select @ErrorCode='',@retmsg ='',@UserName='${userName}', @FullName='${fullName}', @RoleID='${RoleID}', @departmentcode='${departmentcode}', @organization='${organization}', @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 +133,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 +196,19 @@
// 娴嬭瘯绯荤粺鎵撳嵃鏌ヨ璇彞
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)
+ }
+
+ if (setting.$name) {
+ param.menuname = setting.$name
}
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)
@@ -223,26 +231,42 @@
arr_field: statFields.map(col => col.field).join(','),
default_sql: setting.execute ? 'true' : 'false'
}
+
+ if (setting.transaction === 'true') {
+ param.func = 'sPC_Get_TableData_try'
+ }
let _dataresource = setting.dataresource
let _customScript = ''
+ let userName = sessionStorage.getItem('User_Name') || ''
+ let fullName = sessionStorage.getItem('Full_Name') || ''
+ let RoleID = sessionStorage.getItem('role_id') || ''
+ let departmentcode = sessionStorage.getItem('departmentcode') || ''
+ let organization = sessionStorage.getItem('organization') || ''
+ 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),@RoleID nvarchar(512),@departmentcode nvarchar(50),@organization nvarchar(50),@login_city nvarchar(50)
+ Select @ErrorCode='',@retmsg ='',@UserName='${userName}', @FullName='${fullName}', @RoleID='${RoleID}', @departmentcode='${departmentcode}', @organization='${organization}', @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 +275,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 +295,7 @@
regoptions.forEach(item => {
_dataresource = _dataresource.replace(item.reg, item.value)
})
+ _search = ''
}
if (_customScript) {
@@ -297,8 +316,12 @@
// 娴嬭瘯绯荤粺鎵撳嵃鏌ヨ璇彞
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)
+ }
+
+ if (setting.$name) {
+ param.menuname = setting.$name
}
param.custom_script = Utils.formatOptions(_customScript)
@@ -354,7 +377,7 @@
}
/**
- * @description 鑾峰彇绯荤粺瀛樺偍杩囩▼ sPC_Get_TableData 鐨勫弬鏁�
+ * @description 鑾峰彇绯荤粺鍓嶇疆鑴氭湰
*/
static getDefaultPrevQueryParam (setting, search, menuType) {
let param = {
@@ -366,6 +389,10 @@
let sql = ''
let userName = sessionStorage.getItem('User_Name') || ''
let fullName = sessionStorage.getItem('Full_Name') || ''
+ let RoleID = sessionStorage.getItem('role_id') || ''
+ let departmentcode = sessionStorage.getItem('departmentcode') || ''
+ let organization = sessionStorage.getItem('organization') || ''
+ let city = sessionStorage.getItem('city') || ''
if (sessionStorage.getItem('isEditState') === 'true') {
userName = sessionStorage.getItem('CloudUserName') || ''
@@ -380,8 +407,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),@RoleID nvarchar(512),@departmentcode nvarchar(50),@organization nvarchar(50),@login_city nvarchar(50)
+ Select @ErrorCode='',@retmsg ='',@UserName='${userName}', @FullName='${fullName}', @RoleID='${RoleID}', @departmentcode='${departmentcode}', @organization='${organization}', @login_city='${city}'
${sql}
aaa:
if @ErrorCode!=''
@@ -396,11 +423,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 => {
@@ -434,15 +464,28 @@
}
/**
- * @description 鑾峰彇绯荤粺瀛樺偍杩囩▼ sPC_Get_TableData 鐨勫弬鏁�
+ * @description 鑾峰彇绯荤粺鍥炶皟鑴氭湰
*/
static getCallBackQueryParams (setting, sql, errSql) {
let param = {
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 RoleID = sessionStorage.getItem('role_id') || ''
+ let departmentcode = sessionStorage.getItem('departmentcode') || ''
+ let organization = sessionStorage.getItem('organization') || ''
+ 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),@RoleID nvarchar(512),@departmentcode nvarchar(50),@organization nvarchar(50),@login_city nvarchar(50)
+ Select @ErrorCode='',@retmsg='',@UserName='${userName}', @FullName='${fullName}', @RoleID='${RoleID}', @departmentcode='${departmentcode}', @organization='${organization}', @login_city='${city}'
${errSql}
`
let _backCustomScript = `
@@ -490,4 +533,216 @@
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()]
+ }
+}
+
+/**
+ * @description 鐢熸垚鍗曚釜缁勪欢sPC_Get_structured_data璇锋眰鍙傛暟
+ */
+export function getStructDefaultParam (component, searchlist, first) {
+ const { columns, setting, dataName, format } = component
+
+ let arr_field = columns.map(col => col.field)
+ let _dataresource = setting.dataresource
+ let _customScript = setting.customScript
+
+ if (setting.queryType === 'statistics' || _customScript) {
+ let allSearch = Utils.getAllSearchOptions(searchlist)
+ let regoptions = allSearch.map(item => {
+ return {
+ reg: new RegExp('@' + item.key + '@', 'ig'),
+ value: `'${item.value}'`
+ }
+ })
+
+ regoptions.forEach(item => {
+ if (_dataresource && setting.queryType === 'statistics') {
+ _dataresource = _dataresource.replace(item.reg, item.value)
+ }
+ _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 ${arr_field.join(',')} from (select ${arr_field.join(',')} ,ROW_NUMBER() over(order by ${setting.order}) as rows from ${_dataresource} ${_search}) tmptable order by tmptable.rows `
+ } else if (_dataresource) {
+ _dataresource = `select top 1000 ${arr_field.join(',')} from ${_dataresource} ${_search} `
+ }
+
+ if (first) {
+ let userName = sessionStorage.getItem('User_Name') || ''
+ let fullName = sessionStorage.getItem('Full_Name') || ''
+ let RoleID = sessionStorage.getItem('role_id') || ''
+ let departmentcode = sessionStorage.getItem('departmentcode') || ''
+ let organization = sessionStorage.getItem('organization') || ''
+ let city = sessionStorage.getItem('city') || ''
+
+ if (sessionStorage.getItem('isEditState') === 'true') {
+ userName = sessionStorage.getItem('CloudUserName') || ''
+ fullName = sessionStorage.getItem('CloudFullName') || ''
+ }
+ _customScript = `declare @ErrorCode nvarchar(50),@retmsg nvarchar(4000),@UserName nvarchar(50),@FullName nvarchar(50),@RoleID nvarchar(512),@departmentcode nvarchar(50),@organization nvarchar(50),@login_city nvarchar(50)
+ select @ErrorCode='',@retmsg ='',@UserName='${userName}', @FullName='${fullName}', @RoleID='${RoleID}', @departmentcode='${departmentcode}', @organization='${organization}', @login_city='${city}'
+ ${_customScript}
+ `
+ }
+
+ // 娴嬭瘯绯荤粺鎵撳嵃鏌ヨ璇彞
+ if ((options.sysType === 'local' && !window.GLOB.systemType) || window.debugger === true) {
+ _customScript && console.info(`${setting.$name ? `/*${setting.$name} 鑷畾涔夎剼鏈紙鍚屾鏌ヨ锛�/\n` : ''}${_dataresource ? '' : '/*涓嶆墽琛岄粯璁ql*/\n'}${_customScript}`)
+ _dataresource && console.info(`${setting.$name ? `/*${setting.$name} 鏁版嵁婧愶紙鍚屾鏌ヨ锛�*/\n` : ''}` + _dataresource)
+ }
+
+ return {
+ name: dataName,
+ columns: columns,
+ par_tablename: '',
+ type: format === 'array' ? format : '',
+ primaryKey: setting.primaryKey || '',
+ foreign_key: '',
+ sql: _dataresource,
+ script: _customScript,
+ transaction: setting.transaction === 'true'
+ }
+}
+
+/**
+ * @description 鐢熸垚sPC_Get_structured_data璇锋眰鍙傛暟
+ * 1銆佹妸澶ф帴鍙PC_Get_structured_data鐨刲text鎷嗘垚涓変唤锛岀涓�娈碉細@LText1锛岀浜屾@LText锛岀涓夋@LText2
+ */
+export function getStructuredParams (params, config, BID = '') {
+ let LText_field = []
+ let diffUser = false
+ let transaction = false
+
+ let _LText = params.map((item, index) => {
+ let _script = item.script
+
+ if (!diffUser && (/@userid@/ig.test(item.sql) || /@userid@/ig.test(_script))) {
+ diffUser = true
+ }
+ if (item.transaction) {
+ transaction = true
+ }
+
+ item.columns.forEach(cell => {
+ LText_field.push(`Select '${item.name}' as tablename,'${cell.field}' as fieldname,'${cell.datatype}' as field_type`)
+ })
+ return `Select '${item.name}' as tablename,'${window.btoa(window.encodeURIComponent(item.sql))}' as LText,'${window.btoa(window.encodeURIComponent(_script))}' as Lcustomize,'${item.type}' as table_type,'${item.primaryKey}' as primary_key,'${item.par_tablename}' as par_tablename,'${item.foreign_key}' as foreign_key,'${index}' as Sort`
+ })
+
+ let param = {
+ func: 'sPC_Get_structured_data',
+ LText: _LText.join(' union all '),
+ LText_field: LText_field.join(' union all '),
+ BID: BID
+ }
+
+ if (transaction) {
+ param.func = 'sPC_Get_structured_data_try'
+ }
+
+ 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)
+
+ if (config.cacheUseful === 'true') {
+ param.time_type = config.timeUnit
+ param.time_limit = config.cacheTime
+ if (diffUser) {
+ param.userid = sessionStorage.getItem('UserID')
+ }
+ param.data_md5 = md5(JSON.stringify(param))
+ }
+
+ param.timestamp = moment().format('YYYY-MM-DD HH:mm:ss')
+ param.secretkey = Utils.encrypt(param.LText, param.timestamp)
+
+ return param
}
\ No newline at end of file
--
Gitblit v1.8.0