package com.eactive.eai.batch.logger;

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

public interface LogQuery
{


	/**
	 * 로그 Master 테이블에서 해당 메시지ID가 존재하는지 조회
	 */
	public static final String SELECT_EXIST_LOG_COUNT =
		  "SELECT A.LogMasterCnt, B.LogStageCnt, C.LogFileCnt \n"
		+ "FROM   ( SELECT COUNT(*) LogMasterCnt \n"
		+ "         FROM   " + Keys.TABLE_OWNER + "TSEAIBJ03 \n"
		+ "         WHERE  BjobDmndMsgID       = ? \n"
		+ "         AND    BjobDmndSubMsgID    = ? ) A, \n"
		+ "       ( SELECT COUNT(*) LogStageCnt \n"
		+ "         FROM   " + Keys.TABLE_OWNER + "TSEAIBJ04 \n"
		+ "         WHERE  BjobDmndMsgID       = ? \n"
		+ "         AND    BjobDmndSubMsgID    = ? \n"
		+ "         AND    BjobStgeID          = RPAD( ?  ,  2, ' ') \n" 
		+ "         AND    PrcssStgeDstcd      = RPAD( ?  ,  2, ' ') \n"
		+ "         AND    BjobNodeCasNo       = RPAD( ?  , 10, ' ') ) B, \n"
		+ "       ( SELECT COUNT(*) LogFileCnt \n"
		+ "         FROM   " + Keys.TABLE_OWNER + "TSEAIBJ08 \n"
		+ "         WHERE  BjobDmndMsgID       = ? \n"
		+ "         AND    BjobDmndSubMsgID    = ? \n"
		+ "         AND    SndrcvFileName      = ? ) C";

	/**
	 * 로그 Master 테이블 INSERT
	 */
	public static final String INSERT_LOG_MASTER =
		  "INSERT INTO " + Keys.TABLE_OWNER + "TSEAIBJ03 ( \n"
		+ "       BjobDmndMsgID         , BjobDmndSubMsgID   , TelgmReTralCnt        , \n"
		+ "       BjobMsgScheID         , BjobDmndMsgCretnHMS, OsidInstiDstcd        , \n"
		+ "       BjobBzwkDstcd         , BjobPtrnDstcd      , MsgSndrID             , \n"
		+ "       MsgSndrName           , SysLnkgDstcd       , LnkgIPInfoName        , \n"
		+ "       FlowRuleCd            , EAISevrInstncName  , TranStartHMS          , \n"
		+ "       TranEndHMS            , TranPrcssDstcd     , EAIObstclOccurCausCtnt, \n"
		+ "       EAIObstclPrcssCtnt    , ObstclPrcsrID      , ObstclPrcssHMS         ) \n"
		+ "VALUES ( \n"
		+ "       ?                       , ?                    , ?                    , \n"
		+ "       ?                       , ?                    , ?                    , \n"
		+ "       ?                       , ?                    , ?                    , \n"
		+ "       ?                       , ?                    , ?                    , \n"
		+ "       ?                       , ?                    , ?                    , \n"
		+ "       ?                       , ?                    , ?                    , \n"
		+ "       ' '                     , ' '                  , ' '                    )";

