代码优化
This commit is contained in:
parent
4fd4e96906
commit
3646db5880
@ -10,11 +10,12 @@ 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(FileBean fileBean);
|
List<FileBean> selectFileByNameAndPath(String fileName, String filePath);
|
||||||
|
|
||||||
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);
|
||||||
|
@ -4,6 +4,7 @@ import com.qiwenshare.common.cbb.RestResult;
|
|||||||
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.dto.UploadFileDto;
|
||||||
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
@ -18,9 +19,9 @@ public interface IFiletransferService {
|
|||||||
/**
|
/**
|
||||||
* 上传文件
|
* 上传文件
|
||||||
* @param request 请求
|
* @param request 请求
|
||||||
* @param fileBean 文件信息
|
* @param UploadFileDto 文件信息
|
||||||
*/
|
*/
|
||||||
void uploadFile(HttpServletRequest request, FileBean fileBean, UserBean sessionUserBean);
|
void uploadFile(HttpServletRequest request, UploadFileDto UploadFileDto, UserBean sessionUserBean);
|
||||||
|
|
||||||
StorageBean selectStorageBean(StorageBean storageBean);
|
StorageBean selectStorageBean(StorageBean storageBean);
|
||||||
|
|
||||||
|
@ -2,6 +2,7 @@ package com.qiwenshare.file.controller;
|
|||||||
|
|
||||||
import com.alibaba.fastjson.JSON;
|
import com.alibaba.fastjson.JSON;
|
||||||
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
||||||
|
import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper;
|
||||||
import com.qiwenshare.common.cbb.DateUtil;
|
import com.qiwenshare.common.cbb.DateUtil;
|
||||||
import com.qiwenshare.common.cbb.RestResult;
|
import com.qiwenshare.common.cbb.RestResult;
|
||||||
import com.qiwenshare.common.operation.FileOperation;
|
import com.qiwenshare.common.operation.FileOperation;
|
||||||
@ -14,6 +15,10 @@ import com.qiwenshare.file.config.QiwenFileConfig;
|
|||||||
import com.qiwenshare.file.domain.FileBean;
|
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.dto.BatchDeleteFileDto;
|
||||||
|
import com.qiwenshare.file.dto.BatchMoveFileDto;
|
||||||
|
import com.qiwenshare.file.dto.MoveFileDto;
|
||||||
|
import com.qiwenshare.file.dto.RenameFileDto;
|
||||||
import lombok.extern.slf4j.Slf4j;
|
import lombok.extern.slf4j.Slf4j;
|
||||||
import org.apache.commons.lang3.ArrayUtils;
|
import org.apache.commons.lang3.ArrayUtils;
|
||||||
import org.springframework.web.bind.annotation.*;
|
import org.springframework.web.bind.annotation.*;
|
||||||
@ -52,7 +57,7 @@ public class FileController {
|
|||||||
if (!operationCheck(token).isSuccess()){
|
if (!operationCheck(token).isSuccess()){
|
||||||
return operationCheck(token);
|
return operationCheck(token);
|
||||||
}
|
}
|
||||||
List<FileBean> fileBeans = fileService.selectFileByNameAndPath(fileBean);
|
List<FileBean> fileBeans = fileService.selectFileByNameAndPath(fileBean.getFileName(), fileBean.getFilePath());
|
||||||
if (fileBeans != null && !fileBeans.isEmpty()) {
|
if (fileBeans != null && !fileBeans.isEmpty()) {
|
||||||
restResult.setErrorMessage("同名文件已存在");
|
restResult.setErrorMessage("同名文件已存在");
|
||||||
restResult.setSuccess(false);
|
restResult.setSuccess(false);
|
||||||
@ -76,36 +81,57 @@ public class FileController {
|
|||||||
*/
|
*/
|
||||||
@RequestMapping(value = "/renamefile", method = RequestMethod.POST)
|
@RequestMapping(value = "/renamefile", method = RequestMethod.POST)
|
||||||
@ResponseBody
|
@ResponseBody
|
||||||
public RestResult<String> renameFile(@RequestBody FileBean fileBean, @RequestHeader("token") String token) {
|
public RestResult<String> renameFile(@RequestBody RenameFileDto renameFileDto, @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);
|
||||||
}
|
}
|
||||||
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(fileBean);
|
List<FileBean> fileBeans = fileService.selectFileByNameAndPath(renameFileDto.getFileName(), renameFileDto.getFilePath());
|
||||||
if (fileBeans != null && !fileBeans.isEmpty()) {
|
if (fileBeans != null && !fileBeans.isEmpty()) {
|
||||||
restResult.setErrorMessage("同名文件已存在");
|
restResult.setErrorMessage("同名文件已存在");
|
||||||
restResult.setSuccess(false);
|
restResult.setSuccess(false);
|
||||||
return restResult;
|
return restResult;
|
||||||
}
|
}
|
||||||
if (1 == fileBean.getIsDir()) {
|
if (1 == renameFileDto.getIsDir()) {
|
||||||
fileBean.setOldFilePath(fileBean.getFilePath() + fileBean.getOldFileName() + "/");
|
LambdaUpdateWrapper<FileBean> lambdaUpdateWrapper = new LambdaUpdateWrapper<>();
|
||||||
fileBean.setFilePath(fileBean.getFilePath() + fileBean.getFileName() + "/");
|
lambdaUpdateWrapper.set(FileBean::getFileName, renameFileDto.getFileName())
|
||||||
|
.set(FileBean::getUploadTime, DateUtil.getCurrentTime())
|
||||||
|
.eq(FileBean::getFileId, renameFileDto.getFileId());
|
||||||
|
fileService.update(lambdaUpdateWrapper);
|
||||||
|
fileService.replaceFilePath(renameFileDto.getFilePath() + renameFileDto.getFileName() + "/",
|
||||||
|
renameFileDto.getFilePath() + renameFileDto.getOldFileName() + "/");
|
||||||
|
// fileBean.setOldFilePath(renameFileDto.getFilePath() + renameFileDto.getOldFileName() + "/");
|
||||||
|
// fileBean.setFilePath(renameFileDto.getFilePath() + renameFileDto.getFileName() + "/");
|
||||||
} else {
|
} else {
|
||||||
if (fileBean.getIsOSS() == 1) {
|
if (renameFileDto.getIsOSS() == 1) {
|
||||||
FileBean file = fileService.getById(fileBean.getFileId());
|
FileBean file = fileService.getById(renameFileDto.getFileId());
|
||||||
String fileUrl = file.getFileUrl();
|
String fileUrl = file.getFileUrl();
|
||||||
String newFileUrl = fileUrl.replace(file.getFileName(), fileBean.getFileName());
|
String newFileUrl = fileUrl.replace(file.getFileName(), renameFileDto.getFileName());
|
||||||
fileBean.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.set(FileBean::getFileName, renameFileDto.getFileName())
|
||||||
|
.set(FileBean::getUploadTime, DateUtil.getCurrentTime())
|
||||||
|
.set(FileBean::getFileUrl, newFileUrl)
|
||||||
|
.eq(FileBean::getFileId, renameFileDto.getFileId());
|
||||||
|
fileService.update(lambdaUpdateWrapper);
|
||||||
|
} else {
|
||||||
|
LambdaUpdateWrapper<FileBean> lambdaUpdateWrapper = new LambdaUpdateWrapper<>();
|
||||||
|
lambdaUpdateWrapper.set(FileBean::getFileName, renameFileDto.getFileName())
|
||||||
|
.set(FileBean::getUploadTime, DateUtil.getCurrentTime())
|
||||||
|
.eq(FileBean::getFileId, renameFileDto.getFileId());
|
||||||
|
fileService.update(lambdaUpdateWrapper);
|
||||||
}
|
}
|
||||||
|
|
||||||
fileService.updateFile(fileBean);
|
|
||||||
|
}
|
||||||
|
|
||||||
|
// fileService.updateFile(fileBean);
|
||||||
restResult.setSuccess(true);
|
restResult.setSuccess(true);
|
||||||
return restResult;
|
return restResult;
|
||||||
}
|
}
|
||||||
@ -148,13 +174,13 @@ public class FileController {
|
|||||||
*/
|
*/
|
||||||
@RequestMapping(value = "/batchdeletefile", method = RequestMethod.POST)
|
@RequestMapping(value = "/batchdeletefile", method = RequestMethod.POST)
|
||||||
@ResponseBody
|
@ResponseBody
|
||||||
public RestResult<String> deleteImageByIds(@RequestBody FileBean fileBean, @RequestHeader("token") String token) {
|
public RestResult<String> deleteImageByIds(@RequestBody BatchDeleteFileDto batchDeleteFileDto, @RequestHeader("token") String token) {
|
||||||
RestResult<String> result = new RestResult<String>();
|
RestResult<String> result = new RestResult<String>();
|
||||||
if (!operationCheck(token).isSuccess()) {
|
if (!operationCheck(token).isSuccess()) {
|
||||||
return operationCheck(token);
|
return operationCheck(token);
|
||||||
}
|
}
|
||||||
UserBean sessionUserBean = userService.getUserBeanByToken(token);
|
UserBean sessionUserBean = userService.getUserBeanByToken(token);
|
||||||
List<FileBean> fileList = JSON.parseArray(fileBean.getFiles(), FileBean.class);
|
List<FileBean> fileList = JSON.parseArray(batchDeleteFileDto.getFiles(), FileBean.class);
|
||||||
|
|
||||||
for (FileBean file : fileList) {
|
for (FileBean file : fileList) {
|
||||||
fileService.deleteFile(file,sessionUserBean);
|
fileService.deleteFile(file,sessionUserBean);
|
||||||
@ -269,15 +295,15 @@ public class FileController {
|
|||||||
*/
|
*/
|
||||||
@RequestMapping(value = "/movefile", method = RequestMethod.POST)
|
@RequestMapping(value = "/movefile", method = RequestMethod.POST)
|
||||||
@ResponseBody
|
@ResponseBody
|
||||||
public RestResult<String> moveFile(@RequestBody FileBean fileBean, @RequestHeader("token") String token) {
|
public RestResult<String> moveFile(@RequestBody MoveFileDto moveFileDto, @RequestHeader("token") String token) {
|
||||||
RestResult<String> result = new RestResult<String>();
|
RestResult<String> result = new RestResult<String>();
|
||||||
if (!operationCheck(token).isSuccess()){
|
if (!operationCheck(token).isSuccess()){
|
||||||
return operationCheck(token);
|
return operationCheck(token);
|
||||||
}
|
}
|
||||||
String oldfilePath = fileBean.getOldFilePath();
|
String oldfilePath = moveFileDto.getOldFilePath();
|
||||||
String newfilePath = fileBean.getFilePath();
|
String newfilePath = moveFileDto.getFilePath();
|
||||||
String fileName = fileBean.getFileName();
|
String fileName = moveFileDto.getFileName();
|
||||||
String extendName = fileBean.getExtendName();
|
String extendName = moveFileDto.getExtendName();
|
||||||
|
|
||||||
fileService.updateFilepathByFilepath(oldfilePath, newfilePath, fileName, extendName);
|
fileService.updateFilepathByFilepath(oldfilePath, newfilePath, fileName, extendName);
|
||||||
result.setSuccess(true);
|
result.setSuccess(true);
|
||||||
@ -292,15 +318,15 @@ public class FileController {
|
|||||||
*/
|
*/
|
||||||
@RequestMapping(value = "/batchmovefile", method = RequestMethod.POST)
|
@RequestMapping(value = "/batchmovefile", method = RequestMethod.POST)
|
||||||
@ResponseBody
|
@ResponseBody
|
||||||
public RestResult<String> batchMoveFile(@RequestBody FileBean fileBean, @RequestHeader("token") String token) {
|
public RestResult<String> batchMoveFile(@RequestBody BatchMoveFileDto batchMoveFileDto, @RequestHeader("token") String token) {
|
||||||
|
|
||||||
RestResult<String> result = new RestResult<String>();
|
RestResult<String> result = new RestResult<String>();
|
||||||
if (!operationCheck(token).isSuccess()) {
|
if (!operationCheck(token).isSuccess()) {
|
||||||
return operationCheck(token);
|
return operationCheck(token);
|
||||||
}
|
}
|
||||||
|
|
||||||
String files = fileBean.getFiles();
|
String files = batchMoveFileDto.getFiles();
|
||||||
String newfilePath = fileBean.getFilePath();
|
String newfilePath = batchMoveFileDto.getFilePath();
|
||||||
|
|
||||||
List<FileBean> fileList = JSON.parseArray(files, FileBean.class);
|
List<FileBean> fileList = JSON.parseArray(files, FileBean.class);
|
||||||
|
|
||||||
@ -339,7 +365,7 @@ public class FileController {
|
|||||||
*/
|
*/
|
||||||
@RequestMapping(value = "/selectfilebyfiletype", method = RequestMethod.GET)
|
@RequestMapping(value = "/selectfilebyfiletype", method = RequestMethod.GET)
|
||||||
@ResponseBody
|
@ResponseBody
|
||||||
public RestResult<List<FileBean>> selectFileByFileType(FileBean fileBean, @RequestHeader("token") String token) {
|
public RestResult<List<FileBean>> selectFileByFileType(int fileType, @RequestHeader("token") String token) {
|
||||||
RestResult<List<FileBean>> result = new RestResult<List<FileBean>>();
|
RestResult<List<FileBean>> result = new RestResult<List<FileBean>>();
|
||||||
UserBean sessionUserBean = userService.getUserBeanByToken(token);
|
UserBean sessionUserBean = userService.getUserBeanByToken(token);
|
||||||
long userId = sessionUserBean.getUserId();
|
long userId = sessionUserBean.getUserId();
|
||||||
@ -347,7 +373,7 @@ public class FileController {
|
|||||||
userId = 2;
|
userId = 2;
|
||||||
}
|
}
|
||||||
List<FileBean> fileList = new ArrayList<>();
|
List<FileBean> fileList = new ArrayList<>();
|
||||||
if (fileBean.getFileType() == FileUtil.OTHER_TYPE) {
|
if (fileType == FileUtil.OTHER_TYPE) {
|
||||||
|
|
||||||
List<String> arrList = new ArrayList<>();
|
List<String> arrList = new ArrayList<>();
|
||||||
arrList.addAll(Arrays.asList(FileUtil.DOC_FILE));
|
arrList.addAll(Arrays.asList(FileUtil.DOC_FILE));
|
||||||
@ -356,7 +382,7 @@ public class FileController {
|
|||||||
arrList.addAll(Arrays.asList(FileUtil.MUSIC_FILE));
|
arrList.addAll(Arrays.asList(FileUtil.MUSIC_FILE));
|
||||||
fileList = fileService.selectFileNotInExtendNames(arrList, userId);
|
fileList = fileService.selectFileNotInExtendNames(arrList, userId);
|
||||||
} else {
|
} else {
|
||||||
fileList = fileService.selectFileByExtendName(getFileExtendsByType(fileBean.getFileType()), userId);
|
fileList = fileService.selectFileByExtendName(getFileExtendsByType(fileType), userId);
|
||||||
}
|
}
|
||||||
result.setData(fileList);
|
result.setData(fileList);
|
||||||
result.setSuccess(true);
|
result.setSuccess(true);
|
||||||
|
@ -120,13 +120,12 @@ public class FiletransferController {
|
|||||||
restResult.setErrorMessage("没权限,请联系管理员!");
|
restResult.setErrorMessage("没权限,请联系管理员!");
|
||||||
return restResult;
|
return restResult;
|
||||||
}
|
}
|
||||||
FileBean fileBean = new FileBean();
|
|
||||||
BeanUtil.copyProperties(uploadFileDto, fileBean);
|
|
||||||
fileBean.setUserId(sessionUserBean.getUserId());
|
|
||||||
|
|
||||||
filetransferService.uploadFile(request, fileBean, sessionUserBean);
|
uploadFileDto.setUserId(sessionUserBean.getUserId());
|
||||||
|
|
||||||
|
filetransferService.uploadFile(request, uploadFileDto, sessionUserBean);
|
||||||
UploadFileVo uploadFileVo = new UploadFileVo();
|
UploadFileVo uploadFileVo = new UploadFileVo();
|
||||||
uploadFileVo.setTimeStampName(fileBean.getTimeStampName());
|
uploadFileVo.setTimeStampName(uploadFileDto.getTimeStampName());
|
||||||
restResult.setData(uploadFileVo);
|
restResult.setData(uploadFileVo);
|
||||||
return restResult;
|
return restResult;
|
||||||
}
|
}
|
||||||
|
@ -68,41 +68,41 @@ public class FileBean {
|
|||||||
@Column(columnDefinition="varchar(32) comment 'md5标识'")
|
@Column(columnDefinition="varchar(32) comment 'md5标识'")
|
||||||
private String identifier;
|
private String identifier;
|
||||||
|
|
||||||
@Transient
|
// @Transient
|
||||||
@TableField(exist = false)
|
// @TableField(exist = false)
|
||||||
private String oldFilePath;
|
// private String oldFilePath;
|
||||||
|
//
|
||||||
|
// @Transient
|
||||||
|
// @TableField(exist = false)
|
||||||
|
// private String oldFileName;
|
||||||
|
|
||||||
@Transient
|
// @Transient
|
||||||
@TableField(exist = false)
|
// @TableField(exist = false)
|
||||||
private String oldFileName;
|
// private String files;
|
||||||
|
|
||||||
@Transient
|
// @Transient
|
||||||
@TableField(exist = false)
|
// @TableField(exist = false)
|
||||||
private String files;
|
// private Integer fileType;
|
||||||
|
|
||||||
@Transient
|
|
||||||
@TableField(exist = false)
|
|
||||||
private Integer fileType;
|
|
||||||
|
|
||||||
//切片上传相关参数
|
//切片上传相关参数
|
||||||
@Transient
|
// @Transient
|
||||||
@TableField(exist = false)
|
// @TableField(exist = false)
|
||||||
private String taskId;
|
// private String taskId;
|
||||||
@Transient
|
// @Transient
|
||||||
@TableField(exist = false)
|
// @TableField(exist = false)
|
||||||
private int chunkNumber;
|
// private int chunkNumber;
|
||||||
@Transient
|
// @Transient
|
||||||
@TableField(exist = false)
|
// @TableField(exist = false)
|
||||||
private long chunkSize;
|
// private long chunkSize;
|
||||||
@Transient
|
// @Transient
|
||||||
@TableField(exist = false)
|
// @TableField(exist = false)
|
||||||
private int totalChunks;
|
// private int totalChunks;
|
||||||
@Transient
|
// @Transient
|
||||||
@TableField(exist = false)
|
// @TableField(exist = false)
|
||||||
private long totalSize;
|
// private long totalSize;
|
||||||
@Transient
|
// @Transient
|
||||||
@TableField(exist = false)
|
// @TableField(exist = false)
|
||||||
private long currentChunkSize;
|
// private long currentChunkSize;
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -0,0 +1,12 @@
|
|||||||
|
package com.qiwenshare.file.dto;
|
||||||
|
|
||||||
|
import lombok.Data;
|
||||||
|
|
||||||
|
@Data
|
||||||
|
public class BatchDeleteFileDto {
|
||||||
|
|
||||||
|
private String files;
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
}
|
@ -0,0 +1,12 @@
|
|||||||
|
package com.qiwenshare.file.dto;
|
||||||
|
|
||||||
|
import lombok.Data;
|
||||||
|
|
||||||
|
@Data
|
||||||
|
public class BatchMoveFileDto {
|
||||||
|
|
||||||
|
private String files;
|
||||||
|
private String filePath;
|
||||||
|
|
||||||
|
|
||||||
|
}
|
@ -0,0 +1,20 @@
|
|||||||
|
package com.qiwenshare.file.dto;
|
||||||
|
|
||||||
|
import lombok.Data;
|
||||||
|
|
||||||
|
@Data
|
||||||
|
public class MoveFileDto {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 文件路径
|
||||||
|
*/
|
||||||
|
private String filePath;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 文件名
|
||||||
|
*/
|
||||||
|
private String fileName;
|
||||||
|
private String oldFilePath;
|
||||||
|
private String extendName;
|
||||||
|
|
||||||
|
}
|
@ -0,0 +1,22 @@
|
|||||||
|
package com.qiwenshare.file.dto;
|
||||||
|
|
||||||
|
import lombok.Data;
|
||||||
|
|
||||||
|
@Data
|
||||||
|
public class RenameFileDto {
|
||||||
|
private Long fileId;
|
||||||
|
/**
|
||||||
|
* 文件路径
|
||||||
|
*/
|
||||||
|
private String filePath;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 文件名
|
||||||
|
*/
|
||||||
|
private String fileName;
|
||||||
|
|
||||||
|
private Integer isDir;
|
||||||
|
|
||||||
|
private String oldFileName;
|
||||||
|
private Integer isOSS;
|
||||||
|
}
|
@ -11,7 +11,9 @@ 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);
|
||||||
|
@ -53,16 +53,16 @@ public class FileService extends ServiceImpl<FileMapper, FileBean> implements IF
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@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
|
@Override
|
||||||
public List<FileBean> selectFileByNameAndPath(FileBean fileBean) {
|
public List<FileBean> selectFileByNameAndPath(String fileName, String filePath) {
|
||||||
LambdaQueryWrapper<FileBean> lambdaQueryWrapper = new LambdaQueryWrapper<>();
|
LambdaQueryWrapper<FileBean> lambdaQueryWrapper = new LambdaQueryWrapper<>();
|
||||||
lambdaQueryWrapper.eq(FileBean::getFileName, fileBean.getFileName()).eq(FileBean::getFilePath, fileBean.getFilePath());
|
lambdaQueryWrapper.eq(FileBean::getFileName, fileName).eq(FileBean::getFilePath, filePath);
|
||||||
return fileMapper.selectList(lambdaQueryWrapper);
|
return fileMapper.selectList(lambdaQueryWrapper);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -82,6 +82,11 @@ 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
|
||||||
public List<FileBean> selectFileTreeListLikeFilePath(String filePath) {
|
public List<FileBean> selectFileTreeListLikeFilePath(String filePath) {
|
||||||
|
@ -5,6 +5,7 @@ import java.util.List;
|
|||||||
import javax.annotation.Resource;
|
import javax.annotation.Resource;
|
||||||
import javax.servlet.http.HttpServletRequest;
|
import javax.servlet.http.HttpServletRequest;
|
||||||
|
|
||||||
|
import cn.hutool.core.bean.BeanUtil;
|
||||||
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
||||||
import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper;
|
import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper;
|
||||||
import com.qiwenshare.common.cbb.DateUtil;
|
import com.qiwenshare.common.cbb.DateUtil;
|
||||||
@ -16,6 +17,7 @@ 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.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;
|
||||||
@ -38,17 +40,17 @@ public class FiletransferService implements IFiletransferService {
|
|||||||
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void uploadFile(HttpServletRequest request, FileBean fileBean, UserBean sessionUserBean) {
|
public void uploadFile(HttpServletRequest request, UploadFileDto UploadFileDto, UserBean sessionUserBean) {
|
||||||
AliyunOSS oss = qiwenFileConfig.getAliyun().getOss();
|
AliyunOSS oss = qiwenFileConfig.getAliyun().getOss();
|
||||||
request.setAttribute("oss", oss);
|
request.setAttribute("oss", oss);
|
||||||
Uploader uploader;
|
Uploader uploader;
|
||||||
UploadFile uploadFile = new UploadFile();
|
UploadFile uploadFile = new UploadFile();
|
||||||
uploadFile.setChunkNumber(fileBean.getChunkNumber());
|
uploadFile.setChunkNumber(UploadFileDto.getChunkNumber());
|
||||||
uploadFile.setChunkSize(fileBean.getChunkSize());
|
uploadFile.setChunkSize(UploadFileDto.getChunkSize());
|
||||||
uploadFile.setTotalChunks(fileBean.getTotalChunks());
|
uploadFile.setTotalChunks(UploadFileDto.getTotalChunks());
|
||||||
uploadFile.setIdentifier(fileBean.getIdentifier());
|
uploadFile.setIdentifier(UploadFileDto.getIdentifier());
|
||||||
uploadFile.setTotalSize(fileBean.getTotalSize());
|
uploadFile.setTotalSize(UploadFileDto.getTotalSize());
|
||||||
uploadFile.setCurrentChunkSize(fileBean.getCurrentChunkSize());
|
uploadFile.setCurrentChunkSize(UploadFileDto.getCurrentChunkSize());
|
||||||
if (oss.isEnabled()) {
|
if (oss.isEnabled()) {
|
||||||
uploader = new AliyunOSSUploaderFactory().getUploader(uploadFile);
|
uploader = new AliyunOSSUploaderFactory().getUploader(uploadFile);
|
||||||
} else {
|
} else {
|
||||||
@ -58,6 +60,8 @@ public class FiletransferService implements IFiletransferService {
|
|||||||
List<UploadFile> uploadFileList = uploader.upload(request);
|
List<UploadFile> uploadFileList = uploader.upload(request);
|
||||||
for (int i = 0; i < uploadFileList.size(); i++){
|
for (int i = 0; i < uploadFileList.size(); i++){
|
||||||
uploadFile = uploadFileList.get(i);
|
uploadFile = uploadFileList.get(i);
|
||||||
|
FileBean fileBean = new FileBean();
|
||||||
|
BeanUtil.copyProperties(UploadFileDto, fileBean);
|
||||||
fileBean.setTimeStampName(uploadFile.getTimeStampName());
|
fileBean.setTimeStampName(uploadFile.getTimeStampName());
|
||||||
if (uploadFile.getSuccess() == 1){
|
if (uploadFile.getSuccess() == 1){
|
||||||
fileBean.setFileUrl(uploadFile.getUrl());
|
fileBean.setFileUrl(uploadFile.getUrl());
|
||||||
|
@ -18,32 +18,36 @@
|
|||||||
</foreach>
|
</foreach>
|
||||||
</insert>
|
</insert>
|
||||||
|
|
||||||
<update id="updateFile" parameterType="com.qiwenshare.file.domain.FileBean">
|
<update id="replaceFilePath" parameterType="java.lang.String">
|
||||||
<choose>
|
|
||||||
<when test="isDir == 1">
|
|
||||||
UPDATE file SET filename=#{fileName}, uploadTime = #{uploadTime}
|
|
||||||
where fileId = #{fileId};
|
|
||||||
UPDATE file SET filepath=REPLACE(filepath, #{oldFilePath}, #{filePath}) WHERE filepath LIKE N'${oldFilePath}%';
|
UPDATE file SET filepath=REPLACE(filepath, #{oldFilePath}, #{filePath}) WHERE filepath LIKE N'${oldFilePath}%';
|
||||||
</when>
|
|
||||||
<otherwise>
|
|
||||||
update file
|
|
||||||
<set>
|
|
||||||
<if test="fileName != null">
|
|
||||||
fileName = #{fileName},
|
|
||||||
</if>
|
|
||||||
<if test="uploadTime != null">
|
|
||||||
uploadTime = #{uploadTime},
|
|
||||||
</if>
|
|
||||||
<if test="fileUrl != null">
|
|
||||||
fileUrl = #{fileUrl},
|
|
||||||
</if>
|
|
||||||
</set>
|
|
||||||
where fileId = #{fileId}
|
|
||||||
</otherwise>
|
|
||||||
</choose>
|
|
||||||
|
|
||||||
</update>
|
</update>
|
||||||
|
|
||||||
|
<!-- <update id="updateFile" parameterType="java">-->
|
||||||
|
<!-- <choose>-->
|
||||||
|
<!-- <when test="isDir == 1">-->
|
||||||
|
<!-- UPDATE file SET filename=#{fileName}, uploadTime = #{uploadTime}-->
|
||||||
|
<!-- where fileId = #{fileId};-->
|
||||||
|
<!-- UPDATE file SET filepath=REPLACE(filepath, #{oldFilePath}, #{filePath}) WHERE filepath LIKE N'${oldFilePath}%';-->
|
||||||
|
<!-- </when>-->
|
||||||
|
<!-- <otherwise>-->
|
||||||
|
<!-- update file-->
|
||||||
|
<!-- <set>-->
|
||||||
|
<!-- <if test="fileName != null">-->
|
||||||
|
<!-- fileName = #{fileName},-->
|
||||||
|
<!-- </if>-->
|
||||||
|
<!-- <if test="uploadTime != null">-->
|
||||||
|
<!-- uploadTime = #{uploadTime},-->
|
||||||
|
<!-- </if>-->
|
||||||
|
<!-- <if test="fileUrl != null">-->
|
||||||
|
<!-- fileUrl = #{fileUrl},-->
|
||||||
|
<!-- </if>-->
|
||||||
|
<!-- </set>-->
|
||||||
|
<!-- where fileId = #{fileId}-->
|
||||||
|
<!-- </otherwise>-->
|
||||||
|
<!-- </choose>-->
|
||||||
|
|
||||||
|
<!-- </update>-->
|
||||||
|
|
||||||
|
|
||||||
<update id="updateFilepathByFilepath">
|
<update id="updateFilepathByFilepath">
|
||||||
UPDATE file SET filePath=REPLACE(filePath, #{param1}, #{param2})
|
UPDATE file SET filePath=REPLACE(filePath, #{param1}, #{param2})
|
||||||
|
Loading…
Reference in New Issue
Block a user