Пример #1
0
  /**
   * built market browse url
   *
   * @param itemSearch
   * @param name
   * @return
   */
  public static String browseUrl(ItemSearch itemSearch, String name) {
    String url;
    boolean check = false;
    if (itemSearch.getCategoryIds() == null || itemSearch.getCategoryIds().isEmpty()) {
      check = true;
      url = "/tim-kiem.html";
    } else {
      url =
          "/mua-ban/"
              + itemSearch.getCategoryIds().get(0)
              + "/"
              + TextUtils.createAlias(name)
              + ".html";
    }

    String search = "";
    String keyword = itemSearch.getKeyword();
    int pageIndex = itemSearch.getPageIndex();
    if ((itemSearch.getModelIds() != null && !itemSearch.getModelIds().isEmpty())
        || (itemSearch.getManufacturerIds() != null && !itemSearch.getManufacturerIds().isEmpty())
        || (itemSearch.getCityIds() != null && !itemSearch.getCityIds().isEmpty())
        || itemSearch.getOrderBy() > 0
        || (itemSearch.getProperties() != null && !itemSearch.getProperties().isEmpty())
        || (itemSearch.getCondition() == Condition.NEW
            || itemSearch.getCondition() == Condition.OLD)
        || (itemSearch.getListingType() == ListingType.AUCTION
            || itemSearch.getListingType() == ListingType.BUYNOW)
        || (itemSearch.getPriceFrom() > 0 || itemSearch.getPriceTo() > 0)
        || itemSearch.isCod()
        || itemSearch.isFreeShip()
        || itemSearch.isOnlinePayment()
        || itemSearch.isPromotion()
        || (itemSearch.getSellerId() != null && !itemSearch.getSellerId().equals(""))
        || (itemSearch.getPromotionId() != null && !itemSearch.getPromotionId().equals(""))) {
      itemSearch.setKeyword(null);
      itemSearch.setPageIndex(0);
      search =
          "filter="
              + Base64.encodeBase64String(StringUtils.getBytesUtf8(new Gson().toJson(itemSearch)));
    }

    if (keyword != null && !keyword.equals("")) {
      if (check && search.equals("")) {
        return "/s/"
            + keyword.replaceAll("\\s+", "\\+").trim()
            + ".html"
            + (pageIndex <= 1 ? "" : "?page=" + pageIndex);
      } else {
        url += "?keyword=" + keyword.replaceAll("\\s+", "\\+").trim();
        url = pageIndex <= 1 ? url : url + "&page=" + pageIndex;
        return search.equals("") ? url : url + (search.equals("") ? "" : ("&" + search));
      }
    } else {
      return search.equals("")
          ? (pageIndex <= 1 ? url : url + "?page=" + pageIndex)
          : ((pageIndex <= 1 ? (url + "?") : (url + "?page=" + pageIndex + "&")) + search);
    }
  }
Пример #2
0
  /**
   * built shop browse url
   *
   * @param itemSearch
   * @param alias
   * @return
   */
  public static String shopBrowseUrl(ItemSearch itemSearch, String alias) {
    List<String> params = new ArrayList<>();
    if (itemSearch.getKeyword() != null && !itemSearch.getKeyword().equals("")) {
      params.add("keyword=" + itemSearch.getKeyword().replaceAll("\\s+", "\\+"));
    }
    if (itemSearch.getPromotionId() != null && !itemSearch.getPromotionId().equals("")) {
      params.add("promotionId=" + itemSearch.getPromotionId());
    }

    if (itemSearch.getShopCategoryId() != null
        && !itemSearch.getShopCategoryId().trim().equals("")) {
      params.add("cid=" + itemSearch.getShopCategoryId());
    } else if (itemSearch.getCategoryIds() != null && itemSearch.getCategoryIds().size() > 0) {
      params.add("cid=" + itemSearch.getCategoryIds().get(0));
    }

    if (itemSearch.getOrderBy() > 0) {
      params.add("order=" + itemSearch.getOrderBy());
    }
    if (itemSearch.getPageIndex() > 0) {
      params.add("page=" + itemSearch.getPageIndex());
    }

    StringBuilder strParams = new StringBuilder();
    boolean first = true;
    for (String param : params) {
      if (first) {
        first = false;
        strParams.append("?");
      } else {
        strParams.append("&");
      }
      strParams.append(param);
    }
    return "/" + alias + "/browse.html" + strParams.toString();
  }
