From 4c81e6c54f1577f99641aa22f6e3155ed01dc797 Mon Sep 17 00:00:00 2001 From: wangqing <408564126@qq.com> Date: Fri, 8 Mar 2024 22:18:30 +0800 Subject: [PATCH] fix: comment replyToName error --- .../comment/controller/CommentController.java | 3 ++- .../luoo/comment/sensitiveword/MyDdWordAllow.java | 2 +- .../luoo/comment/sensitiveword/MyDdWordDeny.java | 15 +++++++-------- .../com/luoo/comment/service/CommentService.java | 12 +++++++----- 4 files changed, 17 insertions(+), 15 deletions(-) diff --git a/luoo_comment/src/main/java/com/luoo/comment/controller/CommentController.java b/luoo_comment/src/main/java/com/luoo/comment/controller/CommentController.java index 8e92fc7..245e95d 100644 --- a/luoo_comment/src/main/java/com/luoo/comment/controller/CommentController.java +++ b/luoo_comment/src/main/java/com/luoo/comment/controller/CommentController.java @@ -283,7 +283,8 @@ public class CommentController extends BaseController { String userId = userLoginDto.getUserId(); String content =sensitiveWordBs.findFirst(commentVo.getContent()); if (StringUtils.isNotEmpty(content)) { - return Result.forbidden(StatusCode.USER_SENSITIVE_INFO); + return Result.failed(StatusCode.COMMENT_SENSITIVE_INFO); + } Comment comment = new Comment(); BeanUtils.copyProperties(commentVo, comment); diff --git a/luoo_comment/src/main/java/com/luoo/comment/sensitiveword/MyDdWordAllow.java b/luoo_comment/src/main/java/com/luoo/comment/sensitiveword/MyDdWordAllow.java index c690ef0..135f170 100644 --- a/luoo_comment/src/main/java/com/luoo/comment/sensitiveword/MyDdWordAllow.java +++ b/luoo_comment/src/main/java/com/luoo/comment/sensitiveword/MyDdWordAllow.java @@ -1,4 +1,4 @@ -package com.luoo.comment.sensitiveWord; +package com.luoo.comment.sensitiveword; import com.github.houbb.sensitive.word.api.IWordAllow; import org.springframework.stereotype.Component; diff --git a/luoo_comment/src/main/java/com/luoo/comment/sensitiveword/MyDdWordDeny.java b/luoo_comment/src/main/java/com/luoo/comment/sensitiveword/MyDdWordDeny.java index c470896..c2f63aa 100644 --- a/luoo_comment/src/main/java/com/luoo/comment/sensitiveword/MyDdWordDeny.java +++ b/luoo_comment/src/main/java/com/luoo/comment/sensitiveword/MyDdWordDeny.java @@ -1,6 +1,7 @@ -package com.luoo.comment.sensitiveWord; +package com.luoo.comment.sensitiveword; import com.github.houbb.sensitive.word.api.IWordDeny; +import constants.SensitiveWords; import org.springframework.core.io.ClassPathResource; import org.springframework.core.io.Resource; import org.springframework.stereotype.Component; @@ -16,17 +17,15 @@ import java.util.List; @Component public class MyDdWordDeny implements IWordDeny { + String DENY_WORDS= SensitiveWords.DENY_WORDS; @Override public List deny() { List list = new ArrayList<>(); - list.add("落网"); - Resource mySensitiveWords = new ClassPathResource("denyWords.txt"); - try { - Path mySensitiveWordsPath = Paths.get(mySensitiveWords.getFile().getPath()); - list = Files.readAllLines(mySensitiveWordsPath, StandardCharsets.UTF_8); +// list.add("落网"); - } catch (IOException e) { - throw new RuntimeException(e); + String[] s = DENY_WORDS.split("\n"); + for(String denyWord:s) { + list.add(denyWord); } return list; diff --git a/luoo_comment/src/main/java/com/luoo/comment/service/CommentService.java b/luoo_comment/src/main/java/com/luoo/comment/service/CommentService.java index 2444753..e1cde52 100644 --- a/luoo_comment/src/main/java/com/luoo/comment/service/CommentService.java +++ b/luoo_comment/src/main/java/com/luoo/comment/service/CommentService.java @@ -4,10 +4,7 @@ package com.luoo.comment.service; import com.luoo.comment.client.JournalClient; import com.luoo.comment.dao.CommentDao; import com.luoo.comment.dao.CommentHisDao; -import com.luoo.comment.pojo.Comment; -import com.luoo.comment.pojo.CommentHis; -import com.luoo.comment.pojo.JournalRespDTO; -import com.luoo.comment.pojo.PublicationLike; +import com.luoo.comment.pojo.*; import constants.Constants; import dto.UserLoginDto; import dto.UserMessageDto; @@ -54,6 +51,9 @@ public class CommentService { @Autowired private CacheChannel cacheChannel; + @Autowired + private UserInfoService userInfoService; + public List findAll(){ return commentDao.findAll(); } @@ -105,8 +105,10 @@ public class CommentService { comment.setRootId(parentComment.getRootId()); comment.setRootJournalId(parentComment.getRootJournalId()); comment.setRootJournalName(parentComment.getRootJournalName()); - comment.setReplyToNickname(parentComment.getNickName()); +// comment.setReplyToNickname(parentComment.getNickName()); comment.setReplyToUserId(parentComment.getUserId()); + UserInfo userInfo = userInfoService.findById(parentComment.getUserId()); + comment.setReplyToNickname(userInfo.getNickName()); Query query = new Query(); query.addCriteria(Criteria.where("_id").is(comment.getRootId())); Update update = new Update();