示例#1
0
  @RequestMapping("/getHotelsForMap")
  public String getHotelsForMap(
      YouSearchDto dto, Model model, HttpServletRequest request, HttpServletResponse response) {
    String keyWords = (String) request.getParameter("keywords");
    String city = (String) request.getParameter("selectedCityId");
    if (city == null) {
      city = "2";
    }
    dto.setSelectedCityId(city);
    dto.setPageSize(10);
    String str = getDefaultKeyWord(dto);
    // 城市中心坐标
    String cityCenterPoints = hotelService.getCityCenterLatAndLong(dto);
    if (keyWords == null) {
      keyWords = str;
    }
    // 获取推荐列表
    // dto.setKeyWords(str);
    dto.setPageMode("mapNoResult");
    // 推荐商品列表
    B5MPageList<YouHotel> hotelList = hotelService.getYouHotelList(dto);
    String defaultJson = getDefaultListToJson(hotelList.getAll(), "");
    // 设置为真实的keywords
    dto.setKeyWords(keyWords);
    try {
      model.addAttribute("defaultKeyWord", str);
      model.addAttribute("mapKeyword", keyWords);
    } catch (Exception e) {
      e.printStackTrace();
    }
    model.addAttribute(
        "hotelList",
        hotelList.getAll().size() > 10 ? hotelList.getAll().subList(0, 10) : hotelList.getAll());
    model.addAttribute("defaultJson", defaultJson);
    model.addAttribute("mapCity", city);
    model.addAttribute("mapMode", "post");
    model.addAttribute("dataCityKeyId", Constants.XML_CITY);
    model.addAttribute("dataHotelsChn", Constants.HOTEL_INT_CHN_MAP);
    model.addAttribute("searchDto", dto);
    model.addAttribute("cityCenterPoints", cityCenterPoints);

    // 酒店站点城市
    Map<String, String> hotelMap = hotelService.getHotelCity();
    hotelMap.remove("-1");
    model.addAttribute("hotelCity", hotelMap);

    return "hotelMap";
  }
示例#2
0
  /**
   * ajax 获取地图酒店数据
   *
   * @param dto
   * @param model
   * @param request
   * @param response
   * @return
   */
  @RequestMapping("/getHotelsForMapByAjax")
  public String getHotelsForMapByAjax(
      YouSearchDto dto, Model model, HttpServletRequest request, HttpServletResponse response) {
    String keyWords = (String) request.getParameter("keyword");
    String city = (String) request.getParameter("city");
    String currPageNo = (String) request.getParameter("currPageNo");
    String level = (String) request.getParameter("level");
    String callback = request.getParameter("callback");
    String noResult = "";
    dto.setKeyWords(keyWords);
    // 0表示不在列表中,1表示在列表中
    String isKeyWordInMap = "0";

    if (StringUtils.isNotBlank(city)) {
      dto.setSelectedCityId(city);
    }

    if (StringUtils.isNotBlank(currPageNo)) {
      dto.setCurrPageNo(Integer.parseInt(currPageNo));
    }

    if (StringUtils.isNotBlank(level)) {
      dto.setHotelStar(level);
    } else {
      dto.setHotelStar("");
    }
    PrintWriter out = null;

    try {
      dto.setPageMode("map");
      dto.setPageSize(10);
      // 城市中心坐标
      String cityCenterPoints = hotelService.getCityCenterLatAndLong(dto);
      noResult = "{\"all\": [],\"status\":\"-1\",\"cityCenter\":\"" + cityCenterPoints + "\"}";

      B5MPageList<YouHotel> hotelList = hotelService.getYouHotelList(dto);

      Gson gson = new Gson();
      logger.info(
          "getHotelsForMap--->" + city + "---" + keyWords + "---" + hotelList.getAll().size());

      out = response.getWriter();
      String result = gson.toJson(hotelList);
      if (dto.isKeyWordInMap()) {
        isKeyWordInMap = "1";
      }
      result =
          result.substring(0, result.length() - 1)
              + ",\"latitude\":"
              + dto.getLatitude()
              + ",\"longitude\":"
              + dto.getLongitude()
              + ",\"status\":\""
              + 0
              + "\",\"inmap\":\""
              + isKeyWordInMap
              + "\",\"cityCenter\":\""
              + cityCenterPoints
              + "\"}";

      // 下拉框 关键字 无结果页的情况:1、总页数小于1   2、无中心点
      boolean flag1 =
          (dto.getLatitude() == null || dto.getLongitude() == null || hotelList.getTotalPages() < 1)
              && dto.isKeyWordInMap();
      // 非下拉框 关键字 无结果情况
      boolean flag2 = hotelList.getTotalPages() < 1 && !dto.isKeyWordInMap();

      if (callback != null) {
        if (flag1 || flag2) {
          out.print(callback + "(" + noResult + ")");
          logger.info(
              "--getHotelsForMapByAjax-noResult----fl->"
                  + flag1
                  + "--f2-->"
                  + flag2
                  + "---->"
                  + dto.isKeyWordInMap()
                  + "---"
                  + hotelList.getTotalPages());
        } else {
          out.print(callback + "(" + result + ")");
        }
      } else {
        if (flag1 || flag2) {
          out.print(noResult);
          logger.info(
              "--getHotelsForMapByAjax-noResult----fl->"
                  + flag1
                  + "--f2-->"
                  + flag2
                  + "---->"
                  + dto.isKeyWordInMap()
                  + "---"
                  + hotelList.getTotalPages());
        } else {
          out.print(result);
        }
      }
      out.flush();
    } catch (Exception e) {
      out.print(noResult);
      out.flush();
    } finally {
      if (out != null) {
        out.close();
      }
    }
    return null;
  }