| | |
| | | |
| | | import moment from 'moment' |
| | | import { formatSearch, getSearchRegs, joinMainSearchkey } from '@/utils/utils-custom.js' |
| | | |
| | | export default class SettingUtils { |
| | | /** |
| | | * @description 生成页面查询语句 |
| | | */ |
| | | static getDebugSql (verify, scripts, searches, Utils, timestamp) { |
| | | static getDebugSql (verify, scripts, searches) { |
| | | let sql = '' |
| | | let _dataresource = verify.dataresource || '' |
| | | let regoptions = this.getRegOptions(searches) |
| | | let _search = this.formatSearch(searches) |
| | | _search = Utils.joinMainSearchkey(_search) |
| | | let _search = formatSearch(searches) |
| | | let regoptions = getSearchRegs(_search) |
| | | |
| | | _search = _search.replace(/@\$@/ig, '') |
| | | _search = joinMainSearchkey(_search) |
| | | _search = _search ? 'where ' + _search : '' |
| | | |
| | | let arr_field = [] |
| | |
| | | _dataresource = '(' + _dataresource + ') tb' |
| | | } |
| | | |
| | | _dataresource = _dataresource.replace(/@(BID|ID|LoginUID|SessionUid|UserID|Appkey|time_id|datam|typename)@/ig, `'${timestamp}'`) |
| | | _customScript = _customScript.replace(/@(BID|ID|LoginUID|SessionUid|UserID|Appkey|time_id|datam|typename)@/ig, `'${timestamp}'`) |
| | | _tailScript = _tailScript.replace(/@(BID|ID|LoginUID|SessionUid|UserID|Appkey|time_id|datam|typename)@/ig, `'${timestamp}'`) |
| | | _dataresource = _dataresource.replace(/@(BID|ID|LoginUID|SessionUid|UserID|Appkey|time_id|datam|typename)@/ig, `'1949-10-01 15:00:00'`) |
| | | _customScript = _customScript.replace(/@(BID|ID|LoginUID|SessionUid|UserID|Appkey|time_id|datam|typename)@/ig, `'1949-10-01 15:00:00'`) |
| | | _tailScript = _tailScript.replace(/@(BID|ID|LoginUID|SessionUid|UserID|Appkey|time_id|datam|typename)@/ig, `'1949-10-01 15:00:00'`) |
| | | _dataresource = _dataresource.replace(/@\$|\$@/ig, '') |
| | | _customScript = _customScript.replace(/@\$|\$@/ig, '') |
| | | _tailScript = _tailScript.replace(/@\$|\$@/ig, '') |
| | |
| | | } |
| | | |
| | | if (_customScript) { |
| | | sql = `/* sql 验证 */ |
| | | ${declare} |
| | | sql = `${declare} |
| | | ${_customScript} |
| | | ${_dataresource} |
| | | ${_tailScript} |
| | | aaa: |
| | | if @ErrorCode!='' |
| | | insert into tmp_err_retmsg (ID, ErrorCode, retmsg, CreateUserID) select @time_id@,@ErrorCode, @retmsg,@UserID@ |
| | | insert into tmp_err_retmsg (ID, ErrorCode, retmsg, CreateUserID) select '1949-10-01 15:00:00',@ErrorCode, @retmsg,'1949-10-01 15:00:00' |
| | | ` |
| | | } else if (_tailScript) { |
| | | sql = `${declare} |
| | |
| | | ${_tailScript} |
| | | aaa: |
| | | if @ErrorCode!='' |
| | | insert into tmp_err_retmsg (ID, ErrorCode, retmsg, CreateUserID) select @time_id@,@ErrorCode, @retmsg,@UserID@ |
| | | insert into tmp_err_retmsg (ID, ErrorCode, retmsg, CreateUserID) select '1949-10-01 15:00:00',@ErrorCode, @retmsg,'1949-10-01 15:00:00' |
| | | ` |
| | | } else { |
| | | sql = `/* sql 验证 */ |
| | | ${declare} |
| | | sql = `${declare} |
| | | ${_dataresource}` |
| | | } |
| | | sql = sql.replace(/\n\s{8}/ig, '\n') |
| | | console.info(sql) |
| | | sql = sql.replace(/\n/g, ' ') |
| | | |
| | | return sql |
| | | } |
| | | |
| | | /** |
| | | * @description 获取全部搜索条件 |
| | | * @param {Array} searches 搜索条件数组 |
| | | */ |
| | | static formatSearch (searches) { |
| | | if (!searches || searches.length === 0) return [] |
| | | |
| | | let newsearches = [] |
| | | searches.forEach(search => { |
| | | if (!search.field) return |
| | | |
| | | let item = { |
| | | key: search.field, |
| | | match: search.match, |
| | | type: search.type, |
| | | label: search.label, |
| | | value: search.initval, |
| | | required: search.required === 'true' |
| | | } |
| | | |
| | | if (item.type === 'group') { |
| | | item.key = search.datefield |
| | | item.type = 'daterange' |
| | | item.match = 'between' |
| | | item.value = [moment().format('YYYY-MM-DD'), moment().format('YYYY-MM-DD')].join(',') |
| | | |
| | | newsearches.push(item) |
| | | return |
| | | } else if (item.type === 'date') { |
| | | item.value = moment().format('YYYY-MM-DD') |
| | | } else if (item.type === 'datemonth') { |
| | | item.value = moment().format('YYYY-MM') |
| | | } else if (item.type === 'dateweek') { |
| | | item.value = moment().format('YYYY-MM-DD') |
| | | } else if (item.type === 'daterange') { |
| | | item.value = [moment().format('YYYY-MM-DD'), moment().format('YYYY-MM-DD')].join(',') |
| | | } else if (item.type === 'multiselect' || (item.type === 'checkcard' && search.multiple === 'true')) { |
| | | item.type = 'multi' |
| | | item.value = '@$@' |
| | | } else { |
| | | item.value = '@$@' |
| | | } |
| | | newsearches.push(item) |
| | | }) |
| | | |
| | | return newsearches |
| | | } |
| | | |
| | | /** |
| | | * @description 获取搜索用于正则替换 |
| | | * @param {Array} searches 搜索条件 |
| | | * @return {String} searchText 拼接结果 |
| | | */ |
| | | static getRegOptions (searches) { |
| | | if (!searches || searches.length === 0) return [] |
| | | |
| | | let options = [] |
| | | let fieldmap = new Map() |
| | | searches.forEach(search => { |
| | | let item = { |
| | | key: search.field, |
| | | value: '0' |
| | | } |
| | | |
| | | if (fieldmap.has(item.key)) { |
| | | item.key = item.key + '1' |
| | | } |
| | | |
| | | fieldmap.set(item.key, true) |
| | | |
| | | if (search.type === 'group') { |
| | | options.push({ |
| | | key: search.field, |
| | | value: '0' |
| | | }) |
| | | options.push({ |
| | | key: search.datefield, |
| | | value: '0' |
| | | }) |
| | | options.push({ |
| | | key: search.datefield + '1', |
| | | value: '0' |
| | | }) |
| | | options.push(item) |
| | | } else if (['datemonth', 'dateweek'].includes(search.type)) { |
| | | options.push(item) |
| | | options.push({ |
| | | key: item.key + '1', |
| | | value: '0' |
| | | }) |
| | | } else if (search.type === 'daterange') { |
| | | let _skey = search.field |
| | | let _ekey = search.field + '1' |
| | | |
| | | if (/,/.test(search.field)) { |
| | | _skey = search.field.split(',')[0] |
| | | _ekey = search.field.split(',')[1] |
| | | } |
| | | |
| | | options.push({ |
| | | key: _skey, |
| | | value: '0' |
| | | }) |
| | | options.push({ |
| | | key: _ekey, |
| | | value: '0' |
| | | }) |
| | | } else if (search.type === 'text' || search.type === 'select') { |
| | | item.key.split(',').forEach(field => { |
| | | let cell = JSON.parse(JSON.stringify(item)) |
| | | cell.key = field |
| | | |
| | | options.push(cell) |
| | | }) |
| | | } else { |
| | | options.push(item) |
| | | } |
| | | }) |
| | | |
| | | return options |
| | | } |
| | | } |