@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; }
@Override public UserRemarkResult saveOrUpdateRemark(UserRemarkEntity remark) { UserRemarkResult ur = new UserRemarkResult(); try { Integer userId = 0; Integer friendId = 0; UserRemarkEntity remarkEntity = refactorUserRemarkEntity(remark); userId = remarkEntity.getUserId(); friendId = remarkEntity.getFriendId(); if (userId > 0 && friendId > 0) { List<UserRemark> userRemarks = userRemarkService.find( " from UserRemark where userId=" + userId + " and friendId=" + friendId); UserRemark userRemark = null; Date time = new Date(); if (userRemarks != null && userRemarks.size() > 0) { userRemark = userRemarks.get(0); userRemark.setRemark(remark.getRemark()); userRemark.setUpdateDate(time); } else { userRemark = new UserRemark(); userRemark.setRemark(remark.getRemark()); userRemark.setUserId(userId); userRemark.setFriendId(friendId); userRemark.setCreateDate(time); userRemark.setUpdateDate(time); } userRemarkService.saveOrUpdate(userRemark); ur.setErrorCode(0); ur.setErrorMessage(""); UserRemarkEntity userRemarkEntity = ConvertHelper.toUserRemarkEntity(userRemark); ur.setRemark(userRemarkEntity); } else { ValidationError er = ValidationError.PARAM_MISSING; ur.setErrorCode(er.getErrorCode()); ur.setErrorMessage("Param Missing"); } } catch (Exception e) { ValidationError ve = ValidationError.SYSTEM_ERROR; ur.setErrorCode(ve.getErrorCode()); ur.setErrorMessage("系统错误"); logger.error(e.getMessage()); } return ur; }
@Override public QueryUsersResult getAllConditionUser(QueryCondition condition) { QueryUsersResult result = null; Map<Integer, String> remarkMap = new HashMap<Integer, String>(); if (condition.getRemarkUserId() != null) { // 获取所有好友的remark信息 List<UserRemark> userRemarks = userRemarkService.find(" from UserRemark where userId=" + condition.getRemarkUserId()); if (userRemarks != null && userRemarks.size() > 0) { for (int i = 0; i < userRemarks.size(); i++) { UserRemark userRemark = userRemarks.get(i); remarkMap.put(userRemark.getFriendId(), userRemark.getRemark()); } } } // 先查询航班号 String hsql = "from User order by createDate desc"; List<User> husers = userService.find(hsql, 1, 5); String voyagId = null; if (husers != null && husers.size() > 0) { voyagId = husers.get(0).getVoyagId(); } try { List<UserEntity> userList = new ArrayList<UserEntity>(); String phone = condition.getPhone(); 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.getUserName() != null && !condition.getUserName().isEmpty()) { sql += " loginname like '%" + condition.getUserName() + "%' and"; } if (condition.getName() != null && !condition.getName().isEmpty()) { sql += " name like '%" + condition.getName() + "%' and"; } if (condition.getCountry() != null && !condition.getCountry().isEmpty()) { sql += " country='" + condition.getCountry() + "' and"; } if (condition.getPhone() != null && !condition.getPhone().isEmpty()) { sql += " phone='" + condition.getPhone() + "' and"; } if (condition.getArea() != null && !condition.getArea().isEmpty()) { sql += " area ='" + condition.getArea() + "' and"; } if (condition.getAgeStart() > 0) { sql += " age >" + condition.getAgeStart() + " and"; } if (condition.getAgeEnd() > 0) { sql += " age <" + condition.getAgeEnd() + " and"; } if (condition.getSex() > 0) { sql += " sex =" + condition.getSex() + " and"; } if (condition.getUsertype() != null) { sql += " usertype =" + condition.getUsertype() + " and"; } sql = sql.substring(0, sql.length() - 3); String searchSql = ""; if (sql.length() > 8) { if (StringUtils.isBlank(phone)) { searchSql = "from User " + sql + " and cansearch=1"; } else { searchSql = "from User " + sql + " and cansearchbyphone=1"; } } else { if (StringUtils.isBlank(phone)) { searchSql = "from User where cansearch=1"; } else { searchSql = "from User " + sql + " and cansearchbyphone=1"; } } if (condition.getUsertype() != null && condition.getUsertype().equals(1) && voyagId != null) { searchSql += " and voyagId='" + voyagId + "'"; } 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); String remark = remarkMap.get(user.getId()); if (remark != null) { userInfo.setRemark(remark); } userList.add(userInfo); } } } catch (Exception e1) { e1.printStackTrace(); } System.out.println("get all users"); result = new QueryUsersResult(0, "", userList, userList.size()); return result; } catch (Exception e) { // TODO: handle exception result = new QueryUsersResult(-1, "系统错误!", null, 0); return result; } }