From fea0f3eae0516aeb4781677016760ee3ece1bba1 Mon Sep 17 00:00:00 2001 From: junjun Date: Wed, 14 Aug 2024 16:40:26 +0800 Subject: [PATCH] =?UTF-8?q?feat(=E7=BB=84=E7=BB=87=E7=AE=A1=E7=90=86?= =?UTF-8?q?=E4=B8=AD=E5=BF=83):=20=E6=96=B0=E5=A2=9E=E8=A1=80=E7=BC=98?= =?UTF-8?q?=E5=85=B3=E7=B3=BB=E5=88=86=E6=9E=90?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../dataset/manage/DatasetGroupManage.java | 22 +++++++++++++ .../dataset/server/DatasetTreeServer.java | 5 +++ .../datasource/server/DatasourceServer.java | 20 ++++++++++++ .../engine/constant/SQLConstants.java | 2 ++ .../dataease/api/dataset/DatasetTreeApi.java | 4 +++ .../io/dataease/api/ds/DatasourceApi.java | 4 +++ .../permissions/relation/api/RelationApi.java | 14 +++++++++ .../permissions/relation/dto/RelationDTO.java | 22 +++++++++++++ .../relation/dto/RelationListDTO.java | 31 +++++++++++++++++++ .../java/io/dataease/result/ResultCode.java | 3 ++ 10 files changed, 127 insertions(+) create mode 100644 sdk/api/api-permissions/src/main/java/io/dataease/api/permissions/relation/api/RelationApi.java create mode 100644 sdk/api/api-permissions/src/main/java/io/dataease/api/permissions/relation/dto/RelationDTO.java create mode 100644 sdk/api/api-permissions/src/main/java/io/dataease/api/permissions/relation/dto/RelationListDTO.java 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 024d821ff2..683cb561a6 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 @@ -5,6 +5,7 @@ import com.fasterxml.jackson.core.type.TypeReference; import io.dataease.api.dataset.union.DatasetGroupInfoDTO; import io.dataease.api.dataset.union.UnionDTO; import io.dataease.api.dataset.vo.DataSetBarVO; +import io.dataease.api.permissions.relation.api.RelationApi; import io.dataease.commons.constants.OptConstants; import io.dataease.dataset.dao.auto.entity.CoreDatasetGroup; import io.dataease.dataset.dao.auto.entity.CoreDatasetTable; @@ -35,6 +36,7 @@ import jakarta.annotation.Resource; import org.apache.commons.collections4.CollectionUtils; import org.apache.commons.lang3.ObjectUtils; import org.apache.commons.lang3.StringUtils; +import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Component; import org.springframework.transaction.annotation.Transactional; @@ -43,6 +45,8 @@ import java.util.concurrent.locks.Lock; import java.util.concurrent.locks.ReentrantLock; import java.util.stream.Collectors; +import static io.dataease.result.ResultCode.DV_RESOURCE_UNCHECKED; + /** * @Author Junjun */ @@ -75,6 +79,9 @@ public class DatasetGroupManage { @Resource private CoreOptRecentManage coreOptRecentManage; + @Autowired(required = false) + private RelationApi relationManage; + private static final String leafType = "dataset"; private Lock lock = new ReentrantLock(); @@ -176,6 +183,21 @@ public class DatasetGroupManage { return datasetGroupInfoDTO; } + public boolean perDelete(Long id) { + if (LicenseUtil.licenseValid()) { + try { + relationManage.checkAuth(); + } catch (Exception e) { + return false; + } + Long count = relationManage.getDatasetResource(id); + if (count > 0) { + return true; + } + } + return false; + } + @XpackInteract(value = "authResourceTree", before = false) public void delete(Long id) { CoreDatasetGroup coreDatasetGroup = coreDatasetGroupMapper.selectById(id); 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 05815fd531..3e0f9e8aa9 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 @@ -49,6 +49,11 @@ public class DatasetTreeServer implements DatasetTreeApi { return datasetGroupManage.move(dto); } + @Override + public boolean perDelete(Long id) { + return datasetGroupManage.perDelete(id); + } + @DeLog(id = "#p0", ot = LogOT.DELETE, st = LogST.DATASET) @Override public void delete(Long id) { diff --git a/core/core-backend/src/main/java/io/dataease/datasource/server/DatasourceServer.java b/core/core-backend/src/main/java/io/dataease/datasource/server/DatasourceServer.java index 101a58d36e..0b4d40699b 100644 --- a/core/core-backend/src/main/java/io/dataease/datasource/server/DatasourceServer.java +++ b/core/core-backend/src/main/java/io/dataease/datasource/server/DatasourceServer.java @@ -13,6 +13,7 @@ import io.dataease.api.ds.vo.ApiDefinition; import io.dataease.api.ds.vo.CoreDatasourceTaskLogDTO; import io.dataease.api.ds.vo.ExcelFileData; import io.dataease.api.ds.vo.ExcelSheetData; +import io.dataease.api.permissions.relation.api.RelationApi; import io.dataease.commons.constants.TaskStatus; import io.dataease.constant.LogOT; import io.dataease.constant.LogST; @@ -69,6 +70,7 @@ import java.util.stream.Collectors; import static io.dataease.datasource.server.DatasourceTaskServer.ScheduleType.MANUAL; import static io.dataease.datasource.server.DatasourceTaskServer.ScheduleType.RIGHTNOW; +import static io.dataease.result.ResultCode.DS_RESOURCE_UNCHECKED; @RestController @@ -106,6 +108,8 @@ public class DatasourceServer implements DatasourceApi { @Autowired(required = false) private PluginManageApi pluginManage; + @Autowired(required = false) + private RelationApi relationManage; @Override public List query(String keyWord) { @@ -627,6 +631,22 @@ public class DatasourceServer implements DatasourceApi { return datasourceDTO; } + @Override + public boolean perDelete(Long id) { + if (LicenseUtil.licenseValid()) { + try { + relationManage.checkAuth(); + } catch (Exception e) { + return false; + } + Long count = relationManage.getDsResource(id); + if (count > 0) { + return true; + } + } + return false; + } + @Transactional @DeLog(id = "#p0", ot = LogOT.DELETE, st = LogST.DATASOURCE) @Override 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 28d6395879..e1aa7542dc 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 @@ -94,4 +94,6 @@ public class SQLConstants { public static final String QUARTER = "QUARTER(%s)"; public static final String EMPTY_SIGN = "_empty_$"; + + public static final String CONCAT = "CONCAT(%s, %s)"; } 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 2d4f746357..ccafd39c93 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 @@ -60,6 +60,10 @@ public interface DatasetTreeApi { @PostMapping("move") DatasetNodeDTO move(@RequestBody DatasetGroupInfoDTO dto) throws Exception; + @DePermit({"#p0+':manage'"}) + @PostMapping("perDelete/{id}") + boolean perDelete(@PathVariable("id") Long id); + @Operation(summary = "删除数据集") @DePermit({"#p0+':manage'"}) @PostMapping("delete/{id}") diff --git a/sdk/api/api-base/src/main/java/io/dataease/api/ds/DatasourceApi.java b/sdk/api/api-base/src/main/java/io/dataease/api/ds/DatasourceApi.java index d4dfb17142..b7d5d3a88d 100644 --- a/sdk/api/api-base/src/main/java/io/dataease/api/ds/DatasourceApi.java +++ b/sdk/api/api-base/src/main/java/io/dataease/api/ds/DatasourceApi.java @@ -66,6 +66,10 @@ public interface DatasourceApi { @GetMapping("/validate/{datasourceId}") DatasourceDTO validate(@PathVariable("datasourceId") Long datasourceId) throws DEException; + @DePermit({"#p0+':manage'"}) + @PostMapping("/perDelete/{datasourceId}") + boolean perDelete(@PathVariable("datasourceId") Long datasourceId); + @DePermit({"#p0+':manage'"}) @GetMapping("/delete/{datasourceId}") void delete(@PathVariable("datasourceId") Long datasourceId) throws DEException; diff --git a/sdk/api/api-permissions/src/main/java/io/dataease/api/permissions/relation/api/RelationApi.java b/sdk/api/api-permissions/src/main/java/io/dataease/api/permissions/relation/api/RelationApi.java new file mode 100644 index 0000000000..dd437695f6 --- /dev/null +++ b/sdk/api/api-permissions/src/main/java/io/dataease/api/permissions/relation/api/RelationApi.java @@ -0,0 +1,14 @@ +package io.dataease.api.permissions.relation.api; + +import io.dataease.exception.DEException; + +/** + * @Author Junjun + */ +public interface RelationApi { + Long getDsResource(Long id); + + Long getDatasetResource(Long id); + + void checkAuth() throws DEException; +} diff --git a/sdk/api/api-permissions/src/main/java/io/dataease/api/permissions/relation/dto/RelationDTO.java b/sdk/api/api-permissions/src/main/java/io/dataease/api/permissions/relation/dto/RelationDTO.java new file mode 100644 index 0000000000..53a993c734 --- /dev/null +++ b/sdk/api/api-permissions/src/main/java/io/dataease/api/permissions/relation/dto/RelationDTO.java @@ -0,0 +1,22 @@ +package io.dataease.api.permissions.relation.dto; + +import com.fasterxml.jackson.databind.annotation.JsonSerialize; +import com.fasterxml.jackson.databind.ser.std.ToStringSerializer; +import lombok.Data; + +import java.util.List; + +/** + * @Author Junjun + */ +@Data +public class RelationDTO { + @JsonSerialize(using = ToStringSerializer.class) + private Long id; + private String name; + private String auths; + private String type; + private String creator; + private Long updateTime; + private List subRelation; +} diff --git a/sdk/api/api-permissions/src/main/java/io/dataease/api/permissions/relation/dto/RelationListDTO.java b/sdk/api/api-permissions/src/main/java/io/dataease/api/permissions/relation/dto/RelationListDTO.java new file mode 100644 index 0000000000..e36b2238f7 --- /dev/null +++ b/sdk/api/api-permissions/src/main/java/io/dataease/api/permissions/relation/dto/RelationListDTO.java @@ -0,0 +1,31 @@ +package io.dataease.api.permissions.relation.dto; + +import lombok.Data; + +import java.io.Serializable; + +/** + * @Author Junjun + */ +@Data +public class RelationListDTO implements Serializable { + private Long dsId; + private String dsName; + private String dsCreator; + private Long dsUpdateTime; + + private Long datasetId; + private String datasetName; + private String datasetCreator; + private Long datasetUpdateTime; + + private Long dashboardId; + private String dashboardName; + private String dashboardCreator; + private Long dashboardUpdateTime; + + private Long dvId; + private String dvName; + private String dvCreator; + private Long dvUpdateTime; +} diff --git a/sdk/common/src/main/java/io/dataease/result/ResultCode.java b/sdk/common/src/main/java/io/dataease/result/ResultCode.java index 86ad357993..55e5849b3e 100644 --- a/sdk/common/src/main/java/io/dataease/result/ResultCode.java +++ b/sdk/common/src/main/java/io/dataease/result/ResultCode.java @@ -27,6 +27,9 @@ public enum ResultCode { RESULE_DATA_NONE(50001, "数据未找到"), DATA_IS_WRONG(50002, "数据有误"), DATA_ALREADY_EXISTED(50003, "数据已存在"), + DS_RESOURCE_UNCHECKED(50004, "%s个数据集正在使用此数据源,无法删除"), + + DV_RESOURCE_UNCHECKED(50004, "%s个仪表板或数据大屏正在使用此数据集,无法删除"), /* 接口错误:60001-69999 */ INTERFACE_INNER_INVOKE_ERROR(60001, "内部系统接口调用异常"),