| | |
| | | |
| | | import { getSearchRegs, joinMainSearchkey } from '@/utils/utils-custom.js' |
| | | |
| | | export default class SettingUtils { |
| | | /** |
| | | * @description 生成页面查询语句 |
| | | * @return {String} arr_field 显示列字段 |
| | | * @return {String} search 搜索条件 |
| | | * @return {Object} setting 页面设置 |
| | | * @return {Array} regoptions 搜索条件正则替换 |
| | | */ |
| | | static getDebugSql (setting, scripts, arr_field, regoptions, search) { |
| | | static getDebugSql (setting, scripts, arr_field, searches = [], urlFields) { |
| | | let sql = '' |
| | | let _dataresource = setting.dataresource || '' |
| | | let _customScript = '' |
| | |
| | | _customScript = _customScript.replace(/@db@/ig, window.GLOB.externalDatabase) |
| | | } |
| | | |
| | | let _regoptions = getSearchRegs(searches) |
| | | |
| | | let _search = joinMainSearchkey(searches) |
| | | _search = _search ? 'where ' + _search : '' |
| | | |
| | | // 正则替换 |
| | | let _regoptions = regoptions.map(item => { |
| | | return { |
| | | reg: new RegExp('@' + item.key + '@', 'ig'), |
| | | value: `'0'`, |
| | | type: item.type || '' |
| | | } |
| | | if (urlFields && urlFields.length > 0) { |
| | | urlFields.forEach(field => { |
| | | _regoptions.push({ |
| | | reg: new RegExp('@' + field + '@', 'ig'), |
| | | value: `'0'` |
| | | }) |
| | | }) |
| | | } |
| | | |
| | | _regoptions.push({ |
| | | reg: new RegExp('@userName@', 'ig'), |
| | | value: `''` |
| | | }, { |
| | | reg: new RegExp('@fullName@', 'ig'), |
| | | value: `''` |
| | | }, { |
| | | reg: new RegExp('@orderBy@', 'ig'), |
| | | value: setting.order |
| | | }, { |
| | |
| | | value: 1 |
| | | }) |
| | | |
| | | let _search = search |
| | | |
| | | if (setting.queryType === 'statistics' && _dataresource) { |
| | | _regoptions.forEach(item => { |
| | | _dataresource = _dataresource.replace(item.reg, item.value) |
| | | }) |
| | | _search = '' |
| | | } else if (_dataresource) { |
| | | _regoptions.forEach(item => { |
| | | if (item.type !== 'url') return |
| | | _dataresource = _dataresource.replace(item.reg, item.value) |
| | | }) |
| | | } |
| | | |
| | | if (_customScript) { |
| | | _regoptions.forEach(item => { |
| | | _customScript = _customScript.replace(item.reg, item.value) |
| | | }) |
| | | |
| | | if (setting.queryType === 'statistics' && _dataresource) { |
| | | _search = '' |
| | | } |
| | | |
| | | // 数据源处理, 存在显示列时 |
| | |
| | | } |
| | | |
| | | return { sql, errors: errors.join(';') } |
| | | } |
| | | |
| | | /** |
| | | * @description 生成前置或后置语句 |
| | | * @return {String} scripts 脚本 |
| | | * @return {Array} regoptions 搜索条件正则替换 |
| | | */ |
| | | static getCustomDebugSql (scripts, regoptions) { |
| | | 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),@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) select @ErrorCode='',@retmsg ='' |
| | | ${_customScript} |
| | | ` |
| | | } |
| | | |
| | | if (window.GLOB.funcs && window.GLOB.funcs.length > 0) { |
| | | window.GLOB.funcs.forEach(item => { |
| | | let reg = new RegExp('\\$ex@' + item.func_code + '@ex\\$', 'ig') |
| | | _customScript = _customScript.replace(reg, `/*$ex@${item.func_code}-begin*/\n${item.key_sql}\n/*@ex$-end*/`) |
| | | }) |
| | | } |
| | | |
| | | _customScript = _customScript.replace(/@\$|\$@/ig, '') |
| | | _customScript = _customScript.replace(/@userName@|@fullName@/ig, `''`) |
| | | |
| | | // 正则替换 |
| | | if (regoptions) { |
| | | let _regoptions = regoptions.map(item => { |
| | | return { |
| | | reg: new RegExp('@' + item.key + '@', 'ig'), |
| | | value: `'0'` |
| | | } |
| | | }) |
| | | _regoptions.forEach(item => { |
| | | _customScript = _customScript.replace(item.reg, item.value) |
| | | }) |
| | | } |
| | | |
| | | if (_customScript) { |
| | | sql = `${_customScript} |
| | | aaa: |
| | | if @ErrorCode!='' |
| | | insert into tmp_err_retmsg (ID, ErrorCode, retmsg, CreateUserID) select '1949-10-01 15:00:00',@ErrorCode, @retmsg,'1949-10-01 15:00:00' |
| | | ` |
| | | } |
| | | |
| | | return sql |
| | | } |
| | | } |