From c28443ec6b306a49000874c814fad6970856ca52 Mon Sep 17 00:00:00 2001 From: junjun Date: Wed, 17 Apr 2024 09:58:49 +0800 Subject: [PATCH] =?UTF-8?q?feat(=E4=BB=AA=E8=A1=A8=E6=9D=BF):=20=E6=96=87?= =?UTF-8?q?=E6=9C=AC=E4=B8=8B=E6=8B=89=E7=BB=84=E4=BB=B6=E6=94=AF=E6=8C=81?= =?UTF-8?q?=E6=98=BE=E7=A4=BA=E5=AD=97=E6=AE=B5=E5=92=8C=E6=8E=92=E5=BA=8F?= =?UTF-8?q?=E5=AD=97=E6=AE=B5=E8=AE=BE=E7=BD=AE?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../java/io/dataease/dataset/manage/DatasetDataManage.java | 6 +++--- .../java/io/dataease/engine/constant/SQLConstants.java | 2 +- .../main/java/io/dataease/engine/trans/Field2SQLObj.java | 4 ++-- .../main/java/io/dataease/engine/trans/Order2SQLObj.java | 7 ++++--- 4 files changed, 10 insertions(+), 9 deletions(-) diff --git a/core/core-backend/src/main/java/io/dataease/dataset/manage/DatasetDataManage.java b/core/core-backend/src/main/java/io/dataease/dataset/manage/DatasetDataManage.java index d69e0df2e8..87d849ef59 100644 --- a/core/core-backend/src/main/java/io/dataease/dataset/manage/DatasetDataManage.java +++ b/core/core-backend/src/main/java/io/dataease/dataset/manage/DatasetDataManage.java @@ -200,7 +200,7 @@ public class DatasetDataManage { // build query sql SQLMeta sqlMeta = new SQLMeta(); Table2SQLObj.table2sqlobj(sqlMeta, null, "(" + sql + ")", crossDs); - Field2SQLObj.field2sqlObj(sqlMeta, fields, crossDs, dsMap); + Field2SQLObj.field2sqlObj(sqlMeta, fields, fields, crossDs, dsMap); WhereTree2Str.transFilterTrees(sqlMeta, rowPermissionsTree, fields, crossDs, dsMap); Order2SQLObj.getOrders(sqlMeta, fields, datasetGroupInfoDTO.getSortFields(), crossDs, dsMap); String querySQL; @@ -459,7 +459,7 @@ public class DatasetDataManage { rowPermissionsTree = permissionManage.getRowPermissionsTree(datasetGroupInfoDTO.getId(), user.getUserId()); } - Field2SQLObj.field2sqlObj(sqlMeta, fields, crossDs, dsMap); + Field2SQLObj.field2sqlObj(sqlMeta, fields, datasetGroupInfoDTO.getAllFields(), crossDs, dsMap); WhereTree2Str.transFilterTrees(sqlMeta, rowPermissionsTree, fields, crossDs, dsMap); Order2SQLObj.getOrders(sqlMeta, fields, datasetGroupInfoDTO.getSortFields(), crossDs, dsMap); String querySQL = SQLProvider.createQuerySQLWithLimit(sqlMeta, false, needOrder, true, 0, 1000); @@ -585,7 +585,7 @@ public class DatasetDataManage { datasetGroupInfoDTO.setSortFields(Collections.singletonList(deSortField)); } - Field2SQLObj.field2sqlObj(sqlMeta, fields, crossDs, dsMap); + Field2SQLObj.field2sqlObj(sqlMeta, fields, datasetGroupInfoDTO.getAllFields(), crossDs, dsMap); WhereTree2Str.transFilterTrees(sqlMeta, rowPermissionsTree, fields, crossDs, dsMap); Order2SQLObj.getOrders(sqlMeta, fields, datasetGroupInfoDTO.getSortFields(), crossDs, dsMap); String querySQL = SQLProvider.createQuerySQLWithLimit(sqlMeta, false, needOrder, false, 0, 1000); 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 27396f5246..ef85e88b5a 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,7 +47,7 @@ public class SQLConstants { public static final String FIELD_NAME = "%s.`%s`"; - public static final String FIELD_DOT = "`%s`"; + public static final String FIELD_DOT = "%s"; public static final String UNIX_TIMESTAMP = "DE_UNIX_TIMESTAMP(%s)"; diff --git a/core/core-backend/src/main/java/io/dataease/engine/trans/Field2SQLObj.java b/core/core-backend/src/main/java/io/dataease/engine/trans/Field2SQLObj.java index ce17474b6e..6b8378272e 100644 --- a/core/core-backend/src/main/java/io/dataease/engine/trans/Field2SQLObj.java +++ b/core/core-backend/src/main/java/io/dataease/engine/trans/Field2SQLObj.java @@ -20,7 +20,7 @@ import java.util.*; */ public class Field2SQLObj { - public static void field2sqlObj(SQLMeta meta, List fields, boolean isCross, Map dsMap) { + public static void field2sqlObj(SQLMeta meta, List fields,List originFields, boolean isCross, Map dsMap) { SQLObj tableObj = meta.getTable(); if (ObjectUtils.isEmpty(tableObj)) { return; @@ -33,7 +33,7 @@ public class Field2SQLObj { String originField; if (ObjectUtils.isNotEmpty(x.getExtField()) && Objects.equals(x.getExtField(), ExtFieldConstant.EXT_CALC)) { // 解析origin name中有关联的字段生成sql表达式 - String calcFieldExp = Utils.calcFieldRegex(x.getOriginName(), tableObj, fields, isCross, dsMap); + String calcFieldExp = Utils.calcFieldRegex(x.getOriginName(), tableObj, originFields, isCross, dsMap); // 给计算字段处加一个占位符,后续SQL方言转换后再替换 originField = String.format(SqlPlaceholderConstants.CALC_FIELD_PLACEHOLDER, x.getId()); fieldsDialect.put(originField, calcFieldExp); 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 7bbab4e9f5..5798d270be 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 @@ -11,8 +11,8 @@ import io.dataease.engine.constant.SQLConstants; import io.dataease.engine.utils.Utils; import org.apache.commons.lang3.ObjectUtils; import org.apache.commons.lang3.StringUtils; -import org.springframework.util.CollectionUtils; +import java.util.ArrayList; import java.util.List; import java.util.Map; import java.util.Objects; @@ -24,8 +24,8 @@ public class Order2SQLObj { public static void getOrders(SQLMeta meta, List fields, List sortFields, boolean isCross, Map dsMap) { SQLObj tableObj = meta.getTable(); - List xOrders = meta.getXOrders(); - if (ObjectUtils.isEmpty(tableObj) || CollectionUtils.isEmpty(xOrders)) { + List xOrders = meta.getXOrders() == null ? new ArrayList<>() : meta.getXOrders(); + if (ObjectUtils.isEmpty(tableObj)) { return; } if (ObjectUtils.isNotEmpty(sortFields)) { @@ -35,6 +35,7 @@ public class Order2SQLObj { SQLObj order = buildSortField(deSortField, tableObj, i, fields, isCross, dsMap); xOrders.add(order); } + meta.setXOrders(xOrders); } }