package com.qmth.qrzk.repository.user.service.impl;

import java.util.List;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.stereotype.Service;

import com.qmth.qrzk.dao.IUserDao;
import com.qmth.qrzk.repository.service.query.UserQueryParams;
import com.qmth.qrzk.repository.user.model.User;
import com.qmth.qrzk.repository.user.service.IUserService;

@Service("userServiceImpl")
public class UserServiceImpl implements IUserService {

	private static final Logger logger = LoggerFactory.getLogger(UserServiceImpl.class);
	
	@Autowired
	@Qualifier("userDaoImpl")
	private IUserDao userDao;
	
	
	
	public User loginUser(User user) {
		try {
			List<User> ls = userDao.selectUser(user);
			if(ls.size()>0){
				return ls.get(0);
			}
		} catch (Exception e) {
			logger.error(e.getMessage(), e);
		}
		return null;
	}


	
	public int updateLastLoginDate(User user) {
		return userDao.updateLastLoginDate(user);
	}

	
	public User getUserByLoginName(String loginName) {
		try{
			User user = userDao.getLoginUserByUsername(loginName);
			return user;
		}catch (Exception e) {
			logger.error(e.getMessage(), e);
		}
		return null;
	}

	
	public void deleteUser(User userTO)
	{
		try {
			userDao.deleteUser(userTO);
		} catch (Exception e) {
			logger.error(e.getMessage(), e);
		}
	}
	
	public void updateUser(User userTO)
	{
		userDao.updateUser(userTO);
	}


	
	public int addUser(User user) {
		// TODO Auto-generated method stub
		return userDao.insertUser(user);
	}


	
	public int checkUserName(String name) {
		// TODO Auto-generated method stub
		return userDao.queryUserName(name);
	}


	
	public int updatepassword(User user) {
		return userDao.updatePassword(user);
	}


	
	public int updateisEnabled(User user) {
		// TODO Auto-generated method stub
		return userDao.updateStatus(user);
	}
	public User findById(int id) {
		// TODO Auto-generated method stub
		return userDao.findUserById(id);
	}
	public int checkPassword(User user) {
		// TODO Auto-generated method stub
		return userDao.checkPassword(user);
	}
	
	public List<User> queryUsers(UserQueryParams params) {
		return userDao.queryUsers(params);
	}


	public int queryUsersCount(UserQueryParams params) {
		return userDao.queryUsersCount(params);
	}
}
