<?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.qiaoba.module.system.mapper.SysUserPostMapper">

    <select id="selectPostIdsByUserId" resultType="string">
        select post_id from sys_user_post where user_id = #{userId}
    </select>

    <select id="selectPostNamesByUserId" resultType="string">
        select t2.post_name
        from sys_user_post t1
        left join sys_post t2 on t1.post_id = t2.post_id
        where t1.user_id = #{userId}
        order by t2.post_sort asc
    </select>

    <select id="selectUsedPostNameByIds" resultType="string">
        select DISTINCT t1.post_name
        from sys_post t1
        LEFT JOIN sys_user_post t2
        on t1.post_id = t2.post_id
        where t2.post_id in
        <foreach collection="list" item="postId" open="(" separator="," close=")">
            #{postId}
        </foreach>
    </select>

    <delete id="deleteByUserIds">
        delete from sys_user_post where user_id in
        <foreach collection="list" item="userId" open="(" separator="," close=")">
            #{userId}
        </foreach>
    </delete>
</mapper>
