日志注解新增是否保存响应参数
parent
7187161621
commit
8fadbef031
|
@ -37,4 +37,9 @@ public @interface Log
|
||||||
* 是否保存请求的参数
|
* 是否保存请求的参数
|
||||||
*/
|
*/
|
||||||
public boolean isSaveRequestData() default true;
|
public boolean isSaveRequestData() default true;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 是否保存响应的参数
|
||||||
|
*/
|
||||||
|
public boolean isSaveResponseData() default true;
|
||||||
}
|
}
|
||||||
|
|
|
@ -23,7 +23,6 @@ import com.alibaba.fastjson.support.spring.PropertyPreFilters;
|
||||||
import com.ruoyi.common.annotation.Log;
|
import com.ruoyi.common.annotation.Log;
|
||||||
import com.ruoyi.common.core.domain.entity.SysUser;
|
import com.ruoyi.common.core.domain.entity.SysUser;
|
||||||
import com.ruoyi.common.enums.BusinessStatus;
|
import com.ruoyi.common.enums.BusinessStatus;
|
||||||
import com.ruoyi.common.json.JSON;
|
|
||||||
import com.ruoyi.common.utils.ServletUtils;
|
import com.ruoyi.common.utils.ServletUtils;
|
||||||
import com.ruoyi.common.utils.ShiroUtils;
|
import com.ruoyi.common.utils.ShiroUtils;
|
||||||
import com.ruoyi.common.utils.StringUtils;
|
import com.ruoyi.common.utils.StringUtils;
|
||||||
|
@ -94,12 +93,6 @@ public class LogAspect
|
||||||
// 请求的地址
|
// 请求的地址
|
||||||
String ip = ShiroUtils.getIp();
|
String ip = ShiroUtils.getIp();
|
||||||
operLog.setOperIp(ip);
|
operLog.setOperIp(ip);
|
||||||
// 返回参数
|
|
||||||
if (StringUtils.isNotNull(jsonResult))
|
|
||||||
{
|
|
||||||
operLog.setJsonResult(StringUtils.substring(JSON.marshal(jsonResult), 0, 2000));
|
|
||||||
}
|
|
||||||
|
|
||||||
operLog.setOperUrl(ServletUtils.getRequest().getRequestURI());
|
operLog.setOperUrl(ServletUtils.getRequest().getRequestURI());
|
||||||
if (currentUser != null)
|
if (currentUser != null)
|
||||||
{
|
{
|
||||||
|
@ -123,7 +116,7 @@ public class LogAspect
|
||||||
// 设置请求方式
|
// 设置请求方式
|
||||||
operLog.setRequestMethod(ServletUtils.getRequest().getMethod());
|
operLog.setRequestMethod(ServletUtils.getRequest().getMethod());
|
||||||
// 处理设置注解上的参数
|
// 处理设置注解上的参数
|
||||||
getControllerMethodDescription(joinPoint, controllerLog, operLog);
|
getControllerMethodDescription(joinPoint, controllerLog, operLog, jsonResult);
|
||||||
// 保存数据库
|
// 保存数据库
|
||||||
AsyncManager.me().execute(AsyncFactory.recordOper(operLog));
|
AsyncManager.me().execute(AsyncFactory.recordOper(operLog));
|
||||||
}
|
}
|
||||||
|
@ -143,7 +136,7 @@ public class LogAspect
|
||||||
* @param operLog 操作日志
|
* @param operLog 操作日志
|
||||||
* @throws Exception
|
* @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动作
|
// 设置action动作
|
||||||
operLog.setBusinessType(log.businessType().ordinal());
|
operLog.setBusinessType(log.businessType().ordinal());
|
||||||
|
@ -157,6 +150,11 @@ public class LogAspect
|
||||||
// 获取参数的信息,传入到数据库中。
|
// 获取参数的信息,传入到数据库中。
|
||||||
setRequestValue(joinPoint, operLog);
|
setRequestValue(joinPoint, operLog);
|
||||||
}
|
}
|
||||||
|
// 是否需要保存response,参数和值
|
||||||
|
if (log.isSaveResponseData() && StringUtils.isNotNull(jsonResult))
|
||||||
|
{
|
||||||
|
operLog.setJsonResult(StringUtils.substring(JSONObject.toJSONString(jsonResult), 0, 2000));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
Loading…
Reference in New Issue