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

添加评论返回

parent fec67e58
...@@ -36,10 +36,9 @@ public class CommentController { ...@@ -36,10 +36,9 @@ public class CommentController {
@AuthLogin @AuthLogin
@PostMapping(value = "/publishComment") @PostMapping(value = "/publishComment")
@ResponseBody @ResponseBody
public CommonResp<Void> publishCommet(@Validated @RequestBody CreateCommentReq req) { public CommonResp<CommentQo> publishCommet(@Validated @RequestBody CreateCommentReq req) {
String userId = userHolder.getUserId(); String userId = userHolder.getUserId();
commentManager.comment(req, userId); return CommonResp.success(commentManager.comment(req, userId));
return CommonResp.success();
} }
@ApiOperation("评论列表") @ApiOperation("评论列表")
...@@ -68,7 +67,7 @@ public class CommentController { ...@@ -68,7 +67,7 @@ public class CommentController {
@ResponseBody @ResponseBody
public CommonResp<Void> reportComment(@Validated @RequestBody ReportCommentReq req) { public CommonResp<Void> reportComment(@Validated @RequestBody ReportCommentReq req) {
String userId = userHolder.getUserId(); String userId = userHolder.getUserId();
commentManager.report(req,userId); commentManager.report(req, userId);
return CommonResp.success(); return CommonResp.success();
} }
...@@ -76,9 +75,9 @@ public class CommentController { ...@@ -76,9 +75,9 @@ public class CommentController {
@GetMapping(value = "/deleteComment") @GetMapping(value = "/deleteComment")
@AuthLogin @AuthLogin
@ResponseBody @ResponseBody
public CommonResp<Void> reportComment(@RequestParam(value = "commentId") String commentId) { public CommonResp<Void> reportComment(@RequestParam(value = "commentId") String commentId) {
String userId = userHolder.getUserId(); String userId = userHolder.getUserId();
commentManager.delete(commentId,userId); commentManager.delete(commentId, userId);
return CommonResp.success(); return CommonResp.success();
} }
} }
...@@ -23,7 +23,7 @@ public class CodeAutoGenerator { ...@@ -23,7 +23,7 @@ public class CodeAutoGenerator {
String mysqlPassword = "@imeng123"; String mysqlPassword = "@imeng123";
String jdbcUrl = "jdbc:mysql://rm-uf6r22t3d798q4kmkao.mysql.rds.aliyuncs.com:3306/tamp_community"; String jdbcUrl = "jdbc:mysql://rm-uf6r22t3d798q4kmkao.mysql.rds.aliyuncs.com:3306/tamp_community";
// String[] tables = new String[]{"theme"}; // String[] tables = new String[]{"theme"};
String[] tables = new String[]{"visit_log"}; String[] tables = new String[]{"message_queue"};
String basePackage = "com.tanpu.community"; String basePackage = "com.tanpu.community";
String mapperPackage = "dao.mapper.community"; String mapperPackage = "dao.mapper.community";
String entityPackage = "dao.entity.community"; String entityPackage = "dao.entity.community";
......
...@@ -51,7 +51,7 @@ public class CommentManager { ...@@ -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())) { if (StringUtils.isEmpty(req.getComment())) {
throw new IllegalArgumentException("评论内容不能为空"); throw new IllegalArgumentException("评论内容不能为空");
...@@ -70,6 +70,9 @@ public class CommentManager { ...@@ -70,6 +70,9 @@ public class CommentManager {
.build(); .build();
commentService.insertComment(commentEntity); commentService.insertComment(commentEntity);
CommentQo commentQo = ConvertUtil.commentEntity2Qo(commentEntity);
buildUserInfo(commentQo);
return commentQo;
} }
// 查询评论 // 查询评论
...@@ -81,20 +84,9 @@ public class CommentManager { ...@@ -81,20 +84,9 @@ public class CommentManager {
Set<String> likeCommentList = collectionService.getSetByUser(userId, CollectionTypeEnum.LIKE_COMMENT); Set<String> likeCommentList = collectionService.getSetByUser(userId, CollectionTypeEnum.LIKE_COMMENT);
for (CommentQo commentQo : commentQos) { for (CommentQo commentQo : commentQos) {
//查询用户信息 // 封装用户信息
String authorId = commentQo.getAuthorId(); buildUserInfo(commentQo);
UserInfoResp userInfo = redisCache.getObject(StringUtils.joinWith("_", CACHE_FEIGN_USER_INFO, authorId), // 是否点赞及点赞数
60, () ->this.getUserInfo(authorId) , UserInfoResp.class);
if (userInfo != null) {
commentQo.setUserImg(userInfo.getHeadImageUrl());
commentQo.setNickName(userInfo.getNickName());
commentQo.setUserType(userInfo.getUserType());
commentQo.setLevelGrade(userInfo.getLevelGrade());
commentQo.setUserInvestorType(userInfo.getUserInvestorType());
commentQo.setBelongUserOrgId(userInfo.getBelongUserOrgId());
commentQo.setBelongUserOrgName(userInfo.getBelongUserOrgName());
}
//是否点赞及点赞数
String commentId = commentQo.getCommentId(); String commentId = commentQo.getCommentId();
commentQo.setHasLiked(likeCommentList.contains(commentId)); commentQo.setHasLiked(likeCommentList.contains(commentId));
Integer countByTypeAndId = collectionService.getCountByTypeAndId(commentId, CollectionTypeEnum.LIKE_COMMENT); Integer countByTypeAndId = collectionService.getCountByTypeAndId(commentId, CollectionTypeEnum.LIKE_COMMENT);
...@@ -107,6 +99,24 @@ public class CommentManager { ...@@ -107,6 +99,24 @@ public class CommentManager {
.collect(Collectors.toList()); .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);
if (userInfo != null) {
commentQo.setUserImg(userInfo.getHeadImageUrl());
commentQo.setNickName(userInfo.getNickName());
commentQo.setUserType(userInfo.getUserType());
commentQo.setLevelGrade(userInfo.getLevelGrade());
commentQo.setUserInvestorType(userInfo.getUserInvestorType());
commentQo.setBelongUserOrgId(userInfo.getBelongUserOrgId());
commentQo.setBelongUserOrgName(userInfo.getBelongUserOrgName());
}
commentQo.setHasLiked(false);
commentQo.setLikeCount(0);
}
private UserInfoResp getUserInfo(String authorId){ private UserInfoResp getUserInfo(String authorId){
CommonResp<UserInfoResp> userInfoNewCommonResp = feignClientForFatools.queryUserInfoNew(authorId); CommonResp<UserInfoResp> userInfoNewCommonResp = feignClientForFatools.queryUserInfoNew(authorId);
if (userInfoNewCommonResp.isNotSuccess()) { if (userInfoNewCommonResp.isNotSuccess()) {
......
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