예제 #1
0
  public void clearAttributeValue(Attribute attribute) {
    if (attribute == null
        || attribute.getPropertyIndex() == null
        || attribute.getProductCategory() == null) {
      return;
    }

    String jpql =
        "update Goods goods set goods."
            + Goods.ATTRIBUTE_VALUE_PROPERTY_NAME_PREFIX
            + attribute.getPropertyIndex()
            + " = null where goods.productCategory = :productCategory";
    entityManager
        .createQuery(jpql)
        .setParameter("productCategory", attribute.getProductCategory())
        .executeUpdate();
  }
예제 #2
0
  /** 点击商品属性获取结果 */
  @RequestMapping(value = "/slist/{productCategoryId}", method = RequestMethod.GET)
  public String slist(
      @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) {
      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.findPage(
            productCategory,
            brand,
            promotion,
            tags,
            attributeValue,
            startPrice,
            endPrice,
            true,
            true,
            null,
            false,
            isOutOfStock,
            null,
            orderType,
            pageable));
    return "/gw/product/slist";
  }
예제 #3
0
  /** 搜索 */
  @RequestMapping(value = "/search", method = RequestMethod.GET)
  public String search(
      String keyword,
      BigDecimal startPrice,
      BigDecimal endPrice,
      OrderType orderType,
      Integer pageNumber,
      Integer pageSize,
      ModelMap model,
      HttpServletRequest request) {
    System.out.println("gwSearch");
    System.out.println("keyword=" + keyword);
    System.out.println("keyword=" + keyword);
    System.out.println("keyword=" + keyword);

    ProductCategory productCategory = productCategoryService.findProductCategoryByKeyword(keyword);

    Map<Attribute, String> attributeValue = new HashMap<Attribute, String>();
    if (productCategory != null) {
      System.out.println("productCategory=" + productCategory.getName());
      System.out.println("productCategory=" + productCategory.getId());
      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);
        }
      }
    }

    if (StringUtils.isEmpty(keyword)) {
      return ERROR_VIEW;
    }
    Pageable pageable = null;
    if (pageSize != null) {
      pageable = new Pageable(pageNumber, pageSize);
    } else {
      pageable = new Pageable(pageNumber, DEFAULT_PAGE_SIZE);
    }
    Page<Product> page = searchService.search(keyword, startPrice, endPrice, orderType, pageable);
    List<Product> products = page.getContent();
    System.out.println("page.zlh->" + products);
    model.addAttribute("orderTypes", OrderType.values());
    model.addAttribute("productKeyword", keyword);
    model.addAttribute("startPrice", startPrice);
    model.addAttribute("endPrice", endPrice);
    model.addAttribute("orderType", orderType);
    pageable.setSearchValue(keyword);
    pageable.setSearchProperty("name");
    model.addAttribute(
        "page1",
        productService.findPage(
            productCategory,
            null,
            null,
            null,
            attributeValue,
            startPrice,
            endPrice,
            true,
            true,
            null,
            false,
            null,
            null,
            orderType,
            pageable));
    System.out.println(
        productService
            .findPage(
                productCategory,
                null,
                null,
                null,
                attributeValue,
                startPrice,
                endPrice,
                true,
                true,
                null,
                false,
                null,
                null,
                orderType,
                pageable)
            .getTotal());

    model.addAttribute(
        "page",
        productService.findPageByEntcode(
            null,
            null,
            null,
            null,
            null,
            null,
            null,
            null,
            true,
            null,
            null,
            null,
            null,
            OrderType.dateDesc,
            pageable));
    System.out.println(
        productService
            .findPageByEntcode(
                null,
                null,
                null,
                null,
                null,
                null,
                null,
                null,
                true,
                null,
                null,
                null,
                null,
                OrderType.dateDesc,
                pageable)
            .getTotal());

    return "gw/product/search";
  }