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