This commit is contained in:
s2042968 2025-04-22 17:54:54 +08:00
commit 01ff53aa83
4 changed files with 13 additions and 17 deletions

View File

@ -11,8 +11,6 @@ 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 {
@ -29,7 +27,7 @@ public class FileBackupLogController {
@GetMapping(value = "restore")
@UserOperation(value = "系统恢复", modelName = UserOperationModuleEnum.BACKUP_FILE)
public ElectromagneticResult<?> restore() {
List<String> restorePaths = fileBackLogService.restore();
return ElectromagneticResultUtil.success(restorePaths);
Long maxEndTime = fileBackLogService.restore();
return ElectromagneticResultUtil.success(maxEndTime);
}
}

View File

@ -2,11 +2,9 @@ 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);
List<String> restore();
Long restore();
}

View File

@ -1115,7 +1115,6 @@ public class EdFileInfoServiceImpl extends ServiceImpl<EdFileInfoMapper, EdFileI
UserThreadLocal.setSuccessInfo("", "", "查看发布管理成功");
return ElectromagneticResultUtil.success(new UploadRecordVO(0, new ArrayList<>()));
}
lambdaQuery.or(qr -> {
for (String id : list) {
qr.likeRight(EdFileInfo::getFileCode, id);
@ -1253,7 +1252,7 @@ public class EdFileInfoServiceImpl extends ServiceImpl<EdFileInfoMapper, EdFileI
if (file.getId().length() < 6) {
throw new StringIndexOutOfBoundsException("此文件的FILE_CODE小于六位" + id);
}
if (file.getDataOwn().equals(DataOwnEnum.SYS_PRJ.code) || file.getDataOwn().equals(DataOwnEnum.USER_PRJ.code)) {
if (DataOwnEnum.isPrjCode(file.getDataOwn())) {
return id;
}
return file.getFileCode().substring(0, 6);

View File

@ -28,9 +28,7 @@ import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;
import java.io.File;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
import java.util.*;
import java.util.stream.Collectors;
@Slf4j
@ -80,12 +78,11 @@ public class FileBackLogServiceImpl extends ServiceImpl<FileBackupLogMapper, Fil
}
@Override
public List<String> restore() {
public Long 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 = EleCommonUtil.simpleTrueFalse(DataOwnEnum.isUserCode(edFileInfo.getDataOwn()),
@ -97,11 +94,15 @@ 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;
List<FileBackupLog> fileBackupLogs = this.baseMapper.selectList(Wrappers.<FileBackupLog>lambdaQuery().orderByDesc(FileBackupLog::getEndTime).last(" limit 1"));
if (CollUtil.isEmpty(fileBackupLogs)) {
return 0L;
}
Long endTime = fileBackupLogs.get(0).getEndTime();
UserThreadLocal.setSuccessInfo("", "", "数据库恢复成功,最新时间戳为 {}", endTime);
return endTime;
}
}