de/backend/src/main/java/io/dataease/ext/ExtDataSourceMapper.xml

142 lines
5.0 KiB
XML

<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd" >
<mapper namespace="io.dataease.ext.ExtDataSourceMapper">
<resultMap id="BaseResultMapDTO" type="io.dataease.dto.DatasourceDTO"
extends="io.dataease.plugins.common.base.mapper.DatasourceMapper.ResultMapWithBLOBs">
<result column="privileges" property="privileges"/>
</resultMap>
<select id="query" parameterType="io.dataease.ext.query.GridExample" resultMap="BaseResultMapDTO">
select datasource.*,
authInfo.privileges as `privileges`
from (select GET_V_AUTH_MODEL_ID_P_USE (#{extendCondition}, 'link') cids) t,datasource
left join (
SELECT
auth_source,
group_concat( DISTINCT sys_auth_detail.privilege_extend ) as `privileges`
FROM
(
`sys_auth`
LEFT JOIN `sys_auth_detail` ON ((
`sys_auth`.`id` = `sys_auth_detail`.`auth_id`
)))
WHERE
sys_auth_detail.privilege_value = 1
AND sys_auth.auth_source_type = 'link'
AND (
(
sys_auth.auth_target_type = 'dept'
AND sys_auth.auth_target IN ( SELECT dept_id FROM sys_user WHERE user_id = #{extendCondition} )
)
OR (
sys_auth.auth_target_type = 'user'
AND sys_auth.auth_target = #{extendCondition}
)
OR (
sys_auth.auth_target_type = 'role'
AND sys_auth.auth_target IN ( SELECT role_id FROM sys_users_roles WHERE user_id = #{extendCondition} )
)
)
GROUP BY
`sys_auth`.`auth_source`
) authInfo
on datasource.id = authInfo.auth_source
<if test="_parameter != null">
<include refid="io.dataease.ext.query.GridSql.gridCondition"/>
</if>
and FIND_IN_SET(datasource.id,cids)
<if test="orderByClause != null">
order by ${orderByClause}
</if>
<if test="orderByClause == null">
order by update_time desc
</if>
</select>
<select id="queryUnion" resultMap="BaseResultMapDTO">
select datasource.*,
authInfo.privileges as `privileges`
from (select GET_V_AUTH_MODEL_ID_P_USE (#{userId}, 'link') cids) t,datasource
left join (
SELECT
auth_source,
group_concat( DISTINCT sys_auth_detail.privilege_extend ) as `privileges`
FROM
(
`sys_auth`
LEFT JOIN `sys_auth_detail` ON ((
`sys_auth`.`id` = `sys_auth_detail`.`auth_id`
)))
WHERE
sys_auth_detail.privilege_value = 1
AND sys_auth.auth_source_type = 'link'
AND (
(
sys_auth.auth_target_type = 'dept'
AND sys_auth.auth_target IN ( SELECT dept_id FROM sys_user WHERE user_id = #{userId} )
)
OR (
sys_auth.auth_target_type = 'user'
AND sys_auth.auth_target = #{userId}
)
OR (
sys_auth.auth_target_type = 'role'
AND sys_auth.auth_target IN ( SELECT role_id FROM sys_users_roles WHERE user_id = #{userId} )
)
)
GROUP BY
`sys_auth`.`auth_source`
) authInfo
on datasource.id = authInfo.auth_source
<where>
FIND_IN_SET(datasource.id,cids)
<if test="id != null">
and id = #{id,jdbcType=VARCHAR}
</if>
<if test="name != null">
and `name` like concat('%',#{name,jdbcType=VARCHAR},'%')
</if>
<if test="desc != null">
and `desc` = #{desc,jdbcType=VARCHAR}
</if>
<if test="type != null">
and `type` = #{type,jdbcType=VARCHAR}
</if>
<if test="createTime != null">
and create_time = #{createTime,jdbcType=BIGINT}
</if>
<if test="updateTime != null">
and update_time = #{updateTime,jdbcType=BIGINT}
</if>
<if test="configuration != null">
and configuration = #{configuration,jdbcType=LONGVARCHAR}
</if>
</where>
<if test="sort == null">
order by ${sort}
</if>
</select>
<select id="findByPanelId" resultMap="BaseResultMapDTO">
SELECT DISTINCT datasource.id,
datasource.`name`,
datasource.DESC,
datasource.type
FROM chart_view
INNER JOIN panel_view ON chart_view.id = panel_view.chart_view_id
INNER JOIN dataset_table ON chart_view.table_id = dataset_table.id
INNER JOIN datasource ON dataset_table.data_source_id = datasource.id
WHERE panel_view.panel_id = #{panelId}
</select>
<select id="queryDetails" resultMap="BaseResultMapDTO">
select datasource.*,
get_auths(id, 'link', #{userId}) as `privileges`
from datasource
where id = #{datasourceId}
</select>
</mapper>