<?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.younike.system.mapper.SysUserGroupMapper">

    <resultMap type="SysUserGroup" id="SysUserGroupResult">
        <result property="userId"    column="user_id"    />
        <result property="groupId"    column="group_id"    />
    </resultMap>

    <sql id="selectSysUserGroupVo">
        select user_id, group_id from sys_user_group
    </sql>

    <select id="selectSysUserGroupList" parameterType="SysUserGroup" resultMap="SysUserGroupResult">
        <include refid="selectSysUserGroupVo"/>
        <where>
        </where>
    </select>

    <select id="selectSysUserGroupByUserId" parameterType="Long" resultMap="SysUserGroupResult">
        <include refid="selectSysUserGroupVo"/>
        where user_id = #{userId}
    </select>

    <insert id="insertSysUserGroup" parameterType="com.younike.common.core.domain.entity.SysUserGroup">
        insert into sys_user_group
        <trim prefix="(" suffix=")" suffixOverrides=",">
            <if test="userId != null">user_id,</if>
            <if test="groupId != null">group_id,</if>
         </trim>
        <trim prefix="values (" suffix=")" suffixOverrides=",">
            <if test="userId != null">#{userId},</if>
            <if test="groupId != null">#{groupId},</if>
         </trim>
    </insert>

    <update id="updateSysUserGroup" parameterType="SysUserGroup">
        update sys_user_group
        <trim prefix="SET" suffixOverrides=",">
            <if test="groupId != null">group_id = #{groupId},</if>
        </trim>
        where user_id = #{userId}
    </update>

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

    <delete id="deleteSysUserGroupByUserIds" parameterType="String">
        delete from sys_user_group where user_id in
        <foreach item="userId" collection="array" open="(" separator="," close=")">
            #{userId}
        </foreach>
    </delete>
</mapper>
