<?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.dbnt.kcscbackend.auth.mapper.LoginUserMapper">

	<!-- 일반 로그인 -->
	<select id="actionLogin" resultType="LoginVO" parameterType="LoginVO">
		<!-- 일반회원 -->
		<if test="userSe == &quot;USR&quot;">
			
            SELECT EMPLYR_ID AS id
                 , USER_NM AS name
                 , PASSWORD AS password
                 , IHIDNUM AS ihidNum
                 , EMAIL_ADRES AS email
                 , 'USR' AS userSe
                 , ORGNZT_ID AS orgnztId
                 , ESNTL_ID AS uniqId
              FROM LETTNEMPLYRINFO
             WHERE EMPLYR_ID = #{id}
               AND PASSWORD = #{password}
               AND EMPLYR_STTUS_CODE = 'P'
			
		</if>
		<!-- 기업회원 -->
		<if test="userSe == &quot;ENT&quot;">

			SELECT entrprsmber_id AS id
			, cmpny_nm AS name
			, entrprs_mber_password AS password
			, bizrno AS ihidNum
			, applcnt_email_adres AS email
			, 'ENT' AS userSe
			, '-' AS orgnztId
			, esntl_id AS uniqId
			FROM LETTNENTRPRSMBER
			WHERE entrprsmber_id = #{id}
			AND entrprs_mber_password = #{password}
			AND entrprs_mber_sttus = 'P'

		</if>
		<!-- 업무사용자 -->
		<if test="userSe == &quot;USR&quot;">

			SELECT emplyr_id AS id
			, user_nm AS name
			, password AS password
			, ihidnum AS ihidNum
			, email_adres AS email
			, 'USR' AS userSe
			, orgnzt_id AS orgnztId
			, esntl_id AS uniqId
			FROM LETTNEMPLYRINFO
			WHERE emplyr_id = #{id}
			AND password = #{password}
			AND emplyr_sttus_code = 'P'

		</if>
	</select>


	<!-- 인증서 로그인 -->
	<select id="actionCrtfctLogin" resultType="LoginVO" parameterType="LoginVO">

		SELECT emplyr_id AS id
				 , user_nm AS name
				 , password AS password
				 , ihidnum AS ihidNum
				 , email_adres AS email
				 , 'USR' AS userSe
				 , orgnzt_id AS orgnztId
				 , esntl_id AS uniqId
		FROM LETTNEMPLYRINFO
		WHERE sub_dn = #{dn}

	</select>

	<!-- 아이디 찾기 -->
	<select id="searchId" resultType="LoginVO" parameterType="LoginVO">
		<!-- 일반회원 -->
		<if test="userSe == &quot;GNR&quot;">

			SELECT mber_id AS id
			FROM LETTNGNRLMBER
			WHERE mber_nm = #{name}
			AND mber_email_adres = #{email}
			AND mber_sttus = 'P'

		</if>
		<!-- 기업회원 -->
		<if test="userSe == &quot;ENT&quot;">

			SELECT entrprsmber_id AS id
			FROM LETTNENTRPRSMBER
			WHERE cmpny_nm = #{name}
			AND applcnt_email_adres = #{email}
			AND entrprs_mber_sttus = 'P'

		</if>
		<!-- 업무사용자 -->
		<if test="userSe == &quot;USR&quot;">

			SELECT emplyr_id AS id
			FROM LETTNEMPLYRINFO
			WHERE user_nm = #{name}
			AND email_adres = #{email}
			AND emplyr_sttus_code = 'P'

		</if>
	</select>

	<!-- 비밀번호 찾기 -->
	<select id="searchPassword" resultType="LoginVO" parameterType="LoginVO">
		<!-- 일반회원 -->
		<if test="userSe == &quot;GNR&quot;">

			SELECT password AS password
			FROM LETTNGNRLMBER
			WHERE mber_id = #{id}
			AND mber_nm = #{name}
			AND mber_email_adres = #{email}
			AND password_hint = #{passwordHint}
			AND password_cnsr = #{passwordCnsr}
			AND mber_sttus = 'P'

		</if>
		<!-- 기업회원 -->
		<if test="userSe == &quot;ENT&quot;">

			SELECT entrprs_mber_password AS password
			FROM LETTNENTRPRSMBER
			WHERE entrprsmber_id = #{id}
			AND cmpny_nm = #{name}
			AND applcnt_email_adres = #{email}
			AND entrprs_mber_password_hint = #{passwordHint}
			AND entrprs_mber_password_cnsr = #{passwordCnsr}
			AND entrprs_mber_sttus = 'P'

		</if>
		<!-- 업무사용자 -->
		<if test="userSe == &quot;USR&quot;">

			SELECT password AS password
			FROM LETTNEMPLYRINFO
			WHERE emplyr_id = #{id}
			AND user_nm = #{name}
			AND email_adres = #{email}
			AND password_hint = #{passwordHint}
			AND password_cnsr = #{passwordCnsr}
			AND emplyr_sttus_code = 'P'

		</if>
	</select>

	<!-- 변경된 비밀번호를 저장 -->
	<update id="updatePassword" parameterType="LoginVO">
		<!-- 일반회원 -->
		<if test="userSe == &quot;GNR&quot;">

			UPDATE LETTNGNRLMBER
			SET password = #{password}
			WHERE mber_id = #{id}

		</if>
		<!-- 기업회원 -->
		<if test="userSe == &quot;ENT&quot;">

			UPDATE LETTNENTRPRSMBER
			SET entrprs_mber_password = #{password}
			WHERE entrprsmber_id = #{id}

		</if>
		<!-- 업무사용자 -->
		<if test="userSe == &quot;USR&quot;">

			UPDATE LETTNEMPLYRINFO
			SET password = #{password}
			WHERE emplyr_id = #{id}

		</if>
	</update>
</mapper>