|
@@ -457,28 +457,20 @@ public interface StandardlyMapper {
|
|
wholeSql.append("select ");
|
|
wholeSql.append("select ");
|
|
// showData
|
|
// showData
|
|
StringBuilder showDataSql = new StringBuilder();
|
|
StringBuilder showDataSql = new StringBuilder();
|
|
- for (Object columnObj : showData) {
|
|
|
|
- String columnName = (String) columnObj;
|
|
|
|
- showDataSql.append(columnName).append(", ");
|
|
|
|
|
|
+ if (ObjectUtils.isNotEmpty(showData)) {
|
|
|
|
+ for (Object columnObj : showData) {
|
|
|
|
+ String columnName = (String) columnObj;
|
|
|
|
+ showDataSql.append(columnName).append(", ");
|
|
|
|
+ }
|
|
|
|
+ wholeSql.append(StringUtils.substringBeforeLast(showDataSql.toString(), ","));
|
|
|
|
+ } else {
|
|
|
|
+ showDataSql.append(" * ");
|
|
}
|
|
}
|
|
|
|
|
|
- wholeSql.append(StringUtils.substringBeforeLast(showDataSql.toString(), ","));
|
|
|
|
- wholeSql.append(" from ").append(tableName);
|
|
|
|
- wholeSql.append(" where ");
|
|
|
|
|
|
+ wholeSql.append(showDataSql).append(" from ").append(tableName);
|
|
// 条件
|
|
// 条件
|
|
- StringBuilder conditionSql = new StringBuilder();
|
|
|
|
- for (Map.Entry<String, Object> entry : packCondition.entrySet()) {
|
|
|
|
- String key = entry.getKey();
|
|
|
|
- Object valueObj = entry.getValue();
|
|
|
|
- String valueStr = ((String) valueObj);
|
|
|
|
- String[] split = valueStr.split("_");
|
|
|
|
- String value = split[0];
|
|
|
|
- String queryType = split[1];
|
|
|
|
- String columnType = split[2];
|
|
|
|
- conditionSql.append(key).append(covert(queryType, columnType, key, value)).append(" and ");
|
|
|
|
- }
|
|
|
|
|
|
+ packCondition(packCondition, wholeSql);
|
|
|
|
|
|
- wholeSql.append(StringUtils.substringBeforeLast(conditionSql.toString(), " and"));
|
|
|
|
wholeSql.append(" order by ").append(orderBy).append(" limit ").append(limit);
|
|
wholeSql.append(" order by ").append(orderBy).append(" limit ").append(limit);
|
|
if (ObjectUtils.isNotEmpty(offset)) {
|
|
if (ObjectUtils.isNotEmpty(offset)) {
|
|
wholeSql.append(", ").append(offset);
|
|
wholeSql.append(", ").append(offset);
|
|
@@ -498,27 +490,33 @@ public interface StandardlyMapper {
|
|
StringBuilder wholeSql = new StringBuilder();
|
|
StringBuilder wholeSql = new StringBuilder();
|
|
wholeSql.append("select count(1)");
|
|
wholeSql.append("select count(1)");
|
|
wholeSql.append(" from ").append(tableName);
|
|
wholeSql.append(" from ").append(tableName);
|
|
- wholeSql.append(" where ");
|
|
|
|
// 条件
|
|
// 条件
|
|
- StringBuilder conditionSql = new StringBuilder();
|
|
|
|
- for (Map.Entry<String, Object> entry : packCondition.entrySet()) {
|
|
|
|
- String key = entry.getKey();
|
|
|
|
- Object valueObj = entry.getValue();
|
|
|
|
- String valueStr = ((String) valueObj);
|
|
|
|
- // {@link com.boman.system.common.TableServiceCmdService.packValue} 这里是拼参数的地方
|
|
|
|
- String[] split = valueStr.split("_");
|
|
|
|
- String value = split[0];
|
|
|
|
- String queryType = split[1];
|
|
|
|
- String columnType = split[2];
|
|
|
|
- conditionSql.append(key).append(covert(queryType, columnType, key, value)).append(" and ");
|
|
|
|
- }
|
|
|
|
|
|
+ packCondition(packCondition, wholeSql);
|
|
|
|
|
|
- wholeSql.append(StringUtils.substringBeforeLast(conditionSql.toString(), " and"));
|
|
|
|
String result = wholeSql.toString();
|
|
String result = wholeSql.toString();
|
|
LOGGER.info("查询count拼出的sql语句为:{}", result);
|
|
LOGGER.info("查询count拼出的sql语句为:{}", result);
|
|
return result;
|
|
return result;
|
|
}
|
|
}
|
|
|
|
|
|
|
|
+ private void packCondition(JSONObject packCondition, StringBuilder wholeSql) {
|
|
|
|
+ if (ObjectUtils.isNotEmpty(packCondition)) {
|
|
|
|
+ wholeSql.append(" where ");
|
|
|
|
+ StringBuilder conditionSql = new StringBuilder();
|
|
|
|
+ for (Map.Entry<String, Object> entry : packCondition.entrySet()) {
|
|
|
|
+ String key = entry.getKey();
|
|
|
|
+ Object valueObj = entry.getValue();
|
|
|
|
+ String valueStr = ((String) valueObj);
|
|
|
|
+ // {@link com.boman.system.common.TableServiceCmdService.packValue} 这里是拼参数的地方
|
|
|
|
+ String[] split = valueStr.split("_");
|
|
|
|
+ String value = split[0];
|
|
|
|
+ String queryType = split[1];
|
|
|
|
+ String columnType = split[2];
|
|
|
|
+ conditionSql.append(key).append(covert(queryType, columnType, key, value)).append(" and ");
|
|
|
|
+ }
|
|
|
|
+ wholeSql.append(StringUtils.substringBeforeLast(conditionSql.toString(), " and"));
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+
|
|
private String covert(String queryType, String columnType, String key, String value) {
|
|
private String covert(String queryType, String columnType, String key, String value) {
|
|
// false 不需要转义
|
|
// false 不需要转义
|
|
boolean needEscape = columnType.contains(VARCHAR) || columnType.contains(CHAR)
|
|
boolean needEscape = columnType.contains(VARCHAR) || columnType.contains(CHAR)
|