<?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.fs.company.mapper.CompanyUserPostMapper">
    
    <resultMap type="CompanyUserPost" id="CompanyUserPostResult">
        <result property="userId"    column="user_id"    />
        <result property="postId"    column="post_id"    />
    </resultMap>

    <sql id="selectCompanyUserPostVo">
        select user_id, post_id from company_user_post
    </sql>

    <select id="selectCompanyUserPostList" parameterType="CompanyUserPost" resultMap="CompanyUserPostResult">
        <include refid="selectCompanyUserPostVo"/>
        <where>  
        </where>
    </select>
    
    <select id="selectCompanyUserPostById" parameterType="Long" resultMap="CompanyUserPostResult">
        <include refid="selectCompanyUserPostVo"/>
        where user_id = #{userId}
    </select>
        
    <insert id="insertCompanyUserPost" parameterType="CompanyUserPost">
        insert into company_user_post
        <trim prefix="(" suffix=")" suffixOverrides=",">
            <if test="userId != null">user_id,</if>
            <if test="postId != null">post_id,</if>
         </trim>
        <trim prefix="values (" suffix=")" suffixOverrides=",">
            <if test="userId != null">#{userId},</if>
            <if test="postId != null">#{postId},</if>
         </trim>
    </insert>

    <update id="updateCompanyUserPost" parameterType="CompanyUserPost">
        update company_user_post
        <trim prefix="SET" suffixOverrides=",">
            <if test="postId != null">post_id = #{postId},</if>
        </trim>
        where user_id = #{userId}
    </update>

    <delete id="deleteCompanyUserPostById" parameterType="Long">
        delete from company_user_post where user_id = #{userId}
    </delete>

    <delete id="deleteCompanyUserPostByIds" parameterType="String">
        delete from company_user_post where user_id in 
        <foreach item="userId" collection="array" open="(" separator="," close=")">
            #{userId}
        </foreach>
    </delete>
    <insert id="batchUserPost">
        insert into company_user_post(user_id, post_id) values
        <foreach item="item" index="index" collection="list" separator=",">
            (#{item.userId},#{item.postId})
        </foreach>
    </insert>

    <delete id="deleteUserPostByUserId" parameterType="Long">
		delete from company_user_post where user_id=#{userId}
	</delete>
</mapper>