diff --git a/src/main/java/cn/teammodel/controller/admin/service/impl/CommonServiceImpl.java b/src/main/java/cn/teammodel/controller/admin/service/impl/CommonServiceImpl.java index 210f737..1d2fe20 100644 --- a/src/main/java/cn/teammodel/controller/admin/service/impl/CommonServiceImpl.java +++ b/src/main/java/cn/teammodel/controller/admin/service/impl/CommonServiceImpl.java @@ -112,7 +112,11 @@ public class CommonServiceImpl implements CommonService { @Override public Comment saveOrUpdateComment(Comment comment) { - List comments = commentRepository.findById(comment.getId(),comment.getSchool(),comment.getActivityType(),comment.getCode()); + String formattedString = String.format("Comment-%s-%s-%s", + comment.getSchool(), + comment.getYear(), + comment.getSemester()); + List comments = commentRepository.findById(comment.getId(),comment.getSchool(),comment.getActivityType(),formattedString); Comment existingComment = comments.stream().findFirst().orElse(null); if (existingComment != null) { // 如果评论对象存在,则进行更新操作 @@ -125,10 +129,7 @@ public class CommonServiceImpl implements CommonService { return commentRepository.save(existingComment); } else { // 如果评论对象不存在,则创建新的记录 - String formattedString = String.format("Comment-%s-%s-%s", - comment.getSchool(), - comment.getYear(), - comment.getSemester()); + comment.setCode(formattedString); comment.setCreateTime(Instant.now().toEpochMilli()); return commentRepository.save(comment); @@ -145,6 +146,10 @@ public class CommonServiceImpl implements CommonService { @Override public List getCommentById(Comment comment) { - return commentRepository.findById(comment.getId(),comment.getSchool(),comment.getActivityType(),comment.getCode()); + String formattedString = String.format("Comment-%s-%s-%s", + comment.getSchool(), + comment.getYear(), + comment.getSemester()); + return commentRepository.findById(comment.getId(),comment.getSchool(),comment.getActivityType(),formattedString); } }