package com.qmth.qrzk.dao.impl;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.stereotype.Repository;
import org.springframework.transaction.annotation.Transactional;

import com.qmth.qrzk.dao.IUserDao;
import com.qmth.qrzk.repository.common.mapper.UserMapper;
import com.qmth.qrzk.repository.service.query.UserQueryParams;
import com.qmth.qrzk.repository.user.model.ImportBean;
import com.qmth.qrzk.repository.user.model.User;
import com.qmth.qrzk.security.LoginDao;

/**
 * 用户接口的实现类
 * @author 钟辉
 *
 */
@Repository("userDaoImpl")
@Transactional
public class UserDaoImpl implements IUserDao, LoginDao {

	@Autowired
	@Qualifier("userMapper")
	private UserMapper userMapper;

	public List<User> selectUser(User user) {
		if (user == null) {
			return null;
		}
		List<User> userList = userMapper.findUser(user);
		return userList;
	}

	@Override
	public void updateUser(User user) {
		userMapper.updateUser(user);
	}
	@Override
	public int updateLastLoginDate(User user) {
		return userMapper.updateLastLoginDate(user);
	}
	
	@Override
	public int updatePassword(User user) {
		return userMapper.updatePassword(user);
	}

	@Override
	public User getLoginUserByUsername(String userName) {
		if (userName == null) {
			return null;
		}
		User user = userMapper.findUserByUsername(userName);
		return user;
	}

	@Override
	public Integer deleteUser(User poUserTO)  {
		// TODO Auto-generated method stub
		return null;
	}

	@Override
	public List<User> getUsersByCourse(List<Integer> ls) {
		return userMapper.findUserByCourseIds(ls);
	}
	
	@Override
	public List<User> queryUsers(UserQueryParams params) {
		return userMapper.queryUsers(params);
	}

	@Override
	public int insertUser(User user) {
		// TODO Auto-generated method stub
		return userMapper.insertUser(user);
	}

	@Override
	public int queryUserName(String name) {
		// TODO Auto-generated method stub
		User u=new User(name);
		return userMapper.checkUserName(u);
	}

	@Override
	public int updateStatus(User user) {
		return userMapper.updateStatus(user);
	}

	@Override
	public User findUserById(int id) {
		// TODO Auto-generated method stub
		return userMapper.findUserById(id);
	}

	@Override
	public int checkPassword(User user) {
		
		return userMapper.checkPassword(user);
	}

	@Override
	public List<User> getCanSetByUsers(int courseId) {
		return userMapper.getCanSetByUsers(courseId);
	}

	@Override
	public int queryNameFromList(List<ImportBean> list) {
		// TODO Auto-generated method stub
		return userMapper.queryNameFromList(list);
	}

	@Override
	public int insertUserList(List<User> list) {
		// TODO Auto-generated method stub
		return userMapper.insertUserList(list);
	}


	@Override
	public List<User> queryName(String name) {
		// TODO Auto-generated method stub
		return userMapper.queryName(name);
	}

}
