Пример #1
0
  public String queryAgentList() {

    Map params = this.getParams();
    int pageNo = 1;
    if (!StringUtil.isValidStr(isFromUnlock)) {
      pageNo = RequestUtil.getPageNo(request);
    } else {
      String sPageNo = (String) params.get("ec_p");
      if (StringUtil.isValidStr(sPageNo)) {
        pageNo = Integer.parseInt(sPageNo);
      }
      putSession("isFromUnlock", null);
      request.setAttribute("fromUnlock", "1");
    }
    params.put("pageNo", Integer.valueOf(pageNo));

    String beginDate = (String) params.get("beginDate");
    int pageSize = RequestUtil.getCurrentRowsDisplayed(request);
    PaginatedList results = queryDao.queryByPagination(queryID, params, pageSize);

    // 如果在第N页查询时,结果可能会查不到,要重新查才有结果,针对这个的解决办法 by juesuchen
    // getPageSize() means return the maximum number of items per page ,it will equals totalNum
    if (results.size() == 0 && results.getPageSize() > 0) {
      params.put("pageNo", 1);
      results = queryDao.queryByPagination(queryID, params, pageSize);
    }

    RequestUtil.initLimit(request, results.getPageSize(), results.size());
    request.setAttribute("records", results);

    // TlvUtil.getMapToString(super.getSession());
    forward = StringUtil.isValidStr(forward) ? forward : queryID;

    return forward;
  }
 /** 处理重复提交 */
 private boolean isRepeatSubmit() {
   String strutsToken = (String) getParams().get("struts.token");
   String sessionToken = (String) getFromSession("struts.token.session");
   if (StringUtil.StringEquals2(strutsToken, sessionToken)) {
     return true;
   }
   putSession("struts.token.session", strutsToken);
   return false;
 }
