feat: 返回当前文章评论数,最热评论查询

This commit is contained in:
sjm
2024-07-19 16:55:49 +08:00
parent 2015dc7511
commit d860ec841a
5 changed files with 137 additions and 49 deletions

View File

@@ -28,20 +28,34 @@ public class SchisandraShareCommentReplyController {
@Resource
private SchisandraShareCommentReplyDomainService schisandraShareCommentReplyDomainService;
/**
* 点赞
* @param Id
* @return
*/
@GetMapping("addlike")
public Result addLike(String Id){
return Result.ok(schisandraShareCommentReplyDomainService.addLike(Id));
}
@Resource
CaffeineUtil caffeineUtil;
/**
* 返回评论回复总数
* @param detailId
* @return
*/
@GetMapping("returncount")
public Result returncount(String detailId) {
try{
return Result.ok(schisandraShareCommentReplyDomainService.returnCount(detailId));
} catch (Exception e) {
return Result.fail("获取评论数量失败!!!");
}
}
@GetMapping("returnlikes")
public Result<Long> returnlikes(@RequestParam String Id) {
try{
Long l = schisandraShareCommentReplyDomainService.returnLike(Id);
return Result.ok(l);
}catch(Exception e){
return Result.fail("获取点赞数量失败!!!");
}
}
/**
*
* 返回当前评论的回复
* @param commentId
* @return
@@ -89,32 +103,53 @@ public class SchisandraShareCommentReplyController {
}
}
/**
* 查询该动态下的评论(最热)
*/
@GetMapping(value = "listcommenthot")
public Result<List<SchisandraShareCommentReplyDTO>> listCommentHot(@RequestParam String detailId) {
try {
List<SchisandraShareCommentReplyBO> result= (List<SchisandraShareCommentReplyBO>) caffeineUtil
.caffeineBuild().getIfPresent("listcomment"+detailId);
if (result!=null){
return Result.ok(result);
}
result = schisandraShareCommentReplyDomainService.listCommenthot(detailId);
caffeineUtil.caffeineBuild().put("listcommenthot"+detailId, result);
if (log.isInfoEnabled()) {
log.info("获取当前文章评论内容{}", JSON.toJSONString(result));
}
return Result.ok(SchisandraShareCommentReplyDTOConverter.INSTANCE.convertBOToDTOList(result));
} catch (IllegalArgumentException e) {
log.error("参数异常!错误原因{}", e.getMessage(), e);
return Result.fail(e.getMessage());
} catch (Exception e) {
log.error("获取当前文章内容异常!错误原因{}", e.getMessage(), e);
return Result.fail("获取当前文章内容异常!");
}
}
/**
* 新增回复
* @param schisandraShareCommentReplyDTO
* @return
*/
@PostMapping("addreply")
public Result<Boolean> addReply(@RequestBody SchisandraShareCommentReplyDTO schisandraShareCommentReplyDTO) {
try {
if (log.isInfoEnabled()) {
log.info("SchisandraShareCommentReplyController.addComment.dto:{}", JSON.toJSONString(schisandraShareCommentReplyDTO));
log.info("SchisandraShareCommentReplyController.addReply.dto:{}",
JSON.toJSONString(schisandraShareCommentReplyDTO));
}
Preconditions.checkNotNull(schisandraShareCommentReplyDTO.getContent(), "内容不能为空");
Preconditions.checkNotNull(schisandraShareCommentReplyDTO.getDetailId(), "分享文章id不能为空");
Preconditions.checkNotNull(schisandraShareCommentReplyDTO.getUserId(), "发布人id不能为空");
Preconditions.checkNotNull(schisandraShareCommentReplyDTO.getToId(), "评论目标id不能为空");
// Preconditions.checkNotNull(schisandraShareCommentReplyDTO.getReplyType(), "回复类型 0评论 1回复不能为空");
// Preconditions.checkNotNull(schisandraShareCommentReplyDTO.getToUser(), "评论人不能为空");
// Preconditions.checkNotNull(schisandraShareCommentReplyDTO.getReplayAuthor(), "回复人是否作者 1=是 0=否不能为空");
// Preconditions.checkNotNull(schisandraShareCommentReplyDTO.getPicUrls(), "图片内容不能为空");
// Preconditions.checkNotNull(schisandraShareCommentReplyDTO.getLikes(), "点赞数不能为空");
// Preconditions.checkNotNull(schisandraShareCommentReplyDTO.getExtJson(), "预留字段不能为空");
// Preconditions.checkNotNull(schisandraShareCommentReplyDTO.getCreatedBy(), "创建人不能为空");
// Preconditions.checkNotNull(schisandraShareCommentReplyDTO.getCreatedTime(), "创建时间不能为空");
// Preconditions.checkNotNull(schisandraShareCommentReplyDTO.getUpdateBy(), "更新人不能为空");
// Preconditions.checkNotNull(schisandraShareCommentReplyDTO.getUpdateTime(), "更新时间不能为空");
// Preconditions.checkNotNull(schisandraShareCommentReplyDTO.getIsDeleted(), "不能为空");
SchisandraShareCommentReplyBO SchisandraShareCommentReplyBO = SchisandraShareCommentReplyDTOConverter.INSTANCE.convertDTOToBO(schisandraShareCommentReplyDTO);
return Result.ok(schisandraShareCommentReplyDomainService.addReply(SchisandraShareCommentReplyBO));
} catch (Exception e) {
log.error("SchisandraShareCommentReplyController.register.error:{}", e.getMessage(), e);
return Result.fail("新增评论失败");
return Result.fail("新增回复失败");
}
}
@@ -127,27 +162,16 @@ public class SchisandraShareCommentReplyController {
try {
if (log.isInfoEnabled()) {
log.info("SchisandraShareCommentReplyController.addComment.dto:{}", JSON.toJSONString(schisandraShareCommentReplyDTO));
log.info("SchisandraShareCommentReplyController.addComment.dto:{}",
JSON.toJSONString(schisandraShareCommentReplyDTO));
}
Preconditions.checkNotNull(schisandraShareCommentReplyDTO.getContent(), "内容不能为空");
Preconditions.checkNotNull(schisandraShareCommentReplyDTO.getDetailId(), "分享文章id不能为空");
Preconditions.checkNotNull(schisandraShareCommentReplyDTO.getUserId(), "发布人id不能为空");
// Preconditions.checkNotNull(schisandraShareCommentReplyDTO.getReplyType(), "回复类型 0评论 1回复不能为空");
// Preconditions.checkNotNull(schisandraShareCommentReplyDTO.getToId(), "评论目标id不能为空");
// Preconditions.checkNotNull(schisandraShareCommentReplyDTO.getToUser(), "评论人不能为空");
// Preconditions.checkNotNull(schisandraShareCommentReplyDTO.getReplyId(), "回复目标id不能为空");
// Preconditions.checkNotNull(schisandraShareCommentReplyDTO.getReplyUser(), "回复人不能为空");
// Preconditions.checkNotNull(schisandraShareCommentReplyDTO.getReplayAuthor(), "回复人是否作者 1=是 0=否不能为空");
// Preconditions.checkNotNull(schisandraShareCommentReplyDTO.getPicUrls(), "图片内容不能为空");
// Preconditions.checkNotNull(schisandraShareCommentReplyDTO.getLikes(), "点赞数不能为空");
// Preconditions.checkNotNull(schisandraShareCommentReplyDTO.getExtJson(), "预留字段不能为空");
// Preconditions.checkNotNull(schisandraShareCommentReplyDTO.getCreatedBy(), "创建人不能为空");
// Preconditions.checkNotNull(schisandraShareCommentReplyDTO.getCreatedTime(), "创建时间不能为空");
// Preconditions.checkNotNull(schisandraShareCommentReplyDTO.getUpdateBy(), "更新人不能为空");
// Preconditions.checkNotNull(schisandraShareCommentReplyDTO.getUpdateTime(), "更新时间不能为空");
// Preconditions.checkNotNull(schisandraShareCommentReplyDTO.getIsDeleted(), "不能为空");
SchisandraShareCommentReplyBO SchisandraShareCommentReplyBO = SchisandraShareCommentReplyDTOConverter.INSTANCE.convertDTOToBO(schisandraShareCommentReplyDTO);
return Result.ok(schisandraShareCommentReplyDomainService.addComment(SchisandraShareCommentReplyBO));
SchisandraShareCommentReplyBO schisandraShareCommentReplyBO = SchisandraShareCommentReplyDTOConverter.INSTANCE.convertDTOToBO(schisandraShareCommentReplyDTO);
caffeineUtil.caffeineBuild().invalidate("listcommenthot"+schisandraShareCommentReplyBO.getDetailId());
caffeineUtil.caffeineBuild().invalidate("listcomment"+schisandraShareCommentReplyBO.getDetailId());
return Result.ok(schisandraShareCommentReplyDomainService.addComment(schisandraShareCommentReplyBO));
} catch (Exception e) {
log.error("SchisandraShareCommentReplyController.register.error:{}", e.getMessage(), e);
return Result.fail("新增评论失败");
@@ -219,7 +243,8 @@ public class SchisandraShareCommentReplyController {
Preconditions.checkNotNull(schisandraShareCommentReplyDTO.getUpdateTime(), "更新时间不能为空");
Preconditions.checkNotNull(schisandraShareCommentReplyDTO.getIsDeleted(), "不能为空");
SchisandraShareCommentReplyBO schisandraShareCommentReplyBO = SchisandraShareCommentReplyDTOConverter.INSTANCE.convertDTOToBO(schisandraShareCommentReplyDTO);
caffeineUtil.caffeineBuild().invalidate(""+schisandraShareCommentReplyBO.getDetailId());
caffeineUtil.caffeineBuild().invalidate("listcommenthot"+schisandraShareCommentReplyBO.getDetailId());
caffeineUtil.caffeineBuild().invalidate("listcomment"+schisandraShareCommentReplyBO.getDetailId());
return Result.ok(schisandraShareCommentReplyDomainService.delete(schisandraShareCommentReplyBO));
} catch (Exception e) {
log.error("SchisandraShareCommentReplyController.delete.error:{}", e.getMessage(), e);

View File

@@ -33,7 +33,11 @@ public interface SchisandraShareCommentReplyDomainService {
List<SchisandraShareCommentReplyBO> listComment(String detailId);
List<SchisandraShareCommentReplyBO> listCommenthot(String detailId);
List<SchisandraShareCommentReplyBO> listReply(String commentId);
Boolean addLike(String Id);
Long returnLike(String Id);
Long returnCount(String detailId);
}

View File

@@ -34,6 +34,7 @@ public class SchisandraShareCommentReplyDomainServiceImpl implements SchisandraS
public Boolean addComment(SchisandraShareCommentReplyBO schisandraShareCommentReplyBO) {
SchisandraShareCommentReply schisandraShareCommentReply = SchisandraShareCommentReplyBOConverter.INSTANCE.convertBOToEntity(schisandraShareCommentReplyBO);
schisandraShareCommentReply.setIsDeleted(IsDeletedFlagEnum.UN_DELETED.getCode());
schisandraShareCommentReply.setReplayAuthor(0);
schisandraShareCommentReply.setReplyCount(0);
schisandraShareCommentReply.setReplyType(0);
schisandraShareCommentReply.setLikes(0L);
@@ -44,9 +45,9 @@ public class SchisandraShareCommentReplyDomainServiceImpl implements SchisandraS
public Boolean addReply(SchisandraShareCommentReplyBO schisandraShareCommentReplyBO) {
SchisandraShareCommentReply schisandraShareCommentReply = SchisandraShareCommentReplyBOConverter.INSTANCE.convertBOToEntity(schisandraShareCommentReplyBO);
schisandraShareCommentReply.setIsDeleted(IsDeletedFlagEnum.UN_DELETED.getCode());
schisandraShareCommentReply.setReplyCount(0);
schisandraShareCommentReply.setReplyType(1);
schisandraShareCommentReply.setLikes(0L);
Assert.notNull(schisandraShareCommentReply.getToId());
//查询to_user
SchisandraShareCommentReply comment = schisandraShareCommentReplyService.queryById(schisandraShareCommentReply.getToId());
@@ -87,6 +88,18 @@ public class SchisandraShareCommentReplyDomainServiceImpl implements SchisandraS
return schisandraShareCommentBOS;
}
@Override
public List<SchisandraShareCommentReplyBO> listCommenthot(String detailId) {
List<SchisandraShareCommentReply> schisandraShareComments = schisandraShareCommentReplyService.listCommenthot(detailId);
List<SchisandraShareCommentReplyBO> schisandraShareCommentBOS = SchisandraShareCommentReplyBOConverter.INSTANCE.convertEntityToBOList(schisandraShareComments);
schisandraShareCommentBOS.forEach(schisandraShareCommentReplyBO -> {
AuthUserInfoEntity userInfo = userRpc.getUserInfo(schisandraShareCommentReplyBO.getUserId());
schisandraShareCommentReplyBO.setNick(userInfo.getNickName());
schisandraShareCommentReplyBO.setAvatar(userInfo.getAvatar());
});
return schisandraShareCommentBOS;
}
@Override
public List<SchisandraShareCommentReplyBO> listReply(String commentId) {
List<SchisandraShareCommentReply> schisandraShareReplies = schisandraShareCommentReplyService.listReply(commentId);
@@ -101,9 +114,13 @@ public class SchisandraShareCommentReplyDomainServiceImpl implements SchisandraS
}
@Override
public Boolean addLike(String Id) {
SchisandraShareCommentReply schisandraShareCommentReply = schisandraShareCommentReplyService.queryById(Id);
schisandraShareCommentReply.setLikes(schisandraShareCommentReply.getLikes()+1);
return schisandraShareCommentReplyService.update(schisandraShareCommentReply) > 0;
public Long returnLike(String Id) {
SchisandraShareCommentReply schisandraShareCommentReply = schisandraShareCommentReplyService.returnLike(Id);
return schisandraShareCommentReply.getLikes();
}
@Override
public Long returnCount(String detailId) {
return schisandraShareCommentReplyService.returnCount(detailId);
}
}

View File

@@ -45,5 +45,11 @@ public interface SchisandraShareCommentReplyService {
List<SchisandraShareCommentReply> listComment(String detailId);
List<SchisandraShareCommentReply> listCommenthot(String detailId);
List<SchisandraShareCommentReply> listReply(String commentId);
SchisandraShareCommentReply returnLike(String Id);
Long returnCount(String detailId);
}

View File

@@ -1,7 +1,6 @@
package com.schisandra.share.infra.basic.service.impl;
import com.mybatisflex.core.query.QueryWrapper;
import com.schisandra.share.common.enums.IsDeletedFlagEnum;
import com.schisandra.share.infra.basic.entity.SchisandraShareCommentReply;
import com.schisandra.share.infra.basic.dao.SchisandraShareCommentReplyDao;
import com.schisandra.share.infra.basic.entity.table.SchisandraShareCommentReplyTableDef;
@@ -10,6 +9,7 @@ import org.springframework.stereotype.Service;
import javax.annotation.Resource;
import java.util.List;
import static com.mybatisflex.core.query.QueryMethods.count;
/**
* 评论回复表 表服务实现类
@@ -85,6 +85,24 @@ public class SchisandraShareCommentReplyServiceImpl implements SchisandraShareCo
return this.schisandraShareCommentReplyDao.selectListByQuery(wrapper);
}
@Override
public List<SchisandraShareCommentReply> listCommenthot(String detailId) {
QueryWrapper wrapper = QueryWrapper.create()
.select(SchisandraShareCommentReplyTableDef.SCHISANDRA_SHARE_COMMENT_REPLY.USER_ID,
SchisandraShareCommentReplyTableDef.SCHISANDRA_SHARE_COMMENT_REPLY.ID,
SchisandraShareCommentReplyTableDef.SCHISANDRA_SHARE_COMMENT_REPLY.CONTENT,
SchisandraShareCommentReplyTableDef.SCHISANDRA_SHARE_COMMENT_REPLY.PIC_URLS,
SchisandraShareCommentReplyTableDef.SCHISANDRA_SHARE_COMMENT_REPLY.LIKES,
SchisandraShareCommentReplyTableDef.SCHISANDRA_SHARE_COMMENT_REPLY.REPLY_COUNT,
SchisandraShareCommentReplyTableDef.SCHISANDRA_SHARE_COMMENT_REPLY.REPLAY_AUTHOR,
SchisandraShareCommentReplyTableDef.SCHISANDRA_SHARE_COMMENT_REPLY.CREATED_TIME)
.from(SchisandraShareCommentReplyTableDef.SCHISANDRA_SHARE_COMMENT_REPLY)
.where(SchisandraShareCommentReplyTableDef.SCHISANDRA_SHARE_COMMENT_REPLY.DETAIL_ID.eq(detailId))
.where(SchisandraShareCommentReplyTableDef.SCHISANDRA_SHARE_COMMENT_REPLY.REPLY_TYPE.eq(0))
.orderBy(SchisandraShareCommentReplyTableDef.SCHISANDRA_SHARE_COMMENT_REPLY.CREATED_TIME,false);
return this.schisandraShareCommentReplyDao.selectListByQuery(wrapper);
}
@Override
public List<SchisandraShareCommentReply> listReply(String commentId){
QueryWrapper wrapper = QueryWrapper.create()
@@ -103,4 +121,22 @@ public class SchisandraShareCommentReplyServiceImpl implements SchisandraShareCo
.orderBy(SchisandraShareCommentReplyTableDef.SCHISANDRA_SHARE_COMMENT_REPLY.CREATED_TIME,true);
return this.schisandraShareCommentReplyDao.selectListByQuery(wrapper);
}
@Override
public SchisandraShareCommentReply returnLike(String id){
QueryWrapper wrapper = QueryWrapper.create()
.select(SchisandraShareCommentReplyTableDef.SCHISANDRA_SHARE_COMMENT_REPLY.LIKES)
.from(SchisandraShareCommentReplyTableDef.SCHISANDRA_SHARE_COMMENT_REPLY)
.where(SchisandraShareCommentReplyTableDef.SCHISANDRA_SHARE_COMMENT_REPLY.ID.eq(id));
return this.schisandraShareCommentReplyDao.selectOneByQuery(wrapper);
}
@Override
public Long returnCount(String detailId){
QueryWrapper wrapper = QueryWrapper.create()
.select(count(SchisandraShareCommentReplyTableDef.SCHISANDRA_SHARE_COMMENT_REPLY.ID))
.from(SchisandraShareCommentReplyTableDef.SCHISANDRA_SHARE_COMMENT_REPLY)
.where(SchisandraShareCommentReplyTableDef.SCHISANDRA_SHARE_COMMENT_REPLY.DETAIL_ID.eq(detailId));
return this.schisandraShareCommentReplyDao.selectCountByQuery(wrapper);
}
}