<?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.ActivityHelpMapper">
    <resultMap  id="BaseResultMap" type="ActivityHelp" >
        <result    column="activity_help_id"    property="activityHelpId" />
        <result    column="activity_id"    property="activityId" />
        <result    column="user_open_id"    property="userOpenId" />
        <result    column="activity_create_time"    property="activityCreateTime" />
        <result    column="user_head"    property="userHead" />
        <result    column="user_nickname"    property="userNickname" />
    </resultMap>
    <sql    id="Base_List" >
        t.activity_help_id,
        t.activity_id,
        t.user_open_id,
        t.activity_create_time
    </sql>
    <select id="getActivityHelpList" resultMap="BaseResultMap" parameterType="ActivityHelp" >
        select
            <include refid="Base_List" />,
            tiuu.user_head,
            tiuu.user_nickname
        from tb_iamberry_activity_help t
        LEFT JOIN tb_iamberry_user_userinfo tiuu ON t.user_open_id = tiuu.user_openid
        <where>
            <if test="activityHelpId != null ">
                AND t.activity_help_id = #{activityHelpId}
            </if >
            <if test="activityId != null ">
                AND t.activity_id = #{activityId}
            </if >
            <if test="userOpenId != null and userOpenId != ''">
                AND t.user_open_id = #{userOpenId}
            </if >
        </where>
    </select>
    <select id="getActivityHelpById" resultMap="BaseResultMap" parameterType="Integer" >
        select
        <include refid="Base_List" />
        from tb_iamberry_activity_help t
        where t.activity_help_id= #{activityHelpId}
    </select>
    <insert id="save" parameterType="ActivityHelp" >
        insert into
        tb_iamberry_activity_help
        (
        activity_id,
        user_open_id
        )
        values
        (
        #{activityId},
        #{userOpenId}
        )
    </insert>
    <update id="update" parameterType="ActivityHelp" >
        update
        tb_iamberry_activity_help
        <set >
            <if test="activityId != null ">
                activity_id = #{activityId},
            </if >
            <if test="userOpenId != null and userOpenId != ''">
                user_open_id = #{userOpenId},
            </if >
        </set >
        where activity_help_id= #{activityHelpId}
    </update>
</mapper>