<?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="cn.fateverse.admin.mapper.UserPostMapper">


    <insert id="batchInsert">
        insert into sys_user_post (user_id, post_id) VALUES
        <foreach collection="list" separator="," item="userPost">
            (#{userPost.userId},#{userPost.postId})
        </foreach>
    </insert>
    
    <delete id="deleteByUserId">
        delete from sys_user_post where user_id = #{userId}
    </delete>
    
    <delete id="removeBind">
        delete from sys_user_post where post_id = #{postId}
        and user_id in
        <foreach collection="userIds" item="userId" open="(" separator="," close=")">
            #{userId}
        </foreach>
    </delete>

    <delete id="removeBindByPostId">
        delete from sys_user_post where post_id = #{postId}
    </delete>

    <select id="selectPostIdListByUserId" resultType="java.lang.Long">
        select post_id from sys_user_post where user_id = #{userId}
    </select>
</mapper>