package com.eactive.eai.batch.scheduler;

import com.eactive.eai.common.dao.Keys;

/**
* 1. 기능 : SchedulerMessageDAO에서 사용하는 SQL Query를 정의한 상수 인터페이스
* 2. 처리 개요 : SchedulerMessageDAO에서 사용하는 SQL Query를 정의한다.
* *
* 3. 주의사항
*    - JobProcessing 테이블(TSEAIBS04)의 처리구분 필드(MsgPrcssStusCd)는 다음과 같이 태그를 정의한다.
*      I(영문 대문자): JobQueue 테이블에서 JobProcessing 테이블로 처음 전달된 레코드(insert default value)
*      S: F/C로 전달된 레코드, 즉 진행중임을 나타낸다.
*      C: 사용자에 의해서 진행이 중지 요청된 레코드이다. 즉, 완전히 해당 프로세스가 중지되었는지 알 수 없다.
*      T: F/C에서 정상 종료된 레코드이다.
*      E: F/C에서 진행 중에 에러로 종료된 레코드이다.
*
* @author  :송영국
* @version : v 1.0.0
* @see : 관련 기능을 참조
* @since   : 2006.01.10
*/
public interface SchedulerMessageQueryForMariadb
{
    //1. File Event 발생시 스케쥴정보에서 해당 거래구분코드의 전체 스케쥴 정보 조회
    //order by 우선순위에 의한 맨 처음 한건을 수행할 스케쥴로 설정함
    public static String SELECT_SEND_SCHEDULE_BY_BIZCODE =
          "SELECT A.BjobMsgScheID    ,\n"
        + "       A.BjobMsgDstcd     ,\n"
        + "       B.BjobTranDstcdName,\n"
        + "       A.SndrcvStartHMS   ,\n"
        + "       A.SndrcvEndHMS     ,\n"
        + "       B.BjobBzwkDstcd    ,\n"
        + "       A.BjobPtrnDstcd    ,\n"
        + "       LTRIM(RTRIM(A.OsidInstiDstcd))   AS OsidInstiDstcd, \n"
        + "       B.MsgPrcssPrity    ,\n"
        + "       CASE WHEN (  DATE_FORMAT( NOW(), '%Y%m') >= A.SndrcvStartHMS AND \n"
        + "                   DATE_FORMAT( NOW(), '%Y%m') <  IFNULL(RTRIM(A.SndrcvEndHMS), '9999') ) THEN 1  \n"  //--스케쥴시작시간 <= 현재시간 < 스케쥴종료시간 
        + "            WHEN ( DATE_FORMAT( NOW(), '%Y%m') <  A.SndrcvStartHMS                   ) THEN 2  \n"  //--현재시간 < 스케쥴시작시간 (미래스케쥴) 
        + "                                                                                         ELSE 3  \n"  //--현재시간 > 스케쥴시작시간 (지나간스케쥴) 
        + "       END FetchPriority  ,\n"
        + "       A.HoldyPrcssDstcd  ,\n"
        + "       A.StartDlayNoday   ,\n"
        + "       A.EndDlayNoday      \n"
        + "FROM   " + Keys.TABLE_OWNER + "TSEAIBS01 A,\n"
        + "       " + Keys.TABLE_OWNER + "TSEAIBJ01 B \n"
        + "WHERE  A.BjobMsgDstcd      = B.BjobMsgDstcd \n"
        + "AND    B.BjobBzwkDstcd     = ? \n"
        + "AND    LTRIM(RTRIM(A.OsidInstiDstcd))    = ? \n"
        + "AND    B.BjobTranDstcdName = ? \n"
        + "AND    A.BjobPtrnDstcd     = 'RS'\n" 
        + "AND    A.ThisMsgUseYn      = '1' \n"
        + "AND    B.ThisMsgUseYn      = '1' \n"
        + "ORDER BY B.MsgPrcssPrity, FetchPriority, A.SndrcvStartHMS, A.SndrcvEndHMS, B.BjobTranDstcdName";

    //1-1. File Event 발생시 스케쥴정보에서 해당 거래구분코드의 전체 스케쥴 정보 조회
    //order by 우선순위에 의한 맨 처음 한건을 수행할 스케쥴로 설정함
    public static String SELECT_RECV_SCHEDULE_BY_BIZCODE =
          "SELECT A.BjobMsgScheID    , \n"
        + "       A.BjobMsgDstcd     , \n"
        + "       B.BjobTranDstcdName, \n"
        + "       A.SndrcvStartHMS   , \n"
        + "       A.SndrcvEndHMS     , \n"
        + "       B.BjobBzwkDstcd    , \n"
        + "       A.BjobPtrnDstcd    , \n"
        + "       LTRIM(RTRIM(A.OsidInstiDstcd))   AS OsidInstiDstcd, \n"
        + "       B.MsgPrcssPrity    , \n"
        + "       CASE WHEN ( DATE_FORMAT( NOW(), '%Y%m') >= A.SndrcvStartHMS AND \n"
        + "                   DATE_FORMAT( NOW(), '%Y%m') <  IFNULL(RTRIM(A.SndrcvEndHMS), '9999') ) THEN 1  \n" //--스케쥴시작시간 <= 현재시간 < 스케쥴종료시간 
        + "            WHEN ( DATE_FORMAT( NOW(), '%Y%m') <  A.SndrcvStartHMS                   ) THEN 2  \n" //--현재시간 < 스케쥴시작시간 (미래스케쥴) 
        + "                                                                                         ELSE 3  \n" //--현재시간 > 스케쥴시작시간 (지나간스케쥴) 
        + "       END FetchPriority , \n"
        + "       A.HoldyPrcssDstcd , \n"
        + "       A.StartDlayNoday  , \n"
        + "       A.EndDlayNoday      \n"
        + "FROM   " + Keys.TABLE_OWNER + "TSEAIBS01 A,\n"
        + "       " + Keys.TABLE_OWNER + "TSEAIBJ01 B \n"
        + "WHERE  A.BjobMsgDstcd      = B.BjobMsgDstcd\n"
        + "AND    B.BjobBzwkDstcd     = ?                 \n"
        + "AND    LTRIM(RTRIM(A.OsidInstiDstcd))    = ?   \n"
        + "AND    B.BjobTranDstcdName = ?                 \n"
        + "AND    A.BjobPtrnDstcd     = 'RR'              \n"
        //+ "AND    A.ThisMsgUseYn      = '1' \n"
        + "AND    B.ThisMsgUseYn      = '1' \n"
        + "ORDER BY B.MsgPrcssPrity, FetchPriority, A.SndrcvStartHMS, A.SndrcvEndHMS, B.BjobTranDstcdName";

