@SuppressWarnings({"unchecked", "rawtypes"})
  public void execute(
      Environment env, Map params, TemplateModel[] loopVars, TemplateDirectiveBody body)
      throws TemplateException, IOException {
    Long articleCategoryId =
        FreemarkerUtils.getParameter(ARTICLE_CATEGORY_ID_PARAMETER_NAME, Long.class, params);
    Long[] tagIds = FreemarkerUtils.getParameter(TAG_IDS_PARAMETER_NAME, Long[].class, params);

    ArticleCategory articleCategory = articleCategoryService.find(articleCategoryId);
    List<Tag> tags = tagService.findList(tagIds);

    List<Article> articles;
    if ((articleCategoryId != null && articleCategory == null)
        || (tagIds != null && tags.isEmpty())) {
      articles = new ArrayList<Article>();
    } else {
      boolean useCache = useCache(env, params);
      String cacheRegion = getCacheRegion(env, params);
      Integer count = getCount(params);
      List<Filter> filters = getFilters(params, Article.class);
      List<Order> orders = getOrders(params);
      if (useCache) {
        articles =
            articleService.findList(articleCategory, tags, count, filters, orders, cacheRegion);
      } else {
        articles = articleService.findList(articleCategory, tags, count, filters, orders);
      }
    }
    setLocalVariable(VARIABLE_NAME, articles, env, body);
  }
Example #2
0
  /** 列表 */
  @RequestMapping(value = "/list", method = RequestMethod.GET)
  public String list(
      Long brandId,
      Long promotionId,
      Long[] tagIds,
      BigDecimal startPrice,
      BigDecimal endPrice,
      OrderType orderType,
      Integer pageNumber,
      Integer pageSize,
      HttpServletRequest request,
      ModelMap model) {
    Brand brand = brandService.find(brandId);
    Promotion promotion = promotionService.find(promotionId);
    List<Tag> tags = tagService.findList(tagIds);
    Pageable pageable = new Pageable(pageNumber, pageSize);
    model.addAttribute("orderTypes", OrderType.values());
    model.addAttribute("brand", brand);
    model.addAttribute("promotion", promotion);
    model.addAttribute("tags", tags);
    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(
            null,
            brand,
            promotion,
            tags,
            null,
            startPrice,
            endPrice,
            true,
            true,
            null,
            false,
            null,
            null,
            orderType,
            pageable));

    if (null != tags
        && tags.size() == 1
        && (tags.get(0).getId() == 405 || tags.get(0).getName().equals("积分"))) {
      System.out.println("检查积分静态页面");
      return "/shop/product/pointsList";
    }
    return "/shop/product/list";
  }
Example #3
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";
  }