| | |
| | | package com.ruoyi.framework.aspectj;
|
| | |
|
| | | import java.lang.reflect.Method;
|
| | | import java.util.Collection;
|
| | | import java.util.Iterator;
|
| | | import java.util.Map;
|
| | | import javax.servlet.http.HttpServletRequest;
|
| | | import javax.servlet.http.HttpServletResponse;
|
| | |
| | | import org.slf4j.Logger;
|
| | | import org.slf4j.LoggerFactory;
|
| | | import org.springframework.stereotype.Component;
|
| | | import org.springframework.validation.BindingResult;
|
| | | import org.springframework.web.multipart.MultipartFile;
|
| | | import org.springframework.web.servlet.HandlerMapping;
|
| | | import com.alibaba.fastjson.JSON;
|
| | | import com.ruoyi.common.enums.HttpMethod;
|
| | | import com.ruoyi.common.utils.SecurityUtils;
|
| | | import com.ruoyi.common.utils.ServletUtils;
|
| | | import com.ruoyi.common.utils.StringUtils;
|
| | | import com.ruoyi.common.utils.ip.IpUtils;
|
| | | import com.ruoyi.common.utils.spring.SpringUtils;
|
| | | import com.ruoyi.framework.aspectj.lang.annotation.Log;
|
| | | import com.ruoyi.framework.aspectj.lang.enums.BusinessStatus;
|
| | | import com.ruoyi.framework.manager.AsyncManager;
|
| | | import com.ruoyi.framework.manager.factory.AsyncFactory;
|
| | | import com.ruoyi.framework.security.LoginUser;
|
| | | import com.ruoyi.framework.security.service.TokenService;
|
| | | import com.ruoyi.project.monitor.domain.SysOperLog;
|
| | |
|
| | | /**
|
| | |
| | | }
|
| | |
|
| | | // 获取当前的用户
|
| | | LoginUser loginUser = SpringUtils.getBean(TokenService.class).getLoginUser(ServletUtils.getRequest());
|
| | | LoginUser loginUser = SecurityUtils.getLoginUser();
|
| | |
|
| | | // *========数据库日志=========*//
|
| | | SysOperLog operLog = new SysOperLog();
|
| | |
| | | // 请求的地址
|
| | | String ip = IpUtils.getIpAddr(ServletUtils.getRequest());
|
| | | operLog.setOperIp(ip);
|
| | | // 返回参数
|
| | | operLog.setJsonResult(JSON.toJSONString(jsonResult));
|
| | |
|
| | | operLog.setOperUrl(ServletUtils.getRequest().getRequestURI());
|
| | | if (loginUser != null)
|
| | | {
|
| | |
| | | // 设置请求方式
|
| | | operLog.setRequestMethod(ServletUtils.getRequest().getMethod());
|
| | | // 处理设置注解上的参数
|
| | | getControllerMethodDescription(joinPoint, controllerLog, operLog);
|
| | | getControllerMethodDescription(joinPoint, controllerLog, operLog, jsonResult);
|
| | | // 保存数据库
|
| | | AsyncManager.me().execute(AsyncFactory.recordOper(operLog));
|
| | | }
|
| | |
| | | * @param operLog 操作日志
|
| | | * @throws Exception
|
| | | */
|
| | | public void getControllerMethodDescription(JoinPoint joinPoint, Log log, SysOperLog operLog) throws Exception
|
| | | public void getControllerMethodDescription(JoinPoint joinPoint, Log log, SysOperLog operLog, Object jsonResult) throws Exception
|
| | | {
|
| | | // 设置action动作
|
| | | operLog.setBusinessType(log.businessType().ordinal());
|
| | |
| | | {
|
| | | // 获取参数的信息,传入到数据库中。
|
| | | setRequestValue(joinPoint, operLog);
|
| | | }
|
| | | // 是否需要保存response,参数和值
|
| | | if (log.isSaveResponseData() && StringUtils.isNotNull(jsonResult))
|
| | | {
|
| | | operLog.setJsonResult(StringUtils.substring(JSON.toJSONString(jsonResult), 0, 2000));
|
| | | }
|
| | | }
|
| | |
|
| | |
| | | {
|
| | | for (int i = 0; i < paramsArray.length; i++)
|
| | | {
|
| | | if (!isFilterObject(paramsArray[i]))
|
| | | if (StringUtils.isNotNull(paramsArray[i]) && !isFilterObject(paramsArray[i]))
|
| | | {
|
| | | Object jsonObj = JSON.toJSON(paramsArray[i]);
|
| | | params += jsonObj.toString() + " ";
|
| | |
| | | * @param o 对象信息。
|
| | | * @return 如果是需要过滤的对象,则返回true;否则返回false。
|
| | | */
|
| | | @SuppressWarnings("rawtypes")
|
| | | public boolean isFilterObject(final Object o)
|
| | | {
|
| | | return o instanceof MultipartFile || o instanceof HttpServletRequest || o instanceof HttpServletResponse;
|
| | | Class<?> clazz = o.getClass();
|
| | | if (clazz.isArray())
|
| | | {
|
| | | return clazz.getComponentType().isAssignableFrom(MultipartFile.class);
|
| | | }
|
| | | else if (Collection.class.isAssignableFrom(clazz))
|
| | | {
|
| | | Collection collection = (Collection) o;
|
| | | for (Iterator iter = collection.iterator(); iter.hasNext();)
|
| | | {
|
| | | return iter.next() instanceof MultipartFile;
|
| | | }
|
| | | }
|
| | | else if (Map.class.isAssignableFrom(clazz))
|
| | | {
|
| | | Map map = (Map) o;
|
| | | for (Iterator iter = map.entrySet().iterator(); iter.hasNext();)
|
| | | {
|
| | | Map.Entry entry = (Map.Entry) iter.next();
|
| | | return entry.getValue() instanceof MultipartFile;
|
| | | }
|
| | | }
|
| | | return o instanceof MultipartFile || o instanceof HttpServletRequest || o instanceof HttpServletResponse
|
| | | || o instanceof BindingResult;
|
| | | }
|
| | | }
|