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

添加注释

parent 16b5ae0a
......@@ -124,35 +124,36 @@ public class ThemeManager {
@Transactional
public CreateThemeResp publishTheme(CreateThemeReq req, String userId) {
//保存主题表
// 保存主题表
ThemeEntity themeEntity = new ThemeEntity();
BeanUtils.copyProperties(req, themeEntity);
themeEntity.setAuthorId(userId);
themeEntity.setContent(JsonUtil.toJson(req.getContent()));
//讨论类型,将讨论中的文本放入到discussContent中
// 讨论类型,将讨论中的文本放入到discussContent中
if (ThemeTypeEnum.DISCUSSION.getCode().equals(themeEntity.getThemeType())) {
String content = req.getContent().get(0).getValue();
if (content.length()>256){
content= content.substring(0,255);
// discuss_content字段上限为256个字符
if (content.length() > 256) {
content = content.substring(0, 255);
}
themeEntity.setDiscussContent(content);
}
//腾讯云敏感词校验
// 腾讯云敏感词校验
checkContent(themeEntity.getContent());
if (StringUtils.isEmpty(req.getEditThemeId())) {
//新建
// 新建
themeService.insertTheme(themeEntity);
} else {
//修改
// 修改
themeService.update(themeEntity, req.getEditThemeId());
themeEntity.setThemeId(req.getEditThemeId());
}
//保存附件表
// 保存附件表
List<ThemeAttachmentEntity> themeAttachments = ConvertUtil.themeReqToAttachmentList(req, themeEntity.getThemeId());
if (StringUtils.isNotEmpty(req.getEditThemeId())) {
//修改需要刪除
// 修改需要刪除
themeAttachmentService.deleteByThemeId(req.getEditThemeId());
}
themeAttachmentService.insertList(themeAttachments);
......@@ -180,10 +181,10 @@ public class ThemeManager {
.build();
if (StringUtils.isEmpty(req.getEditThemeId()) || req.getEditThemeId().equals(req.getFormerThemeId())) {
//新建
// 新建
themeService.insertTheme(themeEntity);
} else {
//修改
// 修改
themeService.update(themeEntity, req.getEditThemeId());
themeEntity.setThemeId(req.getEditThemeId());
......@@ -252,31 +253,31 @@ public class ThemeManager {
return resp;
}
//主题Entity转QO,组装所有信息
// 主题Entity转QO,组装所有信息
private List<ThemeQo> convertEntityToQo(List<ThemeEntity> themeEntities, String userId) {
//Entity转Qo
List<ThemeQo> themeQos = ConvertUtil.themeEntitiesToDTOs(themeEntities);
//批量查询附件detail
// 批量查询附件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);
......@@ -285,18 +286,18 @@ public class ThemeManager {
themeQo.setForwardCount(forwardCount);
}
//组装和当前用户相关信息
// 组装和当前用户相关信息
private void buildThemeExtraInfoByUser(String userId, ThemeQo themeQo) {
String themeId = themeQo.getThemeId();
//是否关注作者
// 是否关注作者
themeQo.setFollow(followRelService.checkFollow(themeQo.getAuthorId(), userId));
//是否点赞
// 是否点赞
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);
}
......@@ -329,19 +330,19 @@ public class ThemeManager {
}
//查询正文
// 查询正文
public ThemeQo getThemeDetail(String themeId, String userId) {
//TODO 临时埋点,接入新埋点后删除
visitSummaryService.addPageView(userId, themeId, VisitTypeEnum.THEME_PAGE_VIEW);
//查询详情
// 查询详情
ThemeQo themeQo = redisCache.getObject(StringUtils.joinWith("_", CACHE_THEME_ID, themeId), 60,
() -> this.getDetailCommon(themeId), ThemeQo.class);
//添加用户相关信息
// 添加用户相关信息
buildThemeExtraInfoByUser(userId, themeQo);
return themeQo;
}
//正文通用信息,与用户无关,可使用缓存
// 正文通用信息,与用户无关,可使用缓存
private ThemeQo getDetailCommon(String themeId) {
ThemeEntity themeEntity = themeService.queryByThemeId(themeId);
if (themeEntity == null) {
......@@ -477,9 +478,9 @@ public class ThemeManager {
private List<ThemeQo> getCommentThemeQos(QueryRecordThemeReq req, String userId) {
List<ThemeQo> commentThemeList = new ArrayList<>();
List<ThemeEntity> themeEntities;
//评论列表
// 评论列表
List<CommentEntity> commentEntities = commentService.queryCommentsByUserId(req.getUserId(), req.getLastId(), req.getPageSize());
//当前用户信息
// 当前用户信息
UserInfoNew userInfo = redisCache.getObject(StringUtils.joinWith(CACHE_FEIGN_USER_INFO, req.getUserId()),
60 * 10, () -> this.getUserInfo(req.getUserId()), UserInfoNew.class);
Set<String> replyThemeIds = commentEntities.stream().map(CommentEntity::getThemeId).collect(Collectors.toSet());
......@@ -488,12 +489,12 @@ public class ThemeManager {
}
themeEntities = themeService.queryByThemeIds(new ArrayList<>(replyThemeIds));
List<ThemeQo> themeQos = convertEntityToQo(themeEntities, userId);
//组装附件
// 组装附件
batchFeignCallService.getAttachDetailByBatch(themeQos);
//主题列表
// 主题列表
Map<String, ThemeQo> themeMap = themeQos.stream()
.collect(Collectors.toMap(ThemeQo::getThemeId, o -> o));
//主题+评论封装转发对象
// 主题+评论封装转发对象
for (CommentEntity commentEntity : commentEntities) {
String themeId = commentEntity.getThemeId();
//评论内容包装到ThemeContentQo里
......
......@@ -79,7 +79,8 @@ public class CollectionService {
return collectionMapper.selectList(new LambdaQueryWrapper<CollectionEntity>()
.eq(CollectionEntity::getUserId, userId)
.eq(CollectionEntity::getCollectionType, type.getCode())
.eq(CollectionEntity::getDeleteTag, DeleteTagEnum.NOT_DELETED.getCode()))
.eq(CollectionEntity::getDeleteTag, DeleteTagEnum.NOT_DELETED.getCode())
.orderByDesc(CollectionEntity::getCollectionTime))
.stream().map(CollectionEntity::getTargetId).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