Commit 43719a2f authored by 刘基明's avatar 刘基明

热度算法加入用户质量

parent 4769e67a
...@@ -46,10 +46,13 @@ public class ThemeAnalysDO { ...@@ -46,10 +46,13 @@ public class ThemeAnalysDO {
@ApiModelProperty(value = "距今时间") @ApiModelProperty(value = "距今时间")
private Long minuteTillNow; private Long minuteTillNow;
@ApiModelProperty(value = "用户质量")
private Double userWeight = 0.0;
public Double getScore() { public Double getScore() {
double w = (double) (viewCount*0.1 + forwardCount*3 + commentCount*2 + likeCount*1 + collectCount*3); //质量=帖子质量+用户质量
double w = (double) (viewCount * 0.1 + forwardCount * 3 + commentCount * 2 + likeCount * 1 + collectCount * 3) + userWeight;
double i = 1;//初试权重 double i = 1;//初试权重
double t = Double.valueOf(minuteTillNow) / 60; double t = Double.valueOf(minuteTillNow) / 60;
double g = 0.1;//时间系数 double g = 0.1;//时间系数
......
...@@ -3,10 +3,7 @@ package com.tanpu.community.dao.entity.community; ...@@ -3,10 +3,7 @@ package com.tanpu.community.dao.entity.community;
import com.baomidou.mybatisplus.annotation.IdType; import com.baomidou.mybatisplus.annotation.IdType;
import com.baomidou.mybatisplus.annotation.TableId; import com.baomidou.mybatisplus.annotation.TableId;
import com.baomidou.mybatisplus.annotation.TableName; import com.baomidou.mybatisplus.annotation.TableName;
import com.fasterxml.jackson.databind.annotation.JsonDeserialize; import com.fasterxml.jackson.annotation.JsonFormat;
import com.fasterxml.jackson.databind.annotation.JsonSerialize;
import com.fasterxml.jackson.datatype.jsr310.deser.LocalDateTimeDeserializer;
import com.fasterxml.jackson.datatype.jsr310.ser.LocalDateTimeSerializer;
import io.swagger.annotations.ApiModel; import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty; import io.swagger.annotations.ApiModelProperty;
import lombok.AllArgsConstructor; import lombok.AllArgsConstructor;
...@@ -64,12 +61,10 @@ public class CommentEntity implements Serializable { ...@@ -64,12 +61,10 @@ public class CommentEntity implements Serializable {
@ApiModelProperty(value = "举报状态 0:未被举报 1:被举报 2:已处理") @ApiModelProperty(value = "举报状态 0:未被举报 1:被举报 2:已处理")
private Integer reportStatus; private Integer reportStatus;
@JsonDeserialize(using = LocalDateTimeDeserializer.class) @JsonFormat(shape = JsonFormat.Shape.STRING, pattern="yyyy-MM-dd HH:mm:ss",timezone = "GMT+8")
@JsonSerialize(using = LocalDateTimeSerializer.class)
private LocalDateTime createTime; private LocalDateTime createTime;
@JsonDeserialize(using = LocalDateTimeDeserializer.class) @JsonFormat(shape = JsonFormat.Shape.STRING, pattern="yyyy-MM-dd HH:mm:ss",timezone = "GMT+8")
@JsonSerialize(using = LocalDateTimeSerializer.class)
private LocalDateTime updateTime; private LocalDateTime updateTime;
private Integer deleteTag; private Integer deleteTag;
......
...@@ -211,7 +211,7 @@ public class ThemeManager { ...@@ -211,7 +211,7 @@ public class ThemeManager {
return convertEntityToQo(themeEntities, userId); return convertEntityToQo(themeEntities, userId);
} }
//主题Entity转QO //主题Entity转QO,组装所有信息
private List<ThemeQo> convertEntityToQo(List<ThemeEntity> themeEntities, String userId) { private List<ThemeQo> convertEntityToQo(List<ThemeEntity> themeEntities, String userId) {
//Entity转Qo //Entity转Qo
List<ThemeQo> themeQos = ConvertUtil.themeEntitiesToDTOs(themeEntities); List<ThemeQo> themeQos = ConvertUtil.themeEntitiesToDTOs(themeEntities);
...@@ -219,7 +219,9 @@ public class ThemeManager { ...@@ -219,7 +219,9 @@ public class ThemeManager {
batchFeignCallService.getAttachDetailByBatch(themeQos); batchFeignCallService.getAttachDetailByBatch(themeQos);
//其他信息 //其他信息
for (ThemeQo themeQO : themeQos) { for (ThemeQo themeQO : themeQos) {
//通用信息
buildThemeQoExtraInfo(themeQO); buildThemeQoExtraInfo(themeQO);
//和用户相关信息
buildThemeExtraInfoByUser(userId, themeQO); buildThemeExtraInfoByUser(userId, themeQO);
} }
......
package com.tanpu.community.service; package com.tanpu.community.service;
import com.tanpu.common.api.CommonResp;
import com.tanpu.common.exception.BizException;
import com.tanpu.community.api.beans.qo.ThemeAnalysDO; import com.tanpu.community.api.beans.qo.ThemeAnalysDO;
import com.tanpu.community.api.beans.qo.TopicRankQo; import com.tanpu.community.api.beans.qo.TopicRankQo;
import com.tanpu.community.api.beans.vo.feign.fatools.UserInfoNew;
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.cache.RedisCache;
import com.tanpu.community.dao.entity.community.ThemeEntity; import com.tanpu.community.dao.entity.community.ThemeEntity;
import com.tanpu.community.dao.entity.community.TopicEntity; import com.tanpu.community.dao.entity.community.TopicEntity;
import com.tanpu.community.feign.fatools.FeignClientForFatools;
import com.tanpu.community.util.ConvertUtil; import com.tanpu.community.util.ConvertUtil;
import org.apache.commons.collections4.CollectionUtils; import org.apache.commons.collections4.CollectionUtils;
import org.apache.commons.lang3.StringUtils;
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 java.util.*; import java.util.*;
import java.util.stream.Collectors; import java.util.stream.Collectors;
import static com.tanpu.community.api.constants.RedisKeyConstant.CACGE_FEIGN_USER_INFO;
@Service @Service
public class RankService { public class RankService {
@Autowired @Autowired
...@@ -27,6 +36,12 @@ public class RankService { ...@@ -27,6 +36,12 @@ public class RankService {
@Autowired @Autowired
private VisitSummaryService visitSummaryService; private VisitSummaryService visitSummaryService;
@Autowired
private RedisCache redisCache;
@Resource
private FeignClientForFatools feignClientForFatools;
//最热 //最热
private List<ThemeAnalysDO> rankThemeList = new ArrayList<>(); private List<ThemeAnalysDO> rankThemeList = new ArrayList<>();
...@@ -54,6 +69,17 @@ public class RankService { ...@@ -54,6 +69,17 @@ public class RankService {
theme.setForwardCount(forwardCount); theme.setForwardCount(forwardCount);
theme.setCollectCount(bookCount); theme.setCollectCount(bookCount);
theme.setViewCount(viewCount); theme.setViewCount(viewCount);
//查询用户质量
String authorId = theme.getAuthorId();
UserInfoNew authorInfo = redisCache.getObject(StringUtils.joinWith(CACGE_FEIGN_USER_INFO, authorId),
60 * 10, () -> this.getUserInfo(authorId), UserInfoNew.class);
if (authorInfo == null || authorInfo.getLevelGrade() == null) {
theme.setUserWeight(0.0);
} else {
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::getScore));
...@@ -62,6 +88,14 @@ public class RankService { ...@@ -62,6 +88,14 @@ public class RankService {
} }
private UserInfoNew getUserInfo(String authorId) {
CommonResp<UserInfoNew> userInfoNewCommonResp = feignClientForFatools.queryUsersListNew(authorId);
if (userInfoNewCommonResp.isNotSuccess()) {
throw new BizException("内部接口调用失败");
}
return userInfoNewCommonResp.getData();
}
/** /**
* 计算话题热度 * 计算话题热度
...@@ -76,7 +110,7 @@ public class RankService { ...@@ -76,7 +110,7 @@ public class RankService {
} }
for (TopicRankQo topic : topicRankQos) { 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);
topic.setDisscussCount(0); topic.setDisscussCount(0);
continue; continue;
...@@ -100,13 +134,14 @@ public class RankService { ...@@ -100,13 +134,14 @@ public class RankService {
/** /**
* 最新和热门主题集合 * 最新和热门主题集合
*
* @param hotCount * @param hotCount
* @param newCount * @param newCount
* @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.rankThemeList.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());
Set<String> newThemeIds = themeService.selectExcludeUser(null, null, newCount) Set<String> newThemeIds = themeService.selectExcludeUser(null, null, newCount)
...@@ -117,11 +152,12 @@ public class RankService { ...@@ -117,11 +152,12 @@ public class RankService {
/** /**
* 话题详情 * 话题详情
*
* @param topicId 话题Id * @param topicId 话题Id
* @return * @return
*/ */
public TopicRankQo getTopicDetail(String topicId){ public TopicRankQo getTopicDetail(String topicId) {
if (this.rankTopicList.size()==0){ if (this.rankTopicList.size() == 0) {
rankTopics(); rankTopics();
} }
List<TopicRankQo> matchTopic = this.rankTopicList.stream().filter(o -> topicId.equals(o.getTopicId())).limit(1).collect(Collectors.toList()); List<TopicRankQo> matchTopic = this.rankTopicList.stream().filter(o -> topicId.equals(o.getTopicId())).limit(1).collect(Collectors.toList());
...@@ -130,34 +166,32 @@ public class RankService { ...@@ -130,34 +166,32 @@ public class RankService {
} }
public List<TopicRankQo> getRankTopicList() { public List<TopicRankQo> getRankTopicList() {
if (this.rankTopicList.size()==0){ if (this.rankTopicList.size() == 0) {
this.rankTopics(); this.rankTopics();
} }
return rankTopicList; return rankTopicList;
} }
public List<TopicRankQo> getRankTopicListTop4() { public List<TopicRankQo> getRankTopicListTop4() {
if (this.rankTopicList.size()==0){ if (this.rankTopicList.size() == 0) {
this.rankTopics(); this.rankTopics();
} }
return rankTopicListTop4; return rankTopicListTop4;
} }
public List<ThemeAnalysDO> getRankThemeList() { public List<ThemeAnalysDO> getRankThemeList() {
if (this.rankThemeList.size()==0){ if (this.rankThemeList.size() == 0) {
rankThemes(); rankThemes();
} }
return rankThemeList; return rankThemeList;
} }
public List<String> getRankThemeListByTopic(String topicId) { public List<String> getRankThemeListByTopic(String topicId) {
if (this.rankThemeList.size()==0){ if (this.rankThemeList.size() == 0) {
this.rankThemes(); this.rankThemes();
} }
return rankThemeList.stream().filter(o->topicId.equals(o.getTopicId())) return rankThemeList.stream().filter(o -> topicId.equals(o.getTopicId()))
.map(ThemeAnalysDO::getThemeId) .map(ThemeAnalysDO::getThemeId)
.collect(Collectors.toList()); .collect(Collectors.toList());
} }
......
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