    //2. 위 1번 쿼리에 의한 스케쥴 정보를 작업대기목록 테이블에 INSERT
    public static final String INSERT_JOB_QUEUE =
          "INSERT INTO " + Keys.TABLE_OWNER + "TSEAIBS03 ( \n"
        + "          BjobDmndMsgID , BjobDmndSubMsgID , TelgmReTralCnt   , BjobDmndMsgCretnHMS, BjobMsgScheID     , \n"
        + "          BjobBzwkDstcd , OsidInstiDstcd   , BjobPtrnDstcd    , SndrcvStartHMS     , \n"
        + "          SndrcvEndHMS  , SndrcvFileDirName, SndrcvFileName   , BkupSndrcvFileName , \n"
        + "          MsgPrcssPrity , HdrInfoName      , ThisMsgAmndrID   , ThisMsgAmndHMS ) \n"
        + "VALUES ( \n"
        + "          ?                 , ?                    , ?                    , SUBSTR( DATE_FORMAT( NOW(2), '%Y%m%d%H%i%s%f'), 1, 16 ) , ? , \n"
        + "          ?                 , ?                    , ?                    , ?                      , \n"
        + "          ?                 , ?                    , ?                    , ?                      , \n"
        + "          ?                 , ?                    , ?                    , ?                           )";

    //3. Timer Event 발생시 작업대기목록 테이블에서 수행할(현재시간에 걸리는) 전체 작업목록을 조회
    public static final String SELECT_EXECUTABLE_JOB_FROM_QUEUE =
          "SELECT A.BjobDmndMsgID      , \n"
        + "       A.BjobDmndSubMsgID   , \n"
        + "       A.TelgmReTralCnt     , \n"
        + "       A.BjobDmndMsgCretnHMS, \n"
        + "       A.BjobMsgScheID      , \n"
        + "       A.BjobBzwkDstcd      , \n"
        + "       LTRIM(RTRIM(A.OsidInstiDstcd ))  AS OsidInstiDstcd   , \n"
        + "       A.BjobPtrnDstcd      , \n"
        + "       A.SndrcvStartHMS     , \n"
        + "       A.SndrcvEndHMS       , \n"
        + "       A.SndrcvFileDirName  , \n"
        + "       A.SndrcvFileName     , \n"
        + "       A.BkupSndrcvFileName , \n"
        + "       A.MsgPrcssPrity      , \n"
        + "       A.ThisMsgAmndrID     , \n"
        + "       A.ThisMsgAmndHMS     , \n"
        + "       C.BjobMsgDstcd       , \n"
        + "       C.BjobTranDstcdName  , \n"
        + "       D.OsidInstiName      , \n"
        + "       D.TelgmBlckSize      , \n"
        + "       D.TelgmSernoSize     , \n"
        + "       D.TelgmPcketSize     , \n"
        + "       CASE A.BjobPtrnDstcd WHEN 'RS' THEN D.SendPrcssRuleCd  \n"
        + "                                WHEN 'RR' THEN D.RecvPrcssRuleCd END AS FlowRuleCode,  \n"
        + "       E.BjobBzwkName       , \n"
        + "       A.HdrInfoName        , \n"
        + "       B.HoldyPrcssDstcd    , \n"
        + "       B.StartDlayNoday     , \n"
        + "       B.EndDlayNoday       , \n"
        + "       B.RqstRecvReTralUseYn  \n"            //2009.6.16 요구송신의 경우에도 재시도여부 플래그로 사용. by kscheon
        + "FROM   " + Keys.TABLE_OWNER + "TSEAIBS03      A, \n"
        + "       " + Keys.TABLE_OWNER + "TSEAIBS01      B, \n"
        + "       " + Keys.TABLE_OWNER + "TSEAIBJ01      C, \n"
        + "       " + Keys.TABLE_OWNER + "TSEAIBJ06      D, \n"
        + "       " + Keys.TABLE_OWNER + "TSEAIBJ02      E \n"
        + "WHERE  A.BjobMsgScheID    = B.BjobMsgScheID \n"
        + "AND    B.BjobMsgDstcd     = C.BjobMsgDstcd \n"
        + "AND    A.BjobBzwkDstcd    = D.BjobBzwkDstcd \n"
        + "AND    LTRIM(RTRIM(A.OsidInstiDstcd))   = LTRIM(RTRIM(D.OsidInstiDstcd)) \n"
        + "AND    A.BjobBzwkDstcd    = E.BjobBzwkDstcd \n"
        + "AND    A.MsgPrcssPrity    > 0  \n"   //--suspend 스케쥴 제외
        + "AND    A.SndrcvStartHMS                       <= SUBSTR( DATE_FORMAT( NOW(2), '%Y%m%d%H%i%s%f'), 1, 16 ) \n"
        + "AND    IFNULL(RTRIM(A.SndrcvEndHMS), '99991231') >  SUBSTR( DATE_FORMAT( NOW(2), '%Y%m%d%H%i%s%f'), 1, 16 ) \n" //--종료시간이 없으면 종료시간 체크 안함 
        + "ORDER BY  A.BjobBzwkDstcd, A.MsgPrcssPrity, C.BjobTranDstcdName, A.SndrcvFileName, A.BjobDmndMsgCretnHMS, A.SndrcvStartHMS";

