<?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.TsaAnswerPhaseDao">

	<!-- 답변문구 목록 -->
	<select id="getAnswerPhaseList" parameterType="AnswerPhase" resultType="AnswerPhase">
		/* TsaAnswerPhase.getAnswerPhaseList */
		 SELECT SITE_CD                                      /*사이트코드*/
		      , ANS_SQ                                       /*답변일련번호*/
		      , ANS_CLSF                                     /*답변종류코드*/
		      , ANS_TITLE                                    /*답변제목*/
		      , ANS_CONTENT                                  /*답변내용*/
		      , USE_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_ANS_PHASE
		WHERE   1 = 1
		<if test="siteCd != null and siteCd != ''">
		AND     SITE_CD = #{siteCd}
		</if>
		<if test="ansClsf != null and ansClsf != ''">
		AND     ANS_CLSF = #{ansClsf}
		</if>
		<if test="useYn != null and useYn != ''">
		AND     USE_YN = #{useYn}
		</if>
		<if test="ansTitle != null and ansTitle != ''">
		AND     ANS_TITLE LIKE CONCAT('%',#{ansTitle},'%')
		</if>
		ORDER   BY SITE_CD, ANS_CLSF, ANS_SQ
	</select>

	<!-- 기본답변문구 등록/수정 -->
	<insert id="saveAnswerPhase" parameterType="AnswerPhase">
		/* TsaAnswerPhase.saveAnswerPhase */
		INSERT INTO TB_ANS_PHASE (
		       ANS_SQ
		     , ANS_CLSF
		     , SITE_CD
		     , ANS_TITLE
		     , ANS_CONTENT
		     , USE_YN
		     , REG_NO
		     , REG_DT
		     , UPD_NO
		     , UPD_DT
		)
		VALUES (
		       NULL
		     , #{ansClsf}
		     , #{siteCd}
		     , #{ansTitle}
		     , #{ansContent}
		     , #{useYn}
		     , #{regNo}
		     , NOW()
		     , #{updNo}
		     , NOW()
		)
		ON DUPLICATE KEY UPDATE
		       SITE_CD = #{siteCd}
		     , ANS_CLSF = #{ansClsf}
		     , ANS_TITLE = #{ansTitle}
		     , ANS_CONTENT = #{ansContent}
		     , USE_YN = #{useYn}
		     , UPD_NO = #{updNo}
		     , UPD_DT = NOW()
	</insert>

</mapper>