Пример #3
0
  public String execute() {

    try {
      request = getRequest();
      httpResponse = getHttpResponse();
      label = request.getParameter("label");

      boolean isValiDate = true; // 是否有效日期
      log.info(
          "hotel query para:cityCode="
              + cityCode
              + ",cityName="
              + cityName
              + ",inDate="
              + inDate
              + ",outDate="
              + outDate
              + ",hotelName="
              + hotelName
              + ",geoName="
              + geoName);
      // 处理日期为空的情况
      if (null == inDate || null == outDate) {
        isValiDate = false;
      }
      if (isValiDate) {
        Pattern pattern = Pattern.compile("^[0-9]{4}-[0-9]{1,2}-[0-9]{1,2}"); // 校验日期格式为 2012-11-01
        Matcher inDateMatcher = pattern.matcher(inDate);
        Matcher outDateMatcher = pattern.matcher(outDate);
        if (!inDateMatcher.matches() || !outDateMatcher.matches()) {
          isValiDate = false; // 日期格式不匹配
        }
      }

      if (!isValiDate) {
        inDate = DateUtil.dateToString(DateUtil.getDate(DateUtil.getSystemDate(), 1));
        outDate = DateUtil.dateToString(DateUtil.getDate(DateUtil.getSystemDate(), 2));
      }

      queryOrderRecordService.saveOrderRecord(
          request,
          super.getHttpResponse(),
          DateUtil.getDate(inDate),
          DateUtil.getDate(outDate),
          null,
          3);

      // 添加入住、离店日期到cookie
      CookieUtils.setCookie(request, httpResponse, "inDate", inDate, -1, "", "/");
      CookieUtils.setCookie(request, httpResponse, "outDate", outDate, -1, "", "/");
      int nightNum =
          DateUtil.getDay(
              DateUtil.stringToDateMain(inDate, "yyyy-MM-dd"),
              DateUtil.stringToDateMain(outDate, "yyyy-MM-dd"));
      if (0 >= nightNum || 28 < nightNum) {
        return super.forwardError("查询不能超过28天");
      }
      if (StringUtil.isValidStr(cityCode) && cityCode.matches("^\\w+$")) {
        cityCode = cityCode.toUpperCase();
        cityName = InitServlet.cityObj.get(cityCode);
      } else {
        cityCode = "PEK";
      }

      if (StringUtil.isValidStr(bizCode) && bizCode.matches("^\\w+$")) {
        bizCode = bizCode.toUpperCase();
        bizValue = InitServlet.businessSozeObj.get(bizCode);
      } else {
        bizCode = null;
      }

      if (StringUtil.isValidStr(distinctCode) && distinctCode.matches("^\\w+$")) {
        distinctCode = distinctCode.toUpperCase();
        distinctValue = InitServlet.citySozeObj.get(distinctCode);
      } else {
        distinctCode = null;
      }
      if (StringUtil.isValidStr(hotelGroupId) && hotelGroupId.matches("^\\d+$")) {
        hotelGroupName = CityBrandConstant.getCityBrandName(Long.parseLong(hotelGroupId));
      } else {
        hotelGroupId = null;
      }
    } catch (Exception e) {
      log.error("HotelQueryAction set condition has a wrong", e);
    }
    if (StringUtil.isValidStr(geoId) && geoId.matches("^//d+$")) {
      try {
        HtlGeographicalposition geographicalposition =
            geographicalPositionService.getGeographicalposition(Long.valueOf(geoId));
        if (geographicalposition != null) {
          geoName = geographicalposition.getName();
          geoType = String.valueOf(geographicalposition.getGptypeId());
        }
      } catch (Exception e) {
        log.error("HotelQueryAction 查询地理信息出错:geoId =" + geoId + "error:", e);
      }
    }
    try {
      // 设值
      QueryHotelCondition queryHotelCondition = new QueryHotelCondition();
      queryHotelCondition.setFromChannel(SaleChannel.WEB);
      queryHotelCondition.setInDate(DateUtil.getDate(inDate));
      queryHotelCondition.setOutDate(DateUtil.getDate(outDate));
      queryHotelCondition.setHotelName(hotelName);
      queryHotelCondition.setCityCode(cityCode);
      queryHotelCondition.setBizZone(bizCode);
      queryHotelCondition.setDistrict(distinctCode);

      if (payMethod != null && !"".equals(payMethod)) {
        queryHotelCondition.setPayMethod(payMethod);
      }

      if (hotelStar != null) {
        queryHotelCondition.setStarLeval(hotelStar.replaceAll("#", ""));
      }
      if (StringUtil.isValidStr(priceStr)) {
        String[] priceArr = priceStr.split("-");

        if (priceArr[0].matches("^\\d+(\\.)?\\d*$")) {
          queryHotelCondition.setMinPrice(priceArr[0]);
        }
        if (priceArr.length > 1 && priceArr[1].matches("^\\d+(\\.)?\\d*$")) {
          queryHotelCondition.setMaxPrice(priceArr[1]);
        }
      }
      queryHotelCondition.setHotelGroup(hotelGroupId);
      queryHotelCondition.setGeoName(geoName);
      queryHotelCondition.setGeoId(geoId);
      if (StringUtil.isValidStr(promoteType) && promoteType.matches("\\d+")) {
        queryHotelCondition.setPromoteType(Integer.parseInt(promoteType));
      } else {
        promoteType = "1";
      }
      CookieUtils.setCookie(request, httpResponse, "promoteType", promoteType, -1, "", "/");

      HotelQueryHandler handler = new HotelQueryHandler();
      long time_start = System.currentTimeMillis();
      handler.setQueryHotelCondition(queryHotelCondition);
      hotelSearchService.queryOnlyHotelsByHandler(queryHotelCondition, handler);
      log.info("酒店基本信息查询时间(ms):" + (System.currentTimeMillis() - time_start));
      List<HotelResultVO> hotelVOList = handler.getHotelResutlList();
      hotelCount = handler.getHotelCount();

      // add by ting.li
      if (hotelVOList != null && hotelVOList.size() == 0) {
        if (queryHotelCondition.getHotelName() != null
            && !"".equals(queryHotelCondition.getHotelName())) {
          fagHasSearchHotel = true;
          queryHotelCondition.setHotelName(null);
          hotelSearchService.queryOnlyHotelsByHandler(queryHotelCondition, handler);
          hotelVOList = handler.getHotelResutlList();
        }
      }

      for (int i = 0; i < hotelVOList.size(); i++) {
        HotelResultVO hotelVo = hotelVOList.get(i);
        if (hotelVo != null) {
          String hotelId = String.valueOf(hotelVo.getHotelId());
          hotelIdsStr += hotelId + ",";
        }
      }
      hotelIdsStr = StringUtil.deleteLastChar(hotelIdsStr, ',');

      HotelListShowVm vm = new HotelListShowVm();
      hotelListOut = new String();
      if (hotelVOList.size() == 0) {
        display_helper = "";
      }
      for (int i = 0; i < hotelVOList.size(); i++) {
        String hotelListOut1 = vm.getHotelListWithTemplate(hotelVOList.get(i));
        hotelListOut += hotelListOut1;
      }
      projectcode = CookieUtils.getCookieValue(request, "projectcode");
      cashbackrate = channelCashBackService.getChannelCashBacktRate(projectcode);
      log.info("酒店总时间(ms):" + (System.currentTimeMillis() - time_start));
    } catch (Exception e) {
      super.setErrorCode("H02");
      log.error("HotelQueryAction  query hotel has a wrong!", e);
    }

    return SUCCESS;
  }
