From 6c5b3561e570cf5454a7c1b1d796b2183ee4b4a9 Mon Sep 17 00:00:00 2001 From: wisonic-s Date: Thu, 7 Dec 2023 16:50:04 +0800 Subject: [PATCH] =?UTF-8?q?fix:=20=E6=9F=A5=E8=AF=A2=E7=BB=84=E4=BB=B6?= =?UTF-8?q?=E5=8E=BB=E9=99=A4=E5=8C=85=E5=90=AB=E5=88=97=E6=9D=83=E9=99=90?= =?UTF-8?q?=E8=84=B1=E6=95=8F=E5=92=8C=E7=A6=81=E7=94=A8=E7=9A=84=E5=88=97?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../dataset/manage/DatasetGroupManage.java | 22 +++++++++++++++++++ .../manage/DatasetTableFieldManage.java | 21 +++++++++++++++--- .../dataset/server/DatasetFieldServer.java | 5 +++++ .../dataset/server/DatasetTreeServer.java | 6 +++++ core/core-frontend/src/api/dataset.ts | 9 ++++++++ .../v-query/QueryConditionConfiguration.vue | 14 +++++------- .../dataease/api/dataset/DatasetTableApi.java | 4 ++++ .../dataease/api/dataset/DatasetTreeApi.java | 3 +++ 8 files changed, 72 insertions(+), 12 deletions(-) diff --git a/core/core-backend/src/main/java/io/dataease/dataset/manage/DatasetGroupManage.java b/core/core-backend/src/main/java/io/dataease/dataset/manage/DatasetGroupManage.java index eb8906f0aa..beae6d17b6 100644 --- a/core/core-backend/src/main/java/io/dataease/dataset/manage/DatasetGroupManage.java +++ b/core/core-backend/src/main/java/io/dataease/dataset/manage/DatasetGroupManage.java @@ -498,4 +498,26 @@ public class DatasetGroupManage { geFullName(parent.getPid(), fullName); } } + + public List getDetailWithPerm(List ids) { + var result = new ArrayList(); + if (CollectionUtil.isNotEmpty(ids)) { + var dsList = coreDatasetGroupMapper.selectBatchIds(ids); + if (CollectionUtil.isNotEmpty(dsList)) { + dsList.forEach(ds -> { + DatasetTableDTO dto = new DatasetTableDTO(); + BeanUtils.copyBean(dto, ds); + var fields = datasetTableFieldManage.listFieldsWithPermissions(ds.getId()); + List dimensionList = fields.stream().filter(ele -> StringUtils.equalsIgnoreCase(ele.getGroupType(), "d")).toList(); + List quotaList = fields.stream().filter(ele -> StringUtils.equalsIgnoreCase(ele.getGroupType(), "q")).toList(); + Map> map = new LinkedHashMap<>(); + map.put("dimensionList", dimensionList); + map.put("quotaList", quotaList); + dto.setFields(map); + result.add(dto); + }); + } + } + return result; + } } diff --git a/core/core-backend/src/main/java/io/dataease/dataset/manage/DatasetTableFieldManage.java b/core/core-backend/src/main/java/io/dataease/dataset/manage/DatasetTableFieldManage.java index 2531acc95d..4525e2fa15 100644 --- a/core/core-backend/src/main/java/io/dataease/dataset/manage/DatasetTableFieldManage.java +++ b/core/core-backend/src/main/java/io/dataease/dataset/manage/DatasetTableFieldManage.java @@ -1,6 +1,9 @@ package io.dataease.dataset.manage; +import cn.hutool.core.collection.CollUtil; import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; +import io.dataease.api.chart.dto.ColumnPermissionItem; +import io.dataease.auth.bo.TokenUserBO; import io.dataease.dataset.dao.auto.entity.CoreDatasetTableField; import io.dataease.dataset.dao.auto.mapper.CoreDatasetGroupMapper; import io.dataease.dataset.dao.auto.mapper.CoreDatasetTableFieldMapper; @@ -9,6 +12,7 @@ import io.dataease.datasource.provider.CalciteProvider; import io.dataease.dto.dataset.DatasetTableFieldDTO; import io.dataease.exception.DEException; import io.dataease.i18n.Translator; +import io.dataease.utils.AuthUtils; import io.dataease.utils.BeanUtils; import io.dataease.utils.IDUtils; import jakarta.annotation.Resource; @@ -18,9 +22,7 @@ import org.springframework.stereotype.Component; import org.springframework.transaction.annotation.Transactional; import org.springframework.util.CollectionUtils; -import java.util.LinkedHashMap; -import java.util.List; -import java.util.Map; +import java.util.*; import java.util.stream.Collectors; /** @@ -187,6 +189,19 @@ public class DatasetTableFieldManage { return map; } + public List listFieldsWithPermissions(Long id) { + List fields = selectByDatasetGroupId(id); + Map desensitizationList = new HashMap<>(); + Long userId = AuthUtils.getUser() == null ? null : AuthUtils.getUser().getUserId(); + return permissionManage + .filterColumnPermissions(fields, desensitizationList, id, userId) + .stream() + .filter(o -> !desensitizationList.containsKey(o.getDataeaseName())) + .sorted(Comparator.comparing(DatasetTableFieldDTO::getGroupType)) + .toList(); + } + + public List transDTO(List list) { return list.stream().map(ele -> { DatasetTableFieldDTO dto = new DatasetTableFieldDTO(); diff --git a/core/core-backend/src/main/java/io/dataease/dataset/server/DatasetFieldServer.java b/core/core-backend/src/main/java/io/dataease/dataset/server/DatasetFieldServer.java index 874451e7d2..652014ce82 100644 --- a/core/core-backend/src/main/java/io/dataease/dataset/server/DatasetFieldServer.java +++ b/core/core-backend/src/main/java/io/dataease/dataset/server/DatasetFieldServer.java @@ -53,6 +53,11 @@ public class DatasetFieldServer implements DatasetTableApi { return datasetTableFieldManage.listByDQ(id); } + @Override + public List listFieldsWithPermissions(Long id) { + return datasetTableFieldManage.listFieldsWithPermissions(id); + } + @Override public List multFieldValuesForPermissions(@RequestBody MultFieldValuesRequest multFieldValuesRequest) throws Exception { return datasetDataManage.getFieldEnum(multFieldValuesRequest.getFieldIds()); diff --git a/core/core-backend/src/main/java/io/dataease/dataset/server/DatasetTreeServer.java b/core/core-backend/src/main/java/io/dataease/dataset/server/DatasetTreeServer.java index a5eed1544e..de5c71fe4a 100644 --- a/core/core-backend/src/main/java/io/dataease/dataset/server/DatasetTreeServer.java +++ b/core/core-backend/src/main/java/io/dataease/dataset/server/DatasetTreeServer.java @@ -77,4 +77,10 @@ public class DatasetTreeServer implements DatasetTreeApi { public List getSqlParams(List ids) throws Exception { return datasetGroupManage.getSqlParams(ids); } + + @Override + public List detailWithPerm(List ids) throws Exception { + return datasetGroupManage.getDetailWithPerm(ids); + } + } diff --git a/core/core-frontend/src/api/dataset.ts b/core/core-frontend/src/api/dataset.ts index 616ad68a78..27f6b3060b 100644 --- a/core/core-frontend/src/api/dataset.ts +++ b/core/core-frontend/src/api/dataset.ts @@ -154,6 +154,11 @@ export const getDsDetails = async (data): Promise => { return res?.data }) } +export const getDsDetailsWithPerm = async (data): Promise => { + return request.post({ url: '/datasetTree/detailWithPerm', data }).then(res => { + return res?.data + }) +} export const getSqlParams = async (data): Promise => { return request.post({ url: '/datasetTree/getSqlParams', data }).then(res => { return res?.data @@ -175,6 +180,10 @@ export const multFieldValuesForPermissions = (data = {}) => { return request.post({ url: '/datasetField/multFieldValuesForPermissions', data }) } +export const listFieldsWithPermissions = (datasetId: number) => { + return request.get({ url: '/datasetField/listWithPermissions/' + datasetId }) +} + export const saveRowPermission = (data = {}) => { return request.post({ url: '/dataset/rowPermissions/save', data }) } diff --git a/core/core-frontend/src/custom-component/v-query/QueryConditionConfiguration.vue b/core/core-frontend/src/custom-component/v-query/QueryConditionConfiguration.vue index f1755b4c90..94a84ca605 100644 --- a/core/core-frontend/src/custom-component/v-query/QueryConditionConfiguration.vue +++ b/core/core-frontend/src/custom-component/v-query/QueryConditionConfiguration.vue @@ -7,7 +7,7 @@ import { useI18n } from '@/hooks/web/useI18n' import { fieldType } from '@/utils/attr' import { ElMessage } from 'element-plus-secondary' import type { DatasetDetail } from '@/api/dataset' -import { getDsDetails, getSqlParams } from '@/api/dataset' +import { getDsDetailsWithPerm, getSqlParams, listFieldsWithPermissions } from '@/api/dataset' import EmptyBackground from '@/components/empty-background/src/EmptyBackground.vue' import { cloneDeep } from 'lodash-es' import Select from './Select.vue' @@ -391,7 +391,7 @@ const init = (queryId: string) => { } const params = [...new Set(datasetFieldList.value.map(ele => ele.tableId).filter(ele => !!ele))] if (!params.length) return - getDsDetails(params) + getDsDetailsWithPerm(params) .then(res => { res .filter(ele => !!ele) @@ -438,7 +438,7 @@ const handleCondition = item => { curComponent.value = conditions.value.find(ele => ele.id === item.id) multiple.value = curComponent.value.multiple - if (!curComponent.value.dataset.fields.length) { + if (!curComponent.value.dataset.fields.length && curComponent.value.dataset.id) { getOptions(curComponent.value.dataset.id, curComponent.value) } datasetFieldList.value.forEach(ele => { @@ -468,12 +468,8 @@ const handleCondition = item => { } const getOptions = (id, component) => { - getDsDetails([id]).then(res => { - res.forEach(ele => { - if (!ele) return - const { dimensionList, quotaList } = ele.fields - component.dataset.fields = [...dimensionList, ...quotaList] - }) + listFieldsWithPermissions(id).then(res => { + component.dataset.fields = res.data }) } diff --git a/sdk/api/api-base/src/main/java/io/dataease/api/dataset/DatasetTableApi.java b/sdk/api/api-base/src/main/java/io/dataease/api/dataset/DatasetTableApi.java index d484428c8b..940834e8ca 100644 --- a/sdk/api/api-base/src/main/java/io/dataease/api/dataset/DatasetTableApi.java +++ b/sdk/api/api-base/src/main/java/io/dataease/api/dataset/DatasetTableApi.java @@ -3,6 +3,7 @@ package io.dataease.api.dataset; import io.dataease.api.dataset.dto.MultFieldValuesRequest; import io.dataease.api.dataset.engine.SQLFunctionDTO; import io.dataease.dto.dataset.DatasetTableFieldDTO; +import org.springframework.web.bind.annotation.GetMapping; import org.springframework.web.bind.annotation.PathVariable; import org.springframework.web.bind.annotation.PostMapping; import org.springframework.web.bind.annotation.RequestBody; @@ -37,6 +38,9 @@ public interface DatasetTableApi { @PostMapping("listByDQ/{id}") Map> listByDQ(@PathVariable Long id); + @GetMapping ("listWithPermissions/{id}") + List listFieldsWithPermissions(@PathVariable Long id); + @PostMapping("multFieldValuesForPermissions") List multFieldValuesForPermissions(@RequestBody MultFieldValuesRequest multFieldValuesRequest) throws Exception; diff --git a/sdk/api/api-base/src/main/java/io/dataease/api/dataset/DatasetTreeApi.java b/sdk/api/api-base/src/main/java/io/dataease/api/dataset/DatasetTreeApi.java index 1c85ceef2a..083f0f4081 100644 --- a/sdk/api/api-base/src/main/java/io/dataease/api/dataset/DatasetTreeApi.java +++ b/sdk/api/api-base/src/main/java/io/dataease/api/dataset/DatasetTreeApi.java @@ -72,4 +72,7 @@ public interface DatasetTreeApi { @PostMapping("getSqlParams") List getSqlParams(@RequestBody List ids) throws Exception; + + @PostMapping("detailWithPerm") + List detailWithPerm(@RequestBody List ids) throws Exception; }