| | |
| | | } |
| | | |
| | | /** |
| | | * @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 表名 |
| | |
| | | let verify = btn.verify || {} |
| | | let _formFieldValue = {} |
| | | // 需要声明的变量集 |
| | | 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', 'id', 'bid', 'loginuid', 'sessionuid', 'userid', 'appkey'] |
| | | let _vars = ['tbid', 'errorcode', 'retmsg', 'billcode', 'bvoucher', 'fibvoucherdate', 'fiyear', 'username', 'fullname'] |
| | | |
| | | // 主键字段 |
| | | let primaryKey = setting.primaryKey || 'id' |
| | |
| | | let _sql = `Declare @tbid nvarchar(50),@ErrorCode nvarchar(50),@retmsg nvarchar(4000),@BillCode nvarchar(50),@BVoucher nvarchar(50),@FIBVoucherDate nvarchar(50), @FiYear nvarchar(50), @UserName nvarchar(50),@FullName nvarchar(50) |
| | | ` |
| | | |
| | | let _initvars = ['ID', 'BID', 'LoginUID', 'SessionUid', 'UserID', 'Appkey'] // 已赋值字段集 |
| | | // let _initvars = ['ID', 'BID', 'LoginUID', 'SessionUid', 'UserID', 'Appkey'] // 已赋值字段集 |
| | | // let _initvars = ['id', 'bid', 'loginuid', 'sessionuid', 'userid', 'appkey'] // 已赋值字段集 |
| | | let _initvars = [] // 已赋值字段集 |
| | | let _initfields = [] |
| | | let _declarefields = [] |
| | | |
| | |
| | | if (formdata) { |
| | | formdata.forEach(form => { |
| | | _formFieldValue[form.key] = form.value |
| | | let _key = form.key.toLowerCase() |
| | | |
| | | if (!_initvars.includes(form.key)) { |
| | | _initvars.push(form.key) |
| | | _initfields.push(`@${form.key}='${form.value}'`) |
| | | if (!_initvars.includes(_key)) { |
| | | _initvars.push(_key) |
| | | |
| | | if (form.type === 'number' && typeof(form.value) === 'number') { |
| | | _initfields.push(`@${_key}=${form.value}`) |
| | | } else { |
| | | _initfields.push(`@${_key}='${form.value}'`) |
| | | } |
| | | } |
| | | |
| | | if (!_vars.includes(form.key)) { |
| | | _vars.push(form.key) |
| | | if (!_vars.includes(_key)) { |
| | | _vars.push(_key) |
| | | |
| | | let _type = `nvarchar(${form.fieldlen})` |
| | | |
| | |
| | | _type = `decimal(18,${form.fieldlen})` |
| | | } |
| | | |
| | | _declarefields.push(`@${form.key} ${_type}`) |
| | | _declarefields.push(`@${_key} ${_type}`) |
| | | } |
| | | }) |
| | | } |
| | |
| | | |
| | | if (logcolumns && logcolumns.length > 0) { |
| | | logcolumns.forEach(col => { |
| | | if (!_initvars.includes(col.field)) { |
| | | _initvars.push(col.field) |
| | | let _key = col.field.toLowerCase() |
| | | |
| | | if (!_initvars.includes(_key)) { |
| | | _initvars.push(_key) |
| | | |
| | | let _val = data.hasOwnProperty(col.field) ? data[col.field] : '' |
| | | _initfields.push(`@${col.field}='${_val}'`) |
| | | |
| | | if (col.type === 'number' && typeof(_val) === 'number') { |
| | | _initfields.push(`@${_key}=${_val}`) |
| | | } else { |
| | | _initfields.push(`@${_key}='${_val}'`) |
| | | } |
| | | } |
| | | |
| | | if (!_vars.includes(col.field)) { |
| | | _vars.push(col.field) |
| | | if (!_vars.includes(_key)) { |
| | | _vars.push(_key) |
| | | |
| | | let _type = `nvarchar(${col.fieldlength || 50})` |
| | | |
| | | if (col.type === 'number') { |
| | | let _length = (col.decimal || col.decimal === 0) ? col.decimal : 18 |
| | | let _length = col.decimal ? col.decimal : 0 |
| | | _type = `decimal(18,${_length})` |
| | | } else if (col.type === 'picture' || col.type === 'textarea') { |
| | | _type = `nvarchar(${col.fieldlength || 512})` |
| | | } |
| | | |
| | | _declarefields.push(`@${col.field} ${_type}`) |
| | | _declarefields.push(`@${_key} ${_type}`) |
| | | } |
| | | }) |
| | | } |
| | |
| | | ` |
| | | } |
| | | |
| | | // 添加时主键为空 |
| | | if (btn.sqlType === 'insert') { |
| | | primaryId = '' |
| | | } |
| | | // 添加时主键为空 改为前台生成 |
| | | // if (btn.sqlType === 'insert') { |
| | | // primaryId = '' |
| | | // } |
| | | |
| | | // 去除禁用的验证 |
| | | if (verify.contrasts) { |
| | |
| | | |
| | | // 唯一性验证,必须存在表单(表单存在时,主键均为单值),必须填写数据源 |
| | | if (formdata && verify.uniques && verify.uniques.length > 0) { |
| | | let hasBid = false // 检验表单及列字段中是否有bid |
| | | let _keys_ = Object.keys(_formFieldValue).map(key => key.toLowerCase()) |
| | | if (_keys_.includes('bid')) { |
| | | hasBid = true |
| | | } |
| | | |
| | | verify.uniques.forEach(item => { |
| | | let _fieldValue = [] // 表单键值对field=value |
| | | let _value = [] // 表单值,用于错误提示 |
| | | let _labels = item.fieldlabel.split(',') // 表单提示文字 |
| | | |
| | | item.field.split(',').forEach((_field, index) => { |
| | | _fieldValue.push(`${_field}='${_formFieldValue[_field]}'`) |
| | | let _fval = `'${_formFieldValue[_field]}'` |
| | | // if (['id', 'bid', 'loginuid', 'sessionuid', 'userid', 'appkey'].includes(_field.toLowerCase())) { |
| | | // _fval = '@' + _field + '@' |
| | | // } |
| | | if (_field.toLowerCase() === 'bid' && !hasBid) { // 表单中没有bid则使用系统bid变量 |
| | | _fval = '@BID@' |
| | | } |
| | | _fieldValue.push(`${_field}=${_fval}`) |
| | | _value.push(`${_labels[index] || ''}:${_formFieldValue[_field] || ''}`) |
| | | }) |
| | | |
| | |
| | | } |
| | | |
| | | let _declare = '' |
| | | if (!_vars.includes(item.field)) { |
| | | _declare = `Declare @${item.field} nvarchar(50)` |
| | | let _key = item.field.toLowerCase() |
| | | |
| | | if (!_vars.includes(_key)) { |
| | | _declare = `Declare @${_key} nvarchar(50)` |
| | | _vars.push(_key) |
| | | } |
| | | _vars.push(item.field) |
| | | |
| | | _sql += `${_declare} |
| | | select @BillCode='', @${item.field}='' |
| | | select @BillCode='', @${_key}='' |
| | | exec s_get_BillCode |
| | | @ModularDetailCode='${_ModularDetailCode}', |
| | | @Type=${item.Type}, |
| | |
| | | @retmsg=@retmsg output |
| | | if @ErrorCode!='' |
| | | goto aaa |
| | | set @${item.field}=@BillCode |
| | | set @${_key}=@BillCode |
| | | ` |
| | | }) |
| | | } |
| | | |
| | | let _updateconfig = '' |
| | | let hasvoucher = false |
| | | |
| | | // 凭证-显示列中选取,必须选行 |
| | | if (verify.voucher && verify.voucher.enabled && data) { |
| | | let _voucher = verify.voucher |
| | | |
| | | _updateconfig = ',BVoucher=@BVoucher,FIBVoucherDate=@FIBVoucherDate,FiYear=@FiYear' |
| | | hasvoucher = true |
| | | |
| | | _sql += `exec s_BVoucher_Create |
| | | @Bill ='${data[_voucher.linkField]}', |
| | |
| | | } |
| | | |
| | | // 用于取用户信息 |
| | | let _user = `select @UserName=UserName,@FullName=FullName from SUsers where UID=@UserID |
| | | 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 |
| | | |
| | | // 添加、修改、逻辑删除、物理删除 |
| | | if (btn.OpenType === 'pop' && btn.sqlType === 'insert' && verify.default !== 'false') { |
| | | let keys = [] |
| | | let values = [] |
| | | |
| | | formdata.forEach(item => { |
| | | if (item.type === 'funcvar') { |
| | | keys.push(item.key) |
| | | keys.push(item.key.toLowerCase()) |
| | | values.push('@' + item.key) |
| | | } else if (item.type === 'number') { |
| | | keys.push(item.key) |
| | | keys.push(item.key.toLowerCase()) |
| | | values.push(item.value) |
| | | } else { |
| | | keys.push(item.key) |
| | | keys.push(item.key.toLowerCase()) |
| | | values.push('\'' + item.value + '\'') |
| | | } |
| | | }) |
| | | |
| | | if (!keys.includes(primaryKey)) { |
| | | keys.push(primaryKey) |
| | | values.push('\'' + primaryId + '\'') |
| | | } |
| | | if (!keys.includes('createuserid')) { |
| | | keys.push('createuserid') |
| | | values.push('@userid@') |
| | | } |
| | | if (!keys.includes('createuser')) { |
| | | keys.push('createuser') |
| | | values.push('@username') |
| | | } |
| | | if (!keys.includes('createstaff')) { |
| | | keys.push('createstaff') |
| | | values.push('@fullname') |
| | | } |
| | | if (!keys.includes('bid')) { |
| | | keys.push('bid') |
| | | values.push('@BID@') |
| | | } |
| | | |
| | | keys = keys.join(',') |
| | | values = values.join(',') |
| | | _sql += _user |
| | | _sql += `insert into ${btn.sql} (${keys},createuserid,CreateUser,CreateStaff,BID) select ${values},@userid,@username,@fullname,@BID;` |
| | | _sql += `insert into ${btn.sql} (${keys}) select ${values};` |
| | | } else if (btn.OpenType === 'pop' && btn.sqlType === 'update' && verify.default !== 'false') { |
| | | let _form = [] |
| | | let _arr = [] |
| | | |
| | | formdata.forEach(item => { |
| | | _arr.push(item.key.toLowerCase()) |
| | | |
| | | if (item.type === 'funcvar') { |
| | | _form.push(item.key + '=@' + item.key) |
| | | } else if (item.type === 'number') { |
| | |
| | | _form.push(item.key + '=\'' + item.value + '\'') |
| | | } |
| | | }) |
| | | |
| | | if (!_arr.includes('modifydate')) { |
| | | _form.push('modifydate=getdate()') |
| | | } |
| | | if (!_arr.includes('modifyuserid')) { |
| | | _form.push('modifyuserid=@userid@') |
| | | } |
| | | if (hasvoucher) { |
| | | if (!_arr.includes('bvoucher')) { |
| | | _form.push('BVoucher=@BVoucher') |
| | | } |
| | | if (!_arr.includes('fibvoucherdate')) { |
| | | _form.push('FIBVoucherDate=@FIBVoucherDate') |
| | | } |
| | | if (!_arr.includes('fiyear')) { |
| | | _form.push('FiYear=@FiYear') |
| | | } |
| | | } |
| | | |
| | | _form = _form.join(',') |
| | | _sql += `update ${btn.sql} set ${_form},modifydate=getdate(),modifyuserid=@userid${_updateconfig} where ${primaryKey}=@${primaryKey};` |
| | | _sql += `update ${btn.sql} set ${_form} where ${primaryKey}=@${primaryKeyName};` |
| | | } else if ((btn.OpenType === 'prompt' || btn.OpenType === 'exec') && btn.sqlType === 'LogicDelete' && verify.default !== 'false') { // 逻辑删除 |
| | | _sql += `update ${btn.sql} set deleted=1,modifydate=getdate(),modifyuserid=@userid where ${primaryKey}=@${primaryKey};` |
| | | _sql += `update ${btn.sql} set deleted=1,modifydate=getdate(),modifyuserid=@userid@ where ${primaryKey}=@${primaryKeyName};` |
| | | } else if ((btn.OpenType === 'prompt' || btn.OpenType === 'exec') && btn.sqlType === 'delete' && verify.default !== 'false') { // 物理删除 |
| | | let _msg = '' |
| | | if (data && logcolumns && logcolumns.length > 0) { |
| | |
| | | }) |
| | | } |
| | | _sql += _user |
| | | _sql += `insert into snote (remark,createuserid,CreateUser,CreateStaff) select '删除表:${btn.sql} 数据: ${_msg}${primaryKey}='+@${primaryKey},@userid,@username,@fullname delete ${btn.sql} where ${primaryKey}=@${primaryKey};` |
| | | _sql += `insert into snote (remark,createuserid,CreateUser,CreateStaff) select '删除表:${btn.sql} 数据: ${_msg}${primaryKey}='+@${primaryKeyName},@userid@,@username,@fullname delete ${btn.sql} where ${primaryKey}=@${primaryKeyName};` |
| | | } |
| | | |
| | | // 拼接自定义脚本 |