	/**
	 * 로그 Stage 테이블 INSERT
	 */
	public static final String INSERT_LOG_STAGE =
		  "INSERT INTO " + Keys.TABLE_OWNER + "TSEAIBJ04 ( \n"
		+ "       BjobDmndMsgID           , BjobDmndSubMsgID        , BjobStgeID              , \n"
		+ "       PrcssStgeDstcd          , BjobRuleCd              , BjobStgeCd              , \n"
		+ "       BjobStgeSerno           , BjobStgePtrnName        , BjobFlowCmpoClsName     , \n"
		+ "       TelgmDcsnID             , TelgmDcsnClsName        , TelgmDcsnMsgCd          , \n"
		+ "       ThisStgeTelgmID         , ThisStgeClsName         , ThisStgeMsgCd           , \n"
		+ "       TelgmPertypCdValCtnt    , TelgmDstcdValCtnt       , TelgmMgtCdValCtnt       , \n"
		+ "       RspnsCdValCtnt          , \n"
		+ "       BjobNodeCasNo           , BjobMsgDstcd            , OsidInstiDstcd          , \n"
		+ "       BjobBzwkDstcd           , BjobPtrnDstcd           , BjobTranDstcdName       , \n"
		+ "       RqstRecvFileStorgDirName, SndrcvFileName          , BkupSndrcvFileName      , \n"
		+ "       EAISevrInstncName       , ThisStgeStartHMS        , ThisStgeEndHMS          , \n"
		+ "       ThisStgePrcssRsultCd    , EAIObstclOccurCausCtnt  , BjobTelgmHdr            , \n"
		+ "       BjobTelgmTbody            ) \n"
		+ "VALUES ( \n"
		+ "       ?                         , ?                         , ?                         , \n"
		+ "       ?                         , ?                         , ?                         , \n"
		+ "       ?                         , ?                         , ?                         , \n"
		+ "       ?                         , ?                         , ?                         , \n"
		+ "       ?                         , ?                         , ?                         , \n"
		+ "       ?                         , \n"
		+ "       ?                         , ?                         , ?                         , \n"
		+ "       ?                         , ?                         , ?                         , \n"
		+ "       ?                         , ?                         , ?                         , \n"
		+ "       ?                         , ?                         , ?                         , \n"
		+ "       ?                         , ?                         , ?                         , \n"
		+ "       ?                         , ?                         , ?                         , \n"
		+ "       ?                          )";

	/**
	 * 로그 Stage 테이블 UPDATE
	 */
	public static final String UPDATE_LAST_LOG_STAGE =
		  "UPDATE " + Keys.TABLE_OWNER + "TSEAIBJ04 \n"
		  + "SET  BjobRuleCd               = ? , \n"
		  + "        BjobStgeCd               = ? , \n"
		  + "        BjobStgeSerno            = ? , \n"
		  + "        BjobStgePtrnName         = ? , \n"
		  + "        BjobFlowCmpoClsName      = ? , \n"
		  + "        TelgmDcsnID              = ? , \n"
		  + "        TelgmDcsnClsName         = ? , \n"
		  + "        TelgmDcsnMsgCd           = ? , \n"
		  + "        ThisStgeTelgmID          = ? , \n"
		  + "        ThisStgeClsName          = ? , \n"
		  + "        ThisStgeMsgCd            = ? , \n"
		  + "        TelgmPertypCdValCtnt     = ? , \n"
		  + "        TelgmDstcdValCtnt        = ? , \n"
		  + "        TelgmMgtCdValCtnt        = ? , \n"
		  + "        RspnsCdValCtnt           = ? , \n"
		  + "        BjobNodeCasNo            = ? , \n"
		  + "        BjobMsgDstcd             = ? , \n"
		  + "        OsidInstiDstcd           = ? , \n"
		  + "        BjobBzwkDstcd            = ? , \n"
		  + "        BjobPtrnDstcd            = ? , \n"
		  + "        BjobTranDstcdName        = ? , \n"
		  + "        RqstRecvFileStorgDirName = ? , \n"
		  + "        SndrcvFileName           = ? , \n"
		  + "        BkupSndrcvFileName       = ? , \n"
		  + "        EAISevrInstncName        = ? , \n"
		  + "        ThisStgeStartHMS         = ? , \n"
		  + "        ThisStgeEndHMS           = ? , \n"
		  + "        ThisStgePrcssRsultCd     = ? , \n"
		  + "        EAIObstclOccurCausCtnt   = ? , \n"
		  + "        BjobTelgmHdr             = ? , \n"
		  + "        BjobTelgmTbody           = ?   \n"
		  + " WHERE  BjobDmndMsgID          = ? \n"
		  + " AND    BjobDmndSubMsgID       = ? \n"
		  + " AND    BjobStgeID             = ? \n"
		  + " AND    PrcssStgeDstcd         = ? \n"
		  + " AND    BjobNodeCasNo          = ( SELECT MAX(BjobNodeCasNo ) \n"
		  + "                                       FROM " + Keys.TABLE_OWNER + "TSEAIBJ04 \n"
		  + "                                       WHERE  BjobDmndMsgID          = ? \n"
		  + "                                       AND    BjobDmndSubMsgID       = ? \n"
		  + "                                       AND    BjobStgeID             = ? \n"
		  + "                                       AND    PrcssStgeDstcd         = ? )\n";

