king
2021-08-23 5166ce2427279fff0af29aca44346b60c65e3159
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
 
export default class SettingUtils {
  /**
   * @description 生成前置或后置语句
   * @return {String}  scripts       脚本
   */
  static getCustomDebugSql (scripts) {
    let sql = ''
    let _customScript = ''
 
    scripts.forEach(script => {
      if (script.status === 'false') return
 
      _customScript += `
      ${script.sql}
      `
    })
 
    if (_customScript) {
      _customScript = `declare @ErrorCode nvarchar(50),@retmsg nvarchar(4000),@UserName nvarchar(50),@FullName nvarchar(50),@RoleID nvarchar(512),@departmentcode nvarchar(50),@organization nvarchar(50),@login_city nvarchar(50) select @ErrorCode='',@retmsg =''
        ${_customScript}
      `
    }
 
    _customScript = _customScript.replace(/@\$|\$@/ig, '')
    _customScript = _customScript.replace(/@userName@|@fullName@|@login_city@/ig, `''`)
    // 外联数据库替换
    if (window.GLOB.externalDatabase !== null) {
      _customScript = _customScript.replace(/@db@/ig, window.GLOB.externalDatabase)
    }
 
    if (_customScript) {
      sql = `/* sql 验证 */
        ${_customScript}
        aaa:
        if @ErrorCode!=''
          insert into tmp_err_retmsg (ID, ErrorCode, retmsg, CreateUserID) select @time_id@,@ErrorCode, @retmsg,@UserID@
      `
    }
    sql = sql.replace(/\n\s{8}/ig, '\n')
    console.info(sql)
 
    return sql
  }
}