wuheng 1 year ago
parent
commit
a034a9d4b7

+ 91 - 3
common/src/main/java/com/koobietech/eas/common/utils/FileManager.java

@@ -1,7 +1,95 @@
 package com.koobietech.eas.common.utils;
 
+import org.apache.poi.xwpf.usermodel.XWPFDocument;
+
+import java.io.*;
+
 public class FileManager {
-//    public boolean saveDocument(XWPFDocument document, String savePath){
-//
-//    }
+    public boolean saveDocument(XWPFDocument document, String savePath){
+        boolean ret = true;
+        FileOutputStream fileOutputStream = null;
+        try {
+            fileOutputStream = new FileOutputStream(savePath);
+            document.write(fileOutputStream);
+        } catch (IOException e) {
+            ret = false;
+        } finally {
+            try {
+                fileOutputStream.close();
+            } catch (IOException e) {}
+        }
+        return ret;
+    }
+
+    public boolean saveDocument(XWPFDocument document, String savePath, String fileName){
+        return saveDocument(document, savePath + fileName);
+    }
+
+    public boolean createPath(String path){
+        File file = new File(path);
+        if (!file.exists()){
+            file.mkdirs();
+        }
+        return true;
+    }
+
+    public boolean saveFile(InputStream stream, String savePath){
+        FileOutputStream fileOutputStream = null;
+        try {
+            fileOutputStream = new FileOutputStream(savePath);
+            int bytesRead;
+            byte[] buffer = new byte[1024];
+            while ((bytesRead = stream.read(buffer)) != -1){
+                fileOutputStream.write(bytesRead);
+            }
+        } catch (IOException e) {
+            e.printStackTrace();
+        } finally {
+            try {
+                fileOutputStream.close();
+            }catch (IOException e){}
+        }
+        return true;
+    }
+
+    public boolean saveFile(InputStream  stream, String savePath, String fileName) {
+        return saveFile(stream, savePath + fileName);
+    }
+
+    public boolean isFileExists(String filePath){
+        File file = new File(filePath);
+        return file.exists();
+    }
+
+    public boolean deleteFile(String filePath){
+        File file = new File(filePath);
+        return file.delete();
+    }
+
+    public boolean isFolderExists(String folderPath){
+        File file = new File(folderPath);
+        return file.exists();
+    }
+
+    public boolean createFolder(String folderPath){
+        File file = new File(folderPath);
+        return file.mkdirs();
+    }
+
+    public boolean deleteFolder(String folderPath){
+        File file = new File(folderPath);
+        return file.delete();
+    }
+
+    public boolean copyFile(String srcFilePath, String destFilePath){
+        File srcFile = new File(srcFilePath);
+        File destFile = new File(destFilePath);
+        return srcFile.renameTo(destFile);
+    }
+
+    public boolean moveFile(String srcFilePath, String destFilePath){
+        File srcFile = new File(srcFilePath);
+        File destFile = new File(destFilePath);
+        return srcFile.renameTo(destFile);
+    }
 }

+ 4 - 0
controller/pom.xml

@@ -14,6 +14,10 @@
     </parent>
 
     <dependencies>
+        <dependency>
+            <groupId>xerces</groupId>
+            <artifactId>xercesImpl</artifactId>
+        </dependency>
         <dependency>
             <groupId>com.anji-plus</groupId>
             <artifactId>spring-boot-starter-captcha</artifactId>

+ 19 - 5
controller/src/test/java/com/koobietech/eas/controller/ControllerApplicationTests.java

@@ -1,14 +1,18 @@
 package com.koobietech.eas.controller;
 
 import cn.afterturn.easypoi.excel.ExcelExportUtil;
+import cn.afterturn.easypoi.excel.ExcelImportUtil;
 import cn.afterturn.easypoi.excel.entity.ExportParams;
+import cn.afterturn.easypoi.excel.entity.ImportParams;
 import cn.afterturn.easypoi.excel.entity.params.ExcelExportEntity;
+import cn.afterturn.easypoi.handler.inter.IReadHandler;
 import cn.afterturn.easypoi.handler.inter.IWriter;
 import com.koobietech.eas.common.constant.UserType;
 import com.koobietech.eas.common.pojo.JwtUserDto;
 import com.koobietech.eas.common.service.RedisService;
 import com.koobietech.eas.common.utils.JwtManager;
 import com.koobietech.eas.common.utils.PasswordManager;
+import com.koobietech.eas.mbg.model.EasArcTlsScores;
 import com.koobietech.eas.mbg.model.EasSysLogs;
 import org.apache.poi.ss.usermodel.Workbook;
 import org.junit.jupiter.api.Test;
@@ -23,11 +27,22 @@ import java.util.*;
 @SpringBootTest
 class ControllerApplicationTests {
 
-    @Test
-    void contextLoads() throws IOException {
+//    @Test
+//    void contextLoads() {
+//        try {
+//            ImportParams params = new ImportParams();
+//            List<Map<String, Object>> arc = ExcelImportUtil.importExcel(
+//                    new FileInputStream("C:\\Users\\lc\\Desktop\\1.xlsx"),
+//                    Map.class, params);
+//            for (Map<String, Object> map : arc) {
+//                System.out.println(map);
+//            }
+//        } catch (Exception e) {
+//            e.printStackTrace();
+//        }
+//    }
+
 
-        InputStream wordStream = this.getClass().getClassLoader().getResourceAsStream("\\temp\\StuRegistTemp.docx");
-        System.out.println( wordStream );
 
 //        List<Map> list = new ArrayList<>();
 //        Workbook workbook = null;
@@ -62,6 +77,5 @@ class ControllerApplicationTests {
 //        fos.close();
 
 
-    }
 
 }

+ 12 - 1
pom.xml

@@ -33,13 +33,24 @@
         <javax.servlet-api.version>4.0.1</javax.servlet-api.version>
         <spring-data-redis.version>2.7.3</spring-data-redis.version>
         <knife4j.version>4.1.0</knife4j.version>
-        <easypoi.version>4.3.0</easypoi.version>
+        <easypoi.version>4.4.0</easypoi.version>
         <pagehelper.starter.version>1.3.1</pagehelper.starter.version>
         <maven.compiler.plugin.version>3.8.1</maven.compiler.plugin.version>
         <captcha.version>1.3.0</captcha.version>
+        <xerces.version>2.9.1</xerces.version>
     </properties>
     <dependencyManagement>
         <dependencies>
+            <dependency>
+                <groupId>xerces</groupId>
+                <artifactId>xercesImpl</artifactId>
+                <version>${xerces.version}</version>
+            </dependency>
+            <dependency>
+                <groupId>cn.afterturn</groupId>
+                <artifactId>easypoi-wps</artifactId>
+                <version>${easypoi.version}</version>
+            </dependency>
             <dependency>
                 <groupId>com.anji-plus</groupId>
                 <artifactId>spring-boot-starter-captcha</artifactId>

+ 7 - 0
upload/src/main/java/com/koobietech/eas/upload/UploadService.java

@@ -1,4 +1,11 @@
 package com.koobietech.eas.upload;
 
 public class UploadService {
+    public boolean uploadFile(){
+        return false;
+    }
+
+    public boolean moveFile(){
+        return false;
+    }
 }