package com.eactive.eai.adapter.ftp;

import java.io.File;
import java.io.FileOutputStream;
import java.io.IOException;
import java.net.Socket;
import java.util.regex.Matcher;
import java.util.regex.Pattern;

import org.apache.commons.net.ftp.FTPFile;

import com.eactive.eai.adapter.socket.config.ConfigurationContext;
import com.eactive.eai.adapter.socket.service.SocketService;
import com.eactive.eai.batch.common.CalendarUtil;
import com.eactive.eai.batch.common.LogUtil;
import com.eactive.eai.batch.common.StringUtil;
import com.eactive.eai.batch.doc.BatchDoc;
import com.eactive.eai.batch.ftp.FTPFileObject;
import com.eactive.eai.batch.ftp.FTPUtil;
import com.eactive.eai.batch.osd.OutsideManager;
import com.eactive.eai.batch.osd.OutsideVO;
import com.eactive.eai.batch.running.BatchRunningJobManager;
import com.eactive.eai.common.exception.ExceptionUtil;
import com.eactive.eai.common.property.PropManager;
import com.eactive.eai.common.util.DatetimeUtil;
import com.eactive.eai.common.util.Logger;


/**
 * 우체국 공융 ftp 전송을 위함 SFTP 
 * 
 * 파일명 : FTP00
 *
 */

public class FTP00 extends Transfer implements SocketService {

    private static final String PROP_GROUP_NAME_PREFIX = "TelegramInfo";
    
    private static final String REMOTE_PATH = "remote.path";// 원격지 경로 #YYYYMMDD#
    private static final String FILENAME_PATTERN = "filename.pattern";// 기준일자 [YYYYMMDD] 당일이전일 [YYYYMMDD-1][YYYYMMDD-2][YYYYMMDD+1]
    private static final String EXT_NAME = "ext.name";
    private static final String FTP_FILE_TYPE = "ftp.file.type";// ftp ASCII 인 경우만 default BINARY
    private static final String BASE_DATE_OVER_YN = "basedate.over.yn"; // 기준일 이후 파일전송여부
    
    /** ftp 0 , 인증 방법 1 = id, 2 = key 방식 */
    private static final String AUTH_TYPE = "sftp.auth.type";
    
    private static final String TRANS_LIB = "sftp.trans.lib";
    
