代码重构
This commit is contained in:
parent
97dbaf9e03
commit
dbe05ea599
@ -3,27 +3,26 @@ 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.FileBean;
|
||||||
import com.qiwenshare.file.domain.UserBean;
|
import com.qiwenshare.file.domain.UserBean;
|
||||||
|
import com.qiwenshare.file.domain.UserFile;
|
||||||
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
public interface IFileService extends IService<FileBean> {
|
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);
|
||||||
|
|
||||||
public void increaseFilePointCount(Long fileId);
|
void increaseFilePointCount(Long fileId);
|
||||||
|
|
||||||
|
void decreaseFilePointCount(Long fileId);
|
||||||
|
|
||||||
|
// List<FileBean> selectFileListByPath(FileBean fileBean);
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
public void decreaseFilePointCount(Long fileId);
|
|
||||||
List<FileBean> selectFilePathTreeByUserId(FileBean fileBean);
|
|
||||||
List<FileBean> selectFileListByPath(FileBean fileBean);
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
List<FileBean> selectFileTreeListLikeFilePath(String filePath);
|
|
||||||
void deleteFile(FileBean fileBean, UserBean sessionUserBean);
|
|
||||||
|
|
||||||
void updateFilepathByFilepath(String oldfilePath, String newfilePath, String fileName, String extendName);
|
|
||||||
List<FileBean> selectFileByExtendName(List<String> fileNameList, long userId);
|
|
||||||
List<FileBean> selectFileNotInExtendNames(List<String> fileNameList, long userId);
|
|
||||||
}
|
}
|
||||||
|
@ -2,6 +2,7 @@ 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.FileBean;
|
||||||
|
import com.qiwenshare.file.domain.UserBean;
|
||||||
import com.qiwenshare.file.domain.UserFile;
|
import com.qiwenshare.file.domain.UserFile;
|
||||||
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
@ -11,4 +12,11 @@ public interface IUserFileService extends IService<UserFile> {
|
|||||||
List<UserFile> selectUserFileByNameAndPath(String fileName, String filePath, Long userId);
|
List<UserFile> selectUserFileByNameAndPath(String fileName, String filePath, Long userId);
|
||||||
void replaceUserFilePath(String filePath, String oldFilePath, Long userId);
|
void replaceUserFilePath(String filePath, String oldFilePath, Long userId);
|
||||||
List<Map<String, Object>> userFileList(UserFile userFile);
|
List<Map<String, Object>> userFileList(UserFile userFile);
|
||||||
|
void updateFilepathByFilepath(String oldfilePath, String newfilePath, String fileName, String extendName);
|
||||||
|
|
||||||
|
List<Map<String, Object>> selectFileByExtendName(List<String> fileNameList, long userId);
|
||||||
|
List<Map<String, Object>> selectFileNotInExtendNames(List<String> fileNameList, long userId);
|
||||||
|
List<UserFile> selectFileTreeListLikeFilePath(String filePath);
|
||||||
|
List<UserFile> selectFilePathTreeByUserId(Long userId);
|
||||||
|
void deleteUserFile(UserFile userFile, UserBean sessionUserBean);
|
||||||
}
|
}
|
||||||
|
@ -1,5 +1,6 @@
|
|||||||
package com.qiwenshare.file.controller;
|
package com.qiwenshare.file.controller;
|
||||||
|
|
||||||
|
import cn.hutool.core.bean.BeanUtil;
|
||||||
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.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper;
|
||||||
@ -200,10 +201,10 @@ public class FileController {
|
|||||||
return operationCheck(token);
|
return operationCheck(token);
|
||||||
}
|
}
|
||||||
UserBean sessionUserBean = userService.getUserBeanByToken(token);
|
UserBean sessionUserBean = userService.getUserBeanByToken(token);
|
||||||
List<FileBean> fileList = JSON.parseArray(batchDeleteFileDto.getFiles(), FileBean.class);
|
List<UserFile> userFiles = JSON.parseArray(batchDeleteFileDto.getFiles(), UserFile.class);
|
||||||
|
|
||||||
for (FileBean file : fileList) {
|
for (UserFile userFile : userFiles) {
|
||||||
fileService.deleteFile(file,sessionUserBean);
|
userFileService.deleteUserFile(userFile,sessionUserBean);
|
||||||
}
|
}
|
||||||
|
|
||||||
result.setData("批量删除文件成功");
|
result.setData("批量删除文件成功");
|
||||||
@ -218,13 +219,16 @@ public class FileController {
|
|||||||
*/
|
*/
|
||||||
@RequestMapping(value = "/deletefile", method = RequestMethod.POST)
|
@RequestMapping(value = "/deletefile", method = RequestMethod.POST)
|
||||||
@ResponseBody
|
@ResponseBody
|
||||||
public String deleteFile(@RequestBody FileBean fileBean, @RequestHeader("token") String token) {
|
public String deleteFile(@RequestBody DeleteFileDto deleteFileDto, @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 JSON.toJSONString(operationCheck(token));
|
return JSON.toJSONString(operationCheck(token));
|
||||||
}
|
}
|
||||||
UserBean sessionUserBean = userService.getUserBeanByToken(token);
|
UserBean sessionUserBean = userService.getUserBeanByToken(token);
|
||||||
fileService.deleteFile(fileBean, sessionUserBean);
|
UserFile userFile = new UserFile();
|
||||||
|
userFile.setUserFileId(deleteFileDto.getUserFileId());
|
||||||
|
BeanUtil.copyProperties(deleteFileDto, userFile);
|
||||||
|
userFileService.deleteUserFile(userFile, sessionUserBean);
|
||||||
|
|
||||||
result.setSuccess(true);
|
result.setSuccess(true);
|
||||||
String resultJson = JSON.toJSONString(result);
|
String resultJson = JSON.toJSONString(result);
|
||||||
@ -238,16 +242,16 @@ public class FileController {
|
|||||||
*/
|
*/
|
||||||
@RequestMapping(value = "/unzipfile", method = RequestMethod.POST)
|
@RequestMapping(value = "/unzipfile", method = RequestMethod.POST)
|
||||||
@ResponseBody
|
@ResponseBody
|
||||||
public RestResult<String> unzipFile(@RequestBody FileBean fileBean, @RequestHeader("token") String token) {
|
public RestResult<String> unzipFile(@RequestBody UnzipFileDto unzipFileDto, @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 zipFileUrl = PathUtil.getStaticPath() + fileBean.getFileUrl();
|
String zipFileUrl = PathUtil.getStaticPath() + unzipFileDto.getFileUrl();
|
||||||
File file = FileOperation.newFile(zipFileUrl);
|
File file = FileOperation.newFile(zipFileUrl);
|
||||||
String unzipUrl = file.getParent();
|
String unzipUrl = file.getParent();
|
||||||
String[] arr = fileBean.getFileUrl().split("\\.");
|
String[] arr = unzipFileDto.getFileUrl().split("\\.");
|
||||||
if (arr.length <= 1) {
|
if (arr.length <= 1) {
|
||||||
result.setErrorMessage("文件名格式错误!");
|
result.setErrorMessage("文件名格式错误!");
|
||||||
result.setSuccess(false);
|
result.setSuccess(false);
|
||||||
@ -279,29 +283,34 @@ public class FileController {
|
|||||||
File currentFile = FileOperation.newFile(totalFileUrl);
|
File currentFile = FileOperation.newFile(totalFileUrl);
|
||||||
|
|
||||||
FileBean tempFileBean = new FileBean();
|
FileBean tempFileBean = new FileBean();
|
||||||
tempFileBean.setUploadTime(DateUtil.getCurrentTime());
|
UserFile userFile = new UserFile();
|
||||||
tempFileBean.setUserId(sessionUserBean.getUserId());
|
|
||||||
tempFileBean.setFilePath(FileUtil.pathSplitFormat(fileBean.getFilePath() + entryName.replace(currentFile.getName(), "")).replace("\\", "/"));
|
userFile.setUploadTime(DateUtil.getCurrentTime());
|
||||||
|
userFile.setUserId(sessionUserBean.getUserId());
|
||||||
|
userFile.setFilePath(FileUtil.pathSplitFormat(unzipFileDto.getFilePath() + entryName.replace(currentFile.getName(), "")).replace("\\", "/"));
|
||||||
|
|
||||||
if (currentFile.isDirectory()){
|
if (currentFile.isDirectory()){
|
||||||
|
|
||||||
tempFileBean.setIsDir(1);
|
userFile.setIsDir(1);
|
||||||
|
|
||||||
tempFileBean.setFileName(currentFile.getName());
|
userFile.setFileName(currentFile.getName());
|
||||||
tempFileBean.setTimeStampName(currentFile.getName());
|
tempFileBean.setTimeStampName(currentFile.getName());
|
||||||
//tempFileBean.setFileUrl(File.separator + (file.getParent() + File.separator + currentFile.getName()).replace(PathUtil.getStaticPath(), ""));
|
|
||||||
}else{
|
}else{
|
||||||
|
|
||||||
tempFileBean.setIsDir(0);
|
userFile.setIsDir(0);
|
||||||
|
userFile.setExtendName(FileUtil.getFileType(totalFileUrl));
|
||||||
tempFileBean.setExtendName(FileUtil.getFileType(totalFileUrl));
|
userFile.setFileName(FileUtil.getFileNameNotExtend(currentFile.getName()));
|
||||||
tempFileBean.setFileName(FileUtil.getFileNameNotExtend(currentFile.getName()));
|
|
||||||
tempFileBean.setFileSize(currentFile.length());
|
tempFileBean.setFileSize(currentFile.length());
|
||||||
tempFileBean.setTimeStampName(FileUtil.getFileNameNotExtend(currentFile.getName()));
|
tempFileBean.setTimeStampName(FileUtil.getFileNameNotExtend(currentFile.getName()));
|
||||||
tempFileBean.setFileUrl(File.separator + (currentFile.getPath()).replace(PathUtil.getStaticPath(), ""));
|
tempFileBean.setFileUrl(File.separator + (currentFile.getPath()).replace(PathUtil.getStaticPath(), ""));
|
||||||
}
|
}
|
||||||
fileBeanList.add(tempFileBean);
|
fileService.save(tempFileBean);
|
||||||
|
userFile.setFileId(tempFileBean.getFileId());
|
||||||
|
userFileService.save(userFile);
|
||||||
|
//fileBeanList.add(tempFileBean);
|
||||||
}
|
}
|
||||||
fileService.batchInsertFile(fileBeanList, sessionUserBean.getUserId());
|
|
||||||
|
// fileService.batchInsertFile(fileBeanList, sessionUserBean.getUserId());
|
||||||
result.setSuccess(true);
|
result.setSuccess(true);
|
||||||
|
|
||||||
return result;
|
return result;
|
||||||
@ -325,7 +334,7 @@ public class FileController {
|
|||||||
String fileName = moveFileDto.getFileName();
|
String fileName = moveFileDto.getFileName();
|
||||||
String extendName = moveFileDto.getExtendName();
|
String extendName = moveFileDto.getExtendName();
|
||||||
|
|
||||||
fileService.updateFilepathByFilepath(oldfilePath, newfilePath, fileName, extendName);
|
userFileService.updateFilepathByFilepath(oldfilePath, newfilePath, fileName, extendName);
|
||||||
result.setSuccess(true);
|
result.setSuccess(true);
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
@ -348,10 +357,10 @@ public class FileController {
|
|||||||
String files = batchMoveFileDto.getFiles();
|
String files = batchMoveFileDto.getFiles();
|
||||||
String newfilePath = batchMoveFileDto.getFilePath();
|
String newfilePath = batchMoveFileDto.getFilePath();
|
||||||
|
|
||||||
List<FileBean> fileList = JSON.parseArray(files, FileBean.class);
|
List<UserFile> fileList = JSON.parseArray(files, UserFile.class);
|
||||||
|
|
||||||
for (FileBean file : fileList) {
|
for (UserFile userFile : fileList) {
|
||||||
fileService.updateFilepathByFilepath(file.getFilePath(), newfilePath, file.getFileName(), file.getExtendName());
|
userFileService.updateFilepathByFilepath(userFile.getFilePath(), newfilePath, userFile.getFileName(), userFile.getExtendName());
|
||||||
}
|
}
|
||||||
|
|
||||||
result.setData("批量移动文件成功");
|
result.setData("批量移动文件成功");
|
||||||
@ -385,14 +394,14 @@ public class FileController {
|
|||||||
*/
|
*/
|
||||||
@RequestMapping(value = "/selectfilebyfiletype", method = RequestMethod.GET)
|
@RequestMapping(value = "/selectfilebyfiletype", method = RequestMethod.GET)
|
||||||
@ResponseBody
|
@ResponseBody
|
||||||
public RestResult<List<FileBean>> selectFileByFileType(int fileType, @RequestHeader("token") String token) {
|
public RestResult<List<Map<String, Object>>> selectFileByFileType(int fileType, @RequestHeader("token") String token) {
|
||||||
RestResult<List<FileBean>> result = new RestResult<List<FileBean>>();
|
RestResult<List<Map<String, Object>>> result = new RestResult<List<Map<String, Object>>>();
|
||||||
UserBean sessionUserBean = userService.getUserBeanByToken(token);
|
UserBean sessionUserBean = userService.getUserBeanByToken(token);
|
||||||
long userId = sessionUserBean.getUserId();
|
long userId = sessionUserBean.getUserId();
|
||||||
if (qiwenFileConfig.isShareMode()){
|
if (qiwenFileConfig.isShareMode()){
|
||||||
userId = 2;
|
userId = 2;
|
||||||
}
|
}
|
||||||
List<FileBean> fileList = new ArrayList<>();
|
List<Map<String, Object>> fileList = new ArrayList<>();
|
||||||
if (fileType == FileUtil.OTHER_TYPE) {
|
if (fileType == FileUtil.OTHER_TYPE) {
|
||||||
|
|
||||||
List<String> arrList = new ArrayList<>();
|
List<String> arrList = new ArrayList<>();
|
||||||
@ -400,9 +409,9 @@ public class FileController {
|
|||||||
arrList.addAll(Arrays.asList(FileUtil.IMG_FILE));
|
arrList.addAll(Arrays.asList(FileUtil.IMG_FILE));
|
||||||
arrList.addAll(Arrays.asList(FileUtil.VIDEO_FILE));
|
arrList.addAll(Arrays.asList(FileUtil.VIDEO_FILE));
|
||||||
arrList.addAll(Arrays.asList(FileUtil.MUSIC_FILE));
|
arrList.addAll(Arrays.asList(FileUtil.MUSIC_FILE));
|
||||||
fileList = fileService.selectFileNotInExtendNames(arrList, userId);
|
fileList = userFileService.selectFileNotInExtendNames(arrList, userId);
|
||||||
} else {
|
} else {
|
||||||
fileList = fileService.selectFileByExtendName(getFileExtendsByType(fileType), userId);
|
fileList = userFileService.selectFileByExtendName(getFileExtendsByType(fileType), userId);
|
||||||
}
|
}
|
||||||
result.setData(fileList);
|
result.setData(fileList);
|
||||||
result.setSuccess(true);
|
result.setSuccess(true);
|
||||||
@ -417,15 +426,15 @@ public class FileController {
|
|||||||
@ResponseBody
|
@ResponseBody
|
||||||
public RestResult<TreeNode> getFileTree(@RequestHeader("token") String token){
|
public RestResult<TreeNode> getFileTree(@RequestHeader("token") String token){
|
||||||
RestResult<TreeNode> result = new RestResult<TreeNode>();
|
RestResult<TreeNode> result = new RestResult<TreeNode>();
|
||||||
FileBean fileBean = new FileBean();
|
UserFile userFile = new UserFile();
|
||||||
UserBean sessionUserBean = userService.getUserBeanByToken(token);
|
UserBean sessionUserBean = userService.getUserBeanByToken(token);
|
||||||
if (qiwenFileConfig.isShareMode()){
|
if (qiwenFileConfig.isShareMode()){
|
||||||
fileBean.setUserId(2L);
|
userFile.setUserId(2L);
|
||||||
}else{
|
}else{
|
||||||
fileBean.setUserId(sessionUserBean.getUserId());
|
userFile.setUserId(sessionUserBean.getUserId());
|
||||||
}
|
}
|
||||||
|
|
||||||
List<FileBean> filePathList = fileService.selectFilePathTreeByUserId(fileBean);
|
List<UserFile> filePathList = userFileService.selectFilePathTreeByUserId(sessionUserBean.getUserId());
|
||||||
TreeNode resultTreeNode = new TreeNode();
|
TreeNode resultTreeNode = new TreeNode();
|
||||||
resultTreeNode.setLabel("/");
|
resultTreeNode.setLabel("/");
|
||||||
|
|
||||||
|
@ -13,8 +13,7 @@ import javax.persistence.*;
|
|||||||
* @author ma116
|
* @author ma116
|
||||||
*/
|
*/
|
||||||
@Data
|
@Data
|
||||||
@Table(name = "file", uniqueConstraints = {
|
@Table(name = "file")
|
||||||
@UniqueConstraint(name = "fileindex", columnNames = {"fileName", "filePath", "extendName"})})
|
|
||||||
@Entity
|
@Entity
|
||||||
@TableName("file")
|
@TableName("file")
|
||||||
public class FileBean {
|
public class FileBean {
|
||||||
|
@ -6,7 +6,8 @@ import lombok.Data;
|
|||||||
import javax.persistence.*;
|
import javax.persistence.*;
|
||||||
|
|
||||||
@Data
|
@Data
|
||||||
@Table(name = "userfile")
|
@Table(name = "userfile", uniqueConstraints = {
|
||||||
|
@UniqueConstraint(name = "fileindex", columnNames = {"fileName", "filePath", "extendName"})})
|
||||||
@Entity
|
@Entity
|
||||||
@TableName("userfile")
|
@TableName("userfile")
|
||||||
public class UserFile {
|
public class UserFile {
|
||||||
|
@ -0,0 +1,11 @@
|
|||||||
|
package com.qiwenshare.file.dto;
|
||||||
|
|
||||||
|
import lombok.Data;
|
||||||
|
|
||||||
|
@Data
|
||||||
|
public class DeleteFileDto {
|
||||||
|
private Long userFileId;
|
||||||
|
private String filePath;
|
||||||
|
private String fileName;
|
||||||
|
private Integer isDir;
|
||||||
|
}
|
@ -0,0 +1,9 @@
|
|||||||
|
package com.qiwenshare.file.dto;
|
||||||
|
|
||||||
|
import lombok.Data;
|
||||||
|
|
||||||
|
@Data
|
||||||
|
public class UnzipFileDto {
|
||||||
|
private String fileUrl;
|
||||||
|
private String filePath;
|
||||||
|
}
|
@ -15,7 +15,7 @@ public interface FileMapper extends BaseMapper<FileBean> {
|
|||||||
|
|
||||||
|
|
||||||
|
|
||||||
void updateFilepathByFilepath(String oldfilePath, String newfilePath);
|
|
||||||
void updateFilepathByPathAndName(String oldfilePath, String newfilePath, String fileName, String extendName);
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -1,6 +1,7 @@
|
|||||||
package com.qiwenshare.file.mapper;
|
package com.qiwenshare.file.mapper;
|
||||||
|
|
||||||
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
|
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
|
||||||
|
import com.qiwenshare.file.domain.FileBean;
|
||||||
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 org.apache.ibatis.annotations.Param;
|
||||||
@ -11,4 +12,10 @@ 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);
|
void replaceFilePath(@Param("filePath") String filePath, @Param("oldFilePath") String oldFilePath, @Param("userId") Long userId);
|
||||||
List<Map<String, Object>> userFileList(UserFile userFile);
|
List<Map<String, Object>> userFileList(UserFile userFile);
|
||||||
|
|
||||||
|
void updateFilepathByPathAndName(String oldfilePath, String newfilePath, String fileName, String extendName);
|
||||||
|
void updateFilepathByFilepath(String oldfilePath, String newfilePath);
|
||||||
|
|
||||||
|
List<Map<String, Object>> selectFileByExtendName(List<String> fileNameList, long userId);
|
||||||
|
List<Map<String, Object>> selectFileNotInExtendNames(List<String> fileNameList, long userId);
|
||||||
}
|
}
|
||||||
|
@ -11,10 +11,12 @@ import com.qiwenshare.common.util.PathUtil;
|
|||||||
import com.qiwenshare.file.api.IFileService;
|
import com.qiwenshare.file.api.IFileService;
|
||||||
import com.qiwenshare.file.config.AliyunConfig;
|
import com.qiwenshare.file.config.AliyunConfig;
|
||||||
import com.qiwenshare.file.config.QiwenFileConfig;
|
import com.qiwenshare.file.config.QiwenFileConfig;
|
||||||
|
import com.qiwenshare.file.domain.UserFile;
|
||||||
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.UserFileMapper;
|
||||||
import lombok.extern.slf4j.Slf4j;
|
import lombok.extern.slf4j.Slf4j;
|
||||||
import org.apache.commons.lang3.ArrayUtils;
|
import org.apache.commons.lang3.ArrayUtils;
|
||||||
import org.apache.shiro.SecurityUtils;
|
import org.apache.shiro.SecurityUtils;
|
||||||
@ -31,27 +33,29 @@ public class FileService extends ServiceImpl<FileMapper, FileBean> implements IF
|
|||||||
@Resource
|
@Resource
|
||||||
FileMapper fileMapper;
|
FileMapper fileMapper;
|
||||||
@Resource
|
@Resource
|
||||||
|
UserFileMapper userFileMapper;
|
||||||
|
@Resource
|
||||||
FiletransferService filetransferService;
|
FiletransferService filetransferService;
|
||||||
@Resource
|
@Resource
|
||||||
QiwenFileConfig qiwenFileConfig;
|
QiwenFileConfig qiwenFileConfig;
|
||||||
|
|
||||||
@Override
|
// @Override
|
||||||
public void batchInsertFile(List<FileBean> fileBeanList, Long userId) {
|
// public void batchInsertFile(List<FileBean> fileBeanList, Long userId) {
|
||||||
StorageBean storageBean = filetransferService.selectStorageBean(new StorageBean(userId));
|
// StorageBean storageBean = filetransferService.selectStorageBean(new StorageBean(userId));
|
||||||
long fileSizeSum = 0;
|
// long fileSizeSum = 0;
|
||||||
for (FileBean fileBean : fileBeanList) {
|
// for (FileBean fileBean : fileBeanList) {
|
||||||
if (fileBean.getIsDir() == 0) {
|
// if (fileBean.getIsDir() == 0) {
|
||||||
fileSizeSum += fileBean.getFileSize();
|
// fileSizeSum += fileBean.getFileSize();
|
||||||
}
|
// }
|
||||||
}
|
// }
|
||||||
fileMapper.batchInsertFile(fileBeanList);
|
// fileMapper.batchInsertFile(fileBeanList);
|
||||||
if (storageBean != null) {
|
// if (storageBean != null) {
|
||||||
long updateFileSize = storageBean.getStorageSize() + fileSizeSum;
|
// long updateFileSize = storageBean.getStorageSize() + fileSizeSum;
|
||||||
|
//
|
||||||
storageBean.setStorageSize(updateFileSize);
|
// storageBean.setStorageSize(updateFileSize);
|
||||||
filetransferService.updateStorageBean(storageBean);
|
// filetransferService.updateStorageBean(storageBean);
|
||||||
}
|
// }
|
||||||
}
|
// }
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void increaseFilePointCount(Long fileId) {
|
public void increaseFilePointCount(Long fileId) {
|
||||||
@ -76,143 +80,20 @@ public class FileService extends ServiceImpl<FileMapper, FileBean> implements IF
|
|||||||
|
|
||||||
|
|
||||||
|
|
||||||
@Override
|
// @Override
|
||||||
public List<FileBean> selectFilePathTreeByUserId(FileBean fileBean) {
|
// public List<FileBean> selectFileListByPath(FileBean fileBean) {
|
||||||
LambdaQueryWrapper<FileBean> lambdaQueryWrapper = new LambdaQueryWrapper<>();
|
// LambdaQueryWrapper<FileBean> lambdaQueryWrapper = new LambdaQueryWrapper<>();
|
||||||
lambdaQueryWrapper.eq(FileBean::getUserId, fileBean.getUserId()).eq(FileBean::getIsDir, 1);
|
// lambdaQueryWrapper.eq(FileBean::getFilePath, fileBean.getFilePath())
|
||||||
return fileMapper.selectList(lambdaQueryWrapper);
|
// .eq(FileBean::getUserId, fileBean.getUserId())
|
||||||
}
|
// .orderByDesc(FileBean::getIsDir);
|
||||||
|
// return fileMapper.selectList(lambdaQueryWrapper);
|
||||||
@Override
|
// }
|
||||||
public List<FileBean> selectFileListByPath(FileBean fileBean) {
|
|
||||||
LambdaQueryWrapper<FileBean> lambdaQueryWrapper = new LambdaQueryWrapper<>();
|
|
||||||
lambdaQueryWrapper.eq(FileBean::getFilePath, fileBean.getFilePath())
|
|
||||||
.eq(FileBean::getUserId, fileBean.getUserId())
|
|
||||||
.orderByDesc(FileBean::getIsDir);
|
|
||||||
return fileMapper.selectList(lambdaQueryWrapper);
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public List<FileBean> selectFileTreeListLikeFilePath(String filePath) {
|
|
||||||
FileBean fileBean = new FileBean();
|
|
||||||
filePath = filePath.replace("\\", "\\\\\\\\");
|
|
||||||
filePath = filePath.replace("'", "\\'");
|
|
||||||
filePath = filePath.replace("%", "\\%");
|
|
||||||
filePath = filePath.replace("_", "\\_");
|
|
||||||
|
|
||||||
fileBean.setFilePath(filePath);
|
|
||||||
|
|
||||||
LambdaQueryWrapper<FileBean> lambdaQueryWrapper = new LambdaQueryWrapper<>();
|
|
||||||
|
|
||||||
log.info("删除文件路径:" + filePath);
|
|
||||||
|
|
||||||
lambdaQueryWrapper.likeRight(FileBean::getFilePath, filePath);
|
|
||||||
return fileMapper.selectList(lambdaQueryWrapper);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void deleteFile(FileBean fileBean, UserBean sessionUserBean) {
|
|
||||||
StorageBean storageBean = filetransferService.selectStorageBean(new StorageBean(sessionUserBean.getUserId()));
|
|
||||||
long deleteSize = 0;
|
|
||||||
String fileUrl = PathUtil.getStaticPath() + fileBean.getFileUrl();
|
|
||||||
if (fileBean.getIsDir() == 1) {
|
|
||||||
//1、先删除子目录
|
|
||||||
String filePath = fileBean.getFilePath() + fileBean.getFileName() + "/";
|
|
||||||
List<FileBean> fileList = selectFileTreeListLikeFilePath(filePath);
|
|
||||||
|
|
||||||
for (int i = 0; i < fileList.size(); i++){
|
|
||||||
FileBean file = fileList.get(i);
|
|
||||||
//1.1、删除数据库文件
|
|
||||||
fileMapper.deleteById(file.getFileId());
|
|
||||||
//1.2、如果是文件,需要记录文件大小
|
|
||||||
if (file.getIsDir() != 1){
|
|
||||||
deleteSize += file.getFileSize();
|
|
||||||
//1.3、删除服务器文件,只删除文件,目录是虚拟的
|
|
||||||
if (file.getFileUrl() != null && file.getFileUrl().indexOf("upload") != -1){
|
|
||||||
if (file.getIsOSS() != null && file.getIsOSS() == 1) {
|
|
||||||
AliyunOSSDelete.deleteObject(qiwenFileConfig.getAliyun().getOss(), file.getFileUrl().substring(1));
|
|
||||||
} else {
|
|
||||||
FileOperation.deleteFile(PathUtil.getStaticPath() + file.getFileUrl());
|
|
||||||
if (FileUtil.isImageFile(file.getExtendName())) {
|
|
||||||
FileOperation.deleteFile(PathUtil.getStaticPath() + file.getFileUrl().replace(file.getTimeStampName(), file.getTimeStampName() + "_min"));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
//2、根目录单独删除
|
|
||||||
fileMapper.deleteById(fileBean.getFileId());
|
|
||||||
}else{
|
|
||||||
fileMapper.deleteById(fileBean.getFileId());
|
|
||||||
deleteSize = FileOperation.getFileSize(fileUrl);
|
|
||||||
if (deleteSize == 0) {
|
|
||||||
deleteSize = fileBean.getFileSize();
|
|
||||||
}
|
|
||||||
//删除服务器文件
|
|
||||||
if (fileBean.getFileUrl() != null && fileBean.getFileUrl().indexOf("upload") != -1){
|
|
||||||
if (fileBean.getIsOSS() != null && fileBean.getIsOSS() == 1) {
|
|
||||||
AliyunOSSDelete.deleteObject(qiwenFileConfig.getAliyun().getOss(), fileBean.getFileUrl().substring(1));
|
|
||||||
} else {
|
|
||||||
FileOperation.deleteFile(fileUrl);
|
|
||||||
if (FileUtil.isImageFile(fileBean.getExtendName())) {
|
|
||||||
FileOperation.deleteFile(PathUtil.getStaticPath() + fileBean.getFileUrl().replace(fileBean.getTimeStampName(), fileBean.getTimeStampName() + "_min"));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if (storageBean != null) {
|
|
||||||
long updateFileSize = storageBean.getStorageSize() - deleteSize;
|
|
||||||
if (updateFileSize < 0) {
|
|
||||||
updateFileSize = 0;
|
|
||||||
}
|
|
||||||
storageBean.setStorageSize(updateFileSize);
|
|
||||||
filetransferService.updateStorageBean(storageBean);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void updateFilepathByFilepath(String oldfilePath, String newfilePath, String fileName, String extendName) {
|
|
||||||
if ("null".equals(extendName)){
|
|
||||||
extendName = null;
|
|
||||||
}
|
|
||||||
//移动根目录
|
|
||||||
fileMapper.updateFilepathByPathAndName(oldfilePath, newfilePath, fileName, extendName);
|
|
||||||
|
|
||||||
//移动子目录
|
|
||||||
oldfilePath = oldfilePath + fileName + "/";
|
|
||||||
newfilePath = newfilePath + fileName + "/";
|
|
||||||
|
|
||||||
oldfilePath = oldfilePath.replace("\\", "\\\\\\\\");
|
|
||||||
oldfilePath = oldfilePath.replace("'", "\\'");
|
|
||||||
oldfilePath = oldfilePath.replace("%", "\\%");
|
|
||||||
oldfilePath = oldfilePath.replace("_", "\\_");
|
|
||||||
|
|
||||||
if (extendName == null) { //为null说明是目录,则需要移动子目录
|
|
||||||
fileMapper.updateFilepathByFilepath(oldfilePath, newfilePath);
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public List<FileBean> selectFileByExtendName(List<String> fileNameList, long userId) {
|
|
||||||
LambdaQueryWrapper<FileBean> wrapper = new LambdaQueryWrapper<>();
|
|
||||||
wrapper.in(FileBean::getExtendName, fileNameList).eq(FileBean::getUserId, userId);
|
|
||||||
List<FileBean> fileBeans = fileMapper.selectList(wrapper);
|
|
||||||
return fileBeans;
|
|
||||||
//return fileMapper.selectFileByExtendName(fileNameList, userId);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public List<FileBean> selectFileNotInExtendNames(List<String> fileNameList, long userId) {
|
|
||||||
LambdaQueryWrapper<FileBean> wrapper = new LambdaQueryWrapper<>();
|
|
||||||
wrapper.notIn(FileBean::getExtendName, fileNameList).eq(FileBean::getUserId, userId);
|
|
||||||
List<FileBean> fileBeans = fileMapper.selectList(wrapper);
|
|
||||||
return fileBeans;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
@ -1,20 +1,36 @@
|
|||||||
package com.qiwenshare.file.service;
|
package com.qiwenshare.file.service;
|
||||||
|
|
||||||
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.extension.service.impl.ServiceImpl;
|
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
||||||
|
import com.qiwenshare.common.cbb.DateUtil;
|
||||||
import com.qiwenshare.file.api.IUserFileService;
|
import com.qiwenshare.file.api.IUserFileService;
|
||||||
import com.qiwenshare.file.domain.FileBean;
|
import com.qiwenshare.file.domain.FileBean;
|
||||||
|
import com.qiwenshare.file.domain.StorageBean;
|
||||||
|
import com.qiwenshare.file.domain.UserBean;
|
||||||
import com.qiwenshare.file.domain.UserFile;
|
import com.qiwenshare.file.domain.UserFile;
|
||||||
import com.qiwenshare.file.mapper.FileMapper;
|
import com.qiwenshare.file.mapper.FileMapper;
|
||||||
import com.qiwenshare.file.mapper.UserFileMapper;
|
import com.qiwenshare.file.mapper.UserFileMapper;
|
||||||
|
import lombok.extern.slf4j.Slf4j;
|
||||||
|
import org.springframework.stereotype.Service;
|
||||||
|
|
||||||
import javax.annotation.Resource;
|
import javax.annotation.Resource;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
|
||||||
|
@Slf4j
|
||||||
|
@Service
|
||||||
public class UserFileService extends ServiceImpl<UserFileMapper, UserFile> implements IUserFileService {
|
public class UserFileService extends ServiceImpl<UserFileMapper, UserFile> implements IUserFileService {
|
||||||
@Resource
|
@Resource
|
||||||
UserFileMapper userFileMapper;
|
UserFileMapper userFileMapper;
|
||||||
|
@Resource
|
||||||
|
FileMapper fileMapper;
|
||||||
|
@Resource
|
||||||
|
FileService fileService;
|
||||||
|
@Resource
|
||||||
|
FiletransferService filetransferService;
|
||||||
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public List<UserFile> selectUserFileByNameAndPath(String fileName, String filePath, Long userId) {
|
public List<UserFile> selectUserFileByNameAndPath(String fileName, String filePath, Long userId) {
|
||||||
LambdaQueryWrapper<UserFile> lambdaQueryWrapper = new LambdaQueryWrapper<>();
|
LambdaQueryWrapper<UserFile> lambdaQueryWrapper = new LambdaQueryWrapper<>();
|
||||||
@ -31,4 +47,167 @@ public class UserFileService extends ServiceImpl<UserFileMapper, UserFile> impl
|
|||||||
public List<Map<String, Object>> userFileList(UserFile userFile) {
|
public List<Map<String, Object>> userFileList(UserFile userFile) {
|
||||||
return userFileMapper.userFileList(userFile);
|
return userFileMapper.userFileList(userFile);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void updateFilepathByFilepath(String oldfilePath, String newfilePath, String fileName, String extendName) {
|
||||||
|
if ("null".equals(extendName)){
|
||||||
|
extendName = null;
|
||||||
|
}
|
||||||
|
//移动根目录
|
||||||
|
userFileMapper.updateFilepathByPathAndName(oldfilePath, newfilePath, fileName, extendName);
|
||||||
|
|
||||||
|
//移动子目录
|
||||||
|
oldfilePath = oldfilePath + fileName + "/";
|
||||||
|
newfilePath = newfilePath + fileName + "/";
|
||||||
|
|
||||||
|
oldfilePath = oldfilePath.replace("\\", "\\\\\\\\");
|
||||||
|
oldfilePath = oldfilePath.replace("'", "\\'");
|
||||||
|
oldfilePath = oldfilePath.replace("%", "\\%");
|
||||||
|
oldfilePath = oldfilePath.replace("_", "\\_");
|
||||||
|
|
||||||
|
if (extendName == null) { //为null说明是目录,则需要移动子目录
|
||||||
|
userFileMapper.updateFilepathByFilepath(oldfilePath, newfilePath);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public List<Map<String, Object>> selectFileByExtendName(List<String> fileNameList, long userId) {
|
||||||
|
// LambdaQueryWrapper<FileBean> wrapper = new LambdaQueryWrapper<>();
|
||||||
|
// wrapper.in(FileBean::getExtendName, fileNameList).eq(FileBean::getUserId, userId);
|
||||||
|
// List<FileBean> fileBeans = fileMapper.selectList(wrapper);
|
||||||
|
// return fileBeans;
|
||||||
|
return userFileMapper.selectFileByExtendName(fileNameList, userId);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public List<Map<String, Object>> selectFileNotInExtendNames(List<String> fileNameList, long userId) {
|
||||||
|
// LambdaQueryWrapper<FileBean> wrapper = new LambdaQueryWrapper<>();
|
||||||
|
// wrapper.notIn(FileBean::getExtendName, fileNameList).eq(FileBean::getUserId, userId);
|
||||||
|
// List<FileBean> fileBeans = fileMapper.selectList(wrapper);
|
||||||
|
return userFileMapper.selectFileNotInExtendNames(fileNameList, userId);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public List<UserFile> selectFileTreeListLikeFilePath(String filePath) {
|
||||||
|
UserFile userFile = new UserFile();
|
||||||
|
filePath = filePath.replace("\\", "\\\\\\\\");
|
||||||
|
filePath = filePath.replace("'", "\\'");
|
||||||
|
filePath = filePath.replace("%", "\\%");
|
||||||
|
filePath = filePath.replace("_", "\\_");
|
||||||
|
|
||||||
|
userFile.setFilePath(filePath);
|
||||||
|
|
||||||
|
LambdaQueryWrapper<UserFile> lambdaQueryWrapper = new LambdaQueryWrapper<>();
|
||||||
|
|
||||||
|
log.info("删除文件路径:" + filePath);
|
||||||
|
|
||||||
|
lambdaQueryWrapper.likeRight(UserFile::getFilePath, filePath);
|
||||||
|
return userFileMapper.selectList(lambdaQueryWrapper);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public List<UserFile> selectFilePathTreeByUserId(Long userId) {
|
||||||
|
LambdaQueryWrapper<UserFile> lambdaQueryWrapper = new LambdaQueryWrapper<>();
|
||||||
|
lambdaQueryWrapper.eq(UserFile::getUserId, userId)
|
||||||
|
.eq(UserFile::getIsDir, 1);
|
||||||
|
return userFileMapper.selectList(lambdaQueryWrapper);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void deleteUserFile(UserFile userFile, UserBean sessionUserBean) {
|
||||||
|
StorageBean storageBean = filetransferService.selectStorageBean(new StorageBean(sessionUserBean.getUserId()));
|
||||||
|
long deleteSize = 0;
|
||||||
|
//String fileUrl = PathUtil.getStaticPath() + fileBean.getFileUrl();
|
||||||
|
if (userFile.getIsDir() == 1) {
|
||||||
|
//1、先删除子目录
|
||||||
|
String filePath = userFile.getFilePath() + userFile.getFileName() + "/";
|
||||||
|
List<UserFile> fileList = selectFileTreeListLikeFilePath(filePath);
|
||||||
|
|
||||||
|
for (int i = 0; i < fileList.size(); i++){
|
||||||
|
UserFile userFileTemp = fileList.get(i);
|
||||||
|
//1.1、删除数据库文件
|
||||||
|
//userFileMapper.deleteById(userFileTemp.getUserFileId());
|
||||||
|
//1.2、如果是文件,需要记录文件大小
|
||||||
|
if (userFileTemp.getIsDir() != 1){
|
||||||
|
FileBean fileBean = fileMapper.selectById(userFileTemp.getFileId());
|
||||||
|
deleteSize += fileBean.getFileSize();
|
||||||
|
//1.3、删除服务器文件,只删除文件,目录是虚拟的
|
||||||
|
// if (file.getFileUrl() != null && file.getFileUrl().indexOf("upload") != -1){
|
||||||
|
// if (file.getIsOSS() != null && file.getIsOSS() == 1) {
|
||||||
|
// AliyunOSSDelete.deleteObject(qiwenFileConfig.getAliyun().getOss(), file.getFileUrl().substring(1));
|
||||||
|
// } else {
|
||||||
|
// FileOperation.deleteFile(PathUtil.getStaticPath() + file.getFileUrl());
|
||||||
|
// if (FileUtil.isImageFile(file.getExtendName())) {
|
||||||
|
// FileOperation.deleteFile(PathUtil.getStaticPath() + file.getFileUrl().replace(file.getTimeStampName(), file.getTimeStampName() + "_min"));
|
||||||
|
// }
|
||||||
|
// }
|
||||||
|
//
|
||||||
|
// }
|
||||||
|
|
||||||
|
LambdaUpdateWrapper<FileBean> fileBeanLambdaUpdateWrapper = new LambdaUpdateWrapper<>();
|
||||||
|
fileBeanLambdaUpdateWrapper.set(FileBean::getPointCount, fileBean.getPointCount() -1)
|
||||||
|
.eq(FileBean::getFileId, fileBean.getFileId());
|
||||||
|
// fileService.decreaseFilePointCount(fileBean.getFileId());
|
||||||
|
}
|
||||||
|
//标记删除标志
|
||||||
|
LambdaUpdateWrapper<UserFile> userFileLambdaUpdateWrapper = new LambdaUpdateWrapper<>();
|
||||||
|
userFileLambdaUpdateWrapper.set(UserFile::getDeleteFlag, 1)
|
||||||
|
.set(UserFile::getDeleteTime, DateUtil.getCurrentTime())
|
||||||
|
.eq(UserFile::getUserFileId, userFileTemp.getUserFileId());
|
||||||
|
userFileMapper.update(null, userFileLambdaUpdateWrapper);
|
||||||
|
|
||||||
|
}
|
||||||
|
//2、根目录单独删除
|
||||||
|
//userFileMapper.deleteById(userFile.getUserFileId());
|
||||||
|
LambdaUpdateWrapper<UserFile> userFileLambdaUpdateWrapper = new LambdaUpdateWrapper<>();
|
||||||
|
userFileLambdaUpdateWrapper.set(UserFile::getDeleteFlag, 1)
|
||||||
|
.set(UserFile::getDeleteTime, DateUtil.getCurrentTime())
|
||||||
|
.eq(UserFile::getUserFileId, userFile.getUserFileId());
|
||||||
|
userFileMapper.update(null, userFileLambdaUpdateWrapper);
|
||||||
|
}else{
|
||||||
|
//userFileMapper.deleteById(userFile.getUserFileId());
|
||||||
|
UserFile userFileTemp = userFileMapper.selectById(userFile.getUserFileId());
|
||||||
|
FileBean fileBean = fileMapper.selectById(userFileTemp.getFileId());
|
||||||
|
|
||||||
|
|
||||||
|
deleteSize = fileBean.getFileSize();
|
||||||
|
|
||||||
|
//删除服务器文件
|
||||||
|
// if (fileBean.getFileUrl() != null && fileBean.getFileUrl().indexOf("upload") != -1){
|
||||||
|
// if (fileBean.getIsOSS() != null && fileBean.getIsOSS() == 1) {
|
||||||
|
// AliyunOSSDelete.deleteObject(qiwenFileConfig.getAliyun().getOss(), fileBean.getFileUrl().substring(1));
|
||||||
|
// } else {
|
||||||
|
// FileOperation.deleteFile(fileUrl);
|
||||||
|
// if (FileUtil.isImageFile(fileBean.getExtendName())) {
|
||||||
|
// FileOperation.deleteFile(PathUtil.getStaticPath() + fileBean.getFileUrl().replace(fileBean.getTimeStampName(), fileBean.getTimeStampName() + "_min"));
|
||||||
|
// }
|
||||||
|
// }
|
||||||
|
// }
|
||||||
|
|
||||||
|
LambdaUpdateWrapper<UserFile> userFileLambdaUpdateWrapper = new LambdaUpdateWrapper<>();
|
||||||
|
userFileLambdaUpdateWrapper.set(UserFile::getDeleteFlag, 1)
|
||||||
|
.set(UserFile::getDeleteTime, DateUtil.getCurrentTime())
|
||||||
|
.eq(UserFile::getUserFileId, userFileTemp.getUserFileId());
|
||||||
|
userFileMapper.update(null, userFileLambdaUpdateWrapper);
|
||||||
|
|
||||||
|
LambdaUpdateWrapper<FileBean> fileBeanLambdaUpdateWrapper = new LambdaUpdateWrapper<>();
|
||||||
|
fileBeanLambdaUpdateWrapper.set(FileBean::getPointCount, fileBean.getPointCount() -1)
|
||||||
|
.eq(FileBean::getFileId, fileBean.getFileId());
|
||||||
|
}
|
||||||
|
|
||||||
|
if (storageBean != null) {
|
||||||
|
long updateFileSize = storageBean.getStorageSize() - deleteSize;
|
||||||
|
if (updateFileSize < 0) {
|
||||||
|
updateFileSize = 0;
|
||||||
|
}
|
||||||
|
storageBean.setStorageSize(updateFileSize);
|
||||||
|
filetransferService.updateStorageBean(storageBean);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -47,21 +47,6 @@
|
|||||||
<!-- </update>-->
|
<!-- </update>-->
|
||||||
|
|
||||||
|
|
||||||
<update id="updateFilepathByFilepath">
|
|
||||||
UPDATE file SET filePath=REPLACE(filePath, #{param1}, #{param2})
|
|
||||||
WHERE filePath like N'${param1}%'
|
|
||||||
</update>
|
|
||||||
|
|
||||||
<update id="updateFilepathByPathAndName">
|
|
||||||
update file set filePath = #{param2}
|
|
||||||
where filePath = #{param1} and fileName = #{param3}
|
|
||||||
<if test="param4 != null">
|
|
||||||
and extendName = #{param4}
|
|
||||||
</if>
|
|
||||||
<if test="param4 == null">
|
|
||||||
and extendName is null
|
|
||||||
</if>
|
|
||||||
</update>
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
@ -14,8 +14,55 @@
|
|||||||
<select id="userFileList" parameterType="com.qiwenshare.file.domain.UserFile" resultType="java.util.Map">
|
<select id="userFileList" parameterType="com.qiwenshare.file.domain.UserFile" resultType="java.util.Map">
|
||||||
select * from userfile
|
select * from userfile
|
||||||
left join file on file.fileId = userfile.fileId
|
left join file on file.fileId = userfile.fileId
|
||||||
where userId = #{userId} and filePath = #{filePath}
|
<where>
|
||||||
|
<if test="userId != null">
|
||||||
|
and userId = #{userId}
|
||||||
|
</if>
|
||||||
|
<if test="filePath != null">
|
||||||
|
and filePath = #{filePath}
|
||||||
|
</if>
|
||||||
|
<if test="extendName != null">
|
||||||
|
and extendName = #{extendName}
|
||||||
|
</if>
|
||||||
|
</where>
|
||||||
|
|
||||||
</select>
|
</select>
|
||||||
|
|
||||||
|
<select id="selectFileByExtendName" parameterType="com.qiwenshare.file.domain.UserFile" resultType="java.util.Map">
|
||||||
|
select * from userfile
|
||||||
|
left join file on file.fileId = userfile.fileId
|
||||||
|
where extendName in
|
||||||
|
<foreach collection="fileNameList" open="(" close=")" separator="," item="fileName" >
|
||||||
|
#{fileName}
|
||||||
|
</foreach>
|
||||||
|
and userId = #{userId}
|
||||||
|
</select>
|
||||||
|
|
||||||
|
<select id="selectFileNotInExtendNames" parameterType="com.qiwenshare.file.domain.UserFile" resultType="java.util.Map">
|
||||||
|
select * from userfile
|
||||||
|
left join file on file.fileId = userfile.fileId
|
||||||
|
where extendName not in
|
||||||
|
<foreach collection="fileNameList" open="(" close=")" separator="," item="fileName" >
|
||||||
|
#{fileName}
|
||||||
|
</foreach>
|
||||||
|
and userId = #{userId}
|
||||||
|
</select>
|
||||||
|
|
||||||
|
|
||||||
|
<update id="updateFilepathByFilepath">
|
||||||
|
UPDATE file SET filePath=REPLACE(filePath, #{param1}, #{param2})
|
||||||
|
WHERE filePath like N'${param1}%'
|
||||||
|
</update>
|
||||||
|
|
||||||
|
<update id="updateFilepathByPathAndName">
|
||||||
|
update userfile set filePath = #{param2}
|
||||||
|
where filePath = #{param1} and fileName = #{param3}
|
||||||
|
<if test="param4 != null">
|
||||||
|
and extendName = #{param4}
|
||||||
|
</if>
|
||||||
|
<if test="param4 == null">
|
||||||
|
and extendName is null
|
||||||
|
</if>
|
||||||
|
</update>
|
||||||
|
|
||||||
</mapper>
|
</mapper>
|
Loading…
Reference in New Issue
Block a user