chendayu 2 年之前
父节点
当前提交
13881b050f

+ 3 - 3
src/main/java/com/example/fms/controller/FileMangerController.java

@@ -43,7 +43,7 @@ public class FileMangerController {
     @PostMapping("/uploadSystemFile1")
     @Operation(summary = "上传文件")
     public String upload(MultipartFile file, Integer sourceId) {
-        System.out.println(file +"------------"+sourceId);
+        System.out.println(file + "------------" + sourceId);
         return Response.success();
     }
 
@@ -61,7 +61,7 @@ public class FileMangerController {
 
     @PostMapping("/getFileData")
     @Operation(summary = "获取文件信息")
-    public List<SystemFile> getFileData(@RequestBody List<Integer> fileIds){
+    public List<SystemFile> getFileData(@RequestBody List<Integer> fileIds) {
         LambdaQueryWrapper<SystemFile> queryWrapper = new LambdaQueryWrapper<>();
         queryWrapper.in(SystemFile::getId, fileIds);
         List<SystemFile> systemFiles = systemFileService.list(queryWrapper);
@@ -70,7 +70,7 @@ public class FileMangerController {
 
     @PostMapping("/deleteSystemFile")
     @Operation(summary = "删除文件")
-    public String delete(@RequestBody FMSDeleteFileDTO fMSDeleteFileDTO){
+    public String delete(@RequestBody FMSDeleteFileDTO fMSDeleteFileDTO) {
         fileManagerService.delete(fMSDeleteFileDTO.getIds(), fMSDeleteFileDTO.getType());
         return Response.success("删除系统文件成功");
     }

+ 16 - 14
src/main/java/com/example/fms/service/FileFactoryService.java

@@ -33,8 +33,8 @@ public class FileFactoryService {
      * @param sourceId
      * @return
      */
-    public List<SystemFileDTO> uploadFiles(List<MultipartFile> files, Integer sourceId){
-        if(files != null && files.size() != 0) {
+    public List<SystemFileDTO> uploadFiles(List<MultipartFile> files, Integer sourceId) {
+        if (files != null && files.size() != 0) {
             //调用解析配置方法,获取配置信息
             List<ConfigSettingVO> configSettingVOS = ExcuteConfigUtils.excuteConfigVO();
             ConfigSettingVO configSettingVO = configSettingVOS.stream().filter(item -> item.getSourceId().equals(sourceId)).findFirst().orElse(null);
@@ -42,7 +42,7 @@ public class FileFactoryService {
                 return null;
             }
             String sourceName = configSettingVO.getSourceName();
-            if(sourceName.equals("FSS")) {
+            if (sourceName.equals("FSS")) {
                 return this.uploadToFSS(files, configSettingVO);
             }
             return null;
@@ -58,15 +58,15 @@ public class FileFactoryService {
      * @param configSettingVO
      * @return
      */
-    public List<SystemFileDTO> uploadToFSS(List<MultipartFile> files, ConfigSettingVO configSettingVO){
+    public List<SystemFileDTO> uploadToFSS(List<MultipartFile> files, ConfigSettingVO configSettingVO) {
         List<SystemFileDTO> systemFileDTOS = new ArrayList<>();
-        for(MultipartFile file:files){
+        for (MultipartFile file : files) {
             try {
                 String directoryName = fileUtils.getDirectoryName();
                 SystemFileDTO systemFileDTO = SftpService.upload(configSettingVO.getFilePath() + directoryName, file, configSettingVO);
-                systemFileDTO.setPType(0);
+                systemFileDTO.setPType(configSettingVO.getSourceId());
                 systemFileDTO.setOriginalName(file.getOriginalFilename());
-                systemFileDTO.setFilePath("/file/" + directoryName + "/" + systemFileDTO.getFileName());
+                systemFileDTO.setFilePath(configSettingVO.getFilePath() + directoryName + "/" + systemFileDTO.getFileName());
                 systemFileDTOS.add(systemFileDTO);
             } catch (Exception e) {
                 e.printStackTrace();
@@ -78,6 +78,7 @@ public class FileFactoryService {
 
     /**
      * 下载文件
+     *
      * @param downloadSysFileDTO
      * @throws Exception
      */
@@ -98,16 +99,17 @@ public class FileFactoryService {
             return null;
         }
     }
+
     /**
-     * @param //directory 下载目录 根据SFTP设置的根目录来进行传输
+     * @param //directory    下载目录 根据SFTP设置的根目录来进行传输
      * @param //downloadFile 下载的文件
-     * @param //saveFile 存在本地的路径
+     * @param //saveFile     存在本地的路径
      */
     public byte[] downloadFromFSS(DownloadSysFileDTO downloadSysFileDTO, ConfigSettingVO configSettingVO) throws Exception {
         //下载目录,也是存储路径
         String filePath = downloadSysFileDTO.getFilePath();
         int index = filePath.lastIndexOf("/");
-        String directory = filePath.substring(0,index);
+        String directory = filePath.substring(0, index);
         //下载的文件,也就是文件名
         String downloadFile = downloadSysFileDTO.getFileName();
         //存在本地的路径,随机生成
@@ -116,18 +118,19 @@ public class FileFactoryService {
         byte[] fileData = SftpService.download(directory, downloadFile, configSettingVO);
         return fileData;
     }
+
     /**
      * 删除文件
      *
      * @param filePath
      * @param pType
      */
-    public static void delete(String filePath, Integer pType){
+    public static void delete(String filePath, Integer pType) {
         //调用解析配置方法,获取配置信息
         List<ConfigSettingVO> configSettingVOS = ExcuteConfigUtils.excuteConfigVO();
         //根据传入类型判断从哪里删除数据
         //如果为1,则为服务器
-        if(pType.equals(1)){
+        if (pType.equals(1)) {
             int sourceId = 1;
             ConfigSettingVO configSettingVO = configSettingVOS.stream().filter(item -> item.getSourceId().equals(sourceId)).findFirst().orElse(null);
             //拆分路径字符串
@@ -141,12 +144,11 @@ public class FileFactoryService {
             } catch (Exception e) {
                 throw new XiaoShiException("删除错误");
             }
-        } else if(pType.equals(2)){//类型为2,则为阿里云OSS
+        } else if (pType.equals(2)) {//类型为2,则为阿里云OSS
             int sourceId = 2;
             ConfigSettingVO configSettingVO = configSettingVOS.stream().filter(item -> item.getSourceId().equals(sourceId)).findFirst().orElse(null);
         }
     }
 
 
-
 }

+ 16 - 16
src/main/java/com/example/fms/service/FileMangerService.java

@@ -33,13 +33,13 @@ public class FileMangerService {
      * @param files
      * @param sourceId
      */
-    public List<Integer> add(List<MultipartFile> files, Integer sourceId){
-        if(files != null && files.size() != 0){
+    public List<Integer> add(List<MultipartFile> files, Integer sourceId) {
+        if (files != null && files.size() != 0) {
             //1.获取文件上传到服务器,调用FileFactory的uploadFile
             List<SystemFileDTO> systemFileDTOS = fileFactoryService.uploadFiles(files, sourceId);
             //2.根据上传后的返回实体类信息,将实体类信息入库,调用systemFileService add
-            if(systemFileDTOS != null && systemFileDTOS.size() != 0 ) {
-                List<Integer> insertIds = systemFileService.add(systemFileDTOS,sourceId);
+            if (systemFileDTOS != null && systemFileDTOS.size() != 0) {
+                List<Integer> insertIds = systemFileService.add(systemFileDTOS, sourceId);
                 return insertIds;
             } else {
                 throw new XiaoShiException("入表信息为空");
@@ -52,12 +52,12 @@ public class FileMangerService {
     //取系统文件
     public byte[] download(Integer fileId) throws Exception {
         DownloadSysFileDTO downloadSysFileDTO = new DownloadSysFileDTO();
-        if(fileId != null){
+        if (fileId != null) {
             SystemFileVO systemFileVO = systemFileService.query(fileId);
-            if(systemFileVO.getIsDelete().equals(1)){
+            if (systemFileVO.getIsDelete().equals(1)) {
                 return null;
             } else {
-                BeanUtils.copyProperties(systemFileVO,downloadSysFileDTO);
+                BeanUtils.copyProperties(systemFileVO, downloadSysFileDTO);
                 downloadSysFileDTO.setSourceId(systemFileVO.getPType());
                 return fileFactoryService.download(downloadSysFileDTO);
             }
@@ -71,19 +71,19 @@ public class FileMangerService {
      * @param ids
      * @param type
      */
-    public void delete(List<Integer> ids, Integer type){
+    public void delete(List<Integer> ids, Integer type) {
         //首先判断传入的需要删除的id集合不能为空
-        if(CollectionUtils.isEmpty(ids)){
+        if (CollectionUtils.isEmpty(ids)) {
             throw new XiaoShiException("需要删除的id集合不能为空");
         }
-        if(type == null){
+        if (type == null) {
             throw new XiaoShiException("删除类型不能为空");
         }
         //有逻辑删除和物理删除两种,需要进行判定,传入类型为2时,物理删除;传入类型为1时,逻辑删除
         //逻辑删除(更新isDelete字段为1)
-        if(type.equals(1)){
+        if (type.equals(1)) {
             //遍历传入的id集合,获取需要更新的对象,赋值给实体类
-            for(int i = 0; i < ids.size(); i++){
+            for (int i = 0; i < ids.size(); i++) {
                 SystemFileVO systemFileVO = systemFileMapper.query(ids.get(i));
                 systemFileVO.setIsDelete(1);
                 //将查询出来的vo赋值给实体类
@@ -91,7 +91,7 @@ public class FileMangerService {
                 BeanUtils.copyProperties(systemFileVO, systemFile);
                 //更新表
                 int row = systemFileMapper.update(systemFile);
-                if(row != 1){
+                if (row != 1) {
                     String mes = "逻辑删除系统文件第" + i + "条失败";
                     log.info("逻辑删除失败,{}", mes);
                     throw new XiaoShiException(mes);
@@ -100,8 +100,8 @@ public class FileMangerService {
         }
         //物理删除(删除服务器文件,删除数据库中记录)
         //sftp删除文件
-        if(type.equals(2)){
-            for(int i = 0; i < ids.size(); i++){
+        if (type.equals(2)) {
+            for (int i = 0; i < ids.size(); i++) {
                 //根据id到表中查询该文件记录的数据
                 SystemFileVO systemFileVO = systemFileService.query(ids.get(i));
                 //pType判断是服务器还是阿里云OSS
@@ -109,7 +109,7 @@ public class FileMangerService {
                 String filePath = systemFileVO.getFilePath();
                 fileFactoryService.delete(filePath, pType);
                 int row = systemFileMapper.deleteById(ids.get(i));
-                if(row != 1){
+                if (row != 1) {
                     throw new XiaoShiException("删除异常");
                 } else {
                     log.info("删除成功");

+ 9 - 8
src/main/java/com/example/fms/service/SystemFileService.java

@@ -30,12 +30,12 @@ public class SystemFileService extends ServiceImpl<SystemFileMapper, SystemFile>
      *
      * @param systemFileDTOS
      */
-    public List<Integer> add(List<SystemFileDTO> systemFileDTOS,Integer sourceId){
+    public List<Integer> add(List<SystemFileDTO> systemFileDTOS, Integer sourceId) {
         //判断传入列表不为空
-        if(systemFileDTOS != null && systemFileDTOS.size() > 0){
+        if (systemFileDTOS != null && systemFileDTOS.size() > 0) {
             List<Integer> insertIds = new ArrayList<>();
             //遍历传入列表
-            for(int i = 0; i < systemFileDTOS.size(); i++) {
+            for (int i = 0; i < systemFileDTOS.size(); i++) {
                 SystemFile systemFile = new SystemFile();
                 //取集合中的dto对象,并赋值给实体类
                 SystemFileDTO systemFileDTO = systemFileDTOS.get(i);
@@ -58,13 +58,14 @@ public class SystemFileService extends ServiceImpl<SystemFileMapper, SystemFile>
 
     /**
      * 更新系统文件(批量)
+     *
      * @param systemFileUpdateDTOS
      */
-    public void update(List<SystemFileUpdateDTO> systemFileUpdateDTOS){
+    public void update(List<SystemFileUpdateDTO> systemFileUpdateDTOS) {
         //判断传入对象不为空
-        if(systemFileUpdateDTOS != null && systemFileUpdateDTOS.size() > 0){
+        if (systemFileUpdateDTOS != null && systemFileUpdateDTOS.size() > 0) {
             //遍历传入列表
-            for(int i = 0; i < systemFileUpdateDTOS.size(); i++){
+            for (int i = 0; i < systemFileUpdateDTOS.size(); i++) {
                 //取集合中的dto对象,并赋值给实体类
                 SystemFileUpdateDTO systemFileUpdateDTO = systemFileUpdateDTOS.get(i);
                 SystemFile systemFile = this.getById(systemFileUpdateDTO.getId());
@@ -83,9 +84,9 @@ public class SystemFileService extends ServiceImpl<SystemFileMapper, SystemFile>
      * @param id
      * @return
      */
-    public SystemFileVO query(Integer id){
+    public SystemFileVO query(Integer id) {
         //id不为空且id不等于0
-        if(id != null && id != 0){
+        if (id != null && id != 0) {
             SystemFileVO systemFileVO = new SystemFileVO();
             SystemFile systemFile = this.getById(id);
             BeanUtils.copyProperties(systemFile, systemFileVO);