| | |
| | | * @description sql加密 |
| | | * @return {String} value |
| | | */ |
| | | static formatOptions (value) { |
| | | static formatOptions (value, isUnFormat = false) { |
| | | if (!value) return '' |
| | | |
| | | let salt = 'minKe' // 盐值 |
| | |
| | | value: ' mrlbkk ' |
| | | }] |
| | | |
| | | // 替换关键字 |
| | | format.forEach(item => { |
| | | let reg = new RegExp('(^|\\s)' + item.key + '(\\s|$)', 'ig') |
| | | value = value.replace(reg, item.value) |
| | | }) |
| | | if (!isUnFormat) { // 加密 |
| | | // 替换关键字 |
| | | format.forEach(item => { |
| | | let reg = new RegExp('(^|\\s)' + item.key + '(\\s|$)', 'ig') |
| | | value = value.replace(reg, item.value) |
| | | }) |
| | | |
| | | // 1、替换%符(数据库中解析后sql报错) |
| | | value = value.replace(/%/ig, ' mpercent ') |
| | | |
| | | // 1、encode编码(中文字符超出base64加密范围),2、base64加密 |
| | | value = window.btoa(window.encodeURIComponent(value)) |
| | | |
| | | // 插入字符 |
| | | let index = Math.floor(value.length / 2) |
| | | value = value.slice(0, index) + salt + value.slice(index) |
| | | |
| | | // base64加密 |
| | | value = window.btoa(value) |
| | | } else { // 解密 |
| | | try { |
| | | value = window.atob(value) |
| | | value = value.replace(salt, '') |
| | | value = window.decodeURIComponent(window.atob(value)) |
| | | value = value.replace(/\smpercent\s/g, '%') |
| | | |
| | | // 1、替换%符(数据库中解析后sql报错),2、去除收尾多余空格 |
| | | value = value.replace(/%/ig, 'mpercent') |
| | | value = value.replace(/(^\s|\s$)/ig, '') |
| | | |
| | | // 1、encode编码(中文字符超出base64加密范围),2、base64加密 |
| | | value = window.btoa(window.encodeURIComponent(value)) |
| | | |
| | | // 插入字符 |
| | | let index = Math.floor(value.length / 2) |
| | | value = value.slice(0, index) + salt + value.slice(index) |
| | | |
| | | // base64加密 |
| | | value = window.btoa(value) |
| | | format.forEach(item => { |
| | | let reg = new RegExp(item.value, 'g') |
| | | value = value.replace(reg, ' ' + item.key + ' ') |
| | | }) |
| | | |
| | | value = value.replace(/(^\s+|\s+$)/ig, '') |
| | | } catch { |
| | | console.warn('UnFormat Failure') |
| | | value = '' |
| | | } |
| | | } |
| | | |
| | | return value |
| | | } |
| | |
| | | let errors = [] |
| | | let _topline = btn.range || 0 |
| | | let upId = this.getuuid() |
| | | |
| | | if (btn.scripts && btn.scripts.length > 0) { |
| | | btn.scripts = btn.scripts.filter(item => item.status !== 'false') |
| | | } |
| | | |
| | | let _Ltext = data.map((item, lindex) => { |
| | | let vals = btn.columns.map((col, cindex) => { |
| | | let val = item[col.Column] !== undefined ? item[col.Column] : '' |
| | |
| | | }) |
| | | } |
| | | } else if (/^int/ig.test(col.type)) { |
| | | if (!val) { |
| | | if (!val && val !== 0) { |
| | | let _error = _position + dict['main.excel.content.emptyerror'] |
| | | errors.push(_error) |
| | | } else { |
| | |
| | | } |
| | | } |
| | | } else if (/^Decimal/ig.test(col.type)) { |
| | | if (!val) { |
| | | if (!val && val !== 0) { |
| | | let _error = _position + dict['main.excel.content.emptyerror'] |
| | | errors.push(_error) |
| | | } else { |
| | |
| | | |
| | | let _insert = '' |
| | | |
| | | if (btn.scripts && btn.scripts.length > 0) { |
| | | btn.scripts.forEach(script => { |
| | | if (script.position !== 'front') return |
| | | |
| | | _insert += ` |
| | | ${script.sql} |
| | | ` |
| | | }) |
| | | } |
| | | |
| | | if (btn.default !== 'false') { |
| | | _insert = ` |
| | | Insert into ${item.sheet} (${fields},createuserid,createuser,createstaff,bid) |
| | |
| | | |
| | | if (btn.scripts && btn.scripts.length > 0) { |
| | | btn.scripts.forEach(script => { |
| | | if (script.status === 'false') return |
| | | if (script.position === 'front') return |
| | | |
| | | _insert += ` |
| | | ${script.sql} |
| | |
| | | * @return {String} type 执行类型 |
| | | * @return {String} table 表名 |
| | | */ |
| | | static getSysDefaultSql (btn, setting, formdata, param, data, logcolumns) { |
| | | static getSysDefaultSql (btn, setting, formdata, param, data, logcolumns, tab) { |
| | | let primaryId = param.ID |
| | | let BID = param.BID |
| | | let verify = btn.verify || {} |
| | | let _formFieldValue = {} |
| | | let _actionType = null |
| | | |
| | | if (verify.default !== 'false') { // 判断是否使用默认sql |
| | | _actionType = btn.sqlType |
| | | } |
| | | |
| | | // 需要声明的变量集 |
| | | // 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', 'modulardetailcode'] |
| | |
| | | |
| | | if (!_vars.includes(_key)) { |
| | | _vars.push(_key) |
| | | |
| | | if (form.fieldlen && form.fieldlen > 2048) { |
| | | form.fieldlen = 'max' |
| | | } |
| | | |
| | | let _type = `nvarchar(${form.fieldlen})` |
| | | |
| | |
| | | |
| | | if (!_vars.includes(_key)) { |
| | | _vars.push(_key) |
| | | |
| | | if (col.fieldlength && col.fieldlength > 2048) { |
| | | col.fieldlength = 'max' |
| | | } |
| | | |
| | | let _type = `nvarchar(${col.fieldlength || 50})` |
| | | |
| | |
| | | |
| | | // 自定义验证 |
| | | if (verify.customverifys && verify.customverifys.length > 0) { |
| | | verify.customverifys.forEach(item => { |
| | | verify.customverifys.forEach(item => { |
| | | _sql += `select @tbid='', @ErrorCode='',@retmsg='' |
| | | select top 1 @tbid='X' from (${item.sql}) a |
| | | If @tbid ${item.result === 'true' ? '!=' : '='}'' |
| | |
| | | } |
| | | |
| | | // 单号生成,使用上级id(BID)或列表数据,声明变量(检验) |
| | | 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('${btn.uuid}'+@BID@,48)` |
| | | _lpline = `set @ModularDetailCode= 'Lp'+ right('${item.mark || btn.uuid}'+@BID@,48)` |
| | | } else { |
| | | _lpline = `set @ModularDetailCode= 'Lp'+ right('${btn.uuid}'+@${item.linkField},48)` |
| | | _lpline = `set @ModularDetailCode= 'Lp'+ right('${item.mark || btn.uuid}'+@${item.linkField},48)` |
| | | } |
| | | _ModularDetailCode = '@ModularDetailCode' |
| | | } else if (item.TypeCharOne === 'BN') { |
| | |
| | | _vars.push(_key) |
| | | } |
| | | |
| | | _sql += `${_declare} |
| | | _billcodesSql += `${_declare} |
| | | select @BillCode='', @${_key}='', @ModularDetailCode='' |
| | | ${_lpline} |
| | | exec s_get_BillCode |
| | |
| | | set @${_key}=@BillCode |
| | | ` |
| | | }) |
| | | |
| | | if (_actionType !== 'insertOrUpdate') { |
| | | _sql += _billcodesSql |
| | | } |
| | | } |
| | | |
| | | let hasvoucher = false |
| | |
| | | @VoucherTypeOne ='${_voucher.VoucherTypeOne}', |
| | | @VoucherTypeTwo ='${_voucher.VoucherTypeTwo}', |
| | | @Type =${_voucher.Type}, |
| | | @UserID=@UserID@, |
| | | @Username=@Username, |
| | | @FullName=@FullName, |
| | | @BVoucher =@BVoucher OUTPUT , |
| | | @FIBVoucherDate =@FIBVoucherDate OUTPUT , |
| | | @FiYear =@FiYear OUTPUT , |
| | |
| | | |
| | | let primaryKeyName = ['id', 'bid', 'loginuid', 'sessionuid', 'userid', 'appkey'].includes(primaryKey.toLowerCase()) ? primaryKey + '@' : primaryKey |
| | | |
| | | let _actionType = null |
| | | |
| | | if (verify.default !== 'false') { // 判断是否使用默认sql |
| | | _actionType = btn.sqlType |
| | | } |
| | | |
| | | // 添加、修改、逻辑删除、物理删除 |
| | | if (_actionType === 'insert') { |
| | | let _insertsql = '' |
| | | if (_actionType === 'insert' || _actionType === 'insertOrUpdate') { // 添加语句 |
| | | let keys = [] |
| | | let values = [] |
| | | |
| | |
| | | values.push('@fullname') |
| | | } |
| | | if (!keys.includes('bid')) { |
| | | keys.push('bid') |
| | | if (tab && tab.foreignKey && !keys.includes(tab.foreignKey.toLowerCase())) { |
| | | keys.push(tab.foreignKey) |
| | | } else { |
| | | keys.push('bid') |
| | | } |
| | | values.push('@BID@') |
| | | } else if (tab && tab.foreignKey && !keys.includes(tab.foreignKey.toLowerCase())) { |
| | | keys.push(tab.foreignKey) |
| | | values.push('@BID@') |
| | | } |
| | | |
| | | keys = keys.join(',') |
| | | values = values.join(',') |
| | | _sql += `insert into ${btn.sql} (${keys}) select ${values};` |
| | | } else if (_actionType === 'update') { |
| | | _insertsql = `insert into ${btn.sql} (${keys}) select ${values};` |
| | | } |
| | | |
| | | let _updatesql = '' |
| | | if (_actionType === 'update' || _actionType === 'insertOrUpdate') { // 修改语句 |
| | | let _form = [] |
| | | let _arr = [] |
| | | |
| | |
| | | _arr.push(item.key.toLowerCase()) |
| | | |
| | | if (item.type === 'funcvar') { |
| | | _form.push(item.key + '=@' + item.key) |
| | | if (_actionType === 'update') { |
| | | _form.push(item.key + '=@' + item.key) |
| | | } else if (_actionType === 'insertOrUpdate') { // 添加或修改时,函数变量添加表单数值 |
| | | _form.push(item.key + '=\'' + item.value + '\'') |
| | | } |
| | | } else if (item.type === 'number') { |
| | | _form.push(item.key + '=' + item.value) |
| | | } else { |
| | |
| | | _form.push('FiYear=@FiYear') |
| | | } |
| | | } |
| | | |
| | | _form = _form.join(',') |
| | | _sql += `update ${btn.sql} set ${_form} where ${primaryKey}=@${primaryKeyName};` |
| | | _updatesql = `update ${btn.sql} set ${_form} where ${primaryKey}=@${primaryKeyName};` |
| | | } |
| | | |
| | | // 拼接自定义脚本 |
| | | if (verify.scripts && verify.scripts.length > 0) { |
| | | let _scripts = '' |
| | | verify.scripts.forEach(item => { |
| | | if (item.position !== 'front') return |
| | | |
| | | _scripts += ` |
| | | ${item.sql}` |
| | | }) |
| | | _sql += `${_scripts}` |
| | | } |
| | | |
| | | // 添加、修改、逻辑删除、物理删除 |
| | | if (_actionType === 'insert') { |
| | | _sql += _insertsql |
| | | } else if (_actionType === 'update') { |
| | | _sql += _updatesql |
| | | } else if (_actionType === 'LogicDelete') { // 逻辑删除 |
| | | _sql += `update ${btn.sql} set deleted=1,modifydate=getdate(),modifyuserid=@userid@ where ${primaryKey}=@${primaryKeyName};` |
| | | |
| | |
| | | } |
| | | }) |
| | | } |
| | | _sql += `insert into snote (remark,createuserid,CreateUser,CreateStaff) select '删除表:${btn.sql} 数据: ${_msg}${primaryKey}='+@${primaryKeyName},@userid@,@username,@fullname delete ${btn.sql} where ${primaryKey}=@${primaryKeyName};` |
| | | _sql += `insert into snote (remark,createuserid,CreateUser,CreateStaff) select left('删除表:${btn.sql} 数据: ${_msg}${primaryKey}='+@${primaryKeyName},200),@userid@,@username,@fullname delete ${btn.sql} where ${primaryKey}=@${primaryKeyName};` |
| | | } else if (_actionType === 'insertOrUpdate') { |
| | | _sql += `select @tbid='' |
| | | select @tbid='X' from ${btn.sql} where ${primaryKey}=@ID@ |
| | | if @tbid='' |
| | | begin |
| | | ${_billcodesSql} |
| | | ${_insertsql} |
| | | end |
| | | else |
| | | begin |
| | | ${_updatesql} |
| | | end |
| | | ` |
| | | } |
| | | |
| | | // 拼接自定义脚本 |
| | | if (verify.scripts && verify.scripts.length > 0) { |
| | | let _scripts = '' |
| | | verify.scripts.forEach(item => { |
| | | if (item.position === 'front') return |
| | | |
| | | _scripts += ` |
| | | ${item.sql}` |
| | | }) |