合并冲突
This commit is contained in:
commit
a7c19b1c93
|
|
@ -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,16 +53,16 @@ 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<InputStreamResource> download(@RequestParam("id") String id) throws Exception {
|
||||
|
|
|
|||
|
|
@ -8,9 +8,9 @@ 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<InputStreamResource> download(String id) throws Exception;
|
||||
|
||||
|
|
|
|||
|
|
@ -26,18 +26,19 @@ 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<InputStreamResource> download(String id) throws Exception {
|
||||
|
|
@ -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;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -24,6 +24,11 @@ public interface EdFileInfoMapper extends BaseMapper<EdFileInfo> {
|
|||
.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();
|
||||
|
||||
|
|
|
|||
|
|
@ -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<EdFileRelation> {
|
||||
|
||||
/**
|
||||
* 创建文件关系
|
||||
|
|
|
|||
|
|
@ -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);
|
||||
|
|
|
|||
|
|
@ -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<UserAccessLog> {
|
||||
|
||||
/**
|
||||
* 分页查询操作记录(审计)
|
||||
|
|
|
|||
|
|
@ -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()
|
||||
|
|
|
|||
|
|
@ -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,18 @@ public class CommonService {
|
|||
return count == 0;
|
||||
}
|
||||
|
||||
public String getFileSysPath(String dbPath, int dataOwnCode) {
|
||||
ArrayList<String> 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);
|
||||
int dataOwnCode = fileInfo.getDataOwn();
|
||||
DataOwnEnum enumByCode = DataOwnEnum.getEnumByCode(dataOwnCode);
|
||||
String filePath;
|
||||
switch (Objects.requireNonNull(enumByCode)) {
|
||||
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 + id;
|
||||
default -> throw new BizException("参数错误");
|
||||
}
|
||||
return destPath.replace("//", "/");
|
||||
return filePath;
|
||||
}
|
||||
|
||||
public String getDbPath(String dbPath) {
|
||||
|
|
@ -243,6 +243,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 +262,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());
|
||||
|
|
@ -436,11 +429,11 @@ 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), "禁止删除目录");
|
||||
String srcFilePath = getFileSysPath(srcFileInfo.getFilePath(), dataOwnCode);
|
||||
String srcFilePath = getFileSysPath(srcFileInfo.getId());
|
||||
String uuid = IdUtil.fastSimpleUUID();
|
||||
try {
|
||||
// 这里要分两种情况,1是删除层级目录,2是删除用户创建的文件夹
|
||||
|
|
@ -486,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.<EdFileInfo>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());
|
||||
|
|
@ -514,12 +504,6 @@ public class CommonService {
|
|||
return null;
|
||||
}
|
||||
|
||||
public String getPrjNameByDbPath(String dbPath) {
|
||||
List<String> paths = StrUtil.split(dbPath, MYSQL_FILE_PATH_SPLIT);
|
||||
String prjId = paths.get(0);
|
||||
return edFileInfoMapper.selectById(prjId).getFileName();
|
||||
}
|
||||
|
||||
public Set<String> selectPrjLeafs(int dataOwnCode, List<String> accessibleIds) {
|
||||
|
||||
Set<String> res = new HashSet<>();
|
||||
|
|
@ -545,18 +529,6 @@ public class CommonService {
|
|||
return res;
|
||||
}
|
||||
|
||||
public void deletePrjSysDir(Map<String, String> map) {
|
||||
|
||||
for (Map.Entry<String, String> 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--) {
|
||||
|
|
|
|||
|
|
@ -54,17 +54,15 @@ 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.*;
|
||||
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<EdFileInfoMapper, EdFileInfo> implements EdFileInfoService {
|
||||
|
||||
private static final Map<String, List<String>> FILE_DB_ID_NAME = new ConcurrentHashMap<>();
|
||||
private final EleLog log = new EleLog(EdFileInfoServiceImpl.class);
|
||||
@Resource
|
||||
private CommonService commonService;
|
||||
|
|
@ -81,11 +79,9 @@ public class EdFileInfoServiceImpl extends ServiceImpl<EdFileInfoMapper, EdFileI
|
|||
@Resource
|
||||
private FileTagRelationService fileTagRelationService;
|
||||
@Resource
|
||||
private FileTagRelationMapper fileTagRelationMapper;
|
||||
private UserAccessLogService userAccessLogService;
|
||||
@Resource
|
||||
private EdFileRelationMapper edFileRelationMapper;
|
||||
@Resource
|
||||
private EdFileFavoriteMapper edFileFavoriteMapper;
|
||||
private EdFileRelationService edFileRelationService;
|
||||
|
||||
/**
|
||||
* 查询文件列表
|
||||
|
|
@ -95,7 +91,6 @@ public class EdFileInfoServiceImpl extends ServiceImpl<EdFileInfoMapper, EdFileI
|
|||
*/
|
||||
@Override
|
||||
public ElectromagneticResult<?> queryEdFileInfo(FileInfoQueryDTO pars, int dataOwnCode) {
|
||||
|
||||
if (DataOwnEnum.isSysCode(dataOwnCode)) {
|
||||
String parentId = pars.getParentId();
|
||||
List<String> accessibleTree = permissionService.getAccessibleTree();
|
||||
|
|
@ -252,7 +247,7 @@ public class EdFileInfoServiceImpl extends ServiceImpl<EdFileInfoMapper, EdFileI
|
|||
EdFileInfo fileInfo = this.baseMapper.selectById(id);
|
||||
String dbPath = commonService.getDbPath(fileInfo.getFilePath());
|
||||
if (fileInfo.getDataType() == EleDataTypeEnum.FOLDER.code) {
|
||||
ElectromagneticResult<?> res = commonService.deleteFolder(id, dataOwnCode);
|
||||
ElectromagneticResult<?> res = commonService.deleteFolder(id);
|
||||
UserThreadLocal.setSuccessInfo(fileInfo.getParentId(), id, "作废目录 {} 成功,路径为 {}", fileInfo.getFileName(), dbPath);
|
||||
return res;
|
||||
}
|
||||
|
|
@ -274,7 +269,7 @@ public class EdFileInfoServiceImpl extends ServiceImpl<EdFileInfoMapper, EdFileI
|
|||
public ResponseEntity<InputStreamResource> 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);
|
||||
|
|
@ -284,7 +279,7 @@ public class EdFileInfoServiceImpl extends ServiceImpl<EdFileInfoMapper, EdFileI
|
|||
headers.add("Cache-Control", "no-cache, no-store, must-revalidate");
|
||||
headers.add("Pragma", "no-cache");
|
||||
headers.add("Expires", "0");
|
||||
String newFileName = Base64.encode(fileName.substring(0, fileName.lastIndexOf(".")));
|
||||
String newFileName = Base64.encode(fileInfo.getFileName() + "." + fileInfo.getFileType());
|
||||
response.setHeader("content-disposition", "attachment;filename=" + newFileName);
|
||||
UserThreadLocal.setSuccessInfo(fileInfo.getParentId(), fileInfo.getFileId(), "下载文件 {} 成功,文件路径 {}", fileName, dbPath);
|
||||
// 构建响应实体(可以返回<byte[]或Resource,返回类型取决body入参类型)
|
||||
|
|
@ -344,7 +339,7 @@ public class EdFileInfoServiceImpl extends ServiceImpl<EdFileInfoMapper, EdFileI
|
|||
throw new BizException("文件名已经存在");
|
||||
}
|
||||
|
||||
String srcFilePath = commonService.getFileSysPath(fileInfo.getFilePath(), dataOwnCode);
|
||||
String srcFilePath = commonService.getFileSysPath(fileInfo.getId());
|
||||
String dbPath = commonService.getDbPath(fileInfo.getFilePath());
|
||||
this.baseMapper.update(new EdFileInfo(), Wrappers.lambdaUpdate(EdFileInfo.class)
|
||||
.eq(EdFileInfo::getId, updateFileInfoDTO.getId())
|
||||
|
|
@ -485,29 +480,40 @@ 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.json", Charset.defaultCharset());
|
||||
Map<String, Object> 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<String, Object> importInfoMap) {
|
||||
|
||||
private void updateUserAccessLog(String prjDirPath) {
|
||||
String path = prjDirPath + File.separator + USER_ACCESS_LOG + ".json";
|
||||
List<UserAccessLog> userAccessLogs = JSONUtil.toList(FileUtil.readString(path, Charset.defaultCharset()), UserAccessLog.class);
|
||||
userAccessLogService.saveOrUpdateBatch(userAccessLogs);
|
||||
}
|
||||
|
||||
private void updateFileTageInfo(Map<String, Object> importInfoMap) {
|
||||
|
||||
private void updateFileRelationInfo(String prjDirPath) {
|
||||
String path = prjDirPath + File.separator + ED_TAG_RELATIONS + ".json";
|
||||
List<EdFileRelation> relations = JSONUtil.toList(FileUtil.readString(path, Charset.defaultCharset()), EdFileRelation.class);
|
||||
edFileRelationService.saveOrUpdateBatch(relations);
|
||||
}
|
||||
|
||||
private void updateCollectionInfo(Map<String, Object> importInfoMap) {
|
||||
List<EdFileFavorite> edFileFavorites = (List<EdFileFavorite>) 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<FileTagRelation> relations = JSONUtil.toList(FileUtil.readString(path, Charset.defaultCharset()), FileTagRelation.class);
|
||||
fileTagRelationService.saveOrUpdateBatch(relations);
|
||||
}
|
||||
|
||||
private void updatePrjInfo(Map<String, Object> importInfoMap, String prjDirPath, Integer dataOwnCode) {
|
||||
List<EdFileInfo> importAllFiles = (List<EdFileInfo>) importInfoMap.getOrDefault(PRJ_INFO, new ArrayList<>());
|
||||
private void updateCollectionInfo(String prjDirPath) {
|
||||
String path = prjDirPath + File.separator + ED_FILE_FAVORITE + ".json";
|
||||
List<EdFileFavorite> 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<EdFileInfo> importAllFiles = JSONUtil.toList(FileUtil.readString(path, Charset.defaultCharset()), EdFileInfo.class);
|
||||
// 找出层级文件夹
|
||||
List<EdFileInfo> prjFolders = importAllFiles.stream().filter(e -> DataOwnEnum.isPrjCode(e.getDataOwn()))
|
||||
.toList();
|
||||
|
|
@ -531,10 +537,7 @@ public class EdFileInfoServiceImpl extends ServiceImpl<EdFileInfoMapper, EdFileI
|
|||
if (foldersMap.get(fileName).getId().equals(edFileInfo.getId())) { // id相同,不做处理
|
||||
log.info("id相同,不做处理");
|
||||
} else { // 文件名重复,导入的文件名需要添加“_1”
|
||||
String previousName = edFileInfo.getFileName();
|
||||
resetFolderInfo(edFileInfo);
|
||||
String afterName = edFileInfo.getFileName();
|
||||
FILE_DB_ID_NAME.put(edFileInfo.getId(), List.of(previousName, afterName));
|
||||
allObjs.add(edFileInfo);
|
||||
}
|
||||
} else { // 没有同名文件夹
|
||||
|
|
@ -556,10 +559,7 @@ public class EdFileInfoServiceImpl extends ServiceImpl<EdFileInfoMapper, EdFileI
|
|||
// 在线上没有找到,则该批文件是从线下上传的
|
||||
if (CollUtil.isEmpty(dbFileInfos)) {
|
||||
EdFileInfo fileInfo = importFiles.stream().filter(e -> 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);
|
||||
// 线下和线上都存在
|
||||
|
|
@ -664,7 +664,7 @@ public class EdFileInfoServiceImpl extends ServiceImpl<EdFileInfoMapper, EdFileI
|
|||
.eq(EdFileInfo::getDataType, EleDataTypeEnum.FILE.code)
|
||||
.eq(EdFileInfo::getEffectFlag, EffectFlagEnum.EFFECT.code));
|
||||
if (count > 0) {
|
||||
fileName = fileName + "_1";
|
||||
fileName = fileName + APPEND_NEW_FILE_NAME;
|
||||
} else {
|
||||
fileInfo.setFileName(fileName);
|
||||
return;
|
||||
|
|
@ -682,7 +682,7 @@ public class EdFileInfoServiceImpl extends ServiceImpl<EdFileInfoMapper, EdFileI
|
|||
.eq(EdFileInfo::getDataType, EleDataTypeEnum.FOLDER.code)
|
||||
.eq(EdFileInfo::getEffectFlag, EffectFlagEnum.EFFECT.code));
|
||||
if (count > 0) {
|
||||
fileName = fileName + "_1";
|
||||
fileName = fileName + APPEND_NEW_FILE_NAME;
|
||||
} else {
|
||||
fileInfo.setFileName(fileName);
|
||||
return;
|
||||
|
|
@ -691,50 +691,15 @@ 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();
|
||||
List<File> 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 = maps.get(id);
|
||||
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);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -772,22 +737,22 @@ public class EdFileInfoServiceImpl extends ServiceImpl<EdFileInfoMapper, EdFileI
|
|||
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;
|
||||
String nowTimeStr = EleCommonUtil.getNowTimeStr();
|
||||
|
||||
fileSystemService.writeStringToFile(mysqlFilePath, mysqlInfo);
|
||||
// 导出工程目录信息
|
||||
List<String> 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 +772,7 @@ public class EdFileInfoServiceImpl extends ServiceImpl<EdFileInfoMapper, EdFileI
|
|||
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());
|
||||
String fileName = Base64.encode(fileSystemResource.getFilename() + "_" + nowTimeStr);
|
||||
headers.add("Pragma", "no-cache");
|
||||
headers.add("Expires", "0");
|
||||
response.setHeader("content-disposition", "attachment;filename=" + fileName);
|
||||
|
|
@ -821,37 +786,37 @@ public class EdFileInfoServiceImpl extends ServiceImpl<EdFileInfoMapper, EdFileI
|
|||
.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 exportLogInfo(String nowTimeStr, List<String> exportFileIds, String userDownloadDataDir) {
|
||||
List<UserAccessLog> 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 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)
|
||||
.eq(EdFileRelation::getEffectFlag, EffectFlagEnum.EFFECT.code)
|
||||
.and(wrapper -> wrapper
|
||||
.in(EdFileRelation::getId1, accessibleFileIds)
|
||||
.or()
|
||||
.in(EdFileRelation::getId2, accessibleFileIds)));
|
||||
exportInfoMap.put(ED_FILE_RELATION, edFileRelations);
|
||||
private void exportFileTagInfo(String nowTimeStr, List<String> exportFileIds, String userDownloadDataDir) {
|
||||
List<FileTagRelation> 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 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)
|
||||
.eq(EdFileFavorite::getEffectFlag, EffectFlagEnum.EFFECT.code)
|
||||
.in(EdFileFavorite::getFileId, accessibleFileIds));
|
||||
exportInfoMap.put(ED_FILE_FAVORITE, edFileFavorites);
|
||||
private void exportFileRelationInfo(String nowTimeStr, List<String> exportFileIds, String userDownloadDataDir) {
|
||||
List<EdFileRelation> edFileRelations = edFileRelationService.getBaseMapper().selectList(Wrappers.lambdaQuery(EdFileRelation.class).in(EdFileRelation::getId1, exportFileIds)
|
||||
.or()
|
||||
.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 exportPrjInfo(Map<String, Object> exportInfoMap, int dataOwnCode, String dataIdArr, String userDownloadDataDir) throws IOException {
|
||||
private void exportCollectionInfo(String nowTimeStr, List<String> exportFileIds, String userDownloadDataDir) {
|
||||
List<EdFileFavorite> 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);
|
||||
}
|
||||
|
||||
private List<String> exportPrjInfo(String nowTimeStr, int dataOwnCode, String dataIdArr, String userDownloadDataDir) {
|
||||
String[] ids = dataIdArr.split(",");
|
||||
if (DataOwnEnum.isSysCode(dataOwnCode) || DataOwnEnum.isRepoCode(dataOwnCode)) {
|
||||
Map<String, Boolean> map = permissionService.filterExportIds(ids);
|
||||
|
|
@ -878,107 +843,18 @@ public class EdFileInfoServiceImpl extends ServiceImpl<EdFileInfoMapper, EdFileI
|
|||
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());
|
||||
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<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()));
|
||||
// }
|
||||
|
||||
/**
|
||||
* 文件上传
|
||||
*
|
||||
|
|
@ -1015,8 +891,8 @@ public class EdFileInfoServiceImpl extends ServiceImpl<EdFileInfoMapper, EdFileI
|
|||
long dirCount = this.baseMapper.selectCount(queryWrapper);
|
||||
Assert.isTrue(dirCount == 0, "文件 {} 上传到 {} 失败,层级结构不允许上传文件,同名同后缀的处理方式为 {}", fileName, destPath, strategyStr);
|
||||
EdFileInfo newEdFileInfo = new EdFileInfo();
|
||||
EdFileInfo finalEdFileInfo;
|
||||
newEdFileInfo.newInit();
|
||||
EdFileInfo finalEdFileInfo;
|
||||
// 首先检查是否是同名文件
|
||||
try {
|
||||
Assert.isTrue(EleCommonUtil.isFileNameValid(fileName), NAME_VALID_MSG);
|
||||
|
|
@ -1048,11 +924,10 @@ public class EdFileInfoServiceImpl extends ServiceImpl<EdFileInfoMapper, EdFileI
|
|||
.setDataStatus(PublishEnum.PUBLISHED.getCode())
|
||||
.setEffectFlag(EffectFlagEnum.EFFECT.code);
|
||||
this.saveOrUpdate(newEdFileInfo);
|
||||
String fileDestPath = commonService.getFileSysPath(newEdFileInfo.getFilePath(), dataOwnCode);
|
||||
String fileDestPath = commonService.getFileSysPath(newEdFileInfo.getId());
|
||||
FileUtil.writeFromStream(file.getInputStream(), fileDestPath);
|
||||
EleCommonUtil.encryptFile(fileDestPath, SecureUtil.aes(FILE_SEC_PASSWD.getBytes()));
|
||||
finalEdFileInfo = newEdFileInfo;
|
||||
// fileSystemService.save(FileUtil.getInputStream(fileDestPath), fileDestPath); // 这里会导致文件大小为0,考虑到当前的系统为OS文件系统,暂不处理
|
||||
}
|
||||
} catch (Exception e) {
|
||||
String info = StrFormatter.format("文件 {} 为上传到 {} 失败,原因 {},同名同后缀的处理方式为 {}", fileName, destPath, e.getMessage(), strategyStr);
|
||||
|
|
@ -1078,7 +953,7 @@ public class EdFileInfoServiceImpl extends ServiceImpl<EdFileInfoMapper, EdFileI
|
|||
destPath,
|
||||
strategyStr,
|
||||
Optional.ofNullable(finalEdFileInfo).map(EdFileInfo::getFileName).orElse(fileName) + "." + Optional.ofNullable(finalEdFileInfo).map(EdFileInfo::getFileType).orElse(suffix));
|
||||
return ElectromagneticResultUtil.success(true);
|
||||
return ElectromagneticResultUtil.success(newEdFileInfo.getId());
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
@ -1110,8 +985,7 @@ public class EdFileInfoServiceImpl extends ServiceImpl<EdFileInfoMapper, EdFileI
|
|||
|
||||
Assert.isTrue(FileRepeatEnum.contains(strategy), "解决重名文件参数错误");
|
||||
// 获取原文件mysql模型
|
||||
EdFileInfo srcFileInfo = this.baseMapper.selectById(id);
|
||||
String srcFilePath = commonService.getFileSysPath(srcFileInfo.getFilePath(), dataOwnCode);
|
||||
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)
|
||||
|
|
@ -1134,9 +1008,6 @@ public class EdFileInfoServiceImpl extends ServiceImpl<EdFileInfoMapper, EdFileI
|
|||
.setFilePath(destFolderInfo.getFilePath() + MYSQL_FILE_PATH_SPLIT + srcFileInfo.getId())
|
||||
.setFileCode(newFileCode);
|
||||
this.baseMapper.updateById(srcFileInfo);
|
||||
// 文件系统移动文件
|
||||
String destFilePath = commonService.getFileSysPath(srcFileInfo.getFilePath(), dataOwnCode);
|
||||
fileSystemService.moveFile(srcFilePath, destFilePath);
|
||||
} else {
|
||||
srcFileInfo = handMoveConflict(targetFolderId, strategy, srcFileInfo, destFolderInfo, dataOwnCode);
|
||||
}
|
||||
|
|
@ -1156,10 +1027,10 @@ public class EdFileInfoServiceImpl extends ServiceImpl<EdFileInfoMapper, EdFileI
|
|||
|
||||
if (strategy == IGNORE.code) {
|
||||
return srcFileInfo;
|
||||
} else if (strategy == FileRepeatEnum.REVERSION.code) {
|
||||
} else if (strategy == REVERSION.code) {
|
||||
// 做版本更新
|
||||
List<EdFileInfo> 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()));
|
||||
|
|
@ -1178,15 +1049,12 @@ public class EdFileInfoServiceImpl extends ServiceImpl<EdFileInfoMapper, EdFileI
|
|||
.setFileCode(fileCode)
|
||||
.setEffectFlag(EffectFlagEnum.EFFECT.code);
|
||||
this.baseMapper.insert(destSaveFileInfo);
|
||||
String srcFilePath = commonService.getFileSysPath(srcFileInfo.getFilePath(), dataOwnCode);
|
||||
String destFilePath = commonService.getFileSysPath(destSaveFileInfo.getFilePath(), dataOwnCode);
|
||||
fileSystemService.copyFile(srcFilePath, destFilePath);
|
||||
this.baseMapper.deleteById(srcFileInfo.getId());
|
||||
this.baseMapper.update(new EdFileInfo(), Wrappers.lambdaUpdate(EdFileInfo.class)
|
||||
.set(EdFileInfo::getEffectFlag, EffectFlagEnum.NOT_EFFECTIVE.code)
|
||||
.eq(EdFileInfo::getId, fileInfoTmp.getId()));
|
||||
return destSaveFileInfo;
|
||||
} else {
|
||||
} else if (strategy == NEW.code) {
|
||||
// 文件名加“_1”,版本号从100开始
|
||||
// 处理MySQL相关逻辑
|
||||
EdFileInfo newEdFileInfo = BeanUtil.copyProperties(srcFileInfo, EdFileInfo.class);
|
||||
|
|
@ -1195,17 +1063,15 @@ public class EdFileInfoServiceImpl extends ServiceImpl<EdFileInfoMapper, EdFileI
|
|||
newEdFileInfo.setParentId(targetFolderId)
|
||||
.setFileVersion(FILE_START_VERSION)
|
||||
.setDataOwn(dataOwnCode)
|
||||
.setFileName(srcFileInfo.getFileName() + "_1")
|
||||
.setFileName(srcFileInfo.getFileName() + APPEND_NEW_FILE_NAME)
|
||||
.setFileCode(commonService.createFileCode(dbPathByDbPath, srcFileInfo.getFileType(), FILE_START_VERSION, newEdFileInfo.getFileTime()))
|
||||
.setFilePath(destFolderInfo.getFilePath() + MYSQL_FILE_PATH_SPLIT + newEdFileInfo.getId());
|
||||
resetFileInfoName(newEdFileInfo);
|
||||
this.baseMapper.insert(newEdFileInfo);
|
||||
// 移动文件
|
||||
String srcFileSysPath = commonService.getFileSysPath(srcFileInfo.getFilePath(), dataOwnCode);
|
||||
String destFileSysPath = commonService.getFileSysPath(newEdFileInfo.getFilePath(), dataOwnCode);
|
||||
fileSystemService.moveFile(srcFileSysPath, destFileSysPath);
|
||||
this.baseMapper.deleteById(srcFileInfo.getId());
|
||||
return newEdFileInfo;
|
||||
} else {
|
||||
throw new BizException("参数错误");
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -1220,8 +1086,7 @@ public class EdFileInfoServiceImpl extends ServiceImpl<EdFileInfoMapper, EdFileI
|
|||
public ElectromagneticResult<?> copyFile(String id, String targetFolderId, Integer strategy, int dataOwnCode) {
|
||||
Assert.isTrue(FileRepeatEnum.contains(strategy), "解决重名文件参数错误");
|
||||
// 获取原文件mysql模型
|
||||
EdFileInfo srcFileInfo = this.baseMapper.selectById(id);
|
||||
String srcFileDbPath = srcFileInfo.getFilePath();
|
||||
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)
|
||||
|
|
@ -1246,12 +1111,11 @@ public class EdFileInfoServiceImpl extends ServiceImpl<EdFileInfoMapper, EdFileI
|
|||
.setFilePath(destFolderInfo.getFilePath() + MYSQL_FILE_PATH_SPLIT + destFileInfo.getId())
|
||||
.setFileCode(newFileCode);
|
||||
this.baseMapper.insert(destFileInfo);
|
||||
// 文件系统移动文件
|
||||
String srcFilePath = commonService.getFileSysPath(srcFileDbPath, dataOwnCode);
|
||||
String destFilePath = commonService.getFileSysPath(destFileInfo.getFilePath(), dataOwnCode);
|
||||
fileSystemService.copyFile(srcFilePath, destFilePath);
|
||||
String srcPath = commonService.getFileSysPath(srcFileInfo.getId());
|
||||
String destPath = commonService.getFileSysPath(destFileInfo.getId());
|
||||
fileSystemService.copyFile(srcPath, destPath);
|
||||
} else {
|
||||
destFileInfo = handCopyConflict(targetFolderId, strategy, srcFileInfo, destFolderInfo, dataOwnCode);
|
||||
destFileInfo = handCopyConflict(targetFolderId, strategy, srcFileInfo, destFolderInfo);
|
||||
}
|
||||
UserThreadLocal.setSuccessInfo(destFileInfo.getParentId(), destFileInfo.getFileId(), "文件 {} 复制到 {},成功,处理文件同名同后缀的方式为 {},最终文件名为 {}", destFileInfo.getFileName() + "." + destFileInfo.getFileName(),
|
||||
commonService.getDbPath(destFolderInfo.getFilePath()), FileRepeatEnum.getDesc(strategy), srcFileInfo.getFileName());
|
||||
|
|
@ -1321,7 +1185,7 @@ public class EdFileInfoServiceImpl extends ServiceImpl<EdFileInfoMapper, EdFileI
|
|||
return ElectromagneticResultUtil.success(fileInfoVO);
|
||||
}
|
||||
|
||||
private EdFileInfo handCopyConflict(String targetFolderId, Integer strategy, EdFileInfo srcFileInfo, EdFileInfo destFolderInfo, int dataOwnCode) {
|
||||
private EdFileInfo handCopyConflict(String targetFolderId, Integer strategy, EdFileInfo srcFileInfo, EdFileInfo destFolderInfo) {
|
||||
// 禁止同目录下移动和复制
|
||||
if (srcFileInfo.getParentId().equals(destFolderInfo.getId())) {
|
||||
String info = "禁止相同文件夹下复制文件";
|
||||
|
|
@ -1332,10 +1196,10 @@ public class EdFileInfoServiceImpl extends ServiceImpl<EdFileInfoMapper, EdFileI
|
|||
if (strategy == IGNORE.code) {
|
||||
return destFolderInfo;
|
||||
}
|
||||
if (strategy == FileRepeatEnum.REVERSION.code) {
|
||||
if (strategy == REVERSION.code) {
|
||||
// 做版本更新
|
||||
LambdaQueryWrapper<EdFileInfo> 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());
|
||||
|
|
@ -1357,11 +1221,11 @@ public class EdFileInfoServiceImpl extends ServiceImpl<EdFileInfoMapper, EdFileI
|
|||
.eq(EdFileInfo::getFileName, srcFileInfo.getFileName())
|
||||
.eq(EdFileInfo::getFileType, srcFileInfo.getFileType()).set(EdFileInfo::getEffectFlag, EffectFlagEnum.NOT_EFFECTIVE.code));
|
||||
this.baseMapper.insert(destSaveFileInfo);
|
||||
String srcFilePath = commonService.getFileSysPath(srcFileInfo.getFilePath(), dataOwnCode);
|
||||
String destFilePath = commonService.getFileSysPath(destSaveFileInfo.getFilePath(), dataOwnCode);
|
||||
fileSystemService.copyFile(srcFilePath, destFilePath);
|
||||
String srcPath = commonService.getFileSysPath(srcFileInfo.getId());
|
||||
String destPath = commonService.getFileSysPath(destSaveFileInfo.getId());
|
||||
fileSystemService.copyFile(srcPath, destPath);
|
||||
return destSaveFileInfo;
|
||||
} else {
|
||||
} else if (strategy == FileRepeatEnum.NEW.code) {
|
||||
// 文件名加“_1”,版本号从100开始
|
||||
// 处理MySQL相关逻辑
|
||||
EdFileInfo newEdFileInfo = BeanUtil.copyProperties(srcFileInfo, EdFileInfo.class);
|
||||
|
|
@ -1369,16 +1233,17 @@ public class EdFileInfoServiceImpl extends ServiceImpl<EdFileInfoMapper, EdFileI
|
|||
String dbPathByDbPath = commonService.getCodePathByDbPath(destFolderInfo.getFilePath());
|
||||
newEdFileInfo.setParentId(targetFolderId)
|
||||
.setFileVersion(FILE_START_VERSION)
|
||||
.setFileName(srcFileInfo.getFileName() + "_1")
|
||||
.setFileName(srcFileInfo.getFileName() + APPEND_NEW_FILE_NAME)
|
||||
.setFileCode(commonService.createFileCode(dbPathByDbPath, srcFileInfo.getFileType(), FILE_START_VERSION, newEdFileInfo.getFileTime()))
|
||||
.setFilePath(destFolderInfo.getFilePath() + MYSQL_FILE_PATH_SPLIT + newEdFileInfo.getId());
|
||||
resetFileInfoName(newEdFileInfo);
|
||||
this.baseMapper.insert(newEdFileInfo);
|
||||
// 移动文件
|
||||
String srcFileSysPath = commonService.getFileSysPath(srcFileInfo.getFilePath(), dataOwnCode);
|
||||
String destFileSysPath = commonService.getFileSysPath(newEdFileInfo.getFilePath(), dataOwnCode);
|
||||
fileSystemService.copyFile(srcFileSysPath, destFileSysPath);
|
||||
String srcPath = commonService.getFileSysPath(srcFileInfo.getId());
|
||||
String destPath = commonService.getFileSysPath(newEdFileInfo.getId());
|
||||
fileSystemService.copyFile(srcPath, destPath);
|
||||
return newEdFileInfo;
|
||||
} else {
|
||||
throw new BizException("参数错误");
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -1387,7 +1252,20 @@ public class EdFileInfoServiceImpl extends ServiceImpl<EdFileInfoMapper, EdFileI
|
|||
String fileName = file.getOriginalFilename();
|
||||
String mainName = FileUtil.mainName(fileName);
|
||||
String suffix = FileUtil.getSuffix(fileName);
|
||||
if (strategy == FileRepeatEnum.REVERSION.code) {
|
||||
EdFileInfo newEdFileInfo = new EdFileInfo();
|
||||
newEdFileInfo.newInit();
|
||||
String timeStr = EleCommonUtil.getNowTimeStr();
|
||||
newEdFileInfo.setFileName(mainName)
|
||||
.setFileType(suffix)
|
||||
.setFileContent(EleCommonUtil.parse(file.getInputStream(), suffix))
|
||||
.setFileTime(timeStr)
|
||||
.setFileSize(file.getSize())
|
||||
.setDataType(EleDataTypeEnum.FILE.code)
|
||||
.setDataStatus(PublishEnum.PUBLISHED.getCode())
|
||||
.setSaveStatus(EleDataSaveStatusEnum.SUCCESS.code)
|
||||
.setDataOwn(dataOwnCode)
|
||||
.setEffectFlag(EffectFlagEnum.EFFECT.code);
|
||||
if (strategy == REVERSION.code) {
|
||||
// 版本更新
|
||||
// step1:找到同名文件的MySQL对象
|
||||
List<EdFileInfo> parentFileInfos = this.baseMapper.selectList(Wrappers.lambdaQuery(EdFileInfo.class)
|
||||
|
|
@ -1401,69 +1279,43 @@ public class EdFileInfoServiceImpl extends ServiceImpl<EdFileInfoMapper, EdFileI
|
|||
// 找到当前展示的版本
|
||||
EdFileInfo effectFileInfo = parentFileInfos.stream().filter(e -> 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.getFilePath(), dataOwnCode);
|
||||
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.getFilePath(), dataOwnCode);
|
||||
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) {
|
||||
|
|
@ -1546,7 +1398,7 @@ public class EdFileInfoServiceImpl extends ServiceImpl<EdFileInfoMapper, EdFileI
|
|||
EdFileInfo fileInfo = this.baseMapper.selectById(id);
|
||||
Assert.isTrue(Objects.nonNull(fileInfo), "文件不存在");
|
||||
String fileDbPath = commonService.getDbPath(fileInfo.getFilePath());
|
||||
String fileSysPath = commonService.getFileSysPath(fileInfo.getFilePath(), dataOwnCode);
|
||||
String fileSysPath = commonService.getFileSysPath(fileInfo.getId());
|
||||
String fileSaveTmpPath = elePropertyConfig.getEleTmpPath() + File.separator + IdUtil.fastSimpleUUID() + "." + fileInfo.getFileType();
|
||||
FileUtil.copy(fileSysPath, fileSaveTmpPath, true);
|
||||
EleCommonUtil.decryptFile(fileSaveTmpPath, SecureUtil.aes(FILE_SEC_PASSWD.getBytes()));
|
||||
|
|
@ -1622,37 +1474,24 @@ public class EdFileInfoServiceImpl extends ServiceImpl<EdFileInfoMapper, EdFileI
|
|||
* @return
|
||||
*/
|
||||
@Override
|
||||
@Transactional
|
||||
public boolean addFavorite(String userId, String fileId) {
|
||||
|
||||
EdFileInfo fileInfo = this.baseMapper.selectById(fileId);
|
||||
// 文件是否有效
|
||||
Assert.isTrue(fileInfo != null && fileInfo.getEffectFlag().equals(EffectFlagEnum.EFFECT.code), StrFormatter.format("文件已删除,无法收藏!"));
|
||||
|
||||
EdFileFavorite favorite = fileFavoriteService.getOne(
|
||||
Wrappers.<EdFileFavorite>lambdaQuery()
|
||||
.eq(EdFileFavorite::getUserId, userId)
|
||||
.eq(EdFileFavorite::getFileId, fileId)
|
||||
);
|
||||
// 检查是否已存在有效收藏
|
||||
if (favorite != null && EffectFlagEnum.EFFECT.code.equals(favorite.getEffectFlag())) {
|
||||
// 查询是否已存在
|
||||
LambdaQueryWrapper<EdFileFavorite> queryWrapper = new LambdaQueryWrapper<>();
|
||||
queryWrapper.eq(EdFileFavorite::getUserId, userId)
|
||||
.eq(EdFileFavorite::getFileId, fileId);
|
||||
if (fileFavoriteService.getOne(queryWrapper) != null) {
|
||||
throw new BizException("文件已收藏,无法重复收藏!");
|
||||
}
|
||||
|
||||
boolean isSaved;
|
||||
if (favorite != null) {
|
||||
favorite.setEffectFlag(EffectFlagEnum.EFFECT.code);
|
||||
isSaved = fileFavoriteService.updateById(favorite);
|
||||
} else {
|
||||
EdFileFavorite fileFavorite = new EdFileFavorite();
|
||||
fileFavorite.newInit();
|
||||
fileFavorite.setUserId(userId);
|
||||
fileFavorite.setFileId(fileId);
|
||||
isSaved = fileFavoriteService.save(fileFavorite);
|
||||
}
|
||||
|
||||
// 插入收藏记录
|
||||
EdFileFavorite favorite = new EdFileFavorite();
|
||||
favorite.setUserId(userId);
|
||||
favorite.setFileId(fileId);
|
||||
boolean isSaved = fileFavoriteService.save(favorite);
|
||||
if (isSaved) {
|
||||
UserThreadLocal.setSuccessInfo("", fileId, StrFormatter.format("收藏了文件"));
|
||||
EdFileInfo fileInfo = this.baseMapper.selectById(fileId);
|
||||
UserThreadLocal.setSuccessInfo(Optional.ofNullable(fileInfo).map(EdFileInfo::getParentId).orElse(""), fileId, StrFormatter.format("收藏了文件"));
|
||||
}
|
||||
return isSaved;
|
||||
}
|
||||
|
|
@ -1668,8 +1507,7 @@ public class EdFileInfoServiceImpl extends ServiceImpl<EdFileInfoMapper, EdFileI
|
|||
public boolean isFavorite(String userId, String fileId) {
|
||||
LambdaQueryWrapper<EdFileFavorite> queryWrapper = new LambdaQueryWrapper<>();
|
||||
queryWrapper.eq(EdFileFavorite::getUserId, userId)
|
||||
.eq(EdFileFavorite::getFileId, fileId)
|
||||
.eq(EdFileFavorite::getEffectFlag, EffectFlagEnum.EFFECT.code);
|
||||
.eq(EdFileFavorite::getFileId, fileId);
|
||||
return fileFavoriteService.getOne(queryWrapper) != null;
|
||||
}
|
||||
|
||||
|
|
@ -1682,7 +1520,10 @@ public class EdFileInfoServiceImpl extends ServiceImpl<EdFileInfoMapper, EdFileI
|
|||
*/
|
||||
@Override
|
||||
public boolean removeFavorite(String userId, String fileId) {
|
||||
boolean isRemoved = fileFavoriteService.logicRemove(userId, fileId);
|
||||
LambdaQueryWrapper<EdFileFavorite> queryWrapper = new LambdaQueryWrapper<>();
|
||||
queryWrapper.eq(EdFileFavorite::getUserId, userId)
|
||||
.eq(EdFileFavorite::getFileId, fileId);
|
||||
boolean isRemoved = fileFavoriteService.remove(queryWrapper);
|
||||
if (isRemoved) {
|
||||
UserThreadLocal.setSuccessInfo("", fileId, StrFormatter.format("取消了收藏"));
|
||||
}
|
||||
|
|
@ -1711,9 +1552,7 @@ public class EdFileInfoServiceImpl extends ServiceImpl<EdFileInfoMapper, EdFileI
|
|||
fileIds = this.baseMapper.selectList(queryWrapper).stream().map(EdFileInfo::getFileId).toList();
|
||||
} else {
|
||||
LambdaQueryWrapper<EdFileFavorite> queryWrapper = new LambdaQueryWrapper<>();
|
||||
queryWrapper.select(EdFileFavorite::getFileId)
|
||||
.eq(EdFileFavorite::getUserId, userId)
|
||||
.eq(EdFileFavorite::getEffectFlag, EffectFlagEnum.EFFECT.code);
|
||||
queryWrapper.select(EdFileFavorite::getFileId).eq(EdFileFavorite::getUserId, userId);
|
||||
fileIds = fileFavoriteService.listObjs(queryWrapper, Object::toString);
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -1,10 +1,7 @@
|
|||
package com.electromagnetic.industry.software.manage.service.serviceimpl;
|
||||
|
||||
import cn.hutool.core.io.FileUtil;
|
||||
import cn.hutool.core.lang.Assert;
|
||||
import cn.hutool.core.text.StrFormatter;
|
||||
import cn.hutool.core.util.StrUtil;
|
||||
import cn.hutool.crypto.SecureUtil;
|
||||
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
||||
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
|
||||
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
||||
|
|
@ -34,7 +31,6 @@ import static com.electromagnetic.industry.software.common.cons.ElectromagneticC
|
|||
@Service
|
||||
public class EdFileRelationServiceImpl extends ServiceImpl<EdFileRelationMapper, EdFileRelation> implements EdFileRelationService {
|
||||
|
||||
private final EleLog log = new EleLog(EdFileInfoServiceImpl.class);
|
||||
@Resource
|
||||
EdFileInfoMapper edFileInfoMapper;
|
||||
@Resource
|
||||
|
|
@ -217,98 +213,19 @@ public class EdFileRelationServiceImpl extends ServiceImpl<EdFileRelationMapper,
|
|||
@Override
|
||||
@Transactional(rollbackFor = Exception.class)
|
||||
public ElectromagneticResult<?> uploadFileAndRelation(String parentId, String id, MultipartFile file, String desc, int dataOwnCode) {
|
||||
Assert.isTrue(EleCommonUtil.isFileNameValid(file.getOriginalFilename()), NAME_VALID_MSG);
|
||||
String fileName = file.getOriginalFilename();
|
||||
String mainName = FileUtil.mainName(fileName);
|
||||
String suffix = FileUtil.getSuffix(fileName);
|
||||
Assert.isTrue(StrUtil.isNotEmpty(suffix), "文件类型不能为空");
|
||||
String destPath = commonService.getDbPathById(parentId);
|
||||
Assert.isTrue(!file.isEmpty(), StrFormatter.format("文件 {} 为空,文件上传到 {} 失败", fileName, destPath));
|
||||
Assert.isTrue(EleCommonUtil.isFileNameValid(file.getOriginalFilename()), StrFormatter.format("文件 {} {},上传到 {} 失败", fileName, NAME_VALID_MSG, destPath));
|
||||
// 查找下一层,看是否存在顶级定义相关文件,如果存在,则该层属于管理员层级定义的,不允许上传文件
|
||||
LambdaQueryWrapper<EdFileInfo> queryWrapper = Wrappers.lambdaQuery(EdFileInfo.class)
|
||||
.eq(EdFileInfo::getParentId, parentId)
|
||||
.eq(EdFileInfo::getEffectFlag, EffectFlagEnum.EFFECT.code)
|
||||
.eq(EdFileInfo::getDataType, EleDataTypeEnum.FOLDER.code);
|
||||
DataOwnEnum obj = DataOwnEnum.getEnumByCode(dataOwnCode);
|
||||
switch (Objects.requireNonNull(obj)) {
|
||||
case USER_FILE, USER_PRJ -> queryWrapper.eq(EdFileInfo::getDataOwn, DataOwnEnum.USER_PRJ.code);
|
||||
case SYS_FILE, SYS_PRJ -> queryWrapper.eq(EdFileInfo::getDataOwn, DataOwnEnum.SYS_PRJ.code);
|
||||
case REPO_PRJ, REPO_FILE -> queryWrapper.eq(EdFileInfo::getDataOwn, DataOwnEnum.REPO_PRJ.code);
|
||||
default -> ElectromagneticResultUtil.fail("-1", "参数错误");
|
||||
}
|
||||
|
||||
long dirCount = edFileInfoMapper.selectCount(queryWrapper);
|
||||
Assert.isTrue(dirCount == 0, "文件 {} 上传到 {} 失败,层级结构不允许上传文件", fileName, destPath);
|
||||
EdFileInfo newEdFileInfo = new EdFileInfo();
|
||||
EdFileInfo finalEdFileInfo;
|
||||
newEdFileInfo.newInit();
|
||||
|
||||
try {
|
||||
Assert.isTrue(EleCommonUtil.isFileNameValid(fileName), NAME_VALID_MSG);
|
||||
Long count = edFileInfoService.count(Wrappers.lambdaQuery(EdFileInfo.class)
|
||||
.eq(EdFileInfo::getParentId, parentId)
|
||||
.eq(EdFileInfo::getFileName, mainName)
|
||||
.eq(EdFileInfo::getEffectFlag, EffectFlagEnum.EFFECT.code)
|
||||
.eq(EdFileInfo::getFileType, suffix));
|
||||
|
||||
if (count > 0) {
|
||||
finalEdFileInfo = edFileInfoService.handUploadRepeatFile(parentId, file, 3, dataOwnCode);
|
||||
} else {
|
||||
EdFileInfo parentFolderInfo = edFileInfoMapper.selectOne(Wrappers.lambdaQuery(EdFileInfo.class)
|
||||
.eq(EdFileInfo::getId, parentId)
|
||||
.eq(EdFileInfo::getEffectFlag, EffectFlagEnum.EFFECT.code));
|
||||
|
||||
String codePathByDbPath = commonService.getCodePathByDbPath(parentFolderInfo.getFilePath());
|
||||
String fileCode = commonService.createFileCode(codePathByDbPath, suffix, FILE_START_VERSION, newEdFileInfo.getFileTime());
|
||||
newEdFileInfo.setParentId(parentId)
|
||||
.setFileCode(fileCode)
|
||||
.setSaveStatus(EleDataSaveStatusEnum.SUCCESS.code)
|
||||
.setDataOwn(dataOwnCode)
|
||||
.setFileName(mainName)
|
||||
.setFileContent(EleCommonUtil.parse(file.getInputStream(), suffix))
|
||||
.setFileType(suffix)
|
||||
.setFileVersion(FILE_START_VERSION)
|
||||
.setFileSize(file.getSize())
|
||||
.setFilePath(parentFolderInfo.getFilePath() + MYSQL_FILE_PATH_SPLIT + newEdFileInfo.getId())
|
||||
.setDataType(EleDataTypeEnum.FILE.code)
|
||||
.setDataStatus(PublishEnum.PUBLISHED.getCode())
|
||||
.setEffectFlag(EffectFlagEnum.EFFECT.code);
|
||||
edFileInfoService.saveOrUpdate(newEdFileInfo);
|
||||
String fileDestPath = commonService.getFileSysPath(newEdFileInfo.getFilePath(), dataOwnCode);
|
||||
FileUtil.writeFromStream(file.getInputStream(), fileDestPath);
|
||||
EleCommonUtil.encryptFile(fileDestPath, SecureUtil.aes(FILE_SEC_PASSWD.getBytes()));
|
||||
finalEdFileInfo = newEdFileInfo;
|
||||
// 创建文件关系
|
||||
EdFileRelation relation = new EdFileRelation();
|
||||
relation.setId1(id);
|
||||
relation.setId2(newEdFileInfo.getId());
|
||||
relation.setRelationship(desc);
|
||||
createRelation(relation);
|
||||
}
|
||||
} catch (Exception e) {
|
||||
newEdFileInfo.setParentId(parentId)
|
||||
.setFileName(mainName)
|
||||
.setFileType(suffix)
|
||||
.setFileSize(file.getSize())
|
||||
.setDataType(EleDataTypeEnum.FILE.code)
|
||||
.setDataStatus(PublishEnum.PUBLISHED.getCode())
|
||||
.setSaveStatus(EleDataSaveStatusEnum.FAIL.code)
|
||||
.setDataOwn(dataOwnCode)
|
||||
.setEffectFlag(EffectFlagEnum.NOT_EFFECTIVE.code);
|
||||
edFileInfoService.saveOrUpdate(newEdFileInfo);
|
||||
String info = "上传文件失败";
|
||||
log.error(info, e);
|
||||
throw new BizException(info);
|
||||
}
|
||||
String otherFileName = edFileInfoMapper.selectById(id).getFileName();
|
||||
UserThreadLocal.setSuccessInfo(Optional.ofNullable(finalEdFileInfo).map(EdFileInfo::getParentId).orElse(""),
|
||||
Optional.ofNullable(finalEdFileInfo).map(EdFileInfo::getFileId).orElse(""),
|
||||
"文件 {} 为上传到 {} 成功,存入的文件名为 {},成功与文件 {} 建立了关系",
|
||||
fileName,
|
||||
destPath,
|
||||
Optional.ofNullable(finalEdFileInfo).map(EdFileInfo::getFileName).orElse(fileName) + "." + Optional.ofNullable(finalEdFileInfo).map(EdFileInfo::getFileType).orElse(suffix),
|
||||
otherFileName);
|
||||
// 上传文件
|
||||
ElectromagneticResult<?> uploadResult = edFileInfoService.upload(parentId, file, FileRepeatEnum.NEW.code, dataOwnCode);
|
||||
Assert.notNull(uploadResult.getData(), "上传失败");
|
||||
String relatedFileId = (String) uploadResult.getData();
|
||||
// 创建文件关系
|
||||
EdFileRelation relation = new EdFileRelation();
|
||||
relation.newInit();
|
||||
relation.setId1(id);
|
||||
relation.setId2(relatedFileId);
|
||||
relation.setRelationship(desc);
|
||||
createRelation(relation);
|
||||
UserThreadLocal.setSuccessInfo("", id, StrFormatter.format("建立了文件 {} 与文件 {} 的关系", id, relatedFileId));
|
||||
return ElectromagneticResultUtil.success(true);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -4,7 +4,6 @@ import cn.hutool.core.collection.CollUtil;
|
|||
import cn.hutool.core.collection.CollectionUtil;
|
||||
import cn.hutool.core.lang.Assert;
|
||||
import cn.hutool.core.text.StrFormatter;
|
||||
import cn.hutool.core.util.IdUtil;
|
||||
import cn.hutool.core.util.StrUtil;
|
||||
import cn.hutool.json.JSONUtil;
|
||||
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
||||
|
|
@ -85,24 +84,23 @@ public class EdPrjServiceImpl extends ServiceImpl<EdFileInfoMapper, EdFileInfo>
|
|||
try {
|
||||
// 保存信息到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)
|
||||
.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)
|
||||
.eq(EdFileInfo::getDataOwn, DataOwnEnum.SYS_PRJ.code))
|
||||
.intValue();
|
||||
} else {
|
||||
prjCount = this.baseMapper.selectCount(Wrappers.lambdaQuery(EdFileInfo.class).eq(EdFileInfo::getParentId, PRJ_PARENT_ID)
|
||||
.eq(EdFileInfo::getDataOwn, DataOwnEnum.REPO_PRJ.code))
|
||||
.intValue();
|
||||
Long prjCount;
|
||||
DataOwnEnum enumByCode = DataOwnEnum.getEnumByCode(dataOwnCode);
|
||||
LambdaQueryWrapper<EdFileInfo> qw = Wrappers.lambdaQuery(EdFileInfo.class).eq(EdFileInfo::getParentId, PRJ_PARENT_ID);
|
||||
switch (Objects.requireNonNull(enumByCode)) {
|
||||
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);
|
||||
String newPrjId = String.valueOf(id + 1);
|
||||
|
||||
EdFileInfo fileInfo = new EdFileInfo();
|
||||
fileInfo.newInit();
|
||||
String nowTimeStr = EleCommonUtil.getNowTimeStr();
|
||||
fileInfo.setId(newPrjId)
|
||||
.setFileType("文件夹")
|
||||
|
|
@ -115,19 +113,11 @@ public class EdPrjServiceImpl extends ServiceImpl<EdFileInfoMapper, EdFileInfo>
|
|||
.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);
|
||||
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 +154,19 @@ public class EdPrjServiceImpl extends ServiceImpl<EdFileInfoMapper, EdFileInfo>
|
|||
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<EdFileInfoMapper, EdFileInfo>
|
|||
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<EdFileInfoMapper, EdFileInfo>
|
|||
.eq(EdFileInfo::getDataStatus, EleDataStatusEnum.WAIT_DELETED.code)
|
||||
.likeRight(EdFileInfo::getFilePath, prjId);
|
||||
List<EdFileInfo> edFileInfos = this.baseMapper.selectList(queryWrapper);
|
||||
Map<String, String> map = new HashMap<>();
|
||||
Map<String, String> 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<String, String> 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<EdFileInfoMapper, EdFileInfo>
|
|||
.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) {
|
||||
|
|
@ -389,7 +358,7 @@ public class EdPrjServiceImpl extends ServiceImpl<EdFileInfoMapper, EdFileInfo>
|
|||
@Override
|
||||
@Transactional(rollbackFor = Exception.class)
|
||||
public ElectromagneticResult<?> deleteFolder(String fileId, int dataOwnCode) {
|
||||
return commonService.deleteFolder(fileId, dataOwnCode);
|
||||
return commonService.deleteFolder(fileId);
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
@ -408,7 +377,6 @@ public class EdPrjServiceImpl extends ServiceImpl<EdFileInfoMapper, EdFileInfo>
|
|||
// 查找source的全部目录
|
||||
List<EdFileInfo> sourceEdFileInfos = commonService.selectAllPrjFolder(sourceId, dataOwnCode);
|
||||
List<EdFileInfo> targetEdFileInfos = commonService.selectAllPrjFolder(targetId, dataOwnCode);
|
||||
//
|
||||
Set<String> sourceNames = sourceEdFileInfos.stream().filter(e -> StrUtil.count(e.getFilePath(), MYSQL_FILE_PATH_SPLIT) == 1).map(EdFileInfo::getFileName).collect(Collectors.toSet());
|
||||
Set<String> 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<EdFileInfoMapper, EdFileInfo>
|
|||
|
||||
Map<String, String> idMaps = new HashMap<>();
|
||||
idMaps.put(sourceId, targetId);
|
||||
List<String> sysFilePaths = new ArrayList<>();
|
||||
for (int i = 1; i <= elePropertyConfig.getPrjFolderMaxLength(); ++i) {
|
||||
int layerIndex = i;
|
||||
List<EdFileInfo> currentSourceLayerDirs = sourceEdFileInfos.stream().filter(e -> StrUtil.count(e.getFilePath(), MYSQL_FILE_PATH_SPLIT) == layerIndex).toList();
|
||||
|
|
@ -436,6 +403,7 @@ public class EdPrjServiceImpl extends ServiceImpl<EdFileInfoMapper, EdFileInfo>
|
|||
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<EdFileInfoMapper, EdFileInfo>
|
|||
this.save(targetFile);
|
||||
targetEdFileInfos.add(targetFile);
|
||||
idMaps.put(edFileInfo.getFileId(), newFolderId);
|
||||
String targetSysFilePath = commonService.getFileSysPath(targetFile.getFilePath(), dataOwnCode);
|
||||
sysFilePaths.add(targetSysFilePath);
|
||||
}
|
||||
} else {
|
||||
List<EdFileInfo> edFileInfos = this.baseMapper.selectList(Wrappers.lambdaQuery(EdFileInfo.class)
|
||||
|
|
@ -472,6 +438,7 @@ public class EdPrjServiceImpl extends ServiceImpl<EdFileInfoMapper, EdFileInfo>
|
|||
|
||||
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<EdFileInfoMapper, EdFileInfo>
|
|||
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<EdFileInfoMapper, EdFileInfo>
|
|||
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) {
|
||||
|
|
|
|||
|
|
@ -135,8 +135,8 @@ 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());
|
||||
backupHandler.backupFiles(fileSysPath, edFileInfo.getParentId());
|
||||
String fileSysPath = commonService.getFileSysPath(edFileInfo.getId());
|
||||
backupHandler.backupFiles(fileSysPath);
|
||||
String fileDbPath = commonService.getDbPath(edFileInfo.getFilePath());
|
||||
// 移动到tmp目录,七天后删除
|
||||
fileSystemService.moveFile(fileSysPath, elePropertyConfig.getEleTmpPath() + File.separator + new File(fileSysPath).getName());
|
||||
|
|
@ -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("删除文件成功");
|
||||
|
|
|
|||
|
|
@ -11,16 +11,15 @@ 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);
|
||||
}
|
||||
|
||||
/**
|
||||
* @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);
|
||||
|
|
@ -51,11 +50,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());
|
||||
|
|
|
|||
|
|
@ -31,7 +31,6 @@ import java.util.stream.Collectors;
|
|||
@Service
|
||||
public class UserAccessLogServiceImpl extends ServiceImpl<UserAccessLogMapper, UserAccessLog> implements UserAccessLogService {
|
||||
|
||||
|
||||
@Resource
|
||||
private UserMapper userMapper;
|
||||
|
||||
|
|
|
|||
|
|
@ -21,10 +21,9 @@ public class BackupHandler {
|
|||
@Resource
|
||||
private ElePropertyConfig elePropertyConfig;
|
||||
|
||||
public BackupFileResLog backupFiles(String filePath, String id) {
|
||||
public BackupFileResLog backupFiles(String filePath) {
|
||||
Map<String, Object> 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,15 +42,15 @@ public class BackupHandler {
|
|||
return JSONUtil.toBean(data, BackupFileResLog.class);
|
||||
}
|
||||
|
||||
public BackupFileResLog deleteFile(String id) {
|
||||
Map<String, Object> 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<String, Object> 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);
|
||||
|
|
|
|||
|
|
@ -66,9 +66,9 @@ public class BackupTask {
|
|||
EdFileInfo fileInfo = this.edFileInfoMapper.selectOne(Wrappers.<EdFileInfo>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);
|
||||
BackupFileResLog resLog = backupHandler.backupFiles(sysFilePath);
|
||||
long endTime = System.currentTimeMillis();
|
||||
fileBackupLogMapper.update(null, Wrappers.<FileBackupLog>lambdaUpdate()
|
||||
.eq(FileBackupLog::getFileId, id)
|
||||
|
|
@ -97,10 +97,10 @@ 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());
|
||||
BackupFileResLog resLog = backupHandler.backupFiles(fileSysPath);
|
||||
long endTime = System.currentTimeMillis();
|
||||
FileBackupLog backupLog = new FileBackupLog()
|
||||
.setId(IdWorker.getSnowFlakeIdString())
|
||||
|
|
|
|||
|
|
@ -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";
|
||||
|
|
@ -27,4 +25,8 @@ public interface ElectromagneticConstants {
|
|||
String PRJ_INFO = "prj_info";
|
||||
|
||||
String EXPORT_PRJ_NAME = "electromagnetic_export";
|
||||
|
||||
String USER_ACCESS_LOG = "user_access_log";
|
||||
|
||||
String APPEND_NEW_FILE_NAME = "_1";
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in New Issue