zoukankan      html  css  js  c++  java
  • portal商品展示功能逻辑

    看下接口:

    返回值:

    门户商品搜索功能的实现:

    根据分类id进行搜索,根据关键词进行搜索,并按照一定的顺序排序

    业务逻辑:

    1、查询分类是否存在。

    2、如果分类存在,则递归分类,展示父类商品,子类商品,孙子类商品,递归获取商品的分类id,获取到该id下面的子类商品

    3、根据关键字和分类id查询商品

     //前端显示商品列表,并按照一定的顺序排序
        @Override
        public ServerResponse<PageInfo> getPortalProductList(Integer categoryId, String keyword, String orderBy, Integer pageNum, Integer pageSize) {
            if (StringUtils.isBlank(keyword) && categoryId == null) {
                return ServerResponse.createByErrorCodeMessage(ResponseCode.ILLEGAL_ARGUMENT.getCode(), ResponseCode.ILLEGAL_ARGUMENT.getDesc());
            }
            List<Integer> categoryIdList = Lists.newArrayList();
            //这里需要根据商品id来判断这个类别是否存在,如果分类不存在,则返回给前台一个空即可
            if (categoryId != null) {
                mmall_category category = categoryMapper.selectByPrimaryKey(categoryId);
                if (category == null && StringUtils.isBlank(keyword)) {
                    //如果分类为空,则返回该类别为空的结果集,不报错
                    PageHelper.startPage(pageNum, pageSize);
                    List<ProductListVo> list = Lists.newArrayList();
                    PageInfo info = new PageInfo(list);
                    return ServerResponse.createBySuccess(info);
                }
                //商品展示的时候,当我们在搜索某一类商品的时候,它会有很多子类,比如手机类别,有华为型号的,华为型号下面又有很多子类,所以递归函数来调用
    
                categoryIdList = categoryService.getDeepCategory(category.getId()).getData();
            }
            //接下来判断关键字是否为空
            if (keyword != null) {
                keyword = new StringBuilder().append("%").append(keyword).append("%").toString();
            }
            //排序处理
            PageHelper.startPage(pageNum, pageSize);
           /* if (StringUtils.isNotBlank(orderBy)){
                //分页的排序
                if (Const.ProductListOrderBy.PRICE_ASC_DESC.contains(orderBy)){
                    //进行分割
                   String[] orderArray=orderBy.split("_");
                   //排序
                   PageHelper.orderBy(orderArray[0]+" "+orderArray[1]);
                }
            }*/
            List<mmall_product> productList = productMapper.selectProtalProduct(StringUtils.isBlank(keyword) ? null : keyword, categoryIdList.size() == 0 ? null : categoryIdList);
            List<ProductListVo> productListVoList = Lists.newArrayList();
            if (!CollectionUtils.isEmpty(productList)) {
                for (mmall_product product : productList) {
                    ProductListVo productListVo = this.productConvertVo(product);
                    productListVoList.add(productListVo);
                }
            }
            PageInfo info = new PageInfo(productListVoList);
            return ServerResponse.createBySuccess(info);
        }
    

      

    递归的代码:

    //这里递归获取子节点,即当前节点下的所以子节点以及子节点的节点都要列出
        @Override
        public ServerResponse<List<Integer>> getDeepCategory(Integer categoryId) {
           Set<mmall_category> categorySet= Sets.newHashSet();//这是guava缓存的技巧
          //在这里进行初始化Set集合
           findChildrenCategory(categorySet,categoryId);
           List<Integer> list= Lists.newArrayList();
           if (categoryId!=null){
               for (mmall_category categoryItem:categorySet) {
                   list.add(categoryItem.getId());
               }
           }
           return ServerResponse.createBySuccess(list);
        }
        //递归代码的实现
        public Set<mmall_category> findChildrenCategory(Set<mmall_category> categorySet,Integer categoryId){
          mmall_category category=mmall_categoryMapper.selectByPrimaryKey(categoryId);
          if (category!=null){
              categorySet.add(category);
          }
          //categorySet其实是用来存储这些列表数据的
          //查找子节点递归函数必须有一个终止条件
           List<mmall_category> categoryList=mmall_categoryMapper.selectCategoryByParentId(categoryId);
            for (mmall_category categoryItem: categoryList) {
                findChildrenCategory(categorySet,categoryItem.getId());
            }
            return categorySet;
        }
    

      

  • 相关阅读:
    NOTIFYICONDATA结构
    OA系统权限管理设计(转载)
    JQuery打造下拉框联动效果
    MapReduce实现矩阵相乘
    Linux系统下安装phpmyadmin方法
    个人封装的一个Camera类
    从零开始学C++之STL(七):剩下5种算法代码分析与使用示例(remove 、rotate 、sort、lower_bound、accumulate)
    Java实现 蓝桥杯VIP 算法提高 3-1课后习题2
    Java实现 蓝桥杯VIP 算法提高 3-1课后习题2
    Java实现 蓝桥杯VIP 算法提高 3-1课后习题2
  • 原文地址:https://www.cnblogs.com/fengli9998/p/7979199.html
Copyright © 2011-2022 走看看