<?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.tuoheng.mapper.ClientUserRoleMapper">

    <insert id="batchInsert" parameterType="java.util.List">
        insert into t_client_user_role (user_id, client_id, role_id, create_user,role_name)
        VALUES
        <foreach collection="list" item="it" separator=",">
            (#{it.userId}, #{it.clientId}, #{it.roleId}, #{it.createUser},#{it.roleName})
        </foreach>
    </insert>

    <insert id="insert" parameterType="com.tuoheng.model.po.ClientUserRolePo">
        insert into t_client_user_role (user_id, client_id, role_id, create_user, role_name)
        VALUES (#{userId}, #{clientId}, #{roleId}, #{createUser}, #{roleName})
    </insert>

    <update id="updateUserClientRole" parameterType="com.tuoheng.model.po.ClientUserRolePo">
        update t_client_user_role
        <set>
            <if test="roleId != null">
                role_id = #{roleId},
            </if>
            <if test="updateUser != null">
                update_user = #{updateUser},
            </if>
        </set>
        where user_id = #{userId} and client_id = #{clientId}
    </update>
    <delete id="deleteByUserIdAndClient">
        delete
        from t_client_user_role
        where user_id = #{userId}
          and client_id = #{clientId}
    </delete>
    <select id="selectListByUserId" resultType="com.tuoheng.model.po.ClientUserRolePo">
        SELECT *
        FROM t_client_user_role
        WHERE user_id = #{userId}
    </select>

</mapper>
