king
2019-12-19 ff045a6a19e2e0bd5c2433aae71145401627c22d
src/utils/utils.js
@@ -223,6 +223,58 @@
  }
  /**
   * @description 初始化搜索条件
   * @param {Array}   searches     搜索条件
   * @return {String}  searches    格式化后结果
   */
  static formatCustomMainSearch (searches) {
    if (!searches || searches.length === 0) return {}
    let newsearches = {}
    searches.forEach(item => {
      if (item.type === 'date') {
        let timetail = ''
        if (item.match === '<' || item.match === '<=') {
          timetail = ' 23:59:59.999'
        } else if (item.match === '>' || item.match === '>=') {
          timetail = ' 00:00:00.000'
        }
        if (newsearches[item.key]) {
          newsearches[item.key + '1'] = item.value ? item.value + timetail : null
        } else {
          newsearches[item.key] = item.value ? item.value + timetail : null
        }
      } else if (item.type === 'datemonth') {
        // 月-过滤条件,从月开始至结束
        let _startval = null
        let _endval = null
        if (item.value) {
          _startval = moment(item.value, 'YYYY-MM').startOf('month').format('YYYY-MM-DD') + ' 00:00:00.000'
          _endval = moment(item.value, 'YYYY-MM').endOf('month').format('YYYY-MM-DD') + ' 23:59:59.999'
        }
        newsearches[item.key] = _startval
        newsearches[item.key + '1'] = _endval
      } else if (item.type === 'dateweek') {
        newsearches[item.key] = item.value ? item.value[0] + ' 00:00:00.000' : null
        newsearches[item.key + '1'] = item.value ? item.value[1] + ' 23:59:59.999' : null
      } else if (item.type === 'daterange') {
        newsearches[item.key] = item.value ? item.value[0] + ' 00:00:00.000' : null
        newsearches[item.key + '1'] = item.value ? item.value[1] + ' 23:59:59.999' : null
      } else {
        newsearches[item.key] = item.value
      }
    })
    return newsearches
  }
  /**
   * @description 拼接搜索条件main
   * @param {Array}   searches     搜索条件
   * @return {String}  searchText  拼接结果
@@ -361,7 +413,7 @@
    } else if ((btn.OpenType === 'prompt' || btn.OpenType === 'exec') && btn.sqlType === 'delete') {
      _sql = `insert into snote (remark,createuserid) select '删除表:${btn.sql} 数据: id='+@id,@userid delete ${btn.sql} where ${setting.primaryKey}=@id`
    }
    console.log(_sql)
    return _sql
  }
@@ -374,14 +426,139 @@
  }
  /**
   * @description 创建页面存储过程
   * @return {String}
   */
  static getTableFunc (param, menu, config) {
    let form = ''
    let formParam = ''
    let _columns = []
    if (config.search && config.search.length > 0) {
      let _fields = new Map()
      config.search.forEach(item => {
        if (item.field) {
          let type = ''
          let _f = item.field
          if (item.type.match(/date/ig)) {
            type = 'datetime=null'
          } else {
            type = 'nvarchar(50)=\'\''
          }
          if (_fields.has(item.field)) {
            _f = _f + '1'
          }
          _fields.set(item.field, true)
          formParam = formParam + `mchr13k@${_f} ${type},`
        }
      })
    }
    if (config.columns && config.columns.length > 0) {
      config.columns.forEach(item => {
        if (item.field) {
          _columns.push(`${item.field} as ${item.label}`)
        }
      })
      form = `
        declare @dc table (${_columns.join(',')})
        @tableid ='${menu.MenuID}'
      `
    }
    let Ltext = `create proc ${param.innerFunc}
    ( /*${menu.MenuName}*/
    @BID nvarchar(50)='',
    @ID nvarchar(50)='',${formParam}
    @PageIndex nvarchar(50)='',
    @PageSize nvarchar(50)='',
    @OrderCol nvarchar(50)='',
    @OrderType nvarchar(50)='',
    @sEPTMenuNo nvarchar(50)='${menu.MenuNo}',
    @lang nvarchar(50)='',
    @debug nvarchar(50)='',
    @LoginUID nvarchar(50)='',
    @SessionUid nvarchar(50)='',
    @UserID nvarchar(50),
    @ErrorCode nvarchar(50) out,
    @retmsg nvarchar(4000) out
    )
    as
    begin
    declare  @BegindateTest datetime,@EnddateTest datetime
    select  @BegindateTest=getdate()
    set @ErrorCode=''
    set @retmsg=''
    BEGIN TRY
      /*事务操作*/
      BEGIN TRAN
        /*具体业务操作*/
         /*
        select top 10 * from sProcExcep order by id desc
        declare @UserName  nvarchar(50),@FullName nvarchar(50)
        select @UserName=UserName,@FullName=FullName from SUsers where UID=@UserID
        ${form}
        if 1=2
        begin
          set @ErrorCode='E'
          set @retmsg='在此写报错'
          goto GOTO_RETURN
        end
        insert into sNote (remark,createuserid,CreateUser,CreateStaff)
        select '在此写日志',@UserID,@UserName,@FullName
        */
      COMMIT TRAN
      SET NOCOUNT ON
      RETURN
    END TRY
    BEGIN CATCH
      /*错误处理*/
      ROLLBACK TRAN
      DECLARE @ErrorMessage NVARCHAR(4000);
      DECLARE @ErrorSeverity INT;
      DECLARE @ErrorState INT;
      /*把自定义的友好的错误信息提示加上*/
      set @ErrorCode=cast(ERROR_NUMBER() as nvarchar(50))
      SET @retmsg=ERROR_MESSAGE();
      SELECT @ErrorMessage=ERROR_MESSAGE(),
        @ErrorSeverity=ERROR_SEVERITY(),
        @ErrorState=ERROR_STATE();
      RAISERROR(@ErrorMessage, /*-- Message text.*/
        @ErrorSeverity, /*-- Severity.*/
        @ErrorState  /*-- State.*/
        );
    END CATCH
    GOTO_RETURN:
      ROLLBACK TRAN
    END`
    console.log(Ltext)
    Ltext = Ltext.replace(/\n\s{4}/ig, 'mchr13k')
    return Ltext
  }
  /**
   * @description 创建存储过程
   * @return {String}
   */
  static getfunc (param, btn, menu, columns) {
    let form = ''
    let formParam = ''
    console.log(menu)
    console.log(columns)
    if (param.fields && param.fields.length > 0) {
      let _fields = []
      param.fields.forEach(item => {
@@ -511,7 +688,7 @@
      ROLLBACK TRAN
      
    END`
    console.log(Ltext)
    Ltext = Ltext.replace(/\n\s{4}/ig, 'mchr13k')
    return Ltext