<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE sqlMap PUBLIC "-//iBATIS.com//DTD SQL Map 2.0//EN"
    "http://www.ibatis.com/dtd/sql-map-2.dtd">

<sqlMap namespace="BapProcWork">
    <statement id="selectListCount" parameterClass="java.util.HashMap" resultClass="java.lang.Integer">
    	SELECT COUNT(*)
		  FROM (
				   SELECT S4.BjobBzwkDstcd
					 FROM $schemaId$.TSEAIBS04 S4
					 	, $schemaId$.TSEAIBJ02 J2
				  	 	, $schemaId$.TSEAIBJ06 J6
				  	WHERE S4.BjobBzwkDstcd  = J2.BjobBzwkDstcd
				  	  AND S4.BjobBzwkDstcd  = J6.BjobBzwkDstcd    
				  	  AND S4.OsidInstiDstcd = J6.OsidInstiDstcd                                
					  <isNotEmpty prepend="AND" property="searchStartTime1">
						S4.SndrcvStartHMS BETWEEN #searchStartTime1# AND #searchEndTime1#
					  </isNotEmpty>
					  <isNotEmpty prepend="AND" property="searchStartTime2">
						S4.SndrcvEndHMS BETWEEN #searchStartTime2# AND #searchEndTime2#
					  </isNotEmpty>
					  <isNotEmpty prepend="AND" property="searchBjobBzwkDstcd">
						S4.BjobBzwkDstcd = #searchBjobBzwkDstcd#
					  </isNotEmpty>
					  <isNotEmpty prepend="AND" property="searchOsidInstiDstcd">
						S4.OsidInstiDstcd = #searchOsidInstiDstcd#
					  </isNotEmpty>
					  <isNotEmpty prepend="AND" property="searchSndrcvFileName">
						UPPER(S4.SndrcvFileName) like CONCAT( '%' , UPPER(#searchSndrcvFileName#) , '%')
					  </isNotEmpty>
			   ) ORGTABLE
    </statement>
    
    <statement id="selectList" parameterClass="java.util.HashMap" resultClass="java.util.HashMap">
		SELECT *
		  FROM (
				   SELECT @NO := @NO + 1 AS ROWNO
				   		, S4.BJOBDMNDMSGID								/* 작업요청메시지ID (UUID)  */
				        , S4.BJOBDMNDSUBMSGID							/* 작업요청부메시지ID (SUBUUID) */
				        , S4.TELGMRETRALCNT								/* 전문재시도수     */
				        , S4.SYSLNKGDSTCD								/* 시스템연결구분코드     */
				        , S4.BJOBDMNDMSGCRETNHMS						/* 작업요청메시지 생성시각  */
				        , S4.BJOBMSGSCHEID								/* 작업메시지 일정ID   */
				        , S4.BJOBBZWKDSTCD								/* 업무구분코드     */
				        , J2.BJOBBZWKNAME		AS BJOBBZWKDSTCDNAME	/* 업무구분명     */
				        , S4.OSIDINSTIDSTCD								/* 대외기관구분코드    */
				        , J6.OSIDINSTINAME		AS OSIDINSTIDSTCDNAME	/* 대외기관구분명     */
				        , S4.BJOBPTRNDSTCD								/* 작업유형구분코드    */
				        , S4.SNDRCVSTARTHMS								/* 송수신 시작시각    */
				        , S4.SNDRCVENDHMS								/* 송수신 종료시각    */
				        , S4.SNDRCVFILEDIRNAME							/* 송수신 파일 디렉토리명  */
				        , S4.SNDRCVFILENAME								/* 송수신 파일명    */
				        , S4.BKUPSNDRCVFILENAME							/* 백업 송수신 파일명   */
				        , S4.MSGPRCSSPRITY								/* 메시지처리 우선순위   */
				        , S4.THISMSGAMNDRID								/* 메시지수정자ID    */
				        , S4.THISMSGAMNDHMS								/* 메시지 수정시각    */
				        , S4.MSGQUEETRACTDMNDHMS						/* 메시지큐추출요청시각    */
				        , S4.MSGPRCSSSTUSCD								/* 메시지처리상태코드    */
					 FROM $schemaId$.TSEAIBS04 S4
					 	, $schemaId$.TSEAIBJ02 J2
				  	 	, $schemaId$.TSEAIBJ06 J6,  (SELECT @NO := 0) R
				  	WHERE S4.BjobBzwkDstcd  = J2.BjobBzwkDstcd
				  	  AND S4.BjobBzwkDstcd  = J6.BjobBzwkDstcd
				  	  AND S4.OsidInstiDstcd = J6.OsidInstiDstcd
					  <isNotEmpty prepend="AND" property="searchStartTime1">
						S4.SndrcvStartHMS BETWEEN #searchStartTime1# AND #searchEndTime1#
					  </isNotEmpty>
					  <isNotEmpty prepend="AND" property="searchStartTime2">
						S4.SndrcvEndHMS BETWEEN #searchStartTime2# AND #searchEndTime2#
					  </isNotEmpty>
					  <isNotEmpty prepend="AND" property="searchBjobBzwkDstcd">
						S4.BjobBzwkDstcd = #searchBjobBzwkDstcd#
					  </isNotEmpty>
					  <isNotEmpty prepend="AND" property="searchOsidInstiDstcd">
						S4.OsidInstiDstcd = #searchOsidInstiDstcd#
					  </isNotEmpty>
					  <isNotEmpty prepend="AND" property="searchSndrcvFileName">
						UPPER(S4.SndrcvFileName) like CONCAT( '%' , UPPER(#searchSndrcvFileName#) , '%')
					  </isNotEmpty>
					  ORDER BY S4.MsgPrcssPrity ASC, S4.SndrcvStartHMS DESC, S4.BjobBzwkDstcd  ASC
			   ) ORGTABLE
		WHERE ROWNO BETWEEN #startNum# AND #endNum#
    </statement>
    
	<statement id="selectDetail" parameterClass="java.util.HashMap" resultClass="java.util.HashMap">
		SELECT @NO := @NO + 1 AS ROWNO
			 , S4.BJOBDMNDMSGID
	         , S4.BJOBDMNDSUBMSGID
	         , S4.TELGMRETRALCNT
	         , S4.SYSLNKGDSTCD
	         , S4.BJOBDMNDMSGCRETNHMS
	         , S4.BJOBMSGSCHEID
	         , S4.BJOBBZWKDSTCD
	         , J2.BJOBBZWKNAME		AS BJOBBZWKDSTCDNAME
	         , S4.BJOBBZWKDSTCD
	         , J6.OSIDINSTINAME		AS OSIDINSTIDSTCDNAME
	         , S4.OSIDINSTIDSTCD
	         , CASE WHEN S4.BJOBPTRNDSTCD='RS' THEN '송신' 
					WHEN S4.BJOBPTRNDSTCD='RR' THEN '수신' 
					ELSE S4.BJOBPTRNDSTCD 
				END AS BJOBPTRNDSTCD
	         , S4.SNDRCVSTARTHMS
	         , S4.SNDRCVENDHMS
	         , S4.SNDRCVFILEDIRNAME
	         , S4.SNDRCVFILENAME
	         , S4.BKUPSNDRCVFILENAME
	         , S4.MSGPRCSSPRITY
	         , S4.THISMSGAMNDRID
	         , S4.THISMSGAMNDHMS
	         , S4.MSGQUEETRACTDMNDHMS						/* 메시지큐추출요청시각    */
	         , S4.MSGPRCSSSTUSCD								/* 메시지처리상태코드    */
		  FROM $schemaId$.TSEAIBS04 S4
		  	 , $schemaId$.TSEAIBJ02 J2
		  	 , $schemaId$.TSEAIBJ06 J6,  (SELECT @NO := 0) R
		 WHERE S4.BjobBzwkDstcd		= J2.BjobBzwkDstcd
		   AND S4.BjobBzwkDstcd		= J6.BjobBzwkDstcd
		   AND S4.OsidInstiDstcd	= J6.OsidInstiDstcd
		   AND S4.BjobMsgScheID		= #bjobMsgScheID#
		   AND S4.BjobDmndSubMsgID	= #bjobDmndSubMsgID#
		 ORDER BY S4.MsgPrcssPrity ASC, S4.SndrcvStartHMS DESC, S4.BjobBzwkDstcd  ASC
	</statement>
  
	<statement id="delete" parameterClass="java.util.HashMap" resultClass="java.lang.Integer">
    	DELETE FROM $schemaId$.TSEAIBS04 
		 WHERE BjobDmndMsgID	= #bjobDmndMsgID#
		   AND BjobDmndSubMsgID	= #bjobDmndSubMsgID#
	</statement>
    
</sqlMap>