@ -112,7 +112,7 @@ public class CommonServiceImpl implements CommonService {
@Override
@Override
public Comment saveOrUpdateComment ( Comment comment ) {
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 ) ;
Comment existingComment = comments . stream ( ) . findFirst ( ) . orElse ( null ) ;
if ( existingComment ! = null ) {
if ( existingComment ! = null ) {
// 如果评论对象存在,则进行更新操作
// 如果评论对象存在,则进行更新操作
@ -125,7 +125,11 @@ public class CommonServiceImpl implements CommonService {
return commentRepository . save ( existingComment ) ;
return commentRepository . save ( existingComment ) ;
} else {
} 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 ( ) ) ;
comment . setCreateTime ( Instant . now ( ) . toEpochMilli ( ) ) ;
return commentRepository . save ( comment ) ;
return commentRepository . save ( comment ) ;
}
}
@ -141,6 +145,6 @@ public class CommonServiceImpl implements CommonService {
@Override
@Override
public List < Comment > getCommentById ( Comment comment ) {
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 ( ) );
}
}
}
}