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

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

	<!-- 휴면회원 선정기간 총 대상-->
	<select id="getDormantCustomerScheduleListCount" parameterType="CustomerSearch" resultType="int">
		/*TsbCustomerDao.getDormantCustomerScheduleListCount*/
		SELECT  COUNT(*) AS CNT
		FROM    TB_CUSTOMER C
		WHERE   C.CUST_STAT = 'G104_10' -- 활동회원
		AND     C.SITE_CD = #{siteCd}
		AND     C.LOGIN_LDT >= DATE_FORMAT(DATE_ADD(CURRENT_DATE(), INTERVAL  -#{dormantSelectDays} - 1 DAY), '%Y%m%d%H%i%S')
		AND     C.LOGIN_LDT <![CDATA[<]]> DATE_FORMAT(DATE_ADD(CURRENT_DATE(), INTERVAL -#{dormantSelectDays} DAY), '%Y%m%d%H%i%S')
		AND     NOT EXISTS (
		                    SELECT 1
		                    FROM  TB_CUST_CONTACT_HST CCH
		                    WHERE CCH.RECEIVER_NO = C.CUST_NO
		                    AND   CCH.CONTACT_TYPE = 'G054_207' /*회원-휴면계정전환예정*/
		                    AND   CCH.SEND_DT > DATE_FORMAT(DATE_ADD(CURRENT_DATE(), INTERVAL - 4 DAY), '%Y-%m-%d')
		                   )
	</select>

	<!-- 휴면회원 선정기간 등록된 일로 휴면안내 메일 발송-->
	<select id="getDormantCustomerScheduleList" parameterType="CustomerSearch" resultType="Customer">
		/*TsbCustomerDao.getDormantCustomerScheduleList*/
		<include refid="selectForPagingHeader"/>
		    SELECT  C.CUST_NO
		          , C.CUST_ID
		          , C.CUST_NM
		          , C.CELL_PHNNO
		          , C.EMAIL
		          , C.SNS_TYPE
		          , DATE_FORMAT(C.LOGIN_LDT, '%Y-%m-%d') AS LOGIN_LDT
		          , DATE_FORMAT(DATE_ADD(C.LOGIN_LDT, INTERVAL #{dormantConversionDay} +1 DAY), '%Y.%m.%d') AS DORMANT_DT
		          , DATE_FORMAT(DATE_ADD(C.LOGIN_LDT, INTERVAL #{dormantConversionDay} DAY), '%Y%m%d') AS FEW_DT
		    FROM    TB_CUSTOMER C
		    WHERE   C.CUST_STAT = 'G104_10' -- 활동회원
		    AND     C.SITE_CD = #{siteCd}
		    AND     C.LOGIN_LDT >= DATE_FORMAT(DATE_ADD(CURRENT_DATE(), INTERVAL  -#{dormantSelectDays} - 1 DAY), '%Y%m%d%H%i%S')
		    AND     C.LOGIN_LDT <![CDATA[<]]> DATE_FORMAT(DATE_ADD(CURRENT_DATE(), INTERVAL -#{dormantSelectDays} DAY), '%Y%m%d%H%i%S')
		    AND     NOT EXISTS (
		                        SELECT 1
		                        FROM  TB_CUST_CONTACT_HST CCH
		                        WHERE CCH.RECEIVER_NO = C.CUST_NO
		                        AND   CCH.CONTACT_TYPE = 'G054_207' /*회원-휴면계정전환예정*/
		                        AND   CCH.SEND_DT > DATE_FORMAT(DATE_ADD(CURRENT_DATE(), INTERVAL - 4 DAY), '%Y-%m-%d')
		                        )
		    ORDER BY C.CUST_NO
		<include refid="selectForPagingFooter"/>
	</select>

	<!--휴면회원전환기간 등록된 일로 휴면 처리-->
	<select id="getDormentCustomerList" parameterType="CustomerSearch" resultType="Customer">
		/*TsbCustomerDao.getDormentCustomerList*/
		SELECT CUST_NO
		     , CUST_ID
		     , CUST_NM
		     , BIRTH_YMD
		     , SEX_GB
		     , CELL_PHNNO
		     , EMAIL
		     , SITE_CD
		     , FRONT_GB
		     , CUST_GB
		     , CUST_GRADE
		     , JOIN_DT
		     , LOGIN_LDT
		     , REG_NO
		     , REG_DT
		     , UPD_NO
		     , UPD_DT
		     , DATEDIFF(NOW() , LOGIN_LDT) AS AUTO_SECEDE_PERIOD
		     , DATE_FORMAT(DATE_ADD(CURRENT_DATE(), INTERVAL - 1 DAY), '%Y-%m-%d') AS REVISIT_DT
		     , DATE_FORMAT(CURRENT_DATE(), '%Y-%m-%d') AS DORMANT_DT
		FROM   TB_CUSTOMER
		WHERE  CUST_STAT = 'G104_10' -- 활동회원
		AND    SITE_CD = #{siteCd}
		AND    LOGIN_LDT >= DATE_FORMAT(DATE_ADD(CURRENT_DATE(), INTERVAL - #{dormantConversionDay} - 1 DAY), '%Y%m%d%H%i%S') -- CURRENT_DATE() -365 -1
		AND    LOGIN_LDT <![CDATA[<]]> DATE_FORMAT(DATE_ADD(CURRENT_DATE(), INTERVAL - #{dormantConversionDay} DAY), '%Y%m%d%H%i%S')
	</select>

	<!-- 휴면회원 테이블 휴면회원정보 저장 -->
	<insert id="createDormantCustomer" parameterType="CustomerSearch" timeout="360">
		/*TsbCustomerDao.createDormantCustomer*/
		INSERT INTO TB_DORMANT_CUST (
		       CUST_NO
		     , CUST_ID
		     , CUST_NM
		     , PASSWD
		     , BIRTH_YMD
		     , SEX_GB
		     , CELL_PHNNO
		     , APP_AGREE_YN
		     , APP_AGREE_DT
		     , SMS_AGREE_YN
		     , SMS_AGREE_DT
		     , EMAIL
		     , EMAIL_AGREE_YN
		     , EMAIL_AGREE_DT
		     , MK_AGREE_YN
		     , MK_AGREE_DT
		     , HOME_ZIPCODE
		     , HOME_BASE_ADDR
		     , HOME_DTL_ADDR
		     , SITE_CD
		     , FRONT_GB
		     , AF_LINK_CD
		     , CUST_GB
		     , CUST_GRADE
		     , JOIN_DT
		     , FOREIGNER_YN
		     , CUST_STAT
		     , PASSWD_CHG_DT
		     , TEMP_PASSWD_YN
		     , LOGIN_LDT
		     , CI
		     , AUTH_DT
		     , SNS_TYPE
		     , MANAGED_RSN
		     , MANAGED_DTL_RSN
		     , MANAGED_DT
		     , SECEDE_RSN
		     , SECEDE_DTL_RSN
		     , SECEDE_DT
		     , BIRTH_MM
		     , REG_NO
		     , REG_DT
		     , UPD_NO
		     , UPD_DT
		     , DORMANT_DT
		)
		SELECT CUST_NO
		     , CUST_ID
		     , CUST_NM
		     , PASSWD
		     , BIRTH_YMD
		     , SEX_GB
		     , CELL_PHNNO
		     , APP_AGREE_YN
		     , APP_AGREE_DT
		     , SMS_AGREE_YN
		     , SMS_AGREE_DT
		     , EMAIL
		     , EMAIL_AGREE_YN
		     , EMAIL_AGREE_DT
		     , MK_AGREE_YN
		     , MK_AGREE_DT
		     , HOME_ZIPCODE
		     , HOME_BASE_ADDR
		     , HOME_DTL_ADDR
		     , SITE_CD
		     , FRONT_GB
		     , AF_LINK_CD
		     , CUST_GB
		     , CUST_GRADE
		     , JOIN_DT
		     , FOREIGNER_YN
		     , 'G104_20'     AS CUST_STAT
		     , PASSWD_CHG_DT
		     , TEMP_PASSWD_YN
		     , LOGIN_LDT
		     , CI
		     , AUTH_DT
		     , SNS_TYPE
		     , MANAGED_RSN
		     , MANAGED_DTL_RSN
		     , MANAGED_DT
		     , SECEDE_RSN
		     , SECEDE_DTL_RSN
		     , SECEDE_DT
		     , BIRTH_MM
		     , #{regNo}      AS REG_NO
		     , NOW()         AS REG_DT
		     , UPD_NO
		     , UPD_DT
		     , NOW()         AS DORMANT_DT
		FROM   TB_CUSTOMER
		WHERE  CUST_STAT = 'G104_10' -- 활동회원
		AND    SITE_CD = #{siteCd}
		AND    LOGIN_LDT >= DATE_FORMAT(DATE_ADD(CURRENT_DATE(), INTERVAL -#{dormantConversionDay}  -1 DAY), '%Y%m%d%H%i%S')
		AND    LOGIN_LDT <![CDATA[<]]> DATE_FORMAT(DATE_ADD(CURRENT_DATE(), INTERVAL -#{dormantConversionDay} DAY), '%Y%m%d%H%i%S')
	</insert>

	<!--회원정보 휴면처리-->
	<update id="updateDormantCustomer" parameterType="CustomerSearch" timeout="360">
		/*TsbCustomerDao.updateDormantCustomer*/
		UPDATE TB_CUSTOMER
		SET    CUST_NM = #{encodedCustNm}
		     , BIRTH_YMD = NULL
		     , SEX_GB = NULL
		     , CELL_PHNNO = NULL
		     , SMS_AGREE_YN = 'N'
		     , SMS_AGREE_DT = NULL
		     , EMAIL = NULL
		     , EMAIL_AGREE_YN = 'N'
		     , EMAIL_AGREE_DT = NULL
		     , APP_AGREE_YN = 'N'
		     , APP_AGREE_DT = NULL
		     , MK_AGREE_YN = 'N'
		     , MK_AGREE_DT = NULL
		     , HOME_ZIPCODE = NULL
		     , HOME_BASE_ADDR = NULL
		     , HOME_DTL_ADDR = NULL
		     , CUST_STAT = 'G104_20'
		     , UPD_DT = NOW()
		WHERE  CUST_NO IN (
		                   SELECT CUST_NO
		                   FROM   TB_DORMANT_CUST
		                   WHERE  DORMANT_DT >= DATE_FORMAT(CURRENT_DATE(), '%Y%m%d%H%i%S')
		                   AND    SITE_CD = #{siteCd}
		                   )
	</update>

	<!--주문정보 휴면주문정보 생성-->
	<insert id="createDormantOrder" parameterType="CustomerSearch">
		/*TsbCustomerDao.createDormantOrder*/
		INSERT INTO TB_ORDER_DORMANT (
		      ORD_NO
		    , CUST_NO
		    , ORD_NM
		    , ORD_PHNNO
		    , ORD_TELNO
		    , ORD_EMAIL
		    , REG_NO
		    , REG_DT
		)
		SELECT ORD_NO
		     , CUST_NO
		     , ORD_NM
		     , ORD_PHNNO
		     , ORD_TELNO
		     , ORD_EMAIL
		     , #{regNo}       AS REG_NO
		     , NOW()          AS REG_DT
		FROM   TB_ORDER
		WHERE  CUST_NO IN (
		                   SELECT CUST_NO
		                   FROM   TB_DORMANT_CUST
		                   WHERE  DORMANT_DT >= DATE_FORMAT(CURRENT_DATE(), '%Y%m%d%H%i%S')
		                   AND    SITE_CD = #{siteCd}
		                   )
	</insert>

	<!--주문정보 휴면처리-->
	<update id="updateDormantOrder" parameterType="CustomerSearch">
		/*TsbCustomerDao.updateDormantOrder*/
		UPDATE TB_ORDER
		SET    ORD_NM = '휴면'
		     , ORD_PHNNO = NULL
		     , ORD_TELNO = NULL
		     , ORD_EMAIL = NULL
		WHERE  CUST_NO IN (
		                   SELECT CUST_NO
		                   FROM   TB_DORMANT_CUST
		                   WHERE  DORMANT_DT >= DATE_FORMAT(CURRENT_DATE(), '%Y%m%d%H%i%S')
		                   AND    SITE_CD = #{siteCd}
		                  )
	</update>


	<!-- 재가입불가 기간 지난 회원 -->
	<select id="getExpireSecedeCustomerList" parameterType="CustomerSearch" resultType="Customer">
		/*TsbCustomerDao.getExpireSecedeCustomerList*/
		SELECT C.CUST_NO
		FROM   TB_CUSTOMER C
		WHERE  C.CUST_STAT = 'G104_30' -- 탈퇴회원
		AND    C.SITE_CD = #{siteCd}
		AND    C.SECEDE_DT <![CDATA[<]]> DATE_FORMAT(DATE_ADD(CURRENT_DATE(), INTERVAL -#{rejoinRejectDay} DAY), '%Y%m%d%H%i%S')
		AND    EXISTS (
		               SELECT 1
		               FROM TB_SECEDE_CUST SC
		               WHERE SC.CUST_NO = C.CUST_NO
		               )
	</select>

	<!--개인정보 이용내역 안내(년 1회) 대상-->
	<select id="getPrivacyPolicyNoticeTargetList" parameterType="CustomerSearch" resultType="Customer">
		/*TsbCustomerDao.getPrivacyPolicyNoticeTargetList*/
		SELECT  C.CUST_NO
		      , C.CUST_ID
		      , C.CUST_NM
		      , C.CELL_PHNNO
		      , C.EMAIL
		      , DATEDIFF(NOW(), C.JOIN_DT) AS DIFF_JOIN_DT
		FROM    TB_CUSTOMER C
		WHERE   C.CUST_STAT = 'G104_10' -- 활동회원
		AND     C.SITE_CD = #{siteCd}
		AND     NOT EXISTS (
		                    SELECT 1
		                    FROM  TB_CUST_CONTACT_HST CCH
		                    WHERE CCH.RECEIVER_NO = C.CUST_NO
		                    AND   CCH.SEND_DT >= DATE_FORMAT(CONCAT(YEAR(NOW()),'-01-01 00:00:00'), '%Y%m%d%H%i%S')
		                    AND   CCH.SEND_DT <![CDATA[<=]]> DATE_FORMAT(CONCAT(YEAR(NOW()),'-12-31 23:59:59'), '%Y%m%d%H%i%S')
		                    AND   CCH.CONTACT_TYPE = 'G054_208'
		                    )
	</select>

	<!--개인정보 이용내역 안내(년 1회) 대상 생성 및 발송(알림톡) -->
	<insert id="createPrivacyPolicyNoticeKko" parameterType="SsgDirectMessage" timeout="600">
		/*TsbCustomerDao.createPrivacyPolicyNoticeKko*/
		INSERT INTO style24_msg.SSG_SEND_TRAN_KKO (
		       FUSERID                        /*사용자계정*/
		     , FSECTIONCODE                   /*계층코드(SINC로부터 부여받은 코드값)*/
		     , FCAMPCODE                      /*캠페인코드(CRM전송 등에 이용)*/
		     , FYELLOWID                      /*KKO발신프로필키(카카오 전송을 위해 승인받은 프로필키)*/
		     , FKKOSUBJECT                    /*KKO친구툭전용제목*/
		     , FTEMPLATEKEY                   /*KKO템플릿키*/
		     , FKKOBUTTON                     /*KKO버튼(링크기능, JSON 이용)*/
		     , FMSGTYPE                       /*메시지타입(4:KKO)*/
		     , FMESSAGE                       /*메시지본문*/
		     , FSENDDATE                      /*메시지발송시간(예약메시지인경우 해당 예약일시)*/
		     , FKKORESENDTYPE                 /*KKO/KKF재발송메시지타입(SMS/LMS)*/
		     , FKKORESENDMSG                  /*KKO/KKF재발송메시지내용*/
		     , FDESTINE                       /*수신자전화번호*/
		     , FCALLBACK                      /*발신자전화번호(회신번호)*/
		)
		SELECT C.CUST_NO                     AS FUSERID
		     , #{fsectioncode}               AS FSECTIONCODE
		     , #{fcampcode}                  AS FCAMPCODE
		     , #{fyellowid}                  AS FYELLOWID
		     , #{fkkosubject}                AS FKKOSUBJECT
		     , #{ftemplatekey}               AS FTEMPLATEKEY
		     , #{fkkobutton}                 AS FKKOBUTTON
		     , '4'                           AS FMSGTYPE
		     , #{fmessage}                   AS FMESSAGE
		     , CASE WHEN DATE_FORMAT(NOW(), '%H') <![CDATA[<=]]> 8 THEN STR_TO_DATE(CONCAT(DATE_FORMAT(NOW(), '%Y-%M-%D'), ' 9'), '%Y-%M-%D %H')
		            WHEN DATE_FORMAT(NOW(), '%H') BETWEEN 9 AND 19 THEN NOW()
		            ELSE STR_TO_DATE(CONCAT(DATE_FORMAT(ADDDATE(NOW(), INTERVAL 1 DAY), '%Y-%M-%D'), ' 9'), '%Y-%M-%D %H')
		       END                           AS FSENDDATE
		     , #{fkkoresendtype}             AS FKKORESENDTYPE
		     , #{fkkoresendmsg}              AS FKKORESENDMSG
		     , FN_DEC_AES(C.CELL_PHNNO)      AS FDESTINE
		     , #{fcallback}                  AS FCALLBACK
		FROM   TB_CUSTOMER C
		WHERE  C.CUST_STAT = 'G104_10' -- 활동회원
		AND    C.CELL_PHNNO IS NOT NULL
		AND    NOT EXISTS (
		                   SELECT 1
		                   FROM  TB_CUST_CONTACT_HST CCH
		                   WHERE CCH.RECEIVER_NO = C.CUST_NO
		                   AND   CCH.SEND_DT >= DATE_FORMAT(CONCAT(YEAR(NOW()),'-01-01 00:00:00'), '%Y%m%d%H%i%S')
 		                   AND   CCH.SEND_DT <![CDATA[<=]]> DATE_FORMAT(CONCAT(YEAR(NOW()),'-12-31 23:59:59'), '%Y%m%d%H%i%S')
		                   AND   CCH.CONTACT_METHOD = 'G055_12' -- 알림톡
		                   AND   CCH.CONTACT_TYPE = 'G054_208'  -- 개인정보이용 내역
		                   )
	</insert>

	<!--개인정보 이용내역 안내(년 1회) 대상 생성 및 발송(알림톡) -->
	<insert id="createPrivacyPolicyNoticeKkoDev" parameterType="SsgDirectMessage" timeout="600">
		/*TsbCustomerDao.createPrivacyPolicyNoticeKkoDev*/
		INSERT INTO SSG_SEND_TRAN_KKO (
		       FUSERID                       /*사용자계정*/
		     , FSECTIONCODE                  /*계층코드(SINC로부터 부여받은 코드값)*/
		     , FCAMPCODE                     /*캠페인코드(CRM전송 등에 이용)*/
		     , FYELLOWID                     /*KKO발신프로필키(카카오 전송을 위해 승인받은 프로필키)*/
		     , FKKOSUBJECT                   /*KKO친구툭전용제목*/
		     , FTEMPLATEKEY                  /*KKO템플릿키*/
		     , FKKOBUTTON                    /*KKO버튼(링크기능, JSON 이용)*/
		     , FMSGTYPE                      /*메시지타입(4:KKO)*/
		     , FMESSAGE                      /*메시지본문*/
		     , FSENDDATE                     /*메시지발송시간(예약메시지인경우 해당 예약일시)*/
		     , FKKORESENDTYPE                /*KKO/KKF재발송메시지타입(SMS/LMS)*/
		     , FKKORESENDMSG                 /*KKO/KKF재발송메시지내용*/
		     , FDESTINE                      /*수신자전화번호*/
		     , FCALLBACK                     /*발신자전화번호(회신번호)*/
		)
		SELECT C.CUST_NO                     AS FUSERID
		     , #{fsectioncode}               AS FSECTIONCODE
		     , #{fcampcode}                  AS FCAMPCODE
		     , #{fyellowid}                  AS FYELLOWID
		     , #{fkkosubject}                AS FKKOSUBJECT
		     , #{ftemplatekey}               AS FTEMPLATEKEY
		     , #{fkkobutton}                 AS FKKOBUTTON
		     , '4'                           AS FMSGTYPE
		     , #{fmessage}                   AS FMESSAGE
		     , CASE WHEN DATE_FORMAT(NOW(), '%H') <![CDATA[<=]]> 8 THEN STR_TO_DATE(CONCAT(DATE_FORMAT(NOW(), '%Y-%M-%D'), ' 9'), '%Y-%M-%D %H')
		            WHEN DATE_FORMAT(NOW(), '%H') BETWEEN 9 AND 19 THEN NOW()
		            ELSE STR_TO_DATE(CONCAT(DATE_FORMAT(ADDDATE(NOW(), INTERVAL 1 DAY), '%Y-%M-%D'), ' 9'), '%Y-%M-%D %H')
		       END                           AS FSENDDATE
		     , #{fkkoresendtype}             AS FKKORESENDTYPE
		     , #{fkkoresendmsg}              AS FKKORESENDMSG
		     , FN_DEC_AES(C.CELL_PHNNO)      AS FDESTINE
		     , #{fcallback}                  AS FCALLBACK
		FROM   TB_CUSTOMER C
		WHERE  C.CUST_STAT = 'G104_10' -- 활동회원
		AND    C.CELL_PHNNO IS NOT NULL
		AND    NOT EXISTS (
		                   SELECT 1
		                   FROM  TB_CUST_CONTACT_HST CCH
		                   WHERE CCH.RECEIVER_NO = C.CUST_NO
		                   AND   CCH.SEND_DT >= DATE_FORMAT(CONCAT(YEAR(NOW()),'-01-01 00:00:00'), '%Y%m%d%H%i%S')
 		                   AND   CCH.SEND_DT <![CDATA[<=]]> DATE_FORMAT(CONCAT(YEAR(NOW()),'-12-31 23:59:59'), '%Y%m%d%H%i%S')
		                   AND   CCH.CONTACT_METHOD = 'G055_12' -- 알림톡
		                   AND   CCH.CONTACT_TYPE = 'G054_208'  -- 개인정보이용 내역
		                   )
	</insert>

	<!--개인정보 이용내역 안내(년 1회) 대상 생성 및 발송(메일) -->
	<insert id="createPrivacyPolicyNoticeEmail" parameterType="Netpathy" timeout="600">
		/*TsbCustomerDao.createPrivacyPolicyNoticeEmail*/
		INSERT INTO style24_msg.AUTOMAIL_INTERFACE (
		       LEGACYID     /*회원ID*/
		     , AUTOTYPE     /*자동메일타입*/
		     , EMAIL        /*이메일*/
		     , NAME         /*이름*/
		     , INSERTDATE   /*입력일*/
		     , SENDTIME     /*예약전송일*/
		     , OPENTIME
		     , SENTTIME
		     , SENDYN       /*전송여부*/
		     , CMPNCODE
		     , FROMADDRESS
		     , FROMNAME
		     , TITLE        /*메일제목*/
		     , CONTENT      /*메일내용*/
		     , TAG1
		     , TAG2
		     , TAG3
		     , TAG4
		     , TAG5
		     , TAG6
		     , TAG7
		     , TAG8
		     , TAG9
		     , TAG10
		)
		SELECT C.CUST_ID                                               AS LEGACYID
		     , #{autotype}                                             AS AUTOTYPE
		     , FN_DEC_AES(C.EMAIL)                                     AS EMAIL
		     , FN_DEC_AES(C.CUST_NM)                                   AS NAME
		     , NOW()                                                   AS INSERTDATE
		     , IFNULL(STR_TO_DATE(#{sendtime},'%Y%m%d%H%i%S'),NOW())   AS SENDTIME
		     , NULL                                                    AS OPENTIME
		     , NULL                                                    AS SENTTIME
		     , 'N'                                                     AS SENDYN
		     , NULL                                                    AS CMPNCODE
		     , NULL                                                    AS FROMADDRESS
		     , NULL                                                    AS FROMNAME
		     , #{title}                                                AS TITLE
		     , #{content}                                              AS CONTENT
		     , NULL                                                    AS TAG1
		     , NULL                                                    AS TAG2
		     , NULL                                                    AS TAG3
		     , NULL                                                    AS TAG4
		     , NULL                                                    AS TAG5
		     , NULL                                                    AS TAG6
		     , NULL                                                    AS TAG7
		     , NULL                                                    AS TAG8
		     , NULL                                                    AS TAG9
		     , NULL                                                    AS TAG10
		FROM   TB_CUSTOMER C
		WHERE  C.CUST_STAT = 'G104_10' -- 활동회원
		AND    C.EMAIL IS NOT NULL
		AND    NOT EXISTS (
		                   SELECT 1
		                   FROM  TB_CUST_CONTACT_HST CCH
		                   WHERE CCH.RECEIVER_NO = C.CUST_NO
		                   AND   CCH.SEND_DT >= DATE_FORMAT(CONCAT(YEAR(NOW()),'-01-01 00:00:00'), '%Y%m%d%H%i%S')
 		                   AND   CCH.SEND_DT <![CDATA[<=]]> DATE_FORMAT(CONCAT(YEAR(NOW()),'-12-31 23:59:59'), '%Y%m%d%H%i%S')
		                   AND   CCH.CONTACT_METHOD = 'G055_20' -- EMAIL
		                   AND   CCH.CONTACT_TYPE = 'G054_208'  -- 개인정보이용 내역
		                   )
	</insert>

	<!--개인정보 이용내역 안내(년 1회) 대상 생성 및 발송(메일) -->
	<insert id="createPrivacyPolicyNoticeEmailDev" parameterType="Netpathy" timeout="600">
		/*TsbCustomerDao.createPrivacyPolicyNoticeEmailDev*/
		INSERT INTO AUTOMAIL_INTERFACE (
		       LEGACYID     /*회원ID*/
		     , AUTOTYPE     /*자동메일타입*/
		     , EMAIL        /*이메일*/
		     , NAME         /*이름*/
		     , INSERTDATE   /*입력일*/
		     , SENDTIME     /*예약전송일*/
		     , OPENTIME
		     , SENTTIME
		     , SENDYN       /*전송여부*/
		     , CMPNCODE
		     , FROMADDRESS
		     , FROMNAME
		     , TITLE        /*메일제목*/
		     , CONTENT      /*메일내용*/
		     , TAG1
		     , TAG2
		     , TAG3
		     , TAG4
		     , TAG5
		     , TAG6
		     , TAG7
		     , TAG8
		     , TAG9
		     , TAG10
		)
		SELECT C.CUST_ID                                               AS LEGACYID
		     , #{autotype}                                             AS AUTOTYPE
		     , FN_DEC_AES(C.EMAIL)                                     AS EMAIL
		     , FN_DEC_AES(C.CUST_NM)                                   AS NAME
		     , NOW()                                                   AS INSERTDATE
		     , IFNULL(STR_TO_DATE(#{sendtime},'%Y%m%d%H%i%S'),NOW())   AS SENDTIME
		     , NULL                                                    AS OPENTIME
		     , NULL                                                    AS SENTTIME
		     , 'N'                                                     AS SENDYN
		     , NULL                                                    AS CMPNCODE
		     , NULL                                                    AS FROMADDRESS
		     , NULL                                                    AS FROMNAME
		     , #{title}                                                AS TITLE
		     , #{content}                                              AS CONTENT
		     , NULL                                                    AS TAG1
		     , NULL                                                    AS TAG2
		     , NULL                                                    AS TAG3
		     , NULL                                                    AS TAG4
		     , NULL                                                    AS TAG5
		     , NULL                                                    AS TAG6
		     , NULL                                                    AS TAG7
		     , NULL                                                    AS TAG8
		     , NULL                                                    AS TAG9
		     , NULL                                                    AS TAG10
		FROM   TB_CUSTOMER C
		WHERE  C.CUST_STAT = 'G104_10' -- 활동회원
		AND    C.EMAIL IS NOT NULL
		AND    NOT EXISTS (
		                   SELECT 1
		                   FROM  TB_CUST_CONTACT_HST CCH
		                   WHERE CCH.RECEIVER_NO = C.CUST_NO
		                   AND   CCH.SEND_DT >= DATE_FORMAT(CONCAT(YEAR(NOW()),'-01-01 00:00:00'), '%Y%m%d%H%i%S')
 		                   AND   CCH.SEND_DT <![CDATA[<=]]> DATE_FORMAT(CONCAT(YEAR(NOW()),'-12-31 23:59:59'), '%Y%m%d%H%i%S')
		                   AND   CCH.CONTACT_METHOD = 'G055_20' -- EMAIL
		                   AND   CCH.CONTACT_TYPE = 'G054_208'  -- 개인정보이용 내역
		                   )
	</insert>

	<!-- 회원접촉이력 생성 -->
	<insert id="createCustomerContactHistoryBulk" parameterType="CustContactHst" timeout="600">
		/* TscCustomer.createCustomerContactHistoryBulk */
		INSERT INTO TB_CUST_CONTACT_HST (
		       CONTACT_TYPE
		     , CONTACT_METHOD
		     , CONTACT_CONTENTS
		     , CONTACT_MEMO
		     , SENDER_NO
		     , SEND_DT
		     , RECEIVER_NO
		     , REG_NO
		     , REG_DT
		)
		SELECT #{contactType}              AS CONTACT_TYPE
		     , #{contactMethod}            AS CONTACT_METHOD
		     , #{contactContents}          AS CONTACT_CONTENTS
		     , #{contactMemo}              AS CONTACT_MEMO
		     , IFNULL(#{senderNo}, 99999)  AS SENDER_NO
		     , NOW()                       AS SEND_DT
		     , C.CUST_NO                   AS RECEIVER_NO
		     , IFNULL(#{regNo}, 99999)     AS REG_NO
		     , NOW()                       AS REG_DT
		FROM   TB_CUSTOMER C
		WHERE  C.CUST_STAT = 'G104_10' -- 활동회원
		<if test="contactType == 'G054_208'"> -- 개인정보이용 내역인 경우
		    <if test="contactMethod == 'G055_12'">
		AND   C.CELL_PHNNO IS NOT NULL
		    </if>
		    <if test="contactMethod == 'G055_20'">
		AND   C.EMAIL IS NOT NULL
		    </if>
		</if>
		AND    NOT EXISTS (
		                   SELECT 1
		                   FROM  TB_CUST_CONTACT_HST CCH
		                   WHERE CCH.RECEIVER_NO = C.CUST_NO
		                   AND   CCH.SEND_DT >= DATE_FORMAT(CONCAT(YEAR(NOW()),'-01-01 00:00:00'), '%Y%m%d%H%i%S')
 		                   AND   CCH.SEND_DT <![CDATA[<=]]> DATE_FORMAT(CONCAT(YEAR(NOW()),'-12-31 23:59:59'), '%Y%m%d%H%i%S')
		                   AND   CCH.CONTACT_METHOD = #{contactMethod}
		                   AND   CCH.CONTACT_TYPE = #{contactType}
		                   )
	</insert>

		<!--마케팅 정보 수신자 / 가입일로부터 2년 마다-->
	<select id="getMarketingAgreeNoticeTargetListCount" parameterType="CustomerSearch" resultType="int">
		/*TsbCustomerDao.getMarketingAgreeNoticeTargetListCount*/
		SELECT  COUNT(*) AS CNT
		FROM    TB_CUSTOMER C
		WHERE   C.CUST_STAT = 'G104_10' -- 활동회원
		AND    (C.SMS_AGREE_YN = 'Y' OR C.EMAIL_AGREE_YN = 'Y' OR C.MK_AGREE_YN = 'Y')
		AND     TIMESTAMPDIFF(YEAR,JOIN_DT, NOW()) >= 2
		AND     TIMESTAMPDIFF(YEAR,JOIN_DT, NOW()) MOD 2 = 0
		AND     C.SITE_CD = #{siteCd}
		AND     NOT EXISTS (
		                    SELECT 1
		                    FROM  TB_CUST_CONTACT_HST CCH
		                    WHERE CCH.RECEIVER_NO = C.CUST_NO
		                    AND   CCH.SEND_DT >= DATE_FORMAT(CONCAT(YEAR(NOW()),'-01-01 00:00:00'), '%Y%m%d%H%i%S')
		                    AND   CCH.SEND_DT <![CDATA[<=]]> DATE_FORMAT(CONCAT(YEAR(NOW()),'-12-31 23:59:59'), '%Y%m%d%H%i%S')
		                    AND   CCH.CONTACT_TYPE = 'G054_209'
		                    )
	</select>

	<!--마케팅 정보 수신자 / 가입일로부터 2년 마다-->
	<select id="getMarketingAgreeNoticeTargetList" parameterType="CustomerSearch" resultType="Customer">
		/*TsbCustomerDao.getMarketingAgreeNoticeTargetList*/
		<include refid="selectForPagingHeader"/>
		SELECT  C.CUST_NO
		      , C.CUST_ID
		      , C.CUST_NM
		      , C.CELL_PHNNO
		      , C.EMAIL
		      , C.SMS_AGREE_YN
		      , C.EMAIL_AGREE_YN
		      , C.APP_AGREE_YN
		      , C.MK_AGREE_YN
		      , DATE_FORMAT(C.APP_AGREE_DT, '%Y.%m.%d') AS APP_AGREE_DT
		      , DATE_FORMAT(C.SMS_AGREE_DT, '%Y.%m.%d') AS SMS_AGREE_DT
		      , DATE_FORMAT(C.EMAIL_AGREE_DT, '%Y.%m.%d') AS EMAIL_AGREE_DT
		      , DATE_FORMAT(C.MK_AGREE_DT, '%Y.%m.%d') AS MK_AGREE_DT
		      , ROW_NUMBER() OVER (ORDER BY C.CUST_NO) AS NUMB
		FROM    TB_CUSTOMER C
		WHERE   C.CUST_STAT = 'G104_10' -- 활동회원
		AND    (C.SMS_AGREE_YN = 'Y' OR C.EMAIL_AGREE_YN = 'Y' OR C.MK_AGREE_YN = 'Y')
		AND     TIMESTAMPDIFF(YEAR,JOIN_DT, NOW()) >= 2
		AND     TIMESTAMPDIFF(YEAR,JOIN_DT, NOW()) MOD 2 = 0
		AND     C.SITE_CD = #{siteCd}
		AND     NOT EXISTS (
		                    SELECT 1
		                    FROM  TB_CUST_CONTACT_HST CCH
		                    WHERE CCH.RECEIVER_NO = C.CUST_NO
		                    AND   CCH.SEND_DT >= DATE_FORMAT(CONCAT(YEAR(NOW()),'-01-01 00:00:00'), '%Y%m%d%H%i%S')
		                    AND   CCH.SEND_DT <![CDATA[<=]]> DATE_FORMAT(CONCAT(YEAR(NOW()),'-12-31 23:59:59'), '%Y%m%d%H%i%S')
		                    AND   CCH.CONTACT_TYPE = 'G054_209'
		                    )
		ORDER BY C.CUST_NO
		<include refid="selectForPagingFooter"/>
	</select>

	<!--회원등급정책 목록-->
	<select id="getCustGradePolicyList" parameterType="CustGrade" resultType="CustGrade">
		/*TsbCustomerDao.getCustGradePolicyList*/
		SELECT GRADE_CD      AS GRADE_ACD
		     , MIN_BUY_AMT
		     , MIN_BUY_CNT
		     , BUY_EXCEPT_AMT
		     , CAL_MONTHS
		FROM   TB_CUST_GRADE_POLICY
		WHERE  USE_YN = 'Y'
		AND    SITE_CD = #{siteCd}
		ORDER BY GRADE_CD
	</select>

	<!--변경된 회원등급 이력 생성-->
	<insert id="createChangeCustGradeHst" parameterType="CustGrade" timeout="600">
		/*TsbCustomerDao.createChangeCustGradeHst*/
		INSERT INTO TB_CUST_GRADE_HST (
		       CUST_NO
		     , APPLY_YMD
		     , GRADE_BCD
		     , GRADE_ACD
		     , REAL_ORD_AMT
		     , ORD_CNT
		     , REG_NO
		     , REG_DT
		)
		SELECT TG.CUST_NO
		     , DATE_FORMAT(NOW(), '%Y%m%d') AS APPLY_YMD
		     , TG.CUST_GRADE                AS GRADE_BCD
		     , #{gradeAcd}                  AS GRADE_ACD
		     , TG.SUM_REAL_ORD_AMT          AS REAL_ORD_AMT
		     , TG.ORD_NO_CNT                AS ORD_CNT
		     , #{regNo}                     AS REG_NO
		     , NOW()                        AS REG_DT
		FROM (
		     SELECT C.CUST_NO
		          , COUNT(DISTINCT ORD.ORD_NO)      AS ORD_NO_CNT
		          , IFNULL(SUM(ORD.SUM_REAL_ORD_AMT), 0) AS SUM_REAL_ORD_AMT
		          , MAX(C.CUST_GRADE)               AS CUST_GRADE
		     FROM TB_CUSTOMER C
		     LEFT JOIN (
		                SELECT O.CUST_NO
		                     , O.ORD_NO
		                     , SUM(OD.REAL_ORD_AMT + OD.GFCD_USE_AMT) AS SUM_REAL_ORD_AMT
		                FROM   TB_ORDER O
		                INNER JOIN
		                       TB_ORDER_DETAIL OD
		                WHERE  O.ORD_NO = OD.ORD_NO
		                AND    OD.ORD_DTL_STAT IN ('G013_60', 'G013_70') /*구매확정*/
		                AND    O.ORD_DT >= DATE_ADD(LAST_DAY(NOW() - INTERVAL 1 MONTH) + INTERVAL 1 DAY, INTERVAL - #{calMonths} MONTH)
		                AND    O.ORD_DT <![CDATA[<]]> DATE_ADD(LAST_DAY(NOW()), INTERVAL 1 DAY) /*익월 1일*/
		                GROUP BY O.ORD_NO, O.CUST_NO
		                HAVING SUM(OD.REAL_ORD_AMT + OD.GFCD_USE_AMT) >= #{buyExceptAmt}
		               ) ORD
		     ON    C.CUST_NO = ORD.CUST_NO
		     WHERE C.CUST_STAT = 'G104_10'
		     AND   C.CUST_NO != 0
		     GROUP BY C.CUST_NO
		     ) TG
		WHERE (TG.ORD_NO_CNT >= #{minBuyCnt} OR TG.SUM_REAL_ORD_AMT >= #{minBuyAmt})
		AND   NOT EXISTS (
		                  SELECT 1
		                  FROM  TB_CUST_GRADE_HST CGH
		                  WHERE CGH.CUST_NO = TG.CUST_NO
		                  AND   CGH.APPLY_YMD = DATE_FORMAT(NOW(), '%Y%m%d')
		                 )
	</insert>

	<!--변경된등급 회원 이력 생성-->
	<insert id="createChangeCustomerHst" parameterType="CustGrade" timeout="600">
		/*TsbCustomerDao.createChangeCustomerHst*/
		INSERT INTO TB_CUSTOMER_HST (
		       CUST_NO
		     , CUST_ID
		     , CUST_NM
		     , PASSWD
		     , BIRTH_YMD
		     , SEX_GB
		     , CELL_PHNNO
		     , APP_AGREE_YN
		     , APP_AGREE_DT
		     , SMS_AGREE_YN
		     , SMS_AGREE_DT
		     , EMAIL
		     , EMAIL_AGREE_YN
		     , EMAIL_AGREE_DT
		     , MK_AGREE_YN
		     , MK_AGREE_DT
		     , HOME_ZIPCODE
		     , HOME_BASE_ADDR
		     , HOME_DTL_ADDR
		     , SITE_CD
		     , FRONT_GB
		     , AF_LINK_CD
		     , CUST_GB
		     , CUST_GRADE
		     , JOIN_DT
		     , FOREIGNER_YN
		     , CUST_STAT
		     , PASSWD_CHG_DT
		     , TEMP_PASSWD_YN
		     , LOGIN_LDT
		     , CI
		     , AUTH_DT
		     , SNS_TYPE
		     , MANAGED_RSN
		     , MANAGED_DTL_RSN
		     , MANAGED_DT
		     , SECEDE_RSN
		     , SECEDE_DTL_RSN
		     , SECEDE_DT
		     , RM_DORMANT_DT
		     , REG_NO
		     , REG_DT
		     , UPD_NO
		     , UPD_DT
		)
		SELECT CUST_NO
		     , CUST_ID
		     , CUST_NM
		     , PASSWD
		     , BIRTH_YMD
		     , SEX_GB
		     , CELL_PHNNO
		     , APP_AGREE_YN
		     , APP_AGREE_DT
		     , SMS_AGREE_YN
		     , SMS_AGREE_DT
		     , EMAIL
		     , EMAIL_AGREE_YN
		     , EMAIL_AGREE_DT
		     , MK_AGREE_YN
		     , MK_AGREE_DT
		     , HOME_ZIPCODE
		     , HOME_BASE_ADDR
		     , HOME_DTL_ADDR
		     , SITE_CD
		     , FRONT_GB
		     , AF_LINK_CD
		     , CUST_GB
		     , CUST_GRADE
		     , JOIN_DT
		     , FOREIGNER_YN
		     , CUST_STAT
		     , PASSWD_CHG_DT
		     , TEMP_PASSWD_YN
		     , LOGIN_LDT
		     , CI
		     , AUTH_DT
		     , SNS_TYPE
		     , MANAGED_RSN
		     , MANAGED_DTL_RSN
		     , MANAGED_DT
		     , SECEDE_RSN
		     , SECEDE_DTL_RSN
		     , SECEDE_DT
		     , RM_DORMANT_DT
		     , #{regNo}   AS REG_NO
		     , NOW()      AS REG_DT
		     , UPD_NO
		     , UPD_DT
		FROM   TB_CUSTOMER
		WHERE  CUST_NO IN (
		                   SELECT CGH.CUST_NO
		                   FROM   TB_CUST_GRADE_HST CGH
		                   WHERE  CGH.APPLY_YMD = DATE_FORMAT(NOW(), '%Y%m%d')
		                   )
	</insert>

	<!--회원등급 변경 처리-->
	<update id="updateCustomerGrade" parameterType="CustGrade" timeout="600">
		/*TsbCustomerDao.updateCustomerGrade*/
		UPDATE TB_CUSTOMER C
		INNER JOIN
		       TB_CUST_GRADE_HST CGH
		ON     C.CUST_NO = CGH.CUST_NO
		SET    CUST_GRADE = CGH.GRADE_ACD
		     , UPD_DT = NOW()
		     , UPD_NO = #{updNo}
		WHERE  CGH.APPLY_YMD = DATE_FORMAT(NOW(), '%Y%m%d')
	</update>

		<!--회원등급 대상 목록-->
	<select id="getCustGradeChangeTargetListCount" parameterType="CustomerSearch" resultType="int">
		/*TsbCustomerDao.getCustGradeChangeTargetListCount*/
		SELECT COUNT(*) AS CNT
		FROM   TB_CUSTOMER C
		INNER JOIN
		       TB_CUST_GRADE_HST CGH
		ON     C.CUST_NO = CGH.CUST_NO
		WHERE  C.CUST_STAT = 'G104_10'
		AND    C.SITE_CD = #{siteCd}
		AND    CGH.APPLY_YMD = DATE_FORMAT(NOW(), '%Y%m%d')
	</select>

	<!--회원등급 대상 목록-->
	<select id="getCustGradeChangeTargetList" parameterType="CustomerSearch" resultType="Customer">
		/*TsbCustomerDao.getCustGradeChangeTargetList*/
		<include refid="selectForPagingHeader"/>
		    SELECT C.CUST_NO
		         , C.CUST_NM
		         , C.CELL_PHNNO
		         , C.EMAIL
		         , C.SMS_AGREE_YN
		         , C.EMAIL_AGREE_YN
		         , FN_GET_CODE_NM('G110', CGH.GRADE_ACD) AS CUST_GRADE_NM
		         , SUBSTR(CGH.APPLY_YMD, 5, 2) AS MM
		         , ROW_NUMBER() OVER (ORDER BY C.CUST_NO) AS NUMB
		    FROM   TB_CUSTOMER C
		    INNER JOIN
		           TB_CUST_GRADE_HST CGH
		    ON     C.CUST_NO = CGH.CUST_NO
		    WHERE  C.CUST_STAT = 'G104_10'
		    AND    C.SITE_CD = #{siteCd}
		    AND    CGH.APPLY_YMD = DATE_FORMAT(NOW(), '%Y%m%d')
		    ORDER BY C.CUST_NO
		<include refid="selectForPagingFooter"/>
	</select>

	<!-- 넷퍼시메일솔루션 회원정보 Truncate - 운영DB -->
	<select id="truncateNetpathyMailCustomer" statementType="CALLABLE">
		/* TsbCustomerDao.truncateNetpathyMailCustomer */
		/* TRUNCATE TABLE STYLE24_MAILBATCH.NETPATHY_MEMBER */
		{ CALL FN_INIT_TABLE('STYLE24_MAILBATCH.NETPATHY_MEMBER') }
	</select>

	<!-- 넷퍼시메일솔루션 회원정보 Truncate - 개발DB -->
	<select id="truncateNetpathyMailCustomerDev" statementType="CALLABLE">
		/* TsbCustomerDao.truncateNetpathyMailCustomerDev */
		/* TRUNCATE TABLE NETPATHY_MEMBER */
		{ CALL FN_INIT_TABLE('NETPATHY_MEMBER') }
	</select>

	<!-- 넷퍼시메일솔루션 회원정보 생성 - 운영DB -->
	<insert id="createNetpathyMailCustomer" timeout="600">
		/* TsbCustomerDao.createNetpathyMailCustomer */
		INSERT INTO STYLE24_MAILBATCH.NETPATHY_MEMBER (
		       CUST_NO
		     , CUST_ID
		     , CUST_NM
		     , BIRTH_YMD
		     , EMAIL
		     , EMAIL_AGREE_YN
		     , SEX_GB
		     , ZIPCODE
		     , JOIN_DT
		     , UPD_DT
		)
		SELECT C.CUST_NO                                 /*회원GUID(=회원번호)*/
		     , C.CUST_ID                                 /*로그인ID(=회원ID)*/
		     , C.CUST_NM                                 /*회원명(암호화된값)*/
		     , C.BIRTH_YMD                               /*생년월일(암호화된값)*/
		     , C.EMAIL                                   /*이메일(암호화된값)*/
		     , C.EMAIL_AGREE_YN                          /*메일수신여부*/
		     , C.SEX_GB                                  /*성별(암호화된값)*/
		     , CDA.RECIP_ZIPCODE              AS ZIPCODE /*우편번호*/
		     , IFNULL(C.JOIN_DT,'1900-01-01') AS JOIN_DT /*가입일시*/
		     , C.UPD_DT                                  /*수정일시*/
		FROM   TB_CUSTOMER C
		LEFT OUTER JOIN TB_CUST_DELIVERY_ADDR CDA ON C.CUST_NO = CDA.CUST_NO
		                                         AND CDA.DEL_YN = 'N' /*삭제안된넘*/
		                                         AND CDA.DEFAULT_YN = 'Y' /*기본배송지*/
		WHERE  CUST_STAT = 'G104_10' /*활동회원*/
	</insert>

	<!-- 넷퍼시메일솔루션 회원정보 생성 - 개발DB -->
	<insert id="createNetpathyMailCustomerDev" timeout="600">
		/* TsbCustomerDao.createNetpathyMailCustomerDev */
		INSERT INTO NETPATHY_MEMBER (
		       CUST_NO
		     , CUST_ID
		     , CUST_NM
		     , BIRTH_YMD
		     , EMAIL
		     , EMAIL_AGREE_YN
		     , SEX_GB
		     , ZIPCODE
		     , JOIN_DT
		     , UPD_DT
		)
		SELECT C.CUST_NO                                 /*회원GUID(=회원번호)*/
		     , C.CUST_ID                                 /*로그인ID(=회원ID)*/
		     , C.CUST_NM                                 /*회원명(암호화된값)*/
		     , C.BIRTH_YMD                               /*생년월일(암호화된값)*/
		     , C.EMAIL                                   /*이메일(암호화된값)*/
		     , C.EMAIL_AGREE_YN                          /*메일수신여부*/
		     , C.SEX_GB                                  /*성별(암호화된값)*/
		     , CDA.RECIP_ZIPCODE              AS ZIPCODE /*우편번호*/
		     , IFNULL(C.JOIN_DT,'1900-01-01') AS JOIN_DT /*가입일시*/
		     , C.UPD_DT                                  /*수정일시*/
		FROM   TB_CUSTOMER C
		LEFT OUTER JOIN TB_CUST_DELIVERY_ADDR CDA ON C.CUST_NO = CDA.CUST_NO
		                                         AND CDA.DEL_YN = 'N' /*삭제안된넘*/
		                                         AND CDA.DEFAULT_YN = 'Y' /*기본배송지*/
		WHERE  CUST_STAT = 'G104_10' /*활동회원*/
	</insert>

	<!-- 넷퍼시메일솔루션 탈퇴/휴면회원정보 Truncate - 운영DB -->
	<select id="truncateNetpathyMailWithdrawalCustomer" statementType="CALLABLE">
		/* TsbCustomerDao.truncateNetpathyMailWithdrawalCustomer */
		/*TRUNCATE TABLE STYLE24_MAILBATCH.NETPATHY_WITHDRAWAL*/
		{ CALL FN_INIT_TABLE('STYLE24_MAILBATCH.NETPATHY_WITHDRAWAL') }
	</select>

	<!-- 넷퍼시메일솔루션 탈퇴/휴면회원정보 Truncate - 개발DB -->
	<select id="truncateNetpathyMailWithdrawalCustomerDev" statementType="CALLABLE">
		/* TsbCustomerDao.truncateNetpathyMailWithdrawalCustomerDev */
		/*TRUNCATE TABLE NETPATHY_WITHDRAWAL*/
		{ CALL FN_INIT_TABLE('NETPATHY_WITHDRAWAL') }
	</select>

	<!-- 넷퍼시메일솔루션 탈퇴/휴면회원정보 생성 - 운영DB -->
	<insert id="createNetpathyMailWithdrawalCustomer" timeout="600">
		/* TsbCustomerDao.createNetpathyMailWithdrawalCustomer */
		INSERT INTO STYLE24_MAILBATCH.NETPATHY_WITHDRAWAL (
		       CUST_NO
		     , CUST_ID
		     , CUST_NM
		     , JOIN_DT
		     , REG_DT
		)
		SELECT CUST_NO                              /*회원GUID(=회원번호)*/
		     , CUST_ID                              /*로그인ID(=회원ID)*/
		     , CUST_NM                              /*회원명(암호화된값)*/
		     , IFNULL(JOIN_DT,SECEDE_DT) AS JOIN_DT /*가입일시*/
		     , SECEDE_DT                 AS REG_DT  /*등록일시*/
		FROM   TB_SECEDE_CUST
		UNION ALL
		SELECT CUST_NO              /*회원GUID(=회원번호)*/
		     , CUST_ID              /*로그인ID(=회원ID)*/
		     , CUST_NM              /*회원명(암호화된값)*/
		     , JOIN_DT              /*가입일시*/
		     , DORMANT_DT AS REG_DT /*등록일시*/
		FROM   TB_DORMANT_CUST
	</insert>

	<!-- 넷퍼시메일솔루션 탈퇴/휴면회원정보 생성 - 개발DB -->
	<insert id="createNetpathyMailWithdrawalCustomerDev" timeout="600">
		/* TsbCustomerDao.createNetpathyMailWithdrawalCustomerDev */
		INSERT INTO NETPATHY_WITHDRAWAL (
		       CUST_NO
		     , CUST_ID
		     , CUST_NM
		     , JOIN_DT
		     , REG_DT
		)
		SELECT CUST_NO                              /*회원GUID(=회원번호)*/
		     , CUST_ID                              /*로그인ID(=회원ID)*/
		     , CUST_NM                              /*회원명(암호화된값)*/
		     , IFNULL(JOIN_DT,SECEDE_DT) AS JOIN_DT /*가입일시*/
		     , SECEDE_DT                 AS REG_DT  /*등록일시*/
		FROM   TB_SECEDE_CUST
		UNION ALL
		SELECT CUST_NO              /*회원GUID(=회원번호)*/
		     , CUST_ID              /*로그인ID(=회원ID)*/
		     , CUST_NM              /*회원명(암호화된값)*/
		     , JOIN_DT              /*가입일시*/
		     , DORMANT_DT AS REG_DT /*등록일시*/
		FROM   TB_DORMANT_CUST
	</insert>

	<!-- 넷퍼시메일솔루션 회원포인트정보 Truncate - 운영DB -->
	<select id="truncateNetpathyMailCustomerPoint" statementType="CALLABLE">
		/* TsbCustomerDao.truncateNetpathyMailCustomerPoint */
		/*TRUNCATE TABLE STYLE24_MAILBATCH.NETPATHY_POINT*/
		{ CALL FN_INIT_TABLE('STYLE24_MAILBATCH.NETPATHY_POINT') }
	</select>

	<!-- 넷퍼시메일솔루션 회원포인트정보 Truncate - 개발DB -->
	<select id="truncateNetpathyMailCustomerPointDev" statementType="CALLABLE">
		/* TsbCustomerDao.truncateNetpathyMailCustomerPointDev */
		/* TRUNCATE TABLE NETPATHY_POINT */
		{ CALL FN_INIT_TABLE('NETPATHY_POINT') }
	</select>

	<!-- 넷퍼시메일솔루션 회원포인트정보 생성 - 운영DB -->
	<insert id="createNetpathyMailCustomerPoint" timeout="600">
		/* TsbCustomerDao.createNetpathyMailCustomerPoint */
		INSERT INTO STYLE24_MAILBATCH.NETPATHY_POINT (
		       CUST_NO
		     , CUST_ID
		     , RM_PNT_AMT
		     , PREV_DT
		)
		SELECT CP.CUST_NO                                                                       /*회원번호*/
		     , C.CUST_ID                                                                        /*회원ID*/
		     , SUM(CASE WHEN CP.EXP_CMP_DT IS NULL THEN CP.RM_PNT_AMT ELSE 0 END) AS RM_PNT_AMT /*남은포인트금액*/
		     , DATE_ADD(CURRENT_DATE(), INTERVAL -1 DAY)                          AS PREV_DT    /*전일*/
		FROM   TB_CUST_POINT CP
		     , TB_CUSTOMER C
		WHERE  CP.CUST_NO = C.CUST_NO
		AND    CP.CUST_NO IN (SELECT CUST_NO
		                      FROM   TB_CUST_POINT
		                      WHERE  UPD_DT <![CDATA[>=]]> DATE_ADD(CURRENT_DATE(), INTERVAL -1 DAY)
		                      AND    UPD_DT <![CDATA[<]]> CURRENT_DATE()
		                     )
		AND    C.CUST_STAT = 'G104_10' /*활동회원만*/
		GROUP  BY CP.CUST_NO
	</insert>

	<!-- 넷퍼시메일솔루션 회원포인트정보 생성 - 개발DB -->
	<insert id="createNetpathyMailCustomerPointDev" timeout="600">
		/* TsbCustomerDao.createNetpathyMailCustomerPointDev */
		INSERT INTO NETPATHY_POINT (
		       CUST_NO
		     , CUST_ID
		     , RM_PNT_AMT
		     , PREV_DT
		)
		SELECT CP.CUST_NO                                                                       /*회원번호*/
		     , C.CUST_ID                                                                        /*회원ID*/
		     , SUM(CASE WHEN CP.EXP_CMP_DT IS NULL THEN CP.RM_PNT_AMT ELSE 0 END) AS RM_PNT_AMT /*남은포인트금액*/
		     , DATE_ADD(CURRENT_DATE(), INTERVAL -1 DAY)                          AS PREV_DT    /*전일*/
		FROM   TB_CUST_POINT CP
		     , TB_CUSTOMER C
		WHERE  CP.CUST_NO = C.CUST_NO
		AND    CP.CUST_NO IN (SELECT CUST_NO
		                      FROM   TB_CUST_POINT
		                      WHERE  UPD_DT <![CDATA[>=]]> DATE_ADD(CURRENT_DATE(), INTERVAL -1 DAY)
		                      AND    UPD_DT <![CDATA[<]]> CURRENT_DATE()
		                     )
		AND    C.CUST_STAT = 'G104_10' /*활동회원만*/
		GROUP  BY CP.CUST_NO
	</insert>

	<!--생일쿠폰 다운로드 안내 대상자-->
	<select id="getBirthDayTargetListCount" parameterType="CustomerSearch" resultType="int">
		/*TsbCustomerDao.getBirthDayTargetListCount*/
		WITH TAB_COUPON_REFVAL1 AS (
		    SELECT CR.CPN_ID
		         , CR.CPN_TARGET
		         , CASE WHEN CR.CPN_TARGET = 'G260_10' /*상품*/ THEN (SELECT GOODS_NM FROM TB_GOODS WHERE GOODS_CD = CR.REF_VAL AND GOODS_STAT = 'G008_90')
		                WHEN CR.CPN_TARGET = 'G260_11' /*카테고리*/ THEN
		                    CASE WHEN IFNULL((SELECT COUNT(1) FROM TB_CATE_4SRCH WHERE CATE1_NO = CR.REF_VAL),0) > 0
		                              THEN (SELECT CATE1_NM FROM TB_CATE_4SRCH WHERE CATE1_NO = CR.REF_VAL LIMIT 1)
		                         WHEN IFNULL((SELECT COUNT(1) FROM TB_CATE_4SRCH WHERE CATE2_NO = CR.REF_VAL),0) > 0
		                              THEN (SELECT CONCAT(CATE1_NM,' > ',CATE2_NM) FROM TB_CATE_4SRCH WHERE CATE2_NO = CR.REF_VAL LIMIT 1)
		                         WHEN IFNULL((SELECT COUNT(1) FROM TB_CATE_4SRCH WHERE CATE3_NO = CR.REF_VAL),0) > 0 THEN (SELECT CONCAT(CATE1_NM,' > ',CATE2_NM) FROM TB_CATE_4SRCH WHERE CATE3_NO = CR.REF_VAL LIMIT 1)
		                         WHEN IFNULL((SELECT COUNT(1) FROM TB_CATE_4SRCH WHERE CATE4_NO = CR.REF_VAL),0) > 0 THEN (SELECT CONCAT(CATE1_NM,' > ',CATE2_NM) FROM TB_CATE_4SRCH WHERE CATE4_NO = CR.REF_VAL LIMIT 1)
		                    END
		                WHEN CR.CPN_TARGET = 'G260_12' /*브랜드*/ THEN (SELECT BRAND_KNM FROM TB_BRAND WHERE BRAND_CD = CR.REF_VAL AND USE_YN = 'Y')
		                WHEN CR.CPN_TARGET = 'G260_13' /*업체*/ THEN (SELECT SUPPLY_COMP_NM FROM TB_SUPPLY_COMPANY WHERE SUPPLY_COMP_CD = CR.REF_VAL AND USE_YN = 'Y' AND SUPPLY_STAT = 'G010_30')
		           END AS REF_VAL
		         , RANK() OVER(PARTITION BY CR.CPN_ID, CR.CPN_TARGET ORDER BY REF_VAL) AS RK
		    FROM   TB_COUPON_REFVAL CR
		    WHERE  CR.CPN_TARGET != 'G260_14' /*제외상품아닌넘*/
		    AND    CR.CPN_ID IN (
		                         SELECT GRADE_CPN_ID3
		                         FROM   TB_CUST_GRADE_POLICY
		                         WHERE  USE_YN = 'Y'
		                         )
		)
		, TAB_COUPON_REFVAL2 AS (
		    SELECT CPN_ID
		         , CPN_TARGET
		         , GROUP_CONCAT(REF_VAL ORDER BY RK ASC SEPARATOR '/' ) AS REF_VAL
		         , (SELECT COUNT(*)
		            FROM   TAB_COUPON_REFVAL1
		            WHERE  CPN_ID = CR.CPN_ID
		            AND    CPN_TARGET = CR.CPN_TARGET)                  AS CNT
		    FROM   TAB_COUPON_REFVAL1 CR
		    WHERE  1 = 1
		    AND    (
		            (CPN_TARGET != 'G260_12' AND RK = 1) /*브랜드 외는 1개만 노출*/
		            OR
		            (CPN_TARGET = 'G260_12' AND RK <![CDATA[<=]]> 2) /*브랜드만 2개 노출*/
		           )
		    GROUP  BY CPN_ID, CPN_TARGET
		    LIMIT  1
		)
		SELECT COUNT(*) AS CNT
		FROM   TB_CUSTOMER C
		INNER JOIN
		       TB_CUST_GRADE_POLICY CGP
		ON     C.CUST_GRADE = CGP.GRADE_CD
		AND    CGP.USE_YN = 'Y'
		INNER JOIN
		       TB_COUPON CO
		ON     CGP.GRADE_CPN_ID3 = CO.CPN_ID
		AND    CO.CPN_STAT = 'G232_11'
		LEFT OUTER JOIN
		       TAB_COUPON_REFVAL2 CR
		ON     CO.CPN_ID = CR.CPN_ID
		WHERE  C.CUST_STAT = 'G104_10'
		AND    C.SITE_CD = #{siteCd}
		AND    (C.SMS_AGREE_YN = 'Y' OR C.EMAIL_AGREE_YN = 'Y')
		AND    C.BIRTH_MM = FN_ENC_AES(DATE_FORMAT(NOW(), '%m')) -- 현재월 암호화
		AND    NOT EXISTS (
		                   SELECT 1
		                   FROM   TB_CUST_CONTACT_HST CCH
		                   WHERE  CCH.RECEIVER_NO = C.CUST_NO
		                   AND    CCH.SEND_DT > DATE_FORMAT(DATE_ADD(LAST_DAY(NOW()), INTERVAL -1 MONTH ), '%Y%m%d')
		                   AND    CCH.SEND_DT <![CDATA[<]]> DATE_FORMAT(DATE_ADD(LAST_DAY(NOW()), INTERVAL 1 DAY), '%Y%m%d')
		                   AND    CCH.CONTACT_TYPE = 'G054_210' /*생일쿠폰 다운로드 안내*/
		                   )
	</select>

	<!--생일쿠폰 다운로드 안내 대상자-->
	<select id="getBirthDayTargetList" parameterType="CustomerSearch" resultType="CustCoupon">
		/*TsbCustomerDao.getBirthDayTargetList*/
		<include refid="selectForPagingHeader"/>
		WITH TAB_COUPON_REFVAL1 AS (
		    SELECT CR.CPN_ID
		         , CR.CPN_TARGET
		         , CASE WHEN CR.CPN_TARGET = 'G260_10' /*상품*/ THEN (SELECT GOODS_NM FROM TB_GOODS WHERE GOODS_CD = CR.REF_VAL AND GOODS_STAT = 'G008_90')
		                WHEN CR.CPN_TARGET = 'G260_11' /*카테고리*/ THEN
		                    CASE WHEN IFNULL((SELECT COUNT(1) FROM TB_CATE_4SRCH WHERE CATE1_NO = CR.REF_VAL),0) > 0
		                              THEN (SELECT CATE1_NM FROM TB_CATE_4SRCH WHERE CATE1_NO = CR.REF_VAL LIMIT 1)
		                         WHEN IFNULL((SELECT COUNT(1) FROM TB_CATE_4SRCH WHERE CATE2_NO = CR.REF_VAL),0) > 0
		                              THEN (SELECT CONCAT(CATE1_NM,' > ',CATE2_NM) FROM TB_CATE_4SRCH WHERE CATE2_NO = CR.REF_VAL LIMIT 1)
		                         WHEN IFNULL((SELECT COUNT(1) FROM TB_CATE_4SRCH WHERE CATE3_NO = CR.REF_VAL),0) > 0 THEN (SELECT CONCAT(CATE1_NM,' > ',CATE2_NM) FROM TB_CATE_4SRCH WHERE CATE3_NO = CR.REF_VAL LIMIT 1)
		                         WHEN IFNULL((SELECT COUNT(1) FROM TB_CATE_4SRCH WHERE CATE4_NO = CR.REF_VAL),0) > 0 THEN (SELECT CONCAT(CATE1_NM,' > ',CATE2_NM) FROM TB_CATE_4SRCH WHERE CATE4_NO = CR.REF_VAL LIMIT 1)
		                    END
		                WHEN CR.CPN_TARGET = 'G260_12' /*브랜드*/ THEN (SELECT BRAND_KNM FROM TB_BRAND WHERE BRAND_CD = CR.REF_VAL AND USE_YN = 'Y')
		                WHEN CR.CPN_TARGET = 'G260_13' /*업체*/ THEN (SELECT SUPPLY_COMP_NM FROM TB_SUPPLY_COMPANY WHERE SUPPLY_COMP_CD = CR.REF_VAL AND USE_YN = 'Y' AND SUPPLY_STAT = 'G010_30')
		           END AS REF_VAL
		         , RANK() OVER(PARTITION BY CR.CPN_ID, CR.CPN_TARGET ORDER BY REF_VAL) AS RK
		    FROM   TB_COUPON_REFVAL CR
		    WHERE  CR.CPN_TARGET != 'G260_14' /*제외상품아닌넘*/
		    AND    CR.CPN_ID IN (
		                         SELECT GRADE_CPN_ID3
		                         FROM   TB_CUST_GRADE_POLICY
		                         WHERE  USE_YN = 'Y'
		                         )
		)
		, TAB_COUPON_REFVAL2 AS (
		    SELECT CPN_ID
		         , CPN_TARGET
		         , GROUP_CONCAT(REF_VAL ORDER BY RK ASC SEPARATOR '/' ) AS REF_VAL
		         , (SELECT COUNT(*)
		            FROM   TAB_COUPON_REFVAL1
		            WHERE  CPN_ID = CR.CPN_ID
		            AND    CPN_TARGET = CR.CPN_TARGET)                  AS CNT
		    FROM   TAB_COUPON_REFVAL1 CR
		    WHERE  1 = 1
		    AND    (
		            (CPN_TARGET != 'G260_12' AND RK = 1) /*브랜드 외는 1개만 노출*/
		            OR
		            (CPN_TARGET = 'G260_12' AND RK <![CDATA[<=]]> 2) /*브랜드만 2개 노출*/
		           )
		    GROUP  BY CPN_ID, CPN_TARGET
		    LIMIT  1
		)
		SELECT C.CUST_NO
		     , C.CUST_NM
		     , C.EMAIL
		     , C.CELL_PHNNO
		     , C.SMS_AGREE_YN
		     , C.EMAIL_AGREE_YN
		     , C.SNS_TYPE
		     , C.CUST_GRADE
		     , DATE_FORMAT(LAST_DAY(NOW() - INTERVAL 1 MONTH)+ INTERVAL 1 DAY, '%Y%m%d%H%i%S')   AS AVAIL_STDT
		     , DATE_FORMAT(CONCAT(LAST_DAY(NOW()), ' 23:59:59'), '%Y%m%d%H%i%S')                 AS AVAIL_EDDT
			 , DATE_FORMAT(LAST_DAY(NOW() - INTERVAL 1 MONTH)+ INTERVAL 1 DAY, '%Y.%m.%d %H:%i') AS AVAIL_STDT_TIME
		     , DATE_FORMAT(CONCAT(LAST_DAY(NOW()), ' 23:59:59'), '%Y.%m.%d %H:%i')               AS AVAIL_EDDT_TIME
		     , CO.CPN_ID
		     , CO.END_ALIM_YN
		     , CO.DC_PVAL                                                                      AS DC_VAL
		     , CASE WHEN CO.DC_WAY = 'G240_10' THEN '원'
		            ELSE '%'
		       END                                                                             AS DC_WAY
		     , CO.MAX_DC_AMT
		     , CONCAT(CASE WHEN CO.BUY_LIMIT_AMT = 0 THEN ''
		                    ELSE CONCAT(FORMAT(CO.BUY_LIMIT_AMT , 0),'원 이상 구매 시 ')
		              END
		             ,CASE WHEN CO.MAX_DC_AMT = 0 THEN ''
		                   ELSE CONCAT('최대 ',FORMAT(CO.MAX_DC_AMT , 0),'원 할인')
		              END
		             )                                                                     AS USE_CONDITION
		     , CASE WHEN CO.CUST_PUB_LIMIT_QTY = 0 THEN ''
		            ELSE CONCAT('1인당 최대',CO.CUST_PUB_LIMIT_QTY,'매')
		       END                                                                         AS ISSUE_CONDITION
		     , (
		        SELECT COUNT(1)
		        FROM   TB_CUST_COUPON CCP
		        WHERE  CCP.CUST_NO = C.CUST_NO
		        AND    CCP.CPN_ID = CO.CPN_ID
		       )                                                                            AS CPN_CNT
		     , CONCAT(CR.REF_VAL, CASE WHEN CR.CPN_TARGET = 'G260_10' AND CR.CNT > 1 THEN ' 외'
		                               WHEN CR.CPN_TARGET = 'G260_11' AND CR.CNT > 1 THEN ' 외'
		                               WHEN CR.CPN_TARGET = 'G260_12' AND CR.CNT > 2 THEN ' 외'
		                               WHEN CR.CPN_TARGET = 'G260_13' AND CR.CNT > 1 THEN ' 외'
		                               ELSE ''
		                          END) AS TGT_CONDITION /*대상조건*/
		     , DATE_FORMAT(C.EMAIL_AGREE_DT, '%Y.%m.%d')                                   AS EMAIL_AGREE_DT
		FROM   TB_CUSTOMER C
		INNER JOIN
		       TB_CUST_GRADE_POLICY CGP
		ON     C.CUST_GRADE = CGP.GRADE_CD
		AND    CGP.USE_YN = 'Y'
		INNER JOIN
		       TB_COUPON CO
		ON     CGP.GRADE_CPN_ID3 = CO.CPN_ID
		AND    CO.CPN_STAT = 'G232_11'
		LEFT OUTER JOIN
		       TAB_COUPON_REFVAL2 CR
		ON     CO.CPN_ID = CR.CPN_ID
		WHERE  C.CUST_STAT = 'G104_10'
		AND    C.SITE_CD = #{siteCd}
		AND    (C.SMS_AGREE_YN = 'Y' OR C.EMAIL_AGREE_YN = 'Y')
		AND    C.BIRTH_MM = FN_ENC_AES(DATE_FORMAT(NOW(), '%m')) -- 현재월 암호화
		AND    NOT EXISTS (
		                   SELECT 1
		                   FROM   TB_CUST_CONTACT_HST CCH
		                   WHERE  CCH.RECEIVER_NO = C.CUST_NO
		                   AND    CCH.SEND_DT > DATE_FORMAT(DATE_ADD(LAST_DAY(NOW()), INTERVAL -1 MONTH ), '%Y%m%d')
		                   AND    CCH.SEND_DT <![CDATA[<]]> DATE_FORMAT(DATE_ADD(LAST_DAY(NOW()), INTERVAL 1 DAY), '%Y%m%d')
		                   AND    CCH.CONTACT_TYPE = 'G054_210' /*생일쿠폰 다운로드 안내*/
		                   )
		ORDER BY C.CUST_NO
		<include refid="selectForPagingFooter"/>
	</select>

	<!--휴면/미접속자 대상 목록-->
	<select id="getComBackNotiTarketListCount" parameterType="CustomerSearch" resultType="int">
		/* TsbCustomerDao.getComBackNotiTarketListCount*/
		SELECT COUNT(*) AS CNT
		FROM   TB_CUSTOMER C
		WHERE  C.CUST_STAT = 'G104_10'
		AND    C.SITE_CD = #{siteCd}
		AND    (C.SMS_AGREE_YN = 'Y' OR C.EMAIL_AGREE_YN = 'Y')
		AND    C.LOGIN_LDT >= DATE_FORMAT(DATE_ADD(CURRENT_DATE(), INTERVAL -#{stDay} DAY), '%Y%m%d%H%i%S')
		AND    C.LOGIN_LDT <![CDATA[<]]> DATE_FORMAT(DATE_ADD(CURRENT_DATE(), INTERVAL -#{edDay} + 1 DAY), '%Y%m%d%H%i%S')
		AND    NOT EXISTS (
		                   SELECT 1
		                   FROM   TB_CUST_CONTACT_HST CCH
		                   WHERE  CCH.RECEIVER_NO = C.CUST_NO
		                   AND    CCH.SEND_DT > DATE_FORMAT(DATE_ADD(LAST_DAY(NOW()), INTERVAL -1 MONTH ), '%Y%m%d')
		                   AND    CCH.SEND_DT <![CDATA[<]]> DATE_FORMAT(DATE_ADD(LAST_DAY(NOW()), INTERVAL 1 DAY), '%Y%m%d')
		                   AND    CCH.CONTACT_TYPE = 'G054_212' /*이번달에 휴면 쿠폰 받은 사람 제외*/
		                   )
	</select>

	<!--휴면/미접속자 대상 목록-->
	<select id="getComBackNotiTarketList" parameterType="CustomerSearch" resultType="Customer">
		/* TsbCustomerDao.getComBackNotiTarketList*/
		<include refid="selectForPagingHeader"/>
		SELECT C.CUST_NO
		     , C.CUST_ID
		     , C.CUST_NM
		     , C.EMAIL
		     , C.CELL_PHNNO
		     , C.SMS_AGREE_YN
		     , C.EMAIL_AGREE_YN
		     , DATE_FORMAT(C.EMAIL_AGREE_DT, '%Y.%m.%d') AS EMAIL_AGREE_DT
		     , DATEDIFF(NOW(), C.LOGIN_LDT) AS DIFF_LOGIN_LDT
		     , C.SNS_TYPE
		FROM   TB_CUSTOMER C
		WHERE  C.CUST_STAT = 'G104_10'
		AND    C.SITE_CD = #{siteCd}
		AND    (C.SMS_AGREE_YN = 'Y' OR C.EMAIL_AGREE_YN = 'Y')
		AND    C.LOGIN_LDT >= DATE_FORMAT(DATE_ADD(CURRENT_DATE(), INTERVAL -#{stDay} DAY), '%Y%m%d%H%i%S')
		AND    C.LOGIN_LDT <![CDATA[<]]> DATE_FORMAT(DATE_ADD(CURRENT_DATE(), INTERVAL -#{edDay} + 1 DAY), '%Y%m%d%H%i%S')
		AND    NOT EXISTS (
		                   SELECT 1
		                   FROM   TB_CUST_CONTACT_HST CCH
		                   WHERE  CCH.RECEIVER_NO = C.CUST_NO
		                   AND    CCH.SEND_DT > DATE_FORMAT(DATE_ADD(LAST_DAY(NOW()), INTERVAL -1 MONTH ), '%Y%m%d')
		                   AND    CCH.SEND_DT <![CDATA[<]]> DATE_FORMAT(DATE_ADD(LAST_DAY(NOW()), INTERVAL 1 DAY), '%Y%m%d')
		                   AND    CCH.CONTACT_TYPE = 'G054_212' /*이번달에 휴면 쿠폰 받은 사람 제외*/
		                   )
		ORDER BY C.CUST_NO
		<include refid="selectForPagingFooter"/>
	</select>

</mapper>