<?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, 6)))+100001 ),2), #bjobBzwkDstcd# || '00001' )
        FROM   $schemaId$.TSEAIBJ01
        WHERE BjobBzwkDstcd = #bjobBzwkDstcd#
    </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="updateBJ01" resultClass="java.lang.Integer">
		UPDATE $schemaId$.TSEAIBJ01
		SET BjobMsgDsticName          =  #bjobMsgDsticName#          ,
		    BjobBzwkDstcd             =  #bjobBzwkDstcd#             ,
		    BjobTranDstcdName         =  #bjobTranDstcdName#         ,
            BjobTelgmHdrSize          =  #bjobTelgmHdrSize#          ,
            BjobTelgmTrailSize        =  #bjobTelgmTrailSize#        ,
            EAIFileSendUseYn          =  #fileSendUseYn#             ,
            EAIFileRecvUseYn          =  #fileRecvUseYn#             ,
            RecvNotiUseYn             =  ' '                         ,
            ThisMsgUseYn              =  #thisMsgUseYn#              ,
            ThisMsgAmndrID            =  #userid#            ,
            ThisMsgAmndHMS            =  SUBSTR(HEX(CURRENT TIMESTAMP), 1, 17),
            MsgPrcssPrity             =  #msgPrcssPrity#             ,
            BjobTelgmRecSize          =  #bjobTelgmRecSize#          ,
            UapplCd                   =  #uapplCd#                   ,
            SndrcvFileName            =  #sndRcvFileName#            ,
            ThisMsgChrgIDs            =  #thisMsgChrgIDs#            ,
            GroupCoCd                 =  #groupCoCd#                 ,
            RmtNodeName				  =  #rmtNodeName#			  	 ,
            SndScriptName             =  #sndScriptName#             ,
            LogCretnYn                =  #logCretnYn#
		WHERE BjobMsgDstcd = #bjobMsgDstcd#
	</statement>	
	
    <statement id="generatePKBS01" resultClass="java.lang.String">
        SELECT 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 BjobMsgDstcd = #bjobMsgDstcd#
            ) LEFTCODE
        FROM $schemaId$.TSEAIBJ01
        WHERE BjobMsgDstcd = #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                = SUBSTR(HEX(CURRENT TIMESTAMP), 1, 17)
        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#                                 ,
             SUBSTR(HEX(CURRENT TIMESTAMP), 1, 17)		 ,
             #rqstRecvReTralCnt#                         ,
             #rqstRecvReTralUseYn#                       ,
             #rqstRecvReTralIntvalTtm#                   ,
             ' '                                         ,
             #startDlayNoday#                            ,
             #endDlayNoday#                              ,
             #holdyPrcssDstcd#                           ,
             #rpttYn#                                    ,
             #thisMsgUseYn#                              ,
             ' '                                         ,
             #userid#                                    ,
             SUBSTR(HEX(CURRENT TIMESTAMP), 1, 17) ,
             #userid#                                    ,
             SUBSTR(HEX(CURRENT TIMESTAMP), 1, 17)
        )
    </statement>		

</sqlMap>