<?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.rwk.system.mapper.RwkAddressBookMapper">
    
    <resultMap type="RwkAddressBook" id="RwkAddressBookResult">
        <result property="id"    column="id"    />
        <result property="bookName"    column="book_name"    />
        <result property="information"    column="information"    />
        <result property="addressGroup"    column="address_group"    />
        <result property="createDate"    column="create_date"    />
        <result property="email"    column="email"    />
        <result property="othersInf"    column="others_inf"    />
    </resultMap>

    <sql id="selectRwkAddressBookVo">
        select id, book_name, information, address_group, create_date, email, others_inf from rwk_address_book
    </sql>

    <select id="selectRwkAddressBookList" parameterType="RwkAddressBook" resultMap="RwkAddressBookResult">
        <include refid="selectRwkAddressBookVo"/>
        <where>  
            <if test="bookName != null  and bookName != ''"> and book_name like concat('%', #{bookName}, '%')</if>
            <if test="information != null  and information != ''"> and information = #{information}</if>
            <if test="addressGroup != null "> and address_group = #{addressGroup}</if>
            <if test="createDate != null "> and create_date = #{createDate}</if>
            <if test="email != null  and email != ''"> and email = #{email}</if>
            <if test="othersInf != null  and othersInf != ''"> and others_inf = #{othersInf}</if>
        </where>
    </select>
    
    <select id="selectRwkAddressBookById" parameterType="Long" resultMap="RwkAddressBookResult">
        <include refid="selectRwkAddressBookVo"/>
        where id = #{id}
    </select>

    <insert id="insertRwkAddressBook" parameterType="RwkAddressBook" useGeneratedKeys="true" keyProperty="id">
        insert into rwk_address_book
        <trim prefix="(" suffix=")" suffixOverrides=",">
            <if test="bookName != null">book_name,</if>
            <if test="information != null">information,</if>
            <if test="addressGroup != null">address_group,</if>
            <if test="createDate != null">create_date,</if>
            <if test="email != null">email,</if>
            <if test="othersInf != null">others_inf,</if>
         </trim>
        <trim prefix="values (" suffix=")" suffixOverrides=",">
            <if test="bookName != null">#{bookName},</if>
            <if test="information != null">#{information},</if>
            <if test="addressGroup != null">#{addressGroup},</if>
            <if test="createDate != null">#{createDate},</if>
            <if test="email != null">#{email},</if>
            <if test="othersInf != null">#{othersInf},</if>
         </trim>
    </insert>

    <update id="updateRwkAddressBook" parameterType="RwkAddressBook">
        update rwk_address_book
        <trim prefix="SET" suffixOverrides=",">
            <if test="bookName != null">book_name = #{bookName},</if>
            <if test="information != null">information = #{information},</if>
            <if test="addressGroup != null">address_group = #{addressGroup},</if>
            <if test="createDate != null">create_date = #{createDate},</if>
            <if test="email != null">email = #{email},</if>
            <if test="othersInf != null">others_inf = #{othersInf},</if>
        </trim>
        where id = #{id}
    </update>

    <delete id="deleteRwkAddressBookById" parameterType="Long">
        delete from rwk_address_book where id = #{id}
    </delete>

    <delete id="deleteRwkAddressBookByIds" parameterType="String">
        delete from rwk_address_book where id in 
        <foreach item="id" collection="array" open="(" separator="," close=")">
            #{id}
        </foreach>
    </delete>

</mapper>