@Override
 public boolean verifyAccountRep(String account) {
   int n = userDao.countByAccount(account);
   if (n != 0) {
     return true;
   }
   return false;
 }
  @Override
  public void editUserBasic(
      Long userId,
      String nickName,
      String userName,
      Integer sex,
      int birthdayYear,
      int birthdayMonth,
      int birthdayDay,
      String summary,
      String qqId,
      String wangwangId) {
    // 数据不能为空
    if (userId <= 0 || nickName.trim().equals("") || userName.trim().equals("")) {
      throw new IllegalArgumentException();
    }
    // 验证昵称格式
    if (!StringUtil.match(nickName, "^.{1,12}$")) {
      throw new ServiceException(ErrService.UserS.ACC_106, "昵称:“" + nickName + "”格式错误。");
    }
    // 验证生日格式
    Calendar calendar = Calendar.getInstance();
    try {
      calendar.set(birthdayYear, birthdayMonth - 1, birthdayDay);
    } catch (Exception e) {
      throw new ServiceException(
          ErrService.UserS.ACC_104,
          "生日:“" + birthdayYear + "年" + birthdayMonth + "月" + birthdayDay + "日”,格式错误。",
          e);
    }
    // 验证昵称
    User user = userDao.queryById(userId);
    if (!user.getNickName().equals(nickName)) {
      if (this.verifyNickRep(nickName)) {
        throw new ServiceException(ErrService.UserS.ACC_102, "昵称:“" + nickName + "”已经被使用。");
      }
    }

    JSONObject eaddress = new JSONObject();
    if (!StringUtil.isEmptyOrNull(qqId)) {
      eaddress.put("qqId", qqId);
    }
    if (!StringUtil.isEmptyOrNull(wangwangId)) {
      eaddress.put("wangwangId", wangwangId);
    }

    userDao.update(
        userId,
        nickName,
        userName,
        sex,
        birthdayYear,
        birthdayMonth,
        birthdayDay,
        eaddress.toString(),
        summary);
  }
 @Override
 public User checkLogin(String account, String password) {
   password = PasswordMD.md5(password);
   User u = userDao.queryByAccount(account);
   if (u == null) {
     u = userDao.queryByEnEmail(account);
   }
   if (u != null && password.equals(u.getPassword())) {
     return u;
   } else {
     throw new ServiceException(ErrService.UserS.ACC_109, "用户账号或者密码错误");
   }
 }
 @Override
 public void editUserEmail(Long userId, String email) {
   if (email == null || email.equals("")) {
     throw new ServiceException(ErrService.UserS.ACC_102, "电子邮箱格式错误。");
   }
   User u = userDao.queryByEnEmail(email);
   if (u != null) {
     throw new ServiceException(ErrService.UserS.ACC_102, "该电子邮箱已经被激活。");
   }
   User user = userDao.queryById(userId);
   if (!email.equals(user.getEmail())) {
     userDao.updateEmail(userId, email);
   }
 }
  @Override
  public String getRongToken(long userId, boolean isNew, String resAccountUri) {
    User user = this.getUserById(userId);
    if (user == null) {
      return null;
    }
    if (user.getRongToken() != null && !isNew) {
      return user.getRongToken();
    }

    String imgUrl = user.getPhotoPath();
    if (imgUrl != null && !imgUrl.startsWith("http://")) {
      imgUrl = resAccountUri + imgUrl;
    }

    UserToken ut = null;
    try {
      String appKey = "0vnjpoadnxp5z";
      String appSecret = "3UH04WirdR69D";
      ApiRongIM.init(appKey, appSecret);
      ut = ApiRongIM.getToken(user.getUserId() + "", user.getNickName(), imgUrl);
      user.setRongToken(ut.getToken());
    } catch (Exception e) {
      logger.error("userId=" + user.getUserId(), e);
    }
    // 修改数据库
    userDao.updateRongToken(userId, user.getRongToken());

    return user.getRongToken();
  }
 private User addUser(User user) {
   userDao.insert(user);
   // UserStatistics userSta = new UserStatistics();
   // userSta.setUserId(user.getUserId());
   // userStatisticsDao.insert(userSta);
   return user;
 }
  @Override
  public void editUserPasswore(Long userId, String oldPsw, String newPsw) {
    // 验证密码格式
    if (!StringUtil.match(newPsw, "^.{6,20}$")) {
      throw new ServiceException(ErrService.UserS.ACC_107, "密码:“" + newPsw + "”格式错误。");
    }

    // 密码MD5加密
    oldPsw = PasswordMD.md5(oldPsw);
    User user = userDao.queryById(userId);
    if (!user.getPassword().equals(oldPsw)) {
      throw new ServiceException(ErrService.UserS.ACC_103, "用户:“" + userId + "”原始密码错误。");
    }

    newPsw = PasswordMD.md5(newPsw);
    userDao.updatePsw(userId, newPsw);
  }
 @Override
 public boolean verifyNickRep(String nick) {
   int n = userDao.countByNick(nick);
   if (n != 0) {
     return true;
   }
   return false;
 }
  private User register(String nickName, String photoPath) {
    if (StringUtil.isEmptyOrNull(nickName)) {
      throw new IllegalArgumentException();
    }

    long userId = userDao.getId();
    User user = new User();
    user.setPhotoPath(photoPath);
    user.setNickName(nickName + userId);
    user.setAddTime(new Date());
    user.setUserId(userId);
    return this.addUser(user);
  }
 @Override
 public PageInfo<User> getUserList(String nickName, int currPage, int pageSize) {
   return userDao.queryListByKeyword(nickName, currPage, pageSize);
 }
 @Override
 public void editUserPhoto(Long userId, String photoPath) {
   userDao.updatePhoto(userId, photoPath);
 }
 @Override
 public User getUserById(Long userId) {
   return userDao.queryById(userId);
 }
 @Override
 public User getUserByAccount(String account) {
   return userDao.queryByAccount(account);
 }