<?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.batch.biz.dao.TsbGoodsEpDao">
	<!-- 페이징을 위한 select절 상단 -->
	<sql id="selectForPagingHeader">
		SELECT *
		FROM (
	</sql>

	<!-- 페이징을 위한 select절 하단 -->
	<sql id="selectForPagingFooter">
		) ORIGINAL
		LIMIT #{limitStartRow} ,  #{pageSize}
	</sql>

	<!-- 상품 이미지 정보 truncate -->
	<delete id="truncateEpGoodsImage" timeout="360">
		/* TsbGoodsEp.truncateEpGoodsImage */
		TRUNCATE TABLE TB_EP_GOODS_IMG
	</delete>
	
	<!-- 상품 이미지 정보 생성 -->
	<insert id="createEpGoodsImage" parameterType="GoodsEp" timeout="360">
		/* TsbGoodsEp.createEpGoodsImage */
		INSERT INTO TB_EP_GOODS_IMG (
		       GOODS_CD
		     , IMAGE_LINK
		)
		SELECT G.GOODS_CD
		     , CONCAT(#{goodsImgUrl},GI.SYS_IMG_NM) AS IMAGE_LINK
		FROM   TB_GOODS G
		     , (
		     	SELECT GOODS_CD , COLOR_CD, MIN(SYS_IMG_NM) AS SYS_IMG_NM  FROM TB_GOODS_IMG 
				WHERE DEFAULT_IMG_YN = 'Y'
				GROUP BY GOODS_CD , COLOR_CD
		       ) GI
		WHERE  G.GOODS_CD = GI.GOODS_CD
		AND    IF(G.SELF_GOODS_YN = 'N','XX',G.MAIN_COLOR_CD) = GI.COLOR_CD
	</insert>
	
	<!-- 상품 추가 이미지 정보 truncate -->
	<delete id="truncateEpGoodsAddImage">
		/* TsbGoodsEp.truncateEpGoodsAddImage */
		TRUNCATE TABLE TB_EP_GOODS_ADD_IMG
	</delete>
	
	<!-- 상품 추가 이미지 정보 생성 -->
	<insert id="createEpGoodsAddImage" parameterType="GoodsEp" timeout="360">
		/* TsbGoodsEp.createEpGoodsAddImage */
		INSERT INTO TB_EP_GOODS_ADD_IMG (
		       GOODS_CD
		     , ADD_IMAGE_LINK
		)
		SELECT GOODS_CD
		     , GROUP_CONCAT(CONCAT(#{goodsImgUrl},SYS_IMG_NM) SEPARATOR '|') AS ADD_IMAGE_LINK
		FROM   (SELECT GI.GOODS_CD
		             , GI.SYS_IMG_NM
		             , RANK() OVER(PARTITION BY GI.GOODS_CD
		                           ORDER BY GI.DISP_ORD, GI.SYS_IMG_NM) AS RK
		        FROM   TB_GOODS G
		             , TB_GOODS_IMG GI
		        WHERE  G.GOODS_CD = GI.GOODS_CD
		        AND    IF(G.SELF_GOODS_YN = 'N','XX',G.MAIN_COLOR_CD) = GI.COLOR_CD
		        AND    GI.DEFAULT_IMG_YN = 'N'
		       ) Z
		WHERE  RK <![CDATA[<=]]> 4
		GROUP  BY GOODS_CD
	</insert>
	
	<!-- EP카드행사 정보 truncate -->
	<delete id="truncateEpCardEvent">
		/* TsbGoodsEp.truncateEpCardEvent */
		TRUNCATE TABLE TB_EP_CARD_EVENT
	</delete>
	
	<!-- EP카드행사 정보 생성 -->
	<insert id="createEpCardEvent" timeout="360">
		/* TsbGoodsEp.createEpCardEvent */
		INSERT INTO TB_EP_CARD_EVENT (
		       GOODS_CD
		     , CARD_EVENT
		)
		SELECT G.GOODS_CD
		     , GROUP_CONCAT(DISTINCT
		                    CONCAT(FN_GET_CODE_NM('G941',CPT.PRMT_TARGET_CD),'^',
		                           (G.CURR_PRICE
		                            -
		                            CASE WHEN CPC.DC_WAY = 'G240_10' /*정액할인*/ THEN CPC.DC_VAL
		                                 ELSE /*정율할인*/ CAST(G.CURR_PRICE * CPC.DC_VAL / 100 AS SIGNED INTEGER)
		                            END))
		                    SEPARATOR '|') AS CARD_EVENT
		FROM   TB_CARD_PROMOTION CP
		     , TB_CARD_PROMOTION_CONDITION CPC
		     , TB_CARD_PROMOTION_TARGET CPT
		     , (
		        SELECT G.GOODS_CD
		             , IFNULL(GBP.PC_CURR_PRICE,G.CURR_PRICE) * G.MIN_ORD_QTY AS CURR_PRICE
		        FROM   TB_GOODS G
		             , TB_GOODS_BENEFIT_PRICE GBP
		        WHERE  G.GOODS_CD = GBP.GOODS_CD
		       ) G
		WHERE  CP.CARD_PRMT_SQ = CPC.CARD_PRMT_SQ
		AND    CPC.CARD_PRMT_CDT_SQ = CPT.CARD_PRMT_CDT_SQ
		AND    CP.PRMT_GB = 'A' /*카드할인*/
		AND    CP.DC_GB = '1' /*즉시할인*/
		AND    CP.PRMT_STD <![CDATA[<=]]> DATE_FORMAT(CURRENT_DATE(),'%Y%m%d')
		AND    CP.PRMT_EDD <![CDATA[>=]]> DATE_FORMAT(CURRENT_DATE(),'%Y%m%d')
		AND    CP.DISP_YN = 'Y'
		AND    CPC.MIN_PAY_AMT <![CDATA[<]]> G.CURR_PRICE
		GROUP  BY G.GOODS_CD
	</insert>
	
	<!-- EP쿠폰 정보 truncate -->
	<delete id="truncateEpCoupon">
		/* TsbGoodsEp.truncateEpCoupon */
		TRUNCATE TABLE TB_EP_COUPON
	</delete>
	
	<!-- EP쿠폰 정보 생성 -->
	<insert id="createEpCoupon" timeout="360">
		/* TsbGoodsEp.createEpCoupon */
		INSERT INTO TB_EP_COUPON (
		       GOODS_CD
		     , COUPON
		)
		SELECT GOODS_CD
		     , CONCAT(IFNULL(NORMAL_CPN,''),IF(AFLINK_CPN11 IS NULL,'',CONCAT('^',AFLINK_CPN11)),IF(AFLINK_CPN10 IS NULL,'',CONCAT('^',AFLINK_CPN10))) AS COUPON
		FROM   (
		        SELECT CR.REF_VAL            AS GOODS_CD
		             , CASE WHEN IFNULL(CAC.CNT,0) = 0 THEN
		                        CONCAT(C.DC_PVAL,CASE WHEN C.DC_WAY = 'G240_10' THEN '원' ELSE '%' END)
		                    ELSE
		                        NULL
		               END                   AS NORMAL_CPN /*일반쿠폰*/
		             , CASE WHEN IFNULL(CAC.CNT,0) <![CDATA[>]]> 0 AND C.DC_WAY = 'G240_10' THEN
		                        C.DC_PVAL
		                    ELSE
		                        NULL
		               END                   AS AFLINK_CPN10 /*정액제휴쿠폰*/
		             , CASE WHEN IFNULL(CAC.CNT,0) <![CDATA[>]]> 0 AND C.DC_WAY = 'G240_11' THEN
		                        C.DC_PVAL
		                    ELSE
		                        NULL
		               END                   AS AFLINK_CPN11 /*정율제휴쿠폰*/
		             , CASE WHEN IFNULL(CAC.CNT,0) = 0 THEN
		                        CASE WHEN C.DC_WAY = 'G240_10' THEN C.DC_PVAL
		                             ELSE IFNULL(GBP.PC_CURR_PRICE,G.CURR_PRICE) * G.MIN_ORD_QTY * C.DC_PVAL / 100
		                        END
		                    ELSE
		                        0
		               END                   AS NCPN_DC_AMT /*일반쿠폰할인금액*/
		             , RANK() OVER(PARTITION BY CR.REF_VAL
		                           ORDER BY (CASE WHEN IFNULL(CAC.CNT,0) = 0 THEN
		                                              CASE WHEN C.DC_WAY = 'G240_10' THEN C.DC_PVAL
		                                                   ELSE IFNULL(GBP.PC_CURR_PRICE,G.CURR_PRICE) * G.MIN_ORD_QTY * C.DC_PVAL / 100
		                                              END
		                                          ELSE
		                                              0
		                                     END) DESC,
		                                    (CASE WHEN IFNULL(CAC.CNT,0) <![CDATA[>]]> 0 AND C.DC_WAY = 'G240_10' THEN
		                                              C.DC_PVAL
		                                          ELSE
		                                              0
		                                     END) DESC,
		                                    (CASE WHEN IFNULL(CAC.CNT,0) <![CDATA[>]]> 0 AND C.DC_WAY = 'G240_11' THEN
		                                              IFNULL(GBP.PC_CURR_PRICE,G.CURR_PRICE) * G.MIN_ORD_QTY * C.DC_PVAL / 100
		                                          ELSE
		                                              0
		                                     END) DESC
		                          )          AS RK
		        FROM   TB_COUPON C
		        INNER JOIN TB_COUPON_REFVAL CR ON C.CPN_ID = CR.CPN_ID
		        INNER JOIN TB_GOODS G ON CR.REF_VAL = G.GOODS_CD
		        LEFT OUTER JOIN TB_GOODS_BENEFIT_PRICE GBP ON G.GOODS_CD = GBP.GOODS_CD
		        LEFT OUTER JOIN (
		                         SELECT CPN_ID
		                              , COUNT(*) AS CNT
		                         FROM   TB_COUPON_AF_CHANNEL
		                         WHERE  AF_LINK_CD IN (SELECT AF_LINK_CD
		                                               FROM   TB_AF_LINK
		                                               WHERE  AF_CHANNEL = 'G053_02' /*네이버*/
		                                               AND    USE_YN = 'Y'
		                                              )
		                         GROUP  BY CPN_ID
		                        ) CAC ON C.CPN_ID = CAC.CPN_ID
		        WHERE  C.SITE_CD = 'G000_10'
		        AND    C.CPN_STAT = 'G232_11' /*진행쿠폰*/
		        AND    C.CPN_TYPE IN ('G230_11','G230_20') /*상품쿠폰,주문서쿠폰*/
		        AND    (
		                (C.PD_GB = 'D' AND NOW() <![CDATA[<]]> DATE_ADD(NOW(), INTERVAL C.AVAIL_DAYS DAY))
		                OR
		                (C.PD_GB = 'P' AND NOW() BETWEEN C.AVAIL_STDT AND C.AVAIL_EDDT)
		               )
		        AND    C.APPLY_SCOPE = 'I' /*개별쿠폰*/
		        AND    CR.CPN_TYPE IN ('G230_11','G230_20') /*상품쿠폰,주문서쿠폰*/
		        AND    CR.CPN_TARGET = 'G260_10' /*상품쿠폰*/
		        AND    CR.DEL_YN = 'N'
		        AND    NOT EXISTS (SELECT 1
		                           FROM   TB_COUPON_REFVAL
		                           WHERE  CPN_ID = CR.CPN_ID
		                           AND    CPN_TARGET = 'G260_14' /*제외상품*/
		                           AND    REF_VAL = CR.REF_VAL
		                           AND    DEL_YN = 'N'
		                          )
		       ) Z
		WHERE  RK = 1
		AND    (
		        NORMAL_CPN IS NOT NULL
		        OR
		        AFLINK_CPN10 IS NOT NULL
		        OR
		        AFLINK_CPN11 IS NOT NULL
		       )
	</insert>
	
	<!-- EP무이자행사 정보 truncate -->
	<delete id="truncateEpInterestFreeEvent">
		/* TsbGoodsEp.truncateEpInterestFreeEvent */
		TRUNCATE TABLE TB_EP_INTEREST_FREE_EVENT
	</delete>
	
	<!-- EP무이자행사 정보 생성 -->
	<insert id="createEpInterestFreeEvent" timeout="360">
		/* TsbGoodsEp.createEpInterestFreeEvent */
		INSERT INTO TB_EP_INTEREST_FREE_EVENT (
		       GOODS_CD
		     , INTEREST_FREE_EVENT
		)
		SELECT G.GOODS_CD
		     , GROUP_CONCAT(DISTINCT
		                    CONCAT(FN_GET_CODE_NM('G941',CPT.PRMT_TARGET_CD),'^',
		                           CPC.MIN_NO_ITRT,'~',CPC.MAX_NO_ITRT)
		                    SEPARATOR '|') AS INTEREST_FREE_EVENT /*무이자이벤트정보*/
		FROM   TB_CARD_PROMOTION CP
		     , TB_CARD_PROMOTION_CONDITION CPC
		     , TB_CARD_PROMOTION_TARGET CPT
		     , (
		        SELECT G.GOODS_CD
		             , IFNULL(GBP.PC_CURR_PRICE,G.CURR_PRICE) * G.MIN_ORD_QTY AS CURR_PRICE
		        FROM   TB_GOODS G
		             , TB_GOODS_BENEFIT_PRICE GBP
		        WHERE  G.GOODS_CD = GBP.GOODS_CD
		       ) G
		WHERE  CP.CARD_PRMT_SQ = CPC.CARD_PRMT_SQ
		AND    CPC.CARD_PRMT_CDT_SQ = CPT.CARD_PRMT_CDT_SQ
		AND    CP.PRMT_GB = 'B' /*무이자할부*/
		AND    CP.PRMT_STD <![CDATA[<=]]> DATE_FORMAT(CURRENT_DATE(),'%Y%m%d')
		AND    CP.PRMT_EDD <![CDATA[>=]]> DATE_FORMAT(CURRENT_DATE(),'%Y%m%d')
		AND    CP.DISP_YN = 'Y'
		AND    CPC.MIN_PAY_AMT <![CDATA[<]]> G.CURR_PRICE
		GROUP  BY G.GOODS_CD
	</insert>
	
	<!-- EP네이버 정보 삭제 -->
	<delete id="deleteEpNaver" parameterType="String" timeout="360">
		/* TsbGoodsEp.deleteEpNaver */
		DELETE FROM TB_EP_NAVER WHERE GB = #{gb}
	</delete>
	
	<!-- EP네이버 이전 데이터로 백업 -->
	<insert id="createPreviousEpNaver" timeout="360">
		/* TsbGoodsEp.createPreviousEpNaver */
		INSERT INTO TB_EP_NAVER (
		       GB
		     , ID
		     , TITLE
		     , PRICE_PC
		     , PRICE_MOBILE
		     , NORMAL_PRICE
		     , LINK
		     , MOBILE_LINK
		     , IMAGE_LINK
		     , ADD_IMAGE_LINK
		     , CATEGORY_NAME1
		     , CATEGORY_NAME2
		     , CATEGORY_NAME3
		     , CATEGORY_NAME4
		     , NAVER_CATEGORY
		     , GOODS_GB_NM
		     , IMPORT_FLAG
		     , PARALLEL_IMPORT
		     , ORDER_MADE
		     , PRODUCT_FLAG
		     , ADULT
		     , MANUFACTURE_DEFINE_NUMBER
		     , BRAND
		     , MAKER
		     , ORIGIN
		     , CARD_EVENT
		     , EVENT_WORDS
		     , COUPON
		     , PARTNER_COUPON_DOWNLOAD
		     , INTEREST_FREE_EVENT
		     , POINT
		     , SEARCH_TAG
		     , MINIMUM_PURCHASE_QUANTITY
		     , REVIEW_COUNT
		     , SHIPPING
		     , AGE_GROUP
		     , GENDER
		     , GOODS_STAT
		     , SELF_MALL_YN
		     , SELL_STDT
		     , SELL_EDDT
		)
		SELECT 'PREV' AS GB
		     , ID
		     , TITLE
		     , PRICE_PC
		     , PRICE_MOBILE
		     , NORMAL_PRICE
		     , LINK
		     , MOBILE_LINK
		     , IMAGE_LINK
		     , ADD_IMAGE_LINK
		     , CATEGORY_NAME1
		     , CATEGORY_NAME2
		     , CATEGORY_NAME3
		     , CATEGORY_NAME4
		     , NAVER_CATEGORY
		     , GOODS_GB_NM
		     , IMPORT_FLAG
		     , PARALLEL_IMPORT
		     , ORDER_MADE
		     , PRODUCT_FLAG
		     , ADULT
		     , MANUFACTURE_DEFINE_NUMBER
		     , BRAND
		     , MAKER
		     , ORIGIN
		     , CARD_EVENT
		     , EVENT_WORDS
		     , COUPON
		     , PARTNER_COUPON_DOWNLOAD
		     , INTEREST_FREE_EVENT
		     , POINT
		     , SEARCH_TAG
		     , MINIMUM_PURCHASE_QUANTITY
		     , REVIEW_COUNT
		     , SHIPPING
		     , AGE_GROUP
		     , GENDER
		     , GOODS_STAT
		     , SELF_MALL_YN
		     , SELL_STDT
		     , SELL_EDDT
		FROM   TB_EP_NAVER
		WHERE  GB = 'LAST'
	</insert>
	
	<!-- EP네이버 현재 데이터 생성 -->
	<insert id="createCurrentEpNaver" parameterType="GoodsEp" timeout="1000">
		/* TsbGoodsEp.createCurrentEpNaver */
		INSERT INTO TB_EP_NAVER (
		       GB
		     , ID
		     , TITLE
		     , PRICE_PC
		     , PRICE_MOBILE
		     , NORMAL_PRICE
		     , LINK
		     , MOBILE_LINK
		     , IMAGE_LINK
		     , ADD_IMAGE_LINK
		     , CATEGORY_NAME1
		     , CATEGORY_NAME2
		     , CATEGORY_NAME3
		     , CATEGORY_NAME4
		     , NAVER_CATEGORY
		     , GOODS_GB_NM
		     , IMPORT_FLAG
		     , PARALLEL_IMPORT
		     , ORDER_MADE
		     , PRODUCT_FLAG
		     , ADULT
		     , MANUFACTURE_DEFINE_NUMBER
		     , BRAND
		     , MAKER
		     , ORIGIN
		     , CARD_EVENT
		     , EVENT_WORDS
		     , COUPON
		     , PARTNER_COUPON_DOWNLOAD
		     , INTEREST_FREE_EVENT
		     , POINT
		     , SEARCH_TAG
		     , MINIMUM_PURCHASE_QUANTITY
		     , REVIEW_COUNT
		     , SHIPPING
		     , AGE_GROUP
		     , GENDER
		     , GOODS_STAT
		     , SELF_MALL_YN
		     , SELL_STDT
		     , SELL_EDDT
		)
		SELECT 'CURR'                                                 AS GB                       /*구분(PREV:이전, CURR:현재)*/
		     , G.GOODS_CD                                             AS ID                       /*상품ID*/
		     , SUBSTRING(CONCAT('[',CASE WHEN B.DISP_NM_LANG = 'EN' THEN B.BRAND_ENM ELSE B.BRAND_KNM END,'] ',
		                        G.GOODS_NM,
		                        IFNULL(G.GOODS_NUM,'')),1,100)        AS TITLE                    /*상품명*/
		     , IFNULL(GBP.PC_CURR_PRICE,G.CURR_PRICE) * G.MIN_ORD_QTY AS PRICE_PC                 /*즉시할인이적용된가격*/
		     , IFNULL(GBP.MO_CURR_PRICE,G.CURR_PRICE) * G.MIN_ORD_QTY AS PRICE_MOBILE             /*즉시할인이적용된가격*/
		     , G.LIST_PRICE                                           AS NORMAL_PRICE             /*정상가*/
		     , CONCAT(#{goodsDtlUrl},G.GOODS_CD)                      AS LINK                     /*PC상세URL*/
		     , CONCAT(#{goodsDtlUrl},G.GOODS_CD)                      AS MOBILE_LINK              /*모바일상세URL*/
		     , GI.IMAGE_LINK                                                                      /*이미지URL*/
		     , GAI.ADD_IMAGE_LINK                                                                 /*추가이미지URL(4개까지. |로 구분)*/
		     , SUBSTRING_INDEX(I.ITEMKIND_NM,'>',1)                   AS CATEGORY_NAME1           /*카테고리명1*/
		     , CASE WHEN SUBSTRING_INDEX(SUBSTRING_INDEX(I.ITEMKIND_NM,'>',1),'>',-1) = SUBSTRING_INDEX(SUBSTRING_INDEX(I.ITEMKIND_NM,'>',2),'>',-1) THEN
		                NULL
		            ELSE
		                SUBSTRING_INDEX(SUBSTRING_INDEX(I.ITEMKIND_NM,'>',2),'>',-1)
		       END                                                    AS CATEGORY_NAME2           /*카테고리명2*/
		     , CASE WHEN SUBSTRING_INDEX(SUBSTRING_INDEX(I.ITEMKIND_NM,'>',2),'>',-1) = SUBSTRING_INDEX(SUBSTRING_INDEX(I.ITEMKIND_NM,'>',3),'>',-1) THEN
		                NULL
		            ELSE
		                SUBSTRING_INDEX(SUBSTRING_INDEX(I.ITEMKIND_NM,'>',3),'>',-1)
		       END                                                    AS CATEGORY_NAME3           /*카테고리명3*/
		     , CASE WHEN SUBSTRING_INDEX(SUBSTRING_INDEX(I.ITEMKIND_NM,'>',3),'>',-1) = SUBSTRING_INDEX(SUBSTRING_INDEX(I.ITEMKIND_NM,'>',4),'>',-1) THEN
		                NULL
		            ELSE
		                SUBSTRING_INDEX(SUBSTRING_INDEX(I.ITEMKIND_NM,'>',4),'>',-1)
		       END                                                    AS CATEGORY_NAME4            /*카테고리명4*/
		     , EC.EP_CATE_CD                                          AS NAVER_CATEGORY            /*네이버카테고리*/
		     , CC1.CD_NM                                              AS GOODS_GB_NM               /*상품구분명*/
		     , G.FOREIGN_BUY_YN                                       AS IMPORT_FLAG               /*해외구매대행여부*/
		     , G.PARALLEL_IMPORT_YN                                   AS PARALLEL_IMPORT           /*병행수입여부*/
		     , G.ORDER_MADE_YN                                        AS ORDER_MADE                /*주문제작상품여부*/
		     , IF(GRS.GOODS_CD IS NULL,NULL,'예약판매')               AS PRODUCT_FLAG              /*예약판매*/
		     , G.ADULT_YN                                             AS ADULT                     /*성인여부*/
		     , G.GOODS_NUM                                            AS MANUFACTURE_DEFINE_NUMBER /*제품코드*/
		     , IF(B.DISP_NM_LANG = 'EN',B.BRAND_ENM,B.BRAND_KNM)      AS BRAND                     /*브랜드명*/
		     , SUBSTRING(GNI.NI_CONTENT,1,50)                         AS MAKER                     /*제조사*/
		     , CC2.CD_NM                                              AS ORIGIN                    /*원산지*/
		     , CE.CARD_EVENT                                                                       /*카드행사*/
		     , G.GOODS_TNM                                            AS EVENT_WORDS               /*상품셀링문구*/
		     , TEC.COUPON                                                                          /*쿠폰*/
		     , IF(TEC.COUPON IS NULL,NULL,'Y')                        AS PARTNER_COUPON_DOWNLOAD   /*쿠폰다운로드여부*/
		     , IFE.INTEREST_FREE_EVENT                                                             /*무이자행사*/
		     , CONCAT('스타일포인트','^',
		              CAST(IFNULL(GBP.PC_CURR_PRICE,G.CURR_PRICE) * G.MIN_ORD_QTY * G.PNT_PRATE AS SIGNED INTEGER)
		             )                                                AS POINT                     /*포인트*/
		     , SUBSTRING(CONCAT(IFNULL(G.GOODS_SNM,''),
		                        CASE WHEN LENGTH(IFNULL(G.GOODS_SNM1,'')) = 0 THEN
		                                 ''
		                             ELSE
		                                 '|'
		                        END,
		                        IFNULL(G.GOODS_SNM1,'')
		                       ),1,100)                               AS SEARCH_TAG                /*검색태그*/
		     , CASE WHEN G.MIN_ORD_QTY > 0 THEN
		                G.MIN_ORD_QTY
		            ELSE
		                NULL
		       END                                                    AS MINIMUM_PURCHASE_QUANTITY /*최소구매금액*/
		     , IFNULL(GS.REVIEW_REG_CNT,0)                            AS REVIEW_COUNT              /*상품평수*/
		     , IFNULL(CASE WHEN DFP.DELV_FEE_CRITE = 'G078_20' /*무료*/ THEN
		                       0
		                   ELSE /*조건부무료 또는 유료*/
		                       CASE WHEN DFP.MIN_ORD_AMT <![CDATA[<=]]> IFNULL(GBP.PC_CURR_PRICE,G.CURR_PRICE) * G.MIN_ORD_QTY THEN
		                                0
		                            ELSE
		                                DFP.DELV_FEE
		                       END
		              END,0)                                          AS SHIPPING                  /*배송료*/
		     , CASE WHEN SUBSTRING(I.ITEMKIND_CD,1,2) = '07' THEN '유아'
		            WHEN SUBSTRING(I.ITEMKIND_CD,1,2) IN ('08','09','10') THEN '아동'
		            WHEN SUBSTRING(I.ITEMKIND_CD,1,2) IN ('11','12','13') THEN '청소년'
		            ELSE '성인'
		       END                                                    AS AGE_GROUP                 /*나이*/
		     , CASE WHEN G.SEX_GB = 'G007_F' THEN '여성'
		            WHEN G.SEX_GB = 'G007_M' THEN '남성'
		            ELSE '남여공용'
		       END                                                    AS GENDER                    /*성별*/
		     , G.GOODS_STAT
		     , G.SELF_MALL_YN
		     , G.SELL_STDT
		     , G.SELL_EDDT
		FROM   TB_GOODS G
		INNER JOIN TB_BRAND B ON G.BRAND_CD = B.BRAND_CD
		INNER JOIN TB_ITEMKIND I ON G.ITEMKIND_CD = I.ITEMKIND_CD
		INNER JOIN TB_DELV_FEE_POLICY DFP ON G.DELV_FEE_CD = DFP.DELV_FEE_CD 
		                                 AND G.SUPPLY_COMP_CD = DFP.SUPPLY_COMP_CD
		INNER JOIN TB_EP_GOODS_IMG GI ON G.GOODS_CD = GI.GOODS_CD
		LEFT OUTER JOIN TB_GOODS_BENEFIT_PRICE GBP ON G.GOODS_CD = GBP.GOODS_CD
		LEFT OUTER JOIN TB_GOODS_SUMMARY GS ON G.GOODS_CD = GS.GOODS_CD
		LEFT OUTER JOIN TB_EP_GOODS_ADD_IMG GAI ON G.GOODS_CD = GAI.GOODS_CD
		LEFT OUTER JOIN (
		                 SELECT ITEMKIND_CD
		                      , MIN(EP_CATE_CD) AS EP_CATE_CD
		                 FROM   TB_EP_CATE
		                 WHERE  EP_GB = '10' /*네이버*/
		                 AND    USE_YN = 'Y'
		                 GROUP  BY ITEMKIND_CD
		                ) EC ON G.ITEMKIND_CD = EC.ITEMKIND_CD
		LEFT OUTER JOIN TB_GOODS_RES_SELL GRS ON G.GOODS_CD = GRS.GOODS_CD
		                                     AND GRS.DELV_RES_DT >= NOW()
		                                     AND GRS.USE_YN = 'Y'
		LEFT OUTER JOIN TB_EP_CARD_EVENT CE ON G.GOODS_CD = CE.GOODS_CD
		LEFT OUTER JOIN TB_EP_COUPON TEC ON G.GOODS_CD = TEC.GOODS_CD
		LEFT OUTER JOIN TB_EP_INTEREST_FREE_EVENT IFE ON G.GOODS_CD = IFE.GOODS_CD
		LEFT OUTER JOIN TB_GOODS_NOTI_INFO GNI ON G.GOODS_CD = GNI.GOODS_CD
		                                      AND GNI.NI_ITEM_CD = 'G005_005' /*제조사*/
		LEFT OUTER JOIN TB_COMMON_CODE CC1 ON G.GOODS_GB = CC1.CD
		                                 AND CC1.CD_GB = 'G073'
		LEFT OUTER JOIN TB_COMMON_CODE CC2 ON G.ORIGIN_CD = CC2.CD
		                                  AND CC2.CD_GB = 'G076'
		WHERE  1 = 1
		<choose>
		    <when test='epType == "SUMMARY"'> <!-- 요약EP -->
		AND    G.UPD_DT >= DATE_ADD(NOW(), INTERVAL -7 HOUR)
		    </when>
		    <otherwise> <!-- 전체EP -->
		AND    G.GOODS_STAT = 'G008_90' /*승인완료상품*/
		AND    G.SELF_MALL_YN = 'Y' /*몰노출상품*/
		AND    G.SELL_STDT <![CDATA[<=]]> NOW() /*유효한 판매기간*/
		AND    G.SELL_EDDT <![CDATA[>=]]> NOW() /*유효한 판매기간*/
		AND    G.ADULT_YN = 'N' /*성인상품아닌넘만*/
		    </otherwise>
		</choose>
		AND    NOT EXISTS (SELECT 1
		                   FROM   TB_GOODS_EP_SKIP
		                   WHERE  GOODS_CD = G.GOODS_CD
		                   AND    NOW() BETWEEN APPLY_STDT AND APPLY_EDDT
		                  )
	</insert>
	
	<!-- 최종 EP네이버 생성 -->
	<insert id="createLastEpNaver" parameterType="GoodsEp" timeout="360">
		/* TsbGoodsEp.createLastEpNaver */
		INSERT INTO TB_EP_NAVER (
		       GB
		     , ID
		     , TITLE
		     , PRICE_PC
		     , PRICE_MOBILE
		     , NORMAL_PRICE
		     , LINK
		     , MOBILE_LINK
		     , IMAGE_LINK
		     , ADD_IMAGE_LINK
		     , CATEGORY_NAME1
		     , CATEGORY_NAME2
		     , CATEGORY_NAME3
		     , CATEGORY_NAME4
		     , NAVER_CATEGORY
		     , GOODS_GB_NM
		     , IMPORT_FLAG
		     , PARALLEL_IMPORT
		     , ORDER_MADE
		     , PRODUCT_FLAG
		     , ADULT
		     , MANUFACTURE_DEFINE_NUMBER
		     , BRAND
		     , MAKER
		     , ORIGIN
		     , CARD_EVENT
		     , EVENT_WORDS
		     , COUPON
		     , PARTNER_COUPON_DOWNLOAD
		     , INTEREST_FREE_EVENT
		     , POINT
		     , SEARCH_TAG
		     , MINIMUM_PURCHASE_QUANTITY
		     , REVIEW_COUNT
		     , SHIPPING
		     , AGE_GROUP
		     , GENDER
		     , GOODS_STAT
		     , SELF_MALL_YN
		     , SELL_STDT
		     , SELL_EDDT
		     , UPD_GB
		     , UPDATE_TIME
		)
		SELECT 'LAST'                                 AS GB
		     , ID
		     , TITLE
		     , PRICE_PC
		     , PRICE_MOBILE
		     , NORMAL_PRICE
		     , LINK
		     , MOBILE_LINK
		     , IMAGE_LINK
		     , ADD_IMAGE_LINK
		     , CATEGORY_NAME1
		     , CATEGORY_NAME2
		     , CATEGORY_NAME3
		     , CATEGORY_NAME4
		     , NAVER_CATEGORY
		     , GOODS_GB_NM
		     , IMPORT_FLAG
		     , PARALLEL_IMPORT
		     , ORDER_MADE
		     , PRODUCT_FLAG
		     , ADULT
		     , MANUFACTURE_DEFINE_NUMBER
		     , BRAND
		     , MAKER
		     , ORIGIN
		     , CARD_EVENT
		     , EVENT_WORDS
		     , COUPON
		     , PARTNER_COUPON_DOWNLOAD
		     , INTEREST_FREE_EVENT
		     , POINT
		     , SEARCH_TAG
		     , MINIMUM_PURCHASE_QUANTITY
		     , REVIEW_COUNT
		     , SHIPPING
		     , AGE_GROUP
		     , GENDER
		     , GOODS_STAT
		     , SELF_MALL_YN
		     , SELL_STDT
		     , SELL_EDDT
		     , UPD_GB
		     , DATE_FORMAT(NOW(),'%Y-%m-%d %H:%i:%S') AS UPDATE_TIME /*변경일시*/
		FROM   (
		        /*신규 목록*/
		        SELECT ID
		             , TITLE
		             , PRICE_PC
		             , PRICE_MOBILE
		             , NORMAL_PRICE
		             , LINK
		             , MOBILE_LINK
		             , IMAGE_LINK
		             , ADD_IMAGE_LINK
		             , CATEGORY_NAME1
		             , CATEGORY_NAME2
		             , CATEGORY_NAME3
		             , CATEGORY_NAME4
		             , NAVER_CATEGORY
		             , GOODS_GB_NM
		             , IMPORT_FLAG
		             , PARALLEL_IMPORT
		             , ORDER_MADE
		             , PRODUCT_FLAG
		             , ADULT
		             , MANUFACTURE_DEFINE_NUMBER
		             , BRAND
		             , MAKER
		             , ORIGIN
		             , CARD_EVENT
		             , EVENT_WORDS
		             , COUPON
		             , PARTNER_COUPON_DOWNLOAD
		             , INTEREST_FREE_EVENT
		             , POINT
		             , SEARCH_TAG
		             , MINIMUM_PURCHASE_QUANTITY
		             , REVIEW_COUNT
		             , SHIPPING
		             , AGE_GROUP
		             , GENDER
		             , GOODS_STAT
		             , SELF_MALL_YN
		             , SELL_STDT
		             , SELL_EDDT
		             , 'I'                         AS UPD_GB /*변경구분*/
		        FROM   TB_EP_NAVER X
		        WHERE  GB = 'CURR' /*현재데이터*/
		        <if test='epType == "SUMMARY"'> <!-- 요약EP -->
		        AND    NOT EXISTS (SELECT 1
		                           FROM   TB_EP_NAVER
		                           WHERE  GB = 'PREV' /*이전백업데이터*/
		                           AND    ID = X.ID
		                          )
		        </if>
		        <if test='epType == "SUMMARY"'> <!-- 요약EP -->
		        UNION ALL
		        /*변경 목록*/
		        SELECT X.ID
		             , X.TITLE
		             , X.PRICE_PC
		             , X.PRICE_MOBILE
		             , X.NORMAL_PRICE
		             , X.LINK
		             , X.MOBILE_LINK
		             , X.IMAGE_LINK
		             , X.ADD_IMAGE_LINK
		             , X.CATEGORY_NAME1
		             , X.CATEGORY_NAME2
		             , X.CATEGORY_NAME3
		             , X.CATEGORY_NAME4
		             , X.NAVER_CATEGORY
		             , X.GOODS_GB_NM
		             , X.IMPORT_FLAG
		             , X.PARALLEL_IMPORT
		             , X.ORDER_MADE
		             , X.PRODUCT_FLAG
		             , X.ADULT
		             , X.MANUFACTURE_DEFINE_NUMBER
		             , X.BRAND
		             , X.MAKER
		             , X.ORIGIN
		             , X.CARD_EVENT
		             , X.EVENT_WORDS
		             , X.COUPON
		             , X.PARTNER_COUPON_DOWNLOAD
		             , X.INTEREST_FREE_EVENT
		             , X.POINT
		             , X.SEARCH_TAG
		             , X.MINIMUM_PURCHASE_QUANTITY
		             , X.REVIEW_COUNT
		             , X.SHIPPING
		             , X.AGE_GROUP
		             , X.GENDER
		             , X.GOODS_STAT
		             , X.SELF_MALL_YN
		             , X.SELL_STDT
		             , X.SELL_EDDT
		             , 'U'                         AS UPD_GB /*변경구분*/
		        FROM   TB_EP_NAVER X
		             , TB_EP_NAVER Y
		        WHERE  X.ID = Y.ID
		        AND    X.GB = 'CURR' /*현재데이터*/
		        AND    Y.GB = 'PREV' /*이전백업데이터*/
		        AND    (
		                X.PRICE_PC != X.PRICE_PC OR
		                X.PRICE_MOBILE != X.PRICE_MOBILE OR
		                X.NORMAL_PRICE != X.NORMAL_PRICE OR
		                X.LINK != X.LINK OR
		                X.MOBILE_LINK != X.MOBILE_LINK OR
		                X.IMAGE_LINK != X.IMAGE_LINK OR
		                X.ADD_IMAGE_LINK != X.ADD_IMAGE_LINK OR
		                X.CATEGORY_NAME1 != X.CATEGORY_NAME1 OR
		                X.CATEGORY_NAME2 != X.CATEGORY_NAME2 OR
		                X.CATEGORY_NAME3 != X.CATEGORY_NAME3 OR
		                X.CATEGORY_NAME4 != X.CATEGORY_NAME4 OR
		                X.NAVER_CATEGORY != X.NAVER_CATEGORY OR
		                X.GOODS_GB_NM != X.GOODS_GB_NM OR
		                X.IMPORT_FLAG != X.IMPORT_FLAG OR
		                X.PARALLEL_IMPORT != X.PARALLEL_IMPORT OR
		                X.ORDER_MADE != X.ORDER_MADE OR
		                X.PRODUCT_FLAG != X.PRODUCT_FLAG OR
		                X.ADULT != X.ADULT OR
		                X.MANUFACTURE_DEFINE_NUMBER != X.MANUFACTURE_DEFINE_NUMBER OR
		                X.BRAND != X.BRAND OR
		                X.MAKER != X.MAKER OR
		                X.ORIGIN != X.ORIGIN OR
		                X.CARD_EVENT != X.CARD_EVENT OR
		                X.EVENT_WORDS != X.EVENT_WORDS OR
		                X.COUPON != X.COUPON OR
		                X.PARTNER_COUPON_DOWNLOAD != X.PARTNER_COUPON_DOWNLOAD OR
		                X.INTEREST_FREE_EVENT != X.INTEREST_FREE_EVENT OR
		                X.POINT != X.POINT OR
		                X.SEARCH_TAG != X.SEARCH_TAG OR
		                X.MINIMUM_PURCHASE_QUANTITY != X.MINIMUM_PURCHASE_QUANTITY OR
		                X.REVIEW_COUNT != X.REVIEW_COUNT OR
		                X.SHIPPING != X.SHIPPING OR
		                X.AGE_GROUP != X.AGE_GROUP OR
		                X.GENDER != X.GENDER
		               )
		        UNION ALL
		        /*삭제된 목록*/
		        SELECT X.ID
		             , X.TITLE
		             , X.PRICE_PC
		             , X.PRICE_MOBILE
		             , X.NORMAL_PRICE
		             , X.LINK
		             , X.MOBILE_LINK
		             , X.IMAGE_LINK
		             , X.ADD_IMAGE_LINK
		             , X.CATEGORY_NAME1
		             , X.CATEGORY_NAME2
		             , X.CATEGORY_NAME3
		             , X.CATEGORY_NAME4
		             , X.NAVER_CATEGORY
		             , X.GOODS_GB_NM
		             , X.IMPORT_FLAG
		             , X.PARALLEL_IMPORT
		             , X.ORDER_MADE
		             , X.PRODUCT_FLAG
		             , X.ADULT
		             , X.MANUFACTURE_DEFINE_NUMBER
		             , X.BRAND
		             , X.MAKER
		             , X.ORIGIN
		             , X.CARD_EVENT
		             , X.EVENT_WORDS
		             , X.COUPON
		             , X.PARTNER_COUPON_DOWNLOAD
		             , X.INTEREST_FREE_EVENT
		             , X.POINT
		             , X.SEARCH_TAG
		             , X.MINIMUM_PURCHASE_QUANTITY
		             , X.REVIEW_COUNT
		             , X.SHIPPING
		             , X.AGE_GROUP
		             , X.GENDER
		             , X.GOODS_STAT
		             , X.SELF_MALL_YN
		             , X.SELL_STDT
		             , X.SELL_EDDT
		             , 'D'                         AS UPD_GB /*변경구분*/
		        FROM   TB_EP_NAVER X
		             , TB_EP_NAVER Y
		        WHERE  X.ID = Y.ID
		        AND    X.GB = 'CURR' /*현재데이터*/
		        AND    Y.GB = 'PREV' /*이전백업데이터*/
		        AND    (
		                (Y.GOODS_STAT != 'G008_70' AND X.GOODS_STAT = 'G008_70')
		                OR
		                (Y.SELF_MALL_YN = 'Y' AND X.SELF_MALL_YN = 'N')
		                OR
		                (Y.SELL_EDDT != X.SELL_EDDT AND Y.SELL_EDDT <![CDATA[<]]> NOW())
		               )
		        </if>
		       ) X
	</insert>

	<!-- 네이버 EP 총건수 -->
	<select id="getNaverEpTotalCount" resultType="int">
		/* TsbGoodsEp.getNaverEpTotalCount */
		SELECT COUNT(1)
		FROM   TB_EP_NAVER
		WHERE  GB = 'LAST'
	</select>
	
	<!-- 네이버 EP 목록 -->
	<select id="getNaverEpList" resultType="GoodsEp" timeout="600">
		/* TsbGoodsEp.getNaverEpList */
		SELECT IFNULL(ID,'')                        AS ID
		     , IFNULL(TITLE,'')                     AS TITLE
		     , PRICE_PC
		     , PRICE_MOBILE
		     , NORMAL_PRICE
		     , IFNULL(LINK,'')                      AS LINK
		     , IFNULL(MOBILE_LINK,'')               AS MOBILE_LINK
		     , IFNULL(IMAGE_LINK,'')                AS IMAGE_LINK
		     , IFNULL(ADD_IMAGE_LINK,'')            AS ADD_IMAGE_LINK
		     , IFNULL(CATEGORY_NAME1,'')            AS CATEGORY_NAME1
		     , IFNULL(CATEGORY_NAME2,'')            AS CATEGORY_NAME2
		     , IFNULL(CATEGORY_NAME3,'')            AS CATEGORY_NAME3
		     , IFNULL(CATEGORY_NAME4,'')            AS CATEGORY_NAME4
		     , IFNULL(NAVER_CATEGORY,'')            AS NAVER_CATEGORY
		     , IFNULL(GOODS_GB_NM,'')               AS GOODS_GB_NM
		     , IFNULL(IMPORT_FLAG,'')               AS IMPORT_FLAG
		     , IFNULL(PARALLEL_IMPORT,'')           AS PARALLEL_IMPORT
		     , IFNULL(ORDER_MADE,'')                AS ORDER_MADE
		     , IFNULL(PRODUCT_FLAG,'')              AS PRODUCT_FLAG
		     , IFNULL(ADULT,'')                     AS ADULT
		     , IFNULL(MANUFACTURE_DEFINE_NUMBER,'') AS MANUFACTURE_DEFINE_NUMBER
		     , IFNULL(BRAND,'')                     AS BRAND
		     , IFNULL(MAKER,'')                     AS MAKER
		     , IFNULL(ORIGIN,'')                    AS ORIGIN
		     , IFNULL(CARD_EVENT,'')                AS CARD_EVENT
		     , IFNULL(EVENT_WORDS,'')               AS EVENT_WORDS
		     , IFNULL(COUPON,'')                    AS COUPON
		     , IFNULL(PARTNER_COUPON_DOWNLOAD,'')   AS PARTNER_COUPON_DOWNLOAD
		     , IFNULL(INTEREST_FREE_EVENT,'')       AS INTEREST_FREE_EVENT
		     , IFNULL(POINT,'')                     AS POINT
		     , IFNULL(SEARCH_TAG,'')                AS SEARCH_TAG
		     , IFNULL(MINIMUM_PURCHASE_QUANTITY,'') AS MINIMUM_PURCHASE_QUANTITY
		     , REVIEW_COUNT
		     , IFNULL(SHIPPING,'')                  AS SHIPPING
		     , IFNULL(AGE_GROUP,'')                 AS AGE_GROUP
		     , IFNULL(GENDER,'')                    AS GENDER
		     , UPD_GB
		     , UPDATE_TIME
		FROM   TB_EP_NAVER
		WHERE  GB = 'LAST'
	</select>

	<!-- 네이버 EP 페이징 목록 -->
	<select id="getNaverEpPagingList" resultType="GoodsEp" parameterType="GoodsEp" timeout="600">
		/* TsbGoodsEp.getNaverEpPaginList */
		<include refid="selectForPagingHeader"/>
		SELECT IFNULL(ID,'')                        AS ID
		     , IFNULL(TITLE,'')                     AS TITLE
		     , PRICE_PC
		     , PRICE_MOBILE
		     , NORMAL_PRICE
		     , IFNULL(LINK,'')                      AS LINK
		     , IFNULL(MOBILE_LINK,'')               AS MOBILE_LINK
		     , IFNULL(IMAGE_LINK,'')                AS IMAGE_LINK
		     , IFNULL(ADD_IMAGE_LINK,'')            AS ADD_IMAGE_LINK
		     , IFNULL(CATEGORY_NAME1,'')            AS CATEGORY_NAME1
		     , IFNULL(CATEGORY_NAME2,'')            AS CATEGORY_NAME2
		     , IFNULL(CATEGORY_NAME3,'')            AS CATEGORY_NAME3
		     , IFNULL(CATEGORY_NAME4,'')            AS CATEGORY_NAME4
		     , IFNULL(NAVER_CATEGORY,'')            AS NAVER_CATEGORY
		     , IFNULL(GOODS_GB_NM,'')               AS GOODS_GB_NM
		     , IFNULL(IMPORT_FLAG,'')               AS IMPORT_FLAG
		     , IFNULL(PARALLEL_IMPORT,'')           AS PARALLEL_IMPORT
		     , IFNULL(ORDER_MADE,'')                AS ORDER_MADE
		     , IFNULL(PRODUCT_FLAG,'')              AS PRODUCT_FLAG
		     , IFNULL(ADULT,'')                     AS ADULT
		     , IFNULL(MANUFACTURE_DEFINE_NUMBER,'') AS MANUFACTURE_DEFINE_NUMBER
		     , IFNULL(BRAND,'')                     AS BRAND
		     , IFNULL(MAKER,'')                     AS MAKER
		     , IFNULL(ORIGIN,'')                    AS ORIGIN
		     , IFNULL(CARD_EVENT,'')                AS CARD_EVENT
		     , IFNULL(EVENT_WORDS,'')               AS EVENT_WORDS
		     , IFNULL(COUPON,'')                    AS COUPON
		     , IFNULL(PARTNER_COUPON_DOWNLOAD,'')   AS PARTNER_COUPON_DOWNLOAD
		     , IFNULL(INTEREST_FREE_EVENT,'')       AS INTEREST_FREE_EVENT
		     , IFNULL(POINT,'')                     AS POINT
		     , IFNULL(SEARCH_TAG,'')                AS SEARCH_TAG
		     , IFNULL(MINIMUM_PURCHASE_QUANTITY,'') AS MINIMUM_PURCHASE_QUANTITY
		     , REVIEW_COUNT
		     , IFNULL(SHIPPING,'')                  AS SHIPPING
		     , IFNULL(AGE_GROUP,'')                 AS AGE_GROUP
		     , IFNULL(GENDER,'')                    AS GENDER
		     , UPD_GB
		     , UPDATE_TIME
		FROM   TB_EP_NAVER
		WHERE  GB = 'LAST'
		ORDER  BY ID
		<include refid="selectForPagingFooter"/>
	</select>
	
	<!-- 네이버 판매지수EP 목록 -->
	<select id="getNaverSellEpList" resultType="GoodsEp">
		/* TsbGoodsEp.getNaverSellEpList */
		SELECT DATE_FORMAT(DATE_ADD(CURRENT_DATE(),INTERVAL -1 DAY),'%Y-%m-%d') AS DT          /*일자*/
		     , OD.GOODS_CD                                                      AS ID          /*상품ID*/
		     , SUM(OD.ORD_QTY - OD.CNCL_RTN_QTY)                                AS SALE_COUNT  /*판매수량*/
		     , SUM(OD.ORD_AMT - OD.CNCL_RTN_AMT)                                AS SALE_PRICE  /*판매금액*/
		     , COUNT(DISTINCT OD.ORD_NO)                                        AS ORDER_COUNT /*주문수량*/
		FROM   TB_ORDER O
		     , TB_ORDER_DETAIL OD
		WHERE  O.ORD_NO = OD.ORD_NO
		AND    O.PAY_DT <![CDATA[>]]> DATE_ADD(CURRENT_DATE(), INTERVAL -2 DAY)
		AND    O.PAY_DT <![CDATA[<]]> CURRENT_DATE()
		AND    OD.ORD_DTL_STAT IN ('G013_20','G013_30','G013_35','G013_40','G013_50','G013_55','G013_60','G013_70')
		AND    OD.AF_LINK_CD IN (SELECT AF_LINK_CD
		                         FROM   TB_AF_LINK
		                         WHERE  AF_CHANNEL = 'G053_02' /*네이버*/
		                         AND    USE_YN = 'Y'
		                        )
		GROUP  BY DATE_FORMAT(DATE_ADD(CURRENT_DATE(), INTERVAL -1 DAY),'%Y-%m-%d'), OD.GOODS_CD
	</select>
	
	<!-- EP다음 정보 삭제 -->
	<delete id="deleteEpDaum" parameterType="String">
		/* TsbGoodsEp.deleteEpDaum */
		DELETE FROM TB_EP_DAUM WHERE GB = #{gb}
	</delete>
	
	<!-- EP다음 이전 데이터로 백업 -->
	<insert id="createPreviousEpDaum" timeout="360">
		/* TsbGoodsEp.createPreviousEpDaum */
		INSERT INTO TB_EP_DAUM (
		       GB
		     , MAPID
		     , LPRICE
		     , PRICE
		     , MPRIC
		     , PNAME
		     , PGURL
		     , IGURL
		     , CATE1
		     , CAID1
		     , CATE2
		     , CAID2
		     , CATE3
		     , CAID3
		     , CATE4
		     , CAID4
		     , MODEL
		     , BRAND
		     , MAKER
		     , COUPON
		     , MCOUPON
		     , PCARD
		     , POINT
		     , DELIV
		     , DELIVTERM
		     , RATING
		     , REVCT
		     , EVENT
		     , CARDDN
		     , CARDP
		     , ADULT
		     , PUBDATE
		     , GOODS_STAT
		     , SELF_MALL_YN
		     , SELL_STDT
		     , SELL_EDDT
		)
		SELECT 'PREV' AS GB
		     , MAPID
		     , LPRICE
		     , PRICE
		     , MPRIC
		     , PNAME
		     , PGURL
		     , IGURL
		     , CATE1
		     , CAID1
		     , CATE2
		     , CAID2
		     , CATE3
		     , CAID3
		     , CATE4
		     , CAID4
		     , MODEL
		     , BRAND
		     , MAKER
		     , COUPON
		     , MCOUPON
		     , PCARD
		     , POINT
		     , DELIV
		     , DELIVTERM
		     , RATING
		     , REVCT
		     , EVENT
		     , CARDDN
		     , CARDP
		     , ADULT
		     , PUBDATE
		     , GOODS_STAT
		     , SELF_MALL_YN
		     , SELL_STDT
		     , SELL_EDDT
		FROM   TB_EP_DAUM
		WHERE  GB = 'LAST'
	</insert>
	
	<!-- EP다음 현재 데이터 생성 -->
	<insert id="createCurrentEpDaum_BACK" parameterType="GoodsEp" timeout="360">
		/* TsbGoodsEp.createCurrentEpDaum */
		WITH GOODS_DATA AS (
			SELECT G.GOODS_CD
			     , G.ITEMKIND_CD
			     , G.GOODS_GB
			     , G.ORIGIN_CD
			     , G.LIST_PRICE
			     , G.CURR_PRICE
			     , G.MIN_ORD_QTY
			     , G.FOREIGN_BUY_YN
			     , G.GOODS_NM
			     , G.GOODS_NUM
			     , G.PNT_PRATE
			     , G.SELF_GOODS_YN
			     , G.ADULT_YN
			     , G.GOODS_TNM
			     , G.REG_DT
			     , G.GOODS_STAT
				 , G.SELF_MALL_YN
				 , G.SELL_STDT
				 , G.SELL_EDDT
			     , B.BRAND_ENM
			     , B.BRAND_KNM
			     , B.DISP_NM_LANG
			     , I.ITEMKIND_NM
			     , DFP.DELV_FEE_CRITE
			     , DFP.DELV_FEE
			     , DFP.MIN_ORD_AMT
			FROM   TB_DELV_FEE_POLICY DFP
			INNER JOIN TB_GOODS G ON G.DELV_FEE_CD = DFP.DELV_FEE_CD
			                     AND G.SUPPLY_COMP_CD = DFP.SUPPLY_COMP_CD
			INNER JOIN TB_BRAND B ON G.BRAND_CD = B.BRAND_CD
			INNER JOIN TB_ITEMKIND I ON G.ITEMKIND_CD = I.ITEMKIND_CD
			WHERE  1 = 1
			<choose>
			    <when test='epType == "SUMMARY"'> <!-- 요약EP -->
			AND    G.UPD_DT >= DATE_ADD(NOW(), INTERVAL -7 HOUR)
			    </when>
			    <otherwise> <!-- 전체EP -->
			AND    G.GOODS_STAT = 'G008_90' /*승인완료상품*/
			AND    G.SELF_MALL_YN = 'Y' /*몰노출상품*/
			AND    G.SELL_STDT <![CDATA[<=]]> NOW() /*유효한 판매기간*/
			AND    G.SELL_EDDT <![CDATA[>=]]> NOW() /*유효한 판매기간*/
			AND    G.ADULT_YN = 'N' /*성인상품아닌넘만*/
			    </otherwise>
			</choose>
			AND    NOT EXISTS (SELECT 1
			                   FROM   TB_GOODS_EP_SKIP
			                   WHERE  GOODS_CD = G.GOODS_CD
			                   AND    NOW() BETWEEN APPLY_STDT AND APPLY_EDDT)
		)
		SELECT 'CURR'                                                                                              AS GB         /*구분(PREV:이전, CURR:현재)*/
		     , G.GOODS_CD                                                                                          AS MAPID      /*상품ID*/
		     , G.LIST_PRICE                                                                                        AS LPRICE     /*정상가*/
		     , IFNULL(GBP.PC_CURR_PRICE,G.CURR_PRICE) * G.MIN_ORD_QTY                                              AS PRICE      /*즉시할인이적용된가격*/
		     , IFNULL(GBP.MO_CURR_PRICE,G.CURR_PRICE) * G.MIN_ORD_QTY                                              AS MPRIC      /*즉시할인이적용된가격*/
		     , SUBSTRING(CONCAT(CASE WHEN CC1.CD IN ('G073_12','G073_13') THEN CONCAT('[',CC1.CD_NM,']')
		                             WHEN G.FOREIGN_BUY_YN = 'Y' THEN '[해외]'
		                             ELSE ''
		                        END,
		                       '[',CASE WHEN G.DISP_NM_LANG = 'EN' THEN G.BRAND_ENM ELSE G.BRAND_KNM END,'] ',
		                       G.GOODS_NM,
		                       IFNULL(G.GOODS_NUM,'')),1,100)                                                      AS PNAME      /*상품명*/
		     , CONCAT(#{goodsDtlUrl},G.GOODS_CD)                                                                   AS PGURL      /*PC상세URL*/
		     , GI.IMAGE_LINK                                                                                       AS IGURL      /*이미지URL*/
		     , SUBSTRING_INDEX(G.ITEMKIND_NM,'>',1)                                                                AS CATE1      /*카테고리명1*/
		     , SUBSTRING(G.ITEMKIND_CD,1,2)                                                                        AS CAID1      /*카테고리ID1*/
		     , CASE WHEN SUBSTRING_INDEX(SUBSTRING_INDEX(G.ITEMKIND_NM,'>',1),'>',-1) = SUBSTRING_INDEX(SUBSTRING_INDEX(G.ITEMKIND_NM,'>',2),'>',-1) THEN
		                NULL
		            ELSE
		                SUBSTRING_INDEX(SUBSTRING_INDEX(G.ITEMKIND_NM,'>',2),'>',-1)
		       END                                                                                                 AS CATE2      /*카테고리명2*/
		     , SUBSTRING(G.ITEMKIND_CD,3,2)                                                                        AS CAID2      /*카테고리ID2*/
		     , CASE WHEN SUBSTRING_INDEX(SUBSTRING_INDEX(G.ITEMKIND_NM,'>',2),'>',-1) = SUBSTRING_INDEX(SUBSTRING_INDEX(G.ITEMKIND_NM,'>',3),'>',-1) THEN
		                NULL
		            ELSE
		                SUBSTRING_INDEX(SUBSTRING_INDEX(G.ITEMKIND_NM,'>',3),'>',-1)
		       END                                                                                                 AS CATE3      /*카테고리명3*/
		     , SUBSTRING(G.ITEMKIND_CD,5,2)                                                                        AS CAID3      /*카테고리ID3*/
		     , CASE WHEN SUBSTRING_INDEX(SUBSTRING_INDEX(G.ITEMKIND_NM,'>',3),'>',-1) = SUBSTRING_INDEX(SUBSTRING_INDEX(G.ITEMKIND_NM,'>',4),'>',-1) THEN
		                NULL
		            ELSE
		                SUBSTRING_INDEX(SUBSTRING_INDEX(G.ITEMKIND_NM,'>',4),'>',-1)
		       END                                                                                                 AS CATE4      /*카테고리명4*/
		     , SUBSTRING(G.ITEMKIND_CD,7,2)                                                                        AS CAID4      /*카테고리ID4*/
		     , G.GOODS_NUM                                                                                         AS MODEL      /*모델(품번)*/
		     , IF(G.DISP_NM_LANG = 'EN',G.BRAND_ENM,G.BRAND_KNM)                                                   AS BRAND      /*브랜드명*/
		     , SUBSTRING(GNI.NI_CONTENT,1,50)                                                                      AS MAKER      /*제조사*/
		     , TEC.COUPON                                                                                                        /*쿠폰*/
		     , TEC.COUPON                                                                                          AS MCOUPON    /*모바일쿠폰*/
		     , IFE.INTEREST_FREE_EVENT                                                                             AS PCARD      /*무이자행사*/
		     , CONCAT('',G.PNT_PRATE)                                                                              AS POINT      /*포인트율*/
		     , IFNULL(CASE WHEN G.DELV_FEE_CRITE = 'G078_20' /*무료*/ THEN
		                       0
		                   ELSE /*조건부무료 또는 유료*/
		                       CASE WHEN G.MIN_ORD_AMT <![CDATA[<=]]> IFNULL(GBP.PC_CURR_PRICE,G.CURR_PRICE) * G.MIN_ORD_QTY THEN
		                                0
		                            ELSE
		                                G.DELV_FEE
		                       END
		              END,0)                                                                                       AS DELIV      /*배송료*/
		     , CASE WHEN G.SELF_GOODS_YN = 'Y' THEN 1 ELSE 3 END                                                   AS DELIVTERM  /*배송기간(자사상품:1일,입점상품:3일)*/
		     , CASE WHEN GS.SCORE IS NULL OR GS.SCORE = 0.0 THEN ''
		            ELSE CONCAT(IFNULL(GS.SCORE,0),'/',5)
		       END                                                                                                 AS RATING     /*상품평평점*/
		     , IFNULL(GS.REVIEW_REG_CNT,0)                                                                         AS REVCT      /*상품평수*/
		     , G.GOODS_TNM                                                                                         AS EVENT      /*상품셀링문구*/
		     , SUBSTRING_INDEX(SUBSTRING_INDEX(CE.CARD_EVENT,'|',1),'^',1)                                         AS CARDDN     /*카드행사*/
		     , SUBSTRING(SUBSTRING_INDEX(CE.CARD_EVENT,'|',1),INSTR(SUBSTRING_INDEX(CE.CARD_EVENT,'|',1),'^') + 1) AS CARDP      /*카드할인가*/
		     , G.ADULT_YN                                                                                          AS ADULT      /*성인여부*/
		     , DATE_FORMAT(G.REG_DT,'%Y%m%d')                                                                      AS PUBDATE    /*등록일*/
		     , G.GOODS_STAT
		     , G.SELF_MALL_YN
		     , G.SELL_STDT
		     , G.SELL_EDDT
		FROM   GOODS_DATA G
		LEFT   OUTER JOIN TB_GOODS_BENEFIT_PRICE GBP 
		ON     G.GOODS_CD = GBP.GOODS_CD
		LEFT   OUTER JOIN TB_GOODS_SUMMARY GS 
		ON     G.GOODS_CD = GS.GOODS_CD
		LEFT   OUTER JOIN TB_EP_GOODS_IMG GI 
		ON     G.GOODS_CD = GI.GOODS_CD
		LEFT   OUTER JOIN TB_EP_GOODS_ADD_IMG GAI 
		ON     G.GOODS_CD = GAI.GOODS_CD
		LEFT   OUTER JOIN (
		    SELECT ITEMKIND_CD
		         , MIN(EP_CATE_CD) AS EP_CATE_CD
		    FROM   TB_EP_CATE
		    WHERE  EP_GB = '10' /*네이버*/
		    AND    USE_YN = 'Y'
		    GROUP  BY ITEMKIND_CD
		) EC ON G.ITEMKIND_CD = EC.ITEMKIND_CD
		LEFT   OUTER JOIN TB_GOODS_RES_SELL GRS 
		ON     G.GOODS_CD = GRS.GOODS_CD
		AND    GRS.DELV_RES_DT >= NOW()
		AND    GRS.USE_YN = 'Y'
		LEFT   OUTER JOIN TB_EP_CARD_EVENT CE 
		ON     G.GOODS_CD = CE.GOODS_CD
		LEFT   OUTER JOIN TB_EP_COUPON TEC 
		ON     G.GOODS_CD = TEC.GOODS_CD
		LEFT   OUTER JOIN TB_EP_INTEREST_FREE_EVENT IFE 
		ON     G.GOODS_CD = IFE.GOODS_CD
		LEFT   OUTER JOIN TB_GOODS_NOTI_INFO GNI 
		ON     G.GOODS_CD = GNI.GOODS_CD
		AND    GNI.NI_ITEM_CD = 'G005_005' /*제조사*/
		LEFT   OUTER JOIN TB_COMMON_CODE CC1 
		ON     G.GOODS_GB = CC1.CD
		AND    CC1.CD_GB = 'G073'
		LEFT   OUTER JOIN TB_COMMON_CODE CC2 
		ON     G.ORIGIN_CD = CC2.CD
		AND    CC2.CD_GB = 'G076'
	</insert>

	<!-- EP다음 현재 데이터 생성 -->
	<insert id="createCurrentEpDaum" parameterType="GoodsEp" timeout="360">
		/* TsbGoodsEp.createCurrentEpDaum */
		INSERT INTO TB_EP_DAUM (
		       GB
		     , MAPID
		     , LPRICE
		     , PRICE
		     , MPRIC
		     , PNAME
		     , PGURL
		     , IGURL
		     , CATE1
		     , CAID1
		     , CATE2
		     , CAID2
		     , CATE3
		     , CAID3
		     , CATE4
		     , CAID4
		     , MODEL
		     , BRAND
		     , MAKER
		     , COUPON
		     , MCOUPON
		     , PCARD
		     , POINT
		     , DELIV
		     , DELIVTERM
		     , RATING
		     , REVCT
		     , EVENT
		     , CARDDN
		     , CARDP
		     , ADULT
		     , PUBDATE
		     , GOODS_STAT
		     , SELF_MALL_YN
		     , SELL_STDT
		     , SELL_EDDT
		)
		SELECT 'CURR'                                                                                              AS GB         /*구분(PREV:이전, CURR:현재)*/
		     , G.GOODS_CD                                                                                          AS MAPID      /*상품ID*/
		     , G.LIST_PRICE                                                                                        AS LPRICE     /*정상가*/
		     , IFNULL(GBP.PC_CURR_PRICE,G.CURR_PRICE) * G.MIN_ORD_QTY                                              AS PRICE      /*즉시할인이적용된가격*/
		     , IFNULL(GBP.MO_CURR_PRICE,G.CURR_PRICE) * G.MIN_ORD_QTY                                              AS MPRIC      /*즉시할인이적용된가격*/
		     , SUBSTRING(CONCAT(CASE WHEN CC1.CD IN ('G073_12','G073_13') THEN CONCAT('[',CC1.CD_NM,']')
		                             WHEN G.FOREIGN_BUY_YN = 'Y' THEN '[해외]'
		                             ELSE ''
		                        END,
		                       '[',CASE WHEN B.DISP_NM_LANG = 'EN' THEN B.BRAND_ENM ELSE B.BRAND_KNM END,'] ',
		                       G.GOODS_NM,
		                       IFNULL(G.GOODS_NUM,'')),1,100)                                                      AS PNAME      /*상품명*/
		     , CONCAT(#{goodsDtlUrl},G.GOODS_CD)                                                                   AS PGURL      /*PC상세URL*/
		     , GI.IMAGE_LINK                                                                                       AS IGURL      /*이미지URL*/
		     , SUBSTRING_INDEX(I.ITEMKIND_NM,'>',1)                                                                AS CATE1      /*카테고리명1*/
		     , SUBSTRING(G.ITEMKIND_CD,1,2)                                                                        AS CAID1      /*카테고리ID1*/
		     , CASE WHEN SUBSTRING_INDEX(SUBSTRING_INDEX(I.ITEMKIND_NM,'>',1),'>',-1) = SUBSTRING_INDEX(SUBSTRING_INDEX(I.ITEMKIND_NM,'>',2),'>',-1) THEN
		                NULL
		            ELSE
		                SUBSTRING_INDEX(SUBSTRING_INDEX(I.ITEMKIND_NM,'>',2),'>',-1)
		       END                                                                                                 AS CATE2      /*카테고리명2*/
		     , SUBSTRING(G.ITEMKIND_CD,3,2)                                                                        AS CAID2      /*카테고리ID2*/
		     , CASE WHEN SUBSTRING_INDEX(SUBSTRING_INDEX(I.ITEMKIND_NM,'>',2),'>',-1) = SUBSTRING_INDEX(SUBSTRING_INDEX(I.ITEMKIND_NM,'>',3),'>',-1) THEN
		                NULL
		            ELSE
		                SUBSTRING_INDEX(SUBSTRING_INDEX(I.ITEMKIND_NM,'>',3),'>',-1)
		       END                                                                                                 AS CATE3      /*카테고리명3*/
		     , SUBSTRING(G.ITEMKIND_CD,5,2)                                                                        AS CAID3      /*카테고리ID3*/
		     , CASE WHEN SUBSTRING_INDEX(SUBSTRING_INDEX(I.ITEMKIND_NM,'>',3),'>',-1) = SUBSTRING_INDEX(SUBSTRING_INDEX(I.ITEMKIND_NM,'>',4),'>',-1) THEN
		                NULL
		            ELSE
		                SUBSTRING_INDEX(SUBSTRING_INDEX(I.ITEMKIND_NM,'>',4),'>',-1)
		       END                                                                                                 AS CATE4      /*카테고리명4*/
		     , SUBSTRING(G.ITEMKIND_CD,7,2)                                                                        AS CAID4      /*카테고리ID4*/
		     , G.GOODS_NUM                                                                                         AS MODEL      /*모델(품번)*/
		     , IF(B.DISP_NM_LANG = 'EN',B.BRAND_ENM,B.BRAND_KNM)                                                   AS BRAND      /*브랜드명*/
		     , SUBSTRING(GNI.NI_CONTENT,1,50)                                                                      AS MAKER      /*제조사*/
		     , TEC.COUPON                                                                                                        /*쿠폰*/
		     , TEC.COUPON                                                                                          AS MCOUPON    /*모바일쿠폰*/
		     , IFE.INTEREST_FREE_EVENT                                                                             AS PCARD      /*무이자행사*/
		     , CONCAT('',G.PNT_PRATE)                                                                              AS POINT      /*포인트율*/
		     , IFNULL(CASE WHEN DFP.DELV_FEE_CRITE = 'G078_20' /*무료*/ THEN
		                       0
		                   ELSE /*조건부무료 또는 유료*/
		                       CASE WHEN DFP.MIN_ORD_AMT <![CDATA[<=]]> IFNULL(GBP.PC_CURR_PRICE,G.CURR_PRICE) * G.MIN_ORD_QTY THEN
		                                0
		                            ELSE
		                                DFP.DELV_FEE
		                       END
		              END,0)                                                                                       AS DELIV      /*배송료*/
		     , CASE WHEN G.SELF_GOODS_YN = 'Y' THEN 1 ELSE 3 END                                                   AS DELIVTERM  /*배송기간(자사상품:1일,입점상품:3일)*/
		     , CASE WHEN GS.SCORE IS NULL OR GS.SCORE = 0.0 THEN ''
		            ELSE CONCAT(IFNULL(GS.SCORE,0),'/',5)
		       END                                                                                                 AS RATING     /*상품평평점*/
		     , IFNULL(GS.REVIEW_REG_CNT,0)                                                                         AS REVCT      /*상품평수*/
		     , G.GOODS_TNM                                                                                         AS EVENT      /*상품셀링문구*/
		     , SUBSTRING_INDEX(SUBSTRING_INDEX(CE.CARD_EVENT,'|',1),'^',1)                                         AS CARDDN     /*카드행사*/
		     , SUBSTRING(SUBSTRING_INDEX(CE.CARD_EVENT,'|',1),INSTR(SUBSTRING_INDEX(CE.CARD_EVENT,'|',1),'^') + 1) AS CARDP      /*카드할인가*/
		     , G.ADULT_YN                                                                                          AS ADULT      /*성인여부*/
		     , DATE_FORMAT(G.REG_DT,'%Y%m%d')                                                                      AS PUBDATE    /*등록일*/
		     , G.GOODS_STAT
		     , G.SELF_MALL_YN
		     , G.SELL_STDT
		     , G.SELL_EDDT
		FROM   TB_GOODS G
		INNER JOIN TB_BRAND B ON G.BRAND_CD = B.BRAND_CD
		INNER JOIN TB_ITEMKIND I ON G.ITEMKIND_CD = I.ITEMKIND_CD
		INNER JOIN TB_DELV_FEE_POLICY DFP ON G.DELV_FEE_CD = DFP.DELV_FEE_CD
		                                 AND G.SUPPLY_COMP_CD = DFP.SUPPLY_COMP_CD
		INNER JOIN TB_EP_GOODS_IMG GI ON G.GOODS_CD = GI.GOODS_CD
		LEFT OUTER JOIN TB_GOODS_BENEFIT_PRICE GBP ON G.GOODS_CD = GBP.GOODS_CD
		LEFT OUTER JOIN TB_GOODS_SUMMARY GS ON G.GOODS_CD = GS.GOODS_CD
		LEFT OUTER JOIN TB_EP_GOODS_ADD_IMG GAI ON G.GOODS_CD = GAI.GOODS_CD
		LEFT OUTER JOIN (
		                 SELECT ITEMKIND_CD
		                      , MIN(EP_CATE_CD) AS EP_CATE_CD
		                 FROM   TB_EP_CATE
		                 WHERE  EP_GB = '10' /*네이버*/
		                 AND    USE_YN = 'Y'
		                 GROUP  BY ITEMKIND_CD
		                ) EC ON G.ITEMKIND_CD = EC.ITEMKIND_CD
		LEFT OUTER JOIN TB_GOODS_RES_SELL GRS ON G.GOODS_CD = GRS.GOODS_CD
		                                     AND GRS.DELV_RES_DT >= NOW()
		                                     AND GRS.USE_YN = 'Y'
		LEFT OUTER JOIN TB_EP_CARD_EVENT CE ON G.GOODS_CD = CE.GOODS_CD
		LEFT OUTER JOIN TB_EP_COUPON TEC ON G.GOODS_CD = TEC.GOODS_CD
		LEFT OUTER JOIN TB_EP_INTEREST_FREE_EVENT IFE ON G.GOODS_CD = IFE.GOODS_CD
		LEFT OUTER JOIN TB_GOODS_NOTI_INFO GNI ON G.GOODS_CD = GNI.GOODS_CD
		                                      AND GNI.NI_ITEM_CD = 'G005_005' /*제조사*/
		LEFT OUTER JOIN TB_COMMON_CODE CC1 ON G.GOODS_GB = CC1.CD
		                                 AND CC1.CD_GB = 'G073'
		LEFT OUTER JOIN TB_COMMON_CODE CC2 ON G.ORIGIN_CD = CC2.CD
		                                  AND CC2.CD_GB = 'G076'
		WHERE  1 = 1
		<choose>
		    <when test='epType == "SUMMARY"'> <!-- 요약EP -->
		AND    G.UPD_DT >= DATE_ADD(NOW(), INTERVAL -7 HOUR)
		    </when>
		    <otherwise> <!-- 전체EP -->
		AND    G.GOODS_STAT = 'G008_90' /*승인완료상품*/
		AND    G.SELF_MALL_YN = 'Y' /*몰노출상품*/
		AND    G.SELL_STDT <![CDATA[<=]]> NOW() /*유효한 판매기간*/
		AND    G.SELL_EDDT <![CDATA[>=]]> NOW() /*유효한 판매기간*/
		AND    G.ADULT_YN = 'N' /*성인상품아닌넘만*/
		    </otherwise>
		</choose>
		AND    NOT EXISTS (SELECT 1
		                   FROM   TB_GOODS_EP_SKIP
		                   WHERE  GOODS_CD = G.GOODS_CD
		                   AND    NOW() BETWEEN APPLY_STDT AND APPLY_EDDT
		                  )
	</insert>
	
	<!-- 최종 EP다음 데이터 생성 -->
	<insert id="createLastEpDaum" parameterType="GoodsEp" timeout="360">
		/* TsbGoodsEp.createLastEpDaum */
		INSERT INTO TB_EP_DAUM (
		       GB
		     , MAPID
		     , LPRICE
		     , PRICE
		     , MPRIC
		     , PNAME
		     , PGURL
		     , IGURL
		     , UPIMG
		     , CATE1
		     , CAID1
		     , CATE2
		     , CAID2
		     , CATE3
		     , CAID3
		     , CATE4
		     , CAID4
		     , MODEL
		     , BRAND
		     , MAKER
		     , COUPON
		     , MCOUPON
		     , PCARD
		     , POINT
		     , DELIV
		     , DELIVTERM
		     , RATING
		     , REVCT
		     , EVENT
		     , CARDDN
		     , CARDP
		     , ADULT
		     , PUBDATE
		     , GOODS_STAT
		     , SELF_MALL_YN
		     , SELL_STDT
		     , SELL_EDDT
		     , UPD_GB
		     , UTIME
		)
		SELECT 'LAST'                                 AS GB
		     , MAPID
		     , LPRICE
		     , PRICE
		     , MPRIC
		     , PNAME
		     , PGURL
		     , IGURL
		     , UPIMG
		     , CATE1
		     , CAID1
		     , CATE2
		     , CAID2
		     , CATE3
		     , CAID3
		     , CATE4
		     , CAID4
		     , MODEL
		     , BRAND
		     , MAKER
		     , COUPON
		     , MCOUPON
		     , PCARD
		     , POINT
		     , DELIV
		     , DELIVTERM
		     , RATING
		     , REVCT
		     , EVENT
		     , CARDDN
		     , CARDP
		     , ADULT
		     , PUBDATE
		     , GOODS_STAT
		     , SELF_MALL_YN
		     , SELL_STDT
		     , SELL_EDDT
		     , UPD_GB
		     , DATE_FORMAT(NOW(),'%Y%m%d%H%i%S') AS UTIME
		FROM   (
		        /*신규 목록*/
		        SELECT MAPID
		             , LPRICE
		             , PRICE
		             , MPRIC
		             , PNAME
		             , PGURL
		             , IGURL
		             , 'N'           AS UPIMG
		             , CATE1
		             , CAID1
		             , CATE2
		             , CAID2
		             , CATE3
		             , CAID3
		             , CATE4
		             , CAID4
		             , MODEL
		             , BRAND
		             , MAKER
		             , COUPON
		             , MCOUPON
		             , PCARD
		             , POINT
		             , DELIV
		             , DELIVTERM
		             , RATING
		             , REVCT
		             , EVENT
		             , CARDDN
		             , CARDP
		             , ADULT
		             , PUBDATE
		             , GOODS_STAT
		             , SELF_MALL_YN
		             , SELL_STDT
		             , SELL_EDDT
		             , 'I'           AS UPD_GB /*변경구분*/
		        FROM   TB_EP_DAUM X
		        WHERE  GB = 'CURR' /*현재데이터*/
		        <if test='epType == "SUMMARY"'> <!-- 요약EP -->
		        AND    NOT EXISTS (SELECT 1
		                           FROM   TB_EP_DAUM
		                           WHERE  GB = 'PREV' /*이전백업데이터*/
		                           AND    MAPID = X.MAPID
		                          )
		        </if>
		        <if test='epType == "SUMMARY"'> <!-- 요약EP -->
		        UNION ALL
		        /*변경 목록*/
		        SELECT X.MAPID
		             , X.LPRICE
		             , X.PRICE
		             , X.MPRIC
		             , X.PNAME
		             , X.PGURL
		             , X.IGURL
		             , CASE WHEN X.IGURL != Y.IGURL THEN 'Y' ELSE 'N' END AS UPIMG
		             , X.CATE1
		             , X.CAID1
		             , X.CATE2
		             , X.CAID2
		             , X.CATE3
		             , X.CAID3
		             , X.CATE4
		             , X.CAID4
		             , X.MODEL
		             , X.BRAND
		             , X.MAKER
		             , X.COUPON
		             , X.MCOUPON
		             , X.PCARD
		             , X.POINT
		             , X.DELIV
		             , X.DELIVTERM
		             , X.RATING
		             , X.REVCT
		             , X.EVENT
		             , X.CARDDN
		             , X.CARDP
		             , X.ADULT
		             , X.PUBDATE
		             , X.GOODS_STAT
		             , X.SELF_MALL_YN
		             , X.SELL_STDT
		             , X.SELL_EDDT
		             , 'U'                         AS UPD_GB /*변경구분*/
		        FROM   TB_EP_DAUM X
		             , TB_EP_DAUM Y
		        WHERE  X.MAPID = Y.MAPID
		        AND    X.GB = 'CURR' /*현재데이터*/
		        AND    Y.GB = 'PREV' /*이전백업데이터*/
		        AND    (
		                X.MAPID != Y.MAPID OR
		                X.LPRICE != Y.LPRICE OR
		                X.PRICE != Y.PRICE OR
		                X.MPRIC != Y.MPRIC OR
		                X.PNAME != Y.PNAME OR
		                X.PGURL != Y.PGURL OR
		                X.IGURL != Y.IGURL OR
		                X.CATE1 != Y.CATE1 OR
		                X.CAID1 != Y.CAID1 OR
		                X.CATE2 != Y.CATE2 OR
		                X.CAID2 != Y.CAID2 OR
		                X.CATE3 != Y.CATE3 OR
		                X.CAID3 != Y.CAID3 OR
		                X.CATE4 != Y.CATE4 OR
		                X.CAID4 != Y.CAID4 OR
		                X.MODEL != Y.MODEL OR
		                X.BRAND != Y.BRAND OR
		                X.MAKER != Y.MAKER OR
		                X.COUPON != Y.COUPON OR
		                X.MCOUPON != Y.MCOUPON OR
		                X.PCARD != Y.PCARD OR
		                X.POINT != Y.POINT OR
		                X.DELIV != Y.DELIV OR
		                X.DELIVTERM != Y.DELIVTERM OR
		                X.RATING != Y.RATING OR
		                X.REVCT != Y.REVCT OR
		                X.EVENT != Y.EVENT OR
		                X.CARDDN != Y.CARDDN OR
		                X.CARDP != Y.CARDP OR
		                X.ADULT != Y.ADULT OR
		                X.PUBDATE != Y.PUBDATE
		               )
		        UNION ALL
		        /*삭제된 목록*/
		        SELECT X.MAPID
		             , X.LPRICE
		             , X.PRICE
		             , X.MPRIC
		             , X.PNAME
		             , X.PGURL
		             , X.IGURL
		             , CASE WHEN X.IGURL != Y.IGURL THEN 'Y' ELSE 'N' END AS UPIMG
		             , X.CATE1
		             , X.CAID1
		             , X.CATE2
		             , X.CAID2
		             , X.CATE3
		             , X.CAID3
		             , X.CATE4
		             , X.CAID4
		             , X.MODEL
		             , X.BRAND
		             , X.MAKER
		             , X.COUPON
		             , X.MCOUPON
		             , X.PCARD
		             , X.POINT
		             , X.DELIV
		             , X.DELIVTERM
		             , X.RATING
		             , X.REVCT
		             , X.EVENT
		             , X.CARDDN
		             , X.CARDP
		             , X.ADULT
		             , X.PUBDATE
		             , X.GOODS_STAT
		             , X.SELF_MALL_YN
		             , X.SELL_STDT
		             , X.SELL_EDDT
		             , 'D'                         AS UPD_GB /*변경구분*/
		        FROM   TB_EP_DAUM X
		             , TB_EP_DAUM Y
		        WHERE  X.MAPID = Y.MAPID
		        AND    X.GB = 'CURR' /*현재데이터*/
		        AND    Y.GB = 'PREV' /*이전백업데이터*/
		        AND    (
		                (Y.GOODS_STAT != 'G008_70' AND X.GOODS_STAT = 'G008_70')
		                OR
		                (Y.SELF_MALL_YN = 'Y' AND X.SELF_MALL_YN = 'N')
		                OR
		                (Y.SELL_EDDT != X.SELL_EDDT AND Y.SELL_EDDT <![CDATA[<]]> NOW())
		               )
		        </if>
		       ) X
	</insert>

	<!-- 다음 EP 목록 -->
	<select id="getDaumEpList" resultType="GoodsEp" timeout="1000">
		/* TsbGoodsEp.getDaumEpList */
		SELECT IFNULL(MAPID,'')     AS MAPID
		     , LPRICE
		     , PRICE
		     , MPRIC
		     , IFNULL(UPD_GB,'')    AS UPD_GB
		     , IFNULL(UTIME,'')     AS UTIME
		     , IFNULL(PNAME,'')     AS PNAME
		     , IFNULL(PGURL,'')     AS PGURL
		     , IFNULL(IGURL,'')     AS IGURL
		     , IFNULL(UPIMG,'')     AS UPIMG
		     , IFNULL(CATE1,'')     AS CATE1
		     , IFNULL(CAID1,'')     AS CAID1
		     , IFNULL(CATE2,'')     AS CATE2
		     , IFNULL(CAID2,'')     AS CAID2
		     , IFNULL(CATE3,'')     AS CATE3
		     , IFNULL(CAID3,'')     AS CAID3
		     , IFNULL(CATE4,'')     AS CATE4
		     , IFNULL(CAID4,'')     AS CAID4
		     , IFNULL(MODEL,'')     AS MODEL
		     , IFNULL(BRAND,'')     AS BRAND
		     , IFNULL(MAKER,'')     AS MAKER
		     , IFNULL(COUPON,'')    AS COUPON
		     , IFNULL(MCOUPON,'')   AS MCOUPON
		     , IFNULL(PCARD,'')     AS PCARD
		     , IFNULL(POINT,'')     AS POINT
		     , IFNULL(DELIV,'')     AS DELIV
		     , IFNULL(DELIVTERM,'') AS DELIVTERM
		     , IFNULL(RATING,'')    AS RATING
		     , IFNULL(REVCT,'')     AS REVCT
		     , IFNULL(EVENT,'')     AS EVENT
		     , IFNULL(CARDDN,'')    AS CARDDN
		     , IFNULL(CARDP,'')     AS CARDP
		     , IFNULL(ADULT,'')     AS ADULT
		     , IFNULL(PUBDATE,'')   AS PUBDATE
		FROM   TB_EP_DAUM
		WHERE  GB = 'LAST'
	</select>
	
	<!-- 다음 EP 총건수 -->
	<select id="getDaumEpTotalCount" resultType="int">
		/* TsbGoodsEp.getDaumEpTotalCount */
		SELECT COUNT(1)
		FROM   TB_EP_DAUM
		WHERE  GB = 'LAST'
	</select>
	
	<!-- 다음 EP 페이징 목록 -->
	<select id="getDaumEpPagingList" resultType="GoodsEp" timeout="1000">
		/* TsbGoodsEp.getDaumEpPagingList */
		<include refid="selectForPagingHeader"/>
		SELECT IFNULL(MAPID,'')     AS MAPID
		     , LPRICE
		     , PRICE
		     , MPRIC
		     , IFNULL(UPD_GB,'')    AS UPD_GB
		     , IFNULL(UTIME,'')     AS UTIME
		     , IFNULL(PNAME,'')     AS PNAME
		     , IFNULL(PGURL,'')     AS PGURL
		     , IFNULL(IGURL,'')     AS IGURL
		     , IFNULL(UPIMG,'')     AS UPIMG
		     , IFNULL(CATE1,'')     AS CATE1
		     , IFNULL(CAID1,'')     AS CAID1
		     , IFNULL(CATE2,'')     AS CATE2
		     , IFNULL(CAID2,'')     AS CAID2
		     , IFNULL(CATE3,'')     AS CATE3
		     , IFNULL(CAID3,'')     AS CAID3
		     , IFNULL(CATE4,'')     AS CATE4
		     , IFNULL(CAID4,'')     AS CAID4
		     , IFNULL(MODEL,'')     AS MODEL
		     , IFNULL(BRAND,'')     AS BRAND
		     , IFNULL(MAKER,'')     AS MAKER
		     , IFNULL(COUPON,'')    AS COUPON
		     , IFNULL(MCOUPON,'')   AS MCOUPON
		     , IFNULL(PCARD,'')     AS PCARD
		     , IFNULL(POINT,'')     AS POINT
		     , IFNULL(DELIV,'')     AS DELIV
		     , IFNULL(DELIVTERM,'') AS DELIVTERM
		     , IFNULL(RATING,'')    AS RATING
		     , IFNULL(REVCT,'')     AS REVCT
		     , IFNULL(EVENT,'')     AS EVENT
		     , IFNULL(CARDDN,'')    AS CARDDN
		     , IFNULL(CARDP,'')     AS CARDP
		     , IFNULL(ADULT,'')     AS ADULT
		     , IFNULL(PUBDATE,'')   AS PUBDATE
		FROM   TB_EP_DAUM
		WHERE  GB = 'LAST'
		ORDER  BY MAPID
		<include refid="selectForPagingFooter"/>
	</select>
	
	<!-- 다음 상품평EP 목록 -->
	<select id="getDaumReviewEpList" resultType="GoodsEp">
		/* TsbGoodsEp.getDaumReviewEpList */
		SELECT R.GOODS_CD                           AS MAPID    /*상품ID*/
		     , R.REVIEW_SQ                          AS REVIEWID /*상품평ID*/
		     , CASE WHEN R.DISP_YN = 'N' OR R.DEL_YN = 'Y' THEN 'D'
		            ELSE 'S'
		       END                                  AS STATUS   /*상품평상태(S:정상, D:삭제)*/
		     , R.REVIEW_TITLE                       AS TITLE    /*상품평제목*/
		     , SUBSTRING(R.REVIEW_CONTENT,1,250)    AS CONTENT  /*상품평내용(250자이내)*/
		     , C.CUST_NM                            AS WRITER
		     , DATE_FORMAT(R.REG_DT,'%Y%m%d%H%i%S') AS CDATE /*상품평작성일시*/
		     , R.SCORE                              AS RATING /*상품평점수*/
		FROM   TB_REVIEW R
		     , TB_CUSTOMER C
		WHERE  R.REG_NO = C.CUST_NO
		AND    R.CONFIRM_YN = 'Y' /*컨펌된넘*/
	</select>
	
</mapper>