    //3. Timer Event 발생시 작업대기목록 테이블에서 수행할(현재시간에 걸리는) 전체 작업목록을 조회
    public static final String SELECT_EXECUTABLE_JOB_FROM_QUEUE_WITH_SUSPENDED_JOB =
          "SELECT A.BjobDmndMsgID      , \n"
        + "       A.BjobDmndSubMsgID   , \n"
        + "       A.TelgmReTralCnt     , \n"
        + "       A.BjobDmndMsgCretnHMS, \n"
        + "       A.BjobMsgScheID      , \n"
        + "       A.BjobBzwkDstcd      , \n"
        + "       LTRIM(RTRIM(A.OsidInstiDstcd ))  AS OsidInstiDstcd   , \n"
        + "       A.BjobPtrnDstcd      , \n"
        + "       A.SndrcvStartHMS     , \n"
        + "       A.SndrcvEndHMS       , \n"
        + "       A.SndrcvFileDirName  , \n"
        + "       A.SndrcvFileName     , \n"
        + "       A.BkupSndrcvFileName , \n"
        + "       A.MsgPrcssPrity      , \n"
        + "       A.ThisMsgAmndrID     , \n"
        + "       A.ThisMsgAmndHMS     , \n"
        + "       C.BjobMsgDstcd       , \n"
        + "       C.BjobTranDstcdName  , \n"
        + "       D.OsidInstiName      , \n"
        + "       D.TelgmBlckSize      , \n"
        + "       D.TelgmSernoSize     , \n"
        + "       D.TelgmPcketSize     , \n"
        + "       CASE A.BjobPtrnDstcd WHEN 'RS' THEN D.SendPrcssRuleCd  \n"
        + "                                WHEN 'RR' THEN D.RecvPrcssRuleCd END AS FlowRuleCode,  \n"
        + "       E.BjobBzwkName       , \n"
        + "       A.HdrInfoName        , \n"
        + "       B.HoldyPrcssDstcd    , \n"
        + "       B.StartDlayNoday     , \n"
        + "       B.EndDlayNoday       , \n"
        + "       B.RqstRecvReTralUseYn  \n"            //2009.6.16 요구송신의 경우에도 재시도여부 플래그로 사용. by kscheon
        + "FROM   " + Keys.TABLE_OWNER + "TSEAIBS03      A, \n"
        + "       " + Keys.TABLE_OWNER + "TSEAIBS01      B, \n"
        + "       " + Keys.TABLE_OWNER + "TSEAIBJ01      C, \n"
        + "       " + Keys.TABLE_OWNER + "TSEAIBJ06      D, \n"
        + "       " + Keys.TABLE_OWNER + "TSEAIBJ02      E \n"
        + "WHERE  A.BjobMsgScheID    = B.BjobMsgScheID \n"
        + "AND    B.BjobMsgDstcd     = C.BjobMsgDstcd \n"
        + "AND    A.BjobBzwkDstcd    = D.BjobBzwkDstcd \n"
        + "AND    LTRIM(RTRIM(A.OsidInstiDstcd))   = LTRIM(RTRIM(D.OsidInstiDstcd)) \n"
        + "AND    A.BjobBzwkDstcd    = E.BjobBzwkDstcd \n"
//        + "AND    A.MsgPrcssPrity    > '0'  \n"   //--suspend 스케쥴 제외
        + "AND    A.SndrcvStartHMS                       <= TO_CHAR(SYSTIMESTAMP,'YYYYMMDDHH24MISSFF3') \n"
        + "AND    IFNULL(RTRIM(A.SndrcvEndHMS), '99991231') >  TO_CHAR(SYSTIMESTAMP,'YYYYMMDDHH24MISSFF3') \n" //--종료시간이 없으면 종료시간 체크 안함 
        + "ORDER BY  A.BjobBzwkDstcd, A.MsgPrcssPrity, C.BjobTranDstcdName, A.SndrcvFileName, A.BjobDmndMsgCretnHMS, A.SndrcvStartHMS";

    
    //4. 위 3번 쿼리에 의해 조회된 작업목록을 수행하기 전에 해당 작업의 연결정보가 현재 사용중인지
    //체크하기 위해 작업진행목록 테이블에서 전체 연결정보를 조회
    public static final String SELECT_EXECUTING_SYSTEMCONNID_FROM_PROCESSING =
          "SELECT SysLnkgDstcd \n"
        + "FROM   " + Keys.TABLE_OWNER + "TSEAIBS04 \n"
        + "WHERE  MsgPrcssStusCd IN ('S','I','C')";
    
//  4-1. 위 3번 쿼리에 의해 조회된 작업목록을 수행하기 전에 해당 작업의 앞선 우선순위 작업이 수행중인지 확인하기 위한 쿼리
    //2009.8.14 by kscheon
    public static final String SELECT_EXECUTING_JOB_FROM_PROCESSING =
          "SELECT BjobBzwkDstcd, MsgPrcssPrity \n"
        + "FROM   " + Keys.TABLE_OWNER + "TSEAIBS04 \n"
        + "WHERE  BjobBzwkDstcd = ?\n"
        + "AND  MsgPrcssStusCd IN ('S','I','C') \n"
        + "ORDER BY  MsgPrcssPrity ";

