优化系统恢复的逻辑。
This commit is contained in:
parent
b13f41f8ed
commit
330d0a4310
|
|
@ -11,6 +11,8 @@ import org.springframework.web.bind.annotation.RequestMapping;
|
||||||
import org.springframework.web.bind.annotation.RequestParam;
|
import org.springframework.web.bind.annotation.RequestParam;
|
||||||
import org.springframework.web.bind.annotation.RestController;
|
import org.springframework.web.bind.annotation.RestController;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
@RestController
|
@RestController
|
||||||
@RequestMapping("/data/ed/backup/")
|
@RequestMapping("/data/ed/backup/")
|
||||||
public class FileBackupLogController {
|
public class FileBackupLogController {
|
||||||
|
|
@ -27,7 +29,7 @@ public class FileBackupLogController {
|
||||||
@GetMapping(value = "restore")
|
@GetMapping(value = "restore")
|
||||||
@UserOperation(value = "系统恢复", modelName = UserOperationModuleEnum.BACKUP_FILE)
|
@UserOperation(value = "系统恢复", modelName = UserOperationModuleEnum.BACKUP_FILE)
|
||||||
public ElectromagneticResult<?> restore() {
|
public ElectromagneticResult<?> restore() {
|
||||||
fileBackLogService.restore();
|
List<String> restorePaths = fileBackLogService.restore();
|
||||||
return ElectromagneticResultUtil.success(true);
|
return ElectromagneticResultUtil.success(restorePaths);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -2,9 +2,11 @@ package com.electromagnetic.industry.software.manage.service;
|
||||||
|
|
||||||
import com.electromagnetic.industry.software.common.resp.ElectromagneticResult;
|
import com.electromagnetic.industry.software.common.resp.ElectromagneticResult;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
public interface FileBackLogService {
|
public interface FileBackLogService {
|
||||||
|
|
||||||
ElectromagneticResult<?> query(Integer pageNumber, Integer pageSize);
|
ElectromagneticResult<?> query(Integer pageNumber, Integer pageSize);
|
||||||
|
|
||||||
void restore();
|
List<String> restore();
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -201,7 +201,7 @@ public class CommonService {
|
||||||
EdFileInfo fileInfo = map.get(id);
|
EdFileInfo fileInfo = map.get(id);
|
||||||
String tmp;
|
String tmp;
|
||||||
if (fileInfo.getDataType().equals(EleDataTypeEnum.FILE.code)) {
|
if (fileInfo.getDataType().equals(EleDataTypeEnum.FILE.code)) {
|
||||||
tmp = fileInfo.getFileName() + "." + fileInfo.getFileType() + "." + fileInfo.getFileCode();
|
tmp = fileInfo.getFileName() + "." + fileInfo.getFileType();
|
||||||
} else {
|
} else {
|
||||||
tmp = fileInfo.getFileName() + File.separator;
|
tmp = fileInfo.getFileName() + File.separator;
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -79,18 +79,19 @@ public class FileBackLogServiceImpl extends ServiceImpl<FileBackupLogMapper, Fil
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void restore() {
|
public List<String> restore() {
|
||||||
List<EdFileInfo> edFileInfos = edFileInfoMapper.selectList(Wrappers.lambdaQuery(EdFileInfo.class)
|
List<EdFileInfo> edFileInfos = edFileInfoMapper.selectList(Wrappers.lambdaQuery(EdFileInfo.class)
|
||||||
.select(EdFileInfo.class, file -> !StrUtil.equals(file.getColumn(), "file_content"))
|
.select(EdFileInfo.class, file -> !StrUtil.equals(file.getColumn(), "file_content"))
|
||||||
.eq(EdFileInfo::getPermanentDeleted, false)
|
.eq(EdFileInfo::getPermanentDeleted, false)
|
||||||
.eq(EdFileInfo::getDataType, EleDataTypeEnum.FILE.code));
|
.eq(EdFileInfo::getDataType, EleDataTypeEnum.FILE.code));
|
||||||
|
List<String> restoreFilePaths = new ArrayList<>();
|
||||||
for (EdFileInfo edFileInfo : edFileInfos) {
|
for (EdFileInfo edFileInfo : edFileInfos) {
|
||||||
|
|
||||||
String destPath = "";
|
String destPath;
|
||||||
if (DataOwnEnum.isUserCode(edFileInfo.getDataOwn())) {
|
if (DataOwnEnum.isUserCode(edFileInfo.getDataOwn())) {
|
||||||
destPath = commonService.getPrjRootPath1(edFileInfo.getDataOwn()) + File.separator + edFileInfo.getCreatedBy() + File.separator + commonService.getDbPath(edFileInfo.getFilePath());
|
destPath = commonService.getPrjRootPath1(edFileInfo.getDataOwn()) + File.separator + edFileInfo.getCreatedBy() + File.separator + edFileInfo.getId();
|
||||||
} else {
|
} else {
|
||||||
destPath = commonService.getPrjRootPath1(edFileInfo.getDataOwn()) + File.separator + commonService.getDbPath(edFileInfo.getFilePath());
|
destPath = commonService.getPrjRootPath1(edFileInfo.getDataOwn()) + File.separator + edFileInfo.getId();
|
||||||
}
|
}
|
||||||
destPath = destPath.replace("//", "/");
|
destPath = destPath.replace("//", "/");
|
||||||
log.info("back up file path is {}", destPath);
|
log.info("back up file path is {}", destPath);
|
||||||
|
|
@ -98,9 +99,11 @@ public class FileBackLogServiceImpl extends ServiceImpl<FileBackupLogMapper, Fil
|
||||||
byte[] bytes = backupHandler.downloadFile(edFileInfo.getId());
|
byte[] bytes = backupHandler.downloadFile(edFileInfo.getId());
|
||||||
FileUtil.writeBytes(bytes, destPath);
|
FileUtil.writeBytes(bytes, destPath);
|
||||||
String dbPath = commonService.getDbPath(edFileInfo.getFilePath());
|
String dbPath = commonService.getDbPath(edFileInfo.getFilePath());
|
||||||
|
restoreFilePaths.add(dbPath);
|
||||||
UserThreadLocal.setSuccessInfo(edFileInfo.getParentId(), edFileInfo.getId(), "{} 恢复成功,路径为 {}", edFileInfo.getFileName() + "." + edFileInfo.getFileType(), dbPath);
|
UserThreadLocal.setSuccessInfo(edFileInfo.getParentId(), edFileInfo.getId(), "{} 恢复成功,路径为 {}", edFileInfo.getFileName() + "." + edFileInfo.getFileType(), dbPath);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
UserThreadLocal.setSuccessInfo("", "", "数据库恢复成功");
|
UserThreadLocal.setSuccessInfo("", "", "数据库恢复成功");
|
||||||
|
return restoreFilePaths;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue