From 5efd36bce8692333ef3c8de4b98a1d375e41510f Mon Sep 17 00:00:00 2001 From: "zhouj1203@hotmail.com" Date: Fri, 30 Aug 2024 13:51:28 +0800 Subject: [PATCH] =?UTF-8?q?=E6=9B=B4=E6=96=B0=E6=95=B0=E6=8D=AE=E7=BB=93?= =?UTF-8?q?=E6=9E=84?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../admin/service/impl/CommonServiceImpl.java | 10 +++++++--- .../java/cn/teammodel/model/entity/common/Comment.java | 4 ++++ .../cn/teammodel/repository/CommentRepository.java | 4 ++-- 3 files changed, 13 insertions(+), 5 deletions(-) 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 7a8451b..210f737 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,7 @@ public class CommonServiceImpl implements CommonService { @Override public Comment saveOrUpdateComment(Comment comment) { - List comments = commentRepository.findById(comment.getId(),comment.getSchool(),comment.getActivityType()); + List comments = commentRepository.findById(comment.getId(),comment.getSchool(),comment.getActivityType(),comment.getCode()); Comment existingComment = comments.stream().findFirst().orElse(null); if (existingComment != null) { // 如果评论对象存在,则进行更新操作 @@ -125,7 +125,11 @@ public class CommonServiceImpl implements CommonService { return commentRepository.save(existingComment); } else { // 如果评论对象不存在,则创建新的记录 - comment.setCode("Comment-"+ comment.getSchool()); + 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); } @@ -141,6 +145,6 @@ public class CommonServiceImpl implements CommonService { @Override public List getCommentById(Comment comment) { - return commentRepository.findById(comment.getId(),comment.getSchool(),comment.getActivityType()); + return commentRepository.findById(comment.getId(),comment.getSchool(),comment.getActivityType(),comment.getCode()); } } diff --git a/src/main/java/cn/teammodel/model/entity/common/Comment.java b/src/main/java/cn/teammodel/model/entity/common/Comment.java index d0acbc5..ffc3667 100644 --- a/src/main/java/cn/teammodel/model/entity/common/Comment.java +++ b/src/main/java/cn/teammodel/model/entity/common/Comment.java @@ -28,6 +28,10 @@ public class Comment extends BaseItem { private int ttl = -1; private Long createTime; private Long updateTime; + @ApiModelProperty("学年") + private int year; + @ApiModelProperty("当前学年所处第几学期") + private int semester; @Data public static class ContentInfo { @ApiModelProperty("评论内容") diff --git a/src/main/java/cn/teammodel/repository/CommentRepository.java b/src/main/java/cn/teammodel/repository/CommentRepository.java index cddfcf4..9087efa 100644 --- a/src/main/java/cn/teammodel/repository/CommentRepository.java +++ b/src/main/java/cn/teammodel/repository/CommentRepository.java @@ -13,7 +13,7 @@ import java.util.List; @Repository public interface CommentRepository extends CosmosRepository { - @Query("select * from Comment as s where s.id = @id and s.pk = 'Comment' and s.school = @school and s.activityType = @activityType ") - List findById(@Param("id") String id, @Param("school") String school,@Param("activityType") String activityType); + @Query("select * from Comment as s where s.id = @id and s.pk = 'Comment' and s.school = @school and s.activityType = @activityType and s.code = @code ") + List findById(@Param("id") String id, @Param("school") String school,@Param("activityType") String activityType,@Param("code") String code); }