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

topic返回对象优化

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