package com.eactive.eai.rms.onl.common.dao;

import java.util.HashMap;
import java.util.List;
import java.util.Vector;

import org.apache.log4j.Logger;
import org.springframework.stereotype.Repository;

import com.eactive.eai.rms.common.base.SqlMapClientTemplateDao;
import com.eactive.eai.rms.common.util.CommonUtil;
import com.ibatis.sqlmap.client.event.RowHandler;

@Repository("itsmScheduler")
@SuppressWarnings("unchecked")
public class ItsmSchedulerDaoImpl extends SqlMapClientTemplateDao implements ItsmSchedulerDAO {

	private static final Logger logger = Logger.getLogger(ItsmSchedulerDaoImpl.class);
	
	@SuppressWarnings("deprecation")
	public Vector<String[]> getItsmErrorLogList(String owner, String logDate, 
			String errCodeList, String allBList) throws Exception {

        final HashMap<String, String> paramMap = new HashMap<String, String>();
        paramMap.put("schemaId", owner);
        paramMap.put("logTablename",  CommonUtil.getLogErrTable(logDate));
        paramMap.put("logTablename2", CommonUtil.getLogTable(logDate, true));
        paramMap.put("logDate",       logDate);
        paramMap.put("errCodeList",   errCodeList);
        paramMap.put("allBList",      allBList);
//        paramMap.put("rowno",    String.valueOf(MAX_ROWS));
        
		try {

			final Vector<String[]> vt = new Vector<String[]>();
	    	template.queryWithRowHandler("ItsmScheduler.getItsmErrorLogList", paramMap,
	    			new RowHandler(){
	                    public void handleRow(Object valueObject) {

	            			HashMap<String, String> rowMap = (HashMap<String, String>)valueObject;

	    					String[] row = new String[12];
	    					row[0] = rowMap.get("DATE");
	    					row[1] = rowMap.get("TIMER");
	    					row[2] = rowMap.get("EAIBZWKDSTCD");
	    					row[3] = rowMap.get("TARGETCODE");
	    					row[4] = rowMap.get("EAISYSCODE");
	    					row[5] = rowMap.get("EAISVCNAME");
	    					row[6] = rowMap.get("EAIERRCD");
	    					row[7] = rowMap.get("EAISVCDESC"); 
	    					row[8] = rowMap.get("INTFACSENDTRANCD"); 
	    					row[9] = rowMap.get("PGUID"); 
	    					row[10] = rowMap.get("LOGPRCSSSERNO"); 
	    					row[11] = rowMap.get("EAIERRCTNT"); 
    						
	    					vt.add(row);
	        }});
			return vt;
		} catch (Exception e) {
			logger.error("getItsmErrorLogList error", e);
			throw e;
		}
	}
	
	public List getRecvTranCdErrorLogList(HashMap param) throws Exception {
    	return template.queryForList("ItsmScheduler.getRecvTranCdErrorLogList", param);
    }
	
	public void insertErrorRecvTranCdSmsSendLog(HashMap param) throws Exception {
    	this.template.insert("ItsmScheduler.insertErrorRecvTranCdSmsSendLog", param);
    }
	
	public HashMap getRecvTranCdErrorSendSmsInfo(HashMap param) throws Exception {
		return (HashMap)template.queryForObject("ItsmScheduler.getRecvTranCdErrorSendSmsInfo", param);
    }
	
	public void insertErrorSmsSendLog(HashMap param) throws Exception {
    	this.template.insert("ItsmScheduler.insertErrorSmsSendLog", param);
    }
	
	public HashMap getErrorSmsSendYmd(HashMap param) throws Exception {
		return (HashMap)template.queryForObject("ItsmScheduler.getErrorSmsSendYmd", param);
    }
	
	
	
	
}