    //5. 위 3번 쿼리의 결과 작업중 연결정보의 체크에 의해 걸러진 작업들을 제외한 모든 작업들을
    //작업진행목록 테이블로 이동. 이동 후 각각의 작업을 요구송수신 JPD 호출함.
    public static final String MOVE_JOB_FROM_QUEUE_TO_PROCESSING =
          "INSERT INTO " + Keys.TABLE_OWNER + "TSEAIBS04 ( \n"
        + "       BjobDmndMsgID      , BjobDmndSubMsgID, TelgmReTralCnt     , BjobDmndMsgCretnHMS, BjobMsgScheID , \n"
        + "       BjobBzwkDstcd      , OsidInstiDstcd  , SysLnkgDstcd       , BjobPtrnDstcd , \n"
        + "       SndrcvStartHMS     , SndrcvEndHMS    , SndrcvFileDirName  , SndrcvFileName, \n"
        + "       BkupSndrcvFileName , MsgPrcssPrity   , ThisMsgAmndrID     , ThisMsgAmndHMS, \n"
        + "       MsgQueEtractDmndHMS, MsgPrcssStusCd ) \n"
        + "SELECT \n"
        + "       BjobDmndMsgID      , BjobDmndSubMsgID, TelgmReTralCnt     , BjobDmndMsgCretnHMS, BjobMsgScheID , \n"
        + "       BjobBzwkDstcd      , OsidInstiDstcd , CAST ( ?  AS CHAR(12) ), BjobPtrnDstcd , \n"
        + "       SndrcvStartHMS     , SndrcvEndHMS    , SndrcvFileDirName  , SndrcvFileName, \n"
        + "       BkupSndrcvFileName , MsgPrcssPrity   , ThisMsgAmndrID     , ThisMsgAmndHMS, \n"
        + "       SUBSTR( DATE_FORMAT( NOW(2), '%Y%m%d%H%i%s%f'), 1, 16 ), 'I' \n"
        + "FROM   " + Keys.TABLE_OWNER + "TSEAIBS03 \n"
        + "WHERE  BjobDmndMsgID = ?";

    //5-1. 위 5번 쿼리를 분리 하여 큐에서 잡을 읽음.
    public static final String SELCT_JOB_FROM_QUEUE =
           "SELECT TelgmReTralCnt     ,\n" +
           "       BjobDmndMsgCretnHMS,\n" +
           "       BjobMsgScheID      ,\n" +
           "       BjobBzwkDstcd      ,\n" +
           "       LTRIM(RTRIM(OsidInstiDstcd))  AS OsidInstiDstcd ,\n" +
           "       BjobPtrnDstcd      ,\n" +
           "       SndrcvStartHMS     ,\n" +
           "       SndrcvEndHMS       ,\n" +
           "       SndrcvFileDirName  ,\n" +
           "       SndrcvFileName     ,\n" +
           "       BkupSndrcvFileName ,\n" +
           "       MsgPrcssPrity      ,\n" +
           "       ThisMsgAmndrID     ,\n" +
           "       ThisMsgAmndHMS      \n" +
           "FROM   " + Keys.TABLE_OWNER + "TSEAIBS03 \n" +
           "WHERE  BjobDmndMsgID = ? \n" +
           "  AND  BjobDmndSubMsgID = ? ";

    //5-2.  위 5번 쿼리를 분리 하여 프로세싱 테이블에 잡을 INSERT함
    //작업진행목록 테이블로 이동. 이동 후 각각의 작업을 요구송수신 JPD 호출함.
    public static final String UPDATE_PROCESSING_WITH_NEW_JOB =
          "UPDATE " + Keys.TABLE_OWNER + "TSEAIBS04\n"
            + "SET   TelgmReTralCnt      = IFNULL( ?, TelgmReTralCnt     ),\n"
            + "      BjobDmndMsgCretnHMS = IFNULL( ?, BjobDmndMsgCretnHMS),\n"
            + "      BjobMsgScheID       = IFNULL( ?, BjobMsgScheID      ),\n"
            + "      BjobBzwkDstcd       = IFNULL( ?, BjobBzwkDstcd      ),\n"
            + "      OsidInstiDstcd      = IFNULL( ?, OsidInstiDstcd     ),\n"
            + "      BjobPtrnDstcd       = IFNULL( ?, BjobPtrnDstcd      ),\n"
            + "      SndrcvStartHMS      = IFNULL( ?, SndrcvStartHMS     ),\n"
            + "      SndrcvEndHMS        = IFNULL( ?, SndrcvEndHMS       ),\n"
            + "      SndrcvFileDirName   = IFNULL( ?, SndrcvFileDirName  ),\n"
            + "      SndrcvFileName      = IFNULL( ?, SndrcvFileName     ),\n"
            + "      BkupSndrcvFileName  = IFNULL( ?, BkupSndrcvFileName ),\n"
            + "      MsgPrcssPrity       = IFNULL( ?, MsgPrcssPrity      ),\n"
            + "      ThisMsgAmndrID      = IFNULL( ?, ThisMsgAmndrID     ),\n"
            + "      ThisMsgAmndHMS      = IFNULL( ?, ThisMsgAmndHMS     ),\n"
            + "      MsgQueEtractDmndHMS = TO_CHAR(SYSTIMESTAMP,'YYYYMMDDHH24MISSFF3'),\n"
            + "      MsgPrcssStusCd      = 'I'\n"
            + "WHERE BjobDmndMsgID       = ?  \n"
            + "AND   BjobDmndSubMsgID    = ?";

    //6. 위 5번 쿼리 후 이동한 작업을 대기목록에서 DELETE
    public static final String DELETE_JOB_FROM_QUEUE =
          "DELETE FROM " + Keys.TABLE_OWNER + "TSEAIBS03 \n"
        + "WHERE  BjobDmndMsgID = ?";

    //7. 요구송수신 JPD에서 해당 작업 종료 및 오류 후 해당 작업을 Job_Processing 테이블에서 DELETE
    public static final String DELETE_JOB_FROM_PROCESSING =
          "DELETE FROM " + Keys.TABLE_OWNER + "TSEAIBS04 \n"
        + "WHERE  BjobDmndMsgID = ?";

