<?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.lemon.lifecenter.mapper.LoginMapper">
    <select id="selectMemberIdCount" parameterType="LoginDTO" resultType="int">
        <![CDATA[
            SELECT COUNT(*) total
              FROM member
             WHERE id = #{id}
        ]]>
    </select>
    
    
    <select id="selectMemberCount" parameterType="LoginDTO" resultType="int">
        <![CDATA[
            SELECT COUNT(*) total
              FROM member
             WHERE id = #{id}
               AND password = #{password}
        ]]>
    </select>
  
    <select id="selectMemberData" parameterType="LoginDTO"  resultType="LoginDTO">
        <![CDATA[
            SELECT id AS id,
                   create_date AS createDate,
                   update_date AS updateDate,
                   name AS name,
                   phone_number AS phoneNumber,
                   last_login_time AS lastLoginTime,
                   fail_count AS failCount,
                   use_yn AS useYn,
                   group_idx AS groupIdx,
                   center_code AS centerCode
              FROM member
             WHERE id = #{id}
               AND password = #{password}
        ]]>
    </select>
    
    <select id="selectMemberFailCount" parameterType="LoginDTO" resultType="int">
        <![CDATA[
            SELECT fail_count AS failCount
              FROM member
             WHERE id = #{id}
        ]]>
    </select>
    
    <update id="updateMemberLoginData" parameterType="LoginDTO">
        <![CDATA[
            UPDATE MEMBER
               SET FAIL_COUNT = #{failCount}
        ]]>
        <if test="resultCode != null and resultCode.equals( '00' )">
            <![CDATA[
                   LAST_LOGIN_TIME = NOW()
            ]]>
        </if>
        <![CDATA[
             WHERE ID = #{id}
        ]]>
    </update>
    
    
    <insert id="insertAccessHistory" parameterType="HashMap">
        <![CDATA[
            INSERT INTO ACCESS_HISTORY
                        (ID,    IP,    LOGIN_TIME, SUCCESS_YN,   lOG_MESSAGE)
                  VALUE (#{id}, #{ip}, NOW(),      #{successYn}, #{logMessage})
        ]]>
    </insert>
</mapper>