Commit 64eb10aa authored by 刘基明's avatar 刘基明

theme添加字段discussContent

parent 8100aa13
...@@ -5,20 +5,14 @@ import com.tanpu.common.exception.BizException; ...@@ -5,20 +5,14 @@ import com.tanpu.common.exception.BizException;
import com.tanpu.community.api.beans.qo.TopicRankQo; import com.tanpu.community.api.beans.qo.TopicRankQo;
import com.tanpu.community.api.beans.req.page.Page; import com.tanpu.community.api.beans.req.page.Page;
import com.tanpu.community.api.beans.req.topic.TopicSearchReq; import com.tanpu.community.api.beans.req.topic.TopicSearchReq;
import com.tanpu.community.api.beans.vo.TopicDataAnalysDTO;
import com.tanpu.community.api.constants.RedisKeyConstant;
import com.tanpu.community.api.enums.CollectionTypeEnum;
import com.tanpu.community.api.enums.VisitTypeEnum; import com.tanpu.community.api.enums.VisitTypeEnum;
import com.tanpu.community.dao.entity.community.TopicEntity;
import com.tanpu.community.service.*; import com.tanpu.community.service.*;
import com.tanpu.community.util.PageUtils; import com.tanpu.community.util.PageUtils;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service; import org.springframework.stereotype.Service;
import javax.annotation.Resource; import javax.annotation.Resource;
import java.util.HashSet;
import java.util.List; import java.util.List;
import java.util.Set;
@Service @Service
public class TopicManager { public class TopicManager {
...@@ -26,18 +20,6 @@ public class TopicManager { ...@@ -26,18 +20,6 @@ public class TopicManager {
@Autowired @Autowired
private TopicService topicService; private TopicService topicService;
@Autowired
private RedisService redisService;
@Autowired
private ThemeService themeService;
@Autowired
private CollectionService collectionService;
@Autowired
private CommentService commentService;
@Autowired @Autowired
private VisitSummaryService visitSummaryService; private VisitSummaryService visitSummaryService;
@Autowired @Autowired
...@@ -74,54 +56,5 @@ public class TopicManager { ...@@ -74,54 +56,5 @@ public class TopicManager {
} }
public void refreshRedisCache() {
List<TopicEntity> topicEntities = topicService.queryAll();
for (TopicEntity topic : topicEntities) {
String topicId = topic.getTopicId();
Long viewCountModify = topic.getViewCntAdjust();
List<String> themeIds = themeService.queryThemeIdsByTopic(topicId);
Integer likeCountByThemeIds = collectionService.getCountByTypeAndIds(themeIds, CollectionTypeEnum.LIKE_THEME);
Integer bookCountByThemeIds = collectionService.getCountByTypeAndIds(themeIds, CollectionTypeEnum.COLLECT_THEME);
Long commentCountByThemeIds = (long) commentService.getCommentCountByThemeIds(themeIds);
Set<String> postUsers = themeService.getPostUserCount(themeIds);
Set<String> commentUsers = commentService.getCommentUserCount(themeIds);
HashSet<String> totalUsers = new HashSet<>(postUsers);
totalUsers.addAll(commentUsers);
redisService.set(RedisKeyConstant.TOPIC_LIKE_COUNT_ + topicId, likeCountByThemeIds);
redisService.set(RedisKeyConstant.TOPIC_BOOK_COUNT_ + topicId, bookCountByThemeIds);
redisService.set(RedisKeyConstant.TOPIC_COMMENT_COUNT_ + topicId, commentCountByThemeIds);
redisService.set(RedisKeyConstant.TOPIC_TOTAL_VIEW_COUNT_ + topicId, commentCountByThemeIds + themeIds.size());
redisService.set(RedisKeyConstant.TOPIC_THEME_COUNT_ + topicId, commentCountByThemeIds + themeIds.size());
redisService.set(RedisKeyConstant.TOPIC_DISCUSS_COUNT_ + topicId, commentCountByThemeIds + themeIds.size());
redisService.set(RedisKeyConstant.TOPIC_POST_USER_COUNT_ + topicId, (long) postUsers.size());
redisService.set(RedisKeyConstant.TOPIC_COMMENT_USER_COUNT_ + topicId, (long) commentUsers.size());
redisService.set(RedisKeyConstant.TOPIC_TOTAL_USER_COUNT_ + topicId, (long) totalUsers.size());
}
}
//返回数据分析
public TopicDataAnalysDTO queryDataAnalysis(String topicId) {
TopicDataAnalysDTO topicDataAnalysDTO = new TopicDataAnalysDTO();
TopicEntity topicEntity = topicService.queryById(topicId);
if (topicEntity == null) {
throw new BizException("话题未找到,id:" + topicId);
}
this.refreshRedisCache();
topicDataAnalysDTO.setId(topicId);
topicDataAnalysDTO.setTopicTitle(topicEntity.getTopicTitle());
topicDataAnalysDTO.setCommentCount(redisService.getInteger(RedisKeyConstant.TOPIC_COMMENT_COUNT_ + topicId));
topicDataAnalysDTO.setPosterCount(redisService.getInteger(RedisKeyConstant.TOPIC_POST_USER_COUNT_ + topicId));
topicDataAnalysDTO.setReplIierCount(redisService.getInteger(RedisKeyConstant.TOPIC_COMMENT_USER_COUNT_ + topicId));
topicDataAnalysDTO.setThemeCount(redisService.getInteger(RedisKeyConstant.TOPIC_THEME_COUNT_ + topicId));
topicDataAnalysDTO.setUserTotalCount(redisService.getInteger(RedisKeyConstant.TOPIC_TOTAL_USER_COUNT_ + topicId));
topicDataAnalysDTO.setViewTotalCount(redisService.getInteger(RedisKeyConstant.TOPIC_TOTAL_VIEW_COUNT_ + topicId));
topicDataAnalysDTO.setViewPageCount(redisService.getInteger(RedisKeyConstant.TOPIC_PAGE_VIEW_COUNT_ + topicId));
return topicDataAnalysDTO;
}
} }
...@@ -39,6 +39,9 @@ public class RecommendService { ...@@ -39,6 +39,9 @@ public class RecommendService {
@Autowired @Autowired
private ThemeService themeService; private ThemeService themeService;
@Autowired
private VisitSummaryService visitSummaryService;
//最新 //最新
private List<ThemeAnalysDO> recentThemeList = new ArrayList<>(); private List<ThemeAnalysDO> recentThemeList = new ArrayList<>();
//推荐 //推荐
...@@ -65,7 +68,7 @@ public class RecommendService { ...@@ -65,7 +68,7 @@ public class RecommendService {
//混合 //混合
Set<String> returnedIds = (StringUtils.isEmpty(lastId)) ? new HashSet<>() : returnedIdsMap.get(userId); Set<String> returnedIds = (StringUtils.isEmpty(lastId)) ? 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); 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)){
...@@ -124,7 +127,7 @@ public class RecommendService { ...@@ -124,7 +127,7 @@ public class RecommendService {
} }
//逐个插入 //逐个插入
private void getResultList(List<String> hotThemeIds, Integer hotTag, List<String> newThemeIds, Integer newTag, List<String> recThemeIds, Integer recTag, Set<String> returnedIds, List<String> result, Integer pageSize) { private void getResultList(List<String> hotThemeIds, Integer hotTag, List<String> newThemeIds, Integer newTag, List<String> recThemeIds, Integer recTag, Set<String> returnedIds, List<String> result, Integer pageSize, String userId) {
if (hotThemeIds.size() <= hotTag && newThemeIds.size() <= newTag && recThemeIds.size() <= recTag) { if (hotThemeIds.size() <= hotTag && newThemeIds.size() <= newTag && recThemeIds.size() <= recTag) {
//所有列表已循环结束,返回 //所有列表已循环结束,返回
return; return;
...@@ -164,10 +167,11 @@ public class RecommendService { ...@@ -164,10 +167,11 @@ public class RecommendService {
} }
} }
//TODO 去重已看过(查看正文) //去重已看过(查看正文)
result = visitSummaryService.filterUserNotVisited(userId,result);
if (result.size() < pageSize) { if (result.size() < pageSize) {
getResultList(hotThemeIds, hotTag, newThemeIds, newTag, recThemeIds, recTag, returnedIds, result, pageSize); getResultList(hotThemeIds, hotTag, newThemeIds, newTag, recThemeIds, recTag, returnedIds, result, pageSize, userId);
} }
} }
......
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