派生自 projectDept/qhighschool

EricsHu
2022-12-05 068fc7f2e81178e55fa191a13709af64b1a163f6
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
46
47
48
49
50
51
52
53
54
55
56
57
58
59
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<Param> lstParams) {
        Map<String, String[]> mapParams = request.getParameterMap();
        Set<Map.Entry<String, String[]>> entryseSet = mapParams.entrySet();
        String strKey = "";
        String strValue = "";
        List<String> lstSupportQuery = Arrays.asList(strSupportQueryArray);
        /**
         * 条件分为以下几种情况: 1、关键字查询  2、单选按钮的数据字典值  3、复选数组,比如类型
         * 4、时间范围,比如开始时间和结束时间 5、数字范围, 6、其它类型
         */
        for (Map.Entry<String, String[]> 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+"%"));
                }
            }
        }
    }
    
}