    //9. 요구수신 Timer Event 발생시 스케쥴정보 테이블에서 현재시간에 걸리는 요구수신 스케쥴 정보 조회
    //단, 해당 스케쥴정보는 대기목록 또는 진행목록에 존재하지 않아야 함
    //Master로그 테이블에서 해당 날자의 요구수신 스케쥴ID의 파일 수신완료 건이 존재하지 말아야 함
    public static String SELECT_EXECUTABLE_RECV_SCHEDULE_LIST =
          "SELECT A.BjobMsgScheID    , \n"
        + "       A.BjobMsgDstcd     , \n"
        + "       B.BjobTranDstcdName, \n"
        + "       A.SndrcvStartHMS   , \n"
        + "       A.SndrcvEndHMS     , \n"
        + "       B.BjobBzwkDstcd    , \n"
        + "       A.BjobPtrnDstcd    , \n"
        + "       A.HoldyPrcssDstcd  , \n"
        + "       A.RpttYn           , \n"
        + "       LTRIM(RTRIM(A.OsidInstiDstcd))   AS OsidInstiDstcd , \n"
        + "       A.RqstRecvReTralUseYn    , \n"
        + "       A.RqstRecvReTralCnt      , \n"
        + "       A.RqstRecvReTralIntvalTtm, \n"
        + "       IFNULL(C.RecvFileEndCnt ,  0) RecvFileEndCnt , \n"
        + "       IFNULL(C.RecvFileFailCnt,  0) RecvFileFailCnt, \n"
        + "       IFNULL(C.RecentExecTime , '') RecentExecTime \n"        
        + "FROM   " + Keys.TABLE_OWNER + "TSEAIBJ01 B, \n"
        + "       " + Keys.TABLE_OWNER + "TSEAIBS01 A  \n"      
        + "       LEFT OUTER JOIN ( SELECT BjobMsgScheID, \n"
        + "                SUM(CASE TranPrcssDstcd WHEN 'T' THEN 1 "
        + "                                            ELSE 0 END) AS RecvFileEndCnt ,\n" //  --파일전송 완료 건수
        + "                SUM(CASE TranPrcssDstcd WHEN 'T'THEN 0 "
        + "                                            ELSE 1 END) AS RecvFileFailCnt,\n" //  --파일전송 미완료 건수 
        + "                MAX(BjobDmndMsgCretnHMS)            RecentExecTime \n"     //   --최근 수행 시간 
        + "         FROM   " + Keys.TABLE_OWNER + "TSEAIBJ03 \n"
        + "         WHERE  BjobPtrnDstcd       = 'RR'    \n"  // --요구수신만 
        + "         AND    BjobDmndMsgCretnHMS LIKE CONCAT ( DATE_FORMAT( NOW(), '%Y%m%d'), '%')  \n"
        + "         GROUP BY BjobMsgScheID ) C  "       
        + "on A.BjobMsgScheID     = C.BjobMsgScheID \n"
        + "WHERE  A.BjobMsgDstcd      = B.BjobMsgDstcd \n"
        + "AND    A.BjobPtrnDstcd     = 'RR' \n"
        + "AND    A.ThisMsgUseYn      = '1' \n"
        + "AND    B.ThisMsgUseYn      = '1' \n"
        + "AND    A.SndrcvStartHMS                   <= DATE_FORMAT( NOW(), '%H%i')   \n"
        + "AND    IFNULL(RTRIM(A.SndrcvEndHMS), '9999') >  DATE_FORMAT( NOW(), '%H%i')     \n"
        + "AND    NOT EXISTS ( SELECT X.BjobMsgScheID \n"
        + "                    FROM   " + Keys.TABLE_OWNER + "TSEAIBS03 X         \n" //--대기목록 테이블에 존재하지 않고 
        + "                    WHERE  X.BjobMsgScheID       = A.BjobMsgScheID   \n"
        + "                      AND  X.SndrcvEndHMS       >= DATE_FORMAT( NOW(), '%Y%m%d') ) \n" //--미래의 스케쥴이  
        + "AND    NOT EXISTS ( SELECT Y.BjobMsgScheID \n"
        + "                    FROM   " + Keys.TABLE_OWNER + "TSEAIBS04 Y          \n" //--진행목록 테이블에 존재하지 않고
        + "                    WHERE  Y.BjobMsgScheID       = A.BjobMsgScheID ) \n"
        + "ORDER BY A.SndrcvStartHMS, B.BjobTranDstcdName, A.SndrcvEndHMS";

    
        //10. 스케줄 아이디에 해당되는 스케줄 정보 조회(요구수신)
    public static String SELECT_SEND_SCHEDULE_BY_SCHEDULEID =
          "SELECT A.BjobMsgScheID    , \n"
        + "       A.BjobMsgDstcd     , \n"
        + "       B.BjobTranDstcdName, \n"
        + "       A.SndrcvStartHMS   , \n"
        + "       A.SndrcvEndHMS     , \n"
        + "       B.BjobBzwkDstcd    , \n"
        + "       A.BjobPtrnDstcd    , \n"
        + "       LTRIM(RTRIM(A.OsidInstiDstcd )) AS OsidInstiDstcd  ,\n"
        + "       A.RqstRecvReTralCnt   ,\n"
        + "       A.RqstRecvReTralUseYn   ,\n"
        + "       A.RqstRecvReTralIntvalTtm   \n"
        + "FROM   " + Keys.TABLE_OWNER + "TSEAIBS01       A,   \n"
        + "       " + Keys.TABLE_OWNER + "TSEAIBJ01       B    \n"
        + "WHERE  A.BjobMsgDstcd      = B.BjobMsgDstcd \n"
        + "AND    A.BjobMsgScheID     = ?                  \n"
        + "AND    A.BjobPtrnDstcd     = 'RR'               \n" //--요구수신만
        + "AND    A.ThisMsgUseYn      = '1'                \n"
        + "AND    B.ThisMsgUseYn      = '1'                \n";

