<?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.MemberMapper">

    <resultMap type="Member" id="MemberResult">
        <result property="memberId"    column="member_id"    />
        <result property="name"    column="name"    />
        <result property="mobile"    column="mobile"    />
        <result property="email"    column="email"    />
        <result property="registerTime"    column="register_time"    />
        <result property="lastLoginTime"    column="last_login_time"    />
        <result property="lastLoginIp"    column="last_login_ip"    />
        <result property="loginNum"    column="login_num"    />
        <result property="unionid"    column="unionid"    />
        <result property="openid"    column="openid"    />
        <result property="nickName"    column="nick_name"    />
        <result property="avatarUrl"    column="avatar_url"    />
        <result property="gender"    column="gender"    />
        <result property="province"    column="province"    />
        <result property="city"    column="city"    />
        <result property="country"    column="country"    />
        <result property="language"    column="language"    />
        <result property="lastLat"    column="last_lat"    />
        <result property="lastLng"    column="last_lng"    />
        <result property="isShop"    column="is_shop"    />
    </resultMap>

    <sql id="selectMemberVo">
        select member_id, name, mobile, email, register_time, last_login_time, last_login_ip, login_num, unionid, openid, nick_name, avatar_url, gender, province, city, country, language, last_lat, last_lng,
        (select count(*) from t_shop  where t_shop.member_id = t_member.member_id) is_shop
        from t_member
    </sql>

    <select id="selectMemberList" parameterType="Member" resultMap="MemberResult">
        <include refid="selectMemberVo"/>
        <where>
            <if test="name != null  and name != ''"> and name like concat('%', #{name}, '%')</if>
            <if test="mobile != null  and mobile != ''"> and mobile = #{mobile}</if>
            <if test="nickName != null  and nickName != ''"> and nick_name like concat('%', #{nickName}, '%')</if>
            <if test="gender != null  and gender != ''"> and gender = #{gender}</if>
        </where>
    </select>

    <select id="selectMemberByMemberId" parameterType="Long" resultMap="MemberResult">
        <include refid="selectMemberVo"/>
        where member_id = #{memberId}
    </select>

    <insert id="insertMember" parameterType="Member" useGeneratedKeys="true" keyProperty="memberId">
        insert into t_member
        <trim prefix="(" suffix=")" suffixOverrides=",">
            <if test="name != null and name != ''">name,</if>
            <if test="mobile != null and mobile != ''">mobile,</if>
            <if test="email != null">email,</if>
            <if test="registerTime != null">register_time,</if>
            <if test="lastLoginTime != null">last_login_time,</if>
            <if test="lastLoginIp != null">last_login_ip,</if>
            <if test="loginNum != null">login_num,</if>
            <if test="unionid != null">unionid,</if>
            <if test="openid != null">openid,</if>
            <if test="nickName != null">nick_name,</if>
            <if test="avatarUrl != null">avatar_url,</if>
            <if test="gender != null">gender,</if>
            <if test="province != null">province,</if>
            <if test="city != null">city,</if>
            <if test="country != null">country,</if>
            <if test="language != null">language,</if>
            <if test="lastLat != null">last_lat,</if>
            <if test="lastLng != null">last_lng,</if>
         </trim>
        <trim prefix="values (" suffix=")" suffixOverrides=",">
            <if test="name != null and name != ''">#{name},</if>
            <if test="mobile != null and mobile != ''">#{mobile},</if>
            <if test="email != null">#{email},</if>
            <if test="registerTime != null">#{registerTime},</if>
            <if test="lastLoginTime != null">#{lastLoginTime},</if>
            <if test="lastLoginIp != null">#{lastLoginIp},</if>
            <if test="loginNum != null">#{loginNum},</if>
            <if test="unionid != null">#{unionid},</if>
            <if test="openid != null">#{openid},</if>
            <if test="nickName != null">#{nickName},</if>
            <if test="avatarUrl != null">#{avatarUrl},</if>
            <if test="gender != null">#{gender},</if>
            <if test="province != null">#{province},</if>
            <if test="city != null">#{city},</if>
            <if test="country != null">#{country},</if>
            <if test="language != null">#{language},</if>
            <if test="lastLat != null">#{lastLat},</if>
            <if test="lastLng != null">#{lastLng},</if>
         </trim>
    </insert>

    <update id="updateMember" parameterType="Member">
        update t_member
        <trim prefix="SET" suffixOverrides=",">
            <if test="name != null and name != ''">name = #{name},</if>
            <if test="mobile != null and mobile != ''">mobile = #{mobile},</if>
            <if test="email != null">email = #{email},</if>
            <if test="registerTime != null">register_time = #{registerTime},</if>
            <if test="lastLoginTime != null">last_login_time = #{lastLoginTime},</if>
            <if test="lastLoginIp != null">last_login_ip = #{lastLoginIp},</if>
            <if test="loginNum != null">login_num = #{loginNum},</if>
            <if test="unionid != null">unionid = #{unionid},</if>
            <if test="openid != null">openid = #{openid},</if>
            <if test="nickName != null">nick_name = #{nickName},</if>
            <if test="avatarUrl != null">avatar_url = #{avatarUrl},</if>
            <if test="gender != null">gender = #{gender},</if>
            <if test="province != null">province = #{province},</if>
            <if test="city != null">city = #{city},</if>
            <if test="country != null">country = #{country},</if>
            <if test="language != null">language = #{language},</if>
            <if test="lastLat != null">last_lat = #{lastLat},</if>
            <if test="lastLng != null">last_lng = #{lastLng},</if>
        </trim>
        where member_id = #{memberId}
    </update>

    <delete id="deleteMemberByMemberId" parameterType="Long">
        delete from t_member where member_id = #{memberId}
    </delete>

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

    <select id="selectByOpenId" resultMap="MemberResult">
        <include refid="selectMemberVo"/>
        where openid = #{openId}

    </select>
</mapper>
