From 5149b6596173f0b02bdc79dbc21e24ac5fcb0dc2 Mon Sep 17 00:00:00 2001 From: chenxudong Date: Thu, 10 Apr 2025 10:48:44 +0800 Subject: [PATCH] =?UTF-8?q?=E5=BC=80=E5=8F=91=E4=BA=86=E9=83=A8=E5=88=86?= =?UTF-8?q?=E5=AF=BC=E5=87=BA=E5=AF=BC=E5=85=A5=E7=9A=84=E5=8A=9F=E8=83=BD?= =?UTF-8?q?=EF=BC=8C=E5=90=8E=E6=9C=9F=E6=A0=B9=E6=8D=AE=E5=AE=9E=E9=99=85?= =?UTF-8?q?=E9=9C=80=E6=B1=82=E5=86=B3=E5=AE=9A=E6=98=AF=E5=90=A6=E9=87=8D?= =?UTF-8?q?=E6=96=B0=E5=BC=80=E5=8F=91=E3=80=82?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../serviceimpl/EdFileInfoServiceImpl.java | 136 +++++++++++++++++- .../common/cons/ElectromagneticConstants.java | 24 ++++ 2 files changed, 155 insertions(+), 5 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 cc42aea..c028ea8 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 @@ -27,11 +27,8 @@ import com.electromagnetic.industry.software.common.pojo.RespPageVO; import com.electromagnetic.industry.software.common.resp.ElectromagneticResult; import com.electromagnetic.industry.software.common.util.*; import com.electromagnetic.industry.software.manage.config.ElePropertyConfig; -import com.electromagnetic.industry.software.manage.mapper.EdFileInfoMapper; -import com.electromagnetic.industry.software.manage.mapper.UserMapper; -import com.electromagnetic.industry.software.manage.pojo.models.EdFileFavorite; -import com.electromagnetic.industry.software.manage.pojo.models.EdFileInfo; -import com.electromagnetic.industry.software.manage.pojo.models.User; +import com.electromagnetic.industry.software.manage.mapper.*; +import com.electromagnetic.industry.software.manage.pojo.models.*; import com.electromagnetic.industry.software.manage.pojo.other.FileInfoVO; import com.electromagnetic.industry.software.manage.pojo.other.UploadRecordDTO; import com.electromagnetic.industry.software.manage.pojo.req.*; @@ -87,6 +84,24 @@ public class EdFileInfoServiceImpl extends ServiceImpl batchExport1(String dataIdArr, HttpServletResponse response, int dataOwnCode) throws IOException { + + String[] ids = dataIdArr.split(","); + + if (DataOwnEnum.isSysCode(dataOwnCode) || DataOwnEnum.isRepoCode(dataOwnCode)) { + Map map = permissionService.filterExportIds(ids); + Assert.isTrue(!map.containsValue(Boolean.FALSE), "有未授权的层级目录,禁止导出"); + } + + Map exportInfoMap = new HashMap<>(); + // 查询需要导出的文件信息 + List edFileInfos = this.baseMapper.selectList(Wrappers.lambdaQuery(EdFileInfo.class) + .in(EdFileInfo::getParentId, Arrays.asList(ids)) + .eq(EdFileInfo::getDataType, EleDataTypeEnum.FILE.code) + .eq(EdFileInfo::getAllDeleted, false) + .eq(EdFileInfo::getPermanentDeleted, false)); + exportInfoMap.put(PRJ_FILE, edFileInfos); + List accessibleIds = edFileInfos.stream().map(EdFileInfo::getId).toList(); + List paths = edFileInfos.stream().map(EdFileInfo::getFilePath).toList(); + // 先导出MySQL数据库相关信息 + exportMysqlInfo(accessibleIds, exportInfoMap); + // 导出工程目录信息 + exportPrjDirs(paths, exportInfoMap, dataOwnCode); + // 导出工程文件信息 +// exportPrjFiles(); + return null; + } + + private void exportPrjFiles(int dataOwnCode) { + String userDownloadDataDir = elePropertyConfig.getDownloadDataDir(dataOwnCode) + File.separator + UserThreadLocal.getUserId(); + + + + } + + private void exportPrjDirs(List filePaths, Map map, Integer dataOwnCode) { + Set prjIds = new HashSet<>(); + for (String path : filePaths) { + String prjId = path.split(MYSQL_FILE_PATH_SPLIT)[0]; + prjIds.add(prjId); + } + List list = new ArrayList<>(); + for (String prjId : prjIds) { + LambdaQueryWrapper queryWrapper = Wrappers.lambdaQuery(EdFileInfo.class) + .likeRight(EdFileInfo::getFilePath, prjId) + .eq(EdFileInfo::getDataType, EleDataTypeEnum.FOLDER.code) + .eq(EdFileInfo::getAllDeleted, false) + .eq(EdFileInfo::getPermanentDeleted, false) + .eq(EdFileInfo::getEffectFlag, EffectFlagEnum.EFFECT.code); + if (DataOwnEnum.isUserCode(dataOwnCode)) { + queryWrapper.eq(EdFileInfo::getDataOwn, DataOwnEnum.USER_PRJ.code) + .or() + .eq(EdFileInfo::getDataOwn, DataOwnEnum.USER_FILE.code); + } else if (DataOwnEnum.isRepoCode(dataOwnCode)) { + queryWrapper.eq(EdFileInfo::getDataOwn, DataOwnEnum.REPO_PRJ.code) + .or() + .eq(EdFileInfo::getDataOwn, DataOwnEnum.REPO_FILE.code); + } else { + queryWrapper.eq(EdFileInfo::getDataOwn, DataOwnEnum.SYS_PRJ.code) + .or() + .eq(EdFileInfo::getDataOwn, DataOwnEnum.SYS_FILE.code); + } + List edFileInfos = this.baseMapper.selectList(queryWrapper); + list.addAll(edFileInfos); + } + map.put(PRJ_DIR, list); + } + + private void exportMysqlInfo(List accessibleIds, Map map) { + // 收藏夹 + List edFileFavorites = edFileFavoriteMapper.selectList(Wrappers.lambdaQuery(EdFileFavorite.class) + .in(EdFileFavorite::getFileId, accessibleIds)); + map.put(ED_FILE_FAVORITE, edFileFavorites); + + // 文件格式(只导出,不导入) + List fileFormats = fileFormatMapper.selectList(null); + map.put(ED_FILE_FORMAT, fileFormats); + + // 文件关系 + List edFileRelations = edFileRelationMapper.selectList(Wrappers.lambdaQuery(EdFileRelation.class) + .in(EdFileRelation::getId1, accessibleIds) + .or() + .in(EdFileRelation::getId2, accessibleIds)); + map.put(ED_FILE_RELATION, edFileRelations); + + // 角色(只导出,不导入) + List roles = roleMapper.selectList(null); + map.put(ED_ROLE, roles); + + // 角色权限(只导出,不导入) + List rolePermissions = rolePermissionMapper.selectList(null); + map.put(ED_ROLE_PERMISSION, rolePermissions); + + // 标签(只导出,不导入) + List edTagLibraries = edTagLibraryMapper.selectList(null); + map.put(ED_TAG_LIBRARY, edTagLibraries); + + // 标签文件关系 + List fileTagRelations = fileTagRelationMapper.selectList(Wrappers.lambdaQuery(FileTagRelation.class).in(FileTagRelation::getFileId, accessibleIds)); + map.put(ED_TAG_RELATIONS, fileTagRelations); + + // 用户(只导出当前用户) + User user = userMapper.selectById(UserThreadLocal.getUserId()); + map.put(ED_USERS, user); + + // 用户角色 + List userRoles = userRoleMapper.selectList(null); + map.put(ED_USER_ROLE, userRoles); + } + /** * 导出 * 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 1dc6ca0..4c5bb0a 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 @@ -17,4 +17,28 @@ public interface ElectromagneticConstants { String FILE_SEC_PASSWD = "adknfhkj87654knd"; String DELETE_FLAG = "deleted"; + + String ED_FILE_FAVORITE = "ed_file_favorite"; + + String ED_FILE_FORMAT = "ed_file_format"; + + String ED_FILE_INFO = "ed_file_info"; + + String ED_FILE_RELATION = "ed_file_relation"; + + String ED_ROLE = "ed_role"; + + String ED_ROLE_PERMISSION = "ed_role_permission"; + + String ED_TAG_LIBRARY = "ed_tag_library"; + + String ED_USER_ROLE = "ed_user_role"; + + String ED_USERS = "ed_users"; + + String ED_TAG_RELATIONS = "file_tag_relations"; + + String PRJ_DIR = "prj_dir"; + + String PRJ_FILE = "prj_file"; }