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

	<select id="selectTotalLogHistoryCount" parameterType="hashmap" resultType="hashmap">
		SELECT COUNT(*)                     AS "totalCount"
		  FROM MU_LOG_HISTORY AS MLH
		 WHERE MLH.USE_YN = 'Y'
	</select>
	
	<select id="selectListLogHistory" parameterType="hashmap" resultType="hashmap">
		SELECT MU_LOG_HISTORY_ID            AS "muLogHistoryId"
			  ,WRITE_DATE                   AS "writeDate"
			  ,RNUM                         AS "rowNum"
		  FROM (
					SELECT MU_LOG_HISTORY_ID
						  ,WRITE_DATE
						  ,CAST(@RNUM:=@RNUM + 1 AS CHAR) AS RNUM
					  FROM (
								SELECT MLH.MU_LOG_HISTORY_ID
									  ,DATE_FORMAT(MLH.WRITE_DATE, '%Y-%m-%d') AS WRITE_DATE
								  FROM MU_LOG_HISTORY MLH
								 WHERE MLH.USE_YN = 'Y'
							  ORDER BY MLH.WRITE_DATE DESC
								 LIMIT 18446744073709551615
						   ) MLH, (SELECT @RNUM:=0) R
					 WHERE 1 = 1
			   ) MLH
		 WHERE 1 = 1
		 LIMIT ${start}, ${limit}
	</select>
	
	<select id="selectLogHistory" parameterType="hashmap" resultType="hashmap">
		SELECT MLH.MU_LOG_HISTORY_ID                   AS "muLogHistoryId"
			  ,MLH.MU_MEMBER_ID                        AS "muMemberId"
			  ,DATE_FORMAT(MLH.WRITE_DATE, '%Y-%m-%d') AS "writeDate"
		  FROM MU_LOG_HISTORY MLH
		 WHERE MLH.USE_YN             = 'Y'
		   AND MLH.MU_LOG_HISTORY_ID  = #{muLogHistoryId}
		 LIMIT 0, 1
	</select>
	
	<insert id="insertLogHistory" parameterType="hashmap">
		<selectKey resultType="string" keyProperty="id" order="BEFORE">
			SELECT CONCAT(#{muLogHistoryId},LPAD((SELECT NEXTVAL(MU_LOG_HISTORY_SEQ)), 11, 0))
		</selectKey>
		INSERT INTO MU_LOG_HISTORY(
					 MU_LOG_HISTORY_ID
					,MU_MEMBER_ID
					,VISIT_IP
					,VISIT_ORIGIN_AGENT
					,VISIT_AGENT
					,VISIT_OS
					,URL
					,FUNC
					,SERVICE
					,FUNC_NAME
					,SERVICE_NAME
					,REQUEST_VALUE
					,RESPONSE_VALUE
					,RESULT_CODE
					,RESULT_MSG
					,WRITE_DATE
					,WRITE_TIME
					,CUD_FLAG
					,USE_YN
					,REG_ID
					,REG_DATE
					,MOD_ID
					,MOD_DATE
					,T_ID
					,T_DATE
		)VALUES(
					 #{id}
					,#{muMemberId}
					,#{visitIp,jdbcType=VARCHAR}
					,#{visitOriginAgent,jdbcType=VARCHAR}
					,#{visitAgent,jdbcType=VARCHAR}
					,#{visitOs,jdbcType=VARCHAR}
					,#{url,jdbcType=VARCHAR}
					,#{func,jdbcType=VARCHAR}
					,#{service,jdbcType=VARCHAR}
					,#{funcName,jdbcType=VARCHAR}
					,#{serviceName,jdbcType=VARCHAR}
					,#{requestValue}
					,#{responseValue}
					,#{resultCode,jdbcType=VARCHAR}
					,#{resultMsg,jdbcType=VARCHAR}
					,CURDATE()
					,CURTIME()
					,'C'
					,'Y'
					,#{regId}
					,NOW()
					,#{modId}
					,NOW()
					,#{tId}
					,#{tDate}
		)
	</insert>

	<update id="updateLogHistory" parameterType="hashmap">
		UPDATE MU_LOG_HISTORY
		   SET MOD_ID              = #{modId}
			  ,MOD_DATE            = NOW()
			  ,CUD_FLAG            = 'U'
			  ,TITLE               = #{title}
			  ,CONTENT             = #{content}
			  ,WRITE_NAME          = #{writeName}
			  ,WRITE_DATE          = #{writeDate}
		 WHERE USE_YN            = 'Y'
		   AND MU_LOG_HISTORY_ID = #{muLogHistoryId}
	</update>
	
	<update id="deleteLogHistory" parameterType="hashmap">
		UPDATE MU_LOG_HISTORY
		   SET MOD_ID               = #{modId}
			  ,MOD_DATE	            = NOW()
			  ,CUD_FLAG             = 'D'
			  ,USE_YN               = 'N'
		 WHERE USE_YN            = 'Y'
		   AND MU_LOG_HISTORY_ID = #{muLogHistoryId}
	</update>
</mapper>