<?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="com.iflytek.astron.console.toolkit.mapper.group.GroupVisibilityMapper">

    <select id="getRepoVisibilityList" resultType="com.iflytek.astron.console.toolkit.entity.table.group.GroupVisibility">
        select gv.* from group_visibility gv left join repo r on gv.relation_id = r.id
        where gv.`type` = 1 and r.visibility = 1 and
        <if test="spaceId != null">
            gv.space_id = #{spaceId}
        </if>
        <if test="spaceId == null">
            gv.user_id = #{uid}
        </if>
    </select>
    <select id="listUser" resultType="com.iflytek.astron.console.toolkit.entity.vo.group.GroupUserTagVO">
        select s.id as uid, s.login, s.nickname, s.email from group_visibility t1 left join system_user s on t1.user_id = s.id
        where t1.uid = #{uid} and type = #{type} and relation_id = #{id}
    </select>
    <select id="getToolVisibilityList" resultType="com.iflytek.astron.console.toolkit.entity.table.group.GroupVisibility">
        select gv.* from group_visibility gv left join tool_box tb on gv.relation_id = tb.id
        where gv.`type` = 2 and tb.visibility = 1 and gv.user_id = #{uid}
    </select>
    <select id="getSquareToolVisibilityList" resultType="com.iflytek.astron.console.toolkit.entity.table.group.GroupVisibility">
        select
        gv.*
        from
        group_visibility gv
        left join tool_box tb on
        gv.relation_id = tb.id
        <where>
            gv.`type` = 2
            and tb.visibility = 1
            and gv.user_id =
            #{uid} and tb.is_public = 1;
        </where>
    </select>
</mapper>
