Browse Source

fix:尝试实现预览pdf

chillqi 3 years ago
parent
commit
4028e293cc

+ 5 - 0
seecoder-portal-server/pom.xml

@@ -152,6 +152,11 @@
             <artifactId>postgresql</artifactId>
             <version>42.3.6</version>
         </dependency>
+        <dependency>
+            <groupId>commons-io</groupId>
+            <artifactId>commons-io</artifactId>
+            <version>2.4</version>
+        </dependency>
     </dependencies>
 
 </project>

+ 8 - 0
seecoder-portal-server/src/main/java/cn/seecoder/seecoderportalserver/SeecoderPortalServerApplication.java

@@ -6,6 +6,14 @@ import org.mybatis.spring.annotation.MapperScan;
 import org.springframework.boot.SpringApplication;
 import org.springframework.boot.autoconfigure.SpringBootApplication;
 import org.springframework.boot.context.properties.EnableConfigurationProperties;
+import org.springframework.web.bind.annotation.RequestMapping;
+import org.springframework.web.servlet.config.annotation.CorsRegistry;
+import org.springframework.web.servlet.config.annotation.WebMvcConfigurerAdapter;
+
+import javax.servlet.http.HttpServletRequest;
+import javax.servlet.http.HttpServletResponse;
+import java.util.HashMap;
+import java.util.Map;
 
 /**
  * @author Kunduin

+ 11 - 1
seecoder-portal-server/src/main/java/cn/seecoder/seecoderportalserver/config/SpringSecurityConfiguration.java

@@ -104,6 +104,7 @@ public class SpringSecurityConfiguration extends WebSecurityConfigurerAdapter {
                         "/api/message/getByCourseId",
                         "/api/message/getView",
                         "/api/message/read",
+                        "/api/message/getInvitations",
                         "/api/project",
                         "/api/project/findAll",
                         "/api/project/findCourse",
@@ -115,7 +116,16 @@ public class SpringSecurityConfiguration extends WebSecurityConfigurerAdapter {
                         "/api/group/one",
                         "/api/group/all",
                         "/api/group/member/add",
-                        "/api/group/rule"
+                        "/api/group/rule",
+                        "/api/courseWare",
+                        "/api/courseWare/create",
+                        "/api/courseWare/getCourseWaresByCourseId",
+                        "/api/courseWare/getById",
+                        "/api/courseWare/checkName",
+                        "/api/courseWare/changeCourseWareName",
+                        "/api/courseWare/uploadCourseWareFile",
+                        "/api/courseWare/delete"
+
                 )
                 .permitAll() // authenticate
                 .and()

+ 2 - 0
seecoder-portal-server/src/main/java/cn/seecoder/seecoderportalserver/service/CourseWareService.java

@@ -30,4 +30,6 @@ public interface CourseWareService {
 
     String changeCourseWareName(Long id, String name);
 
+    String getCourseWareUrlById(Long id);
+
 }

+ 6 - 0
seecoder-portal-server/src/main/java/cn/seecoder/seecoderportalserver/serviceImpl/CourseWareServiceImpl.java

@@ -150,4 +150,10 @@ public class CourseWareServiceImpl implements CourseWareService {
         return newName;
     }
 
+    @Override
+    public String getCourseWareUrlById(Long id) {
+        CourseWare courseWare = courseWareRepository.findCourseWareById(id);
+        return courseWare.getFileUrl();
+    }
+
 }

+ 28 - 5
seecoder-portal-server/src/main/java/cn/seecoder/seecoderportalserver/web/rest/CourseWareController.java

@@ -13,6 +13,11 @@ import org.springframework.web.multipart.MultipartFile;
 import javax.servlet.http.HttpServletRequest;
 import javax.servlet.http.HttpServletResponse;
 import java.io.IOException;
+import java.io.InputStream;
+import java.io.OutputStream;
+import java.net.HttpURLConnection;
+import java.net.URL;
+import org.apache.commons.io.IOUtils;
 import java.util.List;
 
 @RestController
@@ -56,14 +61,32 @@ public class CourseWareController {
         return OkResponse.of(courseWareService.getCourseWareById(id));
     }
 
-//    @GetMapping("/download")
-//    public OkResponse<String> downloadCourseWare(HttpServletRequest req, HttpServletResponse res, @RequestParam Long id) throws IOException {
-//        return OkResponse.of(courseWareService.downloadCourseWare(req, res, id));
-//    }
-
     @PostMapping("/changeCourseWareName")
     public OkResponse<String> changeCourseWareName(@RequestParam Long id, @RequestParam String newName) {
         return OkResponse.of(courseWareService.changeCourseWareName(id, newName));
     }
 
+    @GetMapping("/getUrlById")
+    public OkResponse<String> getCourseWareUrlById(@RequestParam Long id) {
+        return OkResponse.of(courseWareService.getCourseWareUrlById(id));
+    }
+
+//    @RequestMapping(name = "/showPdf")
+//    public String showPdf(HttpServletRequest request, HttpServletResponse response, String pdfUrl) {
+//        try {
+//            pdfUrl = pdfUrl.trim();
+//            URL url = new URL(pdfUrl);
+//            HttpURLConnection conn = (HttpURLConnection) url.openConnection();
+//            conn.setConnectTimeout(5*1000);
+//            InputStream inputStream = conn.getInputStream();
+//            response.setHeader("Content-Disposition", "attachment;fileName=show.pdf");
+//            response.setContentType("multipart/form-data");
+//            OutputStream outputStream = response.getOutputStream();
+//            IOUtils.write(IOUtils.toByteArray(inputStream), outputStream);
+//        } catch (Exception e) {
+//            e.printStackTrace();
+//        }
+//        return null;
+//    }
+
 }

+ 1 - 1
seecoder-portal-server/src/main/resources/application-dev.yml

@@ -9,7 +9,7 @@ spring:
   datasource:
     url: jdbc:postgresql://localhost:5432/portal
     username: postgres
-    password: postgres
+    password: 123456
 #    username: postgres
 #    password: postgres
 

+ 1 - 0
seecoder-portal-server/src/main/resources/application.yml

@@ -12,6 +12,7 @@ aliyun:
     region-id: cn-hangzhou
     sys-domain: dysmsapi.aliyuncs.com
     sys-version: 2017-05-25
+
   oss:
     endpoint: https://oss-cn-hangzhou.aliyuncs.com
     accessKeyId: LTAI4Fi1qmL4iuhH8t7G7r2H