From a27733ec1ddcb0c33366a16dba07ec1a82598704 Mon Sep 17 00:00:00 2001 From: wisonic-s Date: Mon, 13 Mar 2023 16:13:55 +0800 Subject: [PATCH] =?UTF-8?q?fix(=E8=A7=86=E5=9B=BE-=E6=97=A5=E6=9C=9F?= =?UTF-8?q?=E5=AD=97=E6=AE=B5=E4=B8=8B=E9=92=BB):=20=E4=BF=AE=E5=A4=8D?= =?UTF-8?q?=E8=A7=86=E5=9B=BE=E4=B8=8B=E9=92=BB=E6=97=B6=E5=8C=85=E5=90=AB?= =?UTF-8?q?=E6=97=A5=E6=9C=9F=E5=AD=97=E6=AE=B5=E8=BF=94=E5=9B=9E=E7=A9=BA?= =?UTF-8?q?=E6=95=B0=E6=8D=AE?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit https://www.tapd.cn/55578866/bugtrace/bugs/view/1155578866001023529 --- .../dataease/provider/query/db2/Db2QueryProvider.java | 9 +++++---- .../dataease/provider/query/es/EsQueryProvider.java | 7 ++++--- .../provider/query/hive/HiveQueryProvider.java | 8 ++++---- .../provider/query/impala/ImpalaQueryProvider.java | 7 ++++--- .../provider/query/oracle/OracleQueryProvider.java | 8 ++++---- .../dataease/provider/query/pg/PgQueryProvider.java | 11 +++++++---- .../query/redshift/RedshiftQueryProvider.java | 9 ++++++--- .../query/sqlserver/SqlserverQueryProvider.java | 9 +++------ 8 files changed, 37 insertions(+), 31 deletions(-) diff --git a/backend/src/main/java/io/dataease/provider/query/db2/Db2QueryProvider.java b/backend/src/main/java/io/dataease/provider/query/db2/Db2QueryProvider.java index a0940c08ab..80252527f8 100644 --- a/backend/src/main/java/io/dataease/provider/query/db2/Db2QueryProvider.java +++ b/backend/src/main/java/io/dataease/provider/query/db2/Db2QueryProvider.java @@ -1115,23 +1115,24 @@ public class Db2QueryProvider extends QueryProvider { } if (field.getDeType() == DeTypeConstants.DE_TIME) { + String format = transDateFormat(request.getDateStyle(), request.getDatePattern()); if (field.getDeExtractType() == DeTypeConstants.DE_STRING || field.getDeExtractType() == 5) { if (StringUtils.isNotEmpty(field.getDateFormat())) { originName = String.format(Db2Constants.TO_DATE, originName, field.getDateFormat()); } else { originName = String.format(Db2Constants.STR_TO_DATE, originName); } - whereName = String.format(Db2Constants.DATE_FORMAT, originName, Db2Constants.DEFAULT_DATE_FORMAT); + whereName = String.format(Db2Constants.DATE_FORMAT, originName, format); } if (field.getDeExtractType() == DeTypeConstants.DE_INT || field.getDeExtractType() == 3 || field.getDeExtractType() == 4) { String cast = String.format(Db2Constants.CAST, originName, Db2Constants.DEFAULT_INT_FORMAT); - whereName = String.format(Db2Constants.FROM_UNIXTIME, cast, Db2Constants.DEFAULT_DATE_FORMAT); + whereName = String.format(Db2Constants.FROM_UNIXTIME, cast, format); } if (field.getDeExtractType() == DeTypeConstants.DE_TIME) { if (field.getType().equalsIgnoreCase("TIME")) { - whereName = String.format(Db2Constants.FORMAT_TIME, originName, Db2Constants.DEFAULT_DATE_FORMAT); + whereName = String.format(Db2Constants.FORMAT_TIME, originName, format); } else if (field.getType().equalsIgnoreCase("DATE")) { - whereName = String.format(Db2Constants.FORMAT_DATE, originName, Db2Constants.DEFAULT_DATE_FORMAT); + whereName = String.format(Db2Constants.FORMAT_DATE, originName, format); } else { whereName = originName; } diff --git a/backend/src/main/java/io/dataease/provider/query/es/EsQueryProvider.java b/backend/src/main/java/io/dataease/provider/query/es/EsQueryProvider.java index 019b09e61a..fd02228338 100644 --- a/backend/src/main/java/io/dataease/provider/query/es/EsQueryProvider.java +++ b/backend/src/main/java/io/dataease/provider/query/es/EsQueryProvider.java @@ -1080,15 +1080,16 @@ public class EsQueryProvider extends QueryProvider { } if (field.getDeType() == 1) { + String format = transDateFormat(request.getDateStyle(), request.getDatePattern()); if (field.getDeExtractType() == 0 || field.getDeExtractType() == 5) { - whereName = String.format(EsSqlLConstants.STR_TO_DATE, originName, StringUtils.isNotEmpty(field.getDateFormat()) ? field.getDateFormat() : EsSqlLConstants.DEFAULT_DATE_FORMAT, EsSqlLConstants.DEFAULT_DATE_FORMAT); + whereName = String.format(EsSqlLConstants.STR_TO_DATE, originName, StringUtils.isNotEmpty(field.getDateFormat()) ? field.getDateFormat() : EsSqlLConstants.DEFAULT_DATE_FORMAT, format); } if (field.getDeExtractType() == 2 || field.getDeExtractType() == 3 || field.getDeExtractType() == 4) { String cast = String.format(EsSqlLConstants.CAST, originName, "timestamp"); - whereName = String.format(EsSqlLConstants.DATETIME_FORMAT, cast, EsSqlLConstants.DEFAULT_DATE_FORMAT); + whereName = String.format(EsSqlLConstants.DATETIME_FORMAT, cast, format); } if (field.getDeExtractType() == 1) { - whereName = originName; + whereName = String.format(EsSqlLConstants.DATETIME_FORMAT, originName, format); } } else if (field.getDeType() == 2 || field.getDeType() == 3) { if (field.getDeExtractType() == 0 || field.getDeExtractType() == 5) { diff --git a/backend/src/main/java/io/dataease/provider/query/hive/HiveQueryProvider.java b/backend/src/main/java/io/dataease/provider/query/hive/HiveQueryProvider.java index f5e1ed62a0..8ec11f5649 100644 --- a/backend/src/main/java/io/dataease/provider/query/hive/HiveQueryProvider.java +++ b/backend/src/main/java/io/dataease/provider/query/hive/HiveQueryProvider.java @@ -1035,17 +1035,17 @@ public class HiveQueryProvider extends QueryProvider { } else { originName = String.format(HiveConstants.KEYWORD_FIX, tableObj.getTableAlias(), field.getOriginName()); } - + String format = transDateFormat(request.getDateStyle(), request.getDatePattern()); if (field.getDeType() == DeTypeConstants.DE_TIME) { if (field.getDeExtractType() == DeTypeConstants.DE_STRING || field.getDeExtractType() == 5) { - whereName = String.format(HiveConstants.STR_TO_DATE, originName, StringUtils.isNotEmpty(field.getDateFormat()) ? field.getDateFormat() : HiveConstants.DEFAULT_DATE_FORMAT); + whereName = String.format(HiveConstants.DATE_FORMAT, originName, format); } if (field.getDeExtractType() == DeTypeConstants.DE_INT || field.getDeExtractType() == 3 || field.getDeExtractType() == 4) { String cast = String.format(HiveConstants.CAST, originName, HiveConstants.DEFAULT_INT_FORMAT) + "/1000"; - whereName = String.format(HiveConstants.FROM_UNIXTIME, cast, HiveConstants.DEFAULT_DATE_FORMAT); + whereName = String.format(HiveConstants.FROM_UNIXTIME, cast, format); } if (field.getDeExtractType() == DeTypeConstants.DE_TIME) { - whereName = originName; + whereName = String.format(HiveConstants.DATE_FORMAT, originName, format); } } else if (field.getDeType() == 2 || field.getDeType() == 3) { if (field.getDeExtractType() == 0 || field.getDeExtractType() == 5) { diff --git a/backend/src/main/java/io/dataease/provider/query/impala/ImpalaQueryProvider.java b/backend/src/main/java/io/dataease/provider/query/impala/ImpalaQueryProvider.java index 99b70857b6..210ff42c02 100644 --- a/backend/src/main/java/io/dataease/provider/query/impala/ImpalaQueryProvider.java +++ b/backend/src/main/java/io/dataease/provider/query/impala/ImpalaQueryProvider.java @@ -1032,16 +1032,17 @@ public class ImpalaQueryProvider extends QueryProvider { originName = String.format(ImpalaConstants.KEYWORD_FIX, tableObj.getTableAlias(), field.getOriginName()); } + String format = transDateFormat(request.getDateStyle(), request.getDatePattern()); if (field.getDeType() == DeTypeConstants.DE_TIME) { if (field.getDeExtractType() == DeTypeConstants.DE_STRING || field.getDeExtractType() == 5) { - whereName = String.format(ImpalaConstants.STR_TO_DATE, originName, StringUtils.isNotEmpty(field.getDateFormat()) ? field.getDateFormat() : ImpalaConstants.DEFAULT_DATE_FORMAT ,ImpalaConstants.DEFAULT_DATE_FORMAT); + whereName = String.format(ImpalaConstants.STR_TO_DATE, originName, StringUtils.isNotEmpty(field.getDateFormat()) ? field.getDateFormat() : ImpalaConstants.DEFAULT_DATE_FORMAT, format); } if (field.getDeExtractType() == DeTypeConstants.DE_INT || field.getDeExtractType() == 3 || field.getDeExtractType() == 4) { String cast = String.format(ImpalaConstants.CAST, originName, ImpalaConstants.DEFAULT_INT_FORMAT) + "/1000"; - whereName = String.format(ImpalaConstants.FROM_UNIXTIME, cast, ImpalaConstants.DEFAULT_DATE_FORMAT); + whereName = String.format(ImpalaConstants.FROM_UNIXTIME, cast, format); } if (field.getDeExtractType() == DeTypeConstants.DE_TIME) { - whereName = originName; + whereName = String.format(ImpalaConstants.DATE_FORMAT, originName, format); } } else if (field.getDeType() == 2 || field.getDeType() == 3) { if (field.getDeExtractType() == 0 || field.getDeExtractType() == 5) { diff --git a/backend/src/main/java/io/dataease/provider/query/oracle/OracleQueryProvider.java b/backend/src/main/java/io/dataease/provider/query/oracle/OracleQueryProvider.java index dcd743da03..a943170556 100644 --- a/backend/src/main/java/io/dataease/provider/query/oracle/OracleQueryProvider.java +++ b/backend/src/main/java/io/dataease/provider/query/oracle/OracleQueryProvider.java @@ -1205,17 +1205,17 @@ public class OracleQueryProvider extends QueryProvider { } else { originName = String.format(OracleConstants.KEYWORD_FIX, tableObj.getTableAlias(), field.getOriginName()); } - + String format = transDateFormat(request.getDateStyle(), request.getDatePattern()); if (field.getDeType() == 1) { if (field.getDeExtractType() == 0 || field.getDeExtractType() == 5) { - whereName = String.format(OracleConstants.TO_DATE, originName, StringUtils.isNotEmpty(field.getDateFormat()) ? field.getDateFormat() : OracleConstants.DEFAULT_DATE_FORMAT); + whereName = String.format(OracleConstants.TO_DATE, originName, format); } if (field.getDeExtractType() == 2 || field.getDeExtractType() == 3 || field.getDeExtractType() == 4) { String cast = String.format(OracleConstants.CAST, originName, OracleConstants.DEFAULT_INT_FORMAT) + "/1000"; - whereName = String.format(OracleConstants.FROM_UNIXTIME, cast, OracleConstants.DEFAULT_DATE_FORMAT); + whereName = String.format(OracleConstants.FROM_UNIXTIME, cast, format); } if (field.getDeExtractType() == 1) { - whereName = originName; + whereName = String.format(OracleConstants.TO_CHAR, format); } } else if (field.getDeType() == 2 || field.getDeType() == 3) { if (field.getDeExtractType() == 0 || field.getDeExtractType() == 5) { diff --git a/backend/src/main/java/io/dataease/provider/query/pg/PgQueryProvider.java b/backend/src/main/java/io/dataease/provider/query/pg/PgQueryProvider.java index 6acb16b903..05c4af1617 100644 --- a/backend/src/main/java/io/dataease/provider/query/pg/PgQueryProvider.java +++ b/backend/src/main/java/io/dataease/provider/query/pg/PgQueryProvider.java @@ -1072,15 +1072,18 @@ public class PgQueryProvider extends QueryProvider { } if (field.getDeType() == 1) { - if (field.getDeExtractType() == 0 || field.getDeExtractType() == 5) { - whereName = String.format(PgConstants.STR_TO_DATE, originName, StringUtils.isNotEmpty(field.getDateFormat()) ? field.getDateFormat() : PgConstants.DEFAULT_DATE_FORMAT); + String format = transDateFormat(request.getDateStyle(), request.getDatePattern()); + if (field.getDeExtractType() == 0 || field.getDeExtractType() == 5 || field.getDeExtractType() == 1) { + String timestamp = String.format(PgConstants.STR_TO_DATE, originName, StringUtils.isNotEmpty(field.getDateFormat()) ? field.getDateFormat() : PgConstants.DEFAULT_DATE_FORMAT); + whereName = String.format(PgConstants.DATE_FORMAT, timestamp, format); } if (field.getDeExtractType() == 2 || field.getDeExtractType() == 3 || field.getDeExtractType() == 4) { String cast = String.format(PgConstants.CAST, originName, "bigint"); - whereName = String.format(PgConstants.FROM_UNIXTIME, cast); + String timestamp = String.format(PgConstants.FROM_UNIXTIME, cast); + whereName = String.format(PgConstants.DATE_FORMAT, timestamp, format); } if (field.getDeExtractType() == 1) { - whereName = originName; + whereName = String.format(PgConstants.DATE_FORMAT, originName, format); } } else if (field.getDeType() == 2 || field.getDeType() == 3) { if (field.getDeExtractType() == 0 || field.getDeExtractType() == 5) { diff --git a/backend/src/main/java/io/dataease/provider/query/redshift/RedshiftQueryProvider.java b/backend/src/main/java/io/dataease/provider/query/redshift/RedshiftQueryProvider.java index 61aec7505f..52636edbfd 100644 --- a/backend/src/main/java/io/dataease/provider/query/redshift/RedshiftQueryProvider.java +++ b/backend/src/main/java/io/dataease/provider/query/redshift/RedshiftQueryProvider.java @@ -1067,15 +1067,18 @@ public class RedshiftQueryProvider extends QueryProvider { } if (field.getDeType() == 1) { + String format = transDateFormat(request.getDateStyle(), request.getDatePattern()); if (field.getDeExtractType() == 0 || field.getDeExtractType() == 5) { - whereName = String.format(PgConstants.STR_TO_DATE, originName, StringUtils.isNotEmpty(field.getDateFormat()) ? field.getDateFormat() : PgConstants.DEFAULT_DATE_FORMAT); + String timestamp = String.format(PgConstants.STR_TO_DATE, originName, StringUtils.isNotEmpty(field.getDateFormat()) ? field.getDateFormat() : PgConstants.DEFAULT_DATE_FORMAT); + whereName = String.format(PgConstants.DATE_FORMAT, timestamp, format); } if (field.getDeExtractType() == 2 || field.getDeExtractType() == 3 || field.getDeExtractType() == 4) { String cast = String.format(PgConstants.CAST, originName, "bigint"); - whereName = String.format(PgConstants.FROM_UNIXTIME, cast); + String timestamp = String.format(PgConstants.FROM_UNIXTIME, cast); + whereName = String.format(PgConstants.DATE_FORMAT, timestamp, format); } if (field.getDeExtractType() == 1) { - whereName = originName; + whereName = String.format(PgConstants.DATE_FORMAT, originName, format); } } else if (field.getDeType() == 2 || field.getDeType() == 3) { if (field.getDeExtractType() == 0 || field.getDeExtractType() == 5) { diff --git a/backend/src/main/java/io/dataease/provider/query/sqlserver/SqlserverQueryProvider.java b/backend/src/main/java/io/dataease/provider/query/sqlserver/SqlserverQueryProvider.java index 824a611b3f..a18d3de5db 100644 --- a/backend/src/main/java/io/dataease/provider/query/sqlserver/SqlserverQueryProvider.java +++ b/backend/src/main/java/io/dataease/provider/query/sqlserver/SqlserverQueryProvider.java @@ -1080,15 +1080,12 @@ public class SqlserverQueryProvider extends QueryProvider { } if (field.getDeType() == 1) { - if (field.getDeExtractType() == 0 || field.getDeExtractType() == 5) { - whereName = String.format(SqlServerSQLConstants.STRING_TO_DATE, originName, StringUtils.isNotEmpty(field.getDateFormat()) ? field.getDateFormat() : SqlServerSQLConstants.DEFAULT_DATE_FORMAT); + if (field.getDeExtractType() == 0 || field.getDeExtractType() == 5 || field.getDeExtractType() == 1) { + whereName = transDateFormat(request.getDateStyle(), request.getDatePattern(), originName); } if (field.getDeExtractType() == 2 || field.getDeExtractType() == 3 || field.getDeExtractType() == 4) { String cast = String.format(SqlServerSQLConstants.LONG_TO_DATE, originName + "/1000"); - whereName = String.format(SqlServerSQLConstants.FROM_UNIXTIME, cast); - } - if (field.getDeExtractType() == 1) { - whereName = originName; + whereName = transDateFormat(request.getDateStyle(), request.getDatePattern(), cast);; } } else if (field.getDeType() == 2 || field.getDeType() == 3) { if (field.getDeExtractType() == 0 || field.getDeExtractType() == 5) {