|  | @@ -1,12 +1,17 @@
 | 
	
		
			
				|  |  |  package com.tzld.piaoquan.content.understanding.handle;
 | 
	
		
			
				|  |  |  
 | 
	
		
			
				|  |  | +import java.util.HashMap;
 | 
	
		
			
				|  |  |  import java.util.List;
 | 
	
		
			
				|  |  | +import java.util.Map;
 | 
	
		
			
				|  |  |  
 | 
	
		
			
				|  |  |  import javax.servlet.http.HttpServletRequest;
 | 
	
		
			
				|  |  |  
 | 
	
		
			
				|  |  |  import com.tzld.piaoquan.content.understanding.common.base.CommonResponse;
 | 
	
		
			
				|  |  | +import com.tzld.piaoquan.content.understanding.service.LoghubService;
 | 
	
		
			
				|  |  |  import org.slf4j.Logger;
 | 
	
		
			
				|  |  |  import org.slf4j.LoggerFactory;
 | 
	
		
			
				|  |  | +import org.springframework.beans.factory.annotation.Autowired;
 | 
	
		
			
				|  |  | +import org.springframework.beans.factory.annotation.Value;
 | 
	
		
			
				|  |  |  import org.springframework.util.CollectionUtils;
 | 
	
		
			
				|  |  |  import org.springframework.validation.BindException;
 | 
	
		
			
				|  |  |  import org.springframework.validation.ObjectError;
 | 
	
	
		
			
				|  | @@ -29,6 +34,14 @@ public class GlobalExceptionHandle {
 | 
	
		
			
				|  |  |  
 | 
	
		
			
				|  |  |      private static Logger LOGGER = LoggerFactory.getLogger(GlobalExceptionHandle.class);
 | 
	
		
			
				|  |  |  
 | 
	
		
			
				|  |  | +    @Autowired
 | 
	
		
			
				|  |  | +    private LoghubService loghubService;
 | 
	
		
			
				|  |  | +
 | 
	
		
			
				|  |  | +    @Value("aliyun.log.project")
 | 
	
		
			
				|  |  | +    private String aliyunLogProject;
 | 
	
		
			
				|  |  | +    @Value("aliyun.log.logstore.error")
 | 
	
		
			
				|  |  | +    private String aliyunLogLogstoreError;
 | 
	
		
			
				|  |  | +
 | 
	
		
			
				|  |  |      @ExceptionHandler
 | 
	
		
			
				|  |  |      public Object handleException(HttpServletRequest req, Exception exception) throws Exception {
 | 
	
		
			
				|  |  |          String uri = req.getRequestURI();
 | 
	
	
		
			
				|  | @@ -39,6 +52,11 @@ public class GlobalExceptionHandle {
 | 
	
		
			
				|  |  |              response.setCode(e.getCode());
 | 
	
		
			
				|  |  |              response.setMsg(e.getMsg());
 | 
	
		
			
				|  |  |              LOGGER.warn("uri:" + uri + "\n" + "CustomException log.", exception);
 | 
	
		
			
				|  |  | +            Map<String, Object> logMap = new HashMap<>();
 | 
	
		
			
				|  |  | +            logMap.put("uri", "uri");
 | 
	
		
			
				|  |  | +            logMap.put("code", e.getCode());
 | 
	
		
			
				|  |  | +            logMap.put("msg", e.getMsg());
 | 
	
		
			
				|  |  | +            loghubService.asyncSubmitLog(aliyunLogProject, aliyunLogLogstoreError, "" , logMap);
 | 
	
		
			
				|  |  |          } else if (exception instanceof MethodArgumentNotValidException) {
 | 
	
		
			
				|  |  |              // 参数校验异常
 | 
	
		
			
				|  |  |              MethodArgumentNotValidException e = (MethodArgumentNotValidException) exception;
 | 
	
	
		
			
				|  | @@ -53,6 +71,11 @@ public class GlobalExceptionHandle {
 | 
	
		
			
				|  |  |              response.setCode(ExceptionEnum.PARAMS_INVALID.getCode());
 | 
	
		
			
				|  |  |              response.setMsg(errorMsg.toString());
 | 
	
		
			
				|  |  |              LOGGER.warn("uri:" + uri + "\n" + "MethodArgumentNotValidException log.", exception);
 | 
	
		
			
				|  |  | +            Map<String, Object> logMap = new HashMap<>();
 | 
	
		
			
				|  |  | +            logMap.put("uri", "uri");
 | 
	
		
			
				|  |  | +            logMap.put("code", ExceptionEnum.PARAMS_INVALID.getCode());
 | 
	
		
			
				|  |  | +            logMap.put("msg", errorMsg.toString());
 | 
	
		
			
				|  |  | +            loghubService.asyncSubmitLog(aliyunLogProject, aliyunLogLogstoreError, "" , logMap);
 | 
	
		
			
				|  |  |          } else if (exception instanceof BindException) {
 | 
	
		
			
				|  |  |              // 参数绑定异常
 | 
	
		
			
				|  |  |              BindException e = (BindException) exception;
 | 
	
	
		
			
				|  | @@ -67,10 +90,20 @@ public class GlobalExceptionHandle {
 | 
	
		
			
				|  |  |              response.setCode(ExceptionEnum.PARAMS_INVALID.getCode());
 | 
	
		
			
				|  |  |              response.setMsg(errorMsg.toString());
 | 
	
		
			
				|  |  |              LOGGER.warn("uri:" + uri + "\n" + "BindException log.", exception);
 | 
	
		
			
				|  |  | +            Map<String, Object> logMap = new HashMap<>();
 | 
	
		
			
				|  |  | +            logMap.put("uri", "uri");
 | 
	
		
			
				|  |  | +            logMap.put("code", ExceptionEnum.PARAMS_INVALID.getCode());
 | 
	
		
			
				|  |  | +            logMap.put("msg", errorMsg.toString());
 | 
	
		
			
				|  |  | +            loghubService.asyncSubmitLog(aliyunLogProject, aliyunLogLogstoreError, "" , logMap);
 | 
	
		
			
				|  |  |          } else {
 | 
	
		
			
				|  |  |              response.setCode(ExceptionEnum.SYSTEM_ERROR.getCode());
 | 
	
		
			
				|  |  |              response.setMsg(ExceptionEnum.SYSTEM_ERROR.getMsg());
 | 
	
		
			
				|  |  |              LOGGER.error("uri:" + uri + "\n" + "unknow exception log.", exception);
 | 
	
		
			
				|  |  | +            Map<String, Object> logMap = new HashMap<>();
 | 
	
		
			
				|  |  | +            logMap.put("uri", "uri");
 | 
	
		
			
				|  |  | +            logMap.put("code", ExceptionEnum.SYSTEM_ERROR.getCode());
 | 
	
		
			
				|  |  | +            logMap.put("msg", ExceptionEnum.SYSTEM_ERROR.getMsg());
 | 
	
		
			
				|  |  | +            loghubService.asyncSubmitLog(aliyunLogProject, aliyunLogLogstoreError, "" , logMap);
 | 
	
		
			
				|  |  |          }
 | 
	
		
			
				|  |  |          return response;
 | 
	
		
			
				|  |  |      }
 |