销售日志+销售统计

yaoyao
lijiayao 2023-12-19 09:12:13 +08:00
parent 36ea8358da
commit f820822b9e
1 changed files with 85 additions and 85 deletions

View File

@ -1,85 +1,85 @@
//package com.bwie.gateway.filters;
//
//import com.bwie.common.constants.TokenConstants;
//import com.bwie.common.utils.JwtUtils;
//import com.bwie.common.utils.StringUtils;
//import com.bwie.gateway.config.IgnoreWhiteConfig;
//import com.bwie.gateway.utils.GatewayUtils;
//import org.springframework.beans.factory.annotation.Autowired;
//import org.springframework.cloud.gateway.filter.GatewayFilterChain;
//import org.springframework.cloud.gateway.filter.GlobalFilter;
//import org.springframework.core.Ordered;
//import org.springframework.data.redis.core.RedisTemplate;
//import org.springframework.http.HttpStatus;
//import org.springframework.http.server.reactive.ServerHttpRequest;
//import org.springframework.stereotype.Component;
//import org.springframework.web.server.ServerWebExchange;
//import reactor.core.publisher.Mono;
//
//import java.util.List;
//
///**
// * @ClassName:
// * @Description: 鉴权过滤器
// * @Author: zhuwenqiang
// * @Date: 2023/8/18
// */
//@Component
//public class AuthFilter implements GlobalFilter, Ordered {
//
// @Autowired
// private IgnoreWhiteConfig ignoreWhiteConfig;
//
// @Autowired
// private RedisTemplate<String, String> redisTemplate;
//
// /**
// * 过滤方法 验证 token
// * @param exchange 请求的上下文 通过这个参数 可以获取到 请求对象 以及 响应对象
// * @param chain 网关过滤器链 chain 放行 或者 拦截
// * @return Mono
// */
// @Override
// public Mono<Void> filter(ServerWebExchange exchange, GatewayFilterChain chain) {
// // 验证当前的请求 是否需要拦截 【配置白名单请求 不拦截的请求 】 将白名单请求配置到配置文件中
// // 获取系统白名单请求
// List<String> whites = ignoreWhiteConfig.getWhites();
// // 获取当前的请求 URI
// ServerHttpRequest request = exchange.getRequest();
// String path = request.getURI().getPath();
// boolean matches = StringUtils.matches(path, whites);
// if (matches) { // 放行
// return chain.filter(exchange);
// }
// // 获取token
// String token = request.getHeaders().getFirst(TokenConstants.TOKEN);
// // token 非空验证
// if (StringUtils.isEmpty(token)) {
// // 不放行 提示错误信息
// return GatewayUtils.errorResponse(exchange, "token不能为空", HttpStatus.UNAUTHORIZED);
// }
// try {
// // token 合法性性
// JwtUtils.parseToken(token);
// } catch (Exception ex) {
// return GatewayUtils.errorResponse(exchange, "token格式错误");
// }
// // token 是否过期
// // 获取 UserKey
// String userKey = JwtUtils.getUserKey(token);
// if (!redisTemplate.hasKey(TokenConstants.LOGIN_TOKEN_KEY + userKey)) {
// return GatewayUtils.errorResponse(exchange, "token过期");
// }
// // 放行
// return chain.filter(exchange);
// }
//
// /**
// * 当存在多个filter的时候 用来执行执行的优先级
// * @return 数字 数字的值越小 执行的优先级越高
// */
// @Override
// public int getOrder() {
// return 0;
// }
//}
package com.bwie.gateway.filters;
import com.bwie.common.constants.TokenConstants;
import com.bwie.common.utils.JwtUtils;
import com.bwie.common.utils.StringUtils;
import com.bwie.gateway.config.IgnoreWhiteConfig;
import com.bwie.gateway.utils.GatewayUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.cloud.gateway.filter.GatewayFilterChain;
import org.springframework.cloud.gateway.filter.GlobalFilter;
import org.springframework.core.Ordered;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.http.HttpStatus;
import org.springframework.http.server.reactive.ServerHttpRequest;
import org.springframework.stereotype.Component;
import org.springframework.web.server.ServerWebExchange;
import reactor.core.publisher.Mono;
import java.util.List;
/**
* @ClassName:
* @Description:
* @Author: zhuwenqiang
* @Date: 2023/8/18
*/
@Component
public class AuthFilter implements GlobalFilter, Ordered {
@Autowired
private IgnoreWhiteConfig ignoreWhiteConfig;
@Autowired
private RedisTemplate<String, String> redisTemplate;
/**
* token
* @param exchange
* @param chain chain
* @return Mono
*/
@Override
public Mono<Void> filter(ServerWebExchange exchange, GatewayFilterChain chain) {
// 验证当前的请求 是否需要拦截 【配置白名单请求 不拦截的请求 】 将白名单请求配置到配置文件中
// 获取系统白名单请求
List<String> whites = ignoreWhiteConfig.getWhites();
// 获取当前的请求 URI
ServerHttpRequest request = exchange.getRequest();
String path = request.getURI().getPath();
boolean matches = StringUtils.matches(path, whites);
if (matches) { // 放行
return chain.filter(exchange);
}
// 获取token
String token = request.getHeaders().getFirst(TokenConstants.TOKEN);
// token 非空验证
if (StringUtils.isEmpty(token)) {
// 不放行 提示错误信息
return GatewayUtils.errorResponse(exchange, "token不能为空", HttpStatus.UNAUTHORIZED);
}
try {
// token 合法性性
JwtUtils.parseToken(token);
} catch (Exception ex) {
return GatewayUtils.errorResponse(exchange, "token格式错误");
}
// token 是否过期
// 获取 UserKey
String userKey = JwtUtils.getUserKey(token);
if (!redisTemplate.hasKey(TokenConstants.LOGIN_TOKEN_KEY + userKey)) {
return GatewayUtils.errorResponse(exchange, "token过期");
}
// 放行
return chain.filter(exchange);
}
/**
* filter
* @return
*/
@Override
public int getOrder() {
return 0;
}
}