1、相同路径下上传同名文件优化处理
2、图片预览优化(深度适配阿里云OSS,fastdfs增加缓存) 3、数据保存路径修改
This commit is contained in:
parent
450d87bbc8
commit
4e039d12eb
@ -4,6 +4,7 @@ import com.qiwenshare.file.domain.FileBean;
|
||||
import com.qiwenshare.file.domain.StorageBean;
|
||||
import com.qiwenshare.file.dto.DownloadFileDTO;
|
||||
import com.qiwenshare.file.dto.UploadFileDTO;
|
||||
import com.qiwenshare.file.dto.file.PreviewDTO;
|
||||
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
import javax.servlet.http.HttpServletResponse;
|
||||
@ -22,6 +23,7 @@ public interface IFiletransferService {
|
||||
void uploadFile(HttpServletRequest request, UploadFileDTO UploadFileDto, Long userId);
|
||||
|
||||
void downloadFile(HttpServletResponse httpServletResponse, DownloadFileDTO downloadFileDTO);
|
||||
void previewFile(HttpServletResponse httpServletResponse, PreviewDTO previewDTO);
|
||||
void deleteFile(FileBean fileBean);
|
||||
StorageBean selectStorageBean(StorageBean storageBean);
|
||||
|
||||
|
@ -36,12 +36,11 @@ public class FileDealComp {
|
||||
private IElasticSearchService elasticSearchService;
|
||||
public static Executor exec = Executors.newFixedThreadPool(10);
|
||||
|
||||
@Resource
|
||||
UFOFactory ufoFactory;
|
||||
/**
|
||||
* 获取重复文件名
|
||||
*
|
||||
* 场景: 文件还原时,在 savefilePath 路径下,保存 测试.txt 文件重名,则会生成 测试(1).txt
|
||||
* 场景1: 文件还原时,在 savefilePath 路径下,保存 测试.txt 文件重名,则会生成 测试(1).txt
|
||||
* 场景2: 上传文件时,在 savefilePath 路径下,保存 测试.txt 文件重名,则会生成 测试(1).txt
|
||||
*
|
||||
* @param userFile
|
||||
* @param savefilePath
|
||||
|
@ -2,9 +2,12 @@ package com.qiwenshare.file.config;
|
||||
|
||||
|
||||
import com.qiwenshare.file.interceptor.AuthenticationInterceptor;
|
||||
import joptsimple.util.PathProperties;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.context.annotation.Configuration;
|
||||
import org.springframework.web.bind.annotation.RestController;
|
||||
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
|
||||
import org.springframework.web.servlet.config.annotation.PathMatchConfigurer;
|
||||
import org.springframework.web.servlet.config.annotation.ResourceHandlerRegistry;
|
||||
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;
|
||||
|
||||
@ -44,11 +47,13 @@ public class WebMvcConfig implements WebMvcConfigurer {
|
||||
list.add("/share/**");
|
||||
registry.addInterceptor(authenticationInterceptor)
|
||||
.addPathPatterns(list)
|
||||
.excludePathPatterns("/filetransfer/downloadfile",
|
||||
.excludePathPatterns("/file",
|
||||
"/filetransfer/downloadfile",
|
||||
"/filetransfer/preview",
|
||||
"/share/sharefileList",
|
||||
"/share/sharetype",
|
||||
"/share/checkextractioncode",
|
||||
"/share/checkendtime");
|
||||
}
|
||||
|
||||
}
|
@ -45,7 +45,7 @@ import static com.qiwenshare.common.util.FileUtil.getFileExtendsByType;
|
||||
@Tag(name = "file", description = "该接口为文件接口,主要用来做一些文件的基本操作,如创建目录,删除,移动,复制等。")
|
||||
@RestController
|
||||
@Slf4j
|
||||
@RequestMapping("/file")
|
||||
@RequestMapping({"/file", "/api/file"})
|
||||
public class FileController {
|
||||
|
||||
@Resource
|
||||
|
@ -19,6 +19,7 @@ import com.qiwenshare.file.dto.DownloadFileDTO;
|
||||
import com.qiwenshare.file.dto.UploadFileDTO;
|
||||
import com.qiwenshare.file.dto.file.PreviewDTO;
|
||||
import com.qiwenshare.file.service.StorageService;
|
||||
import com.qiwenshare.file.vo.file.FileListVo;
|
||||
import com.qiwenshare.file.vo.file.UploadFileVo;
|
||||
import io.swagger.v3.oas.annotations.Operation;
|
||||
import io.swagger.v3.oas.annotations.tags.Tag;
|
||||
@ -30,6 +31,7 @@ import javax.annotation.Resource;
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
import javax.servlet.http.HttpServletResponse;
|
||||
import java.io.UnsupportedEncodingException;
|
||||
import java.sql.SQLIntegrityConstraintViolationException;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
@ -37,7 +39,7 @@ import java.util.Map;
|
||||
@Slf4j
|
||||
@Tag(name = "filetransfer", description = "该接口为文件传输接口,主要用来做文件的上传和下载")
|
||||
@RestController
|
||||
@RequestMapping("/filetransfer")
|
||||
@RequestMapping({"/filetransfer", "/api/filetransfer"})
|
||||
public class FiletransferController {
|
||||
|
||||
@Resource
|
||||
@ -77,19 +79,28 @@ public class FiletransferController {
|
||||
FileBean file = list.get(0);
|
||||
|
||||
UserFile userFile = new UserFile();
|
||||
userFile.setFileId(file.getFileId());
|
||||
|
||||
userFile.setUserId(sessionUserBean.getUserId());
|
||||
userFile.setFilePath(uploadFileDto.getFilePath());
|
||||
String fileName = uploadFileDto.getFilename();
|
||||
userFile.setFileName(fileName.substring(0, fileName.lastIndexOf(".")));
|
||||
userFile.setFileName(FileUtil.getFileNameNotExtend(fileName));
|
||||
userFile.setExtendName(FileUtil.getFileExtendName(fileName));
|
||||
userFile.setDeleteFlag(0);
|
||||
userFile.setIsDir(0);
|
||||
userFile.setUploadTime(DateUtil.getCurrentTime());
|
||||
userFileService.save(userFile);
|
||||
fileService.increaseFilePointCount(file.getFileId());
|
||||
List<FileListVo> userFileList = userFileService.userFileList(userFile, null, null);
|
||||
if (userFileList.size() <= 0) {
|
||||
|
||||
userFile.setIsDir(0);
|
||||
userFile.setUploadTime(DateUtil.getCurrentTime());
|
||||
userFile.setFileId(file.getFileId());
|
||||
//"fileName", "filePath", "extendName", "deleteFlag", "userId"
|
||||
|
||||
userFileService.save(userFile);
|
||||
fileService.increaseFilePointCount(file.getFileId());
|
||||
fileDealComp.uploadESByUserFileId(userFile.getUserFileId());
|
||||
}
|
||||
|
||||
uploadFileVo.setSkipUpload(true);
|
||||
fileDealComp.uploadESByUserFileId(userFile.getUserFileId());
|
||||
|
||||
} else {
|
||||
uploadFileVo.setSkipUpload(false);
|
||||
|
||||
@ -171,11 +182,9 @@ public class FiletransferController {
|
||||
}
|
||||
|
||||
httpServletResponse.addHeader("Content-Disposition", "fileName=" + fileName);// 设置文件名
|
||||
DownloadFileDTO downloadFileDTO = new DownloadFileDTO();
|
||||
downloadFileDTO.setUserFileId(previewDTO.getUserFileId());
|
||||
downloadFileDTO.setIsMin(previewDTO.getIsMin());
|
||||
|
||||
try {
|
||||
filetransferService.downloadFile(httpServletResponse, downloadFileDTO);
|
||||
filetransferService.previewFile(httpServletResponse, previewDTO);
|
||||
}catch (Exception e){
|
||||
//org.apache.catalina.connector.ClientAbortException: java.io.IOException: 你的主机中的软件中止了一个已建立的连接。
|
||||
e.printStackTrace();
|
||||
|
@ -28,7 +28,7 @@ import java.util.List;
|
||||
@Tag(name = "recoveryfile", description = "文件删除后会进入回收站,该接口主要是对回收站文件进行管理")
|
||||
@RestController
|
||||
@Slf4j
|
||||
@RequestMapping("/recoveryfile")
|
||||
@RequestMapping({"/recoveryfile", "/api/recoveryfile"})
|
||||
public class RecoveryFileController {
|
||||
@Resource
|
||||
IRecoveryFileService recoveryFileService;
|
||||
|
@ -32,7 +32,7 @@ import java.util.*;
|
||||
@Tag(name = "share", description = "该接口为文件分享接口")
|
||||
@RestController
|
||||
@Slf4j
|
||||
@RequestMapping("/share")
|
||||
@RequestMapping({"/share", "/api/share"})
|
||||
public class ShareController {
|
||||
|
||||
public static final String CURRENT_MODULE = "文件分享";
|
||||
|
@ -28,7 +28,7 @@ import java.util.Map;
|
||||
@Tag(name = "user", description = "该接口为用户接口,主要做用户登录,注册和校验token")
|
||||
@RestController
|
||||
@Slf4j
|
||||
@RequestMapping("/user")
|
||||
@RequestMapping({"/user", "/api/user"})
|
||||
public class UserController {
|
||||
|
||||
@Resource
|
||||
@ -102,8 +102,6 @@ public class UserController {
|
||||
}
|
||||
UserBean sessionUserBean = userService.getUserBeanByToken(token);
|
||||
if (sessionUserBean != null) {
|
||||
String domain = UFOAutoConfiguration.aliyunConfig.getOss().getDomain();
|
||||
sessionUserBean.setViewDomain(domain);
|
||||
return RestResult.success().data(sessionUserBean);
|
||||
|
||||
} else {
|
||||
|
@ -96,10 +96,6 @@ public class UserBean {
|
||||
@TableField(exist = false)
|
||||
private String token;
|
||||
|
||||
@Transient
|
||||
@TableField(exist = false)
|
||||
private String viewDomain;
|
||||
|
||||
/**
|
||||
* 角色列表
|
||||
*/
|
||||
|
@ -7,5 +7,4 @@ import lombok.Data;
|
||||
@Schema(name = "下载文件DTO",required = true)
|
||||
public class DownloadFileDTO {
|
||||
private Long userFileId;
|
||||
private String isMin;
|
||||
}
|
||||
|
@ -16,19 +16,6 @@ public class UploadFileDTO {
|
||||
@Schema(description = "文件路径")
|
||||
private String filePath;
|
||||
|
||||
/**
|
||||
* 上传时间
|
||||
*/
|
||||
@Schema(description = "上传时间")
|
||||
private String uploadTime;
|
||||
|
||||
/**
|
||||
* 扩展名
|
||||
*/
|
||||
@Schema(description = "扩展名")
|
||||
private String extendName;
|
||||
|
||||
|
||||
@Schema(description = "文件名")
|
||||
private String filename;
|
||||
|
||||
|
@ -24,11 +24,14 @@ import com.qiwenshare.file.component.FileDealComp;
|
||||
import com.qiwenshare.file.domain.UserFile;
|
||||
import com.qiwenshare.file.dto.DownloadFileDTO;
|
||||
import com.qiwenshare.file.dto.UploadFileDTO;
|
||||
import com.qiwenshare.file.dto.file.PreviewDTO;
|
||||
import com.qiwenshare.file.mapper.FileMapper;
|
||||
import com.qiwenshare.file.domain.FileBean;
|
||||
import com.qiwenshare.file.domain.StorageBean;
|
||||
import com.qiwenshare.file.mapper.StorageMapper;
|
||||
import com.qiwenshare.file.mapper.UserFileMapper;
|
||||
import com.qiwenshare.file.vo.file.FileListVo;
|
||||
import com.qiwenshare.ufo.exception.DownloadException;
|
||||
import com.qiwenshare.ufo.exception.UploadException;
|
||||
import com.qiwenshare.ufo.factory.StorageTypeEnum;
|
||||
import com.qiwenshare.ufo.factory.UFOFactory;
|
||||
@ -36,6 +39,8 @@ import com.qiwenshare.ufo.operation.delete.Deleter;
|
||||
import com.qiwenshare.ufo.operation.delete.domain.DeleteFile;
|
||||
import com.qiwenshare.ufo.operation.download.Downloader;
|
||||
import com.qiwenshare.ufo.operation.download.domain.DownloadFile;
|
||||
import com.qiwenshare.ufo.operation.preview.Previewer;
|
||||
import com.qiwenshare.ufo.operation.preview.domain.PreviewFile;
|
||||
import com.qiwenshare.ufo.operation.upload.Uploader;
|
||||
import com.qiwenshare.ufo.operation.upload.domain.UploadFile;
|
||||
import com.qiwenshare.ufo.util.PathUtil;
|
||||
@ -62,16 +67,16 @@ public class FiletransferService implements IFiletransferService {
|
||||
FileDealComp fileDealComp;
|
||||
|
||||
@Override
|
||||
public void uploadFile(HttpServletRequest request, UploadFileDTO UploadFileDto, Long userId) {
|
||||
public void uploadFile(HttpServletRequest request, UploadFileDTO uploadFileDto, Long userId) {
|
||||
|
||||
|
||||
UploadFile uploadFile = new UploadFile();
|
||||
uploadFile.setChunkNumber(UploadFileDto.getChunkNumber());
|
||||
uploadFile.setChunkSize(UploadFileDto.getChunkSize());
|
||||
uploadFile.setTotalChunks(UploadFileDto.getTotalChunks());
|
||||
uploadFile.setIdentifier(UploadFileDto.getIdentifier());
|
||||
uploadFile.setTotalSize(UploadFileDto.getTotalSize());
|
||||
uploadFile.setCurrentChunkSize(UploadFileDto.getCurrentChunkSize());
|
||||
uploadFile.setChunkNumber(uploadFileDto.getChunkNumber());
|
||||
uploadFile.setChunkSize(uploadFileDto.getChunkSize());
|
||||
uploadFile.setTotalChunks(uploadFileDto.getTotalChunks());
|
||||
uploadFile.setIdentifier(uploadFileDto.getIdentifier());
|
||||
uploadFile.setTotalSize(uploadFileDto.getTotalSize());
|
||||
uploadFile.setCurrentChunkSize(uploadFileDto.getCurrentChunkSize());
|
||||
|
||||
Uploader uploader = ufoFactory.getUploader();
|
||||
if (uploader == null) {
|
||||
@ -83,7 +88,7 @@ public class FiletransferService implements IFiletransferService {
|
||||
for (int i = 0; i < uploadFileList.size(); i++){
|
||||
uploadFile = uploadFileList.get(i);
|
||||
FileBean fileBean = new FileBean();
|
||||
BeanUtil.copyProperties(UploadFileDto, fileBean);
|
||||
BeanUtil.copyProperties(uploadFileDto, fileBean);
|
||||
fileBean.setTimeStampName(uploadFile.getTimeStampName());
|
||||
if (uploadFile.getSuccess() == 1){
|
||||
fileBean.setFileUrl(uploadFile.getUrl());
|
||||
@ -92,13 +97,19 @@ public class FiletransferService implements IFiletransferService {
|
||||
fileBean.setPointCount(1);
|
||||
fileMapper.insert(fileBean);
|
||||
UserFile userFile = new UserFile();
|
||||
userFile.setFileId(fileBean.getFileId());
|
||||
userFile.setExtendName(uploadFile.getFileType());
|
||||
userFile.setFileName(uploadFile.getFileName());
|
||||
userFile.setFilePath(UploadFileDto.getFilePath());
|
||||
userFile.setDeleteFlag(0);
|
||||
userFile.setFilePath(uploadFileDto.getFilePath());
|
||||
userFile.setUserId(userId);
|
||||
userFile.setFileName(uploadFile.getFileName());
|
||||
userFile.setExtendName(uploadFile.getFileType());
|
||||
userFile.setDeleteFlag(0);
|
||||
userFile.setIsDir(0);
|
||||
List<FileListVo> userFileList = userFileMapper.userFileList(userFile, null, null);
|
||||
if (userFileList.size() > 0) {
|
||||
String fileName = fileDealComp.getRepeatFileName(userFile, uploadFileDto.getFilePath());
|
||||
userFile.setFileName(fileName);
|
||||
}
|
||||
userFile.setFileId(fileBean.getFileId());
|
||||
|
||||
userFile.setUploadTime(DateUtil.getCurrentTime());
|
||||
userFileMapper.insert(userFile);
|
||||
fileDealComp.uploadESByUserFileId(userFile.getUserFileId());
|
||||
@ -118,14 +129,11 @@ public class FiletransferService implements IFiletransferService {
|
||||
Downloader downloader = ufoFactory.getDownloader(fileBean.getStorageType());
|
||||
if (downloader == null) {
|
||||
log.error("下载失败,文件存储类型不支持下载,storageType:{}", fileBean.getStorageType());
|
||||
throw new UploadException("下载失败");
|
||||
throw new DownloadException("下载失败");
|
||||
}
|
||||
DownloadFile downloadFile = new DownloadFile();
|
||||
if ("true".equals(downloadFileDTO.getIsMin())) {
|
||||
downloadFile.setFileUrl(fileBean.getFileUrl().replace("." + userFile.getExtendName(), "_min." + userFile.getExtendName()));
|
||||
} else {
|
||||
downloadFile.setFileUrl(fileBean.getFileUrl());
|
||||
}
|
||||
|
||||
downloadFile.setFileUrl(fileBean.getFileUrl());
|
||||
downloadFile.setFileSize(fileBean.getFileSize());
|
||||
|
||||
downloader.download(httpServletResponse, downloadFile);
|
||||
@ -210,6 +218,26 @@ public class FiletransferService implements IFiletransferService {
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void previewFile(HttpServletResponse httpServletResponse, PreviewDTO previewDTO) {
|
||||
UserFile userFile = userFileMapper.selectById(previewDTO.getUserFileId());
|
||||
FileBean fileBean = fileMapper.selectById(userFile.getFileId());
|
||||
Previewer previewer = ufoFactory.getPreviewer(fileBean.getStorageType());
|
||||
if (previewer == null) {
|
||||
log.error("预览失败,文件存储类型不支持预览,storageType:{}", fileBean.getStorageType());
|
||||
throw new UploadException("预览失败");
|
||||
}
|
||||
PreviewFile previewFile = new PreviewFile();
|
||||
previewFile.setFileUrl(fileBean.getFileUrl());
|
||||
previewFile.setFileSize(fileBean.getFileSize());
|
||||
if ("true".equals(previewDTO.getIsMin())) {
|
||||
previewer.imageThumbnailPreview(httpServletResponse, previewFile);
|
||||
} else {
|
||||
previewer.imageOriginalPreview(httpServletResponse, previewFile);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void deleteFile(FileBean fileBean) {
|
||||
Deleter deleter = null;
|
||||
|
@ -1,8 +1,9 @@
|
||||
|
||||
#jdbc连接-h2数据库
|
||||
spring.datasource.driverClassName=org.h2.Driver
|
||||
spring.datasource.url = jdbc:h2:file:D:/temp_db/file;MODE=MYSQL;DATABASE_TO_LOWER=TRUE
|
||||
spring.datasource.url = jdbc:h2:file:C:/ProgramData/QiwenNetDisk/file;MODE=MYSQL;DATABASE_TO_LOWER=TRUE
|
||||
spring.datasource.username=sa
|
||||
spring.datasource.password=
|
||||
spring.h2.console.enabled=true
|
||||
|
||||
|
||||
|
@ -27,6 +27,9 @@
|
||||
<if test="userFile.userFileId != null">
|
||||
and a.userFileId = #{userFile.userFileId}
|
||||
</if>
|
||||
<if test="userFile.fileName != null">
|
||||
and a.fileName = #{userFile.fileName}
|
||||
</if>
|
||||
and a.deleteFlag = 0
|
||||
</where>
|
||||
ORDER BY isDir desc
|
||||
|
Loading…
Reference in New Issue
Block a user