// 封装用户之间的好友关系 private void friendUserMap(User user, String client_id, Map<String, Object> msg) { boolean is_friend = userService.isFriend(client_id, user.getClient_id()); msg.put("is_friend", is_friend); if (!is_friend) msg.put("has_invitation", friendService.isInvited(client_id, user.getClient_id())); else msg.put("has_invitation", !is_friend); }
@RequestMapping("find") public ResponseEntity<List<Label>> findLabelByUser(@RequestParam String client_id) { User user = new User(); user.setClient_id(client_id); List<Label> labels = labelDao.findLabelByUser(user); return new ResponseEntity<List<Label>>(labels, HttpStatus.OK); }
@RequestMapping("leaveTopic") public String leaveTopic(@RequestParam String client_id, @RequestParam String huanxin_group_id) { User user = new User(); Topic topic = new Topic(); topic.setHuanxin_group_id(huanxin_group_id); user.setClient_id(client_id); topicDao.userLeaveTopic(user); return "SUCCESS"; }
/** * 该方法是usersToMapConvertor(List<User> users,String client_id)方法的改良版, 核心作用相同,该方法多了一层按标签排序 * * @param users * @return 2015-12-18:暂时去掉标签排序 */ public Map<String, Object> usersToMapSortedConvertor(List<User> users, User me) { List<Map<String, Object>> usersmsg = new ArrayList<Map<String, Object>>(); for (User u : users) { Map<String, Object> msg = new HashMap<String, Object>(); msg.put( "user", userMapBuilder( u, me.getClient_id(), conditionGenetator("hasDistance") /*false,false,true*/)); usersmsg.add(msg); // 比较当前用户哪些标签是根据使用者的标签被推出来的 } // 排序操作,详细请看 SortUtil 类 System.out.println("你的标签:" + me.getLabelnames()); usersmsg = SortUtil.sortByLabelName(usersmsg, me.getLabelnames()); return generateResult(usersmsg); }
/** * 该方法是usersToMapSortedConvertor(List<User> users,String client_id)方法的改良版, * 核心作用相同,除了有按行业排序,该方法多了一层按距离排序。现根据行业排序,然后根据距离排序 * * @param users * @return notice:在推荐的同行中如果有人没有location记录,则为其设置一个默认坐标 */ public Map<String, Object> usersToMapSortedWithDistanceConvertor(List<User> users, User me) { List<Map<String, Object>> usersmsg = new ArrayList<Map<String, Object>>(); for (User u : users) { Map<String, Object> msg = new HashMap<String, Object>(); msg.put( "user", userMapBuilder( u, me.getClient_id(), conditionGenetator("hasFriend", "hasRoom", "hasDistance") /*true,true,true*/)); usersmsg.add(msg); } // 排序操作,详细请看 SortUtil 类 usersmsg = SortUtil.sortByLabelName(usersmsg, me.getLabelnames()); if (locationService.findLocationByUser(me) != null) usersmsg = SortUtil.sortByDistance(usersmsg); return generateResult(usersmsg); }
@RequestMapping("addTopic") public String addTopic( HttpServletRequest request, @RequestParam String client_id, @RequestParam String huanxin_group_id, @RequestParam String subject, @RequestParam String label_name) throws Exception { request.setCharacterEncoding("UTF-8"); User user = new User(); user.setClient_id(client_id); Label label = new Label(); label.setLabel_name(label_name); Topic topic = new Topic(); topic.setHuanxin_group_id(huanxin_group_id); topic.setLabel(label); topic.setUser(user); topicDao.save(topic); return "success"; }
/** * 业务功能:标记用户和目标标签列表有哪些是相同的 * * @param u * @param label_names * @return */ private List<String> markLabel(User u, List<String> label_names) { List<String> labels = new ArrayList<String>(); for (Label l : u.getLabellist()) { boolean ismarked = false; for (String lab_name : label_names) { if (l.getLabel_name().equalsIgnoreCase(lab_name) || l.getLabel_name().contains(lab_name) || lab_name.contains(l.getLabel_name())) { ismarked = true; } } if (ismarked) { labels.add(l.getLabel_name() + "\t\t"); } else { labels.add(l.getLabel_name()); } } return labels; }
/** * 添加时间:2015-10-19 业务功能:返回带薪资的用户信息,并返回是否可以更改薪资信息 * * @param user * @param ignore * @param client_id * @return */ public Map<String, Object> salaryConvertor(User user) { Map<String, Object> msg = new HashMap<String, Object>(); Map<String, Object> usermap = new HashMap<String, Object>(); int nextdate = 0; if (user.getNext_change() != null) { nextdate = TimeUtil.dateGap(user.getNext_change(), new Date()); } if (nextdate <= 0) { nextdate = 0; } msg.put("client_id", user.getClient_id()); msg.put("ry_id", user.getRy_id()); msg.put("username", user.getUsername()); msg.put("salary", user.getSalary() + ""); msg.put("date_gap", nextdate); usermap.put("user", msg); return usermap; }
// 封装用户的房间信息 private void roomUserMap(User user, String client_id, Map<String, Object> msg) { Room room = roomService.findRoomByOwner(user.getClient_id()); msg.putAll(roomUtil.roomToMapConverterTemplate(room)); roomUtil.followRoomMap(msg, room, client_id); }
// 基础的用户信息封装 private void baseUserMap(User user, Map<String, Object> msg) { msg.put("labels", user.getLabelnames()); msg.put("email", user.getEmail()); msg.put("sex", user.getSex()); msg.put("username", user.getUsername()); msg.put("phone", user.getPhone()); msg.put("city", user.getCityValue()); msg.put("client_id", user.getClient_id()); msg.put("ry_id", user.getRy_id()); msg.put( "image", Constant.IMAGE_PATH + user.getClient_id() + File.separator + user.getImage() + Constant.IMAGE_NAME); msg.put("created_at", user.getCreated_at()); msg.put("birth", user.getBirth()); msg.put("type", true); }