    //12. 주어진 스케쥴 코드로  해당하는 스케쥴 정보를 구한다.
    public static final String SELECT_SCHEDULE_BY_CODE =
          "SELECT  B.BjobBzwkDstcd,                         \n"
        + "        C.BjobBzwkName,                          \n"
        + "        LTRIM(RTRIM(A.OsidInstiDstcd)) AS OsidInstiDstcd,          \n"
        + "        D.OsidInstiName,                         \n"
        + "        A.BjobMsgDstcd,                          \n"
        + "        A.BjobMsgScheID,                         \n"
        + "        A.BjobPtrnDstcd,                         \n"
        + "        B.BjobTranDstcdName,                     \n"
        + "        A.RqstRecvReTralCnt,                     \n"
        + "        A.SndrcvStartHMS,                        \n"
        + "        A.SndrcvEndHMS                           \n"
        + "FROM    " + Keys.TABLE_OWNER + "TSEAIBS01 A,         \n"
        + "        " + Keys.TABLE_OWNER + "TSEAIBJ01 B,         \n"
        + "        " + Keys.TABLE_OWNER + "TSEAIBJ02 C,         \n"
        + "        " + Keys.TABLE_OWNER + "TSEAIBJ06 D          \n"
        + "WHERE   A.BjobMsgDstcd = B.BjobMsgDstcd      \n"
        + "    AND B.BjobBzwkDstcd = C.BjobBzwkDstcd    \n"
        + "    AND B.BjobBzwkDstcd = D.BjobBzwkDstcd    \n"
        + "    AND LTRIM(RTRIM(A.OsidInstiDstcd)) = LTRIM(RTRIM(D.OsidInstiDstcd )) \n"
        + "    AND LTRIM(RTRIM(A.BjobMsgScheID)) = ?                      \n";
        
        
    
    
//  13. 스케줄 아이디에 해당되는 스케줄 정보 조회(요구송신)
    public static String SELECT_REQ_SEND_SCHEDULE_BY_SCHEDULEID =
          "SELECT A.BjobMsgScheID           , \n"
        + "       A.BjobMsgDstcd            , \n"
        + "       B.BjobTranDstcdName       , \n"
        + "       A.SndrcvStartHMS          , \n"
        + "       A.SndrcvEndHMS            , \n"
        + "       B.BjobBzwkDstcd           , \n"
        + "       A.BjobPtrnDstcd           , \n"
        + "       A.RqstRecvReTralUseYn     , \n"
        + "       A.RqstRecvReTralIntvalTtm , \n"
        + "       A.RqstRecvReTralCnt       , \n"
        + "       B.MsgPrcssPrity           , \n"
        + "       LTRIM(RTRIM(A.OsidInstiDstcd )) AS OsidInstiDstcd, \n"
        + "       IFNULL(C.RecvFileFailCnt,  0)      AS RecvFileFailCnt \n"
        + "FROM   " + Keys.TABLE_OWNER + "TSEAIBJ01       B, \n"
        + "       " + Keys.TABLE_OWNER + "TSEAIBS01       A \n"
        + "       LEFT OUTER JOIN ( SELECT BjobMsgScheID, \n"
        + "                SUM(CASE TranPrcssDstcd WHEN 'T'THEN 0 "
        + "                                            ELSE 1 END) AS RecvFileFailCnt\n" //--파일전송 미완료 건수 
        + "         FROM   " + Keys.TABLE_OWNER + "TSEAIBJ03 \n"
        + "         WHERE  BjobPtrnDstcd       = 'RS'   \n"  //--요구송신만
        + "         AND    BjobDmndMsgCretnHMS LIKE CONCAT( DATE_FORMAT( NOW(), '%Y%m%d'), '%' ) \n"
        + "         GROUP BY BjobMsgScheID ) C  \n"       
        + " on A.BjobMsgScheID     = C.BjobMsgScheID \n"
        + "WHERE  A.BjobMsgDstcd         = B.BjobMsgDstcd \n"
        + "AND    RTRIM(A.BjobMsgScheID) = ? \n"
        + "AND    A.BjobPtrnDstcd        = 'RS'\n" //--요구송신만 
        + "AND    A.ThisMsgUseYn         = '1' \n"
        + "AND    B.ThisMsgUseYn         = '1' \n";

    //위 5번 쿼리 후 이전 로그 테이블에서 DELETE
    public static final String DELETE_JOB_FROM_LOGMASTER =
          "DELETE FROM " + Keys.TABLE_OWNER + "TSEAIBJ03 \n"
        + "WHERE  BjobDmndMsgID = ?";
    //위 5번 쿼리 후 이전 로그 테이블에서 DELETE
    public static final String DELETE_JOB_FROM_LOGDETAIL =
          "DELETE FROM " + Keys.TABLE_OWNER + "TSEAIBJ04 \n"
        + "WHERE  BjobDmndMsgID = ?";

    /**
     * BATCH작업 메시지일정 ID를 조회하는 쿼리
     */
    public static final String GET_BJOBMSGSCHEID = 
              " SELECT CONCAT( BjobBzwkDstcd,  ? , BjobTranDstcdName ,                                                                                             "
            + "         (                                                                                                                                          "
            + "            SELECT                                                                                                                                  "
            + "                CASE LENGTH(TO_CHAR(TO_NUMBER(IFNULL(MAX(SUBSTR(RTRIM(BjobMsgScheID), LENGTH(RTRIM(BjobMsgScheID))-2, 3)), '0')) + 1))         "
            + "                    WHEN 1                                                                                                                          "
            + "                        THEN CONCAT( '00' , TO_CHAR(TO_NUMBER(IFNULL(MAX(SUBSTR(RTRIM(BjobMsgScheID), LENGTH(RTRIM(BjobMsgScheID))-2, 3)), '0')) + 1) ) "
            + "                    WHEN 2                                                                                                                          "
            + "                        THEN CONCAT( '0' , TO_CHAR(TO_NUMBER(IFNULL(MAX(SUBSTR(RTRIM(BjobMsgScheID), LENGTH(RTRIM(BjobMsgScheID))-2, 3)), '0')) + 1) )  "
            + "                    WHEN 3                                                                                                                          "
            + "                        THEN TO_CHAR(TO_NUMBER(IFNULL(MAX(SUBSTR(RTRIM(BjobMsgScheID), LENGTH(RTRIM(BjobMsgScheID))-2, 3)), '0')) + 1)         "
            + "                END                                                                                                                                 "
            + "         FROM "+Keys.TABLE_OWNER +"TSEAIBS01                                                                                                        "
            + "         WHERE BjobMsgDstcd = ?                                                                                                                 "
            + "        ) LEFTCODE                                                                                                                                  "
            + "     FROM "+Keys.TABLE_OWNER +"TSEAIBJ01                                                                                                            "
            + " WHERE BjobMsgDstcd = ?                                                                                                                         ";

