package com.chinacreator.process.dao;

import java.sql.SQLException;
import java.util.Date;

import org.springframework.stereotype.Component;

import com.chinacreator.process.exception.ServiceException;
import com.chinacreator.process.util.DataSource;
import com.frameworkset.common.poolman.PreparedDBUtil;

@Component
public class SysDao {
	
	/**
	 * 获取当前时间
	 * @return
	 */
	public Date getSysdate() {
		String sql = "select sysdate from dual";
		PreparedDBUtil pdb = new PreparedDBUtil();
		try {
			pdb.preparedSelect(DataSource.NET3G, sql);
			pdb.executePrepared();
			return pdb.getDate(0, 0);
		} catch (SQLException e) {
			throw new ServiceException("获取系统时间失败", e);
		}
	}
	
	/**
	 * 获取月末
	 * @return
	 */
	public String getLastDay() {
		String sql = "select to_char(last_day(trunc(sysdate)),'yyyymmdd') from dual";
		PreparedDBUtil pdb = new PreparedDBUtil();
		try {
			pdb.preparedSelect(DataSource.NET3G, sql);
			pdb.executePrepared();
			return pdb.getString(0, 0);
		} catch (SQLException e) {
			throw new ServiceException("获取系统时间失败", e);
		}
	}
	
	public String getID() {
		String sql = "select to_char(sysdate,'yyyyMMddhh24miss')||SEQ_COMMON6.nextval from dual";
		PreparedDBUtil pdb = new PreparedDBUtil();
		try {
			pdb.preparedSelect(DataSource.NET3G, sql);
			pdb.executePrepared();
			return pdb.getString(0, 0);
		} catch (SQLException e) {
			throw new ServiceException("获取序号失败", e);
		}
	}
}
