DingXiaoYu 3 роки тому
батько
коміт
1bfdef962e

+ 1 - 0
java_compile/src/main/java/com/example/config/AppConfig.java

@@ -26,6 +26,7 @@ public class AppConfig {
     public String getAppName() {
         return appName;
     }
+
     public String getSparkServer() {
         return sparkServerAddr;
     }

+ 3 - 2
java_compile/src/main/java/com/example/config/JwtFilter.java

@@ -3,6 +3,7 @@ package com.example.config;
 import io.jsonwebtoken.Claims;
 import io.jsonwebtoken.Jwts;
 import io.jsonwebtoken.SignatureException;
+import org.springframework.stereotype.Component;
 import org.springframework.web.filter.GenericFilterBean;
 
 import javax.servlet.FilterChain;
@@ -16,6 +17,7 @@ import java.io.IOException;
 /**
  * Created by LXY on 2017/7/2.
  */
+//这个类先不要用了,感觉有点问题
 public class JwtFilter extends GenericFilterBean{
 
     @Override
@@ -27,7 +29,6 @@ public class JwtFilter extends GenericFilterBean{
         if ("OPTIONS".equals(request.getMethod())) {
             response.setStatus(HttpServletResponse.SC_OK);
 
-            chain.doFilter(req, res);
         } else {
             if(authHeader==null||!authHeader.startsWith("Bearer ")){
                 throw new ServletException("Missing or invalid Authorization header");
@@ -40,7 +41,7 @@ public class JwtFilter extends GenericFilterBean{
             }catch (final SignatureException e){
                 throw new ServletException("Invalid token");
             }
-            chain.doFilter(req,res);
         }
+        chain.doFilter(req, res);
     }
 }

+ 2 - 2
java_compile/src/main/java/com/example/controller/FileController.java

@@ -31,11 +31,11 @@ public class FileController {
      * @return fileId
      */
     @PostMapping(value = "/upload")
-    public Response fileLoader(@RequestParam(value="userId", required = false) String userId,
+    public Response fileLoader(@RequestParam(value="userId", required = false) Integer userId,
                                @RequestParam(value="file", required = false) MultipartFile file,
                                @RequestParam(value="fileName") String filename) {
         try {
-            int rsl = fileService.uploadFile(Integer.parseInt(userId), file, filename);
+            int rsl = fileService.uploadFile(userId, file, filename);
             return rsl != 0 ? new NormalRes(rsl) : new ErrorRes(40002, "Server error.");
         } catch (Exception e) {
             log.info("error fileLoader");

+ 7 - 6
java_compile/src/main/java/com/example/entity/User.java

@@ -1,26 +1,27 @@
 package com.example.entity;
 
+import lombok.AllArgsConstructor;
 import lombok.Data;
+import lombok.NoArgsConstructor;
 
-import javax.persistence.Entity;
-import javax.persistence.Id;
-import javax.persistence.Table;
+import javax.persistence.*;
 
 /**
  * The User table entity
  */
 @Data
 @Entity
+@AllArgsConstructor
+@NoArgsConstructor
 @Table(name = "user")
 public class User {
     @Id
-    private String id;
+    @GeneratedValue(strategy = GenerationType.IDENTITY)
+    private Integer id;
 
     private String username;
     private String password;
 
-    public User() {}
-
     public User(String username, String password) {
         this.username = username;
         this.password = password;

+ 1 - 1
java_compile/src/main/java/com/example/services/LoginService.java

@@ -30,7 +30,7 @@ public class LoginService {
         String jwtToken="";  //保存jwt token秘钥
         jwtToken = Jwts.builder().setSubject(username).claim("roles", "user").setIssuedAt(new Date())
                 .signWith(SignatureAlgorithm.HS256, "secretkey").compact();
-        return new LoginPojo(equals, equals ? user.getId() : null,jwtToken);
+        return new LoginPojo(equals, equals ? user.getId() : null, equals ? jwtToken : null);
     }
 
     public boolean addUser(User user){

+ 1 - 1
java_compile/src/main/java/com/example/services/pojo/LoginPojo.java

@@ -11,6 +11,6 @@ import lombok.Data;
 @AllArgsConstructor
 public class LoginPojo {
     private boolean loginStatus;
-    private String userId;
+    private Integer userId;
     private String jwtToken;
 }

+ 2 - 2
java_compile/src/main/resources/application.properties

@@ -2,7 +2,7 @@
 
 //com.jtang.spark.serverAddr = spark://${com.jtang.server.address}:7070
 
-com.jtang.hdfs.serverAddr = hdfs://${com.jtang.server.address}:9000/data/java_compile/
+com.jtang.hdfs.serverAddr = hdfs://${com.jtang.server.address}:9000/
 
 com.jtang.spark.serverAddr = local
 
@@ -18,7 +18,7 @@ spring.datasource.driver-class-name=com.mysql.cj.jdbc.Driver
 spring.jpa.hibernate.ddl-auto=update
 spring.jpa.show-sql=true
 
-com.jtang.server.address= 114.212.245.120
+com.jtang.server.address= 172.29.7.102
 com.jtang.spark.executorMemory = 2g
 
 spring.http.multipart.max-file-size=500MB

+ 1 - 1
java_compile/src/test/java/com/example/java_compile/FileControllerTests.java

@@ -46,7 +46,7 @@ class FileControllerTests {
         FileInputStream fileInputStream = new FileInputStream(pdfFile);
         MultipartFile multipartFile = new MockMultipartFile(pdfFile.getName(), pdfFile.getName(),
                 ContentType.APPLICATION_OCTET_STREAM.toString(), fileInputStream);
-        Response response = fileController.fileLoader("1",multipartFile,"event_data.csv");
+        Response response = fileController.fileLoader(1,multipartFile,"event_data.csv");
         System.out.println(response.toString());
 
     }