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
| if (config.get(FindConfig.GROUP_BY) != null && !"".equals(config.get(FindConfig.GROUP_BY))){ sql.append("SUM(").append(config.get(FindConfig.FIELD)).append(") FROM ").append("`").append(table).append("`"); sql.append(toWhereSql(query, "0".equals(config.get(FindConfig.LIKE)),config.get(FindConfig.SQLHWERE))); sql.append(" ").append("GROUP BY ").append(config.get(FindConfig.GROUP_BY)); }else { sql.append(" SUM(").append(config.get(FindConfig.FIELD)).append(") FROM ").append("`").append(table).append("`"); sql.append(toWhereSql(query, "0".equals(config.get(FindConfig.LIKE)),config.get(FindConfig.SQLHWERE))); } log.info("[{}] - 查询操作,sql: {}",table,sql); return sql.toString(); }
public String avg(Map<String,String> query,Map<String,String> config){ StringBuffer sql = new StringBuffer(" SELECT "); if (config.get(FindConfig.GROUP_BY) != null && !"".equals(config.get(FindConfig.GROUP_BY))){ sql.append("AVG(").append(config.get(FindConfig.FIELD)).append(") FROM ").append("`").append(table).append("`"); sql.append(toWhereSql(query, "0".equals(config.get(FindConfig.LIKE)),config.get(FindConfig.SQLHWERE))); sql.append(" ").append("GROUP BY ").append(config.get(FindConfig.GROUP_BY)); }else { sql.append(" AVG(").append(config.get(FindConfig.FIELD)).append(") FROM ").append("`").append(table).append("`"); sql.append(toWhereSql(query, "0".equals(config.get(FindConfig.LIKE)),config.get(FindConfig.SQLHWERE))); } log.info("[{}] - 查询操作,sql: {}",table,sql); return sql.toString(); }
public void toWhereWrapper(Map<String,String> query, Boolean like, QueryWrapper wrapper) { if (query.size() > 0) { try { for (Map.Entry<String, String> entry : query.entrySet()) { if (entry.getKey().contains(FindConfig.MIN_)) { String min = humpToLine(entry.getKey()).replace("_min", ""); wrapper.ge(min,URLDecoder.decode(entry.getValue(), "UTF-8")); continue; } if (entry.getKey().contains(FindConfig.MAX_)) { String max = humpToLine(entry.getKey()).replace("_max", ""); wrapper.le(max,URLDecoder.decode(entry.getValue(), "UTF-8")); continue; } if (like == true) { if (entry.getValue()!=null) wrapper.like(humpToLine(entry.getKey()),"%"+URLDecoder.decode(entry.getValue(), "UTF-8")+"%"); } else { if (entry.getValue()!=null) wrapper.eq(humpToLine(entry.getKey()),URLDecoder.decode(entry.getValue(), "UTF-8")); } } } catch (UnsupportedEncodingException e) { log.info("拼接sql 失败:{}", e.getMessage()); } } }
|