	/**
	 * 로그 Stage 테이블 UPDATE 
	 */
	public static final String UPDATE_LOG_STAGE =
		  "UPDATE " + Keys.TABLE_OWNER + "TSEAIBJ04 \n"
		  + "SET  BjobRuleCd               = ? , \n"
		  + "        BjobStgeCd               = ? , \n"
		  + "        BjobStgeSerno            = ? , \n"
		  + "        BjobStgePtrnName         = ? , \n"
		  + "        BjobFlowCmpoClsName      = ? , \n"
		  + "        TelgmDcsnID              = ? , \n"
		  + "        TelgmDcsnClsName         = ? , \n"
		  + "        TelgmDcsnMsgCd           = ? , \n"
		  + "        ThisStgeTelgmID          = ? , \n"
		  + "        ThisStgeClsName          = ? , \n"
		  + "        ThisStgeMsgCd            = ? , \n"
		  + "        TelgmPertypCdValCtnt     = ? , \n"
		  + "        TelgmDstcdValCtnt        = ? , \n"
		  + "        TelgmMgtCdValCtnt        = ? , \n"
		  + "        RspnsCdValCtnt           = ? , \n"
		  + "        BjobMsgDstcd             = ? , \n"
		  + "        OsidInstiDstcd           = ? , \n"
		  + "        BjobBzwkDstcd            = ? , \n"
		  + "        BjobPtrnDstcd            = ? , \n"
		  + "        BjobTranDstcdName        = ? , \n"
		  + "        RqstRecvFileStorgDirName = ? , \n"
		  + "        SndrcvFileName           = ? , \n"
		  + "        BkupSndrcvFileName       = ? , \n"
		  + "        EAISevrInstncName        = ? , \n"
		  + "        ThisStgeStartHMS         = ? , \n"
		  + "        ThisStgeEndHMS           = ? , \n"
		  + "        ThisStgePrcssRsultCd     = ? , \n"
		  + "        EAIObstclOccurCausCtnt   = ? , \n"
		  + "        BjobTelgmHdr             = ? , \n"
		  + "        BjobTelgmTbody           = ?   \n"
		  + " WHERE  BjobDmndMsgID          = ? \n"
		  + " AND    BjobDmndSubMsgID       = ? \n"
		  + " AND    BjobStgeID             = ? \n"
		  + " AND    PrcssStgeDstcd         = ? \n"
		  + " AND    BjobNodeCasNo          =  ? \n";

	/**
	 * 로그 Master 테이블 UPDATE (종료시간, 거래처리구분, 장애발생원인 필드만)
	 */
	public static final String UPDATE_MASTER_LOG_FINISH =
		  "UPDATE " + Keys.TABLE_OWNER + "TSEAIBJ03 \n"
		+ "SET    TranEndHMS             = ?, \n"
		+ "       TranPrcssDstcd         = ?, \n"
		+ "       EAIObstclOccurCausCtnt = ? \n"
		+ "WHERE  BjobDmndMsgID          = ? \n"
		+ "AND    BjobDmndSubMsgID       = ?";

