更新数据结构

develop
zhouj1203@hotmail.com 4 months ago
parent ab5ad3088b
commit 5efd36bce8

@ -112,7 +112,7 @@ public class CommonServiceImpl implements CommonService {
@Override
public Comment saveOrUpdateComment(Comment comment) {
List<Comment> comments = commentRepository.findById(comment.getId(),comment.getSchool(),comment.getActivityType());
List<Comment> 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<Comment> getCommentById(Comment comment) {
return commentRepository.findById(comment.getId(),comment.getSchool(),comment.getActivityType());
return commentRepository.findById(comment.getId(),comment.getSchool(),comment.getActivityType(),comment.getCode());
}
}

@ -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("评论内容")

@ -13,7 +13,7 @@ import java.util.List;
@Repository
public interface CommentRepository extends CosmosRepository<Comment, String> {
@Query("select * from Comment as s where s.id = @id and s.pk = 'Comment' and s.school = @school and s.activityType = @activityType ")
List<Comment> 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<Comment> findById(@Param("id") String id, @Param("school") String school,@Param("activityType") String activityType,@Param("code") String code);
}

Loading…
Cancel
Save