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

	<!-- FAQ 목록 -->
	<select id="getFaqList" parameterType="Faq" resultType="Faq">
		/* TsaFaq.getFaqList */
		SELECT FAQ_SQ                                       /*FAQ일련번호(SEQ_FAQ sequence)*/
		     , SITE_CD                                      /*사이트코드(공통코드G000)*/
		     , FAQ_TYPE                                     /*FAQ유형(공통코드G046)*/
		     , QUESTION                                     /*질문*/
		     , ANSWER                                       /*답변*/
		     , USE_YN                                       /*사용여부(Y:사용)*/
		     , READ_CNT                                     /*조회수*/
		     , DISP_ORD                                     /*표시순서*/
		     , 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_FAQ
		WHERE  SITE_CD = #{siteCd}
		<if test='faqType != null and faqType !=""'>
		AND    FAQ_TYPE = #{faqType}
		</if>
		<if test='useYn != null and useYn !=""'>
		AND    USE_YN = #{useYn}
		</if>
		<if test="searchTxt != null and searchTxt !=''">
		AND    (
		        LOWER(QUESTION) LIKE CONCAT('%',LOWER(#{searchTxt}),'%')
		        OR
		        LOWER(ANSWER) LIKE CONCAT('%',LOWER(#{searchTxt}),'%')
		       )
		</if>
	</select>

	<!-- FAQ 등록/수정 -->
	<insert id="saveFaq" parameterType="Faq">
		/* TsaFaq.saveFaq */
		INSERT INTO TB_FAQ (
		       FAQ_SQ
		     , SITE_CD
		     , FAQ_TYPE
		     , QUESTION
		     , ANSWER
		     , USE_YN
		     , READ_CNT
		     , DISP_ORD
		     , REG_NO
		     , REG_DT
		     , UPD_NO
		     , UPD_DT
		)
		VALUES (
		       #{faqSq}
		     , #{siteCd}
		     , #{faqType}
		     , #{question}
		     , #{answer}
		     , #{useYn}
		     , 0
		     , #{dispOrd}
		     , #{regNo}
		     , NOW()
		     , #{updNo}
		     , NOW()
		)
		ON DUPLICATE KEY UPDATE
		       SITE_CD = #{siteCd}
		     , FAQ_TYPE = #{faqType}
		     , QUESTION = #{question}
		     , ANSWER = #{answer}
		     , USE_YN = #{useYn}
		     , DISP_ORD = #{dispOrd}
		     , UPD_NO = #{updNo}
		     , UPD_DT = NOW()
	</insert>

	<!-- FAQ 상세 -->
	<select id="getFaq" parameterType="Integer" resultType="Faq">
		/* TsaFaq.getFaq */
		SELECT FAQ_SQ                                    /*FAQ일련번호*/
		     , SITE_CD                                   /*사이트코드*/
		     , FN_GET_CODE_NM('G000',SITE_CD) AS SITE_NM /*사이트명*/
		     , FAQ_TYPE                                  /*유형*/
		     , QUESTION                                  /*질문*/
		     , ANSWER                                    /*답변*/
		     , USE_YN                                    /*사용여부*/
		     , READ_CNT                                  /*조회수*/
		     , DISP_ORD                                  /*표시순서*/
		FROM   TB_FAQ
		WHERE  FAQ_SQ = #{faqSq}
	</select>

</mapper>