开发了部分导出导入的功能,后期根据实际需求决定是否重新开发。

This commit is contained in:
chenxudong 2025-04-10 10:48:44 +08:00
parent 0a75c9c773
commit 5149b65961
2 changed files with 155 additions and 5 deletions

View File

@ -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<EdFileInfoMapper, EdFileI
@Resource
private FileTagRelationService fileTagRelationService;
@Resource
private EdFileFavoriteMapper edFileFavoriteMapper;
@Resource
private FileFormatMapper fileFormatMapper;
@Resource
private EdFileRelationMapper edFileRelationMapper;
@Resource
private RoleMapper roleMapper;
@Resource
private RolePermissionMapper rolePermissionMapper;
@Resource
private EdTagLibraryMapper edTagLibraryMapper;
@Resource
private FileTagRelationMapper fileTagRelationMapper;
@Resource
private UserRoleMapper userRoleMapper;
/**
* 查询文件列表
*
@ -676,6 +691,117 @@ public class EdFileInfoServiceImpl extends ServiceImpl<EdFileInfoMapper, EdFileI
.eq(EdFileInfo::getEffectFlag, false));
}
public ResponseEntity<InputStreamResource> batchExport1(String dataIdArr, HttpServletResponse response, int dataOwnCode) throws IOException {
String[] ids = dataIdArr.split(",");
if (DataOwnEnum.isSysCode(dataOwnCode) || DataOwnEnum.isRepoCode(dataOwnCode)) {
Map<String, Boolean> map = permissionService.filterExportIds(ids);
Assert.isTrue(!map.containsValue(Boolean.FALSE), "有未授权的层级目录,禁止导出");
}
Map<String, Object> exportInfoMap = new HashMap<>();
// 查询需要导出的文件信息
List<EdFileInfo> 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<String> accessibleIds = edFileInfos.stream().map(EdFileInfo::getId).toList();
List<String> 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<String> filePaths, Map<String, Object> map, Integer dataOwnCode) {
Set<String> prjIds = new HashSet<>();
for (String path : filePaths) {
String prjId = path.split(MYSQL_FILE_PATH_SPLIT)[0];
prjIds.add(prjId);
}
List<EdFileInfo> list = new ArrayList<>();
for (String prjId : prjIds) {
LambdaQueryWrapper<EdFileInfo> 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<EdFileInfo> edFileInfos = this.baseMapper.selectList(queryWrapper);
list.addAll(edFileInfos);
}
map.put(PRJ_DIR, list);
}
private void exportMysqlInfo(List<String> accessibleIds, Map<String, Object> map) {
// 收藏夹
List<EdFileFavorite> edFileFavorites = edFileFavoriteMapper.selectList(Wrappers.lambdaQuery(EdFileFavorite.class)
.in(EdFileFavorite::getFileId, accessibleIds));
map.put(ED_FILE_FAVORITE, edFileFavorites);
// 文件格式只导出不导入
List<FileFormat> fileFormats = fileFormatMapper.selectList(null);
map.put(ED_FILE_FORMAT, fileFormats);
// 文件关系
List<EdFileRelation> edFileRelations = edFileRelationMapper.selectList(Wrappers.lambdaQuery(EdFileRelation.class)
.in(EdFileRelation::getId1, accessibleIds)
.or()
.in(EdFileRelation::getId2, accessibleIds));
map.put(ED_FILE_RELATION, edFileRelations);
// 角色只导出不导入
List<Role> roles = roleMapper.selectList(null);
map.put(ED_ROLE, roles);
// 角色权限只导出不导入
List<RolePermission> rolePermissions = rolePermissionMapper.selectList(null);
map.put(ED_ROLE_PERMISSION, rolePermissions);
// 标签只导出不导入
List<EdTagLibrary> edTagLibraries = edTagLibraryMapper.selectList(null);
map.put(ED_TAG_LIBRARY, edTagLibraries);
// 标签文件关系
List<FileTagRelation> 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<UserRole> userRoles = userRoleMapper.selectList(null);
map.put(ED_USER_ROLE, userRoles);
}
/**
* 导出
*

View File

@ -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";
}