Эх сурвалжийг харах

feat Dockerfile部署脚本添加

4 өдөр өмнө
parent
commit
b9b2c1ece1

+ 5 - 0
edu-travel-common/edu-travel-common-datasource/pom.xml

@@ -25,6 +25,11 @@
             <scope>provided</scope>
         </dependency>
         <dependency>
+            <groupId>edu.travel</groupId>
+            <artifactId>edu-travel-common-excel</artifactId>
+            <version>1.0-SNAPSHOT</version>
+        </dependency>
+        <dependency>
             <groupId>mysql</groupId>
             <artifactId>mysql-connector-java</artifactId>
             <scope>provided</scope>

+ 42 - 4
edu-travel-common/edu-travel-common-datasource/src/main/java/edu/travel/web/BaseController.java

@@ -1,5 +1,8 @@
 package edu.travel.web;
 
+import com.alibaba.excel.EasyExcel;
+import com.alibaba.excel.context.AnalysisContext;
+import com.alibaba.excel.read.listener.ReadListener;
 import com.baomidou.mybatisplus.extension.service.IService;
 import edu.travel.interfaces.InsertGroups;
 import edu.travel.interfaces.UpdateGroups;
@@ -7,6 +10,8 @@ import edu.travel.resp.BaseResponse;
 import edu.travel.resp.PageResponse;
 import edu.travel.rpc.RPCBaseResponse;
 import edu.travel.rpc.RPCPageResponse;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.context.annotation.Lazy;
 import org.springframework.http.HttpStatus;
@@ -14,16 +19,49 @@ import org.springframework.transaction.annotation.Transactional;
 import org.springframework.validation.Errors;
 import org.springframework.validation.ObjectError;
 import org.springframework.validation.annotation.Validated;
-import org.springframework.web.bind.annotation.GetMapping;
-import org.springframework.web.bind.annotation.PostMapping;
-import org.springframework.web.bind.annotation.RequestBody;
-import org.springframework.web.bind.annotation.RequestParam;
+import org.springframework.web.bind.annotation.*;
+import org.springframework.web.multipart.MultipartFile;
 
+import javax.servlet.http.HttpServletResponse;
+import java.io.IOException;
+import java.io.UnsupportedEncodingException;
+import java.net.URLEncoder;
 import java.util.List;
 
 public class BaseController<T> {
+    Logger logger = LoggerFactory.getLogger(BaseController.class);
     @Autowired
     private IService<T> service;
+    @GetMapping("/download")
+    public void download(T clazz,HttpServletResponse response) throws IOException {
+        response.setContentType("application/vnd.openxmlformats-officedocument.spreadsheetml.sheet");
+        response.setCharacterEncoding("utf-8");
+        String fileName = URLEncoder.encode("导出数据.xlsx", "UTF-8").replaceAll("\\+", "%20");
+        response.setHeader("Content-Disposition", "attachment;filename*=utf-8''" + fileName + ".xlsx");
+        List<T> list = service.list();
+        EasyExcel.write(response.getOutputStream(), clazz.getClass())
+                .sheet("数据")
+                .doWrite(list);
+    }
+    @PostMapping("/upload/excel")
+    public RPCBaseResponse uploadExcel(@RequestBody T clazz ,@RequestPart("file") MultipartFile file) throws IOException {
+        EasyExcel.read(file.getInputStream(),clazz.getClass(),new ReadListener<T>(){
+
+            @Override
+            public void invoke(T t, AnalysisContext analysisContext) {
+                saveTarget(t);
+            }
+
+            @Override
+            public void doAfterAllAnalysed(AnalysisContext analysisContext) {
+                logger.debug("读取完成");
+            }
+        })
+                .sheet()
+                .doRead();
+        return RPCBaseResponse.success();
+    }
+
     @GetMapping("/getById")
     public RPCBaseResponse<T> getId(String id) {
         T byId = service.getById(id);

+ 26 - 0
edu-travel-common/edu-travel-common-excel/pom.xml

@@ -0,0 +1,26 @@
+<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+         xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
+    <modelVersion>4.0.0</modelVersion>
+    <parent>
+        <groupId>edu.travel</groupId>
+        <artifactId>edu-travel-common</artifactId>
+        <version>1.0-SNAPSHOT</version>
+    </parent>
+
+    <artifactId>edu-travel-common-excel</artifactId>
+    <packaging>jar</packaging>
+
+    <name>edu-travel-common-excel</name>
+    <url>http://maven.apache.org</url>
+
+    <properties>
+        <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
+    </properties>
+
+    <dependencies>
+        <dependency>
+            <groupId>com.alibaba</groupId>
+            <artifactId>easyexcel</artifactId>
+        </dependency>
+    </dependencies>
+</project>

+ 1 - 0
edu-travel-common/pom.xml

@@ -28,6 +28,7 @@
         <module>edu-travel-common-adapter</module>
         <module>edu-travel-kafka</module>
         <module>edu-travel-common-guava</module>
+        <module>edu-travel-common-excel</module>
     </modules>
 
     <properties>