package com.vctgo.file.service.impl;

import java.util.*;
import java.util.stream.Collectors;

import com.alibaba.fastjson2.JSONArray;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.OrderItem;
import com.vctgo.common.core.constant.RoleConstants;
import com.vctgo.common.core.constant.SecurityConstants;
import com.vctgo.common.core.utils.DateUtils;
import com.vctgo.common.core.utils.StrUtils;
import com.vctgo.common.redis.service.RedisService;
import com.vctgo.common.security.utils.SecurityUtils;
import com.vctgo.file.domain.FileAshInfo;
import com.vctgo.file.domain.FileReUserOperate;
import com.vctgo.file.mapper.FileAshInfoMapper;
import com.vctgo.file.mapper.FileInfoMapper;
import com.vctgo.file.mapper.FileReUserOperateMapper;
import com.vctgo.file.service.IDistributedFileSystemService;
import com.vctgo.file.service.IFileAshInfoService;
import com.vctgo.file.service.IFileInfoService;
import com.vctgo.file.utils.ConstantUtils;
import com.vctgo.file.utils.FileInfoTreeUtils;
import com.vctgo.file.utils.FileUtils;
import com.vctgo.system.api.domain.FileInfo;
import com.vctgo.system.api.domain.SysRole;
import com.vctgo.system.api.domain.SysUserTempalte;
import com.vctgo.system.api.model.LoginUser;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.collections4.CollectionUtils;
import org.apache.commons.io.FilenameUtils;
import org.apache.commons.lang.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.vctgo.common.core.text.Convert;
import com.vctgo.common.core.utils.ServletUtils;
import com.vctgo.common.mybatisplus.constant.MybatisPageConstants;

/**
 * 文件回收站基本信息Service业务层处理
 *
 * @author caesar
 * @date 2024-02-26
 */
@Slf4j
@Service
public class FileAshInfoServiceImpl implements IFileAshInfoService {
    @Autowired
    private FileAshInfoMapper fileAshInfoMapper;
    @Autowired
    private FileInfoMapper fileInfoMapper;
    @Autowired
    private RedisService redisService;
    @Autowired
    private FileReUserOperateMapper fileReUserOperateMapper;
    @Autowired
    private IFileInfoService fileInfoService;

    @Override
    public IPage<FileAshInfo> getFileAshPage(FileAshInfo fileAshInfo) {
        Page page = new Page(Convert.toLong(ServletUtils.getParameterToInt(MybatisPageConstants.PAGE_NUM), 1L), Convert.toLong(ServletUtils.getParameterToInt(MybatisPageConstants.PAGE_SIZE), 50L));
        // 超级管理员/文件资源管理员可以查看全部回收文件、文件夹
        List<String> roleKeyList = SecurityUtils.getLoginUser().getSysRolesList().stream().map(SysRole::getRoleKey).collect(Collectors.toList());
        if (!roleKeyList.contains(RoleConstants.ROLE_KEY_ADMIN) && !roleKeyList.contains(RoleConstants.ROLE_KEY_FILE_RESOURCE_USER)) {
            fileAshInfo.setUpdateById(SecurityUtils.getUserId());
        }
        //从redis获取当前租户下的全部人员
        List<SysUserTempalte> sysUserTemplateList = new ArrayList<>();
        Collection<String> keys = redisService.keys(SecurityConstants.DETAILS_TENANT + SecurityUtils.getTenantId());
        if (CollectionUtils.isNotEmpty(keys)) {
            List<String> multiCacheValue = redisService.getMultiCacheValue(new ArrayList<>(keys));
            multiCacheValue.forEach(cache -> sysUserTemplateList.addAll(JSONArray.parseArray(cache, SysUserTempalte.class)));
        }
        if (StrUtils.isNotEmpty(fileAshInfo.getUpdateBy())) {
            List<Long> userIdList = sysUserTemplateList.stream().filter(sysUserTempalte -> sysUserTempalte.getNickName().contains(fileAshInfo.getUpdateBy())).map(SysUserTempalte::getUserId).collect(Collectors.toList());
            fileAshInfo.setUserIdList(userIdList);
            if (CollectionUtils.isEmpty(userIdList)) {
                return new Page<>();
            }
        }
        fileAshInfo.setTenantId(SecurityUtils.getTenantId());
        fileAshInfo.setIsDeleted(ConstantUtils.IS_DELETED_0);
        IPage<FileAshInfo> fileIPage = fileAshInfoMapper.selectFileAshInfoList(page, fileAshInfo);
        if (CollectionUtils.isNotEmpty(fileIPage.getRecords())) {
            fileIPage.getRecords().forEach(fileInfoTmp -> fileInfoTmp
                    .setFileSizeBytes(Objects.nonNull(fileInfoTmp.getFileSize()) ? FileUtils.convertBytes(fileInfoTmp.getFileSize()) : ""));
            /**
             *  填充创建人、更新人昵称
             */
            //用户数据形式转化
            HashMap<String, SysUserTempalte> userTemplateHashMap = new HashMap<>();
            if (CollectionUtils.isNotEmpty(sysUserTemplateList)) {
                for (SysUserTempalte sysUserTemplate : sysUserTemplateList) {
                    userTemplateHashMap.put(sysUserTemplate.getUserId() + "", sysUserTemplate);
                }
            }
            for (FileAshInfo info : fileIPage.getRecords()) {
                //创建人
                SysUserTempalte sysUserTemplateCreate = userTemplateHashMap.get(info.getCreateById() + "");
                info.setCreateBy(userTemplateHashMap.get(info.getCreateById() + "") != null ? sysUserTemplateCreate.getNickName() : "");
                //更新人
                SysUserTempalte sysUserTemplateUpdate = userTemplateHashMap.get(info.getUpdateById() + "");
                info.setUpdateBy(userTemplateHashMap.get(info.getUpdateById() + "") != null ? sysUserTemplateUpdate.getNickName() : "");
            }
        }
        return fileIPage;
    }