    /**
     * BATCH작업 일정 정보를 등록하는 쿼리
     */
    public static final String ADD_JOB_SCH_INFO = 
              "INSERT INTO "+Keys.TABLE_OWNER +"TSEAIBS01 ( "
            + "  BjobMsgScheID                     "
            + " ,BjobMsgDstcd                      "
            + " ,BjobPtrnDstcd                     "
            + " ,OsidInstiDstcd                    "
            + " ,SndrcvStartHMS                    "
            + " ,SndrcvEndHMS                      "
            + " ,MsgSndrID                         "
            + " ,ScheFrstRegiHMS                   "
            + " ,RqstRecvReTralCnt                 "
            + " ,RqstRecvReTralUseYn               "
            + " ,RqstRecvReTralIntvalTtm           "
            + " ,RqstRecvFileStorgDirName          "
            + " ,StartDlayNoday                    "
            + " ,EndDlayNoday                      "
            + " ,HoldyPrcssDstcd                   "
            + " ,RpttYn                            "
            + " ,ThisMsgUseYn                      "
            + " ,ThisMsgScheDesc                   "
            + " ,ThisMsgRegsntID                   "
            + " ,ThisMsgRegiHMS                    "
            + " ,ThisMsgAmndrID                    "
            + " ,ThisMsgAmndHMS     )              "
            + " values (                               "
            + "  ?                                     "
            + " ,?                                     "
            + " ,?                                     "
            + " ,?                                     "
            + " ,?                                     "
            + " ,?                                     "
            + " ,?                                     "
            + " ,TO_CHAR(SYSTIMESTAMP,'YYYYMMDDHH24MISSFF3') "
            + " ,?                                     "
            + " ,?                                     "
            + " ,?                                     "
            + " ,' '                                   "
            + " ,?                                     "
            + " ,?                                     "
            + " ,?                                     "
            + " ,?                                     "
            + " ,?                                     "
            + " ,' '                                   "
            + " ,?                                     "
            + " ,TO_CHAR(SYSTIMESTAMP,'YYYYMMDDHH24MISSFF3') "
            + " ,?                                     "
            + " ,TO_CHAR(SYSTIMESTAMP,'YYYYMMDDHH24MISSFF3') "
            + " )                                       ";

    /**
     * BATCH작업 일정 정보를 등록하는 쿼리
     */
    public static final String SELECT_LOG_MASTER_BY_KEYS = 
          " SELECT A.BjobDmndMsgID         , \n"
        + "        A.BjobDmndSubMsgID      , \n"
        + "        A.TelgmReTralCnt        , \n"
        + "        A.BjobMsgScheID         , \n"
        + "        A.BjobDmndMsgCretnHMS   , \n"
        + "        A.BjobBzwkDstcd         , \n"
        + "        C.BjobBzwkName          , \n"
        + "        A.OsidInstiDstcd        , \n"
        + "        D.OsidInstiName         , \n"
        + "        A.BjobPtrnDstcd         , \n"
        + "        A.MsgSndrID             , \n"
        + "        A.MsgSndrName           , \n"
        + "        A.SysLnkgDstcd          , \n"
        + "        A.LnkgIPInfoName        , \n"
        + "        A.FlowRuleCd            , \n"
        + "        A.EAISevrInstncName     , \n"
        + "        A.TranStartHMS          , \n"
        + "        A.TranEndHMS            , \n"
        + "        A.TranPrcssDstcd        , \n"
        + "        A.EAIObstclOccurCausCtnt, \n"
        + "        A.ObstclPrcsrID         , \n"
        + "        A.ObstclPrcssHMS          \n"
        + " FROM   "+Keys.TABLE_OWNER +"TSEAIBJ03  A\n"
        + "        LEFT OUTER JOIN "+Keys.TABLE_OWNER +"TSEAIBJ02 C ON A.BjobBzwkDstcd = C.BjobBzwkDstcd \n"
        + "        LEFT OUTER JOIN "+Keys.TABLE_OWNER +"TSEAIBJ06 D ON A.BjobBzwkDstcd = D.BjobBzwkDstcd \n"
        + "                      AND A.OsidInstiDstcd = D.OsidInstiDstcd  \n"
        + " WHERE  A.BjobDmndMsgID         LIKE CONCAT( ? ,'%' ) \n"
        + "   AND  A.BjobDmndSubMsgID      LIKE CONCAT( ? ,'%' ) \n";

