king
2020-04-15 02a05c4e82e74c290e80ae7710fbb394ed7cac7a
src/utils/utils.js
@@ -164,8 +164,8 @@
    })
    // 1、替换%符(数据库中解析后sql报错),2、去除收尾多余空格
    value = value.replace(/%/ig, 'mpercent')
    value = value.replace(/(^\s|\s$)/ig, '')
    value = value.replace(/%/ig, ' mpercent ')
    // value = value.replace(/(^\s|\s$)/ig, '')
    // 1、encode编码(中文字符超出base64加密范围),2、base64加密
    value = window.btoa(window.encodeURIComponent(value))
@@ -505,7 +505,7 @@
            })
          }
        } 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 {
@@ -523,7 +523,7 @@
            }
          }
        } 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 {
@@ -667,11 +667,17 @@
   * @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']
@@ -901,6 +907,7 @@
    }
    // 单号生成,使用上级id(BID)或列表数据,声明变量(检验)
    let _billcodesSql  = ''
    if (verify.billcodes && verify.billcodes.length > 0) {
      verify.billcodes.forEach(item => {
        let _ModularDetailCode = ''
@@ -932,7 +939,7 @@
          _vars.push(_key)
        }
        _sql += `${_declare}
        _billcodesSql += `${_declare}
          select @BillCode='', @${_key}='', @ModularDetailCode=''
          ${_lpline}
          exec s_get_BillCode
@@ -948,6 +955,10 @@
          set @${_key}=@BillCode
          `
      })
      if (_actionType !== 'insertOrUpdate') {
        _sql += _billcodesSql
      }
    }
    let hasvoucher = false
@@ -979,14 +990,8 @@
    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 = []
@@ -1020,14 +1025,21 @@
        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@')
      }
      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 = []
@@ -1060,9 +1072,15 @@
          _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 (_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};`
    
@@ -1078,6 +1096,19 @@
        })
      }
      _sql += `insert into snote (remark,createuserid,CreateUser,CreateStaff) select '删除表:${btn.sql} 数据: ${_msg}${primaryKey}='+@${primaryKeyName},@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
      `
    }
    // 拼接自定义脚本