From a7938fbc431502c0a631f188b6e8d7ae5e67a3d1 Mon Sep 17 00:00:00 2001
From: king <18310653075@163.com>
Date: 星期四, 06 一月 2022 18:27:07 +0800
Subject: [PATCH] 2022-01-06
---
src/utils/utils-datamanage.js | 646 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++--
1 files changed, 616 insertions(+), 30 deletions(-)
diff --git a/src/utils/utils-datamanage.js b/src/utils/utils-datamanage.js
index 3aac834..4b98d65 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'
@@ -13,23 +14,22 @@
* @param {Number} pageSize 姣忛〉鏁伴噺
* @param {String} BID 涓婄骇ID
* @param {String} menuType 鑿滃崟绫诲瀷锛屾櫘閫氳彍鍗曚笌HS
- * @param {Boolean} dataManager 鏁版嵁鏉冮檺
* @return {Object} param
*/
- static getQueryDataParams (setting, arrFields, search = [], orderBy = '', pageIndex = 1, pageSize = 10, BID, menuType, dataManager) {
+ 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)) {
- param = this.getDefaultQueryParam(setting, arrFields, search, orderBy, pageIndex, pageSize, menuType)
+ 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)
+ param = this.getCustomQueryParam(setting, search, orderBy, pageIndex, pageSize, menuType, id)
}
if (BID) {
param.BID = BID
}
// 鏁版嵁绠$悊鏉冮檺
- if (dataManager) {
+ if (sessionStorage.getItem('dataM') === 'true') {
param.dataM = 'Y'
}
@@ -39,19 +39,21 @@
/**
* @description 鑾峰彇鐢ㄦ埛鑷畾涔夊瓨鍌ㄨ繃绋嬩紶鍙�
*/
- static getCustomQueryParam (setting, search, orderBy, pageIndex, pageSize, menuType) {
+ static getCustomQueryParam (setting, search, orderBy, pageIndex, pageSize, menuType, id) {
let param = Utils.formatCustomMainSearch(search)
if (orderBy) {
param.OrderCol = orderBy
}
- if (setting.laypage) {
+ if (id) {
+ param.ID = id
+ } else if (setting.laypage) {
param.PageIndex = pageIndex
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') {
@@ -64,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
}
}
@@ -79,27 +81,51 @@
/**
* @description 鑾峰彇绯荤粺瀛樺偍杩囩▼ sPC_Get_TableData 鐨勫弬鏁�
*/
- static getDefaultQueryParam (setting, arrFields, search, orderBy, pageIndex, pageSize, menuType) {
+ static getDefaultQueryParam (setting, arrFields, search, orderBy, pageIndex, pageSize, menuType, id) {
let param = {
func: 'sPC_Get_TableData',
obj_name: 'data',
+ exec_type: 'y',
arr_field: arrFields,
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') || ''
+ fullName = sessionStorage.getItem('CloudFullName') || ''
+ }
+
let _dataresource = setting.dataresource
let _customScript = ''
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),@mk_departmentcode nvarchar(50),@mk_organization nvarchar(50),@login_city nvarchar(50)
+ Select @ErrorCode='',@retmsg ='',@UserName='${userName}', @FullName='${fullName}', @RoleID='${RoleID}', @mk_departmentcode='${departmentcode}', @mk_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)
-
regoptions = allSearch.map(item => {
return {
reg: new RegExp('@' + item.key + '@', 'ig'),
@@ -111,7 +137,7 @@
value: orderBy
}, {
reg: new RegExp('@pageSize@', 'ig'),
- value: pageSize
+ value: setting.laypage ? pageSize : '9999'
}, {
reg: new RegExp('@pageIndex@', 'ig'),
value: pageIndex
@@ -120,14 +146,22 @@
let _search = ''
- if (setting.queryType === 'statistics' && _dataresource) { // 缁熻鏁版嵁婧愶紝鍐呭鏇挎崲
- regoptions.forEach(item => {
- _dataresource = _dataresource.replace(item.reg, item.value)
- })
- } else if (_dataresource) {
- _search = Utils.joinMainSearchkey(search)
- if (_search) {
- _search = 'where ' + _search
+ if (_dataresource) {
+ if (setting.queryType === 'statistics') { // 缁熻鏁版嵁婧愶紝鍐呭鏇挎崲
+ regoptions.forEach(item => {
+ _dataresource = _dataresource.replace(item.reg, item.value)
+ })
+ if (id) {
+ _dataresource = _dataresource + ` where ${setting.primaryKey || 'ID'}='${id}'`
+ }
+ } else if (!id) {
+ _search = Utils.joinMainSearchkey(search)
+ if (_search) {
+ _search = 'where ' + _search
+ }
+ } else if (id) {
+ _search = Utils.joinMainSearchkey(search)
+ _search = `where ${_search ? _search + ' AND ' : ''} ${setting.primaryKey || 'ID'}='${id}'`
}
}
@@ -140,7 +174,7 @@
let LText = ''
let DateCount = ''
- if (_dataresource && setting.laypage && orderBy) {
+ if (_dataresource && setting.laypage && orderBy && !id) {
LText = ` select top ${pageSize} ${arrFields} from (select ${arrFields} ,ROW_NUMBER() over(order by ${orderBy}) as rows from ${_dataresource} ${_search}) tmptable where rows > ${pageSize * (pageIndex - 1)} order by tmptable.rows `
DateCount = `select count(1) as total from ${_dataresource} ${_search}`
} else if (_dataresource && orderBy) {
@@ -160,22 +194,48 @@
_customScript = `${_customScript}
aaa:
if @ErrorCode!=''
- insert into tmp_err_retmsg (ID, ErrorCode, retmsg, CreateUserID) select @time_id@,@ErrorCode, @retmsg,@UserID@
+ 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)
+ _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.timestamp = moment().format('YYYY-MM-DD HH:mm:ss')
- param.secretkey = Utils.encrypt(param.LText, param.timestamp)
param.DateCount = Utils.formatOptions(DateCount)
+
+ // 澶氬眰缁撴瀯鏁版嵁
+ // LText = `SELECT a.id as bid,a.ID,a.workerCode,a.workerName,a.jobName,a.Initials,case when isnull(m.friend_id ,'') ='' then ''
+ // when isnull(m.status,0)=10 then '宸叉坊鍔�' else '寰呴�氳繃' end as friend_text
+ // ,case when images='' then 'http://epc.mk9h.cn/Content/images/upload/img/kane.jpg' else images end as icon FROM
+ // (select friend_id,status from oa_mail_list where userid='sso202004100959326131C0805998B6745F886F9' and Initials=case when right('0',1)='0' then Initials else '0' end
+ // and status=10 and deleted=0) m
+ // inner join (select * from BD_workers where
+ // Initials=case when right('0',1)='0' then Initials else '0' end and deleted=0 ) a
+ // on a.id=m.friend_id `
+ // param.custom_script = ''
+ // param.LText = Utils.formatOptions(LText)
+ // param.DateCount = ''
+ // param.prm_field = 'workerCode'
+ // param.arr_field = 'workerName,jobName'
+ // param.tabid = 'ID'
+ // param.parid = 'BID'
+ // param.sub_name = 'sub_data'
+ // param.sub_field = 'BID,friend_text,icon,Initials'
+
+ // 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)
if (menuType === 'HS') { // 浜戠鏁版嵁楠岃瘉
param.open_key = Utils.encryptOpenKey(param.secretkey, param.timestamp)
@@ -183,4 +243,530 @@
return param
}
+
+ /**
+ * @description 鑾峰彇绯荤粺瀛樺偍杩囩▼ sPC_Get_TableData 鍚堣鍊肩殑鍙傛暟
+ */
+ static getStatQueryDataParams (setting, statFields, search, orderBy, BID, menuType) {
+ let param = {
+ func: 'sPC_Get_TableData',
+ obj_name: 'data',
+ exec_type: 'y',
+ 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),@UserName nvarchar(50),@FullName nvarchar(50),@RoleID nvarchar(512),@mk_departmentcode nvarchar(50),@mk_organization nvarchar(50),@login_city nvarchar(50)
+ Select @ErrorCode='',@retmsg ='',@UserName='${userName}', @FullName='${fullName}', @RoleID='${RoleID}', @mk_departmentcode='${departmentcode}', @mk_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)
+
+ regoptions = allSearch.map(item => {
+ return {
+ reg: new RegExp('@' + item.key + '@', 'ig'),
+ value: `'${item.value}'`
+ }
+ })
+ regoptions.push({
+ 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)
+ })
+ _search = ''
+ }
+
+ 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.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 = ''
+
+ param.timestamp = moment().format('YYYY-MM-DD HH:mm:ss')
+ param.secretkey = Utils.encrypt('', param.timestamp)
+
+ if (menuType === 'HS') { // 浜戠鏁版嵁楠岃瘉
+ param.open_key = Utils.encryptOpenKey(param.secretkey, param.timestamp)
+ }
+
+ if (BID) {
+ param.BID = BID
+ }
+
+ // 鏁版嵁绠$悊鏉冮檺
+ if (sessionStorage.getItem('dataM') === 'true') {
+ param.dataM = 'Y'
+ }
+
+ 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 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') || ''
+ }
+
+ 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),@RoleID nvarchar(512),@mk_departmentcode nvarchar(50),@mk_organization nvarchar(50),@login_city nvarchar(50)
+ Select @ErrorCode='',@retmsg ='',@UserName='${userName}', @FullName='${fullName}', @RoleID='${RoleID}', @mk_departmentcode='${departmentcode}', @mk_organization='${organization}', @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 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),@mk_departmentcode nvarchar(50),@mk_organization nvarchar(50),@login_city nvarchar(50)
+ Select @ErrorCode='',@retmsg='',@UserName='${userName}', @FullName='${fullName}', @RoleID='${RoleID}', @mk_departmentcode='${departmentcode}', @mk_organization='${organization}', @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()]
+ }
+}
+
+/**
+ * @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),@mk_departmentcode nvarchar(50),@mk_organization nvarchar(50),@login_city nvarchar(50)
+ select @ErrorCode='',@retmsg ='',@UserName='${userName}', @FullName='${fullName}', @RoleID='${RoleID}', @mk_departmentcode='${departmentcode}', @mk_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