libo 4 years ago
parent
commit
656c9a85ce

+ 20 - 0
src/main/java/com/tdba/cxb/ares/api/config/CorsConfig.java

@@ -0,0 +1,20 @@
1
+package com.tdba.cxb.ares.api.config;
2
+
3
+import org.springframework.web.servlet.config.annotation.CorsRegistry;
4
+import org.springframework.web.servlet.config.annotation.WebMvcConfigurerAdapter;
5
+
6
+/**
7
+ * @program: order-web
8
+ * @description:
9
+ * @author: libo
10
+ * @create: 2022-06-10 11:13:38
11
+ */
12
+public class CorsConfig extends WebMvcConfigurerAdapter {
13
+
14
+    @Override
15
+    public void addCorsMappings(CorsRegistry registry) {
16
+        registry.addMapping("/**").allowedOrigins("*")
17
+                .allowedMethods("GET", "HEAD", "POST","PUT", "DELETE", "OPTIONS")
18
+                .allowCredentials(true).maxAge(3600);
19
+    }
20
+}

+ 41 - 0
src/main/java/com/tdba/cxb/ares/api/config/CorsFilter.java

@@ -0,0 +1,41 @@
1
+package com.tdba.cxb.ares.api.config;
2
+
3
+import org.springframework.stereotype.Component;
4
+
5
+import javax.servlet.*;
6
+import javax.servlet.annotation.WebFilter;
7
+import javax.servlet.http.HttpServletRequest;
8
+import javax.servlet.http.HttpServletResponse;
9
+import java.io.IOException;
10
+
11
+/**
12
+ * @program: order-web
13
+ * @description:
14
+ * @author: libo
15
+ * @create: 2022-06-10 11:11:28
16
+ */
17
+@Component
18
+@WebFilter(urlPatterns = "/*", filterName = "CorsFilter")
19
+public class CorsFilter implements Filter {
20
+
21
+    @Override
22
+    public void doFilter(ServletRequest req, ServletResponse res, FilterChain chain) throws IOException, ServletException {
23
+        HttpServletResponse response = (HttpServletResponse) res;
24
+        HttpServletRequest reqs = (HttpServletRequest) req;
25
+        String curOrigin = reqs.getHeader("Origin");
26
+        response.setHeader("Access-Control-Allow-Origin", "*");
27
+//        response.setHeader("Access-Control-Allow-Credentials", "true");
28
+        response.setHeader("Access-Control-Allow-Methods", "GET,POST,PATCH,PUT,DELETE,OPTIONS,DELETE");
29
+        response.setHeader("Access-Control-Allow-Headers", " X-Token, user-token, Content-Type, If-Match, If-Modified-Since, If-None-Match, If-Unmodified-Since, X-Requested-With");
30
+        chain.doFilter(req, res);
31
+    }
32
+
33
+
34
+    @Override
35
+    public void init(FilterConfig filterConfig) {
36
+    }
37
+
38
+
39
+    @Override
40
+    public void destroy() {}
41
+}

+ 2 - 1
src/main/java/com/tdba/cxb/ares/api/config/FIlterConfig.java

@@ -5,6 +5,8 @@ import org.springframework.context.annotation.Configuration;
5 5
 import org.springframework.web.cors.CorsConfiguration;
6 6
 import org.springframework.web.cors.UrlBasedCorsConfigurationSource;
7 7
 import org.springframework.web.filter.CorsFilter;
8
+import org.springframework.web.servlet.config.annotation.CorsRegistry;
9
+import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;
8 10
 
9 11
 import java.util.ArrayList;
10 12
 import java.util.List;
@@ -12,7 +14,6 @@ import java.util.List;
12 14
 /**
13 15
  * 过滤器配置
14 16
  */
15
-@Configuration
16 17
 public class FIlterConfig {
17 18
 
18 19
     private CorsConfiguration buildConfig() {

+ 3 - 0
src/main/java/com/tdba/cxb/ares/api/service/UserService.java

@@ -23,6 +23,7 @@ import java.time.ZoneOffset;
23 23
 import java.util.ArrayList;
24 24
 import java.util.List;
25 25
 import java.util.Objects;
26
+import java.util.stream.Collectors;
26 27
 
27 28
 /**
28 29
  * @program: order-web
@@ -165,6 +166,8 @@ public class UserService {
165 166
             }
166 167
         });
167 168
         if(!resultList.isEmpty()){
169
+            //相同用户ID,日期合并
170
+//            resultList.stream().
168 171
             userCountMapper.insertSelectiveForeach(resultList);
169 172
         }
170 173
     }

+ 1 - 0
src/main/resources/application.yml

@@ -11,6 +11,7 @@ spring:
11 11
     parser:
12 12
       allow-numeric-leading-zeros: true
13 13
 
14
+
14 15
 mybatis:
15 16
 #  configuration:
16 17
     ## 开启驼峰格式