代码重构
This commit is contained in:
parent
31c69e84a8
commit
2006343cc7
@ -11,11 +11,13 @@ public interface IFileService extends IService<FileBean> {
|
|||||||
|
|
||||||
void batchInsertFile(List<FileBean> fileBeanList, Long userId);
|
void batchInsertFile(List<FileBean> fileBeanList, Long userId);
|
||||||
//void updateFile(FileBean fileBean);
|
//void updateFile(FileBean fileBean);
|
||||||
List<FileBean> selectFileByNameAndPath(String fileName, String filePath);
|
|
||||||
|
|
||||||
|
public void increaseFilePointCount(Long fileId);
|
||||||
|
|
||||||
|
public void decreaseFilePointCount(Long fileId);
|
||||||
List<FileBean> selectFilePathTreeByUserId(FileBean fileBean);
|
List<FileBean> selectFilePathTreeByUserId(FileBean fileBean);
|
||||||
List<FileBean> selectFileListByPath(FileBean fileBean);
|
List<FileBean> selectFileListByPath(FileBean fileBean);
|
||||||
void replaceFilePath(String filePath, String oldFilePath);
|
|
||||||
|
|
||||||
|
|
||||||
List<FileBean> selectFileTreeListLikeFilePath(String filePath);
|
List<FileBean> selectFileTreeListLikeFilePath(String filePath);
|
||||||
|
@ -21,7 +21,7 @@ public interface IFiletransferService {
|
|||||||
* @param request 请求
|
* @param request 请求
|
||||||
* @param UploadFileDto 文件信息
|
* @param UploadFileDto 文件信息
|
||||||
*/
|
*/
|
||||||
void uploadFile(HttpServletRequest request, UploadFileDto UploadFileDto, UserBean sessionUserBean);
|
void uploadFile(HttpServletRequest request, UploadFileDto UploadFileDto, Long userId);
|
||||||
|
|
||||||
StorageBean selectStorageBean(StorageBean storageBean);
|
StorageBean selectStorageBean(StorageBean storageBean);
|
||||||
|
|
||||||
|
@ -1,7 +1,12 @@
|
|||||||
package com.qiwenshare.file.api;
|
package com.qiwenshare.file.api;
|
||||||
|
|
||||||
import com.baomidou.mybatisplus.extension.service.IService;
|
import com.baomidou.mybatisplus.extension.service.IService;
|
||||||
|
import com.qiwenshare.file.domain.FileBean;
|
||||||
import com.qiwenshare.file.domain.UserFile;
|
import com.qiwenshare.file.domain.UserFile;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
public interface IUserFileService extends IService<UserFile> {
|
public interface IUserFileService extends IService<UserFile> {
|
||||||
|
List<UserFile> selectUserFileByNameAndPath(String fileName, String filePath, Long userId);
|
||||||
|
void replaceUserFilePath(String filePath, String oldFilePath, Long userId);
|
||||||
}
|
}
|
||||||
|
@ -16,10 +16,7 @@ import com.qiwenshare.file.domain.FileBean;
|
|||||||
import com.qiwenshare.file.domain.TreeNode;
|
import com.qiwenshare.file.domain.TreeNode;
|
||||||
import com.qiwenshare.file.domain.UserBean;
|
import com.qiwenshare.file.domain.UserBean;
|
||||||
import com.qiwenshare.file.domain.UserFile;
|
import com.qiwenshare.file.domain.UserFile;
|
||||||
import com.qiwenshare.file.dto.BatchDeleteFileDto;
|
import com.qiwenshare.file.dto.*;
|
||||||
import com.qiwenshare.file.dto.BatchMoveFileDto;
|
|
||||||
import com.qiwenshare.file.dto.MoveFileDto;
|
|
||||||
import com.qiwenshare.file.dto.RenameFileDto;
|
|
||||||
import com.qiwenshare.file.service.UserFileService;
|
import com.qiwenshare.file.service.UserFileService;
|
||||||
import lombok.extern.slf4j.Slf4j;
|
import lombok.extern.slf4j.Slf4j;
|
||||||
import org.apache.commons.lang3.ArrayUtils;
|
import org.apache.commons.lang3.ArrayUtils;
|
||||||
@ -56,29 +53,29 @@ public class FileController {
|
|||||||
*/
|
*/
|
||||||
@RequestMapping(value = "/createfile", method = RequestMethod.POST)
|
@RequestMapping(value = "/createfile", method = RequestMethod.POST)
|
||||||
@ResponseBody
|
@ResponseBody
|
||||||
public RestResult<String> createFile(@RequestBody FileBean fileBean, @RequestHeader("token") String token) {
|
public RestResult<String> createFile(@RequestBody CreateFileDto createFileDto, @RequestHeader("token") String token) {
|
||||||
RestResult<String> restResult = new RestResult<>();
|
RestResult<String> restResult = new RestResult<>();
|
||||||
if (!operationCheck(token).isSuccess()){
|
if (!operationCheck(token).isSuccess()){
|
||||||
return operationCheck(token);
|
return operationCheck(token);
|
||||||
}
|
}
|
||||||
List<FileBean> fileBeans = fileService.selectFileByNameAndPath(fileBean.getFileName(), fileBean.getFilePath());
|
|
||||||
if (fileBeans != null && !fileBeans.isEmpty()) {
|
UserBean sessionUserBean = userService.getUserBeanByToken(token);
|
||||||
|
|
||||||
|
List<UserFile> userFiles = userFileService.selectUserFileByNameAndPath(createFileDto.getFileName(), createFileDto.getFilePath(), sessionUserBean.getUserId());
|
||||||
|
if (userFiles != null && !userFiles.isEmpty()) {
|
||||||
restResult.setErrorMessage("同名文件已存在");
|
restResult.setErrorMessage("同名文件已存在");
|
||||||
restResult.setSuccess(false);
|
restResult.setSuccess(false);
|
||||||
return restResult;
|
return restResult;
|
||||||
}
|
}
|
||||||
UserBean sessionUserBean = userService.getUserBeanByToken(token);
|
|
||||||
|
|
||||||
// fileBean.setUserId(sessionUserBean.getUserId());
|
|
||||||
|
|
||||||
fileBean.setUploadTime(DateUtil.getCurrentTime());
|
|
||||||
|
|
||||||
fileService.save(fileBean);
|
|
||||||
|
|
||||||
UserFile userFile = new UserFile();
|
UserFile userFile = new UserFile();
|
||||||
userFile.setFileId(fileBean.getFileId());
|
|
||||||
userFile.setUserId(sessionUserBean.getUserId());
|
userFile.setUserId(sessionUserBean.getUserId());
|
||||||
|
userFile.setFileName(createFileDto.getFileName());
|
||||||
|
userFile.setFilePath(createFileDto.getFilePath());
|
||||||
userFile.setDeleteFlag(0);
|
userFile.setDeleteFlag(0);
|
||||||
|
userFile.setIsDir(1);
|
||||||
|
userFile.setUploadTime(DateUtil.getCurrentTime());
|
||||||
|
|
||||||
userFileService.save(userFile);
|
userFileService.save(userFile);
|
||||||
|
|
||||||
restResult.setSuccess(true);
|
restResult.setSuccess(true);
|
||||||
@ -100,43 +97,53 @@ public class FileController {
|
|||||||
UserBean sessionUserBean = userService.getUserBeanByToken(token);
|
UserBean sessionUserBean = userService.getUserBeanByToken(token);
|
||||||
// fileBean.setUserId(sessionUserBean.getUserId());
|
// fileBean.setUserId(sessionUserBean.getUserId());
|
||||||
// fileBean.setUploadTime(DateUtil.getCurrentTime());
|
// fileBean.setUploadTime(DateUtil.getCurrentTime());
|
||||||
List<FileBean> fileBeans = fileService.selectFileByNameAndPath(renameFileDto.getFileName(), renameFileDto.getFilePath());
|
List<UserFile> userFiles = userFileService.selectUserFileByNameAndPath(renameFileDto.getFileName(), renameFileDto.getFilePath(), sessionUserBean.getUserId());
|
||||||
if (fileBeans != null && !fileBeans.isEmpty()) {
|
if (userFiles != null && !userFiles.isEmpty()) {
|
||||||
restResult.setErrorMessage("同名文件已存在");
|
restResult.setErrorMessage("同名文件已存在");
|
||||||
restResult.setSuccess(false);
|
restResult.setSuccess(false);
|
||||||
return restResult;
|
return restResult;
|
||||||
}
|
}
|
||||||
if (1 == renameFileDto.getIsDir()) {
|
if (1 == renameFileDto.getIsDir()) {
|
||||||
LambdaUpdateWrapper<FileBean> lambdaUpdateWrapper = new LambdaUpdateWrapper<>();
|
LambdaUpdateWrapper<UserFile> lambdaUpdateWrapper = new LambdaUpdateWrapper<>();
|
||||||
lambdaUpdateWrapper.set(FileBean::getFileName, renameFileDto.getFileName())
|
lambdaUpdateWrapper.set(UserFile::getFileName, renameFileDto.getFileName())
|
||||||
.set(FileBean::getUploadTime, DateUtil.getCurrentTime())
|
.set(UserFile::getUploadTime, DateUtil.getCurrentTime())
|
||||||
.eq(FileBean::getFileId, renameFileDto.getFileId());
|
.eq(UserFile::getUserFileId, renameFileDto.getUserFileId());
|
||||||
fileService.update(lambdaUpdateWrapper);
|
userFileService.update(lambdaUpdateWrapper);
|
||||||
fileService.replaceFilePath(renameFileDto.getFilePath() + renameFileDto.getFileName() + "/",
|
userFileService.replaceUserFilePath(renameFileDto.getFilePath() + renameFileDto.getFileName() + "/",
|
||||||
renameFileDto.getFilePath() + renameFileDto.getOldFileName() + "/");
|
renameFileDto.getFilePath() + renameFileDto.getOldFileName() + "/", sessionUserBean.getUserId());
|
||||||
// fileBean.setOldFilePath(renameFileDto.getFilePath() + renameFileDto.getOldFileName() + "/");
|
|
||||||
// fileBean.setFilePath(renameFileDto.getFilePath() + renameFileDto.getFileName() + "/");
|
|
||||||
} else {
|
} else {
|
||||||
if (renameFileDto.getIsOSS() == 1) {
|
if (renameFileDto.getIsOSS() == 1) {
|
||||||
FileBean file = fileService.getById(renameFileDto.getFileId());
|
LambdaQueryWrapper<UserFile> lambdaQueryWrapper = new LambdaQueryWrapper<>();
|
||||||
|
lambdaQueryWrapper.eq(UserFile::getUserFileId, renameFileDto.getUserFileId());
|
||||||
|
UserFile userFile = userFileService.getOne(lambdaQueryWrapper);
|
||||||
|
|
||||||
|
FileBean file = fileService.getById(userFile.getFileId());
|
||||||
String fileUrl = file.getFileUrl();
|
String fileUrl = file.getFileUrl();
|
||||||
String newFileUrl = fileUrl.replace(file.getFileName(), renameFileDto.getFileName());
|
String newFileUrl = fileUrl.replace(userFile.getFileName(), renameFileDto.getFileName());
|
||||||
// renameFileDto.setFileUrl(newFileUrl);
|
// renameFileDto.setFileUrl(newFileUrl);
|
||||||
AliyunOSSRename.rename(qiwenFileConfig.getAliyun().getOss(),
|
AliyunOSSRename.rename(qiwenFileConfig.getAliyun().getOss(),
|
||||||
fileUrl.substring(1),
|
fileUrl.substring(1),
|
||||||
newFileUrl.substring(1));
|
newFileUrl.substring(1));
|
||||||
LambdaUpdateWrapper<FileBean> lambdaUpdateWrapper = new LambdaUpdateWrapper<>();
|
LambdaUpdateWrapper<FileBean> lambdaUpdateWrapper = new LambdaUpdateWrapper<>();
|
||||||
lambdaUpdateWrapper.set(FileBean::getFileName, renameFileDto.getFileName())
|
lambdaUpdateWrapper
|
||||||
.set(FileBean::getUploadTime, DateUtil.getCurrentTime())
|
// .set(FileBean::getFileName, renameFileDto.getFileName())
|
||||||
|
// .set(FileBean::getUploadTime, DateUtil.getCurrentTime())
|
||||||
.set(FileBean::getFileUrl, newFileUrl)
|
.set(FileBean::getFileUrl, newFileUrl)
|
||||||
.eq(FileBean::getFileId, renameFileDto.getFileId());
|
.eq(FileBean::getFileId, file.getFileId());
|
||||||
fileService.update(lambdaUpdateWrapper);
|
fileService.update(lambdaUpdateWrapper);
|
||||||
|
|
||||||
|
LambdaUpdateWrapper<UserFile> userFileLambdaUpdateWrapper = new LambdaUpdateWrapper<>();
|
||||||
|
userFileLambdaUpdateWrapper
|
||||||
|
.set(UserFile::getFileName, renameFileDto.getFileName())
|
||||||
|
.set(UserFile::getUploadTime, DateUtil.getCurrentTime())
|
||||||
|
.eq(UserFile::getUserFileId, renameFileDto.getUserFileId());
|
||||||
|
userFileService.update(userFileLambdaUpdateWrapper);
|
||||||
} else {
|
} else {
|
||||||
LambdaUpdateWrapper<FileBean> lambdaUpdateWrapper = new LambdaUpdateWrapper<>();
|
LambdaUpdateWrapper<UserFile> lambdaUpdateWrapper = new LambdaUpdateWrapper<>();
|
||||||
lambdaUpdateWrapper.set(FileBean::getFileName, renameFileDto.getFileName())
|
lambdaUpdateWrapper.set(UserFile::getFileName, renameFileDto.getFileName())
|
||||||
.set(FileBean::getUploadTime, DateUtil.getCurrentTime())
|
.set(UserFile::getUploadTime, DateUtil.getCurrentTime())
|
||||||
.eq(FileBean::getFileId, renameFileDto.getFileId());
|
.eq(UserFile::getUserFileId, renameFileDto.getUserFileId());
|
||||||
fileService.update(lambdaUpdateWrapper);
|
userFileService.update(lambdaUpdateWrapper);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -12,11 +12,13 @@ import com.qiwenshare.common.util.PathUtil;
|
|||||||
import com.qiwenshare.common.cbb.RestResult;
|
import com.qiwenshare.common.cbb.RestResult;
|
||||||
import com.qiwenshare.file.api.IFileService;
|
import com.qiwenshare.file.api.IFileService;
|
||||||
import com.qiwenshare.file.api.IFiletransferService;
|
import com.qiwenshare.file.api.IFiletransferService;
|
||||||
|
import com.qiwenshare.file.api.IUserFileService;
|
||||||
import com.qiwenshare.file.api.IUserService;
|
import com.qiwenshare.file.api.IUserService;
|
||||||
import com.qiwenshare.file.config.QiwenFileConfig;
|
import com.qiwenshare.file.config.QiwenFileConfig;
|
||||||
import com.qiwenshare.file.domain.FileBean;
|
import com.qiwenshare.file.domain.FileBean;
|
||||||
import com.qiwenshare.file.domain.StorageBean;
|
import com.qiwenshare.file.domain.StorageBean;
|
||||||
import com.qiwenshare.file.domain.UserBean;
|
import com.qiwenshare.file.domain.UserBean;
|
||||||
|
import com.qiwenshare.file.domain.UserFile;
|
||||||
import com.qiwenshare.file.dto.UploadFileDto;
|
import com.qiwenshare.file.dto.UploadFileDto;
|
||||||
import com.qiwenshare.file.vo.file.UploadFileVo;
|
import com.qiwenshare.file.vo.file.UploadFileVo;
|
||||||
import org.springframework.beans.factory.annotation.Autowired;
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
@ -46,6 +48,8 @@ public class FiletransferController {
|
|||||||
IFileService fileService;
|
IFileService fileService;
|
||||||
@Resource
|
@Resource
|
||||||
IUserService userService;
|
IUserService userService;
|
||||||
|
@Resource
|
||||||
|
IUserFileService userFileService;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 上传文件
|
* 上传文件
|
||||||
@ -76,14 +80,17 @@ public class FiletransferController {
|
|||||||
List<FileBean> list = fileService.listByMap(param);
|
List<FileBean> list = fileService.listByMap(param);
|
||||||
if (list != null && !list.isEmpty()) {
|
if (list != null && !list.isEmpty()) {
|
||||||
FileBean file = list.get(0);
|
FileBean file = list.get(0);
|
||||||
file.setUserId(sessionUserBean.getUserId());
|
|
||||||
file.setUploadTime(DateUtil.getCurrentTime());
|
UserFile userFile = new UserFile();
|
||||||
file.setFilePath(uploadFileDto.getFilePath());
|
userFile.setFileId(file.getFileId());
|
||||||
|
userFile.setUserId(sessionUserBean.getUserId());
|
||||||
|
userFile.setFilePath(uploadFileDto.getFilePath());
|
||||||
String fileName = uploadFileDto.getFilename();
|
String fileName = uploadFileDto.getFilename();
|
||||||
file.setFileName(fileName.substring(0, fileName.lastIndexOf(".")));
|
userFile.setFileName(fileName.substring(0, fileName.lastIndexOf(".")));
|
||||||
file.setExtendName(FileUtil.getFileType(fileName));
|
userFile.setExtendName(FileUtil.getFileType(fileName));
|
||||||
file.setPointCount(file.getPointCount() + 1);
|
userFile.setDeleteFlag(0);
|
||||||
fileService.save(file);
|
userFileService.save(userFile);
|
||||||
|
fileService.increaseFilePointCount(file.getFileId());
|
||||||
uploadFileVo.setSkipUpload(true);
|
uploadFileVo.setSkipUpload(true);
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
@ -92,7 +99,6 @@ public class FiletransferController {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
//fileBean.setUserId(sessionUserBean.getUserId());
|
|
||||||
restResult.setData(uploadFileVo);
|
restResult.setData(uploadFileVo);
|
||||||
restResult.setSuccess(true);
|
restResult.setSuccess(true);
|
||||||
return restResult;
|
return restResult;
|
||||||
@ -107,7 +113,7 @@ public class FiletransferController {
|
|||||||
@RequestMapping(value = "/uploadfile", method = RequestMethod.POST)
|
@RequestMapping(value = "/uploadfile", method = RequestMethod.POST)
|
||||||
@ResponseBody
|
@ResponseBody
|
||||||
public RestResult<UploadFileVo> uploadFile(HttpServletRequest request, UploadFileDto uploadFileDto, @RequestHeader("token") String token) {
|
public RestResult<UploadFileVo> uploadFile(HttpServletRequest request, UploadFileDto uploadFileDto, @RequestHeader("token") String token) {
|
||||||
RestResult<UploadFileVo> restResult = new RestResult<UploadFileVo>();
|
RestResult<UploadFileVo> restResult = new RestResult<>();
|
||||||
UserBean sessionUserBean = userService.getUserBeanByToken(token);
|
UserBean sessionUserBean = userService.getUserBeanByToken(token);
|
||||||
if (sessionUserBean == null){
|
if (sessionUserBean == null){
|
||||||
restResult.setSuccess(false);
|
restResult.setSuccess(false);
|
||||||
@ -121,97 +127,12 @@ public class FiletransferController {
|
|||||||
return restResult;
|
return restResult;
|
||||||
}
|
}
|
||||||
|
|
||||||
uploadFileDto.setUserId(sessionUserBean.getUserId());
|
filetransferService.uploadFile(request, uploadFileDto, sessionUserBean.getUserId());
|
||||||
|
|
||||||
filetransferService.uploadFile(request, uploadFileDto, sessionUserBean);
|
|
||||||
UploadFileVo uploadFileVo = new UploadFileVo();
|
UploadFileVo uploadFileVo = new UploadFileVo();
|
||||||
uploadFileVo.setTimeStampName(uploadFileDto.getTimeStampName());
|
|
||||||
restResult.setData(uploadFileVo);
|
restResult.setData(uploadFileVo);
|
||||||
return restResult;
|
return restResult;
|
||||||
}
|
}
|
||||||
/**
|
|
||||||
* 下载文件
|
|
||||||
*
|
|
||||||
* @return
|
|
||||||
*/
|
|
||||||
@RequestMapping(value = "/downloadfile", method = RequestMethod.GET)
|
|
||||||
public String downloadFile(HttpServletResponse response, FileBean fileBean) {
|
|
||||||
RestResult<String> restResult = new RestResult<>();
|
|
||||||
String fileName = null;// 文件名
|
|
||||||
try {
|
|
||||||
fileName = new String(fileBean.getFileName().getBytes("utf-8"), "ISO-8859-1");
|
|
||||||
} catch (UnsupportedEncodingException e) {
|
|
||||||
e.printStackTrace();
|
|
||||||
}
|
|
||||||
fileName = fileName + "." + fileBean.getExtendName();
|
|
||||||
response.setContentType("application/force-download");// 设置强制下载不打开
|
|
||||||
response.addHeader("Content-Disposition", "attachment;fileName=" + fileName);// 设置文件名
|
|
||||||
byte[] buffer = new byte[1024];
|
|
||||||
BufferedInputStream bis = null;
|
|
||||||
FileBean fileBean1 = fileService.getById(fileBean.getFileId());
|
|
||||||
if (fileBean1.getIsOSS() != null && fileBean1.getIsOSS() == 1) {
|
|
||||||
|
|
||||||
AliyunOSSDownload aliyunOSSDownload= new AliyunOSSDownload();
|
|
||||||
OSS ossClient = aliyunOSSDownload.createOSSClient(qiwenFileConfig.getAliyun().getOss());
|
|
||||||
OSSObject ossObject = ossClient.getObject(qiwenFileConfig.getAliyun().getOss().getBucketName(), fileBean1.getTimeStampName());
|
|
||||||
InputStream inputStream = ossObject.getObjectContent();
|
|
||||||
try {
|
|
||||||
bis = new BufferedInputStream(inputStream);
|
|
||||||
OutputStream os = response.getOutputStream();
|
|
||||||
int i = bis.read(buffer);
|
|
||||||
while (i != -1) {
|
|
||||||
os.write(buffer, 0, i);
|
|
||||||
i = bis.read(buffer);
|
|
||||||
}
|
|
||||||
} catch (IOException e) {
|
|
||||||
e.printStackTrace();
|
|
||||||
} finally {
|
|
||||||
if (bis != null) {
|
|
||||||
try {
|
|
||||||
bis.close();
|
|
||||||
} catch (IOException e) {
|
|
||||||
e.printStackTrace();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
ossClient.shutdown();
|
|
||||||
} else {
|
|
||||||
//设置文件路径
|
|
||||||
File file = FileOperation.newFile(PathUtil.getStaticPath() + fileBean.getFileUrl());
|
|
||||||
if (file.exists()) {
|
|
||||||
|
|
||||||
|
|
||||||
FileInputStream fis = null;
|
|
||||||
|
|
||||||
try {
|
|
||||||
fis = new FileInputStream(file);
|
|
||||||
bis = new BufferedInputStream(fis);
|
|
||||||
OutputStream os = response.getOutputStream();
|
|
||||||
int i = bis.read(buffer);
|
|
||||||
while (i != -1) {
|
|
||||||
os.write(buffer, 0, i);
|
|
||||||
i = bis.read(buffer);
|
|
||||||
}
|
|
||||||
|
|
||||||
} catch (Exception e) {
|
|
||||||
e.printStackTrace();
|
|
||||||
} finally {
|
|
||||||
if (bis != null) {
|
|
||||||
try {
|
|
||||||
bis.close();
|
|
||||||
} catch (IOException e) {
|
|
||||||
e.printStackTrace();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
return null;
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 获取存储信息
|
* 获取存储信息
|
||||||
|
@ -25,30 +25,15 @@ public class FileBean {
|
|||||||
@Column(columnDefinition="bigint(20) comment '文件id'")
|
@Column(columnDefinition="bigint(20) comment '文件id'")
|
||||||
private Long fileId;
|
private Long fileId;
|
||||||
|
|
||||||
@Column(columnDefinition="varchar(500) comment '文件url'")
|
|
||||||
private String fileUrl;
|
|
||||||
|
|
||||||
@Column(columnDefinition="varchar(500) comment '文件路径'")
|
|
||||||
private String filePath;
|
|
||||||
|
|
||||||
@Column(columnDefinition="varchar(25) comment '上传时间'")
|
|
||||||
private String uploadTime;
|
|
||||||
|
|
||||||
@Column(columnDefinition="varchar(50) comment '时间戳名称'")
|
@Column(columnDefinition="varchar(50) comment '时间戳名称'")
|
||||||
private String timeStampName;
|
private String timeStampName;
|
||||||
|
|
||||||
@Column(columnDefinition="varchar(10) comment '扩展名'")
|
@Column(columnDefinition="varchar(500) comment '文件url'")
|
||||||
private String extendName;
|
private String fileUrl;
|
||||||
|
|
||||||
@Column(columnDefinition="varchar(100) comment '文件名'")
|
|
||||||
private String fileName;
|
|
||||||
|
|
||||||
@Column(columnDefinition="bigint(10) comment '文件大小'")
|
@Column(columnDefinition="bigint(10) comment '文件大小'")
|
||||||
private Long fileSize;
|
private Long fileSize;
|
||||||
|
|
||||||
@Column(columnDefinition="int(1) comment '是否是目录 0-否, 1-是'")
|
|
||||||
private Integer isDir;
|
|
||||||
|
|
||||||
@Column(columnDefinition="int(1) comment '是否是OSS云存储 0-否, 1-是'")
|
@Column(columnDefinition="int(1) comment '是否是OSS云存储 0-否, 1-是'")
|
||||||
private Integer isOSS;
|
private Integer isOSS;
|
||||||
|
|
||||||
|
@ -21,6 +21,21 @@ public class UserFile {
|
|||||||
@Column(columnDefinition="bigint(20) comment '文件id'")
|
@Column(columnDefinition="bigint(20) comment '文件id'")
|
||||||
private Long fileId;
|
private Long fileId;
|
||||||
|
|
||||||
|
@Column(columnDefinition="varchar(100) comment '文件名'")
|
||||||
|
private String fileName;
|
||||||
|
|
||||||
|
@Column(columnDefinition="varchar(500) comment '文件路径'")
|
||||||
|
private String filePath;
|
||||||
|
|
||||||
|
@Column(columnDefinition="varchar(10) comment '扩展名'")
|
||||||
|
private String extendName;
|
||||||
|
|
||||||
|
@Column(columnDefinition="int(1) comment '是否是目录 0-否, 1-是'")
|
||||||
|
private Integer isDir;
|
||||||
|
|
||||||
|
@Column(columnDefinition="varchar(25) comment '上传时间'")
|
||||||
|
private String uploadTime;
|
||||||
|
|
||||||
@Column(columnDefinition="int(11) comment '文件删除标志 0/null-正常, 1-删除'")
|
@Column(columnDefinition="int(11) comment '文件删除标志 0/null-正常, 1-删除'")
|
||||||
private Integer deleteFlag;
|
private Integer deleteFlag;
|
||||||
|
|
||||||
|
@ -0,0 +1,9 @@
|
|||||||
|
package com.qiwenshare.file.dto;
|
||||||
|
|
||||||
|
import lombok.Data;
|
||||||
|
|
||||||
|
@Data
|
||||||
|
public class CreateFileDto {
|
||||||
|
private String fileName;
|
||||||
|
private String filePath;
|
||||||
|
}
|
@ -4,7 +4,7 @@ import lombok.Data;
|
|||||||
|
|
||||||
@Data
|
@Data
|
||||||
public class RenameFileDto {
|
public class RenameFileDto {
|
||||||
private Long fileId;
|
private Long userFileId;
|
||||||
/**
|
/**
|
||||||
* 文件路径
|
* 文件路径
|
||||||
*/
|
*/
|
||||||
|
@ -13,17 +13,6 @@ import javax.persistence.*;
|
|||||||
@Schema(name = "上传文件DTO",required = true)
|
@Schema(name = "上传文件DTO",required = true)
|
||||||
public class UploadFileDto {
|
public class UploadFileDto {
|
||||||
|
|
||||||
private Long fileId;
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
private Long userId;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 文件URL
|
|
||||||
*/
|
|
||||||
private String fileUrl;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 文件路径
|
* 文件路径
|
||||||
*/
|
*/
|
||||||
@ -34,11 +23,6 @@ public class UploadFileDto {
|
|||||||
*/
|
*/
|
||||||
private String uploadTime;
|
private String uploadTime;
|
||||||
|
|
||||||
/**
|
|
||||||
* 时间戳名称
|
|
||||||
*/
|
|
||||||
private String timeStampName;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 扩展名
|
* 扩展名
|
||||||
*/
|
*/
|
||||||
@ -54,25 +38,6 @@ public class UploadFileDto {
|
|||||||
*/
|
*/
|
||||||
private Long fileSize;
|
private Long fileSize;
|
||||||
|
|
||||||
/**
|
|
||||||
* 是否是目录
|
|
||||||
*/
|
|
||||||
private Integer isDir;
|
|
||||||
|
|
||||||
private Integer isOSS;
|
|
||||||
|
|
||||||
private Integer pointCount;
|
|
||||||
|
|
||||||
private String oldFilePath;
|
|
||||||
|
|
||||||
private String oldFileName;
|
|
||||||
|
|
||||||
private String files;
|
|
||||||
|
|
||||||
private Integer fileType;
|
|
||||||
|
|
||||||
private String taskId;
|
|
||||||
|
|
||||||
private int chunkNumber;
|
private int chunkNumber;
|
||||||
|
|
||||||
private long chunkSize;
|
private long chunkSize;
|
||||||
|
@ -13,7 +13,7 @@ public interface FileMapper extends BaseMapper<FileBean> {
|
|||||||
void batchInsertFile(List<FileBean> fileBeanList);
|
void batchInsertFile(List<FileBean> fileBeanList);
|
||||||
// void updateFile(FileBean fileBean);
|
// void updateFile(FileBean fileBean);
|
||||||
|
|
||||||
void replaceFilePath(@Param("filePath") String filePath, @Param("oldFilePath") String oldFilePath);
|
|
||||||
|
|
||||||
void updateFilepathByFilepath(String oldfilePath, String newfilePath);
|
void updateFilepathByFilepath(String oldfilePath, String newfilePath);
|
||||||
void updateFilepathByPathAndName(String oldfilePath, String newfilePath, String fileName, String extendName);
|
void updateFilepathByPathAndName(String oldfilePath, String newfilePath, String fileName, String extendName);
|
||||||
|
@ -3,7 +3,11 @@ package com.qiwenshare.file.mapper;
|
|||||||
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
|
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
|
||||||
import com.qiwenshare.file.domain.UserBean;
|
import com.qiwenshare.file.domain.UserBean;
|
||||||
import com.qiwenshare.file.domain.UserFile;
|
import com.qiwenshare.file.domain.UserFile;
|
||||||
|
import org.apache.ibatis.annotations.Param;
|
||||||
|
|
||||||
|
import java.util.Map;
|
||||||
|
|
||||||
public interface UserFileMapper extends BaseMapper<UserFile> {
|
public interface UserFileMapper extends BaseMapper<UserFile> {
|
||||||
|
void replaceFilePath(@Param("filePath") String filePath, @Param("oldFilePath") String oldFilePath, @Param("userId") Long userId);
|
||||||
|
Map<String, Object> userFileList(UserFile userFile);
|
||||||
}
|
}
|
||||||
|
@ -53,18 +53,27 @@ public class FileService extends ServiceImpl<FileMapper, FileBean> implements IF
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void increaseFilePointCount(Long fileId) {
|
||||||
|
FileBean fileBean = fileMapper.selectById(fileId);
|
||||||
|
fileBean.setPointCount(fileBean.getPointCount()+1);
|
||||||
|
fileMapper.updateById(fileBean);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void decreaseFilePointCount(Long fileId) {
|
||||||
|
FileBean fileBean = fileMapper.selectById(fileId);
|
||||||
|
fileBean.setPointCount(fileBean.getPointCount()-1);
|
||||||
|
fileMapper.updateById(fileBean);
|
||||||
|
}
|
||||||
|
|
||||||
// @Override
|
// @Override
|
||||||
// public void updateFile(FileBean fileBean) {
|
// public void updateFile(FileBean fileBean) {
|
||||||
// fileBean.setUploadTime(DateUtil.getCurrentTime());
|
// fileBean.setUploadTime(DateUtil.getCurrentTime());
|
||||||
// fileMapper.updateFile(fileBean);
|
// fileMapper.updateFile(fileBean);
|
||||||
// }
|
// }
|
||||||
|
|
||||||
@Override
|
|
||||||
public List<FileBean> selectFileByNameAndPath(String fileName, String filePath) {
|
|
||||||
LambdaQueryWrapper<FileBean> lambdaQueryWrapper = new LambdaQueryWrapper<>();
|
|
||||||
lambdaQueryWrapper.eq(FileBean::getFileName, fileName).eq(FileBean::getFilePath, filePath);
|
|
||||||
return fileMapper.selectList(lambdaQueryWrapper);
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@ -83,10 +92,7 @@ public class FileService extends ServiceImpl<FileMapper, FileBean> implements IF
|
|||||||
return fileMapper.selectList(lambdaQueryWrapper);
|
return fileMapper.selectList(lambdaQueryWrapper);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
|
||||||
public void replaceFilePath(String filePath, String oldFilePath) {
|
|
||||||
fileMapper.replaceFilePath(filePath, oldFilePath);
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -17,12 +17,14 @@ import com.qiwenshare.file.api.IFiletransferService;
|
|||||||
|
|
||||||
import com.qiwenshare.common.domain.AliyunOSS;
|
import com.qiwenshare.common.domain.AliyunOSS;
|
||||||
import com.qiwenshare.file.config.QiwenFileConfig;
|
import com.qiwenshare.file.config.QiwenFileConfig;
|
||||||
|
import com.qiwenshare.file.domain.UserFile;
|
||||||
import com.qiwenshare.file.dto.UploadFileDto;
|
import com.qiwenshare.file.dto.UploadFileDto;
|
||||||
import com.qiwenshare.file.mapper.FileMapper;
|
import com.qiwenshare.file.mapper.FileMapper;
|
||||||
import com.qiwenshare.file.domain.FileBean;
|
import com.qiwenshare.file.domain.FileBean;
|
||||||
import com.qiwenshare.file.domain.StorageBean;
|
import com.qiwenshare.file.domain.StorageBean;
|
||||||
import com.qiwenshare.file.domain.UserBean;
|
import com.qiwenshare.file.domain.UserBean;
|
||||||
import com.qiwenshare.file.mapper.StorageMapper;
|
import com.qiwenshare.file.mapper.StorageMapper;
|
||||||
|
import com.qiwenshare.file.mapper.UserFileMapper;
|
||||||
import org.springframework.stereotype.Service;
|
import org.springframework.stereotype.Service;
|
||||||
|
|
||||||
|
|
||||||
@ -36,11 +38,13 @@ public class FiletransferService implements IFiletransferService {
|
|||||||
|
|
||||||
@Resource
|
@Resource
|
||||||
QiwenFileConfig qiwenFileConfig;
|
QiwenFileConfig qiwenFileConfig;
|
||||||
|
@Resource
|
||||||
|
UserFileMapper userFileMapper;
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void uploadFile(HttpServletRequest request, UploadFileDto UploadFileDto, UserBean sessionUserBean) {
|
public void uploadFile(HttpServletRequest request, UploadFileDto UploadFileDto, Long userId) {
|
||||||
AliyunOSS oss = qiwenFileConfig.getAliyun().getOss();
|
AliyunOSS oss = qiwenFileConfig.getAliyun().getOss();
|
||||||
request.setAttribute("oss", oss);
|
request.setAttribute("oss", oss);
|
||||||
Uploader uploader;
|
Uploader uploader;
|
||||||
@ -66,19 +70,27 @@ public class FiletransferService implements IFiletransferService {
|
|||||||
if (uploadFile.getSuccess() == 1){
|
if (uploadFile.getSuccess() == 1){
|
||||||
fileBean.setFileUrl(uploadFile.getUrl());
|
fileBean.setFileUrl(uploadFile.getUrl());
|
||||||
fileBean.setFileSize(uploadFile.getFileSize());
|
fileBean.setFileSize(uploadFile.getFileSize());
|
||||||
fileBean.setFileName(uploadFile.getFileName());
|
//fileBean.setUploadTime(DateUtil.getCurrentTime());
|
||||||
fileBean.setExtendName(uploadFile.getFileType());
|
|
||||||
fileBean.setUploadTime(DateUtil.getCurrentTime());
|
|
||||||
fileBean.setIsOSS(uploadFile.getIsOSS());
|
fileBean.setIsOSS(uploadFile.getIsOSS());
|
||||||
fileBean.setIsDir(0);
|
|
||||||
fileBean.setPointCount(1);
|
fileBean.setPointCount(1);
|
||||||
fileMapper.insert(fileBean);
|
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.setUserId(userId);
|
||||||
|
userFile.setIsDir(0);
|
||||||
|
userFile.setUploadTime(DateUtil.getCurrentTime());
|
||||||
|
userFileMapper.insert(userFile);
|
||||||
|
|
||||||
synchronized (FiletransferService.class) {
|
synchronized (FiletransferService.class) {
|
||||||
long sessionUserId = sessionUserBean.getUserId();
|
|
||||||
StorageBean storageBean = selectStorageBean(new StorageBean(sessionUserId));
|
StorageBean storageBean = selectStorageBean(new StorageBean(userId));
|
||||||
if (storageBean == null) {
|
if (storageBean == null) {
|
||||||
StorageBean storage = new StorageBean(sessionUserId);
|
StorageBean storage = new StorageBean(userId);
|
||||||
storage.setStorageSize(fileBean.getFileSize());
|
storage.setStorageSize(fileBean.getFileSize());
|
||||||
insertStorageBean(storage);
|
insertStorageBean(storage);
|
||||||
} else {
|
} else {
|
||||||
|
@ -1,9 +1,28 @@
|
|||||||
package com.qiwenshare.file.service;
|
package com.qiwenshare.file.service;
|
||||||
|
|
||||||
|
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
||||||
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
||||||
import com.qiwenshare.file.api.IUserFileService;
|
import com.qiwenshare.file.api.IUserFileService;
|
||||||
|
import com.qiwenshare.file.domain.FileBean;
|
||||||
import com.qiwenshare.file.domain.UserFile;
|
import com.qiwenshare.file.domain.UserFile;
|
||||||
|
import com.qiwenshare.file.mapper.FileMapper;
|
||||||
import com.qiwenshare.file.mapper.UserFileMapper;
|
import com.qiwenshare.file.mapper.UserFileMapper;
|
||||||
|
|
||||||
|
import javax.annotation.Resource;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
public class UserFileService extends ServiceImpl<UserFileMapper, UserFile> implements IUserFileService {
|
public class UserFileService extends ServiceImpl<UserFileMapper, UserFile> implements IUserFileService {
|
||||||
|
@Resource
|
||||||
|
UserFileMapper userFileMapper;
|
||||||
|
@Override
|
||||||
|
public List<UserFile> selectUserFileByNameAndPath(String fileName, String filePath, Long userId) {
|
||||||
|
LambdaQueryWrapper<UserFile> lambdaQueryWrapper = new LambdaQueryWrapper<>();
|
||||||
|
lambdaQueryWrapper.eq(UserFile::getFileName, fileName).eq(UserFile::getFilePath, filePath).eq(UserFile::getUserId, userId);
|
||||||
|
return userFileMapper.selectList(lambdaQueryWrapper);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void replaceUserFilePath(String filePath, String oldFilePath, Long userId) {
|
||||||
|
userFileMapper.replaceFilePath(filePath, oldFilePath, userId);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -18,9 +18,7 @@
|
|||||||
</foreach>
|
</foreach>
|
||||||
</insert>
|
</insert>
|
||||||
|
|
||||||
<update id="replaceFilePath" parameterType="java.lang.String">
|
|
||||||
UPDATE file SET filepath=REPLACE(filepath, #{oldFilePath}, #{filePath}) WHERE filepath LIKE N'${oldFilePath}%';
|
|
||||||
</update>
|
|
||||||
|
|
||||||
<!-- <update id="updateFile" parameterType="java">-->
|
<!-- <update id="updateFile" parameterType="java">-->
|
||||||
<!-- <choose>-->
|
<!-- <choose>-->
|
||||||
|
@ -6,7 +6,15 @@
|
|||||||
|
|
||||||
<mapper namespace="com.qiwenshare.file.mapper.UserFileMapper">
|
<mapper namespace="com.qiwenshare.file.mapper.UserFileMapper">
|
||||||
|
|
||||||
<select id="selectFileListByPath" >
|
<update id="replaceFilePath">
|
||||||
|
UPDATE userfile SET filepath=REPLACE(filepath, #{oldFilePath}, #{filePath})
|
||||||
|
WHERE filepath LIKE N'${oldFilePath}%' and userId = #{userId};
|
||||||
|
</update>
|
||||||
|
|
||||||
|
<select id="userFileList" parameterType="com.qiwenshare.file.domain.UserFile" resultType="java.util.Map">
|
||||||
|
select * from userfile
|
||||||
|
left join file on file.fileId = userfile.fileId
|
||||||
|
where userId = #{userId}
|
||||||
|
|
||||||
</select>
|
</select>
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user