    public static final String SELECT_FILE_LOG_BY_KEYS =
            "SELECT RqstRecvFileStorgDirName   ,\n" +
            "       BkupSndrcvFileName         ,\n" +
            "       BjobTranDstcdName          ,\n" +
            "       HdrInfoName                 \n" +
            " FROM  "+Keys.TABLE_OWNER +"TSEAIBJ08  \n" +
            " WHERE BjobDmndMsgID    = ?        \n" +
            "   AND BjobDmndSubMsgID = ?        \n" +
            "   AND SndrcvFileName   = ?        \n";

//    public static final String SELECT_STAGE_LOGS_BY_KEYS = 
//          "SELECT B.BjobDmndMsgID           , \n"
//        + "       B.BjobDmndSubMsgID        , \n"
//        + "       B.BjobStgeID              , \n"
//        + "       B.PrcssStgeDstcd          , \n"
//        + "       B.BjobRuleCd              , \n"
//        + "       C.FlowRulePtrnDesc        , \n"
//        + "       B.BjobStgeCd              , \n"
//        + "       D.BjobStgeFlxblCndnDesc   , \n"
//        + "       B.BjobStgeSerno           , \n"
//        + "       B.BjobStgePtrnName        , \n"
//        + "       B.BjobFlowCmpoClsName     , \n"
//        + "       B.TelgmDcsnID             , \n"
//        + "       B.TelgmDcsnClsName        , \n"
//        + "       B.TelgmDcsnMsgCd          , \n"
//        + "       B.ThisStgeTelgmID         , \n"
//        + "       B.ThisStgeClsName         , \n"
//        + "       B.ThisStgeMsgCd           , \n"
//        + "       B.TelgmPertypCdValCtnt    , \n"
//        + "       B.TelgmDstcdValCtnt       , \n"
//        + "       B.TelgmMgtCdValCtnt       , \n"
//        + "       B.RspnsCdValCtnt          , \n"
//        + "       B.BjobNodeCasNo           , \n"
//        + "       B.BjobMsgDstcd            , \n"
//        + "       E.BjobMsgDsticName        , \n"
//        + "       B.BjobTranDstcdName       , \n"
//        + "       B.RqstRecvFileStorgDirName, \n"
//        + "       B.SndrcvFileName          , \n"
//        + "       B.BkupSndrcvFileName      , \n"
//        + "       B.ThisStgeStartHMS        , \n"
//        + "       B.ThisStgeEndHMS          , \n"
//        + "       B.ThisStgePrcssRsultCd    , \n"
//        + "       B.EAIObstclOccurCausCtnt    \n"
//        + " FROM  "+Keys.TABLE_OWNER +"TSEAIBJ04 B LEFT OUTER JOIN "+Keys.TABLE_OWNER +"TSEAIBR04 C ON B.BjobRuleCd = C.BjobBzwkPrcssDstcd \n"
//        + "                         LEFT OUTER JOIN "+Keys.TABLE_OWNER +"TSEAIBR02 D ON B.BjobRuleCd = D.BjobBzwkPrcssDstcd \n"
//        + "                                                          AND B.BjobStgeSerno = D.BjobStgeSerno \n"
//        + "                         LEFT OUTER JOIN "+Keys.TABLE_OWNER +"TSEAIBJ01 E ON B.BjobMsgDstcd = E.BjobMsgDstcd \n"
//        + " WHERE B.BjobDmndMsgID           LIKE CONCAT( ? ,'%' ) \n"
//        + "   AND B.BjobDmndSubMsgID        LIKE CONCAT( ? ,'%' ) \n"
//        + " ORDER BY B.BjobDmndMsgID, B.BjobDmndSubMsgID, B.ThisStgeStartHMS, B.BjobMsgDstcd";
    
    public static final String SELECT_SCHEDULE_BASIS = 
           "SELECT A.BjobMsgScheID      ,                 \n"
         + "       B.BjobBzwkDstcd      ,                 \n"
         + "       C.BjobBzwkName       ,                 \n"
         + "       A.OsidInstiDstcd     ,                 \n"
         + "       D.OsidInstiName      ,                 \n"
         + "       B.BjobTranDstcdName  ,                 \n"
         + "       A.BjobMsgDstcd       ,                 \n"
         + "       A.SendRecvYn         ,                 \n"
         + "       A.SndrcvCyclTypName  ,                 \n"
         + "       B.UapplCd            ,                 \n"
         + "       B.ThisMsgChrgIDs     ,                 \n"
         + "       A.SndrcvStartHMS     ,                 \n"
         + "       A.SndrcvEndHMS                         \n"
         + "FROM   "+Keys.TABLE_OWNER +"TSEAIBS05 A,          \n" 
         + "       "+Keys.TABLE_OWNER +"TSEAIBJ01 B,          \n" 
         + "       "+Keys.TABLE_OWNER +"TSEAIBJ02 C,          \n" 
         + "       "+Keys.TABLE_OWNER +"TSEAIBJ06 D           \n" 
         + "WHERE  A.BjobMsgDstcd   = B.BjobMsgDstcd  \n"
         + "AND    B.BjobBzwkDstcd  = C.BjobBzwkDstcd \n"
         + "AND    B.BjobBzwkDstcd  = D.BjobBzwkDstcd \n"
         + "AND    A.OsidInstiDstcd = D.OsidInstiDstcd\n"
         + "AND    A.EAIWarnYn      = '1'                 \n"
         + "AND    A.ThisMsgUseYn   = '1'                 \n"
         + "AND    A.SndrcvEndHMS   < DATE_FORMAT( NOW(), '%H%i%s') \n";

    public static final String DELETE_ALL_JOBS_FROM_PROCESSING =
        "DELETE FROM " + Keys.TABLE_OWNER + "TSEAIBS04";

    public static final String SELECT_ALL_JOBS_FROM_PROCESSING =
    	  "SELECT BjobDmndMsgID      ,\n"
    	+ "       BjobDmndSubMsgID   ,\n"
    	+ "       TelgmReTralCnt     ,\n"
    	+ "       SysLnkgDstcd       ,\n"
    	+ "       BjobDmndMsgCretnHMS,\n"
    	+ "       BjobMsgScheID      ,\n"
    	+ "       BjobBzwkDstcd      ,\n"
    	+ "       OsidInstiDstcd     ,\n"
    	+ "       BjobPtrnDstcd      ,\n"
    	+ "       SndrcvStartHMS     ,\n"
    	+ "       SndrcvEndHMS       ,\n"
    	+ "       SndrcvFileDirName  ,\n"
    	+ "       SndrcvFileName     ,\n"
    	+ "       BkupSndrcvFileName ,\n"
    	+ "       MsgPrcssPrity      ,\n"
    	+ "       ThisMsgAmndrID     ,\n"
    	+ "       ThisMsgAmndHMS     ,\n"
    	+ "       MsgQueEtractDmndHMS,\n"
    	+ "       MsgPrcssStusCd      \n"
        + "FROM " + Keys.TABLE_OWNER + "TSEAIBS04";

}