king
2024-04-24 3c7455f8d64b989181e5773efa6c22368351fa38
src/utils/utils.js
@@ -1145,6 +1145,13 @@
    let _uniquesql = ''
    if (btn.uniques && btn.uniques.length > 0) {
      let textFields = []
      btn.columns.forEach((col) => {
        if (/^Nvarchar/ig.test(col.type)) {
          textFields.push(col.Column)
        }
      })
      btn.uniques.forEach(unique => {
        if (unique.status === 'false' || !unique.verifyType) return
@@ -1153,6 +1160,14 @@
        let _afields = _fields.map(_field => `a.${_field}`)
        _fields_ = _fields_.join(' and ')
        let _where = []
        _fields.forEach(f => {
          if (textFields.includes(f)) {
            _where.push(`${f}!=''`)
          }
        })
        _where = _where.length ? `where ${_where.join(' and ')} ` : ''
        if (unique.verifyType === 'logic' || unique.verifyType === 'logic_temp') {
          _fields_ += ' and b.deleted=0'
        }
@@ -1160,7 +1175,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} ${_where}) a group by ${unique.field} having sum(n)>1
      
      If @tbid!=''
      Begin
@@ -1169,7 +1184,7 @@
      end
      
      ${unique.verifyType.indexOf('temp') === -1 ? `Set @tbid=''
      Select top 1 @tbid=${_afields.join('+\' \'+')} from  #${sheet} a Inner join ${database}${sheet} b on ${_fields_}
      Select top 1 @tbid=${_afields.join('+\' \'+')} from ${_where ? `(select * from #${sheet} ${_where})` : `#${sheet}`} a Inner join ${database}${sheet} b on ${_fields_}
      
      If @tbid!=''
      Begin