Commit 8820293a authored by 刘基明's avatar 刘基明

转发内容使用缓存

parent fd325b13
...@@ -37,6 +37,8 @@ public class RedisKeyConstant { ...@@ -37,6 +37,8 @@ public class RedisKeyConstant {
public static final String CAHCE_COMMENT_ID = "CACHE_COMMENT_ID_"; public static final String CAHCE_COMMENT_ID = "CACHE_COMMENT_ID_";
// 主题本身 // 主题本身
public static final String CACHE_THEME_ID = "CACHE_THEME_ID_"; public static final String CACHE_THEME_ID = "CACHE_THEME_ID_";
// 转发主题本身
public static final String CACHE_FORMER_THEME_ID = "CACHE_FORMER_THEME_ID_";
public static final String THEME_VIEW_COUNT_="THEME_VIEW_COUNT_"; public static final String THEME_VIEW_COUNT_="THEME_VIEW_COUNT_";
public static final String THEME_LIKE_COUNT_="THEME_LIKE_COUNT_"; public static final String THEME_LIKE_COUNT_="THEME_LIKE_COUNT_";
......
...@@ -33,6 +33,7 @@ import java.time.LocalDateTime; ...@@ -33,6 +33,7 @@ import java.time.LocalDateTime;
import java.util.*; import java.util.*;
import java.util.stream.Collectors; import java.util.stream.Collectors;
import static com.tanpu.community.api.constants.RedisKeyConstant.CACHE_FORMER_THEME_ID;
import static com.tanpu.community.api.constants.RedisKeyConstant.CACHE_THEME_ID; import static com.tanpu.community.api.constants.RedisKeyConstant.CACHE_THEME_ID;
@Slf4j @Slf4j
...@@ -259,8 +260,12 @@ public class ThemeManager { ...@@ -259,8 +260,12 @@ public class ThemeManager {
throw new BizException("找不到帖子id:" + themeId); throw new BizException("找不到帖子id:" + themeId);
} }
ThemeQo themeQo = ConvertUtil.themeEntityToQo(themeEntity); ThemeQo themeQo = ConvertUtil.themeEntityToQo(themeEntity);
//附件
batchFeignCallService.getAttachDetail(themeQo); batchFeignCallService.getAttachDetail(themeQo);
//转发、收藏、点赞
buildThemeQoExtraInfo( themeQo); buildThemeQoExtraInfo( themeQo);
return themeQo; return themeQo;
} }
...@@ -341,11 +346,13 @@ public class ThemeManager { ...@@ -341,11 +346,13 @@ public class ThemeManager {
} }
//组装主题详情 //转发对象、点赞、收藏、转发数
private void buildThemeQoExtraInfo( ThemeQo themeQo) { private void buildThemeQoExtraInfo( ThemeQo themeQo) {
String themeId = themeQo.getThemeId(); String themeId = themeQo.getThemeId();
//封装转发对象 //封装转发对象
buildFormerTheme(themeQo); FormerThemeQo former = redisCache.getObject(StringUtils.joinWith("_", CACHE_FORMER_THEME_ID, themeId), 60,
() -> this.getFormerTheme(themeQo.getFormerThemeId()), FormerThemeQo.class);
themeQo.setFormerTheme(former);
//点赞,收藏,转发 //点赞,收藏,转发
Integer likeCount = collectionService.getCountByTypeAndId(themeId, CollectionTypeEnum.LIKE_THEME); Integer likeCount = collectionService.getCountByTypeAndId(themeId, CollectionTypeEnum.LIKE_THEME);
Integer commentCount = commentService.getCommentCountByThemeId(themeId); Integer commentCount = commentService.getCommentCountByThemeId(themeId);
...@@ -378,10 +385,13 @@ public class ThemeManager { ...@@ -378,10 +385,13 @@ public class ThemeManager {
private void buildFormerTheme(ThemeQo themeQo) { private void buildFormerTheme(ThemeQo themeQo) {
String formerThemeId = themeQo.getFormerThemeId(); String formerThemeId = themeQo.getFormerThemeId();
if (StringUtils.isNotEmpty(formerThemeId)) { if (StringUtils.isNotEmpty(formerThemeId)) {
ThemeQo formerTheme = ConvertUtil.themeEntityToQo(themeService.queryByThemeId(formerThemeId)); ThemeQo formerTheme = ConvertUtil.themeEntityToQo(themeService.queryByThemeId(formerThemeId));
if (formerTheme != null) { if (formerTheme != null) {
//单个查询详情 //单个查询详情
batchFeignCallService.getAttachDetail(formerTheme); batchFeignCallService.getAttachDetail(formerTheme);
FormerThemeQo f = ConvertUtil.themeQo2FormerThemeQo(formerTheme); FormerThemeQo f = ConvertUtil.themeQo2FormerThemeQo(formerTheme);
themeQo.setFormerTheme(f); themeQo.setFormerTheme(f);
...@@ -390,6 +400,20 @@ public class ThemeManager { ...@@ -390,6 +400,20 @@ public class ThemeManager {
} }
} }
//返回被转发主题
private FormerThemeQo getFormerTheme(String formerThemeId) {
if (StringUtils.isNotEmpty(formerThemeId)) {
ThemeQo formerTheme = ConvertUtil.themeEntityToQo(themeService.queryByThemeId(formerThemeId));
if (formerTheme != null) {
batchFeignCallService.getAttachDetail(formerTheme);
FormerThemeQo f = ConvertUtil.themeQo2FormerThemeQo(formerTheme);
return f;
}
}
return null;
}
//逻辑删除 //逻辑删除
public void delete(String themeId) { public void delete(String themeId) {
......
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