From 073c13ca41edc8473c12753c1db7d04954c0d34c Mon Sep 17 00:00:00 2001 From: junjun Date: Fri, 27 Oct 2023 11:27:09 +0800 Subject: [PATCH] =?UTF-8?q?fix:=20SQL=E4=B8=ADorder=20by=E5=85=B3=E9=94=AE?= =?UTF-8?q?=E5=AD=97=E5=A4=84=E7=90=86?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../java/io/dataease/engine/constant/SQLConstants.java | 2 ++ .../main/java/io/dataease/engine/sql/SQLProvider.java | 10 ++++++++-- .../java/io/dataease/engine/trans/Order2SQLObj.java | 5 ++++- 3 files changed, 14 insertions(+), 3 deletions(-) diff --git a/core/core-backend/src/main/java/io/dataease/engine/constant/SQLConstants.java b/core/core-backend/src/main/java/io/dataease/engine/constant/SQLConstants.java index 0b5f2e18da..2a7282373d 100644 --- a/core/core-backend/src/main/java/io/dataease/engine/constant/SQLConstants.java +++ b/core/core-backend/src/main/java/io/dataease/engine/constant/SQLConstants.java @@ -47,6 +47,8 @@ public class SQLConstants { public static final String FIELD_NAME = "%s.`%s`"; + public static final String FIELD_DOT = "`%s`"; + public static final String UNIX_TIMESTAMP = "UNIX_TIMESTAMP(%s)"; public static final String DATE_FORMAT = "DATE_FORMAT(%s,'%s')"; diff --git a/core/core-backend/src/main/java/io/dataease/engine/sql/SQLProvider.java b/core/core-backend/src/main/java/io/dataease/engine/sql/SQLProvider.java index 9b6ed8849f..c2fa39f1d3 100644 --- a/core/core-backend/src/main/java/io/dataease/engine/sql/SQLProvider.java +++ b/core/core-backend/src/main/java/io/dataease/engine/sql/SQLProvider.java @@ -56,7 +56,10 @@ public class SQLProvider { if (ObjectUtils.isNotEmpty(xFields)) { xOrders = new ArrayList<>(); SQLObj sqlObj = xFields.get(0); - SQLObj result = SQLObj.builder().orderField(sqlObj.getFieldAlias()).orderAlias(sqlObj.getFieldAlias()).orderDirection("ASC").build(); + SQLObj result = SQLObj.builder() + .orderField(String.format(SQLConstants.FIELD_DOT, sqlObj.getFieldAlias())) + .orderAlias(String.format(SQLConstants.FIELD_DOT, sqlObj.getFieldAlias())) + .orderDirection("ASC").build(); xOrders.add(result); } } @@ -115,7 +118,10 @@ public class SQLProvider { if (needOrder && ObjectUtils.isEmpty(orders)) { if (ObjectUtils.isNotEmpty(xFields) || ObjectUtils.isNotEmpty(yFields)) { SQLObj sqlObj = ObjectUtils.isNotEmpty(xFields) ? xFields.get(0) : yFields.get(0); - SQLObj result = SQLObj.builder().orderField(sqlObj.getFieldAlias()).orderAlias(sqlObj.getFieldAlias()).orderDirection("ASC").build(); + SQLObj result = SQLObj.builder() + .orderField(String.format(SQLConstants.FIELD_DOT, sqlObj.getFieldAlias())) + .orderAlias(String.format(SQLConstants.FIELD_DOT, sqlObj.getFieldAlias())) + .orderDirection("ASC").build(); orders.add(result); } } diff --git a/core/core-backend/src/main/java/io/dataease/engine/trans/Order2SQLObj.java b/core/core-backend/src/main/java/io/dataease/engine/trans/Order2SQLObj.java index 14943c40e8..53f57b6f54 100644 --- a/core/core-backend/src/main/java/io/dataease/engine/trans/Order2SQLObj.java +++ b/core/core-backend/src/main/java/io/dataease/engine/trans/Order2SQLObj.java @@ -78,7 +78,10 @@ public class Order2SQLObj { fieldName = originField; } } - SQLObj result = SQLObj.builder().orderField(originField).orderAlias(originField).orderDirection(f.getOrderDirection()).build(); + SQLObj result = SQLObj.builder() + .orderField(String.format(SQLConstants.FIELD_DOT, originField)) + .orderAlias(String.format(SQLConstants.FIELD_DOT, originField)) + .orderDirection(f.getOrderDirection()).build(); return result; }