	/**
	 * 로그 Master 테이블 UPDATE (시작단계 이후 로그 Master의 필드가 결정되는 경우 update)
	 */
	public static final String UPDATE_MASTER_LOG_CONTINUE =
		  "UPDATE " + Keys.TABLE_OWNER + "TSEAIBJ03 \n"
	    + "SET    BjobMsgScheID       = NVL(?, BjobMsgScheID ), \n"
	    + "       OsidInstiDstcd      = NVL(?, OsidInstiDstcd), \n"
	    + "       BjobBzwkDstcd       = NVL(?, BjobBzwkDstcd ), \n"
	    + "       BjobPtrnDstcd       = NVL(?, BjobPtrnDstcd ), \n"
	    + "       MsgSndrID           = NVL(?, MsgSndrID     ), \n"
	    + "       MsgSndrName         = NVL(?, MsgSndrName   ), \n"
	    + "       SysLnkgDstcd        = NVL(?, SysLnkgDstcd  ), \n"
	    + "       FlowRuleCd          = NVL(?, FlowRuleCd    ), \n"
	    + "       TranStartHMS        = NVL(?, TranStartHMS  ), \n"
	    + "       TranPrcssDstcd      = NVL(?, TranPrcssDstcd) \n"
		+ "WHERE  BjobDmndMsgID       = ? \n"
		+ "AND    BjobDmndSubMsgID    = ?";

	/**
	 * 로그 File 테이블에서 해당 파일로그가 존재하는지 조회
	 */
	public static final String SELECT_FILE_LOG_EXIST_COUNT =
		  "SELECT COUNT(*) LogFileCnt \n"
		+ "FROM   " + Keys.TABLE_OWNER + "TSEAIBJ08 \n"
		+ "WHERE  BjobDmndMsgID          = ? \n"
		+ "AND    BjobDmndSubMsgID       = ? \n"
		+ "AND    SndrcvFileName         = ?";

	/**
	 * 로그 File 테이블 INSERT
	 */
	public static final String INSERT_LOG_FILE =
		  "INSERT INTO " + Keys.TABLE_OWNER + "TSEAIBJ08 ( \n" +
		        " BjobDmndMsgID           ,\n" +
				" BjobDmndSubMsgID        ,\n" +
				" BjobBzwkDstcd           ,\n" +
		        " OsidInstiDstcd          ,\n" +
				" BjobMsgDstcd            ,\n" +
				" BjobPtrnDstcd           ,\n" +
		        " BjobTranDstcdName       ,\n" +
				" RqstRecvFileStorgDirName,\n" +
				" SndrcvFileName          ,\n" +
		        " BkupSndrcvFileName      ,\n" +
				" SndrcvRecCnt            ,\n" +
				" SndrcvFileSize          ,\n" +
				" EAISevrInstncName       ,\n" +
		        " FileTrsmtStartHMS       ,\n" +
				" FileTrsmtEndHMS         ,\n" +
				" ThisStgePrcssRsultCd    ,\n" +
		        " EAIObstclOccurCausCtnt  ,\n" +
				" HdrInfoName             ,\n" +
				" BjobFileHdrCtnt         ,\n" +
				" BjobFileTrailCtnt       )\n"
		+ "VALUES ( ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ? )";

