From b3547d1c531e479021219fda5df153a11b9b52a3 Mon Sep 17 00:00:00 2001 From: king <18310653075@163.com> Date: 星期一, 31 八月 2020 17:28:09 +0800 Subject: [PATCH] 2020-08-31 --- src/utils/utils.js | 191 +++++++++++++++++++++++------------------------ 1 files changed, 92 insertions(+), 99 deletions(-) diff --git a/src/utils/utils.js b/src/utils/utils.js index c2cc84f..3c58522 100644 --- a/src/utils/utils.js +++ b/src/utils/utils.js @@ -689,7 +689,7 @@ arrfield = arrfield.join(',') if (item.orderBy) { - sql = 'select distinct ' + arrfield + ',' + item.orderBy + ' as orderfield from ' + _datasource + ' order by orderfield ' + item.orderType + sql = `select ${arrfield} from (select distinct ${arrfield},${item.orderBy} as orderfield from ${_datasource} ) a order by orderfield ${item.orderType}` } else { sql = 'select distinct ' + arrfield + ' from ' + _datasource } @@ -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') || '' @@ -765,11 +765,11 @@ val = val.replace(/(^\s*$)|\t*|\v*/ig, '') - if (!val && col.required === 'true') { // 蹇呭~鏍¢獙 + if (!val && col.required === 'true') { // 蹇呭~鏍¢獙 errors.push(_position + dict['main.excel.content.emptyerror']) - } else if (val.length > col.limit) { // 闀垮害鏍¢獙 + } else if (col.limit && val.length > col.limit) { // 闀垮害鏍¢獙 errors.push(_position + dict['main.excel.content.maxlimit']) - } else { // 鍏抽敭瀛楁牎楠� + } else { // 鍏抽敭瀛楁牎楠� keys.forEach(key => { let _patten = new RegExp('(^' + key + '\\s+)|(\\s+' + key + '\\s+)', 'ig') if (_patten.test(val)) { @@ -815,7 +815,10 @@ if (val > 2958465 || val <= 0) { // 鏃堕棿杩囧ぇ鎴栧皬浜庣瓑浜�0 errors.push(_position + dict['main.excel.content.date.over']) } else { // 鏃堕棿鏍煎紡鍖� - val = this.formatExcelDate(val) + 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, '') @@ -840,9 +843,11 @@ _lineIndex = _lineIndex.substring(_lineIndex.length - 6) 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(',')}`) } @@ -923,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@ @@ -943,8 +948,7 @@ aaa: select @ErrorCode as ErrorCode,@retmsg as retmsg` - // if (window.GLOB.systemType !== 'production' && options.sysType !== 'cloud') { - if (window.GLOB.systemType !== 'production') { + if ((window.GLOB.systemType !== 'production' && options.sysType !== 'cloud') || window.debugger === true) { let fsql = ` ${_sql} ${_sqlInsert} @@ -965,7 +969,7 @@ Select @ErrorCode='', @retmsg='', @UserName='${userName}', @FullName='${fullName}' ` } - + return { sql: _sql, lines: result.map((list, index) => { @@ -981,20 +985,6 @@ } /** - * @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 琛ㄥ悕 @@ -1006,7 +996,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 @@ -1257,6 +1247,77 @@ ` }) } + + // 鑷畾涔夐獙璇� + verify.customverifys && verify.customverifys.forEach(item => { + _sql += ` + /* 鑷畾涔夐獙璇� */ + select @tbid='', @ErrorCode='',@retmsg='' + select top 1 @tbid='X' from (${item.sql}) a + If @tbid ${item.result === 'true' ? '!=' : '='}'' + Begin + select @ErrorCode='${item.errorCode}',@retmsg='${item.errmsg}' + goto aaa + end + ` + }) + + // 鍗曞彿鐢熸垚锛屼娇鐢ㄤ笂绾d锛圔ID锛夋垨鍒楄〃鏁版嵁锛屽0鏄庡彉閲忥紙妫�楠岋級 + let _billcodesSql = '' + if (verify.billcodes && verify.billcodes.length > 0) { + verify.billcodes.forEach(item => { + let _ModularDetailCode = '' + 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}'` + } else { + _ModularDetailCode = `'${item.ModularDetailCode}'` + } + + let _declare = '' + let _key = item.field.toLowerCase() + + if (!_vars.includes(_key)) { + _declare = `Declare @${_key} nvarchar(50)` + _vars.push(_key) + } + + _billcodesSql += ` + /* 鍗曞彿鐢熸垚 */ + ${_declare} + select @BillCode='', @${_key}='', @ModularDetailCode='' + ${_lpline} + exec s_get_BillCode + @ModularDetailCode=${_ModularDetailCode}, + @Type=${item.Type}, + @TypeCharOne='${item.TypeCharOne}', + @TypeCharTwo ='${item.TypeCharTwo}', + @BillCode =@BillCode output, + @ErrorCode =@ErrorCode output, + @retmsg=@retmsg output + if @ErrorCode!='' + goto aaa + set @${_key}=@BillCode + ` + }) + + if (_actionType !== 'insertOrUpdate') { + _sql += _billcodesSql + } + } // 鍞竴鎬ч獙璇侊紝蹇呴』瀛樺湪琛ㄥ崟锛堣〃鍗曞瓨鍦ㄦ椂锛屼富閿潎涓哄崟鍊硷級,蹇呴』濉啓鏁版嵁婧愶紝澶氳鎷兼帴鏃朵笉鍙敤 if (formdata && verify.uniques && verify.uniques.length > 0 && btn.Ot !== 'requiredOnce') { @@ -1332,77 +1393,6 @@ ` }) } - - // 鑷畾涔夐獙璇� - verify.customverifys && verify.customverifys.forEach(item => { - _sql += ` - /* 鑷畾涔夐獙璇� */ - select @tbid='', @ErrorCode='',@retmsg='' - select top 1 @tbid='X' from (${item.sql}) a - If @tbid ${item.result === 'true' ? '!=' : '='}'' - Begin - select @ErrorCode='${item.errorCode}',@retmsg='${item.errmsg}' - goto aaa - end - ` - }) - - // 鍗曞彿鐢熸垚锛屼娇鐢ㄤ笂绾d锛圔ID锛夋垨鍒楄〃鏁版嵁锛屽0鏄庡彉閲忥紙妫�楠岋級 - let _billcodesSql = '' - if (verify.billcodes && verify.billcodes.length > 0) { - verify.billcodes.forEach(item => { - let _ModularDetailCode = '' - 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}'` - } else { - _ModularDetailCode = `'${item.ModularDetailCode}'` - } - - let _declare = '' - let _key = item.field.toLowerCase() - - if (!_vars.includes(_key)) { - _declare = `Declare @${_key} nvarchar(50)` - _vars.push(_key) - } - - _billcodesSql += ` - /* 鍗曞彿鐢熸垚 */ - ${_declare} - select @BillCode='', @${_key}='', @ModularDetailCode='' - ${_lpline} - exec s_get_BillCode - @ModularDetailCode=${_ModularDetailCode}, - @Type=${item.Type}, - @TypeCharOne='${item.TypeCharOne}', - @TypeCharTwo ='${item.TypeCharTwo}', - @BillCode =@BillCode output, - @ErrorCode =@ErrorCode output, - @retmsg=@retmsg output - if @ErrorCode!='' - goto aaa - set @${_key}=@BillCode - ` - }) - - if (_actionType !== 'insertOrUpdate') { - _sql += _billcodesSql - } - } let hasvoucher = false @@ -1439,6 +1429,8 @@ let values = [] formdata.forEach(item => { + if (item.writein === false) return + keys.push(item.key.toLowerCase()) values.push('@' + item.key) }) @@ -1482,6 +1474,8 @@ let _arr = [] formdata.forEach(item => { + if (item.writein === false) return + _arr.push(item.key.toLowerCase()) _form.push(item.key + '=@' + item.key) }) @@ -1591,8 +1585,7 @@ _sql += ` aaa: select @ErrorCode as ErrorCode,@retmsg as retmsg` - // if (window.GLOB.systemType !== 'production' && options.sysType !== 'cloud') { - if (window.GLOB.systemType !== 'production') { + if ((window.GLOB.systemType !== 'production' && options.sysType !== 'cloud') || window.debugger === true) { _sql = _sql.replace(/\n\s{8}/ig, '\n') console.log(_sql) } -- Gitblit v1.8.0