    @Override
    public void doBatchRemoveFile(String ids) {
        //全部文件、文件夹
        List<FileInfo> fileInfoRootList = fileInfoMapper.selectList(new LambdaQueryWrapper<FileInfo>().in(FileInfo::getId, Arrays.asList(ids.split(","))));
        if (CollectionUtils.isNotEmpty(fileInfoRootList)) {
            for (FileInfo fileInfoRoot : fileInfoRootList) {
                //文件
                if (ConstantUtils.IS_DIRECTORY_FILE_0.equals(fileInfoRoot.getFileIsDirectory())) {
                    fileInfoRoot.setIsDeleted(ConstantUtils.IS_DELETED_1);
                    fileInfoMapper.updateById(fileInfoRoot);
                }
                //文件夹
                if (ConstantUtils.IS_DIRECTORY_FILE_1.equals(fileInfoRoot.getFileIsDirectory())) {
                    //当前文件夹
                    fileInfoRoot.setIsDeleted(ConstantUtils.IS_DELETED_1);
                    fileInfoMapper.updateById(fileInfoRoot);
                    //子文件、文件夹
                    List<FileInfo> fileInfoChildList = fileInfoMapper.selectListByParentId(fileInfoRoot.getId());
                    if (CollectionUtils.isNotEmpty(fileInfoChildList)) {
                        for (FileInfo childFile : fileInfoChildList) {
                            childFile.setIsDeleted(ConstantUtils.IS_DELETED_1);
                        }
                        fileInfoMapper.updateBatch(fileInfoChildList);
                    }
                }
            }
        }
        //回收站文件删除
        List<FileAshInfo> fileAshInfoList = fileAshInfoMapper.selectList(new QueryWrapper<FileAshInfo>().lambda().in(FileAshInfo::getFileId, Arrays.asList(ids.split(","))));
        fileAshInfoList = fileAshInfoList.stream().peek(fileAshInfo -> fileAshInfo.setIsDeleted(ConstantUtils.IS_DELETED_1)).collect(Collectors.toList());
        fileAshInfoMapper.updateBatch(fileAshInfoList);
    }

