Commit b55058e2 authored by 刘基明's avatar 刘基明

推荐主题

parent cf3b7aed
...@@ -41,7 +41,7 @@ public class CommentQo { ...@@ -41,7 +41,7 @@ public class CommentQo {
@ApiModelProperty(value = "2级评论") @ApiModelProperty(value = "2级评论")
private List<CommentLv2Qo> commentLv2Qos; private List<CommentLv2Qo> commentLv2Qos;
//认证标签相关 // 认证标签相关
@ApiModelProperty("认证标签用-用户等级体系 0 游客 1注册用户 10投资人 20 探普理顾 30 探普专家理顾 40 交易理财师 50 首席投顾") @ApiModelProperty("认证标签用-用户等级体系 0 游客 1注册用户 10投资人 20 探普理顾 30 探普专家理顾 40 交易理财师 50 首席投顾")
private Integer levelGrade; private Integer levelGrade;
@ApiModelProperty("认证标签用-当levelGrade=10有值 1投资萌新 2投资达人") @ApiModelProperty("认证标签用-当levelGrade=10有值 1投资萌新 2投资达人")
......
...@@ -63,9 +63,10 @@ public class CommentManager { ...@@ -63,9 +63,10 @@ public class CommentManager {
commentService.insertComment(commentEntity); commentService.insertComment(commentEntity);
} }
//查询评论 // 查询评论
public List<CommentQo> queryComments(String themeId, String userId) { public List<CommentQo> queryComments(String themeId, String userId) {
List<CommentEntity> commentEntities = commentService.selectByThemeIdAndParentId(themeId, null); // 因为需要排序,所以从库中查询所有评论
List<CommentEntity> commentEntities = commentService.selectByThemeId(themeId);
List<CommentQo> commentQos = ConvertUtil.commentEntity2Qos(commentEntities); List<CommentQo> commentQos = ConvertUtil.commentEntity2Qos(commentEntities);
Set<String> likeCommentList = collectionService.getListByUser(userId, CollectionTypeEnum.LIKE_COMMENT); Set<String> likeCommentList = collectionService.getListByUser(userId, CollectionTypeEnum.LIKE_COMMENT);
......
...@@ -154,7 +154,7 @@ public class ThemeManager { ...@@ -154,7 +154,7 @@ public class ThemeManager {
return CreateThemeResp.builder().themeId(themeEntity.getThemeId()).build(); return CreateThemeResp.builder().themeId(themeEntity.getThemeId()).build();
} }
//转发主题 // 转发主题
public CreateThemeResp forward(ForwardThemeReq req, String userId) { public CreateThemeResp forward(ForwardThemeReq req, String userId) {
ThemeEntity targetTheme = themeService.queryByThemeId(req.getFormerThemeId()); ThemeEntity targetTheme = themeService.queryByThemeId(req.getFormerThemeId());
ThemeEntity themeEntity = ThemeEntity.builder() ThemeEntity themeEntity = ThemeEntity.builder()
...@@ -178,7 +178,7 @@ public class ThemeManager { ...@@ -178,7 +178,7 @@ public class ThemeManager {
} }
//查询主题列表:推荐/关注/热门/最新 // 查询主题列表:推荐/关注/热门/最新
public List<ThemeQo> queryThemes(ThemeListReq req, String userId) { public List<ThemeQo> queryThemes(ThemeListReq req, String userId) {
List<ThemeEntity> themeEntities = new ArrayList<>(); List<ThemeEntity> themeEntities = new ArrayList<>();
if (ThemeListTypeEnum.RECOMMEND.getCode().equals(req.getType())) { if (ThemeListTypeEnum.RECOMMEND.getCode().equals(req.getType())) {
......
...@@ -28,7 +28,7 @@ public class TopicManager { ...@@ -28,7 +28,7 @@ public class TopicManager {
@Resource @Resource
private UserHolder userHolder; private UserHolder userHolder;
//新增话题 // 新增话题
public void insertTopic(String topicTitle, String userId) { public void insertTopic(String topicTitle, String userId) {
if (topicService.queryByTitile(topicTitle) == null) { if (topicService.queryByTitile(topicTitle) == null) {
throw new BizException("话题名称已存在:" + topicTitle); throw new BizException("话题名称已存在:" + topicTitle);
...@@ -37,18 +37,20 @@ public class TopicManager { ...@@ -37,18 +37,20 @@ public class TopicManager {
} }
//首页-话题标签 // 首页-话题标签
public List<TopicRankQo> getTop4TopicTitles() { public List<TopicRankQo> getTop4TopicTitles() {
return rankService.getRankTopicListTop4(); return rankService.getRankTopicListTop4();
} }
//话题搜索列表 // 话题搜索列表
public Page<TopicRankQo> getAllTopicBriefInfo(TopicSearchReq req) { public Page<TopicRankQo> getAllTopicBriefInfo(TopicSearchReq req) {
return PageUtils.page(req.getPage(), rankService.getRankTopicList());
List<TopicRankQo> topicList = rankService.getRankTopicList(req.getSearchKeyword());
return PageUtils.page(req.getPage(), topicList);
} }
//话题详情页 // 话题详情页
public TopicRankQo getDetail(String topicId) { public TopicRankQo getDetail(String topicId) {
//话题详情 //话题详情
visitSummaryService.addPageView(userHolder.getUserId(), topicId, VisitTypeEnum.TOPIC_PAGE_VIEW); visitSummaryService.addPageView(userHolder.getUserId(), topicId, VisitTypeEnum.TOPIC_PAGE_VIEW);
......
...@@ -3,7 +3,6 @@ package com.tanpu.community.service; ...@@ -3,7 +3,6 @@ package com.tanpu.community.service;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.fasterxml.jackson.core.type.TypeReference; import com.fasterxml.jackson.core.type.TypeReference;
import com.tanpu.common.exception.BizException; import com.tanpu.common.exception.BizException;
import com.tanpu.common.redis.RedisKeyHelper;
import com.tanpu.common.uuid.UuidGenHelper; import com.tanpu.common.uuid.UuidGenHelper;
import com.tanpu.community.api.enums.CommentTypeEnum; import com.tanpu.community.api.enums.CommentTypeEnum;
import com.tanpu.community.api.enums.DeleteTagEnum; import com.tanpu.community.api.enums.DeleteTagEnum;
...@@ -41,6 +40,8 @@ public class CommentService { ...@@ -41,6 +40,8 @@ public class CommentService {
public void insertComment(CommentEntity commentEntity) { public void insertComment(CommentEntity commentEntity) {
commentEntity.setCommentId(uuidGenHelper.getUuidStr()); commentEntity.setCommentId(uuidGenHelper.getUuidStr());
commentMapper.insert(commentEntity); commentMapper.insert(commentEntity);
//失效缓存
redisCache.evict(StringUtils.joinWith("_", CACHE_COMMENT_THEMEID, commentEntity.getThemeId()));
} }
...@@ -72,8 +73,8 @@ public class CommentService { ...@@ -72,8 +73,8 @@ public class CommentService {
.stream().map(CommentEntity::getAuthorId).collect(Collectors.toSet()); .stream().map(CommentEntity::getAuthorId).collect(Collectors.toSet());
} }
public List<CommentEntity> selectByThemeIdAndParentId(String themeId, String parentId) { public List<CommentEntity> selectByThemeId(String themeId) {
return redisCache.getList(StringUtils.joinWith("_", CACHE_COMMENT_THEMEID, themeId, parentId), return redisCache.getList(StringUtils.joinWith("_", CACHE_COMMENT_THEMEID, themeId),
60, () -> { 60, () -> {
LambdaQueryWrapper<CommentEntity> queryWrapper = new LambdaQueryWrapper<CommentEntity>() LambdaQueryWrapper<CommentEntity> queryWrapper = new LambdaQueryWrapper<CommentEntity>()
.eq(CommentEntity::getThemeId, themeId) .eq(CommentEntity::getThemeId, themeId)
......
...@@ -55,7 +55,7 @@ public class RankService { ...@@ -55,7 +55,7 @@ public class RankService {
*/ */
public void rankThemes() { public void rankThemes() {
//7天内所有主题进行热度值排序 //7天内所有主题进行热度值排序
List<ThemeEntity> themeEntities = themeService.queryRecentdays(7); List<ThemeEntity> themeEntities = themeService.queryRecentdays(4);
List<ThemeAnalysDO> themeAnalysDOS = ConvertUtil.themeEntityToAnalysDOs(themeEntities); List<ThemeAnalysDO> themeAnalysDOS = ConvertUtil.themeEntityToAnalysDOs(themeEntities);
for (ThemeAnalysDO theme : themeAnalysDOS) { for (ThemeAnalysDO theme : themeAnalysDOS) {
String themeId = theme.getThemeId(); String themeId = theme.getThemeId();
...@@ -166,11 +166,16 @@ public class RankService { ...@@ -166,11 +166,16 @@ public class RankService {
} }
public List<TopicRankQo> getRankTopicList() { public List<TopicRankQo> getRankTopicList(String keyword) {
if (this.rankTopicList.size() == 0) { if (this.rankTopicList.size() == 0) {
this.rankTopics(); this.rankTopics();
} }
if (StringUtils.isEmpty(keyword)){
return rankTopicList; return rankTopicList;
}else {
//过滤关键字
return this.rankTopicList.stream().filter(o->o.getTopicTitle().contains(keyword)).collect(Collectors.toList());
}
} }
public List<TopicRankQo> getRankTopicListTop4() { public List<TopicRankQo> getRankTopicListTop4() {
......
...@@ -66,18 +66,20 @@ public class RecommendService { ...@@ -66,18 +66,20 @@ public class RecommendService {
List<String> recThemeIds = getPythonRecommendList(userId); List<String> recThemeIds = getPythonRecommendList(userId);
//混合 //混合
Set<String> returnedIds = (StringUtils.isEmpty(lastId)) ? new HashSet<>() : returnedIdsMap.get(userId); Set<String> returnedIds = (StringUtils.isEmpty(lastId)) || !returnedIdsMap.containsKey(userId)
|| returnedIdsMap.get(userId) == null ?
new HashSet<>() : returnedIdsMap.get(userId);
List<String> result = new ArrayList<>(); List<String> result = new ArrayList<>();
getResultList(hotThemeIds, 0, newThemeIds, 0, recThemeIds, 0, returnedIds, result, pageSize,userId); getResultList(hotThemeIds, 0, newThemeIds, 0, recThemeIds, 0, returnedIds, result, pageSize, userId);
result = result.stream().limit(pageSize).collect(Collectors.toList()); result = result.stream().limit(pageSize).collect(Collectors.toList());
//记录已返回主题id //记录已返回主题id
if(StringUtils.isEmpty(lastId)){ if (StringUtils.isEmpty(lastId)) {
returnedIdsMap.put(userId,new HashSet<>(result)); returnedIdsMap.put(userId, new HashSet<>(result));
}else { } else {
HashSet<String> newSet = new HashSet<>(); HashSet<String> newSet = new HashSet<>();
newSet.addAll(returnedIdsMap.get(userId)); newSet.addAll(returnedIdsMap.get(userId));
newSet.addAll(result); newSet.addAll(result);
returnedIdsMap.put(userId,newSet); returnedIdsMap.put(userId, newSet);
} }
return result; return result;
} }
...@@ -168,7 +170,7 @@ public class RecommendService { ...@@ -168,7 +170,7 @@ public class RecommendService {
} }
//去重已看过(查看正文) //去重已看过(查看正文)
result = visitSummaryService.filterUserNotVisited(userId,result); result = visitSummaryService.filterUserNotVisited(userId, result);
if (result.size() < pageSize) { if (result.size() < pageSize) {
getResultList(hotThemeIds, hotTag, newThemeIds, newTag, recThemeIds, recTag, returnedIds, result, pageSize, userId); getResultList(hotThemeIds, hotTag, newThemeIds, newTag, recThemeIds, recTag, returnedIds, result, pageSize, userId);
......
...@@ -110,5 +110,5 @@ recommend: ...@@ -110,5 +110,5 @@ recommend:
new: 2 new: 2
python: 1 python: 1
python: python:
enable: true enable: false
url: http://172.168.0.164:9000/api/get_recommend?user_id=2431614397151511 url: http://172.168.0.164:9000/api/get_recommend?user_id=2431614397151511
\ No newline at end of file
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