文件物理删除与恢复
This commit is contained in:
parent
38fcdcb859
commit
5eb98d6f78
|
|
@ -30,12 +30,12 @@ public class FileController {
|
|||
|
||||
@RequestMapping("/upload")
|
||||
public ElectromagneticResult<?> upload(@RequestParam("file") MultipartFile file, @RequestParam("path") String path) {
|
||||
BackupFileResLog backupFileResLog = BackupFileResLog.builder().backupStartTime(new Date()).fileName(file.getOriginalFilename()).backupStatus(true).build();
|
||||
BackupFileResLog backupFileResLog = BackupFileResLog.builder().backupStartTime(new Date()).fileName(file.getOriginalFilename()).backupSuccess(true).build();
|
||||
try {
|
||||
fileService.upload(file);
|
||||
} catch (Exception e) {
|
||||
String details = ExceptionUtil.stacktraceToString(e);
|
||||
backupFileResLog.setBackupStatus(false);
|
||||
backupFileResLog.setBackupSuccess(false);
|
||||
backupFileResLog.setFailInfoDetail(details);
|
||||
log.error("备份文件失败,原因--->{}", e.getMessage(), e);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -0,0 +1,38 @@
|
|||
package com.electromagnetic.industry.software.manage.config;
|
||||
|
||||
import cn.hutool.core.io.FileUtil;
|
||||
import com.electromagnetic.industry.software.common.util.EleCommonUtil;
|
||||
import lombok.Getter;
|
||||
import org.springframework.core.env.Environment;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
import javax.annotation.PostConstruct;
|
||||
import javax.annotation.Resource;
|
||||
|
||||
@Component
|
||||
@Getter
|
||||
public class ElePropertyConfig {
|
||||
|
||||
@Resource
|
||||
private Environment environment;
|
||||
|
||||
private String downloadDataDir = "";
|
||||
private String uploadDataDir = "";
|
||||
private String tmpDir = "";
|
||||
private String eleDataPath;
|
||||
private String userDataPath;
|
||||
|
||||
private String prjDir;
|
||||
|
||||
@PostConstruct
|
||||
public void init() {
|
||||
uploadDataDir = EleCommonUtil.isWinOs() ? environment.getProperty("data.upload.windows.tmp.path") : environment.getProperty("data.upload.linux.tmp.path");
|
||||
downloadDataDir = EleCommonUtil.isWinOs() ? environment.getProperty("data.download.windows.tmp.path") : environment.getProperty("data.download.linux.tmp.path");
|
||||
tmpDir = EleCommonUtil.isWinOs() ? environment.getProperty("data.windows.tmp.path") : environment.getProperty("data.linux.tmp.path");
|
||||
eleDataPath = EleCommonUtil.isWinOs() ? environment.getProperty("data.windows.path") : environment.getProperty("data.linux.path");
|
||||
userDataPath = EleCommonUtil.isWinOs() ? environment.getProperty("data.windows.user.path") : environment.getProperty("data.linux.user.path");
|
||||
String tmp = EleCommonUtil.isWinOs() ? environment.getProperty("data.windows.path") : environment.getProperty("data.linux.path");
|
||||
prjDir = FileUtil.getParent(tmp, 1);
|
||||
}
|
||||
|
||||
}
|
||||
|
|
@ -0,0 +1,40 @@
|
|||
package com.electromagnetic.industry.software.manage.controller;
|
||||
|
||||
import com.electromagnetic.industry.software.common.annotations.UserOperation;
|
||||
import com.electromagnetic.industry.software.common.enums.UserOperationModuleEnum;
|
||||
import com.electromagnetic.industry.software.common.resp.ElectromagneticResult;
|
||||
import com.electromagnetic.industry.software.manage.pojo.req.RecycleFileQueryDTO;
|
||||
import com.electromagnetic.industry.software.manage.service.FileRecycleService;
|
||||
import org.springframework.web.bind.annotation.RequestBody;
|
||||
import org.springframework.web.bind.annotation.RequestMapping;
|
||||
import org.springframework.web.bind.annotation.RequestParam;
|
||||
import org.springframework.web.bind.annotation.RestController;
|
||||
|
||||
import javax.annotation.Resource;
|
||||
|
||||
@RestController
|
||||
@RequestMapping("/data/ed/recycle/file")
|
||||
public class FileRecycleController {
|
||||
|
||||
@Resource
|
||||
private FileRecycleService fileRecycleService;
|
||||
|
||||
@RequestMapping("list")
|
||||
@UserOperation(value = "查看回收站", modelName = UserOperationModuleEnum.DATABASE)
|
||||
public ElectromagneticResult<?> list(@RequestBody RecycleFileQueryDTO pars) {
|
||||
return fileRecycleService.list(pars);
|
||||
}
|
||||
|
||||
@RequestMapping("remove")
|
||||
@UserOperation(value = "查看回收站", modelName = UserOperationModuleEnum.DATABASE)
|
||||
public ElectromagneticResult<?> remove(@RequestParam String fileId) {
|
||||
return fileRecycleService.remove(fileId);
|
||||
}
|
||||
|
||||
@RequestMapping("list")
|
||||
@UserOperation(value = "查看回收站", modelName = UserOperationModuleEnum.DATABASE)
|
||||
public ElectromagneticResult<?> recover(@RequestParam String fileId) {
|
||||
return fileRecycleService.recover(fileId);
|
||||
}
|
||||
|
||||
}
|
||||
|
|
@ -1,9 +1,9 @@
|
|||
package com.electromagnetic.industry.software.manage.mapper;
|
||||
|
||||
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
|
||||
import com.electromagnetic.industry.software.manage.pojo.models.EleFileBackupLog;
|
||||
import com.electromagnetic.industry.software.manage.pojo.models.FileBackupLog;
|
||||
import org.apache.ibatis.annotations.Mapper;
|
||||
|
||||
@Mapper
|
||||
public interface EleFileBackupLogMapper extends BaseMapper<EleFileBackupLog> {
|
||||
public interface FileBackupLogMapper extends BaseMapper<FileBackupLog> {
|
||||
}
|
||||
|
|
@ -1,35 +0,0 @@
|
|||
package com.electromagnetic.industry.software.manage.pojo.models;
|
||||
|
||||
import com.baomidou.mybatisplus.annotation.TableName;
|
||||
import lombok.Data;
|
||||
import lombok.NoArgsConstructor;
|
||||
|
||||
import java.util.Date;
|
||||
|
||||
@TableName("ele_file_backup_log")
|
||||
@Data
|
||||
@NoArgsConstructor
|
||||
public class EleFileBackupLog {
|
||||
|
||||
public EleFileBackupLog(Date reqStartTime, Date reqEndTime, long fileTime, String id) {
|
||||
this.reqStartTime = reqStartTime;
|
||||
this.reqEndTime = reqEndTime;
|
||||
this.fileTime = fileTime;
|
||||
this.id = id;
|
||||
}
|
||||
|
||||
private String id;
|
||||
private Date reqStartTime;
|
||||
private Date backupStartTime;
|
||||
private Date backupEndTime;
|
||||
private Date reqEndTime;
|
||||
private Date createTime;
|
||||
|
||||
private String fileName;
|
||||
|
||||
private Boolean backupStatus;
|
||||
|
||||
private String failInfoDetail;
|
||||
|
||||
private long fileTime;
|
||||
}
|
||||
|
|
@ -0,0 +1,37 @@
|
|||
package com.electromagnetic.industry.software.manage.pojo.models;
|
||||
|
||||
import com.baomidou.mybatisplus.annotation.TableName;
|
||||
import lombok.Builder;
|
||||
import lombok.Data;
|
||||
import lombok.experimental.Accessors;
|
||||
|
||||
import java.util.Date;
|
||||
|
||||
@TableName("file_backup_log")
|
||||
@Builder
|
||||
@Data
|
||||
@Accessors(chain = true)
|
||||
public class FileBackupLog {
|
||||
|
||||
private String id;
|
||||
|
||||
private String fileId;
|
||||
|
||||
private boolean backupSuccess;
|
||||
|
||||
private Date createTime;
|
||||
|
||||
private Long startTime;
|
||||
|
||||
private Long endTime;
|
||||
|
||||
private Long duration;
|
||||
|
||||
private String failInfoDetail;
|
||||
|
||||
private long fileTime;
|
||||
|
||||
private String fileName;
|
||||
|
||||
private Integer source;
|
||||
}
|
||||
|
|
@ -0,0 +1,50 @@
|
|||
package com.electromagnetic.industry.software.manage.pojo.req;
|
||||
|
||||
import lombok.Data;
|
||||
|
||||
@Data
|
||||
public class RecycleFileQueryDTO {
|
||||
|
||||
private String keyword;
|
||||
|
||||
private int pageNum;
|
||||
|
||||
private int pageSize;
|
||||
|
||||
/**
|
||||
* 文件名排序 (0-升序,1-降序)
|
||||
*/
|
||||
private Integer fileNameSort;
|
||||
|
||||
/**
|
||||
* 文件类型 (0-升序,1-降序)
|
||||
*/
|
||||
private Integer fileTypeSort;
|
||||
|
||||
/**
|
||||
* 文件类型过滤
|
||||
*/
|
||||
private String fileType;
|
||||
|
||||
/**
|
||||
* 上传时间(0-升序,1-降序)
|
||||
*/
|
||||
private Integer createdTime;
|
||||
|
||||
/**
|
||||
* 修改时间(0-升序,1-降序)
|
||||
*/
|
||||
private Integer updatedTime;
|
||||
|
||||
|
||||
/**
|
||||
* 版本号(0-升序,1-降序
|
||||
*/
|
||||
private Integer versionSort;
|
||||
|
||||
/**
|
||||
* 文件大小0-升序,1-降序)
|
||||
*/
|
||||
private Integer fileSizeSort;
|
||||
|
||||
}
|
||||
|
|
@ -0,0 +1,32 @@
|
|||
package com.electromagnetic.industry.software.manage.pojo.resp;
|
||||
|
||||
import lombok.Data;
|
||||
|
||||
import java.util.Date;
|
||||
|
||||
@Data
|
||||
public class FileRecycleQueryVO {
|
||||
|
||||
private String id;
|
||||
|
||||
private String fileId;
|
||||
|
||||
private String fileName;
|
||||
|
||||
private String fileType;
|
||||
|
||||
private String fileVersion;
|
||||
|
||||
private Date updateTime;
|
||||
|
||||
private String fileNote;
|
||||
|
||||
private long fileSize;
|
||||
|
||||
private String fileSizeShow;
|
||||
|
||||
private String updatedBy;
|
||||
|
||||
private String userName;
|
||||
|
||||
}
|
||||
|
|
@ -177,11 +177,6 @@ public interface EdFileInfoService {
|
|||
* @param response
|
||||
*/
|
||||
ResponseEntity<InputStreamResource> preview(String id, HttpServletResponse response, int dataOwnCode);
|
||||
/**
|
||||
* 计算fileSizeShow字段
|
||||
* @param records
|
||||
*/
|
||||
void resetFileSize(List<FileInfoVO> records);
|
||||
|
||||
/**
|
||||
* 收藏页 数据查询
|
||||
|
|
|
|||
|
|
@ -0,0 +1,14 @@
|
|||
package com.electromagnetic.industry.software.manage.service;
|
||||
|
||||
import com.electromagnetic.industry.software.common.resp.ElectromagneticResult;
|
||||
import com.electromagnetic.industry.software.manage.pojo.req.RecycleFileQueryDTO;
|
||||
|
||||
public interface FileRecycleService {
|
||||
|
||||
ElectromagneticResult<?> list(RecycleFileQueryDTO queryDTO);
|
||||
|
||||
ElectromagneticResult<?> remove(String fileId);
|
||||
|
||||
ElectromagneticResult<?> recover(String fileId);
|
||||
|
||||
}
|
||||
|
|
@ -18,6 +18,7 @@ import com.electromagnetic.industry.software.common.util.EleCommonUtil;
|
|||
import com.electromagnetic.industry.software.common.util.EleLog;
|
||||
import com.electromagnetic.industry.software.common.util.ElectromagneticResultUtil;
|
||||
import com.electromagnetic.industry.software.common.util.UserThreadLocal;
|
||||
import com.electromagnetic.industry.software.manage.config.ElePropertyConfig;
|
||||
import com.electromagnetic.industry.software.manage.mapper.EdFileInfoMapper;
|
||||
import com.electromagnetic.industry.software.manage.pojo.models.EdFileInfo;
|
||||
import com.electromagnetic.industry.software.manage.pojo.resp.FileProjectVO;
|
||||
|
|
@ -67,12 +68,8 @@ public class CommonService {
|
|||
@Value("${prj.folder.max.length}")
|
||||
private int prjFolderMaxLength;
|
||||
|
||||
private String eleDataPath;
|
||||
|
||||
private String userDataPath;
|
||||
|
||||
@Resource
|
||||
private Environment environment;
|
||||
private ElePropertyConfig elePropertyConfig;
|
||||
|
||||
@Resource
|
||||
private EdFileInfoMapper edFileInfoMapper;
|
||||
|
|
@ -80,17 +77,11 @@ public class CommonService {
|
|||
@Resource
|
||||
private FileSystemService fileSystemService;
|
||||
|
||||
@PostConstruct
|
||||
public void init() {
|
||||
eleDataPath = EleCommonUtil.isWinOs() ? environment.getProperty("data.windows.path") : environment.getProperty("data.linux.path");
|
||||
userDataPath = EleCommonUtil.isWinOs() ? environment.getProperty("data.windows.user.path") : environment.getProperty("data.linux.user.path");
|
||||
}
|
||||
|
||||
public String getEleDataPath(int dataOwnCode) {
|
||||
if (dataOwnCode == DataOwnEnum.USER_PRJ.code) {
|
||||
return userDataPath;
|
||||
return elePropertyConfig.getUserDataPath();
|
||||
}
|
||||
return eleDataPath;
|
||||
return elePropertyConfig.getEleDataPath();
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
@ -110,7 +101,7 @@ public class CommonService {
|
|||
public String getFileSysPath(String dbPath, int dataOwnCode) {
|
||||
ArrayList<String> paths = CollUtil.newArrayList(dbPath.split(MYSQL_FILE_PATH_SPLIT));
|
||||
String path = getDbPath(paths);
|
||||
String prePath = dataOwnCode == DataOwnEnum.USER_PRJ.code ? userDataPath : eleDataPath;
|
||||
String prePath = dataOwnCode == DataOwnEnum.USER_PRJ.code ? elePropertyConfig.getUserDataPath() : elePropertyConfig.getEleDataPath();
|
||||
return prePath + File.separator + path;
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -8,6 +8,7 @@ import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
|||
import com.electromagnetic.industry.software.common.enums.EffectFlagEnum;
|
||||
import com.electromagnetic.industry.software.common.enums.EleDataSaveStatusEnum;
|
||||
import com.electromagnetic.industry.software.common.exception.BizException;
|
||||
import com.electromagnetic.industry.software.common.util.EleCommonUtil;
|
||||
import com.electromagnetic.industry.software.common.util.UserThreadLocal;
|
||||
import com.electromagnetic.industry.software.manage.mapper.EdFileFavoriteMapper;
|
||||
import com.electromagnetic.industry.software.manage.pojo.models.EdFileFavorite;
|
||||
|
|
@ -78,7 +79,7 @@ public class EdFileFavoriteServiceImpl extends ServiceImpl<EdFileFavoriteMapper,
|
|||
// 创建分页对象
|
||||
Page<FileInfoVO> page = new Page<>(fileInfoQueryDTO.getPageNum(), fileInfoQueryDTO.getPageSize());
|
||||
IPage<FileInfoVO> fileInfoVOIPage = fileInfoService.queryFileList(page, fileIds, fileInfoQueryDTO, EleDataSaveStatusEnum.SUCCESS.code, EffectFlagEnum.EFFECT.code);
|
||||
fileInfoService.resetFileSize(fileInfoVOIPage.getRecords());
|
||||
fileInfoVOIPage.getRecords().forEach(e -> e.setFileSizeShow(EleCommonUtil.convertFileSize(e.getFileSize())));
|
||||
UserThreadLocal.setSuccessInfo("", "", "查询了收藏列表");
|
||||
return fileInfoVOIPage;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -24,6 +24,7 @@ import com.electromagnetic.industry.software.common.exception.BizException;
|
|||
import com.electromagnetic.industry.software.common.exception.PermissionDeniedException;
|
||||
import com.electromagnetic.industry.software.common.resp.ElectromagneticResult;
|
||||
import com.electromagnetic.industry.software.common.util.*;
|
||||
import com.electromagnetic.industry.software.manage.config.ElePropertyConfig;
|
||||
import com.electromagnetic.industry.software.manage.mapper.EdFileInfoMapper;
|
||||
import com.electromagnetic.industry.software.manage.mapper.UserMapper;
|
||||
import com.electromagnetic.industry.software.manage.pojo.models.EdFileInfo;
|
||||
|
|
@ -35,7 +36,6 @@ import com.electromagnetic.industry.software.manage.pojo.resp.*;
|
|||
import com.electromagnetic.industry.software.manage.service.EdFileInfoService;
|
||||
import com.electromagnetic.industry.software.manage.service.FileSystemService;
|
||||
import com.electromagnetic.industry.software.manage.service.PermissionService;
|
||||
import org.springframework.core.env.Environment;
|
||||
import org.springframework.core.io.FileSystemResource;
|
||||
import org.springframework.core.io.InputStreamResource;
|
||||
import org.springframework.http.HttpHeaders;
|
||||
|
|
@ -46,7 +46,6 @@ import org.springframework.transaction.annotation.Propagation;
|
|||
import org.springframework.transaction.annotation.Transactional;
|
||||
import org.springframework.web.multipart.MultipartFile;
|
||||
|
||||
import javax.annotation.PostConstruct;
|
||||
import javax.annotation.Resource;
|
||||
import javax.servlet.http.HttpServletResponse;
|
||||
import java.io.*;
|
||||
|
|
@ -62,28 +61,21 @@ import static com.electromagnetic.industry.software.common.cons.ElectromagneticC
|
|||
public class EdFileInfoServiceImpl extends ServiceImpl<EdFileInfoMapper, EdFileInfo> implements EdFileInfoService {
|
||||
|
||||
private final EleLog log = new EleLog(EdFileInfoServiceImpl.class);
|
||||
|
||||
@Resource
|
||||
private CommonService commonService;
|
||||
|
||||
@Resource
|
||||
private FileSystemService fileSystemService;
|
||||
@Resource
|
||||
private Environment environment;
|
||||
|
||||
@Resource
|
||||
private PermissionService permissionService;
|
||||
|
||||
@Resource
|
||||
private UserMapper userMapper;
|
||||
|
||||
private String downloadDataDir = "";
|
||||
private String uploadDataDir = "";
|
||||
private String tmpDir = "";
|
||||
|
||||
@PostConstruct
|
||||
public void init() {
|
||||
uploadDataDir = EleCommonUtil.isWinOs() ? environment.getProperty("data.upload.windows.tmp.path") : environment.getProperty("data.upload.linux.tmp.path");
|
||||
downloadDataDir = EleCommonUtil.isWinOs() ? environment.getProperty("data.download.windows.tmp.path") : environment.getProperty("data.download.linux.tmp.path");
|
||||
tmpDir = EleCommonUtil.isWinOs() ? environment.getProperty("data.windows.tmp.path") : environment.getProperty("data.linux.tmp.path");
|
||||
}
|
||||
|
||||
@Resource
|
||||
private ElePropertyConfig elePropertyConfig;
|
||||
/**
|
||||
* 查询文件列表
|
||||
*
|
||||
|
|
@ -102,7 +94,6 @@ public class EdFileInfoServiceImpl extends ServiceImpl<EdFileInfoMapper, EdFileI
|
|||
LambdaQueryWrapper<EdFileInfo> queryWrapper = Wrappers.lambdaQuery(EdFileInfo.class)
|
||||
.select(EdFileInfo.class, file -> !file.getColumn().equals("file_content"))
|
||||
.select()
|
||||
.eq(EdFileInfo::getDataOwn, DataOwnEnum.COMMON.code)
|
||||
.eq(EdFileInfo::getSaveStatus, EleDataSaveStatusEnum.SUCCESS.code)
|
||||
.eq(EdFileInfo::getEffectFlag, EffectFlagEnum.EFFECT.code)
|
||||
.eq(EdFileInfo::getParentId, pars.getParentId())
|
||||
|
|
@ -144,26 +135,11 @@ public class EdFileInfoServiceImpl extends ServiceImpl<EdFileInfoMapper, EdFileI
|
|||
Page<EdFileInfo> edFileInfoPage = this.baseMapper.selectPage(new Page<>(pars.getPageNum(), pars.getPageSize()), queryWrapper);
|
||||
long total = edFileInfoPage.getTotal();
|
||||
List<FileInfoVO> records = BeanUtil.copyToList(edFileInfoPage.getRecords(), FileInfoVO.class);
|
||||
resetFileSize(records);
|
||||
records.forEach(e -> e.setFileSizeShow(EleCommonUtil.convertFileSize(e.getFileSize())));
|
||||
UserThreadLocal.setSuccessInfo("", "", "查询文件成功");
|
||||
return ElectromagneticResultUtil.success(new RespPageVO<>(total, records));
|
||||
}
|
||||
|
||||
@Override
|
||||
public void resetFileSize(List<FileInfoVO> records) {
|
||||
for (FileInfoVO fileInfoDTO : records) {
|
||||
if (fileInfoDTO.getFileSize() < 1024) {
|
||||
fileInfoDTO.setFileSizeShow(fileInfoDTO.getFileSize() + "B");
|
||||
} else if (fileInfoDTO.getFileSize() < 1024 * 1024) {
|
||||
fileInfoDTO.setFileSizeShow(String.format("%.2f KB", fileInfoDTO.getFileSize() / 1024.0));
|
||||
} else if (fileInfoDTO.getFileSize() < 1024 * 1024 * 1024) {
|
||||
fileInfoDTO.setFileSizeShow(String.format("%.2f MB", fileInfoDTO.getFileSize() / (1024.0 * 1024)));
|
||||
} else {
|
||||
fileInfoDTO.setFileSizeShow(String.format("%.2f GB", fileInfoDTO.getFileSize() / (1024.0 * 1024 * 1024)));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 新建文件夹
|
||||
*
|
||||
|
|
@ -362,7 +338,7 @@ public class EdFileInfoServiceImpl extends ServiceImpl<EdFileInfoMapper, EdFileI
|
|||
@Override
|
||||
public ElectromagneticResult<?> checkChunkExist(FileChunkDTO fileChunkDTO) {
|
||||
String currentUserId = UserThreadLocal.getUserId();
|
||||
String userUploadFolder = uploadDataDir + File.separator + currentUserId;
|
||||
String userUploadFolder = elePropertyConfig.getUploadDataDir() + File.separator + currentUserId;
|
||||
String identifier = fileChunkDTO.getIdentifier();
|
||||
List<Integer> uploadedChunks = getUploadedChunks(identifier, userUploadFolder);
|
||||
return ElectromagneticResultUtil.success(new FileChunkResultDTO(false, new HashSet<>(uploadedChunks)));
|
||||
|
|
@ -392,7 +368,7 @@ public class EdFileInfoServiceImpl extends ServiceImpl<EdFileInfoMapper, EdFileI
|
|||
String currentUserId = UserThreadLocal.getUserId();
|
||||
String identifier = fileChunkDTO.getIdentifier();
|
||||
// 首先检查该分片有没被上传,如果有则禁止上传
|
||||
String destPath = uploadDataDir + File.separator + currentUserId + File.separator + identifier + File.separator + fileChunkDTO.getChunkNumber() + UPLOAD_FILE_CHUNK_SUFFIX;
|
||||
String destPath = elePropertyConfig.getUploadDataDir() + File.separator + currentUserId + File.separator + identifier + File.separator + fileChunkDTO.getChunkNumber() + UPLOAD_FILE_CHUNK_SUFFIX;
|
||||
boolean exist = FileUtil.exist(destPath);
|
||||
if (exist) {
|
||||
return ElectromagneticResultUtil.fail("-1", "文件已经存在,请勿重复上传");
|
||||
|
|
@ -438,7 +414,7 @@ public class EdFileInfoServiceImpl extends ServiceImpl<EdFileInfoMapper, EdFileI
|
|||
throw new BizException(info);
|
||||
}
|
||||
String uuid = IdUtil.fastSimpleUUID();
|
||||
String tmpDir = uploadDataDir + currentUserId + File.separator + uuid + File.separator;
|
||||
String tmpDir = elePropertyConfig.getUploadDataDir() + currentUserId + File.separator + uuid + File.separator;
|
||||
ZipUtil.unzip(zipDirPath, tmpDir);
|
||||
update2Database(tmpDir, dataOwnCode);
|
||||
fileSystemService.deleteFile(zipDirPath, destColibPath);
|
||||
|
|
@ -642,7 +618,7 @@ public class EdFileInfoServiceImpl extends ServiceImpl<EdFileInfoMapper, EdFileI
|
|||
*/
|
||||
@Override
|
||||
public ResponseEntity<InputStreamResource> batchExport(String dataIdArr, HttpServletResponse response, int dataOwnCode) throws IOException {
|
||||
String userDownloadDataDir = downloadDataDir + File.separator + UserThreadLocal.getUserId();
|
||||
String userDownloadDataDir = elePropertyConfig.getDownloadDataDir() + File.separator + UserThreadLocal.getUserId();
|
||||
String[] ids = dataIdArr.split(",");
|
||||
Map<String, Boolean> map = permissionService.filterExportIds(ids);
|
||||
Assert.isTrue(!map.containsValue(Boolean.FALSE), "有未授权的层级目录,禁止导出");
|
||||
|
|
@ -1176,7 +1152,7 @@ public class EdFileInfoServiceImpl extends ServiceImpl<EdFileInfoMapper, EdFileI
|
|||
private String doSysFileMerge(String identifier, String fileName, Integer totalChunks) {
|
||||
String currentUserId = UserThreadLocal.getUserId();
|
||||
for (int i = 1; i <= totalChunks; i++) {
|
||||
String tmpPath = uploadDataDir + File.separator + currentUserId + File.separator + identifier + File.separator + i + UPLOAD_FILE_CHUNK_SUFFIX;
|
||||
String tmpPath = elePropertyConfig.getUploadDataDir() + File.separator + currentUserId + File.separator + identifier + File.separator + i + UPLOAD_FILE_CHUNK_SUFFIX;
|
||||
if (!FileUtil.exist(new File(tmpPath))) {
|
||||
String info = StrFormatter.format("第{}个分片没有上传完成,请上传完成后再合并。", i);
|
||||
log.error(info);
|
||||
|
|
@ -1184,8 +1160,8 @@ public class EdFileInfoServiceImpl extends ServiceImpl<EdFileInfoMapper, EdFileI
|
|||
}
|
||||
}
|
||||
// 合并分片
|
||||
String destColibPath = uploadDataDir + File.separator + currentUserId + File.separator + fileName;
|
||||
String path = uploadDataDir + File.separator + currentUserId + File.separator + identifier;
|
||||
String destColibPath = elePropertyConfig.getUploadDataDir() + File.separator + currentUserId + File.separator + fileName;
|
||||
String path = elePropertyConfig.getUploadDataDir() + File.separator + currentUserId + File.separator + identifier;
|
||||
BufferedOutputStream outputStream = FileUtil.getOutputStream(destColibPath);
|
||||
for (int i = 1; i <= totalChunks; i++) {
|
||||
try (BufferedInputStream inputStream = FileUtil.getInputStream(path + File.separator + i + UPLOAD_FILE_CHUNK_SUFFIX)) {
|
||||
|
|
@ -1251,12 +1227,12 @@ public class EdFileInfoServiceImpl extends ServiceImpl<EdFileInfoMapper, EdFileI
|
|||
EdFileInfo fileInfo = this.baseMapper.selectById(id);
|
||||
Assert.isTrue(Objects.nonNull(fileInfo), "文件不存在");
|
||||
String fileSysPath = commonService.getFileSysPath(fileInfo.getFilePath(), dataOwnCode);
|
||||
String fileSaveTmpPath = tmpDir + File.separator + IdUtil.fastSimpleUUID() + "." + fileInfo.getFileType();
|
||||
String fileSaveTmpPath = elePropertyConfig.getTmpDir() + File.separator + IdUtil.fastSimpleUUID() + "." + fileInfo.getFileType();
|
||||
FileUtil.copy(fileSysPath, fileSaveTmpPath, true);
|
||||
EleCommonUtil.decryptFile(fileSaveTmpPath, SecureUtil.aes(FILE_SEC_PASSWD.getBytes()));
|
||||
|
||||
if (Arrays.asList("doc", "docx").contains(fileInfo.getFileType())) {
|
||||
String pdfTmpPath = tmpDir + File.separator + fileInfo.getFileName() + "_" + IdUtil.fastSimpleUUID() + ".pdf";
|
||||
String pdfTmpPath = elePropertyConfig.getTmpDir() + File.separator + fileInfo.getFileName() + "_" + IdUtil.fastSimpleUUID() + ".pdf";
|
||||
OfficeFileUtil.doc2pdf(fileSaveTmpPath, pdfTmpPath);
|
||||
fileSaveTmpPath = pdfTmpPath;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -0,0 +1,223 @@
|
|||
package com.electromagnetic.industry.software.manage.service.serviceimpl;
|
||||
|
||||
import cn.hutool.core.bean.BeanUtil;
|
||||
import cn.hutool.core.collection.CollUtil;
|
||||
import cn.hutool.core.io.FileUtil;
|
||||
import cn.hutool.core.text.StrFormatter;
|
||||
import cn.hutool.core.util.ObjUtil;
|
||||
import cn.hutool.core.util.StrUtil;
|
||||
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
||||
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
|
||||
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
||||
import com.electromagnetic.industry.software.common.enums.*;
|
||||
import com.electromagnetic.industry.software.common.exception.BizException;
|
||||
import com.electromagnetic.industry.software.common.pojo.BackupFileResLog;
|
||||
import com.electromagnetic.industry.software.common.resp.ElectromagneticResult;
|
||||
import com.electromagnetic.industry.software.common.util.EleCommonUtil;
|
||||
import com.electromagnetic.industry.software.common.util.ElectromagneticResultUtil;
|
||||
import com.electromagnetic.industry.software.common.util.IdWorker;
|
||||
import com.electromagnetic.industry.software.common.util.UserThreadLocal;
|
||||
import com.electromagnetic.industry.software.manage.config.ElePropertyConfig;
|
||||
import com.electromagnetic.industry.software.manage.mapper.EdFileInfoMapper;
|
||||
import com.electromagnetic.industry.software.manage.mapper.UserMapper;
|
||||
import com.electromagnetic.industry.software.manage.pojo.models.EdFileInfo;
|
||||
import com.electromagnetic.industry.software.manage.pojo.models.FileBackupLog;
|
||||
import com.electromagnetic.industry.software.manage.pojo.models.User;
|
||||
import com.electromagnetic.industry.software.manage.pojo.req.RecycleFileQueryDTO;
|
||||
import com.electromagnetic.industry.software.manage.pojo.resp.FileRecycleQueryVO;
|
||||
import com.electromagnetic.industry.software.manage.pojo.resp.RespPageVO;
|
||||
import com.electromagnetic.industry.software.manage.service.FileRecycleService;
|
||||
import com.electromagnetic.industry.software.manage.service.FileSystemService;
|
||||
import com.electromagnetic.industry.software.manage.service.PermissionService;
|
||||
import com.electromagnetic.industry.software.manage.tasks.BackupTask;
|
||||
import org.springframework.stereotype.Service;
|
||||
import org.springframework.transaction.annotation.Transactional;
|
||||
|
||||
import javax.annotation.Resource;
|
||||
import java.io.File;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Date;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
@Service
|
||||
public class FileRecycleServiceImpl implements FileRecycleService {
|
||||
|
||||
@Resource
|
||||
private EdFileInfoMapper edFileInfoMapper;
|
||||
@Resource
|
||||
private PermissionService permissionService;
|
||||
@Resource
|
||||
private UserMapper userMapper;
|
||||
@Resource
|
||||
private CommonService commonService;
|
||||
@Resource
|
||||
private BackupTask backupTask;
|
||||
@Resource
|
||||
private FileSystemService fileSystemService;
|
||||
@Resource
|
||||
private ElePropertyConfig elePropertyConfig;
|
||||
|
||||
@Override
|
||||
public ElectromagneticResult<?> list(RecycleFileQueryDTO pars) {
|
||||
|
||||
LambdaQueryWrapper<EdFileInfo> queryWrapper = Wrappers.lambdaQuery(EdFileInfo.class)
|
||||
.select(EdFileInfo.class, file -> !file.getColumn().equals("file_content"))
|
||||
.eq(EdFileInfo::getAllDeleted, true)
|
||||
.eq(EdFileInfo::getPermanentDeleted, false)
|
||||
.eq(EdFileInfo::getDataType, EleDataTypeEnum.FILE.code)
|
||||
|
||||
.eq(StrUtil.isNotEmpty(pars.getFileType()), EdFileInfo::getFileType, pars.getFileType())
|
||||
.orderByAsc(ObjUtil.equals(pars.getCreatedTime(), 0), EdFileInfo::getCreatedTime)
|
||||
.orderByDesc(ObjUtil.equals(pars.getCreatedTime(), 1), EdFileInfo::getCreatedTime)
|
||||
.orderByDesc(ObjUtil.isAllEmpty(pars.getCreatedTime(), pars.getVersionSort(), pars.getFileSizeSort(), pars.getFileNameSort(), pars.getUpdatedTime(), pars.getFileTypeSort()), EdFileInfo::getCreatedTime)
|
||||
.orderByDesc(ObjUtil.isAllEmpty(pars.getCreatedTime(), pars.getVersionSort(), pars.getFileSizeSort(), pars.getFileNameSort(), pars.getUpdatedTime(), pars.getFileTypeSort()), EdFileInfo::getCreatedTime)
|
||||
.orderByAsc(ObjUtil.equals(pars.getVersionSort(), 0), EdFileInfo::getFileVersion)
|
||||
.orderByDesc(ObjUtil.equals(pars.getVersionSort(), 1), EdFileInfo::getFileVersion)
|
||||
|
||||
.orderByAsc(ObjUtil.equals(pars.getFileSizeSort(), 0), EdFileInfo::getFileSize)
|
||||
.orderByDesc(ObjUtil.equals(pars.getFileSizeSort(), 1), EdFileInfo::getFileSize)
|
||||
|
||||
.orderByAsc(ObjUtil.equals(pars.getFileNameSort(), 0), EdFileInfo::getFileName)
|
||||
.orderByDesc(ObjUtil.equals(pars.getFileNameSort(), 1), EdFileInfo::getFileName)
|
||||
|
||||
.orderByAsc(ObjUtil.equals(pars.getUpdatedTime(), 0), EdFileInfo::getUpdatedTime)
|
||||
.orderByDesc(ObjUtil.equals(pars.getUpdatedTime(), 1), EdFileInfo::getUpdatedTime)
|
||||
|
||||
.orderByAsc(ObjUtil.equals(pars.getFileTypeSort(), 0), EdFileInfo::getSort)
|
||||
.orderByDesc(ObjUtil.equals(pars.getFileTypeSort(), 1), EdFileInfo::getSort);
|
||||
|
||||
if (StrUtil.isNotEmpty(pars.getKeyword())) {
|
||||
queryWrapper.and(qr -> qr.like(EdFileInfo::getFileName, pars.getKeyword())
|
||||
.or()
|
||||
.like(EdFileInfo::getFileCode, pars.getKeyword())
|
||||
.or()
|
||||
.like(EdFileInfo::getFileNote, pars.getKeyword())
|
||||
.or()
|
||||
.like(EdFileInfo::getFileContent, pars.getKeyword()));
|
||||
}
|
||||
|
||||
if (!UserThreadLocal.getAdminType().equals(AdminTypeEnum.SYSTEM.getValue())) {
|
||||
List<String> accessibleTree = permissionService.getAccessibleTree();
|
||||
if (CollUtil.isNotEmpty(accessibleTree)) {
|
||||
for (String permission : accessibleTree) {
|
||||
queryWrapper.or().likeRight(EdFileInfo::getFileCode, permission);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Page<EdFileInfo> edFileInfoPage = this.edFileInfoMapper.selectPage(new Page<>(pars.getPageNum(), pars.getPageSize()), queryWrapper);
|
||||
long total = edFileInfoPage.getTotal();
|
||||
List<FileRecycleQueryVO> records = BeanUtil.copyToList(edFileInfoPage.getRecords(), FileRecycleQueryVO.class);
|
||||
resetRes(records);
|
||||
UserThreadLocal.setSuccessInfo("", "", "查询所有删除文件成功");
|
||||
return ElectromagneticResultUtil.success(new RespPageVO<>(total, records));
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
@Transactional(rollbackFor = Exception.class)
|
||||
public ElectromagneticResult<?> remove(String fileId) {
|
||||
|
||||
// 备份该文件
|
||||
List<EdFileInfo> edFileInfos = this.edFileInfoMapper.selectList(Wrappers.lambdaQuery(EdFileInfo.class)
|
||||
.select(EdFileInfo.class, file -> !file.getColumn().equals("file_content"))
|
||||
.eq(EdFileInfo::getFileId, fileId));
|
||||
List<String> fileSysPaths = new ArrayList<>();
|
||||
for (EdFileInfo edFileInfo : edFileInfos) {
|
||||
String fileSysPath = commonService.getFileSysPath(edFileInfo.getFilePath(), edFileInfo.getDataOwn());
|
||||
FileBackupLog fileBackupLog = backupTask.getBaseMapper().selectOne(Wrappers.lambdaQuery(FileBackupLog.class).eq(FileBackupLog::getFileId, edFileInfo.getId()));
|
||||
|
||||
String saveFileName = edFileInfo.getFileName() + "." + edFileInfo.getFileType() + "." + edFileInfo.getFileCode();
|
||||
|
||||
// 表示从没有备份过该文件
|
||||
if (fileBackupLog != null) {
|
||||
long startTime = System.currentTimeMillis();
|
||||
BackupFileResLog backup = backupTask.backup(fileSysPath);
|
||||
long endTime = System.currentTimeMillis();
|
||||
|
||||
FileBackupLog backupLog = FileBackupLog.builder()
|
||||
.id(IdWorker.getSnowFlakeIdString())
|
||||
.fileId(edFileInfo.getId())
|
||||
.startTime(startTime)
|
||||
.endTime(endTime)
|
||||
.duration(endTime - startTime)
|
||||
.fileTime(FileUtil.lastModifiedTime(fileSysPath).getTime())
|
||||
.createTime(new Date())
|
||||
.fileName(saveFileName)
|
||||
.source(FileBackupSource.SYS_BACKUP.code)
|
||||
.build();
|
||||
|
||||
if (backup.getBackupSuccess()) {
|
||||
backupLog.setBackupSuccess(true);
|
||||
backupTask.getBaseMapper().insert(backupLog);
|
||||
} else {
|
||||
backupLog.setBackupSuccess(false);
|
||||
backupLog.setFailInfoDetail(backup.getFailInfoDetail());
|
||||
backupTask.getBaseMapper().insert(backupLog);
|
||||
throw new BizException(StrFormatter.format("删除文件 {} 失败,原因 备份该文件出现错误,联系管理员查看日志", saveFileName));
|
||||
}
|
||||
|
||||
} else {
|
||||
long startTime = System.currentTimeMillis();
|
||||
BackupFileResLog backup = backupTask.backup(fileSysPath);
|
||||
long endTime = System.currentTimeMillis();
|
||||
fileBackupLog.setStartTime(startTime)
|
||||
.setEndTime(endTime)
|
||||
.setDuration(endTime - startTime)
|
||||
.setFileTime(FileUtil.lastModifiedTime(fileSysPath).getTime())
|
||||
.setCreateTime(new Date())
|
||||
.setFileName(saveFileName);
|
||||
if (backup.getBackupSuccess()) {
|
||||
fileBackupLog.setBackupSuccess(true);
|
||||
backupTask.getBaseMapper().update(fileBackupLog, null);
|
||||
} else {
|
||||
fileBackupLog.setBackupSuccess(false);
|
||||
fileBackupLog.setFailInfoDetail(backup.getFailInfoDetail());
|
||||
backupTask.getBaseMapper().update(fileBackupLog, null);
|
||||
throw new BizException(StrFormatter.format("删除文件 {} 失败,原因 备份该文件出现错误,联系管理员查看日志", saveFileName));
|
||||
}
|
||||
}
|
||||
fileSysPaths.add(fileSysPath);
|
||||
}
|
||||
|
||||
// 移动到tmp目录,七天后删除
|
||||
for (String fileSysPath : fileSysPaths) {
|
||||
fileSystemService.moveFile(fileSysPath, elePropertyConfig.getTmpDir() + File.separator + new File(fileSysPath).getName());
|
||||
}
|
||||
|
||||
// 更新MySQL数据库
|
||||
this.edFileInfoMapper.update(null, Wrappers.lambdaUpdate(EdFileInfo.class)
|
||||
.eq(EdFileInfo::getFileId, fileId)
|
||||
.set(EdFileInfo::getEffectFlag, EffectFlagEnum.NOT_EFFECTIVE.code)
|
||||
.set(EdFileInfo::getPermanentDeleted, true)
|
||||
.set(EdFileInfo::getAllDeleted, true));
|
||||
UserThreadLocal.setSuccessInfo("", "", "删除文件 {} 成功,文件id {}", edFileInfos.get(0).getFileName() + "." + edFileInfos.get(0).getFileType(), fileId);
|
||||
return ElectromagneticResultUtil.success("删除文件成功");
|
||||
}
|
||||
|
||||
@Override
|
||||
public ElectromagneticResult<?> recover(String fileId) {
|
||||
|
||||
List<EdFileInfo> edFileInfos = this.edFileInfoMapper.selectList(Wrappers.lambdaQuery(EdFileInfo.class)
|
||||
.select(EdFileInfo.class, file -> !file.getColumn().equals("file_content"))
|
||||
.orderByDesc(EdFileInfo::getUpdatedTime)
|
||||
.eq(EdFileInfo::getFileId, fileId)
|
||||
.last("limit 1"));
|
||||
EdFileInfo edFileInfo = edFileInfos.get(0);
|
||||
edFileInfo.setEffectFlag(EffectFlagEnum.EFFECT.code);
|
||||
this.edFileInfoMapper.update(edFileInfo, null);
|
||||
UserThreadLocal.setSuccessInfo(edFileInfo.getParentId(), edFileInfo.getId(), "还原文件 {} 成功,文件id为 {}", edFileInfo.getFileName() + "." + edFileInfo.getFileType(), fileId);
|
||||
return ElectromagneticResultUtil.success("还原文件成功");
|
||||
}
|
||||
|
||||
private void resetRes(List<FileRecycleQueryVO> records) {
|
||||
List<String> userIds = records.stream().map(FileRecycleQueryVO::getUpdatedBy).collect(Collectors.toList());
|
||||
Map<String, String> idNameMap = userMapper.selectList(Wrappers.<User>lambdaQuery().in(User::getId, userIds)).stream().collect(Collectors.toMap(User::getUserId, User::getUserName));
|
||||
records.forEach(e -> {
|
||||
e.setFileSizeShow(EleCommonUtil.convertFileSize(e.getFileSize()));
|
||||
e.setUserName(idNameMap.get(e.getUpdatedBy()));
|
||||
});
|
||||
}
|
||||
}
|
||||
|
|
@ -9,13 +9,11 @@ import com.baomidou.mybatisplus.core.toolkit.Wrappers;
|
|||
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
||||
import com.electromagnetic.industry.software.common.pojo.BackupFileResLog;
|
||||
import com.electromagnetic.industry.software.common.resp.ElectromagneticResult;
|
||||
import com.electromagnetic.industry.software.manage.mapper.EleFileBackupLogMapper;
|
||||
import com.electromagnetic.industry.software.manage.pojo.models.EleFileBackupLog;
|
||||
import org.springframework.core.env.Environment;
|
||||
import org.springframework.scheduling.annotation.Scheduled;
|
||||
import com.electromagnetic.industry.software.manage.config.ElePropertyConfig;
|
||||
import com.electromagnetic.industry.software.manage.mapper.FileBackupLogMapper;
|
||||
import com.electromagnetic.industry.software.manage.pojo.models.FileBackupLog;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
import javax.annotation.PostConstruct;
|
||||
import javax.annotation.Resource;
|
||||
import java.io.File;
|
||||
import java.io.FileFilter;
|
||||
|
|
@ -25,35 +23,25 @@ import java.util.List;
|
|||
import java.util.Map;
|
||||
|
||||
@Component
|
||||
public class BackupTask extends ServiceImpl<EleFileBackupLogMapper, EleFileBackupLog> {
|
||||
public class BackupTask extends ServiceImpl<FileBackupLogMapper, FileBackupLog> {
|
||||
|
||||
private String host;
|
||||
private int port;
|
||||
|
||||
private String prjDir;
|
||||
|
||||
@Resource
|
||||
private Environment environment;
|
||||
|
||||
@PostConstruct
|
||||
public void init() {
|
||||
String osName = System.getProperty("os.name").toLowerCase();
|
||||
String tmp = osName.startsWith("win") ? environment.getProperty("data.windows.path") : environment.getProperty("data.linux.path");
|
||||
prjDir = FileUtil.getParent(tmp, 1);
|
||||
}
|
||||
private ElePropertyConfig elePropertyConfig;
|
||||
|
||||
// @Scheduled(cron = "0 0 1 * * ?")
|
||||
public void backup() {
|
||||
long lastFileTime = getLastFileTime();
|
||||
List<File> files = filter(lastFileTime, prjDir);
|
||||
List<File> files = filter(lastFileTime, elePropertyConfig.getPrjDir());
|
||||
for (File file : files) {
|
||||
String fileCode = getFileCode(file);
|
||||
Date reqStartTime = new Date();
|
||||
BackupFileResLog resLog = backup(file.getAbsolutePath());
|
||||
Date reqEndTime = new Date();
|
||||
EleFileBackupLog resDb = new EleFileBackupLog(reqStartTime, reqEndTime, file.lastModified(), fileCode);
|
||||
BeanUtil.copyProperties(resLog, resDb);
|
||||
this.saveOrUpdate(resDb);
|
||||
|
||||
// this.saveOrUpdate(resDb);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -69,9 +57,9 @@ public class BackupTask extends ServiceImpl<EleFileBackupLogMapper, EleFileBacku
|
|||
}
|
||||
|
||||
private long getLastFileTime() {
|
||||
List<EleFileBackupLog> eleFileBackupLogs = this.baseMapper.selectList(Wrappers.lambdaQuery(EleFileBackupLog.class)
|
||||
.select(EleFileBackupLog::getFileTime)
|
||||
.orderByDesc(EleFileBackupLog::getFileTime)
|
||||
List<FileBackupLog> eleFileBackupLogs = this.baseMapper.selectList(Wrappers.lambdaQuery(FileBackupLog.class)
|
||||
.select(FileBackupLog::getFileTime)
|
||||
.orderByDesc(FileBackupLog::getFileTime)
|
||||
.last("limit 1"));
|
||||
if (eleFileBackupLogs.isEmpty()) {
|
||||
return 0L;
|
||||
|
|
@ -79,7 +67,7 @@ public class BackupTask extends ServiceImpl<EleFileBackupLogMapper, EleFileBacku
|
|||
return eleFileBackupLogs.get(0).getFileTime();
|
||||
}
|
||||
|
||||
private BackupFileResLog backup(String filePath) {
|
||||
public BackupFileResLog backup(String filePath) {
|
||||
String prjPath = "";
|
||||
Map<String, Object> map = new HashMap<>();
|
||||
map.put("file", new File(filePath));
|
||||
|
|
|
|||
|
|
@ -0,0 +1,14 @@
|
|||
package com.electromagnetic.industry.software.common.enums;
|
||||
|
||||
import lombok.AllArgsConstructor;
|
||||
|
||||
@AllArgsConstructor
|
||||
public enum FileBackupSource {
|
||||
|
||||
SYS_BACKUP(0, "系统备份"),
|
||||
REMOVE(1, "删除文件");
|
||||
|
||||
public int code;
|
||||
public String desc;
|
||||
|
||||
}
|
||||
|
|
@ -8,9 +8,14 @@ import java.util.Date;
|
|||
@Data
|
||||
@Builder
|
||||
public class BackupFileResLog {
|
||||
|
||||
private Date backupStartTime;
|
||||
|
||||
private String fileName;
|
||||
private Boolean backupStatus;
|
||||
|
||||
private Boolean backupSuccess;
|
||||
|
||||
private Date backupEndTime;
|
||||
|
||||
private String failInfoDetail;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -122,4 +122,17 @@ public final class EleCommonUtil {
|
|||
}
|
||||
return stringBuilder.toString();
|
||||
}
|
||||
|
||||
public static String convertFileSize(long size) {
|
||||
if (size < 1024) {
|
||||
return size + "B";
|
||||
} else if (size < 1024 * 1024) {
|
||||
return String.format("%.2f KB", size / 1024.0);
|
||||
} else if (size < 1024 * 1024 * 1024) {
|
||||
return String.format("%.2f MB", size / (1024.0 * 1024));
|
||||
} else {
|
||||
return String.format("%.2f GB", size / (1024.0 * 1024 * 1024));
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in New Issue