mirror of
				https://gitee.com/hhyykk/ipms-sjy.git
				synced 2025-10-31 10:18:42 +08:00 
			
		
		
		
	将 login_log、error_log 迁移到 yudao-core-service 项目中
This commit is contained in:
		| @@ -81,7 +81,7 @@ public class ApiAccessLogFilter extends OncePerRequestFilter { | ||||
|                                       Map<String, String> queryString, String requestBody, Exception ex) { | ||||
|         // 处理用户信息 | ||||
|         accessLog.setUserId(WebFrameworkUtils.getLoginUserId(request)); | ||||
|         accessLog.setUserType(WebFrameworkUtils.getUserType(request)); | ||||
|         accessLog.setUserType(WebFrameworkUtils.getLoginUserType(request)); | ||||
|         // 设置访问结果 | ||||
|         CommonResult<?> result = WebFrameworkUtils.getCommonResult(request); | ||||
|         if (result != null) { | ||||
|   | ||||
| @@ -16,8 +16,7 @@ public interface ApiAccessLogFrameworkService { | ||||
|      * 创建 API 访问日志 | ||||
|      * | ||||
|      * @param createDTO 创建信息 | ||||
|      * @return 是否创建成功 | ||||
|      */ | ||||
|     Future<Boolean> createApiAccessLogAsync(@Valid ApiAccessLogCreateDTO createDTO); | ||||
|     void createApiAccessLogAsync(@Valid ApiAccessLogCreateDTO createDTO); | ||||
|  | ||||
| } | ||||
|   | ||||
| @@ -16,8 +16,7 @@ public interface ApiErrorLogFrameworkService { | ||||
|      * 创建 API 错误日志 | ||||
|      * | ||||
|      * @param createDTO 创建信息 | ||||
|      * @return 是否创建成功 | ||||
|      */ | ||||
|     Future<Boolean> createApiErrorLogAsync(@Valid ApiErrorLogCreateDTO createDTO); | ||||
|     void createApiErrorLogAsync(@Valid ApiErrorLogCreateDTO createDTO); | ||||
|  | ||||
| } | ||||
|   | ||||
| @@ -245,7 +245,7 @@ public class GlobalExceptionHandler { | ||||
|     private void initExceptionLog(ApiErrorLogCreateDTO errorLog, HttpServletRequest request, Throwable e) { | ||||
|         // 处理用户信息 | ||||
|         errorLog.setUserId(WebFrameworkUtils.getLoginUserId(request)); | ||||
|         errorLog.setUserType(WebFrameworkUtils.getUserType(request)); | ||||
|         errorLog.setUserType(WebFrameworkUtils.getLoginUserType(request)); | ||||
|         // 设置异常字段 | ||||
|         errorLog.setExceptionName(e.getClass().getName()); | ||||
|         errorLog.setExceptionMessage(ExceptionUtil.getMessage(e)); | ||||
|   | ||||
| @@ -17,6 +17,7 @@ import javax.servlet.http.HttpServletRequest; | ||||
| public class WebFrameworkUtils { | ||||
|  | ||||
|     private static final String REQUEST_ATTRIBUTE_LOGIN_USER_ID = "login_user_id"; | ||||
|     private static final String REQUEST_ATTRIBUTE_LOGIN_USER_TYPE = "login_user_type"; | ||||
|  | ||||
|     private static final String REQUEST_ATTRIBUTE_COMMON_RESULT = "common_result"; | ||||
|  | ||||
| @@ -24,6 +25,10 @@ public class WebFrameworkUtils { | ||||
|         request.setAttribute(REQUEST_ATTRIBUTE_LOGIN_USER_ID, userId); | ||||
|     } | ||||
|  | ||||
|     public static void setLoginUserType(ServletRequest request, Integer userType) { | ||||
|         request.setAttribute(REQUEST_ATTRIBUTE_LOGIN_USER_TYPE, userType); | ||||
|     } | ||||
|  | ||||
|     /** | ||||
|      * 获得当前用户的编号,从请求中 | ||||
|      * | ||||
| @@ -37,15 +42,24 @@ public class WebFrameworkUtils { | ||||
|         return (Long) request.getAttribute(REQUEST_ATTRIBUTE_LOGIN_USER_ID); | ||||
|     } | ||||
|  | ||||
|     /** | ||||
|      * 获得当前用户的类型,从请求中 | ||||
|      * | ||||
|      * @param request 请求 | ||||
|      * @return 用户编号 | ||||
|      */ | ||||
|     public static Integer getLoginUserType(HttpServletRequest request) { | ||||
|         if (request == null) { | ||||
|             return null; | ||||
|         } | ||||
|         return (Integer) request.getAttribute(REQUEST_ATTRIBUTE_LOGIN_USER_TYPE); | ||||
|     } | ||||
|  | ||||
|     public static Long getLoginUserId() { | ||||
|         HttpServletRequest request = getRequest(); | ||||
|         return getLoginUserId(request); | ||||
|     } | ||||
|  | ||||
|     public static Integer getUserType(HttpServletRequest request) { | ||||
|         return UserTypeEnum.ADMIN.getValue(); // TODO 芋艿:等后续优化 | ||||
|     } | ||||
|  | ||||
|     public static void setCommonResult(ServletRequest request, CommonResult<?> result) { | ||||
|         request.setAttribute(REQUEST_ATTRIBUTE_COMMON_RESULT, result); | ||||
|     } | ||||
|   | ||||
		Reference in New Issue
	
	Block a user
	 YunaiV
					YunaiV