package com.qxueyou.scc.base.util;
import java.util.Arrays;
import java.util.List;
import java.util.Map;
import java.util.Set;
import javax.servlet.http.HttpServletRequest;
import org.apache.commons.lang3.StringUtils;
import com.qxueyou.scc.base.model.Param;
public class ParamsUtils {
/**
* 获取查询条件的公用方法
*
* @param request HttpServletRequest
* @param strSupportQueryArray 定义自己功能模块支持查询的条件数组集合
* @param lstQueryCondition 查询条件
*/
public static void getAllQueryCondition(HttpServletRequest request, String[] strSupportQueryArray,
List lstParams) {
Map mapParams = request.getParameterMap();
Set> entryseSet = mapParams.entrySet();
String strKey = "";
String strValue = "";
List lstSupportQuery = Arrays.asList(strSupportQueryArray);
/**
* 条件分为以下几种情况: 1、关键字查询 2、单选按钮的数据字典值 3、复选数组,比如类型
* 4、时间范围,比如开始时间和结束时间 5、数字范围, 6、其它类型
*/
for (Map.Entry entry : entryseSet) {
/** 获取参数中的键值对 */
strKey = entry.getKey().toString();
strValue = entry.getValue()[0];
/** 不支持的条件将会被过滤 */
if (lstSupportQuery.contains(strKey) && StringUtils.isNotBlank(strValue)) {
// 去空格
strValue = strValue.trim();
if (strValue.matches("^[0-9]*[0-9][0-9]*$")) {// 单选 数字
lstParams.add(new Param(strKey, " = ", strValue));
} else if (strValue.contains(",")) {// 复选 数字
if (strValue.replace(",", "").matches("^-?[0-9]*$")){
lstParams.add(new Param(strKey, " in ", strValue ));
}
} else if (strValue.contains("~")) {// 时间范围
}else if (strValue.contains("-")) {// 数字范围
} else {// 其它
lstParams.add(new Param(strKey, " LIKE ", "%"+strValue+"%"));
}
}
}
}
}