Merge pull request #9146 from dataease/pr@dev-v2@feat_filter

feat(仪表板): 文本下拉组件支持显示字段和排序字段设置
This commit is contained in:
Junjun 2024-04-17 10:00:23 +08:00 committed by GitHub
commit e4afcb2e07
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
4 changed files with 10 additions and 9 deletions

View File

@ -200,7 +200,7 @@ public class DatasetDataManage {
// build query sql // build query sql
SQLMeta sqlMeta = new SQLMeta(); SQLMeta sqlMeta = new SQLMeta();
Table2SQLObj.table2sqlobj(sqlMeta, null, "(" + sql + ")", crossDs); 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); WhereTree2Str.transFilterTrees(sqlMeta, rowPermissionsTree, fields, crossDs, dsMap);
Order2SQLObj.getOrders(sqlMeta, fields, datasetGroupInfoDTO.getSortFields(), crossDs, dsMap); Order2SQLObj.getOrders(sqlMeta, fields, datasetGroupInfoDTO.getSortFields(), crossDs, dsMap);
String querySQL; String querySQL;
@ -459,7 +459,7 @@ public class DatasetDataManage {
rowPermissionsTree = permissionManage.getRowPermissionsTree(datasetGroupInfoDTO.getId(), user.getUserId()); 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); WhereTree2Str.transFilterTrees(sqlMeta, rowPermissionsTree, fields, crossDs, dsMap);
Order2SQLObj.getOrders(sqlMeta, fields, datasetGroupInfoDTO.getSortFields(), crossDs, dsMap); Order2SQLObj.getOrders(sqlMeta, fields, datasetGroupInfoDTO.getSortFields(), crossDs, dsMap);
String querySQL = SQLProvider.createQuerySQLWithLimit(sqlMeta, false, needOrder, true, 0, 1000); String querySQL = SQLProvider.createQuerySQLWithLimit(sqlMeta, false, needOrder, true, 0, 1000);
@ -585,7 +585,7 @@ public class DatasetDataManage {
datasetGroupInfoDTO.setSortFields(Collections.singletonList(deSortField)); 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); WhereTree2Str.transFilterTrees(sqlMeta, rowPermissionsTree, fields, crossDs, dsMap);
Order2SQLObj.getOrders(sqlMeta, fields, datasetGroupInfoDTO.getSortFields(), crossDs, dsMap); Order2SQLObj.getOrders(sqlMeta, fields, datasetGroupInfoDTO.getSortFields(), crossDs, dsMap);
String querySQL = SQLProvider.createQuerySQLWithLimit(sqlMeta, false, needOrder, false, 0, 1000); String querySQL = SQLProvider.createQuerySQLWithLimit(sqlMeta, false, needOrder, false, 0, 1000);

View File

@ -47,7 +47,7 @@ public class SQLConstants {
public static final String FIELD_NAME = "%s.`%s`"; 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)"; public static final String UNIX_TIMESTAMP = "DE_UNIX_TIMESTAMP(%s)";

View File

@ -20,7 +20,7 @@ import java.util.*;
*/ */
public class Field2SQLObj { public class Field2SQLObj {
public static void field2sqlObj(SQLMeta meta, List<DatasetTableFieldDTO> fields, boolean isCross, Map<Long, DatasourceSchemaDTO> dsMap) { public static void field2sqlObj(SQLMeta meta, List<DatasetTableFieldDTO> fields,List<DatasetTableFieldDTO> originFields, boolean isCross, Map<Long, DatasourceSchemaDTO> dsMap) {
SQLObj tableObj = meta.getTable(); SQLObj tableObj = meta.getTable();
if (ObjectUtils.isEmpty(tableObj)) { if (ObjectUtils.isEmpty(tableObj)) {
return; return;
@ -33,7 +33,7 @@ public class Field2SQLObj {
String originField; String originField;
if (ObjectUtils.isNotEmpty(x.getExtField()) && Objects.equals(x.getExtField(), ExtFieldConstant.EXT_CALC)) { if (ObjectUtils.isNotEmpty(x.getExtField()) && Objects.equals(x.getExtField(), ExtFieldConstant.EXT_CALC)) {
// 解析origin name中有关联的字段生成sql表达式 // 解析origin name中有关联的字段生成sql表达式
String calcFieldExp = Utils.calcFieldRegex(x.getOriginName(), tableObj, fields, isCross, dsMap); String calcFieldExp = Utils.calcFieldRegex(x.getOriginName(), tableObj, originFields, isCross, dsMap);
// 给计算字段处加一个占位符后续SQL方言转换后再替换 // 给计算字段处加一个占位符后续SQL方言转换后再替换
originField = String.format(SqlPlaceholderConstants.CALC_FIELD_PLACEHOLDER, x.getId()); originField = String.format(SqlPlaceholderConstants.CALC_FIELD_PLACEHOLDER, x.getId());
fieldsDialect.put(originField, calcFieldExp); fieldsDialect.put(originField, calcFieldExp);

View File

@ -11,8 +11,8 @@ import io.dataease.engine.constant.SQLConstants;
import io.dataease.engine.utils.Utils; import io.dataease.engine.utils.Utils;
import org.apache.commons.lang3.ObjectUtils; import org.apache.commons.lang3.ObjectUtils;
import org.apache.commons.lang3.StringUtils; import org.apache.commons.lang3.StringUtils;
import org.springframework.util.CollectionUtils;
import java.util.ArrayList;
import java.util.List; import java.util.List;
import java.util.Map; import java.util.Map;
import java.util.Objects; import java.util.Objects;
@ -24,8 +24,8 @@ public class Order2SQLObj {
public static void getOrders(SQLMeta meta, List<DatasetTableFieldDTO> fields, List<DeSortField> sortFields, boolean isCross, Map<Long, DatasourceSchemaDTO> dsMap) { public static void getOrders(SQLMeta meta, List<DatasetTableFieldDTO> fields, List<DeSortField> sortFields, boolean isCross, Map<Long, DatasourceSchemaDTO> dsMap) {
SQLObj tableObj = meta.getTable(); SQLObj tableObj = meta.getTable();
List<SQLObj> xOrders = meta.getXOrders(); List<SQLObj> xOrders = meta.getXOrders() == null ? new ArrayList<>() : meta.getXOrders();
if (ObjectUtils.isEmpty(tableObj) || CollectionUtils.isEmpty(xOrders)) { if (ObjectUtils.isEmpty(tableObj)) {
return; return;
} }
if (ObjectUtils.isNotEmpty(sortFields)) { if (ObjectUtils.isNotEmpty(sortFields)) {
@ -35,6 +35,7 @@ public class Order2SQLObj {
SQLObj order = buildSortField(deSortField, tableObj, i, fields, isCross, dsMap); SQLObj order = buildSortField(deSortField, tableObj, i, fields, isCross, dsMap);
xOrders.add(order); xOrders.add(order);
} }
meta.setXOrders(xOrders);
} }
} }