From 1b63d7572dbd655c7c1f7736030a562a10f5b4ad Mon Sep 17 00:00:00 2001 From: junjun Date: Fri, 13 Sep 2024 10:21:59 +0800 Subject: [PATCH] =?UTF-8?q?refactor:=20=E6=95=B0=E6=8D=AE=E9=9B=86?= =?UTF-8?q?=E9=A2=84=E8=A7=88=E7=95=8C=E9=9D=A2=E6=95=B0=E6=8D=AE=E5=8A=A0?= =?UTF-8?q?=E8=BD=BD=E9=80=9F=E5=BA=A6=20#12099?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../dataset/manage/DatasetDataManage.java | 52 ++++++++++++++++++- .../dataset/server/DatasetDataServer.java | 5 ++ core/core-frontend/src/api/dataset.ts | 6 +++ .../views/visualized/data/dataset/index.vue | 9 ++-- .../dataease/api/dataset/DatasetDataApi.java | 4 ++ 5 files changed, 71 insertions(+), 5 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 3715efd527..ad2d6abe47 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 @@ -250,8 +250,6 @@ public class DatasetDataManage { map.put("allFields", fieldList); } map.put("sql", Base64.getEncoder().encodeToString(querySQL.getBytes())); - String replaceSql = provider.rebuildSQL(SQLProvider.createQuerySQL(sqlMeta, false, false, false), sqlMeta, crossDs, dsMap); - map.put("total", getDatasetTotal(datasetGroupInfoDTO, replaceSql, null)); return map; } @@ -263,6 +261,56 @@ public class DatasetDataManage { return 0L; } + public Long getDatasetCountWithWhere(Long datasetGroupId) throws Exception { + DatasetGroupInfoDTO datasetGroupInfoDTO = datasetGroupManage.getForCount(datasetGroupId); + Map sqlMap = datasetSQLManage.getUnionSQLForEdit(datasetGroupInfoDTO, null); + String sql = (String) sqlMap.get("sql"); + + // 获取allFields + List fields = datasetGroupInfoDTO.getAllFields(); + if (ObjectUtils.isEmpty(fields)) { + DEException.throwException(Translator.get("i18n_no_fields")); + } + + buildFieldName(sqlMap, fields); + + Map dsMap = (Map) sqlMap.get("dsMap"); + DatasourceUtils.checkDsStatus(dsMap); + List dsList = new ArrayList<>(); + for (Map.Entry next : dsMap.entrySet()) { + dsList.add(next.getValue().getType()); + } + boolean crossDs = Utils.isCrossDs(dsMap); + if (!crossDs) { + if (notFullDs.contains(dsMap.entrySet().iterator().next().getValue().getType()) && (boolean) sqlMap.get("isFullJoin")) { + DEException.throwException(Translator.get("i18n_not_full")); + } + sql = Utils.replaceSchemaAlias(sql, dsMap); + } + + List rowPermissionsTree = new ArrayList<>(); + TokenUserBO user = AuthUtils.getUser(); + if (user != null) { + rowPermissionsTree = permissionManage.getRowPermissionsTree(datasetGroupInfoDTO.getId(), user.getUserId()); + } + + Provider provider; + if (crossDs) { + provider = ProviderFactory.getDefaultProvider(); + } else { + provider = ProviderFactory.getProvider(dsList.getFirst()); + } + + // build query sql + SQLMeta sqlMeta = new SQLMeta(); + Table2SQLObj.table2sqlobj(sqlMeta, null, "(" + sql + ")", crossDs); + Field2SQLObj.field2sqlObj(sqlMeta, fields, fields, crossDs, dsMap, Utils.getParams(fields), null, pluginManage); + WhereTree2Str.transFilterTrees(sqlMeta, rowPermissionsTree, fields, crossDs, dsMap, Utils.getParams(fields), null, pluginManage); + Order2SQLObj.getOrders(sqlMeta, datasetGroupInfoDTO.getSortFields(), fields, crossDs, dsMap, Utils.getParams(fields), null, pluginManage); + String replaceSql = provider.rebuildSQL(SQLProvider.createQuerySQL(sqlMeta, false, false, false), sqlMeta, crossDs, dsMap); + return getDatasetTotal(datasetGroupInfoDTO, replaceSql, null); + } + public Long getDatasetTotal(DatasetGroupInfoDTO datasetGroupInfoDTO, String s, ChartExtRequest request) throws Exception { Map sqlMap = datasetSQLManage.getUnionSQLForEdit(datasetGroupInfoDTO, request); Map dsMap = (Map) sqlMap.get("dsMap"); diff --git a/core/core-backend/src/main/java/io/dataease/dataset/server/DatasetDataServer.java b/core/core-backend/src/main/java/io/dataease/dataset/server/DatasetDataServer.java index f24e6b6a6d..e1ce9ff994 100644 --- a/core/core-backend/src/main/java/io/dataease/dataset/server/DatasetDataServer.java +++ b/core/core-backend/src/main/java/io/dataease/dataset/server/DatasetDataServer.java @@ -73,6 +73,11 @@ public class DatasetDataServer implements DatasetDataApi { return datasetDataManage.getDatasetTotal(datasetGroupInfoDTO.getId()); } + @Override + public Long getDatasetTotal(DatasetGroupInfoDTO datasetGroupInfoDTO) throws Exception { + return datasetDataManage.getDatasetCountWithWhere(datasetGroupInfoDTO.getId()); + } + @Override public List getFieldValueTree(MultFieldValuesRequest multFieldValuesRequest) throws Exception { try { diff --git a/core/core-frontend/src/api/dataset.ts b/core/core-frontend/src/api/dataset.ts index 68defbb30b..fe8c87b3db 100644 --- a/core/core-frontend/src/api/dataset.ts +++ b/core/core-frontend/src/api/dataset.ts @@ -172,6 +172,12 @@ export const getDatasetPreview = async (id): Promise => { }) } +export const getDatasetTotal = async (id): Promise => { + return request.post({ url: `/datasetData/getDatasetTotal`, data: { id: id } }).then(res => { + return res?.data + }) +} + export const getDatasetDetails = async (id): Promise => { return request.post({ url: `/datasetTree/details/${id}`, data: {} }).then(res => { return res?.data diff --git a/core/core-frontend/src/views/visualized/data/dataset/index.vue b/core/core-frontend/src/views/visualized/data/dataset/index.vue index 52604e9c69..2dbba88474 100644 --- a/core/core-frontend/src/views/visualized/data/dataset/index.vue +++ b/core/core-frontend/src/views/visualized/data/dataset/index.vue @@ -38,7 +38,8 @@ import { barInfoApi, perDelete, exportDatasetData, - exportLimit + exportLimit, + getDatasetTotal } from '@/api/dataset' import EmptyBackground from '@/components/empty-background/src/EmptyBackground.vue' import DeResourceGroupOpt from '@/views/common/DeResourceGroupOpt.vue' @@ -313,7 +314,7 @@ onBeforeMount(() => { const columns = shallowRef([]) const tableData = shallowRef([]) -const total = ref(0) +const total = ref(null) const handleNodeClick = (data: BusiTreeNode) => { if (!data.leaf) { @@ -459,11 +460,13 @@ const handleClick = (tabName: TabPaneName) => { dataPreview = (res?.data?.data as Array<{}>) || [] columns.value = columnsPreview tableData.value = dataPreview - total.value = res.total }) .finally(() => { dataPreviewLoading.value = false }) + getDatasetTotal(nodeInfo.id).then(res => { + total.value = res + }) break case 'structPreview': columns.value = allFieldsColumns diff --git a/sdk/api/api-base/src/main/java/io/dataease/api/dataset/DatasetDataApi.java b/sdk/api/api-base/src/main/java/io/dataease/api/dataset/DatasetDataApi.java index c730656e0b..51d4af9221 100644 --- a/sdk/api/api-base/src/main/java/io/dataease/api/dataset/DatasetDataApi.java +++ b/sdk/api/api-base/src/main/java/io/dataease/api/dataset/DatasetDataApi.java @@ -50,6 +50,10 @@ public interface DatasetDataApi { @PostMapping("getDatasetCount") Long getDatasetCount(@RequestBody DatasetGroupInfoDTO datasetGroupInfoDTO) throws Exception; + @Operation(summary = "获取数据集数据量", hidden = true) + @PostMapping("getDatasetTotal") + Long getDatasetTotal(@RequestBody DatasetGroupInfoDTO datasetGroupInfoDTO) throws Exception; + @Operation(summary = "获取下拉树数据", hidden = true) @PostMapping("getFieldTree") List getFieldValueTree(@RequestBody MultFieldValuesRequest multFieldValuesRequest) throws Exception;