Commit 8403ad2b authored by jiaorz's avatar jiaorz

网关日志限制修改

parent fb71804a
...@@ -2,8 +2,6 @@ package com.github.wxiaoqi.security.gate.filter; ...@@ -2,8 +2,6 @@ package com.github.wxiaoqi.security.gate.filter;
import com.alibaba.fastjson.JSONObject; import com.alibaba.fastjson.JSONObject;
import com.github.wxiaoqi.security.admin.feign.UserFeign; import com.github.wxiaoqi.security.admin.feign.UserFeign;
import com.github.wxiaoqi.security.admin.feign.dto.AppUserDTO;
import com.github.wxiaoqi.security.admin.feign.dto.UserDTO;
import com.github.wxiaoqi.security.api.vo.authority.PermissionInfo; import com.github.wxiaoqi.security.api.vo.authority.PermissionInfo;
import com.github.wxiaoqi.security.api.vo.log.LogInfo; import com.github.wxiaoqi.security.api.vo.log.LogInfo;
import com.github.wxiaoqi.security.auth.client.config.ServiceAuthConfig; import com.github.wxiaoqi.security.auth.client.config.ServiceAuthConfig;
...@@ -27,25 +25,23 @@ import org.springframework.beans.factory.annotation.Autowired; ...@@ -27,25 +25,23 @@ import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value; import org.springframework.beans.factory.annotation.Value;
import org.springframework.cloud.gateway.filter.GatewayFilterChain; import org.springframework.cloud.gateway.filter.GatewayFilterChain;
import org.springframework.cloud.gateway.filter.GlobalFilter; import org.springframework.cloud.gateway.filter.GlobalFilter;
import org.springframework.cloud.gateway.support.DefaultServerRequest;
import org.springframework.cloud.gateway.support.ServerWebExchangeUtils; import org.springframework.cloud.gateway.support.ServerWebExchangeUtils;
import org.springframework.context.annotation.Configuration; import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.Lazy; import org.springframework.context.annotation.Lazy;
import org.springframework.core.io.buffer.DataBuffer; import org.springframework.core.io.buffer.DataBuffer;
import org.springframework.http.HttpMethod;
import org.springframework.http.HttpStatus; import org.springframework.http.HttpStatus;
import org.springframework.http.MediaType;
import org.springframework.http.server.reactive.ServerHttpRequest; import org.springframework.http.server.reactive.ServerHttpRequest;
import org.springframework.util.MultiValueMap;
import org.springframework.web.bind.annotation.RequestMethod; import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.reactive.function.server.ServerRequest;
import org.springframework.web.server.ServerWebExchange; import org.springframework.web.server.ServerWebExchange;
import reactor.core.publisher.Flux; import reactor.core.publisher.Flux;
import reactor.core.publisher.Mono; import reactor.core.publisher.Mono;
import java.net.URI; import java.net.URI;
import java.nio.charset.StandardCharsets; import java.nio.charset.StandardCharsets;
import java.util.*; import java.util.Date;
import java.util.Iterator;
import java.util.LinkedHashSet;
import java.util.List;
import java.util.function.Predicate; import java.util.function.Predicate;
import java.util.regex.Pattern; import java.util.regex.Pattern;
import java.util.stream.Collectors; import java.util.stream.Collectors;
...@@ -99,7 +95,7 @@ public class AccessGatewayFilter implements GlobalFilter { ...@@ -99,7 +95,7 @@ public class AccessGatewayFilter implements GlobalFilter {
log.info("check token and user permission...."); log.info("check token and user permission....");
LinkedHashSet requiredAttribute = serverWebExchange.getRequiredAttribute(ServerWebExchangeUtils.GATEWAY_ORIGINAL_REQUEST_URL_ATTR); LinkedHashSet requiredAttribute = serverWebExchange.getRequiredAttribute(ServerWebExchangeUtils.GATEWAY_ORIGINAL_REQUEST_URL_ATTR);
ServerHttpRequest request = serverWebExchange.getRequest(); ServerHttpRequest request = serverWebExchange.getRequest();
setLogService(serverWebExchange, gatewayFilterChain); // setLogService(serverWebExchange, gatewayFilterChain);
String requestUri = request.getPath().pathWithinApplication().value(); String requestUri = request.getPath().pathWithinApplication().value();
if (requiredAttribute != null) { if (requiredAttribute != null) {
Iterator<URI> iterator = requiredAttribute.iterator(); Iterator<URI> iterator = requiredAttribute.iterator();
...@@ -287,105 +283,105 @@ public class AccessGatewayFilter implements GlobalFilter { ...@@ -287,105 +283,105 @@ public class AccessGatewayFilter implements GlobalFilter {
} }
public void setLogService(ServerWebExchange exchange, GatewayFilterChain chain) { // public void setLogService(ServerWebExchange exchange, GatewayFilterChain chain) {
MediaType mediaType = exchange.getRequest().getHeaders().getContentType(); // MediaType mediaType = exchange.getRequest().getHeaders().getContentType();
ServerRequest serverRequest = new DefaultServerRequest(exchange); // ServerRequest serverRequest = new DefaultServerRequest(exchange);
//
// 如果是json格式,将body内容转化为object or map 都可 // // 如果是json格式,将body内容转化为object or map 都可
if (MediaType.APPLICATION_JSON.isCompatibleWith(mediaType)) { // if (MediaType.APPLICATION_JSON.isCompatibleWith(mediaType)) {
Mono<Object> modifiedBody = serverRequest.bodyToMono(Object.class) // Mono<Object> modifiedBody = serverRequest.bodyToMono(Object.class)
.flatMap(body -> { // .flatMap(body -> {
recordLog(exchange.getRequest(), body); // recordLog(exchange.getRequest(), body);
return Mono.just(body); // return Mono.just(body);
}); // });
//
} // }
// 如果是表单请求 // // 如果是表单请求
else if (MediaType.APPLICATION_FORM_URLENCODED.isCompatibleWith(mediaType)) { // else if (MediaType.APPLICATION_FORM_URLENCODED.isCompatibleWith(mediaType)) {
Mono<String> modifiedBody = serverRequest.bodyToMono(String.class) // Mono<String> modifiedBody = serverRequest.bodyToMono(String.class)
// .log("modify_request_mono", Level.INFO) // // .log("modify_request_mono", Level.INFO)
.flatMap(body -> { // .flatMap(body -> {
recordLog(exchange.getRequest(), body); // recordLog(exchange.getRequest(), body);
//
return Mono.just(body); // return Mono.just(body);
}); // });
//
} // }
// TODO 这里未来还可以限制一些格式 // // TODO 这里未来还可以限制一些格式
//
// 无法兼容的请求,则不读取body,像Get请求这种 // // 无法兼容的请求,则不读取body,像Get请求这种
recordLog(exchange.getRequest(), ""); // recordLog(exchange.getRequest(), "");
} // }
//
private void recordLog(ServerHttpRequest request, Object body) { // private void recordLog(ServerHttpRequest request, Object body) {
// 记录要访问的url // // 记录要访问的url
if (!getNotLogUri().contains(request.getURI().getRawPath())) { // if (!getNotLogUri().contains(request.getURI().getRawPath())) {
//
//
StringBuilder builder = new StringBuilder(); // StringBuilder builder = new StringBuilder();
log.info("=================请求uri:" + request.getURI().getRawPath()); // log.info("=================请求uri:" + request.getURI().getRawPath());
// 记录访问的方法 // // 记录访问的方法
HttpMethod method = request.getMethod(); // HttpMethod method = request.getMethod();
if (null != method) { // if (null != method) {
log.info("=================请求方法:" + method.name()); // log.info("=================请求方法:" + method.name());
} // }
request.getHeaders().add("uuid", UUID.randomUUID().toString()); // request.getHeaders().add("uuid", UUID.randomUUID().toString());
// 记录头部信息 // // 记录头部信息
builder.append(", header { "); // builder.append(", header { ");
for (Map.Entry<String, List<String>> entry : request.getHeaders().entrySet()) { // for (Map.Entry<String, List<String>> entry : request.getHeaders().entrySet()) {
builder.append(entry.getKey()).append(":").append(StringUtils.join(entry.getValue(), ",")).append(","); // builder.append(entry.getKey()).append(":").append(StringUtils.join(entry.getValue(), ",")).append(",");
if("uuid".equals(entry.getKey())) { // if("uuid".equals(entry.getKey())) {
if(entry.getValue() != null && entry.getValue().size() > 0) { // if(entry.getValue() != null && entry.getValue().size() > 0) {
log.info("=================请求方法uuid:" + entry.getValue().get(0)); // log.info("=================请求方法uuid:" + entry.getValue().get(0));
} // }
} // }
if("Authorization".equals(entry.getKey())) { // if("Authorization".equals(entry.getKey())) {
if(entry.getValue() != null && entry.getValue().size() > 0) { // if(entry.getValue() != null && entry.getValue().size() > 0) {
getAdminUserInfo(entry.getValue().get(0)); // getAdminUserInfo(entry.getValue().get(0));
} // }
//
} // }
} // }
log.info("=================请求头header:" + builder.toString()); // log.info("=================请求头header:" + builder.toString());
// 记录参数 // // 记录参数
builder = new StringBuilder(); // builder = new StringBuilder();
// 处理get的请求 // // 处理get的请求
if (null != method && HttpMethod.GET.matches(method.name())) { // if (null != method && HttpMethod.GET.matches(method.name())) {
// 记录请求的参数信息 针对GET 请求 // // 记录请求的参数信息 针对GET 请求
MultiValueMap<String, String> queryParams = request.getQueryParams(); // MultiValueMap<String, String> queryParams = request.getQueryParams();
for (Map.Entry<String, List<String>> entry : queryParams.entrySet()) { // for (Map.Entry<String, List<String>> entry : queryParams.entrySet()) {
builder.append(entry.getKey()).append("=").append(StringUtils.join(entry.getValue(), ",")).append(","); // builder.append(entry.getKey()).append("=").append(StringUtils.join(entry.getValue(), ",")).append(",");
} // }
} else { // } else {
// 从body中读取参数 // // 从body中读取参数
builder.append(body); // builder.append(body);
} // }
log.info("=================请求参数:" + builder.toString()); // log.info("=================请求参数:" + builder.toString());
} // }
} // }
//
private void getAdminUserInfo(String token) { // private void getAdminUserInfo(String token) {
if(token !=null) { // if(token !=null) {
UserDTO userDTO = userFeign.userinfoByToken(token).getData(); // UserDTO userDTO = userFeign.userinfoByToken(token).getData();
if(userDTO != null) { // if(userDTO != null) {
log.info("=================后台用户名:username = {}", userDTO.getUsername()); // log.info("=================后台用户名:username = {}", userDTO.getUsername());
log.info("=================后台姓名: name = {}", userDTO.getName()); // log.info("=================后台姓名: name = {}", userDTO.getName());
} else { // } else {
AppUserDTO appUserDTO = userFeign.userDetailByToken(token).getData(); // AppUserDTO appUserDTO = userFeign.userDetailByToken(token).getData();
if(appUserDTO != null) { // if(appUserDTO != null) {
log.info("=================APP用户名:userId = {}", appUserDTO.getUserid()); // log.info("=================APP用户名:userId = {}", appUserDTO.getUserid());
log.info("=================APP姓名: name = {}", appUserDTO.getRealname()); // log.info("=================APP姓名: name = {}", appUserDTO.getRealname());
log.info("=================APP手机号: phone = {}", appUserDTO.getUsername()); // log.info("=================APP手机号: phone = {}", appUserDTO.getUsername());
} // }
} // }
} // }
} // }
//
@Value("${logback.ignore-log-path}") // @Value("${logback.ignore-log-path}")
String[] path; // String[] path;
public List<String> getNotLogUri() { // public List<String> getNotLogUri() {
return Arrays.asList(path); // return Arrays.asList(path);
} // }
} }
...@@ -19,7 +19,6 @@ import org.springframework.http.codec.ClientCodecConfigurer; ...@@ -19,7 +19,6 @@ import org.springframework.http.codec.ClientCodecConfigurer;
import org.springframework.http.codec.json.Jackson2JsonDecoder; import org.springframework.http.codec.json.Jackson2JsonDecoder;
import org.springframework.http.codec.json.Jackson2JsonEncoder; import org.springframework.http.codec.json.Jackson2JsonEncoder;
import org.springframework.http.server.reactive.ServerHttpResponseDecorator; import org.springframework.http.server.reactive.ServerHttpResponseDecorator;
import org.springframework.stereotype.Component;
import org.springframework.util.MultiValueMap; import org.springframework.util.MultiValueMap;
import org.springframework.web.reactive.function.BodyInserter; import org.springframework.web.reactive.function.BodyInserter;
import org.springframework.web.reactive.function.BodyInserters; import org.springframework.web.reactive.function.BodyInserters;
...@@ -31,7 +30,7 @@ import reactor.core.publisher.Mono; ...@@ -31,7 +30,7 @@ import reactor.core.publisher.Mono;
import java.util.function.Consumer; import java.util.function.Consumer;
import java.util.function.Function; import java.util.function.Function;
@Component //@Component
@Slf4j @Slf4j
public class ResponseRecordFilter implements GlobalFilter, Ordered { public class ResponseRecordFilter implements GlobalFilter, Ordered {
......
...@@ -62,6 +62,10 @@ public class SmsTemplateDTO { ...@@ -62,6 +62,10 @@ public class SmsTemplateDTO {
public static final int REFUND_A = 22; public static final int REFUND_A = 22;
//违章押金退还 //违章押金退还
public static final int REFUND_B = 23; public static final int REFUND_B = 23;
//旅游内部通知(客服)
public static final int PAY_H = 24;
//取消旅游订单(客服)
public static final int CANCEL_F = 25;
......
...@@ -58,6 +58,11 @@ public class CCPRestSmsBiz{ ...@@ -58,6 +58,11 @@ public class CCPRestSmsBiz{
//违章押金退还 23 //违章押金退还 23
public static final String TEMPLATE_ID_FINISH_B = "460773"; public static final String TEMPLATE_ID_FINISH_B = "460773";
//旅游内部通知(客服)24
public static final String TEMPLATE_ID_PAY_H = "461421";
//取消旅游订单(客服)25
public static final String TEMPLATE_ID_CANCEL_F = "461424";
...@@ -131,6 +136,12 @@ public class CCPRestSmsBiz{ ...@@ -131,6 +136,12 @@ public class CCPRestSmsBiz{
case 23 : case 23 :
CCPRestSmsUtils.sendTemplateSMS(phoneNumbers,params,TEMPLATE_ID_FINISH_B); CCPRestSmsUtils.sendTemplateSMS(phoneNumbers,params,TEMPLATE_ID_FINISH_B);
break; break;
case 24 :
CCPRestSmsUtils.sendTemplateSMS(phoneNumbers,params,TEMPLATE_ID_PAY_H);
break;
case 25 :
CCPRestSmsUtils.sendTemplateSMS(phoneNumbers,params,TEMPLATE_ID_CANCEL_F);
break;
} }
......
...@@ -82,7 +82,7 @@ public class VehicleActiveService { ...@@ -82,7 +82,7 @@ public class VehicleActiveService {
} }
//修改预约记录状态 //修改预约记录状态
if(departureVo.getBookRecordId() != null) { if(departureVo.getBookRecordId() != null) {
updateBookRecordStatus(departureVo.getBookRecordId()); updateBookRecordStatus(departureVo.getBookRecordId(), 1);
} }
VehicleDepartureLogVo vehicleDepartureLogVo = vehicleDepartureLogMapper.selectByBookRecordId(departureVo.getBookRecordId()); VehicleDepartureLogVo vehicleDepartureLogVo = vehicleDepartureLogMapper.selectByBookRecordId(departureVo.getBookRecordId());
if(vehicleDepartureLogVo != null) { if(vehicleDepartureLogVo != null) {
...@@ -154,7 +154,7 @@ public class VehicleActiveService { ...@@ -154,7 +154,7 @@ public class VehicleActiveService {
} }
if(arrivalVo.getBookRecordId() != null) { if(arrivalVo.getBookRecordId() != null) {
updateBookRecordStatus(arrivalVo.getBookRecordId()); updateBookRecordStatus(arrivalVo.getBookRecordId(), 2);
} }
...@@ -192,10 +192,15 @@ public class VehicleActiveService { ...@@ -192,10 +192,15 @@ public class VehicleActiveService {
} }
} }
public void updateBookRecordStatus(Integer bookRecordId) { public void updateBookRecordStatus(Integer bookRecordId, Integer type) {
VehicleBookRecord vehicleBookRecord = vehicleBookRecordBiz.selectById(bookRecordId); VehicleBookRecord vehicleBookRecord = vehicleBookRecordBiz.selectById(bookRecordId);
if(vehicleBookRecord != null) { if(vehicleBookRecord != null) {
vehicleBookRecord.setStatus(VehicleBookRecordStatus.LIFTED.getCode()); vehicleBookRecord.setStatus(VehicleBookRecordStatus.LIFTED.getCode());
if(type == 1) {
vehicleBookRecord.setActualStartDate(new Date());
} else {
vehicleBookRecord.setActualEndDate(new Date());
}
vehicleBookRecordBiz.updateSelectiveByIdRe(vehicleBookRecord); vehicleBookRecordBiz.updateSelectiveByIdRe(vehicleBookRecord);
} else { } else {
throw new BaseException(ResCode.VEHICLE_BOOK_RECORD_IS_NOT_EXIST.getDesc(), throw new BaseException(ResCode.VEHICLE_BOOK_RECORD_IS_NOT_EXIST.getDesc(),
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment