1.文件系统完全依赖MySQL,去除操作系统层面的维护。

2.整理代码。
This commit is contained in:
chenxudong 2025-04-16 11:26:07 +08:00
parent 98d8b621b3
commit c983fda287
10 changed files with 100 additions and 281 deletions

View File

@ -1,5 +1,6 @@
package com.electromagnetic.industry.software.manage.pojo.models;
import cn.hutool.core.util.IdUtil;
import com.baomidou.mybatisplus.annotation.TableField;
import com.baomidou.mybatisplus.annotation.TableName;
import com.electromagnetic.industry.software.common.enums.EffectFlagEnum;
@ -124,6 +125,9 @@ public class EdFileInfo extends BaseModel {
@TableField(value = "permanent_deleted")
private Boolean permanentDeleted;
@TableField(value = "uuid")
private String uuid;
public void newInit() {
String userId = UserThreadLocal.getUserId();
String newFileDbId = IdWorker.getSnowFlakeIdString();
@ -137,5 +141,6 @@ public class EdFileInfo extends BaseModel {
this.setCreatedBy(userId);
this.setFileId(newFileDbId);
this.setEffectFlag(EffectFlagEnum.EFFECT.code);
this.setUuid(IdUtil.fastSimpleUUID());
}
}

View File

@ -4,8 +4,6 @@ import java.io.InputStream;
public interface FileSystemService {
void createDirectory(String path);
void copyFile(String source, String destination);
void moveFile(String source, String destination);
@ -16,8 +14,6 @@ public interface FileSystemService {
void renameFile(String sourcePath, String sourceName, String newName);
boolean checkFolderExist(String newPath);
boolean writeStringToFile(String filePath, String contents);
boolean deleteFile(String... filePaths);

View File

@ -1,7 +1,6 @@
package com.electromagnetic.industry.software.manage.service.serviceimpl;
import cn.hutool.core.collection.CollUtil;
import cn.hutool.core.io.FileUtil;
import cn.hutool.core.lang.Assert;
import cn.hutool.core.lang.tree.Tree;
import cn.hutool.core.lang.tree.TreeNodeConfig;
@ -137,17 +136,21 @@ public class CommonService {
return count == 0;
}
public String getFileSysPath(String dbPath, int dataOwnCode) {
ArrayList<String> paths = CollUtil.newArrayList(dbPath.split(MYSQL_FILE_PATH_SPLIT));
String path = getDbPath(paths);
String destPath;
if (DataOwnEnum.isUserCode(dataOwnCode)) {
EdFileInfo prjFileInfo = edFileInfoMapper.selectById(paths.get(0));
destPath = getPrjRootPath1(dataOwnCode) + prjFileInfo.getCreatedBy() + File.separator + path;
} else {
destPath = getPrjRootPath1(dataOwnCode) + File.separator + path;
public String getFileSysPath(String id) {
EdFileInfo fileInfo = edFileInfoMapper.selectById(id);
String uuid = fileInfo.getUuid();
String fileType = fileInfo.getFileType();
int dataOwnCode = fileInfo.getDataOwn();
DataOwnEnum enumByCode = DataOwnEnum.getEnumByCode(dataOwnCode);
String fileName = id + MYSQL_FILE_PATH_SPLIT + uuid + "." + fileType;
String filePath;
switch (Objects.requireNonNull(enumByCode)) {
case SYS_FILE, SYS_PRJ, REPO_PRJ, REPO_FILE -> filePath = getPrjRootPath1(dataOwnCode) + fileName;
case USER_FILE, USER_PRJ ->
filePath = getPrjRootPath1(dataOwnCode) + fileInfo.getCreatedBy() + File.separator + fileName;
default -> throw new BizException("参数错误");
}
return destPath.replace("//", "/");
return filePath;
}
public String getDbPath(String dbPath) {
@ -243,6 +246,7 @@ public class CommonService {
try {
String path = currentPath + MYSQL_FILE_PATH_SPLIT + folderId;
EdFileInfo fileInfo = new EdFileInfo();
fileInfo.newInit();
String nowTimeStr = EleCommonUtil.getNowTimeStr();
fileInfo.setId(folderId)
.setFileId(folderId)
@ -261,14 +265,6 @@ public class CommonService {
.setDataOwn(dataOwnCode)
.setEffectFlag(EffectFlagEnum.EFFECT.code);
edFileInfoMapper.insert(fileInfo);
// 保存到文件系统
String targetFilePath;
if (DataOwnEnum.isUserCode(dataOwnCode)) {
targetFilePath = getPrjRootPath1(dataOwnCode) + File.separator + UserThreadLocal.getUserId() + File.separator + getDbPath(paths) + File.separator + folderName;
} else {
targetFilePath = getPrjRootPath1(dataOwnCode) + File.separator + getDbPath(paths) + File.separator + folderName;
}
fileSystemService.createDirectory(targetFilePath);
return ElectromagneticResultUtil.success(folderId);
} catch (Exception e) {
String info = StrFormatter.format("{} 添加失败,原因 {}", folderName, e.getMessage());
@ -440,7 +436,7 @@ public class CommonService {
// 如果文件夹下存在文件包括文件夹和已经逻辑删除的文件则不允许删除后面管理员选择会有物理删除文件夹和文件的功能此时MySQL和文件系统则会进行物理删除该文件
EdFileInfo srcFileInfo = edFileInfoMapper.selectById(id);
Assert.isTrue(srcFileInfo.getDataType().equals(EleDataTypeEnum.FOLDER.code), "禁止删除目录");
String srcFilePath = getFileSysPath(srcFileInfo.getFilePath(), dataOwnCode);
String srcFilePath = getFileSysPath(srcFileInfo.getId());
String uuid = IdUtil.fastSimpleUUID();
try {
// 这里要分两种情况1是删除层级目录2是删除用户创建的文件夹
@ -514,12 +510,6 @@ public class CommonService {
return null;
}
public String getPrjNameByDbPath(String dbPath) {
List<String> paths = StrUtil.split(dbPath, MYSQL_FILE_PATH_SPLIT);
String prjId = paths.get(0);
return edFileInfoMapper.selectById(prjId).getFileName();
}
public Set<String> selectPrjLeafs(int dataOwnCode, List<String> accessibleIds) {
Set<String> res = new HashSet<>();
@ -545,18 +535,6 @@ public class CommonService {
return res;
}
public void deletePrjSysDir(Map<String, String> map) {
for (Map.Entry<String, String> entry : map.entrySet()) {
String srcPath = entry.getKey();
String newName = entry.getValue();
if (!FileUtil.exist(srcPath)) {
continue;
}
fileSystemService.renameFile(srcPath, newName);
}
}
public String getLastPrjLeafId(String path) {
String[] split = path.split(MYSQL_FILE_PATH_SPLIT);
for (int i = split.length - 1; i >= 0; i--) {

View File

@ -86,6 +86,8 @@ public class EdFileInfoServiceImpl extends ServiceImpl<EdFileInfoMapper, EdFileI
private EdFileRelationMapper edFileRelationMapper;
@Resource
private EdFileFavoriteMapper edFileFavoriteMapper;
@Resource
private UserAccessLogMapper userAccessLogMapper;
/**
* 查询文件列表
@ -274,7 +276,7 @@ public class EdFileInfoServiceImpl extends ServiceImpl<EdFileInfoMapper, EdFileI
public ResponseEntity<InputStreamResource> download(String id, HttpServletResponse response, int dataOwnCode) {
String fileName = "";
EdFileInfo fileInfo = this.baseMapper.selectById(id);
String fileSysPath = commonService.getFileSysPath(fileInfo.getFilePath(), dataOwnCode);
String fileSysPath = commonService.getFileSysPath(id);
String dbPath = commonService.getDbPath(fileInfo.getFilePath());
try {
Assert.isTrue(FileUtil.exist(fileSysPath), "下载文件不存在,路径为 {}", dbPath);
@ -344,7 +346,7 @@ public class EdFileInfoServiceImpl extends ServiceImpl<EdFileInfoMapper, EdFileI
throw new BizException("文件名已经存在");
}
String srcFilePath = commonService.getFileSysPath(fileInfo.getFilePath(), dataOwnCode);
String srcFilePath = commonService.getFileSysPath(fileInfo.getId());
String dbPath = commonService.getDbPath(fileInfo.getFilePath());
this.baseMapper.update(new EdFileInfo(), Wrappers.lambdaUpdate(EdFileInfo.class)
.eq(EdFileInfo::getId, updateFileInfoDTO.getId())
@ -691,7 +693,6 @@ public class EdFileInfoServiceImpl extends ServiceImpl<EdFileInfoMapper, EdFileI
}
private void update2FileSystem(Set<EdFileInfo> needMove2FileSystemFiles, String prjDirPath, int dataOwnCode) {
Map<String, EdFileInfo> maps = needMove2FileSystemFiles.stream().collect(Collectors.toMap(EdFileInfo::getId, e -> e));
List<EdFileInfo> files = needMove2FileSystemFiles.stream().filter(e -> e.getDataType().equals(EleDataTypeEnum.FILE.code)).toList();
for (EdFileInfo edFileInfo : files) {
String filePath = edFileInfo.getFilePath();
@ -706,7 +707,6 @@ public class EdFileInfoServiceImpl extends ServiceImpl<EdFileInfoMapper, EdFileI
StringBuilder destDirPath = new StringBuilder();
for (String id : filePath.split(MYSQL_FILE_PATH_SPLIT)) {
// EdFileInfo fileInfo = maps.get(id);
EdFileInfo fileInfo = this.baseMapper.selectById(id);
if (fileInfo.getDataType().equals(EleDataTypeEnum.FOLDER.code)) {
String previousDirName = FILE_DB_ID_NAME.containsKey(id) ?
@ -734,7 +734,6 @@ public class EdFileInfoServiceImpl extends ServiceImpl<EdFileInfoMapper, EdFileI
"." + edFileInfo.getFileCode();
}
log.info("source path is ----> {}, dest path is --->{}", sourcePath, destPath);
fileSystemService.moveFile(sourcePath, destPath);
}
}
@ -772,22 +771,22 @@ public class EdFileInfoServiceImpl extends ServiceImpl<EdFileInfoMapper, EdFileI
Assert.isTrue(!map.containsValue(Boolean.FALSE), "有未授权的层级目录,禁止导出");
}
Map<String, Object> exportInfoMap = new HashMap<>();
// 导出工程目录信息
exportPrjInfo(exportInfoMap, dataOwnCode, dataIdArr, userDownloadDataDir);
// 导出文件收藏相关信息
exportCollectionInfo(exportInfoMap);
// 导出文件关系
exportFileRelationInfo(exportInfoMap);
// 导出标签相关信息
exportFileTagInfo(exportInfoMap);
String mysqlInfo = JSONUtil.toJsonStr(exportInfoMap);
String mysqlFilePath = userDownloadDataDir + File.separator + EXPORT_PRJ_NAME + File.separator + "mysql.json";
String prjDirPath = userDownloadDataDir + File.separator + EXPORT_PRJ_NAME;
String exportZipFile = userDownloadDataDir + File.separator + EXPORT_PRJ_NAME + ".zip";
String exportColibFile = userDownloadDataDir + File.separator + File.separator + EXPORT_PRJ_NAME + EXPORT_FILE_SUFFIX;
String nowTimeStr = EleCommonUtil.getNowTimeStr();
fileSystemService.writeStringToFile(mysqlFilePath, mysqlInfo);
// 导出工程目录信息
List<String> exportFileIds = exportPrjInfo(nowTimeStr, dataOwnCode, dataIdArr, userDownloadDataDir);
// 导出文件收藏相关信息
exportCollectionInfo(nowTimeStr, exportFileIds, userDownloadDataDir);
// 导出文件关系
exportFileRelationInfo(nowTimeStr, exportFileIds, userDownloadDataDir);
// 导出标签相关信息
exportFileTagInfo(nowTimeStr, exportFileIds, userDownloadDataDir);
// 导出操作记录相关
exportLogInfo(nowTimeStr, exportFileIds, userDownloadDataDir);
String prjDirPath = userDownloadDataDir + File.separator + EXPORT_PRJ_NAME + "_" + nowTimeStr;
String exportZipFile = userDownloadDataDir + File.separator + EXPORT_PRJ_NAME + "_" + nowTimeStr + ".zip";
String exportColibFile = userDownloadDataDir + File.separator + File.separator + EXPORT_PRJ_NAME + "_" + nowTimeStr + EXPORT_FILE_SUFFIX;
FileUtil.del(exportColibFile);
ZipUtil.zip(prjDirPath, exportZipFile);
AES aes = SecureUtil.aes(FILE_SEC_PASSWD.getBytes());
@ -807,7 +806,7 @@ public class EdFileInfoServiceImpl extends ServiceImpl<EdFileInfoMapper, EdFileI
FileSystemResource fileSystemResource = new FileSystemResource(file);
HttpHeaders headers = new HttpHeaders();
headers.add("Cache-Control", "no-cache, no-store, must-revalidate");
String fileName = Base64.encode(EleCommonUtil.getNowTimeStr() + "_" + fileSystemResource.getFilename());
String fileName = Base64.encode(fileSystemResource.getFilename() + "_" + nowTimeStr);
headers.add("Pragma", "no-cache");
headers.add("Expires", "0");
response.setHeader("content-disposition", "attachment;filename=" + fileName);
@ -821,30 +820,37 @@ public class EdFileInfoServiceImpl extends ServiceImpl<EdFileInfoMapper, EdFileI
.body(new InputStreamResource(fileSystemResource.getInputStream()));
}
private void exportFileTagInfo(Map<String, Object> exportInfoMap) {
List<EdFileInfo> fileInfos = (List<EdFileInfo>) exportInfoMap.getOrDefault(PRJ_INFO, new ArrayList<>());
List<String> accessibleFileIds = fileInfos.stream().map(EdFileInfo::getId).toList();
List<FileTagRelation> fileTagRelations = fileTagRelationMapper.selectList(Wrappers.lambdaQuery(FileTagRelation.class).in(FileTagRelation::getFileId, accessibleFileIds));
exportInfoMap.put(ED_TAG_RELATIONS, fileTagRelations);
private void exportLogInfo(String nowTimeStr, List<String> exportFileIds, String userDownloadDataDir) {
List<UserAccessLog> userAccessLogs = userAccessLogMapper.selectList(null);
String json = JSONUtil.toJsonStr(userAccessLogs);
String path = userDownloadDataDir + File.separator + EXPORT_PRJ_NAME + "_" + nowTimeStr + File.separator + USER_ACCESS_LOG + ".json";
fileSystemService.writeStringToFile(path, json);
}
private void exportFileRelationInfo(Map<String, Object> exportInfoMap) {
List<EdFileInfo> fileInfos = (List<EdFileInfo>) exportInfoMap.getOrDefault(PRJ_INFO, new ArrayList<>());
List<String> accessibleFileIds = fileInfos.stream().map(EdFileInfo::getId).toList();
List<EdFileRelation> edFileRelations = edFileRelationMapper.selectList(Wrappers.lambdaQuery(EdFileRelation.class).in(EdFileRelation::getId1, accessibleFileIds)
private void exportFileTagInfo(String nowTimeStr, List<String> exportFileIds, String userDownloadDataDir) {
List<FileTagRelation> fileTagRelations = fileTagRelationMapper.selectList(Wrappers.lambdaQuery(FileTagRelation.class).in(FileTagRelation::getFileId, exportFileIds));
String path = userDownloadDataDir + File.separator + EXPORT_PRJ_NAME + "_" + nowTimeStr + File.separator + ED_TAG_RELATIONS + ".json";
String json = JSONUtil.toJsonStr(fileTagRelations);
fileSystemService.writeStringToFile(path, json);
}
private void exportFileRelationInfo(String nowTimeStr, List<String> exportFileIds, String userDownloadDataDir) {
List<EdFileRelation> edFileRelations = edFileRelationMapper.selectList(Wrappers.lambdaQuery(EdFileRelation.class).in(EdFileRelation::getId1, exportFileIds)
.or()
.in(EdFileRelation::getId2, accessibleFileIds));
exportInfoMap.put(ED_FILE_RELATION, edFileRelations);
.in(EdFileRelation::getId2, exportFileIds));
String json = JSONUtil.toJsonStr(edFileRelations);
String path = userDownloadDataDir + File.separator + EXPORT_PRJ_NAME + "_" + nowTimeStr + File.separator + ED_FILE_RELATION + ".json";
fileSystemService.writeStringToFile(path, json);
}
private void exportCollectionInfo(Map<String, Object> exportInfoMap) {
List<EdFileInfo> fileInfos = (List<EdFileInfo>) exportInfoMap.getOrDefault(PRJ_INFO, new ArrayList<>());
List<String> accessibleFileIds = fileInfos.stream().map(EdFileInfo::getId).toList();
List<EdFileFavorite> edFileFavorites = edFileFavoriteMapper.selectList(Wrappers.lambdaQuery(EdFileFavorite.class).in(EdFileFavorite::getFileId, accessibleFileIds));
exportInfoMap.put(ED_FILE_FAVORITE, edFileFavorites);
private void exportCollectionInfo(String nowTimeStr, List<String> exportFileIds, String userDownloadDataDir) {
List<EdFileFavorite> edFileFavorites = edFileFavoriteMapper.selectList(Wrappers.lambdaQuery(EdFileFavorite.class).in(EdFileFavorite::getFileId, exportFileIds));
String json = JSONUtil.toJsonStr(edFileFavorites);
String path = userDownloadDataDir + File.separator + EXPORT_PRJ_NAME + "_" + nowTimeStr + File.separator + ED_FILE_FAVORITE + ".json";
fileSystemService.writeStringToFile(path, json);
}
private void exportPrjInfo(Map<String, Object> exportInfoMap, int dataOwnCode, String dataIdArr, String userDownloadDataDir) throws IOException {
private List<String> exportPrjInfo(String nowTimeStr, int dataOwnCode, String dataIdArr, String userDownloadDataDir) {
String[] ids = dataIdArr.split(",");
if (DataOwnEnum.isSysCode(dataOwnCode) || DataOwnEnum.isRepoCode(dataOwnCode)) {
Map<String, Boolean> map = permissionService.filterExportIds(ids);
@ -871,107 +877,18 @@ public class EdFileInfoServiceImpl extends ServiceImpl<EdFileInfoMapper, EdFileI
resFiles.clear();
resFiles.addAll(tmps.values());
resFiles.add(prjFileInfo);
String prjName = commonService.getPrjNameByDbPath(resFiles.get(0).getFilePath());
List<EdFileInfo> folders = resFiles.stream().filter(e -> e.getDataType().equals(EleDataTypeEnum.FOLDER.code)).toList();
List<EdFileInfo> files = resFiles.stream().filter(e -> e.getDataType().equals(EleDataTypeEnum.FILE.code)).toList();
for (EdFileInfo edFileInfo : folders) {
String destFolderPath = userDownloadDataDir + File.separator + prjName + File.separator + commonService.getDbPath(edFileInfo.getFilePath()); // file
fileSystemService.createDirectory(destFolderPath);
}
for (EdFileInfo edFileInfo : files) {
String filePath = commonService.getFileSysPath(edFileInfo.getFilePath(), dataOwnCode); // file
String destPath = userDownloadDataDir + File.separator + prjName + File.separator + commonService.getDbPath(edFileInfo.getFilePath());
String filePath = commonService.getFileSysPath(edFileInfo.getId()); // file
String destPath = userDownloadDataDir + File.separator + EXPORT_PRJ_NAME + "_" + nowTimeStr + File.separator + commonService.getDbPath(edFileInfo.getFilePath());
fileSystemService.copyFile(filePath, destPath);
}
exportInfoMap.put(PRJ_INFO, resFiles);
String json = JSONUtil.toJsonStr(files);
String mysqlFilePath = userDownloadDataDir + File.separator + EXPORT_PRJ_NAME + "_" + nowTimeStr + File.separator + PRJ_INFO + ".json";
fileSystemService.writeStringToFile(mysqlFilePath, json);
return files.stream().map(EdFileInfo::getId).toList();
}
// @Override
// public ResponseEntity<InputStreamResource> batchExport1(String dataIdArr, HttpServletResponse response, int dataOwnCode) throws IOException {
// String userDownloadDataDir = elePropertyConfig.getDownloadDataDir(dataOwnCode) + File.separator + UserThreadLocal.getUserId();
// String[] ids = dataIdArr.split(",");
// if (DataOwnEnum.isSysCode(dataOwnCode) || DataOwnEnum.isRepoCode(dataOwnCode)) {
// Map<String, Boolean> map = permissionService.filterExportIds(ids);
// Assert.isTrue(!map.containsValue(Boolean.FALSE), "有未授权的层级目录,禁止导出");
// }
// Map<String, EdFileInfo> maps = new HashMap<>();
// for (String id : ids) {
// Map<String, EdFileInfo> edFileInfos = this.baseMapper.selectList(Wrappers.lambdaQuery(EdFileInfo.class)
// .like(EdFileInfo::getFilePath, MYSQL_FILE_PATH_SPLIT + id + MYSQL_FILE_PATH_SPLIT))
// .stream().collect(Collectors.toMap(EdFileInfo::getId, e -> e));
// maps.putAll(edFileInfos);
// }
// List<EdFileInfo> resFiles = new ArrayList<>(maps.values());
// String prjId = resFiles.get(0).getFilePath().split(MYSQL_FILE_PATH_SPLIT)[0];
// List<EdFileInfo> prjFolders = this.baseMapper.selectList(Wrappers.lambdaQuery(EdFileInfo.class)
// .likeRight(EdFileInfo::getFilePath, prjId + MYSQL_FILE_PATH_SPLIT)
// .eq(EdFileInfo::getDataType, EleDataTypeEnum.FOLDER.code)
// .eq(EdFileInfo::getDataOwn, DataOwnEnum.getPrjCodeByFileCode(dataOwnCode))
// .eq(EdFileInfo::getEffectFlag, EffectFlagEnum.EFFECT.code));
// EdFileInfo prjFileInfo = this.baseMapper.selectById(prjId);
// Map<String, EdFileInfo> prjFoldersMap = prjFolders.stream().collect(Collectors.toMap(EdFileInfo::getId, e -> e));
// Map<String, EdFileInfo> tmps = resFiles.stream().collect(Collectors.toMap(EdFileInfo::getId, e -> e));
// tmps.putAll(prjFoldersMap);
// resFiles.clear();
// resFiles.addAll(tmps.values());
// resFiles.add(prjFileInfo);
// String prjName = commonService.getPrjNameByDbPath(resFiles.get(0).getFilePath());
// List<EdFileInfo> folders = resFiles.stream().filter(e -> e.getDataType().equals(EleDataTypeEnum.FOLDER.code)).toList();
// List<EdFileInfo> files = resFiles.stream().filter(e -> e.getDataType().equals(EleDataTypeEnum.FILE.code)).toList();
// for (EdFileInfo edFileInfo : folders) {
// String destFolderPath = userDownloadDataDir + File.separator + prjName + File.separator + commonService.getDbPath(edFileInfo.getFilePath()); // file
// fileSystemService.createDirectory(destFolderPath);
// }
// for (EdFileInfo edFileInfo : files) {
// String filePath = commonService.getFileSysPath(edFileInfo.getFilePath(), dataOwnCode); // file
// String destPath = userDownloadDataDir + File.separator + prjName + File.separator + commonService.getDbPath(edFileInfo.getFilePath());
// fileSystemService.copyFile(filePath, destPath);
// }
// String mysqlInfo = JSONUtil.toJsonStr(resFiles);
//
// String mysqlFilePath = userDownloadDataDir + File.separator + prjName + File.separator + "mysql.json";
// String prjDirPath = userDownloadDataDir + File.separator + prjName;
// String exportZipFile = userDownloadDataDir + File.separator + prjName + ".zip";
// String exportColibFile = userDownloadDataDir + File.separator + File.separator + prjName + EXPORT_FILE_SUFFIX;
//
// fileSystemService.writeStringToFile(mysqlFilePath, mysqlInfo);
// if (FileUtil.exist(exportColibFile)) {
// FileUtil.del(exportColibFile);
// }
//
// ZipUtil.zip(prjDirPath, exportZipFile);
// AES aes = SecureUtil.aes(FILE_SEC_PASSWD.getBytes());
// try (
// InputStream inputStream = Files.newInputStream(Paths.get(exportZipFile));
// OutputStream outputStream = Files.newOutputStream(Paths.get(exportColibFile));
// ) {
// aes.encrypt(inputStream, outputStream, true);
// } catch (Exception e) {
// String info = "导出失败。";
// log.error(info, e);
// throw new BizException(info);
// } finally {
// fileSystemService.deleteFile(exportZipFile, prjDirPath);
// }
// File file = FileUtil.newFile(exportColibFile);
// FileSystemResource fileSystemResource = new FileSystemResource(file);
// HttpHeaders headers = new HttpHeaders();
// headers.add("Cache-Control", "no-cache, no-store, must-revalidate");
// String fileName = Base64.encode(EleCommonUtil.getNowTimeStr() + "_" + fileSystemResource.getFilename());
// headers.add("Pragma", "no-cache");
// headers.add("Expires", "0");
// response.setHeader("content-disposition", "attachment;filename=" + fileName);
// UserThreadLocal.setSuccessInfo("", "", "导出数据库成功");
// // 构建响应实体(可以返回<byte[]或Resource返回类型取决body入参类型)
// return ResponseEntity
// .ok()
// .headers(headers)
// .contentLength(fileSystemResource.contentLength())
// .contentType(MediaType.parseMediaType("application/octet-stream"))
// .body(new InputStreamResource(fileSystemResource.getInputStream()));
// }
/**
* 文件上传
*
@ -1008,8 +925,8 @@ public class EdFileInfoServiceImpl extends ServiceImpl<EdFileInfoMapper, EdFileI
long dirCount = this.baseMapper.selectCount(queryWrapper);
Assert.isTrue(dirCount == 0, "文件 {} 上传到 {} 失败,层级结构不允许上传文件,同名同后缀的处理方式为 {}", fileName, destPath, strategyStr);
EdFileInfo newEdFileInfo = new EdFileInfo();
EdFileInfo finalEdFileInfo;
newEdFileInfo.newInit();
EdFileInfo finalEdFileInfo;
// 首先检查是否是同名文件
try {
Assert.isTrue(EleCommonUtil.isFileNameValid(fileName), NAME_VALID_MSG);
@ -1028,6 +945,7 @@ public class EdFileInfoServiceImpl extends ServiceImpl<EdFileInfoMapper, EdFileI
String codePathByDbPath = commonService.getCodePathByDbPath(parentFolderInfo.getFilePath());
String fileCode = commonService.createFileCode(codePathByDbPath, suffix, FILE_START_VERSION, newEdFileInfo.getFileTime());
newEdFileInfo.setParentId(parentId)
.setUuid(IdUtil.simpleUUID())
.setFileCode(fileCode)
.setSaveStatus(EleDataSaveStatusEnum.SUCCESS.code)
.setDataOwn(dataOwnCode)
@ -1041,11 +959,10 @@ public class EdFileInfoServiceImpl extends ServiceImpl<EdFileInfoMapper, EdFileI
.setDataStatus(PublishEnum.PUBLISHED.getCode())
.setEffectFlag(EffectFlagEnum.EFFECT.code);
this.saveOrUpdate(newEdFileInfo);
String fileDestPath = commonService.getFileSysPath(newEdFileInfo.getFilePath(), dataOwnCode);
String fileDestPath = commonService.getFileSysPath(newEdFileInfo.getId());
FileUtil.writeFromStream(file.getInputStream(), fileDestPath);
EleCommonUtil.encryptFile(fileDestPath, SecureUtil.aes(FILE_SEC_PASSWD.getBytes()));
finalEdFileInfo = newEdFileInfo;
// fileSystemService.save(FileUtil.getInputStream(fileDestPath), fileDestPath); // 这里会导致文件大小为0考虑到当前的系统为OS文件系统暂不处理
}
} catch (Exception e) {
String info = StrFormatter.format("文件 {} 为上传到 {} 失败,原因 {},同名同后缀的处理方式为 {}", fileName, destPath, e.getMessage(), strategyStr);
@ -1104,7 +1021,6 @@ public class EdFileInfoServiceImpl extends ServiceImpl<EdFileInfoMapper, EdFileI
Assert.isTrue(FileRepeatEnum.contains(strategy), "解决重名文件参数错误");
// 获取原文件mysql模型
EdFileInfo srcFileInfo = this.baseMapper.selectById(id);
String srcFilePath = commonService.getFileSysPath(srcFileInfo.getFilePath(), dataOwnCode);
// 判断目标路径下是否有同名文件如果所有的同名文件1如果所有文件都已经被作废则该文件为新文件版本号从100开始2如果有没有被作废的文件则冲突处理方式按---1-跳过冲突文件 2-做版本更新 3-重命名文件名加"_1"
long count = this.baseMapper.selectCount(Wrappers.lambdaQuery(EdFileInfo.class)
.eq(EdFileInfo::getParentId, targetFolderId)
@ -1127,9 +1043,6 @@ public class EdFileInfoServiceImpl extends ServiceImpl<EdFileInfoMapper, EdFileI
.setFilePath(destFolderInfo.getFilePath() + MYSQL_FILE_PATH_SPLIT + srcFileInfo.getId())
.setFileCode(newFileCode);
this.baseMapper.updateById(srcFileInfo);
// 文件系统移动文件
String destFilePath = commonService.getFileSysPath(srcFileInfo.getFilePath(), dataOwnCode);
fileSystemService.moveFile(srcFilePath, destFilePath);
} else {
srcFileInfo = handMoveConflict(targetFolderId, strategy, srcFileInfo, destFolderInfo, dataOwnCode);
}
@ -1171,9 +1084,6 @@ public class EdFileInfoServiceImpl extends ServiceImpl<EdFileInfoMapper, EdFileI
.setFileCode(fileCode)
.setEffectFlag(EffectFlagEnum.EFFECT.code);
this.baseMapper.insert(destSaveFileInfo);
String srcFilePath = commonService.getFileSysPath(srcFileInfo.getFilePath(), dataOwnCode);
String destFilePath = commonService.getFileSysPath(destSaveFileInfo.getFilePath(), dataOwnCode);
fileSystemService.copyFile(srcFilePath, destFilePath);
this.baseMapper.deleteById(srcFileInfo.getId());
this.baseMapper.update(new EdFileInfo(), Wrappers.lambdaUpdate(EdFileInfo.class)
.set(EdFileInfo::getEffectFlag, EffectFlagEnum.NOT_EFFECTIVE.code)
@ -1193,10 +1103,6 @@ public class EdFileInfoServiceImpl extends ServiceImpl<EdFileInfoMapper, EdFileI
.setFilePath(destFolderInfo.getFilePath() + MYSQL_FILE_PATH_SPLIT + newEdFileInfo.getId());
resetFileInfoName(newEdFileInfo);
this.baseMapper.insert(newEdFileInfo);
// 移动文件
String srcFileSysPath = commonService.getFileSysPath(srcFileInfo.getFilePath(), dataOwnCode);
String destFileSysPath = commonService.getFileSysPath(newEdFileInfo.getFilePath(), dataOwnCode);
fileSystemService.moveFile(srcFileSysPath, destFileSysPath);
this.baseMapper.deleteById(srcFileInfo.getId());
return newEdFileInfo;
}
@ -1239,10 +1145,6 @@ public class EdFileInfoServiceImpl extends ServiceImpl<EdFileInfoMapper, EdFileI
.setFilePath(destFolderInfo.getFilePath() + MYSQL_FILE_PATH_SPLIT + destFileInfo.getId())
.setFileCode(newFileCode);
this.baseMapper.insert(destFileInfo);
// 文件系统移动文件
String srcFilePath = commonService.getFileSysPath(srcFileDbPath, dataOwnCode);
String destFilePath = commonService.getFileSysPath(destFileInfo.getFilePath(), dataOwnCode);
fileSystemService.copyFile(srcFilePath, destFilePath);
} else {
destFileInfo = handCopyConflict(targetFolderId, strategy, srcFileInfo, destFolderInfo, dataOwnCode);
}
@ -1350,9 +1252,6 @@ public class EdFileInfoServiceImpl extends ServiceImpl<EdFileInfoMapper, EdFileI
.eq(EdFileInfo::getFileName, srcFileInfo.getFileName())
.eq(EdFileInfo::getFileType, srcFileInfo.getFileType()).set(EdFileInfo::getEffectFlag, EffectFlagEnum.NOT_EFFECTIVE.code));
this.baseMapper.insert(destSaveFileInfo);
String srcFilePath = commonService.getFileSysPath(srcFileInfo.getFilePath(), dataOwnCode);
String destFilePath = commonService.getFileSysPath(destSaveFileInfo.getFilePath(), dataOwnCode);
fileSystemService.copyFile(srcFilePath, destFilePath);
return destSaveFileInfo;
} else {
// 文件名加_1版本号从100开始
@ -1367,10 +1266,6 @@ public class EdFileInfoServiceImpl extends ServiceImpl<EdFileInfoMapper, EdFileI
.setFilePath(destFolderInfo.getFilePath() + MYSQL_FILE_PATH_SPLIT + newEdFileInfo.getId());
resetFileInfoName(newEdFileInfo);
this.baseMapper.insert(newEdFileInfo);
// 移动文件
String srcFileSysPath = commonService.getFileSysPath(srcFileInfo.getFilePath(), dataOwnCode);
String destFileSysPath = commonService.getFileSysPath(newEdFileInfo.getFilePath(), dataOwnCode);
fileSystemService.copyFile(srcFileSysPath, destFileSysPath);
return newEdFileInfo;
}
}
@ -1421,7 +1316,7 @@ public class EdFileInfoServiceImpl extends ServiceImpl<EdFileInfoMapper, EdFileI
.setDataOwn(dataOwnCode)
.setEffectFlag(EffectFlagEnum.EFFECT.code);
this.baseMapper.insert(newEdFileInfo);
String fileDestPath = commonService.getFileSysPath(newEdFileInfo.getFilePath(), dataOwnCode);
String fileDestPath = commonService.getFileSysPath(newEdFileInfo.getId());
fileSystemService.save(file.getInputStream(), fileDestPath);
EleCommonUtil.encryptFile(fileDestPath, SecureUtil.aes(FILE_SEC_PASSWD.getBytes()));
return newEdFileInfo;
@ -1451,7 +1346,7 @@ public class EdFileInfoServiceImpl extends ServiceImpl<EdFileInfoMapper, EdFileI
.setEffectFlag(EffectFlagEnum.EFFECT.code);
resetFileInfoName(newEdFileInfo);
this.baseMapper.insert(newEdFileInfo);
String fileDestPath = commonService.getFileSysPath(newEdFileInfo.getFilePath(), dataOwnCode);
String fileDestPath = commonService.getFileSysPath(newEdFileInfo.getId());
fileSystemService.save(file.getInputStream(), fileDestPath);
EleCommonUtil.encryptFile(fileDestPath, SecureUtil.aes(FILE_SEC_PASSWD.getBytes()));
return newEdFileInfo;
@ -1539,7 +1434,7 @@ public class EdFileInfoServiceImpl extends ServiceImpl<EdFileInfoMapper, EdFileI
EdFileInfo fileInfo = this.baseMapper.selectById(id);
Assert.isTrue(Objects.nonNull(fileInfo), "文件不存在");
String fileDbPath = commonService.getDbPath(fileInfo.getFilePath());
String fileSysPath = commonService.getFileSysPath(fileInfo.getFilePath(), dataOwnCode);
String fileSysPath = commonService.getFileSysPath(fileInfo.getId());
String fileSaveTmpPath = elePropertyConfig.getEleTmpPath() + File.separator + IdUtil.fastSimpleUUID() + "." + fileInfo.getFileType();
FileUtil.copy(fileSysPath, fileSaveTmpPath, true);
EleCommonUtil.decryptFile(fileSaveTmpPath, SecureUtil.aes(FILE_SEC_PASSWD.getBytes()));

View File

@ -254,7 +254,7 @@ public class EdFileRelationServiceImpl extends ServiceImpl<EdFileRelationMapper,
}
edFileInfoService.saveOrUpdate(newEdFileInfo);
String fileDestPath = commonService.getFileSysPath(newEdFileInfo.getFilePath(), dataOwnCode);
String fileDestPath = commonService.getFileSysPath(newEdFileInfo.getId());
FileUtil.writeFromStream(file.getInputStream(), fileDestPath);
EleCommonUtil.encryptFile(fileDestPath, SecureUtil.aes(FILE_SEC_PASSWD.getBytes()));

View File

@ -4,7 +4,6 @@ import cn.hutool.core.collection.CollUtil;
import cn.hutool.core.collection.CollectionUtil;
import cn.hutool.core.lang.Assert;
import cn.hutool.core.text.StrFormatter;
import cn.hutool.core.util.IdUtil;
import cn.hutool.core.util.StrUtil;
import cn.hutool.json.JSONUtil;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
@ -86,23 +85,24 @@ public class EdPrjServiceImpl extends ServiceImpl<EdFileInfoMapper, EdFileInfo>
// 保存信息到MySQL
String maxPrjId = this.baseMapper.maxPrjId();
int prjCount;
if (DataOwnEnum.isUserCode(dataOwnCode)) {
prjCount = this.baseMapper.selectCount(Wrappers.lambdaQuery(EdFileInfo.class).eq(EdFileInfo::getParentId, PRJ_PARENT_ID)
DataOwnEnum enumByCode = DataOwnEnum.getEnumByCode(dataOwnCode);
switch (Objects.requireNonNull(enumByCode)) {
case USER_PRJ, USER_FILE -> prjCount = this.baseMapper.selectCount(Wrappers.lambdaQuery(EdFileInfo.class).eq(EdFileInfo::getParentId, PRJ_PARENT_ID)
.eq(EdFileInfo::getDataOwn, DataOwnEnum.USER_PRJ.code).eq(EdFileInfo::getCreatedBy, UserThreadLocal.getUserId()))
.intValue();
} else if (DataOwnEnum.isSysCode(dataOwnCode)) {
prjCount = this.baseMapper.selectCount(Wrappers.lambdaQuery(EdFileInfo.class).eq(EdFileInfo::getParentId, PRJ_PARENT_ID)
case SYS_PRJ, SYS_FILE -> prjCount = this.baseMapper.selectCount(Wrappers.lambdaQuery(EdFileInfo.class).eq(EdFileInfo::getParentId, PRJ_PARENT_ID)
.eq(EdFileInfo::getDataOwn, DataOwnEnum.SYS_PRJ.code))
.intValue();
} else {
prjCount = this.baseMapper.selectCount(Wrappers.lambdaQuery(EdFileInfo.class).eq(EdFileInfo::getParentId, PRJ_PARENT_ID)
case REPO_PRJ, REPO_FILE -> prjCount = this.baseMapper.selectCount(Wrappers.lambdaQuery(EdFileInfo.class).eq(EdFileInfo::getParentId, PRJ_PARENT_ID)
.eq(EdFileInfo::getDataOwn, DataOwnEnum.REPO_PRJ.code))
.intValue();
default -> throw new BizException("参数错误");
}
int id = Integer.parseInt(StrUtil.isEmpty(maxPrjId) ? "100000" : maxPrjId);
String newPrjId = String.valueOf(id + 1);
EdFileInfo fileInfo = new EdFileInfo();
fileInfo.newInit();
String nowTimeStr = EleCommonUtil.getNowTimeStr();
fileInfo.setId(newPrjId)
.setFileType("文件夹")
@ -120,14 +120,6 @@ public class EdPrjServiceImpl extends ServiceImpl<EdFileInfoMapper, EdFileInfo>
.setDataOwn(dataOwnCode)
.setEffectFlag(EffectFlagEnum.EFFECT.code);
this.save(fileInfo);
// 保存到文件系统
String prjPath;
if (DataOwnEnum.isUserCode(dataOwnCode)) {
prjPath = commonService.getPrjRootPath1(dataOwnCode) + File.separator + UserThreadLocal.getUserId() + File.separator + prjName;
} else {
prjPath = commonService.getPrjRootPath1(dataOwnCode) + File.separator + prjName;
}
fileSystemService.createDirectory(prjPath);
UserThreadLocal.setSuccessInfo("", newPrjId, "创建 {} 项目成功。", prjName);
} catch (Exception e) {
String info = StrFormatter.format("工程 {} 创建失败,具体为--->{}", prjName, e.getMessage());
@ -164,27 +156,17 @@ public class EdPrjServiceImpl extends ServiceImpl<EdFileInfoMapper, EdFileInfo>
return ElectromagneticResultUtil.fail("-1", info);
}
String newPath;
if (DataOwnEnum.isUserCode(dataOwnCode)) {
newPath = commonService.getPrjRootPath1(dataOwnCode) + File.separator + UserThreadLocal.getUserId() + File.separator + newPrjName;
} else {
newPath = commonService.getPrjRootPath1(dataOwnCode) + File.separator + newPrjName;
}
if (fileSystemService.checkFolderExist(newPath)) {
String tmpPath = newPrjName + "_" + IdUtil.fastSimpleUUID() + DELETE_FLAG;
fileSystemService.renameFile(newPath, tmpPath);
}
this.baseMapper.update(new EdFileInfo(), Wrappers.lambdaUpdate(EdFileInfo.class)
.eq(EdFileInfo::getId, prjId)
.set(EdFileInfo::getFileName, newPrjName));
String prjPath;
if (DataOwnEnum.isUserCode(dataOwnCode)) {
prjPath = commonService.getPrjRootPath1(dataOwnCode) + File.separator + UserThreadLocal.getUserId() + File.separator;
} else {
prjPath = commonService.getPrjRootPath1(dataOwnCode) + File.separator;
DataOwnEnum enumByCode = DataOwnEnum.getEnumByCode(dataOwnCode);
switch (Objects.requireNonNull(enumByCode)) {
case USER_PRJ, USER_FILE -> prjPath = commonService.getPrjRootPath1(dataOwnCode) + File.separator + UserThreadLocal.getUserId() + File.separator;
case REPO_PRJ, REPO_FILE, SYS_PRJ, SYS_FILE -> prjPath = commonService.getPrjRootPath1(dataOwnCode) + File.separator;
default -> throw new BizException("参数错误");
}
fileSystemService.renameFile(prjPath, oldPrjName, newPrjName);
UserThreadLocal.setSuccessInfo("", prjId, "修改工层名 {} 为 {} 成功。", oldPrjName, newPrjName);
} catch (Exception e) {
@ -226,7 +208,6 @@ public class EdPrjServiceImpl extends ServiceImpl<EdFileInfoMapper, EdFileInfo>
this.baseMapper.update(new EdFileInfo(), Wrappers.lambdaUpdate(EdFileInfo.class).set(EdFileInfo::getEffectFlag, EffectFlagEnum.NOT_EFFECTIVE.code).in(EdFileInfo::getId, ids));
// 对原文件进行处理
EdFileInfo prjFile = this.getById(prjId);
fileSystemService.renameFile(commonService.getFileSysPath(prjId, dataOwnCode), prjFile.getFileName() + "_" + IdUtil.fastSimpleUUID() + DELETE_FLAG);
UserThreadLocal.setSuccessInfo("", prjId, "废除 {} 项目成功。", prjFile.getFileName());
return ElectromagneticResultUtil.success(true);
} catch (Exception e) {
@ -346,22 +327,11 @@ public class EdPrjServiceImpl extends ServiceImpl<EdFileInfoMapper, EdFileInfo>
.eq(EdFileInfo::getDataStatus, EleDataStatusEnum.WAIT_DELETED.code)
.likeRight(EdFileInfo::getFilePath, prjId);
List<EdFileInfo> edFileInfos = this.baseMapper.selectList(queryWrapper);
Map<String, String> map = new HashMap<>();
Map<String, String> idNameMap = new HashMap<>();
for (EdFileInfo edFileInfo : edFileInfos) {
String fileSysPath = commonService.getFileSysPath(edFileInfo.getFilePath(), dataOwnCode);
String uuid = IdUtil.fastSimpleUUID();
String newName = edFileInfo.getFileName() + MYSQL_FILE_PATH_SPLIT + uuid + DELETE_FLAG;
map.put(fileSysPath, newName);
idNameMap.put(edFileInfo.getId(), newName);
}
for (Map.Entry<String, String> entry : idNameMap.entrySet()) {
String id = entry.getKey();
String newName = entry.getValue();
this.update(new EdFileInfo(), Wrappers.lambdaUpdate(EdFileInfo.class)
.eq(EdFileInfo::getId, id)
.set(EdFileInfo::getFileName, newName)
.eq(EdFileInfo::getId, edFileInfo.getId())
.set(EdFileInfo::getAllDeleted, true)
.set(EdFileInfo::getPermanentDeleted, true)
.set(EdFileInfo::getEffectFlag, EffectFlagEnum.NOT_EFFECTIVE.code));
}
// 其余置为发布状态
@ -370,7 +340,6 @@ public class EdPrjServiceImpl extends ServiceImpl<EdFileInfoMapper, EdFileInfo>
.eq(EdFileInfo::getDataStatus, EleDataStatusEnum.NOT_PUBLISHED.code)
.likeRight(EdFileInfo::getFilePath, prjId);
this.update(new EdFileInfo(), updateWrapper);
commonService.deletePrjSysDir(map);
UserThreadLocal.setSuccessInfo("", prjId, "项目 {} 发布成功", fileInfo.getFileName());
return ElectromagneticResultUtil.success(true);
} catch (Exception e) {
@ -408,7 +377,6 @@ public class EdPrjServiceImpl extends ServiceImpl<EdFileInfoMapper, EdFileInfo>
// 查找source的全部目录
List<EdFileInfo> sourceEdFileInfos = commonService.selectAllPrjFolder(sourceId, dataOwnCode);
List<EdFileInfo> targetEdFileInfos = commonService.selectAllPrjFolder(targetId, dataOwnCode);
//
Set<String> sourceNames = sourceEdFileInfos.stream().filter(e -> StrUtil.count(e.getFilePath(), MYSQL_FILE_PATH_SPLIT) == 1).map(EdFileInfo::getFileName).collect(Collectors.toSet());
Set<String> targetNames = targetEdFileInfos.stream().filter(e -> StrUtil.count(e.getFilePath(), MYSQL_FILE_PATH_SPLIT) == 1).map(EdFileInfo::getFileName).collect(Collectors.toSet());
@ -421,7 +389,6 @@ public class EdPrjServiceImpl extends ServiceImpl<EdFileInfoMapper, EdFileInfo>
Map<String, String> idMaps = new HashMap<>();
idMaps.put(sourceId, targetId);
List<String> sysFilePaths = new ArrayList<>();
for (int i = 1; i <= elePropertyConfig.getPrjFolderMaxLength(); ++i) {
int layerIndex = i;
List<EdFileInfo> currentSourceLayerDirs = sourceEdFileInfos.stream().filter(e -> StrUtil.count(e.getFilePath(), MYSQL_FILE_PATH_SPLIT) == layerIndex).toList();
@ -436,6 +403,7 @@ public class EdPrjServiceImpl extends ServiceImpl<EdFileInfoMapper, EdFileInfo>
String nowTimeStr = EleCommonUtil.getNowTimeStr();
String fileCode = commonService.createFileCode(targetId, EleDataTypeEnum.FOLDER.desc, FILE_START_VERSION, nowTimeStr);
EdFileInfo targetFile = new EdFileInfo();
targetFile.newInit();
targetFile.setId(newFolderId)
.setFileId(newFolderId)
.setFileName(edFileInfo.getFileName())
@ -454,8 +422,6 @@ public class EdPrjServiceImpl extends ServiceImpl<EdFileInfoMapper, EdFileInfo>
this.save(targetFile);
targetEdFileInfos.add(targetFile);
idMaps.put(edFileInfo.getFileId(), newFolderId);
String targetSysFilePath = commonService.getFileSysPath(targetFile.getFilePath(), dataOwnCode);
sysFilePaths.add(targetSysFilePath);
}
} else {
List<EdFileInfo> edFileInfos = this.baseMapper.selectList(Wrappers.lambdaQuery(EdFileInfo.class)
@ -472,6 +438,7 @@ public class EdPrjServiceImpl extends ServiceImpl<EdFileInfoMapper, EdFileInfo>
String fileCode = commonService.createFileCode(targetId, EleDataTypeEnum.FOLDER.desc, FILE_START_VERSION, nowTimeStr);
EdFileInfo targetFile = new EdFileInfo();
targetFile.newInit();
targetFile.setId(newFolderId)
.setFileId(newFolderId)
.setFileName(edFileInfo.getFileName())
@ -490,14 +457,9 @@ public class EdPrjServiceImpl extends ServiceImpl<EdFileInfoMapper, EdFileInfo>
this.save(targetFile);
targetEdFileInfos.add(targetFile);
idMaps.put(edFileInfo.getFileId(), newFolderId);
String targetSysFilePath = commonService.getFileSysPath(targetFile.getFilePath(), dataOwnCode);
sysFilePaths.add(targetSysFilePath);
}
}
}
for (String path : sysFilePaths) {
fileSystemService.createDirectory(path);
}
UserThreadLocal.setSuccessInfo("", targetId, "层级沿用成功");
return ElectromagneticResultUtil.success(true);
} catch (Exception e) {
@ -523,14 +485,9 @@ public class EdPrjServiceImpl extends ServiceImpl<EdFileInfoMapper, EdFileInfo>
String parentId = this.baseMapper.selectById(id).getParentId();
// 首先检查同层是否有同名目录
Assert.isTrue(commonService.notExistSameFolder(parentId, newFolderName, dataOwnCode), StrFormatter.format("{} 子集名已经存在", newFolderName));
EdFileInfo fileInfo = this.baseMapper.selectOne(Wrappers.lambdaQuery(EdFileInfo.class)
.select(EdFileInfo.class, file -> !StrUtil.equals(file.getColumn(), "file_content"))
.eq(EdFileInfo::getId, id));
String sysFilePath = commonService.getFileSysPath(fileInfo.getFilePath(), dataOwnCode);
this.baseMapper.update(new EdFileInfo(), Wrappers.lambdaUpdate(EdFileInfo.class)
.eq(EdFileInfo::getId, id)
.set(EdFileInfo::getFileName, newFolderName));
fileSystemService.renameFile(sysFilePath, newFolderName);
UserThreadLocal.setSuccessInfo(parentId, id, "子集名称 {} 修改成功", newFolderName);
return ElectromagneticResultUtil.success(true);
} catch (Exception e) {

View File

@ -135,7 +135,7 @@ public class FileRecycleServiceImpl implements FileRecycleService {
.select(EdFileInfo.class, file -> !StrUtil.equals(file.getColumn(), "file_content"))
.eq(EdFileInfo::getFileId, fileId));
for (EdFileInfo edFileInfo : edFileInfos) {
String fileSysPath = commonService.getFileSysPath(edFileInfo.getFilePath(), edFileInfo.getDataOwn());
String fileSysPath = commonService.getFileSysPath(edFileInfo.getId());
backupHandler.backupFiles(fileSysPath, edFileInfo.getParentId());
String fileDbPath = commonService.getDbPath(edFileInfo.getFilePath());
// 移动到tmp目录七天后删除
@ -147,10 +147,6 @@ public class FileRecycleServiceImpl implements FileRecycleService {
.set(EdFileInfo::getPermanentDeleted, true)
.set(EdFileInfo::getAllDeleted, true));
UserThreadLocal.setSuccessInfo(edFileInfo.getParentId(), edFileInfo.getId(), "删除文件 {} 成功文件id {},文件路径 {}", edFileInfos.get(0).getFileName() + "." + edFileInfos.get(0).getFileType(), edFileInfo.getId(), fileDbPath);
// BackupFileResLog resLog = backupHandler.deleteFile(edFileInfo.getId());
// if (!Optional.ofNullable(resLog).map(BackupFileResLog::getBackupSuccess).orElse(false)) {
// log.warn("删除备份文件异常");
// }
return ElectromagneticResultUtil.success("删除文件成功");
}
return ElectromagneticResultUtil.success("删除文件成功");

View File

@ -11,11 +11,6 @@ import java.nio.charset.Charset;
@Service
public class FileSystemServiceImpl implements FileSystemService {
@Override
public void createDirectory(String path) {
FileUtil.mkdir(path);
}
@Override
public void copyFile(String source, String destination) {
FileUtil.copy(source, destination, true);
@ -51,11 +46,6 @@ public class FileSystemServiceImpl implements FileSystemService {
FileUtil.rename(sourceFile, newName, true);
}
@Override
public boolean checkFolderExist(String newPath) {
return FileUtil.exist(newPath);
}
@Override
public boolean writeStringToFile(String filePath, String contents) {
FileUtil.writeString(contents, filePath, Charset.defaultCharset());

View File

@ -66,7 +66,7 @@ public class BackupTask {
EdFileInfo fileInfo = this.edFileInfoMapper.selectOne(Wrappers.<EdFileInfo>lambdaQuery()
.select(EdFileInfo.class, file -> !StrUtil.equals(file.getColumn(), "file_content"))
.eq(EdFileInfo::getId, id));
String sysFilePath = commonService.getFileSysPath(fileInfo.getFilePath(), fileInfo.getDataOwn());
String sysFilePath = commonService.getFileSysPath(fileInfo.getId());
long startTime = System.currentTimeMillis();
BackupFileResLog resLog = backupHandler.backupFiles(sysFilePath, id);
long endTime = System.currentTimeMillis();
@ -97,7 +97,7 @@ public class BackupTask {
UserLoginInfo userLoginInfo = new UserLoginInfo();
userLoginInfo.setUserId(edFileInfo.getCreatedBy());
UserThreadLocal.set(userLoginInfo);
String fileSysPath = commonService.getFileSysPath(edFileInfo.getFilePath(), edFileInfo.getDataOwn());
String fileSysPath = commonService.getFileSysPath(edFileInfo.getId());
UserThreadLocal.remove();
long startTime = System.currentTimeMillis();
BackupFileResLog resLog = backupHandler.backupFiles(fileSysPath, edFileInfo.getId());

View File

@ -27,4 +27,6 @@ public interface ElectromagneticConstants {
String PRJ_INFO = "prj_info";
String EXPORT_PRJ_NAME = "electromagnetic_export";
String USER_ACCESS_LOG = "user_access_log";
}