/**
* 删除视频
*
* @param ids
* @return
*/
@Transactional(rollbackFor = AppRuntimeException.class)
@Override
public void deleteBatch(Integer[] ids) {
for (final Integer id : ids) {
doDelete(id);
FriendRing friendRingEntity = friendRingDao.queryOneByVideoId(id);
if(friendRingEntity!=null){
//所有的一级评论
List<FriendRingComment> CommentsLv1ByFriendId = friendRingCommentDao.listLv1CommentByFriendId(friendRingEntity.getFriendId());
//如果没有评论直接删除朋友圈及其相关数据
if(CommentsLv1ByFriendId!=null||CommentsLv1ByFriendId.size()!=0){
for(FriendRingComment CommentLv1ByFriendId:CommentsLv1ByFriendId){
//递归删除评论
deleteComment(CommentLv1ByFriendId.getCommentId(),CommentLv1ByFriendId.getParentCommentId());
}
}
//删除朋友圈其他相关信息
int deletefriendRingFile=friendRingFileDao.delete(friendRingEntity.getFriendId());
int deletefriendRingLike=friendRingLikeDao.delete(friendRingEntity.getFriendId());
int deletefriendRingLookSet=friendRingLookSetDao.delete(friendRingEntity.getFriendId());
int deletefriendRingAt = friendRingAtDao.delete(friendRingEntity.getFriendId());
int deletefriendRing=friendRingDao.delete(friendRingEntity.getFriendId());
}
}
}
/**
* 递归删除评论
* @param commendId
* @param parentId
*/
private void deleteComment(Integer commendId,Integer parentId){
//查询parentID是commendId的所有数据 (根据一级评论查询二级评论)
List<FriendRingComment> CommentsByParentId = friendRingCommentDao.listByParentId(commendId);
//如果存在子级评论继续查询
if(CommentsByParentId!=null&&CommentsByParentId.size()>0) {
for(FriendRingComment CommentByParentId : CommentsByParentId){
deleteComment(CommentByParentId.getCommentId(),CommentByParentId.getParentCommentId());
}
}else{
//首先删除评论相关的数据
int deletefriendRingCommentLike=friendRingCommentLikeDao.delete(commendId);
int deletefriendRingCommentReply=friendRingCommentReplyDao.delete(commendId);
int affectedRows = friendRingCommentDao.delete(commendId);
//根据parentID查询父级评论
if(parentId!=0){
FriendRingComment parentComment = friendRingCommentDao.queryParentByParentId(parentId);
deleteComment(parentComment.getCommentId(),parentComment.getParentCommentId());
}
}
}