Ejemplo n.º 1
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;
  }
Ejemplo n.º 2
0
  private void setDtoParameter(YouSearchDto dto, HttpServletRequest request) {
    String keyWords = (String) request.getParameter("keywords");
    String city = (String) request.getParameter("city");
    String ajaxType = (String) request.getParameter("ajaxType");
    String currPageNo = (String) request.getParameter("currPageNo");
    String order = (String) request.getParameter("order");
    // 新添加的搜索条件
    String type0 = request.getParameter("type0");
    String destination = request.getParameter("destination");
    String days = request.getParameter("days");
    String type1 = request.getParameter("type1");
    String priceStart = request.getParameter("price_start");
    String priceEnd = request.getParameter("price_end");
    String timeStart = request.getParameter("J_date1");
    String timeEnd = request.getParameter("J_date2");

    // 酒店新添加的条件
    String hotelPrice = request.getParameter("hotel_price");
    String hotelStar = request.getParameter("hotel_star");

    if (keyWords != null) {
      dto.setKeyWords(DefaultParameterUtil.dealParamters(keyWords, ""));
    } else {
      dto.setKeyWords(DefaultParameterUtil.dealParamters(dto.getKeyWords(), ""));
    }
    if (city != null) {
      dto.setIpLocate(DefaultParameterUtil.dealParamters(city, ""));
    }

    if (ajaxType != null) {
      dto.setAjaxType(DefaultParameterUtil.dealParamters(ajaxType, ""));
    }
    if (currPageNo != null) {
      dto.setCurrPageNoTemp(DefaultParameterUtil.dealParamters(currPageNo, ""));
    }
    if (order != null) {
      dto.setOrder(DefaultParameterUtil.dealParamters(order, ""));
    }
    // 新的搜索条件
    if (type0 != null) {
      dto.setType0(type0);
    }
    if (destination != null) {
      dto.setDestination(destination);
    }
    if (days != null) {
      dto.setDays(days);
    }
    if (type1 != null) {
      dto.setType1(type1);
    }
    if (!"".equals(priceStart) && priceStart != null) {
      dto.setPriceStart(priceStart);
    } else {
      dto.setPriceStart("");
    }

    if (!"".equals(priceEnd) && priceEnd != null) {
      dto.setPriceEnd(priceEnd);
    } else {
      dto.setPriceEnd("");
    }

    if (timeStart != null) {
      dto.setTimeStart(timeStart);
    }
    if (timeEnd != null) {
      dto.setTimeEnd(timeEnd);
    }

    // 酒店新的条件
    if (hotelPrice != null) {
      dto.setHotelPrice(hotelPrice);
    }
    if (hotelStar != null) {
      dto.setHotelStar(hotelStar);
      dto.setHotelStarChn(Constants.HOTEL_INT_CHN_MAP.get(hotelStar));
    }
  }