From ae6ce73e7abde1121a788f884e54ccd6cfad0460 Mon Sep 17 00:00:00 2001 From: king <18310653075@163.com> Date: 星期二, 11 八月 2020 13:59:29 +0800 Subject: [PATCH] 2020-08-11 --- src/utils/utils.js | 119 +++++++++++++++++++++++++++++++---------------------------- 1 files changed, 63 insertions(+), 56 deletions(-) diff --git a/src/utils/utils.js b/src/utils/utils.js index 12faef9..3fa55b7 100644 --- a/src/utils/utils.js +++ b/src/utils/utils.js @@ -705,7 +705,7 @@ * @return {String} btn 鎸夐挳 * @return {String} data excel鏁版嵁 */ - static getExcelInSql (item, data, dict) { + static getExcelInSql (item, data, dict, BID) { let btn = item.verify let keys = ['delete', 'drop', 'insert', 'truncate', 'update'] let userName = sessionStorage.getItem('User_Name') || '' @@ -747,8 +747,11 @@ }) } + // 鎺у埗鍙版墦鍗版暟鎹� + let conLtext = [] let _Ltext = data.map((item, lindex) => { let vals = [] + let convals = [] btn.columns.forEach((col, cindex) => { if (col.import === 'false') return @@ -763,91 +766,90 @@ val = val.replace(/(^\s*$)|\t*|\v*/ig, '') if (!val && col.required === 'true') { // 蹇呭~鏍¢獙 - let _error = _position + dict['main.excel.content.emptyerror'] - errors.push(_error) + errors.push(_position + dict['main.excel.content.emptyerror']) } else if (val.length > col.limit) { // 闀垮害鏍¢獙 - let _error = _position + dict['main.excel.content.maxlimit'] - errors.push(_error) + errors.push(_position + dict['main.excel.content.maxlimit']) } else { // 鍏抽敭瀛楁牎楠� keys.forEach(key => { let _patten = new RegExp('(^' + key + '\\s+)|(\\s+' + key + '\\s+)', 'ig') if (_patten.test(val)) { - let _error = _position + dict['main.excel.includekey'] + key - errors.push(_error) + errors.push(_position + dict['main.excel.includekey'] + key) } }) } } else if (/^int/ig.test(col.type)) { if (!val && val !== 0) { - let _error = _position + dict['main.excel.content.emptyerror'] - errors.push(_error) + errors.push(_position + dict['main.excel.content.emptyerror']) } else { let _val = val + '' if (!/^(([^0][0-9]+|0)$)|^(([1-9]+)$)/.test(_val)) { // 妫�楠屾槸鍚︿负鏁存暟 - let _error = _position + dict['main.excel.content.interror'] - errors.push(_error) + errors.push(_position + dict['main.excel.content.interror']) } else if ((col.min || col.min === 0) && val < col.min) { // 鏈�灏忓�兼楠� - let _error = _position + dict['main.excel.content.limitmin'] - errors.push(_error) + errors.push(_position + dict['main.excel.content.limitmin']) } else if ((col.max || col.max === 0) && val > col.max) { // 鏈�澶у�兼楠� - let _error = _position + dict['main.excel.content.limitmax'] - errors.push(_error) + errors.push(_position + dict['main.excel.content.limitmax']) } } } else if (/^Decimal/ig.test(col.type)) { if (!val && val !== 0) { - let _error = _position + dict['main.excel.content.emptyerror'] - errors.push(_error) + errors.push(_position + dict['main.excel.content.emptyerror']) } else { let _val = val + '' let _vals = _val.split('.') if (!/^(([^0][0-9]+|0)\.([0-9]+)$)|^(([^0][0-9]+|0)$)|^(([1-9]+)\.([0-9]+)$)|^(([1-9]+)$)/.test(_val)) { // 妫�楠屾槸鍚︿负娴偣鏁� - let _error = _position + dict['main.excel.content.floaterror'] - errors.push(_error) - } else if (_vals[0].length > 18) { // 妫�楠屾暣鏁颁綅 - let _error = _position + dict['main.excel.content.floatIntover'] - errors.push(_error) + errors.push(_position + dict['main.excel.content.floaterror']) + } else if (_vals[0].length > 18) { // 妫�楠屾暣鏁颁綅 + errors.push(_position + dict['main.excel.content.floatIntover']) } else if (_vals[1] && _vals[1].length > col.limit) { // 鏈�灏忓�兼楠� - let _error = _position + dict['main.excel.content.floatPointover'] - errors.push(_error) - } else if ((col.min || col.min === 0) && val < col.min) { // 鏈�灏忓�兼楠� - let _error = _position + dict['main.excel.content.limitmin'] - errors.push(_error) - } else if ((col.max || col.max === 0) && val > col.max) { // 鏈�澶у�兼楠� - let _error = _position + dict['main.excel.content.limitmax'] - errors.push(_error) + errors.push(_position + dict['main.excel.content.floatPointover']) + } else if ((col.min || col.min === 0) && val < col.min) { // 鏈�灏忓�兼楠� + errors.push(_position + dict['main.excel.content.limitmin']) + } else if ((col.max || col.max === 0) && val > col.max) { // 鏈�澶у�兼楠� + errors.push(_position + dict['main.excel.content.limitmax']) } } } else if (col.type === 'date') { - val = val.replace(/(^\s*$)|\t*|\v*/ig, '') - - if (!val && col.required === 'true') { // 蹇呭~鏍¢獙 - let _error = _position + dict['main.excel.content.emptyerror'] - errors.push(_error) - } else { // 鍏抽敭瀛楁牎楠� - keys.forEach(key => { - let _patten = new RegExp('(^' + key + '\\s+)|(\\s+' + key + '\\s+)', 'ig') - if (_patten.test(val)) { - let _error = _position + dict['main.excel.includekey'] + key - errors.push(_error) + if (typeof(val) === 'number') { + if (val > 2958465 || val <= 0) { // 鏃堕棿杩囧ぇ鎴栧皬浜庣瓑浜�0 + errors.push(_position + dict['main.excel.content.date.over']) + } else { // 鏃堕棿鏍煎紡鍖� + if (val < 60) { // 1900-2-29锛宔xcel涓瓨鍦紝瀹為檯涓嶅瓨鍦� + val++ } - }) + val = moment('19000101', 'YYYYMMDD').add(Math.floor(val - 2), 'days').format('YYYY-MM-DD') + } + } else if (typeof(val) === 'string') { + val = val.replace(/(^\s*$)|\t*|\v*/ig, '') + if (!val && col.required === 'true') { // 鏃堕棿蹇呭~鏍¢獙 + errors.push(_position + dict['main.excel.content.emptyerror']) + } else if (val && !/^[1-9][0-9]{3}/.test(val)) { // 鏃堕棿姝e垯鏍¢獙 + errors.push(_position + dict['main.excel.content.date.formatError']) + } + } else { // 鏃堕棿鏍煎紡閿欒 + errors.push(_position + dict['main.excel.content.date.formatError']) } } - if (col.type === 'date') { - vals.push(`case when ${col.Column}='' then '1900-01-01' else dateadd(day,cast('${val}' as int)-2,'1900-01-01') end as ${col.Column}`) - } else { - vals.push(`'${val}' as ${col.Column}`) + vals.push(`'${val}'`) + + if (lindex < 40) { + convals.push(`'${val}' as ${col.Column}`) } }) let _lineIndex = '0000' + (lindex + 1) + '0' _lineIndex = _lineIndex.substring(_lineIndex.length - 6) - vals.push(`'${upId + _lineIndex}' as jskey`) + vals.push(`'${upId + _lineIndex}'`) + vals.push(`'${BID}'`) + + if (lindex < 40) { + convals.push(`'${upId + _lineIndex}' as jskey`) + convals.push(`'${BID}' as BID`) + conLtext.push(`Select ${convals.join(',')}`) + } return `Select ${vals.join(',')}` }) @@ -926,13 +928,13 @@ _sql = ` /* 绯荤粺鐢熸垚 */ - declare @${item.sheet} table (${declarefields.join(',')},jskey nvarchar(50) ) + declare @${item.sheet} table (${declarefields.join(',')},jskey nvarchar(50),BID nvarchar(50) ) Declare @UserName nvarchar(50),@FullName nvarchar(50),@ErrorCode nvarchar(50),@retmsg nvarchar(4000),@tbid Nvarchar(512) Select @ErrorCode='', @retmsg='', @UserName='${userName}', @FullName='${fullName}' ${_initCustomScript} ` - _sqlInsert = `Insert into @${item.sheet} (${fields},jskey)` + _sqlInsert = `Insert into @${item.sheet} (${fields},jskey,BID)` _sqlBottom = ` /* 榛樿sql */ delete tmp_excel_in where upid=@upid@ @@ -946,13 +948,14 @@ aaa: select @ErrorCode as ErrorCode,@retmsg as retmsg` - if (window.GLOB.systemType !== 'official') { + // if (window.GLOB.systemType !== 'production' && options.sysType !== 'cloud') { + if (window.GLOB.systemType !== 'production') { let fsql = ` ${_sql} ${_sqlInsert} /* excel鏁版嵁锛堝墠40鏉★級 */ - ${_Ltext.slice(0, 40).join(' Union all ')} + ${conLtext.join(' Union all ')} ${_sqlBottom} ` fsql = fsql.replace(/\n\s{8}/ig, '\n') @@ -967,7 +970,7 @@ Select @ErrorCode='', @retmsg='', @UserName='${userName}', @FullName='${fullName}' ` } - + return { sql: _sql, lines: result.map((list, index) => { @@ -994,7 +997,7 @@ let _formFieldValue = {} let _actionType = null let appkey = window.GLOB.appkey || '' - let sessionUid = sessionStorage.getItem('SessionUid') || '' + let sessionUid = localStorage.getItem('SessionUid') || '' if (verify.default !== 'false') { // 鍒ゆ柇鏄惁浣跨敤榛樿sql _actionType = btn.sqlType @@ -1150,7 +1153,9 @@ // 鍙橀噺璧嬪�� _initfields = _initfields.join(',') if (_initfields) { - _sql += `select ${_initfields} + _sql += ` + + select ${_initfields} ` } @@ -1551,7 +1556,8 @@ _sql += ` /* 榛樿sql */ - insert into snote (remark,createuserid,CreateUser,CreateStaff) select left('鍒犻櫎琛�:${btn.sql} 鏁版嵁: ${_msg}${primaryKey}='+@ID@,200),@userid@,@username,@fullname delete ${btn.sql} where ${primaryKey}${_ID};` + insert into snote (remark,createuserid,CreateUser,CreateStaff) select left('鍒犻櫎琛�:${btn.sql} 鏁版嵁: ${_msg}${primaryKey}='+@ID@,200),@userid@,@username,@fullname + delete ${btn.sql} where ${primaryKey}${_ID};` } else if (_actionType === 'insertOrUpdate') { _sql += ` /* 榛樿sql */ @@ -1576,7 +1582,8 @@ _sql += ` aaa: select @ErrorCode as ErrorCode,@retmsg as retmsg` - if (window.GLOB.systemType !== 'official') { + // if (window.GLOB.systemType !== 'production' && options.sysType !== 'cloud') { + if (window.GLOB.systemType !== 'production') { _sql = _sql.replace(/\n\s{8}/ig, '\n') console.log(_sql) } -- Gitblit v1.8.0