Commit 27fdb913 authored by 张辰's avatar 张辰

代码风格修正

parent e80fc01a
...@@ -50,7 +50,7 @@ public class ThemeAnalysDO { ...@@ -50,7 +50,7 @@ public class ThemeAnalysDO {
private Double userWeight = 0.0; private Double userWeight = 0.0;
public Double getScore() { public Double calcScore() {
//质量=帖子质量+用户质量 //质量=帖子质量+用户质量
double w = (double) (viewCount * 0.1 + forwardCount * 3 + commentCount * 2 + likeCount * 1 + collectCount * 3) + userWeight; double w = (double) (viewCount * 0.1 + forwardCount * 3 + commentCount * 2 + likeCount * 1 + collectCount * 3) + userWeight;
double i = 1;//初试权重 double i = 1;//初试权重
......
...@@ -165,7 +165,7 @@ public class ThemeManager { ...@@ -165,7 +165,7 @@ public class ThemeManager {
.themeType(ThemeTypeEnum.FORWARD.getCode()) .themeType(ThemeTypeEnum.FORWARD.getCode())
.build(); .build();
if (StringUtils.isEmpty(req.getEditThemeId()) || req.getEditThemeId() == req.getFormerThemeId()) { if (StringUtils.isEmpty(req.getEditThemeId()) || req.getEditThemeId().equals(req.getFormerThemeId())) {
//新建 //新建
themeService.insertTheme(themeEntity); themeService.insertTheme(themeEntity);
} else { } else {
...@@ -183,6 +183,7 @@ public class ThemeManager { ...@@ -183,6 +183,7 @@ public class ThemeManager {
List<ThemeEntity> themeEntities = new ArrayList<>(); List<ThemeEntity> themeEntities = new ArrayList<>();
if (ThemeListTypeEnum.RECOMMEND.getCode().equals(req.getType())) { if (ThemeListTypeEnum.RECOMMEND.getCode().equals(req.getType())) {
//推荐 //推荐
List<String> recommendThemeIds = recommendService.getRecommendThemes(req.getLastId(), req.getPageSize(), userId); List<String> recommendThemeIds = recommendService.getRecommendThemes(req.getLastId(), req.getPageSize(), userId);
themeEntities = themeService.queryByThemeIds(recommendThemeIds); themeEntities = themeService.queryByThemeIds(recommendThemeIds);
themeEntities = RankUtils.sortThemeEntityByIds(themeEntities, recommendThemeIds); themeEntities = RankUtils.sortThemeEntityByIds(themeEntities, recommendThemeIds);
...@@ -271,7 +272,6 @@ public class ThemeManager { ...@@ -271,7 +272,6 @@ public class ThemeManager {
themeEntities = themeService.queryThemesByUserId(req.getUserId(), req.getLastId(), req.getPageSize()); themeEntities = themeService.queryThemesByUserId(req.getUserId(), req.getLastId(), req.getPageSize());
break; break;
case 2://回复 case 2://回复
List<ThemeQo> commentThemeList = getCommentThemeQos(req, userId); List<ThemeQo> commentThemeList = getCommentThemeQos(req, userId);
return commentThemeList; return commentThemeList;
case 3://点赞 case 3://点赞
......
...@@ -30,7 +30,7 @@ public class TopicManager { ...@@ -30,7 +30,7 @@ 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) {
throw new BizException("话题名称已存在:" + topicTitle); throw new BizException("话题名称已存在:" + topicTitle);
} }
topicService.addTopic(topicTitle, userId); topicService.addTopic(topicTitle, userId);
......
package com.tanpu.community.service;
import com.tanpu.common.api.CommonResp;
import com.tanpu.common.exception.BizException;
import com.tanpu.community.api.beans.vo.feign.fatools.UserInfoNew;
import com.tanpu.community.feign.fatools.FeignClientForFatools;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
@Service
public class FeignService {
@Autowired
private FeignClientForFatools fatools;
public UserInfoNew getUserInfoById(String userId) {
CommonResp<UserInfoNew> userInfoNewCommonResp = fatools.queryUsersListNew(userId);
if (userInfoNewCommonResp.isNotSuccess()) {
throw new BizException("内部接口调用失败");
}
return userInfoNewCommonResp.getData();
}
}
...@@ -37,6 +37,9 @@ public class RankService { ...@@ -37,6 +37,9 @@ public class RankService {
@Autowired @Autowired
private VisitSummaryService visitSummaryService; private VisitSummaryService visitSummaryService;
@Autowired
private FeignService feignService;
@Autowired @Autowired
private RedisCache redisCache; private RedisCache redisCache;
...@@ -44,7 +47,7 @@ public class RankService { ...@@ -44,7 +47,7 @@ public class RankService {
private FeignClientForFatools feignClientForFatools; private FeignClientForFatools feignClientForFatools;
//最热 //最热
private List<ThemeAnalysDO> rankThemeList = new ArrayList<>(); private List<ThemeAnalysDO> hotestThemes = new ArrayList<>();
private List<TopicRankQo> rankTopicList = new ArrayList<>(); private List<TopicRankQo> rankTopicList = new ArrayList<>();
...@@ -80,28 +83,21 @@ public class RankService { ...@@ -80,28 +83,21 @@ public class RankService {
//查询用户质量 //查询用户质量
String authorId = theme.getAuthorId(); String authorId = theme.getAuthorId();
UserInfoNew authorInfo = redisCache.getObject(StringUtils.joinWith(CACHE_FEIGN_USER_INFO, authorId), UserInfoNew authorInfo = redisCache.getObject(StringUtils.joinWith(CACHE_FEIGN_USER_INFO, authorId),
60 * 10, () -> this.getUserInfo(authorId), UserInfoNew.class); 60 * 10, () -> feignService.getUserInfoById(authorId), UserInfoNew.class);
if (authorInfo == null || authorInfo.getLevelGrade() == null) { if (authorInfo == null || authorInfo.getLevelGrade() == null) {
theme.setUserWeight(0.0); theme.setUserWeight(0.0);
} else { } else {
// 设置用户权重
theme.setUserWeight(authorInfo.getLevelGrade() * 1.0); theme.setUserWeight(authorInfo.getLevelGrade() * 1.0);
} }
} }
//打分 //打分
Map<ThemeAnalysDO, Double> map = themeAnalysDOS.stream().collect(Collectors.toMap(o -> o, ThemeAnalysDO::getScore)); Map<ThemeAnalysDO, Double> map = themeAnalysDOS.stream().collect(Collectors.toMap(o -> o, ThemeAnalysDO::calcScore));
//排序 //排序
rankThemeList = map.entrySet().stream().sorted(Map.Entry.comparingByValue(Comparator.reverseOrder())).map(e -> e.getKey()).collect(Collectors.toList()); hotestThemes = map.entrySet().stream()
.sorted(Map.Entry.comparingByValue(Comparator.reverseOrder()))
} .map(e -> e.getKey()).collect(Collectors.toList());
private UserInfoNew getUserInfo(String authorId) {
CommonResp<UserInfoNew> userInfoNewCommonResp = feignClientForFatools.queryUsersListNew(authorId);
if (userInfoNewCommonResp.isNotSuccess()) {
throw new BizException("内部接口调用失败");
}
return userInfoNewCommonResp.getData();
} }
...@@ -123,7 +119,8 @@ public class RankService { ...@@ -123,7 +119,8 @@ public class RankService {
topic.setDisscussCount(0); topic.setDisscussCount(0);
continue; continue;
} }
//浏览量 // 浏览量
// todo 批量查询
Integer topicPV = visitSummaryService.queryTopicDetailVisit(topic.getTopicId()); Integer topicPV = visitSummaryService.queryTopicDetailVisit(topic.getTopicId());
Integer themePV = visitSummaryService.queryThemeVisit(themeIds); Integer themePV = visitSummaryService.queryThemeVisit(themeIds);
topic.setViewCount(topicPV + themePV); topic.setViewCount(topicPV + themePV);
...@@ -132,7 +129,10 @@ public class RankService { ...@@ -132,7 +129,10 @@ public class RankService {
topic.setDisscussCount(themeIds.size() + commentCount); topic.setDisscussCount(themeIds.size() + commentCount);
} }
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());
this.rankTopicList = rankList; this.rankTopicList = rankList;
this.rankTopicListTop4 = rankList.stream().limit(4).collect(Collectors.toList()); this.rankTopicListTop4 = rankList.stream().limit(4).collect(Collectors.toList());
...@@ -148,7 +148,7 @@ public class RankService { ...@@ -148,7 +148,7 @@ public class RankService {
* @return * @return
*/ */
public List<String> getHotAndNewThemes(Integer hotCount, Integer newCount, String userId) { public List<String> getHotAndNewThemes(Integer hotCount, Integer newCount, String userId) {
Set<String> hotThemeIds = this.rankThemeList.stream().limit(hotCount) Set<String> hotThemeIds = this.hotestThemes.stream().limit(hotCount)
.filter(o -> !userId.equals(o.getAuthorId())) .filter(o -> !userId.equals(o.getAuthorId()))
.map(ThemeAnalysDO::getThemeId) .map(ThemeAnalysDO::getThemeId)
.collect(Collectors.toSet()); .collect(Collectors.toSet());
...@@ -193,18 +193,18 @@ public class RankService { ...@@ -193,18 +193,18 @@ public class RankService {
return rankTopicListTop4; return rankTopicListTop4;
} }
public List<ThemeAnalysDO> getRankThemeList() { public List<ThemeAnalysDO> getHotestThemes() {
if (this.rankThemeList.size() == 0) { if (this.hotestThemes.size() == 0) {
rankThemes(); rankThemes();
} }
return rankThemeList; return hotestThemes;
} }
public List<String> getRankThemeListByTopic(String topicId) { public List<String> getRankThemeListByTopic(String topicId) {
if (this.rankThemeList.size() == 0) { if (this.hotestThemes.size() == 0) {
this.rankThemes(); this.rankThemes();
} }
return rankThemeList.stream().filter(o -> topicId.equals(o.getTopicId())) return hotestThemes.stream().filter(o -> topicId.equals(o.getTopicId()))
.map(ThemeAnalysDO::getThemeId) .map(ThemeAnalysDO::getThemeId)
.collect(Collectors.toList()); .collect(Collectors.toList());
} }
......
...@@ -42,16 +42,16 @@ public class RecommendService { ...@@ -42,16 +42,16 @@ public class RecommendService {
@Autowired @Autowired
private VisitSummaryService visitSummaryService; private VisitSummaryService visitSummaryService;
//最新 // 最新
private List<ThemeAnalysDO> recentThemeList = new ArrayList<>(); private List<ThemeAnalysDO> recentThemeList = new ArrayList<>();
//推荐 // 推荐
private Map<String, List<String>> recommondList = new HashMap<>(); private Map<String, List<String>> recommondList = new HashMap<>();
// // 用户已经看过的
private Map<String, Set<String>> returnedIdsMap = new HashMap<>(); private Map<String, Set<String>> returnedIdsMap = new HashMap<>();
public List<String> getRecommendThemes(String lastId, Integer pageSize, String userId) { public List<String> getRecommendThemes(String lastId, Integer pageSize, String userId) {
//最热话题,剔除当前用户的主题 //最热话题,剔除当前用户的主题
List<String> hotThemeIds = rankService.getRankThemeList().stream() List<String> hotThemeIds = rankService.getHotestThemes().stream()
.filter(o -> !userId.equals(o.getAuthorId())) .filter(o -> !userId.equals(o.getAuthorId()))
.map(ThemeAnalysDO::getThemeId) .map(ThemeAnalysDO::getThemeId)
.collect(Collectors.toList()); .collect(Collectors.toList());
...@@ -65,7 +65,7 @@ public class RecommendService { ...@@ -65,7 +65,7 @@ public class RecommendService {
//推荐话题 //推荐话题
List<String> recThemeIds = getPythonRecommendList(userId); List<String> recThemeIds = getPythonRecommendList(userId);
//混合 // 混合 如果重新搜索,则刷新返回id
Set<String> returnedIds = (StringUtils.isEmpty(lastId)) || !returnedIdsMap.containsKey(userId) Set<String> returnedIds = (StringUtils.isEmpty(lastId)) || !returnedIdsMap.containsKey(userId)
|| returnedIdsMap.get(userId) == null ? || returnedIdsMap.get(userId) == null ?
new HashSet<>() : returnedIdsMap.get(userId); new HashSet<>() : returnedIdsMap.get(userId);
...@@ -130,6 +130,7 @@ public class RecommendService { ...@@ -130,6 +130,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, String userId) { 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;
......
...@@ -47,7 +47,7 @@ public class ThemeService { ...@@ -47,7 +47,7 @@ public class ThemeService {
themeMapper.update(themeEntity, new LambdaUpdateWrapper<ThemeEntity>().eq(ThemeEntity::getThemeId, themeId)); themeMapper.update(themeEntity, new LambdaUpdateWrapper<ThemeEntity>().eq(ThemeEntity::getThemeId, themeId));
} }
//n天内所有主题 //n天内发表的所有主题
public List<ThemeEntity> queryRecentdays(Integer days) { public List<ThemeEntity> queryRecentdays(Integer days) {
LambdaQueryWrapper<ThemeEntity> queryWrapper = new LambdaQueryWrapper<ThemeEntity>() LambdaQueryWrapper<ThemeEntity> queryWrapper = new LambdaQueryWrapper<ThemeEntity>()
.eq(ThemeEntity::getDeleteTag, DeleteTagEnum.NOT_DELETED.getCode()) .eq(ThemeEntity::getDeleteTag, DeleteTagEnum.NOT_DELETED.getCode())
......
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