| | |
| | | } |
| | | |
| | | /** |
| | | * @description 获取excel导入参数 |
| | | * @return {String} btn 按钮 |
| | | * @return {String} data excel数据 |
| | | */ |
| | | static getExcelInSql (item, data, dict) { |
| | | let btn = item.verify |
| | | let keys = ['delete', 'drop', 'insert', 'truncate', 'update'] |
| | | |
| | | let errors = [] |
| | | let _topline = btn.range || 0 |
| | | let _Ltext = data.map((item, lindex) => { |
| | | let vals = btn.columns.map((col, cindex) => { |
| | | let val = item[col.Column] !== undefined ? item[col.Column] : '' |
| | | let _position = (_topline + lindex + 1) + dict['main.excel.line'] + ' ' + (cindex + 1) + dict['main.excel.column'] + ' ' |
| | | |
| | | if (/^Nvarchar/ig.test(col.type)) { |
| | | if (typeof(val) === 'number') { |
| | | val = val.toString() |
| | | } |
| | | |
| | | val = val.replace(/(^\s*$)|\t*|\v*/ig, '') |
| | | |
| | | let limitlen = col.type.match(/\d+/)[0] |
| | | |
| | | if (!val && col.required === 'true') { // 必填校验 |
| | | let _error = _position + dict['main.excel.content.emptyerror'] |
| | | errors.push(_error) |
| | | } else if (val.length > limitlen) { // 长度校验 |
| | | let _error = _position + dict['main.excel.content.maxlimit'] |
| | | 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) |
| | | } |
| | | }) |
| | | } |
| | | } else if (/^int/ig.test(col.type)) { |
| | | if (typeof(val) !== 'number' || parseInt(val) < parseFloat(val)) { // 检验是否为整数 |
| | | let _error = _position + dict['main.excel.content.interror'] |
| | | 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) |
| | | } |
| | | } else if (/^Decimal/ig.test(col.type)) { |
| | | let _val = val + '' |
| | | _val = _val.split('.') |
| | | let limitlen = col.type.match(/\d+/ig)[1] |
| | | |
| | | if (typeof(val) !== 'number') { // 检验是否为浮点数 |
| | | let _error = _position + dict['main.excel.content.floaterror'] |
| | | errors.push(_error) |
| | | } else if (_val[0].length > 18) { // 检验整数位 |
| | | let _error = _position + dict['main.excel.content.floatIntover'] |
| | | errors.push(_error) |
| | | } else if (_val[1] && _val[1].length > limitlen) { // 最小值检验 |
| | | 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) |
| | | } |
| | | } |
| | | |
| | | return `'${val}' as ${col.Column}` |
| | | }) |
| | | |
| | | if (!item.innerFunc) { |
| | | vals.push(`@upid+'${this.getuuid()}' as jskey`) |
| | | } |
| | | |
| | | return `Select ${vals.join(',')}` |
| | | }) |
| | | |
| | | _Ltext = _Ltext.join(' Union all ') |
| | | |
| | | let _sql = '' |
| | | |
| | | if (!item.innerFunc) { |
| | | let declarefields = [] |
| | | let fields = [] |
| | | let timestamp = new Date().getTime() |
| | | |
| | | btn.columns.forEach(col => { |
| | | declarefields.push(`${col.Column} ${col.type}`) |
| | | fields.push(col.Column) |
| | | }) |
| | | |
| | | fields = fields.join(',') |
| | | |
| | | _sql = `declare @${btn.sheet} table (${declarefields.join(',')},jskey nvarchar(50) ) |
| | | Declare @UserName nvarchar(50),@FullName nvarchar(50) ,@upid nvarchar(50) |
| | | select @UserName=UserName,@FullName=FullName from SUsers where UID=@UserID@ |
| | | |
| | | set @upid='${timestamp}' |
| | | |
| | | Insert into @${btn.sheet} (${fields},jskey) |
| | | ${_Ltext} |
| | | |
| | | Insert into ${btn.sheet} (${fields},createuserid,createuser,createstaff,bid,upid) |
| | | Select ${fields},@userid@,@username,@fullname,@BID@,@upid From @${btn.sheet} |
| | | |
| | | Delete @${btn.sheet}` |
| | | |
| | | } else { |
| | | _sql = _Ltext |
| | | } |
| | | |
| | | console.log(_sql) |
| | | return { |
| | | sql: _sql, |
| | | errors: errors.join('; ') |
| | | } |
| | | } |
| | | |
| | | /** |
| | | * @description 使用系统函数时(sPC_TableData_InUpDe ),生成sql语句 |
| | | * @return {String} type 执行类型 |
| | | * @return {String} table 表名 |
| | |
| | | ` |
| | | } |
| | | |
| | | // 添加时主键为空 |
| | | if (btn.sqlType === 'insert') { |
| | | primaryId = '' |
| | | } |
| | | // 添加时主键为空 改为前台生成 |
| | | // if (btn.sqlType === 'insert') { |
| | | // primaryId = '' |
| | | // } |
| | | |
| | | // 去除禁用的验证 |
| | | if (verify.contrasts) { |
| | |
| | | } |
| | | }) |
| | | |
| | | if (!keys.includes(primaryKey)) { |
| | | keys.push(primaryKey) |
| | | values.push('\'' + primaryId + '\'') |
| | | } |
| | | if (!keys.includes('createuserid')) { |
| | | keys.push('createuserid') |
| | | values.push('@userid@') |