Commit fd325b13 authored by 刘基明's avatar 刘基明

正文关注状态错误fix

parent 9c7bc12b
...@@ -21,8 +21,6 @@ import org.springframework.web.bind.annotation.*; ...@@ -21,8 +21,6 @@ import org.springframework.web.bind.annotation.*;
import javax.annotation.Resource; import javax.annotation.Resource;
import java.util.List; import java.util.List;
import static com.tanpu.community.api.constants.RedisKeyConstant.CACHE_THEME_ID;
@RestController @RestController
@Slf4j @Slf4j
@RequestMapping(value = "/api/theme") @RequestMapping(value = "/api/theme")
...@@ -66,9 +64,7 @@ public class ThemeController { ...@@ -66,9 +64,7 @@ public class ThemeController {
@ResponseBody @ResponseBody
public CommonResp<ThemeQo> getThemeMainText(@RequestParam String themeId) { public CommonResp<ThemeQo> getThemeMainText(@RequestParam String themeId) {
String userId = userHolder.getUserId(); String userId = userHolder.getUserId();
ThemeQo themeQo = redisCache.getObject(StringUtils.joinWith("_", CACHE_THEME_ID, themeId), 60, return CommonResp.success(themeManager.getDetail(themeId, userId));
() -> themeManager.getDetail(themeId, userId), ThemeQo.class);
return CommonResp.success(themeQo);
} }
@AuthLogin @AuthLogin
......
...@@ -245,16 +245,27 @@ public class ThemeManager { ...@@ -245,16 +245,27 @@ public class ThemeManager {
//进入详情 //进入详情
visitSummaryService.addPageView(userId, themeId, VisitTypeEnum.THEME_PAGE_VIEW); visitSummaryService.addPageView(userId, themeId, VisitTypeEnum.THEME_PAGE_VIEW);
ThemeQo themeQo = redisCache.getObject(StringUtils.joinWith("_", CACHE_THEME_ID, themeId), 60,
() -> this.getDetailForCommon(themeId), ThemeQo.class);
buildThemeExtraInfoByUser(userId,themeQo);
return themeQo;
}
//正文通用信息,与用户无关,可使用缓存
private ThemeQo getDetailForCommon(String themeId) {
ThemeEntity themeEntity = themeService.queryByThemeId(themeId); ThemeEntity themeEntity = themeService.queryByThemeId(themeId);
if (themeEntity == null) { if (themeEntity == null) {
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(userId, themeQo); buildThemeQoExtraInfo( themeQo);
return themeQo; return themeQo;
} }
// 点赞/取消点赞 // 点赞/取消点赞
public void like(LikeThemeReq req, String userId) { public void like(LikeThemeReq req, String userId) {
if (OperationTypeEnum.CONFIRM.getCode().equals(req.getType())) { if (OperationTypeEnum.CONFIRM.getCode().equals(req.getType())) {
...@@ -322,7 +333,8 @@ public class ThemeManager { ...@@ -322,7 +333,8 @@ public class ThemeManager {
batchFeignCallService.getAttachDetailByBatch(themeQos); batchFeignCallService.getAttachDetailByBatch(themeQos);
//其他信息 //其他信息
for (ThemeQo themeQO : themeQos) { for (ThemeQo themeQO : themeQos) {
buildThemeQoExtraInfo(userId, themeQO); buildThemeQoExtraInfo( themeQO);
buildThemeExtraInfoByUser(userId,themeQO);
} }
return themeQos; return themeQos;
...@@ -330,12 +342,22 @@ public class ThemeManager { ...@@ -330,12 +342,22 @@ public class ThemeManager {
//组装主题详情 //组装主题详情
private void buildThemeQoExtraInfo(String userId, ThemeQo themeQo) { private void buildThemeQoExtraInfo( ThemeQo themeQo) {
String themeId = themeQo.getThemeId(); String themeId = themeQo.getThemeId();
//封装转发对象 //封装转发对象
buildFormerTheme(themeQo); buildFormerTheme(themeQo);
//点赞,收藏,转发
Integer likeCount = collectionService.getCountByTypeAndId(themeId, CollectionTypeEnum.LIKE_THEME);
Integer commentCount = commentService.getCommentCountByThemeId(themeId);
Integer forwardCount = themeService.getForwardCountById(themeId);
themeQo.setCommentCount(commentCount);
themeQo.setLikeCount(likeCount);
themeQo.setForwardCount(forwardCount);
}
//组装和当前用户相关信息
private void buildThemeExtraInfoByUser(String userId, ThemeQo themeQo){
String themeId = themeQo.getThemeId();
//是否关注作者 //是否关注作者
String authorId = themeQo.getAuthorId(); String authorId = themeQo.getAuthorId();
Set<String> fansSet = new HashSet<>(followRelService.queryFansByFollowerId(userId)); Set<String> fansSet = new HashSet<>(followRelService.queryFansByFollowerId(userId));
...@@ -349,13 +371,6 @@ public class ThemeManager { ...@@ -349,13 +371,6 @@ public class ThemeManager {
//是否收藏 //是否收藏
CollectionEntity collectionEntity = collectionService.getNotDeleteTargetCollection(themeId, userId, CollectionTypeEnum.COLLECT_THEME); CollectionEntity collectionEntity = collectionService.getNotDeleteTargetCollection(themeId, userId, CollectionTypeEnum.COLLECT_THEME);
themeQo.setHasCollect(collectionEntity != null); themeQo.setHasCollect(collectionEntity != null);
//点赞,收藏,转发
Integer likeCount = collectionService.getCountByTypeAndId(themeId, CollectionTypeEnum.LIKE_THEME);
Integer commentCount = commentService.getCommentCountByThemeId(themeId);
Integer forwardCount = themeService.getForwardCountById(themeId);
themeQo.setCommentCount(commentCount);
themeQo.setLikeCount(likeCount);
themeQo.setForwardCount(forwardCount);
} }
......
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