package cn.hmsoft.jdbc.mapper;

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

import cn.hmsoft.helper.LocalDateHelper;

/**********************
 * 将每条记录放置在map中
 * 
 * @author zxq
 * @create 2019-05-06 22:32:29
 * @version 2.0.0
 * @email: revisit@126.com
 * @Company: www.hmsoft.cn
 */
public class MapMapper extends AbstractMapper<Map<String, Object>> {

	@Override
	public Map<String, Object> mapRow(ResultSet rs, int rowNum) {
		if (this.columnsIsNull())
			this.setCurrentColumns(rs);
		Map<String, Object> map = new HashMap<String, Object>();
		for (String column : this.columns) {
			try {
				Object oValue = rs.getObject(column);
				if (oValue == null)
					continue;
				// System.out.println(column + ":" + oValue.getClass().getName());
				if (oValue.getClass().getName().equals("java.sql.Date")
						|| oValue.getClass().getName().equals("java.sql.Datetime")
						|| oValue.getClass().getName().equals("java.sql.Timestamp")) {
					map.put(column.toLowerCase(),
							LocalDateHelper.format(LocalDateHelper.fromTimestamp(rs.getTimestamp(column))));

				} else
					map.put(column.toLowerCase(), oValue);
			} catch (Exception e) {
				e.printStackTrace();
			}

		}
		return map;

	}

}
