From 2d3f82c3e07e6acaedbeae8b4ce0849dd588abc6 Mon Sep 17 00:00:00 2001 From: king <18310653075@163.com> Date: 星期三, 29 七月 2020 10:09:32 +0800 Subject: [PATCH] 2020-07-29 --- src/utils/utils.js | 130 ++++++++++++++++++++++++------------------ 1 files changed, 74 insertions(+), 56 deletions(-) diff --git a/src/utils/utils.js b/src/utils/utils.js index 9b4447d..3d0e29e 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,87 @@ 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 { // 鏃堕棿鏍煎紡鍖� + val = this.formatExcelDate(val) + } + } 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 +925,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 +945,14 @@ aaa: select @ErrorCode as ErrorCode,@retmsg as retmsg` - if (window.GLOB.systemType !== 'official' && options.sysType !== 'cloud') { + // 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') @@ -983,6 +983,20 @@ } /** + * @description 鏍煎紡鍖杄xcel涓殑date鍊� + * @param {Number} number 鏃堕棿鍊� + */ + static formatExcelDate(number) { + const time = new Date((number - 1) * 24 * 3600000 + 1) + time.setYear(time.getFullYear() - 70) + const year = time.getFullYear() + const month = time.getMonth() + 1 + const date = time.getDate() - 1 + + return `${year}-${(month < 10 ? '0' + month : month)}-${(date < 10 ? '0' + date : date)}` + } + + /** * @description 浣跨敤绯荤粺鍑芥暟鏃讹紙sPC_TableData_InUpDe 锛夛紝鐢熸垚sql璇彞 * @return {String} type 鎵ц绫诲瀷 * @return {String} table 琛ㄥ悕 @@ -994,7 +1008,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 +1164,9 @@ // 鍙橀噺璧嬪�� _initfields = _initfields.join(',') if (_initfields) { - _sql += `select ${_initfields} + _sql += ` + + select ${_initfields} ` } @@ -1551,7 +1567,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 +1593,8 @@ _sql += ` aaa: select @ErrorCode as ErrorCode,@retmsg as retmsg` - if (window.GLOB.systemType !== 'official' && options.sysType !== 'cloud') { + // 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