コード例 #1
0
ファイル: MyRentServiceImpl.java プロジェクト: szpaddy/weixin
  public HouseInfo findBaseHouseInfoBytHouseId(String tHouseId, Boolean showMap) {
    HouseInfo houseInfo = houseInfoDao.findBaseHouseInfoBytHouseId(tHouseId);
    if (showMap) {
      MapPoint currPoint = new MapPoint(houseInfo.getLongitude(), houseInfo.getLatitude());
      List<MapPoint> lstMark = new ArrayList<MapPoint>();
      lstMark.add(currPoint);
      houseInfo.setMapImg(baiduMapService.crtStaticMapUrl(lstMark, currPoint));
    }

    return houseInfo;
  }
コード例 #2
0
ファイル: MyRentServiceImpl.java プロジェクト: szpaddy/weixin
  @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;
  }
コード例 #3
0
ファイル: MyRentServiceImpl.java プロジェクト: szpaddy/weixin
  @Override
  public MatchResultWrap findAllProjectByQueryVo(MyRentQueryVo queryVo) {
    log.info("findAllProjectByQueryVo begin.");
    // 根据查询条件搜索项目列表-前台校验必输项

    List<MatchResultVo> projectList = myRentalDao.selectProjectByQueryVo(queryVo);

    if (projectList == null || projectList.isEmpty()) {
      return new MatchResultWrap();
    }

    // 工作地点
    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});
    // 搜索五公里以内的房源信息
    List<MatchResultVo> selectedProjectList = extractMatchResult(projectList, wpLon, wpLat);

    String staticUrl = StringUtils.EMPTY;
    if (selectedProjectList == null || selectedProjectList.isEmpty()) {
      return new MatchResultWrap();
    } else {
      // 构造百度url
      List<MapPoint> lstMarks = transformPoint(selectedProjectList);
      staticUrl = baiduMapService.crtStaticMapUrl(lstMarks, currPoint);

      // 交通路线查询
      for (MatchResultVo item : selectedProjectList) {
        BigDecimal lat = item.getLatitude();
        BigDecimal lon = item.getLongitude();
        RequestParam reqParam = new RequestParam();
        reqParam.setDestination(lat.toString().concat(",").concat(lon.toString()));
        reqParam.setOrigin(String.valueOf(wpLat).concat(",").concat(String.valueOf(wpLon)));
        reqParam.setMode(queryVo.getTrafficType());

        switch (ETranfficType.getSelfByCode(queryVo.getTrafficType())) {
          case DRIVING:
            reqParam.setOrigin_region(queryVo.getCityName());
            reqParam.setDestination_region(queryVo.getCityName());
            break;
          case TRANSIT:
          case WALKING:
            reqParam.setRegion(queryVo.getCityName());
            break;
        }

        String duration = baiduMapService.doLeastTimeBetweenTwoPoint(reqParam);
        if (!StringUtils.isBlank(duration)) {
          log.debug(String.valueOf(Math.ceil(Double.valueOf(duration) / 60)));
          item.setDuration(String.valueOf(Math.ceil(Double.valueOf(duration) / 60)));
        }
      }

      Collections.sort(selectedProjectList, new MatchResultVoCompator());
    }

    log.info("findAllProjectByQueryVo end.");
    return new MatchResultWrap(selectedProjectList, currPoint, staticUrl);
  }