<?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="Interface">
  
  <!-- 외부 인터페이스 관리 목록조회 ( PAGE ) -->
  <statement id="selectList" parameterClass="java.util.HashMap" resultClass="java.util.HashMap">
			              
	SELECT * 
	         FROM ( SELECT ROW_NUMBER() OVER(ORDER BY HE01.EAISvcName) ROWNO
	                     , HE01.EAISvcName
	                     , HE01.EAIBzwkDstcd
	                     , SUBSTR( HE01.EAISvcName, 1, LENGTH(HE01.EAISvcName)-2) EAITRANNAME
	                     , HE01.EAISvcDesc
			              , CASE WHEN '$schemaId$' = 'EAI' 
			              		THEN CASE WHEN SUBSTR(HE01.EAISVCNAME, LENGTH(HE01.EAISVCNAME)-1, 2) IN ('S2','R2')
			              				  THEN 'O' ELSE 'I' END
			                     ELSE CASE WHEN SUBSTR(HE01.EAISvcName, LENGTH(HE01.EAISvcName)-1, 2) in ('S2','R1') 
			                 	 			THEN 'O' ELSE 'I' END 
			                 END IO
	                     , SUBSTR(HE01.EAISVCNAME, LENGTH(HE01.EAISVCNAME)-1, 1) SplizDmndDstcd 
                         , SUBSTR(HE01.EAISVCNAME, LENGTH(HE01.EAISVCNAME), 1) StndTelgmWtinExtnlDstcd    
						 , SUBSTR( HE01.GstatSysAdptrBzwkGroupName,2,3) FromName
					     , SUBSTR( HE02.PsvSysAdptrBzwkGroupName,2,3) ToName
						 , HE01.DevUserId DevUser
						 , '' DevUserName
						 , HE01.BankUserId BankUser
						 , '' BankUserName
			             , HE01.CreateBy
			             , HE01.UpdateBy
			             , '' CreateByName
			             , '' UpdateByName
					  FROM $schemaId$.TSEAIHE01 HE01 
          				  LEFT OUTER JOIN $schemaId$.TSEAIHE02 HE02 ON HE01.EAISvcName = HE02.EAISvcName AND HE02.SvcPrcssNo = 1
          				  WHERE HE01.EAIBzwkDstcd IN ( select EAIBZWKDSTCD from $schemaId$.TSEAIRM06 where USERID=#loginId#  )
					      <isNotEmpty prepend="AND" property="searchEaiBzwkDstcd">
					            HE01.EAIBzwkDstcd = #searchEaiBzwkDstcd#
					      </isNotEmpty>
					      <isNotEmpty prepend="AND" property="searchEaiSvcName">
					            HE01.EAISvcName LIKE '%' || #searchEaiSvcName# || '%'
					      </isNotEmpty>
		      )
		 WHERE ROWNO BETWEEN #startNum# AND #endNum# 
  </statement>
  
  <!-- 외부 인터페이스 목록조회 COUNT -->
  <statement id="selectListCount" parameterClass="java.util.HashMap" resultClass="java.lang.Integer">
    SELECT COUNT(*) CNT
      FROM $schemaId$.TSEAIHE01 HE01 
    WHERE HE01.EAIBzwkDstcd IN ( select EAIBZWKDSTCD from $schemaId$.TSEAIRM06 where USERID=#loginId#  )
   <isNotEmpty prepend="AND" property="searchEaiBzwkDstcd">
          HE01.EAIBzwkDstcd = #searchEaiBzwkDstcd#
   </isNotEmpty>
   <isNotEmpty prepend="AND" property="searchEaiSvcName">
          HE01.EAISvcName LIKE '%' || #searchEaiSvcName# || '%'
   </isNotEmpty>
  </statement>  
  
  <!-- 외부 인터페이스 DETAIL -->
  <statement id="selectDetail"  parameterClass="java.util.HashMap" resultClass="java.util.HashMap">
	 	 SELECT HE01.EAISvcName 
	 	      , HE01.EAIBzwkDstcd
	 	      , SUBSTR(HE01.EAISvcName, 1, LENGTH(HE01.EAISvcName)-2) eaiTranName
	          , HE01.EAISvcDesc
              , CASE WHEN '$schemaId$' = 'EAI' 
              		THEN CASE WHEN SUBSTR(HE01.EAISVCNAME, LENGTH(HE01.EAISVCNAME)-1, 2) IN ('S2','R2')
              				  THEN 'O' ELSE 'I' END
                     ELSE CASE WHEN SUBSTR(HE01.EAISvcName, LENGTH(HE01.EAISvcName)-1, 2) in ('S2','R1') 
                 	 			THEN 'O' ELSE 'I' END 
                 END io
              , SUBSTR(HE01.EAISvcName, LENGTH(HE01.EAISvcName)-1, 1) SplizDmndDstcd
	          , SUBSTR(HE01.EAISvcName, LENGTH(HE01.EAISvcName), 1) StndTelgmWtinExtnlDstcd
		      , CASE WHEN HE01.SvcMotivUseDstcd ='SYNC' and HE02.PsvIntfacDsticName ='SYNC' then 'SYNC' 
		             WHEN HE01.SvcMotivUseDstcd ='ASYN' and HE02.PsvIntfacDsticName ='ASYN' then 'ASYN' 
		             WHEN HE01.SvcMotivUseDstcd ='SYNC' and HE02.PsvIntfacDsticName ='ASYN' then 'SYNC_ASYN'
		             WHEN HE01.SvcMotivUseDstcd ='ASYN' and HE02.PsvIntfacDsticName ='SYNC' then 'ASYN_SYNC'
		             end  SvcMotivUseDstcd  
	          , trim(RecvTranName) serviceId
	          , MS02_1.RefMsgIDName || CASE WHEN MS02_2.RefMsgIDName IS NOT NULL THEN ',' || MS02_2.RefMsgIDName END || CASE WHEN MS02_3.RefMsgIDName IS NOT NULL THEN ',' || MS02_3.RefMsgIDName 
	             END LayoutMappingName
	          , FR_1.BzwkFldName bzwkFldName1
	          , NVL(FR_1.MsgFldStartSituVal,0) MsgFldStartSituVal1
	          , NVL(FR_1.MsgFldLen,0) msgFldLen1
	          , FR_2.BzwkFldName bzwkFldName2
	          , NVL(FR_2.MsgFldStartSituVal,0) MsgFldStartSituVal2
	          , NVL(FR_2.MsgFldLen,0) msgFldLen2
	          , HE01.GstatSysAdptrBzwkGroupName fromAdapter
	          , HE02.PsvSysAdptrBzwkGroupName toAdapter
	          , HE02_2.PsvSysAdptrBzwkGroupName extAdapter
	          , HE01.DevUserId
	          , '' DevUserName
	          , HE01.BankUserId  
	          , '' BankUserName
	          , HS04.bzwkSvcKeyName
		  FROM  $schemaId$.TSEAIHE01 HE01 
					  LEFT OUTER JOIN ( 
                            SELECT EAISVCNAME ,hs04.bzwkSvcKeyName
		                         , max(decode(COLUMNNAME,'COMMON_SRVCID',COLUMNVALUE,'')) RecvTranName
		                      FROM $schemaId$.TSEAIHS04 hs04 , $schemaId$.tseaihs05 hs05
		                      where hs04.BZWKSVCKEYNAME =hs05.BZWKSVCKEYNAME
		                     group by hs04.BZWKSVCKEYNAME,EAISVCNAME				
					  ) HS04
					  On HE01.EAISvcName = HS04.EAISvcName
            LEFT OUTER JOIN $schemaId$.TSEAIHE02 HE02   ON HE01.EAISvcName = HE02.EAISvcName AND HE02.SvcPrcssNo = 1
            LEFT OUTER JOIN $schemaId$.TSEAIHE02 HE02_2 ON HE01.EAISvcName = HE02_2.EAISvcName AND HE02_2.SvcPrcssNo = 2
            LEFT OUTER JOIN (SELECT EAISvcName, RefMsgIDName FROM $schemaId$.TSEAIMS02 WHERE RefMsgIDNo=1 ) MS02_1 On HE01.EAISvcName = MS02_1.EAISvcName
            LEFT OUTER JOIN (SELECT EAISvcName, RefMsgIDName FROM $schemaId$.TSEAIMS02 WHERE RefMsgIDNo=2 ) MS02_2 On HE01.EAISvcName = MS02_2.EAISvcName
            LEFT OUTER JOIN (SELECT EAISvcName, RefMsgIDName FROM $schemaId$.TSEAIMS02 WHERE RefMsgIDNo=3 ) MS02_3 On HE01.EAISvcName = MS02_3.EAISvcName
					  LEFT OUTER JOIN (SELECT EAISvcName, BzwkFldName, MsgFldStartSituVal, MsgFldLen FROM $schemaId$.TSEAIFR03 WHERE FldPrcssNo=1 ) FR_1 On HE01.EAISvcName = FR_1.EAISvcName
					  LEFT OUTER JOIN (SELECT EAISvcName, BzwkFldName, MsgFldStartSituVal, MsgFldLen FROM $schemaId$.TSEAIFR03 WHERE FldPrcssNo=2 ) FR_2 On HE01.EAISvcName = FR_2.EAISvcName
		 WHERE HE01.EAISvcName = #eaiSvcName#  
  </statement>
    
  <!-- Detail 추가 정보 -->
  <statement id="selectDetailHE10" parameterClass="java.util.HashMap" resultClass="java.util.HashMap">
  	SELECT 
	  	EAISVCNAME
	  	,'REALTIME' AS OCCURDSTCD
		,TRANSKIND
		,TRANSFREQ
		,SIZEONCE
		,PROCTERM
		,REQCHGR
		,REQCHGRTLNO
		,RESCHGR
		,RESCHGRTLNO
		,RMK
	FROM $schemaId$.TSEAIHE10
  	WHERE EAISvcName = #eaiSvcName#
  </statement>

  <statement id="mergeHE10" parameterClass="java.util.HashMap">
      MERGE INTO $schemaId$.TSEAIHE10 A USING (
            SELECT #eaiSvcName# EAISvcName
              FROM DUAL
            ) B ON (A.EAISvcName = B.EAISvcName)
       WHEN NOT MATCHED THEN
            INSERT (EaiSvcName       , TransKind	,TransFreq		,SizeOnce	,ProcTerm,
            		ReqChgr			,ReqChgrTlno		,ResChgr	,ResChgrTlno	,Rmk
            ) VALUES (#eaiSvcName#          , #transKind#	,#transFreq#		,#sizeOnce#		,#procTerm#	,
            			#reqChgr#			,#reqChgrTlno#		,#resChgr#		,#resChgrTlno#  ,#rmk#                 
	          )
       WHEN MATCHED THEN 
            UPDATE SET       
			             TransKind           		= #transKind#,
			             TransFreq 					= #transFreq#,	
			             SizeOnce                 	= #sizeOnce#, 
			             ProcTerm                   = #procTerm#, 		        
			             ReqChgr					= #reqChgr#,
			             ReqChgrTlno				= #reqChgrTlno#,
			             ResChgr					= #resChgr#,
			             ResChgrTlno				= #resChgrTlno#,
			             Rmk						= #rmk#
     
  </statement>
    
  <statement id="deleteHE10" parameterClass="java.util.HashMap">
    DELETE FROM $schemaId$.TSEAIHE10 
     WHERE EAISvcName = #eaiSvcName#
  </statement>
   
   
   <statement id="selectListHS03"  parameterClass="java.util.HashMap" resultClass="java.util.HashMap">
 	 SELECT * FROM $schemaId$.TSEAIHS03 
 	</statement>
  <statement id="deleteToHS04" parameterClass="java.util.HashMap">
    DELETE FROM $schemaId$.TSEAIHS04 
     WHERE EAISvcName = #eaiTranName#||#splizDmndDstcd#||#stndTelgmWtinExtnlDstcd#       
  </statement>
  <statement id="deleteToHS05" parameterClass="java.util.HashMap">
    DELETE FROM $schemaId$.TSEAIHS05 
     WHERE bzwkSvcKeyName in (SELECT bzwkSvcKeyName from $schemaId$.TSEAIHS04 where EAISvcName = #eaiTranName#||#splizDmndDstcd#||#stndTelgmWtinExtnlDstcd#)       
  </statement>  



  
  <statement id="detailToHS05" resultClass="java.util.HashMap" parameterClass="java.util.HashMap">
        SELECT 
	          HS04.BzwkSvcKeyName
	          , EAISVCNAME
	          , COLUMNNAME
	          , COLUMNVALUE
      FROM $schemaId$.TSEAIHS04 HS04 ,$schemaId$.TSEAIHS05 HS05
     WHERE HS04.BzwkSvcKeyName = HS05.BzwkSvcKeyName
       AND EAISVCNAME = #eaiTranName#||#splizDmndDstcd#||#stndTelgmWtinExtnlDstcd#
  </statement>  
  <!-- 내부표준전문 처리 -->
  <statement id="mergeToHS04" parameterClass="java.util.HashMap">
      MERGE INTO $schemaId$.TSEAIHS04 A USING (
            SELECT #COMMON_IFID#||#HEADER_MESGDMANDVCD#||#COMMON_HMABDVCD# EAISVCNAME
              FROM DUAL
            ) B ON ( A.EAISVCNAME =  B.EAISVCNAME )
       WHEN NOT MATCHED THEN
            INSERT(BzwkSvcKeyName  , EAISVCNAME ) 
            VALUES(#bzwkSvcKeyName#, #COMMON_IFID#||#HEADER_MESGDMANDVCD#||#COMMON_HMABDVCD#) 

  </statement>    
  <statement id="mergeToHS05" parameterClass="java.util.HashMap">
      MERGE INTO $schemaId$.TSEAIHS05 A USING (
            SELECT #bzwkSvcKeyName# bzwkSvcKeyName , #columnName# COLUMNNAME
              FROM DUAL
            ) B ON ( A.bzwkSvcKeyName =  B.bzwkSvcKeyName and a.COLUMNNAME =b.COLUMNNAME)
       WHEN NOT MATCHED THEN
            INSERT(BzwkSvcKeyName    , COLUMNNAME  , COLUMNVALUE ) 
            VALUES(#bzwkSvcKeyName#  , #columnName#, #columnValue#) 
       WHEN MATCHED THEN 
            UPDATE SET
			             COLUMNVALUE = #columnValue#  

  </statement>    
   
   
  <!-- EAI메세지 -->
  <statement id="mergeToHE01" parameterClass="java.util.HashMap">
      MERGE INTO $schemaId$.TSEAIHE01 A USING (
            SELECT #eaiSvcName# EAISvcName
              FROM DUAL
            ) B ON (A.EAISvcName = B.EAISvcName)
       WHEN NOT MATCHED THEN
            INSERT (EAISvcName        , EAIBzwkDstcd    , SvcHMSEonot    , SvcMotivUseDstcd           , SvcPrcesDsticName , 
                    FlowCtrlRoutName  , IntgraDsticName , SvcBfClmnLogYn , GstatSysAdptrBzwkGroupName , SevrLogLvelNo     , 
                    SvcLogLvelNo      , EAISvcDesc      , SimYn          , CreateBy                   , UpdateBy          , 
                    DevUserid          , BankUserid         , CreateOn     , UpdateOn                 

            ) VALUES (#eaiSvcName#      , #eaiBzwkDstcd#    , #svcHMSEonot#    , #svcMotivUseDstcd#           , #svcPrcesDsticName# ,
                      #flowCtrlRoutName#, #intgraDsticName# , #svcBfClmnLogYn# , #gstatSysAdptrBzwkGroupName# , #sevrLogLvelNo#     ,
                      #svcLogLvelNo#    , #eaiSvcDesc#      , 'N'              , #loginId#                   , #loginId#          , 
                      #devUserId#        , #bankUserId#       , to_char(sysdate,'yyyymmddhh24miss')          , to_char(sysdate,'yyyymmddhh24miss')
             
	          )
       WHEN MATCHED THEN 
            UPDATE SET
			             EAIBzwkDstcd               = NVL(#eaiBzwkDstcd#,              ' '),
			             SvcMotivUseDstcd           = NVL(#svcMotivUseDstcd#,          ' '),
			             GstatSysAdptrBzwkGroupName = NVL(#gstatSysAdptrBzwkGroupName#,' '),
			             EAISvcDesc                 = NVL(#eaiSvcDesc#,                ' '),
			             UpdateBy                   = NVL(#loginId#,                  ' '),
			             DevUserId                   = NVL(#devUserId#,                DevUserId),
			             BankUserId                  = NVL(#bankUserd#,                BankUserId),
			             UpdateOn                   = to_char(sysdate,'yyyymmddhh24miss') ,
			             FlowCtrlRoutName           = NVL(#flowCtrlRoutName#,           ' ')

  </statement>
  <delete id="deleteNo2ToHE02" parameterClass="java.util.HashMap">
     DELETE $schemaId$.TSEAIHE02 WHERE EAISvcName = #eaiSvcName# AND SvcPrcssNo=2
  </delete>
  
  <statement id="mergeToHE02" parameterClass="java.util.HashMap">
      MERGE INTO $schemaId$.TSEAIHE02 A USING (
            SELECT #eaiSvcName# EAISvcName, #svcPrcssNo# SvcPrcssNo
              FROM DUAL
            ) B ON ( A.EAISvcName = B.EAISvcName
                 AND A.SvcPrcssNo = B.SvcPrcssNo )
       WHEN NOT MATCHED THEN
            INSERT (EAISvcName,            SvcPrcssNo,               PsvIntfacDsticName,     PsvSysBzwkDstcd,     PsvSysIDName, 
                    PsvSysSvcDsticName,    PsvSysAdptrBzwkGroupName, FlovrYn,                ChngEonot,           ChngMsgIDName, 
                    BascRspnsMsgCmprCtnt,  BascRspnsChngEonot,       BascRspnsChngMsgIDName, ErrRspnsMsgCmprCtnt, ErrRspnsChngEonot, 
                    ErrRspnsChngMsgIDName, NextSvcPrcssNo,           OutbndRoutName,         ToutVal,             CmpenSvcPrcssDsticName, 
                    SupplDelYn,            HdrCtrlDstcd,             HdrRefClsName
            ) VALUES (#eaiSvcName#,            #svcPrcssNo#,               #psvIntfacDsticName#,      #psvSysBzwkDstcd#,        #psvSysIDName#,
											#psvSysSvcDsticName#,    #psvSysAdptrBzwkGroupName#, #flovrYn#,                 #chngEonot#,              #chngMsgIDName#, 
											#bascRspnsMsgCmprCtnt#,  #bascRspnsChngEonot#,       #bascRspnsChngMsgIDName#,  #errRspnsMsgCmprCtnt#,    #errRspnsChngEonot#,
											#errRspnsChngMsgIDName#, #nextSvcPrcssNo#,           #outbndRoutName#,       #toutVal#,#cmpenSvcPrcssDsticName#,
											#supplDelYn#,            #hdrCtrlDstcd#,             #hdrRefClsName#
	          )
       WHEN MATCHED THEN 
            UPDATE SET
									 PsvIntfacDsticName       = NVL(#psvIntfacDsticName#       ,' '),
									 PsvSysBzwkDstcd          = NVL(#psvSysBzwkDstcd#          ,' '),
									 PsvSysAdptrBzwkGroupName = NVL(#psvSysAdptrBzwkGroupName# ,' '),
									 OutbndRoutName           = NVL(#outbndRoutName#           ,' '),
									 SupplDelYn               = NVL(#supplDelYn#               ,'0'),
									 HdrCtrlDstcd             = NVL(#hdrCtrlDstcd#             ,'01'),
									 HdrRefClsName            = NVL(#hdrRefClsName#            ,' ')
									 
									 
									 
  </statement>   
   
	<statement id="selectPopListCount" parameterClass="java.util.HashMap" resultClass="java.lang.Integer">
		SELECT COUNT(*) CNT
		  FROM $schemaId$.TSEAIHE01 HE01 
		<dynamic prepend="WHERE">
			<isNotEmpty prepend="AND" property="eaiSvcName">
				UPPER(HE01.EAISvcName) LIKE UPPER('%' || #eaiSvcName# || '%')
			</isNotEmpty>
		</dynamic>
	</statement>
	
	<statement id="selectPopList" parameterClass="java.util.HashMap" resultClass="java.util.HashMap">
		SELECT * 
		  FROM ( SELECT ROW_NUMBER() OVER(ORDER BY HE01.EAISvcName) ROWNO
					  , HE01.EAISvcName
					  , HE01.EAIBzwkDstcd
					  , SUBSTR( HE01.EAISvcName, 1, LENGTH(HE01.EAISvcName)-2) EAITRANNAME
					  , HE01.EAISvcDesc
					  , CASE WHEN '$schemaId$' = 'EAI' 
								THEN CASE WHEN SUBSTR(HE01.EAISVCNAME, LENGTH(HE01.EAISVCNAME)-1, 2) IN ('S2','R2')
											THEN 'O' ELSE 'I' END
							 ELSE CASE WHEN SUBSTR(HE01.EAISvcName, LENGTH(HE01.EAISvcName)-1, 2) in ('S2','R1') 
										THEN 'O' ELSE 'I' END 
						 END io
					  , SUBSTR(HE01.EAISVCNAME, LENGTH(HE01.EAISVCNAME)-1, 1) SplizDmndDstcd 
					  , SUBSTR(HE01.EAISVCNAME, LENGTH(HE01.EAISVCNAME), 1) StndTelgmWtinExtnlDstcd
				   FROM $schemaId$.TSEAIHE01 HE01
					<dynamic prepend="WHERE">
						<isNotEmpty prepend="AND" property="eaiSvcName">
							UPPER(HE01.EAISvcName) LIKE UPPER('%' || #eaiSvcName# || '%')
						</isNotEmpty>
					</dynamic>
			   )
		 WHERE ROWNO BETWEEN #startNum# AND #endNum# 
	</statement>  
</sqlMap>
  