package com.eactive.eai.batch.rule.sysInfo;

import java.sql.ResultSet;
import java.util.HashMap;

import com.eactive.eai.common.dao.BaseDAO;
import com.eactive.eai.common.dao.DAOException;
import com.eactive.eai.common.exception.ExceptionUtil;
import com.eactive.eai.common.util.Seed;

public class SysInfoDAO extends BaseDAO implements SysInfoQuery
{

    public HashMap<String, SysInfoVO> getAllSysInfos() throws DAOException
    {
    	HashMap<String, SysInfoVO> map = new HashMap<String, SysInfoVO>();
        ResultSet rs = null;
        SysInfoVO vo = null;
        try
        {
            this.connect(GET_ALL_SYSCODES);
            rs = this.executeQuery();

            while(rs.next())
            {
                vo = new SysInfoVO();

            	vo.setSysCd       ( rs.getString("sysCd").trim());
            	vo.setSysName     ( rs.getString("sysName").trim());
            	vo.setSysIp       ( rs.getString("sysIp").trim());
            	vo.setSysPort     ( rs.getShort("sysPort"));
            	vo.setUserId      ( rs.getString("userId").trim());
            	vo.setUserPassword( Seed.decrypt(rs.getString("userPassword")));
            	vo.setSendDir     ( rs.getString("sendDir").trim());
            	vo.setRecvDir     ( rs.getString("recvDir").trim());
            	vo.setSftpYn      ( rs.getString("sftpYn").trim());	
            	

                map.put(vo.getSysCd(), vo);
            }
        } catch(Exception e) {
            throw new DAOException(ExceptionUtil.getErrorCode(e,"BECEAIMFR016"));
        } finally {
            this.disconnect();
        }
        return map;
    }

    /**
     * 지정된 RuleCode와 PhaseCode에 해당 NodeInfo 리스트를 리턴한다.
     */
    public SysInfoVO getSysInfo(String sysCd ) throws DAOException
    {
        SysInfoVO vo = null;
        ResultSet   rs = null;
        try {
            this.connect(GET_SYSCODE);
            this.preparedStatement.setString(1, sysCd);
            rs = executeQuery();
            vo = new SysInfoVO();
            if (rs.next())
            {
            	vo.setSysCd       ( rs.getString("sysCd").trim());
            	vo.setSysName     ( rs.getString("sysName").trim());
            	vo.setSysIp       ( rs.getString("sysIp").trim());
            	vo.setSysPort     ( rs.getShort("sysPort"));
            	vo.setUserId      ( rs.getString("userId").trim());
            	vo.setUserPassword( Seed.decrypt(rs.getString("userPassword")));
            	vo.setSendDir     ( rs.getString("sendDir").trim());
            	vo.setRecvDir     ( rs.getString("recvDir").trim());
            	vo.setSftpYn      ( rs.getString("sftpYn").trim());	
            }
        } catch(Exception e) {
            throw new DAOException(ExceptionUtil.getErrorCode(e,"BECEAIMFR017", new String[] {sysCd, sysCd}));
        } finally {
            this.disconnect();
        }
        return vo;
    }
}
