From 8dab45c624e92c16f3e94aa6e52c85fc2e594eba Mon Sep 17 00:00:00 2001 From: chenxudong Date: Tue, 8 Apr 2025 10:37:58 +0800 Subject: [PATCH] =?UTF-8?q?=E8=A7=A3=E5=86=B3=E5=8F=91=E7=8E=B0=E7=9A=84?= =?UTF-8?q?=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../service/serviceimpl/CommonService.java | 24 ++++++------ .../serviceimpl/EdFileInfoServiceImpl.java | 7 +++- .../service/serviceimpl/EdPrjServiceImpl.java | 37 ++++++++++++++++--- .../software/manage/tasks/BackupHandler.java | 3 ++ 4 files changed, 54 insertions(+), 17 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 2416a2a..501ffee 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 @@ -126,15 +126,6 @@ public class CommonService { return PATH_MAP.get(dataOwnCode) + File.separator; } - public String getPrjRootPath(int dataOwnCode) { - - if (DataOwnEnum.isUserCode(dataOwnCode)) { - return PATH_MAP.get(dataOwnCode) + File.separator + UserThreadLocal.getUserId() + File.separator; - } - - return PATH_MAP.get(dataOwnCode); - } - /** * 检查同层级是否有同名的文件夹 */ @@ -152,7 +143,13 @@ public class CommonService { public String getFileSysPath(String dbPath, int dataOwnCode) { ArrayList paths = CollUtil.newArrayList(dbPath.split(MYSQL_FILE_PATH_SPLIT)); String path = getDbPath(paths); - String destPath = getPrjRootPath(dataOwnCode) + File.separator + path; + 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; + } return destPath.replace("//", "/"); } @@ -263,7 +260,12 @@ public class CommonService { .setDataOwn(dataOwnCode); edFileInfoMapper.insert(fileInfo); // 保存到文件系统 - String targetFilePath = getPrjRootPath(dataOwnCode) + File.separator + getDbPath(paths) + File.separator + folderName; + 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) { 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 b53442e..6cdbee4 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 @@ -646,7 +646,12 @@ public class EdFileInfoServiceImpl extends ServiceImpl .setDataOwn(dataOwnCode); this.save(fileInfo); // 保存到文件系统 - fileSystemService.createDirectory(commonService.getPrjRootPath(dataOwnCode) + File.separator + prjName); + 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()); @@ -158,7 +164,12 @@ public class EdPrjServiceImpl extends ServiceImpl return ElectromagneticResultUtil.fail("-1", info); } - String newPath = commonService.getPrjRootPath(dataOwnCode) + File.separator + newPrjName; + 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); @@ -166,7 +177,15 @@ public class EdPrjServiceImpl extends ServiceImpl this.baseMapper.update(new EdFileInfo(), Wrappers.lambdaUpdate(EdFileInfo.class) .eq(EdFileInfo::getId, prjId) .set(EdFileInfo::getFileName, newPrjName)); - fileSystemService.renameFile(commonService.getPrjRootPath(dataOwnCode), oldPrjName, newPrjName); + + String prjPath; + if (DataOwnEnum.isUserCode(dataOwnCode)) { + prjPath = commonService.getPrjRootPath1(dataOwnCode) + File.separator + UserThreadLocal.getUserId() + File.separator; + } else { + prjPath = commonService.getPrjRootPath1(dataOwnCode) + File.separator; + } + + fileSystemService.renameFile(prjPath, oldPrjName, newPrjName); UserThreadLocal.setSuccessInfo("", prjId, "修改工层名 {} 为 {} 成功。", oldPrjName, newPrjName); } catch (Exception e) { String info = StrFormatter.format("修改工程名异常--->{},{}", newPrjName, e.getMessage()); @@ -229,9 +248,17 @@ public class EdPrjServiceImpl extends ServiceImpl public ElectromagneticResult addFolder(String parentId, String folderName, int dataOwnCode) { Assert.isTrue(EleCommonUtil.isFileNameValid(folderName), NAME_VALID_MSG); // 检查当前目录下有文件,如果有则不允许添加 - long count = this.baseMapper.selectCount(Wrappers.lambdaQuery(EdFileInfo.class) + LambdaQueryWrapper queryWrapper = Wrappers.lambdaQuery(EdFileInfo.class) .eq(EdFileInfo::getParentId, parentId) - .eq(EdFileInfo::getEffectFlag, EffectFlagEnum.EFFECT.code)); + .eq(EdFileInfo::getEffectFlag, EffectFlagEnum.EFFECT.code); + + queryWrapper.and(qr -> qr.eq(EdFileInfo::getDataOwn, DataOwnEnum.USER_FILE.code) + .or() + .eq(EdFileInfo::getDataOwn, DataOwnEnum.REPO_FILE.code) + .or() + .eq(EdFileInfo::getDataOwn, DataOwnEnum.SYS_FILE.code)); + + long count = this.baseMapper.selectCount(queryWrapper); if (count > 0) { return ElectromagneticResultUtil.fail("-1", StrFormatter.format("该层级目录下存在文件或者文件夹,不允许再定义层级目录。父目录id {},子集名称 {}", parentId, folderName)); 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 511c77d..f904d65 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 @@ -7,6 +7,7 @@ import com.electromagnetic.industry.software.common.pojo.BackupFileResLog; import com.electromagnetic.industry.software.common.resp.ElectromagneticResult; import com.electromagnetic.industry.software.manage.config.ElePropertyConfig; import jakarta.annotation.Resource; +import lombok.extern.slf4j.Slf4j; import org.springframework.stereotype.Component; import java.io.File; @@ -14,6 +15,7 @@ import java.util.HashMap; import java.util.Map; @Component +@Slf4j public class BackupHandler { @Resource @@ -24,6 +26,7 @@ public class BackupHandler { 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); ElectromagneticResult resObj = JSONUtil.toBean(res, ElectromagneticResult.class); String data = JSONUtil.toJsonStr(resObj.getData());