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

    <statement id="selectList" resultClass="java.util.HashMap">
        SELECT OSIDINSTINAME        ,
               OSIDINSTIDSTCD       ,
               BJOBBZWKNAME         ,
               BJOBBZWKDSTCD        ,
               SENDPRCSSRULECD      ,
               RECVPRCSSRULECD      ,
               EAIFILESENDPTRNDSTCD ,
               EAIFILERECVPTRNDSTCD ,
               THISMSGUSEYN         ,
               ROWNO
        FROM (
            SELECT A.OsidInstiName        AS OsidInstiName       ,
                   A.OsidInstiDstcd       AS OsidInstiDstcd      ,
                   B.BjobBzwkName         AS BjobBzwkName        ,
                   A.BjobBzwkDstcd        AS BjobBzwkDstcd       ,
                   A.SendPrcssRuleCd      AS SendPrcssRuleCd     ,
                   A.RecvPrcssRuleCd      AS RecvPrcssRuleCd     ,
                   A.EAIFileSendPtrnDstcd AS EAIFileSendPtrnDstcd,
                   A.EAIFileRecvPtrnDstcd AS EAIFileRecvPtrnDstcd,
                   A.ThisMsgUseYn         AS ThisMsgUseYn        ,
                  @NO := @NO + 1 AS ROWNO
            FROM   $schemaId$.TSEAIBJ06 A, $schemaId$.TSEAIBJ02 B,  (SELECT @NO := 0) R
            WHERE  A.BjobBzwkDstcd  = B.BjobBzwkDstcd
            AND    A.OsidInstiName  LIKE CONCAT( '%'  ,  #searchOsidInstiName#   ,  '%')
            AND    A.OsidInstiDstcd LIKE CONCAT( '%'  ,  #searchOsidInstiDstcd#   ,  '%')
            AND    B.BjobBzwkName   LIKE CONCAT( '%'  ,  #searchBjobBzwkName#   ,  '%')
            ORDER BY A.OsidInstiName, A.OsidInstiDstcd, A.BjobBzwkDstcd
           ) TMP
         WHERE ROWNO BETWEEN #startNum# AND #endNum#
    </statement>

    <statement id="selectListCount" resultClass="java.lang.Integer">
        SELECT  COUNT(*) AS TOTALCOUNT
        FROM    $schemaId$.TSEAIBJ06 A,
                $schemaId$.TSEAIBJ02 B
        WHERE   A.BjobBzwkDstcd  =    B.BjobBzwkDstcd
        AND    A.OsidInstiName  LIKE CONCAT( '%'  ,  #searchOsidInstiName#   ,  '%')
        AND    A.OsidInstiDstcd LIKE CONCAT( '%'  ,  #searchOsidInstiDstcd#   ,  '%')
        AND    B.BjobBzwkName   LIKE CONCAT( '%'  ,  #searchBjobBzwkName#   ,  '%')
    </statement>

    <statement id="selectDetail" resultClass="java.util.HashMap">
        SELECT
            BJOBBZWKDSTCD         ,
            OSIDINSTIDSTCD        ,
            OSIDINSTINAME         ,
            ADPTRBZWKGROUPNAME    ,
            SENDPRCSSRULECD       ,
            RECVPRCSSRULECD       ,
            EAIFILESENDPTRNDSTCD  AS FILESENDPTRNDSTCD,
            EAIFILERECVPTRNDSTCD  AS FILERECVPTRNDSTCD,
            TELGMBLCKSIZE         ,
            TELGMSERNOSIZE        ,
            TELGMPCKETSIZE        ,
            TRANSTARTINDX         ,
            TRANENDINDX           ,
            THISMSGUSEYN          ,
            THISMSGREGSNTID       ,
            THISMSGREGIHMS        ,
            THISMSGAMNDRID        ,
            THISMSGAMNDHMS
        FROM $schemaId$.TSEAIBJ06
        WHERE BjobBzwkDstcd = #bjobBzwkDstcd#
        AND   LTRIM(RTRIM(OsidInstiDstcd))= #osidInstiDstcd#
    </statement>

    <statement id="detailSysconn" resultClass="java.util.HashMap">
        SELECT SYSLNKGDSTCD       ,
               RQSTRSPNSDSTCD     ,
               LNKGIPINFONAME     ,
               LNKGPORTINFONAME   ,
               LNKGID             ,
               LNKGPWD            ,
               TCIRTLNKGSTUSCD    ,
               ADPTRBZWKGROUPNAME ,
               ADPTRBZWKNAME      ,
               SHINHANCARDNATIP   ,
               OSIDINSTIIP        ,
               THISMSGUSEYN       ,
               THISMSGREGSNTID    ,
               THISMSGREGIHMS     ,
               THISMSGAMNDRID     ,
               THISMSGAMNDHMS
        FROM $schemaId$.TSEAIBJ05
        WHERE BjobBzwkDstcd = #bjobBzwkDstcd#
        AND   LTRIM(RTRIM(OsidInstiDstcd))= #osidInstiDstcd#
        ORDER BY SysLnkgDstcd
    </statement>

    <statement id="insert" resultClass="java.lang.Integer">
        INSERT INTO $schemaId$.TSEAIBJ06 (
            BjobBzwkDstcd         ,
            OsidInstiDstcd        ,
            OsidInstiName         ,
            AdptrBzwkGroupName    ,
            SendPrcssRuleCd       ,
            RecvPrcssRuleCd       ,
            EAIFileSendPtrnDstcd  ,
            EAIFileRecvPtrnDstcd  ,
            TelgmBlckSize         ,
            TelgmSernoSize        ,
            TelgmPcketSize        ,
            TranStartIndx         ,
            TranEndIndx           ,
            ThisMsgUseYn          ,
            ThisMsgRegsntID       ,
            ThisMsgRegiHMS        ,
            ThisMsgAmndrID        ,
            ThisMsgAmndHMS        )
        VALUES (
            #bjobBzwkDstcd#         ,
            #osidInstiDstcd#        ,
            #osidInstiName#         ,
            #adptrBzwkGroupName#    ,
            #sendPrcssRuleCd#       ,
            #recvPrcssRuleCd#       ,
            #fileSendPtrnDstcd#     ,
            #fileRecvPtrnDstcd#     ,
            #telgmBlckSize#         ,
            #telgmSernoSize#        ,
            #telgmPcketSize#        ,
            #tranStartIndx#         ,
            #tranEndIndx#           ,
            #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 )
        )
    </statement>

    <statement id="insertSysconn" resultClass="java.lang.Integer">
        INSERT INTO $schemaId$.TSEAIBJ05 (
           SysLnkgDstcd         ,
           BjobBzwkDstcd        ,
           OsidInstiDstcd       ,
           RqstRspnsDstcd       ,
           LnkgIPInfoName       ,
           LnkgPortInfoName     ,
           LnkgID               ,
           LnkgPwd              ,
           ToutVal              ,
           TCirtLnkgStusCd      ,
           AdptrBzwkGroupName   ,
           AdptrBzwkName        ,
           ShinhanCardNatIp     ,
           OsidInstiIp          ,
           ThisMsgUseYn         ,
           ThisMsgRegsntID      ,
           ThisMsgRegiHMS       ,
           ThisMsgAmndrID       ,
           ThisMsgAmndHMS    )
        VALUES (
           #sysLnkgDstcd#         ,
           #bjobBzwkDstcd#        ,
           #osidInstiDstcd#       ,
           #rqstRspnsDstcd#       ,
           #lnkgIPInfoName#       ,
           #lnkgPortInfoName#     ,
           COALESCE(#lnkgID#  ,' '  ) ,
           COALESCE(#lnkgPwd# ,' '  ) ,
           #toutVal#              ,
           #tcirtLnkgStusCd#      ,
           COALESCE(#adptrBzwkGroupName#, ' '  ) ,
           COALESCE(#adptrBzwkName#, ' '  ) ,
           COALESCE(#shinhanCardNatIp#, ' '  ) ,
           COALESCE(#osidInstiIp#, ' '  ) ,
           #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 )
        )
    </statement>

    <statement id="update" resultClass="java.lang.Integer">
        UPDATE $schemaId$.TSEAIBJ06
        SET BjobBzwkDstcd          = #bjobBzwkDstcd#         ,
            OsidInstiDstcd         = #osidInstiDstcd#        ,
            OsidInstiName          = #osidInstiName#         ,
            AdptrBzwkGroupName     = #adptrBzwkGroupName#    ,
            SendPrcssRuleCd        = #sendPrcssRuleCd#       ,
            RecvPrcssRuleCd        = #recvPrcssRuleCd#       ,
            EAIFileSendPtrnDstcd   = #fileSendPtrnDstcd#     ,
            EAIFileRecvPtrnDstcd   = #fileRecvPtrnDstcd#     ,
            TelgmBlckSize          = #telgmBlckSize#         ,
            TelgmSernoSize         = #telgmSernoSize#        ,
            TelgmPcketSize         = #telgmPcketSize#        ,
            TranStartIndx          = #tranStartIndx#         ,
            TranEndIndx            = #tranEndIndx#           ,
            ThisMsgUseYn           = #thisMsgUseYn#          ,
            ThisMsgAmndrID         = #userid#        ,
            ThisMsgAmndHMS         = SUBSTR( DATE_FORMAT( NOW(3), '%Y%m%d%H%i%s%f'), 1, 17 )
        WHERE BjobBzwkDstcd        = #bjobBzwkDstcd#
        AND   TRIM(OsidInstiDstcd) = TRIM(#osidInstiDstcd#)
    </statement>

    <statement id="delete" resultClass="java.lang.Integer">
        DELETE  FROM $schemaId$.TSEAIBJ06
        WHERE   BjobBzwkDstcd                = #bjobBzwkDstcd#
        AND     LTRIM(RTRIM(OsidInstiDstcd)) = #osidInstiDstcd#
    </statement>

    <statement id="deleteSysconn" resultClass="java.lang.Integer">
        DELETE FROM $schemaId$.TSEAIBJ05
        WHERE  BjobBzwkDstcd                = #bjobBzwkDstcd#
        AND    LTRIM(RTRIM(OsidInstiDstcd)) = #osidInstiDstcd#
    </statement>

    <statement id="checkCount" resultClass="java.lang.Integer">
        SELECT COUNT(BjobBzwkDstcd)
        FROM   $schemaId$.TSEAIBJ06
        WHERE  BjobBzwkDstcd = #bjobBzwkDstcd#
        AND    LTRIM(RTRIM(OsidInstiDstcd))= #osidInstiDstcd#
    </statement>

    <statement id="checkSysconn" resultClass="java.lang.Integer">
        SELECT COUNT(BjobBzwkDstcd)
        FROM   $schemaId$.TSEAIBJ05
        WHERE  BjobBzwkDstcd = #bjobBzwkDstcd#
        AND    LTRIM(RTRIM(OsidInstiDstcd))= #osidInstiDstcd#
    </statement>

    <statement id="getBzwkDstcd" resultClass="java.util.HashMap">
         SELECT BJOBBZWKDSTCD,
                BJOBBZWKNAME
         FROM   $schemaId$.TSEAIBJ02
         ORDER BY BjobBzwkDstcd
    </statement>

    <statement id="getPrcssRule" resultClass="java.util.HashMap">
         SELECT BJOBBZWKPRCSSDSTCD
         FROM   $schemaId$.TSEAIBR04
         ORDER BY BjobBzwkPrcssDstcd
    </statement>

    <statement id="getAdaptorGroup" resultClass="java.util.HashMap">
         SELECT AdptrBzwkGroupName AS CODE,
                CONCAT( '[' , AdptrBzwkGroupName , ']' , AdptrBzwkGroupDesc) AS NAME
         FROM   $schemaId$.TSEAIBA01
         WHERE  AdptrUseYn = '1'
         ORDER BY AdptrBzwkGroupName
    </statement>

    <statement id="getAdaptor"  resultClass="java.util.HashMap">
        SELECT ADPTRBZWKNAME, ADPTRDESC
        FROM   $schemaId$.TSEAIBA02
        WHERE  AdptrBzwkGroupName = #adptrBzwkGroupName#
        ORDER BY AdptrBzwkName
    </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 = 'O' ) A
             LEFT JOIN
             ( SELECT PrptyName,
                      Prpty2Val
               FROM   $schemaId$.TSEAIBA06
               WHERE  PrptyGroupName = #prptyGroupName# ) B
             ON A.PrptyName = B.PrptyName
        UNION ALL
        SELECT IFNULL(A.PRPTYNAME, B.PRPTYNAME) AS PRPTYNAME,
               A.PRPTYDESC,
               B.PRPTY2VAL
        FROM ( SELECT PrptyName,
                      PrptyDesc
               FROM $schemaId$.TSEAIBP06
               WHERE  BjobBzwkDstcd = #bjobBzwkDstcd#
               AND    PrptyTypDstcd = 'O' ) A
             RIGHT JOIN
             ( SELECT PrptyName,
                      Prpty2Val
               FROM   $schemaId$.TSEAIBA06
               WHERE  PrptyGroupName = #prptyGroupName# ) B
             ON A.PrptyName = B.PrptyName
        WHERE A.PrptyName IS NULL 
        
    </statement>

    <statement id="serverlist" resultClass="java.util.HashMap">
         SELECT EAISEVRINSTNCNAME,
                EAISEVRIP,
                SEVRLSNPORTNAME,
                FLOVRSEVRNAME,
                HOSTNAME
         FROM   $schemaId$.TSEAIBP03
         ORDER BY EAISevrInstncName
    </statement>
</sqlMap>