	@Override
	public void sendFile(BatchDoc batchDoc) throws Exception {
		// TODO Auto-generated method stub
		if(logger.isInfoEnabled()) 
			logger.info("[FTP00] ■ 대외기관→FEP 파일 송신 시작...... ");
		firstActivity = System.currentTimeMillis();
		setLastActivity();
		BatchRunningJobManager.getInstance().addRunningJobInfo(batchDoc.getBatchMsg().getHeader().getUUID(), this, batchDoc);
		
		try {
			String ipaddress = batchDoc.getBatchMsg().getHeader().getRemoteIP();
			int    port      = Integer.parseInt(batchDoc.getBatchMsg().getHeader().getPort());
			String userid    = batchDoc.getBatchMsg().getHeader().getUserID();
			String passwd    = batchDoc.getBatchMsg().getHeader().getUserPassword();
			
			String propName = PROP_GROUP_NAME_PREFIX + "{" +
					batchDoc.getBatchMsg().getHeader().getProcessCode() +
					"_" +
					batchDoc.getBatchMsg().getHeader().getInstitutionCode() + "}";
			PropManager pmanager = PropManager.getInstance();

			String remotePath = pmanager.getProperties(propName).getProperty(REMOTE_PATH, "");
			
	        if ( !remotePath.endsWith("/") )
				remotePath = remotePath + "/";

	        String ftpgb = pmanager.getProperties(propName).getProperty(AUTH_TYPE, "1");
	        
	        
	        //baseDate 추출
			String baseDate = DatetimeUtil.getCurrentDate();
			String reqFileName = batchDoc.getBatchMsg().getHeader().getRenamedFileName();
			if (reqFileName != null && reqFileName.length() > 8) {
				String extName = pmanager.getProperties(propName).getProperty(EXT_NAME);
				if(extName != null && extName.trim().length() > 0){
					//String reqFileNameNoExt = reqFileName.replace(extName, "");
					String reqFileNameNoExt = reqFileName.substring(0, reqFileName.lastIndexOf(extName));// 20241230
					if (reqFileNameNoExt.length() >= 8 && DatetimeUtil.isRightDate(reqFileNameNoExt.substring(reqFileNameNoExt.length() - 8))) {
						baseDate = reqFileNameNoExt.substring(reqFileNameNoExt.length() - 8);
						batchDoc.getBatchMsg().getHeader().setBaseDate(baseDate);
					}
				}
			}
			
//	        remotePath = remotePath.replaceAll("#YYYYMMDD#", baseDate);
			if(remotePath.indexOf("#YYYYMMDD#") > -1){
				remotePath = remotePath.replace("#YYYYMMDD#", baseDate);
			}else if(remotePath.indexOf("#YYYYMMDD-1#") > -1) {
				baseDate = DatetimeUtil.addDays(baseDate, -1);
				remotePath = remotePath.replace("#YYYYMMDD-1#", baseDate);
			}else if(remotePath.indexOf("#YYYYMMDD-2#") > -1) {
				baseDate = DatetimeUtil.addDays(baseDate, -2);
				remotePath = remotePath.replace("#YYYYMMDD-2#", baseDate);
			}else if(remotePath.indexOf("#YYYYMMDD+1#") > -1) {
				baseDate = DatetimeUtil.addDays(baseDate, 1);
				remotePath = remotePath.replace("#YYYYMMDD+1#", baseDate);;
			}
			
			if (!remotePath.endsWith("/"))
				remotePath = remotePath + "/";
			
	        // 실제 파일이름
	        //String orgFileName = batchDoc.getBatchMsg().getHeader().getFileName();
	        // FEP 에서 Rename(송신Real->송신Arch)한 파일이름
			String sendFileName = batchDoc.getBatchMsg().getHeader().getFilePath() + "/"
					+ batchDoc.getBatchMsg().getHeader().getRenamedFileName();
			String remoteFileName = remotePath + batchDoc.getBatchMsg().getHeader().getFileName();
			
			//logger.debug( "[FTP00]sendFileName:" + orgFileName);
			
			if(logger.isDebugEnabled()) 
				logger.debug( "[FTP00]remotePath:" + remotePath);			
			
	        //File 시작시간 설정
			batchDoc.getBatchMsg().getBody().setPhaseStartTime(CalendarUtil.getCurrentTimeNoDash());
			LogUtil.setLogFileStart(batchDoc);

	        //String sendFilePath = batchDoc.getBatchMsg().getHeader().getFilePath();
			
			String connTimeoutStr = pmanager.getProperties(propName).getProperty(CONNECTION_TIMEOUT, "10");
			int connTimeout = Integer.parseInt(connTimeoutStr);
			String setTimeoutStr = pmanager.getProperties(propName).getProperty(READ_TIMEOUT, "10");
			int setTimeout =  Integer.parseInt(setTimeoutStr);			
			String bandWidthLimit = pmanager.getProperties(propName).getProperty(BADNWIDTH, "0");
			bandWidthLimit = bandWidthLimit.replace("K", "000").replace("M", "000000").replaceAll(",", "");
			int bandWidth = Integer.parseInt(bandWidthLimit);
	        	
			String transLib = pmanager.getProperties(propName).getProperty(TRANS_LIB, "JSCH");
			
	        try {
	        	if("SSH".equals(transLib)) {
	        		FTPUtil.store(ipaddress, port, userid, passwd, remoteFileName, sendFileName, true, batchDoc.getLogger(), ftpgb);
	        	}else {
		        	FTPUtil.store(batchDoc, ipaddress, port, userid,
		        			passwd, remotePath, batchDoc.getBatchMsg().getHeader().getFileName(), 
		        			sendFileName, 
		        			connTimeout, setTimeout, true, bandWidth, batchDoc.getLogger(Logger.LOGGER_ADAPTER), ftpgb);
	        	}
	        } catch (Exception e) {
	        	logger.error("[FTP00]파일송신에 실패하였습니다.", e);
	        	throw e;
	        }
	        
			//File 종료시간 설정
	        setLastActivity();
			batchDoc.getBatchMsg().getBody().setPhaseEndTime(CalendarUtil.getCurrentTimeNoDash());
			LogUtil.setLogFileEnd(batchDoc);
	        
		} catch(Exception ex) {
            String[] msgArgs = new String[1];
            msgArgs[0] = batchDoc.getBatchMsg().getHeader().getProcessCode();
            String errCode = "BECEAIFJI002";
            String errMsg = ExceptionUtil.getErrorCode (ex, errCode, msgArgs);
            batchDoc.getBatchMsg().getBody().setErrorMsg(errMsg);
            LogUtil.setErrorLog(batchDoc, ex.getMessage());
            logger.error( errMsg, ex );
            throw ex;
		} finally {
			// SFTP는 실제 disconnect는 FTPUtil-SFTPAdaptor에서 하지만, 연결해제 로그를 찍어주기 위해 호출.
			this.disconnect();
        }
		if(logger.isDebugEnabled()) 
			logger.info("[FTP00] ■ FEP → VAN사 파일 송신 완료.");
		
	}
	
