/** * 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); } }
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); }
public void getAncestors(ItemSearch itemSearch, Map<String, Object> parentCategorys) { List<Object> cats = new ArrayList<>(); if (itemSearch.getCategoryIds() == null || itemSearch.getCategoryIds().isEmpty()) { parentCategorys.put("cats", cats); } else { try { List<Category> ancestors = categoryService.getAncestors(itemSearch.getCategoryIds().get(0)); for (Category cat : ancestors) { cats.add(categoryService.getChilds(cat.getId())); } parentCategorys.put("cats", cats); parentCategorys.put("ancestors", ancestors); } catch (Exception ex) { } } }
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); }
/** * 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(); }
/** * Danh sách sản phẩm cần review * * @param modelMap * @param session * @param page * @return */ @RequestMapping( value = {"/reviewitem"}, method = RequestMethod.GET) public String reviewList( ModelMap modelMap, HttpSession session, @RequestParam(value = "page", defaultValue = "0") int page) { ItemSearch itemSearch = new ItemSearch(); itemSearch.setStatus(4); List<String> cateIds = new ArrayList<>(); List<String> shopCateIds = new ArrayList<>(); List<String> manufIds = new ArrayList<>(); List<String> modelIds = new ArrayList<>(); if (itemSearch.getCategoryIds() == null) { itemSearch.setCategoryIds(new ArrayList<String>()); } itemSearch.setSource(ItemSource.SELLER); long createTime = 1388509200 * 1000L; itemSearch.setCreateTimeFrom(createTime); itemSearch.setCreateTimeTo(System.currentTimeMillis()); if (session.getAttribute("itemSearch") != null && page != 0) { itemSearch = (ItemSearch) session.getAttribute("itemSearch"); } else { session.setAttribute("itemSearch", itemSearch); } Map<String, Object> parentCategorys = new HashMap<>(); getAncestors(itemSearch, parentCategorys); if (page > 0) { itemSearch.setPageIndex(page - 1); } else { itemSearch.setPageIndex(0); } itemSearch.setPageSize(50); DataPage<Item> itemPage = itemService.searchMongo(itemSearch); for (Item item : itemPage.getData()) { if (item.getCategoryId() != null && !item.getCategoryId().equals("") && !cateIds.contains(item.getCategoryId())) { cateIds.add(item.getCategoryId()); } if (item.getShopCategoryId() != null && !item.getShopCategoryId().equals("") && !shopCateIds.contains(item.getShopCategoryId())) { shopCateIds.add(item.getShopCategoryId()); } if (item.getManufacturerId() != null && !item.getManufacturerId().equals("") && !manufIds.contains(item.getManufacturerId())) { manufIds.add(item.getManufacturerId()); } if (item.getModelId() != null && !item.getModelId().equals("") && !modelIds.contains(item.getModelId())) { modelIds.add(item.getModelId()); } } for (Item item : itemPage.getData()) { List<String> images = new ArrayList<>(); if (item != null && item.getImages() != null && !item.getImages().isEmpty()) { for (String img : item.getImages()) { images.add( imageService.getUrl(img).thumbnail(200, 200, "outbound").getUrl(item.getName())); } item.setImages(images); } if (item.getSellerName() == null || item.getSellerName().equals("")) { try { User seller = userService.get(item.getSellerId()); item.setSellerName(seller.getEmail()); } catch (Exception ex) { } } } List<City> cities = cityService.list(); modelMap.put("itemSearch", itemSearch); modelMap.put("itemPage", itemPage); modelMap.put("cities", cities); modelMap.put("itemCates", categoryService.getCategories(cateIds)); modelMap.put("itemShopCates", shopCategoryService.get(shopCateIds)); modelMap.put("itemManuf", manufacturerService.getManufacturers(manufIds)); modelMap.put("itemModels", modelService.getModels(modelIds)); modelMap.put( "clientScript", "category = " + gson.toJson(categoryService.getChilds(null)) + ",cities=" + gson.toJson(cities) + ";reviewitem.init({parentCategorys:" + gson.toJson(parentCategorys) + ", categoryId:'" + (itemSearch.getCategoryIds().isEmpty() ? "" : itemSearch.getCategoryIds().get(0)) + "'});"); return "cp.item.review"; }
/** * Tìm kiếm tất cả sản phẩm * * @param itemSearch * @param session * @param modelMap * @return */ @RequestMapping( value = {"/reviewitem"}, method = RequestMethod.POST) public String reviewSearch( @ModelAttribute("itemSearch") ItemSearch itemSearch, HttpSession session, ModelMap modelMap) { Map<String, Object> parentCategorys = new HashMap<>(); List<String> cateIds = new ArrayList<>(); List<String> shopCateIds = new ArrayList<>(); List<String> manufIds = new ArrayList<>(); List<String> modelIds = new ArrayList<>(); itemSearch.setPageIndex(0); itemSearch.setPageSize(50); if (itemSearch.getCategoryId() != null && !itemSearch.getCategoryId().equals("")) { itemSearch.setCategoryIds(new ArrayList<String>()); itemSearch.getCategoryIds().add(itemSearch.getCategoryId()); } getAncestors(itemSearch, parentCategorys); session.setAttribute("itemSearch", itemSearch); DataPage<Item> itemPage = itemService.searchMongo(itemSearch); for (Item item : itemPage.getData()) { if (item.getCategoryId() != null && !item.getCategoryId().equals("") && !cateIds.contains(item.getCategoryId())) { cateIds.add(item.getCategoryId()); } if (item.getShopCategoryId() != null && !item.getShopCategoryId().equals("") && !shopCateIds.contains(item.getShopCategoryId())) { shopCateIds.add(item.getShopCategoryId()); } if (item.getManufacturerId() != null && !item.getManufacturerId().equals("") && !manufIds.contains(item.getManufacturerId())) { manufIds.add(item.getManufacturerId()); } if (item.getModelId() != null && !item.getModelId().equals("") && !modelIds.contains(item.getModelId())) { modelIds.add(item.getModelId()); } } for (Item item : itemPage.getData()) { List<String> images = new ArrayList<>(); if (item != null && item.getImages() != null && !item.getImages().isEmpty()) { for (String img : item.getImages()) { images.add( imageService.getUrl(img).thumbnail(200, 200, "outbound").getUrl(item.getName())); } item.setImages(images); } if (item.getSellerName() == null || item.getSellerName().equals("")) { try { User seller = userService.get(item.getSellerId()); item.setSellerName(seller.getEmail()); } catch (Exception ex) { } } } if (itemSearch.getCategoryIds() == null) { itemSearch.setCategoryIds(new ArrayList<String>()); } List<City> cities = cityService.list(); modelMap.put("itemSearch", itemSearch); modelMap.put("itemPage", itemPage); modelMap.put("cities", cities); modelMap.put("itemCates", categoryService.getCategories(cateIds)); modelMap.put("itemShopCates", shopCategoryService.get(shopCateIds)); modelMap.put("itemManuf", manufacturerService.getManufacturers(manufIds)); modelMap.put("itemModels", modelService.getModels(modelIds)); modelMap.put( "clientScript", "category = " + gson.toJson(categoryService.getChilds(null)) + ",cities=" + gson.toJson(cities) + ";reviewitem.init({parentCategorys:" + gson.toJson(parentCategorys) + ", categoryId:'" + (itemSearch.getCategoryIds().isEmpty() ? "" : itemSearch.getCategoryIds().get(0)) + "'});"); return "cp.item.review"; }
public static String browse(String id, String name) { ItemSearch itemSearch = new ItemSearch(); itemSearch.setCategoryIds(new ArrayList<String>()); itemSearch.getCategoryIds().add(id); return UrlUtils.browseUrl(itemSearch, name); }
public static String browseUrl(ItemSearch sourceItemSearch, String name, String strChange) { ItemSearch itemSearch; try { itemSearch = (ItemSearch) BeanUtils.cloneBean(sourceItemSearch); itemSearch.setManufacturerIds(new ArrayList<>(sourceItemSearch.getManufacturerIds())); itemSearch.setModelIds(new ArrayList<>(sourceItemSearch.getModelIds())); itemSearch.setCityIds(new ArrayList<>(sourceItemSearch.getCityIds())); itemSearch.setProperties(new ArrayList<>(sourceItemSearch.getProperties())); } 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("cid")) { if (op.equals("mk")) { itemSearch.setCategoryIds(new ArrayList<String>()); itemSearch.getCategoryIds().add(val); } else if (op.equals("rm")) { itemSearch.setCategoryIds(null); itemSearch.setCategoryId(null); } } if (key.equals("keyword")) { if (op.equals("mk")) { itemSearch.setKeyword(val); } else if (op.equals("rm")) { itemSearch.setKeyword(null); } } if (key.equals("sellerId")) { if (op.equals("mk")) { itemSearch.setSellerId(val); } else if (op.equals("rm")) { itemSearch.setSellerId(null); } } if (key.equals("manufacturers")) { if (op.equals("mk")) { itemSearch.getManufacturerIds().remove(val); itemSearch.getManufacturerIds().add(val); } else if (op.equals("rm")) { itemSearch.getManufacturerIds().remove(val); } else if (op.equals("cl")) { itemSearch.getManufacturerIds().clear(); } } if (key.equals("models")) { if (op.equals("mk")) { itemSearch.getModelIds().remove(val); itemSearch.getModelIds().add(val); } else if (op.equals("rm")) { itemSearch.getModelIds().remove(val); } else if (op.equals("cl")) { itemSearch.getModelIds().clear(); } } 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("properties")) { PropertySearch ps = (PropertySearch) JsonUtils.decode(val, new TypeToken<PropertySearch>() {}.getType()); if (op.equals("mk")) { itemSearch.getProperties().remove(ps); itemSearch.getProperties().add(ps); } else if (op.equals("rm")) { itemSearch.getProperties().remove(ps); } else if (op.equals("cl")) { itemSearch.getProperties().clear(); } } if (key.equals("freeship")) { if (op.equals("mk")) { itemSearch.setFreeShip(true); } else if (op.equals("rm")) { itemSearch.setFreeShip(false); } } if (key.equals("cod")) { if (op.equals("mk")) { itemSearch.setCod(true); } else if (op.equals("rm")) { itemSearch.setCod(false); } } if (key.equals("onlinepayment")) { if (op.equals("mk")) { itemSearch.setOnlinePayment(true); } else if (op.equals("rm")) { itemSearch.setOnlinePayment(false); } } if (key.equals("promotion")) { if (op.equals("mk")) { itemSearch.setPromotion(true); } else if (op.equals("rm")) { itemSearch.setPromotion(false); } } if (key.equals("promotionId")) { if (op.equals("mk")) { itemSearch.setPromotionId(val); } else if (op.equals("rm")) { itemSearch.setPromotionId(null); } } 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("condition")) { try { if (val.equals("NEW")) { itemSearch.setCondition(Condition.NEW); } else if (val.equals("OLD")) { itemSearch.setCondition(Condition.OLD); } else { itemSearch.setCondition(null); } } catch (NumberFormatException ex) { } } if (key.equals("pricefrom")) { try { itemSearch.setPriceFrom(Integer.parseInt(val)); } catch (NumberFormatException ex) { } } if (key.equals("priceto")) { try { itemSearch.setPriceTo(Integer.parseInt(val)); } 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) { } } } } return UrlUtils.browseUrl(itemSearch, name); }