<?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.front.biz.dao.TsfFaqDao">

	<!-- Paging -->
	<sql id="pageSql">
		LIMIT #{pageable.startRow}, #{pageable.pageSize}
	</sql>
	<!--// Paging -->
	
	<!-- FAQ 자주 묻는 질문 목록 (10개) -->
	<select id="getFaqLikesList" parameterType="String" resultType="Faq">
		/* TsfFaq.getFaqLikesList */
		SELECT FAQ_SQ   /*FAQ일련번호*/
		     , SITE_CD  /*사이트코드(공통코드G000)*/
		     , FAQ_TYPE /*FAQ유형(공통코드G046)*/
		     , QUESTION /*질문*/
		     , ANSWER   /*답변*/
		     , DISP_ORD /*표시순서*/
		FROM   TB_FAQ
		WHERE  SITE_CD = #{siteCd}
		AND    USE_YN = 'Y'
		ORDER  BY DISP_ORD
		LIMIT 10
	</select>
	
	<!-- FAQ 총건수 -->
	<select id="getFaqTotalCount" parameterType="Faq" resultType="int">
		/* TsfFaq.getFaqTotalCount */
		SELECT COUNT(*) AS CNT
		FROM   TB_FAQ
		WHERE  SITE_CD = #{siteCd}
		<if test='faqType != null and faqType !=""'>
		AND    FAQ_TYPE = #{faqType}
		</if>
		AND    USE_YN = 'Y'
		<if test="searchTxt != null and searchTxt !=''">
		AND    (
		        LOWER(QUESTION) LIKE CONCAT('%',LOWER(#{searchTxt}),'%')
		        OR
		        LOWER(ANSWER) LIKE CONCAT('%',LOWER(#{searchTxt}),'%')
		       )
		</if>
	</select>
	
	<!-- FAQ 목록 -->
	<select id="getFaqList" parameterType="Faq" resultType="Faq">
		/* TsfFaq.getFaqList */
		SELECT FAQ_SQ   /*FAQ일련번호*/
		     , SITE_CD  /*사이트코드(공통코드G000)*/
		     , FAQ_TYPE /*FAQ유형(공통코드G046)*/
		     , QUESTION /*질문*/
		     , ANSWER   /*답변*/
		     , DISP_ORD /*표시순서*/
		FROM   TB_FAQ
		WHERE  SITE_CD = #{siteCd}
		<if test='faqType != null and faqType !=""'>
		AND    FAQ_TYPE = #{faqType}
		</if>
		AND    USE_YN = 'Y'
		<if test="searchTxt != null and searchTxt !=''">
		AND    (
		        LOWER(QUESTION) LIKE CONCAT('%',LOWER(#{searchTxt}),'%')
		        OR
		        LOWER(ANSWER) LIKE CONCAT('%',LOWER(#{searchTxt}),'%')
		       )
		</if>
		ORDER  BY REG_DT DESC
		<include refid="pageSql"></include>
	</select>

	<!-- FAQ 조회수 Update -->
	<update id="updateFaqReadCount" parameterType="Integer">
		/* TsfFaq.updateFaqReadCount */
		UPDATE TB_FAQ
		SET    READ_CNT = READ_CNT + 1
		WHERE  FAQ_SQ = #{faqSq}
	</update>

	<!-- FAQ 상세 -->
	<select id="getFaq" parameterType="Integer" resultType="Faq">
		/* TsfFaq.getFaq */
		SELECT FAQ_SQ                                         /*FAQ일련번호*/
		     , FAQ_TYPE                                       /*FAQ유형*/
		     , FN_GET_CODE_NM('G046',FAQ_TYPE) AS FAQ_TYPE_NM /*FAQ유형명*/
		     , QUESTION                                       /*질문*/
		     , ANSWER                                         /*답변*/
		FROM   TB_FAQ
		WHERE  FAQ_SQ = #{faqSq}
		AND    USE_YN = 'Y'
	</select>

</mapper>