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

    <resultMap type="Member" id="MemberResult">
        <result property="memberId"    column="member_id"    />
        <result property="phone"    column="phone"    />
        <result property="openId"    column="open_id"    />
        <result property="appleId"    column="apple_id"    />
        <result property="nikeName"    column="nike_name"    />
        <result property="realName"    column="real_name"    />
        <result property="sex"    column="sex"    />
        <result property="avatar"    column="avatar"    />
        <result property="closeTime"    column="close_time"    />
        <result property="closeReason"    column="close_reason"    />
        <result property="password"    column="password"    />
        <result property="status"    column="status"    />
        <result property="delFlag"    column="del_flag"    />
        <result property="loginIp"    column="login_ip"    />
        <result property="loginDate"    column="login_date"    />
        <result property="createBy"    column="create_by"    />
        <result property="createTime"    column="create_time"    />
        <result property="updateBy"    column="update_by"    />
        <result property="updateTime"    column="update_time"    />
        <result property="column1"    column="column1"    />
        <result property="column2"    column="column2"    />
        <result property="column3"    column="column3"    />
    </resultMap>

    <resultMap type="MemberVo" id="MemberListResult">
        <result property="memberId"    column="member_id"    />
        <result property="phone"    column="phone"    />
        <result property="openId"    column="open_id"    />
        <result property="appleId"    column="apple_id"    />
        <result property="nikeName"    column="nike_name"    />
        <result property="realName"    column="real_name"    />
        <result property="sex"    column="sex"    />
        <result property="avatar"    column="avatar"    />
        <result property="closeTime"    column="close_time"    />
        <result property="closeReason"    column="close_reason"    />
        <result property="password"    column="password"    />
        <result property="status"    column="status"    />
        <result property="delFlag"    column="del_flag"    />
        <result property="loginIp"    column="login_ip"    />
        <result property="loginDate"    column="login_date"    />
        <result property="createBy"    column="create_by"    />
        <result property="createTime"    column="create_time"    />
        <result property="updateBy"    column="update_by"    />
        <result property="updateTime"    column="update_time"    />
        <result property="column1"    column="column1"    />
        <result property="column2"    column="column2"    />
        <result property="column3"    column="column3"    />
        <collection property="addressList" select="selectMemberAddress" column="member_id"/>
    </resultMap>

    <sql id="selectMemberVo">
        select member_id, phone, open_id, apple_id, nike_name, real_name, sex, avatar, close_time, close_reason, password, status, del_flag, login_ip, login_date, create_by, create_time, update_by, update_time, column1, column2, column3 from member
    </sql>

    <select id="selectMemberList" parameterType="Member" resultMap="MemberResult">
        <include refid="selectMemberVo"/>
        <where>
            <if test="phone != null  and phone != ''"> and phone = #{phone}</if>
            <if test="openId != null  and openId != ''"> and open_id = #{openId}</if>
            <if test="appleId != null  and appleId != ''"> and apple_id = #{appleId}</if>
            <if test="nikeName != null  and nikeName != ''"> and nike_name like concat('%', #{nikeName}, '%')</if>
            <if test="realName != null  and realName != ''"> and real_name like concat('%', #{realName}, '%')</if>
            <if test="sex != null "> and sex = #{sex}</if>
            <if test="avatar != null  and avatar != ''"> and avatar = #{avatar}</if>
            <if test="closeTime != null "> and close_time = #{closeTime}</if>
            <if test="closeReason != null  and closeReason != ''"> and close_reason = #{closeReason}</if>
            <if test="password != null  and password != ''"> and password = #{password}</if>
            <if test="status != null  and status != ''"> and status = #{status}</if>
            <if test="loginIp != null  and loginIp != ''"> and login_ip = #{loginIp}</if>
            <if test="loginDate != null "> and login_date = #{loginDate}</if>
            <if test="column1 != null  and column1 != ''"> and column1 = #{column1}</if>
            <if test="column2 != null  and column2 != ''"> and column2 = #{column2}</if>
            <if test="column3 != null  and column3 != ''"> and column3 = #{column3}</if>
        </where>
    </select>

    <select id="pageList" parameterType="com.younike.system.param.MemberQueryParam" resultMap="MemberListResult">
        select m.* from member m
        where m.del_flag = 0
        <if test="phone != null  and phone != ''"> and m.phone = #{phone}</if>
        <if test="nikeName != null  and nikeName != ''"> and m.nike_name like concat('%', #{nikeName}, '%')</if>
        <if test="status != null and status != ''"> and m.status = #{status}</if>
        <if test="beginTime != null and beginTime != ''">
            and date_format(m.create_time,'%y%m%d') &gt;= date_format(#{beginTime},'%y%m%d')
        </if>
        <if test="endTime != null and endTime != ''">
            and date_format(m.create_time,'%y%m%d') &lt;= date_format(#{endTime},'%y%m%d')
        </if>
        ORDER BY m.create_time DESC
    </select>

    <select id="selectMemberAddress" resultMap="com.younike.system.mapper.MemberAddressMapper.MemberAddressResult" >
        select * from member_address
        where member_id = #{member_id}
        and del_flag = 0
    </select>

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

    <select id="selectMemberByPhone" parameterType="string" resultMap="MemberResult">
        <include refid="selectMemberVo"/>
        where del_flag = '0'
        and phone = #{phone}
    </select>

    <select id="getMemberCount" resultType="java.lang.Integer">
        SELECT
        count(*)
        FROM member
        WHERE del_flag = '0'
    </select>

    <insert id="insertMember" parameterType="Member" useGeneratedKeys="true" keyProperty="memberId">
        insert into member
        <trim prefix="(" suffix=")" suffixOverrides=",">
            <if test="phone != null and phone != ''">phone,</if>
            <if test="openId != null">open_id,</if>
            <if test="appleId != null">apple_id,</if>
            <if test="nikeName != null">nike_name,</if>
            <if test="realName != null">real_name,</if>
            <if test="sex != null">sex,</if>
            <if test="avatar != null">avatar,</if>
            <if test="closeTime != null">close_time,</if>
            <if test="closeReason != null">close_reason,</if>
            <if test="password != null">password,</if>
            <if test="status != null">status,</if>
            <if test="delFlag != null">del_flag,</if>
            <if test="loginIp != null">login_ip,</if>
            <if test="loginDate != null">login_date,</if>
            <if test="createBy != null">create_by,</if>
            <if test="createTime != null">create_time,</if>
            <if test="updateBy != null">update_by,</if>
            <if test="updateTime != null">update_time,</if>
            <if test="column1 != null">column1,</if>
            <if test="column2 != null">column2,</if>
            <if test="column3 != null">column3,</if>
         </trim>
        <trim prefix="values (" suffix=")" suffixOverrides=",">
            <if test="phone != null and phone != ''">#{phone},</if>
            <if test="openId != null">#{openId},</if>
            <if test="appleId != null">#{appleId},</if>
            <if test="nikeName != null">#{nikeName},</if>
            <if test="realName != null">#{realName},</if>
            <if test="sex != null">#{sex},</if>
            <if test="avatar != null">#{avatar},</if>
            <if test="closeTime != null">#{closeTime},</if>
            <if test="closeReason != null">#{closeReason},</if>
            <if test="password != null">#{password},</if>
            <if test="status != null">#{status},</if>
            <if test="delFlag != null">#{delFlag},</if>
            <if test="loginIp != null">#{loginIp},</if>
            <if test="loginDate != null">#{loginDate},</if>
            <if test="createBy != null">#{createBy},</if>
            <if test="createTime != null">#{createTime},</if>
            <if test="updateBy != null">#{updateBy},</if>
            <if test="updateTime != null">#{updateTime},</if>
            <if test="column1 != null">#{column1},</if>
            <if test="column2 != null">#{column2},</if>
            <if test="column3 != null">#{column3},</if>
         </trim>
    </insert>

    <update id="updateMember" parameterType="com.younike.system.domain.Member">
        update member
        <trim prefix="SET" suffixOverrides=",">
            <if test="phone != null and phone != ''">phone = #{phone},</if>
            <if test="openId != null">open_id = #{openId},</if>
            <if test="appleId != null">apple_id = #{appleId},</if>
            <if test="nikeName != null">nike_name = #{nikeName},</if>
            <if test="realName != null">real_name = #{realName},</if>
            <if test="sex != null">sex = #{sex},</if>
            <if test="avatar != null">avatar = #{avatar},</if>
            <if test="closeTime != null">close_time = #{closeTime},</if>
            <if test="closeReason != null">close_reason = #{closeReason},</if>
            <if test="password != null">password = #{password},</if>
            <if test="status != null">status = #{status},</if>
            <if test="delFlag != null">del_flag = #{delFlag},</if>
            <if test="loginIp != null">login_ip = #{loginIp},</if>
            <if test="loginDate != null">login_date = #{loginDate},</if>
            <if test="createBy != null">create_by = #{createBy},</if>
            <if test="createTime != null">create_time = #{createTime},</if>
            <if test="updateBy != null">update_by = #{updateBy},</if>
            <if test="updateTime != null">update_time = #{updateTime},</if>
            <if test="column1 != null">column1 = #{column1},</if>
            <if test="column2 != null">column2 = #{column2},</if>
            <if test="column3 != null">column3 = #{column3},</if>
        </trim>
        where member_id = #{memberId}
    </update>

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

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