|
@@ -4,6 +4,7 @@ import com.alibaba.fastjson.JSONArray;
|
|
|
import com.alibaba.fastjson.JSONObject;
|
|
|
import com.boman.common.core.utils.obj.ObjectUtils;
|
|
|
import com.boman.system.common.FormDataConstant;
|
|
|
+import org.apache.commons.lang3.ArrayUtils;
|
|
|
import org.apache.commons.lang3.StringUtils;
|
|
|
import org.apache.ibatis.annotations.*;
|
|
|
import org.apache.ibatis.annotations.Param;
|
|
@@ -15,6 +16,9 @@ import org.springframework.stereotype.Component;
|
|
|
import java.util.*;
|
|
|
import java.util.function.Consumer;
|
|
|
|
|
|
+import static com.boman.common.core.utils.obj.ObjectUtils.*;
|
|
|
+import static com.boman.system.common.FormDataConstant.*;
|
|
|
+
|
|
|
/**
|
|
|
* @author shiqian
|
|
|
* @description
|
|
@@ -412,7 +416,8 @@ public interface StandardlyMapper {
|
|
|
}
|
|
|
|
|
|
public String selectByCondition(Map<String, Object> para) {
|
|
|
-// JSONObject condition = (JSONObject) para.get("condition");
|
|
|
+ JSONObject condition = (JSONObject) para.get("condition");
|
|
|
+ LOGGER.info("前台传过来的查询条件: {}", condition.toJSONString());
|
|
|
JSONObject packCondition = (JSONObject) para.get("packCondition");
|
|
|
String tableName = (String) para.get("tableName");
|
|
|
String orderBy = (String) para.get("orderBy");
|
|
@@ -440,8 +445,9 @@ public interface StandardlyMapper {
|
|
|
String valueStr = ((String) valueObj);
|
|
|
String[] split = valueStr.split("_");
|
|
|
String value = split[0];
|
|
|
- String type = split[1];
|
|
|
- conditionSql.append(key).append(covert(type, key, value)).append(" and ");
|
|
|
+ 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"));
|
|
@@ -455,17 +461,48 @@ public interface StandardlyMapper {
|
|
|
return result;
|
|
|
}
|
|
|
|
|
|
- private String covert(String type, String key, String value) {
|
|
|
- switch (type) {
|
|
|
+ private String covert(String queryType, String columnType, String key, String value) {
|
|
|
+ // false 不需要转义
|
|
|
+ boolean needEscape = columnType.contains(VARCHAR) || columnType.contains(CHAR)
|
|
|
+ || columnType.contains(DATETIME) || columnType.contains(TIMESTAMP);
|
|
|
+ switch (queryType) {
|
|
|
case FormDataConstant.EQ:
|
|
|
- return " = " + ObjectUtils.escapeStr(value);
|
|
|
+ value = needEscape ? escapeStr(value) : value;
|
|
|
+ return " = " + value;
|
|
|
case FormDataConstant.LIKE:
|
|
|
return " like " + "concat('%', #{condition." + key + "}, '%')";
|
|
|
+ case FormDataConstant.NE:
|
|
|
+ value = needEscape ? escapeStr(value) : value;
|
|
|
+ return " != " + value;
|
|
|
+ case FormDataConstant.GT:
|
|
|
+ value = needEscape ? escapeStr(value) : value;
|
|
|
+ return " > " + value;
|
|
|
+ case FormDataConstant.GTE:
|
|
|
+ value = needEscape ? escapeStr(value) : value;
|
|
|
+ return " >= " + value;
|
|
|
+ case FormDataConstant.LT:
|
|
|
+ value = needEscape ? escapeStr(value) : value;
|
|
|
+ return " < " + value;
|
|
|
+ case FormDataConstant.LTE:
|
|
|
+ value = needEscape ? escapeStr(value) : value;
|
|
|
+ return " <= " + value;
|
|
|
default:
|
|
|
- throw new IllegalArgumentException("参数非法");
|
|
|
+ String[] split = value.split(",");
|
|
|
+ String front = split[0].replace("[", "");
|
|
|
+ String back = split[1].replace("]", "");
|
|
|
+ String max, min;
|
|
|
+ if (front.compareTo(back) > 0) {
|
|
|
+ max = back;
|
|
|
+ min = front;
|
|
|
+ } else {
|
|
|
+ max = front;
|
|
|
+ min = back;
|
|
|
+ }
|
|
|
+
|
|
|
+ max = needEscape ? escapeStr(max) : max;
|
|
|
+ min = needEscape ? escapeStr(min) : min;
|
|
|
+ return " between " + min + " and " + max;
|
|
|
}
|
|
|
}
|
|
|
-
|
|
|
-
|
|
|
}
|
|
|
}
|