|
16 | 16 |
|
17 | 17 | package top.continew.admin.system.service.impl; |
18 | 18 |
|
| 19 | +import cn.hutool.core.collection.CollUtil; |
19 | 20 | import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; |
| 21 | +import com.baomidou.mybatisplus.core.plugins.IgnoreStrategy; |
| 22 | +import com.baomidou.mybatisplus.core.plugins.InterceptorIgnoreHelper; |
20 | 23 | import com.baomidou.mybatisplus.extension.plugins.pagination.Page; |
21 | 24 | import lombok.RequiredArgsConstructor; |
22 | 25 | import org.dromara.x.file.storage.core.FileInfo; |
@@ -94,25 +97,33 @@ public void delete(Long id) { |
94 | 97 | @Override |
95 | 98 | @Transactional(rollbackFor = Exception.class) |
96 | 99 | public void clean() { |
97 | | - // 查询文件 |
| 100 | + // 查询回收站记录 |
98 | 101 | List<FileDO> list = fileMapper.selectListInRecycleBin(); |
99 | | - // 删除记录 |
100 | | - fileMapper.cleanRecycleBin(UserContextHolder.getUserId()); |
101 | | - // 删除文件 |
102 | | - // 批量获取存储配置 |
103 | | - Map<Long, List<FileDO>> fileListGroup = list.stream().collect(Collectors.groupingBy(FileDO::getStorageId)); |
104 | | - List<StorageDO> storageList = storageService.listByIds(fileListGroup.keySet()); |
105 | | - Map<Long, StorageDO> storageGroup = storageList.stream() |
106 | | - .collect(Collectors.toMap(StorageDO::getId, Function.identity(), (existing, replacement) -> existing)); |
107 | | - // 删除文件 |
108 | | - for (Map.Entry<Long, List<FileDO>> entry : fileListGroup.entrySet()) { |
109 | | - StorageDO storage = storageGroup.get(entry.getKey()); |
110 | | - // 清空回收站 |
111 | | - FileInfo fileInfo = new FileInfo(); |
112 | | - fileInfo.setPlatform(storage.getCode()); |
113 | | - fileInfo.setBasePath(StringConstants.EMPTY); |
114 | | - fileInfo.setPath(storage.getRecycleBinPath()); |
115 | | - fileStorageService.delete(fileInfo); |
| 102 | + if (CollUtil.isEmpty(list)) { |
| 103 | + return; |
| 104 | + } |
| 105 | + try { |
| 106 | + InterceptorIgnoreHelper.handle(IgnoreStrategy.builder().blockAttack(true).build()); |
| 107 | + // 删除记录 |
| 108 | + fileMapper.cleanRecycleBin(UserContextHolder.getUserId()); |
| 109 | + // 删除文件 |
| 110 | + // 批量获取存储配置 |
| 111 | + Map<Long, List<FileDO>> fileListGroup = list.stream().collect(Collectors.groupingBy(FileDO::getStorageId)); |
| 112 | + List<StorageDO> storageList = storageService.listByIds(fileListGroup.keySet()); |
| 113 | + Map<Long, StorageDO> storageGroup = storageList.stream() |
| 114 | + .collect(Collectors.toMap(StorageDO::getId, Function.identity(), (existing, replacement) -> existing)); |
| 115 | + // 删除文件 |
| 116 | + for (Map.Entry<Long, List<FileDO>> entry : fileListGroup.entrySet()) { |
| 117 | + StorageDO storage = storageGroup.get(entry.getKey()); |
| 118 | + // 清空回收站 |
| 119 | + FileInfo fileInfo = new FileInfo(); |
| 120 | + fileInfo.setPlatform(storage.getCode()); |
| 121 | + fileInfo.setBasePath(StringConstants.EMPTY); |
| 122 | + fileInfo.setPath(storage.getRecycleBinPath()); |
| 123 | + fileStorageService.delete(fileInfo); |
| 124 | + } |
| 125 | + } finally { |
| 126 | + InterceptorIgnoreHelper.clearIgnoreStrategy(); |
116 | 127 | } |
117 | 128 | } |
118 | 129 |
|
|
0 commit comments