Commit c6f57eff authored by 张辰's avatar 张辰

remove excludeIds

parent a016a8f0
...@@ -9,5 +9,5 @@ import java.util.List; ...@@ -9,5 +9,5 @@ import java.util.List;
public class ThemeFullSearchReq { public class ThemeFullSearchReq {
public Pageable page; public Pageable page;
public String keyword; public String keyword;
public List<String> excludeIds; public String ident;
} }
...@@ -25,5 +25,5 @@ public class ThemeListReq { ...@@ -25,5 +25,5 @@ public class ThemeListReq {
@NotNull(message = "分页") @NotNull(message = "分页")
public Pageable page; public Pageable page;
public List<String> excludeIds; public String ident;
} }
...@@ -8,11 +8,9 @@ import java.util.List; ...@@ -8,11 +8,9 @@ import java.util.List;
@Data @Data
public class ThemeFullSearchResp { public class ThemeFullSearchResp {
public List<String> excludeIds;
public List<ThemeQo> themes; public List<ThemeQo> themes;
public ThemeFullSearchResp() { public ThemeFullSearchResp() {
this.excludeIds = new ArrayList<>();
this.themes = new ArrayList<>(); this.themes = new ArrayList<>();
} }
} }
...@@ -8,5 +8,4 @@ import java.util.List; ...@@ -8,5 +8,4 @@ import java.util.List;
@Data @Data
public class ThemeListResp { public class ThemeListResp {
public List<ThemeQo> themes; public List<ThemeQo> themes;
public List<String> excludeIds;
} }
...@@ -46,12 +46,12 @@ public class RedisCache { ...@@ -46,12 +46,12 @@ public class RedisCache {
delete(key); delete(key);
} }
private String get(String key) { public String get(String key) {
key = cacheName + ":" + key; key = cacheName + ":" + key;
return redisHelper.get(key); return redisHelper.get(key);
} }
private void put(String key, Object obj, Integer expireSeconds) { public void put(String key, Object obj, Integer expireSeconds) {
key = cacheName + ":" + key; key = cacheName + ":" + key;
String value = JsonUtil.toJson(obj); String value = JsonUtil.toJson(obj);
if (expireSeconds == 0) { if (expireSeconds == 0) {
......
...@@ -32,7 +32,7 @@ public class SearchController { ...@@ -32,7 +32,7 @@ public class SearchController {
@PostMapping(value = "/themeFullText") @PostMapping(value = "/themeFullText")
@ResponseBody @ResponseBody
public CommonResp<ThemeFullSearchResp> themeFullText(@RequestBody ThemeFullSearchReq req) { public CommonResp<ThemeFullSearchResp> themeFullText(@RequestBody ThemeFullSearchReq req) {
ThemeFullSearchResp resp = themeManager.themeFullSearch(req.keyword, req.page.pageNumber, req.page.pageSize, req.excludeIds, userHolder.getUserId()); ThemeFullSearchResp resp = themeManager.themeFullSearch(req.keyword, req.page.pageNumber, req.page.pageSize, req.ident, userHolder.getUserId());
return CommonResp.success(resp); return CommonResp.success(resp);
} }
......
package com.tanpu.community.manager; package com.tanpu.community.manager;
import com.alibaba.fastjson.JSON;
import com.google.common.collect.Sets; import com.google.common.collect.Sets;
import com.tanpu.common.api.CommonResp; import com.tanpu.common.api.CommonResp;
import com.tanpu.common.exception.BizException; import com.tanpu.common.exception.BizException;
...@@ -89,7 +90,15 @@ public class ThemeManager { ...@@ -89,7 +90,15 @@ public class ThemeManager {
@Autowired @Autowired
private RecommendService recommendService; private RecommendService recommendService;
public ThemeFullSearchResp themeFullSearch(String keyword, Integer pageNo, Integer pageSize, List<String> excludeIds, String userId) { public ThemeFullSearchResp themeFullSearch(String keyword, Integer pageNo, Integer pageSize, String ident, String userId) {
List<String> excludeIds;
if (pageNo > 1) {
String l = redisCache.get("themeFullSearch_" + ident);
excludeIds = StringUtils.isBlank(l) ? new ArrayList<>() : JSON.parseArray(l, String.class);
} else {
excludeIds = new ArrayList<>();
}
Integer from = (pageNo - 1) * pageSize; Integer from = (pageNo - 1) * pageSize;
ThemeFullSearchResp resp = new ThemeFullSearchResp(); ThemeFullSearchResp resp = new ThemeFullSearchResp();
...@@ -115,7 +124,9 @@ public class ThemeManager { ...@@ -115,7 +124,9 @@ public class ThemeManager {
for (ThemeQo theme : resp.themes) { for (ThemeQo theme : resp.themes) {
theme.briefContent4FullSearch = BizUtils.getThemeContent(keyword, theme); theme.briefContent4FullSearch = BizUtils.getThemeContent(keyword, theme);
} }
resp.excludeIds.addAll(filterEsIds);
excludeIds.addAll(resp.themes.stream().map(ThemeQo::getThemeId).collect(Collectors.toList()));
redisCache.put("themeFullSearch_" + ident, JSON.toJSONString(excludeIds), 60 * 60 * 6);
return resp; return resp;
} }
...@@ -126,7 +137,6 @@ public class ThemeManager { ...@@ -126,7 +137,6 @@ public class ThemeManager {
*/ */
@Transactional @Transactional
public CreateThemeResp publishTheme(CreateThemeReq req, String userId) { public CreateThemeResp publishTheme(CreateThemeReq req, String userId) {
// 保存主题表 // 保存主题表
ThemeEntity themeEntity = new ThemeEntity(); ThemeEntity themeEntity = new ThemeEntity();
BeanUtils.copyProperties(req, themeEntity); BeanUtils.copyProperties(req, themeEntity);
...@@ -193,6 +203,14 @@ public class ThemeManager { ...@@ -193,6 +203,14 @@ public class ThemeManager {
*/ */
// 查询主题列表:推荐/关注/热门/最新 // 查询主题列表:推荐/关注/热门/最新
public ThemeListResp queryThemes(ThemeListReq req, String userId) { public ThemeListResp queryThemes(ThemeListReq req, String userId) {
List<String> excludeIds;
if (req.page.pageNumber > 1) {
String l = redisCache.get("queryThemes_" + req.ident);
excludeIds = StringUtils.isBlank(l) ? new ArrayList<>() : JSON.parseArray(l, String.class);
} else {
excludeIds = new ArrayList<>();
}
Integer pageStart = (req.page.pageNumber - 1) * req.page.pageSize; Integer pageStart = (req.page.pageNumber - 1) * req.page.pageSize;
Integer pageSize = req.page.pageSize; Integer pageSize = req.page.pageSize;
Integer querySize = pageSize * 3; Integer querySize = pageSize * 3;
...@@ -203,7 +221,7 @@ public class ThemeManager { ...@@ -203,7 +221,7 @@ public class ThemeManager {
//推荐 //推荐
// 需要筛掉用户访问过详情的 & 最近出现在列表页过的. // 需要筛掉用户访问过详情的 & 最近出现在列表页过的.
List<String> visitedIds = visitLogService.queryUserRecentVisited(userId); List<String> visitedIds = visitLogService.queryUserRecentVisited(userId);
List<String> excludes = ListUtils.union(req.excludeIds, visitedIds); List<String> excludes = ListUtils.union(excludeIds, visitedIds);
List<String> recmdIds = recommendService.getRecommendThemes(pageStart, querySize, userId, excludes); List<String> recmdIds = recommendService.getRecommendThemes(pageStart, querySize, userId, excludes);
recmdIds = BizUtils.subList(recmdIds, pageStart, pageSize); recmdIds = BizUtils.subList(recmdIds, pageStart, pageSize);
...@@ -212,7 +230,7 @@ public class ThemeManager { ...@@ -212,7 +230,7 @@ public class ThemeManager {
} else if (ThemeListTypeEnum.FOLLOW.getCode().equals(req.getType())) { } else if (ThemeListTypeEnum.FOLLOW.getCode().equals(req.getType())) {
// TODO 临时埋点,接入新埋点后删除 // TODO 临时埋点,接入新埋点后删除
if (CollectionUtils.isEmpty(req.getExcludeIds())) { if (CollectionUtils.isEmpty(excludeIds)) {
visitLogService.addPageView(userId, userId, VisitTypeEnum.FOLLOW_THEME_VIEW); visitLogService.addPageView(userId, userId, VisitTypeEnum.FOLLOW_THEME_VIEW);
} }
// 根据关注列表查询,按时间倒序 // 根据关注列表查询,按时间倒序
...@@ -225,7 +243,7 @@ public class ThemeManager { ...@@ -225,7 +243,7 @@ public class ThemeManager {
throw new BizException("TopicId为空"); throw new BizException("TopicId为空");
} }
List<String> rankThemeIds = rankService.getRankThemeListByTopic(req.getTopicId(), req.excludeIds); List<String> rankThemeIds = rankService.getRankThemeListByTopic(req.getTopicId(), excludeIds);
rankThemeIds = BizUtils.subList(rankThemeIds, pageStart, pageSize); rankThemeIds = BizUtils.subList(rankThemeIds, pageStart, pageSize);
themes = themeService.queryByThemeIds(rankThemeIds); themes = themeService.queryByThemeIds(rankThemeIds);
...@@ -236,14 +254,15 @@ public class ThemeManager { ...@@ -236,14 +254,15 @@ public class ThemeManager {
if (StringUtils.isEmpty(req.getTopicId())) { if (StringUtils.isEmpty(req.getTopicId())) {
throw new BizException("TopicId为空"); throw new BizException("TopicId为空");
} }
themes = themeService.queryNewestByTopic(req.topicId, pageStart, querySize, req.excludeIds); themes = themeService.queryNewestByTopic(req.topicId, pageStart, querySize, excludeIds);
} }
ThemeListResp resp = new ThemeListResp(); ThemeListResp resp = new ThemeListResp();
resp.excludeIds = req.excludeIds;
resp.excludeIds.addAll(themes.stream().map(ThemeEntity::getThemeId).collect(Collectors.toList()));
resp.themes = convertEntityToQo(themes, userId); resp.themes = convertEntityToQo(themes, userId);
excludeIds.addAll(resp.themes.stream().map(ThemeQo::getThemeId).collect(Collectors.toList()));
redisCache.put("queryThemes_" + req.ident, JSON.toJSONString(excludeIds), 60 * 60 * 6);
//组装详情 //组装详情
return resp; return resp;
} }
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment