关于jeecg图表配置范围查询失效问题解决

今天在使用jeecg框架图表配置范围查询时

遇到查询出来的数据错误

在查询时只把范围最大的值作为查询条件,并没有把范围最小的值作为条件进行查询

经过层层debug

发现框架在组合sql语句时没有把范围最小的值拼接到查询sql语句中

解决方法如下:

找到方法

修改为:

 1 public String handleElInSQL(String sql, Map params) {
 2         Pattern p = Pattern.compile("\\{[^}]+\\}");
 3         Matcher m = p.matcher(sql);
 4         //如果条件中存在此标签则替换
 5         while (m.find()) {
 6             String oel = m.group();
 7             String el = oel.replace("{", "").replace("}", "").trim();
 8             //替换{xx:xx}标签
 9             if(el.indexOf(":") != -1) {
10                 String[] elSplit = el.split(":");
11                 String elKey = elSplit[0].trim();
12                 String elValue = elSplit[1].trim();
13                 //如果条件中存在此标签则替换
14                 Object condValue = params.get(elSplit[1].trim()); 
15                 if(condValue != null) {
16                     sql = sql.replace(oel, elKey + condValue.toString().replace(" " + elValue + " ", " " + elKey + " "));
17                 }else {
18                     sql = sql.replace(oel, "1=1");
19                 }
20                 params.remove(elValue);
21             }else {
22                 //替换{xx}标签
23                 Object condValue = params.get(el); 
24                 if(condValue != null) {
25                     if(condValue.toString().indexOf("<=")!=-1) {
26                         String condValueStr = condValue.toString();
27                         String leftCondValue = condValueStr.substring(condValueStr.indexOf(":"),condValueStr.length()); 
28                         leftCondValue = leftCondValue.replace("_end", "");
29                         leftCondValue += "_begin";
30                         leftCondValue = el + " >= " + leftCondValue + " and ";
31                         sql = sql.replace(oel,leftCondValue+ el + condValue.toString());
32                     }else {
33                         sql = sql.replace(oel, el + condValue.toString());
34                     }
35                 }else {
36                     sql = sql.replace(oel, "1=1");
37                 }
38                 params.remove(el);
39             }
40         }
41         return sql;
42     }

这样就可以修复范围查询的bug了

 

猜你喜欢

转载自www.cnblogs.com/pomfor/p/10477483.html
今日推荐