forked from github/dataease
fix: 尝试修复日期过滤存在时区差异的问题
This commit is contained in:
parent
56878766d7
commit
173205cc7f
@ -138,7 +138,7 @@ public class CustomWhere2Str {
|
||||
res = "(" + whereName + " IN ('" + String.join("','", item.getEnumValue()) + "'))";
|
||||
}
|
||||
} else {
|
||||
if (field.getDeType() == 1) {
|
||||
if (field.getDeType() == 1 && isCross) {
|
||||
// 规定几种日期格式,一一匹配,匹配到就是该格式
|
||||
whereName = String.format(SQLConstants.UNIX_TIMESTAMP, whereName);
|
||||
}
|
||||
@ -168,13 +168,23 @@ public class CustomWhere2Str {
|
||||
whereTerm = " BETWEEN ";
|
||||
// 把value类似过滤组件处理,获得start time和end time
|
||||
Map<String, Long> stringLongMap = Utils.parseDateTimeValue(value);
|
||||
whereValue = String.format(SQLConstants.WHERE_VALUE_BETWEEN, stringLongMap.get("startTime"), stringLongMap.get("endTime"));
|
||||
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 if (StringUtils.equalsIgnoreCase(whereTerm, " <> ")) {
|
||||
whereTerm = " NOT BETWEEN ";
|
||||
Map<String, Long> stringLongMap = Utils.parseDateTimeValue(value);
|
||||
whereValue = String.format(SQLConstants.WHERE_VALUE_BETWEEN, stringLongMap.get("startTime"), stringLongMap.get("endTime"));
|
||||
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 {
|
||||
value = Utils.allDateFormat2Long(value) + "";
|
||||
if (isCross) {
|
||||
value = Utils.allDateFormat2Long(value) + "";
|
||||
}
|
||||
whereValue = String.format(SQLConstants.WHERE_VALUE_VALUE, value);
|
||||
}
|
||||
} else {
|
||||
|
@ -74,7 +74,9 @@ public class ExtWhere2Str {
|
||||
String cast = String.format(SQLConstants.CAST, originName, SQLConstants.DEFAULT_INT_FORMAT);
|
||||
// 此处获取标准格式的日期
|
||||
whereName = String.format(SQLConstants.FROM_UNIXTIME, cast, SQLConstants.DEFAULT_DATE_FORMAT);
|
||||
whereName = String.format(SQLConstants.UNIX_TIMESTAMP, whereName);
|
||||
if (isCross) {
|
||||
whereName = String.format(SQLConstants.UNIX_TIMESTAMP, whereName);
|
||||
}
|
||||
}
|
||||
if (field.getDeExtractType() == 1) {
|
||||
// 如果都是时间类型,把date和time类型进行字符串拼接
|
||||
@ -136,10 +138,18 @@ public class ExtWhere2Str {
|
||||
if (request.getDatasetTableField().getDeExtractType() == 2
|
||||
|| request.getDatasetTableField().getDeExtractType() == 3
|
||||
|| request.getDatasetTableField().getDeExtractType() == 4) {
|
||||
whereValue = String.format(SQLConstants.WHERE_VALUE_BETWEEN, value.get(0), value.get(1));
|
||||
if (isCross) {
|
||||
whereValue = String.format(SQLConstants.WHERE_VALUE_BETWEEN, value.get(0), value.get(1));
|
||||
} else {
|
||||
whereValue = String.format(SQLConstants.WHERE_BETWEEN, Utils.transLong2Str(Long.parseLong(value.get(0))), Utils.transLong2Str(Long.parseLong(value.get(1))));
|
||||
}
|
||||
} else {
|
||||
whereName = String.format(SQLConstants.UNIX_TIMESTAMP, whereName);
|
||||
whereValue = String.format(SQLConstants.WHERE_BETWEEN, Long.parseLong(value.get(0)), Long.parseLong(value.get(1)));
|
||||
if (isCross) {
|
||||
whereName = String.format(SQLConstants.UNIX_TIMESTAMP, whereName);
|
||||
whereValue = String.format(SQLConstants.WHERE_BETWEEN, Long.parseLong(value.get(0)), Long.parseLong(value.get(1)));
|
||||
} else {
|
||||
whereValue = String.format(SQLConstants.WHERE_BETWEEN, Utils.transLong2Str(Long.parseLong(value.get(0))), Utils.transLong2Str(Long.parseLong(value.get(1))));
|
||||
}
|
||||
}
|
||||
} else {
|
||||
whereValue = String.format(SQLConstants.WHERE_BETWEEN, value.get(0), value.get(1));
|
||||
|
@ -155,7 +155,7 @@ public class WhereTree2Str {
|
||||
String whereTerm = Utils.transFilterTerm(item.getTerm());
|
||||
String whereValue = "";
|
||||
|
||||
if (field.getDeType() == 1) {
|
||||
if (field.getDeType() == 1 && isCross) {
|
||||
whereName = String.format(SQLConstants.UNIX_TIMESTAMP, whereName);
|
||||
}
|
||||
|
||||
@ -178,13 +178,23 @@ public class WhereTree2Str {
|
||||
whereTerm = " BETWEEN ";
|
||||
// 把value类似过滤组件处理,获得start time和end time
|
||||
Map<String, Long> stringLongMap = Utils.parseDateTimeValue(value);
|
||||
whereValue = String.format(SQLConstants.WHERE_VALUE_BETWEEN, stringLongMap.get("startTime"), stringLongMap.get("endTime"));
|
||||
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 if (StringUtils.equalsIgnoreCase(whereTerm, " <> ")) {
|
||||
whereTerm = " NOT BETWEEN ";
|
||||
Map<String, Long> stringLongMap = Utils.parseDateTimeValue(value);
|
||||
whereValue = String.format(SQLConstants.WHERE_VALUE_BETWEEN, stringLongMap.get("startTime"), stringLongMap.get("endTime"));
|
||||
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 {
|
||||
value = Utils.allDateFormat2Long(value) + "";
|
||||
if (isCross) {
|
||||
value = Utils.allDateFormat2Long(value) + "";
|
||||
}
|
||||
whereValue = String.format(SQLConstants.WHERE_VALUE_VALUE, value);
|
||||
}
|
||||
} else {
|
||||
|
@ -419,6 +419,12 @@ public class Utils {
|
||||
return map;
|
||||
}
|
||||
|
||||
public static String transLong2Str(Long ts) {
|
||||
Date date = new Date(ts);
|
||||
SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
|
||||
return simpleDateFormat.format(date);
|
||||
}
|
||||
|
||||
public static List<CalParam> getParams(List<DatasetTableFieldDTO> list) {
|
||||
if (ObjectUtils.isEmpty(list)) return Collections.emptyList();
|
||||
List<CalParam> param = new ArrayList<>();
|
||||
|
Loading…
Reference in New Issue
Block a user