king
2023-08-27 9097590d848989c4660162f20ca1b8e55eb6ca55
2023-08-27
3个文件已修改
187 ■■■■■ 已修改文件
src/menu/components/table/edit-table/columns/tableIn/index.jsx 10 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
src/tabviews/custom/components/table/edit-table/normalTable/index.jsx 13 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
src/utils/utils.js 164 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
src/menu/components/table/edit-table/columns/tableIn/index.jsx
@@ -535,8 +535,16 @@
                    <Input value={verify.innerFunc} placeholder="" autoComplete="off" onChange={(e) => this.onOptionChange(e.target.value, 'innerFunc')}/>
                  </Form.Item>
                </Col> : null}
                {verify.intertype === 'inner' ? <Col span={8}>
                  <Form.Item required label="记录用户">
                    <Radio.Group value={verify.recordUser || 'false'} onChange={(e) => this.onOptionChange(e.target.value, 'recordUser')}>
                      <Radio value="false">否</Radio>
                      <Radio value="true">是</Radio>
                    </Radio.Group>
                  </Form.Item>
                </Col> : null}
                {verify.intertype === 'system' ? <Col span={8}>
                  <Form.Item required label={'默认sql'}>
                  <Form.Item required label="默认sql">
                    <Radio.Group value={verify.default} onChange={(e) => this.onOptionChange(e.target.value, 'default')}>
                      <Radio value="true">执行</Radio>
                      <Radio value="false">不执行</Radio>
src/tabviews/custom/components/table/edit-table/normalTable/index.jsx
@@ -1674,12 +1674,12 @@
    if (submit.intertype === 'system') { // 系统存储过程
      param.func = 'sPC_TableData_InUpDe'
      
      param.excel_in_type = 'true'
      param.LText1 = Utils.formatOptions(result.insert)
      param.LText2 = Utils.formatOptions(result.bottom)
      delete param.excel_in
      param.exec_type = 'y'
      param.LText = Utils.formatOptions(result.sql)
      param.timestamp = moment().format('YYYY-MM-DD HH:mm:ss')
      param.secretkey = Utils.encrypt(param.LText, param.timestamp)
      param.secretkey = Utils.encrypt('', param.timestamp)
      param.menuname = submit.logLabel
@@ -1701,6 +1701,11 @@
    } else if (submit.intertype === 'inner' && submit.innerFunc) { // 自定义存储过程
      param.func = submit.innerFunc
      if (submit.recordUser === 'true') {
        param.username = sessionStorage.getItem('User_Name') || ''
        param.fullname = sessionStorage.getItem('Full_Name') || ''
      }
      Api.genericInterface(param).then((res) => {
        if (res.status) {
          this.execSuccess(res)
src/utils/utils.js
@@ -1140,9 +1140,10 @@
      
      aaa: select @ErrorCode as ErrorCode,@retmsg as retmsg`
    sql = sql.replace(/\n\s{6}/ig, '\n')
    if (window.GLOB.debugger === true) {
      console.info(sql.replace(/\n\s{8}/ig, '\n'))
      console.info(sql)
    }
  } else {
    for(let i = 0; i < _Ltext.length; i += 20) {
@@ -1193,44 +1194,12 @@
  
  database = database ? (database[0] || '') : ''
  let _initCustomScript = '' // 初始化脚本
  let _prevCustomScript = '' // 默认sql前执行脚本
  let _backCustomScript = '' // 默认sql后执行脚本
  if (btn.scripts && btn.intertype === 'system') {
    btn.scripts.forEach(script => {
      if (script.status === 'false') return
      if (script.position === 'init') {
        _initCustomScript += `
      /* 自定义脚本 */
      ${script.sql}
      `
      } else if (script.position === 'front') {
        _prevCustomScript += `
      /* 自定义脚本 */
      ${script.sql}
      `
      } else {
        _backCustomScript += `
      /* 自定义脚本 */
      ${script.sql}
      `
      }
    })
  }
  // 控制台打印数据
  let conLtext = []
  let _Ltext = data.map(item => {
    let vals = []
    let convals = []
    columns.forEach(col => {
      let val = item[col.field]
      vals.push(`'${val}'`)
      convals.push(`'${val}' as ${col.field}`)
    })
    let key = item.$$uuid
@@ -1240,24 +1209,55 @@
    vals.push(`'${type}'`)
    vals.push(`'${BID}'`)
    convals.push(`'${key}' as jskey`)
    convals.push(`'${type}' as data_type`)
    convals.push(`'${BID}' as BID`)
    conLtext.push(`Select ${convals.join(',')}`)
    return `Select ${vals.join(',')}`
  })
  let result = []
  for(let i = 0; i < _Ltext.length; i += 20) {
    result.push(_Ltext.slice(i, i + 20))
  }
  let _sql = ''
  let _sqlInsert = ''
  let _sqlBottom = ''
  let sql = ''
  if (btn.intertype === 'system') {
    let _initCustomScript = '' // 初始化脚本
    let _prevCustomScript = '' // 默认sql前执行脚本
    let _backCustomScript = '' // 默认sql后执行脚本
    let tb = new RegExp('(^|\\s)@' + sheet + '(\\s|$|(|))', 'ig')
    btn.scripts && btn.scripts.forEach(script => {
      if (script.status === 'false') return
      let _sql = script.sql
      _sql = _sql.replace(tb, `#${sheet}`)
      _sql = _sql.replace(/@BID@/ig, `'${BID}'`)
      _sql = _sql.replace(/@LoginUID@/ig, `'${sessionStorage.getItem('LoginUID') || ''}'`)
      _sql = _sql.replace(/@SessionUid@/ig, `'${localStorage.getItem('SessionUid') || ''}'`)
      _sql = _sql.replace(/@UserID@/ig, `'${sessionStorage.getItem('UserID') || ''}'`)
      _sql = _sql.replace(/@Appkey@/ig, `'${window.GLOB.appkey || ''}'`)
      _sql = _sql.replace(/@typename@/ig, `'admin'`)
      if (sessionStorage.getItem('dataM') === 'true') { // 数据权限
        _sql = _sql.replace(/\$@/ig, '/*').replace(/@\$/ig, '*/').replace(/@datam@/ig, '\'Y\'')
      } else {
        _sql = _sql.replace(/@\$|\$@/ig, '').replace(/@datam@/ig, '\'\'')
      }
      if (script.position === 'init') {
        _initCustomScript += `
      /* 自定义脚本 */
      ${_sql}
      `
      } else if (script.position === 'front') {
        _prevCustomScript += `
      /* 自定义脚本 */
      ${_sql}
      `
      } else {
        _backCustomScript += `
      /* 自定义脚本 */
      ${_sql}
      `
      }
    })
    let _uniquesql = ''
    if (btn.uniques && btn.uniques.length > 0) {
      btn.uniques.forEach(unique => {
@@ -1275,7 +1275,7 @@
        _uniquesql += `
      /* 重复性验证 */
      Set @tbid=''
      Select top 1 @tbid=${_fields.join('+\' \'+')} from (select 1 as n,${unique.field} from @${sheet} ) a group by ${unique.field} having sum(n)>1
      Select top 1 @tbid=${_fields.join('+\' \'+')} from (select 1 as n,${unique.field} from #${sheet} ) a group by ${unique.field} having sum(n)>1
      
      If @tbid!=''
      Begin
@@ -1284,7 +1284,7 @@
      end
      
      ${unique.verifyType.indexOf('temp') === -1 ? `Set @tbid=''
      Select top 1 @tbid=${_afields.join('+\' \'+')} from  @${sheet} a Inner join ${sheet} b on ${_fields_}
      Select top 1 @tbid=${_afields.join('+\' \'+')} from  #${sheet} a Inner join ${sheet} b on ${_fields_}
      
      If @tbid!=''
      Begin
@@ -1313,86 +1313,50 @@
      _insert = `
      /* 默认sql */
      Insert into ${database}${sheet} (${fields},createuserid,createuser,createstaff,bid) 
      Select ${fields},@userid@,@username,@fullname,@BID@ From @${sheet}
      Select ${fields},'${sessionStorage.getItem('UserID') || ''}',@username,@fullname,'${BID}' From #${sheet}
      `
    }
    _sql = `
    sql = `
      /* 系统生成 */
      declare @${sheet} table (${declarefields.join(',')},jskey nvarchar(50),data_type nvarchar(50),BID nvarchar(50) )
      create table #${sheet} (${declarefields.join(',')},jskey nvarchar(50),data_type nvarchar(50),BID nvarchar(50) )
      Declare @UserName nvarchar(50),@FullName nvarchar(50),@RoleID nvarchar(512),@mk_departmentcode nvarchar(512),@mk_organization nvarchar(512),@mk_user_type nvarchar(20),@mk_nation nvarchar(50),@mk_province nvarchar(50),@mk_city nvarchar(50),@mk_district nvarchar(50),@mk_address nvarchar(100),@ErrorCode nvarchar(50),@retmsg nvarchar(4000),@tbid Nvarchar(512)
      
      Select  @ErrorCode='', @retmsg='', @UserName='${userName}', @FullName='${fullName}', @RoleID='${RoleID}', @mk_departmentcode='${departmentcode}', @mk_organization='${organization}', @mk_user_type='${mk_user_type}', @mk_nation='${nation}', @mk_province='${province}', @mk_city='${city}', @mk_district='${district}', @mk_address='${address}'
      ${_initCustomScript}
      `
    _sqlInsert = `Insert into @${sheet} (${fields},jskey,data_type,BID)`
    _sqlBottom = `
      /* 默认sql */
      delete tmp_excel_in where upid=@upid@
      Insert into #${sheet} (${fields},jskey,data_type,BID)
      
      delete tmp_excel_in where datediff(day,createdate,getdate())>15
      /* excel数据*/
      ${_Ltext.join(' Union all ')}
      ${_uniquesql}
      ${_prevCustomScript}
      ${_insert}
      ${_backCustomScript}
      Delete @${sheet}
      drop table #${sheet}
      
      aaa: select @ErrorCode as ErrorCode,@retmsg as retmsg`
    _sql = _sql.replace(/@BID@/ig, `'${BID}'`)
    _sql = _sql.replace(/@LoginUID@/ig, `'${sessionStorage.getItem('LoginUID') || ''}'`)
    _sql = _sql.replace(/@SessionUid@/ig, `'${localStorage.getItem('SessionUid') || ''}'`)
    _sql = _sql.replace(/@UserID@/ig, `'${sessionStorage.getItem('UserID') || ''}'`)
    _sql = _sql.replace(/@Appkey@/ig, `'${window.GLOB.appkey || ''}'`)
    _sql = _sql.replace(/@typename@/ig, `'admin'`)
    _sqlBottom = _sqlBottom.replace(/@BID@/ig, `'${BID}'`)
    _sqlBottom = _sqlBottom.replace(/@LoginUID@/ig, `'${sessionStorage.getItem('LoginUID') || ''}'`)
    _sqlBottom = _sqlBottom.replace(/@SessionUid@/ig, `'${localStorage.getItem('SessionUid') || ''}'`)
    _sqlBottom = _sqlBottom.replace(/@UserID@/ig, `'${sessionStorage.getItem('UserID') || ''}'`)
    _sqlBottom = _sqlBottom.replace(/@Appkey@/ig, `'${window.GLOB.appkey || ''}'`)
    _sqlBottom = _sqlBottom.replace(/@typename@/ig, `'admin'`)
    if (sessionStorage.getItem('dataM') === 'true') { // 数据权限
      _sql = _sql.replace(/\$@/ig, '/*').replace(/@\$/ig, '*/').replace(/@datam@/ig, '\'Y\'')
      _sqlBottom = _sqlBottom.replace(/\$@/ig, '/*').replace(/@\$/ig, '*/').replace(/@datam@/ig, '\'Y\'')
    } else {
      _sql = _sql.replace(/@\$|\$@/ig, '').replace(/@datam@/ig, '\'\'')
      _sqlBottom = _sqlBottom.replace(/@\$|\$@/ig, '').replace(/@datam@/ig, '\'\'')
    }
    sql = sql.replace(/\n\s{6}/ig, '\n')
    if (window.GLOB.debugger === true) {
      let fsql = `
      ${_sql}
      ${_sqlInsert}
      /* table数据 */
      ${conLtext.join(' Union all \n')}
      ${_sqlBottom}
      `
      fsql = fsql.replace(/\n\s{8}/ig, '\n')
      console.info(fsql)
      console.info(sql)
    }
  } else { // s_sDataDictb_excelIn 云端密钥验证参数
    _sql = `
      /* 系统生成 */
      declare @${sheet} table (jskey nvarchar(50))
      Declare @UserName nvarchar(50),@FullName nvarchar(50),@RoleID nvarchar(512),@mk_departmentcode nvarchar(512),@mk_organization nvarchar(512),@mk_user_type nvarchar(20),@mk_nation nvarchar(50),@mk_province nvarchar(50),@mk_city nvarchar(50),@mk_district nvarchar(50),@mk_address nvarchar(100),@ErrorCode nvarchar(50),@retmsg nvarchar(4000),@tbid Nvarchar(512)
      Select  @ErrorCode='', @retmsg='', @UserName='${userName}', @FullName='${fullName}', @RoleID='${RoleID}', @mk_departmentcode='${departmentcode}', @mk_organization='${organization}', @mk_user_type='${mk_user_type}', @mk_nation='${nation}', @mk_province='${province}', @mk_city='${city}', @mk_district='${district}', @mk_address='${address}'
      `
  } else {
    for(let i = 0; i < _Ltext.length; i += 20) {
      result.push(_Ltext.slice(i, i + 20))
    }
  }
  return {
    sql: _sql,
    sql: sql,
    lines: result.map((list, index) => {
      return {
        Ltext: window.btoa(window.encodeURIComponent(list.join(' Union all '))),
        Sort: (index + 1) * 10
      }
    }),
    insert: _sqlInsert,
    bottom: _sqlBottom
    })
  }
}