修复导入部分功能。
This commit is contained in:
parent
67fb0f2b39
commit
044c9f1b42
|
|
@ -33,4 +33,10 @@ public class BaseModel {
|
|||
*/
|
||||
@TableField(value = "updated_by", fill = FieldFill.UPDATE)
|
||||
private String updatedBy;
|
||||
|
||||
/**
|
||||
* 是否有效 0-无效 1-有效
|
||||
*/
|
||||
@TableField(value = "effect_flag")
|
||||
private Integer effectFlag;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -85,11 +85,7 @@ public class EdFileInfo extends BaseModel {
|
|||
*/
|
||||
@TableField(value = "pre_version")
|
||||
private Integer preVersion;
|
||||
/**
|
||||
* 是否有效 0-无效 1-有效
|
||||
*/
|
||||
@TableField(value = "effect_flag")
|
||||
private Integer effectFlag;
|
||||
|
||||
/**
|
||||
* 保存状态,0-上传中 1-上传成功 2-上传失败
|
||||
*/
|
||||
|
|
|
|||
|
|
@ -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.*;
|
||||
|
|
@ -89,6 +86,12 @@ public class EdFileInfoServiceImpl extends ServiceImpl<EdFileInfoMapper, EdFileI
|
|||
|
||||
@Resource
|
||||
private FileTagRelationService fileTagRelationService;
|
||||
@Resource
|
||||
private FileTagRelationMapper fileTagRelationMapper;
|
||||
@Resource
|
||||
private EdFileRelationMapper edFileRelationMapper;
|
||||
@Resource
|
||||
private EdFileFavoriteMapper edFileFavoriteMapper;
|
||||
|
||||
private static final Map<String, List<String>> FILE_DB_ID_NAME = new ConcurrentHashMap<>();
|
||||
|
||||
|
|
@ -490,8 +493,29 @@ public class EdFileInfoServiceImpl extends ServiceImpl<EdFileInfoMapper, EdFileI
|
|||
|
||||
@Transactional(rollbackFor = Exception.class, propagation = Propagation.REQUIRED)
|
||||
public void update2Database(String prjDirPath, int dataOwnCode) {
|
||||
String info = FileUtil.readString(prjDirPath + File.separator + "mysql.info", Charset.defaultCharset());
|
||||
List<EdFileInfo> importAllFiles = JSONUtil.toList(info, EdFileInfo.class);
|
||||
String info = FileUtil.readString(prjDirPath + File.separator + "mysql.json", Charset.defaultCharset());
|
||||
Map<String, Object> importInfoMap = JSONUtil.toBean(info, Map.class);
|
||||
updatePrjInfo(importInfoMap, prjDirPath, dataOwnCode);
|
||||
updateCollectionInfo(importInfoMap);
|
||||
updateFileTageInfo(importInfoMap);
|
||||
updateFileRelationInfo(importInfoMap);
|
||||
}
|
||||
|
||||
private void updateFileRelationInfo(Map<String, Object> importInfoMap) {
|
||||
|
||||
}
|
||||
|
||||
private void updateFileTageInfo(Map<String, Object> importInfoMap) {
|
||||
|
||||
}
|
||||
|
||||
private void updateCollectionInfo(Map<String, Object> importInfoMap) {
|
||||
List<EdFileFavorite> edFileFavorites = (List<EdFileFavorite>)importInfoMap.getOrDefault(ED_FILE_FAVORITE, new ArrayList<>());
|
||||
edFileFavoriteMapper.insertOrUpdate(edFileFavorites);
|
||||
}
|
||||
|
||||
private void updatePrjInfo(Map<String, Object> importInfoMap, String prjDirPath, Integer dataOwnCode) {
|
||||
List<EdFileInfo> importAllFiles = (List<EdFileInfo>)importInfoMap.getOrDefault(PRJ_INFO, new ArrayList<>());
|
||||
// 找出层级文件夹
|
||||
List<EdFileInfo> prjFolders = importAllFiles.stream().filter(e -> DataOwnEnum.isPrjCode(e.getDataOwn()))
|
||||
.toList();
|
||||
|
|
@ -546,7 +570,7 @@ public class EdFileInfoServiceImpl extends ServiceImpl<EdFileInfoMapper, EdFileI
|
|||
FILE_DB_ID_NAME.put(fileInfo.getId(), List.of(previousName, afterName));
|
||||
allObjs.addAll(importFiles);
|
||||
allObjs.add(fileInfo);
|
||||
// 线下和线上都存在
|
||||
// 线下和线上都存在
|
||||
} else {
|
||||
Map<String, EdFileInfo> dbIdMap = dbFileInfos.stream().collect(Collectors.toMap(EdFileInfo::getId, e -> e));
|
||||
Map<String, EdFileInfo> importIdMap = importFiles.stream().collect(Collectors.toMap(EdFileInfo::getId, e -> e));
|
||||
|
|
@ -600,13 +624,13 @@ public class EdFileInfoServiceImpl extends ServiceImpl<EdFileInfoMapper, EdFileI
|
|||
|
||||
saveObjs.add(importFileInfo);
|
||||
dbIdMap.remove(importFileInfo.getId());
|
||||
// 线上版本的修改时间比线下新,用线上的版本。
|
||||
// 线上版本的修改时间比线下新,用线上的版本。
|
||||
} else {
|
||||
dbFileInfo.setFileVersion(start);
|
||||
saveObjs.add(dbFileInfo);
|
||||
dbIdMap.remove(dbFileInfo.getId());
|
||||
}
|
||||
// 该文件是线下上传的。
|
||||
// 该文件是线下上传的。
|
||||
} else {
|
||||
importFileInfo.setFileVersion(start);
|
||||
saveObjs.add(importFileInfo);
|
||||
|
|
@ -673,8 +697,7 @@ public class EdFileInfoServiceImpl extends ServiceImpl<EdFileInfoMapper, EdFileI
|
|||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
private void update2FileSystem(Set<EdFileInfo> needMove2FileSystemFiles, String prjDirPath, int dataOwnCode) {
|
||||
Map<String, EdFileInfo> maps = needMove2FileSystemFiles.stream().collect(Collectors.toMap(EdFileInfo::getId, e -> e));
|
||||
List<EdFileInfo> files = needMove2FileSystemFiles.stream().filter(e -> e.getDataType().equals(EleDataTypeEnum.FILE.code)).toList();
|
||||
|
|
@ -749,7 +772,87 @@ public class EdFileInfoServiceImpl extends ServiceImpl<EdFileInfoMapper, EdFileI
|
|||
*/
|
||||
@Override
|
||||
public ResponseEntity<InputStreamResource> batchExport(String dataIdArr, HttpServletResponse response, int dataOwnCode) throws IOException {
|
||||
|
||||
String[] ids = dataIdArr.split(",");
|
||||
String userDownloadDataDir = elePropertyConfig.getDownloadDataDir(dataOwnCode) + File.separator + UserThreadLocal.getUserId();
|
||||
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<>();
|
||||
// 导出工程目录信息
|
||||
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;
|
||||
|
||||
fileSystemService.writeStringToFile(mysqlFilePath, mysqlInfo);
|
||||
FileUtil.del(exportColibFile);
|
||||
ZipUtil.zip(prjDirPath, exportZipFile);
|
||||
AES aes = SecureUtil.aes(FILE_SEC_PASSWD.getBytes());
|
||||
try (
|
||||
InputStream inputStream = Files.newInputStream(Paths.get(exportZipFile));
|
||||
OutputStream outputStream = Files.newOutputStream(Paths.get(exportColibFile));
|
||||
) {
|
||||
aes.encrypt(inputStream, outputStream, true);
|
||||
} catch (Exception e) {
|
||||
String info = "导出失败。";
|
||||
log.error(info, e);
|
||||
throw new BizException(info);
|
||||
} finally {
|
||||
fileSystemService.deleteFile(exportZipFile, prjDirPath);
|
||||
}
|
||||
File file = FileUtil.newFile(exportColibFile);
|
||||
FileSystemResource fileSystemResource = new FileSystemResource(file);
|
||||
HttpHeaders headers = new HttpHeaders();
|
||||
headers.add("Cache-Control", "no-cache, no-store, must-revalidate");
|
||||
String fileName = Base64.encode(EleCommonUtil.getNowTimeStr() + "_" + fileSystemResource.getFilename());
|
||||
headers.add("Pragma", "no-cache");
|
||||
headers.add("Expires", "0");
|
||||
response.setHeader("content-disposition", "attachment;filename=" + fileName);
|
||||
UserThreadLocal.setSuccessInfo("", "", "导出数据库成功");
|
||||
// 构建响应实体(可以返回<byte[]或Resource,返回类型取决body入参类型)
|
||||
return ResponseEntity
|
||||
.ok()
|
||||
.headers(headers)
|
||||
.contentLength(fileSystemResource.contentLength())
|
||||
.contentType(MediaType.parseMediaType("application/octet-stream"))
|
||||
.body(new InputStreamResource(fileSystemResource.getInputStream()));
|
||||
}
|
||||
|
||||
private void exportFileTagInfo(Map<String, Object> exportInfoMap) {
|
||||
List<EdFileInfo> fileInfos = (List<EdFileInfo>)exportInfoMap.getOrDefault(PRJ_INFO, new ArrayList<>());
|
||||
List<String> accessibleFileIds = fileInfos.stream().map(EdFileInfo::getId).toList();
|
||||
List<FileTagRelation> fileTagRelations = fileTagRelationMapper.selectList(Wrappers.lambdaQuery(FileTagRelation.class).in(FileTagRelation::getFileId, accessibleFileIds));
|
||||
exportInfoMap.put(ED_TAG_RELATIONS, fileTagRelations);
|
||||
}
|
||||
|
||||
private void exportFileRelationInfo(Map<String, Object> exportInfoMap) {
|
||||
List<EdFileInfo> fileInfos = (List<EdFileInfo>)exportInfoMap.getOrDefault(PRJ_INFO, new ArrayList<>());
|
||||
List<String> accessibleFileIds = fileInfos.stream().map(EdFileInfo::getId).toList();
|
||||
List<EdFileRelation> edFileRelations = edFileRelationMapper.selectList(Wrappers.lambdaQuery(EdFileRelation.class).in(EdFileRelation::getId1, accessibleFileIds)
|
||||
.or()
|
||||
.in(EdFileRelation::getId2, accessibleFileIds));
|
||||
exportInfoMap.put(ED_FILE_RELATION, edFileRelations);
|
||||
}
|
||||
|
||||
private void exportCollectionInfo(Map<String, Object> exportInfoMap) {
|
||||
List<EdFileInfo> fileInfos = (List<EdFileInfo>)exportInfoMap.getOrDefault(PRJ_INFO, new ArrayList<>());
|
||||
List<String> accessibleFileIds = fileInfos.stream().map(EdFileInfo::getId).toList();
|
||||
List<EdFileFavorite> edFileFavorites = edFileFavoriteMapper.selectList(Wrappers.lambdaQuery(EdFileFavorite.class).in(EdFileFavorite::getFileId, accessibleFileIds));
|
||||
exportInfoMap.put(ED_FILE_FAVORITE, edFileFavorites);
|
||||
}
|
||||
|
||||
private void exportPrjInfo(Map<String, Object> exportInfoMap, int dataOwnCode, String dataIdArr, String userDownloadDataDir) throws IOException {
|
||||
String[] ids = dataIdArr.split(",");
|
||||
if (DataOwnEnum.isSysCode(dataOwnCode) || DataOwnEnum.isRepoCode(dataOwnCode)) {
|
||||
Map<String, Boolean> map = permissionService.filterExportIds(ids);
|
||||
|
|
@ -788,50 +891,95 @@ public class EdFileInfoServiceImpl extends ServiceImpl<EdFileInfoMapper, EdFileI
|
|||
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.info";
|
||||
String prjDirPath = userDownloadDataDir + File.separator + prjName;
|
||||
String exportZipFile = userDownloadDataDir + File.separator + prjName + ".zip";
|
||||
String exportColibFile = userDownloadDataDir + File.separator + File.separator + prjName + EXPORT_FILE_SUFFIX;
|
||||
|
||||
fileSystemService.writeStringToFile(mysqlFilePath, mysqlInfo);
|
||||
if (FileUtil.exist(exportColibFile)) {
|
||||
FileUtil.del(exportColibFile);
|
||||
}
|
||||
|
||||
ZipUtil.zip(prjDirPath, exportZipFile);
|
||||
AES aes = SecureUtil.aes(FILE_SEC_PASSWD.getBytes());
|
||||
try (
|
||||
InputStream inputStream = Files.newInputStream(Paths.get(exportZipFile));
|
||||
OutputStream outputStream = Files.newOutputStream(Paths.get(exportColibFile));
|
||||
) {
|
||||
aes.encrypt(inputStream, outputStream, true);
|
||||
} catch (Exception e) {
|
||||
String info = "导出失败。";
|
||||
log.error(info, e);
|
||||
throw new BizException(info);
|
||||
} finally {
|
||||
fileSystemService.deleteFile(exportZipFile, prjDirPath);
|
||||
}
|
||||
File file = FileUtil.newFile(exportColibFile);
|
||||
FileSystemResource fileSystemResource = new FileSystemResource(file);
|
||||
HttpHeaders headers = new HttpHeaders();
|
||||
headers.add("Cache-Control", "no-cache, no-store, must-revalidate");
|
||||
String fileName = Base64.encode(EleCommonUtil.getNowTimeStr() + "_" + fileSystemResource.getFilename());
|
||||
headers.add("Pragma", "no-cache");
|
||||
headers.add("Expires", "0");
|
||||
response.setHeader("content-disposition", "attachment;filename=" + fileName);
|
||||
UserThreadLocal.setSuccessInfo("", "", "导出数据库成功");
|
||||
// 构建响应实体(可以返回<byte[]或Resource,返回类型取决body入参类型)
|
||||
return ResponseEntity
|
||||
.ok()
|
||||
.headers(headers)
|
||||
.contentLength(fileSystemResource.contentLength())
|
||||
.contentType(MediaType.parseMediaType("application/octet-stream"))
|
||||
.body(new InputStreamResource(fileSystemResource.getInputStream()));
|
||||
exportInfoMap.put(PRJ_INFO, resFiles);
|
||||
}
|
||||
|
||||
|
||||
// @Override
|
||||
// public ResponseEntity<InputStreamResource> batchExport1(String dataIdArr, HttpServletResponse response, int dataOwnCode) throws IOException {
|
||||
// String userDownloadDataDir = elePropertyConfig.getDownloadDataDir(dataOwnCode) + File.separator + UserThreadLocal.getUserId();
|
||||
// String[] ids = dataIdArr.split(",");
|
||||
// if (DataOwnEnum.isSysCode(dataOwnCode) || DataOwnEnum.isRepoCode(dataOwnCode)) {
|
||||
// Map<String, Boolean> map = permissionService.filterExportIds(ids);
|
||||
// Assert.isTrue(!map.containsValue(Boolean.FALSE), "有未授权的层级目录,禁止导出");
|
||||
// }
|
||||
// Map<String, EdFileInfo> maps = new HashMap<>();
|
||||
// for (String id : ids) {
|
||||
// Map<String, EdFileInfo> edFileInfos = this.baseMapper.selectList(Wrappers.lambdaQuery(EdFileInfo.class)
|
||||
// .like(EdFileInfo::getFilePath, MYSQL_FILE_PATH_SPLIT + id + MYSQL_FILE_PATH_SPLIT))
|
||||
// .stream().collect(Collectors.toMap(EdFileInfo::getId, e -> e));
|
||||
// maps.putAll(edFileInfos);
|
||||
// }
|
||||
// List<EdFileInfo> resFiles = new ArrayList<>(maps.values());
|
||||
// String prjId = resFiles.get(0).getFilePath().split(MYSQL_FILE_PATH_SPLIT)[0];
|
||||
// List<EdFileInfo> prjFolders = this.baseMapper.selectList(Wrappers.lambdaQuery(EdFileInfo.class)
|
||||
// .likeRight(EdFileInfo::getFilePath, prjId + MYSQL_FILE_PATH_SPLIT)
|
||||
// .eq(EdFileInfo::getDataType, EleDataTypeEnum.FOLDER.code)
|
||||
// .eq(EdFileInfo::getDataOwn, DataOwnEnum.getPrjCodeByFileCode(dataOwnCode))
|
||||
// .eq(EdFileInfo::getEffectFlag, EffectFlagEnum.EFFECT.code));
|
||||
// EdFileInfo prjFileInfo = this.baseMapper.selectById(prjId);
|
||||
// Map<String, EdFileInfo> prjFoldersMap = prjFolders.stream().collect(Collectors.toMap(EdFileInfo::getId, e -> e));
|
||||
// Map<String, EdFileInfo> tmps = resFiles.stream().collect(Collectors.toMap(EdFileInfo::getId, e -> e));
|
||||
// tmps.putAll(prjFoldersMap);
|
||||
// resFiles.clear();
|
||||
// resFiles.addAll(tmps.values());
|
||||
// resFiles.add(prjFileInfo);
|
||||
// String prjName = commonService.getPrjNameByDbPath(resFiles.get(0).getFilePath());
|
||||
// List<EdFileInfo> folders = resFiles.stream().filter(e -> e.getDataType().equals(EleDataTypeEnum.FOLDER.code)).toList();
|
||||
// List<EdFileInfo> files = resFiles.stream().filter(e -> e.getDataType().equals(EleDataTypeEnum.FILE.code)).toList();
|
||||
// for (EdFileInfo edFileInfo : folders) {
|
||||
// String destFolderPath = userDownloadDataDir + File.separator + prjName + File.separator + commonService.getDbPath(edFileInfo.getFilePath()); // file
|
||||
// fileSystemService.createDirectory(destFolderPath);
|
||||
// }
|
||||
// for (EdFileInfo edFileInfo : files) {
|
||||
// String filePath = commonService.getFileSysPath(edFileInfo.getFilePath(), dataOwnCode); // file
|
||||
// String destPath = userDownloadDataDir + File.separator + prjName + File.separator + commonService.getDbPath(edFileInfo.getFilePath());
|
||||
// fileSystemService.copyFile(filePath, destPath);
|
||||
// }
|
||||
// String mysqlInfo = JSONUtil.toJsonStr(resFiles);
|
||||
//
|
||||
// String mysqlFilePath = userDownloadDataDir + File.separator + prjName + File.separator + "mysql.json";
|
||||
// String prjDirPath = userDownloadDataDir + File.separator + prjName;
|
||||
// String exportZipFile = userDownloadDataDir + File.separator + prjName + ".zip";
|
||||
// String exportColibFile = userDownloadDataDir + File.separator + File.separator + prjName + EXPORT_FILE_SUFFIX;
|
||||
//
|
||||
// fileSystemService.writeStringToFile(mysqlFilePath, mysqlInfo);
|
||||
// if (FileUtil.exist(exportColibFile)) {
|
||||
// FileUtil.del(exportColibFile);
|
||||
// }
|
||||
//
|
||||
// ZipUtil.zip(prjDirPath, exportZipFile);
|
||||
// AES aes = SecureUtil.aes(FILE_SEC_PASSWD.getBytes());
|
||||
// try (
|
||||
// InputStream inputStream = Files.newInputStream(Paths.get(exportZipFile));
|
||||
// OutputStream outputStream = Files.newOutputStream(Paths.get(exportColibFile));
|
||||
// ) {
|
||||
// aes.encrypt(inputStream, outputStream, true);
|
||||
// } catch (Exception e) {
|
||||
// String info = "导出失败。";
|
||||
// log.error(info, e);
|
||||
// throw new BizException(info);
|
||||
// } finally {
|
||||
// fileSystemService.deleteFile(exportZipFile, prjDirPath);
|
||||
// }
|
||||
// File file = FileUtil.newFile(exportColibFile);
|
||||
// FileSystemResource fileSystemResource = new FileSystemResource(file);
|
||||
// HttpHeaders headers = new HttpHeaders();
|
||||
// headers.add("Cache-Control", "no-cache, no-store, must-revalidate");
|
||||
// String fileName = Base64.encode(EleCommonUtil.getNowTimeStr() + "_" + fileSystemResource.getFilename());
|
||||
// headers.add("Pragma", "no-cache");
|
||||
// headers.add("Expires", "0");
|
||||
// response.setHeader("content-disposition", "attachment;filename=" + fileName);
|
||||
// UserThreadLocal.setSuccessInfo("", "", "导出数据库成功");
|
||||
// // 构建响应实体(可以返回<byte[]或Resource,返回类型取决body入参类型)
|
||||
// return ResponseEntity
|
||||
// .ok()
|
||||
// .headers(headers)
|
||||
// .contentLength(fileSystemResource.contentLength())
|
||||
// .contentType(MediaType.parseMediaType("application/octet-stream"))
|
||||
// .body(new InputStreamResource(fileSystemResource.getInputStream()));
|
||||
// }
|
||||
|
||||
/**
|
||||
* 文件上传
|
||||
*
|
||||
|
|
|
|||
|
|
@ -17,4 +17,14 @@ 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";
|
||||
|
||||
String ED_TAG_RELATIONS = "file_tag_relations";
|
||||
|
||||
String PRJ_INFO = "prj_info";
|
||||
|
||||
String EXPORT_PRJ_NAME = "electromagnetic_export";
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in New Issue