Commit 8100aa13 authored by 刘基明's avatar 刘基明

theme添加字段discussContent

parent 4351eb3f
......@@ -4,16 +4,13 @@ package com.tanpu.community.controller;
import com.tanpu.common.api.CommonResp;
import com.tanpu.common.auth.AuthLogin;
import com.tanpu.common.auth.UserHolder;
import com.tanpu.common.exception.BizException;
import com.tanpu.community.api.beans.qo.ThemeQo;
import com.tanpu.community.api.beans.req.theme.*;
import com.tanpu.community.api.beans.resp.CreateThemeResp;
import com.tanpu.community.cache.RedisCache;
import com.tanpu.community.manager.ThemeManager;
import com.tanpu.community.service.RecommendService;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;
......@@ -33,9 +30,6 @@ public class ThemeController {
@Autowired
private RedisCache redisCache;
@Autowired
private RecommendService recommendService;
@AuthLogin
@ApiOperation("发表主题")
@PostMapping(value = "/publish")
......@@ -51,9 +45,6 @@ public class ThemeController {
@ResponseBody
public CommonResp<List<ThemeQo>> selectInterestList(@Validated @RequestBody ThemeListReq req) {
String userId = userHolder.getUserId();
if(StringUtils.isEmpty(userId)){
throw new BizException("用户为空");
}
List<ThemeQo> result = themeManager.queryThemes(req, userId);
return CommonResp.success(result);
}
......@@ -64,7 +55,7 @@ public class ThemeController {
@ResponseBody
public CommonResp<ThemeQo> getThemeMainText(@RequestParam String themeId) {
String userId = userHolder.getUserId();
return CommonResp.success(themeManager.getDetail(themeId, userId));
return CommonResp.success(themeManager.getThemeDetail(themeId, userId));
}
@AuthLogin
......@@ -116,23 +107,6 @@ public class ThemeController {
return CommonResp.success();
}
@AuthLogin
@ApiOperation("分享主题")
@GetMapping(value = "/share")
@ResponseBody
public CommonResp<Void> shareTheme(String themeId) {
return CommonResp.failed("功能暂未开放");
}
@AuthLogin
@ApiOperation("屏蔽")
@GetMapping(value = "/block")
@ResponseBody
public CommonResp concealTheme(String themeId) {
String userId = userHolder.getUserId();
return CommonResp.success();
}
@AuthLogin
@ApiOperation("关注主题更新数量")
@GetMapping(value = "/updateCount")
......@@ -142,13 +116,4 @@ public class ThemeController {
return CommonResp.success(themeManager.getFollowUpdateCount(userId));
}
@AuthLogin
@GetMapping(value = "/test")
@ResponseBody
public CommonResp<Integer> test() {
String userId = userHolder.getUserId();
System.out.println(recommendService.getRecommendThemes("",20,userId));
return CommonResp.success();
}
}
......@@ -108,7 +108,7 @@ public class ThemeManager {
/**
* 发表主题(修改)
* 发表主题(修改)
*/
@Transactional
public CreateThemeResp publishTheme(CreateThemeReq req, String userId) {
......@@ -211,12 +211,54 @@ public class ThemeManager {
return convertEntityToQo(themeEntities, userId);
}
public List<ThemeQo> searchThemes(ThemeSearchReq req, String userId) {
//主题Entity转QO
private List<ThemeQo> convertEntityToQo(List<ThemeEntity> themeEntities, String userId) {
//Entity转Qo
List<ThemeQo> themeQos = ConvertUtil.themeEntitiesToDTOs(themeEntities);
//批量查询附件detail
batchFeignCallService.getAttachDetailByBatch(themeQos);
//其他信息
for (ThemeQo themeQO : themeQos) {
buildThemeQoExtraInfo(themeQO);
buildThemeExtraInfoByUser(userId, themeQO);
}
List<ThemeEntity> themeEntities = themeService.search(req.getKeyword(), req.getLastId(), req.getPageSize());
return convertEntityToQo(themeEntities, userId);
return themeQos;
}
//转发对象、点赞、收藏、转发数
private void buildThemeQoExtraInfo(ThemeQo themeQo) {
String themeId = themeQo.getThemeId();
//封装转发对象
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 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();
Set<String> fansSet = new HashSet<>(followRelService.queryFansByFollowerId(userId));
themeQo.setFollow(fansSet.contains(authorId));
//是否点赞
CollectionEntity likeEntity = collectionService.getNotDeleteTargetCollection(themeId, userId, CollectionTypeEnum.LIKE_THEME);
themeQo.setHasLiked(likeEntity != null);
//是否转发
Integer forwardCountByUser = themeService.getForwardCountByUser(themeId, userId);
themeQo.setHasForward(forwardCountByUser > 0);
//是否收藏
CollectionEntity collectionEntity = collectionService.getNotDeleteTargetCollection(themeId, userId, CollectionTypeEnum.COLLECT_THEME);
themeQo.setHasCollect(collectionEntity != null);
}
// 返回用户发布、回复、点赞、收藏的主题列表
public List<ThemeQo> queryThemesByUser(QueryRecordThemeReq req, String userId) {
......@@ -245,19 +287,19 @@ public class ThemeManager {
//查询正文
public ThemeQo getDetail(String themeId, String userId) {
public ThemeQo getThemeDetail(String themeId, String userId) {
//进入详情
visitSummaryService.addPageView(userId, themeId, VisitTypeEnum.THEME_PAGE_VIEW);
//查询详情
ThemeQo themeQo = redisCache.getObject(StringUtils.joinWith("_", CACHE_THEME_ID, themeId), 60,
() -> this.getDetailForCommon(themeId), ThemeQo.class);
() -> this.getDetailCommon(themeId), ThemeQo.class);
//添加用户相关信息
buildThemeExtraInfoByUser(userId, themeQo);
return themeQo;
}
//正文通用信息,与用户无关,可使用缓存
private ThemeQo getDetailForCommon(String themeId) {
private ThemeQo getDetailCommon(String themeId) {
ThemeEntity themeEntity = themeService.queryByThemeId(themeId);
if (themeEntity == null) {
throw new BizException("找不到帖子id:" + themeId);
......@@ -317,90 +359,6 @@ public class ThemeManager {
}
}
// 屏蔽(主题)
public void blockTheme(String themeId, String userId) {
blackListService.addBlock(themeId, userId, BlockTypeEnum.THEME);
BlackListEntity selectOne = blackListService.selectOne(themeService.queryByThemeId(themeId).getAuthorId(), userId, BlockTypeEnum.USER.getCode());
if (selectOne == null) {
blackListService.addBlock(themeService.queryByThemeId(themeId).getAuthorId(), userId, BlockTypeEnum.USER);
}
}
// 解除屏蔽(主题)
public void unblockTheme(String themeId, String userId) {
blackListService.removeBlackList(themeId, userId, BlockTypeEnum.USER);
}
//主题Entity转QO
private List<ThemeQo> convertEntityToQo(List<ThemeEntity> themeEntities, String userId) {
//Entity转Qo
List<ThemeQo> themeQos = ConvertUtil.themeEntitiesToDTOs(themeEntities);
//批量查询附件detail
batchFeignCallService.getAttachDetailByBatch(themeQos);
//其他信息
for (ThemeQo themeQO : themeQos) {
buildThemeQoExtraInfo(themeQO);
buildThemeExtraInfoByUser(userId, themeQO);
}
return themeQos;
}
//转发对象、点赞、收藏、转发数
private void buildThemeQoExtraInfo(ThemeQo themeQo) {
String themeId = themeQo.getThemeId();
//封装转发对象
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 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();
Set<String> fansSet = new HashSet<>(followRelService.queryFansByFollowerId(userId));
themeQo.setFollow(fansSet.contains(authorId));
//是否点赞
CollectionEntity likeEntity = collectionService.getNotDeleteTargetCollection(themeId, userId, CollectionTypeEnum.LIKE_THEME);
themeQo.setHasLiked(likeEntity != null);
//是否转发
Integer forwardCountByUser = themeService.getForwardCountByUser(themeId, userId);
themeQo.setHasForward(forwardCountByUser > 0);
//是否收藏
CollectionEntity collectionEntity = collectionService.getNotDeleteTargetCollection(themeId, userId, CollectionTypeEnum.COLLECT_THEME);
themeQo.setHasCollect(collectionEntity != null);
}
//组装被转发主题
private void buildFormerTheme(ThemeQo themeQo) {
String formerThemeId = themeQo.getFormerThemeId();
if (StringUtils.isNotEmpty(formerThemeId)) {
ThemeQo formerTheme = ConvertUtil.themeEntityToQo(themeService.queryByThemeId(formerThemeId));
if (formerTheme != null) {
//单个查询详情
batchFeignCallService.getAttachDetail(formerTheme);
FormerThemeQo f = ConvertUtil.themeQo2FormerThemeQo(formerTheme);
themeQo.setFormerTheme(f);
}
}
}
//返回被转发主题
private FormerThemeQo getFormerTheme(String formerThemeId) {
......@@ -417,7 +375,7 @@ public class ThemeManager {
}
//逻辑删除
//逻辑删除主题
public void delete(String themeId) {
themeService.deleteById(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