	public void recvFile(BatchDoc batchDoc) throws Exception {
		if(logger.isInfoEnabled()) 
			logger.info("@@@@@@@FTP00] ■ 대외기관→FEP 파일 수신 시작...... ");
		firstActivity = System.currentTimeMillis();
		setLastActivity();
		BatchRunningJobManager.getInstance().addRunningJobInfo(batchDoc.getBatchMsg().getHeader().getUUID(), this,
				batchDoc);

		try {

			String ipaddress = batchDoc.getBatchMsg().getHeader().getRemoteIP();
			int port = Integer.parseInt(batchDoc.getBatchMsg().getHeader().getPort());
			String userid = batchDoc.getBatchMsg().getHeader().getUserID();
			String passwd = batchDoc.getBatchMsg().getHeader().getUserPassword();
			
			if(logger.isDebugEnabled()) 
				logger.debug("@@@@FTP00]userid:" + userid);
			//logger.debug("@@@@FTP00]passwd:" + passwd);

			String propName = PROP_GROUP_NAME_PREFIX + "{" + batchDoc.getBatchMsg().getHeader().getProcessCode() + "_"
					+ batchDoc.getBatchMsg().getHeader().getInstitutionCode() + "}";
			PropManager pmanager = PropManager.getInstance();
			
			String remotePath = pmanager.getProperties(propName).getProperty(REMOTE_PATH);
			if (remotePath == null) {
				throw new Exception("해당 기관에 전송 경로가 지정되어 있지 않습니다. -propName:" + propName + "," + REMOTE_PATH);
			}
			
			//SFTP방식
			String ftpgb = pmanager.getProperties(propName).getProperty(AUTH_TYPE, "1");
	        
	        
	        // FTP_FILE_TYPE
			String ftpFileType = pmanager.getProperties(propName).getProperty(FTP_FILE_TYPE, "BINARY");
	        
			if(logger.isDebugEnabled()) 
				logger.debug("[FTP00]FileName:" + batchDoc.getBatchMsg().getHeader().getFileName());
			String reqFileName = batchDoc.getBatchMsg().getHeader().getFileName();
			//baseDate 추출
			String baseDate = DatetimeUtil.getCurrentDate();
			
			String extName = "";
			String reqFileNameNoExt = reqFileName;
			try {
				extName = pmanager.getProperties(propName).getProperty(EXT_NAME);
				if(extName != null && extName.trim().length() > 0)
					reqFileNameNoExt = reqFileName.substring(0, reqFileName.lastIndexOf(extName));// 20241230
			}catch(Exception e) {
			}
			
			if (reqFileNameNoExt != null && reqFileNameNoExt.length() > 8) {
				if (reqFileNameNoExt.length() >= 8 && DatetimeUtil.isRightDate(reqFileNameNoExt.substring(reqFileNameNoExt.length() - 8))) {
					baseDate = reqFileNameNoExt.substring(reqFileNameNoExt.length() - 8);
					batchDoc.getBatchMsg().getHeader().setBaseDate(baseDate);
				}
			}
			
			//remotePath = remotePath.replaceAll("#YYYYMMDD#", baseDate);
			if(remotePath.indexOf("#YYYYMMDD#") > -1){
				remotePath = remotePath.replace("#YYYYMMDD#", baseDate);
			}else if(remotePath.indexOf("#YYYYMMDD-1#") > -1) {
				baseDate = DatetimeUtil.addDays(baseDate, -1);
				remotePath = remotePath.replace("#YYYYMMDD-1#", baseDate);
			}else if(remotePath.indexOf("#YYYYMMDD-2#") > -1) {
				baseDate = DatetimeUtil.addDays(baseDate, -2);
				remotePath = remotePath.replace("#YYYYMMDD-2#", baseDate);
			}else if(remotePath.indexOf("#YYYYMMDD+1#") > -1) {
				baseDate = DatetimeUtil.addDays(baseDate, 1);
				remotePath = remotePath.replace("#YYYYMMDD+1#", baseDate);;
			}
			if (!remotePath.endsWith("/"))
				remotePath = remotePath + "/";

			boolean isFileNameSet = false;// 파일이름이 설정되는지 여부
			try{// 파일 프로퍼티 
				String propFileName = PROP_GROUP_NAME_PREFIX + "{" + batchDoc.getBatchMsg().getHeader().getProcessCode() + "_"
						+ batchDoc.getBatchMsg().getHeader().getBizCode() + "}";
				
				String filenamePattern = pmanager.getProperties(propFileName).getProperty(FILENAME_PATTERN, "");
				if(filenamePattern != null && filenamePattern.length() > 0) {
					isFileNameSet = true;
					reqFileName = filenamePattern;
					reqFileName = reqFileName.replace("[FILENAME]", batchDoc.getBatchMsg().getHeader().getBizCode());
					
					if(reqFileName.indexOf("[YYYYMMDD]") > -1){
						reqFileName = reqFileName.replace("[YYYYMMDD]", baseDate);
					}else if(reqFileName.indexOf("[YYYYMMDD-1]") > -1) {
						String tmpbaseDate = DatetimeUtil.addDays(baseDate, -1);
						reqFileName = reqFileName.replace("[YYYYMMDD-1]", tmpbaseDate);
					}else if(reqFileName.indexOf("[YYYYMMDD-2]") > -1) {
						String tmpbaseDate = DatetimeUtil.addDays(baseDate,-2);
						reqFileName = reqFileName.replace("[YYYYMMDD-2]", tmpbaseDate);
					}else if(reqFileName.indexOf("[YYYYMMDD+1]") > -1){
						String tmpbaseDate = DatetimeUtil.addDays(baseDate, 1);
						reqFileName = reqFileName.replace("[YYYYMMDD+1]", tmpbaseDate);
					}
					
					if(reqFileName.indexOf("[YYYYMM]") > -1){
						reqFileName = reqFileName.replace("[YYYYMM]", baseDate.substring(0,6));
					}
					
					
					if(reqFileName.indexOf("[MMDD]") > -1)  {
						reqFileName = reqFileName.replace("[MMDD]", baseDate.substring(4));
					}else if(reqFileName.indexOf("[MMDD-1]") > -1) {
						String tmpbaseDate = DatetimeUtil.addDays(baseDate,-1);
						reqFileName = reqFileName.replace("[MMDD-1]", tmpbaseDate.substring(4));
					}if(reqFileName.indexOf("[MMDD-2]") > -1) {
						String tmpbaseDate  = DatetimeUtil.addDays(baseDate,-2);
						reqFileName = reqFileName.replace("[MMDD-2]", tmpbaseDate.substring(4));
					}else if(reqFileName.indexOf("[MMDD+1]") > -1) {
						String tmpbaseDate  = DatetimeUtil.addDays(baseDate, 1);
						reqFileName = reqFileName.replace("[MMDD+1]", tmpbaseDate.substring(4));
					}
					if(logger.isDebugEnabled())
						logger.debug("trans reqFileName:"+reqFileName);
				}
			}catch(Exception ex) {
				// 파일프로퍼티 설정 없음
			}
			
			String connTimeoutStr = pmanager.getProperties(propName).getProperty(CONNECTION_TIMEOUT, "30");
			int connTimeout = Integer.parseInt(connTimeoutStr);
			String setTimeoutStr = pmanager.getProperties(propName).getProperty(READ_TIMEOUT, "30");
			int setTimeout =  Integer.parseInt(setTimeoutStr);			
			String bandWidthLimit = pmanager.getProperties(propName).getProperty(BADNWIDTH, "0");
			bandWidthLimit = bandWidthLimit.replace("K", "000").replace("M", "000000").replaceAll(",", "");
			int bandWidth = Integer.parseInt(bandWidthLimit);
			
			boolean selectDate = true;
			try {
				if("Y".equals(pmanager.getProperties(propName).getProperty(BASE_DATE_OVER_YN, "N"))) {
					selectDate = false;
				}
			}catch(Exception e) {
			}
			
			FTPFileObject[] list = FTPUtil.listFilesJSCH(ipaddress, port, userid, passwd, remotePath, true, batchDoc.getLogger(),ftpgb);
			
			if(list == null) {// 파일 경로가 없는경우 20231025
				if(logger.isDebugEnabled())
					logger.debug("[FTP00]remotePath:"+remotePath +" path is none");
				return;
			}
			setLastActivity();

			String bizCode = batchDoc.getBatchMsg().getHeader().getBizCode();
			if(logger.isDebugEnabled()) 
				logger.debug("[FTP00] ■ baseDate[" + baseDate + "] bizCode[" + bizCode + "]");
			
			for (int inx = 0; inx < list.length; inx++) {
				FTPFileObject file = list[inx];
				
				if(!file.isFile())
					continue;
				
				String fileName = file.getName().trim();
				long fileSize = file.getSize();
				
				if(isFileNameSet && fileName.contains(reqFileName)){
					if(logger.isDebugEnabled()) 
						logger.debug("[FTP00]reqFileName=isFileNameSet["+isFileNameSet + "] fileName[" + fileName + "] reqFileName[" + reqFileName +"]");
					fileDownProcess(batchDoc, fileName, fileSize, ipaddress, port, userid,  passwd, remotePath, ftpgb, ftpFileType
							, connTimeout, setTimeout, bandWidth);
				}else if (!isFileNameSet && fileName.contains(bizCode)) {
					if(logger.isDebugEnabled()) 
						logger.debug("[FTP00]reqFileName=isFileNameSet["+isFileNameSet + "] fileName[" + fileName + "] bizCode[" + bizCode +"]");
					
					Matcher matcher = Pattern.compile("(20[0-9]{6})").matcher(fileName.trim());
					if (matcher.find()) {

						String value = matcher.group(1).trim();
						int iday = Integer.parseInt(value);
						int bday = Integer.parseInt(baseDate);
						if (iday >= bday && !selectDate) {  //스케줄러를 통한 파일 수신, 오늘 날짜 이상
							if(logger.isDebugEnabled()) 
								logger.debug("[FTP00]ALL OVER DATE OK-fileName[" + fileName + "]");
							fileDownProcess(batchDoc, fileName, fileSize, ipaddress, port, userid,  passwd, remotePath, ftpgb, ftpFileType
									, connTimeout, setTimeout, bandWidth);

						} else if (iday == bday && selectDate) {  //파일날짜 선택하여 파일 수신, 해당 날짜만 수신
							if(logger.isDebugEnabled()) 
								logger.debug("[FTP00]SELECT_DATE-fileName[" + fileName + "]");
							fileDownProcess(batchDoc, fileName, fileSize, ipaddress, port, userid,  passwd, remotePath, ftpgb, ftpFileType
									, connTimeout, setTimeout, bandWidth);
						}
					}else{
						if(logger.isDebugEnabled())
							logger.debug("[FTP00]No SELECT_DATE-fileName[" + fileName + "]");
						
						try {
							OutsideVO organInfo    = OutsideManager.getInstance().getOutsideInfo(batchDoc.getBatchMsg().getHeader().getProcessCode()
									, batchDoc.getBatchMsg().getHeader().getInstitutionCode());
				    		int bizCodeStartIndex      = organInfo.getBizCdStartIdx();
				    		int bizCodeEndIndex        = organInfo.getBizCdEndIdx();

				    		if (fileName.length() > bizCodeEndIndex && bizCode.equals(fileName.substring(bizCodeStartIndex, bizCodeEndIndex))){
				    			fileDownProcess(batchDoc, fileName, fileSize, ipaddress, port, userid,  passwd, remotePath, ftpgb, ftpFileType
										, connTimeout, setTimeout, bandWidth);
				    		}
						}catch(Exception e) {
							// 
						}
						
					}
				}
			}

		} catch (Exception ex) {
			String[] msgArgs = new String[1];
			msgArgs[0] = batchDoc.getBatchMsg().getHeader().getProcessCode();
			String errCode = "BECEAIFJI002";
			String errMsg = ExceptionUtil.getErrorCode(ex, errCode, msgArgs);
			batchDoc.getBatchMsg().getBody().setErrorMsg(errMsg);
			batchDoc.getBatchMsg().getBody().setPhaseEndTime(DatetimeUtil.getCurrentTimeMillis());
			LogUtil.setErrorLog(batchDoc, ex.getMessage());
			logger.error(errMsg, ex);
			throw ex;
		} finally {
			this.disconnect();
		}
		if(logger.isInfoEnabled()) 
			logger.info("[FTP00] ■ VAN사 → FEP 파일 수신 완료.");
	}

