|  | @@ -1,16 +1,16 @@
 | 
	
		
			
				|  |  |  package com.yonge.log.interceptor;
 | 
	
		
			
				|  |  |  
 | 
	
		
			
				|  |  |  import java.io.IOException;
 | 
	
		
			
				|  |  | +import java.lang.reflect.Array;
 | 
	
		
			
				|  |  |  import java.nio.charset.Charset;
 | 
	
		
			
				|  |  |  import java.text.SimpleDateFormat;
 | 
	
		
			
				|  |  | -import java.util.Date;
 | 
	
		
			
				|  |  | -import java.util.Map;
 | 
	
		
			
				|  |  | -import java.util.Objects;
 | 
	
		
			
				|  |  | +import java.util.*;
 | 
	
		
			
				|  |  |  
 | 
	
		
			
				|  |  |  import javax.servlet.ServletException;
 | 
	
		
			
				|  |  |  import javax.servlet.http.HttpServletRequest;
 | 
	
		
			
				|  |  |  import javax.servlet.http.HttpServletResponse;
 | 
	
		
			
				|  |  |  
 | 
	
		
			
				|  |  | +import io.swagger.annotations.ApiOperation;
 | 
	
		
			
				|  |  |  import org.apache.commons.io.IOUtils;
 | 
	
		
			
				|  |  |  import org.apache.commons.lang3.StringUtils;
 | 
	
		
			
				|  |  |  import org.springframework.beans.factory.annotation.Autowired;
 | 
	
	
		
			
				|  | @@ -41,6 +41,10 @@ public class AuditLogInterceptor extends HandlerInterceptorAdapter {
 | 
	
		
			
				|  |  |  
 | 
	
		
			
				|  |  |  	private SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
 | 
	
		
			
				|  |  |  
 | 
	
		
			
				|  |  | +	private static List<String> ignoreLogUrl;
 | 
	
		
			
				|  |  | +
 | 
	
		
			
				|  |  | +
 | 
	
		
			
				|  |  | +
 | 
	
		
			
				|  |  |  	@Override
 | 
	
		
			
				|  |  |  	public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler) throws ServletException, IOException {
 | 
	
		
			
				|  |  |  
 | 
	
	
		
			
				|  | @@ -48,35 +52,66 @@ public class AuditLogInterceptor extends HandlerInterceptorAdapter {
 | 
	
		
			
				|  |  |  	}
 | 
	
		
			
				|  |  |  
 | 
	
		
			
				|  |  |  	@Override
 | 
	
		
			
				|  |  | -	public void afterCompletion(HttpServletRequest request, HttpServletResponse response, Object handler, Exception ex) throws Exception {
 | 
	
		
			
				|  |  | -
 | 
	
		
			
				|  |  | -		HandlerMethod handlerMethod = (HandlerMethod) handler;
 | 
	
		
			
				|  |  | -		AuditLogAnnotation anno = handlerMethod.getMethodAnnotation(AuditLogAnnotation.class);
 | 
	
		
			
				|  |  | -
 | 
	
		
			
				|  |  | -		if (anno != null) {
 | 
	
		
			
				|  |  | -			AuditLog auditLog = new AuditLog();
 | 
	
		
			
				|  |  | -			auditLog.setOperateName(anno.operateName());
 | 
	
		
			
				|  |  | -			if(StringUtils.isNotBlank(anno.interfaceURL())){
 | 
	
		
			
				|  |  | -				auditLog.setInterfaceUrl(anno.interfaceURL());
 | 
	
		
			
				|  |  | -			}else{
 | 
	
		
			
				|  |  | -				auditLog.setInterfaceUrl(request.getRequestURI());
 | 
	
		
			
				|  |  | +	public void afterCompletion(HttpServletRequest request, HttpServletResponse response, Object handler, Exception ex) {
 | 
	
		
			
				|  |  | +		try {
 | 
	
		
			
				|  |  | +			String servletPath = request.getServletPath();
 | 
	
		
			
				|  |  | +			HandlerMethod handlerMethod = (HandlerMethod) handler;
 | 
	
		
			
				|  |  | +			AuditLogAnnotation anno = handlerMethod.getMethodAnnotation(AuditLogAnnotation.class);
 | 
	
		
			
				|  |  | +			ApiOperation apiOperation = handlerMethod.getMethodAnnotation(ApiOperation.class);
 | 
	
		
			
				|  |  | +			String operateName = null;
 | 
	
		
			
				|  |  | +			if(StringUtils.isEmpty(operateName) && apiOperation != null){
 | 
	
		
			
				|  |  | +				operateName = apiOperation.value();
 | 
	
		
			
				|  |  | +			}
 | 
	
		
			
				|  |  | +			if(StringUtils.isEmpty(operateName) && anno != null){
 | 
	
		
			
				|  |  | +				operateName = anno.operateName();
 | 
	
		
			
				|  |  | +			}
 | 
	
		
			
				|  |  | +			if(anno != null){
 | 
	
		
			
				|  |  | +				saveLog(operateName,servletPath,request);
 | 
	
		
			
				|  |  | +				return;
 | 
	
		
			
				|  |  |  			}
 | 
	
		
			
				|  |  | -			auditLog.setToken(request.getHeader("Authorization"));
 | 
	
		
			
				|  |  | -			auditLog.setService(clientName);
 | 
	
		
			
				|  |  | -			auditLog.setUserIp(WebUtil.getRemoteIp(request));
 | 
	
		
			
				|  |  | -
 | 
	
		
			
				|  |  | -			Map<String, Object> params = WebUtil.getParameterMap(request);
 | 
	
		
			
				|  |  | -			if (params == null || params.size() == 0) {
 | 
	
		
			
				|  |  | -				auditLog.setInputParams(IOUtils.toString(request.getInputStream(), Charset.defaultCharset()));
 | 
	
		
			
				|  |  | -			} else {
 | 
	
		
			
				|  |  | -				auditLog.setInputParams(JsonUtil.toJSONString(WebUtil.getParameterMap(request)));
 | 
	
		
			
				|  |  | +			if(servletPath.contains("/task/") || servletPath.contains("/import/") ){
 | 
	
		
			
				|  |  | +				return;
 | 
	
		
			
				|  |  |  			}
 | 
	
		
			
				|  |  | -			// 操作人
 | 
	
		
			
				|  |  | -			auditLog.setUsername(username);
 | 
	
		
			
				|  |  | -			auditLog.setOperateTime(sdf.format(new Date()));
 | 
	
		
			
				|  |  | -			auditLogService.insert(auditLog);
 | 
	
		
			
				|  |  | +			String substring = servletPath.substring(servletPath.lastIndexOf("/") + 1).toLowerCase();
 | 
	
		
			
				|  |  | +			if(ignoreLogUrl == null){
 | 
	
		
			
				|  |  | +				ignoreLogUrl = new ArrayList<>();
 | 
	
		
			
				|  |  | +				ignoreLogUrl.add("add");
 | 
	
		
			
				|  |  | +				ignoreLogUrl.add("insert");
 | 
	
		
			
				|  |  | +				ignoreLogUrl.add("query");
 | 
	
		
			
				|  |  | +				ignoreLogUrl.add("get");
 | 
	
		
			
				|  |  | +				ignoreLogUrl.add("find");
 | 
	
		
			
				|  |  | +				ignoreLogUrl.add("list");
 | 
	
		
			
				|  |  | +				ignoreLogUrl.add("detail");
 | 
	
		
			
				|  |  | +			}
 | 
	
		
			
				|  |  | +			for (String e : ignoreLogUrl) {
 | 
	
		
			
				|  |  | +				if(substring.contains(e)){
 | 
	
		
			
				|  |  | +					return;
 | 
	
		
			
				|  |  | +				}
 | 
	
		
			
				|  |  | +			}
 | 
	
		
			
				|  |  | +			saveLog(operateName,servletPath,request);
 | 
	
		
			
				|  |  | +		}catch (Exception e){
 | 
	
		
			
				|  |  | +			e.printStackTrace();
 | 
	
		
			
				|  |  |  		}
 | 
	
		
			
				|  |  | +	}
 | 
	
		
			
				|  |  |  
 | 
	
		
			
				|  |  | +	private void saveLog(String operateName,String servletPath,HttpServletRequest request) throws IOException {
 | 
	
		
			
				|  |  | +		AuditLog auditLog = new AuditLog();
 | 
	
		
			
				|  |  | +		auditLog.setOperateName(operateName);
 | 
	
		
			
				|  |  | +		auditLog.setInterfaceUrl(servletPath);
 | 
	
		
			
				|  |  | +		auditLog.setToken(request.getHeader("Authorization"));
 | 
	
		
			
				|  |  | +		auditLog.setService(clientName);
 | 
	
		
			
				|  |  | +		auditLog.setUserIp(WebUtil.getRemoteIp(request));
 | 
	
		
			
				|  |  | +
 | 
	
		
			
				|  |  | +		Map<String, Object> params = WebUtil.getParameterMap(request);
 | 
	
		
			
				|  |  | +		if (params == null || params.size() == 0) {
 | 
	
		
			
				|  |  | +			auditLog.setInputParams(IOUtils.toString(request.getInputStream(), Charset.defaultCharset()));
 | 
	
		
			
				|  |  | +		} else {
 | 
	
		
			
				|  |  | +			auditLog.setInputParams(JsonUtil.toJSONString(WebUtil.getParameterMap(request)));
 | 
	
		
			
				|  |  | +		}
 | 
	
		
			
				|  |  | +		// 操作人
 | 
	
		
			
				|  |  | +		auditLog.setUsername(username);
 | 
	
		
			
				|  |  | +		auditLog.setOperateTime(sdf.format(new Date()));
 | 
	
		
			
				|  |  | +		auditLogService.insert(auditLog);
 | 
	
		
			
				|  |  |  	}
 | 
	
		
			
				|  |  |  
 | 
	
		
			
				|  |  |  	public void setUsername(String username) {
 |