<?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="DashboardTargetForBatch">
  
  <!-- FEP BATCH -->
	<statement id="getBatchProcCountByDate" parameterClass="java.util.HashMap" resultClass="java.util.HashMap">
		SELECT COALESCE( SUM( CASE WHEN A.BJOBSENDRECVGB = 'S' AND A.RESULTCD = 'T' THEN 1 ELSE 0 END ),0) AS SEND_SEND,
		       COALESCE( SUM( CASE WHEN A.BJOBSENDRECVGB = 'R' AND A.RESULTCD = 'T' THEN 1 ELSE 0 END ),0) AS SEND_RECV,
		       COALESCE( SUM( CASE WHEN A.BJOBSENDRECVGB = 'S' AND A.RESULTCD = 'E' THEN 1 ELSE 0 END ),0) AS FAIL_SEND,
		       COALESCE( SUM( CASE WHEN A.BJOBSENDRECVGB = 'R' AND A.RESULTCD = 'E' THEN 1 ELSE 0 END ),0) AS FAIL_RECV,
		       COALESCE( SUM( CASE WHEN A.BJOBSENDRECVGB = 'S' AND A.RESULTCD = 'Q' THEN 1 ELSE 0 END ),0) AS QUED_SEND,
		       COALESCE( SUM( CASE WHEN A.BJOBSENDRECVGB = 'R' AND A.RESULTCD = 'Q' THEN 1 ELSE 0 END ),0) AS QUED_RECV
		FROM (
		       SELECT SUBSTR(BJOBPTRNDSTCD,2,1) AS BJOBSENDRECVGB,
		              THISSTGEPRCSSRSULTCD AS RESULTCD
		       FROM $schemaId$.TSEAIBJ08
					 WHERE      FILETRSMTSTARTHMS BETWEEN #date# || '00000000' AND #date# || '99999999'
		       UNION ALL
		       SELECT 'S' AS BJOBSENDRECVGB,
		              'Q' AS RESULTCD
		       FROM $schemaId$.TSEAIBS03
		       WHERE BJOBPTRNDSTCD = 'RS'
		       AND   SNDRCVENDHMS &gt; #date# || '99999999'
					 ) A
	</statement>
	
	<statement id="getBatchProcCount" parameterClass="java.util.HashMap" resultClass="java.util.HashMap">
		SELECT COALESCE( SUM( CASE WHEN A.BJOBSENDRECVGB = 'S' AND A.RESULTCD = 'T' THEN 1 ELSE 0 END ),0) AS SEND_SEND,
		       COALESCE( SUM( CASE WHEN A.BJOBSENDRECVGB = 'R' AND A.RESULTCD = 'T' THEN 1 ELSE 0 END ),0) AS SEND_RECV,
		       COALESCE( SUM( CASE WHEN A.BJOBSENDRECVGB = 'S' AND A.RESULTCD = 'E' THEN 1 ELSE 0 END ),0) AS FAIL_SEND,
		       COALESCE( SUM( CASE WHEN A.BJOBSENDRECVGB = 'R' AND A.RESULTCD = 'E' THEN 1 ELSE 0 END ),0) AS FAIL_RECV,
		       COALESCE( SUM( CASE WHEN A.BJOBSENDRECVGB = 'S' AND A.RESULTCD = 'Q' THEN 1 ELSE 0 END ),0) AS QUED_SEND,
		       COALESCE( SUM( CASE WHEN A.BJOBSENDRECVGB = 'R' AND A.RESULTCD = 'Q' THEN 1 ELSE 0 END ),0) AS QUED_RECV
		FROM (
		       SELECT SUBSTR(BJOBPTRNDSTCD,2,1) AS BJOBSENDRECVGB,
		              THISSTGEPRCSSRSULTCD AS RESULTCD
		       FROM $schemaId$.TSEAIBJ08
					 WHERE      FILETRSMTSTARTHMS BETWEEN SUBSTR(TO_CHAR(CURRENT_TIMESTAMP,'YYYYMMDDHH24MISSFF3'),1,8) || '00000000'
		              AND SUBSTR(TO_CHAR(CURRENT_TIMESTAMP,'YYYYMMDDHH24MISSFF3'),1,8) || '99999999'
		       UNION ALL
		       SELECT 'S' AS BJOBSENDRECVGB,
		              'Q' AS RESULTCD
		       FROM $schemaId$.TSEAIBS03
		       WHERE BJOBPTRNDSTCD = 'RS'
		       AND   SNDRCVENDHMS &gt; SUBSTR(TO_CHAR(CURRENT_TIMESTAMP,'YYYYMMDDHH24MISSFF3'),1,16)
					 ) A
		</statement>
		
	<statement id="getEaiBatchServerIpList" parameterClass="java.util.HashMap" resultClass="java.util.HashMap">
		SELECT EAISEVRINSTNCNAME EAISVRINSTNM,  EAISEVRIP EAISVRIP,
		       SEVRLSNPORTNAME EAISVRLSNPORT,   FLOVRSEVRNAME FAILOVERSVRNM,
		       HOSTNAME HOSTNAME
		FROM   $schemaId$.TSEAIBP03
		WHERE  EAISEVRINSTNCNAME != 'ALL'
		   AND EAISEVRIP != '*'
		 ORDER BY EAISEVRIP, SEVRLSNPORTNAME ASC
  </statement>
  
  
  <!-- EAI BATCH -->
	<statement id="getEaiBatchProcCount" parameterClass="java.util.HashMap" resultClass="java.util.HashMap">
	  SELECT 
	     COALESCE(SUM(CASE WHEN T2.SNDSTATUSCD='C' THEN 1 ELSE 0 END),0) AS SEND_SEND,
	     COALESCE(SUM(CASE WHEN T2.SNDSTATUSCD NOT IN ('C','S') THEN 1 ELSE 0 END),0) AS FAIL_SEND,
	     COALESCE(SUM(CASE WHEN T2.RCVSTATUSCD='C' THEN 1 ELSE 0 END),0) AS SEND_RECV,
	     COALESCE(SUM(CASE WHEN T2.RCVSTATUSCD NOT IN ('C','S') AND T2.SNDSTATUSCD='C' THEN 1 ELSE 0 END),0) AS FAIL_RECV,
	     COALESCE(SUM(CASE WHEN T2.SNDSTATUSCD='S' THEN 1 ELSE 0 END),0) AS QUED_SEND,
	     COALESCE(SUM(CASE WHEN T2.RCVSTATUSCD='S' THEN 1 ELSE 0 END),0) AS QUED_RECV
	  FROM (
	  SELECT
	   CASE WHEN (SELECT MAX(TRANSSTATUSCD) FROM $schemaId$.TSEAIES03 WHERE BJOBDMNDMSGID=A.BJOBDMNDMSGID AND SNDRCVKIND='1' ) IS NULL 
            THEN CASE WHEN (SELECT MAX(TRANSSTATUSCD) FROM $schemaId$.TSEAIES04 WHERE BJOBDMNDMSGID=A.BJOBDMNDMSGID AND SNDRCVKIND='1' ) IS NOT NULL
                 THEN (SELECT MAX(TRANSSTATUSCD) FROM $schemaId$.TSEAIES04 WHERE BJOBDMNDMSGID=A.BJOBDMNDMSGID AND SNDRCVKIND='1' ) 
                 ELSE 'F'
            END
            ELSE (SELECT MAX(TRANSSTATUSCD) FROM $schemaId$.TSEAIES03 WHERE BJOBDMNDMSGID=A.BJOBDMNDMSGID AND SNDRCVKIND='1' )
       END  AS SNDSTATUSCD
     , CASE WHEN (SELECT MAX(TRANSSTATUSCD) FROM $schemaId$.TSEAIES03 WHERE BJOBDMNDMSGID=A.BJOBDMNDMSGID AND SNDRCVKIND='2' ) IS NULL 
            THEN CASE WHEN (SELECT MAX(TRANSSTATUSCD) FROM $schemaId$.TSEAIES04 WHERE BJOBDMNDMSGID=A.BJOBDMNDMSGID AND SNDRCVKIND='2' ) IS NOT NULL
                 THEN (SELECT MAX(TRANSSTATUSCD) FROM $schemaId$.TSEAIES04 WHERE BJOBDMNDMSGID=A.BJOBDMNDMSGID AND SNDRCVKIND='2' ) 
                 ELSE 'F'
            END  
            ELSE (SELECT MAX(TRANSSTATUSCD) FROM $schemaId$.TSEAIES03 WHERE BJOBDMNDMSGID=A.BJOBDMNDMSGID AND SNDRCVKIND='2' )
       END  AS RCVSTATUSCD
  
	  FROM
	    $schemaId$.TSEAIES01 A
	  WHERE 1=1
	    AND SUBSTR(A.MSGREGDATE,1,8)=TO_CHAR(CURRENT_DATE,'YYYYMMDD')
	   ) T2
  </statement>
  
  <statement id="getEaiBatchProcCountByDate" parameterClass="java.util.HashMap" resultClass="java.util.HashMap">
	  SELECT 
	     COALESCE(SUM(CASE WHEN T2.SNDSTATUSCD='C' THEN 1 ELSE 0 END),0) AS SEND_SEND,
	     COALESCE(SUM(CASE WHEN T2.SNDSTATUSCD NOT IN ('C','S') THEN 1 ELSE 0 END),0) AS FAIL_SEND,
	     COALESCE(SUM(CASE WHEN T2.RCVSTATUSCD='C' THEN 1 ELSE 0 END),0) AS SEND_RECV,
	     COALESCE(SUM(CASE WHEN T2.RCVSTATUSCD NOT IN ('C','S') AND T2.SNDSTATUSCD='C' THEN 1 ELSE 0 END),0) AS FAIL_RECV,
	     COALESCE(SUM(CASE WHEN T2.SNDSTATUSCD='S' THEN 1 ELSE 0 END),0) AS QUED_SEND,
	     COALESCE(SUM(CASE WHEN T2.RCVSTATUSCD='S' THEN 1 ELSE 0 END),0) AS QUED_RECV
	  FROM (
	  SELECT
	   CASE WHEN (SELECT MAX(TRANSSTATUSCD) FROM $schemaId$.TSEAIES03 WHERE BJOBDMNDMSGID=A.BJOBDMNDMSGID AND SNDRCVKIND='1' ) IS NULL 
            THEN CASE WHEN (SELECT MAX(TRANSSTATUSCD) FROM $schemaId$.TSEAIES04 WHERE BJOBDMNDMSGID=A.BJOBDMNDMSGID AND SNDRCVKIND='1' ) IS NOT NULL
                 THEN (SELECT MAX(TRANSSTATUSCD) FROM $schemaId$.TSEAIES04 WHERE BJOBDMNDMSGID=A.BJOBDMNDMSGID AND SNDRCVKIND='1' ) 
                 ELSE 'F'
            END
            ELSE (SELECT MAX(TRANSSTATUSCD) FROM $schemaId$.TSEAIES03 WHERE BJOBDMNDMSGID=A.BJOBDMNDMSGID AND SNDRCVKIND='1' )
       END  AS SNDSTATUSCD
     , CASE WHEN (SELECT MAX(TRANSSTATUSCD) FROM $schemaId$.TSEAIES03 WHERE BJOBDMNDMSGID=A.BJOBDMNDMSGID AND SNDRCVKIND='2' ) IS NULL 
            THEN CASE WHEN (SELECT MAX(TRANSSTATUSCD) FROM $schemaId$.TSEAIES04 WHERE BJOBDMNDMSGID=A.BJOBDMNDMSGID AND SNDRCVKIND='2' ) IS NOT NULL
                 THEN (SELECT MAX(TRANSSTATUSCD) FROM $schemaId$.TSEAIES04 WHERE BJOBDMNDMSGID=A.BJOBDMNDMSGID AND SNDRCVKIND='2' ) 
                 ELSE 'F'
            END  
            ELSE (SELECT MAX(TRANSSTATUSCD) FROM $schemaId$.TSEAIES03 WHERE BJOBDMNDMSGID=A.BJOBDMNDMSGID AND SNDRCVKIND='2' )
       END  AS RCVSTATUSCD
  
	  FROM
	    $schemaId$.TSEAIES01 A
	  WHERE 1=1
	    AND SUBSTR(A.MSGREGDATE,1,8)=#date#
	   ) T2
  </statement>
</sqlMap>
