king
2025-02-05 125517c3e09320afa84a9e19a084d56c8ec3317e
src/utils/utils.js
@@ -71,6 +71,7 @@
      uuid.push(_options.substr(Math.floor(Math.random() * 0x20), 1))
    }
    uuid = timestamp + uuid.join('')
    uuid = uuid.replace(/minke/ig, 'mnkie')
    return uuid
  }
@@ -264,7 +265,7 @@
            }
            if (d) {
              item.initval = moment(d).subtract(item.initval, 'month').format('YYYY-MM')
              item.initval = moment(d).subtract(item.$initval, 'month').format('YYYY-MM')
            }
          }
        }
@@ -293,6 +294,10 @@
              item.initval = [moment().startOf('month').format(format), moment().endOf('month').format(format)].join(',')
            } else if (item.initval === 'lastMonth') {
              item.initval = [moment().subtract(1, 'months').startOf('month').format(format), moment().subtract(1, 'months').endOf('month').format(format)].join(',')
            } else if (item.initval === 'year') {
              item.initval = [moment().startOf('year').format(format), moment().endOf('year').format(format)].join(',')
            } else if (item.initval === 'lastYear') {
              item.initval = [moment().subtract(1, 'years').startOf('year').format(format), moment().subtract(1, 'years').endOf('year').format(format)].join(',')
            } else if (item.initval) {
              try {
                let _initval = JSON.parse(item.initval)
@@ -334,6 +339,10 @@
                item.initval = [moment(d).startOf('month').format(format), moment(d).endOf('month').format(format)].join(',')
              } else if (item.$initval === 'lastMonth') {
                item.initval = [moment(d).subtract(1, 'months').startOf('month').format(format), moment(d).subtract(1, 'months').endOf('month').format(format)].join(',')
              } else if (item.$initval === 'year') {
                item.initval = [moment(d).startOf('year').format(format), moment(d).endOf('year').format(format)].join(',')
              } else if (item.$initval === 'lastYear') {
                item.initval = [moment(d).subtract(1, 'years').startOf('year').format(format), moment(d).subtract(1, 'years').endOf('year').format(format)].join(',')
              } else {
                try {
                  let _initval = JSON.parse(item.$initval)
@@ -416,7 +425,11 @@
          item.$first = true
        }
      }
      if (window.backend && ['select', 'link', 'multiselect', 'checkcard', 'radio'].includes(item.type) && item.resourceType === '1') {
        item.uuid = md5(config.uuid + item.uuid)
      }
      item.oriInitval = item.initval
      if (values) {
@@ -714,6 +727,15 @@
  static getSearchkeys (searches) {
    let searchText = []
    let matchs = {
      'like': '01',
      'not like': '02',
      '=': '03',
      '>': '04',
      '<': '05',
      '>=': '06',
      '<=': '07',
    }
    searches.forEach(item => {
      if (item.forbid || !item.value) return
@@ -834,17 +856,21 @@
        searchText.push({
          key: item.key,
          match: '>=',
          type: 'number',
          type: 'text',
          value: val[0] || -999999999
        }, {
          key: item.key,
          match: '<=',
          type: 'number',
          type: 'text',
          value: val[1] || 999999999
        })
      } else {
        searchText.push(cell)
      }
    })
    searchText.forEach(item => {
      item.match = matchs[item.match] || '01'
    })
    return searchText
@@ -1504,7 +1530,7 @@
 * @return {Object} item   按钮信息
 * @return {Array}  data   excel数据
 */
export function getEditTableSql (verify, data, columns) {
export function getEditTableSql (verify, data, columns, setting) {
  let btn = verify
  let userName = sessionStorage.getItem('User_Name') || ''
  let fullName = sessionStorage.getItem('Full_Name') || ''
@@ -1623,6 +1649,7 @@
        let _fields = unique.field.split(',')
        let _fields_ = _fields.map(_field => `a.${_field}=b.${_field}`)
        _fields_ = _fields_.join(' and ')
        _fields_ += ` and a.jskey != b.${setting.primaryKey || 'id'}`
        let _where = []
        _fields.forEach(f => {
@@ -1679,6 +1706,7 @@
    let declarefields = []
    let fields = []
    let upFields = []
    columns.forEach(col => {
      let key = col.field.toLowerCase()
@@ -1686,15 +1714,27 @@
      declarefields.push(`${col.field} ${col.datatype}`)
      fields.push(col.field)
      upFields.push(`${col.field}=t.${col.field}`)
    })
    fields = fields.join(',')
    upFields = upFields.join(',')
    let _insert = ''
    if (btn.default !== 'false') {
      _insert = `
      /* 默认sql */
      Insert into ${database}${sheet} (${fields},createuserid,createuser,createstaff,bid)
      update a set ${upFields},modifydate=getdate(),modifyuserid='${sessionStorage.getItem('UserID') || ''}',modifyuser=@username,modifystaff=@fullname,deleted=0
      from (select * from #${sheet} where data_type='upt') t
      inner join ${database}${sheet} a on t.jskey=a.${setting.primaryKey || 'id'}
      update a set deleted=1,modifydate=getdate(),modifyuserid='${sessionStorage.getItem('UserID') || ''}',modifyuser=@username,modifystaff=@fullname
      from (select * from #${sheet} where data_type='del') t
      inner join ${database}${sheet} a on t.jskey=a.${setting.primaryKey || 'id'}
      delete t from #${sheet} t inner join ${database}${sheet} a on t.jskey=a.${setting.primaryKey || 'id'}
      Insert into ${database}${sheet} (${fields},createuserid,createuser,createstaff,bid)
      Select ${fields},'${sessionStorage.getItem('UserID') || ''}',@username,@fullname,'${BID}' From #${sheet}
      `
    }
@@ -1753,11 +1793,10 @@
 * @return {Array}   columns   显示列
 * @return {Boolean} retmsg    是否需要数据返回
 */
export function getSysDefaultSql (btn, setting, formdata, param, data, columns, retmsg = false) {
export function getSysDefaultSql (btn, setting, formdata, param, data, columns, retmsg = false, submitType = '') {
  let primaryId = param.ID
  let BID = param.BID || ''
  let verify = btn.verify || {}
  let datavars = {}                 // 声明的变量,表单及显示列
  let _actionType = null
  let _callbacksql = ''
@@ -1791,7 +1830,7 @@
  })
  // 需要声明的变量集
  let _vars = ['tbid', 'errorcode', 'retmsg', 'billcode', 'bvoucher', 'fibvoucherdate', 'fiyear', 'username', 'fullname', 'modulardetailcode', 'roleid', 'mk_departmentcode', 'mk_organization', 'mk_user_type', 'mk_nation', 'mk_province', 'mk_city', 'mk_district', 'mk_address', 'mk_deleted', 'bid']
  let _vars = ['tbid', 'errorcode', 'retmsg', 'billcode', 'bvoucher', 'fibvoucherdate', 'fiyear', 'username', 'fullname', 'modulardetailcode', 'roleid', 'mk_departmentcode', 'mk_organization', 'mk_user_type', 'mk_nation', 'mk_province', 'mk_city', 'mk_district', 'mk_address', 'mk_deleted', 'bid', 'mk_submit_type']
  // 主键字段
  let primaryKey = setting.primaryKey || 'id'
@@ -1803,18 +1842,28 @@
  let _initFormfields = []
  let _initColfields = []
  let _declarefields = []
  let verifyValSql = ''
  // 获取字段键值对
  formdata && formdata.forEach(form => {
    if (form.$verify) {
      verifyValSql += `
      if @${form.key}=${form.type === 'number' ? 0 : `''`}
      begin
        select @errorcode='E',@retmsg='${form.label},关联主表失效'
        goto aaa
      end
      `
    }
    let _key = form.key.toLowerCase()
    datavars[_key] = form.value
    if (!_initvars.includes(_key)) {
      _initvars.push(_key)
      let val = form.value
      if (form.type === 'number' || form.type === 'rate') {
        if (isNaN(val)) {
        if (isNaN(val) || val === '') {
          val = 0
        }
        _initFormfields.push(`@${_key}=${val}`)
@@ -1862,14 +1911,12 @@
  // 添加数据中字段,表单值优先(按钮不选行或多行拼接时跳过)
  if (data && btn.Ot !== 'notRequired' && columns && columns.length > 0) {
    datavars = {..._data, ...datavars}
    const setField = (col) => {
      if (!col.field) return
      let _key = col.field.toLowerCase()
      if (!_initvars.includes(_key)) {
        let _val = datavars.hasOwnProperty(_key) ? datavars[_key] : ''
        let _val = _data.hasOwnProperty(_key) ? _data[_key] : ''
        if (col.datatype && /^date/ig.test(col.datatype) && !_val) {
          _val = '1949-10-01'
@@ -1924,7 +1971,7 @@
    _declarefields = ',' + _declarefields
  }
  _sql = `/* 系统生成 */
      Declare @tbid nvarchar(50),@ErrorCode nvarchar(50),@retmsg nvarchar(4000),@BillCode nvarchar(50),@BVoucher nvarchar(50),@FIBVoucherDate nvarchar(50), @FiYear nvarchar(50),@ModularDetailCode nvarchar(50), @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),@mk_deleted int,@bid nvarchar(50)${_declarefields}
      Declare @tbid nvarchar(50),@ErrorCode nvarchar(50),@retmsg nvarchar(4000),@BillCode nvarchar(50),@BVoucher nvarchar(50),@FIBVoucherDate nvarchar(50), @FiYear nvarchar(50),@ModularDetailCode nvarchar(50), @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),@mk_deleted int,@bid nvarchar(50),@mk_submit_type nvarchar(50)${_declarefields}
    `
  let userName = sessionStorage.getItem('User_Name') || '' 
@@ -1942,7 +1989,7 @@
  // 初始化凭证及用户信息字段
  _sql += `
      /* 凭证及用户信息初始化赋值 */
      select @BVoucher='',@FIBVoucherDate='',@FiYear='',@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}', @mk_deleted=1, @bid='${BID}', @BillCode='', @ModularDetailCode=''
      select @BVoucher='',@FIBVoucherDate='',@FiYear='',@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}', @mk_deleted=1, @bid='${BID}', @mk_submit_type='${submitType}', @BillCode='', @ModularDetailCode=''
      `
  // 表单变量赋值
@@ -2097,22 +2144,21 @@
    verify.billcodes.forEach(item => {
      let _key = item.field.toLowerCase()
      let _linkKey = item.linkField ? item.linkField.toLowerCase() : ''
      if (!keys.includes(_key)) return // 表单中不含单号生成字段
      let _lpline = ''
      if (item.TypeCharOne === 'Lp') {
        if (_linkKey === 'bid' && BID) { // 替换bid
        if (/^BID$/ig.test(item.linkField)) {
          _lpline = `set @ModularDetailCode= 'Lp'+ right('${item.mark || btn.uuid}'+@BID@,48)`
        } else {
          _lpline = `set @ModularDetailCode= 'Lp'+ right('${item.mark || btn.uuid}'+@${_linkKey},48)`
          _lpline = `set @ModularDetailCode= 'Lp'+ right('${item.mark || btn.uuid}'+@${item.linkField},48)`
        }
      } else if (item.TypeCharOne === 'BN') {
        if (_linkKey === 'bid' && BID) { // 替换bid
        if (/^BID$/ig.test(item.linkField)) {
          _lpline = `set @ModularDetailCode= 'BN'+ right(@BID@,48)`
        } else {
          _lpline = `set @ModularDetailCode= 'BN'+ right(@${_linkKey},48)`
          _lpline = `set @ModularDetailCode= 'BN'+ right(@${item.linkField},48)`
        }
      } else {
        _lpline = `set @ModularDetailCode= right('${item.ModularDetailCode}',50)`
@@ -2158,18 +2204,27 @@
      item.field.split(',').forEach((_field, index) => {
        let _key = _field.toLowerCase()
        let _val = datavars[_key] !== undefined ? datavars[_key] : ''
        let _val = ''
        let _val2 = ''
        arr.push(_key)
        if (_key === 'bid' && !_val) { // 表单中没有bid则使用系统bid变量
          _val = BID
        if (_key === 'bid') {
          _val = `'${BID}'`
        } else {
          _val = `@${_field}`
        }
        _fieldValue.push(`${_key}='${_val}'`)
        _value.push(`${_labels[index] || ''}:${_val || ''}`)
        if (_key === 'bid') {
          _val2 = BID
        } else {
          _val2 = `' + @${_field} + '`
        }
        _fieldValue.push(`${_key}=${_val}`)
        _value.push(`${_labels[index] || ''}:${_val2}`)
      })
      if (!arr.includes(primaryKey.toLowerCase())) {
      if (!arr.includes(primaryKey.toLowerCase()) && btn.Ot !== 'notRequired') {
        _fieldValue.push(`${primaryKey} !='${primaryId}'`)
      }
@@ -2222,13 +2277,18 @@
  // 凭证-显示列中选取,必须选行
  if (verify.voucher && verify.voucher.enabled) {
    let _voucher = verify.voucher
    let linkField = `@${_voucher.linkField}`
    if (/^BID$/ig.test(_voucher.linkField)) {
      linkField = `'${BID}'`
    }
    hasvoucher = true
    _sql += `
      /* 创建凭证 */
      exec s_BVoucher_Create
        @Bill ='${_data[_voucher.linkField.toLowerCase()] || ''}',
        @Bill = ${linkField},
        @BVoucherType ='${_voucher.BVoucherType}',
        @VoucherTypeOne ='${_voucher.VoucherTypeOne}',
        @VoucherTypeTwo ='${_voucher.VoucherTypeTwo}',
@@ -2606,6 +2666,10 @@
      error = '行信息中无工作流参数'
    }
    if (!error && verify.flowSql !== 'true' && verify.flowType !== 'start' && line && line.approvalMethod === 'countersign') {
      error = '会签流程需要使用默认脚本'
    }
    if (error) {
      status = 0
      statusName = '异常'
@@ -2654,6 +2718,33 @@
        _sql += `
      /* 工作流默认sql */
      set @retmsg =''
      select @retmsg='X' from s_my_works_flow_role where works_flow_id=@ID@ and works_flow_code=@works_flow_code@ and deleted=0 and userid =@userid@ and works_flow_detail_id =@works_flow_detail_id
      if @retmsg =''
      begin
          select @retmsg='X' from s_my_works_flow_role where works_flow_id=@ID@ and works_flow_code=@works_flow_code@ and userid=@userid@ and works_flow_detail_id =@works_flow_detail_id
          if @retmsg !=''
          begin
              select @ErrorCode='E', @retmsg='当前单据已审核,请刷新后重试'
              goto aaa
          end
          set @retmsg =''
          select @retmsg=userid from s_my_works_flow_role where works_flow_id=@id@ and works_flow_code=@works_flow_code@ and deleted=0 and works_flow_detail_id =@works_flow_detail_id
          if @retmsg !=''
          begin
              select @retmsg=workerCode+workerName from BD_workers where id=@retmsg
              select @retmsg='页面数据已更新,或没有当前单据的审批权限,请联系'+@retmsg+'操作'
              goto aaa
          end
          select @retmsg='页面数据已更新,或没有当前单据的审批权限'
          goto aaa
      end
      declare ${_declare},@works_flow_key_id nvarchar(50),@works_flow_key_status nvarchar(20),@s_my_works_flow_log_param  nvarchar(max),@s_my_works_flow_log_status int,@s_my_works_flow_log_statusname nvarchar(50),@s_my_works_flow_log_detail_id  nvarchar(50)
      select ${_select},@works_flow_key_id='',@works_flow_key_status ='',@s_my_works_flow_log_param='',@s_my_works_flow_log_status=0,@s_my_works_flow_log_statusname='',@s_my_works_flow_log_detail_id=''
@@ -2710,32 +2801,45 @@
        _sql += `
      /* 工作流默认sql */
      set @retmsg =''
      select @retmsg='X' from s_my_works_flow_role where works_flow_id=@ID@ and works_flow_code=@works_flow_code@ and deleted=0 and userid =@userid@
      select @retmsg='X' from s_my_works_flow_role where works_flow_id=@ID@ and works_flow_code=@works_flow_code@ and deleted=0 and userid =@userid@ and works_flow_detail_id =@works_flow_detail_id
      if @retmsg =''
      begin
          select @retmsg='X' from s_my_works_flow_role where works_flow_id=@ID@ and works_flow_code=@works_flow_code@ and userid=@userid@
          select @retmsg='X' from s_my_works_flow_role where works_flow_id=@ID@ and works_flow_code=@works_flow_code@ and userid=@userid@ and works_flow_detail_id =@works_flow_detail_id
          if @retmsg !=''
          begin
              select @ErrorCode='E', @retmsg='当前单据已审核,请刷新后重试'
            goto aaa
              goto aaa
          end
          if @dataM@ !='' 
          begin
            set @retmsg =''
            select @retmsg='X' from s_my_works_flow_role where works_flow_id=@ID@ and works_flow_code=@works_flow_code@ and deleted=0
            select @retmsg='X' from s_my_works_flow_role where works_flow_id=@ID@ and works_flow_code=@works_flow_code@ and deleted=0 and works_flow_detail_id =@works_flow_detail_id
            if @retmsg != ''
            begin
                goto goto_mk
            end
          end
          else
          begin
              set @retmsg =''
              select @retmsg=userid from s_my_works_flow_role where works_flow_id=@id@ and works_flow_code=@works_flow_code@ and deleted=0 and works_flow_detail_id =@works_flow_detail_id
              if @retmsg !=''
              begin
                  select @retmsg=workerCode+workerName from BD_workers where id=@retmsg
                  select @retmsg='页面数据已更新,或没有当前单据的审批权限,请联系'+@retmsg+'操作'
                  goto aaa
              end
          end
          select @retmsg='页面数据已更新,或没有当前单据的审批权限'
            goto aaa
      end
          goto aaa
      end
      goto_mk:
@@ -2749,7 +2853,7 @@
      update s_my_works_flow_role set deleted=10,modifydate=getdate(),upid=@time_id@,modifyuserid=@userid@,modifyuser=@username,modifystaff=@fullname 
      where works_flow_id=@ID@ and works_flow_code=@works_flow_code@ and deleted=0
      ${line.mknode === 'startEdge' ? `update s_my_works_flow_role set deleted=0,modifydate=getdate(),upid=@time_id@,modifyuserid=@userid@,modifyuser=@username,modifystaff=@fullname
      ${line.mknode === 'startEdge' ? `update s_my_works_flow_role set deleted=0,modifydate=getdate(),upid=@time_id@,modifyuserid=@userid@,modifyuser=@username,modifystaff=@fullname,works_flow_detail_id=@works_flow_detail_id@
      where works_flow_id=@ID@ and works_flow_code=@works_flow_code@ and typecharone='begin'` : ''}
      if @check_userids@ != ''
@@ -2808,6 +2912,10 @@
    _sql += _backCustomScript
  }
  if (verifyValSql) {
    _sql += verifyValSql
  }
  if (window.GLOB.breakpoint) {
    let start = new RegExp('\\/\\*\\$breakpoint_begin_' + window.GLOB.breakpoint + '@', 'ig')
    let end = new RegExp('@breakpoint_end_' + window.GLOB.breakpoint + '\\$\\*\\/', 'ig')