perf(手机端): 搜索模块

优化热搜展示
master
hequan_waynaqua 4 years ago
parent 4d0feb0137
commit 2ddbc36bc7

@ -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<SearchVO> page = getPage();
// 查询
@ -86,7 +85,18 @@ public class SearchController extends BaseController {
return R.success().add("goods", Collections.emptyList());
}
List<Goods> goodsList = iGoodsService.list(new QueryWrapper<Goods>().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<SearchHistory> historyList = iSearchHistoryService.selectHostList();
List<String> keywordList = historyList.stream().map(SearchHistory::getKeyword).collect(Collectors.toList());
return R.success().add("data", keywordList);
}
}

@ -42,6 +42,11 @@ public class SearchHistory implements Serializable {
*/
private String from;
/**
* 0 1
*/
private Boolean hasGoods;
/**
*
*/

@ -16,4 +16,6 @@ import java.util.List;
public interface SearchHistoryMapper extends BaseMapper<SearchHistory> {
List<SearchHistory> selectSeachHistoryList(Long memberId);
List<SearchHistory> selectHostList();
}

@ -15,5 +15,15 @@ import java.util.List;
*/
public interface ISearchHistoryService extends IService<SearchHistory> {
/**
*
* @return
*/
List<SearchHistory> selectList();
/**
*
* @return
*/
List<SearchHistory> selectHostList();
}

@ -29,4 +29,9 @@ public class SearchHistoryServiceImpl extends ServiceImpl<SearchHistoryMapper, S
Long memberId = SecurityUtils.getUserId();
return searchHistoryMapper.selectSeachHistoryList(memberId);
}
@Override
public List<SearchHistory> selectHostList() {
return searchHistoryMapper.selectHostList();
}
}

@ -8,6 +8,7 @@
<result column="user_id" property="userId" />
<result column="keyword" property="keyword" />
<result column="from" property="from" />
<result column="has_goods" property="hasGoods" />
<result column="create_time" property="createTime" />
<result column="update_time" property="updateTime" />
<result column="del_flag" property="delFlag" />
@ -16,7 +17,7 @@
<!-- 通用查询结果列 -->
<sql id="selectSerchHistoryVo">
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
</sql>
@ -28,4 +29,18 @@
</where>
</select>
<select id="selectHostList" resultMap="SearchHistoryResult">
SELECT
keyword,
COUNT( keyword ) AS num
FROM
shop_search_history
WHERE
has_goods = 1
GROUP BY
keyword
ORDER BY
num DESC
LIMIT 10
</select>
</mapper>

Loading…
Cancel
Save