Esempio n. 1
0
  /** 官网二级分类列表 */
  @RequestMapping(value = "/plist/{productCategoryId}", method = RequestMethod.GET)
  public String plist(
      @PathVariable Long productCategoryId,
      Long brandId,
      Long promotionId,
      Long[] tagIds,
      BigDecimal startPrice,
      BigDecimal endPrice,
      OrderType orderType,
      Boolean isOutOfStock,
      Integer pageNumber,
      Integer pageSize,
      HttpServletRequest request,
      ModelMap model) {
    ProductCategory productCategory = productCategoryService.find(productCategoryId);

    List<ProductCategory> childrenpCategory =
        productCategoryService.findChildrenByParent(productCategoryId);
    if (productCategory == null) {
      throw new ResourceNotFoundException();
    }
    Brand brand = brandService.find(brandId);
    Promotion promotion = promotionService.find(promotionId);
    List<Tag> tags = tagService.findList(tagIds);
    Map<Attribute, String> attributeValue = new HashMap<Attribute, String>();
    if (productCategory != null) {
      //			System.out.println("treePath=========="+productCategory.getTreePath());
      if (productCategory.getTreePath().length() >= 10) {
        String treePath = productCategory.getTreePath().substring(6, 10);
        //				System.out.println("treePath=========="+productCategory.getTreePath().substring(6,
        // 10));
        //				if(treePath.equals("1080")||treePath.equals("1082")){
        model.addAttribute("treePath", treePath);
        //				}
      }
      Set<Attribute> attributes = productCategory.getAttributes();
      for (Attribute attribute : attributes) {
        String value = request.getParameter("attribute_" + attribute.getId());
        if (StringUtils.isNotEmpty(value) && attribute.getOptions().contains(value)) {
          attributeValue.put(attribute, value);
        }
      }
    }
    Pageable pageable = new Pageable(pageNumber, pageSize);
    model.addAttribute("orderTypes", OrderType.values());
    model.addAttribute("productCategory", productCategory);
    model.addAttribute("childrenpCategory", childrenpCategory);
    model.addAttribute("brand", brand);
    model.addAttribute("promotion", promotion);
    model.addAttribute("tags", tags);
    model.addAttribute("isOutOfStock", isOutOfStock);
    model.addAttribute("attributeValue", attributeValue);
    model.addAttribute("startPrice", startPrice);
    model.addAttribute("endPrice", endPrice);
    model.addAttribute("orderType", orderType);
    model.addAttribute("pageNumber", pageNumber);
    model.addAttribute("pageSize", pageSize);
    model.addAttribute(
        "page",
        productService.findPageGW(
            productCategory,
            brand,
            promotion,
            tags,
            attributeValue,
            startPrice,
            endPrice,
            true,
            true,
            null,
            false,
            isOutOfStock,
            null,
            orderType,
            pageable));
    //		System.out.println("plist电热水器="+productService.findPage(productCategory, brand, promotion,
    //														tags, attributeValue, startPrice, endPrice,
    //														true, true, null, false, isOutOfStock, null, orderType, pageable).getTotal());
    return "/gw/product/plist";
  }