Merge pull request #12189 from dataease/pr@dev-v2@fix_date

fix: 尝试修复日期过滤存在时区差异的问题
This commit is contained in:
Junjun 2024-09-13 11:07:57 +08:00 committed by GitHub
commit fe38547b67
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 26 additions and 10 deletions

View File

@ -164,10 +164,10 @@ public class CustomWhere2Str {
if (field.getDeType() == 1) {
// 如果是动态时间计算具体值
value = fixValue(item);
Map<String, Long> stringLongMap = Utils.parseDateTimeValue(value);
if (StringUtils.equalsIgnoreCase(whereTerm, " = ")) {
whereTerm = " BETWEEN ";
// 把value类似过滤组件处理获得start time和end time
Map<String, Long> stringLongMap = Utils.parseDateTimeValue(value);
if (isCross) {
whereValue = String.format(SQLConstants.WHERE_VALUE_BETWEEN, stringLongMap.get("startTime"), stringLongMap.get("endTime"));
} else {
@ -175,18 +175,26 @@ public class CustomWhere2Str {
}
} else if (StringUtils.equalsIgnoreCase(whereTerm, " <> ")) {
whereTerm = " NOT BETWEEN ";
Map<String, Long> stringLongMap = Utils.parseDateTimeValue(value);
if (isCross) {
whereValue = String.format(SQLConstants.WHERE_VALUE_BETWEEN, stringLongMap.get("startTime"), stringLongMap.get("endTime"));
} else {
whereValue = String.format(SQLConstants.WHERE_BETWEEN, Utils.transLong2Str(stringLongMap.get("startTime")), Utils.transLong2Str(stringLongMap.get("endTime")));
}
} else {
long ts = Utils.allDateFormat2Long(value);
Long startTime = stringLongMap.get("startTime");
Long endTime = stringLongMap.get("endTime");
if (isCross) {
value = ts + "";
if (StringUtils.equalsIgnoreCase(whereTerm, " > ") || StringUtils.equalsIgnoreCase(whereTerm, " <= ")) {
value = endTime + "";
} else if (StringUtils.equalsIgnoreCase(whereTerm, " >= ") || StringUtils.equalsIgnoreCase(whereTerm, " < ")) {
value = startTime + "";
}
} else {
value = Utils.transLong2Str(ts);
if (StringUtils.equalsIgnoreCase(whereTerm, " > ") || StringUtils.equalsIgnoreCase(whereTerm, " <= ")) {
value = Utils.transLong2Str(endTime);
} else if (StringUtils.equalsIgnoreCase(whereTerm, " >= ") || StringUtils.equalsIgnoreCase(whereTerm, " < ")) {
value = Utils.transLong2Str(startTime);
}
}
whereValue = String.format(SQLConstants.WHERE_VALUE_VALUE, value);
}

View File

@ -174,10 +174,10 @@ public class WhereTree2Str {
} else {
// 如果是时间字段过滤当条件是等于和不等于的时候转换成between和not between
if (field.getDeType() == 1) {
Map<String, Long> stringLongMap = Utils.parseDateTimeValue(value);
if (StringUtils.equalsIgnoreCase(whereTerm, " = ")) {
whereTerm = " BETWEEN ";
// 把value类似过滤组件处理获得start time和end time
Map<String, Long> stringLongMap = Utils.parseDateTimeValue(value);
if (isCross) {
whereValue = String.format(SQLConstants.WHERE_VALUE_BETWEEN, stringLongMap.get("startTime"), stringLongMap.get("endTime"));
} else {
@ -185,18 +185,26 @@ public class WhereTree2Str {
}
} else if (StringUtils.equalsIgnoreCase(whereTerm, " <> ")) {
whereTerm = " NOT BETWEEN ";
Map<String, Long> stringLongMap = Utils.parseDateTimeValue(value);
if (isCross) {
whereValue = String.format(SQLConstants.WHERE_VALUE_BETWEEN, stringLongMap.get("startTime"), stringLongMap.get("endTime"));
} else {
whereValue = String.format(SQLConstants.WHERE_BETWEEN, Utils.transLong2Str(stringLongMap.get("startTime")), Utils.transLong2Str(stringLongMap.get("endTime")));
}
} else {
long ts = Utils.allDateFormat2Long(value);
Long startTime = stringLongMap.get("startTime");
Long endTime = stringLongMap.get("endTime");
if (isCross) {
value = ts + "";
if (StringUtils.equalsIgnoreCase(whereTerm, " > ") || StringUtils.equalsIgnoreCase(whereTerm, " <= ")) {
value = endTime + "";
} else if (StringUtils.equalsIgnoreCase(whereTerm, " >= ") || StringUtils.equalsIgnoreCase(whereTerm, " < ")) {
value = startTime + "";
}
} else {
value = Utils.transLong2Str(ts);
if (StringUtils.equalsIgnoreCase(whereTerm, " > ") || StringUtils.equalsIgnoreCase(whereTerm, " <= ")) {
value = Utils.transLong2Str(endTime);
} else if (StringUtils.equalsIgnoreCase(whereTerm, " >= ") || StringUtils.equalsIgnoreCase(whereTerm, " < ")) {
value = Utils.transLong2Str(startTime);
}
}
whereValue = String.format(SQLConstants.WHERE_VALUE_VALUE, value);
}