<?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.iamberry.wechat.service.mapper.ThanksGivingMapper">
    <resultMap  id="BaseResultMap" type="ThanksGiving" >
        <result    column="thanks_giving_id"    property="thanksGivingId" />
        <result    column="thanks_giving_phone"    property="thanksGivingPhone" />
        <result    column="thanks_giving_status"    property="thanksGivingStatus" />
        <result    column="thanks_giving_time"    property="thanksGivingTime" />
        <result    column="thanks_giving_open_id"    property="thanksGivingOpenId" />
        <result    column="coupon_item_id"    property="couponItemId" />
    </resultMap>
    <sql    id="Base_List" >
        t.thanks_giving_id,
        t.thanks_giving_phone,
        t.thanks_giving_status,
        t.thanks_giving_time,
        t.thanks_giving_open_id,
        t.coupon_item_id
    </sql>
    <select id="getThanksGivingList" resultMap="BaseResultMap" parameterType="ThanksGiving" >
        select
        <include refid="Base_List" />
        from tb_iamberry_thanks_giving t
        <where>
            <if test="thanksGivingId != null ">
                AND t.thanks_giving_id = #{thanksGivingId}
            </if >
            <if test="thanksGivingPhone != null and thanksGivingPhone != ''">
                AND t.thanks_giving_phone = #{thanksGivingPhone}
            </if >
            <if test="thanksGivingStatus != null ">
                AND t.thanks_giving_status = #{thanksGivingStatus}
            </if >
            <if test="thanksGivingOpenId != null and thanksGivingOpenId != ''">
                AND t.thanks_giving_open_id = #{thanksGivingOpenId}
            </if >
            <if test="couponItemId != null and couponItemId != ''">
                AND t.coupon_item_id = #{couponItemId}
            </if >
        </where>
    </select>
    <select id="getThanksGivingById" resultMap="BaseResultMap" parameterType="Integer" >
        select
        <include refid="Base_List" />
        from tb_iamberry_thanks_giving t
        where t.thanks_giving_id= #{thanksGivingId}
    </select>

    <select id="getThanksGivingByPhone" resultMap="BaseResultMap" parameterType="String" >
        select
        <include refid="Base_List" />
        from tb_iamberry_thanks_giving t
        where  t.thanks_giving_phone = #{thanksGivingPhone}
    </select>

    <insert id="save" parameterType="ThanksGiving" >
        insert into
        tb_iamberry_thanks_giving
        (
        thanks_giving_phone,
        thanks_giving_status,
        thanks_giving_time,
        thanks_giving_open_id,
        thanks_giving_name,
        coupon_item_id
        )
        values
        (
        #{thanksGivingPhone},
        #{thanksGivingStatus},
        #{thanksGivingTime},
        #{thanksGivingOpenId},
        #{thanksGivingName},
        #{couponItemId}
        )
    </insert>
    <update id="update" parameterType="ThanksGiving" >
        update
        tb_iamberry_thanks_giving
        <set >
            <if test="thanksGivingPhone != null and thanksGivingPhone != ''">
                thanks_giving_phone = #{thanksGivingPhone},
            </if >
            <if test="thanksGivingStatus != null ">
                thanks_giving_status = #{thanksGivingStatus},
            </if >
            <if test="thanksGivingTime != null and thanksGivingTime != ''">
                thanks_giving_time = #{thanksGivingTime},
            </if >
            <if test="thanksGivingOpenId != null and thanksGivingOpenId != ''">
                thanks_giving_open_id = #{thanksGivingOpenId},
            </if >
            <if test="couponItemId != null and couponItemId != ''">
                coupon_item_id = #{couponItemId}
            </if >
        </set >
        where thanks_giving_id= #{thanksGivingId}
    </update>
</mapper>