<?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="mmiBapSync">
<!--  
    <statement id="generatePKBJ01" resultClass="java.lang.String">
        SELECT COALESCE (MAX(SUBSTR(BjobMsgDstcd, 1,5)) || SUBSTR(TO_CHAR(TO_NUMBER(MAX(SUBSTR(BjobMsgDstcd, 9)))+100001 ),2), #bjobBzwkDstcd# || '00001' )
        FROM   $schemaId$.TSEAIBJ01
        WHERE TRIM(BjobBzwkDstcd) = TRIM(#bjobBzwkDstcd#)
    </statement>
-->

    <statement id="generatePKBJ01"  resultClass="java.lang.String">
        SELECT COALESCE (MAX(SUBSTR(BjobMsgDstcd, 1,5)) || SUBSTR(TO_CHAR(TO_NUMBER(MAX(SUBSTR(BjobMsgDstcd, 6)))+100001 ),2), #bzwkDstCd# || '00001' )
        FROM   $schemaId$.TSEAIBJ01
        WHERE TRIM(BjobBzwkDstcd) = TRIM(#bzwkDstCd#)
    </statement>
 <!--  
    <statement id="selectPKBJ01" resultClass="java.lang.String">
		SELECT BjobMsgDstcd
		FROM $schemaId$.TSEAIBJ01 A
        WHERE  A.BjobBzwkDstcd = #bjobBzwkDstcd#
        AND    A.BjobTranDstcdName = #bjobTranDstcdName#
	</statement>	
 -->  
    <statement id="selectPKBJ01" resultClass="java.lang.String">
		SELECT BjobMsgDstcd
		FROM $schemaId$.TSEAIBJ01 A
 		WHERE  TRIM(A.OUTBIZCD) = TRIM(#outBizCd#)
        AND    NVL(A.BjobTranDstcdName,0) = NVL(#fileCode#,0)
	</statement>	

    <statement id="selectNdmNodeBySysId" resultClass="java.lang.String">
		SELECT RmtNodeName
		FROM $schemaId$.TSEAIBA07
        WHERE  SystemId = #systemId#
	</statement>	

    <statement id="selectSysGbCd" resultClass="java.util.HashMap">
		SELECT BjobBzwkDstcd, OsidInstiDstcd
		FROM $schemaId$.TSEAIBA07
        WHERE SystemId like #sysGbName# || '%'
	</statement>	
<!-- 
	<statement id="insertBJ01" resultClass="java.lang.Integer">
		INSERT INTO $schemaId$.TSEAIBJ01 (
		    BjobMsgDstcd              ,
		    BjobMsgDsticName          ,
		    BjobBzwkDstcd             ,
		    BjobTranDstcdName         ,
            BjobTelgmHdrSize          ,
            BjobTelgmTrailSize        ,
            EAIFileSendUseYn          ,
            EAIFileRecvUseYn          ,
            RecvNotiUseYn             ,
            ThisMsgUseYn              ,
            ThisMsgRegsntID           ,
            ThisMsgRegiHMS            ,
            ThisMsgAmndrID            ,
            ThisMsgAmndHMS            ,
            MsgPrcssPrity             ,
            BjobTelgmRecSize          ,
            UapplCd                   ,
            SndrcvFileName            ,
            ThisMsgChrgIDs            ,
            GroupCoCd                 ,
            RmtNodeName				  ,
            SndScriptName			  ,
            LogCretnYn	)
		VALUES (
		    #bjobMsgDstcd#              ,
		    #bjobMsgDsticName#          ,
		    #bjobBzwkDstcd#             ,
		    #bjobTranDstcdName#         ,
            #bjobTelgmHdrSize#          ,
            #bjobTelgmTrailSize#        ,
            #fileSendUseYn#             ,
            #fileRecvUseYn#             ,
            ' '                         ,
            #thisMsgUseYn#              ,
            #userid#           ,
            SUBSTR(HEX(CURRENT TIMESTAMP), 1, 17),
            #userid#            ,
            SUBSTR(HEX(CURRENT TIMESTAMP), 1, 17),
            #msgPrcssPrity#             ,
            #bjobTelgmRecSize#          ,
            #uapplCd#                   ,
            #sndRcvFileName#            ,
            #thisMsgChrgIDs#            ,
            #groupCoCd#                 ,
            #rmtNodeName#			  	,
            #sndScriptName#				,
            #logCretnYn#                 )
	</statement>
 -->
 	<statement id="insertBJ01" resultClass="java.lang.Integer">
		INSERT INTO $schemaId$.TSEAIBJ01 (
		    BjobMsgDstcd              ,
		    BjobMsgDsticName          ,
		    BjobBzwkDstcd             ,
		    BjobTranDstcdName         ,
            BjobTelgmHdrSize          ,
            BjobTelgmTrailSize        ,
            EAIFileSendUseYn          ,
            EAIFileRecvUseYn          ,
            RecvNotiUseYn             ,
            ThisMsgUseYn              ,
            ThisMsgRegsntID           ,
            ThisMsgRegiHMS            ,
            ThisMsgAmndrID            ,
            ThisMsgAmndHMS            ,
            MsgPrcssPrity             ,
            BjobTelgmRecSize          ,
            SYSCD                   ,
            UapplCd                   ,
            SndrcvFileName            ,
            RCVFILEPATTERN ,
            ThisMsgChrgIDs            ,
            GroupCoCd                 ,
            RmtNodeName				  ,
            SndScriptName			  ,
            LogCretnYn,
            SNDRCVFILEPATH,
			FILETRANSSCHE,
			INFID,
			OUTBIZCD,
			FILETRANSALAM,
			FILETRANSCOND,
			OSIDINSTITELNO,
			OSIDINSTIBZWKRSEMPNAME,
			OSIDINSTICODE,
			BZWKRSEMPTELNO,
			BZWKRSEMPNAME)
		VALUES (
			#bjobMsgDstcd#              ,
			#infDesc#          ,
			#bzwkDstCd#             ,
			#fileCode#         ,
			#recSize#          ,
			#recSize#        ,
			#fileSendUseYN#            ,
			#fileRecvUseYN#             ,
			' '                         ,
			'1'              ,
			#authorId#           ,
			TO_CHAR(SYSTIMESTAMP, 'YYYYMMDDHH24MISSFF3'),
			#authorId#            ,
			TO_CHAR(SYSTIMESTAMP, 'YYYYMMDDHH24MISSFF3'),
			'999'             ,
			#recSize#          ,
			#srcBzSystemCd#                   ,
			#appCd#                   ,
			' '            ,
			' '            ,
			#authorId#            ,
			#appCd#                 ,
			' '                         ,
			' '                         ,			
			' '                         ,
			' '                         ,
			' '                         ,
			#infId#                 ,
			#outBizCd#           ,
			' '                         ,
			' '                         ,
			' '                         ,
			' '                         ,
			' '                         ,
			' '                         ,																		
			' '                         )
	</statement>
	<statement id="updateBJ01" resultClass="java.lang.Integer">
		UPDATE $schemaId$.TSEAIBJ01
		SET BjobMsgDsticName          =  #infDesc#          ,
		    BjobBzwkDstcd             =  #bzwkDstCd#             ,
		    BjobTranDstcdName         =  #fileCode#         ,
            BjobTelgmHdrSize          =  #recSize#          ,
            BjobTelgmTrailSize        =  #recSize#        ,
            EAIFileSendUseYn          =  '1'             ,
            EAIFileRecvUseYn          =  '1'             ,
            RecvNotiUseYn             =  ' '                         ,
            ThisMsgUseYn              =  '1'              ,
            ThisMsgAmndrID            =  #authorId#            ,
            ThisMsgAmndHMS            =  SUBSTR(HEX(CURRENT TIMESTAMP), 1, 17),
            MsgPrcssPrity             =  #msgPrcssPrity#             ,
            BjobTelgmRecSize          =  #bjobTelgmRecSize#          ,
            SYSCD					 =  #srcBzSystemCd#          ,
            UapplCd                   =  #uapplCd#                   ,
            SndrcvFileName            =  #sndRcvFileName#            ,
            ThisMsgChrgIDs            =  #thisMsgChrgIDs#            ,
            GroupCoCd                 =  #groupCoCd#                 ,
            RmtNodeName				  =  #rmtNodeName#			  	 ,
            SndScriptName             =  #sndScriptName#             ,
            LogCretnYn                =  #logCretnYn#
		WHERE TRIM(BjobMsgDstcd) = TRIM(#bjobMsgDstcd#)
	</statement>	
	
    <statement id="generatePKBS01" resultClass="java.lang.String">
        SELECT (TRIM(BjobBzwkDstcd) || #bjobPtrnDstcd# || BjobTranDstcdName ||
            (
                SELECT
                    CASE LENGTH(TO_CHAR(TO_NUMBER(COALESCE(MAX(SUBSTR(RTRIM(BjobMsgScheId), LENGTH(RTRIM(BjobMsgScheId))-2, 3)), '0')) + 1))
                        WHEN 1
                            THEN '00' || TO_CHAR(TO_NUMBER(COALESCE(MAX(SUBSTR(RTRIM(BjobMsgScheId), LENGTH(RTRIM(BjobMsgScheId))-2, 3)), '0')) + 1)
                        WHEN 2
                            THEN '0' || TO_CHAR(TO_NUMBER(COALESCE(MAX(SUBSTR(RTRIM(BjobMsgScheId), LENGTH(RTRIM(BjobMsgScheId))-2, 3)), '0')) + 1)
                        WHEN 3
                            THEN TO_CHAR(TO_NUMBER(COALESCE(MAX(SUBSTR(RTRIM(BjobMsgScheId), LENGTH(RTRIM(BjobMsgScheId))-2, 3)), '0')) + 1)
                    END
                FROM $schemaId$.TSEAIBS01
                WHERE TRIM(BjobMsgDstcd) = TRIM(#bjobMsgDstcd#)
            )) AS LEFTCODE
        FROM $schemaId$.TSEAIBJ01
        WHERE TRIM(BjobMsgDstcd) = TRIM(#bjobMsgDstcd#)
    </statement>
    
    <statement id="updateBS01" resultClass="java.lang.Integer">
        UPDATE $schemaId$.TSEAIBS01
        SET
            SndrcvStartHMS                = REPLACE(#sndrcvStartHMS#,':' ) ,
            SndrcvEndHMS                  = REPLACE(#sndrcvEndHMS#,':' )   ,
            RqstRecvReTralCnt             = #rqstRecvReTralCnt#            ,
            RqstRecvReTralUseYn           = #rqstRecvReTralUseYn#          ,
            RqstRecvReTralIntvalTtm       = #rqstRecvReTralIntvalTtm#      ,
            StartDlayNoday                = #startDlayNoday#               ,
            EndDlayNoday                  = #endDlayNoday#                 ,
            HoldyPrcssDstcd               = #holdyPrcssDstcd#              ,
            RpttYn                        = #rpttYn#                       ,
            ThisMsgUseYn                  = #thisMsgUseYn#                 ,
            ThisMsgAmndrID                = #userid#               ,
            ThisMsgAmndHMS                = TO_CHAR(SYSTIMESTAMP, 'YYYYMMDDHH24MISSFF3')
        WHERE RTRIM(BjobMsgScheId) = RTRIM(#bJobMsgScheId#)
    </statement>
    
	<statement id="insertBS01" resultClass="java.lang.Integer">
        INSERT INTO $schemaId$.TSEAIBS01 (
             BjobMsgScheId            ,
             BjobMsgDstcd             ,
             BjobPtrnDstcd            ,
             OsidInstiDstcd           ,
             SndrcvStartHMS           ,
             SndrcvEndHMS             ,
             MsgSndrID                ,
             ScheFrstRegiHMS          ,
             RqstRecvReTralCnt        ,
             RqstRecvReTralUseYn      ,
             RqstRecvReTralIntvalTtm  ,
             RqstRecvFileStorgDirName ,
             StartDlayNoday           ,
             EndDlayNoday             ,
             HoldyPrcssDstcd          ,
             RpttYn                   ,
             ThisMsgUseYn             ,
             ThisMsgScheDesc          ,
             ThisMsgRegsntID          ,
             ThisMsgRegiHMS           ,
             ThisMsgAmndrID           ,
             ThisMsgAmndHMS )
        VALUES (
             #bjobMsgScheId#                             ,
             #bjobMsgDstcd#                              ,
             #bjobPtrnDstcd#                             ,
             #osidInstiDstcd#                            ,
             REPLACE(#sndrcvStartHMS#, ':', '')          ,
             REPLACE(#sndrcvEndHMS#, ':', '')            ,
             #msgSndrID#                                 ,
             TO_CHAR(SYSTIMESTAMP, 'YYYYMMDDHH24MISSFF3')		 ,
             #rqstRecvReTralCnt#                         ,
             #rqstRecvReTralUseYn#                       ,
             #rqstRecvReTralIntvalTtm#                   ,
             ' '                                         ,
             #startDlayNoday#                            ,
             #endDlayNoday#                              ,
             #holdyPrcssDstcd#                           ,
             #rpttYn#                                    ,
             #thisMsgUseYn#                              ,
             ' '                                         ,
             #userid#                                    ,
             TO_CHAR(SYSTIMESTAMP, 'YYYYMMDDHH24MISSFF3') ,
             #userid#                                    ,
             TO_CHAR(SYSTIMESTAMP, 'YYYYMMDDHH24MISSFF3')
        )
    </statement>		

	<statement id="insertPost" resultClass="java.lang.Integer">
		INSERT INTO $schemaId$.TSEAIBJ01 (
											 BJOBMSGDSTCD
											,BJOBMSGDSTICNAME
											,BJOBBZWKDSTCD
											,BJOBTRANDSTCDNAME
											,BJOBTELGMHDRSIZE
											,BJOBTELGMRECSIZE
											,BJOBTELGMTRAILSIZE
											,EAIFILESENDUSEYN
											,EAIFILERECVUSEYN
											,MSGPRCSSPRITY
											,SYSCD
											,UAPPLCD
											,SNDRCVFILENAME
											,RCVFILEPATTERN
											,SNDRCVFILEPATH
											,THISMSGCHRGIDS
											,RECVNOTIUSEYN
											,LOGCRETNYN
											,FILETRANSSCHE
											,THISMSGUSEYN
											,THISMSGREGSNTID
											,THISMSGREGIHMS
											,THISMSGAMNDRID
											,THISMSGAMNDHMS
		                                  ) 
				                  VALUES (
											 #bjobMsgDstcd#
											,#bjobMsgDsticName#
											,#bjobBzwkDstcd#
											,#bjobTranDstcdName#
											,#bjobTelgmRecSize#
											,#bjobTelgmRecSize#
											,#bjobTelgmRecSize#
											,#eaiFileSendUseYn#
											,#eaiFileRecvUseYn#
											,#msgPrcssPrity#
											,#sysCd#
											,#uapplCd#
											,#sndRcvFileName#
											,#rcvFilePattern#
											,#sndrcvfilepath#
											,#thisMsgChrgIDs#
											,#recvnotiuseYn#
											,#logCretnYn#
											,#fileTransSche#
											,#thisMsgUseYn#
											,#thisMsgRegsntID#
											,TO_CHAR(SYSTIMESTAMP, 'YYYYMMDDHH24MISSFF3')
											,#thisMsgAmndrID#
											,TO_CHAR(SYSTIMESTAMP, 'YYYYMMDDHH24MISSFF3')
										 )		
    </statement>
<!--  
	<statement id="updatePost" resultClass="java.lang.Integer">
		UPDATE $schemaId$.TSEAIBJ01
		   SET BJOBMSGDSTICNAME  = #bjobMsgDsticName#
			  ,BJOBBZWKDSTCD     = #bjobBzwkDstcd#
			  ,BJOBTRANDSTCDNAME = #bjobTranDstcdName#
			  ,BJOBTELGMHDRSIZE  = #bjobTelgmRecSize#
			  ,BJOBTELGMRECSIZE  = #bjobTelgmRecSize#
			  ,BJOBTELGMTRAILSIZE = #bjobTelgmRecSize#
			  ,EAIFILESENDUSEYN  = #eaiFileSendUseYn#
			  ,EAIFILERECVUSEYN  = #eaiFileRecvUseYn#
			  ,MSGPRCSSPRITY     = #msgPrcssPrity#
			  ,SYSCD             = #sysCd#
			  ,UAPPLCD           = #uapplCd#
			  ,SNDRCVFILENAME    = #sndRcvFileName#
			  ,RCVFILEPATTERN    = #rcvFilePattern#
			  ,SNDRCVFILEPATH    = #sndrcvfilepath#
			  ,THISMSGCHRGIDS    = #thisMsgChrgIDs#
			  ,RECVNOTIUSEYN     = #recvnotiuseYn#
			  ,LOGCRETNYN        = #logCretnYn#
			  ,FILETRANSSCHE     = #fileTransSche#
			  ,THISMSGUSEYN      = #thisMsgUseYn#
			  ,THISMSGREGSNTID   = #thisMsgRegsntID#
			  ,THISMSGREGIHMS    = TO_CHAR(SYSTIMESTAMP, 'YYYYMMDDHH24MISSFF3')
		 WHERE TRIM(BjobMsgDstcd) = TRIM(#bjobMsgDstcd#)		   	
	</statement>
-->
	<statement id="updatePost" resultClass="java.lang.Integer">
		UPDATE $schemaId$.TSEAIBJ01
		   SET BJOBMSGDSTICNAME  = #infDesc#
			  ,BJOBBZWKDSTCD     = #bzwkDstCd#
			  ,BJOBTRANDSTCDNAME = #fileCode#
			  ,BJOBTELGMHDRSIZE  = #recSize#
			  ,BJOBTELGMRECSIZE  = #recSize#
			  ,BJOBTELGMTRAILSIZE = #recSize#
			  ,EAIFILESENDUSEYN  = #fileSendUseYN#
			  ,EAIFILERECVUSEYN  = #fileRecvUseYN#
			  ,MSGPRCSSPRITY     = '999'
			  ,SYSCD             = #srcBzSystemCd#
			  ,UAPPLCD           = #appCd#
			  ,SNDRCVFILENAME    = ' '
			  ,RCVFILEPATTERN    = ' '
			  ,SNDRCVFILEPATH    = ' '
			  ,THISMSGCHRGIDS    = #authorId#
			  ,RECVNOTIUSEYN     = ' '
			  ,LOGCRETNYN        = ' '
			  ,FILETRANSSCHE     = ' '
			  ,THISMSGUSEYN      = '1'
			  ,THISMSGREGSNTID   = #authorId#
			  ,THISMSGREGIHMS    = TO_CHAR(SYSTIMESTAMP, 'YYYYMMDDHH24MISSFF3')
		 WHERE TRIM(BjobMsgDstcd) = TRIM(#bjobMsgDstcd#)		   	
	</statement>

</sqlMap>