|
@@ -2,6 +2,7 @@ package com.boman.web.core.mapper;
|
|
|
|
|
|
import com.alibaba.fastjson.JSONArray;
|
|
import com.alibaba.fastjson.JSONArray;
|
|
import com.alibaba.fastjson.JSONObject;
|
|
import com.alibaba.fastjson.JSONObject;
|
|
|
|
+import com.boman.web.core.utils.ColumnUtils;
|
|
import org.apache.commons.lang3.StringUtils;
|
|
import org.apache.commons.lang3.StringUtils;
|
|
import org.apache.ibatis.annotations.*;
|
|
import org.apache.ibatis.annotations.*;
|
|
import org.apache.ibatis.annotations.Param;
|
|
import org.apache.ibatis.annotations.Param;
|
|
@@ -168,6 +169,7 @@ public interface StandardlyMapper {
|
|
* @param tableName tableName
|
|
* @param tableName tableName
|
|
* @param condition 属性名和属性值
|
|
* @param condition 属性名和属性值
|
|
* @param packCondition 属性名和属性值 条件
|
|
* @param packCondition 属性名和属性值 条件
|
|
|
|
+ * @param limitOne true sql加上limit 1, false 则不加
|
|
* @return java.util.List<com.alibaba.fastjson.JSONObject>
|
|
* @return java.util.List<com.alibaba.fastjson.JSONObject>
|
|
*/
|
|
*/
|
|
@SelectProvider(type = SqlProvider.class, method = "getByMap")
|
|
@SelectProvider(type = SqlProvider.class, method = "getByMap")
|
|
@@ -176,6 +178,7 @@ public interface StandardlyMapper {
|
|
, @Param("packCondition") JSONObject packCondition
|
|
, @Param("packCondition") JSONObject packCondition
|
|
, @Param("limitOne") boolean limitOne);
|
|
, @Param("limitOne") boolean limitOne);
|
|
|
|
|
|
|
|
+ @SuppressWarnings("unchecked")
|
|
public static class SqlProvider {
|
|
public static class SqlProvider {
|
|
static final String[] READONLY_COLUMNS = new String[]{"OWNERID", "OWNERNAME", "OWNERENAME", "CREATIONDATE", "ID"};
|
|
static final String[] READONLY_COLUMNS = new String[]{"OWNERID", "OWNERNAME", "OWNERENAME", "CREATIONDATE", "ID"};
|
|
|
|
|
|
@@ -644,50 +647,38 @@ public interface StandardlyMapper {
|
|
* @param queryType like > < =
|
|
* @param queryType like > < =
|
|
* @param columnType varchar char textarea timestamp
|
|
* @param columnType varchar char textarea timestamp
|
|
* @param key key
|
|
* @param key key
|
|
- * @param value value
|
|
|
|
|
|
+ * @param valueObj valueObj
|
|
* @return java.lang.String
|
|
* @return java.lang.String
|
|
*/
|
|
*/
|
|
- private String covert(String queryType, String columnType, String key, String value) {
|
|
|
|
|
|
+ private String covert(String queryType, String columnType, String key, Object valueObj) {
|
|
// false 不需要转义
|
|
// false 不需要转义
|
|
- boolean needEscape = columnType.contains(VARCHAR) || columnType.contains(CHAR)
|
|
|
|
- || columnType.contains(DATETIME) || columnType.contains(TIMESTAMP);
|
|
|
|
|
|
+ boolean needEscape = columnType.contains(VARCHAR) || columnType.contains(CHAR)|| columnType.contains(DATETIME) || columnType.contains(TIMESTAMP);
|
|
|
|
+ Object value;
|
|
switch (queryType) {
|
|
switch (queryType) {
|
|
case EQ:
|
|
case EQ:
|
|
- value = needEscape ? escapeStr(value) : value;
|
|
|
|
|
|
+ value = needEscape ? escapeStr((String) valueObj) : valueObj;
|
|
return " = " + value;
|
|
return " = " + value;
|
|
case LIKE:
|
|
case LIKE:
|
|
- return " like " + "concat('%', #{condition." + key + "}, '%')";
|
|
|
|
|
|
+ return " like concat('%', #{condition." + key + "}, '%')";
|
|
case NE:
|
|
case NE:
|
|
- value = needEscape ? escapeStr(value) : value;
|
|
|
|
|
|
+ value = needEscape ? escapeStr((String) valueObj) : valueObj;
|
|
return " != " + value;
|
|
return " != " + value;
|
|
case GT:
|
|
case GT:
|
|
- value = needEscape ? escapeStr(value) : value;
|
|
|
|
|
|
+ value = needEscape ? escapeStr((String) valueObj) : valueObj;
|
|
return " > " + value;
|
|
return " > " + value;
|
|
case GTE:
|
|
case GTE:
|
|
- value = needEscape ? escapeStr(value) : value;
|
|
|
|
|
|
+ value = needEscape ? escapeStr((String) valueObj) : valueObj;
|
|
return " >= " + value;
|
|
return " >= " + value;
|
|
case LT:
|
|
case LT:
|
|
- value = needEscape ? escapeStr(value) : value;
|
|
|
|
|
|
+ value = needEscape ? escapeStr((String) valueObj) : valueObj;
|
|
return " < " + value;
|
|
return " < " + value;
|
|
case LTE:
|
|
case LTE:
|
|
- value = needEscape ? escapeStr(value) : value;
|
|
|
|
|
|
+ value = needEscape ? escapeStr((String) valueObj) : valueObj;
|
|
return " <= " + value;
|
|
return " <= " + value;
|
|
default:
|
|
default:
|
|
- 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;
|
|
|
|
|
|
+ // in
|
|
|
|
+ List<Object> list = ((List<Object>) valueObj);
|
|
|
|
+ return " in (" + ColumnUtils.joinList(list) + ")";
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|