Ejemplo n.º 1
0
 @Override
 public UserResult getUserByName(String loginname) {
   UserResult ur = new UserResult();
   try {
     if (!StringUtils.isBlank(loginname)) {
       User user = userService.findByLoginName(loginname);
       if (user != null) {
         if (user.getUsertype() == 2) {
           BusinessUserDetail businessUserdetail =
               businessUserDetailService.findByUserId(user.getId());
           BusinessUserEntity businessUserVO =
               ConvertHelper.toBusinessUserEntity(user, businessUserdetail);
           ur.setBusinessUser(businessUserVO);
         } else {
           UserDetail userdetail = userDetailService.findByUserId(user.getId());
           UserEntity userVO = ConvertHelper.toUserEntity(user, userdetail);
           ur.setUser(userVO);
         }
       }
     }
     ur.setErrorCode(0);
     ur.setErrorMessage("");
   } catch (Exception ex) {
     ValidationError ve = ValidationError.SYSTEM_ERROR;
     ur.setErrorCode(ve.getErrorCode());
     ur.setErrorMessage("系统错误");
     logger.error(ex.getMessage());
   }
   return ur;
 }
Ejemplo n.º 2
0
 @Override
 public UserResult getUserAndRemark(RemarkQueryCondition condition) {
   UserResult ur = new UserResult();
   try {
     User user = null;
     if (condition != null && condition.getFriendId() != null && condition.getFriendId() > 0) {
       Integer friendId = condition.getFriendId();
       user = userService.findById(friendId);
     }
     if (condition != null && !StringUtils.isBlank(condition.getFriendLoginName())) {
       String loginname = condition.getFriendLoginName();
       user = userService.findByLoginName(loginname);
     }
     if (user != null) {
       UserDetail userdetail = userDetailService.findByUserId(user.getId());
       UserEntity userVO = ConvertHelper.toUserEntity(user, userdetail);
       Integer friendId = 0;
       if (condition != null && condition.getFriendId() != null && condition.getFriendId() > 0) {
         friendId = condition.getFriendId();
       } else {
         friendId = user.getId();
       }
       Integer userId = 0;
       if (condition != null
           && condition.getUserName() != null
               & (condition.getUserId() == null || condition.getUserId() == 0)) {
         User userself = userService.findByLoginName(condition.getUserName());
         if (userself != null) {
           userId = userself.getId();
         }
       } else {
         userId = condition.getUserId();
       }
       if (userId > 0 && friendId > 0) {
         List<UserRemark> userRemarks =
             userRemarkService.find(
                 " from UserRemark where userId=" + userId + " and friendId=" + friendId);
         UserRemark userRemark = null;
         if (userRemarks != null && userRemarks.size() > 0) {
           userRemark = userRemarks.get(0);
           userVO.setRemark(userRemark.getRemark());
         }
       }
       ur.setUser(userVO);
     }
     ur.setErrorCode(0);
     ur.setErrorMessage("");
   } catch (Exception ex) {
     ValidationError ve = ValidationError.SYSTEM_ERROR;
     ur.setErrorCode(ve.getErrorCode());
     ur.setErrorMessage("系统错误");
     logger.error(ex.getMessage());
   }
   return ur;
 }
Ejemplo n.º 3
0
 @Override
 public UserResult register(UserEntity user) {
   UserResult ur = new UserResult();
   try {
     if (user != null) {
       String loginName = user.getLoginname();
       // 检查登录名是否重复
       boolean res = chekLoginName(loginName);
       if (!res) {
         User usr = new User();
         String pwd = "";
         if (user.getPwd() != null) {
           pwd = MD5Util.md5(user.getPwd());
           usr.setPlainPassword(user.getPwd());
         }
         usr.setCreateDate(new Date());
         usr.setLoginname(loginName);
         usr.setPwd(pwd);
         usr.setName(user.getName());
         usr.setPhone(user.getPhone());
         usr.setStatus(3);
         usr.setLat(user.getLat());
         usr.setLon(user.getLon());
         usr.setParseaddress(user.getParseaddress());
         usr.setUsertype(user.getUsertype());
         this.saveOrUpdate(usr);
         User userinfo = userService.findByLoginName(loginName);
         if (userinfo != null) {
           user.setId(userinfo.getId().toString());
         }
         user.setPwd("");
         user.setState(Constants.DEFAULT_STATE);
         user.setCity(Constants.DEFAULT_CITY);
         user.setSex(Constants.DEFAULT_SEX_VALUE);
         ur.setUser(user);
         ur.setErrorCode(0);
         ur.setErrorMessage("");
       } else {
         ValidationError ve = ValidationError.LOGINNAMEREPEAT;
         int errorCode = ve.getErrorCode();
         String message = Utils.getErrorMessage(ve);
         ur.setErrorCode(errorCode);
         ur.setErrorMessage(message);
       }
     }
   } catch (Exception ex) {
     ValidationError er = ValidationError.SYSTEM_ERROR;
     int errorCode = er.getErrorCode();
     ur.setErrorCode(errorCode);
     ur.setErrorMessage("系统错误");
     logger.error(ex.getMessage());
   }
   return ur;
 }
Ejemplo n.º 4
0
 @Override
 public UserResult getUserByShipCard(String shipCard) {
   UserResult ur = new UserResult();
   try {
     if (StringUtils.isNotBlank(shipCard)) {
       User user = userService.findByCardId(shipCard);
       if (user != null) {
         UserEntity ue = ConvertHelper.toUserEntity(user, null);
         ur.setUser(ue);
       }
     }
     ur.setErrorCode(0);
     ur.setErrorMessage("");
   } catch (Exception ex) {
     ur.setErrorCode(-1);
     ur.setErrorMessage(ex.getMessage());
     ex.printStackTrace();
   }
   return ur;
 }
