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); } }