派生自 projectDept/qhighschool

Administrator
2022-11-21 8d0e57a64fe6c31559ffcf38859fb1f5084e1e23
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+"%"));
                }
            }
        }
    }
    
}