zhuguifei
2025-04-28 442928123f63ee497d766f9a7a14f0a6ee067e25
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
package org.jeecg.modules.doc.controller;
 
import com.alibaba.fastjson.JSON;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.apache.shiro.SecurityUtils;
import org.jeecg.common.api.vo.Result;
import org.jeecg.common.system.vo.LoginUser;
import org.jeecg.modules.doc.component.AsyncTaskComp;
import org.jeecg.modules.doc.component.DocFileDealComp;
import org.jeecg.modules.doc.component.PathPermissionComp;
import org.jeecg.modules.doc.constant.Constant;
import org.jeecg.modules.doc.dto.BatchDeleteRecoveryFileDTO;
import org.jeecg.modules.doc.dto.DeleteRecoveryFileDTO;
import org.jeecg.modules.doc.entity.DocFilePath;
import org.jeecg.modules.doc.entity.RecoveryFile;
import org.jeecg.modules.doc.dto.RestoreFileDTO;
import org.jeecg.modules.doc.service.IRecoveryFileService;
import org.jeecg.modules.doc.vo.RecoveryFileListVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
 
import javax.annotation.Resource;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Set;
import java.util.stream.Collectors;
 
@Slf4j
@RestController
@RequestMapping("/recoveryfile")
public class RecoveryFileController {
 
    @Autowired
    private IRecoveryFileService recoveryFileService;
 
    @Resource
    AsyncTaskComp asyncTaskComp;
 
    @Autowired
    PathPermissionComp pathPermissionComp;
 
    @Autowired
    DocFileDealComp fileDealComp;
 
 
    @ApiOperation(value = "删除回收文件", notes = "删除回收文件", tags = {"recoveryfile"})
    @RequestMapping(value = "/deleterecoveryfile", method = RequestMethod.POST)
    @ResponseBody
    public Result<String> deleteRecoveryFile(@RequestBody DeleteRecoveryFileDTO deleteRecoveryFileDTO) {
 
        RecoveryFile recoveryFile = recoveryFileService.getById(deleteRecoveryFileDTO.getRecoveryFileId());
 
        asyncTaskComp.deleteUserFile(recoveryFile.getPathId());
 
        recoveryFileService.removeById(deleteRecoveryFileDTO.getRecoveryFileId());
        return Result.OK("删除成功");
    }
 
 
 
    @ApiOperation(value = "批量删除回收文件", notes = "批量删除回收文件", tags = {"recoveryfile"})
    @RequestMapping(value = "/batchdelete", method = RequestMethod.POST)
    @ResponseBody
    public Result<String> batchDeleteRecoveryFile(@RequestBody BatchDeleteRecoveryFileDTO batchDeleteRecoveryFileDTO) {
        List<RecoveryFile> recoveryFileList = JSON.parseArray(batchDeleteRecoveryFileDTO.getRecoveryFileIds(), RecoveryFile.class);
        for (RecoveryFile recoveryFile : recoveryFileList) {
            RecoveryFile recoveryFile1 = recoveryFileService.getById(recoveryFile.getRecoveryFileId());
 
            if (recoveryFile1 != null) {
                asyncTaskComp.deleteUserFile(recoveryFile1.getPathId());
 
                recoveryFileService.removeById(recoveryFile1.getRecoveryFileId());
            }
 
        }
        return Result.OK("批量删除成功");
    }
 
    @ApiOperation(value = "回收文件列表", notes = "回收文件列表", tags = {"recoveryfile"})
    @RequestMapping(value = "/list", method = RequestMethod.POST)
    @ResponseBody
    public Map<String, Object> getRecoveryFileList() {
        Map<String, Object> map = new HashMap<>();
        LoginUser loginUser = (LoginUser) SecurityUtils.getSubject().getPrincipal();
        // 访问、下载、管理权限包
        Map<String, Map<String, DocFilePath>> pathPermission = pathPermissionComp.getPathPermission();
        // 拥有访问权限的文件id集合
        Map<String, DocFilePath> visits =  pathPermission.get(Constant.VISIT);
        // 拥有下载权限的文件id集合
        //Map<String, DocFilePath> downloads =  pathPermission.get(Constant.DOWNLOAD);
        // 拥有管理权限的文件id集合
        Map<String, DocFilePath> manages =  pathPermission.get(Constant.MANAGE);
 
 
        Result<List<RecoveryFileListVo>> restResult = new Result<>();
        List<RecoveryFileListVo> filePaths = recoveryFileService.selectRecoveryFileList(loginUser.getId());
        // 当前查询结果中可访问的文件集合
        filePaths = filePaths.stream().filter(
                i -> visits.get(i.getPathId())!=null || fileDealComp.isParentsOrChild(visits,i, true)
        ).collect(Collectors.toList());
 
//        Set<String> downloadSet = filePaths.stream().filter(
//                i -> downloads.get(i.getPathId()) != null || fileDealComp.isParentsOrChild(downloads,i, false)
//        ).map(DocFilePath::getPathId).collect(Collectors.toSet());
        Set<String> manageSet = filePaths.stream().filter(
                i -> manages.get(i.getPathId()) != null || fileDealComp.isParentsOrChild(manages,i, false)
        ).map(RecoveryFileListVo::getPathId).collect(Collectors.toSet());
        restResult.setResult(filePaths);
        restResult.setSuccess(true);
        map.put("result", filePaths);
        map.put("success", true);
        map.put("managePrem", manageSet);
        return map;
    }
 
    @ApiOperation(value = "还原文件", notes = "还原文件", tags = {"recoveryfile"})
    @RequestMapping(value = "/restorefile", method = RequestMethod.POST)
    @ResponseBody
    public Result restoreFile(@RequestBody RestoreFileDTO restoreFileDto) {
        LoginUser loginUser = (LoginUser) SecurityUtils.getSubject().getPrincipal();
        recoveryFileService.restorefile(restoreFileDto.getDeleteBatchNum(), restoreFileDto.getFilePath(), restoreFileDto.getPathId(), loginUser.getId());
        return Result.OK("还原成功!");
    }
 
}