From 2ddbc36bc7b3431fe967fb80803ad1bc58901b97 Mon Sep 17 00:00:00 2001 From: hequan_waynaqua <1669738430@qq.com> Date: Mon, 26 Oct 2020 21:32:39 +0800 Subject: [PATCH] =?UTF-8?q?perf(=E6=89=8B=E6=9C=BA=E7=AB=AF):=20=E6=90=9C?= =?UTF-8?q?=E7=B4=A2=E6=A8=A1=E5=9D=97?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 优化热搜展示 --- .../mobile/api/controller/SearchController.java | 14 ++++++++++++-- .../wayn/mobile/api/domain/SearchHistory.java | 5 +++++ .../mobile/api/mapper/SearchHistoryMapper.java | 2 ++ .../api/service/ISearchHistoryService.java | 10 ++++++++++ .../service/impl/SearchHistoryServiceImpl.java | 5 +++++ .../resources/mapper/SearchHistoryMapper.xml | 17 ++++++++++++++++- 6 files changed, 50 insertions(+), 3 deletions(-) diff --git a/waynboot-mobile-api/src/main/java/com/wayn/mobile/api/controller/SearchController.java b/waynboot-mobile-api/src/main/java/com/wayn/mobile/api/controller/SearchController.java index 20ddefd..8677e37 100644 --- a/waynboot-mobile-api/src/main/java/com/wayn/mobile/api/controller/SearchController.java +++ b/waynboot-mobile-api/src/main/java/com/wayn/mobile/api/controller/SearchController.java @@ -61,12 +61,11 @@ public class SearchController extends BaseController { Integer categoryId = searchVO.getCategoryId(); Boolean isHot = searchVO.getIsHot(); Boolean isNew = searchVO.getIsNew(); + SearchHistory searchHistory = new SearchHistory(); if (memberId != null && StringUtils.isNotEmpty(keyword)) { - SearchHistory searchHistory = new SearchHistory(); searchHistory.setCreateTime(LocalDateTime.now()); searchHistory.setUserId(memberId); searchHistory.setKeyword(keyword); - iSearchHistoryService.save(searchHistory); } Page page = getPage(); // 查询 @@ -86,7 +85,18 @@ public class SearchController extends BaseController { return R.success().add("goods", Collections.emptyList()); } List goodsList = iGoodsService.list(new QueryWrapper().in("id", goodsIdList)); + if (goodsList.size() > 0) { + searchHistory.setHasGoods(true); + iSearchHistoryService.save(searchHistory); + } return R.success().add("goods", goodsList); } + @GetMapping("hotList") + public R hotList() { + List historyList = iSearchHistoryService.selectHostList(); + List keywordList = historyList.stream().map(SearchHistory::getKeyword).collect(Collectors.toList()); + return R.success().add("data", keywordList); + } + } diff --git a/waynboot-mobile-api/src/main/java/com/wayn/mobile/api/domain/SearchHistory.java b/waynboot-mobile-api/src/main/java/com/wayn/mobile/api/domain/SearchHistory.java index 41ec3a1..3381016 100644 --- a/waynboot-mobile-api/src/main/java/com/wayn/mobile/api/domain/SearchHistory.java +++ b/waynboot-mobile-api/src/main/java/com/wayn/mobile/api/domain/SearchHistory.java @@ -42,6 +42,11 @@ public class SearchHistory implements Serializable { */ private String from; + /** + * 搜索记录是否有商品结果(0没有 1有) + */ + private Boolean hasGoods; + /** * 创建时间 */ diff --git a/waynboot-mobile-api/src/main/java/com/wayn/mobile/api/mapper/SearchHistoryMapper.java b/waynboot-mobile-api/src/main/java/com/wayn/mobile/api/mapper/SearchHistoryMapper.java index a618e8c..2b39d5e 100644 --- a/waynboot-mobile-api/src/main/java/com/wayn/mobile/api/mapper/SearchHistoryMapper.java +++ b/waynboot-mobile-api/src/main/java/com/wayn/mobile/api/mapper/SearchHistoryMapper.java @@ -16,4 +16,6 @@ import java.util.List; public interface SearchHistoryMapper extends BaseMapper { List selectSeachHistoryList(Long memberId); + + List selectHostList(); } diff --git a/waynboot-mobile-api/src/main/java/com/wayn/mobile/api/service/ISearchHistoryService.java b/waynboot-mobile-api/src/main/java/com/wayn/mobile/api/service/ISearchHistoryService.java index 5bc1895..b25c4a2 100644 --- a/waynboot-mobile-api/src/main/java/com/wayn/mobile/api/service/ISearchHistoryService.java +++ b/waynboot-mobile-api/src/main/java/com/wayn/mobile/api/service/ISearchHistoryService.java @@ -15,5 +15,15 @@ import java.util.List; */ public interface ISearchHistoryService extends IService { + /** + * 分页查询搜索历史 + * @return 分页列表 + */ List selectList(); + + /** + * 查询热搜列表 + * @return 热搜列表 + */ + List selectHostList(); } diff --git a/waynboot-mobile-api/src/main/java/com/wayn/mobile/api/service/impl/SearchHistoryServiceImpl.java b/waynboot-mobile-api/src/main/java/com/wayn/mobile/api/service/impl/SearchHistoryServiceImpl.java index 1aee385..403a566 100644 --- a/waynboot-mobile-api/src/main/java/com/wayn/mobile/api/service/impl/SearchHistoryServiceImpl.java +++ b/waynboot-mobile-api/src/main/java/com/wayn/mobile/api/service/impl/SearchHistoryServiceImpl.java @@ -29,4 +29,9 @@ public class SearchHistoryServiceImpl extends ServiceImpl selectHostList() { + return searchHistoryMapper.selectHostList(); + } } diff --git a/waynboot-mobile-api/src/main/resources/mapper/SearchHistoryMapper.xml b/waynboot-mobile-api/src/main/resources/mapper/SearchHistoryMapper.xml index c01fbb5..b6403d6 100644 --- a/waynboot-mobile-api/src/main/resources/mapper/SearchHistoryMapper.xml +++ b/waynboot-mobile-api/src/main/resources/mapper/SearchHistoryMapper.xml @@ -8,6 +8,7 @@ + @@ -16,7 +17,7 @@ select id, - user_id, keyword, from, create_time, update_time, del_flag + user_id, keyword, from, create_time, has_goods, update_time, del_flag from search_history s @@ -28,4 +29,18 @@ +