Commit fe50a963 authored by yanzg's avatar yanzg

默认日期格式的支持

parent 8e0dcf55
...@@ -16,31 +16,31 @@ class SqlCondUtil { ...@@ -16,31 +16,31 @@ class SqlCondUtil {
/** /**
* 代码片段等级 * 代码片段等级
*/ */
public static final int COND_CODE = 0; public static final int FIELD_CODE = 0;
/** /**
* 时间等级 * 时间等级
*/ */
public static final int COND_DATE = 1; public static final int WHERE_DATE = 1;
/** /**
* ID等级 * ID等级
*/ */
public static final int COND_ID = 2; public static final int WHERE_ID = 2;
/** /**
* 普通相等 * 普通相等
*/ */
public static final int COND_COMMON = 3; public static final int WHERE_COMMON = 3;
/** /**
* 普通IN,NOT IN * 普通IN,NOT IN
*/ */
public static final int COND_IN = 4; public static final int WHERE_IN = 4;
/** /**
* Like条件 * Like条件
*/ */
public static final int COND_LIKE = 5; public static final int WHERE_LIKE = 5;
/** /**
* 全文索引 * 全文索引
*/ */
public static final int COND_MATCH = 6; public static final int WHERE_MATCH = 6;
/** /**
* 将SQL语句条件排序,符合索引 * 将SQL语句条件排序,符合索引
...@@ -48,7 +48,7 @@ class SqlCondUtil { ...@@ -48,7 +48,7 @@ class SqlCondUtil {
* @param fields * @param fields
*/ */
public static List<SqlDataField> sortCond(List<SqlDataField> fields) { public static List<SqlDataField> sortCond(List<SqlDataField> fields) {
// 最大级别 // 获取代码片段的级别,并且放到对应级别的数组中
Map<Integer, List<SqlDataField>> mapLevel = new HashMap<>(); Map<Integer, List<SqlDataField>> mapLevel = new HashMap<>();
for (SqlDataField field : fields) { for (SqlDataField field : fields) {
int level = getCondLevel(field); int level = getCondLevel(field);
...@@ -59,9 +59,9 @@ class SqlCondUtil { ...@@ -59,9 +59,9 @@ class SqlCondUtil {
} }
levelCond.add(field); levelCond.add(field);
} }
// 添加到排序好的条件 // 按照级别返回代码片段
List<SqlDataField> tos = new ArrayList<>(); List<SqlDataField> tos = new ArrayList<>();
for (int i = 0; i <= COND_MATCH; i++) { for (int i = 0; i <= WHERE_MATCH; i++) {
List<SqlDataField> levelCond = mapLevel.get(i); List<SqlDataField> levelCond = mapLevel.get(i);
if (levelCond == null) { if (levelCond == null) {
continue; continue;
...@@ -73,42 +73,38 @@ class SqlCondUtil { ...@@ -73,42 +73,38 @@ class SqlCondUtil {
private static int getCondLevel(SqlDataField field) { private static int getCondLevel(SqlDataField field) {
if (field == null) { if (field == null) {
return COND_COMMON; return WHERE_COMMON;
} }
SqlCond<?> cond = field.getCond(); SqlCond<?> cond = field.getCond();
boolean isWhere = false;
int len = field.getCodes().size() / 2; int len = field.getCodes().size() / 2;
for (int i = 0; i < len; i++) { for (int i = 0; i < len; i++) {
// 判断是否包含where条件,当没有包含where条件时,则属于普通代码片段,优先级最高
String codeName = field.getCodes().get(i * 2).toLowerCase(); String codeName = field.getCodes().get(i * 2).toLowerCase();
String codeValue = field.getCodes().get(i * 2 + 1).toLowerCase(); String codeValue = field.getCodes().get(i * 2 + 1).toLowerCase();
if (codeName.indexOf("where") < 0) { if (codeName.indexOf("where") < 0) {
continue; continue;
} }
// 当包含where条件时,则按照规则排序
isWhere = true;
for (String fieldName : cond.getFields()) { for (String fieldName : cond.getFields()) {
fieldName = fieldName.toLowerCase(); fieldName = fieldName.toLowerCase();
if (fieldName.indexOf("date") > -1 || fieldName.indexOf("time") > -1) { if (fieldName.indexOf("date") > -1 || fieldName.indexOf("time") > -1) {
return COND_DATE; return WHERE_DATE;
} else if (fieldName.indexOf("id") > -1) { } else if (fieldName.indexOf("id") > -1) {
return COND_ID; return WHERE_ID;
} }
} }
if (codeValue.indexOf("in") > -1) { if (codeValue.indexOf("in") > -1) {
return COND_IN; return WHERE_IN;
} else if (codeValue.indexOf("like") > -1) { } else if (codeValue.indexOf("like") > -1) {
return COND_LIKE; return WHERE_LIKE;
} else if (codeValue.indexOf("match") > -1) { } else if (codeValue.indexOf("match") > -1) {
return COND_MATCH; return WHERE_MATCH;
} else {
return WHERE_COMMON;
} }
} }
if (isWhere) { return FIELD_CODE;
return COND_COMMON;
} else {
return COND_CODE;
}
} }
} }
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment