Commit 0e96088d authored by 刘基明's avatar 刘基明

主题推荐优化

parent 4d81b0e8
......@@ -23,6 +23,12 @@ public class TopicRankQo {
@ApiModelProperty(value = "讨论量")
private Integer disscussCount;
@ApiModelProperty(value = "阅读量-格式化")
private String formatViewCount;
@ApiModelProperty(value = "讨论量-格式化")
private String formatDisscussCount;
@ApiModelProperty(value = "是否置顶")
private Integer isTop;
......@@ -42,6 +48,6 @@ public class TopicRankQo {
if (isTop > 0) {
return Integer.MAX_VALUE;
}
return this.viewCount + this.disscussCount * 3 + viewCount + themeWeight;
return this.disscussCount * 3 + viewCount + themeWeight;
}
}
......@@ -6,7 +6,6 @@ import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
import javax.validation.constraints.NotNull;
import java.util.List;
@Data
public class ThemeListReq {
......@@ -19,11 +18,9 @@ public class ThemeListReq {
@ApiModelProperty(value = "话题Id")
public String topicId;
@ApiModelProperty(value = "当前浏览的最后一个themeId,可以为空")
public String lastId="";
@NotNull(message = "分页")
public Pageable page;
@ApiModelProperty(value = "session_id")
public String ident;
}
......@@ -42,7 +42,7 @@ public class ThemeController {
@ResponseBody
public CommonResp<ThemeListResp> selectInterestList(@Validated @RequestBody ThemeListReq req) {
String userId = userHolder.getUserId();
ThemeListResp result = themeManager.queryThemes(req, userId);
ThemeListResp result = themeManager.queryList(req, userId);
return CommonResp.success(result);
}
......
......@@ -60,9 +60,6 @@ public class ThemeManager {
@Autowired
private BlackListService blackListService;
@Autowired
private UserInfoService userInfoService;
@Autowired
private ThemeAttachmentService themeAttachmentService;
......@@ -203,7 +200,7 @@ public class ThemeManager {
* 推荐:由最热,最新和python推荐三个部分组成,比例为6,3,1
*/
// 查询主题列表:推荐/关注/热门/最新
public ThemeListResp queryThemes(ThemeListReq req, String userId) {
public ThemeListResp queryList(ThemeListReq req, String userId) {
List<String> excludeIds;
if (req.page.pageNumber > 1) {
String l = redisCache.get("queryThemes_" + req.ident);
......
......@@ -10,6 +10,7 @@ import com.tanpu.community.cache.RedisCache;
import com.tanpu.community.dao.entity.community.ThemeEntity;
import com.tanpu.community.dao.entity.community.TopicEntity;
import com.tanpu.community.feign.fatools.FeignClientForFatools;
import com.tanpu.community.util.BizUtils;
import com.tanpu.community.util.ConvertUtil;
import org.apache.commons.collections4.CollectionUtils;
import org.apache.commons.lang3.StringUtils;
......@@ -120,7 +121,7 @@ public class RankService {
// 浏览量
Integer topicPV = countMapByTargetIds.getOrDefault(topic.getTopicId(), 0);
Integer themePV = visitLogService.queryThemeVisit(themeIds);
topic.setViewCount(topicPV + themePV);
topic.setViewCount(topicPV + themePV + topic.getViewCntAdjust());
//讨论数=发布主题贴数+回复总数
Integer commentCount = commentService.getTotalCountByThemeIds(themeIds);
topic.setDisscussCount(themeIds.size() + commentCount);
......@@ -128,7 +129,10 @@ public class RankService {
double themeSum = getHotestThemes().stream().filter(o -> topic.getTopicId().equals(o.getTopicId()))
.mapToDouble(ThemeAnalysDO::calcScore)
.sum();
topic.setThemeWeight((int)themeSum);
topic.setThemeWeight((int) themeSum);
//格式化浏览量、讨论量
topic.setFormatViewCount(BizUtils.formatCountNumber(topic.getViewCount()));
topic.setFormatDisscussCount(BizUtils.formatCountNumber(topic.getDisscussCount()));
}
Map<TopicRankQo, Integer> map = topicRankQos.stream().collect(Collectors.toMap(o -> o, TopicRankQo::getRank));
List<TopicRankQo> rankList = map.entrySet().stream()
......
package com.tanpu.community.util;
import com.alibaba.fastjson.JSON;
import com.tanpu.community.api.beans.qo.ThemeContentQo;
import com.tanpu.community.api.beans.qo.ThemeQo;
import com.tanpu.community.api.enums.RelTypeEnum;
import org.apache.commons.lang3.StringUtils;
import java.util.ArrayList;
import java.util.List;
......@@ -37,4 +35,19 @@ public class BizUtils {
}
return "";
}
public static String formatCountNumber(Integer number) {
if (number < 10000) {
return number.toString();
} else {
double d = number * 1.0 / 10000;
return String.format("%.1f",d)+"w";
}
}
public static void main(String[] args) {
System.out.println(formatCountNumber(110400));
System.out.println(formatCountNumber(111100));
System.out.println(formatCountNumber(1000));
}
}
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