fix: 修复无法查询评论回复bug
This commit is contained in:
@@ -5,10 +5,10 @@ import com.google.common.base.Preconditions;
|
||||
import com.schisandra.share.application.convert.SchisandraShareCommentReplyDTOConverter;
|
||||
import com.schisandra.share.application.dto.SchisandraShareCommentReplyDTO;
|
||||
import com.schisandra.share.common.entity.Result;
|
||||
import com.schisandra.share.common.utils.CaffeineUtil;
|
||||
import com.schisandra.share.domain.bo.SchisandraShareCommentReplyBO;
|
||||
import com.schisandra.share.domain.service.SchisandraShareCommentReplyDomainService;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.cache.annotation.Cacheable;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
|
||||
import javax.annotation.Resource;
|
||||
@@ -33,14 +33,15 @@ public class SchisandraShareCommentReplyController {
|
||||
return Result.ok(schisandraShareCommentReplyDomainService.addLike(Id));
|
||||
}
|
||||
|
||||
|
||||
@Resource
|
||||
CaffeineUtil caffeineUtil;
|
||||
/**
|
||||
*
|
||||
* 返回当前评论的回复
|
||||
* @param commentId
|
||||
* @return
|
||||
*/
|
||||
@PostMapping(value = "listreply")
|
||||
@GetMapping(value = "listreply")
|
||||
public Result listReply(@RequestParam String commentId) {
|
||||
try {
|
||||
List<SchisandraShareCommentReplyBO> result = schisandraShareCommentReplyDomainService.listReply(commentId);
|
||||
@@ -60,11 +61,16 @@ public class SchisandraShareCommentReplyController {
|
||||
/**
|
||||
* 查询该动态下的评论
|
||||
*/
|
||||
@Cacheable(value = "listcommen",key = "#detailId")
|
||||
@PostMapping(value = "listcommen")
|
||||
@GetMapping(value = "listcomment")
|
||||
public Result<List<SchisandraShareCommentReplyDTO>> listComment(@RequestParam String detailId) {
|
||||
try {
|
||||
List<SchisandraShareCommentReplyBO> result = schisandraShareCommentReplyDomainService.listComment(detailId);
|
||||
List<SchisandraShareCommentReplyBO> result= (List<SchisandraShareCommentReplyBO>) caffeineUtil
|
||||
.caffeineBuild().getIfPresent("listcomment"+detailId);
|
||||
if (result!=null){
|
||||
return Result.ok(result);
|
||||
}
|
||||
result = schisandraShareCommentReplyDomainService.listComment(detailId);
|
||||
caffeineUtil.caffeineBuild().put("listcomment"+detailId, result);
|
||||
if (log.isInfoEnabled()) {
|
||||
log.info("获取当前文章评论内容{}", JSON.toJSONString(result));
|
||||
}
|
||||
@@ -78,6 +84,28 @@ public class SchisandraShareCommentReplyController {
|
||||
}
|
||||
}
|
||||
|
||||
// /**
|
||||
// * 查询该动态下的评论
|
||||
// */
|
||||
// @Cacheable(value = "commentcount",key = "#detailId")
|
||||
// @PostMapping(value = "commentcount")
|
||||
// public Result listCommentCount(@RequestParam String detailId) {
|
||||
// try {
|
||||
// result = schisandraShareCommentReplyDomainService.listCommentCount(detailId);
|
||||
// if (log.isInfoEnabled()) {
|
||||
// log.info("获取当前文章评论内容{}", JSON.toJSONString(result));
|
||||
// }
|
||||
// return Result.ok(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("获取当前文章内容异常!");
|
||||
// }
|
||||
// }
|
||||
|
||||
|
||||
|
||||
@PostMapping("addreply")
|
||||
public Result<Boolean> addReply(@RequestBody SchisandraShareCommentReplyDTO schisandraShareCommentReplyDTO) {
|
||||
@@ -209,6 +237,7 @@ public class SchisandraShareCommentReplyController {
|
||||
Preconditions.checkNotNull(schisandraShareCommentReplyDTO.getUpdateTime(), "更新时间不能为空");
|
||||
Preconditions.checkNotNull(schisandraShareCommentReplyDTO.getIsDeleted(), "不能为空");
|
||||
SchisandraShareCommentReplyBO schisandraShareCommentReplyBO = SchisandraShareCommentReplyDTOConverter.INSTANCE.convertDTOToBO(schisandraShareCommentReplyDTO);
|
||||
caffeineUtil.caffeineBuild().invalidate(""+schisandraShareCommentReplyBO.getDetailId());
|
||||
return Result.ok(schisandraShareCommentReplyDomainService.delete(schisandraShareCommentReplyBO));
|
||||
} catch (Exception e) {
|
||||
log.error("SchisandraShareCommentReplyController.delete.error:{}", e.getMessage(), e);
|
||||
|
@@ -56,6 +56,7 @@ public class SchisandraShareDetailController {
|
||||
/**
|
||||
* 查询分享详细信息
|
||||
*/
|
||||
@Cacheable(value = "getdetail",key = "#Id")
|
||||
@PostMapping("get_detail")
|
||||
public Result selectDetail(@RequestParam("Id") String Id){
|
||||
try{
|
||||
|
@@ -0,0 +1,31 @@
|
||||
package com.schisandra.share.common.utils;
|
||||
|
||||
|
||||
import com.github.benmanes.caffeine.cache.Cache;
|
||||
import com.github.benmanes.caffeine.cache.Caffeine;
|
||||
import lombok.Setter;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.context.annotation.Bean;
|
||||
import org.springframework.context.annotation.Configuration;
|
||||
|
||||
import java.util.concurrent.TimeUnit;
|
||||
|
||||
@Configuration
|
||||
@Setter
|
||||
@Slf4j
|
||||
public class CaffeineUtil<T>{
|
||||
|
||||
public static int maximumSize=10000;
|
||||
public static int expiresTime = 1;
|
||||
public static TimeUnit unitTime = TimeUnit.MINUTES;
|
||||
@Bean
|
||||
public Cache<String,T> caffeineBuild(){
|
||||
Cache<String, T> cache = Caffeine.newBuilder()
|
||||
.maximumSize(maximumSize)
|
||||
.expireAfterWrite(expiresTime, unitTime)
|
||||
.build();
|
||||
return cache;
|
||||
}
|
||||
|
||||
|
||||
}
|
@@ -9,6 +9,7 @@ import com.schisandra.share.infra.basic.service.SchisandraShareCircleService;
|
||||
import com.schisandra.share.infra.entity.AuthUserInfoEntity;
|
||||
import com.schisandra.share.infra.rpc.UserRpc;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.data.redis.core.RedisTemplate;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
import javax.annotation.Resource;
|
||||
|
@@ -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.setReplyCount(0);
|
||||
schisandraShareCommentReply.setReplyType(0);
|
||||
schisandraShareCommentReply.setLikes(0L);
|
||||
return schisandraShareCommentReplyService.insert(schisandraShareCommentReply) > 0;
|
||||
@@ -91,8 +92,8 @@ public class SchisandraShareCommentReplyDomainServiceImpl implements SchisandraS
|
||||
List<SchisandraShareCommentReply> schisandraShareReplies = schisandraShareCommentReplyService.listReply(commentId);
|
||||
List<SchisandraShareCommentReplyBO> schisandraShareRepliesBO = SchisandraShareCommentReplyBOConverter.INSTANCE.convertEntityToBOList(schisandraShareReplies);
|
||||
schisandraShareRepliesBO.forEach(schisandraShareReplyBO -> {
|
||||
schisandraShareReplyBO.setNickto(userRpc.getUserInfo(schisandraShareReplyBO.getReplyId()).getNickName());
|
||||
AuthUserInfoEntity userInfo = userRpc.getUserInfo(schisandraShareReplyBO.getUserId());
|
||||
schisandraShareReplyBO.setNickto(userInfo.getNickName());
|
||||
schisandraShareReplyBO.setNick(userInfo.getNickName());
|
||||
schisandraShareReplyBO.setAvatar(userInfo.getAvatar());
|
||||
});
|
||||
|
@@ -80,7 +80,6 @@ public class SchisandraShareCommentReplyServiceImpl implements SchisandraShareCo
|
||||
.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))
|
||||
.where(SchisandraShareCommentReplyTableDef.SCHISANDRA_SHARE_COMMENT_REPLY.IS_DELETED.eq(IsDeletedFlagEnum.UN_DELETED.getCode()))
|
||||
.orderBy(SchisandraShareCommentReplyTableDef.SCHISANDRA_SHARE_COMMENT_REPLY.CREATED_TIME,false);
|
||||
return this.schisandraShareCommentReplyDao.selectListByQuery(wrapper);
|
||||
}
|
||||
@@ -98,8 +97,7 @@ public class SchisandraShareCommentReplyServiceImpl implements SchisandraShareCo
|
||||
SchisandraShareCommentReplyTableDef.SCHISANDRA_SHARE_COMMENT_REPLY.CREATED_TIME)
|
||||
.from(SchisandraShareCommentReplyTableDef.SCHISANDRA_SHARE_COMMENT_REPLY)
|
||||
.where(SchisandraShareCommentReplyTableDef.SCHISANDRA_SHARE_COMMENT_REPLY.TO_ID.eq(commentId))
|
||||
.where(SchisandraShareCommentReplyTableDef.SCHISANDRA_SHARE_COMMENT_REPLY.REPLY_TYPE.eq(0))
|
||||
.where(SchisandraShareCommentReplyTableDef.SCHISANDRA_SHARE_COMMENT_REPLY.IS_DELETED.eq(IsDeletedFlagEnum.UN_DELETED.getCode()))
|
||||
.where(SchisandraShareCommentReplyTableDef.SCHISANDRA_SHARE_COMMENT_REPLY.REPLY_TYPE.eq(1))
|
||||
.orderBy(SchisandraShareCommentReplyTableDef.SCHISANDRA_SHARE_COMMENT_REPLY.CREATED_TIME,true);
|
||||
return this.schisandraShareCommentReplyDao.selectListByQuery(wrapper);
|
||||
}
|
||||
|
Reference in New Issue
Block a user