	/**
	 * 파일 재시도시 로그 File 테이블 UPDATE (시작시간 등...)
	 */
	public static final String UPDATE_FILE_LOG_RETRY =
		  "UPDATE " + Keys.TABLE_OWNER + "TSEAIBJ08 \n"
        + "SET    BjobMsgDstcd             = NVL(?, BjobMsgDstcd            ), \n"
		+ "       BjobTranDstcdName        = NVL(?, BjobTranDstcdName       ), \n"
		+ "       RqstRecvFileStorgDirName = NVL(?, RqstRecvFileStorgDirName), \n"
		+ "       BkupSndrcvFileName       = NVL(?, BkupSndrcvFileName      ), \n"
		+ "       SndrcvRecCnt             = NVL(?, SndrcvRecCnt            ), \n"
		+ "       SndrcvFileSize           = NVL(?, SndrcvFileSize          ), \n"
		+ "       FileTrsmtStartHMS        = NVL(?, FileTrsmtStartHMS       ), \n"
		+ "       FileTrsmtEndHMS          = NVL(?, FileTrsmtEndHMS         ), \n"
		+ "       ThisStgePrcssRsultCd     = NVL(?, ThisStgePrcssRsultCd    ), \n"
		+ "       EAIObstclOccurCausCtnt   = NVL(?, EAIObstclOccurCausCtnt  ), \n"
		+ "       HdrInfoName              = NVL(?, HdrInfoName             ), \n"
		+ "       BjobFileHdrCtnt          = NVL(?, BjobFileHdrCtnt         ), \n"
		+ "       BjobFileTrailCtnt        = NVL(?, BjobFileTrailCtnt       ) \n"        
		+ "WHERE  BjobDmndMsgID            = ? \n"
		+ "AND    BjobDmndSubMsgID         = ? \n"
		+ "AND    SndrcvFileName           = ?";

	/**
	 * 파일 종료시 로그 File 테이블 UPDATE (종료시간, 에러메시지 등...)
	 */
	public static final String UPDATE_FILE_LOG_FINISH =
		  "UPDATE " + Keys.TABLE_OWNER + "TSEAIBJ08 \n"
        + "SET    BjobMsgDstcd             = NVL(?, BjobMsgDstcd            ), \n"
		+ "       BjobTranDstcdName        = NVL(?, BjobTranDstcdName       ), \n"
		+ "       RqstRecvFileStorgDirName = NVL(?, RqstRecvFileStorgDirName), \n"
		+ "       BkupSndrcvFileName       = NVL(?, BkupSndrcvFileName      ), \n"
		+ "       SndrcvRecCnt             = NVL(?, SndrcvRecCnt            ), \n"
		+ "       SndrcvFileSize           = NVL(?, SndrcvFileSize          ), \n"
		+ "       FileTrsmtEndHMS          = NVL(?, FileTrsmtEndHMS         ), \n"
		+ "       ThisStgePrcssRsultCd     = NVL(?, ThisStgePrcssRsultCd    ), \n"
		+ "       EAIObstclOccurCausCtnt   = NVL(?, EAIObstclOccurCausCtnt  ), \n"
		+ "       HdrInfoName              = NVL(?, HdrInfoName             ), \n"
		+ "       BjobFileHdrCtnt          = NVL(?, BjobFileHdrCtnt         ), \n"
		+ "       BjobFileTrailCtnt        = NVL(?, BjobFileTrailCtnt       ) \n"
		+ "WHERE  BjobDmndMsgID            = ? \n"
		+ "AND    BjobDmndSubMsgID         = ? \n"
		+ "AND    SndrcvFileName           = ?";

	/**
	 * 당일 성공 거래된 로그를 검색 Framework + NDM + AXWAY (2011.03.23 정동한)
	 */
	public static final String SELECT_FILE_LOG_SUCCESS =
		  "SELECT BjobBzwkDstcd            AS BjobBzwkDstcd    ,\n"
		+ "       OsidInstiDstcd           AS OsidInstiDstcd   ,\n"
		+ "       BjobMsgDstcd             AS BjobMsgDstcd     ,\n"
		+ "       BjobPtrnDstcd            AS BjobPtrnDstcd    ,\n"
		+ "       BjobTranDstcdName        AS BjobTranDstcdName,\n"
		+ "       FileTrsmtStartHMS        AS FileTrsmtStartHMS,\n"
		+ "       FileTrsmtEndHMS          AS FileTrsmtEndHMS   \n"
		+ "FROM   " + Keys.TABLE_OWNER + "TSEAIBJ08                     \n"
		+ "WHERE  FileTrsmtStartHMS        >  TO_CHAR(SYSDATE,'YYYYMMDD') \n"
		+ "AND    ThisStgePrcssRsultCd     =  'T'                   \n";
//		+ "UNION                                                        \n"
//		+ "SELECT BjobBzwkDstcd            AS BjobBzwkDstcd    ,\n"
//		+ "       OsidInstiDstcd           AS OsidInstiDstcd   ,\n"
//		+ "       BjobMsgDstcd             AS BjobMsgDstcd     ,\n"
//		+ "       EAILumpPgmStusDstcd      AS BjobPtrnDstcd    ,\n"
//		+ "       \' \'                        AS BjobTranDstcdName,\n"
//		+ "       EAILumpFileTrsmtStartYMS AS FileTrsmtStartHMS,\n"
//		+ "       EAILumpFileTrsmtEndYMS   AS FileTrsmtEndHMS   \n"
//		+ "FROM   " + Keys.TABLE_OWNER + "TSEAIBU04                     \n"
//		+ "WHERE  EAILumpFileTrsmtStartYMS >  TO_CHAR(SYSDATE,'YYYYMMDD) \n"
//		+ "AND    EAILumpPgmNomalDstcd     =  'TR'                  \n"
//		+ "AND    EAILumpPgmStusDstcd      IN ( 'DR','DS' )         \n";
	
