关于用户朋友圈信息及其评论点赞信息的递归删除

 /**
     * 删除视频
     *
     * @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());
            }
        }
    }

 

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值