From f74ff38c9476c4fa8b963bbfd58b3a968fcd7d7c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E9=A9=AC=E8=B6=85?= Date: Mon, 16 Aug 2021 17:37:02 +0800 Subject: [PATCH] =?UTF-8?q?1=E3=80=81=E4=BF=AE=E5=A4=8D=E6=96=87=E4=BB=B6?= =?UTF-8?q?=E8=A7=A3=E5=8E=8B=E5=A4=B1=E8=B4=A5=E9=97=AE=E9=A2=98=202?= =?UTF-8?q?=E3=80=81=E4=BF=AE=E5=A4=8D=E6=96=B0=E5=BB=BAPPT=E6=96=87?= =?UTF-8?q?=E4=BB=B6=E6=89=93=E5=BC=80=E5=A4=B1=E8=B4=A5=E9=97=AE=E9=A2=98?= =?UTF-8?q?=203=E3=80=81=E6=96=B0=E5=A2=9E=E5=A4=8D=E5=88=B6=E6=96=87?= =?UTF-8?q?=E4=BB=B6=E6=8E=A5=E5=8F=A3=204=E3=80=81=E5=BA=95=E5=B1=82?= =?UTF-8?q?=E4=BB=A3=E7=A0=81=E4=BC=98=E5=8C=96?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- pom.xml | 4 +- .../advice/GlobalExceptionHandlerAdvice.java | 4 +- ...{CMSException.java => QiwenException.java} | 8 +- .../com/qiwenshare/file/api/IFileService.java | 2 +- .../qiwenshare/file/api/IUserFileService.java | 2 + .../file/component/FileDealComp.java | 14 +- .../file/controller/FileController.java | 180 +++++------------ .../controller/FiletransferController.java | 17 +- .../file/controller/OfficeController.java | 4 +- .../file/controller/ShareController.java | 3 + .../com/qiwenshare/file/dto/CopyFileDTO.java | 26 +++ .../file/dto/file/UnzipFileDTO.java | 9 +- .../file/mapper/UserFileMapper.java | 10 + .../qiwenshare/file/service/FileService.java | 181 +++++++++++++++++- .../file/service/FiletransferService.java | 44 ++--- .../file/service/UserFileService.java | 93 +++++---- .../resources/config/application.properties | 8 +- .../{mybatis => }/mapper/FileMapper.xml | 0 .../mapper/OperationLogMapper.xml | 0 .../mapper/RecoveryFileMapper.xml | 0 .../{mybatis => }/mapper/ShareFileMapper.xml | 0 .../{mybatis => }/mapper/ShareMapper.xml | 0 .../{mybatis => }/mapper/StorageMapper.xml | 0 .../{mybatis => }/mapper/UserFileMapper.xml | 41 ++++ .../{mybatis => }/mapper/UserMapper.xml | 0 .../{mybatis => }/mybatis-config.xml | 0 .../resources/static/template/PowerPoint.pptx | Bin 0 -> 33141 bytes src/main/script/winstartw.bat | 31 --- 28 files changed, 412 insertions(+), 269 deletions(-) rename src/main/java/com/qiwenshare/file/advice/{CMSException.java => QiwenException.java} (59%) create mode 100644 src/main/java/com/qiwenshare/file/dto/CopyFileDTO.java rename src/main/resources/{mybatis => }/mapper/FileMapper.xml (100%) rename src/main/resources/{mybatis => }/mapper/OperationLogMapper.xml (100%) rename src/main/resources/{mybatis => }/mapper/RecoveryFileMapper.xml (100%) rename src/main/resources/{mybatis => }/mapper/ShareFileMapper.xml (100%) rename src/main/resources/{mybatis => }/mapper/ShareMapper.xml (100%) rename src/main/resources/{mybatis => }/mapper/StorageMapper.xml (100%) rename src/main/resources/{mybatis => }/mapper/UserFileMapper.xml (71%) rename src/main/resources/{mybatis => }/mapper/UserMapper.xml (100%) rename src/main/resources/{mybatis => }/mybatis-config.xml (100%) delete mode 100644 src/main/script/winstartw.bat diff --git a/pom.xml b/pom.xml index 4b1317c..61e40ee 100644 --- a/pom.xml +++ b/pom.xml @@ -6,12 +6,12 @@ com.qiwenshare qiwenshare - 1.0.7 + 1.0.8 com.qiwenshare qiwen-file - 1.0.7-SNAPSHOT + 1.0.8-SNAPSHOT qiwen-file fileos.qiwenshare.com jar diff --git a/src/main/java/com/qiwenshare/file/advice/GlobalExceptionHandlerAdvice.java b/src/main/java/com/qiwenshare/file/advice/GlobalExceptionHandlerAdvice.java index de28f7d..ebbb5de 100644 --- a/src/main/java/com/qiwenshare/file/advice/GlobalExceptionHandlerAdvice.java +++ b/src/main/java/com/qiwenshare/file/advice/GlobalExceptionHandlerAdvice.java @@ -71,10 +71,10 @@ public class GlobalExceptionHandlerAdvice { /**-------- 自定义定异常处理方法 --------**/ - @ExceptionHandler(CMSException.class) + @ExceptionHandler(QiwenException.class) @ResponseBody @ResponseStatus(HttpStatus.INTERNAL_SERVER_ERROR) - public RestResult error(CMSException e) { + public RestResult error(QiwenException e) { e.printStackTrace(); log.error("全局异常捕获:" + e); return RestResult.fail().message(e.getMessage()).code(e.getCode()); diff --git a/src/main/java/com/qiwenshare/file/advice/CMSException.java b/src/main/java/com/qiwenshare/file/advice/QiwenException.java similarity index 59% rename from src/main/java/com/qiwenshare/file/advice/CMSException.java rename to src/main/java/com/qiwenshare/file/advice/QiwenException.java index 76f68d3..faa929d 100644 --- a/src/main/java/com/qiwenshare/file/advice/CMSException.java +++ b/src/main/java/com/qiwenshare/file/advice/QiwenException.java @@ -7,21 +7,21 @@ import lombok.Data; * 自定义全局异常类 */ @Data -public class CMSException extends RuntimeException { +public class QiwenException extends RuntimeException { private Integer code; - public CMSException(Integer code, String message) { + public QiwenException(Integer code, String message) { super(message); this.code = code; } - public CMSException(ResultCodeEnum resultCodeEnum) { + public QiwenException(ResultCodeEnum resultCodeEnum) { super(resultCodeEnum.getMessage()); this.code = resultCodeEnum.getCode(); } @Override public String toString() { - return "CMSException{" + "code=" + code + ", message=" + this.getMessage() + '}'; + return "QiwenException{" + "code=" + code + ", message=" + this.getMessage() + '}'; } } \ No newline at end of file diff --git a/src/main/java/com/qiwenshare/file/api/IFileService.java b/src/main/java/com/qiwenshare/file/api/IFileService.java index f4f815d..f8b17da 100644 --- a/src/main/java/com/qiwenshare/file/api/IFileService.java +++ b/src/main/java/com/qiwenshare/file/api/IFileService.java @@ -12,7 +12,7 @@ public interface IFileService extends IService { void increaseFilePointCount(Long fileId); void decreaseFilePointCount(Long fileId); - + void unzipFile(long userFileId, int unzipMode, String filePath); diff --git a/src/main/java/com/qiwenshare/file/api/IUserFileService.java b/src/main/java/com/qiwenshare/file/api/IUserFileService.java index b6500f0..63bd9fb 100644 --- a/src/main/java/com/qiwenshare/file/api/IUserFileService.java +++ b/src/main/java/com/qiwenshare/file/api/IUserFileService.java @@ -11,10 +11,12 @@ import java.util.Map; public interface IUserFileService extends IService { List selectUserFileByNameAndPath(String fileName, String filePath, Long userId); + boolean isDirExist(String fileName, String filePath, long userId); List selectSameUserFile(String fileName, String filePath, String extendName, Long userId); void replaceUserFilePath(String filePath, String oldFilePath, Long userId); List userFileList(UserFile userFile, Long beginCount, Long pageCount); void updateFilepathByFilepath(String oldfilePath, String newfilePath, String fileName, String extendName, long userId); + void userFileCopy(String oldfilePath, String newfilePath, String fileName, String extendName, long userId); List selectFileByExtendName(List fileNameList, Long beginCount, Long pageCount, long userId); Long selectCountByExtendName(List fileNameList, Long beginCount, Long pageCount, long userId); diff --git a/src/main/java/com/qiwenshare/file/component/FileDealComp.java b/src/main/java/com/qiwenshare/file/component/FileDealComp.java index 6a7d2e7..b07df9d 100644 --- a/src/main/java/com/qiwenshare/file/component/FileDealComp.java +++ b/src/main/java/com/qiwenshare/file/component/FileDealComp.java @@ -13,7 +13,7 @@ import com.qiwenshare.file.vo.file.FileListVo; import com.qiwenshare.ufop.factory.UFOPFactory; import com.qiwenshare.ufop.operation.read.Reader; import com.qiwenshare.ufop.operation.read.domain.ReadFile; -import com.qiwenshare.ufop.util.PathUtil; +import com.qiwenshare.ufop.util.UFOPUtils; import lombok.extern.slf4j.Slf4j; import org.apache.commons.lang3.StringUtils; import org.springframework.beans.factory.annotation.Autowired; @@ -45,6 +45,7 @@ public class FileDealComp { IShareFileService shareFileService; @Resource IUserFileService userFileService; + @Autowired private IElasticSearchService elasticSearchService; public static Executor exec = Executors.newFixedThreadPool(10); @@ -64,11 +65,13 @@ public class FileDealComp { String extendName = userFile.getExtendName(); Integer deleteFlag = userFile.getDeleteFlag(); Long userId = userFile.getUserId(); + int isDir = userFile.getIsDir(); LambdaQueryWrapper lambdaQueryWrapper = new LambdaQueryWrapper<>(); lambdaQueryWrapper.eq(UserFile::getFilePath, savefilePath) .eq(UserFile::getDeleteFlag, deleteFlag) .eq(UserFile::getUserId, userId) - .eq(UserFile::getFileName, fileName); + .eq(UserFile::getFileName, fileName) + .eq(UserFile::getIsDir, isDir); if (userFile.getIsDir() == 0) { lambdaQueryWrapper.eq(UserFile::getExtendName, extendName); } @@ -87,7 +90,8 @@ public class FileDealComp { lambdaQueryWrapper1.eq(UserFile::getFilePath, savefilePath) .eq(UserFile::getDeleteFlag, deleteFlag) .eq(UserFile::getUserId, userId) - .eq(UserFile::getFileName, fileName + "(" + i + ")"); + .eq(UserFile::getFileName, fileName + "(" + i + ")") + .eq(UserFile::getIsDir, isDir); if (userFile.getIsDir() == 0) { lambdaQueryWrapper1.eq(UserFile::getExtendName, extendName); } @@ -111,10 +115,10 @@ public class FileDealComp { // 加锁,防止并发情况下有重复创建目录情况 Lock lock = new ReentrantLock(); lock.lock(); - String parentFilePath = PathUtil.getParentPath(filePath); + String parentFilePath = UFOPUtils.getParentPath(filePath); while(parentFilePath.contains("/")) { String fileName = parentFilePath.substring(parentFilePath.lastIndexOf("/") + 1); - parentFilePath = PathUtil.getParentPath(parentFilePath); + parentFilePath = UFOPUtils.getParentPath(parentFilePath); LambdaQueryWrapper lambdaQueryWrapper = new LambdaQueryWrapper<>(); lambdaQueryWrapper.eq(UserFile::getFilePath, parentFilePath + FileConstant.pathSeparator) diff --git a/src/main/java/com/qiwenshare/file/controller/FileController.java b/src/main/java/com/qiwenshare/file/controller/FileController.java index 7c66de7..f0a5857 100644 --- a/src/main/java/com/qiwenshare/file/controller/FileController.java +++ b/src/main/java/com/qiwenshare/file/controller/FileController.java @@ -1,34 +1,33 @@ package com.qiwenshare.file.controller; import com.alibaba.fastjson.JSON; - import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper; import com.qiwenshare.common.anno.MyLog; import com.qiwenshare.common.exception.NotLoginException; -import com.qiwenshare.common.util.DateUtil; import com.qiwenshare.common.result.RestResult; -import com.qiwenshare.common.operation.FileOperation; -import com.qiwenshare.common.util.FileUtil; -import com.qiwenshare.file.api.*; +import com.qiwenshare.common.util.DateUtil; +import com.qiwenshare.file.advice.QiwenException; +import com.qiwenshare.file.api.IFileService; +import com.qiwenshare.file.api.IUserFileService; +import com.qiwenshare.file.api.IUserService; import com.qiwenshare.file.component.FileDealComp; import com.qiwenshare.file.config.es.FileSearch; -import com.qiwenshare.file.domain.*; -import com.qiwenshare.file.dto.*; +import com.qiwenshare.file.domain.TreeNode; +import com.qiwenshare.file.domain.UserBean; +import com.qiwenshare.file.domain.UserFile; +import com.qiwenshare.file.dto.BatchMoveFileDTO; +import com.qiwenshare.file.dto.CopyFileDTO; +import com.qiwenshare.file.dto.MoveFileDTO; import com.qiwenshare.file.dto.file.*; import com.qiwenshare.file.vo.file.FileListVo; import com.qiwenshare.ufop.factory.UFOPFactory; -import com.qiwenshare.ufop.operation.copy.domain.CopyFile; -import com.qiwenshare.ufop.operation.download.Downloader; -import com.qiwenshare.ufop.operation.download.domain.DownloadFile; -import com.qiwenshare.ufop.operation.rename.domain.RenameFile; -import com.qiwenshare.ufop.util.PathUtil; +import com.qiwenshare.ufop.util.UFOPUtils; import io.swagger.v3.oas.annotations.Operation; import io.swagger.v3.oas.annotations.Parameter; import io.swagger.v3.oas.annotations.tags.Tag; import lombok.extern.slf4j.Slf4j; import org.apache.commons.codec.digest.DigestUtils; -import org.apache.commons.io.FileUtils; import org.eclipse.jetty.util.StringUtil; import org.elasticsearch.index.query.QueryBuilders; import org.elasticsearch.search.fetch.subphase.highlight.HighlightBuilder; @@ -42,13 +41,10 @@ import org.springframework.data.elasticsearch.core.query.NativeSearchQueryBuilde import org.springframework.web.bind.annotation.*; import javax.annotation.Resource; -import java.io.*; import java.util.*; import java.util.concurrent.Executor; import java.util.concurrent.Executors; -import static com.qiwenshare.common.util.FileUtil.getFileExtendsByType; - @Tag(name = "file", description = "该接口为文件接口,主要用来做一些文件的基本操作,如创建目录,删除,移动,复制等。") @RestController @Slf4j @@ -84,8 +80,9 @@ public class FileController { UserBean sessionUserBean = userService.getUserBeanByToken(token); - List userFiles = userFileService.selectUserFileByNameAndPath(createFileDto.getFileName(), createFileDto.getFilePath(), sessionUserBean.getUserId()); - if (userFiles != null && !userFiles.isEmpty()) { + boolean isDirExist = userFileService.isDirExist(createFileDto.getFileName(), createFileDto.getFilePath(), sessionUserBean.getUserId()); + + if (isDirExist) { return RestResult.fail().message("同名文件已存在"); } @@ -201,7 +198,7 @@ public class FileController { List fileList = null; - userFile.setFilePath(PathUtil.urlDecode(filePath)); + userFile.setFilePath(UFOPUtils.urlDecode(filePath)); if (currentPage == 0 || pageCount == 0) { fileList = userFileService.userFileList(userFile, 0L, 10L); } else { @@ -274,116 +271,41 @@ public class FileController { if (sessionUserBean == null) { throw new NotLoginException(); } - UserFile userFile = userFileService.getById(unzipFileDto.getUserFileId()); - FileBean fileBean = fileService.getById(userFile.getFileId()); - File destFile = new File(PathUtil.getStaticPath() + "temp" + File.separator + fileBean.getFileUrl()); - - - Downloader downloader = ufopFactory.getDownloader(fileBean.getStorageType()); - DownloadFile downloadFile = new DownloadFile(); - downloadFile.setFileUrl(fileBean.getFileUrl()); - downloadFile.setFileSize(fileBean.getFileSize()); - InputStream inputStream = downloader.getInputStream(downloadFile); try { - FileUtils.copyInputStreamToFile(inputStream, destFile); - } catch (IOException e) { - e.printStackTrace(); + fileService.unzipFile(unzipFileDto.getUserFileId(), unzipFileDto.getUnzipMode(), unzipFileDto.getFilePath()); + } catch (QiwenException e) { + return RestResult.fail().message(e.getMessage()); } - - String extendName = userFile.getExtendName(); - - String unzipUrl = (PathUtil.getStaticPath() + "temp" + File.separator + fileBean.getFileUrl()).replace("." + extendName, ""); - - List fileEntryNameList = new ArrayList<>(); - if ("zip".equals(extendName)) { - fileEntryNameList = FileOperation.unzip(destFile, unzipUrl); - } else if ("rar".equals(extendName)) { - try { - fileEntryNameList = FileOperation.unrar(destFile, unzipUrl); - } catch (Exception e) { - e.printStackTrace(); - log.error("rar解压失败" + e); - return RestResult.fail().message("rar解压失败!"); - - - } - } else { - return RestResult.fail().message("不支持的文件格式!"); - } - if (destFile.exists()) { - destFile.delete(); - } - for (int i = 0; i < fileEntryNameList.size(); i++){ - String entryName = fileEntryNameList.get(i); - log.info("文件名:"+ entryName); - executor.execute(() -> { - String totalFileUrl = unzipUrl + entryName; - File currentFile = FileOperation.newFile(totalFileUrl); - - FileBean tempFileBean = new FileBean(); - UserFile saveUserFile = new UserFile(); - - saveUserFile.setUploadTime(DateUtil.getCurrentTime()); - saveUserFile.setUserId(sessionUserBean.getUserId()); - saveUserFile.setFilePath(FileUtil.pathSplitFormat(userFile.getFilePath() + entryName.replace(currentFile.getName(), "")).replace("\\", "/")); - - if (currentFile.isDirectory()){ - saveUserFile.setIsDir(1); - saveUserFile.setFileName(currentFile.getName()); - }else{ - String saveFileUrl = ""; - FileInputStream fileInputStream = null; - try { - fileInputStream = new FileInputStream(currentFile); - CopyFile createFile = new CopyFile(); - createFile.setExtendName(FileUtil.getFileExtendName(totalFileUrl)); - saveFileUrl = ufopFactory.getCopier().copy(fileInputStream, createFile); - } catch (FileNotFoundException e) { - e.printStackTrace(); - } finally { - if (fileInputStream != null) { - try { - log.info("关闭流"); - fileInputStream.close(); - - System.gc(); - try { - Thread.sleep(100); - } catch (InterruptedException e) { - e.printStackTrace(); - } - - } catch (IOException e) { - e.printStackTrace(); - } - } - } - - saveUserFile.setIsDir(0); - saveUserFile.setExtendName(FileUtil.getFileExtendName(totalFileUrl)); - saveUserFile.setFileName(FileUtil.getFileNameNotExtend(currentFile.getName())); - tempFileBean.setFileSize(currentFile.length()); - tempFileBean.setFileUrl(saveFileUrl); - tempFileBean.setPointCount(1); - tempFileBean.setStorageType(storageType); - boolean saveResult = fileService.save(tempFileBean); - if (saveResult) { - boolean result = currentFile.delete(); - log.info("删除{}结果:{}",saveFileUrl, result); - } - } - - saveUserFile.setFileId(tempFileBean.getFileId()); - saveUserFile.setDeleteFlag(0); - userFileService.save(saveUserFile); - }); - - } return RestResult.success(); } + @Operation(summary = "文件复制", description = "可以复制文件或者目录", tags = {"file"}) + @RequestMapping(value = "/copyfile", method = RequestMethod.POST) + @MyLog(operation = "文件复制", module = CURRENT_MODULE) + @ResponseBody + public RestResult copyFile(@RequestBody CopyFileDTO copyFileDTO, @RequestHeader("token") String token) { + + UserBean sessionUserBean = userService.getUserBeanByToken(token); + if (sessionUserBean == null) { + throw new NotLoginException(); + } + String oldfilePath = copyFileDTO.getOldFilePath(); + String newfilePath = copyFileDTO.getFilePath(); + String fileName = copyFileDTO.getFileName(); + String extendName = copyFileDTO.getExtendName(); + if (StringUtil.isEmpty(extendName)) { + String testFilePath = oldfilePath + fileName + "/"; + if (newfilePath.startsWith(testFilePath)) { + return RestResult.fail().message("原路径与目标路径冲突,不能移动"); + } + } + + userFileService.updateFilepathByFilepath(oldfilePath, newfilePath, fileName, extendName, sessionUserBean.getUserId()); + return RestResult.success(); + + } @Operation(summary = "文件移动", description = "可以移动文件或者目录", tags = {"file"}) @RequestMapping(value = "/movefile", method = RequestMethod.POST) @@ -468,19 +390,19 @@ public class FileController { } Long total = 0L; - if (fileType == FileUtil.OTHER_TYPE) { + if (fileType == UFOPUtils.OTHER_TYPE) { List arrList = new ArrayList<>(); - arrList.addAll(Arrays.asList(FileUtil.DOC_FILE)); - arrList.addAll(Arrays.asList(FileUtil.IMG_FILE)); - arrList.addAll(Arrays.asList(FileUtil.VIDEO_FILE)); - arrList.addAll(Arrays.asList(FileUtil.MUSIC_FILE)); + arrList.addAll(Arrays.asList(UFOPUtils.DOC_FILE)); + arrList.addAll(Arrays.asList(UFOPUtils.IMG_FILE)); + arrList.addAll(Arrays.asList(UFOPUtils.VIDEO_FILE)); + arrList.addAll(Arrays.asList(UFOPUtils.MUSIC_FILE)); fileList = userFileService.selectFileNotInExtendNames(arrList,beginCount, pageCount, userId); total = userFileService.selectCountNotInExtendNames(arrList,beginCount, pageCount, userId); } else { - fileList = userFileService.selectFileByExtendName(getFileExtendsByType(fileType), beginCount, pageCount,userId); - total = userFileService.selectCountByExtendName(getFileExtendsByType(fileType), beginCount, pageCount,userId); + fileList = userFileService.selectFileByExtendName(UFOPUtils.getFileExtendsByType(fileType), beginCount, pageCount,userId); + total = userFileService.selectCountByExtendName(UFOPUtils.getFileExtendsByType(fileType), beginCount, pageCount,userId); } Map map = new HashMap<>(); diff --git a/src/main/java/com/qiwenshare/file/controller/FiletransferController.java b/src/main/java/com/qiwenshare/file/controller/FiletransferController.java index fb3730d..6e4c48a 100644 --- a/src/main/java/com/qiwenshare/file/controller/FiletransferController.java +++ b/src/main/java/com/qiwenshare/file/controller/FiletransferController.java @@ -4,21 +4,23 @@ import com.qiwenshare.common.anno.MyLog; import com.qiwenshare.common.exception.NotLoginException; import com.qiwenshare.common.result.RestResult; import com.qiwenshare.common.util.DateUtil; -import com.qiwenshare.common.util.FileUtil; import com.qiwenshare.common.util.MimeUtils; import com.qiwenshare.file.api.IFileService; import com.qiwenshare.file.api.IFiletransferService; import com.qiwenshare.file.api.IUserFileService; import com.qiwenshare.file.api.IUserService; import com.qiwenshare.file.component.FileDealComp; -import com.qiwenshare.file.domain.*; +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.dto.DownloadFileDTO; import com.qiwenshare.file.dto.UploadFileDTO; import com.qiwenshare.file.dto.file.PreviewDTO; import com.qiwenshare.file.service.StorageService; import com.qiwenshare.file.vo.file.FileListVo; import com.qiwenshare.file.vo.file.UploadFileVo; -import com.qiwenshare.ufop.util.PathUtil; +import com.qiwenshare.ufop.util.UFOPUtils; import io.swagger.v3.oas.annotations.Operation; import io.swagger.v3.oas.annotations.tags.Tag; import lombok.extern.slf4j.Slf4j; @@ -29,7 +31,6 @@ import javax.annotation.Resource; import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse; import java.io.UnsupportedEncodingException; -import java.sql.SQLIntegrityConstraintViolationException; import java.util.HashMap; import java.util.List; import java.util.Map; @@ -82,16 +83,16 @@ public class FiletransferController { userFile.setUserId(sessionUserBean.getUserId()); String relativePath = uploadFileDto.getRelativePath(); if (relativePath.contains("/")) { - userFile.setFilePath(uploadFileDto.getFilePath() + PathUtil.getParentPath(relativePath) + "/"); - fileDealComp.restoreParentFilePath(uploadFileDto.getFilePath() + PathUtil.getParentPath(relativePath) + "/", sessionUserBean.getUserId()); + userFile.setFilePath(uploadFileDto.getFilePath() + UFOPUtils.getParentPath(relativePath) + "/"); + fileDealComp.restoreParentFilePath(uploadFileDto.getFilePath() + UFOPUtils.getParentPath(relativePath) + "/", sessionUserBean.getUserId()); fileDealComp.deleteRepeatSubDirFile(uploadFileDto.getFilePath(), sessionUserBean.getUserId()); } else { userFile.setFilePath(uploadFileDto.getFilePath()); } String fileName = uploadFileDto.getFilename(); - userFile.setFileName(FileUtil.getFileNameNotExtend(fileName)); - userFile.setExtendName(FileUtil.getFileExtendName(fileName)); + userFile.setFileName(UFOPUtils.getFileNameNotExtend(fileName)); + userFile.setExtendName(UFOPUtils.getFileExtendName(fileName)); userFile.setDeleteFlag(0); List userFileList = userFileService.userFileList(userFile, null, null); if (userFileList.size() <= 0) { diff --git a/src/main/java/com/qiwenshare/file/controller/OfficeController.java b/src/main/java/com/qiwenshare/file/controller/OfficeController.java index 90df681..9328237 100644 --- a/src/main/java/com/qiwenshare/file/controller/OfficeController.java +++ b/src/main/java/com/qiwenshare/file/controller/OfficeController.java @@ -20,7 +20,7 @@ import com.qiwenshare.ufop.operation.copy.domain.CopyFile; import com.qiwenshare.ufop.operation.download.domain.DownloadFile; import com.qiwenshare.ufop.operation.write.Writer; import com.qiwenshare.ufop.operation.write.domain.WriteFile; -import com.qiwenshare.ufop.util.PathUtil; +import com.qiwenshare.ufop.util.UFOPUtils; import io.swagger.v3.oas.annotations.Operation; import io.swagger.v3.oas.annotations.tags.Tag; import lombok.extern.slf4j.Slf4j; @@ -89,7 +89,7 @@ public class OfficeController { } else if ("pptx".equals(extendName)) { templateFilePath = "template/PowerPoint.pptx"; } - String templateFileUrl = PathUtil.getStaticPath() + templateFilePath; + String templateFileUrl = UFOPUtils.getStaticPath() + templateFilePath; FileInputStream fileInputStream = new FileInputStream(templateFileUrl); Copier copier = ufopFactory.getCopier(); CopyFile copyFile = new CopyFile(); diff --git a/src/main/java/com/qiwenshare/file/controller/ShareController.java b/src/main/java/com/qiwenshare/file/controller/ShareController.java index 19d28b9..2d12506 100644 --- a/src/main/java/com/qiwenshare/file/controller/ShareController.java +++ b/src/main/java/com/qiwenshare/file/controller/ShareController.java @@ -218,6 +218,9 @@ public class ShareController { LambdaQueryWrapper lambdaQueryWrapper = new LambdaQueryWrapper<>(); lambdaQueryWrapper.eq(Share::getShareBatchNum, checkEndTimeDTO.getShareBatchNum()); Share share = shareService.getOne(lambdaQueryWrapper); + if (share == null) { + return RestResult.fail().message("文件不存在!"); + } String endTime = share.getEndTime(); Date endTimeDate = null; try { diff --git a/src/main/java/com/qiwenshare/file/dto/CopyFileDTO.java b/src/main/java/com/qiwenshare/file/dto/CopyFileDTO.java new file mode 100644 index 0000000..e809b27 --- /dev/null +++ b/src/main/java/com/qiwenshare/file/dto/CopyFileDTO.java @@ -0,0 +1,26 @@ +package com.qiwenshare.file.dto; + +import io.swagger.v3.oas.annotations.media.Schema; +import lombok.Data; + +@Data +@Schema(name = "复制文件DTO",required = true) +public class CopyFileDTO { + @Schema(description = "用户文件id", required = true) + private long userFileId; + + @Schema(description = "文件路径", required = true) + private String filePath; + + @Schema(description = "文件名", required = true) + @Deprecated + private String fileName; + + @Schema(description = "旧文件名", required = true) + @Deprecated + private String oldFilePath; + @Schema(description = "扩展名", required = true) + @Deprecated + private String extendName; + +} diff --git a/src/main/java/com/qiwenshare/file/dto/file/UnzipFileDTO.java b/src/main/java/com/qiwenshare/file/dto/file/UnzipFileDTO.java index 7874368..321da33 100644 --- a/src/main/java/com/qiwenshare/file/dto/file/UnzipFileDTO.java +++ b/src/main/java/com/qiwenshare/file/dto/file/UnzipFileDTO.java @@ -9,10 +9,9 @@ public class UnzipFileDTO { @Schema(description = "文件url", required = true) private long userFileId; - @Schema(description = "文件url", required = true) - @Deprecated - private String fileUrl; - @Schema(description = "文件路径", required = true) - @Deprecated + @Schema(description = "解压模式 0-解压到当前文件夹, 1-自动创建该文件名目录,并解压到目录里, 3-手动选择解压目录", required = true) + private int unzipMode; + + @Schema(description = "解压目的文件目录,仅当 unzipMode 为 2 时必传") private String filePath; } diff --git a/src/main/java/com/qiwenshare/file/mapper/UserFileMapper.java b/src/main/java/com/qiwenshare/file/mapper/UserFileMapper.java index b0fc3f5..6bd7d38 100644 --- a/src/main/java/com/qiwenshare/file/mapper/UserFileMapper.java +++ b/src/main/java/com/qiwenshare/file/mapper/UserFileMapper.java @@ -17,6 +17,16 @@ public interface UserFileMapper extends BaseMapper { void updateFilepathByPathAndName(String oldfilePath, String newfilePath, String fileName, String extendName, long userId); void updateFilepathByFilepath(String oldfilePath, String newfilePath, long userId); + void batchInsertByPathAndName(@Param("oldFilePath") String oldFilePath, + @Param("newFilePath") String newfilePath, + @Param("fileName") String fileName, + @Param("extendName") String extendName, + @Param("userId") long userId); + + void batchInsertByFilepath(@Param("oldFilePath") String oldFilePath, + @Param("newFilePath") String newfilePath, + @Param("userId") long userId); + List selectFileByExtendName(List fileNameList, Long beginCount, Long pageCount, long userId); Long selectCountByExtendName(List fileNameList, Long beginCount, Long pageCount, long userId); List selectFileNotInExtendNames(List fileNameList, Long beginCount, Long pageCount, long userId); diff --git a/src/main/java/com/qiwenshare/file/service/FileService.java b/src/main/java/com/qiwenshare/file/service/FileService.java index b98f075..44df03f 100644 --- a/src/main/java/com/qiwenshare/file/service/FileService.java +++ b/src/main/java/com/qiwenshare/file/service/FileService.java @@ -1,23 +1,55 @@ package com.qiwenshare.file.service; import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; +import com.qiwenshare.common.operation.FileOperation; +import com.qiwenshare.common.util.DateUtil; +import com.qiwenshare.file.advice.QiwenException; import com.qiwenshare.file.api.IFileService; +import com.qiwenshare.file.component.FileDealComp; import com.qiwenshare.file.domain.FileBean; +import com.qiwenshare.file.domain.UserFile; import com.qiwenshare.file.mapper.FileMapper; +import com.qiwenshare.file.mapper.UserFileMapper; +import com.qiwenshare.ufop.factory.UFOPFactory; +import com.qiwenshare.ufop.operation.copy.domain.CopyFile; +import com.qiwenshare.ufop.operation.download.Downloader; +import com.qiwenshare.ufop.operation.download.domain.DownloadFile; +import com.qiwenshare.ufop.util.UFOPUtils; import lombok.extern.slf4j.Slf4j; +import org.apache.commons.codec.digest.DigestUtils; +import org.apache.commons.io.FileUtils; +import org.springframework.beans.factory.annotation.Value; import org.springframework.stereotype.Service; import org.springframework.transaction.annotation.Transactional; import javax.annotation.Resource; +import java.io.File; +import java.io.FileInputStream; +import java.io.IOException; +import java.io.InputStream; +import java.util.ArrayList; +import java.util.HashMap; +import java.util.List; +import java.util.Map; +import java.util.concurrent.Executor; +import java.util.concurrent.Executors; @Slf4j @Service @Transactional(rollbackFor=Exception.class) public class FileService extends ServiceImpl implements IFileService { - + public static Executor executor = Executors.newFixedThreadPool(20); @Resource FileMapper fileMapper; + @Resource + UserFileMapper userFileMapper; + @Resource + UFOPFactory ufopFactory; + @Value("${ufop.storage-type}") + private Integer storageType; + @Resource + FileDealComp fileDealComp; @Override public void increaseFilePointCount(Long fileId) { @@ -37,5 +69,152 @@ public class FileService extends ServiceImpl implements IF fileMapper.updateById(fileBean); } + @Override + public void unzipFile(long userFileId, int unzipMode, String filePath) { + UserFile userFile = userFileMapper.selectById(userFileId); + FileBean fileBean = fileMapper.selectById(userFile.getFileId()); + File destFile = new File(UFOPUtils.getStaticPath() + "temp" + File.separator + fileBean.getFileUrl()); + + + Downloader downloader = ufopFactory.getDownloader(fileBean.getStorageType()); + DownloadFile downloadFile = new DownloadFile(); + downloadFile.setFileUrl(fileBean.getFileUrl()); + downloadFile.setFileSize(fileBean.getFileSize()); + InputStream inputStream = downloader.getInputStream(downloadFile); + + try { + FileUtils.copyInputStreamToFile(inputStream, destFile); + } catch (IOException e) { + e.printStackTrace(); + } + + + String extendName = userFile.getExtendName(); + + String unzipUrl = UFOPUtils.getTempPath(fileBean.getFileUrl()).getAbsolutePath().replace("." + extendName, ""); + + List fileEntryNameList = new ArrayList<>(); + if ("zip".equals(extendName)) { + fileEntryNameList = FileOperation.unzip(destFile, unzipUrl); + } else if ("rar".equals(extendName)) { + try { + fileEntryNameList = FileOperation.unrar(destFile, unzipUrl); + } catch (Exception e) { + e.printStackTrace(); + log.error("rar解压失败" + e); + throw new QiwenException(500001, "rar解压异常:" + e.getMessage()); + } + } else { + throw new QiwenException(500002, "不支持的文件格式!"); + } + if (destFile.exists()) { + destFile.delete(); + } + for (int i = 0; i < fileEntryNameList.size(); i++){ + String entryName = fileEntryNameList.get(i); + log.info("文件名:"+ entryName); + executor.execute(() -> { + String totalFileUrl = unzipUrl + entryName; + File currentFile = new File(totalFileUrl); + + FileBean tempFileBean = new FileBean(); + UserFile saveUserFile = new UserFile(); + + saveUserFile.setUploadTime(DateUtil.getCurrentTime()); + saveUserFile.setUserId(userFile.getUserId()); + saveUserFile.setFilePath(UFOPUtils.pathSplitFormat(userFile.getFilePath() + entryName.replace(currentFile.getName(), "")).replace("\\", "/")); + + if (currentFile.isDirectory()){ + saveUserFile.setIsDir(1); + saveUserFile.setFileName(currentFile.getName()); + }else{ + + FileInputStream fileInputStream = null; + FileInputStream fileInputStream1 = null; + try { + fileInputStream = new FileInputStream(currentFile); + String md5Str = DigestUtils.md5Hex(fileInputStream); + Map param = new HashMap(); + param.put("identifier", md5Str); + + List list = fileMapper.selectByMap(param); + if (list != null && !list.isEmpty()) { //文件已存在 + increaseFilePointCount(list.get(0).getFileId()); + saveUserFile.setFileId(list.get(0).getFileId()); + } else { //文件不存在 + fileInputStream1 = new FileInputStream(currentFile); + CopyFile createFile = new CopyFile(); + createFile.setExtendName(UFOPUtils.getFileExtendName(totalFileUrl)); + String saveFileUrl = ufopFactory.getCopier().copy(fileInputStream1, createFile); + tempFileBean.setFileSize(currentFile.length()); + tempFileBean.setFileUrl(saveFileUrl); + tempFileBean.setPointCount(1); + tempFileBean.setStorageType(storageType); + tempFileBean.setIdentifier(md5Str); + fileMapper.insert(tempFileBean); + + saveUserFile.setFileId(tempFileBean.getFileId()); + } + } catch (IOException e) { + e.printStackTrace(); + } finally { + if (fileInputStream != null) { + try { + log.info("关闭流"); + fileInputStream.close(); + } catch (IOException e) { + e.printStackTrace(); + } + } + if (fileInputStream1 != null) { + try { + log.info("关闭流"); + fileInputStream1.close(); + + System.gc(); + try { + Thread.sleep(100); + } catch (InterruptedException e) { + e.printStackTrace(); + } + + } catch (IOException e) { + e.printStackTrace(); + } + + currentFile.delete(); + } + } + + saveUserFile.setIsDir(0); + saveUserFile.setExtendName(UFOPUtils.getFileExtendName(totalFileUrl)); + saveUserFile.setFileName(UFOPUtils.getFileNameNotExtend(currentFile.getName())); + + } + + + saveUserFile.setDeleteFlag(0); + + if (unzipMode == 1) { + String destFilePath = "/" + userFile.getFilePath() + saveUserFile.getFilePath(); + saveUserFile.setFilePath(destFilePath); + } else if(unzipMode == 2) { + saveUserFile.setFilePath(filePath); + } + + String fileName = fileDealComp.getRepeatFileName(saveUserFile, saveUserFile.getFilePath()); + + if (saveUserFile.getIsDir() == 1 && !fileName.equals(saveUserFile.getFileName())) { + //如果是目录,而且重复,什么也不做 + } else { + saveUserFile.setFileName(fileName); + userFileMapper.insert(saveUserFile); + } + + }); + + } + } + } diff --git a/src/main/java/com/qiwenshare/file/service/FiletransferService.java b/src/main/java/com/qiwenshare/file/service/FiletransferService.java index 2841cb5..47d7d69 100644 --- a/src/main/java/com/qiwenshare/file/service/FiletransferService.java +++ b/src/main/java/com/qiwenshare/file/service/FiletransferService.java @@ -1,35 +1,18 @@ package com.qiwenshare.file.service; -import java.io.*; -import java.util.List; -import java.util.zip.Adler32; -import java.util.zip.CheckedOutputStream; -import java.util.zip.ZipEntry; -import java.util.zip.ZipOutputStream; - -import javax.annotation.Resource; -import javax.servlet.http.HttpServletRequest; -import javax.servlet.http.HttpServletResponse; - import cn.hutool.core.bean.BeanUtil; import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper; - -import com.qiwenshare.common.constant.FileConstant; -import com.qiwenshare.common.operation.FileOperation; import com.qiwenshare.common.util.DateUtil; - -import com.qiwenshare.common.util.FileUtil; import com.qiwenshare.file.api.IFiletransferService; - import com.qiwenshare.file.component.FileDealComp; +import com.qiwenshare.file.domain.FileBean; +import com.qiwenshare.file.domain.StorageBean; import com.qiwenshare.file.domain.UserFile; import com.qiwenshare.file.dto.DownloadFileDTO; import com.qiwenshare.file.dto.UploadFileDTO; import com.qiwenshare.file.dto.file.PreviewDTO; import com.qiwenshare.file.mapper.FileMapper; -import com.qiwenshare.file.domain.FileBean; -import com.qiwenshare.file.domain.StorageBean; import com.qiwenshare.file.mapper.StorageMapper; import com.qiwenshare.file.mapper.UserFileMapper; import com.qiwenshare.file.vo.file.FileListVo; @@ -47,12 +30,21 @@ import com.qiwenshare.ufop.operation.preview.domain.PreviewFile; import com.qiwenshare.ufop.operation.upload.Uploader; import com.qiwenshare.ufop.operation.upload.domain.UploadFile; import com.qiwenshare.ufop.operation.upload.domain.UploadFileResult; -import com.qiwenshare.ufop.util.PathUtil; +import com.qiwenshare.ufop.util.UFOPUtils; import lombok.extern.slf4j.Slf4j; -import org.apache.commons.lang3.StringUtils; import org.springframework.stereotype.Service; import org.springframework.transaction.annotation.Transactional; +import javax.annotation.Resource; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; +import java.io.*; +import java.util.List; +import java.util.zip.Adler32; +import java.util.zip.CheckedOutputStream; +import java.util.zip.ZipEntry; +import java.util.zip.ZipOutputStream; + @Slf4j @Service @Transactional(rollbackFor=Exception.class) @@ -103,8 +95,8 @@ public class FiletransferService implements IFiletransferService { UserFile userFile = new UserFile(); String relativePath = uploadFileDto.getRelativePath(); if (relativePath.contains("/")) { - userFile.setFilePath(uploadFileDto.getFilePath() + PathUtil.getParentPath(relativePath) + "/"); - fileDealComp.restoreParentFilePath(uploadFileDto.getFilePath() + PathUtil.getParentPath(relativePath) + "/", userId); + userFile.setFilePath(uploadFileDto.getFilePath() + UFOPUtils.getParentPath(relativePath) + "/"); + fileDealComp.restoreParentFilePath(uploadFileDto.getFilePath() + UFOPUtils.getParentPath(relativePath) + "/", userId); fileDealComp.deleteRepeatSubDirFile(uploadFileDto.getFilePath(), userId); } else { @@ -157,7 +149,7 @@ public class FiletransferService implements IFiletransferService { .eq(UserFile::getDeleteFlag, 0); List userFileList = userFileMapper.selectList(lambdaQueryWrapper); - String staticPath = PathUtil.getStaticPath(); + String staticPath = UFOPUtils.getStaticPath(); String tempPath = staticPath + "temp" + File.separator; File tempDirFile = new File(tempPath); if (!tempDirFile.exists()) { @@ -224,10 +216,10 @@ public class FiletransferService implements IFiletransferService { Downloader downloader = ufopFactory.getDownloader(StorageTypeEnum.LOCAL.getCode()); DownloadFile downloadFile = new DownloadFile(); downloadFile.setFileUrl("temp" + File.separator+userFile.getFileName() + ".zip"); - File tempFile = FileOperation.newFile(PathUtil.getStaticPath() + downloadFile.getFileUrl()); + File tempFile = new File(UFOPUtils.getStaticPath() + downloadFile.getFileUrl()); httpServletResponse.setContentLengthLong(tempFile.length()); downloader.download(httpServletResponse, downloadFile); - String zipPath = PathUtil.getStaticPath() + "temp" + File.separator+userFile.getFileName() + ".zip"; + String zipPath = UFOPUtils.getStaticPath() + "temp" + File.separator+userFile.getFileName() + ".zip"; File file = new File(zipPath); if (file.exists()) { file.delete(); diff --git a/src/main/java/com/qiwenshare/file/service/UserFileService.java b/src/main/java/com/qiwenshare/file/service/UserFileService.java index eff3ab2..119579b 100644 --- a/src/main/java/com/qiwenshare/file/service/UserFileService.java +++ b/src/main/java/com/qiwenshare/file/service/UserFileService.java @@ -43,10 +43,25 @@ public class UserFileService extends ServiceImpl impl lambdaQueryWrapper.eq(UserFile::getFileName, fileName) .eq(UserFile::getFilePath, filePath) .eq(UserFile::getUserId, userId) - .eq(UserFile::getDeleteFlag, "0"); + .eq(UserFile::getDeleteFlag, 0); return userFileMapper.selectList(lambdaQueryWrapper); } + @Override + public boolean isDirExist(String fileName, String filePath, long userId){ + LambdaQueryWrapper lambdaQueryWrapper = new LambdaQueryWrapper<>(); + lambdaQueryWrapper.eq(UserFile::getFileName, fileName) + .eq(UserFile::getFilePath, filePath) + .eq(UserFile::getUserId, userId) + .eq(UserFile::getDeleteFlag, 0) + .eq(UserFile::getIsDir, 1); + List list = userFileMapper.selectList(lambdaQueryWrapper); + if (list != null && !list.isEmpty()) { + return true; + } + return false; + } + @Override public List selectSameUserFile(String fileName, String filePath, String extendName, Long userId) { LambdaQueryWrapper lambdaQueryWrapper = new LambdaQueryWrapper<>(); @@ -68,54 +83,6 @@ public class UserFileService extends ServiceImpl impl return userFileMapper.userFileList(userFile, beginCount, pageCount); } -// public void renameUserFile(Long userFileId, String newFileName, Long userId) { -// UserFile userFile = userFileMapper.selectById(userFileId); -// if (1 == userFile.getIsDir()) { -// LambdaUpdateWrapper lambdaUpdateWrapper = new LambdaUpdateWrapper<>(); -// lambdaUpdateWrapper.set(UserFile::getFileName, newFileName) -// .set(UserFile::getUploadTime, DateUtil.getCurrentTime()) -// .eq(UserFile::getUserFileId, userFile.getUserFileId()); -// userFileMapper.update(null, lambdaUpdateWrapper); -// replaceUserFilePath(userFile.getFilePath() + newFileName + "/", -// userFile.getFilePath() + userFile.getFileName() + "/", userId); -// } else { -// FileBean fileBean = fileMapper.selectById(userFile.getFileId()); -// if (fileBean.getIsOSS() == 1) { -//// LambdaQueryWrapper lambdaQueryWrapper = new LambdaQueryWrapper<>(); -//// lambdaQueryWrapper.eq(UserFile::getUserFileId, renameFileDto.getUserFileId()); -//// UserFile userFile = userFileService.getOne(lambdaQueryWrapper); -//// -//// FileBean file = fileService.getById(userFile.getFileId()); -// String fileUrl = fileBean.getFileUrl(); -// String newFileUrl = fileUrl.replace(userFile.getFileName(), newFileName); -// -// AliyunOSSRename.rename(qiwenFileConfig.getAliyun().getOss(), -// fileUrl.substring(1), -// newFileUrl.substring(1)); -// LambdaUpdateWrapper lambdaUpdateWrapper = new LambdaUpdateWrapper<>(); -// lambdaUpdateWrapper -// .set(FileBean::getFileUrl, newFileUrl) -// .eq(FileBean::getFileId, fileBean.getFileId()); -// fileMapper.update(null, lambdaUpdateWrapper); -// -// LambdaUpdateWrapper userFileLambdaUpdateWrapper = new LambdaUpdateWrapper<>(); -// userFileLambdaUpdateWrapper -// .set(UserFile::getFileName, newFileName) -// .set(UserFile::getUploadTime, DateUtil.getCurrentTime()) -// .eq(UserFile::getUserFileId, userFileId); -// userFileMapper.update(null, userFileLambdaUpdateWrapper); -// } else { -// LambdaUpdateWrapper lambdaUpdateWrapper = new LambdaUpdateWrapper<>(); -// lambdaUpdateWrapper.set(UserFile::getFileName, newFileName) -// .set(UserFile::getUploadTime, DateUtil.getCurrentTime()) -// .eq(UserFile::getUserFileId, userFileId); -// userFileMapper.update(null, lambdaUpdateWrapper); -// } -// -// -// } -// } - @Override public void updateFilepathByFilepath(String oldfilePath, String newfilePath, String fileName, String extendName, long userId) { if ("null".equals(extendName)){ @@ -139,6 +106,34 @@ public class UserFileService extends ServiceImpl impl } + @Override + public void userFileCopy(String oldfilePath, String newfilePath, String fileName, String extendName, long userId) { + + + + if ("null".equals(extendName)){ + extendName = null; + } + + userFileMapper.batchInsertByPathAndName(oldfilePath, newfilePath, fileName, extendName, userId); + //移动根目录 +// userFileMapper.updateFilepathByPathAndName(oldfilePath, newfilePath, fileName, extendName, userId); + + //移动子目录 + oldfilePath = oldfilePath + fileName + "/"; + newfilePath = newfilePath + fileName + "/"; + + oldfilePath = oldfilePath.replace("\\", "\\\\\\\\"); + oldfilePath = oldfilePath.replace("'", "\\'"); + oldfilePath = oldfilePath.replace("%", "\\%"); + oldfilePath = oldfilePath.replace("_", "\\_"); + + if (extendName == null) { //为null说明是目录,则需要移动子目录 + userFileMapper.batchInsertByFilepath(oldfilePath, newfilePath, userId); + } + + } + @Override public List selectFileByExtendName(List fileNameList, Long beginCount, Long pageCount, long userId) { diff --git a/src/main/resources/config/application.properties b/src/main/resources/config/application.properties index 44ef35b..b4dc6a7 100644 --- a/src/main/resources/config/application.properties +++ b/src/main/resources/config/application.properties @@ -16,8 +16,8 @@ logging.level.root=info #mybatis配置 mybatis.type-aliases-package=com.qiwenshare.file.domain -mybatis.config-locations=classpath:mybatis/mybatis-config.xml -mybatis.mapper-locations=classpath:mybatis/mapper/*.xml +mybatis.config-locations=classpath:mybatis-config.xml +mybatis.mapper-locations=classpath:mapper/*.xml #mybatis.configuration.log-impl=org.apache.ibatis.logging.stdout.StdOutImpl @@ -44,7 +44,7 @@ spring.servlet.multipart.enabled=true spring.main.allow-bean-definition-overriding=true mybatis-plus.type-aliases-package=com.qiwenshare.web.domain -mybatis-plus.mapper-locations=classpath:mybatis/mapper/*.xml +mybatis-plus.mapper-locations=classpath:mapper/*.xml mybatis-plus.configuration.map-underscore-to-camel-case=false mybatis-plus.global-config.banner=false @@ -106,6 +106,6 @@ spring.elasticsearch.rest.password= # 当前部署外网IP,用于office预览 -deployment.host: 192.168.31.158:${server.port} +deployment.host=192.168.31.158:${server.port} diff --git a/src/main/resources/mybatis/mapper/FileMapper.xml b/src/main/resources/mapper/FileMapper.xml similarity index 100% rename from src/main/resources/mybatis/mapper/FileMapper.xml rename to src/main/resources/mapper/FileMapper.xml diff --git a/src/main/resources/mybatis/mapper/OperationLogMapper.xml b/src/main/resources/mapper/OperationLogMapper.xml similarity index 100% rename from src/main/resources/mybatis/mapper/OperationLogMapper.xml rename to src/main/resources/mapper/OperationLogMapper.xml diff --git a/src/main/resources/mybatis/mapper/RecoveryFileMapper.xml b/src/main/resources/mapper/RecoveryFileMapper.xml similarity index 100% rename from src/main/resources/mybatis/mapper/RecoveryFileMapper.xml rename to src/main/resources/mapper/RecoveryFileMapper.xml diff --git a/src/main/resources/mybatis/mapper/ShareFileMapper.xml b/src/main/resources/mapper/ShareFileMapper.xml similarity index 100% rename from src/main/resources/mybatis/mapper/ShareFileMapper.xml rename to src/main/resources/mapper/ShareFileMapper.xml diff --git a/src/main/resources/mybatis/mapper/ShareMapper.xml b/src/main/resources/mapper/ShareMapper.xml similarity index 100% rename from src/main/resources/mybatis/mapper/ShareMapper.xml rename to src/main/resources/mapper/ShareMapper.xml diff --git a/src/main/resources/mybatis/mapper/StorageMapper.xml b/src/main/resources/mapper/StorageMapper.xml similarity index 100% rename from src/main/resources/mybatis/mapper/StorageMapper.xml rename to src/main/resources/mapper/StorageMapper.xml diff --git a/src/main/resources/mybatis/mapper/UserFileMapper.xml b/src/main/resources/mapper/UserFileMapper.xml similarity index 71% rename from src/main/resources/mybatis/mapper/UserFileMapper.xml rename to src/main/resources/mapper/UserFileMapper.xml index 1c1394a..6df4505 100644 --- a/src/main/resources/mybatis/mapper/UserFileMapper.xml +++ b/src/main/resources/mapper/UserFileMapper.xml @@ -96,6 +96,47 @@ and userId = #{param5} + + insert into userfile ( deleteBatchNum, deleteFlag, deleteTime, + extendName, fileId, fileName, filePath, isDir, uploadTime, userId) + (select deleteBatchNum, deleteFlag, deleteTime, extendName, fileId, + fileName, #{newFilePath}, isDir, uploadTime, userId + from userfile + + + and userId = #{userId} + + + and fileName = #{fileName} + + + and filePath = #{oldFilePath} + + + + and extendName = #{extendName} + + + and isDir = 1 + + + + + ) + + + + insert into userfile ( deleteBatchNum, deleteFlag, deleteTime, + extendName, fileId, fileName, filePath, isDir, uploadTime, userId) + (select deleteBatchNum, deleteFlag, deleteTime, extendName, fileId, + fileName, REPLACE(filePath, #{oldFilePath}, #{newFilePath}), isDir, + uploadTime, userId + from userfile + where filePath like N'${oldFilePath}%' and userId = #{userId} + ) + + +