	public static final String SELECT_FILE_NAME_SEQ =
		"SELECT LTRIM(TO_CHAR(NVL(MAX(TO_NUMBER(SUBSTR(SndrcvFileName, LENGTH(SndrcvFileName)-2))+1),1),'000')) \n" +
		"FROM    " + Keys.TABLE_OWNER + "TSEAIBJ08                                               \n" +
		"WHERE  BjobBzwkDstcd   = ?                                                          \n" +
		"AND    OsidInstiDstcd  = ?                                                          \n" +
		"AND    SndrcvFileName LIKE ? || '*____' ESCAPE '*'                                  \n" +
		"AND    FileTrsmtStartHMS LIKE TO_CHAR( SYSDATE, 'YYYYMMDD' ) || '%'                 \n" +
		"AND    BjobPtrnDstcd IN ( 'AR', 'RR' )                                              \n" +
		"AND    ThisStgePrcssRsultCd = 'T'                                                   \n";
	
	public static final String SELECT_RENAMED_FILE_NAME_SEQ =
		"SELECT LTRIM(TO_CHAR(NVL(MAX(TO_NUMBER(SUBSTR(BkupSndrcvFileName, LENGTH(BkupSndrcvFileName)-2))+1),1),'000')) \n" +
		"FROM    " + Keys.TABLE_OWNER + "TSEAIBJ08                                               \n" +
		"WHERE  BjobBzwkDstcd   = ?                                                          \n" +
		"AND    OsidInstiDstcd  = ?                                                          \n" +
		"AND    BkupSndrcvFileName LIKE '%' || ? || '*____' ESCAPE '*'                       \n" +
		"AND    FileTrsmtStartHMS LIKE TO_CHAR( SYSDATE, 'YYYYMMDD' ) || '%'                 \n" +
		"AND    BjobPtrnDstcd IN ( 'AR', 'RR' )                                              \n" +
		"AND    ThisStgePrcssRsultCd = 'T'                                                   \n";
	
	public static final String SELECT_FILE_LOG_SUCCESS_COUNT =
			"SELECT  COUNT(*) LogFileCnt \n" +
			"FROM    " + Keys.TABLE_OWNER + "TSEAIBJ08                                           \n" +
			"WHERE  BjobBzwkDstcd   = ?                                                          \n" +
			"AND    OsidInstiDstcd  = ?                                                          \n" +
			"AND    BjobTranDstcdName = ?                                                        \n" +
			"AND    SndrcvFileName  = ?                                                          \n" +
			"AND    FileTrsmtStartHMS LIKE TO_CHAR( SYSDATE, 'YYYYMMDD' ) || '%'                 \n" +
			"AND    BjobPtrnDstcd IN ( 'AR', 'RR' )                                              \n" +
			"AND    ThisStgePrcssRsultCd = 'T'                                                   \n";	
}