浏览代码

token 认证

zjs 1 周之前
父节点
当前提交
8f0d7eecad

+ 15 - 0
src/main/java/com/cn/esermis/config/CorsConfig.java

@@ -1,6 +1,10 @@
1
 package com.cn.esermis.config;
1
 package com.cn.esermis.config;
2
 
2
 
3
+import org.springframework.context.annotation.Bean;
3
 import org.springframework.context.annotation.Configuration;
4
 import org.springframework.context.annotation.Configuration;
5
+import org.springframework.web.cors.CorsConfiguration;
6
+import org.springframework.web.cors.CorsConfigurationSource;
7
+import org.springframework.web.cors.UrlBasedCorsConfigurationSource;
4
 import org.springframework.web.servlet.config.annotation.CorsRegistry;
8
 import org.springframework.web.servlet.config.annotation.CorsRegistry;
5
 import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;
9
 import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;
6
 
10
 
@@ -15,4 +19,15 @@ public class CorsConfig implements WebMvcConfigurer {
15
                 .allowedHeaders("*") // 允许的请求头
19
                 .allowedHeaders("*") // 允许的请求头
16
                 .allowCredentials(true); // 是否允许证书(cookies)
20
                 .allowCredentials(true); // 是否允许证书(cookies)
17
     }
21
     }
22
+
23
+    @Bean
24
+    public CorsConfigurationSource corsConfigurationSource() {
25
+        CorsConfiguration configuration = new CorsConfiguration();
26
+        configuration.addAllowedOrigin("*"); // 允许所有域名访问,也可以指定特定的域名
27
+        configuration.addAllowedMethod("*"); // 允许所有HTTP方法
28
+        configuration.addAllowedHeader("*"); // 允许所有请求头
29
+        UrlBasedCorsConfigurationSource source = new UrlBasedCorsConfigurationSource();
30
+        source.registerCorsConfiguration("/**", configuration);
31
+        return source;
32
+    }
18
 }
33
 }

+ 0 - 1
src/main/java/com/cn/esermis/config/MyBatisPlusConfig.java

@@ -11,5 +11,4 @@ public class MyBatisPlusConfig {
11
         PaginationInterceptor page = new PaginationInterceptor();
11
         PaginationInterceptor page = new PaginationInterceptor();
12
         return page;
12
         return page;
13
     }
13
     }
14
-
15
 }
14
 }

+ 3 - 0
src/main/java/com/cn/esermis/config/MyInterceptor.java

@@ -21,6 +21,9 @@ public class MyInterceptor  implements HandlerInterceptor  {
21
     DataAcquisitionInstrumentMapper dataAcquisitionInstrumentMapper;
21
     DataAcquisitionInstrumentMapper dataAcquisitionInstrumentMapper;
22
     @Override
22
     @Override
23
     public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler) throws Exception {
23
     public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler) throws Exception {
24
+        // 获取 header 中的 Authorization 信息
25
+//        String token = request.getHeader("Authorization");
26
+
24
         String token = extractToken(request);
27
         String token = extractToken(request);
25
         if (token != null) {
28
         if (token != null) {
26
             BaseUser userInfo = TokenUtils.getUserInfo(token);
29
             BaseUser userInfo = TokenUtils.getUserInfo(token);

+ 4 - 0
src/main/java/com/cn/esermis/dpld/entity/DataAcquisitionInstrument.java

@@ -4,7 +4,9 @@ import com.baomidou.mybatisplus.annotation.IdType;
4
 import com.baomidou.mybatisplus.annotation.TableField;
4
 import com.baomidou.mybatisplus.annotation.TableField;
5
 import com.baomidou.mybatisplus.annotation.TableId;
5
 import com.baomidou.mybatisplus.annotation.TableId;
6
 import com.baomidou.mybatisplus.annotation.TableName;
6
 import com.baomidou.mybatisplus.annotation.TableName;
7
+import com.fasterxml.jackson.annotation.JsonFormat;
7
 import lombok.Data;
8
 import lombok.Data;
9
+import org.springframework.format.annotation.DateTimeFormat;
8
 
10
 
9
 import java.math.BigDecimal;
11
 import java.math.BigDecimal;
10
 import java.util.Date;
12
 import java.util.Date;
@@ -42,6 +44,8 @@ public class DataAcquisitionInstrument {
42
      *建设投用日期
44
      *建设投用日期
43
      */
45
      */
44
     @TableField(value = "use_data")
46
     @TableField(value = "use_data")
47
+    @DateTimeFormat(pattern = "yyyy")
48
+    @JsonFormat(pattern = "yyyy",timezone = "GMT+8")
45
     private Date useData;
49
     private Date useData;
46
     /**
50
     /**
47
      * 是否完成验收备案(0否 1是)
51
      * 是否完成验收备案(0否 1是)

+ 6 - 1
src/main/java/com/cn/esermis/dpld/entity/DetectMonitoringFactor.java

@@ -73,9 +73,14 @@ public class DetectMonitoringFactor {
73
     /**
73
     /**
74
      * 量程单位
74
      * 量程单位
75
      */
75
      */
76
-    @TableField(value = "rangeUnit")
76
+    @TableField(value = "range_unit")
77
     private String rangeUnit;
77
     private String rangeUnit;
78
     /**
78
     /**
79
+     * 量程单位
80
+     */
81
+    @TableField(value = "factor_name")
82
+    private String factorName;
83
+    /**
79
      * 数据采集仪主键ID
84
      * 数据采集仪主键ID
80
      */
85
      */
81
     @TableField(value = "data_acquisition_instrument_id")
86
     @TableField(value = "data_acquisition_instrument_id")

+ 2 - 1
src/main/java/com/cn/esermis/dpld/model/AnalyticalInstrumentsVo.java

@@ -5,6 +5,7 @@ import com.cn.esermis.dpld.entity.DetectMonitoringFactor;
5
 import lombok.Data;
5
 import lombok.Data;
6
 import lombok.EqualsAndHashCode;
6
 import lombok.EqualsAndHashCode;
7
 
7
 
8
+import java.util.ArrayList;
8
 import java.util.List;
9
 import java.util.List;
9
 
10
 
10
 @EqualsAndHashCode(callSuper = true)
11
 @EqualsAndHashCode(callSuper = true)
@@ -12,6 +13,6 @@ import java.util.List;
12
 
13
 
13
 public class AnalyticalInstrumentsVo extends AnalyticalInstruments {
14
 public class AnalyticalInstrumentsVo extends AnalyticalInstruments {
14
 
15
 
15
-    private List<DetectMonitoringFactor> detectMonitoringFactors;
16
+    private List<DetectMonitoringFactor> detectMonitoringFactors = new ArrayList<>();
16
 
17
 
17
 }
18
 }