Commit 2a77678a authored by 刘基明's avatar 刘基明

topic返回对象优化

parent 914e30e9
......@@ -6,7 +6,7 @@ import lombok.Data;
@Data
@ApiModel("热点话题对象")
public class TopicHotQo {
public class TopicRankQo {
@ApiModelProperty(value = "话题ID")
private String topicId;
......
......@@ -14,7 +14,7 @@ public class CreateThemeReq {
@NotNull(message = "类型不能为空")
@ApiModelProperty(value = "类型 1:讨论无标题 2:长文有标题 3:转发")
@ApiModelProperty(value = "类型 1:讨论无标题 2:长文有标题")
private Integer themeType;
......
......@@ -2,9 +2,7 @@ package com.tanpu.community.controller;
import com.tanpu.common.api.CommonResp;
import com.tanpu.common.auth.UserHolder;
import com.tanpu.community.api.beans.qo.TopicDetailQo;
import com.tanpu.community.api.beans.qo.TopicHotQo;
import com.tanpu.community.api.beans.qo.TopicTitileQo;
import com.tanpu.community.api.beans.qo.TopicRankQo;
import com.tanpu.community.api.beans.req.page.Page;
import com.tanpu.community.api.beans.req.topic.TopicSearchReq;
import com.tanpu.community.manager.TopicManager;
......@@ -30,25 +28,23 @@ public class TopicController {
@PostMapping(value = "/list")
@ApiOperation("APP全部话题页面,可搜索")
@ResponseBody
public CommonResp<Page<TopicTitileQo>> getTopicBriefInfoList(@RequestBody TopicSearchReq req){
Page<TopicTitileQo> allTopic = topicManager.getAllTopicBriefInfo(req);
return CommonResp.success(allTopic);
public CommonResp<Page<TopicRankQo>> getTopicBriefInfoList(@RequestBody TopicSearchReq req){
return CommonResp.success(topicManager.getAllTopicBriefInfo(req));
}
@GetMapping(value = "/detailPage")
@ApiOperation("话题详情页顶部")
@ResponseBody
public CommonResp<TopicDetailQo> gethotThemes(@RequestParam String topicId){
TopicDetailQo detail = topicManager.getDetail(topicId);
return CommonResp.success(detail);
public CommonResp<TopicRankQo> gethotThemes(@RequestParam String topicId){
return CommonResp.success(topicManager.getDetail(topicId));
}
@GetMapping(value = "/titleList")
@ApiOperation("首页顶部话题标题列")
@ResponseBody
public CommonResp<List<TopicHotQo>> getTitleList(){
return CommonResp.success(topicManager.getHotTopicTitles());
public CommonResp<List<TopicRankQo>> getTitleList(){
return CommonResp.success(topicManager.getTop4TopicTitles());
}
......
......@@ -96,6 +96,9 @@ public class ThemeManager {
}
@Transactional
/**
* 发表主题(可修改)
*/
public CreateThemeResp publishTheme(CreateThemeReq req, String userId) {
//直播类型做转播检查
List<ThemeContentReq> contents = req.getContent();
......@@ -117,7 +120,7 @@ public class ThemeManager {
themeEntity.setAuthorId(userId);
themeEntity.setContent(JsonUtil.toJson(req.getContent()));
//TODO 敏感词过滤
//腾讯云敏感词校验
checkContent(themeEntity.getContent());
if (StringUtils.isEmpty(req.getEditThemeId())) {
......
package com.tanpu.community.manager;
import com.tanpu.common.exception.BizException;
import com.tanpu.community.api.beans.qo.TopicDetailQo;
import com.tanpu.community.api.beans.qo.TopicHotQo;
import com.tanpu.community.api.beans.qo.TopicTitileQo;
import com.tanpu.community.api.beans.qo.TopicRankQo;
import com.tanpu.community.api.beans.req.page.Page;
import com.tanpu.community.api.beans.req.topic.TopicSearchReq;
import com.tanpu.community.api.beans.vo.TopicDTO;
......@@ -14,14 +12,13 @@ import com.tanpu.community.dao.entity.community.TopicEntity;
import com.tanpu.community.service.*;
import com.tanpu.community.util.ConvertUtil;
import com.tanpu.community.util.PageUtils;
import org.apache.commons.collections4.CollectionUtils;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import java.util.HashSet;
import java.util.List;
import java.util.Set;
import java.util.stream.Collectors;
@Service
public class TopicManager {
......@@ -62,56 +59,29 @@ public class TopicManager {
//话题简介列表
public Page<TopicTitileQo> getAllTopicBriefInfo(TopicSearchReq req) {
List<TopicEntity> allTopic = topicService.queryByKeyword(req.getSearchKeyword());
List<TopicTitileQo> topicTitileQos = ConvertUtil.topicEntitiesToBriefDTOs(allTopic);
for (TopicTitileQo topicQo : topicTitileQos) {
//讨论数=发布主题贴数+回复总数
List<String> themeIds = themeService.queryThemeIdsByTopic(topicQo.getTopicId());
Integer commentCount = commentService.getCommentCountByThemeIds(themeIds);
topicQo.setDiscussionCount(String.valueOf(themeIds.size() + commentCount));
//浏览量
Integer topicPV = visitSummaryService.queryTopicDetailVisit(topicQo.getTopicId());
Integer themePV = visitSummaryService.queryThemeVisit(themeIds);
topicQo.setViewCount(String.valueOf(topicPV + themePV));
public Page<TopicRankQo> getAllTopicBriefInfo(TopicSearchReq req) {
if (rankService.rankTopicList.size()==0){
rankService.rankTopics();
}
//TODO 判断顶置
return PageUtils.page(req.getPage(), topicTitileQos);
return PageUtils.page(req.getPage(), rankService.rankTopicList);
}
//话题详情页
public TopicDetailQo getDetail(String topicId) {
TopicEntity topicEntity = topicService.queryById(topicId);
if (topicEntity == null) {
throw new BizException("找不到话题,id:" + topicId);
}
TopicDetailQo topicDetailQo = new TopicDetailQo();
BeanUtils.copyProperties(topicEntity, topicDetailQo);
List<String> themeIds = themeService.queryThemeIdsByTopic(topicId);
if (CollectionUtils.isEmpty(themeIds)) {
topicDetailQo.setViewCount(visitSummaryService.queryTopicDetailVisit(topicId));
topicDetailQo.setDisscussCount(0);
return topicDetailQo;
public TopicRankQo getDetail(String topicId) {
if (rankService.rankTopicList.size()==0){
rankService.rankTopics();
}
//浏览量
Integer topicPV = visitSummaryService.queryTopicDetailVisit(topicId);
Integer themePV = visitSummaryService.queryThemeVisit(themeIds);
topicDetailQo.setViewCount(topicPV + themePV);
//讨论数=发布主题贴数+回复总数
Integer commentCount = commentService.getCommentCountByThemeIds(themeIds);
topicDetailQo.setDisscussCount(themeIds.size() + commentCount);
return topicDetailQo;
List<TopicRankQo> matchTopic = rankService.rankTopicList.stream().filter(o -> o.getTopicId().equals(topicId)).limit(1).collect(Collectors.toList());
matchTopic.add(new TopicRankQo());
return matchTopic.get(0);
}
public List<TopicHotQo> getHotTopicTitles() {
List<TopicHotQo> rankTopicList = rankService.rankTopicList;
if (rankTopicList.size()==0){
public List<TopicRankQo> getTop4TopicTitles() {
if (rankService.rankTopicList.size()==0){
rankService.rankTopics();
}
return rankService.rankTopicList;
return rankService.rankTopicListTop4;
}
public void setTopTopic(String topicId, boolean setTop) {
......
package com.tanpu.community.service;
import com.tanpu.community.api.beans.qo.ThemeAnalysDO;
import com.tanpu.community.api.beans.qo.TopicHotQo;
import com.tanpu.community.api.beans.qo.TopicRankQo;
import com.tanpu.community.api.enums.CollectionTypeEnum;
import com.tanpu.community.api.enums.TopicStatusEnum;
import com.tanpu.community.dao.entity.community.ThemeEntity;
......@@ -30,7 +30,8 @@ public class RankService {
public List<String> rankThemeList = new ArrayList<>();
public List<TopicHotQo> rankTopicList = new ArrayList<>();
public List<TopicRankQo> rankTopicList = new ArrayList<>();
public List<TopicRankQo> rankTopicListTop4 = new ArrayList<>();
public void rankThemes() {
......@@ -61,11 +62,11 @@ public class RankService {
*/
public void rankTopics() {
List<TopicEntity> topicEntities = topicService.queryAll();
List<TopicHotQo> topicHotQos = ConvertUtil.topicEntityToHotQos(topicEntities);
if (topicHotQos.size() == 0) {
List<TopicRankQo> topicRankQos = ConvertUtil.topicEntityToHotQos(topicEntities);
if (topicRankQos.size() == 0) {
return;
}
for (TopicHotQo topic : topicHotQos) {
for (TopicRankQo topic : topicRankQos) {
List<String> themeIds = themeService.queryThemeIdsByTopic(topic.getTopicId());
if (CollectionUtils.isEmpty(themeIds)){
topic.setViewCount(0);
......@@ -80,10 +81,11 @@ public class RankService {
Integer commentCount = commentService.getCommentCountByThemeIds(themeIds);
topic.setDisscussCount(themeIds.size() + commentCount);
}
Map<TopicHotQo, Integer> map = topicHotQos.stream().collect(Collectors.toMap(o -> o, TopicHotQo::getRank));
List<TopicHotQo> rankList = map.entrySet().stream().sorted(Map.Entry.comparingByValue(Comparator.reverseOrder())).map(e -> e.getKey()).limit(4).collect(Collectors.toList());
Map<TopicRankQo, Integer> map = topicRankQos.stream().collect(Collectors.toMap(o -> o, TopicRankQo::getRank));
List<TopicRankQo> rankList = map.entrySet().stream().sorted(Map.Entry.comparingByValue(Comparator.reverseOrder())).map(Map.Entry::getKey).collect(Collectors.toList());
rankList.get(0).setType(TopicStatusEnum.HOTTEST.getCode());
rankTopicList = rankList;
rankTopicListTop4 = rankList.stream().limit(4).collect(Collectors.toList());
return;
}
......
......@@ -18,7 +18,6 @@ import org.springframework.util.StringUtils;
import java.time.LocalDateTime;
import java.time.ZoneOffset;
import java.time.temporal.TemporalField;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
......@@ -94,17 +93,17 @@ public class ConvertUtil {
return topicDTO;
}
public static TopicHotQo topicEntityToHotQo(TopicEntity topicEntity) {
TopicHotQo topicHotQo = new TopicHotQo();
BeanUtils.copyProperties(topicEntity, topicHotQo);
public static TopicRankQo topicEntityToHotQo(TopicEntity topicEntity) {
TopicRankQo topicRankQo = new TopicRankQo();
BeanUtils.copyProperties(topicEntity, topicRankQo);
//2小时内发帖,添加新话题标签
if(TimeUtil.calMinuteTillNow(topicEntity.getCreateTime())<120){
topicHotQo.setType(TopicStatusEnum.NEWEST.getCode());
topicRankQo.setType(TopicStatusEnum.NEWEST.getCode());
}
return topicHotQo;
return topicRankQo;
}
public static List<TopicHotQo> topicEntityToHotQos(List<TopicEntity> topicEntities) {
public static List<TopicRankQo> topicEntityToHotQos(List<TopicEntity> topicEntities) {
if (topicEntities==null){
return Collections.emptyList();
}
......
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