Пример #3
0
  public static String modelDetailUrl(ItemSearch sourceItemSearch, String name, String strChange) {
    ItemSearch itemSearch;
    try {
      itemSearch = (ItemSearch) BeanUtils.cloneBean(sourceItemSearch);
      itemSearch.setModelIds(new ArrayList<>(sourceItemSearch.getModelIds()));
    } catch (IllegalAccessException
        | InstantiationException
        | InvocationTargetException
        | NoSuchMethodException ex) {
      itemSearch = new ItemSearch();
    }
    if (strChange != null && !strChange.equals("")) {
      List<Map<String, String>> changes =
          (List<Map<String, String>>)
              JsonUtils.decode(strChange, new TypeToken<List<Map<String, String>>>() {}.getType());

      for (Map<String, String> ch : changes) {
        String op = ch.get("op");
        String key = ch.get("key");
        String val = ch.get("val");

        if (key.equals("cities")) {
          if (op.equals("mk")) {
            itemSearch.getCityIds().remove(val);
            itemSearch.getCityIds().add(val);
          } else if (op.equals("rm")) {
            itemSearch.getCityIds().remove(val);
          } else if (op.equals("cl")) {
            itemSearch.getCityIds().clear();
          }
        }
        if (key.equals("type")) {
          try {
            if (val.equals("BUYNOW")) {
              itemSearch.setListingType(ListingType.BUYNOW);
            } else if (val.equals("AUCTION")) {
              itemSearch.setListingType(ListingType.AUCTION);
            } else {
              itemSearch.setListingType(null);
            }
          } catch (NumberFormatException ex) {
          }
        }
        if (key.equals("cod")) {
          if (op.equals("mk")) {
            itemSearch.setCod(true);
          } else if (op.equals("rm")) {
            itemSearch.setCod(false);
          }
        }
        if (key.equals("manuf")) {
          if (op.equals("mk")) {
            itemSearch.setManufacturerIds(new ArrayList<String>());
          }
        }
        if (key.equals("promotion")) {
          if (op.equals("mk")) {
            itemSearch.setPromotion(true);
          } else if (op.equals("rm")) {
            itemSearch.setPromotion(false);
          }
        }

        if (key.equals("condition")) {
          try {
            if (val.equals("NEW")) {
              itemSearch.setCondition(Condition.NEW);
            } else if (val.equals("OLD")) {
              itemSearch.setCondition(Condition.OLD);
            } else {
              itemSearch.setListingType(null);
            }
          } catch (NumberFormatException ex) {
          }
        }
        if (key.equals("order")) {
          try {
            itemSearch.setOrderBy(Integer.parseInt(val));
          } catch (NumberFormatException ex) {
          }
        }
        if (key.equals("page")) {
          try {
            itemSearch.setPageIndex(Integer.parseInt(val));
          } catch (NumberFormatException ex) {
          }
        }
      }
    }
    String url;
    if (itemSearch.getModelIds() != null && itemSearch.getModelIds().size() > 0) {
      url =
          "/model/" + itemSearch.getModelIds().get(0) + "/" + TextUtils.createAlias(name) + ".html";
    } else {
      url = "/tim-kiem-model.html";
    }
    String search = "";
    String keyword = itemSearch.getKeyword();
    int pageIndex = itemSearch.getPageIndex();
    if ((itemSearch.getManufacturerIds() != null && !itemSearch.getManufacturerIds().isEmpty())
        || (itemSearch.getCityIds() != null && !itemSearch.getCityIds().isEmpty())
        || itemSearch.getOrderBy() > 0
        || (itemSearch.getProperties() != null && !itemSearch.getProperties().isEmpty())
        || (itemSearch.getCondition() == Condition.NEW
            || itemSearch.getCondition() == Condition.OLD)
        || (itemSearch.getListingType() == ListingType.AUCTION
            || itemSearch.getListingType() == ListingType.BUYNOW)
        || (itemSearch.getPriceFrom() > 0 || itemSearch.getPriceTo() > 0)
        || itemSearch.isCod()
        || itemSearch.isFreeShip()
        || itemSearch.isOnlinePayment()
        || itemSearch.isPromotion()) {
      itemSearch.setKeyword(null);
      search =
          "?filter="
              + Base64.encodeBase64String(StringUtils.getBytesUtf8(new Gson().toJson(itemSearch)));
    }
    if (keyword != null && !keyword.equals("")) {
      url += "?keyword=" + keyword.replaceAll("\\s+", "\\+");
      url = pageIndex <= 1 ? url : url + "&page=" + pageIndex;
      return search.equals("") ? url : url + "&" + search;
    } else {
      return search.equals("")
          ? (pageIndex <= 1 ? url : url + "?page=" + pageIndex)
          : ((pageIndex <= 1 ? (url + "?") : (url + "?page=" + pageIndex + "&")) + search);
    }
  }