/**
   * 能否满足条款(针对每天每个商品) 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;
  }
Example #2
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;
  }
  /**
   * 获取商品信息<br>
   * 目前返回以下信息:<br>
   * roomTypeId=32904, 房型Id<br>
   * roomTypeName=海景预付, 房型名称<br>
   * childRoomTypeId=34053, 价格类型Id<br>
   * childRoomTypeName=标准, 价格类型名称<br>
   * breakfastType=3, 早餐类型<br>
   * breakfastNum=0, 早餐数<br>
   * bedTypeStr=2, 可预订的床型(如"1,2")<br>
   * currency=HKD, 币种(如"RMB")<br>
   * canbook=null, 是否可预订 ("1"为可预订)<br>
   * payToPrepay=false, 面转预(请参看QueryCommodityInfo类的该成员说明)<br>
   * returnAmount=25, 返现金额<br>
   */
  public QueryCommodityInfo queryCommidity(
      Long priceTypeId, String payMethod, Date inDate, Date outDate, boolean forCts) {
    List<Object[]> liRes =
        hotelBookDao.queryCommidity(priceTypeId, payMethod, inDate, outDate, forCts);
    if (null != liRes && !liRes.isEmpty()) {

      boolean bCanBook = true;
      String bed = "";

      int totalDaysHavePrice = 0;
      int totalDays = DateUtil.getDay(inDate, outDate);
      Map<Integer, String> dateMap = new HashMap<Integer, String>(totalDays);

      QueryCommodityInfo comm = new QueryCommodityInfo();
      boolean bFirst = true;
      boolean beds[] = {true, true, true};
      int cashReturnAmount = 0;
      int nPayMethod = PayMethod.PAY.equals(payMethod) ? 1 : 2;

      for (Object[] obj : liRes) {

        if (bFirst) {
          comm.setRoomtypeId(Long.valueOf(obj[0].toString()));
          comm.setRoomtypeName(obj[1].toString());
          comm.setCommodityId(priceTypeId);
          comm.setCommodityName(obj[3].toString());
          comm.setBreakfasttype(obj[5] == null ? 0 : Long.valueOf(obj[5].toString()));
          comm.setBreakfastnumber(obj[6] == null ? 0 : Long.valueOf(obj[6].toString()));
          comm.setCurrency(obj[9].toString());
          comm.setPaymethod(payMethod);
          comm.setPaytoprepay(obj[10] == null ? "" : obj[10].toString());
          comm.setHotelId(Long.valueOf(obj[15].toString()));

          if (null != obj[26]) {
            comm.setBookstartdate((Date) obj[26]);
          }
          if (null != obj[17]) {
            comm.setBookenddate((Date) obj[17]);
          }
          if (null != obj[27]) {
            comm.setMorningtime(obj[27].toString());
          }
          if (null != obj[18]) {
            comm.setEveningtime(obj[18].toString());
          }
          if (null != obj[19]) {
            comm.setContinuumInEnd((Date) obj[19]);
          }
          if (null != obj[20]) {
            comm.setContinuumInStart((Date) obj[20]);
          }
          if (null != obj[21]) {
            comm.setContinueDay(Long.valueOf(obj[21].toString()));
          }
          if (null != obj[22]) {
            comm.setMustIn(obj[22].toString());
          }
          if (null != obj[24]) {
            comm.setRestrictIn(Long.valueOf(obj[24].toString()));
          }
          if (null != obj[25]) {
            comm.setContinueDatesRelation(obj[25].toString());
          }

          bFirst = false;
        }

        Date ableDate = (Date) obj[4];
        int dayIndex = DateUtil.getDay(inDate, ableDate);
        if (!dateMap.containsKey(dayIndex)) {
          dateMap.put(dayIndex, "1");
          totalDaysHavePrice++;

          comm.setCloseflag(null != obj[16] ? obj[16].toString() : "");
          if (bCanBook && "G".equalsIgnoreCase(comm.getCloseflag())) {
            bCanBook = false;
            comm.setCantbookReason("该房型已关房");
          }

          Double salePrice = Double.valueOf(obj[12].toString());
          comm.setSaleprice(salePrice);
          if (bCanBook && (0.1 > salePrice || 99998 < salePrice)) {
            bCanBook = false;
            comm.setCantbookReason("该房型暂无价格");
          }

          // 计算返现金额
          comm.setAbledate((Date) obj[4]);
          comm.setFormula(obj[11].toString());
          comm.setCommissionRate(Double.valueOf(obj[13].toString()));
          comm.setCommission(Double.valueOf(obj[14].toString()));
          BigDecimal cPrice =
              returnService.calculateRoomTypePrice(
                  comm.getFormula(),
                  new BigDecimal(comm.getCommission()),
                  new BigDecimal(comm.getCommissionRate()),
                  new BigDecimal(comm.getSaleprice()));

          // 如果是中旅,俑金等于售价-底价   add by longkangfu
          double commission = comm.getCommission();
          if (forCts) {
            commission = comm.getSaleprice() - Double.valueOf(obj[29].toString());
          }

          // 计算限量返现
          int cashLimitReturnAmount =
              limitFavourableManage.calculateCashLimitReturnAmount(
                  comm.getHotelId(),
                  priceTypeId,
                  ableDate,
                  comm.getCurrency(),
                  new BigDecimal(comm.getSaleprice()),
                  commission);

          // 如果没有限量返现,再计算普通返现,如果有,则不计算普通返现
          if (cashLimitReturnAmount == -1) {
            cashReturnAmount +=
                returnService.calculateCashReturnAmount(
                    priceTypeId, comm.getAbledate(), nPayMethod, comm.getCurrency(), 1, cPrice);
          } else {
            cashReturnAmount += cashLimitReturnAmount;
          }
        }

        this.handleRoomState(obj[8].toString(), beds);
      }

      bFirst = true;
      for (int i = 0; i < beds.length; i++) {
        if (beds[i]) {
          if (bFirst) {
            bed += (i + 1);
            bFirst = false;
          } else {
            bed += "," + (i + 1);
          }
        }
      }

      if (bCanBook && 0 >= bed.length()) {
        bCanBook = false;
        comm.setCantbookReason("该房型满房,暂无法预订");
      }
      if (bCanBook && totalDaysHavePrice < totalDays) {
        bCanBook = false;
        comm.setCantbookReason("该房型暂无价格,无法预订");
      }

      if (bCanBook && !satisfyClauseForPerday(comm, inDate, outDate)) {
        bCanBook = false;
      }

      comm.setBedtype(bed);
      comm.setHasbook(bCanBook ? "1" : "0");

      comm.setReturnCash(Double.valueOf(cashReturnAmount));
      comm.setHasReturnCash(0 < cashReturnAmount);

      return comm;
    } else {
      return null;
    }
  }