文件备份的适配,屏蔽文件删除相关的功能。
This commit is contained in:
parent
2c7b0eea0a
commit
cb4cfe1618
|
|
@ -31,10 +31,10 @@ public class FileController {
|
||||||
private BackupPro backupPro;
|
private BackupPro backupPro;
|
||||||
|
|
||||||
@RequestMapping("/upload")
|
@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();
|
BackupFileResLog backupFileResLog = BackupFileResLog.builder().backupStartTime(new Date()).fileName(file.getOriginalFilename()).backupSuccess(true).build();
|
||||||
try {
|
try {
|
||||||
fileService.upload(file, id);
|
fileService.upload(file);
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
String details = ExceptionUtil.stacktraceToString(e);
|
String details = ExceptionUtil.stacktraceToString(e);
|
||||||
backupFileResLog.setBackupSuccess(false);
|
backupFileResLog.setBackupSuccess(false);
|
||||||
|
|
@ -53,20 +53,20 @@ public class FileController {
|
||||||
return ElectromagneticResultUtil.success(JSONUtil.toJsonStr(backupFileResLog, jsonConfig));
|
return ElectromagneticResultUtil.success(JSONUtil.toJsonStr(backupFileResLog, jsonConfig));
|
||||||
}
|
}
|
||||||
|
|
||||||
@RequestMapping("/remove")
|
// @RequestMapping("/remove")
|
||||||
public ElectromagneticResult<?> remove(@RequestParam("id") String id) {
|
// public ElectromagneticResult<?> remove(@RequestParam("id") String id) {
|
||||||
try {
|
// try {
|
||||||
fileService.remove(id);
|
// fileService.remove(id);
|
||||||
} catch (Exception e) {
|
// } catch (Exception e) {
|
||||||
log.error("删除文件失败, id-->{},原因-->{}", id, e.getMessage(), e);
|
// log.error("删除文件失败, id-->{},原因-->{}", id, e.getMessage(), e);
|
||||||
ElectromagneticResultUtil.fail("-1", e.getMessage());
|
// ElectromagneticResultUtil.fail("-1", e.getMessage());
|
||||||
}
|
// }
|
||||||
return ElectromagneticResultUtil.success(true);
|
// return ElectromagneticResultUtil.success(true);
|
||||||
}
|
// }
|
||||||
|
|
||||||
@RequestMapping("/download")
|
@RequestMapping("/download")
|
||||||
public ResponseEntity<InputStreamResource> download(@RequestParam("id") String id) throws Exception {
|
public ResponseEntity<InputStreamResource> download(@RequestParam("id") String id, @RequestParam("uuid") String uuid) throws Exception {
|
||||||
return fileService.download(id);
|
return fileService.download(id, uuid);
|
||||||
}
|
}
|
||||||
|
|
||||||
@RequestMapping("/backupSql")
|
@RequestMapping("/backupSql")
|
||||||
|
|
|
||||||
|
|
@ -8,11 +8,11 @@ import java.io.IOException;
|
||||||
|
|
||||||
public interface FileService {
|
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;
|
ResponseEntity<InputStreamResource> download(String id, String uuid) throws Exception;
|
||||||
|
|
||||||
void backupSql(MultipartFile file) throws Exception;
|
void backupSql(MultipartFile file) throws Exception;
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -26,22 +26,23 @@ public class FileServiceImpl implements FileService {
|
||||||
private BackupPro backupPro;
|
private BackupPro backupPro;
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void upload(MultipartFile file, String id) throws IOException {
|
public void upload(MultipartFile file) throws IOException {
|
||||||
String destPath = getFileSysPathById(id);
|
String name = FileUtil.mainName(file.getOriginalFilename());
|
||||||
|
String destPath = getFileSysPathById(name);
|
||||||
if (!FileUtil.exist(destPath)) {
|
if (!FileUtil.exist(destPath)) {
|
||||||
FileUtil.writeFromStream(file.getInputStream(), destPath);
|
FileUtil.writeFromStream(file.getInputStream(), destPath);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
// @Override
|
||||||
public void remove(String id) {
|
// public void remove(String id) {
|
||||||
String destPath = getFileSysPathById(id);
|
// String destPath = getFileSysPathById(id);
|
||||||
FileUtil.del(destPath);
|
// FileUtil.del(destPath);
|
||||||
}
|
// }
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public ResponseEntity<InputStreamResource> download(String id) throws Exception {
|
public ResponseEntity<InputStreamResource> download(String id, String uuid) throws Exception {
|
||||||
String destPath = getFileSysPathById(id);
|
String destPath = getFileSysPathById(id + "_" + uuid);
|
||||||
FileSystemResource fileSystemResource = new FileSystemResource(destPath);
|
FileSystemResource fileSystemResource = new FileSystemResource(destPath);
|
||||||
return ResponseEntity
|
return ResponseEntity
|
||||||
.ok()
|
.ok()
|
||||||
|
|
@ -63,9 +64,9 @@ public class FileServiceImpl implements FileService {
|
||||||
FileUtil.del(destPath);
|
FileUtil.del(destPath);
|
||||||
}
|
}
|
||||||
|
|
||||||
private String getFileSysPathById(String id) {
|
private String getFileSysPathById(String fileName) {
|
||||||
String saveFolder = backupPro.getSaveFolder();
|
String saveFolder = backupPro.getSaveFolder();
|
||||||
return saveFolder + File.separator + "prj_files" + File.separator + id;
|
return saveFolder + File.separator + "prj_files" + File.separator + fileName;
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -95,7 +95,7 @@ public class FileBackLogServiceImpl extends ServiceImpl<FileBackupLogMapper, Fil
|
||||||
destPath = destPath.replace("//", "/");
|
destPath = destPath.replace("//", "/");
|
||||||
log.info("back up file path is {}", destPath);
|
log.info("back up file path is {}", destPath);
|
||||||
if (!FileUtil.exist(destPath)) {
|
if (!FileUtil.exist(destPath)) {
|
||||||
byte[] bytes = backupHandler.downloadFile(edFileInfo.getId());
|
byte[] bytes = backupHandler.downloadFile(edFileInfo.getId(), edFileInfo.getUuid());
|
||||||
FileUtil.writeBytes(bytes, destPath);
|
FileUtil.writeBytes(bytes, destPath);
|
||||||
String dbPath = commonService.getDbPath(edFileInfo.getFilePath());
|
String dbPath = commonService.getDbPath(edFileInfo.getFilePath());
|
||||||
UserThreadLocal.setSuccessInfo(edFileInfo.getParentId(), edFileInfo.getId(), "{} 恢复成功,路径为 {}", edFileInfo.getFileName() + "." + edFileInfo.getFileType(), dbPath);
|
UserThreadLocal.setSuccessInfo(edFileInfo.getParentId(), edFileInfo.getId(), "{} 恢复成功,路径为 {}", edFileInfo.getFileName() + "." + edFileInfo.getFileType(), dbPath);
|
||||||
|
|
|
||||||
|
|
@ -24,7 +24,6 @@ public class BackupHandler {
|
||||||
public BackupFileResLog backupFiles(String filePath, String id) {
|
public BackupFileResLog backupFiles(String filePath, String id) {
|
||||||
Map<String, Object> map = new HashMap<>();
|
Map<String, Object> map = new HashMap<>();
|
||||||
map.put("file", new File(filePath));
|
map.put("file", new File(filePath));
|
||||||
map.put("id", id);
|
|
||||||
String url = StrFormatter.format("http://{}:{}/data/file/backup/upload", elePropertyConfig.getRemoteHost(), elePropertyConfig.getRemotePort());
|
String url = StrFormatter.format("http://{}:{}/data/file/backup/upload", elePropertyConfig.getRemoteHost(), elePropertyConfig.getRemotePort());
|
||||||
log.info("back up url is {}", url);
|
log.info("back up url is {}", url);
|
||||||
String res = HttpUtil.post(url, map);
|
String res = HttpUtil.post(url, map);
|
||||||
|
|
@ -43,18 +42,18 @@ public class BackupHandler {
|
||||||
return JSONUtil.toBean(data, BackupFileResLog.class);
|
return JSONUtil.toBean(data, BackupFileResLog.class);
|
||||||
}
|
}
|
||||||
|
|
||||||
public BackupFileResLog deleteFile(String id) {
|
// public BackupFileResLog deleteFile(String id) {
|
||||||
Map<String, Object> map = new HashMap<>();
|
// Map<String, Object> map = new HashMap<>();
|
||||||
map.put("id", id);
|
// map.put("id", id);
|
||||||
String url = StrFormatter.format("http://{}:{}/data/file/backup/remove", elePropertyConfig.getRemoteHost(), elePropertyConfig.getRemotePort());
|
// String url = StrFormatter.format("http://{}:{}/data/file/backup/remove", elePropertyConfig.getRemoteHost(), elePropertyConfig.getRemotePort());
|
||||||
String res = HttpUtil.get(url, map);
|
// String res = HttpUtil.get(url, map);
|
||||||
ElectromagneticResult<?> resObj = JSONUtil.toBean(res, ElectromagneticResult.class);
|
// ElectromagneticResult<?> resObj = JSONUtil.toBean(res, ElectromagneticResult.class);
|
||||||
String data = JSONUtil.toJsonStr(resObj.getData());
|
// String data = JSONUtil.toJsonStr(resObj.getData());
|
||||||
return JSONUtil.toBean(data, BackupFileResLog.class);
|
// return JSONUtil.toBean(data, BackupFileResLog.class);
|
||||||
}
|
// }
|
||||||
|
|
||||||
public byte[] downloadFile(String id) {
|
public byte[] downloadFile(String id, String uuid) {
|
||||||
String url = StrFormatter.format("http://{}:{}/data/file/backup/download?id={}", elePropertyConfig.getRemoteHost(), elePropertyConfig.getRemotePort(), id);
|
String url = StrFormatter.format("http://{}:{}/data/file/backup/download?id={}&&uuid=", elePropertyConfig.getRemoteHost(), elePropertyConfig.getRemotePort(), id, uuid);
|
||||||
return HttpUtil.downloadBytes(url);
|
return HttpUtil.downloadBytes(url);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue