package com.eactive.eai.rms.onl.statistics.trand.dao;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;

import org.springframework.dao.DataAccessException;
import org.springframework.stereotype.Repository;

import com.eactive.eai.rms.common.base.SqlMapClientTemplateDao;
import com.eactive.eai.rms.onl.statistics.eaisvcname.vo.StatisticsForm;
import com.eactive.eai.rms.onl.statistics.trand.vo.TrandBean;
import com.eactive.eai.rms.onl.statistics.trand.vo.TransitionVO;
import com.ibatis.sqlmap.client.event.RowHandler;

/**
 * <pre>
 * 1. 기능 : 
 * 2. 처리 개요 : 
 *     - 
 * 3. 주의사항 : 
 * </pre>
 * @author  : music75
 * @version : $Revision: 1.1 $
 * @since : rts 1.0
 * @spring.bean id="transitionDAO"
 * @spring.property name="dataSource" ref="dataSource"
 */
@Repository("transitionDAO")
public class TransitionDAOImpl
        extends SqlMapClientTemplateDao //BaseJdbcDaoSupport, 
        implements TransitionDAO {

    public List findByTransition(StatisticsForm statisticsForm) {
    	int currentPage = statisticsForm.getPageNum();
    	int pageSize = 50;
    	
		if (currentPage == 0) {
			currentPage = 1;
		}
		if (pageSize == 0) {
			pageSize = 30;
		}
		
		int firstRow = pageSize * (currentPage - 1) + 1;
		int lastRow = firstRow + pageSize - 1;

		final HashMap<String, String> paramMap = new HashMap<String,String>();
		paramMap.put("firstRow", String.valueOf(firstRow));
		paramMap.put("lastRow", String.valueOf(lastRow));
		
        final ArrayList<TransitionVO> al = new ArrayList<TransitionVO>();

        template.queryWithRowHandler("Transition.findByTransition", paramMap,
    			new RowHandler(){
            		@SuppressWarnings("unchecked")
                    public void handleRow(Object valueObject) {
            			TransitionVO vo = (TransitionVO)valueObject;
                        al.add(vo);
        }});
        return al;
    }
    
    public List findTrandArray(String searchField, String searchText)
            throws DataAccessException {
		final HashMap<String, String> paramMap = new HashMap<String,String>();
		paramMap.put("searchField", searchField);
		paramMap.put("searchText",  searchText);

        final ArrayList<TrandBean> al = new ArrayList<TrandBean>();

        template.queryWithRowHandler("Transition.findTrandArray", paramMap,
    			new RowHandler(){
            		@SuppressWarnings("unchecked")
                    public void handleRow(Object valueObject) {
            			TrandBean vo = (TrandBean)valueObject;
                        al.add(vo);
        }});
        return al;
    }
}
