<?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.CompanyRoleDeptMapper">
    
    <resultMap type="CompanyRoleDept" id="CompanyRoleDeptResult">
        <result property="roleId"    column="role_id"    />
        <result property="deptId"    column="dept_id"    />
    </resultMap>

    <sql id="selectCompanyRoleDeptVo">
        select role_id, dept_id from company_role_dept
    </sql>

    <select id="selectCompanyRoleDeptList" parameterType="CompanyRoleDept" resultMap="CompanyRoleDeptResult">
        <include refid="selectCompanyRoleDeptVo"/>
        <where>  
        </where>
    </select>
    
    <select id="selectCompanyRoleDeptById" parameterType="Long" resultMap="CompanyRoleDeptResult">
        <include refid="selectCompanyRoleDeptVo"/>
        where role_id = #{roleId}
    </select>
        
    <insert id="insertCompanyRoleDept" parameterType="CompanyRoleDept">
        insert into company_role_dept
        <trim prefix="(" suffix=")" suffixOverrides=",">
            <if test="roleId != null">role_id,</if>
            <if test="deptId != null">dept_id,</if>
         </trim>
        <trim prefix="values (" suffix=")" suffixOverrides=",">
            <if test="roleId != null">#{roleId},</if>
            <if test="deptId != null">#{deptId},</if>
         </trim>
    </insert>

    <update id="updateCompanyRoleDept" parameterType="CompanyRoleDept">
        update company_role_dept
        <trim prefix="SET" suffixOverrides=",">
            <if test="deptId != null">dept_id = #{deptId},</if>
        </trim>
        where role_id = #{roleId}
    </update>

    <delete id="deleteCompanyRoleDeptById" parameterType="Long">
        delete from company_role_dept where role_id = #{roleId}
    </delete>

    <delete id="deleteCompanyRoleDeptByIds" parameterType="String">
        delete from company_role_dept where role_id in 
        <foreach item="roleId" collection="array" open="(" separator="," close=")">
            #{roleId}
        </foreach>
    </delete>
    <insert id="batchRoleDept">
        insert into company_role_dept(role_id, dept_id) values
        <foreach item="item" index="index" collection="list" separator=",">
            (#{item.roleId},#{item.deptId})
        </foreach>
    </insert>
</mapper>