<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
<mapper namespace="com.style24.core.biz.dao.SsgDirectMessageDao">

	<!-- SMS발송 생성 -->
	<insert id="createSms" parameterType="SsgDirectMessage">
		/* SsgDirectMessage.createSms */
		INSERT INTO style24_msg.SSG_SEND_TRAN_SMS (
		       FSEQ
		     , FUSERID
		     , FSECTIONCODE
		     , FCAMPCODE
		     , FMSGTYPE
		     , FMESSAGE
		     , FSENDDATE
		     , FDESTINE
		     , FCALLBACK
		)
		VALUES (
		       NULL
		     , #{fuserid}
		     , #{fsectioncode}
		     , #{fcampcode}
		     , '0'
		     , #{fmessage}
		     ,
		<choose>
			<when test='bizTime != null and bizTime == "Y"'>
		       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
			</when>
			<otherwise>
		       NOW()
			</otherwise>
		</choose>
		     , #{fdestine}
		     , #{fcallback}
		)
	</insert>
	
	<!-- LMS발송 생성 -->
	<insert id="createLms" parameterType="SsgDirectMessage">
		/* SsgDirectMessage.createLms */
		INSERT INTO style24_msg.SSG_SEND_TRAN_MMS (
		       FSEQ
		     , FUSERID
		     , FSECTIONCODE
		     , FCAMPCODE
		     , FMSGTYPE
		     , FSUBJECT
		     , FMESSAGE
		     , FSENDDATE
		     , FDESTINE
		     , FCALLBACK
		)
		VALUES (
		       NULL
		     , #{fuserid}
		     , #{fsectioncode}
		     , #{fcampcode}
		     , '2'
		     , #{fsubject}
		     , #{fmessage}
		     ,
		<choose>
			<when test='bizTime != null and bizTime == "Y"'>
		       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
			</when>
			<otherwise>
		       NOW()
			</otherwise>
		</choose>
		     , #{fdestine}
		     , #{fcallback}
		)
	</insert>
	
	<!-- 카카오알림톡발송 생성 -->
	<insert id="createKakao" parameterType="SsgDirectMessage">
		/* SsgDirectMessage.createKakao */
		INSERT INTO style24_msg.SSG_SEND_TRAN_KKO (
		       FSEQ            /*메시지SEQ*/
		     , 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       /*발신자전화번호(회신번호)*/
		)
		VALUES (
		       NULL
		     , #{fuserid}
		     , #{fsectioncode}
		     , #{fcampcode}
		     , #{fyellowid}
		     , #{fkkosubject}
		     , #{ftemplatekey}
		     , #{fkkobutton}
		     , '4'
		     , #{fmessage}
		     ,
		<choose>
			<when test='bizTime != null and bizTime == "Y"'>
		       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
			</when>
			<otherwise>
		       NOW()
			</otherwise>
		</choose>
		     , #{fkkoresendtype}
		     , #{fkkoresendmsg}
		     , #{fdestine}
		     , #{fcallback}
		)
	</insert>

		<!-- SMS발송 생성 -->
	<insert id="createSmsDev" parameterType="SsgDirectMessage">
		/* SsgDirectMessage.createSmsDev */
		INSERT INTO SSG_SEND_TRAN_SMS (
		       FSEQ
		     , FUSERID
		     , FSECTIONCODE
		     , FCAMPCODE
		     , FMSGTYPE
		     , FMESSAGE
		     , FSENDDATE
		     , FDESTINE
		     , FCALLBACK
		)
		VALUES (
		       NULL
		     , #{fuserid}
		     , #{fsectioncode}
		     , #{fcampcode}
		     , '0'
		     , #{fmessage}
		     ,
		<choose>
			<when test='bizTime != null and bizTime == "Y"'>
		       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
			</when>
			<otherwise>
		       NOW()
			</otherwise>
		</choose>
		     , #{fdestine}
		     , #{fcallback}
		)
	</insert>

	<!-- LMS발송 생성 -->
	<insert id="createLmsDev" parameterType="SsgDirectMessage">
		/* SsgDirectMessage.createLms */
		INSERT INTO SSG_SEND_TRAN_MMS (
		       FSEQ
		     , FUSERID
		     , FSECTIONCODE
		     , FCAMPCODE
		     , FMSGTYPE
		     , FSUBJECT
		     , FMESSAGE
		     , FSENDDATE
		     , FDESTINE
		     , FCALLBACK
		)
		VALUES (
		       NULL
		     , #{fuserid}
		     , #{fsectioncode}
		     , #{fcampcode}
		     , '2'
		     , #{fsubject}
		     , #{fmessage}
		     ,
		<choose>
			<when test='bizTime != null and bizTime == "Y"'>
		       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
			</when>
			<otherwise>
		       NOW()
			</otherwise>
		</choose>
		     , #{fdestine}
		     , #{fcallback}
		)
	</insert>

	<!-- 카카오알림톡발송 생성 -->
	<insert id="createKakaoDev" parameterType="SsgDirectMessage">
		/* SsgDirectMessage.createKakao */
		INSERT INTO SSG_SEND_TRAN_KKO (
		       FSEQ            /*메시지SEQ*/
		     , 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       /*발신자전화번호(회신번호)*/
		)
		VALUES (
		       NULL
		     , #{fuserid}
		     , #{fsectioncode}
		     , #{fcampcode}
		     , #{fyellowid}
		     , #{fkkosubject}
		     , #{ftemplatekey}
		     , #{fkkobutton}
		     , '4'
		     , #{fmessage}
		     ,
		<choose>
			<when test='bizTime != null and bizTime == "Y"'>
		       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
			</when>
			<otherwise>
		       NOW()
			</otherwise>
		</choose>
		     , #{fkkoresendtype}
		     , #{fkkoresendmsg}
		     , #{fdestine}
		     , #{fcallback}
		)
	</insert>

</mapper>
