Ejemplo n.º 1
0
 /**
  * 该方法是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);
 }
Ejemplo n.º 2
0
 // 封装用户间的距离信息
 private void distanceUserMap(User user, String client_id, Map<String, Object> msg) {
   Location my_local = locationService.findLocationByUser(userService.findUserById(client_id));
   msg.put("distance", locationService.computeDistance(user, my_local));
 }