Esempio n. 1
0
  @Override
  public MatchResultWrap findAllHouseByQueryVo(MyRentQueryVo queryVo) {
    long start = System.currentTimeMillis();
    List<MatchResultVo> listDis = myRentalDao.findHouseByQueryVo(queryVo); // 所有符合条件的房源
    // 获取我的位置的经纬度
    String workPlace = queryVo.getWorkPlace();
    MapPoint currPoint = baiduMapService.getPoint(workPlace, queryVo.getCityName());
    double wpLon = currPoint.getLng().doubleValue();
    double wpLat = currPoint.getLat().doubleValue();
    log.info("lon:[{}],lat[{}]", new Object[] {wpLon, wpLat});

    Map<String, Double> mrMap = new HashMap<String, Double>();
    // 计算房源到我的位置的直线距离
    for (MatchResultVo mr : listDis) {
      double mrDis =
          StringUtil.distanceSimplify(
              wpLat, wpLon, mr.getLatitude().doubleValue(), mr.getLongitude().doubleValue());
      mrMap.put(mr.getHouseId(), mrDis);
    }
    // 按距离远近进行排序
    ArrayList<Map.Entry<String, Double>> listEntries = StringUtil.sortMap(mrMap);

    int stackIndex = queryVo.getStackIndex();
    int MAX = 10;
    MatchResultWrap map = new MatchResultWrap();
    if (stackIndex < listEntries.size()) {
      // 本次请求显示房屋的房屋ID列表
      List<String> housIdList = new ArrayList<String>();
      int endIndex =
          (stackIndex < (listEntries.size() - (listEntries.size() % MAX)))
              ? stackIndex + MAX
              : listEntries.size();
      for (int i = stackIndex; i < endIndex; i++) {
        housIdList.add(listEntries.get(i).getKey());
      }

      // 取得房屋具体信息
      List<MatchResultVo> list = myRentalDao.findHousesByHouseIds(housIdList);
      // 计算通勤时间
      try {
        new AsyncClientHttpExchangeFutureCallback(list, queryVo, wpLon, wpLat).httpAsync();
      } catch (Exception e) {
        e.printStackTrace();
      }
      // 按通勤时间排序
      sortListByTime(list);

      map.setLstResult(list);
      log.info(System.currentTimeMillis() - start + "----------主線程時間-------ms----");
    }
    return map;
  }
Esempio n. 2
0
 public void sortListByTime(List<MatchResultVo> list) {
   Collections.sort(
       list,
       new Comparator<MatchResultVo>() {
         @Override
         public int compare(MatchResultVo o1, MatchResultVo o2) {
           return (int) (Double.valueOf(o1.getDuration()) - Double.valueOf(o2.getDuration()));
         }
       });
   for (MatchResultVo mr : list) {
     String duration = StringUtil.secondToHm(Double.valueOf(mr.getDuration()).intValue());
     mr.setDuration(duration);
     log.info("上班时间:---" + mr.getDuration() + "      价格---" + mr.getLongPrice());
   }
 }