content: package me.flyray.rbac.service.impl;
  
  import java.util.List;
  import java.util.Map;
  
  import org.apache.commons.codec.digest.DigestUtils;
  import org.springframework.beans.factory.annotation.Autowired;
  import org.springframework.stereotype.Service;
  
  import me.flyray.rbac.dao.UserDao;
  import me.flyray.rbac.entity.UserEntity;
  import me.flyray.rbac.service.UserService;
  import me.flyray.rbac.utils.RRException;
  import me.flyray.rbac.validator.Assert;
  
  
  
  @Service("userService")
  public class UserServiceImpl implements UserService {
  	@Autowired
  	private UserDao userDao;
  	
  	@Override
  	public UserEntity queryObject(Long userId){
  		return userDao.queryObject(userId);
  	}
  	
  	@Override
  	public List<UserEntity> queryList(Map<String, Object> map){
  		return userDao.queryList(map);
  	}
  	
  	@Override
  	public int queryTotal(Map<String, Object> map){
  		return userDao.queryTotal(map);
  	}
  	
  	@Override
  	public void save(UserEntity user){
  		user.setPassword(DigestUtils.sha256Hex(user.getPassword()));
  		userDao.save(user);
  	}
  	
  	@Override
  	public void update(UserEntity user){
  		userDao.update(user);
  	}
  	
  	@Override
  	public void delete(Long userId){
  		userDao.delete(userId);
  	}
  	
  	@Override
  	public void deleteBatch(Long[] userIds){
  		userDao.deleteBatch(userIds);
  	}
  
  	@Override
  	public UserEntity queryByMobile(String mobile) {
  		return userDao.queryByMobile(mobile);
  	}
  
  	@Override
  	public long login(String mobile, String password) {
  		UserEntity user = queryByMobile(mobile);
  		Assert.isNull(user, "手机号或密码错误");
  
  		//密码错误
  		if(!user.getPassword().equals(DigestUtils.sha256Hex(password))){
  			throw new RRException("手机号或密码错误");
  		}
  
  		return user.getUserId();
  	}
  }
  