<?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.boman.system.mapper.BomanGroupUserMapper">

    <resultMap type="com.boman.domain.BomanGroupUser" id="BomanGroupUserResult">
        <id property="id" column="id"/>
        <result property="userId" column="user_id"/>
        <result property="userName" column="user_name"/>
        <result property="groupId" column="group_id"/>
        <result property="status" column="status"/>
        <result property="createBy" column="create_by"/>
        <result property="createTime" column="create_time"/>
        <result property="updateBy" column="update_by"/>
        <result property="updateTime" column="update_time"/>
        <result property="isDel" column="is_del"/>
    </resultMap>


    <sql id="selectGroupUserVo">
        select g.id, g.user_id, g.user_name,  g.group_id, g.status, g.create_by, g.create_time, g.update_by, g.update_time, g.is_del
        from boman_group_user g
    </sql>

    <select id="selectGroupUserList" parameterType="Long" resultType="java.lang.Long">
        select user_id from boman_group_user
        where group_id = #{groupId} and is_del = 'N'
    </select>

    <update id="deleteGroupUser" parameterType="Long">
        update  boman_group_user set is_del = 'Y' where user_id in
        <foreach collection="userIds"  item="id" open="(" separator="," close=")">
            #{id}
        </foreach>
        and group_id = #{groupId}
    </update>

    <insert id="insertUserGroup" parameterType="com.boman.domain.BomanGroupUser">
        insert into boman_group_user(
        user_id,
        user_name,
        group_id,
        create_by,
        create_time
        )values
        <foreach collection ="bomanGroupUserList" item="bomanGroupUser" index= "index" separator =",">
         (
            <if test="bomanGroupUser.userId != null">#{bomanGroupUser.userId},</if>
            <if test="bomanGroupUser.userName != null and bomanGroupUser.userName != ''">#{bomanGroupUser.userName},</if>
            <if test="bomanGroupUser.groupId != null">#{bomanGroupUser.groupId},</if>
            <if test="bomanGroupUser.createBy != null and bomanGroupUser.createBy != ''">#{bomanGroupUser.createBy},</if>
            sysdate()
                         )
        </foreach >

    </insert>
</mapper> 