package com.ifish.daoImpl;

import java.math.BigInteger;
import java.util.List;

import org.springframework.stereotype.Repository;

import com.ifish.dao.DeviceUserDao;
import com.ifish.entity.DeviceUser;
import com.ifish.entity.DeviceUserId;
import com.ifish.hibernate.HibernateBaseDao;

/** 
 * @ClassName: DeviceUserDaoImpl
 * @Description: TODO 
 * @author ggw 
 *  
 */

@Repository
public class DeviceUserDaoImpl extends HibernateBaseDao<DeviceUser, DeviceUserId> implements DeviceUserDao {

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

	@Override
	public void removeAll(List<DeviceUser> list) {
		for (DeviceUser deviceUser:list) {
			delete(deviceUser);
		}
	}

	/**
	 * 查询用户的设备数量
	 * @param userId
	 * @return
	 */
	@Override
	public int getDeviceNumById(Integer userId) {
		String sql = "select count(*) from tbl_device_user where user_id=?";
		int deviceNum = ((BigInteger)this.getSession().createSQLQuery(sql).setInteger(0, userId).uniqueResult()).intValue();
		return deviceNum;
	}
	
}