    @Override
    public void doBatchRecoverFile(String ids) {
        LoginUser loginUser = SecurityUtils.getLoginUser();
        /**
         *  全部文件、文件夹
         *  1、文件：
         *      1.1     当前文件目录下，相同文件类型，恢复时文件名是否重复
         *      1.2     当前文件与用户权限关系设置为显示
         *      1.3     当前文件回收站记录删除
         *      1.4             目录上文件夹恢复
         *      1.5             目录上文件夹恢复时文件名是否重复
         *      1.6             目录上文件夹与用户权限关系设置为显示
         *  2、文件夹
         *      2.1     当前文件夹恢复时文件夹名是否重复
         *      2.2     当前文件夹与用户权限关系设置为显示
         *      2.3     当前文件夹回收站文件删除
         *
         *      2.1               目录上文件夹恢复
         *      2.2               目录上文件夹恢复时是否文件名重复
         *      2.3               目录上文件夹与用户权限关系设置为显示
         *
         *      2.1               文件夹下的子文件、子文件夹
         *      2.2               过滤掉出现在回收站中的子文件、子文件夹
         *      2.3                       子文件夹恢复时文件夹名是否重复
         *      2.4                       子文件恢复时文件名是否重复
         *      2.5               子文件、文件夹与用户权限关系设置为显示
         *      2.6               子文件、文件夹恢复
         *
         */
        List<FileInfo> fileInfoRootList = fileInfoMapper.selectList(new LambdaQueryWrapper<FileInfo>().in(FileInfo::getId, Arrays.asList(ids.split(","))));
        if (CollectionUtils.isNotEmpty(fileInfoRootList)) {
            for (FileInfo fileInfoRoot : fileInfoRootList) {
                /**
                 *  文件
                 */
                if (ConstantUtils.IS_DIRECTORY_FILE_0.equals(fileInfoRoot.getFileIsDirectory())) {
                    fileInfoRoot.setFileIsHide(ConstantUtils.IS_DELETED_0);
                    fileInfoRoot.setUpdateById(loginUser.getUserid());
                    fileInfoRoot.setUpdateTime(new Date());
                    //同目录下、相同文件类型、文件名称不可重复,如果重复文件名增加后缀
                    List<FileInfo> fileNameRepeatList = fileInfoService.selectListByFileInfo(FileInfo.builder()
                            .tenantId(SecurityUtils.getTenantId())
                            .fileParentId(fileInfoRoot.getFileParentId())
                            .fileName(fileInfoRoot.getFileName())
                            .fileExtension(fileInfoRoot.getFileExtension())
                            .fileIsDirectory(ConstantUtils.IS_DIRECTORY_FILE_0)
                            .isDeleted(ConstantUtils.IS_DELETED_0)
                            .fileIsHide(ConstantUtils.IS_DELETED_0)
                            .build());
                    if (CollectionUtils.isNotEmpty(fileNameRepeatList)) {
                        for (FileInfo info : fileNameRepeatList) {
                            if (!(fileInfoRoot.getId() + "").equals(info.getId() + "")) {
                                fileInfoRoot.setFileFullName(fileInfoRoot.getFileName() + "_" + System.currentTimeMillis() + "." + fileInfoRoot.getFileExtension());
                                fileInfoRoot.setFileName(fileInfoRoot.getFileFullName().replace("." + fileInfoRoot.getFileExtension(), ""));
                            }
                        }
                    }
                    fileInfoMapper.updateById(fileInfoRoot);
                    //当前文件与用户权限关系设置为显示
                    List<FileReUserOperate> deletedOperateList = fileReUserOperateMapper.selectList(new QueryWrapper<FileReUserOperate>().lambda()
                            .eq(FileReUserOperate::getFileId, fileInfoRoot.getId()));
                    for (FileReUserOperate userOperate : deletedOperateList) {
                        userOperate.setIsDeleted(ConstantUtils.IS_DELETED_0);
                        userOperate.setUpdateById(SecurityUtils.getUserId());
                        userOperate.setUpdateTime(new Date());
                    }
                    fileReUserOperateMapper.updateBatch(deletedOperateList);
                    //当前文件回收站记录删除
                    FileAshInfo fileAshInfo = fileAshInfoMapper.selectOne(new QueryWrapper<FileAshInfo>().lambda()
                            .eq(FileAshInfo::getFileId, fileInfoRoot.getId())
                            .eq(FileAshInfo::getIsDeleted,ConstantUtils.IS_DELETED_0));
                    if (Objects.nonNull(fileAshInfo)) {
                        fileAshInfo.setIsDeleted(ConstantUtils.IS_DELETED_1);
                        fileAshInfo.setUpdateById(SecurityUtils.getUserId());
                        fileAshInfo.setUpdateTime(new Date());
                        fileAshInfoMapper.updateById(fileAshInfo);
                    }
                    //当前文件的目录上文件夹恢复
                    List<String> ancestorFileIdList = Arrays.asList(fileInfoRoot.getAncestors().split(","));
                    List<FileInfo> ancestorFileInfoList = fileInfoMapper.selectList(new QueryWrapper<FileInfo>().lambda().in(FileInfo::getId, ancestorFileIdList));
                    for (FileInfo ancestorFileInfo : ancestorFileInfoList) {
                        //当前文件的目录上文件夹恢复时文件名是否重复
                        List<FileInfo> ancestorFileInfoNameRepeatList = fileInfoService.selectListByFileInfo(FileInfo.builder()
                                .tenantId(SecurityUtils.getTenantId())
                                .fileParentId(ancestorFileInfo.getFileParentId())
                                .fileName(ancestorFileInfo.getFileName())
                                .fileIsDirectory(ConstantUtils.IS_DIRECTORY_FILE_1)
                                .isDeleted(ConstantUtils.IS_DELETED_0)
                                .fileIsHide(ConstantUtils.IS_DELETED_0).build());
                        if (CollectionUtils.isNotEmpty(ancestorFileInfoNameRepeatList)) {
                            for (FileInfo info : ancestorFileInfoNameRepeatList) {
                                if (!(ancestorFileInfo.getId() + "").equals(info.getId() + "")) {
                                    ancestorFileInfo.setFileName(ancestorFileInfo.getFileName() + "_" + System.currentTimeMillis());
                                    ancestorFileInfo.setFileFullName(ancestorFileInfo.getFileName());
                                }
                            }
                        }
                        ancestorFileInfo.setFileIsHide(ConstantUtils.IS_DELETED_0);
                        ancestorFileInfo.setIsDeleted(ConstantUtils.IS_DELETED_0);
                        ancestorFileInfo.setUpdateById(SecurityUtils.getUserId());
                        ancestorFileInfo.setUpdateTime(new Date());
                        fileInfoMapper.updateById(ancestorFileInfo);

                        //当前文件的目录上文件夹与用户权限关系设置为显示
                        List<FileReUserOperate> ancestorFileInfoOperateList = fileReUserOperateMapper.selectList(new QueryWrapper<FileReUserOperate>().lambda()
                                .eq(FileReUserOperate::getFileId, ancestorFileInfo.getId()));
                        for (FileReUserOperate userOperate : ancestorFileInfoOperateList) {
                            userOperate.setIsDeleted(ConstantUtils.IS_DELETED_0);
                            userOperate.setUpdateById(SecurityUtils.getUserId());
                            userOperate.setUpdateTime(new Date());
                        }
                        fileReUserOperateMapper.updateBatch(deletedOperateList);
                    }
                }
                /**
                 *  文件夹
                 */
                if (ConstantUtils.IS_DIRECTORY_FILE_1.equals(fileInfoRoot.getFileIsDirectory())) {
                    //当前文件夹恢复时是否文件夹名是否重复
                    List<FileInfo> fileNameRepeatList = fileInfoService.selectListByFileInfo(FileInfo.builder()
                            .tenantId(SecurityUtils.getTenantId())
                            .fileParentId(fileInfoRoot.getFileParentId())
                            .fileName(fileInfoRoot.getFileName())
                            .fileIsDirectory(ConstantUtils.IS_DIRECTORY_FILE_1)
                            .isDeleted(ConstantUtils.IS_DELETED_0)
                            .fileIsHide(ConstantUtils.IS_DELETED_0)
                            .build());
                    if (CollectionUtils.isNotEmpty(fileNameRepeatList)) {
                        for (FileInfo info : fileNameRepeatList) {
                            if (!(fileInfoRoot.getId() + "").equals(info.getId() + "")) {
                                fileInfoRoot.setFileName(fileInfoRoot.getFileName() + "_" + System.currentTimeMillis());
                                fileInfoRoot.setFileFullName(fileInfoRoot.getFileName());
                            }
                        }
                    }
                    fileInfoRoot.setFileIsHide(ConstantUtils.IS_DELETED_0);
                    fileInfoRoot.setUpdateById(loginUser.getUserid());
                    fileInfoRoot.setUpdateTime(new Date());
                    fileInfoMapper.updateById(fileInfoRoot);
                    //当前文件夹与用户权限关系设置为显示
                    List<FileReUserOperate> deletedOperateList = fileReUserOperateMapper.selectList(new QueryWrapper<FileReUserOperate>().lambda()
                            .eq(FileReUserOperate::getFileId, fileInfoRoot.getId()));
                    for (FileReUserOperate userOperate : deletedOperateList) {
                        userOperate.setIsDeleted(ConstantUtils.IS_DELETED_0);
                        userOperate.setUpdateById(SecurityUtils.getUserId());
                        userOperate.setUpdateTime(new Date());
                    }
                    fileReUserOperateMapper.updateBatch(deletedOperateList);
                    //当前文件夹回收站文件删除
                    FileAshInfo fileAshInfo = fileAshInfoMapper.selectOne(new QueryWrapper<FileAshInfo>().lambda()
                            .eq(FileAshInfo::getFileId, fileInfoRoot.getId())
                            .eq(FileAshInfo::getIsDeleted,ConstantUtils.IS_DELETED_0));
                    if (Objects.nonNull(fileAshInfo)) {
                        fileAshInfo.setIsDeleted(ConstantUtils.IS_DELETED_1);
                        fileAshInfo.setUpdateById(SecurityUtils.getUserId());
                        fileAshInfo.setUpdateTime(new Date());
                        fileAshInfoMapper.updateById(fileAshInfo);
                    }
                    //当前文件夹的目录上文件夹恢复
                    List<String> ancestorFileIdList = Arrays.asList(fileInfoRoot.getAncestors().split(","));
                    List<FileInfo> ancestorFileInfoList = fileInfoMapper.selectList(new QueryWrapper<FileInfo>().lambda().in(FileInfo::getId, ancestorFileIdList));
                    for (FileInfo ancestorFileInfo : ancestorFileInfoList) {
                        //验证当前文件夹的目录上文件夹恢复时是否文件名重复
                        List<FileInfo> ancestorFileInfoNameRepeatList = fileInfoService.selectListByFileInfo(FileInfo.builder()
                                .tenantId(SecurityUtils.getTenantId())
                                .fileParentId(ancestorFileInfo.getFileParentId())
                                .fileName(ancestorFileInfo.getFileName())
                                .fileIsDirectory(ConstantUtils.IS_DIRECTORY_FILE_1)
                                .isDeleted(ConstantUtils.IS_DELETED_0)
                                .fileIsHide(ConstantUtils.IS_DELETED_0).build());
                        if (CollectionUtils.isNotEmpty(ancestorFileInfoNameRepeatList)) {
                            for (FileInfo info : ancestorFileInfoNameRepeatList) {
                                if (!(ancestorFileInfo.getId() + "").equals(info.getId() + "")) {
                                    ancestorFileInfo.setFileName(ancestorFileInfo.getFileName() + "_" + System.currentTimeMillis());
                                    ancestorFileInfo.setFileFullName(ancestorFileInfo.getFileName());
                                }
                            }
                        }
                        ancestorFileInfo.setFileIsHide(ConstantUtils.IS_DELETED_0);
                        ancestorFileInfo.setIsDeleted(ConstantUtils.IS_DELETED_0);
                        ancestorFileInfo.setUpdateById(SecurityUtils.getUserId());
                        ancestorFileInfo.setUpdateTime(new Date());
                        fileInfoMapper.updateById(ancestorFileInfo);

                        //当前文件夹的目录上文件夹与用户权限关系设置为显示
                        List<FileReUserOperate> ancestorFileInfoOperateList = fileReUserOperateMapper.selectList(new QueryWrapper<FileReUserOperate>().lambda()
                                .eq(FileReUserOperate::getFileId, ancestorFileInfo.getId()));
                        for (FileReUserOperate userOperate : ancestorFileInfoOperateList) {
                            userOperate.setIsDeleted(ConstantUtils.IS_DELETED_0);
                            userOperate.setUpdateById(SecurityUtils.getUserId());
                            userOperate.setUpdateTime(new Date());
                        }
                        fileReUserOperateMapper.updateBatch(deletedOperateList);
                    }

                    //文件夹下的子文件、子文件夹
                    List<FileInfo> fileInfoChildList = fileInfoMapper.selectAllListByParentId(fileInfoRoot.getId());
                    //文件夹下的子文件、子文件夹转为树形结构
                    List<FileInfo> fileInfoChildTreeList = FileInfoTreeUtils.getFileInfoTreeList(fileInfoChildList,fileInfoRoot.getId());
                    if (CollectionUtils.isNotEmpty(fileInfoChildTreeList)) {
                        for (FileInfo fileInfoChild : fileInfoChildTreeList) {
                            doRecoverChildFile(fileInfoChild);
                        }
                    }
                }
            }
        }
    }

