Commit 69087f35 authored by 刘基明's avatar 刘基明

添加评论返回

parent fec67e58
......@@ -36,10 +36,9 @@ public class CommentController {
@AuthLogin
@PostMapping(value = "/publishComment")
@ResponseBody
public CommonResp<Void> publishCommet(@Validated @RequestBody CreateCommentReq req) {
public CommonResp<CommentQo> publishCommet(@Validated @RequestBody CreateCommentReq req) {
String userId = userHolder.getUserId();
commentManager.comment(req, userId);
return CommonResp.success();
return CommonResp.success(commentManager.comment(req, userId));
}
@ApiOperation("评论列表")
......@@ -68,7 +67,7 @@ public class CommentController {
@ResponseBody
public CommonResp<Void> reportComment(@Validated @RequestBody ReportCommentReq req) {
String userId = userHolder.getUserId();
commentManager.report(req,userId);
commentManager.report(req, userId);
return CommonResp.success();
}
......@@ -78,7 +77,7 @@ public class CommentController {
@ResponseBody
public CommonResp<Void> reportComment(@RequestParam(value = "commentId") String commentId) {
String userId = userHolder.getUserId();
commentManager.delete(commentId,userId);
commentManager.delete(commentId, userId);
return CommonResp.success();
}
}
......@@ -23,7 +23,7 @@ public class CodeAutoGenerator {
String mysqlPassword = "@imeng123";
String jdbcUrl = "jdbc:mysql://rm-uf6r22t3d798q4kmkao.mysql.rds.aliyuncs.com:3306/tamp_community";
// String[] tables = new String[]{"theme"};
String[] tables = new String[]{"visit_log"};
String[] tables = new String[]{"message_queue"};
String basePackage = "com.tanpu.community";
String mapperPackage = "dao.mapper.community";
String entityPackage = "dao.entity.community";
......
......@@ -51,7 +51,7 @@ public class CommentManager {
// 评论(对主题)
// 发表评论(对主题)
public void comment(CreateCommentReq req, String userId) {
public CommentQo comment(CreateCommentReq req, String userId) {
if (StringUtils.isEmpty(req.getComment())) {
throw new IllegalArgumentException("评论内容不能为空");
......@@ -70,6 +70,9 @@ public class CommentManager {
.build();
commentService.insertComment(commentEntity);
CommentQo commentQo = ConvertUtil.commentEntity2Qo(commentEntity);
buildUserInfo(commentQo);
return commentQo;
}
// 查询评论
......@@ -81,7 +84,23 @@ public class CommentManager {
Set<String> likeCommentList = collectionService.getSetByUser(userId, CollectionTypeEnum.LIKE_COMMENT);
for (CommentQo commentQo : commentQos) {
//查询用户信息
// 封装用户信息
buildUserInfo(commentQo);
// 是否点赞及点赞数
String commentId = commentQo.getCommentId();
commentQo.setHasLiked(likeCommentList.contains(commentId));
Integer countByTypeAndId = collectionService.getCountByTypeAndId(commentId, CollectionTypeEnum.LIKE_COMMENT);
commentQo.setLikeCount(countByTypeAndId);
}
//排序:点赞降序+时间降序
return commentQos.stream().sorted(Comparator.comparing(CommentQo::getLikeCount, Comparator.reverseOrder()).
thenComparing(CommentQo::getUpdateTime, Comparator.reverseOrder()))
.collect(Collectors.toList());
}
private void buildUserInfo(CommentQo commentQo) {
String authorId = commentQo.getAuthorId();
UserInfoResp userInfo = redisCache.getObject(StringUtils.joinWith("_", CACHE_FEIGN_USER_INFO, authorId),
60, () ->this.getUserInfo(authorId) , UserInfoResp.class);
......@@ -94,17 +113,8 @@ public class CommentManager {
commentQo.setBelongUserOrgId(userInfo.getBelongUserOrgId());
commentQo.setBelongUserOrgName(userInfo.getBelongUserOrgName());
}
//是否点赞及点赞数
String commentId = commentQo.getCommentId();
commentQo.setHasLiked(likeCommentList.contains(commentId));
Integer countByTypeAndId = collectionService.getCountByTypeAndId(commentId, CollectionTypeEnum.LIKE_COMMENT);
commentQo.setLikeCount(countByTypeAndId);
}
//排序:点赞降序+时间降序
return commentQos.stream().sorted(Comparator.comparing(CommentQo::getLikeCount, Comparator.reverseOrder()).
thenComparing(CommentQo::getUpdateTime, Comparator.reverseOrder()))
.collect(Collectors.toList());
commentQo.setHasLiked(false);
commentQo.setLikeCount(0);
}
private UserInfoResp getUserInfo(String authorId){
......
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