package com.ifish.daoImpl;

import java.math.BigInteger;

import org.springframework.stereotype.Repository;

import com.ifish.dao.CouponRecordDao;
import com.ifish.entity.CouponRecord;
import com.ifish.hibernate.HibernateBaseDao;

/**
 * 优惠价兑换记录
 * @author Administrator
 *
 */
@Repository
public class CouponRecordDaoImpl extends HibernateBaseDao<CouponRecord, Integer> implements CouponRecordDao {

	@Override
	protected Class<CouponRecord> getEntityClass() {
		return CouponRecord.class;
	}

	@Override
	public int getCouponRecordCountByCouponId(Integer couponId) {
		String sql = "select count(*) from tbl_coupon_record where coupon_id=?";
		return ((BigInteger)getSession().createSQLQuery(sql).setInteger(0, couponId).uniqueResult()).intValue();
	}

	@Override
	public int getCouponRecordCountByUser(Integer userId, Integer couponId) {
		String sql = "select count(*) from tbl_coupon_record where user_id=? and coupon_id=?";
		return ((BigInteger)getSession().createSQLQuery(sql).setInteger(0, userId).setInteger(1, couponId).uniqueResult()).intValue();
	}
	
	
}
