<?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="WebAuth">

	<select id="selectListAuthOption" parameterType="hashMap" resultType="hashMap">
		SELECT MA.MU_AUTH_ID             AS "muAuthId"
			  ,MA.AUTH_NAME              AS "authName"
		  FROM MU_AUTH AS MA
		 WHERE MA.USE_YN     = 'Y'
 	  ORDER BY MA.AUTH_NAME ASC
	</select>
	
	<select id="selectTotalAuthCount" parameterType="hashmap" resultType="hashmap">
		SELECT COUNT(*)  AS "totalCount"
		  FROM MU_AUTH AS MA
		 WHERE MA.USE_YN = 'Y'
	</select>
	
	<select id="selectListAuth" parameterType="hashmap" resultType="hashmap">
		SELECT MA.*
		  FROM (
					SELECT MA.*
						  ,CAST(@RNUM:=@RNUM + 1 AS CHAR) AS "rowNum"
					  FROM (
								SELECT MA.MU_AUTH_ID                          AS "muAuthId"
									  ,MA.AUTH_NAME                           AS "authName"
									  ,DATE_FORMAT(MA.WRITE_DATE, '%Y-%m-%d') AS "writeDate"
								  FROM MU_AUTH AS MA
								 WHERE MA.USE_YN = 'Y'
							  ORDER BY MA.ORDER_NUMBER ASC
								 LIMIT 18446744073709551615
						   ) MA, (SELECT @RNUM:=0) R
					 WHERE 1 = 1
			   ) MA
		 WHERE 1 = 1
	</select>

	<select id="selectAuth" parameterType="hashmap" resultType="hashmap">
		SELECT MA.MU_AUTH_ID                          AS "muAuthId"
			  ,MA.AUTH_NAME                           AS "authName"
			  ,MA.ORDER_NUMBER                           AS "orderNumber"
			  ,DATE_FORMAT(MA.WRITE_DATE, '%Y-%m-%d') AS "writeDate"
		  FROM MU_AUTH AS MA
		 WHERE MA.USE_YN        = 'Y'
		   AND MA.MU_AUTH_ID  = #{muAuthId}
		 LIMIT 0, 1
	</select>
	<update id="updateAuth" parameterType="hashmap">
		UPDATE MU_AUTH
		SET MOD_ID              = #{modId}
		  ,MOD_DATE            = NOW()
		  ,CUD_FLAG            = 'U'
		  ,ORDER_NUMBER           = #{orderNumber}
		  ,AUTH_NAME           = #{authName}
		WHERE USE_YN        = 'Y'
		  AND MU_AUTH_ID  = #{muAuthId}
	</update>
	<insert id="insertAuth" parameterType="hashmap">
		<selectKey resultType="string" keyProperty="id" order="BEFORE">
			SELECT CONCAT(#{muAuthId},LPAD((SELECT NEXTVAL(MU_AUTH_SEQ)), 11, 0))
		</selectKey>
		INSERT INTO MU_AUTH(
					 MU_AUTH_ID
					,ORDER_NUMBER
					,AUTH_NAME
					,WRITE_DATE
					,WRITE_TIME
					,CUD_FLAG
					,USE_YN
					,REG_ID
					,REG_DATE
					,MOD_ID
					,MOD_DATE
					,T_ID
					,T_DATE
		)VALUES(
					 #{id}
					,#{orderNumber}
					,#{authName}
					,CURDATE()
					,CURTIME()
					,'C'
					,'Y'
					,#{regId}
					,NOW()
					,#{modId}
					,NOW()
					,#{tId}
					,#{tDate}
		)
	</insert>
	
	<update id="deleteAuth" parameterType="hashmap">
		UPDATE MU_AUTH
		   SET MOD_ID            = #{modId}
			  ,MOD_DATE	         = NOW()
			  ,CUD_FLAG          = 'D'
			  ,USE_YN            = 'N'
		 WHERE USE_YN        = 'Y'
		   AND MU_AUTH_ID  = #{muAuthId}
	</update>
</mapper>