Exemplo n.º 1
0
 public static String browseToModel(ItemSearch itemSearch, String name) {
   ModelSearch modelSearch = new ModelSearch();
   if (itemSearch.getCategoryIds() != null && !itemSearch.getCategoryIds().isEmpty()) {
     modelSearch.setCategoryId(itemSearch.getCategoryIds().get(0));
   }
   modelSearch.setKeyword(itemSearch.getKeyword());
   modelSearch.setManufacturerIds(itemSearch.getManufacturerIds());
   modelSearch.setProperties(itemSearch.getProperties());
   return UrlUtils.modelBrowseUrl(modelSearch, name);
 }
Exemplo n.º 2
0
 public static String browseToItem(ModelSearch modelSearch, String name) {
   ItemSearch itemSearch = new ItemSearch();
   if (modelSearch.getCategoryId() != null && !modelSearch.getCategoryId().trim().equals("")) {
     itemSearch.setCategoryIds(new ArrayList<String>());
     itemSearch.getCategoryIds().add(modelSearch.getCategoryId());
   }
   itemSearch.setKeyword(modelSearch.getKeyword());
   itemSearch.setManufacturerIds(modelSearch.getManufacturerIds());
   itemSearch.setProperties(modelSearch.getProperties());
   return UrlUtils.browseUrl(itemSearch, name);
 }
Exemplo n.º 3
0
  /**
   * autocomplate model
   *
   * @param keyword
   * @param cateId
   * @param manufacturerId
   * @return
   */
  @RequestMapping(value = "/searchmodel", method = RequestMethod.GET)
  @ResponseBody
  public Response searchmodel(
      @RequestParam(value = "keyword", defaultValue = "") String keyword,
      @RequestParam(value = "categoryId", defaultValue = "") String cateId,
      @RequestParam(value = "manufacturerId", defaultValue = "") String manufacturerId) {

    ModelSearch search = new ModelSearch();
    search.setKeyword(keyword);
    if (cateId != null && !"".equals(cateId.trim()) && !"0".equals(cateId.trim())) {
      search.setCategoryId(cateId);
    }
    if (manufacturerId != null
        && !"".equals(manufacturerId.trim())
        && !"0".equals(manufacturerId.trim())) {
      search.setManufacturerIds(new ArrayList<String>());
      search.getManufacturerIds().add(manufacturerId);
    }
    search.setPageIndex(0);
    search.setPageSize(100);
    DataPage<Model> dataPage = modelService.search(search);
    return new Response(true, "Danh sách model", dataPage);
  }
Exemplo n.º 4
0
  public static String modelBrowseUrl(
      ModelSearch sourceModelSearch, String name, String strChange) {
    ModelSearch modelSearch;
    try {
      modelSearch = (ModelSearch) BeanUtils.cloneBean(sourceModelSearch);
      modelSearch.setManufacturerIds(new ArrayList<>(sourceModelSearch.getManufacturerIds()));
      modelSearch.setProperties(new ArrayList<>(sourceModelSearch.getProperties()));
    } catch (IllegalAccessException
        | InstantiationException
        | InvocationTargetException
        | NoSuchMethodException ex) {
      modelSearch = new ModelSearch();
    }
    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("cid")) {
          modelSearch.setCategoryId(val);
        }
        if (key.equals("keyword")) {
          if (op.equals("mk")) {
            modelSearch.setKeyword(val);
          } else if (op.equals("rm")) {
            modelSearch.setKeyword(null);
          }
        }
        if (key.equals("manufacturers")) {
          if (op.equals("mk")) {
            modelSearch.getManufacturerIds().remove(val);
            modelSearch.getManufacturerIds().add(val);
          } else if (op.equals("rm")) {
            modelSearch.getManufacturerIds().remove(val);
          } else if (op.equals("cl")) {
            modelSearch.getManufacturerIds().clear();
          }
        }
        if (key.equals("properties")) {
          PropertySearch ps =
              (PropertySearch) JsonUtils.decode(val, new TypeToken<PropertySearch>() {}.getType());
          if (op.equals("mk")) {
            modelSearch.getProperties().remove(ps);
            modelSearch.getProperties().add(ps);
          } else if (op.equals("rm")) {
            modelSearch.getProperties().remove(ps);
          } else if (op.equals("cl")) {
            modelSearch.getProperties().clear();
          }
        }

        if (key.equals("order")) {
          try {
            modelSearch.setOrderBy(Integer.parseInt(val));
          } catch (NumberFormatException ex) {
          }
        }
        if (key.equals("page")) {
          try {
            modelSearch.setPageIndex(Integer.parseInt(val));
          } catch (NumberFormatException ex) {
          }
        }
      }
    }
    return UrlUtils.modelBrowseUrl(modelSearch, name);
  }
Exemplo n.º 5
0
  /**
   * built market model browse url
   *
   * @param modelSearch
   * @param name
   * @return
   */
  public static String modelBrowseUrl(ModelSearch modelSearch, String name) {
    String url;

    if (modelSearch.getCategoryId() == null) {
      url = "/tim-kiem-model.html";
    } else {
      url =
          "/mua-ban/model/"
              + modelSearch.getCategoryId()
              + "/"
              + TextUtils.createAlias(name)
              + ".html";
    }
    String search = "";
    String keyword = modelSearch.getKeyword();
    int pageIndex = modelSearch.getPageIndex();
    if ((modelSearch.getManufacturerIds() != null && !modelSearch.getManufacturerIds().isEmpty())
        || modelSearch.getOrderBy() > 0
        || (modelSearch.getProperties() != null && !modelSearch.getProperties().isEmpty())) {
      modelSearch.setKeyword(null);
      modelSearch.setPageIndex(0);
      search =
          "filter="
              + Base64.encodeBase64String(StringUtils.getBytesUtf8(new Gson().toJson(modelSearch)));
    }

    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);
    }
  }