    private void doRecoverChildFile(FileInfo fileInfoChild){
        //判断文件夹下的子文件、子文件夹存在回收站中暂不恢复
        List<FileAshInfo> fileAshInfoList = fileAshInfoMapper.selectList(new QueryWrapper<FileAshInfo>().lambda()
                .eq(FileAshInfo::getFileId, fileInfoChild.getId())
                .eq(FileAshInfo::getIsDeleted, ConstantUtils.IS_DELETED_0));
        if (CollectionUtils.isEmpty(fileAshInfoList)){
            //子文件夹恢复时文件夹名是否重复
            if (ConstantUtils.IS_DIRECTORY_FILE_1.equals(fileInfoChild.getFileIsDirectory())){
                List<FileInfo> ChildFileNameRepeatList = fileInfoService.selectListByFileInfo(FileInfo.builder()
                        .tenantId(SecurityUtils.getTenantId())
                        .fileParentId(fileInfoChild.getFileParentId())
                        .fileName(fileInfoChild.getFileName())
                        .fileIsDirectory(ConstantUtils.IS_DIRECTORY_FILE_1)
                        .isDeleted(ConstantUtils.IS_DELETED_0)
                        .fileIsHide(ConstantUtils.IS_DELETED_0).build());
                if (CollectionUtils.isNotEmpty(ChildFileNameRepeatList)) {
                    for (FileInfo info : ChildFileNameRepeatList) {
                        if (!(fileInfoChild.getId() + "").equals(info.getId() + "")) {
                            fileInfoChild.setFileName(fileInfoChild.getFileName() + "_" + System.currentTimeMillis());
                            fileInfoChild.setFileFullName(fileInfoChild.getFileName());
                        }
                    }
                }
            }
            //子文件恢复时文件名是否重复
            if (ConstantUtils.IS_DIRECTORY_FILE_0.equals(fileInfoChild.getFileIsDirectory())) {
                List<FileInfo> childFileNameRepeatList = fileInfoService.selectListByFileInfo(FileInfo.builder()
                        .tenantId(SecurityUtils.getTenantId())
                        .fileParentId(fileInfoChild.getFileParentId())
                        .fileName(fileInfoChild.getFileName())
                        .fileExtension(fileInfoChild.getFileExtension())
                        .fileIsDirectory(ConstantUtils.IS_DIRECTORY_FILE_0)
                        .isDeleted(ConstantUtils.IS_DELETED_0)
                        .fileIsHide(ConstantUtils.IS_DELETED_0).build());
                if (CollectionUtils.isNotEmpty(childFileNameRepeatList)) {
                    for (FileInfo info : childFileNameRepeatList) {
                        if (!(fileInfoChild.getId() + "").equals(info.getId() + "")) {
                            fileInfoChild.setFileFullName(fileInfoChild.getFileName()+ "_" + System.currentTimeMillis() + "." + fileInfoChild.getFileExtension());
                            fileInfoChild.setFileName(fileInfoChild.getFileFullName().replace("." + fileInfoChild.getFileExtension(), ""));
                        }
                    }
                }
            }
            fileInfoChild.setFileIsHide(ConstantUtils.IS_DELETED_0);
            fileInfoChild.setUpdateById(SecurityUtils.getUserId());
            fileInfoChild.setUpdateTime(new Date());
            //文件夹下的子文件、文件夹与用户权限关系设置为显示
            List<FileReUserOperate> deletedChildOperateList = fileReUserOperateMapper.selectList(new QueryWrapper<FileReUserOperate>().lambda()
                    .eq(FileReUserOperate::getFileId, fileInfoChild.getId()));
            for (FileReUserOperate userOperate : deletedChildOperateList) {
                userOperate.setIsDeleted(ConstantUtils.IS_DELETED_0);
                userOperate.setUpdateById(SecurityUtils.getUserId());
                userOperate.setUpdateTime(new Date());
            }
            fileReUserOperateMapper.updateBatch(deletedChildOperateList);
            //文件夹下的子文件、文件夹恢复
            fileInfoMapper.updateById(fileInfoChild);
            //判断文件夹下的子文件、文件夹下是否存在子文件、文件夹
            List<FileInfo> fileInfoChildSysFileList = fileInfoChild.getSysFileList();
            if (CollectionUtils.isNotEmpty(fileInfoChildSysFileList)){
                for (FileInfo fileInfoChildSysFile : fileInfoChildSysFileList) {
                    doRecoverChildFile(fileInfoChildSysFile);
                }
            }
        }
    }
}
