<?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.hzs.system.sys.mapper.SysUserVertexMapper">

    <!-- 通用查询映射结果 -->
    <resultMap id="BaseResultMap" type="com.hzs.common.domain.system.sys.SysUserVertex">
        <result column="USER_ID" property="userId"/>
        <result column="PK_VERTEX" property="pkVertex"/>
    </resultMap>

    <!-- 批量新增用户查询体系信息 -->
    <insert id="insertUserVertexBatch">
        INSERT ALL
        <foreach collection="list" item="item" separator=" ">
            into sys_user_vertex(user_id, pk_vertex)
            values
            (#{item.userId},#{item.pkVertex})
        </foreach>
        SELECT 1 FROM dual
    </insert>

    <!-- 通过用户ID删除用户和体系关联 -->
    <delete id="deleteUserVertexByUserId">
        delete
        from sys_user_vertex
        where user_id = #{userId}
    </delete>

    <!-- 通过管理员ID查询体系会员列表 -->
    <select id="queryVertexByUser" resultMap="BaseResultMap">
        select bv.pk_member user_id, bv.pk_id pk_vertex
        from SYS_USER_VERTEX suv
                 inner join BD_VERTEX bv
                            on bv.pk_id = suv.pk_vertex
                                and bv.del_flag = 0
        where suv.user_id = #{userId}
        order by suv.pk_vertex
    </select>

</mapper>
