diff --git a/backend/src/main/java/io/dataease/controller/sys/RelationController.java b/backend/src/main/java/io/dataease/controller/sys/RelationController.java new file mode 100644 index 0000000000..df53bc7455 --- /dev/null +++ b/backend/src/main/java/io/dataease/controller/sys/RelationController.java @@ -0,0 +1,53 @@ +package io.dataease.controller.sys; + +import com.github.xiaoymin.knife4j.annotations.ApiSupport; +import io.dataease.auth.annotation.DePermission; +import io.dataease.commons.constants.DePermissionType; +import io.dataease.commons.constants.ResourceAuthLevel; +import io.dataease.commons.utils.AuthUtils; +import io.dataease.dto.RelationDTO; +import io.dataease.service.sys.RelationService; +import io.swagger.annotations.Api; +import io.swagger.annotations.ApiOperation; +import org.springframework.web.bind.annotation.*; + +import javax.annotation.Resource; +import java.util.List; + +/** + * @author WiSoniC + * @date 2022年12月8日15:01:05 + */ +@Api(tags = "系统:血缘关系") +@ApiSupport(order = 230) +@RequestMapping("/api/relation") +@RestController +public class RelationController { + + @Resource + private RelationService relationService; + + @DePermission(type = DePermissionType.DATASOURCE, level = ResourceAuthLevel.DATASOURCE_LEVEL_USE,value = "datasourceId") + @ApiOperation("获取指定数据库的血源关系") + @GetMapping("/datasource/{datasourceId}") + public List getRelationForDatasource(@PathVariable String datasourceId) { + Long userId = AuthUtils.getUser().getUserId(); + return relationService.getRelationForDatasource(datasourceId, userId); + } + + @DePermission(type = DePermissionType.DATASET, level = ResourceAuthLevel.DATASET_LEVEL_USE,value = "datasetId") + @ApiOperation("获取指定数据集的血缘关系") + @GetMapping("/dataset/{datasetId}") + public RelationDTO getRelationForDataset(@PathVariable String datasetId) { + Long userId = AuthUtils.getUser().getUserId(); + return relationService.getRelationForDataset(datasetId, userId); + } + + @DePermission(type = DePermissionType.PANEL, level = ResourceAuthLevel.PANEL_LEVEL_VIEW,value = "panelId") + @ApiOperation("获取指定仪表板的血源关系") + @GetMapping("/panel/{panelId}") + public List getRelationForPanel(@PathVariable String panelId) { + Long userId = AuthUtils.getUser().getUserId(); + return relationService.getRelationForPanel(panelId, userId); + } +} diff --git a/backend/src/main/java/io/dataease/dto/RelationDTO.java b/backend/src/main/java/io/dataease/dto/RelationDTO.java new file mode 100644 index 0000000000..cb417f6f0f --- /dev/null +++ b/backend/src/main/java/io/dataease/dto/RelationDTO.java @@ -0,0 +1,26 @@ +package io.dataease.dto; + +import com.fasterxml.jackson.annotation.JsonInclude; +import io.swagger.annotations.ApiModelProperty; +import lombok.Data; + +import java.util.List; + +/** + * @author WiSoniC + * @date 2022年12月8日18:53:10 + */ +@Data +public class RelationDTO { + @ApiModelProperty("ID") + private String id; + @ApiModelProperty("名称") + private String name; + @ApiModelProperty("权限信息") + private String auths; + @ApiModelProperty("类型") + private String type; + @ApiModelProperty("被引用信息") + @JsonInclude(JsonInclude.Include.NON_EMPTY) + private List subRelation; +} diff --git a/backend/src/main/java/io/dataease/ext/ExtDataSetTableMapper.java b/backend/src/main/java/io/dataease/ext/ExtDataSetTableMapper.java index 4c6684cbcd..9690db0954 100644 --- a/backend/src/main/java/io/dataease/ext/ExtDataSetTableMapper.java +++ b/backend/src/main/java/io/dataease/ext/ExtDataSetTableMapper.java @@ -1,6 +1,7 @@ package io.dataease.ext; import io.dataease.controller.request.dataset.DataSetTableRequest; +import io.dataease.dto.RelationDTO; import io.dataease.dto.dataset.DataSetTableDTO; import io.dataease.plugins.common.base.domain.DatasetTable; import org.apache.ibatis.annotations.Param; @@ -20,4 +21,6 @@ public interface ExtDataSetTableMapper { List findByTableIds(@Param("tableIds") List tableIds); + RelationDTO queryDatasetRelation(@Param("datasetId") String datasetId, @Param("userId")Long userId); + } diff --git a/backend/src/main/java/io/dataease/ext/ExtDataSetTableMapper.xml b/backend/src/main/java/io/dataease/ext/ExtDataSetTableMapper.xml index 38440ec0c7..b51d1e3d16 100644 --- a/backend/src/main/java/io/dataease/ext/ExtDataSetTableMapper.xml +++ b/backend/src/main/java/io/dataease/ext/ExtDataSetTableMapper.xml @@ -156,4 +156,84 @@ #{item} + + diff --git a/backend/src/main/java/io/dataease/ext/ExtDataSourceMapper.java b/backend/src/main/java/io/dataease/ext/ExtDataSourceMapper.java index 18e91bf687..f3ca151aa7 100644 --- a/backend/src/main/java/io/dataease/ext/ExtDataSourceMapper.java +++ b/backend/src/main/java/io/dataease/ext/ExtDataSourceMapper.java @@ -1,6 +1,7 @@ package io.dataease.ext; import io.dataease.controller.request.DatasourceUnionRequest; +import io.dataease.dto.RelationDTO; import io.dataease.dto.DatasourceDTO; import io.dataease.ext.query.GridExample; import org.apache.ibatis.annotations.Param; @@ -19,5 +20,5 @@ public interface ExtDataSourceMapper { DatasourceDTO queryDetails(@Param("datasourceId") String datasourceId, @Param("userId") String userId); - + List queryDatasourceRelation(@Param("datasourceId") String datasourceId, @Param("userId")Long userId); } diff --git a/backend/src/main/java/io/dataease/ext/ExtDataSourceMapper.xml b/backend/src/main/java/io/dataease/ext/ExtDataSourceMapper.xml index 782da6288a..e20645682e 100644 --- a/backend/src/main/java/io/dataease/ext/ExtDataSourceMapper.xml +++ b/backend/src/main/java/io/dataease/ext/ExtDataSourceMapper.xml @@ -6,6 +6,17 @@ extends="io.dataease.plugins.common.base.mapper.DatasourceMapper.ResultMapWithBLOBs"> + + + + + + + + + + + - + diff --git a/backend/src/main/java/io/dataease/ext/ExtPanelGroupMapper.java b/backend/src/main/java/io/dataease/ext/ExtPanelGroupMapper.java index e75ce9a805..68d10de928 100644 --- a/backend/src/main/java/io/dataease/ext/ExtPanelGroupMapper.java +++ b/backend/src/main/java/io/dataease/ext/ExtPanelGroupMapper.java @@ -1,6 +1,7 @@ package io.dataease.ext; import io.dataease.controller.request.panel.PanelGroupRequest; +import io.dataease.dto.RelationDTO; import io.dataease.dto.panel.PanelGroupDTO; import org.apache.ibatis.annotations.Param; @@ -28,6 +29,5 @@ public interface ExtPanelGroupMapper { List panelGroupInit(); - - + List queryPanelRelation(@Param("panelId") String panelId, @Param("userId") Long userId); } diff --git a/backend/src/main/java/io/dataease/ext/ExtPanelGroupMapper.xml b/backend/src/main/java/io/dataease/ext/ExtPanelGroupMapper.xml index 1354bc5b56..d172a7e8f4 100644 --- a/backend/src/main/java/io/dataease/ext/ExtPanelGroupMapper.xml +++ b/backend/src/main/java/io/dataease/ext/ExtPanelGroupMapper.xml @@ -14,6 +14,18 @@ + + + + + + + + + + + + + select + ds.id, + ds.name, + ds_auth.auths, + 'link' `type`, + dt.id dt_id, + dt.name dt_name, + dt_auth.auths dt_auths, + if(dt.id is not null,'dataset',null) dt_type + from + panel_group pg + join + chart_view cv on cv.scene_id = pg.id + join + dataset_table dt on cv.table_id = dt.id + left join + ( + select + t_dt.id,group_concat(distinct sad.privilege_type) auths + from + dataset_table t_dt + left join sys_auth sa on sa.auth_source = t_dt.id + left join sys_auth_detail sad on sa.id = sad.auth_id + where + sa.auth_source_type = 'dataset' + and + sad.privilege_value = 1 + and + ( + ( + sa.auth_target_type = 'dept' + AND sa.auth_target in ( SELECT dept_id FROM sys_user WHERE user_id = #{userId,jdbcType=BIGINT} ) + ) + or + ( + sa.auth_target_type = 'user' + AND sa.auth_target = #{userId,jdbcType=BIGINT} + ) + or + ( + sa.auth_target_type = 'role' + AND sa.auth_target in ( SELECT role_id FROM sys_users_roles WHERE user_id = #{userId,jdbcType=BIGINT} ) + ) + ) + group by sa.auth_source + ) dt_auth on dt.id = dt_auth.id + join datasource ds on dt.data_source_id = ds.id + left join + ( + select + t_pg.id,group_concat(distinct sad.privilege_type) auths + from + panel_group t_pg + left join sys_auth sa on sa.auth_source = t_pg.id + left join sys_auth_detail sad on sa.id = sad.auth_id + where + sa.auth_source_type = 'link' + and + sad.privilege_value = 1 + and + ( + ( + sa.auth_target_type = 'dept' + AND sa.auth_target in ( SELECT dept_id FROM sys_user WHERE user_id = #{userId,jdbcType=BIGINT} ) + ) + OR + ( + sa.auth_target_type = 'user' + AND sa.auth_target = #{userId,jdbcType=BIGINT} + ) + OR + ( + sa.auth_target_type = 'role' + AND sa.auth_target in ( SELECT role_id FROM sys_users_roles WHERE user_id = #{userId,jdbcType=BIGINT} ) + ) + ) + group by sa.auth_source + ) ds_auth on ds_auth.id = ds.id + where pg.id=#{panelId,jdbcType=VARCHAR} + group by dt.id + diff --git a/backend/src/main/java/io/dataease/service/sys/RelationService.java b/backend/src/main/java/io/dataease/service/sys/RelationService.java new file mode 100644 index 0000000000..b4d425fa84 --- /dev/null +++ b/backend/src/main/java/io/dataease/service/sys/RelationService.java @@ -0,0 +1,40 @@ +package io.dataease.service.sys; + +import io.dataease.dto.RelationDTO; +import io.dataease.ext.ExtDataSetTableMapper; +import io.dataease.ext.ExtDataSourceMapper; +import io.dataease.ext.ExtPanelGroupMapper; +import org.springframework.stereotype.Service; + +import javax.annotation.Resource; +import java.util.List; + +/** + * @author WiSoniC + * @date 2022年12月8日15:17:17 + */ +@Service +public class RelationService { + + @Resource + private ExtDataSourceMapper extDataSourceMapper; + + @Resource + private ExtDataSetTableMapper extDataSetTableMapper; + + @Resource + private ExtPanelGroupMapper extPanelGroupMapper; + + public List getRelationForDatasource(String datasourceId, Long userId) { + return extDataSourceMapper.queryDatasourceRelation(datasourceId, userId); + } + + public RelationDTO getRelationForDataset(String datasetId, Long userId) { + return extDataSetTableMapper.queryDatasetRelation(datasetId, userId); + } + + public List getRelationForPanel(String panelId, Long userId) { + return extPanelGroupMapper.queryPanelRelation(panelId, userId); + } + +}