From 1e7aa4f0ff5e13c4a99ba511bb357a4cc63aa0c1 Mon Sep 17 00:00:00 2001 From: king <18310653075@163.com> Date: 星期四, 02 四月 2020 15:21:46 +0800 Subject: [PATCH] 2020-04-02 --- src/utils/utils.js | 157 +++++++++++++++++++++++++++++++++++++++++++-------- 1 files changed, 131 insertions(+), 26 deletions(-) diff --git a/src/utils/utils.js b/src/utils/utils.js index 9edfb85..901b4fe 100644 --- a/src/utils/utils.js +++ b/src/utils/utils.js @@ -194,7 +194,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') : '' @@ -289,6 +291,12 @@ newsearches[item.key] = item.value } }) + + Object.keys(newsearches).forEach(key => { + if (!newsearches[key]) { + delete newsearches[key] + } + }) return newsearches } @@ -318,12 +326,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' @@ -356,6 +360,7 @@ searchText += '(' + item.key + ' ' + item.match + ' \'' + item.value + '\')' } }) + return searchText } @@ -560,6 +565,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 = [] @@ -598,6 +645,7 @@ Insert into @${item.sheet} (${fields},jskey) ${_Ltext} + ${_uniquesql} ${_insert} Delete @${item.sheet} @@ -626,7 +674,6 @@ let _formFieldValue = {} // 闇�瑕佸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', 'modulardetailcode'] // 涓婚敭瀛楁 @@ -637,7 +684,6 @@ ` // let _initvars = ['ID', 'BID', 'LoginUID', 'SessionUid', 'UserID', 'Appkey'] // 宸茶祴鍊煎瓧娈甸泦 - // let _initvars = ['id', 'bid', 'loginuid', 'sessionuid', 'userid', 'appkey'] // 宸茶祴鍊煎瓧娈甸泦 let _initvars = [] // 宸茶祴鍊煎瓧娈甸泦 let _initfields = [] let _declarefields = [] @@ -726,11 +772,6 @@ ` } - // 娣诲姞鏃朵富閿负绌� 鏀逛负鍓嶅彴鐢熸垚 - // if (btn.sqlType === 'insert') { - // primaryId = '' - // } - // 鍘婚櫎绂佺敤鐨勯獙璇� if (verify.contrasts) { verify.contrasts = verify.contrasts.filter(item => item.status !== 'false') @@ -748,8 +789,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}' ` // 鍚敤璐︽湡楠岃瘉 @@ -801,6 +850,7 @@ let _fieldValue = [] // 琛ㄥ崟閿�煎field=value let _value = [] // 琛ㄥ崟鍊硷紝鐢ㄤ簬閿欒鎻愮ず let _labels = item.fieldlabel.split(',') // 琛ㄥ崟鎻愮ず鏂囧瓧 + let arr = [] // 楠岃瘉涓婚敭 item.field.split(',').forEach((_field, index) => { let _fval = `'${_formFieldValue[_field]}'` @@ -810,6 +860,8 @@ if (_field.toLowerCase() === 'bid' && !hasBid) { // 琛ㄥ崟涓病鏈塨id鍒欎娇鐢ㄧ郴缁焍id鍙橀噺 _fval = '@BID@' } + arr.push(_field.toLowerCase()) + _fieldValue.push(`${_field}=${_fval}`) _value.push(`${_labels[index] || ''}锛�${_formFieldValue[_field] || ''}`) }) @@ -819,8 +871,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(', ')} 宸插瓨鍦�' @@ -918,10 +974,6 @@ ` } - // 鐢ㄤ簬鍙栫敤鎴蜂俊鎭� - 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 @@ -948,8 +1000,8 @@ } }) - if (!keys.includes(primaryKey)) { - keys.push(primaryKey) + if (!keys.includes(primaryKey.toLowerCase())) { + keys.push(primaryKey.toLowerCase()) values.push('\'' + primaryId + '\'') } if (!keys.includes('createuserid')) { @@ -971,7 +1023,6 @@ keys = keys.join(',') values = values.join(',') - _sql += _user _sql += `insert into ${btn.sql} (${keys}) select ${values};` } else if (_actionType === 'update') { let _form = [] @@ -1023,7 +1074,6 @@ } }) } - _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};` } @@ -1112,6 +1162,7 @@ let Ltext = `create proc ${param.innerFunc} ( /*${menu.MenuName}*/ + @appkey nvarchar(50)='', @BID nvarchar(50)='',${formParam} @PageIndex nvarchar(50)='', @PageSize nvarchar(50)='', @@ -1269,8 +1320,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)='', @@ -1291,7 +1349,7 @@ /*浜嬪姟鎿嶄綔*/ BEGIN TRAN /*鍏蜂綋涓氬姟鎿嶄綔*/ - + ${_printRemark} /* select top 10 * from sProcExcep order by id desc @@ -1351,6 +1409,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 = [] @@ -1370,7 +1472,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} @@ -1378,10 +1480,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