Merge pull request #4146 from dataease/pr@dev@feat_relationship_analyze

Merge branch 'dev' into pr@dev@feat_relationship_analyze
This commit is contained in:
wisonic-s 2022-12-21 12:47:55 +08:00 committed by GitHub
commit 312f4192a1
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
9 changed files with 391 additions and 4 deletions

View File

@ -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<RelationDTO> 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<RelationDTO> getRelationForPanel(@PathVariable String panelId) {
Long userId = AuthUtils.getUser().getUserId();
return relationService.getRelationForPanel(panelId, userId);
}
}

View File

@ -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<RelationDTO> subRelation;
}

View File

@ -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<DatasetTable> findByTableIds(@Param("tableIds") List<String> tableIds);
RelationDTO queryDatasetRelation(@Param("datasetId") String datasetId, @Param("userId")Long userId);
}

View File

@ -156,4 +156,84 @@
#{item}
</foreach>
</select>
<select id="queryDatasetRelation" resultType="io.dataease.dto.RelationDTO" resultMap="io.dataease.ext.ExtDataSourceMapper.RelationResultMap">
select
dt.id,
dt.name,
dt_auth.auths,
'dataset' `type`,
pg.id panel_id,
pg.name panel_name,
pg_auth.auths panel_auths,
if(pg.id is not null,'panel',null) pg_type
from
dataset_table dt
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 = #{datasetId,jdbcType=VARCHAR}
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
left join chart_view cv on cv.table_id = dt.id
left join panel_group pg on cv.scene_id = pg.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 = 'panel'
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
) pg_auth on pg_auth.id = pg.id
where dt.id=#{datasetId,jdbcType=VARCHAR}
order by id
</select>
</mapper>

View File

@ -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<RelationDTO> queryDatasourceRelation(@Param("datasourceId") String datasourceId, @Param("userId")Long userId);
}

View File

@ -6,6 +6,17 @@
extends="io.dataease.plugins.common.base.mapper.DatasourceMapper.ResultMapWithBLOBs">
<result column="privileges" property="privileges"/>
</resultMap>
<resultMap id="RelationResultMap" type="io.dataease.dto.RelationDTO">
<id column="id" property="id"/>
<result column="name" property="name"/>
<result column="auths" property="auths"/>
<collection property="subRelation" ofType="io.dataease.dto.RelationDTO">
<id column="panel_id" property="id"/>
<result column="panel_name" property="name"/>
<result column="panel_auths" property="auths"/>
<result column="pg_type" property="type"/>
</collection>
</resultMap>
<select id="query" parameterType="io.dataease.ext.query.GridExample" resultMap="BaseResultMapDTO">
select datasource.*,
@ -150,5 +161,84 @@
where id = #{datasourceId}
</select>
<select id="queryDatasourceRelation" resultType="io.dataease.dto.RelationDTO" resultMap="RelationResultMap">
select
dt.id,
dt.name,
dt_auth.auths,
'dataset' `type`,
pg.id panel_id,
pg.name panel_name,
pg_auth.auths panel_auths,
if(pg.id is not null,'panel',null) pg_type
from
datasource ds
join dataset_table dt on dt.data_source_id = ds.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
left join chart_view cv on cv.table_id = dt.id
left join panel_group pg on cv.scene_id = pg.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 = 'panel'
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
) pg_auth on pg_auth.id = pg.id
where ds.id=#{datasourceId,jdbcType=VARCHAR}
order by id
</select>
</mapper>

View File

@ -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<PanelGroupDTO> panelGroupInit();
List<RelationDTO> queryPanelRelation(@Param("panelId") String panelId, @Param("userId") Long userId);
}

View File

@ -14,6 +14,18 @@
<result column="is_default" property="isDefault"/>
</resultMap>
<resultMap id="RelationResultMap" type="io.dataease.dto.RelationDTO">
<id column="id" property="id"/>
<result column="name" property="name"/>
<result column="auths" property="auths"/>
<collection property="subRelation" ofType="io.dataease.dto.RelationDTO">
<id column="dt_id" property="id"/>
<result column="dt_name" property="name"/>
<result column="dt_auths" property="auths"/>
<result column="dt_type" property="type"/>
</collection>
</resultMap>
<select id="findOneWithPrivileges" resultMap="BaseResultMapDTO">
select panel_group.*,
panel_group.name as label,
@ -226,4 +238,86 @@
</delete>
<select id="queryPanelRelation" resultType="io.dataease.dto.RelationDTO" resultMap="RelationResultMap">
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
</select>
</mapper>

View File

@ -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<RelationDTO> getRelationForDatasource(String datasourceId, Long userId) {
return extDataSourceMapper.queryDatasourceRelation(datasourceId, userId);
}
public RelationDTO getRelationForDataset(String datasetId, Long userId) {
return extDataSetTableMapper.queryDatasetRelation(datasetId, userId);
}
public List<RelationDTO> getRelationForPanel(String panelId, Long userId) {
return extPanelGroupMapper.queryPanelRelation(panelId, userId);
}
}