	private void fileDownProcess(BatchDoc batchDoc, String fileName, long fileSize, String ipaddress, int port, 
			String userid, String passwd, String remotePath, String sftpmode, String ftpFileType
			, int connTimeout, int setTimeout, int bandWidth) throws Exception {
		FileOutputStream fos = null;

		batchDoc.getBatchMsg().getHeader().setFileName(fileName);
		batchDoc.getBatchMsg().getHeader().setFileSize(fileSize);

		batchDoc.getBatchMsg().getHeader().setTotRecCnt(1);
		
		if(logger.isDebugEnabled()) 
			logger.debug("@@@@@@@@@batchDoc.getBatchMsg().getHeader().getJobCode()["
					+ batchDoc.getBatchMsg().getHeader().getJobCode() + "]");
		
		String recvFile = "";
		File rcvRealFile = null;
		File rcvChkFile = null;
		
		batchDoc.getBatchMsg().getBody().setPhaseStartTime(DatetimeUtil.getCurrentTimeMillis());
		LogUtil.setLogFileStart(batchDoc);
		try {
			
			if(logger.isDebugEnabled()) 
				logger.debug("@@@@@@@@" + this.getClass().getName() + ".fileName[" + fileName + "]");

			FTPUtil.retrieve(batchDoc, ipaddress, port, userid, passwd, remotePath , fileName, batchDoc.getBatchMsg().getHeader().getFilePath(),
					connTimeout, setTimeout, bandWidth, batchDoc.getLogger(Logger.LOGGER_ADAPTER), sftpmode, ftpFileType);
			
			batchDoc.getBatchMsg().getHeader().setTotRecCnt(1);
			recvFile = batchDoc.getBatchMsg().getHeader().getFilePath() + File.separator + fileName;
			rcvRealFile = new File(recvFile);
			rcvChkFile = new File(StringUtil.realToRootDir(recvFile));
		} catch (Exception e) {
			setLastActivity();
			logger.error(e.getMessage(), e);
			throw new Exception("파일수신에 실패하였습니다. -" + e.getMessage());
		} finally {
			//fos.close();
		}
		try {
			File rcvArchFile = new File(StringUtil.realToArchDir(recvFile));
			
			if(logger.isDebugEnabled()) 
				logger.debug("@@@@@@@@@rcvArchFile[" + rcvArchFile.getName() + "]");
			batchDoc.getBatchMsg().getHeader().getJobCode();

			if (rcvRealFile.exists()) {
				if(logger.isDebugEnabled()) 
					logger.debug("@@@@@@@@@rcvRealFile[" + rcvRealFile.getName() + "]");
				rcvRealFile.renameTo(rcvArchFile);
				rcvChkFile.createNewFile();
			} else {
				throw new Exception("파일수신에 실패하였습니다.");
			}

		} catch (Exception e) {
			throw e;

		}
		// File 종료시간 설정
		batchDoc.getBatchMsg().getBody().setPhaseEndTime(DatetimeUtil.getCurrentTimeMillis());
		LogUtil.setLogFileEnd(batchDoc);
	}
	
