<?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.ActivityMapper">
    <resultMap  id="BaseResultMap" type="Activity" >
        <result    column="activity_id"    property="activityId" />
        <result    column="user_open_id"    property="userOpenId" />
        <result    column="activity_all_help"    property="activityAllHelp" />
        <result    column="activity_already_help"    property="activityAlreadyHelp" />
        <result    column="activity_code_img"    property="activityCodeImg" />
        <result    column="activity_img"    property="activityImg" />
        <result    column="activity_status"    property="activityStatus" />
        <result    column="activity_coupon"    property="activityCoupon" />
        <result    column="activity_create_time"    property="activityCreateTime" />
        <result    column="activity_update_time"    property="activityUpdateTime" />
    </resultMap>
    <sql    id="Base_List" >
        t.activity_id,
        t.user_open_id,
        t.activity_all_help,
        t.activity_already_help,
        t.activity_code_img,
        t.activity_img,
        t.activity_status,
        t.activity_coupon,
        t.activity_create_time,
        t.activity_update_time
    </sql>
    <select id="getActivityList" resultMap="BaseResultMap" parameterType="Activity" >
        select
        <include refid="Base_List" />
        from tb_iamberry_activity t
        <where>
            <if test="activityId != null ">
                AND t.activity_id = #{activityId}
            </if >
            <if test="userOpenId != null and userOpenId != ''">
                AND t.user_open_id = #{userOpenId}
            </if >
            <if test="activityAllHelp != null ">
                AND t.activity_all_help = #{activityAllHelp}
            </if >
            <if test="activityAlreadyHelp != null ">
                AND t.activity_already_help = #{activityAlreadyHelp}
            </if >
            <if test="activityStatus != null ">
                AND t.activity_status = #{activityStatus}
            </if >
            <if test="activityCoupon != null and activityCoupon != ''">
                AND t.activity_coupon = #{activityCoupon}
            </if >
        </where>
    </select>

    <select id="getActivityById" resultMap="BaseResultMap" parameterType="Integer" >
        select
        <include refid="Base_List" />
        from tb_iamberry_activity t
        where t.activity_id= #{activityId}
    </select>

    <select id="getActivityCouponId" resultMap="BaseResultMap" parameterType="String" >
        select
        <include refid="Base_List" />
        from tb_iamberry_activity t
        where t.activity_coupon= #{couponId}
    </select>

    <insert id="save" parameterType="Activity" >
        insert into
        tb_iamberry_activity
        (
        user_open_id,
        activity_all_help,
        activity_code_img,
        activity_img,
        activity_status
        )
        values
        (
        #{userOpenId},
        #{activityAllHelp},
        #{activityCodeImg},
        #{activityImg},
        #{activityStatus}
        )
    </insert>
    <update id="update" parameterType="Activity" >
        update
        tb_iamberry_activity
        <set >
            <if test="userOpenId != null and userOpenId != ''">
                user_open_id = #{userOpenId},
            </if >
            <if test="activityAlreadyHelp != null ">
                activity_already_help = #{activityAlreadyHelp},
            </if >
            <if test="activityCodeImg != null and activityCodeImg != ''">
                activity_code_img = #{activityCodeImg},
            </if >
            <if test="activityImg != null and activityImg != ''">
                activity_img = #{activityImg},
            </if >
            <if test="activityStatus != null ">
                activity_status = #{activityStatus},
            </if >
            <if test="activityCoupon != null and activityCoupon != ''">
                activity_coupon = #{activityCoupon}
            </if >
        </set >
        where activity_id= #{activityId}
    </update>
</mapper>