Commit 48a22737 authored by 张辰's avatar 张辰

修改推荐页

parent 9341711a
......@@ -9,6 +9,8 @@ import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;
import java.time.LocalDateTime;
import java.util.Date;
import java.util.List;
/**
......@@ -31,4 +33,7 @@ public interface VisitSummaryMapper extends BaseMapper<VisitSummaryEntity> {
@Select("select ref_id as id, count(1) as times from visit_summary ${ew.customSqlSegment}")
List<TimesCountEntity> selectCountByThemeIds(@Param(Constants.WRAPPER)LambdaQueryWrapper wrapper);
@Select("select ref_id from visit_summary where visitor_id=#{visitorId} and date(create_time) between #{startDate} and #{endDate}")
List<String> selectRefIdByUserIdAndCreateBetween(@Param("visitorId") String visitorId, @Param("startDate") Date startDate, @Param("endDate") Date endDate);
}
......@@ -26,6 +26,7 @@ import com.tanpu.community.util.RankUtils;
import com.tanpu.community.util.TencentcloudUtils;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.collections4.CollectionUtils;
import org.apache.commons.collections4.ListUtils;
import org.apache.commons.lang3.StringUtils;
import org.apache.commons.lang3.exception.ExceptionUtils;
import org.springframework.beans.BeanUtils;
......@@ -187,51 +188,50 @@ public class ThemeManager {
public ThemeListResp queryThemes(ThemeListReq req, String userId) {
Integer pageStart = (req.page.pageNumber - 1) * req.page.pageSize;
Integer pageSize = req.page.pageSize;
Integer querySize = pageSize * 2;
Integer querySize = pageSize * 3;
List<ThemeEntity> themes = new ArrayList<>();
if (ThemeListTypeEnum.RECOMMEND.getCode().equals(req.getType())) {
//推荐
List<String> recmdIds = recommendService.getRecommendThemes(pageStart, querySize, userId);
//去重已看过(查看正文)
recmdIds = visitSummaryService.filterUserNotVisited(userId, recmdIds);
// 需要筛掉用户访问过详情的 & 最近出现在列表页过的.
List<String> visitedIds = visitSummaryService.queryUserRecentVisited(userId);
List<String> excludes = ListUtils.union(req.excludeIds, visitedIds);
List<String> recmdIds = recommendService.getRecommendThemes(pageStart, querySize, userId, excludes);
recmdIds = BizUtils.subList(recmdIds, pageStart, pageSize);
themes = themeService.queryByThemeIds(recmdIds);
themes = RankUtils.sortThemeEntityByIds(themes, recmdIds);
// filter用户自己的
themes = themes.stream().filter(t -> {
return !userId.equals(t.getAuthorId()) && !req.excludeIds.contains(t.getThemeId());
}).collect(Collectors.toList());
// todo pageNo pageSize
themes = BizUtils.subList(themes, 0, req.page.pageSize);
} else if (ThemeListTypeEnum.FOLLOW.getCode().equals(req.getType())) {
//TODO 临时埋点,接入新埋点后删除
// TODO 临时埋点,接入新埋点后删除
if (CollectionUtils.isEmpty(req.getExcludeIds())) {
visitSummaryService.addPageView(userId, userId, VisitTypeEnum.FOLLOW_THEME_VIEW);
}
//根据关注列表查询
// 根据关注列表查询,按时间倒序
List<String> fansList = followRelService.queryFansByFollowerId(userId);
themes = themeService.queryByUserIds(fansList, pageStart, pageSize);
themes = themeService.queryByUserIdsCreateDesc(fansList, pageStart, pageSize);
} else if (ThemeListTypeEnum.TOPIC_HOT.getCode().equals(req.getType())) {
//根据话题查询热门
// 根据话题查询热门
if (StringUtils.isEmpty(req.getTopicId())) {
throw new BizException("TopicId为空");
}
List<String> rankThemeIds = rankService.getRankThemeListByTopic(req.getTopicId(),pageSize,req.excludeIds);
List<String> rankThemeIds = rankService.getRankThemeListByTopic(req.getTopicId(), req.excludeIds);
rankThemeIds = BizUtils.subList(rankThemeIds, pageStart, pageSize);
themes = themeService.queryByThemeIds(rankThemeIds);
themes = RankUtils.sortThemeEntityByIds(themes, rankThemeIds);
} else if (ThemeListTypeEnum.TOPIC_LATEST.getCode().equals(req.getType())) {
//根据话题查询最新
if (StringUtils.isEmpty(req.getTopicId())) {
throw new BizException("TopicId为空");
}
themes = themeService.queryNewestByTopic(req.topicId, pageStart, pageSize);
themes = themeService.queryNewestByTopic(req.topicId, pageStart, querySize, req.excludeIds);
}
ThemeListResp resp = new ThemeListResp();
resp.excludeIds = req.excludeIds;
resp.excludeIds.addAll(themes.stream().map(ThemeEntity::getThemeId).collect(Collectors.toList()));
......
......@@ -197,13 +197,13 @@ public class RankService {
return hotestThemes;
}
public List<String> getRankThemeListByTopic(String topicId, Integer pageSize, List<String> excludeIds) {
public List<String> getRankThemeListByTopic(String topicId, List<String> excludeIds) {
if (this.hotestThemes.size() == 0) {
this.rankThemes();
}
HashSet<String> excludSet = new HashSet<>(excludeIds);
return hotestThemes.stream().filter(o -> topicId.equals(o.getTopicId()) && !excludSet.contains(o.getThemeId()))
.limit(pageSize)
return hotestThemes.stream()
.filter(o -> topicId.equals(o.getTopicId()) && !excludeIds.contains(o.getThemeId()))
.map(ThemeAnalysDO::getThemeId)
.collect(Collectors.toList());
}
......
......@@ -49,24 +49,32 @@ public class RecommendService {
// 推荐
private Map<String, List<String>> recommondList = new HashMap<>();
public List<String> getRecommendThemes(Integer pageStart, Integer pageSize, String userId) {
//最热话题,剔除当前用户的主题
// todo pageNo , pageSize
public List<String> getRecommendThemes(Integer pageStart, Integer pageSize, String userId, List<String> excludeIds) {
// 最热话题,筛掉用户发表的 & 最近看过的 & excludeIds
List<String> hotThemeIds = rankService.getHotestThemes().stream()
.map(ThemeAnalysDO::getThemeId)
.collect(Collectors.toList());
.filter(theme -> {
return !excludeIds.contains(theme.getThemeId()) && !userId.equals(theme.getAuthorId());
})
.map(ThemeAnalysDO::getThemeId).collect(Collectors.toList());
hotThemeIds = BizUtils.subList(hotThemeIds, pageStart, pageSize);
//最新话题,剔除当前用户的主题
//最新话题,筛掉用户发表的 & 最近看过的 & excludeIds
List<String> newThemeIds = getNewestThemes().stream()
.map(ThemeAnalysDO::getThemeId)
.collect(Collectors.toList());
.filter(theme -> {
return !excludeIds.contains(theme.getThemeId()) && !userId.equals(theme.getAuthorId());
})
.map(ThemeAnalysDO::getThemeId).collect(Collectors.toList());
newThemeIds = BizUtils.subList(newThemeIds, pageStart, pageSize);
//推荐话题
List<String> recThemeIds = getPythonRecommendList(userId);
List<String> result = mergeRecommend(hotThemeIds, newThemeIds, recThemeIds);
result = result.stream().limit(pageSize).collect(Collectors.toList());
return result;
List<String> recThemeIds = getPythonRecommendList(userId).stream()
.filter(id -> {
return !excludeIds.contains(id);
}).collect(Collectors.toList());
recThemeIds = BizUtils.subList(recThemeIds, pageStart, pageSize);
// merge
return mergeRecommend(hotThemeIds, newThemeIds, recThemeIds);
}
// 获取最新话题
......
......@@ -206,9 +206,10 @@ public class ThemeService {
* @param pageSize 查询数量
* @return
*/
public List<ThemeEntity> queryNewestByTopic(String topidId, Integer pageNo, Integer pageSize) {
public List<ThemeEntity> queryNewestByTopic(String topidId, Integer pageNo, Integer pageSize, List<String> excludeIds) {
LambdaQueryWrapper<ThemeEntity> queryWrapper = new LambdaQueryWrapper<ThemeEntity>()
.eq(ThemeEntity::getTopicId, topidId)
.notIn(ThemeEntity::getThemeId, excludeIds)
.last("limit " + pageNo + ", " + pageSize)
.orderByDesc(ThemeEntity::getCreateTime)
.eq(ThemeEntity::getDeleteTag, DeleteTagEnum.NOT_DELETED.getCode());
......@@ -233,7 +234,7 @@ public class ThemeService {
* @param pageSize
* @return
*/
public List<ThemeEntity> queryByUserIds(List<String> userIds, Integer pageStart, Integer pageSize) {
public List<ThemeEntity> queryByUserIdsCreateDesc(List<String> userIds, Integer pageStart, Integer pageSize) {
if (CollectionUtils.isEmpty(userIds)){
return Collections.emptyList();
}
......
......@@ -9,11 +9,13 @@ import com.tanpu.community.dao.mapper.community.VisitSummaryMapper;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.collections4.CollectionUtils;
import org.apache.commons.collections4.ListUtils;
import org.apache.commons.lang3.time.DateUtils;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import javax.annotation.Resource;
import java.time.LocalDateTime;
import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
......@@ -26,6 +28,14 @@ public class VisitSummaryService {
@Resource
private VisitSummaryMapper visitSummaryMapper;
// 获取用户7天内访问过的
public List<String> queryUserRecentVisited(String userId) {
Date endDate = new Date();
Date startDate = DateUtils.addDays(endDate, -7);
List<String> visited = visitSummaryMapper.selectRefIdByUserIdAndCreateBetween(userId, startDate, endDate);
return visited;
}
// 从refIds中去掉用户已经访问过的
public List<String> filterUserNotVisited(String userId, List<String> refIds) {
if (refIds.isEmpty()) {
......@@ -38,7 +48,6 @@ public class VisitSummaryService {
return ListUtils.subtract(refIds, visited);
}
public List<String> queryUserVisited(String userId) {
List<String> visited = visitSummaryMapper.selectList(new LambdaQueryWrapper<VisitSummaryEntity>()
.eq(VisitSummaryEntity::getVisitorId, userId))
.stream().map(VisitSummaryEntity::getRefId).distinct().collect(Collectors.toList());
......
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