當前位置:
首頁 >
portal商品展示功能逻辑
發布時間:2025/6/16
39
豆豆
生活随笔
收集整理的這篇文章主要介紹了
portal商品展示功能逻辑
小編覺得挺不錯的,現在分享給大家,幫大家做個參考.
看下接口:
返回值:
門戶商品搜索功能的實現:
根據分類id進行搜索,根據關鍵詞進行搜索,并按照一定的順序排序
業務邏輯:
1、查詢分類是否存在。
2、如果分類存在,則遞歸分類,展示父類商品,子類商品,孫子類商品,遞歸獲取商品的分類id,獲取到該id下面的子類商品
3、根據關鍵字和分類id查詢商品
//前端顯示商品列表,并按照一定的順序排序@Overridepublic 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);}
遞歸的代碼:
//這里遞歸獲取子節點,即當前節點下的所以子節點以及子節點的節點都要列出@Overridepublic 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;}
?
總結
以上是生活随笔為你收集整理的portal商品展示功能逻辑的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: Winform开发框架重构总结
- 下一篇: js中将字符串转换成json的三种方式