|
@@ -3,7 +3,7 @@
|
|
|
*
|
|
|
*/
|
|
|
|
|
|
-package org.eco.vip.nexus.core.service.file;
|
|
|
+package org.eco.vip.nexus.core.service.files;
|
|
|
|
|
|
|
|
|
import cn.hutool.core.io.FileUtil;
|
|
@@ -22,15 +22,16 @@ import org.eco.vip.core.utils.ImgUtils;
|
|
|
import org.eco.vip.core.utils.IoUtils;
|
|
|
import org.eco.vip.core.utils.MapstructUtils;
|
|
|
import org.eco.vip.core.utils.StrUtils;
|
|
|
-import org.eco.vip.nexus.core.domain.file.File;
|
|
|
-import org.eco.vip.nexus.core.domain.file.pojo.FileBO;
|
|
|
-import org.eco.vip.nexus.core.domain.file.pojo.FileVO;
|
|
|
-import org.eco.vip.nexus.core.mapper.FileMapper;
|
|
|
+import org.eco.vip.nexus.core.domain.files.Files;
|
|
|
+import org.eco.vip.nexus.core.domain.files.pojo.FilesBO;
|
|
|
+import org.eco.vip.nexus.core.domain.files.pojo.FilesVO;
|
|
|
+import org.eco.vip.nexus.core.mapper.FilesMapper;
|
|
|
import org.eco.vip.orm.domain.PageQuery;
|
|
|
import org.eco.vip.orm.service.BaseService;
|
|
|
import org.springframework.stereotype.Service;
|
|
|
import org.springframework.web.multipart.MultipartFile;
|
|
|
|
|
|
+import java.io.File;
|
|
|
import java.io.IOException;
|
|
|
import java.util.List;
|
|
|
import java.util.UUID;
|
|
@@ -38,51 +39,51 @@ import java.util.UUID;
|
|
|
import static org.eco.vip.nexus.core.domain.file.table.FileTableDef.FILE;
|
|
|
|
|
|
/**
|
|
|
- * @description FileService
|
|
|
+ * @description FilesService
|
|
|
*
|
|
|
* @author GaoKunW
|
|
|
* @date 2025/7/22 11:10
|
|
|
*/
|
|
|
@Service
|
|
|
@Slf4j
|
|
|
-public class FileService extends BaseService<FileMapper, File> implements IFileService {
|
|
|
+public class FilesService extends BaseService<FilesMapper, Files> implements IFilesService {
|
|
|
|
|
|
@Resource
|
|
|
- private FileMapper fileMapper;
|
|
|
+ private FilesMapper filesMapper;
|
|
|
|
|
|
- private QueryWrapper buildQueryWrapper(FileBO fileBO) {
|
|
|
+ private QueryWrapper buildQueryWrapper(FilesBO filesBO) {
|
|
|
return super.buildBaseQueryWrapper()
|
|
|
- .and(FILE.FILE_ID.eq(fileBO.getFileId()))
|
|
|
- .and(FILE.ENGINE.eq(fileBO.getEngine()))
|
|
|
- .and(FILE.BUCKET.eq(fileBO.getBucket()))
|
|
|
- .and(FILE.FILE_NAME.eq(fileBO.getFileName()))
|
|
|
- .and(FILE.ORIGINAL_NAME.eq(fileBO.getOriginalName()))
|
|
|
- .and(FILE.STATUS.eq(fileBO.getStatus()));
|
|
|
+ .and(FILE.FILE_ID.eq(filesBO.getFileId()))
|
|
|
+ .and(FILE.ENGINE.eq(filesBO.getEngine()))
|
|
|
+ .and(FILE.BUCKET.eq(filesBO.getBucket()))
|
|
|
+ .and(FILE.FILE_NAME.eq(filesBO.getFileName()))
|
|
|
+ .and(FILE.ORIGINAL_NAME.eq(filesBO.getOriginalName()))
|
|
|
+ .and(FILE.STATUS.eq(filesBO.getStatus()));
|
|
|
}
|
|
|
|
|
|
@Override
|
|
|
- public PageResult<FileVO> selectPage(FileBO fileBO) {
|
|
|
- QueryWrapper queryWrapper = buildQueryWrapper(fileBO);
|
|
|
- Page<FileVO> page = fileMapper.paginateWithRelationsAs(PageQuery.build(), queryWrapper, FileVO.class);
|
|
|
+ public PageResult<FilesVO> selectPage(FilesBO filesBO) {
|
|
|
+ QueryWrapper queryWrapper = buildQueryWrapper(filesBO);
|
|
|
+ Page<FilesVO> page = filesMapper.paginateWithRelationsAs(PageQuery.build(), queryWrapper, FilesVO.class);
|
|
|
return PageResult.build(page);
|
|
|
}
|
|
|
|
|
|
@Override
|
|
|
- public List<FileVO> selectList(FileBO fileBO) {
|
|
|
- QueryWrapper queryWrapper = buildQueryWrapper(fileBO);
|
|
|
- return fileMapper.selectListWithRelationsByQueryAs(queryWrapper, FileVO.class);
|
|
|
+ public List<FilesVO> selectList(FilesBO filesBO) {
|
|
|
+ QueryWrapper queryWrapper = buildQueryWrapper(filesBO);
|
|
|
+ return filesMapper.selectListWithRelationsByQueryAs(queryWrapper, FilesVO.class);
|
|
|
}
|
|
|
|
|
|
@Override
|
|
|
- public boolean insert(FileBO fileBO) {
|
|
|
- File file = MapstructUtils.convert(fileBO, File.class);
|
|
|
- return this.save(file);
|
|
|
+ public boolean insert(FilesBO filesBO) {
|
|
|
+ Files files = MapstructUtils.convert(filesBO, Files.class);
|
|
|
+ return this.save(files);
|
|
|
}
|
|
|
|
|
|
@Override
|
|
|
- public boolean update(FileBO fileBO) {
|
|
|
- File file = MapstructUtils.convert(fileBO, File.class);
|
|
|
- return this.updateById(file);
|
|
|
+ public boolean update(FilesBO filesBO) {
|
|
|
+ Files files = MapstructUtils.convert(filesBO, Files.class);
|
|
|
+ return this.updateById(files);
|
|
|
}
|
|
|
|
|
|
@Override
|
|
@@ -96,15 +97,15 @@ public class FileService extends BaseService<FileMapper, File> implements IFileS
|
|
|
}
|
|
|
|
|
|
@Override
|
|
|
- public FileVO selectById(String id) {
|
|
|
+ public FilesVO selectById(String id) {
|
|
|
QueryWrapper queryWrapper = query().where(FILE.FILE_ID.eq(id).when(StrUtils.isNotBlank(id))).and(FILE.FILE_ID.isNull().when(StrUtils.isBlank(id)));
|
|
|
- return this.getOneAs(queryWrapper, FileVO.class);
|
|
|
+ return this.getOneAs(queryWrapper, FilesVO.class);
|
|
|
}
|
|
|
|
|
|
@Override
|
|
|
- public List<FileVO> selectByUrl(List<String> urls) {
|
|
|
+ public List<FilesVO> selectByUrl(List<String> urls) {
|
|
|
QueryWrapper queryWrapper = query().where(FILE.DOWNLOAD_URL.in(urls));
|
|
|
- return fileMapper.selectListWithRelationsByQueryAs(queryWrapper, FileVO.class);
|
|
|
+ return filesMapper.selectListWithRelationsByQueryAs(queryWrapper, FilesVO.class);
|
|
|
}
|
|
|
|
|
|
@Override
|
|
@@ -132,36 +133,36 @@ public class FileService extends BaseService<FileMapper, File> implements IFileS
|
|
|
private String storageFile(String engine, MultipartFile file) {
|
|
|
String key = UUID.randomUUID().toString().replace("-", "");
|
|
|
String storageUrl = FileLocalUtils.storageFileWithReturnUrl("LocalBucket", key, file);
|
|
|
- File fileInfo = new File();
|
|
|
- fileInfo.setFileId(key);
|
|
|
- fileInfo.setEngine(engine);
|
|
|
- fileInfo.setBucket("LocalBucket");
|
|
|
- fileInfo.setOriginalName(file.getOriginalFilename());
|
|
|
- fileInfo.setDownloadUrl(storageUrl);
|
|
|
+ Files filesInfo = new Files();
|
|
|
+ filesInfo.setFileId(key);
|
|
|
+ filesInfo.setEngine(engine);
|
|
|
+ filesInfo.setBucket("LocalBucket");
|
|
|
+ filesInfo.setOriginalName(file.getOriginalFilename());
|
|
|
+ filesInfo.setDownloadUrl(storageUrl);
|
|
|
String suffix = ObjectUtil.isNotEmpty(file.getOriginalFilename()) ? StrUtil.subAfter(file.getOriginalFilename(),
|
|
|
StrUtil.DOT, true) : null;
|
|
|
- fileInfo.setFileSuffix(suffix);
|
|
|
- fileInfo.setSizeKb(12);
|
|
|
- fileInfo.setSizeInfo(FileUtils.readableFileSize(file.getSize()));
|
|
|
- fileInfo.setFileName(ObjectUtil.isNotEmpty(fileInfo.getFileSuffix()) ? key + StrUtil.DOT + fileInfo.getFileSuffix() : null);
|
|
|
+ filesInfo.setFileSuffix(suffix);
|
|
|
+ filesInfo.setSizeKb(12);
|
|
|
+ filesInfo.setSizeInfo(FileUtils.readableFileSize(file.getSize()));
|
|
|
+ filesInfo.setFileName(ObjectUtil.isNotEmpty(filesInfo.getFileSuffix()) ? key + StrUtil.DOT + filesInfo.getFileSuffix() : null);
|
|
|
if (ObjectUtil.isNotEmpty(suffix)) {
|
|
|
if (isPic(suffix)) {
|
|
|
try {
|
|
|
- fileInfo.setThumbnail(ImgUtils.toBase64DataUri(ImgUtils.scale(ImgUtils.toImage(file.getBytes()),
|
|
|
+ filesInfo.setThumbnail(ImgUtils.toBase64DataUri(ImgUtils.scale(ImgUtils.toImage(file.getBytes()),
|
|
|
100, 100, null), suffix));
|
|
|
} catch (Exception ignored) {
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
- fileInfo.setStorageUrl(storageUrl);
|
|
|
+ filesInfo.setStorageUrl(storageUrl);
|
|
|
|
|
|
- this.save(fileInfo);
|
|
|
+ this.save(filesInfo);
|
|
|
return "";
|
|
|
}
|
|
|
|
|
|
- private void unifiedDownload(FileBO fileBO, HttpServletResponse response, boolean isDownloadAuth) {
|
|
|
- FileVO fileVO = this.selectById(fileBO.getFileId());
|
|
|
- java.io.File file = FileUtils.file(fileVO.getStorageUrl());
|
|
|
+ private void unifiedDownload(FilesBO filesBO, HttpServletResponse response, boolean isDownloadAuth) {
|
|
|
+ FilesVO filesVO = this.selectById(filesBO.getFileId());
|
|
|
+ File file = FileUtils.file(filesVO.getStorageUrl());
|
|
|
if (!FileUtil.exist(file)) {
|
|
|
return;
|
|
|
}
|