@Override public UserResult checkin(UserEntity user) { UserResult ur = new UserResult(); try { UserDetail u = userDetailService.getUserByQuery(user); if (u != null) { u.setStatus(1); userDetailService.saveOrUpdate(u); ur.setErrorCode(0); ur.setErrorMessage(""); } else { ValidationError ve = ValidationError.USER_NOEXIST; 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; }
@Override public QueryUsersResult quickSearchUser(QueryCondition condition) { QueryUsersResult result = null; try { List<UserEntity> userList = new ArrayList<UserEntity>(); System.out.println("query pageNumber is =" + condition.getPageNum()); int pageSize = condition.getPageSize(); if (pageSize < 1) { pageSize = 1; } int curNum = condition.getPageNum(); if (curNum < 1) { curNum = 1; } String sql = "where "; if (condition.getKey() != null) { sql += " (loginname like '%" + condition.getKey().trim() + "%' or name like '%" + condition.getKey().trim() + "%' or realname like '%" + condition.getKey().trim() + "%') and"; } if (condition.getUsertype() != null) { sql += " usertype =" + condition.getUsertype() + " and"; } sql = sql.substring(0, sql.length() - 3); String searchSql = ""; if (sql.length() > 8) { searchSql = "from User " + sql; } else { searchSql = "from User"; } List<User> users = userService.find(searchSql, curNum, pageSize); try { if (users != null && users.size() > 0) { for (User user : users) { UserDetail userdetail = userDetailService.findByUserId(user.getId()); UserEntity userInfo = ConvertHelper.toUserEntity(user, userdetail); userList.add(userInfo); } } } catch (Exception e1) { e1.printStackTrace(); } if (condition.getPageNum() == 1) { List<UserDetail> userDetails = userDetailService.find("from UserDetail where room='" + condition.getKey() + "'"); if (userDetails != null && userDetails.size() > 0) { for (UserDetail userDetail : userDetails) { if (!isContain(users, userDetail.getUserid())) { User user = userService.findById(userDetail.getUserid()); UserEntity userInfo = ConvertHelper.toUserEntity(user, userDetail); userList.add(userInfo); } } } } System.out.println("get all users"); result = new QueryUsersResult(0, "", userList, userList.size()); return result; } catch (Exception e) { result = new QueryUsersResult(-1, "系统错误!", null, 0); return result; } }
/** 修改普通用户 支持单字段更新 */ @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; }