Пример #4
0
  /**
   * 能否满足条款(针对每天每个商品) 1、预订时间在要求的时间范围内 2、入住天数必须大于连住小于限住
   *
   * @param queryInfo
   * @param checkinDate
   * @param checkoutDate
   * @return
   */
  public boolean satisfyClauseForPerday(
      QueryCommodityInfo queryInfo, Date checkinDate, Date checkoutDate) {
    String sDate = "", eDate = "";
    String stime = "", etime = "";

    sDate = DateUtil.dateToString(queryInfo.getBookstartdate()); // 开始日期
    eDate = DateUtil.dateToString(queryInfo.getBookenddate()); // 结束日期
    stime = queryInfo.getMorningtime(); // 开始时间
    etime = queryInfo.getEveningtime(); // 结束时间

    if (null == sDate || "".equals(sDate)) {
      sDate = "1900-01-01";
    }
    if (null == eDate || "".equals(eDate)) {
      eDate = "2099-12-31";
    }

    if (null == stime || "".equals(stime)) stime = "00:00";
    if (null == etime || "".equals(etime)) etime = "23:59";

    Date startDate = DateUtil.stringToDateMinute(sDate + " " + stime); // 开始日期时间
    Date endDate = DateUtil.stringToDateMinute(eDate + " " + etime); // 结束日期时间

    Date curDate = DateUtil.getSystemDate(); // 当前日期								

    boolean flag = true;
    /** 如果当前日期在要求的时间区间内 并且满足连住和限住条件就return true */
    StringBuilder notSatisfyStr = new StringBuilder("");
    if (curDate.before(startDate) || curDate.after(endDate)) { // 不在时间区间内
      flag = false;
      notSatisfyStr.append(" 必须在");
      if (DATE_1970_01_01.after(startDate)) {
        notSatisfyStr.append(DateUtil.datetimeToString(endDate)).append("之前预订。");
      } else {
        notSatisfyStr.append(DateUtil.datetimeToString(startDate));
        if (DATE_2099_01_01.before(endDate)) {
          notSatisfyStr.append("之后预订。");
        } else {
          notSatisfyStr.append("和").append(DateUtil.datetimeToString(endDate)).append("之间预订。");
        }
      }
    }

    if (flag) {
      long bookDays = DateUtil.getDay(checkinDate, checkoutDate);
      long continueDays =
          null == queryInfo.getContinueDay() ? 0 : queryInfo.getContinueDay().longValue(); // 连住
      if (bookDays < continueDays) {
        notSatisfyStr
            .append(" 必须连住")
            .append(continueDays)
            .append("晚(含")
            .append(continueDays)
            .append("晚)");
        flag = false;
      }

      if (flag) {
        Long restrictInDays = queryInfo.getRestrictIn(); // 限住
        if (null != restrictInDays && 0 < restrictInDays.longValue()) {
          if (bookDays != restrictInDays.longValue()) {
            notSatisfyStr.append("  限住" + restrictInDays + "晚");
            flag = false;
          }
        }

        if (flag) {
          // 必住日期判断
          String mustIn = queryInfo.getMustIn();
          if (StringUtil.isValidStr(mustIn)) {
            if (!checkMustInDate(
                queryInfo, notSatisfyStr, checkinDate, checkoutDate, 0 >= notSatisfyStr.length())) {
              flag = false;
            }
          }
        }
      }
    }

    queryInfo.setCantbookReason(notSatisfyStr.toString());

    return flag;
  }
