<?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.dgtly.member.mapper.MemberInfoMapper">
    
    <resultMap type="MemberInfo" id="MemberInfoResult">
        <result property="id"    column="id"    />
        <result property="loginAccount"    column="login_account"    />
        <result property="loginPassword"    column="login_password"    />
        <result property="phone"    column="phone"    />
        <result property="loginTime"    column="login_time"    />
        <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="remark"    column="remark"    />
    </resultMap>

    <sql id="selectMemberInfoVo">
        select id, login_account, login_password, phone, login_time, create_by, create_time, update_by, update_time, remark from member_info
    </sql>

    <select id="selectMemberInfoList" parameterType="MemberInfo" resultMap="MemberInfoResult">
        <include refid="selectMemberInfoVo"/>
        <where>  
            <if test="loginAccount != null  and loginAccount != ''"> and login_account = #{loginAccount}</if>
            <if test="loginPassword != null  and loginPassword != ''"> and login_password = #{loginPassword}</if>
            <if test="phone != null  and phone != ''"> and phone = #{phone}</if>
            <if test="loginTime != null "> and login_time = #{loginTime}</if>
        </where>
    </select>
    
    <select id="selectMemberInfoById" parameterType="Long" resultMap="MemberInfoResult">
        <include refid="selectMemberInfoVo"/>
        where id = #{id}
    </select>
        
    <insert id="insertMemberInfo" parameterType="MemberInfo">
        insert into member_info
        <trim prefix="(" suffix=")" suffixOverrides=",">
            <if test="id != null ">id,</if>
            <if test="loginAccount != null  and loginAccount != ''">login_account,</if>
            <if test="loginPassword != null  and loginPassword != ''">login_password,</if>
            <if test="phone != null  and phone != ''">phone,</if>
            <if test="loginTime != null ">login_time,</if>
            <if test="createBy != null  and createBy != ''">create_by,</if>
            <if test="createTime != null ">create_time,</if>
            <if test="updateBy != null  and updateBy != ''">update_by,</if>
            <if test="updateTime != null ">update_time,</if>
            <if test="remark != null  and remark != ''">remark,</if>
         </trim>
        <trim prefix="values (" suffix=")" suffixOverrides=",">
            <if test="id != null ">#{id},</if>
            <if test="loginAccount != null  and loginAccount != ''">#{loginAccount},</if>
            <if test="loginPassword != null  and loginPassword != ''">#{loginPassword},</if>
            <if test="phone != null  and phone != ''">#{phone},</if>
            <if test="loginTime != null ">#{loginTime},</if>
            <if test="createBy != null  and createBy != ''">#{createBy},</if>
            <if test="createTime != null ">#{createTime},</if>
            <if test="updateBy != null  and updateBy != ''">#{updateBy},</if>
            <if test="updateTime != null ">#{updateTime},</if>
            <if test="remark != null  and remark != ''">#{remark},</if>
         </trim>
    </insert>

    <update id="updateMemberInfo" parameterType="MemberInfo">
        update member_info
        <trim prefix="SET" suffixOverrides=",">
            <if test="loginAccount != null  and loginAccount != ''">login_account = #{loginAccount},</if>
            <if test="loginPassword != null  and loginPassword != ''">login_password = #{loginPassword},</if>
            <if test="phone != null  and phone != ''">phone = #{phone},</if>
            <if test="loginTime != null ">login_time = #{loginTime},</if>
            <if test="createBy != null  and createBy != ''">create_by = #{createBy},</if>
            <if test="createTime != null ">create_time = #{createTime},</if>
            <if test="updateBy != null  and updateBy != ''">update_by = #{updateBy},</if>
            <if test="updateTime != null ">update_time = #{updateTime},</if>
            <if test="remark != null  and remark != ''">remark = #{remark},</if>
        </trim>
        where id = #{id}
    </update>

    <delete id="deleteMemberInfoById" parameterType="Long">
        delete from member_info where id = #{id}
    </delete>

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

    <select id="checkMemberUnique" parameterType="java.lang.String" resultMap="MemberInfoResult">
          select id, login_account, login_password
          from member_info where login_account = #{loginAccount}
    </select>

    <select id="checkMemberPhoneUnique" parameterType="java.lang.String" resultMap="MemberInfoResult">
        select id, login_account, login_password
        from member_info where phone = #{phone}
    </select>


    <select id="memberLogin" parameterType="MemberInfo" resultMap="MemberInfoResult">
          select id, login_account, login_password
          from member_info where (login_account = #{loginAccount} or phone = #{phone}) and login_password = #{loginPassword}
    </select>
</mapper>