	// 정상처리 20241025
	private void fileDownEndProcess(BatchDoc batchDoc, String fileName, String errMsg) throws Exception {
		FileOutputStream fos = null;

		batchDoc.getBatchMsg().getHeader().setFileName(fileName);
		batchDoc.getBatchMsg().getHeader().setFileSize(0);

		batchDoc.getBatchMsg().getHeader().setTotRecCnt(1);
		logger.debug("@@@@@@@@@fileDownEndProcess batchDoc.getBatchMsg().getHeader().getFileName()["+ fileName + "]");
		
		batchDoc.getBatchMsg().getBody().setPhaseStartTime(DatetimeUtil.getCurrentTimeMillis());
		
		LogUtil.setLogFileStart(batchDoc);
		
		batchDoc.getBatchMsg().getHeader().setTotRecCnt(1);
		batchDoc.getBatchMsg().getHeader().getJobCode();
		batchDoc.getBatchMsg().getBody().setErrorMsg(errMsg);
		
		// File 종료시간 설정
		batchDoc.getBatchMsg().getBody().setPhaseEndTime(DatetimeUtil.getCurrentTimeMillis());
		LogUtil.setLogFileEnd(batchDoc);
	}
	
	@Override
	public void shutdown() {
		// TODO Auto-generated method stub
		
	}

