package com.tarena.oss.account.dao;

import java.util.Collection;

import org.springframework.orm.hibernate3.support.HibernateDaoSupport;

import com.tarena.oss.account.pojo.Detaildays;
import com.tarena.oss.account.pojo.Detailmonths;
import com.tarena.oss.account.pojo.Detailyears;

public class AccoutMgmtDAOByHibernate extends HibernateDaoSupport implements
		AccountMgmtDAO {
	
	public Collection<Detaildays> queryAccountByDate(String cond,String year,String month) {
		String firstday=year+"-"+month+"-"+"1";
		String nextday=year+"-"+month+"-"+"31";
		return this.getHibernateTemplate().find(" from Detaildays dd where dd.labIp='"+cond+"'"+" and dd.longTime > '"+firstday+"'"+" and dd.longTime < '"+nextday+"'");
	}

	public Collection<Detailmonths> queryAccountByMonth() {
		
		return this.getHibernateTemplate().find(" from Detailmonths dm where 1=1");
	}
	public Collection<Detailmonths> queryAccountByMonth(String cond,String year) {
		Integer nextyear=Integer.valueOf(year)+1;
//		System.out.println(" from Detailmonths dm where dm.labIp='"+cond+"'"+" and dm.longTime > '"+year+"'"+" and dm.longTime < '"+nextyear+"'");
		return this.getHibernateTemplate().find(" from Detailmonths dm where dm.labIp='"+cond+"'"+" and dm.longTime > '"+year+"'"+" and dm.longTime < '"+nextyear+"'");
	
	}
	
	public Collection<Detailmonths> queryAccountByMonthfor(String year, String month) {
		String firstday=year+"-"+month+"-"+"1";
		String nextday=year+"-"+month+"-"+"31";
		return this.getHibernateTemplate().find(" from Detailmonths dm where dm.longTime > '"+firstday+"'"+" and dm.longTime < '"+nextday+"'");
	}

	
	public Collection<Detailyears> queryAccountByYear() {
		return this.getHibernateTemplate().find(" from Detailyears dy where 1=1");
	}
	
public Collection<Detailyears> queryAccountByYear(String year) {
	Integer nextyear=Integer.valueOf(year)+1;
	return this.getHibernateTemplate().find(" from Detailyears dy where dy.longTime >'"+year+"'"+" and dy.longTime < '"+nextyear+"'");
	}

	public int queryDateCnt() {
		Long value= (Long) this.getHibernateTemplate().find(" select count(*) from Detaildays dd where 1=1 ").get(0);
		return value.intValue();
	}

	public int queryDateCnt(String cond) {
		Long value= (Long) this.getHibernateTemplate().find(" select count(*) from Detaildays dd where 1=1 "+cond).get(0);
		return value.intValue();
	}

	public int queryMonthCnt() {
		Long value= (Long) this.getHibernateTemplate().find(" select count(*) from Detailmonths dm where 1=1 ").get(0);
		return value.intValue();
	}

	public int queryMonthCnt(String cond) {
		Long value= (Long) this.getHibernateTemplate().find(" select count(*) from Detailmonths dm where 1=1 "+cond).get(0);
		return value.intValue();
	}

	public int queryYearCnt() {
		Long value= (Long) this.getHibernateTemplate().find(" select count(*) from Detailyears dy where 1=1 ").get(0);
		return value.intValue();
	}

	public int queryYearCnt(String cond) {
		Long value= (Long) this.getHibernateTemplate().find(" select count(*) from Detailyears dy where 1=1 "+cond).get(0);
		return value.intValue();
	}

	
	

	

	

}
