Commit 7754ef0c authored by 刘基明's avatar 刘基明

topic返回对象优化

parent 2a77678a
...@@ -17,7 +17,7 @@ import java.util.List; ...@@ -17,7 +17,7 @@ import java.util.List;
@NoArgsConstructor @NoArgsConstructor
public class ThemeContentQo { public class ThemeContentQo {
@ApiModelProperty(value = "RelTypeEnum类型,108:文本,88:产品 3:直播 6:短视频 303:新版课程-视频,新版课程-音频,109:单图(长文) 110:多图(讨论)") @ApiModelProperty(value = "RelTypeEnum类型,108:文本,88:产品 3:直播 6:短视频 303:新版课程-视频,304: 新版课程-音频,109:单图(长文) 110:多图(讨论)")
private String type; private String type;
@ApiModelProperty(value = "文本的值是内容,附件的值为id") @ApiModelProperty(value = "文本的值是内容,附件的值为id")
......
...@@ -76,7 +76,7 @@ public enum RelTypeEnum { ...@@ -76,7 +76,7 @@ public enum RelTypeEnum {
/** /**
* 新版课程 * 新版课程
*/ */
NEW_COURSE_SECTION_VIDEO(304, "新版课程 - 小节 - 视频", 303), NEW_COURSE_SECTION_VIDEO(304, "新版课程 - 小节 - 视频", 304),
/** /**
* 新版课程附件 * 新版课程附件
......
...@@ -4,13 +4,11 @@ import com.tanpu.common.exception.BizException; ...@@ -4,13 +4,11 @@ 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.TopicDTO;
import com.tanpu.community.api.beans.vo.TopicDataAnalysDTO; import com.tanpu.community.api.beans.vo.TopicDataAnalysDTO;
import com.tanpu.community.api.constants.RedisKeyConstant; import com.tanpu.community.api.constants.RedisKeyConstant;
import com.tanpu.community.api.enums.CollectionTypeEnum; import com.tanpu.community.api.enums.CollectionTypeEnum;
import com.tanpu.community.dao.entity.community.TopicEntity; 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.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;
...@@ -18,7 +16,6 @@ import org.springframework.stereotype.Service; ...@@ -18,7 +16,6 @@ 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 {
...@@ -46,44 +43,29 @@ public class TopicManager { ...@@ -46,44 +43,29 @@ public class TopicManager {
//新增话题 //新增话题
public void insertTopic(String topicTitle, String userId) { public void insertTopic(String topicTitle, String userId) {
if (topicService.queryByTitile(topicTitle) == null) { if (topicService.queryByTitile(topicTitle) == null) {
topicService.addTopic(topicTitle, userId); throw new BizException("话题名称已存在:"+topicTitle);
} }
return; topicService.addTopic(topicTitle, userId);
} }
//话题详情列表 //首页-话题标签
public List<TopicDTO> getAllTopicDetail() { public List<TopicRankQo> getTop4TopicTitles() {
return ConvertUtil.topicEntitiesToDTOs(topicService.queryAll()); return rankService.getRankTopicListTop4();
} }
//话题简介列表 //话题搜索列表
public Page<TopicRankQo> getAllTopicBriefInfo(TopicSearchReq req) { public Page<TopicRankQo> getAllTopicBriefInfo(TopicSearchReq req) {
if (rankService.rankTopicList.size()==0){ return PageUtils.page(req.getPage(), rankService.getRankTopicList());
rankService.rankTopics();
}
return PageUtils.page(req.getPage(), rankService.rankTopicList);
} }
//话题详情页 //话题详情页
public TopicRankQo getDetail(String topicId) { public TopicRankQo getDetail(String topicId) {
if (rankService.rankTopicList.size()==0){ return rankService.getTopicDetail(topicId);
rankService.rankTopics();
}
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<TopicRankQo> getTop4TopicTitles() {
if (rankService.rankTopicList.size()==0){
rankService.rankTopics();
}
return rankService.rankTopicListTop4;
}
public void setTopTopic(String topicId, boolean setTop) { public void setTopTopic(String topicId, boolean setTop) {
TopicEntity topicEntity = topicService.queryById(topicId); TopicEntity topicEntity = topicService.queryById(topicId);
if (topicEntity == null) { if (topicEntity == null) {
......
...@@ -28,12 +28,15 @@ public class RankService { ...@@ -28,12 +28,15 @@ public class RankService {
private VisitSummaryService visitSummaryService; private VisitSummaryService visitSummaryService;
public List<String> rankThemeList = new ArrayList<>(); private List<String> rankThemeList = new ArrayList<>();
public List<TopicRankQo> rankTopicList = new ArrayList<>(); private List<TopicRankQo> rankTopicList = new ArrayList<>();
public List<TopicRankQo> rankTopicListTop4 = new ArrayList<>(); private List<TopicRankQo> rankTopicListTop4 = new ArrayList<>();
/**
* 计算主题热度排行
*/
public void rankThemes() { public void rankThemes() {
List<ThemeEntity> themeEntities = themeService.queryAll(); List<ThemeEntity> themeEntities = themeService.queryAll();
List<ThemeAnalysDO> themeAnalysDOS = ConvertUtil.themeEntityToAnalysDOs(themeEntities); List<ThemeAnalysDO> themeAnalysDOS = ConvertUtil.themeEntityToAnalysDOs(themeEntities);
...@@ -84,12 +87,18 @@ public class RankService { ...@@ -84,12 +87,18 @@ public class RankService {
Map<TopicRankQo, Integer> map = topicRankQos.stream().collect(Collectors.toMap(o -> o, TopicRankQo::getRank)); 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()); 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; this.rankTopicList = rankList;
rankTopicListTop4 = rankList.stream().limit(4).collect(Collectors.toList()); this.rankTopicListTop4 = rankList.stream().limit(4).collect(Collectors.toList());
return; return;
} }
/**
* 最新和热门主题集合
* @param hotCount
* @param newCount
* @return
*/
public List<String> getHotAndNewThemes(Integer hotCount, Integer newCount) { public List<String> getHotAndNewThemes(Integer hotCount, Integer newCount) {
Set<String> hotThemeIds = this.rankThemeList.stream().limit(hotCount).collect(Collectors.toSet()); Set<String> hotThemeIds = this.rankThemeList.stream().limit(hotCount).collect(Collectors.toSet());
Set<String> newThemeIds = themeService.selectExcludeUser(null, null, newCount) Set<String> newThemeIds = themeService.selectExcludeUser(null, null, newCount)
...@@ -98,4 +107,33 @@ public class RankService { ...@@ -98,4 +107,33 @@ public class RankService {
return new ArrayList<>(hotThemeIds); return new ArrayList<>(hotThemeIds);
} }
/**
* 话题详情
* @param topicId 话题Id
* @return
*/
public TopicRankQo getTopicDetail(String topicId){
if (this.rankTopicList.size()==0){
rankTopics();
}
List<TopicRankQo> matchTopic = this.rankTopicList.stream().filter(o -> o.getTopicId().equals(topicId)).limit(1).collect(Collectors.toList());
matchTopic.add(new TopicRankQo());
return matchTopic.get(0);
}
public List<String> getRankThemeList() {
return rankThemeList;
}
public List<TopicRankQo> getRankTopicList() {
if (this.rankTopicList.size()==0){
this.rankTopics();
}
return rankTopicList;
}
public List<TopicRankQo> getRankTopicListTop4() {
return rankTopicListTop4;
}
} }
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