bc_zhang hace 4 años
padre
commit
20bad46a16

+ 33 - 22
src/main/java/com/zglc/fm/controller/FaultController.java

@@ -49,9 +49,11 @@ public class FaultController {
     public Result<Object> importFile(HttpServletRequest request, @RequestParam("file") MultipartFile file){
         Date date = new Date();
         String sourcePath1;
-
         sourcePath1 = "d:\\sourcefm";
-        String filePath = FileTool.fileUp(file, sourcePath1, date.getTime() + file.getOriginalFilename());
+        String extName = ""; // 扩展名格式:
+        extName = file.getOriginalFilename().substring(file.getOriginalFilename().lastIndexOf("."));
+        String filePath = FileTool.fileUp(file, sourcePath1, new Date().getTime()  + extName);
+//        String filePath = FileTool.fileUp(file, sourcePath1, date.getTime() + file.getOriginalFilename());
 
         FileTypeUtil.Type fileType = FileTypeUtil.getFileType(file.getOriginalFilename());
         if (fileType == FileTypeUtil.Type.DOC || fileType == FileTypeUtil.Type.DOCX ||  fileType == FileTypeUtil.Type.RTF ) {
@@ -60,26 +62,26 @@ public class FaultController {
         if (fileType == FileTypeUtil.Type.PPT || fileType == FileTypeUtil.Type.PPTX) {
             Ppt2ToPdf.convertPpt2Pdf(filePath, sourcePath1);
         }
-        if (fileType == FileTypeUtil.Type.DOC) {
-            deleteDir(new File(filePath));
-            filePath = filePath.replaceAll( "doc","pdf");
-        }
-        if (fileType == FileTypeUtil.Type.DOCX) {
-            deleteDir(new File(filePath));
-            filePath = filePath.replaceAll( "docx","pdf");
-        }
-        if (fileType == FileTypeUtil.Type.RTF) {
-            deleteDir(new File(filePath));
-            filePath = filePath.replaceAll( "rtf","pdf");
-        }
-        if (fileType == FileTypeUtil.Type.PPT) {
-            deleteDir(new File(filePath));
-            filePath = filePath.replaceAll( "ppt","pdf");
-        }
-        if (fileType == FileTypeUtil.Type.PPTX) {
-            deleteDir(new File(filePath));
-            filePath = filePath.replaceAll( "pptx","pdf");
-        }
+//        if (fileType == FileTypeUtil.Type.DOC) {
+////            deleteDir(new File(filePath));
+//            filePath = filePath.replaceAll( "doc","pdf");
+//        }
+//        if (fileType == FileTypeUtil.Type.DOCX) {
+////            deleteDir(new File(filePath));
+//            filePath = filePath.replaceAll( "docx","pdf");
+//        }
+//        if (fileType == FileTypeUtil.Type.RTF) {
+////            deleteDir(new File(filePath));
+//            filePath = filePath.replaceAll( "rtf","pdf");
+//        }
+//        if (fileType == FileTypeUtil.Type.PPT) {
+////            deleteDir(new File(filePath));
+//            filePath = filePath.replaceAll( "ppt","pdf");
+//        }
+//        if (fileType == FileTypeUtil.Type.PPTX) {
+////            deleteDir(new File(filePath));
+//            filePath = filePath.replaceAll( "pptx","pdf");
+//        }
         filePath = filePath.replaceAll( "d:","");
         return Result.success(filePath);
     }
@@ -90,6 +92,15 @@ public class FaultController {
         file.delete();
     }
 
+    @ApiOperation("浏览资料")
+    @ApiResponses({
+            @ApiResponse(code = 0, message = "成功")
+    })
+    @GetMapping("browse")
+    public Result<String> browse(@RequestParam String filepath){
+        return faultService.browse(filepath);
+    }
+
     @ApiOperation("列出所有")
     @ApiResponses({
             @ApiResponse(code = 0, message = "成功")

+ 19 - 0
src/main/java/com/zglc/fm/service/FaultService.java

@@ -3,6 +3,7 @@ package com.zglc.fm.service;
 import com.zglc.fm.base.Result;
 import com.zglc.fm.dao.master.FaultDao;
 import com.zglc.fm.entity.*;
+import com.zglc.fm.utils.FileTypeUtil;
 import org.springframework.beans.factory.annotation.Value;
 import org.springframework.stereotype.Service;
 import tk.mybatis.mapper.entity.Example;
@@ -81,6 +82,24 @@ public class FaultService {
         file.delete();
     }
 
+    public Result<String> browse(String filepath){
+        FileTypeUtil.Type fileType = FileTypeUtil.getFileType(filepath);
+        if (fileType == FileTypeUtil.Type.DOC ) {
+            filepath = filepath.replaceAll( "doc","pdf");
+        }
+        if (fileType == FileTypeUtil.Type.DOCX ) {
+            filepath = filepath.replaceAll( "docx","pdf");
+        }
+        if (fileType == FileTypeUtil.Type.PPT ) {
+            filepath = filepath.replaceAll( "ppt","pdf");
+        }
+        if (fileType == FileTypeUtil.Type.PPTX ) {
+            filepath = filepath.replaceAll( "pptx","pdf");
+        }
+        return Result.success(filepath);
+    }
+
+
     public Result<String> edit(FaultEntity data) {
         boolean flag = true;
         String msg = "";