package com.seeyon.apps.src_automatic.dao;

import java.sql.SQLException;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;

import org.apache.commons.collections.map.HashedMap;

import com.seeyon.ctp.common.exceptions.BusinessException;
import com.seeyon.ctp.util.JDBCAgent;

public class AutomaticDaoImpl implements IAutomaticDao {

	@Override
	public List<Map<String,Object>> getAutomaticTime() throws SQLException, BusinessException {
		List<Map<String,Object>> lists = new ArrayList<Map<String,Object>>();
		JDBCAgent agent = new JDBCAgent();
		try {
			StringBuilder sql = new StringBuilder(getAutomaticTime);
//			StringBuilder sql = new StringBuilder("SELECT id FROM formmain_0536 WHERE field0013 = ? ");
			List<Object> p = new ArrayList<Object>();
			agent.execute(sql.toString(), p);
			List<Map> list = agent.resultSetToList();
			if (list != null && list.size() > 0) {
				Map map = list.get(0);
				Object time = map.get("field0001");
				Object timingHour = map.get("field0002");
				Object timingMinute = map.get("field0003");
				Object intervalHour = map.get("field0004");
				Object intervalMinute = map.get("field0005");
				Map<String,Object> timeMap = new HashedMap();
				timeMap.put("time", time);
				timeMap.put("timingHour", timingHour);
				timeMap.put("timingMinute", timingMinute);
				timeMap.put("intervalHour", intervalHour);
				timeMap.put("intervalMinute", intervalMinute);
				lists.add(timeMap);
			}
		}finally {
			if (agent != null) {
				agent.close();
			}
		}
		return lists;
		
	}
	
	
//	private String getAutomaticTime = "SELECT field0001,field0002,field0003,field0004,field0005 FROM formmain_0185 ";
	
	private String getAutomaticTime = "SELECT field0001,field0002,field0003,field0004,field0005 FROM formmain_3048 ";

}
