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

	<sql id="bu03where">
		<dynamic prepend="WHERE">
			<isEqual prepend="AND" property="searchFrameWorkGb" compareValue="3">
				FileTrsmtPtrnDstcd = 'NDM'
			</isEqual>
			<isEqual prepend="AND" property="searchFrameWorkGb" compareValue="4">
				FileTrsmtPtrnDstcd = 'FTP'
			</isEqual>
			<isEqual prepend="AND" property="searchProcessType" compareValue="S">
				SENDRECVYN = 'S'
			</isEqual>
			<isEqual prepend="AND" property="searchProcessType" compareValue="R">
				SENDRECVYN = 'R'
			</isEqual>
		</dynamic>
	</sql>
	
	<sql id="bu04where">
		<dynamic prepend="WHERE">
			<isEqual prepend="AND" property="searchFrameWorkGb" compareValue="5">
				EAILumpPgmDstcd = 'AX' AND EAILumpPgmStusDstcd IN ( 'DS' , 'DR' )
			</isEqual>
			<isEqual prepend="AND" property="searchFrameWorkGb" compareValue="6">
				EAILumpPgmDstcd = 'AX' AND EAILumpPgmStusDstcd IN ( 'HS' , 'HR', 'SS' , 'SR' )
			</isEqual>
			<isEqual prepend="AND" property="searchFrameWorkGb" compareValue="7">
				EAILumpPgmDstcd = 'ND' AND EAILumpPgmStusDstcd IN ( 'DS' , 'DR' )
			</isEqual>
			<isEqual prepend="AND" property="searchFrameWorkGb" compareValue="8">
				EAILumpPgmDstcd = 'ND' AND EAILumpPgmStusDstcd IN ( 'HS' , 'HR', 'SS' , 'SR' )
			</isEqual>
			<isNotEqual prepend="AND" property="searchProcessType" compareValue="A">
				SUBSTR(EAILumpPgmStusDstcd, 2,1) = #searchProcessType#
			</isNotEqual>
		</dynamic>
	</sql>
	<sql id="traceFrom">
			(
		<isLessEqual property="searchFrameWorkGb" compareValue="2">
			SELECT 'F/W' AS FrameWorkGb,
			        BjobMsgDstcd AS BjobMsgDstcd,
					SndrcvFileName AS SndrcvFileName,
					SndrcvFileSize AS SndrcvFileSize,
					ThisStgePrcssRsultCd AS ThisStgePrcssRsultCd,
                    CASE WHEN SUBSTR(FileTrsmtStartHMS,15,3) = '   ' THEN SUBSTR(FileTrsmtStartHMS,1,14) || '000' ELSE FileTrsmtStartHMS END AS FileTrsmtStartHMS,
                    CASE WHEN SUBSTR(FileTrsmtEndHMS,15,3) = '   ' THEN SUBSTR(FileTrsmtEndHMS,1,14) || '000' ELSE FileTrsmtEndHMS END AS FileTrsmtEndHMS,
					BjobDmndMsgID AS BjobDmndMsgID,
					BjobDmndSubMsgID AS BjobDmndSubMsgID,
					BjobBzwkDstcd,
					OsidInstiDstcd,
					SUBSTR(BjobPtrnDstcd, 2, 1) AS SndRcv
			FROM $schemaId$.TSEAIBJ08
			<isNotEqual prepend="WHERE" property="searchProcessType" compareValue="A">
				SUBSTR(BjobPtrnDstcd, 2, 1) = #searchProcessType#
			</isNotEqual>
		</isLessEqual>
		<isEqual property="searchFrameWorkGb" compareValue="2">
			UNION 
		</isEqual>
		<isGreaterEqual property="searchFrameWorkGb" compareValue="2">
			<isLessEqual property="searchFrameWorkGb" compareValue="4">
				SELECT  FILETRSMTPTRNDSTCD||'(F)' AS FrameWorkGb,
				        BjobMsgDstcd AS BjobMsgDstcd,
						TrsmtFileName AS SndrcvFileName,
						FileTrsmtSize AS SndrcvFileSize,
						NDMRspnsCd AS ThisStgePrcssRsultCd,
                        CASE WHEN SUBSTR(FileTrsmtStartHMS,15,3) = '   ' THEN SUBSTR(FileTrsmtStartHMS,1,14) || '000' ELSE FileTrsmtStartHMS END AS FileTrsmtStartHMS,
                        CASE WHEN SUBSTR(FileTrsmtEndHMS,15,3) = '   ' THEN SUBSTR(FileTrsmtEndHMS,1,14) || '000' ELSE FileTrsmtEndHMS END AS FileTrsmtEndHMS,
						' ' AS BjobDmndMsgID,
						' ' AS BjobDmndSubMsgID,
						BjobBzwkDstcd,
						OsidInstiDstcd,
						SendrecvYn AS SndRcv
				FROM $schemaId$.TSEAIBU03
				<include refid="bu03where"/>
			</isLessEqual>
			<isEqual property="searchFrameWorkGb" compareValue="2">
				UNION 
			</isEqual>
			<isNotEqual property="searchFrameWorkGb" compareValue="3">
				<isLessEqual property="searchFrameWorkGb" compareValue="6">
					SELECT CASE WHEN EAILumpPgmDstcd = 'AX' AND EAILumpPgmStusDstcd IN ( 'DS' , 'DR' )              THEN 'AD'
					            WHEN EAILumpPgmDstcd = 'AX' AND EAILumpPgmStusDstcd IN ( 'HS' , 'HR', 'SS' , 'SR' ) THEN 'AN'
					       END AS FrameWorkGb,
					       BjobMsgDstcd AS BjobMsgDstcd,
					       EAILumpLOCALFileName AS SndrcvFileName,
					       EAILUMPFILESIZEVAL AS SndrcvFileSize,
					       EAILumpPgmNomalDstcd AS ThisStgePrcssRsultCd,
                           CASE WHEN SUBSTR(EAILumpFileTrsmtStartYMS,15,3) = '   ' THEN SUBSTR(EAILumpFileTrsmtStartYMS,1,14) || '000' ELSE EAILumpFileTrsmtStartYMS END AS FileTrsmtStartHMS,
                           CASE WHEN SUBSTR(EAILumpFileTrsmtEndYMS,15,3) = '   ' THEN SUBSTR(EAILumpFileTrsmtEndYMS,1,14) || '000' ELSE EAILumpFileTrsmtEndYMS END AS FileTrsmtEndHMS,
					       ' ' AS BjobDmndMsgID,
					       ' ' AS BjobDmndSubMsgID,
					       BjobBzwkDstcd,
					       OsidInstiDstcd,
					       SUBSTR(EAILumpPgmStusDstcd, 2,1) AS SndRcv    
					  FROM $schemaId$.TSEAIBU04
					  <include refid="bu04where"/>
				</isLessEqual>
			</isNotEqual>
		</isGreaterEqual>
		<isEqual property="searchFrameWorkGb" compareValue="7">
				SELECT 'NDM' AS FrameWorkGb,
				       '' AS BjobMsgDstcd,
				       SRC_FILE AS SndrcvFileName,
				       BYTES_SENT AS SndrcvFileSize,
				       COND_CODE AS ThisStgePrcssRsultCd,
				       TO_CHAR(TO_DATE(START_TIME, 'YYYY/MM/DD HH24:MI:SS.FF3'), 'YYYYMMDDHH24MISSFF3') AS FileTrsmtStartHMS,
				       TO_CHAR(TO_DATE(STOP_TIME, 'YYYY/MM/DD HH24:MI:SS.FF3'), 'YYYYMMDDHH24MISSFF3') AS FileTrsmtEndHMS,
				       ' ' AS BjobDmndMsgID,
				       ' ' AS BjobDmndSubMsgID,
				       ' ' AS BjobBzwkDstcd,
				       ' ' AS OsidInstiDstcd,
				       CASE WHEN DIRECTION = 'outBound' THEN 'S' ELSE 'R' END AS SndRcv     
				  FROM $schemaId$.TSEAIEG$tableNum$
		</isEqual>			
			) A LEFT OUTER JOIN $schemaId$.TSEAIBJ02 B ON A.BjobBzwkDstcd = B.BjobBzwkDstcd   
				LEFT OUTER JOIN $schemaId$.TSEAIBJ06 C ON A.BjobBzwkDstcd = C.BjobBzwkDstcd AND A.OsidInstiDstcd = C.OsidInstiDstcd
				LEFT OUTER JOIN $schemaId$.TSEAIBJ01 D ON A.BjobMsgDstcd = D.BjobMsgDstcd
	</sql>

	<sql id="traceWhere">
		<dynamic prepend="WHERE">
			<isNotEmpty prepend="AND" property="searchBjobTranDstcdName">
				A.SndrcvFileName    LIKE '%' || #searchBjobTranDstcdName# || '%'
			</isNotEmpty>
			<isNotEmpty prepend="AND" property="searchOsidInstiDstcd">
				C.OsidInstiName     LIKE '%' || #searchOsidInstiDstcd# || '%'
			</isNotEmpty>
			<isNotEmpty prepend="AND" property="searchBjobBzwkDstcd">
				A.BjobBzwkDstcd      LIKE '%' || #searchBjobBzwkDstcd# || '%'
			</isNotEmpty>
			<isNotEmpty prepend="AND" property="searchStartTime">
			    A.FileTrsmtStartHMS like '2%' AND A.FileTrsmtStartHMS &gt; #searchStartTime# || '000000000'
			</isNotEmpty>
			<isNotEmpty prepend="AND" property="searchEndTime">
				A.FileTrsmtEndHMS like '2%' AND A.FileTrsmtEndHMS &lt; #searchEndTime# || '235959999'
			</isNotEmpty>
    		<isEqual prepend="AND" property="searchThisStgePrcssRsultCd" compareValue="T">
				A.ThisStgePrcssRsultCd IN ('T', '0', 'TR')
			</isEqual>
			<isEqual prepend="AND" property="searchThisStgePrcssRsultCd" compareValue="P">
				A.ThisStgePrcssRsultCd = 'P'
			</isEqual>
			<isEqual prepend="AND" property="searchThisStgePrcssRsultCd" compareValue="E">
				A.ThisStgePrcssRsultCd NOT IN ('T', '0', 'P', 'TR')
			</isEqual>
			<isEqual prepend="AND" property="searchProcessType" compareValue="A">
				A.SndRcv IN ('S','R')
			</isEqual>
			<isEqual prepend="AND" property="searchProcessType" compareValue="S">
				A.SndRcv = 'S'
			</isEqual>
			<isEqual prepend="AND" property="searchProcessType" compareValue="R">
				A.SndRcv = 'R'
			</isEqual>
		</dynamic>
	</sql>
	
	<statement id="selectList" resultClass="java.util.HashMap">
		SELECT E.*
		FROM (
			SELECT A.FrameWorkGb AS FRAMEWORKGB,
			       A.SndrcvFileName AS SNDRCVFILENAME,
			       A.SndrcvFileSize AS SNDRCVFILESIZE,
			       B.BjobBzwkName AS BJOBBZWKNAME,
			       C.OsidInstiName AS OSIDINSTINAME,
			       CASE
			         WHEN A.ThisStgePrcssRsultCd = 'T' THEN 'C'
			         WHEN A.ThisStgePrcssRsultCd = '0' THEN 'C'
			         WHEN A.ThisStgePrcssRsultCd = 'TR' THEN 'C'
			         WHEN A.ThisStgePrcssRsultCd = 'P' THEN 'P'
			         WHEN A.ThisStgePrcssRsultCd = 'S' THEN 'P'
			         ELSE 'E'
			       END AS THISSTGEPRCSSRSULTCD,
			       A.FileTrsmtStartHMS AS FILETRSMTSTARTHMS,
			       A.FileTrsmtEndHMS AS FILETRSMTENDHMS,
			       TO_DATE(A.FileTrsmtEndHMS,'YYYY/MM/DD HH24:MI:SS.FF3')-TO_DATE(A.FileTrsmtStartHMS,'YYYY/MM/DD HH24:MI:SS.FF3') AS FILETRSMTHMS,
			       A.BjobDmndMsgID AS BJOBDMNDMSGID,
			       A.BjobDmndSubMsgID AS BJOBDMNDSUBMSGID,
			       A.SndRcv AS SNDRCV
			FROM
			<include refid="traceFrom"/>
			<include refid="traceWhere"/>
		) E
		<dynamic prepend="ORDER BY">
			<isEqual property="searchDistCd" compareValue="fileSize">
				SNDRCVFILESIZE DESC, ABS(FILETRSMTHMS) DESC
			</isEqual>
			<isEqual property="searchDistCd" compareValue="procTime">
				ABS(FILETRSMTHMS) DESC, SNDRCVFILESIZE DESC
			</isEqual>
		</dynamic>
	</statement> 
</sqlMap>
