From bf772e586c29b4858366dbad143b1eaeca3c46ed Mon Sep 17 00:00:00 2001 From: king <18310653075@163.com> Date: 星期五, 17 四月 2020 10:18:09 +0800 Subject: [PATCH] 2020-04-17 --- src/utils/utils.js | 380 +++++++++++++++++++++++++++++++++++++++++++---------- 1 files changed, 307 insertions(+), 73 deletions(-) diff --git a/src/utils/utils.js b/src/utils/utils.js index a5aa2dd..39c4111 100644 --- a/src/utils/utils.js +++ b/src/utils/utils.js @@ -1,5 +1,6 @@ import moment from 'moment' import md5 from 'md5' +import options from '@/store/options.js' const service = window.GLOB.service ? (/\/$/.test(window.GLOB.service) ? window.GLOB.service : window.GLOB.service + '/') : '' @@ -53,7 +54,7 @@ * @description sql鍔犲瘑 * @return {String} value */ - static formatOptions (value) { + static formatOptions (value, isUnFormat = false) { if (!value) return '' let salt = 'minKe' // 鐩愬�� @@ -156,25 +157,43 @@ value: ' mrlbkk ' }] - // 鏇挎崲鍏抽敭瀛� - format.forEach(item => { - let reg = new RegExp('(^|\\s)' + item.key + '(\\s|$)', 'ig') - value = value.replace(reg, item.value) - }) + if (!isUnFormat) { // 鍔犲瘑 + // 鏇挎崲鍏抽敭瀛� + format.forEach(item => { + let reg = new RegExp('(^|\\s)' + item.key + '(\\s|$)', 'ig') + value = value.replace(reg, item.value) + }) + + // 1銆佹浛鎹�%绗︼紙鏁版嵁搴撲腑瑙f瀽鍚巗ql鎶ラ敊锛� + value = value.replace(/%/ig, ' mpercent ') + + // 1銆乪ncode缂栫爜锛堜腑鏂囧瓧绗﹁秴鍑篵ase64鍔犲瘑鑼冨洿锛夛紝2銆乥ase64鍔犲瘑 + value = window.btoa(window.encodeURIComponent(value)) + + // 鎻掑叆瀛楃 + let index = Math.floor(value.length / 2) + value = value.slice(0, index) + salt + value.slice(index) + + // base64鍔犲瘑 + value = window.btoa(value) + } else { // 瑙e瘑 + try { + value = window.atob(value) + value = value.replace(salt, '') + value = window.decodeURIComponent(window.atob(value)) + value = value.replace(/\smpercent\s/g, '%') - // 1銆佹浛鎹�%绗︼紙鏁版嵁搴撲腑瑙f瀽鍚巗ql鎶ラ敊锛夛紝2銆佸幓闄ゆ敹灏惧浣欑┖鏍� - value = value.replace(/%/ig, 'mpercent') - value = value.replace(/(^\s|\s$)/ig, '') - - // 1銆乪ncode缂栫爜锛堜腑鏂囧瓧绗﹁秴鍑篵ase64鍔犲瘑鑼冨洿锛夛紝2銆乥ase64鍔犲瘑 - value = window.btoa(window.encodeURIComponent(value)) - - // 鎻掑叆瀛楃 - let index = Math.floor(value.length / 2) - value = value.slice(0, index) + salt + value.slice(index) - - // base64鍔犲瘑 - value = window.btoa(value) + format.forEach(item => { + let reg = new RegExp(item.value, 'g') + value = value.replace(reg, ' ' + item.key + ' ') + }) + + value = value.replace(/(^\s+|\s+$)/ig, '') + } catch { + console.warn('UnFormat Failure') + value = '' + } + } return value } @@ -193,7 +212,9 @@ key: search.field, match: search.match, type: search.type, - value: search.initval + label: search.label, + value: search.initval, + required: search.required === 'true' } if (item.type === 'date') { item.value = item.value ? moment().subtract(item.value, 'days').format('YYYY-MM-DD') : '' @@ -288,6 +309,12 @@ newsearches[item.key] = item.value } }) + + Object.keys(newsearches).forEach(key => { + if (!newsearches[key]) { + delete newsearches[key] + } + }) return newsearches } @@ -317,12 +344,8 @@ searchText += item.key + ' ' + item.match + ' \'' + str + item.value + str + '\'' } else if (item.type === 'multiselect') { - let str = item.match === '=' ? '' : '%' - let options = item.value.map(val => { - return item.key + ' ' + item.match + ' \'' + str + val + str + '\'' - }) - searchText += '(' + options.join(' OR ') + ')' + searchText += `'${item.value}' ` + item.match + ' \'%\'+' + item.key + '+\'%\'' } else if (item.type === 'date') { let _val = item.value let timetail = ' 00:00:00.000' @@ -355,6 +378,7 @@ searchText += '(' + item.key + ' ' + item.match + ' \'' + item.value + '\')' } }) + return searchText } @@ -391,6 +415,7 @@ */ static getrealurl (url) { if (!url) return '' + let baseurl = '' if (process.env.NODE_ENV === 'production') { baseurl = document.location.origin + '/' + service @@ -402,6 +427,24 @@ // } let realurl = url.match(/^http/) || url.match(/^\/\//) ? url : baseurl + url return realurl + } + + /** + * @description 鑾峰彇浜戠鍥剧墖鐪熷疄璺緞 + * @return {String} url 鍥剧墖璺緞 + */ + static getcloudurl (url) { + if (!url) return '' + + let baseurl = '' + + if (options.cloudServiceApi) { + baseurl = options.cloudServiceApi.replace(/webapi(.*)$/, '') + } else { + baseurl = document.location.origin + '/' + service + } + + return url.match(/^http/) || url.match(/^\/\//) ? url : baseurl + url } /** @@ -452,6 +495,11 @@ let errors = [] let _topline = btn.range || 0 let upId = this.getuuid() + + if (btn.scripts && btn.scripts.length > 0) { + btn.scripts = btn.scripts.filter(item => item.status !== 'false') + } + let _Ltext = data.map((item, lindex) => { let vals = btn.columns.map((col, cindex) => { let val = item[col.Column] !== undefined ? item[col.Column] : '' @@ -480,7 +528,7 @@ }) } } else if (/^int/ig.test(col.type)) { - if (!val) { + if (!val && val !== 0) { let _error = _position + dict['main.excel.content.emptyerror'] errors.push(_error) } else { @@ -498,7 +546,7 @@ } } } else if (/^Decimal/ig.test(col.type)) { - if (!val) { + if (!val && val !== 0) { let _error = _position + dict['main.excel.content.emptyerror'] errors.push(_error) } else { @@ -540,6 +588,48 @@ let _sql = '' if (item.intertype === 'inner' && !item.innerFunc) { + let _uniquesql = '' + if (btn.uniques && btn.uniques.length > 0) { + btn.uniques.forEach(unique => { + if (unique.status === 'false') return + + let _fields = unique.field.split(',') + let _fields_ = _fields.map(_field => { + return `a.${_field}=b.${_field}` + }) + _fields_ = _fields_.join(' and ') + + if (unique.verifyType !== 'physical') { + _fields_ += ' and b.deleted=0' + } + + _uniquesql += ` + Set @tbid='' + Select top 1 @tbid=${_fields.join('+\' \'+')} from (select 1 as n,${unique.field} from @${item.sheet} ) a group by ${unique.field} having sum(n)>1 + + If @tbid!='' + Begin + select @ErrorCode='${unique.errorCode}',@retmsg=@tbid+' 閲嶅' + goto aaa + end + + Set @tbid='' + Select top 1 @tbid=${_fields.join('+\' \'+')} from @${item.sheet} a + Inner join ${item.sheet} b on ${_fields_} + + If @tbid!='' + Begin + select @ErrorCode='${unique.errorCode}',@retmsg=@tbid+' 涓庡凡鏈夋暟鎹噸澶�' + goto aaa + end + ` + }) + + if (_uniquesql) { + _uniquesql = 'Declare @tbid Nvarchar(512)' + _uniquesql + } + } + let declarefields = [] let fields = [] @@ -552,6 +642,16 @@ let _insert = '' + if (btn.scripts && btn.scripts.length > 0) { + btn.scripts.forEach(script => { + if (script.position !== 'front') return + + _insert += ` + ${script.sql} + ` + }) + } + if (btn.default !== 'false') { _insert = ` Insert into ${item.sheet} (${fields},createuserid,createuser,createstaff,bid) @@ -561,7 +661,7 @@ if (btn.scripts && btn.scripts.length > 0) { btn.scripts.forEach(script => { - if (script.status === 'false') return + if (script.position === 'front') return _insert += ` ${script.sql} @@ -578,6 +678,7 @@ Insert into @${item.sheet} (${fields},jskey) ${_Ltext} + ${_uniquesql} ${_insert} Delete @${item.sheet} @@ -599,25 +700,29 @@ * @return {String} type 鎵ц绫诲瀷 * @return {String} table 琛ㄥ悕 */ - static getSysDefaultSql (btn, setting, formdata, param, data, logcolumns) { + static getSysDefaultSql (btn, setting, formdata, param, data, logcolumns, tab) { let primaryId = param.ID let BID = param.BID let verify = btn.verify || {} let _formFieldValue = {} + let _actionType = null + + if (verify.default !== 'false') { // 鍒ゆ柇鏄惁浣跨敤榛樿sql + _actionType = btn.sqlType + } + // 闇�瑕佸0鏄庣殑鍙橀噺闆� // let _vars = ['tbid', 'ErrorCode', 'retmsg', 'BillCode', 'BVoucher', 'FIBVoucherDate', 'FiYear', 'UserName', 'FullName', 'ID', 'BID', 'LoginUID', 'SessionUid', 'UserID', 'Appkey'] - // let _vars = ['tbid', 'errorcode', 'retmsg', 'billcode', 'bvoucher', 'fibvoucherdate', 'fiyear', 'username', 'fullname', 'id', 'bid', 'loginuid', 'sessionuid', 'userid', 'appkey'] - let _vars = ['tbid', 'errorcode', 'retmsg', 'billcode', 'bvoucher', 'fibvoucherdate', 'fiyear', 'username', 'fullname'] + let _vars = ['tbid', 'errorcode', 'retmsg', 'billcode', 'bvoucher', 'fibvoucherdate', 'fiyear', 'username', 'fullname', 'modulardetailcode'] // 涓婚敭瀛楁 let primaryKey = setting.primaryKey || 'id' // 绯荤粺鍙橀噺澹版槑涓庤缃垵濮嬪�� - let _sql = `Declare @tbid nvarchar(50),@ErrorCode nvarchar(50),@retmsg nvarchar(4000),@BillCode nvarchar(50),@BVoucher nvarchar(50),@FIBVoucherDate nvarchar(50), @FiYear nvarchar(50), @UserName nvarchar(50),@FullName nvarchar(50) + let _sql = `Declare @tbid nvarchar(50),@ErrorCode nvarchar(50),@retmsg nvarchar(4000),@BillCode nvarchar(50),@BVoucher nvarchar(50),@FIBVoucherDate nvarchar(50), @FiYear nvarchar(50), @UserName nvarchar(50),@FullName nvarchar(50),@ModularDetailCode nvarchar(50) ` // let _initvars = ['ID', 'BID', 'LoginUID', 'SessionUid', 'UserID', 'Appkey'] // 宸茶祴鍊煎瓧娈甸泦 - // let _initvars = ['id', 'bid', 'loginuid', 'sessionuid', 'userid', 'appkey'] // 宸茶祴鍊煎瓧娈甸泦 let _initvars = [] // 宸茶祴鍊煎瓧娈甸泦 let _initfields = [] let _declarefields = [] @@ -640,6 +745,10 @@ if (!_vars.includes(_key)) { _vars.push(_key) + + if (form.fieldlen && form.fieldlen > 2048) { + form.fieldlen = 'max' + } let _type = `nvarchar(${form.fieldlen})` @@ -676,6 +785,10 @@ if (!_vars.includes(_key)) { _vars.push(_key) + + if (col.fieldlength && col.fieldlength > 2048) { + col.fieldlength = 'max' + } let _type = `nvarchar(${col.fieldlength || 50})` @@ -706,11 +819,6 @@ ` } - // 娣诲姞鏃朵富閿负绌� 鏀逛负鍓嶅彴鐢熸垚 - // if (btn.sqlType === 'insert') { - // primaryId = '' - // } - // 鍘婚櫎绂佺敤鐨勯獙璇� if (verify.contrasts) { verify.contrasts = verify.contrasts.filter(item => item.status !== 'false') @@ -728,8 +836,16 @@ verify.scripts = verify.scripts.filter(item => item.status !== 'false') } - // 鍒濆鍖栧嚟璇佸瓧娈� - _sql += `select @BVoucher='',@FIBVoucherDate='',@FiYear='',@ErrorCode='',@retmsg='' + 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') || '' + } + + // 鍒濆鍖栧嚟璇佸強鐢ㄦ埛淇℃伅瀛楁 + _sql += `select @BVoucher='',@FIBVoucherDate='',@FiYear='',@ErrorCode='',@retmsg='',@UserName='${userName}', @FullName='${fullName}' ` // 鍚敤璐︽湡楠岃瘉 @@ -781,6 +897,7 @@ let _fieldValue = [] // 琛ㄥ崟閿�煎field=value let _value = [] // 琛ㄥ崟鍊硷紝鐢ㄤ簬閿欒鎻愮ず let _labels = item.fieldlabel.split(',') // 琛ㄥ崟鎻愮ず鏂囧瓧 + let arr = [] // 楠岃瘉涓婚敭 item.field.split(',').forEach((_field, index) => { let _fval = `'${_formFieldValue[_field]}'` @@ -790,6 +907,8 @@ if (_field.toLowerCase() === 'bid' && !hasBid) { // 琛ㄥ崟涓病鏈塨id鍒欎娇鐢ㄧ郴缁焍id鍙橀噺 _fval = '@BID@' } + arr.push(_field.toLowerCase()) + _fieldValue.push(`${_field}=${_fval}`) _value.push(`${_labels[index] || ''}锛�${_formFieldValue[_field] || ''}`) }) @@ -799,8 +918,12 @@ _verifyType = ' and deleted=0' } + if (!arr.includes(primaryKey.toLowerCase())) { + _fieldValue.push(`${primaryKey} !='${primaryId}'`) + } + _sql += `select @tbid='', @ErrorCode='',@retmsg='' - select @tbid='X' from ${btn.sql} where ${_fieldValue.join(' and ')} and ${primaryKey} !='${primaryId}'${_verifyType} + select @tbid='X' from ${btn.sql} where ${_fieldValue.join(' and ')}${_verifyType} If @tbid!='' Begin select @ErrorCode='${item.errorCode}',@retmsg='${_value.join(', ')} 宸插瓨鍦�' @@ -812,7 +935,7 @@ // 鑷畾涔夐獙璇� if (verify.customverifys && verify.customverifys.length > 0) { - verify.customverifys.forEach(item => { + verify.customverifys.forEach(item => { _sql += `select @tbid='', @ErrorCode='',@retmsg='' select top 1 @tbid='X' from (${item.sql}) a If @tbid ${item.result === 'true' ? '!=' : '='}'' @@ -825,19 +948,28 @@ } // 鍗曞彿鐢熸垚锛屼娇鐢ㄤ笂绾d锛圔ID锛夋垨鍒楄〃鏁版嵁锛屽0鏄庡彉閲忥紙妫�楠岋級 + let _billcodesSql = '' if (verify.billcodes && verify.billcodes.length > 0) { verify.billcodes.forEach(item => { let _ModularDetailCode = '' - if (item.TypeCharOne === 'Lp' || item.TypeCharOne === 'BN') { + let _lpline = '' + if (item.TypeCharOne === 'Lp') { + if (item.linkField === 'BID' && BID) { // 鏇挎崲bid + _lpline = `set @ModularDetailCode= 'Lp'+ right('${item.mark || btn.uuid}'+@BID@,48)` + } else { + _lpline = `set @ModularDetailCode= 'Lp'+ right('${item.mark || btn.uuid}'+@${item.linkField},48)` + } + _ModularDetailCode = '@ModularDetailCode' + } else if (item.TypeCharOne === 'BN') { let _val = '' if (item.linkField === 'BID' && BID) { // 鏇挎崲bid _val = BID } else if (data && data.hasOwnProperty(item.linkField)) { _val = data[item.linkField] } - _ModularDetailCode = item.TypeCharOne + _val + _ModularDetailCode = `'${item.TypeCharOne + _val}'` } else { - _ModularDetailCode = item.ModularDetailCode + _ModularDetailCode = `'${item.ModularDetailCode}'` } let _declare = '' @@ -848,10 +980,11 @@ _vars.push(_key) } - _sql += `${_declare} - select @BillCode='', @${_key}='' + _billcodesSql += `${_declare} + select @BillCode='', @${_key}='', @ModularDetailCode='' + ${_lpline} exec s_get_BillCode - @ModularDetailCode='${_ModularDetailCode}', + @ModularDetailCode=${_ModularDetailCode}, @Type=${item.Type}, @TypeCharOne='${item.TypeCharOne}', @TypeCharTwo ='${item.TypeCharTwo}', @@ -863,6 +996,10 @@ set @${_key}=@BillCode ` }) + + if (_actionType !== 'insertOrUpdate') { + _sql += _billcodesSql + } } let hasvoucher = false @@ -879,6 +1016,9 @@ @VoucherTypeOne ='${_voucher.VoucherTypeOne}', @VoucherTypeTwo ='${_voucher.VoucherTypeTwo}', @Type =${_voucher.Type}, + @UserID=@UserID@, + @Username=@Username, + @FullName=@FullName, @BVoucher =@BVoucher OUTPUT , @FIBVoucherDate =@FIBVoucherDate OUTPUT , @FiYear =@FiYear OUTPUT , @@ -889,20 +1029,10 @@ ` } - // 鐢ㄤ簬鍙栫敤鎴蜂俊鎭� - let _user = `select @UserName=UserName,@FullName=FullName from SUsers where UID=@UserID@ - ` - let primaryKeyName = ['id', 'bid', 'loginuid', 'sessionuid', 'userid', 'appkey'].includes(primaryKey.toLowerCase()) ? primaryKey + '@' : primaryKey - let _actionType = null - - if (verify.default !== 'false') { // 鍒ゆ柇鏄惁浣跨敤榛樿sql - _actionType = btn.sqlType - } - - // 娣诲姞銆佷慨鏀广�侀�昏緫鍒犻櫎銆佺墿鐞嗗垹闄� - if (_actionType === 'insert') { + let _insertsql = '' + if (_actionType === 'insert' || _actionType === 'insertOrUpdate') { // 娣诲姞璇彞 let keys = [] let values = [] @@ -919,8 +1049,8 @@ } }) - if (!keys.includes(primaryKey)) { - keys.push(primaryKey) + if (!keys.includes(primaryKey.toLowerCase())) { + keys.push(primaryKey.toLowerCase()) values.push('\'' + primaryId + '\'') } if (!keys.includes('createuserid')) { @@ -936,15 +1066,24 @@ values.push('@fullname') } if (!keys.includes('bid')) { - keys.push('bid') + if (tab && tab.foreignKey && !keys.includes(tab.foreignKey.toLowerCase())) { + keys.push(tab.foreignKey) + } else { + keys.push('bid') + } + values.push('@BID@') + } else if (tab && tab.foreignKey && !keys.includes(tab.foreignKey.toLowerCase())) { + keys.push(tab.foreignKey) values.push('@BID@') } keys = keys.join(',') values = values.join(',') - _sql += _user - _sql += `insert into ${btn.sql} (${keys}) select ${values};` - } else if (_actionType === 'update') { + _insertsql = `insert into ${btn.sql} (${keys}) select ${values};` + } + + let _updatesql = '' + if (_actionType === 'update' || _actionType === 'insertOrUpdate') { // 淇敼璇彞 let _form = [] let _arr = [] @@ -952,7 +1091,11 @@ _arr.push(item.key.toLowerCase()) if (item.type === 'funcvar') { - _form.push(item.key + '=@' + item.key) + if (_actionType === 'update') { + _form.push(item.key + '=@' + item.key) + } else if (_actionType === 'insertOrUpdate') { // 娣诲姞鎴栦慨鏀规椂锛屽嚱鏁板彉閲忔坊鍔犺〃鍗曟暟鍊� + _form.push(item.key + '=\'' + item.value + '\'') + } } else if (item.type === 'number') { _form.push(item.key + '=' + item.value) } else { @@ -977,9 +1120,27 @@ _form.push('FiYear=@FiYear') } } - _form = _form.join(',') - _sql += `update ${btn.sql} set ${_form} where ${primaryKey}=@${primaryKeyName};` + _updatesql = `update ${btn.sql} set ${_form} where ${primaryKey}=@${primaryKeyName};` + } + + // 鎷兼帴鑷畾涔夎剼鏈� + if (verify.scripts && verify.scripts.length > 0) { + let _scripts = '' + verify.scripts.forEach(item => { + if (item.position !== 'front') return + + _scripts += ` + ${item.sql}` + }) + _sql += `${_scripts}` + } + + // 娣诲姞銆佷慨鏀广�侀�昏緫鍒犻櫎銆佺墿鐞嗗垹闄� + if (_actionType === 'insert') { + _sql += _insertsql + } else if (_actionType === 'update') { + _sql += _updatesql } else if (_actionType === 'LogicDelete') { // 閫昏緫鍒犻櫎 _sql += `update ${btn.sql} set deleted=1,modifydate=getdate(),modifyuserid=@userid@ where ${primaryKey}=@${primaryKeyName};` @@ -994,14 +1155,28 @@ } }) } - _sql += _user - _sql += `insert into snote (remark,createuserid,CreateUser,CreateStaff) select '鍒犻櫎琛�:${btn.sql} 鏁版嵁: ${_msg}${primaryKey}='+@${primaryKeyName},@userid@,@username,@fullname delete ${btn.sql} where ${primaryKey}=@${primaryKeyName};` + _sql += `insert into snote (remark,createuserid,CreateUser,CreateStaff) select left('鍒犻櫎琛�:${btn.sql} 鏁版嵁: ${_msg}${primaryKey}='+@${primaryKeyName},200),@userid@,@username,@fullname delete ${btn.sql} where ${primaryKey}=@${primaryKeyName};` + } else if (_actionType === 'insertOrUpdate') { + _sql += `select @tbid='' + select @tbid='X' from ${btn.sql} where ${primaryKey}=@ID@ + if @tbid='' + begin + ${_billcodesSql} + ${_insertsql} + end + else + begin + ${_updatesql} + end + ` } // 鎷兼帴鑷畾涔夎剼鏈� if (verify.scripts && verify.scripts.length > 0) { let _scripts = '' verify.scripts.forEach(item => { + if (item.position === 'front') return + _scripts += ` ${item.sql}` }) @@ -1083,6 +1258,7 @@ let Ltext = `create proc ${param.innerFunc} ( /*${menu.MenuName}*/ + @appkey nvarchar(50)='', @BID nvarchar(50)='',${formParam} @PageIndex nvarchar(50)='', @PageSize nvarchar(50)='', @@ -1213,6 +1389,10 @@ update ${param.name} set ${field3},modifydate=getdate(),modifyuserid=@UserID ` + } else if (btn.OpenType === 'prompt' || btn.OpenType === 'exec') { + form = ` + update ${param.name} set ModifyDate=getdate(),ModifyUserID=@UserID where ${primaryKey}=@${primaryKey} + ` } if (columns) { @@ -1240,8 +1420,15 @@ ` } + // 鎵撳嵃鑷畾涔夋ā鏉垮瓧娈垫彁绀� + let _printRemark = '' + if (btn.funcType === 'print') { + _printRemark = '/* 鑷畾涔夋暟鎹墦鍗版ā鏉挎椂锛岃浣跨敤TemplateID瀛楁 */' + } + let Ltext = `create proc ${param.funcName} ( /*${menu.MenuName} ${btn.label}*/ + @appkey nvarchar(50)='', @BID nvarchar(50)='',${formParam} @sEPTMenuNo nvarchar(50)='${param.menuNo}', @lang nvarchar(50)='', @@ -1262,7 +1449,7 @@ /*浜嬪姟鎿嶄綔*/ BEGIN TRAN /*鍏蜂綋涓氬姟鎿嶄綔*/ - + ${_printRemark} /* select top 10 * from sProcExcep order by id desc @@ -1322,6 +1509,50 @@ static getexcelInfunc (param, btn, menu) { let _verify = btn.verify + let _uniquesql = '' + if (_verify.uniques && _verify.uniques.length > 0) { + _verify.uniques.forEach(unique => { + if (unique.status === 'false') return + + let _fields = unique.field.split(',') + let _fields_ = _fields.map(_field => { + return `a.${_field}=b.${_field}` + }) + _fields_ = _fields_.join(' and ') + + if (unique.verifyType !== 'physical') { + _fields_ += ' and b.deleted=0' + } + + _uniquesql += ` + Set @tbid='' + Select top 1 @tbid=${_fields.join('+\' \'+')} from (select 1 as n,${unique.field} from @${btn.sheet} ) a group by ${unique.field} having sum(n)>1 + + If @tbid!='' + Begin + select @ErrorCode='${unique.errorCode}',@retmsg=@tbid+' 閲嶅' + goto aaa + end + + Set @tbid='' + Select top 1 @tbid=${_fields.join('+\' \'+')} from @${btn.sheet} a + Inner join ${btn.sheet} b on ${_fields_} + + If @tbid!='' + Begin + select @ErrorCode='${unique.errorCode}',@retmsg=@tbid+' 涓庡凡鏈夋暟鎹噸澶�' + goto aaa + end + ` + }) + + if (_uniquesql) { + _uniquesql = ` + Declare @tbid Nvarchar(512) + ${_uniquesql}` + } + } + let declarefields = [] let fields = [] @@ -1341,7 +1572,7 @@ exec s_KeyWords_Replace @LText=@LText, @BID=@BID,@LoginUID=@LoginUID,@SessionUid=@SessionUid,@UserID=@UserID,@ID=@ID - + ${_uniquesql} Insert into ${btn.sheet} (${fields},createuserid,createuser,createstaff,bid) Select ${fields},@userid,@username,@fullname,@BID From @${btn.sheet} @@ -1349,10 +1580,13 @@ let Ltext = `create proc ${param.funcName} ( /*${menu.MenuName} ${btn.label}*/ + @appkey nvarchar(50)='', @ID nvarchar(50)='', @BID nvarchar(50)='', @Ltext nvarchar(max)='', @sEPTMenuNo nvarchar(50)='${param.menuNo}', + @secretkey nvarchar(50)='', + @timestamp nvarchar(50)='', @lang nvarchar(50)='', @LoginUID nvarchar(50)='', @SessionUid nvarchar(50)='', -- Gitblit v1.8.0