Пример #5
0
  /**
   * 对必住日期进行逻辑判断的方法
   *
   * @param queryInfo
   * @param bookHintNoMeet
   * @param checkInDate
   * @param checkOutDate
   * @param bFirst
   * @return
   */
  private boolean checkMustInDate(
      QueryCommodityInfo queryInfo,
      StringBuilder bookHintNoMeet,
      Date checkInDate,
      Date checkOutDate,
      boolean bFirst) {

    List<MustDate> mustInDates = new ArrayList<MustDate>(2);
    int type = MustDate.getMustIndatesAndType(mustInDates, queryInfo.getMustIn());
    boolean isCanLive = false;
    StringBuilder noMeet = new StringBuilder();
    String mustDatesRelation = queryInfo.getContinueDatesRelation();
    if (!StringUtil.isValidStr(mustDatesRelation) || mustDatesRelation.equals("or")) { // 里边为 或者
      // 逻辑判断
      // 得到必住日期集合
      if (type == MustDate.DATE_TYPE) { // 必住日期逻辑
        for (MustDate date : mustInDates) {
          // //如果入住日期包括任意一个必住日期即可入住
          if (DateUtil.isBetween(date.getContinueDate(), checkInDate, checkOutDate)) {
            isCanLive = true;
            break;
          }
          noMeet.append(DateUtil.dateToString(date.getContinueDate())).append(",");
        }
        if (!isCanLive) {
          if (bFirst) {
            bookHintNoMeet.append("入住此房型,住店日期需至少包含");
          } else {
            bookHintNoMeet.append("并且住店日期需至少包含");
          }
          noMeet.deleteCharAt(noMeet.length() - 1);
          bookHintNoMeet.append(noMeet.toString());
          if (bFirst) {
            bookHintNoMeet.append("中任意一天方可接受预订。");
          } else {
            bookHintNoMeet.append("中任意一天。");
          }
        }
      } else if (type == MustDate.WEEK_TYPE) { // 必住星期逻辑
        for (MustDate date : mustInDates) {
          if (DateUtil.isBetween(checkInDate, date.getContinueDate(), date.getContinueEndDate())) {
            String[] checkInWeeks = date.getWeeks().split(",");
            Date[] checkInDates = DateUtil.getDateWithWeek(checkInDate, checkOutDate, checkInWeeks);
            if (0 < checkInDates.length) { // 说明入住日期内已经至少包含有一个必住星期
              isCanLive = true;
            } else {
              noMeet
                  .append("从")
                  .append(DateUtil.dateToString(date.getContinueDate()))
                  .append("至")
                  .append(DateUtil.dateToString(date.getContinueEndDate()))
                  .append("期间的星期")
                  .append(date.getWeeks());
            }
            break;
          }
        }
        // 如果不能入住,则显示提示信息
        if (!isCanLive) {
          if (bFirst) {
            bookHintNoMeet.append("入住此房型,住店日期需至少包含");
          } else {
            bookHintNoMeet.append("并且住店日期需至少包含");
          }
          bookHintNoMeet.append(noMeet.toString());
          if (bFirst) {
            bookHintNoMeet.append("中任意一天方可接受预订。");
          } else {
            bookHintNoMeet.append("中任意一天。");
          }
        }
      }
    } else { // 里边为 并且 逻辑判断
      if (type == MustDate.DATE_TYPE) { // 必住日期逻辑
        if (!DateUtil.isBetween(queryInfo.getContinuumInStart(), checkInDate, checkOutDate)
            || !DateUtil.isBetween(queryInfo.getContinuumInEnd(), checkInDate, checkOutDate)) {
          // 不能入住
          if (bFirst) {
            bookHintNoMeet.append("入住此房型,住店日期需包含");
          } else {
            bookHintNoMeet.append("并且住店日期需包含");
          }
          for (MustDate date : mustInDates)
            noMeet.append(DateUtil.dateToString(date.getContinueDate())).append(",");
          noMeet.deleteCharAt(noMeet.length() - 1);
          bookHintNoMeet.append(noMeet.toString());
          if (bFirst) {
            bookHintNoMeet.append("方可接受预订。");
          } else {
            bookHintNoMeet.append("。");
          }
        } else isCanLive = true; // 可以入住
      } else if (type == MustDate.WEEK_TYPE) { // 必住星期逻辑
        for (MustDate date : mustInDates) {
          if (DateUtil.isBetween(checkInDate, date.getContinueDate(), date.getContinueEndDate())) {
            String[] checkInWeeks = date.getWeeks().split(",");
            Date[] checkInDates = DateUtil.getDateWithWeek(checkInDate, checkOutDate, checkInWeeks);
            if (checkInDates.length >= checkInWeeks.length) { // 说明入住日期内已经至少包含有一个整体的必住星期
              isCanLive = true;
            } else {
              noMeet
                  .append("从")
                  .append(DateUtil.dateToString(date.getContinueDate()))
                  .append("至")
                  .append(DateUtil.dateToString(date.getContinueEndDate()))
                  .append("期间的逢星期")
                  .append(date.getWeeks());
            }
            break;
          }
        }
        // 如果不能入住,则显示提示信息
        if (!isCanLive) {
          if (bFirst) {
            bookHintNoMeet.append("入住此房型,住店日期需包含");
          } else {
            bookHintNoMeet.append("并且住店日期需包含");
          }
          bookHintNoMeet.append(noMeet.toString());
          if (bFirst) {
            bookHintNoMeet.append("方可接受预订。");
          } else {
            bookHintNoMeet.append("。");
          }
        }
      }
    }
    return isCanLive;
  }