<?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.huijy.management.mapper.MemberHelpMapper">

    <resultMap type="MemberHelp" id="MemberHelpResult">
        <result property="memberHelpId"    column="member_help_id"    />
        <result property="memberId"    column="member_id"    />
        <result property="memberName"    column="member_name"    />
        <result property="nickName"    column="nick_name"    />
        <result property="memberPhone"    column="member_phone"    />
        <result property="phone"    column="phone"    />
        <result property="createTime"    column="create_time"    />
        <result property="lat"    column="lat"    />
        <result property="lng"    column="lng"    />
    </resultMap>

    <sql id="selectMemberHelpVo">
        select member_help_id, member_id, phone, create_time, lat, lng,
         (select name from t_member where t_member.member_id = t_member_help.member_id) member_name,
         (select nick_name from t_member where t_member.member_id = t_member_help.member_id) nick_name
         from t_member_help
    </sql>

    <select id="selectMemberHelpList" parameterType="MemberHelp" resultMap="MemberHelpResult">
        <include refid="selectMemberHelpVo"/>
        <where>
        </where>
    </select>

    <select id="selectMemberHelpByMemberHelpId" parameterType="Long" resultMap="MemberHelpResult">
        <include refid="selectMemberHelpVo"/>
        where member_help_id = #{memberHelpId}
    </select>

    <insert id="insertMemberHelp" parameterType="MemberHelp" useGeneratedKeys="true" keyProperty="memberHelpId">
        insert into t_member_help
        <trim prefix="(" suffix=")" suffixOverrides=",">
            <if test="memberId != null">member_id,</if>
            <if test="phone != null">phone,</if>
            <if test="createTime != null">create_time,</if>
            <if test="lat != null">lat,</if>
            <if test="lng != null">lng,</if>
            <if test="memberPhone != null">member_phone,</if>
         </trim>
        <trim prefix="values (" suffix=")" suffixOverrides=",">
            <if test="memberId != null">#{memberId},</if>
            <if test="phone != null">#{phone},</if>
            <if test="createTime != null">#{createTime},</if>
            <if test="lat != null">#{lat},</if>
            <if test="lng != null">#{lng},</if>
            <if test="memberPhone != null">#{memberPhone},</if>
         </trim>
    </insert>

    <update id="updateMemberHelp" parameterType="MemberHelp">
        update t_member_help
        <trim prefix="SET" suffixOverrides=",">
            <if test="memberId != null">member_id = #{memberId},</if>
            <if test="phone != null">phone = #{phone},</if>
            <if test="createTime != null">create_time = #{createTime},</if>
            <if test="lat != null">lat = #{lat},</if>
            <if test="lng != null">lng = #{lng},</if>
            <if test="memberPhone != null">member_phone = #{memberPhone},</if>
        </trim>
        where member_help_id = #{memberHelpId}
    </update>

    <delete id="deleteMemberHelpByMemberHelpId" parameterType="Long">
        delete from t_member_help where member_help_id = #{memberHelpId}
    </delete>

    <delete id="deleteMemberHelpByMemberHelpIds" parameterType="String">
        delete from t_member_help where member_help_id in
        <foreach item="memberHelpId" collection="array" open="(" separator="," close=")">
            #{memberHelpId}
        </foreach>
    </delete>
</mapper>
