<?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="kr.co.uplus.ez.api.comm.CommMapper">

	<select id="getMenuByRole" parameterType="string" resultType="kr.co.uplus.ez.api.comm.dto.Menu">
		/* comm-mapper.xml(getMenuByRole) */
		SELECT eam2.MENU_NO as menuNo 
		   , null  as prntsMenuNo
		   , eam2.MENU_NM  as menuNm
		   , eam2.MENU_ODRG as menuOdrg
		   , eam2.USE_YN  as useYn
		   , eam2.AUTCHK_GRPNO as autchkGrpno
		   , eam2.MENU_LVL as menuLvl
		   , eam2.MENU_URL as menuUrl
		FROM hubez_admin.EZ_ADM_AUTMENU eaa 
		   INNER JOIN hubez_admin.EZ_ADM_MENU eam 
		      on eam.MENU_NO = eaa.MENU_NO 
		   INNER JOIN hubez_admin.EZ_ADM_MENU eam2 
		      ON eam2.MENU_NO = eam.PRNTS_MENU_NO 
		WHERE AUT_CD = #{role}
			AND eam.USE_YN = 'Y'
		UNION 
		SELECT eam.MENU_NO as menuNo 
		   , eam.PRNTS_MENU_NO  as prntsMenuNo
		   , eam.MENU_NM  as menuNm
		   , eam.MENU_ODRG as menuOdrg
		   , eam.USE_YN  as useYn
		   , eam.AUTCHK_GRPNO as autchkGrpno
		   , eam.MENU_LVL as menuLvl
		   , eam.MENU_URL as menuUrl
		FROM hubez_admin.EZ_ADM_AUTMENU eaa 
		   INNER JOIN hubez_admin.EZ_ADM_MENU eam 
		      ON eam.MENU_NO = eaa.MENU_NO 
		   INNER JOIN hubez_admin.EZ_ADM_MENU eam2 
		      ON eam2.MENU_NO = eam.PRNTS_MENU_NO 
		WHERE AUT_CD = #{role}
			AND eam.USE_YN = 'Y'
			AND	eam2.USE_YN = 'Y'
		ORDER BY menuLvl, menuOdrg;
	</select>

	<select id="getCommCode" parameterType="kr.co.uplus.ez.api.comm.dto.CodeReqDto"	resultType="kr.co.uplus.ez.api.comm.dto.Code">
		/* comm-mapper.xml(getCommCode) */
		SELECT
			T2.GRP_CD as grp_cd
			,T2.DTL_CD as code
			,T2.DTL_CD_NM as codeNm
			,T2.SORT_ODRG as sortOrder
			,T2.USE_YN as useYn
		FROM hubez_common.EZ_CD_GRP T1
			LEFT JOIN hubez_common.EZ_CD_DTL T2
			ON T1.GRP_CD = T2.GRP_CD
		WHERE T1.GRP_CD = #{grpCd}
		ORDER BY T2.SORT_ODRG
	</select>

	<select id="getAuthCode" resultType="kr.co.uplus.ez.api.comm.dto.Auth">
		/* comm-mapper.xml(getAuthCode) */
		SELECT
			AUT_CD,
			AUT_NM,
			USE_YN
		FROM
			hubez_admin.EZ_ADM_AUT
		ORDER BY
			AUT_CD
	</select>
	
	<insert id="insertWebMsgCli" parameterType="String">
    	/* extCarryOverAmtNoti.insertWebMsgCli - 메시지 원장 등록 */
    	INSERT INTO		hubez_send.EZ_MSG_REAL
    		(
    			CLIENT_KEY,
				REQ_PRODUCT,
				TRAFFIC_TYPE,
				MSG_STATUS,
				REQ_DATE,
				MSG_BIZ_KEY,
				TEMPLATE_CODE,
				SEND_GROUP_KEY,
				CALLBACK_NUMBER,
				DEPT_CODE,
				MSG,
				PHONE,
				MERGE_DATA,
				TITLE,
				FILE_LIST,
				FB_PRODUCT,
				FB_TITLE,
				FB_MSG,
				FB_FILE_ID,
				RCS_MSGBASE_ID,
				RCS_HEADER,
				RCS_FOOTER,
				RCS_COPY_ALLOWED,
				RCS_EXPIRY_OPTION,
				RCS_AGENCY_ID,
				RCS_BUTTON,
				KAKAO_SENDER_KEY,
				KAKAO_TEMPLATE_KEY,
				KAKAO_BUTTON,
				KAKAO_IMAGE_WIDE_YN,
				KAKAO_IMAGE_URL,
				KAKAO_IMAGE_LINK,
				PUSH_APP_ID,
				PUSH_PROVIDER,
				PUSH_APP_USER_ID,
				WEB_REQ_ID,
				ORDER_ID
	    	) 
	    VALUES 
	    	(
    		    #{clientKey},
				#{reqProduct},
				#{trafficType},
				#{msgStatus},
				NOW(),
				#{msgBizKey},
				#{templateCode},
				#{sendGroupKey},
				#{callbackNumber},
				#{deptCode},
				#{msg},
				#{phone},
				#{mergeData},
				#{title},
				#{fileList},
				#{fbProduct},
				#{fbTitle},
				#{fbMsg},
				#{fbFileId},
				#{rcsMsgbaseId},
				#{rcsHeader},
				#{rcsFooter},
				#{rcsCopyAllowed},
				#{rcsExpiryOption},
				#{rcsAgencyId},
				#{rcsButton},
				#{kakaoSenderKey},
				#{kakaoTemplateKey},
				#{kakaoButton},
				#{kakaoImageWideYn},
				#{kakaoImageUrl},
				#{kakaoImageLink},
				#{pushAppId},
				#{pushProvider},
				#{pushAppUserId},
				#{webReqId},
				#{orderId}
    		)
    </insert>
	
	<insert id="insertNotiHst" parameterType="String">
    	/* extCarryOverAmtNoti.insertNotiHst - 알림 이력 등록 */
    	INSERT INTO hubez_common.EZ_NOTI_HIST
    		(
    			SND_YMD,
				USER_SEQ,
				NOTI_SEQ,
				NOTI_DIV,
				NOTI_MSG,
				WEB_REQ_ID,
				REG_DT
	    	) 
	    VALUES 
	    	(
    		    DATE_FORMAT(NOW(), '%Y%m%d'),
				#{userSeq},
				#{notiSeq},
				#{notiDiv},
				#{notiMsg},
				#{webReqId},
				NOW()
    		)
    </insert>
</mapper>