Ejemplo n.º 5
0
 @Override
 public UserResult getUser(String id) {
   UserResult ur = new UserResult();
   try {
     if (!StringUtils.isBlank(id)) {
       User user = userService.findById(Integer.valueOf(id));
       if (user != null) {
         UserDetail userdetail = userDetailService.findByUserId(Integer.parseInt(id));
         UserEntity userVO = ConvertHelper.toUserEntity(user, userdetail);
         ur.setUser(userVO);
       }
     }
     ur.setErrorCode(0);
     ur.setErrorMessage("");
   } catch (Exception ex) {
     ValidationError ve = ValidationError.SYSTEM_ERROR;
     ur.setErrorCode(ve.getErrorCode());
     ur.setErrorMessage("系统错误");
     logger.error(ex.getMessage());
   }
   return ur;
 }
Ejemplo n.º 6
0
  /** 登录服务 return UserResult */
  @Override
  public UserResult login(UserEntity user) {
    UserResult ur = new UserResult();
    try {
      String username = user.getLoginname();
      String password = MD5Util.md5(user.getPwd());
      User u = null;
      u = userService.findByLoginNameAndPwd(username, password);
      if (u == null) {
        ValidationError er = ValidationError.LOGINFAILE;
        int errorCode = er.getErrorCode();
        String errorMessage = er.getErrorMessage();
        ur.setErrorCode(errorCode);
        ur.setErrorMessage(errorMessage);

      } else {
        if (u.getUsertype() == 2) {
          BusinessUserDetail businessUserdetail = businessUserDetailService.findByUserId(u.getId());
          BusinessUserEntity businessUserVO =
              ConvertHelper.toBusinessUserEntity(u, businessUserdetail);
          ur.setBusinessUser(businessUserVO);
        } else {
          UserDetail userdetail = userDetailService.findByUserId(u.getId());
          UserEntity userVO = ConvertHelper.toUserEntity(u, userdetail);
          ur.setUser(userVO);
        }
        ur.setErrorCode(0);
        ur.setErrorMessage("");
      }
    } catch (Exception ex) {
      ValidationError er = ValidationError.SYSTEM_ERROR;
      ur.setErrorCode(er.getErrorCode());
      ur.setErrorMessage("系统错误");
      logger.error(ex.getMessage());
    }
    return ur;
  }
Ejemplo n.º 7
0
  /** 修改普通用户 支持单字段更新 */
  @Override
  public UserResult updateuser(UserEntity user) {
    UserResult ur = new UserResult();
    try {
      if (user != null) {
        UserDetail userdetail = null;
        String id = user.getId();
        int userid = 0;
        if (!StringUtils.isBlank(id)) {
          userid = Integer.parseInt(id);
          updateUserCommon(
              id,
              user.getName(),
              user.getPhone(),
              user.getBoatcard(),
              user.getCansearchbyphone(),
              user.getHideroomtelephone(),
              user.getCansearch(),
              user.getRealname(),
              user.getRoomtelephone(),
              user.getAge());
          userdetail = userDetailService.findByUserId(userid);
        }
        if (userid > 0) {
          Date date = new Date();
          if (userdetail == null) {
            userdetail = new UserDetail();
            userdetail.setUserid(userid);
            userdetail.setCreateDate(date);
          }
          userdetail.setUpdateDate(date);
          if (user.getAge() != null) {
            userdetail.setAge(user.getAge());
          }
          if (user.getCity() != null) {
            userdetail.setCity(user.getCity());
          }
          if (user.getCountry() != null) {
            userdetail.setCountry(user.getCountry());
          }
          String sex = user.getSex();
          if (sex != null) {
            userdetail.setSex(Integer.valueOf(sex));
          }
          if (user.getState() != null) {
            userdetail.setState(user.getState());
          }
          if (user.getConstellation() != null) {
            userdetail.setConstellation(user.getConstellation());
          }
          if (user.getSignature() != null) {
            userdetail.setSignature(user.getSignature());
          }
          if (user.getHobby() != null) {
            userdetail.setHobby(user.getHobby());
          }
          if (user.getCansearchbyphone() != null) {}

          if (user.getRoomtelephone() != null) {
            userdetail.setRoom(user.getRoomtelephone());
          }
          userDetailService.saveOrUpdate(userdetail);
          if (!StringUtils.isBlank(id)) {
            User usr = userService.findById(Integer.parseInt(id));
            if (usr != null) {
              ur.setErrorCode(0);
              ur.setErrorMessage("");
              UserEntity userVO = ConvertHelper.toUserEntity(usr, userdetail);
              ur.setUser(userVO);
            } else {
              ValidationError er = ValidationError.USER_NOEXIST;
              int errorCode = er.getErrorCode();
              String errorMessage = er.getErrorMessage();
              ur.setErrorCode(errorCode);
              ur.setErrorMessage(errorMessage);
            }
          }
        }
      }

    } catch (Exception ex) {
      ValidationError ve = ValidationError.SYSTEM_ERROR;
      ur.setErrorCode(ve.getErrorCode());
      ur.setErrorMessage("系统错误");
      logger.error(ex.getMessage());
    }
    return ur;
  }