<?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.style24.admin.biz.dao.TsaClauseDao">

	<!-- 약관 목록 조회 -->
	<select id="getClauseList" parameterType="Clause" resultType="Clause">
		/* TsaClasue.getClauseList */
		SELECT CLAUSE_SQ
		     , SITE_CD
		     , CLAUSE_TYPE
		     , CLAUSE_TITLE
		     , CLAUSE_CONTENT
		     , DATE_FORMAT(EFFECT_DT,'%Y%m%d')    AS EFFECT_DT
		     , DISP_YN
		     , FN_GET_USER_NM(REG_NO)             AS REG_NM
		     , DATE_FORMAT(REG_DT,'%Y%m%d%H%i%S') AS REG_DT
		     , FN_GET_USER_NM(UPD_NO)             AS UPD_NM
		     , DATE_FORMAT(UPD_DT,'%Y%m%d%H%i%S') AS UPD_DT
		FROM   TB_CLAUSE
		WHERE  SITE_CD = #{siteCd}
		<if test="clauseType != null and clauseType != ''">
		AND    CLAUSE_TYPE = #{clauseType}
		</if>
		ORDER  BY CLAUSE_TYPE
	</select>
	
	<!-- 약관 상세 조회 -->
	<select id="getClauseDetail" parameterType="Integer" resultType="Clause">
		/* TsaClause.getClauseDetail */
		SELECT CLAUSE_SQ
		     , SITE_CD
		     , CLAUSE_TYPE
		     , CLAUSE_TITLE
		     , CLAUSE_CONTENT
		     , DATE_FORMAT(EFFECT_DT,'%Y%m%d')    AS EFFECT_DT
		     , DISP_YN
		     , FN_GET_USER_NM(REG_NO)             AS REG_NM
		     , DATE_FORMAT(REG_DT,'%Y%m%d%H%i%S') AS REG_DT
		     , FN_GET_USER_NM(UPD_NO)             AS UPD_NM
		     , DATE_FORMAT(UPD_DT,'%Y%m%d%H%i%S') AS UPD_DT
		FROM   TB_CLAUSE
		WHERE  CLAUSE_SQ = #{clauseSq}
	</select>

	<!-- 약관 생성 -->
	<insert id="createClause" parameterType="Clause">
		/* TsaClasue.createClause */
		INSERT INTO TB_CLAUSE (
		       CLAUSE_SQ
		     , SITE_CD
		     , CLAUSE_TYPE
		     , CLAUSE_TITLE
		     , CLAUSE_CONTENT
		     , EFFECT_DT
		     , DISP_YN
		     , REG_NO
		     , REG_DT
		     , UPD_NO
		     , UPD_DT
		)
		VALUES (
		       NULL
		     , #{siteCd}
		     , #{clauseType}
		     , #{clauseTitle}
		     , #{clauseContent}
		     , STR_TO_DATE(#{effectDt},'%Y-%m-%d')
		     , #{dispYn}
		     , #{regNo}
		     , NOW()
		     , #{updNo}
		     , NOW()
		)
	</insert>

	<!-- 약관 수정 -->
	<update id="updateClause" parameterType="Clause">
		/* TsaClasue.updateClause */
		UPDATE TB_CLAUSE
		SET    SITE_CD = #{siteCd}
		     , CLAUSE_TYPE = #{clauseType}
		     , CLAUSE_TITLE = #{clauseTitle}
		     , CLAUSE_CONTENT = #{clauseContent}
		     , EFFECT_DT = STR_TO_DATE(#{effectDt},'%Y-%m-%d')
		     , DISP_YN = #{dispYn}
		     , UPD_NO = #{updNo}
		     , UPD_DT = NOW()
		WHERE  CLAUSE_SQ = #{clauseSq}
	</update>

</mapper>