优化代码
This commit is contained in:
parent
567f6e53e8
commit
0fd2804517
|
|
@ -34,4 +34,8 @@ public class FileRecycleQueryVO {
|
||||||
private String dataOwner;
|
private String dataOwner;
|
||||||
|
|
||||||
private int dataOwnCode;
|
private int dataOwnCode;
|
||||||
|
|
||||||
|
private String filePath;
|
||||||
|
|
||||||
|
private String filePrjPath;
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -553,4 +553,32 @@ public class CommonService {
|
||||||
return "";
|
return "";
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public Map<String, String> getFilesPath(List<String> paths) {
|
||||||
|
Map<String, String> res = new HashMap<>();
|
||||||
|
if (CollUtil.isEmpty(paths)) {
|
||||||
|
return res;
|
||||||
|
}
|
||||||
|
Set<String> ids = new HashSet<>();
|
||||||
|
for (String path : paths) {
|
||||||
|
String[] strs = path.split(MYSQL_FILE_PATH_SPLIT);
|
||||||
|
ids.addAll(Arrays.asList(strs));
|
||||||
|
}
|
||||||
|
Map<String, String> idNameMap = edFileInfoMapper.selectList(Wrappers.<EdFileInfo>lambdaQuery()
|
||||||
|
.select(EdFileInfo::getFileName, EdFileInfo::getId)
|
||||||
|
.in(EdFileInfo::getId, ids))
|
||||||
|
.stream()
|
||||||
|
.collect(Collectors.toMap(EdFileInfo::getId, EdFileInfo::getFileName));
|
||||||
|
|
||||||
|
for (String path : paths) {
|
||||||
|
String[] strs = path.split(MYSQL_FILE_PATH_SPLIT);
|
||||||
|
StringBuilder stringBuilder = new StringBuilder();
|
||||||
|
for (int i = 0; i < strs.length - 1; i++) {
|
||||||
|
String id = strs[i];
|
||||||
|
String name = idNameMap.get(id);
|
||||||
|
stringBuilder.append("/").append(name);
|
||||||
|
}
|
||||||
|
res.put(path, stringBuilder.substring(1));
|
||||||
|
}
|
||||||
|
return res;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -33,6 +33,7 @@ import org.springframework.transaction.annotation.Transactional;
|
||||||
|
|
||||||
import javax.annotation.Resource;
|
import javax.annotation.Resource;
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
|
import java.util.HashMap;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
import java.util.stream.Collectors;
|
import java.util.stream.Collectors;
|
||||||
|
|
@ -112,8 +113,16 @@ public class FileRecycleServiceImpl implements FileRecycleService {
|
||||||
Page<EdFileInfo> edFileInfoPage = this.edFileInfoMapper.selectPage(new Page<>(pars.getPageNum(), pars.getPageSize()), queryWrapper);
|
Page<EdFileInfo> edFileInfoPage = this.edFileInfoMapper.selectPage(new Page<>(pars.getPageNum(), pars.getPageSize()), queryWrapper);
|
||||||
long total = edFileInfoPage.getTotal();
|
long total = edFileInfoPage.getTotal();
|
||||||
List<FileRecycleQueryVO> records = BeanUtil.copyToList(edFileInfoPage.getRecords(), FileRecycleQueryVO.class);
|
List<FileRecycleQueryVO> records = BeanUtil.copyToList(edFileInfoPage.getRecords(), FileRecycleQueryVO.class);
|
||||||
records.forEach(e -> e.setDataOwner(DataOwnEnum.getTypeByCode(e.getDataOwnCode())));
|
|
||||||
resetRes(records);
|
List<String> filePaths = records.stream().map(FileRecycleQueryVO::getFilePath).collect(Collectors.toList());
|
||||||
|
Map<String, String> filesPath = commonService.getFilesPath(filePaths);
|
||||||
|
Map<String, String> userIdNameMap = getUserIdNameMap(records.stream().map(FileRecycleQueryVO::getUpdatedBy).collect(Collectors.toList()));
|
||||||
|
records.forEach(e -> {
|
||||||
|
e.setDataOwner(DataOwnEnum.getTypeByCode(e.getDataOwnCode()));
|
||||||
|
e.setFilePrjPath(filesPath.get(e.getFilePath()));
|
||||||
|
e.setFileSizeShow(EleCommonUtil.convertFileSize(e.getFileSize()));
|
||||||
|
e.setUserName(userIdNameMap.get(e.getUpdatedBy()));
|
||||||
|
});
|
||||||
UserThreadLocal.setSuccessInfo("", "", "查询所有删除文件成功");
|
UserThreadLocal.setSuccessInfo("", "", "查询所有删除文件成功");
|
||||||
return ElectromagneticResultUtil.success(new RespPageVO<>(total, records));
|
return ElectromagneticResultUtil.success(new RespPageVO<>(total, records));
|
||||||
}
|
}
|
||||||
|
|
@ -177,17 +186,17 @@ public class FileRecycleServiceImpl implements FileRecycleService {
|
||||||
return ElectromagneticResultUtil.success("还原文件成功");
|
return ElectromagneticResultUtil.success("还原文件成功");
|
||||||
}
|
}
|
||||||
|
|
||||||
private void resetRes(List<FileRecycleQueryVO> records) {
|
private Map<String, String> getUserIdNameMap(List<String> userIds) {
|
||||||
|
Map<String, String> res = new HashMap<>();
|
||||||
|
|
||||||
if (CollUtil.isEmpty(records)) {
|
if (CollUtil.isEmpty(userIds)) {
|
||||||
return;
|
return res;
|
||||||
}
|
}
|
||||||
|
|
||||||
List<String> userIds = records.stream().map(FileRecycleQueryVO::getUpdatedBy).collect(Collectors.toList());
|
return userMapper.selectList(Wrappers.<User>lambdaQuery()
|
||||||
Map<String, String> idNameMap = userMapper.selectList(Wrappers.<User>lambdaQuery().in(User::getId, userIds)).stream().collect(Collectors.toMap(User::getUserId, User::getUserName));
|
.select(User::getUserId, User::getUserName)
|
||||||
records.forEach(e -> {
|
.in(User::getUserId, userIds))
|
||||||
e.setFileSizeShow(EleCommonUtil.convertFileSize(e.getFileSize()));
|
.stream().collect(Collectors.toMap(User::getUserId, User::getUserName));
|
||||||
e.setUserName(idNameMap.get(e.getUpdatedBy()));
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue