From c983fda287244d6e2be69fcd1e7bdc8b8b15237a Mon Sep 17 00:00:00 2001 From: chenxudong Date: Wed, 16 Apr 2025 11:26:07 +0800 Subject: [PATCH 01/14] =?UTF-8?q?1.=E6=96=87=E4=BB=B6=E7=B3=BB=E7=BB=9F?= =?UTF-8?q?=E5=AE=8C=E5=85=A8=E4=BE=9D=E8=B5=96MySQL=EF=BC=8C=E5=8E=BB?= =?UTF-8?q?=E9=99=A4=E6=93=8D=E4=BD=9C=E7=B3=BB=E7=BB=9F=E5=B1=82=E9=9D=A2?= =?UTF-8?q?=E7=9A=84=E7=BB=B4=E6=8A=A4=E3=80=82=202.=E6=95=B4=E7=90=86?= =?UTF-8?q?=E4=BB=A3=E7=A0=81=E3=80=82?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../manage/pojo/models/EdFileInfo.java | 5 + .../manage/service/FileSystemService.java | 4 - .../service/serviceimpl/CommonService.java | 54 ++--- .../serviceimpl/EdFileInfoServiceImpl.java | 217 +++++------------- .../EdFileRelationServiceImpl.java | 2 +- .../service/serviceimpl/EdPrjServiceImpl.java | 77 ++----- .../serviceimpl/FileRecycleServiceImpl.java | 6 +- .../serviceimpl/FileSystemServiceImpl.java | 10 - .../software/manage/tasks/BackupTask.java | 4 +- .../common/cons/ElectromagneticConstants.java | 2 + 10 files changed, 100 insertions(+), 281 deletions(-) diff --git a/electrmangnetic/src/main/java/com/electromagnetic/industry/software/manage/pojo/models/EdFileInfo.java b/electrmangnetic/src/main/java/com/electromagnetic/industry/software/manage/pojo/models/EdFileInfo.java index 267572d..3e7d7e3 100644 --- a/electrmangnetic/src/main/java/com/electromagnetic/industry/software/manage/pojo/models/EdFileInfo.java +++ b/electrmangnetic/src/main/java/com/electromagnetic/industry/software/manage/pojo/models/EdFileInfo.java @@ -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()); } } diff --git a/electrmangnetic/src/main/java/com/electromagnetic/industry/software/manage/service/FileSystemService.java b/electrmangnetic/src/main/java/com/electromagnetic/industry/software/manage/service/FileSystemService.java index 581e7ad..49ba7fc 100644 --- a/electrmangnetic/src/main/java/com/electromagnetic/industry/software/manage/service/FileSystemService.java +++ b/electrmangnetic/src/main/java/com/electromagnetic/industry/software/manage/service/FileSystemService.java @@ -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); diff --git a/electrmangnetic/src/main/java/com/electromagnetic/industry/software/manage/service/serviceimpl/CommonService.java b/electrmangnetic/src/main/java/com/electromagnetic/industry/software/manage/service/serviceimpl/CommonService.java index 2f91d9f..5b32c64 100644 --- a/electrmangnetic/src/main/java/com/electromagnetic/industry/software/manage/service/serviceimpl/CommonService.java +++ b/electrmangnetic/src/main/java/com/electromagnetic/industry/software/manage/service/serviceimpl/CommonService.java @@ -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 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 paths = StrUtil.split(dbPath, MYSQL_FILE_PATH_SPLIT); - String prjId = paths.get(0); - return edFileInfoMapper.selectById(prjId).getFileName(); - } - public Set selectPrjLeafs(int dataOwnCode, List accessibleIds) { Set res = new HashSet<>(); @@ -545,18 +535,6 @@ public class CommonService { return res; } - public void deletePrjSysDir(Map map) { - - for (Map.Entry 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--) { diff --git a/electrmangnetic/src/main/java/com/electromagnetic/industry/software/manage/service/serviceimpl/EdFileInfoServiceImpl.java b/electrmangnetic/src/main/java/com/electromagnetic/industry/software/manage/service/serviceimpl/EdFileInfoServiceImpl.java index b70e9a4..11480c0 100644 --- a/electrmangnetic/src/main/java/com/electromagnetic/industry/software/manage/service/serviceimpl/EdFileInfoServiceImpl.java +++ b/electrmangnetic/src/main/java/com/electromagnetic/industry/software/manage/service/serviceimpl/EdFileInfoServiceImpl.java @@ -86,6 +86,8 @@ public class EdFileInfoServiceImpl extends ServiceImpl 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 needMove2FileSystemFiles, String prjDirPath, int dataOwnCode) { - Map maps = needMove2FileSystemFiles.stream().collect(Collectors.toMap(EdFileInfo::getId, e -> e)); List 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 {}, dest path is --->{}", sourcePath, destPath); - fileSystemService.moveFile(sourcePath, destPath); } } @@ -772,22 +771,22 @@ public class EdFileInfoServiceImpl extends ServiceImpl 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 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 exportInfoMap) { - List fileInfos = (List) exportInfoMap.getOrDefault(PRJ_INFO, new ArrayList<>()); - List accessibleFileIds = fileInfos.stream().map(EdFileInfo::getId).toList(); - List edFileRelations = edFileRelationMapper.selectList(Wrappers.lambdaQuery(EdFileRelation.class).in(EdFileRelation::getId1, accessibleFileIds) + private void exportFileTagInfo(String nowTimeStr, List exportFileIds, String userDownloadDataDir) { + List 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 exportFileIds, String userDownloadDataDir) { + List 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 exportInfoMap) { - List fileInfos = (List) exportInfoMap.getOrDefault(PRJ_INFO, new ArrayList<>()); - List accessibleFileIds = fileInfos.stream().map(EdFileInfo::getId).toList(); - List edFileFavorites = edFileFavoriteMapper.selectList(Wrappers.lambdaQuery(EdFileFavorite.class).in(EdFileFavorite::getFileId, accessibleFileIds)); - exportInfoMap.put(ED_FILE_FAVORITE, edFileFavorites); + private void exportCollectionInfo(String nowTimeStr, List exportFileIds, String userDownloadDataDir) { + List 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 exportInfoMap, int dataOwnCode, String dataIdArr, String userDownloadDataDir) throws IOException { + private List exportPrjInfo(String nowTimeStr, int dataOwnCode, String dataIdArr, String userDownloadDataDir) { String[] ids = dataIdArr.split(","); if (DataOwnEnum.isSysCode(dataOwnCode) || DataOwnEnum.isRepoCode(dataOwnCode)) { Map map = permissionService.filterExportIds(ids); @@ -871,107 +877,18 @@ public class EdFileInfoServiceImpl extends ServiceImpl folders = resFiles.stream().filter(e -> e.getDataType().equals(EleDataTypeEnum.FOLDER.code)).toList(); List 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 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 map = permissionService.filterExportIds(ids); -// Assert.isTrue(!map.containsValue(Boolean.FALSE), "有未授权的层级目录,禁止导出"); -// } -// Map maps = new HashMap<>(); -// for (String id : ids) { -// Map 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 resFiles = new ArrayList<>(maps.values()); -// String prjId = resFiles.get(0).getFilePath().split(MYSQL_FILE_PATH_SPLIT)[0]; -// List 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 prjFoldersMap = prjFolders.stream().collect(Collectors.toMap(EdFileInfo::getId, e -> e)); -// Map 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 folders = resFiles.stream().filter(e -> e.getDataType().equals(EleDataTypeEnum.FOLDER.code)).toList(); -// List 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("", "", "导出数据库成功"); -// // 构建响应实体(可以返回 // 保存信息到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 .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 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 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 .eq(EdFileInfo::getDataStatus, EleDataStatusEnum.WAIT_DELETED.code) .likeRight(EdFileInfo::getFilePath, prjId); List edFileInfos = this.baseMapper.selectList(queryWrapper); - Map map = new HashMap<>(); - Map 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 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 .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 // 查找source的全部目录 List sourceEdFileInfos = commonService.selectAllPrjFolder(sourceId, dataOwnCode); List targetEdFileInfos = commonService.selectAllPrjFolder(targetId, dataOwnCode); - // Set sourceNames = sourceEdFileInfos.stream().filter(e -> StrUtil.count(e.getFilePath(), MYSQL_FILE_PATH_SPLIT) == 1).map(EdFileInfo::getFileName).collect(Collectors.toSet()); Set 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 Map idMaps = new HashMap<>(); idMaps.put(sourceId, targetId); - List sysFilePaths = new ArrayList<>(); for (int i = 1; i <= elePropertyConfig.getPrjFolderMaxLength(); ++i) { int layerIndex = i; List currentSourceLayerDirs = sourceEdFileInfos.stream().filter(e -> StrUtil.count(e.getFilePath(), MYSQL_FILE_PATH_SPLIT) == layerIndex).toList(); @@ -436,6 +403,7 @@ public class EdPrjServiceImpl extends ServiceImpl 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 this.save(targetFile); targetEdFileInfos.add(targetFile); idMaps.put(edFileInfo.getFileId(), newFolderId); - String targetSysFilePath = commonService.getFileSysPath(targetFile.getFilePath(), dataOwnCode); - sysFilePaths.add(targetSysFilePath); } } else { List edFileInfos = this.baseMapper.selectList(Wrappers.lambdaQuery(EdFileInfo.class) @@ -472,6 +438,7 @@ public class EdPrjServiceImpl extends ServiceImpl 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 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 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) { diff --git a/electrmangnetic/src/main/java/com/electromagnetic/industry/software/manage/service/serviceimpl/FileRecycleServiceImpl.java b/electrmangnetic/src/main/java/com/electromagnetic/industry/software/manage/service/serviceimpl/FileRecycleServiceImpl.java index 57e1e87..5d75584 100644 --- a/electrmangnetic/src/main/java/com/electromagnetic/industry/software/manage/service/serviceimpl/FileRecycleServiceImpl.java +++ b/electrmangnetic/src/main/java/com/electromagnetic/industry/software/manage/service/serviceimpl/FileRecycleServiceImpl.java @@ -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("删除文件成功"); diff --git a/electrmangnetic/src/main/java/com/electromagnetic/industry/software/manage/service/serviceimpl/FileSystemServiceImpl.java b/electrmangnetic/src/main/java/com/electromagnetic/industry/software/manage/service/serviceimpl/FileSystemServiceImpl.java index 66856cf..8428742 100644 --- a/electrmangnetic/src/main/java/com/electromagnetic/industry/software/manage/service/serviceimpl/FileSystemServiceImpl.java +++ b/electrmangnetic/src/main/java/com/electromagnetic/industry/software/manage/service/serviceimpl/FileSystemServiceImpl.java @@ -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()); diff --git a/electrmangnetic/src/main/java/com/electromagnetic/industry/software/manage/tasks/BackupTask.java b/electrmangnetic/src/main/java/com/electromagnetic/industry/software/manage/tasks/BackupTask.java index 11115c2..361f865 100644 --- a/electrmangnetic/src/main/java/com/electromagnetic/industry/software/manage/tasks/BackupTask.java +++ b/electrmangnetic/src/main/java/com/electromagnetic/industry/software/manage/tasks/BackupTask.java @@ -66,7 +66,7 @@ public class BackupTask { EdFileInfo fileInfo = this.edFileInfoMapper.selectOne(Wrappers.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()); diff --git a/electromagnetic-common/src/main/java/com/electromagnetic/industry/software/common/cons/ElectromagneticConstants.java b/electromagnetic-common/src/main/java/com/electromagnetic/industry/software/common/cons/ElectromagneticConstants.java index 6d8bff6..801e3f3 100644 --- a/electromagnetic-common/src/main/java/com/electromagnetic/industry/software/common/cons/ElectromagneticConstants.java +++ b/electromagnetic-common/src/main/java/com/electromagnetic/industry/software/common/cons/ElectromagneticConstants.java @@ -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"; } From df763a94c93bbf7123663360a090c39da5d0149a Mon Sep 17 00:00:00 2001 From: chenxudong Date: Wed, 16 Apr 2025 11:41:23 +0800 Subject: [PATCH 02/14] =?UTF-8?q?=E8=A7=A3=E5=86=B3=E6=96=87=E4=BB=B6copy?= =?UTF-8?q?=E7=9A=84bug?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../service/serviceimpl/EdFileInfoServiceImpl.java | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/electrmangnetic/src/main/java/com/electromagnetic/industry/software/manage/service/serviceimpl/EdFileInfoServiceImpl.java b/electrmangnetic/src/main/java/com/electromagnetic/industry/software/manage/service/serviceimpl/EdFileInfoServiceImpl.java index 11480c0..996c226 100644 --- a/electrmangnetic/src/main/java/com/electromagnetic/industry/software/manage/service/serviceimpl/EdFileInfoServiceImpl.java +++ b/electrmangnetic/src/main/java/com/electromagnetic/industry/software/manage/service/serviceimpl/EdFileInfoServiceImpl.java @@ -1120,7 +1120,6 @@ public class EdFileInfoServiceImpl extends ServiceImpl Date: Wed, 16 Apr 2025 11:49:31 +0800 Subject: [PATCH 03/14] =?UTF-8?q?=E4=BC=98=E5=8C=96=E4=B8=8B=E8=BD=BD?= =?UTF-8?q?=E6=96=87=E4=BB=B6=E5=90=8D=E7=A7=B0=E7=9A=84=E5=B1=95=E7=A4=BA?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../manage/service/serviceimpl/EdFileInfoServiceImpl.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/electrmangnetic/src/main/java/com/electromagnetic/industry/software/manage/service/serviceimpl/EdFileInfoServiceImpl.java b/electrmangnetic/src/main/java/com/electromagnetic/industry/software/manage/service/serviceimpl/EdFileInfoServiceImpl.java index 996c226..8a3e431 100644 --- a/electrmangnetic/src/main/java/com/electromagnetic/industry/software/manage/service/serviceimpl/EdFileInfoServiceImpl.java +++ b/electrmangnetic/src/main/java/com/electromagnetic/industry/software/manage/service/serviceimpl/EdFileInfoServiceImpl.java @@ -286,7 +286,7 @@ public class EdFileInfoServiceImpl extends ServiceImpl Date: Wed, 16 Apr 2025 12:06:19 +0800 Subject: [PATCH 04/14] =?UTF-8?q?=E6=96=87=E4=BB=B6=E5=A4=87=E4=BB=BD?= =?UTF-8?q?=E7=9A=84=E9=80=82=E9=85=8D=EF=BC=8C=E5=B1=8F=E8=94=BD=E6=96=87?= =?UTF-8?q?=E4=BB=B6=E5=88=A0=E9=99=A4=E7=9B=B8=E5=85=B3=E7=9A=84=E5=8A=9F?= =?UTF-8?q?=E8=83=BD=E3=80=82?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../backup/controller/FileController.java | 28 +++++++++---------- .../software/backup/service/FileService.java | 6 ++-- .../backup/serviceimp/FileServiceImpl.java | 23 +++++++-------- .../serviceimpl/FileBackLogServiceImpl.java | 2 +- .../software/manage/tasks/BackupHandler.java | 23 ++++++++------- 5 files changed, 41 insertions(+), 41 deletions(-) diff --git a/electrmangnetic-backup/src/main/java/com/electromagnetic/industry/software/backup/controller/FileController.java b/electrmangnetic-backup/src/main/java/com/electromagnetic/industry/software/backup/controller/FileController.java index 783e034..4415b8f 100644 --- a/electrmangnetic-backup/src/main/java/com/electromagnetic/industry/software/backup/controller/FileController.java +++ b/electrmangnetic-backup/src/main/java/com/electromagnetic/industry/software/backup/controller/FileController.java @@ -31,10 +31,10 @@ public class FileController { private BackupPro backupPro; @RequestMapping("/upload") - public ElectromagneticResult upload(@RequestParam("file") MultipartFile file, @RequestParam("id") String id) { + public ElectromagneticResult upload(@RequestParam("file") MultipartFile file) { BackupFileResLog backupFileResLog = BackupFileResLog.builder().backupStartTime(new Date()).fileName(file.getOriginalFilename()).backupSuccess(true).build(); try { - fileService.upload(file, id); + fileService.upload(file); } catch (Exception e) { String details = ExceptionUtil.stacktraceToString(e); backupFileResLog.setBackupSuccess(false); @@ -53,20 +53,20 @@ public class FileController { return ElectromagneticResultUtil.success(JSONUtil.toJsonStr(backupFileResLog, jsonConfig)); } - @RequestMapping("/remove") - public ElectromagneticResult remove(@RequestParam("id") String id) { - try { - fileService.remove(id); - } catch (Exception e) { - log.error("删除文件失败, id-->{},原因-->{}", id, e.getMessage(), e); - ElectromagneticResultUtil.fail("-1", e.getMessage()); - } - return ElectromagneticResultUtil.success(true); - } +// @RequestMapping("/remove") +// public ElectromagneticResult remove(@RequestParam("id") String id) { +// try { +// fileService.remove(id); +// } catch (Exception e) { +// log.error("删除文件失败, id-->{},原因-->{}", id, e.getMessage(), e); +// ElectromagneticResultUtil.fail("-1", e.getMessage()); +// } +// return ElectromagneticResultUtil.success(true); +// } @RequestMapping("/download") - public ResponseEntity download(@RequestParam("id") String id) throws Exception { - return fileService.download(id); + public ResponseEntity download(@RequestParam("id") String id, @RequestParam("uuid") String uuid) throws Exception { + return fileService.download(id, uuid); } @RequestMapping("/backupSql") diff --git a/electrmangnetic-backup/src/main/java/com/electromagnetic/industry/software/backup/service/FileService.java b/electrmangnetic-backup/src/main/java/com/electromagnetic/industry/software/backup/service/FileService.java index a1df2dc..a8e94dd 100644 --- a/electrmangnetic-backup/src/main/java/com/electromagnetic/industry/software/backup/service/FileService.java +++ b/electrmangnetic-backup/src/main/java/com/electromagnetic/industry/software/backup/service/FileService.java @@ -8,11 +8,11 @@ import java.io.IOException; public interface FileService { - void upload(MultipartFile file, String id) throws IOException; + void upload(MultipartFile file) throws IOException; - void remove(String id); +// void remove(String id); - ResponseEntity download(String id) throws Exception; + ResponseEntity download(String id, String uuid) throws Exception; void backupSql(MultipartFile file) throws Exception; } diff --git a/electrmangnetic-backup/src/main/java/com/electromagnetic/industry/software/backup/serviceimp/FileServiceImpl.java b/electrmangnetic-backup/src/main/java/com/electromagnetic/industry/software/backup/serviceimp/FileServiceImpl.java index e09963c..aa313ff 100644 --- a/electrmangnetic-backup/src/main/java/com/electromagnetic/industry/software/backup/serviceimp/FileServiceImpl.java +++ b/electrmangnetic-backup/src/main/java/com/electromagnetic/industry/software/backup/serviceimp/FileServiceImpl.java @@ -26,22 +26,23 @@ public class FileServiceImpl implements FileService { private BackupPro backupPro; @Override - public void upload(MultipartFile file, String id) throws IOException { - String destPath = getFileSysPathById(id); + public void upload(MultipartFile file) throws IOException { + String name = FileUtil.mainName(file.getOriginalFilename()); + String destPath = getFileSysPathById(name); if (!FileUtil.exist(destPath)) { FileUtil.writeFromStream(file.getInputStream(), destPath); } } - @Override - public void remove(String id) { - String destPath = getFileSysPathById(id); - FileUtil.del(destPath); - } +// @Override +// public void remove(String id) { +// String destPath = getFileSysPathById(id); +// FileUtil.del(destPath); +// } @Override - public ResponseEntity download(String id) throws Exception { - String destPath = getFileSysPathById(id); + public ResponseEntity download(String id, String uuid) throws Exception { + String destPath = getFileSysPathById(id + "_" + uuid); FileSystemResource fileSystemResource = new FileSystemResource(destPath); return ResponseEntity .ok() @@ -63,9 +64,9 @@ public class FileServiceImpl implements FileService { FileUtil.del(destPath); } - private String getFileSysPathById(String id) { + private String getFileSysPathById(String fileName) { String saveFolder = backupPro.getSaveFolder(); - return saveFolder + File.separator + "prj_files" + File.separator + id; + return saveFolder + File.separator + "prj_files" + File.separator + fileName; } } diff --git a/electrmangnetic/src/main/java/com/electromagnetic/industry/software/manage/service/serviceimpl/FileBackLogServiceImpl.java b/electrmangnetic/src/main/java/com/electromagnetic/industry/software/manage/service/serviceimpl/FileBackLogServiceImpl.java index 5d0f2cc..84ce556 100644 --- a/electrmangnetic/src/main/java/com/electromagnetic/industry/software/manage/service/serviceimpl/FileBackLogServiceImpl.java +++ b/electrmangnetic/src/main/java/com/electromagnetic/industry/software/manage/service/serviceimpl/FileBackLogServiceImpl.java @@ -95,7 +95,7 @@ public class FileBackLogServiceImpl extends ServiceImpl map = new HashMap<>(); map.put("file", new File(filePath)); - map.put("id", id); String url = StrFormatter.format("http://{}:{}/data/file/backup/upload", elePropertyConfig.getRemoteHost(), elePropertyConfig.getRemotePort()); log.info("back up url is {}", url); String res = HttpUtil.post(url, map); @@ -43,18 +42,18 @@ public class BackupHandler { return JSONUtil.toBean(data, BackupFileResLog.class); } - public BackupFileResLog deleteFile(String id) { - Map map = new HashMap<>(); - map.put("id", id); - String url = StrFormatter.format("http://{}:{}/data/file/backup/remove", elePropertyConfig.getRemoteHost(), elePropertyConfig.getRemotePort()); - String res = HttpUtil.get(url, map); - ElectromagneticResult resObj = JSONUtil.toBean(res, ElectromagneticResult.class); - String data = JSONUtil.toJsonStr(resObj.getData()); - return JSONUtil.toBean(data, BackupFileResLog.class); - } +// public BackupFileResLog deleteFile(String id) { +// Map map = new HashMap<>(); +// map.put("id", id); +// String url = StrFormatter.format("http://{}:{}/data/file/backup/remove", elePropertyConfig.getRemoteHost(), elePropertyConfig.getRemotePort()); +// String res = HttpUtil.get(url, map); +// ElectromagneticResult resObj = JSONUtil.toBean(res, ElectromagneticResult.class); +// String data = JSONUtil.toJsonStr(resObj.getData()); +// return JSONUtil.toBean(data, BackupFileResLog.class); +// } - public byte[] downloadFile(String id) { - String url = StrFormatter.format("http://{}:{}/data/file/backup/download?id={}", elePropertyConfig.getRemoteHost(), elePropertyConfig.getRemotePort(), id); + public byte[] downloadFile(String id, String uuid) { + String url = StrFormatter.format("http://{}:{}/data/file/backup/download?id={}&&uuid=", elePropertyConfig.getRemoteHost(), elePropertyConfig.getRemotePort(), id, uuid); return HttpUtil.downloadBytes(url); } } From e1e6e9f466c6a09011336d38bff18cbfb4ca61ce Mon Sep 17 00:00:00 2001 From: chenxudong Date: Wed, 16 Apr 2025 13:43:33 +0800 Subject: [PATCH 05/14] =?UTF-8?q?=E5=8E=BB=E6=8E=89uuid?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../software/backup/controller/FileController.java | 4 ++-- .../industry/software/backup/service/FileService.java | 2 +- .../software/backup/serviceimp/FileServiceImpl.java | 4 ++-- .../industry/software/manage/pojo/models/EdFileInfo.java | 4 ---- .../software/manage/service/serviceimpl/CommonService.java | 7 ++----- .../manage/service/serviceimpl/EdFileInfoServiceImpl.java | 1 - .../manage/service/serviceimpl/FileBackLogServiceImpl.java | 2 +- .../industry/software/manage/tasks/BackupHandler.java | 4 ++-- 8 files changed, 10 insertions(+), 18 deletions(-) diff --git a/electrmangnetic-backup/src/main/java/com/electromagnetic/industry/software/backup/controller/FileController.java b/electrmangnetic-backup/src/main/java/com/electromagnetic/industry/software/backup/controller/FileController.java index 4415b8f..525e7c0 100644 --- a/electrmangnetic-backup/src/main/java/com/electromagnetic/industry/software/backup/controller/FileController.java +++ b/electrmangnetic-backup/src/main/java/com/electromagnetic/industry/software/backup/controller/FileController.java @@ -65,8 +65,8 @@ public class FileController { // } @RequestMapping("/download") - public ResponseEntity download(@RequestParam("id") String id, @RequestParam("uuid") String uuid) throws Exception { - return fileService.download(id, uuid); + public ResponseEntity download(@RequestParam("id") String id) throws Exception { + return fileService.download(id); } @RequestMapping("/backupSql") diff --git a/electrmangnetic-backup/src/main/java/com/electromagnetic/industry/software/backup/service/FileService.java b/electrmangnetic-backup/src/main/java/com/electromagnetic/industry/software/backup/service/FileService.java index a8e94dd..21f924c 100644 --- a/electrmangnetic-backup/src/main/java/com/electromagnetic/industry/software/backup/service/FileService.java +++ b/electrmangnetic-backup/src/main/java/com/electromagnetic/industry/software/backup/service/FileService.java @@ -12,7 +12,7 @@ public interface FileService { // void remove(String id); - ResponseEntity download(String id, String uuid) throws Exception; + ResponseEntity download(String id) throws Exception; void backupSql(MultipartFile file) throws Exception; } diff --git a/electrmangnetic-backup/src/main/java/com/electromagnetic/industry/software/backup/serviceimp/FileServiceImpl.java b/electrmangnetic-backup/src/main/java/com/electromagnetic/industry/software/backup/serviceimp/FileServiceImpl.java index aa313ff..296fcff 100644 --- a/electrmangnetic-backup/src/main/java/com/electromagnetic/industry/software/backup/serviceimp/FileServiceImpl.java +++ b/electrmangnetic-backup/src/main/java/com/electromagnetic/industry/software/backup/serviceimp/FileServiceImpl.java @@ -41,8 +41,8 @@ public class FileServiceImpl implements FileService { // } @Override - public ResponseEntity download(String id, String uuid) throws Exception { - String destPath = getFileSysPathById(id + "_" + uuid); + public ResponseEntity download(String id) throws Exception { + String destPath = getFileSysPathById(id); FileSystemResource fileSystemResource = new FileSystemResource(destPath); return ResponseEntity .ok() diff --git a/electrmangnetic/src/main/java/com/electromagnetic/industry/software/manage/pojo/models/EdFileInfo.java b/electrmangnetic/src/main/java/com/electromagnetic/industry/software/manage/pojo/models/EdFileInfo.java index 3e7d7e3..fba5bb4 100644 --- a/electrmangnetic/src/main/java/com/electromagnetic/industry/software/manage/pojo/models/EdFileInfo.java +++ b/electrmangnetic/src/main/java/com/electromagnetic/industry/software/manage/pojo/models/EdFileInfo.java @@ -125,9 +125,6 @@ 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(); @@ -141,6 +138,5 @@ public class EdFileInfo extends BaseModel { this.setCreatedBy(userId); this.setFileId(newFileDbId); this.setEffectFlag(EffectFlagEnum.EFFECT.code); - this.setUuid(IdUtil.fastSimpleUUID()); } } diff --git a/electrmangnetic/src/main/java/com/electromagnetic/industry/software/manage/service/serviceimpl/CommonService.java b/electrmangnetic/src/main/java/com/electromagnetic/industry/software/manage/service/serviceimpl/CommonService.java index 5b32c64..05da72d 100644 --- a/electrmangnetic/src/main/java/com/electromagnetic/industry/software/manage/service/serviceimpl/CommonService.java +++ b/electrmangnetic/src/main/java/com/electromagnetic/industry/software/manage/service/serviceimpl/CommonService.java @@ -138,16 +138,13 @@ public class CommonService { 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 SYS_FILE, SYS_PRJ, REPO_PRJ, REPO_FILE -> filePath = getPrjRootPath1(dataOwnCode) + id; case USER_FILE, USER_PRJ -> - filePath = getPrjRootPath1(dataOwnCode) + fileInfo.getCreatedBy() + File.separator + fileName; + filePath = getPrjRootPath1(dataOwnCode) + fileInfo.getCreatedBy() + File.separator + id; default -> throw new BizException("参数错误"); } return filePath; diff --git a/electrmangnetic/src/main/java/com/electromagnetic/industry/software/manage/service/serviceimpl/EdFileInfoServiceImpl.java b/electrmangnetic/src/main/java/com/electromagnetic/industry/software/manage/service/serviceimpl/EdFileInfoServiceImpl.java index 8a3e431..8b38c39 100644 --- a/electrmangnetic/src/main/java/com/electromagnetic/industry/software/manage/service/serviceimpl/EdFileInfoServiceImpl.java +++ b/electrmangnetic/src/main/java/com/electromagnetic/industry/software/manage/service/serviceimpl/EdFileInfoServiceImpl.java @@ -945,7 +945,6 @@ public class EdFileInfoServiceImpl extends ServiceImpl Date: Wed, 16 Apr 2025 13:55:14 +0800 Subject: [PATCH 06/14] =?UTF-8?q?=E4=BC=98=E5=8C=96=E4=BB=A3=E7=A0=81?= =?UTF-8?q?=E3=80=82?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../manage/pojo/models/EdFileInfo.java | 1 - .../service/serviceimpl/CommonService.java | 2 +- .../serviceimpl/EdFileInfoServiceImpl.java | 2 +- .../service/serviceimpl/EdPrjServiceImpl.java | 28 +++++++++---------- 4 files changed, 16 insertions(+), 17 deletions(-) diff --git a/electrmangnetic/src/main/java/com/electromagnetic/industry/software/manage/pojo/models/EdFileInfo.java b/electrmangnetic/src/main/java/com/electromagnetic/industry/software/manage/pojo/models/EdFileInfo.java index fba5bb4..267572d 100644 --- a/electrmangnetic/src/main/java/com/electromagnetic/industry/software/manage/pojo/models/EdFileInfo.java +++ b/electrmangnetic/src/main/java/com/electromagnetic/industry/software/manage/pojo/models/EdFileInfo.java @@ -1,6 +1,5 @@ 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; diff --git a/electrmangnetic/src/main/java/com/electromagnetic/industry/software/manage/service/serviceimpl/CommonService.java b/electrmangnetic/src/main/java/com/electromagnetic/industry/software/manage/service/serviceimpl/CommonService.java index 05da72d..f6c0d35 100644 --- a/electrmangnetic/src/main/java/com/electromagnetic/industry/software/manage/service/serviceimpl/CommonService.java +++ b/electrmangnetic/src/main/java/com/electromagnetic/industry/software/manage/service/serviceimpl/CommonService.java @@ -429,7 +429,7 @@ public class CommonService { return map; } - public ElectromagneticResult deleteFolder(String id, int dataOwnCode) { + public ElectromagneticResult deleteFolder(String id) { // 如果文件夹下存在文件(包括文件夹和已经逻辑删除的文件),则不允许删除。后面管理员选择会有物理删除文件夹和文件的功能,此时MySQL和文件系统则会进行物理删除该文件。 EdFileInfo srcFileInfo = edFileInfoMapper.selectById(id); Assert.isTrue(srcFileInfo.getDataType().equals(EleDataTypeEnum.FOLDER.code), "禁止删除目录"); diff --git a/electrmangnetic/src/main/java/com/electromagnetic/industry/software/manage/service/serviceimpl/EdFileInfoServiceImpl.java b/electrmangnetic/src/main/java/com/electromagnetic/industry/software/manage/service/serviceimpl/EdFileInfoServiceImpl.java index 8b38c39..43f513e 100644 --- a/electrmangnetic/src/main/java/com/electromagnetic/industry/software/manage/service/serviceimpl/EdFileInfoServiceImpl.java +++ b/electrmangnetic/src/main/java/com/electromagnetic/industry/software/manage/service/serviceimpl/EdFileInfoServiceImpl.java @@ -254,7 +254,7 @@ public class EdFileInfoServiceImpl extends ServiceImpl res = commonService.deleteFolder(id, dataOwnCode); + ElectromagneticResult res = commonService.deleteFolder(id); UserThreadLocal.setSuccessInfo(fileInfo.getParentId(), id, "作废目录 {} 成功,路径为 {}", fileInfo.getFileName(), dbPath); return res; } diff --git a/electrmangnetic/src/main/java/com/electromagnetic/industry/software/manage/service/serviceimpl/EdPrjServiceImpl.java b/electrmangnetic/src/main/java/com/electromagnetic/industry/software/manage/service/serviceimpl/EdPrjServiceImpl.java index 947d13e..fef3039 100644 --- a/electrmangnetic/src/main/java/com/electromagnetic/industry/software/manage/service/serviceimpl/EdPrjServiceImpl.java +++ b/electrmangnetic/src/main/java/com/electromagnetic/industry/software/manage/service/serviceimpl/EdPrjServiceImpl.java @@ -84,18 +84,16 @@ public class EdPrjServiceImpl extends ServiceImpl try { // 保存信息到MySQL String maxPrjId = this.baseMapper.maxPrjId(); - int prjCount; + Long prjCount; DataOwnEnum enumByCode = DataOwnEnum.getEnumByCode(dataOwnCode); + LambdaQueryWrapper qw = Wrappers.lambdaQuery(EdFileInfo.class).eq(EdFileInfo::getParentId, PRJ_PARENT_ID); 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(); - 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(); - 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(); + case USER_PRJ, USER_FILE -> + prjCount = this.baseMapper.selectCount(qw.eq(EdFileInfo::getDataOwn, DataOwnEnum.USER_PRJ.code).eq(EdFileInfo::getCreatedBy, UserThreadLocal.getUserId())); + case SYS_PRJ, SYS_FILE -> + prjCount = this.baseMapper.selectCount(qw.eq(EdFileInfo::getDataOwn, DataOwnEnum.SYS_PRJ.code)); + case REPO_PRJ, REPO_FILE -> + prjCount = this.baseMapper.selectCount(qw.eq(EdFileInfo::getDataOwn, DataOwnEnum.REPO_PRJ.code)); default -> throw new BizException("参数错误"); } int id = Integer.parseInt(StrUtil.isEmpty(maxPrjId) ? "100000" : maxPrjId); @@ -115,7 +113,7 @@ public class EdPrjServiceImpl extends ServiceImpl .setDataStatus(EleDataStatusEnum.NOT_PUBLISHED.code) .setSaveStatus(EleDataSaveStatusEnum.SUCCESS.code) .setFilePath(newPrjId) - .setSort(++prjCount) + .setSort(prjCount.intValue() + 1) .setFileCode(commonService.createFileCode(newPrjId, EleDataTypeEnum.FOLDER.desc, FILE_START_VERSION, nowTimeStr)) .setDataOwn(dataOwnCode) .setEffectFlag(EffectFlagEnum.EFFECT.code); @@ -163,8 +161,10 @@ public class EdPrjServiceImpl extends ServiceImpl String prjPath; 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; + 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); @@ -358,7 +358,7 @@ public class EdPrjServiceImpl extends ServiceImpl @Override @Transactional(rollbackFor = Exception.class) public ElectromagneticResult deleteFolder(String fileId, int dataOwnCode) { - return commonService.deleteFolder(fileId, dataOwnCode); + return commonService.deleteFolder(fileId); } /** From 7e4e8df1f41512b7c28b6ea32365f79664eae055 Mon Sep 17 00:00:00 2001 From: chenxudong Date: Wed, 16 Apr 2025 14:17:08 +0800 Subject: [PATCH 07/14] =?UTF-8?q?=E4=BC=98=E5=8C=96=E4=BB=A3=E7=A0=81?= =?UTF-8?q?=E3=80=82?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../serviceimpl/EdFileInfoServiceImpl.java | 83 +++++++++---------- 1 file changed, 37 insertions(+), 46 deletions(-) diff --git a/electrmangnetic/src/main/java/com/electromagnetic/industry/software/manage/service/serviceimpl/EdFileInfoServiceImpl.java b/electrmangnetic/src/main/java/com/electromagnetic/industry/software/manage/service/serviceimpl/EdFileInfoServiceImpl.java index 43f513e..be3c213 100644 --- a/electrmangnetic/src/main/java/com/electromagnetic/industry/software/manage/service/serviceimpl/EdFileInfoServiceImpl.java +++ b/electrmangnetic/src/main/java/com/electromagnetic/industry/software/manage/service/serviceimpl/EdFileInfoServiceImpl.java @@ -59,7 +59,7 @@ import java.util.stream.Collectors; import static com.electromagnetic.industry.software.common.cons.ElectromagneticConstants.*; import static com.electromagnetic.industry.software.common.enums.DataOwnEnum.USER_FILE; -import static com.electromagnetic.industry.software.common.enums.FileRepeatEnum.IGNORE; +import static com.electromagnetic.industry.software.common.enums.FileRepeatEnum.*; @Service public class EdFileInfoServiceImpl extends ServiceImpl implements EdFileInfoService { @@ -1061,7 +1061,7 @@ public class EdFileInfoServiceImpl extends ServiceImpl sameFileInfos = this.baseMapper.selectList(Wrappers.lambdaQuery(EdFileInfo.class) .select(EdFileInfo.class, file -> !StrUtil.equals(file.getColumn(), "file_content")) @@ -1088,7 +1088,7 @@ public class EdFileInfoServiceImpl extends ServiceImpl queryWrapper = Wrappers.lambdaQuery(EdFileInfo.class) .select(EdFileInfo.class, file -> !StrUtil.equals(file.getColumn(), "file_content")) @@ -1257,7 +1259,7 @@ public class EdFileInfoServiceImpl extends ServiceImpl parentFileInfos = this.baseMapper.selectList(Wrappers.lambdaQuery(EdFileInfo.class) @@ -1296,69 +1313,43 @@ public class EdFileInfoServiceImpl extends ServiceImpl e.getEffectFlag().equals(EffectFlagEnum.EFFECT.code)).toList().get(0); String codePathByDbPath = commonService.getCodePathByDbPath(effectFileInfo.getFilePath()); - String timeStr = EleCommonUtil.getNowTimeStr(); String fileCode = commonService.createFileCode(codePathByDbPath, suffix, FILE_START_VERSION, timeStr); // 将原有效的版本置为false this.baseMapper.update(new EdFileInfo(), Wrappers.lambdaUpdate(EdFileInfo.class) .set(EdFileInfo::getEffectFlag, EffectFlagEnum.NOT_EFFECTIVE.code) .eq(EdFileInfo::getId, effectFileInfo.getId())); // 新增文件 - EdFileInfo newEdFileInfo = new EdFileInfo(); - newEdFileInfo.newInit(); newEdFileInfo.setFileId(effectFileInfo.getFileId()) .setParentId(parentId) .setFileCode(fileCode) - .setFileName(mainName) - .setFileType(suffix) .setFileVersion(maxFileVersion + 1) .setPreVersion(maxFileVersion) - .setFileContent(EleCommonUtil.parse(file.getInputStream(), suffix)) - .setFileTime(timeStr) - .setFileSize(file.getSize()) .setFilePath(parentFileInfo.getFilePath() + MYSQL_FILE_PATH_SPLIT + newEdFileInfo.getId()) - .setDataType(EleDataTypeEnum.FILE.code) - .setDataStatus(PublishEnum.PUBLISHED.getCode()) - .setFileCode(fileCode) - .setSaveStatus(EleDataSaveStatusEnum.SUCCESS.code) - .setDataOwn(dataOwnCode) - .setEffectFlag(EffectFlagEnum.EFFECT.code); - this.baseMapper.insert(newEdFileInfo); - String fileDestPath = commonService.getFileSysPath(newEdFileInfo.getId()); - fileSystemService.save(file.getInputStream(), fileDestPath); - EleCommonUtil.encryptFile(fileDestPath, SecureUtil.aes(FILE_SEC_PASSWD.getBytes())); - return newEdFileInfo; - } else if (strategy == FileRepeatEnum.NEW.code) { + .setFileCode(fileCode); + } else if (strategy == NEW.code) { // 文件名加”_1“,存为新文件 EdFileInfo parentFileInfo = this.baseMapper.selectOne(Wrappers.lambdaQuery(EdFileInfo.class) .eq(EdFileInfo::getId, parentId) .eq(EdFileInfo::getEffectFlag, EffectFlagEnum.EFFECT.code)); String codePathByDbPath = commonService.getCodePathByDbPath(parentFileInfo.getFilePath()); - EdFileInfo newEdFileInfo = new EdFileInfo(); - newEdFileInfo.newInit(); String fileCode = commonService.createFileCode(codePathByDbPath, suffix, FILE_START_VERSION, newEdFileInfo.getFileTime()); newEdFileInfo.setParentId(parentId) .setFileCode(fileCode) - .setFileName(mainName) - .setFileType(suffix) - .setFileContent(EleCommonUtil.parse(file.getInputStream(), suffix)) .setFileVersion(FILE_START_VERSION) - .setFileTime(newEdFileInfo.getFileTime()) .setFileSize(file.getSize()) .setFilePath(parentFileInfo.getFilePath() + MYSQL_FILE_PATH_SPLIT + newEdFileInfo.getId()) - .setDataType(EleDataTypeEnum.FILE.code) - .setDataStatus(PublishEnum.PUBLISHED.getCode()) - .setFileCode(fileCode) - .setSaveStatus(EleDataSaveStatusEnum.SUCCESS.code) - .setDataOwn(dataOwnCode) - .setEffectFlag(EffectFlagEnum.EFFECT.code); + .setFileCode(fileCode); resetFileInfoName(newEdFileInfo); - this.baseMapper.insert(newEdFileInfo); - String fileDestPath = commonService.getFileSysPath(newEdFileInfo.getId()); - fileSystemService.save(file.getInputStream(), fileDestPath); - EleCommonUtil.encryptFile(fileDestPath, SecureUtil.aes(FILE_SEC_PASSWD.getBytes())); - return newEdFileInfo; + } else if (strategy == IGNORE.code) { + return null; + } else { + throw new BizException("参数错误"); } - return null; + this.baseMapper.insert(newEdFileInfo); + String fileDestPath = commonService.getFileSysPath(newEdFileInfo.getId()); + fileSystemService.save(file.getInputStream(), fileDestPath); + EleCommonUtil.encryptFile(fileDestPath, SecureUtil.aes(FILE_SEC_PASSWD.getBytes())); + return newEdFileInfo; } private String doSysFileMerge(String identifier, String fileName, Integer totalChunks, int dataOwnCode) { From 2f1d15240ea327c618861f1d803c484fe6dc9b40 Mon Sep 17 00:00:00 2001 From: chenxudong Date: Wed, 16 Apr 2025 14:51:40 +0800 Subject: [PATCH 08/14] =?UTF-8?q?=E4=BC=98=E5=8C=96=E4=BB=A3=E7=A0=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../serviceimpl/EdFileInfoServiceImpl.java | 53 +++---------------- .../serviceimpl/FileSystemServiceImpl.java | 5 ++ 2 files changed, 12 insertions(+), 46 deletions(-) diff --git a/electrmangnetic/src/main/java/com/electromagnetic/industry/software/manage/service/serviceimpl/EdFileInfoServiceImpl.java b/electrmangnetic/src/main/java/com/electromagnetic/industry/software/manage/service/serviceimpl/EdFileInfoServiceImpl.java index be3c213..b196db3 100644 --- a/electrmangnetic/src/main/java/com/electromagnetic/industry/software/manage/service/serviceimpl/EdFileInfoServiceImpl.java +++ b/electrmangnetic/src/main/java/com/electromagnetic/industry/software/manage/service/serviceimpl/EdFileInfoServiceImpl.java @@ -64,7 +64,6 @@ import static com.electromagnetic.industry.software.common.enums.FileRepeatEnum. @Service public class EdFileInfoServiceImpl extends ServiceImpl implements EdFileInfoService { - private static final Map> FILE_DB_ID_NAME = new ConcurrentHashMap<>(); private final EleLog log = new EleLog(EdFileInfoServiceImpl.class); @Resource private CommonService commonService; @@ -533,10 +532,7 @@ public class EdFileInfoServiceImpl extends ServiceImpl e.getEffectFlag().equals(EffectFlagEnum.EFFECT.code)).findFirst().get(); - String previousName = fileInfo.getFileName(); resetFileInfoName(fileInfo); - String afterName = fileInfo.getFileName(); - FILE_DB_ID_NAME.put(fileInfo.getId(), List.of(previousName, afterName)); allObjs.addAll(importFiles); allObjs.add(fileInfo); // 线下和线上都存在 @@ -694,46 +687,14 @@ public class EdFileInfoServiceImpl extends ServiceImpl needMove2FileSystemFiles, String prjDirPath, int dataOwnCode) { List files = needMove2FileSystemFiles.stream().filter(e -> e.getDataType().equals(EleDataTypeEnum.FILE.code)).toList(); + List files1 = FileUtil.loopFiles(new File(prjDirPath), file -> file.isDirectory() && file.getName().startsWith(EXPORT_PRJ_NAME)); + String prjFilePath = files1.get(0).getAbsolutePath(); for (EdFileInfo edFileInfo : files) { - String filePath = edFileInfo.getFilePath(); - String previousFileName = FILE_DB_ID_NAME.containsKey(edFileInfo.getId()) ? - FILE_DB_ID_NAME.get(edFileInfo.getId()).get(0) : - edFileInfo.getFileName(); - String afterFileName = FILE_DB_ID_NAME.containsKey(edFileInfo.getId()) ? - FILE_DB_ID_NAME.get(edFileInfo.getId()).get(1) : - edFileInfo.getFileName(); - - StringBuilder sysFileDirPath = new StringBuilder(); - StringBuilder destDirPath = new StringBuilder(); - - for (String id : filePath.split(MYSQL_FILE_PATH_SPLIT)) { - EdFileInfo fileInfo = this.baseMapper.selectById(id); - if (fileInfo.getDataType().equals(EleDataTypeEnum.FOLDER.code)) { - String previousDirName = FILE_DB_ID_NAME.containsKey(id) ? - FILE_DB_ID_NAME.get(id).get(0) : fileInfo.getFileName(); - sysFileDirPath.append(previousDirName).append(File.separator); - String afterDirName = FILE_DB_ID_NAME.containsKey(id) ? - FILE_DB_ID_NAME.get(id).get(1) : fileInfo.getFileName(); - destDirPath.append(afterDirName).append(File.separator); - } - } - String sourcePath = prjDirPath + File.separator + sysFileDirPath + previousFileName + "." + edFileInfo.getFileType() + "." + edFileInfo.getFileCode(); - String destPath; - if (DataOwnEnum.isUserCode(dataOwnCode)) { - destPath = commonService.getPrjRootPath1(dataOwnCode) + - UserThreadLocal.getUserId() + File.separator + - destDirPath + File.separator + sysFileDirPath + - afterFileName + - "." + edFileInfo.getFileType() + - "." + edFileInfo.getFileCode(); - } else { - destPath = commonService.getPrjRootPath1(dataOwnCode) + File.separator + - destDirPath + File.separator + - afterFileName + - "." + edFileInfo.getFileType() + - "." + edFileInfo.getFileCode(); - } - log.info("source path is ----> {}, dest path is --->{}", sourcePath, destPath); + String id = edFileInfo.getId(); + String sourcePath = prjFilePath + File.separator + id; + String destPath = commonService.getPrjRootPath1(dataOwnCode) + File.separator + id; + fileSystemService.moveFile(sourcePath, destPath); + log.info("file import to file system source path is ----> {}, dest path is --->{}", sourcePath, destPath); } } diff --git a/electrmangnetic/src/main/java/com/electromagnetic/industry/software/manage/service/serviceimpl/FileSystemServiceImpl.java b/electrmangnetic/src/main/java/com/electromagnetic/industry/software/manage/service/serviceimpl/FileSystemServiceImpl.java index 8428742..1cdcbd0 100644 --- a/electrmangnetic/src/main/java/com/electromagnetic/industry/software/manage/service/serviceimpl/FileSystemServiceImpl.java +++ b/electrmangnetic/src/main/java/com/electromagnetic/industry/software/manage/service/serviceimpl/FileSystemServiceImpl.java @@ -16,6 +16,11 @@ public class FileSystemServiceImpl implements FileSystemService { FileUtil.copy(source, destination, true); } + /** + * + * @param source /user/aaa/bbb.txt + * @param destination /user/bbb/aaa.txt + */ @Override public void moveFile(String source, String destination) { String destParentDir = FileUtil.getParent(destination, 1); From b634a4396fdd52f576e27f3c510a5b79ced1bb63 Mon Sep 17 00:00:00 2001 From: chenxudong Date: Wed, 16 Apr 2025 14:56:35 +0800 Subject: [PATCH 09/14] clean code --- .../service/serviceimpl/EdFileInfoServiceImpl.java | 9 ++++----- .../service/serviceimpl/FileSystemServiceImpl.java | 3 +-- .../software/common/cons/ElectromagneticConstants.java | 2 ++ 3 files changed, 7 insertions(+), 7 deletions(-) diff --git a/electrmangnetic/src/main/java/com/electromagnetic/industry/software/manage/service/serviceimpl/EdFileInfoServiceImpl.java b/electrmangnetic/src/main/java/com/electromagnetic/industry/software/manage/service/serviceimpl/EdFileInfoServiceImpl.java index b196db3..96fd5e0 100644 --- a/electrmangnetic/src/main/java/com/electromagnetic/industry/software/manage/service/serviceimpl/EdFileInfoServiceImpl.java +++ b/electrmangnetic/src/main/java/com/electromagnetic/industry/software/manage/service/serviceimpl/EdFileInfoServiceImpl.java @@ -54,7 +54,6 @@ import java.nio.charset.Charset; import java.nio.file.Files; import java.nio.file.Paths; import java.util.*; -import java.util.concurrent.ConcurrentHashMap; import java.util.stream.Collectors; import static com.electromagnetic.industry.software.common.cons.ElectromagneticConstants.*; @@ -659,7 +658,7 @@ public class EdFileInfoServiceImpl extends ServiceImpl 0) { - fileName = fileName + "_1"; + fileName = fileName + APPEND_NEW_FILE_NAME; } else { fileInfo.setFileName(fileName); return; @@ -677,7 +676,7 @@ public class EdFileInfoServiceImpl extends ServiceImpl 0) { - fileName = fileName + "_1"; + fileName = fileName + APPEND_NEW_FILE_NAME; } else { fileInfo.setFileName(fileName); return; @@ -1058,7 +1057,7 @@ public class EdFileInfoServiceImpl extends ServiceImpl Date: Wed, 16 Apr 2025 15:37:42 +0800 Subject: [PATCH 10/14] =?UTF-8?q?=E8=A7=A3=E5=86=B3=E5=A4=8D=E5=88=B6?= =?UTF-8?q?=E5=92=8C=E7=A7=BB=E5=8A=A8=E6=96=87=E4=BB=B6=E6=97=B6=E6=96=87?= =?UTF-8?q?=E4=BB=B6=E5=86=85=E5=AE=B9=E4=B8=A2=E5=A4=B1=E7=9A=84bug?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../industry/software/manage/mapper/EdFileInfoMapper.java | 5 +++++ .../manage/service/serviceimpl/EdFileInfoServiceImpl.java | 8 ++++---- 2 files changed, 9 insertions(+), 4 deletions(-) diff --git a/electrmangnetic/src/main/java/com/electromagnetic/industry/software/manage/mapper/EdFileInfoMapper.java b/electrmangnetic/src/main/java/com/electromagnetic/industry/software/manage/mapper/EdFileInfoMapper.java index 014bd64..15bf363 100644 --- a/electrmangnetic/src/main/java/com/electromagnetic/industry/software/manage/mapper/EdFileInfoMapper.java +++ b/electrmangnetic/src/main/java/com/electromagnetic/industry/software/manage/mapper/EdFileInfoMapper.java @@ -24,6 +24,11 @@ public interface EdFileInfoMapper extends BaseMapper { .eq(EdFileInfo::getId, id)); } + default EdFileInfo selectById1(String id) { + return this.selectOne(Wrappers.lambdaQuery(EdFileInfo.class) + .eq(EdFileInfo::getId, id)); + } + @Select("select max(id) from ed_file_info where length(id) = 6") String maxPrjId(); diff --git a/electrmangnetic/src/main/java/com/electromagnetic/industry/software/manage/service/serviceimpl/EdFileInfoServiceImpl.java b/electrmangnetic/src/main/java/com/electromagnetic/industry/software/manage/service/serviceimpl/EdFileInfoServiceImpl.java index 96fd5e0..7d75e52 100644 --- a/electrmangnetic/src/main/java/com/electromagnetic/industry/software/manage/service/serviceimpl/EdFileInfoServiceImpl.java +++ b/electrmangnetic/src/main/java/com/electromagnetic/industry/software/manage/service/serviceimpl/EdFileInfoServiceImpl.java @@ -979,7 +979,7 @@ public class EdFileInfoServiceImpl extends ServiceImpl sameFileInfos = this.baseMapper.selectList(Wrappers.lambdaQuery(EdFileInfo.class) - .select(EdFileInfo.class, file -> !StrUtil.equals(file.getColumn(), "file_content")) + .select() .eq(EdFileInfo::getParentId, targetFolderId) .eq(EdFileInfo::getFileName, srcFileInfo.getFileName()) .eq(EdFileInfo::getFileType, srcFileInfo.getFileType())); @@ -1080,7 +1080,7 @@ public class EdFileInfoServiceImpl extends ServiceImpl copyFile(String id, String targetFolderId, Integer strategy, int dataOwnCode) { Assert.isTrue(FileRepeatEnum.contains(strategy), "解决重名文件参数错误"); // 获取原文件mysql模型 - EdFileInfo srcFileInfo = this.baseMapper.selectById(id); + EdFileInfo srcFileInfo = this.baseMapper.selectById1(id); // 判断目标路径下是否有同名文件,如果所有的同名文件:1)如果所有文件都已经被作废,则该文件为新文件,版本号从100开始。2)如果有没有被作废的文件,则冲突处理方式按---1-跳过冲突文件 2-做版本更新 3-重命名,文件名加"_1" long count = this.baseMapper.selectCount(Wrappers.lambdaQuery(EdFileInfo.class) .eq(EdFileInfo::getParentId, targetFolderId) @@ -1193,7 +1193,7 @@ public class EdFileInfoServiceImpl extends ServiceImpl queryWrapper = Wrappers.lambdaQuery(EdFileInfo.class) - .select(EdFileInfo.class, file -> !StrUtil.equals(file.getColumn(), "file_content")) + .select() .eq(EdFileInfo::getParentId, targetFolderId) .eq(EdFileInfo::getFileName, srcFileInfo.getFileName()) .eq(EdFileInfo::getFileType, srcFileInfo.getFileType()); From 1aae819f4ea21a103a75e77a289c4518696c2650 Mon Sep 17 00:00:00 2001 From: chenxudong Date: Wed, 16 Apr 2025 16:07:36 +0800 Subject: [PATCH 11/14] =?UTF-8?q?=E6=96=87=E4=BB=B6=E5=A4=87=E4=BB=BD?= =?UTF-8?q?=E7=9A=84bug?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../manage/service/serviceimpl/FileRecycleServiceImpl.java | 2 +- .../industry/software/manage/tasks/BackupHandler.java | 2 +- .../industry/software/manage/tasks/BackupTask.java | 4 ++-- 3 files changed, 4 insertions(+), 4 deletions(-) diff --git a/electrmangnetic/src/main/java/com/electromagnetic/industry/software/manage/service/serviceimpl/FileRecycleServiceImpl.java b/electrmangnetic/src/main/java/com/electromagnetic/industry/software/manage/service/serviceimpl/FileRecycleServiceImpl.java index 5d75584..fce2e4b 100644 --- a/electrmangnetic/src/main/java/com/electromagnetic/industry/software/manage/service/serviceimpl/FileRecycleServiceImpl.java +++ b/electrmangnetic/src/main/java/com/electromagnetic/industry/software/manage/service/serviceimpl/FileRecycleServiceImpl.java @@ -136,7 +136,7 @@ public class FileRecycleServiceImpl implements FileRecycleService { .eq(EdFileInfo::getFileId, fileId)); for (EdFileInfo edFileInfo : edFileInfos) { String fileSysPath = commonService.getFileSysPath(edFileInfo.getId()); - backupHandler.backupFiles(fileSysPath, edFileInfo.getParentId()); + backupHandler.backupFiles(fileSysPath); String fileDbPath = commonService.getDbPath(edFileInfo.getFilePath()); // 移动到tmp目录,七天后删除 fileSystemService.moveFile(fileSysPath, elePropertyConfig.getEleTmpPath() + File.separator + new File(fileSysPath).getName()); diff --git a/electrmangnetic/src/main/java/com/electromagnetic/industry/software/manage/tasks/BackupHandler.java b/electrmangnetic/src/main/java/com/electromagnetic/industry/software/manage/tasks/BackupHandler.java index 4e6878e..20ef993 100644 --- a/electrmangnetic/src/main/java/com/electromagnetic/industry/software/manage/tasks/BackupHandler.java +++ b/electrmangnetic/src/main/java/com/electromagnetic/industry/software/manage/tasks/BackupHandler.java @@ -21,7 +21,7 @@ public class BackupHandler { @Resource private ElePropertyConfig elePropertyConfig; - public BackupFileResLog backupFiles(String filePath, String id) { + public BackupFileResLog backupFiles(String filePath) { Map map = new HashMap<>(); map.put("file", new File(filePath)); String url = StrFormatter.format("http://{}:{}/data/file/backup/upload", elePropertyConfig.getRemoteHost(), elePropertyConfig.getRemotePort()); diff --git a/electrmangnetic/src/main/java/com/electromagnetic/industry/software/manage/tasks/BackupTask.java b/electrmangnetic/src/main/java/com/electromagnetic/industry/software/manage/tasks/BackupTask.java index 361f865..961ec1a 100644 --- a/electrmangnetic/src/main/java/com/electromagnetic/industry/software/manage/tasks/BackupTask.java +++ b/electrmangnetic/src/main/java/com/electromagnetic/industry/software/manage/tasks/BackupTask.java @@ -68,7 +68,7 @@ public class BackupTask { .eq(EdFileInfo::getId, id)); String sysFilePath = commonService.getFileSysPath(fileInfo.getId()); long startTime = System.currentTimeMillis(); - BackupFileResLog resLog = backupHandler.backupFiles(sysFilePath, id); + BackupFileResLog resLog = backupHandler.backupFiles(sysFilePath); long endTime = System.currentTimeMillis(); fileBackupLogMapper.update(null, Wrappers.lambdaUpdate() .eq(FileBackupLog::getFileId, id) @@ -100,7 +100,7 @@ public class BackupTask { String fileSysPath = commonService.getFileSysPath(edFileInfo.getId()); UserThreadLocal.remove(); long startTime = System.currentTimeMillis(); - BackupFileResLog resLog = backupHandler.backupFiles(fileSysPath, edFileInfo.getId()); + BackupFileResLog resLog = backupHandler.backupFiles(fileSysPath); long endTime = System.currentTimeMillis(); FileBackupLog backupLog = new FileBackupLog() .setId(IdWorker.getSnowFlakeIdString()) From d466e8fa16e63c98d7eacdf6f24594f8a69e60c8 Mon Sep 17 00:00:00 2001 From: chenxudong Date: Wed, 16 Apr 2025 16:27:18 +0800 Subject: [PATCH 12/14] =?UTF-8?q?Ai=E4=B8=AD=E5=BC=BA=E5=88=B6=E4=BD=BF?= =?UTF-8?q?=E7=94=A8=E4=B8=AD=E6=96=87=E5=9B=9E=E7=AD=94?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../software/manage/service/serviceimpl/ChatService.java | 2 ++ 1 file changed, 2 insertions(+) diff --git a/electrmangnetic/src/main/java/com/electromagnetic/industry/software/manage/service/serviceimpl/ChatService.java b/electrmangnetic/src/main/java/com/electromagnetic/industry/software/manage/service/serviceimpl/ChatService.java index 2b389b8..7ada349 100644 --- a/electrmangnetic/src/main/java/com/electromagnetic/industry/software/manage/service/serviceimpl/ChatService.java +++ b/electrmangnetic/src/main/java/com/electromagnetic/industry/software/manage/service/serviceimpl/ChatService.java @@ -174,6 +174,7 @@ public class ChatService { aiQuestionRecordMapper.insert(record); UserThreadLocal.remove(); return ChatClient.builder(model) + .defaultSystem("必须用中文回答") .defaultAdvisors(messageChatMemoryAdvisor, questionAnswerAdvisor) .defaultOptions(OllamaOptions .builder() @@ -193,6 +194,7 @@ public class ChatService { UserThreadLocal.remove(); aiQuestionRecordMapper.insert(record); return ChatClient.builder(model) + .defaultSystem("必须用中文回答") .defaultAdvisors(messageChatMemoryAdvisor, questionAnswerAdvisor) .defaultOptions(OllamaOptions .builder() From dda88c8aadb2aca6850da12637cb9f6eede3dec9 Mon Sep 17 00:00:00 2001 From: chenxudong Date: Wed, 16 Apr 2025 17:06:58 +0800 Subject: [PATCH 13/14] =?UTF-8?q?=E4=BF=AE=E5=A4=8D=E5=B7=B2=E7=9F=A5?= =?UTF-8?q?=E9=97=AE=E9=A2=98=E3=80=82?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../software/manage/service/serviceimpl/CommonService.java | 3 --- .../software/common/cons/ElectromagneticConstants.java | 2 -- 2 files changed, 5 deletions(-) diff --git a/electrmangnetic/src/main/java/com/electromagnetic/industry/software/manage/service/serviceimpl/CommonService.java b/electrmangnetic/src/main/java/com/electromagnetic/industry/software/manage/service/serviceimpl/CommonService.java index f6c0d35..0eb3b98 100644 --- a/electrmangnetic/src/main/java/com/electromagnetic/industry/software/manage/service/serviceimpl/CommonService.java +++ b/electrmangnetic/src/main/java/com/electromagnetic/industry/software/manage/service/serviceimpl/CommonService.java @@ -479,12 +479,9 @@ public class CommonService { return ElectromagneticResultUtil.fail("-1", info); } else { // 逻辑删除文件夹 - String newFileName = srcFileInfo.getFileName() + MYSQL_FILE_PATH_SPLIT + uuid + DELETE_FLAG; edFileInfoMapper.update(new EdFileInfo(), Wrappers.lambdaUpdate() .eq(EdFileInfo::getId, id) - .set(EdFileInfo::getFileName, newFileName) .set(EdFileInfo::getEffectFlag, EffectFlagEnum.NOT_EFFECTIVE.code)); - fileSystemService.renameFile(srcFilePath, newFileName); } } UserThreadLocal.setSuccessInfo(srcFileInfo.getParentId(), id, "删除目录 {} 成功", srcFileInfo.getFileName()); diff --git a/electromagnetic-common/src/main/java/com/electromagnetic/industry/software/common/cons/ElectromagneticConstants.java b/electromagnetic-common/src/main/java/com/electromagnetic/industry/software/common/cons/ElectromagneticConstants.java index 5712597..3cffab6 100644 --- a/electromagnetic-common/src/main/java/com/electromagnetic/industry/software/common/cons/ElectromagneticConstants.java +++ b/electromagnetic-common/src/main/java/com/electromagnetic/industry/software/common/cons/ElectromagneticConstants.java @@ -16,8 +16,6 @@ public interface ElectromagneticConstants { String FILE_SEC_PASSWD = "adknfhkj87654knd"; - String DELETE_FLAG = "_deleted"; - String ED_FILE_FAVORITE = "ed_file_favorite"; String ED_FILE_RELATION = "ed_file_relation"; From d9525bc13bd64a92c588122d71e8e61e97adc71e Mon Sep 17 00:00:00 2001 From: chenxudong Date: Wed, 16 Apr 2025 18:00:42 +0800 Subject: [PATCH 14/14] =?UTF-8?q?=E5=AE=8C=E6=88=90=E5=AF=BC=E5=85=A5?= =?UTF-8?q?=E5=AF=BC=E5=87=BA=E6=96=87=E4=BB=B6=E5=85=B6=E4=BD=99=E5=B1=9E?= =?UTF-8?q?=E6=80=A7=E7=9A=84=E5=A4=A7=E4=BD=93=E9=80=BB=E8=BE=91=E3=80=82?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../manage/service/EdFileRelationService.java | 3 +- .../manage/service/UserAccessLogService.java | 4 +- .../serviceimpl/EdFileInfoServiceImpl.java | 58 ++++++++++--------- .../serviceimpl/UserAccessLogServiceImpl.java | 1 - 4 files changed, 37 insertions(+), 29 deletions(-) diff --git a/electrmangnetic/src/main/java/com/electromagnetic/industry/software/manage/service/EdFileRelationService.java b/electrmangnetic/src/main/java/com/electromagnetic/industry/software/manage/service/EdFileRelationService.java index d1e4594..4c1c6bd 100644 --- a/electrmangnetic/src/main/java/com/electromagnetic/industry/software/manage/service/EdFileRelationService.java +++ b/electrmangnetic/src/main/java/com/electromagnetic/industry/software/manage/service/EdFileRelationService.java @@ -1,12 +1,13 @@ package com.electromagnetic.industry.software.manage.service; +import com.baomidou.mybatisplus.extension.service.IService; import com.electromagnetic.industry.software.common.resp.ElectromagneticResult; import com.electromagnetic.industry.software.manage.pojo.models.EdFileRelation; import com.electromagnetic.industry.software.manage.pojo.req.CheckNameUniqueRequest; import com.electromagnetic.industry.software.manage.pojo.resp.FileRelationViewVO; import org.springframework.web.multipart.MultipartFile; -public interface EdFileRelationService { +public interface EdFileRelationService extends IService { /** * 创建文件关系 diff --git a/electrmangnetic/src/main/java/com/electromagnetic/industry/software/manage/service/UserAccessLogService.java b/electrmangnetic/src/main/java/com/electromagnetic/industry/software/manage/service/UserAccessLogService.java index 71f12d8..26977a6 100644 --- a/electrmangnetic/src/main/java/com/electromagnetic/industry/software/manage/service/UserAccessLogService.java +++ b/electrmangnetic/src/main/java/com/electromagnetic/industry/software/manage/service/UserAccessLogService.java @@ -1,9 +1,11 @@ package com.electromagnetic.industry.software.manage.service; +import com.baomidou.mybatisplus.extension.service.IService; import com.electromagnetic.industry.software.common.resp.ElectromagneticResult; +import com.electromagnetic.industry.software.manage.pojo.models.UserAccessLog; import com.electromagnetic.industry.software.manage.pojo.req.AccessLogQueryDTO; -public interface UserAccessLogService { +public interface UserAccessLogService extends IService { /** * 分页查询操作记录(审计) diff --git a/electrmangnetic/src/main/java/com/electromagnetic/industry/software/manage/service/serviceimpl/EdFileInfoServiceImpl.java b/electrmangnetic/src/main/java/com/electromagnetic/industry/software/manage/service/serviceimpl/EdFileInfoServiceImpl.java index 7d75e52..e322202 100644 --- a/electrmangnetic/src/main/java/com/electromagnetic/industry/software/manage/service/serviceimpl/EdFileInfoServiceImpl.java +++ b/electrmangnetic/src/main/java/com/electromagnetic/industry/software/manage/service/serviceimpl/EdFileInfoServiceImpl.java @@ -79,13 +79,9 @@ public class EdFileInfoServiceImpl extends ServiceImpl queryEdFileInfo(FileInfoQueryDTO pars, int dataOwnCode) { - if (DataOwnEnum.isSysCode(dataOwnCode)) { String parentId = pars.getParentId(); List accessibleTree = permissionService.getAccessibleTree(); @@ -485,29 +480,40 @@ public class EdFileInfoServiceImpl extends ServiceImpl importInfoMap = JSONUtil.toBean(info, Map.class); - updatePrjInfo(importInfoMap, prjDirPath, dataOwnCode); - updateCollectionInfo(importInfoMap); - updateFileTageInfo(importInfoMap); - updateFileRelationInfo(importInfoMap); + updatePrjInfo(prjDirPath, dataOwnCode); + updateCollectionInfo(prjDirPath); + updateFileTageInfo(prjDirPath); + updateFileRelationInfo(prjDirPath); + updateUserAccessLog(prjDirPath); } - private void updateFileRelationInfo(Map importInfoMap) { - + private void updateUserAccessLog(String prjDirPath) { + String path = prjDirPath + File.separator + USER_ACCESS_LOG + ".json"; + List userAccessLogs = JSONUtil.toList(FileUtil.readString(path, Charset.defaultCharset()), UserAccessLog.class); + userAccessLogService.saveOrUpdateBatch(userAccessLogs); } - private void updateFileTageInfo(Map importInfoMap) { - + private void updateFileRelationInfo(String prjDirPath) { + String path = prjDirPath + File.separator + ED_TAG_RELATIONS + ".json"; + List relations = JSONUtil.toList(FileUtil.readString(path, Charset.defaultCharset()), EdFileRelation.class); + edFileRelationService.saveOrUpdateBatch(relations); } - private void updateCollectionInfo(Map importInfoMap) { - List edFileFavorites = (List) importInfoMap.getOrDefault(ED_FILE_FAVORITE, new ArrayList<>()); - edFileFavoriteMapper.insertOrUpdate(edFileFavorites); + private void updateFileTageInfo(String prjDirPath) { + String path = prjDirPath + File.separator + USER_ACCESS_LOG + ".json"; + List relations = JSONUtil.toList(FileUtil.readString(path, Charset.defaultCharset()), FileTagRelation.class); + fileTagRelationService.saveOrUpdateBatch(relations); } - private void updatePrjInfo(Map importInfoMap, String prjDirPath, Integer dataOwnCode) { - List importAllFiles = (List) importInfoMap.getOrDefault(PRJ_INFO, new ArrayList<>()); + private void updateCollectionInfo(String prjDirPath) { + String path = prjDirPath + File.separator + ED_FILE_FAVORITE + ".json"; + List edFileFavorites = JSONUtil.toList(FileUtil.readString(path, Charset.defaultCharset()), EdFileFavorite.class); + fileFavoriteService.saveOrUpdateBatch(edFileFavorites); + } + + private void updatePrjInfo(String prjDirPath, Integer dataOwnCode) { + String path = prjDirPath + File.separator + PRJ_INFO + ".json"; + List importAllFiles = JSONUtil.toList(FileUtil.readString(path, Charset.defaultCharset()), EdFileInfo.class); // 找出层级文件夹 List prjFolders = importAllFiles.stream().filter(e -> DataOwnEnum.isPrjCode(e.getDataOwn())) .toList(); @@ -781,21 +787,21 @@ public class EdFileInfoServiceImpl extends ServiceImpl exportFileIds, String userDownloadDataDir) { - List userAccessLogs = userAccessLogMapper.selectList(null); + List userAccessLogs = userAccessLogService.getBaseMapper().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 exportFileTagInfo(String nowTimeStr, List exportFileIds, String userDownloadDataDir) { - List fileTagRelations = fileTagRelationMapper.selectList(Wrappers.lambdaQuery(FileTagRelation.class).in(FileTagRelation::getFileId, exportFileIds)); + List fileTagRelations = fileTagRelationService.getBaseMapper().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 exportFileIds, String userDownloadDataDir) { - List edFileRelations = edFileRelationMapper.selectList(Wrappers.lambdaQuery(EdFileRelation.class).in(EdFileRelation::getId1, exportFileIds) + List edFileRelations = edFileRelationService.getBaseMapper().selectList(Wrappers.lambdaQuery(EdFileRelation.class).in(EdFileRelation::getId1, exportFileIds) .or() .in(EdFileRelation::getId2, exportFileIds)); String json = JSONUtil.toJsonStr(edFileRelations); @@ -804,7 +810,7 @@ public class EdFileInfoServiceImpl extends ServiceImpl exportFileIds, String userDownloadDataDir) { - List edFileFavorites = edFileFavoriteMapper.selectList(Wrappers.lambdaQuery(EdFileFavorite.class).in(EdFileFavorite::getFileId, exportFileIds)); + List edFileFavorites = fileFavoriteService.getBaseMapper().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); diff --git a/electrmangnetic/src/main/java/com/electromagnetic/industry/software/manage/service/serviceimpl/UserAccessLogServiceImpl.java b/electrmangnetic/src/main/java/com/electromagnetic/industry/software/manage/service/serviceimpl/UserAccessLogServiceImpl.java index 9285020..3c5dfc0 100644 --- a/electrmangnetic/src/main/java/com/electromagnetic/industry/software/manage/service/serviceimpl/UserAccessLogServiceImpl.java +++ b/electrmangnetic/src/main/java/com/electromagnetic/industry/software/manage/service/serviceimpl/UserAccessLogServiceImpl.java @@ -31,7 +31,6 @@ import java.util.stream.Collectors; @Service public class UserAccessLogServiceImpl extends ServiceImpl implements UserAccessLogService { - @Resource private UserMapper userMapper;