<?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.core.biz.dao.TscMailTemplateDao">

	<!-- 메일템플릿 정보 -->
	<select id="getMailTemplate" parameterType="Integer" resultType="MailTemplate">
		/* TscMailTemplate.getMailTemplate */
		SELECT MAILT_SQ     /*메일템플릿일련번호*/
		     , MAILT_GB     /*메일템플릿구분*/
		     , MAILH_SQ     /*메일헤더일련번호*/
		     , MAILF_SQ     /*메일푸터일련번호*/
		     , MAILT_NM     /*메일템플릿명*/
		     , MAIL_CONTENT /*메일내용*/
		     , USE_YN
		FROM   TB_MAILT
		WHERE  MAILT_SQ = #{mailtSq}
	</select>
	
	<!-- 메일템플릿코너 목록 -->
	<select id="getMailTemplateCornerList" parameterType="Integer" resultType="MailTemplateCorner">
		/* TscMailTemplate.getMailTemplateCornerList */
		SELECT MAILTC_SQ   /*메일템플릿코너일련번호*/
		     , MAILT_SQ    /*메일템플릿일련번호*/
		     , MAILTC_NM   /*메일템플릿코너명*/
		     , GOODS_CPR   /*상품노출건수*/
		     , MAILTC_LINK /*메일템플릿코너링크*/
		FROM   TB_MAILTC
		WHERE  MAILT_SQ = #{mailtSq}
		AND    USE_YN = 'Y' /*사용하는넘만*/
	</select>
	
	<!-- 메일템플릿코너상품 목록 -->
	<select id="getMailTemplateCornerGoodsList" parameterType="Integer" resultType="MailTemplateGoods">
		/* TscMailTemplate.getMailTemplateCornerGoodsList */
		SELECT M.MAILTC_SQ               /*메일템플릿코너일련번호*/
		     , M.GOODS_CD                /*상품코드*/
		     , B.BRAND_ENM AS BRAND_NM   /*브랜드명*/
		     , G.GOODS_NM                /*상품명*/
		     , G.GOODS_TNM               /*상품타이틀명*/
		     , G.GOODS_STAT              /*상품상태*/
		     , G.LIST_PRICE              /*정상가*/
		     , G.CURR_PRICE              /*현재판매가*/
		     , G.DC_RATE                 /*할인율*/
		     , (SELECT MAX(SYS_IMG_NM)
		        FROM   TB_GOODS_IMG
		        WHERE  GOODS_CD = M.GOODS_CD
		        AND    DEFAULT_IMG_YN = 'Y'
		       )           AS SYS_IMG_NM /*상품이미지명*/
		     , (SELECT GROUP_CONCAT(CASE WHEN BENEFIT_GB = '10' THEN '쿠폰할인'
		                                 WHEN BENEFIT_GB = '20' THEN '무료배송'
		                                 WHEN BENEFIT_GB = '30' THEN '사은품'
		                                 WHEN BENEFIT_GB = '40' THEN '신상'
		                                 WHEN BENEFIT_GB = '50' THEN '총알배송'
		                            END  SEPARATOR ',')
		        FROM   TB_GOODS_BENEFIT
		        WHERE  GOODS_CD = M.GOODS_CD
		       )           AS BENEFITS   /*혜택(,로연결된문자열)*/
		     , M.DISP_ORD                /*노출순서*/
		FROM   TB_MAILTC_GOODS M
		     , TB_GOODS G
		     , TB_BRAND B
		WHERE  M.GOODS_CD = G.GOODS_CD
		AND    G.BRAND_CD = B.BRAND_CD
		AND    M.MAILTC_SQ = #{mailtcSq}
		ORDER  BY M.DISP_ORD
	</select>
	
	<!-- 메일템플릿 미리보기 조회 -->
	<select id="getMailTemplatePreview" parameterType="Integer" resultType="MailTemplate">
		/* TscMailTemplate.getMailTemplatePreview */
		SELECT A.MAILT_GB                        /*메일템플릿구분*/
		     , B.MAILHF_CONTENT AS MAILH_CONTENT /*헤더내용*/
		     , C.MAILHF_CONTENT AS MAILF_CONTENT /*푸터내용*/
		     , A.MAIL_CONTENT                    /*메일내용*/
             , A.MAILT_NM
		FROM   TB_MAILT A
		     , TB_MAILHF B
		     , TB_MAILHF C
		WHERE  A.MAILH_SQ = B.MAILHF_SQ /*헤더*/
		AND    A.MAILF_SQ = C.MAILHF_SQ /*푸터*/
		AND    A.MAILT_SQ = #{mailtSq}
	</select>
	
</mapper>