doomiwork 4.1.8 → 4.1.10
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/package.json +1 -1
- package/utilities/requestparser.js +18 -7
package/package.json
CHANGED
|
@@ -106,7 +106,8 @@ module.exports.parseTagForParameterize = (req, filterSetting={}) => {
|
|
|
106
106
|
///type=parameter表示参数化方式查询
|
|
107
107
|
///type=joint 表示拼接sql语句查询
|
|
108
108
|
///scope=[] 表示需要解析的字段必须在此列表内容中
|
|
109
|
-
|
|
109
|
+
/// split 进来的替换内容是否需要被split拆分成多个参数
|
|
110
|
+
let {pattern:sql,type='parameter',inscope=[],allowEmpty=false,split=false,subitem,splitjoint='or',splitchar='|'} = filterSetting;
|
|
110
111
|
if (!sql) return {sql:''};
|
|
111
112
|
///定义正则准备查找sql中的特定关键字
|
|
112
113
|
const matched = sql.match(/@.*?@/g);
|
|
@@ -129,11 +130,21 @@ module.exports.parseTagForParameterize = (req, filterSetting={}) => {
|
|
|
129
130
|
if (isEmptyValue(keyValue) && !allowEmpty) return {sql:'',params:[]};
|
|
130
131
|
// if (keyValue) {
|
|
131
132
|
if(type.toLowerCase() === 'parameter'){
|
|
132
|
-
|
|
133
|
-
if
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
133
|
+
/// 需要用|拆分成多个参数
|
|
134
|
+
if(split && subitem){
|
|
135
|
+
const multiParams = keyValue.split(splitchar),multiItems = [];
|
|
136
|
+
for(const subitemValue of multiParams){
|
|
137
|
+
multiItems.push(subitem);
|
|
138
|
+
params.push(matchContent[0].replace(matchContent[1], subitemValue));
|
|
139
|
+
}
|
|
140
|
+
sql = sql.replace(ele, multiItems.join(' '+splitjoint+' '));
|
|
141
|
+
}else{
|
|
142
|
+
sql = sql.replace(ele, '?'); ///变成参数化查询
|
|
143
|
+
if (Array.isArray(keyValue))
|
|
144
|
+
params.push(keyValue)
|
|
145
|
+
else
|
|
146
|
+
params.push(matchContent[0].replace(matchContent[1], keyValue));// '%' + keyValue + '%')
|
|
147
|
+
}
|
|
137
148
|
} else if (type.toLowerCase() === 'joint'){ ///拼接sql语句查询
|
|
138
149
|
///拼接的SQL语句,keyvalue必须在scope列表中,否则不予拼接
|
|
139
150
|
const result = inscope.some(item => item.toLowerCase() === matchValue.toLowerCase());
|
|
@@ -207,7 +218,7 @@ module.exports.getListInfo = (req, dataKey, cfgType = 0, dao) => {
|
|
|
207
218
|
if (sqltype==='sql'){
|
|
208
219
|
const mainParameterlizedSql = this.parseTagForParameterize(req, { pattern: sql, allowEmpty:true });
|
|
209
220
|
if (!mainParameterlizedSql.sql) return null;
|
|
210
|
-
sql = `${mainParameterlizedSql.sql} ${searchCondition.filter ||''} ${sort ? (' order by ' + sort) : ''} ${export2Excel ? '' : ' limit ' + Number(pageSize) + ' OFFSET ' + (Math.max(Number(page), 1) - 1) * Number(pageSize)};SELECT FOUND_ROWS() AS total
|
|
221
|
+
sql = `${mainParameterlizedSql.sql} ${searchCondition.filter ||''} ${sort ? (' order by ' + sort) : ''} ${export2Excel ? '' : ' limit ' + Number(pageSize) + ' OFFSET ' + (Math.max(Number(page), 1) - 1) * Number(pageSize)};SELECT FOUND_ROWS() AS total;`;
|
|
211
222
|
SqlParameters = SqlParameters.concat(mainParameterlizedSql.params || [], searchCondition.params);
|
|
212
223
|
/*** 如果存在汇总列的sql,则把SQL放置在最末尾 */
|
|
213
224
|
if (countsql) {
|