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); }