<?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="BapMessageProc">

	<statement id="selectList" resultClass="java.util.HashMap">
        SELECT BJOBMSGDSTCD            ,
               BJOBBZWKDSTCD           ,
               BJOBBZWKNAME            ,
               BJOBMSGDSTICNAME        ,
               BJOBTRANDSTCDNAME       ,
               EAIFILESENDUSEYN        ,
               EAIFILERECVUSEYN        ,
               THISMSGUSEYN            ,
               UAPPLCD                 ,
               GROUPCOCD               ,
               BJOBTELGMRECSIZE        ,
               SNDRCVFILENAME          ,
               THISMSGCHRGIDS          ,
               BJOBINSTIDSTCD          ,
                ROWNO
        FROM ( SELECT @NO := @NO + 1 AS ROWNO,
                      A.BjobMsgDstcd,
                      case when A.EAIFileSendUseYn = '1' then A.UapplCd
                           else A.BjobBzwkDstcd end BjobBzwkDstcd,
                      B.BjobBzwkName,
                      A.BjobMsgDsticName,
                      A.BjobTranDstcdName,
                      A.BjobTelgmRecSize,
                      A.EAIFileSendUseYn,
                      A.EAIFileRecvUseYn,
                      A.SndrcvFileName,
                      A.ThisMsgUseYn,
                      A.ThisMsgChrgIDs,
                      A.BjobInstiDstcd,	
                      case when A.EAIFileSendUseYn = '1' then A.BjobBzwkDstcd
                           else A.UapplCd end UapplCd,
                      A.GroupCoCd	
               FROM   $schemaId$.TSEAIBJ01 A, $schemaId$.TSEAIBJ02 B,  (SELECT @NO := 0) R
               WHERE  A.BjobBzwkDstcd = B.BjobBzwkDstcd
               AND    A.BjobMsgDstcd Like #likeBjobMsgDstcd#
               AND    A.BjobMsgDsticName Like #likeBjobMsgDsticName#
               AND    A.BjobTranDstcdName Like #likeBjobTranDstcdName#
               AND    A.UapplCd Like #likeUapplCd#
               AND    A.ThisMsgChrgIDs LIKE #likeThisMsgChrgIDs#
               AND    A.BjobInstiDstcd LIKE #likeBjobInstiDstcd#
            <isEqual prepend="AND" property="searchThisMsgUseYn" compareValue="1">
                      A.ThisMsgUseYn = '1'
            </isEqual>
            <isEqual prepend="AND" property="searchThisMsgUseYn" compareValue="0">
                      A.ThisMsgUseYn != '1'
            </isEqual>
            <isNotEmpty prepend="AND" property="searchBjobBzwkDstcd" >
                      B.BjobBzwkDstcd = #searchBjobBzwkDstcd#
            </isNotEmpty>
               ORDER BY BjobTranDstcdName, BjobMsgDstcd
			<isNotEmpty prepend="AND" property="groupCoCd" >
                      A.GroupCoCd = #searchGroupCoCd#
			</isNotEmpty>
	         ) TMP
	 	WHERE ROWNO BETWEEN #startNum# AND #endNum#
	</statement>

    <statement id="generatePK" resultClass="java.lang.String">
        SELECT 
        (COALESCE( 
			CONCAT( MAX(SUBSTR(BjobMsgDstcd, 1,5)) , SUBSTR( CAST( CAST( MAX( SUBSTR(BjobMsgDstcd, 6) ) AS UNSIGNED) + 100001 AS CHAR),2) ) , 
			CONCAT( #bjobBzwkDstcd# , 	'00001')
		)) AS MSGKEY
        FROM   $schemaId$.TSEAIBJ01
        WHERE BjobBzwkDstcd = #bjobBzwkDstcd#
    </statement>

    <statement id="checkCount" resultClass="java.lang.Integer">
        SELECT COUNT(BjobMsgDstcd)
        FROM   $schemaId$.TSEAIBJ01
        WHERE BjobMsgDstcd = #bjobMsgDstcd#
        OR   ( BjobBzwkDstcd = #bjobBzwkDstcd# AND BjobTranDstcdName = #bjobTranDstcdName# )
    </statement>
    
	<statement id="getBzwkDstcd" parameterClass="java.util.HashMap" resultClass="java.util.HashMap">
         SELECT BJOBBZWKDSTCD, BJOBBZWKNAME
         FROM $schemaId$.TSEAIBJ02
         ORDER BY BjobBzwkDstcd
	</statement>
	
	<statement id="getProps" resultClass="java.util.HashMap">
        SELECT IFNULL(A.PRPTYNAME, B.PRPTYNAME) AS PRPTYNAME,
               A.PRPTYDESC AS PRPTYDESC,
               B.PRPTY2VAL AS PRPTY2VAL
        FROM ( SELECT PrptyName,
                      PrptyDesc
               FROM $schemaId$.TSEAIBP06
               WHERE  BjobBzwkDstcd = #bjobBzwkDstcd#
               AND    PrptyTypDstcd = 'F' ) A
             LEFT JOIN
             ( SELECT PrptyName,
                      Prpty2Val
               FROM   $schemaId$.TSEAIBA06
               WHERE  PrptyGroupName = #propGroupName# ) B
             ON A.PrptyName = B.PrptyName
        UNION ALL
        SELECT IFNULL(A.PRPTYNAME, B.PRPTYNAME) AS PRPTYNAME,
               A.PRPTYDESC AS PRPTYDESC,
               B.PRPTY2VAL AS PRPTY2VAL
        FROM ( SELECT PrptyName,
                      PrptyDesc
               FROM $schemaId$.TSEAIBP06
               WHERE  BjobBzwkDstcd = #bjobBzwkDstcd#
               AND    PrptyTypDstcd = 'F' ) A
             RIGHT JOIN
             ( SELECT PrptyName,
                      Prpty2Val
               FROM   $schemaId$.TSEAIBA06
               WHERE  PrptyGroupName = #propGroupName# ) B
             ON A.PrptyName = B.PrptyName
             WHERE A.PrptyName IS NULL 
	</statement>

    <statement id="selectOsidInstiDstcd" parameterClass="java.util.HashMap" resultClass="java.util.HashMap">
        SELECT OsidInstiDstcd AS CODE
        	 , OsidInstiName AS NAME
          FROM $schemaId$.TSEAIBJ06
         WHERE LTRIM(RTRIM(BjobBzwkDstcd)) = #bjobBzwkDstcd#
         ORDER BY OsidInstiDstcd
    </statement>

	<statement id="insert" 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              ,
            ThisMsgChrgIDs              ,
            GroupCoCd                   ,
            IntfID                      ,
            BjobInstiDstcd              ,
            DataVrfyYn                  ,
            BJobCycleGb                 ,
            ProcYn                      ,
            DupCnt                      ,
            EndYn                       ,
            EndCnt                      ,
            SndScriptname
            )
     VALUES (
            #bjobMsgDstcd#              ,
            #bjobMsgDsticName#          ,
            #bjobBzwkDstcd#             ,
            #bjobTranDstcdName#         ,
            #bjobTelgmHdrSize#          ,
            #bjobTelgmTrailSize#        ,
            #fileSendUseYn#             ,
            #fileRecvUseYn#             ,
            #recvNotiUseYn#             ,
            #thisMsgUseYn#              ,
            #userid#           ,
            SUBSTR( DATE_FORMAT( NOW(3), '%Y%m%d%H%i%s%f'), 1, 17 ),
            #userid#            ,
            SUBSTR( DATE_FORMAT( NOW(3), '%Y%m%d%H%i%s%f'), 1, 17 ),
            #msgPrcssPrity#             ,
            #bjobTelgmRecSize#          ,
            IFNULL(#sysCd#, ' ')        ,
            #uapplCd#                   ,
            #sndrcvFileName#            ,
            IFNULL(#thisMsgChrgIDs#,' '),
            IFNULL(#groupCoCd#, ' ')    ,
            IFNULL(#intfID#, ' ')       ,
            IFNULL(#bjobInstiDstcd#,' '),
            IFNULL(#dataVrfyYn#, 0)     ,
            IFNULL(#bJobCycleGb#, ' ')  ,
            IFNULL(#procYn#, 0)         ,
            IFNULL(#dupCnt#, 0)         ,
            IFNULL(#endYn#, 0)          ,
            IFNULL(#endCnt#, 0)         ,
            IFNULL(#sndScriptname#, ' ')
            )
	</statement>

	<statement id="update" resultClass="java.lang.Integer">
     UPDATE $schemaId$.TSEAIBJ01
        SET BjobMsgDsticName          =  #bjobMsgDsticName#          ,
            BjobBzwkDstcd             =  #bjobBzwkDstcd#             ,
            BjobTranDstcdName         =  #bjobTranDstcdName#         ,
            BjobTelgmHdrSize          =  #bjobTelgmHdrSize#          ,
            BjobTelgmTrailSize        =  #bjobTelgmTrailSize#        ,
            EAIFileSendUseYn          =  #fileSendUseYn#             ,
            EAIFileRecvUseYn          =  #fileRecvUseYn#             ,
            RecvNotiUseYn             =  #recvNotiUseYn#             ,
            ThisMsgUseYn              =  #thisMsgUseYn#              ,
            ThisMsgAmndrID            =  #userid#                    ,
            ThisMsgAmndHMS            =  SUBSTR( DATE_FORMAT( NOW(3), '%Y%m%d%H%i%s%f'), 1, 17 ),
            MsgPrcssPrity             =  #msgPrcssPrity#             ,
            BjobTelgmRecSize          =  #bjobTelgmRecSize#          ,
            SysCd                     =  IFNULL(#sysCd#, ' ')        ,
            UapplCd                   =  #uapplCd#                   ,
            SndrcvFileName            =  #sndrcvFileName#            ,
            ThisMsgChrgIDs            =  IFNULL(#thisMsgChrgIDs#,' '),
            GroupCoCd                 =  IFNULL(#groupCoCd#, ' ')    ,
            IntfID                    =  IFNULL(#intfID#, ' ')       ,
            BjobInstiDstcd            =  IFNULL(#bjobInstiDstcd#,' '),
            DataVrfyYn                =  IFNULL(#dataVrfyYn#, 0)     ,
            BJobCycleGb               =  IFNULL(#bJobCycleGb#, ' ')  ,
            ProcYn                    =  IFNULL(#procYn#, 0)         ,
            DupCnt                    =  IFNULL(#dupCnt#, 0)         ,
            EndYn                     =  IFNULL(#endYn#, 0)          ,
            EndCnt                    =  IFNULL(#endCnt#, 0)         ,
            SndScriptname             =  IFNULL(#sndScriptname#, ' ')
      WHERE BjobMsgDstcd = #bjobMsgDstcd#
	</statement>

	<statement id="userCount" resultClass="java.lang.Integer">
        SELECT COUNT(*) AS "TotalCount"
        FROM   $schemaId$.TSEAIRM02
		<dynamic prepend="WHERE">
		    <isNotEmpty prepend="AND" property="pafiarInfoEmpid" >
                 PafiarInfoEmpid LIKE CONCAT( #pafiarInfoEmpid#  ,  '%') 
		    </isNotEmpty>
		    <isNotEmpty prepend="AND" property="userName" >
                 UserName LIKE CONCAT(  #userName# , '%')
		    </isNotEmpty>
		</dynamic> 
	</statement>	

	<statement id="getUserList" resultClass="java.util.HashMap">
        SELECT PAFIARINFOEMPID,
               USERNAME
        FROM   ( SELECT @NO := @NO + 1 AS ROWNO,
                        PafiarInfoEmpid,
                        UserName
                 FROM   $schemaId$.TSEAIRM02,  (SELECT @NO := 0) R
				<dynamic prepend="WHERE">
				    <isNotEmpty prepend="AND" property="pafiarInfoEmpid" >
		                 PafiarInfoEmpid LIKE CONCAT( #pafiarInfoEmpid#  ,  '%') 
				    </isNotEmpty>
				    <isNotEmpty prepend="AND" property="userName" >
		                 UserName LIKE CONCAT(  #userName# , '%')
				    </isNotEmpty>
				</dynamic>
				ORDER BY PafiarInfoEmpid 
	           ) TMP
	 	WHERE ROWNO BETWEEN #startNum# AND #endNum#
	</statement>	

	<statement id="getUserList2" resultClass="java.util.HashMap">
        SELECT PAFIARINFOEMPID,
               USERNAME
        FROM   $schemaId$.TSEAIRM02
        WHERE  PafiarInfoEmpid IN (
                                <iterate property="chrgIDs" conjunction=", ">
                                    #chrgIDs[]#
                                </iterate>
                                    )
	</statement>

	<statement id="getUserList3" resultClass="java.util.HashMap">
        SELECT PAFIARINFOEMPID,
               USERNAME
        FROM   $schemaId$.TSEAIRM02
	</statement>

    <statement id="checkPK" parameterClass="java.util.HashMap" resultClass="java.lang.String">
        SELECT CASE WHEN COUNT(1) > 0 THEN 'Y'  ELSE 'N' END AS checkPK
          FROM $schemaId$.$tableName$
         WHERE $columnName$ = #columnValue#
    </statement>

	<statement id="selectVerifyInfo" parameterClass="java.util.HashMap" resultClass="java.util.HashMap">
		SELECT A.BJOBMSGDSTCD 
			 , A.BJOBBZWKDSTCD
			 , B.HDRVERIYN
			 , B.HDRVERIOFFSET
			 , B.HDRVERILEN
			 , B.HDRVERIVAL
			 , B.DATAVERIYN
			 , B.DATAVERIOFFSET
			 , B.DATAVERILEN
			 , B.DATAVERIVAL
			 , B.TRAILVERIYN
			 , B.TRAILVERIOFFSET
			 , B.TRAILVERILEN
			 , B.TRAILVERIVAL
			 , B.THISMSGUSEYN
			 , B.THISMSGREGSNTID
			 , B.THISMSGREGIHMS
			 , B.THISMSGAMNDRID
			 , B.THISMSGAMNDHMS
		  FROM $schemaId$.TSEAIBJ01 A
		  LEFT OUTER JOIN $schemaId$.TSEAIBJ12 B
			ON A.BJOBMSGDSTCD = B.BJOBMSGDSTCD
		 WHERE A.BJOBMSGDSTCD = #bjobMsgDstcd#
	</statement>

	<statement id="updateVerifyInfo" parameterClass="java.util.HashMap" resultClass="java.lang.Integer">
		INSERT 
		  INTO $schemaId$.TSEAIBJ12 (
			   BJOBMSGDSTCD
			 , HDRVERIYN
			 , HDRVERIOFFSET
			 , HDRVERILEN
			 , HDRVERIVAL
			 , DATAVERIYN
			 , DATAVERIOFFSET
			 , DATAVERILEN
			 , DATAVERIVAL
			 , TRAILVERIYN
			 , TRAILVERIOFFSET
			 , TRAILVERILEN
			 , TRAILVERIVAL
			 , THISMSGUSEYN
			 , THISMSGREGSNTID
			 , THISMSGREGIHMS
			 , THISMSGAMNDRID
			 , THISMSGAMNDHMS
			 )
		VALUES (
			   #bjobMsgDstcd#
			 , IFNULL(#hdrVeriYn#, '0')
			 , IFNULL(#hdrVeriOffset#, 0)
			 , IFNULL(#hdrVeriLen#, 0)
			 , IFNULL(#hdrVeriVal#, ' ')
			 , IFNULL(#dataVeriYn#, '0')
			 , IFNULL(#dataVeriOffset#, 0)
			 , IFNULL(#dataVeriLen#, 0)
			 , IFNULL(#dataVeriVal#, ' ')
			 , IFNULL(#trailVeriYn#, '0')
			 , IFNULL(#trailVeriOffset#, 0)
			 , IFNULL(#trailVeriLen#, 0)
			 , IFNULL(#trailVeriVal#, ' ')
			 , IFNULL(#thisMsgUseYn#, '0')
			 , #userid#
			 , SUBSTR( DATE_FORMAT( NOW(3), '%Y%m%d%H%i%s%f'), 1, 17 )
			 , #userid#
			 , SUBSTR( DATE_FORMAT( NOW(3), '%Y%m%d%H%i%s%f'), 1, 17 )
			 )
			ON DUPLICATE KEY 
		UPDATE hdrVeriYn = IFNULL(#hdrVeriYn#, '0')
			 , hdrVeriOffSet = IFNULL(#hdrVeriOffset#, 0)
			 , hdrVeriLen = IFNULL(#hdrVeriLen#, 0)
			 , hdrVeriVal = IFNULL(#hdrVeriVal#, ' ')
			 , dataVeriYn = IFNULL(#dataVeriYn#, '0')
			 , dataVeriOffSet = IFNULL(#dataVeriOffset#, 0)
			 , dataVeriLen = IFNULL(#dataVeriLen#, 0)
			 , dataVeriVal = IFNULL(#dataVeriVal#, ' ')
			 , trailVeriYn = IFNULL(#trailVeriYn#, '0')
			 , trailVeriOffSet = IFNULL(#trailVeriOffset#, 0)
			 , trailVeriLen = IFNULL(#trailVeriLen#, 0)
			 , trailVeriVal = IFNULL(#trailVeriVal#, ' ')
			 , thisMsgUseYn = IFNULL(#thisMsgUseYn#, '0')
			 , thismsgamndrid = #userid#
			 , thismsgamndhms = SUBSTR( DATE_FORMAT( NOW(3), '%Y%m%d%H%i%s%f'), 1, 17 )
	</statement>
	
	<statement id="deleteVerifyInfo" parameterClass="java.util.HashMap" resultClass="java.lang.Integer">
		DELETE FROM $schemaId$.TSEAIBJ12 WHERE BjobMsgDstcd = #bjobMsgDstcd#
	</statement>

</sqlMap>