	@Override
	public Socket getCurrentSocket() {
		// TODO Auto-generated method stub
		return null;
	}

	@Override
	public boolean connect() {
		// TODO Auto-generated method stub
		return false;
	}

	@Override
	public ConfigurationContext getContext() {
		// TODO Auto-generated method stub
		return null;
	}

	@Override
	public void setControl(Object control) {
		// TODO Auto-generated method stub
		
	}

	@Override
	public void notifyMessage() {
		// TODO Auto-generated method stub
		
	}

	@Override
	public boolean idle(long timeout) {
		// TODO Auto-generated method stub
		return false;
	}

	@Override
	public int getCurrentState() {
		// TODO Auto-generated method stub
		return 0;
	}

	@Override
	public boolean isConnected() throws IOException {
		// TODO Auto-generated method stub
		return false;
	}

	@Override
	public boolean isActive() {
		// TODO Auto-generated method stub
		return false;
	}

	@Override
	public void checkActivity() {
		// TODO Auto-generated method stub
		
	}

	@Override
	public String getRemoteIPAddress() {
		// TODO Auto-generated method stub
		return null;
	}

	@Override
	public void setLastActivity() {
		// TODO Auto-generated method stub
		lastActivity = System.currentTimeMillis();
	}

	@Override
	public long getFirstActivity() {
		// TODO Auto-generated method stub
		return 0;
	}

	@Override
	public long getLastActivity() {
		// TODO Auto-generated method stub
		return 0;
	}
}
