portal商品展示功能逻辑
生活随笔
收集整理的這篇文章主要介紹了
portal商品展示功能逻辑
小編覺得挺不錯(cuò)的,現(xiàn)在分享給大家,幫大家做個(gè)參考.
看下接口:
返回值:
門戶商品搜索功能的實(shí)現(xiàn):
根據(jù)分類id進(jìn)行搜索,根據(jù)關(guān)鍵詞進(jìn)行搜索,并按照一定的順序排序
業(yè)務(wù)邏輯:
1、查詢分類是否存在。
2、如果分類存在,則遞歸分類,展示父類商品,子類商品,孫子類商品,遞歸獲取商品的分類id,獲取到該id下面的子類商品
3、根據(jù)關(guān)鍵字和分類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();//這里需要根據(jù)商品id來判斷這個(gè)類別是否存在,如果分類不存在,則返回給前臺一個(gè)空即可if (categoryId != null) {mmall_category category = categoryMapper.selectByPrimaryKey(categoryId);if (category == null && StringUtils.isBlank(keyword)) {//如果分類為空,則返回該類別為空的結(jié)果集,不報(bào)錯(cuò)PageHelper.startPage(pageNum, pageSize);List<ProductListVo> list = Lists.newArrayList();PageInfo info = new PageInfo(list);return ServerResponse.createBySuccess(info);}//商品展示的時(shí)候,當(dāng)我們在搜索某一類商品的時(shí)候,它會有很多子類,比如手機(jī)類別,有華為型號的,華為型號下面又有很多子類,所以遞歸函數(shù)來調(diào)用categoryIdList = categoryService.getDeepCategory(category.getId()).getData();}//接下來判斷關(guān)鍵字是否為空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)){//進(jìn)行分割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);}
遞歸的代碼:
//這里遞歸獲取子節(jié)點(diǎn),即當(dāng)前節(jié)點(diǎn)下的所以子節(jié)點(diǎn)以及子節(jié)點(diǎn)的節(jié)點(diǎn)都要列出@Overridepublic ServerResponse<List<Integer>> getDeepCategory(Integer categoryId) {Set<mmall_category> categorySet= Sets.newHashSet();//這是guava緩存的技巧//在這里進(jìn)行初始化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);}//遞歸代碼的實(shí)現(xiàn)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其實(shí)是用來存儲這些列表數(shù)據(jù)的//查找子節(jié)點(diǎn)遞歸函數(shù)必須有一個(gè)終止條件List<mmall_category> categoryList=mmall_categoryMapper.selectCategoryByParentId(categoryId);for (mmall_category categoryItem: categoryList) {findChildrenCategory(categorySet,categoryItem.getId());}return categorySet;}
?
總結(jié)
以上是生活随笔為你收集整理的portal商品展示功能逻辑的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: Winform开发框架重构总结
- 下一篇: js中将字符串转换成json的三种方式