|
|
|
@ -29,7 +29,7 @@ import java.util.Map;
|
|
|
|
|
/**
|
|
|
|
|
* 操作日志记录处理
|
|
|
|
|
*
|
|
|
|
|
* @author ruoyi
|
|
|
|
|
* @author Lion Li
|
|
|
|
|
*/
|
|
|
|
|
@Slf4j
|
|
|
|
|
@Aspect
|
|
|
|
@ -68,12 +68,10 @@ public class LogAspect {
|
|
|
|
|
OperLogEvent operLog = new OperLogEvent();
|
|
|
|
|
operLog.setStatus(BusinessStatus.SUCCESS.ordinal());
|
|
|
|
|
// 请求的地址
|
|
|
|
|
operLog.setOperIp(ServletUtils.getClientIP());
|
|
|
|
|
String ip = ServletUtils.getClientIP();
|
|
|
|
|
operLog.setOperIp(ip);
|
|
|
|
|
operLog.setOperUrl(StringUtils.substring(ServletUtils.getRequest().getRequestURI(), 0, 255));
|
|
|
|
|
String username = LoginHelper.getUsername();
|
|
|
|
|
if (StringUtils.isNotBlank(username)) {
|
|
|
|
|
operLog.setOperName(username);
|
|
|
|
|
}
|
|
|
|
|
operLog.setOperName(LoginHelper.getUsername());
|
|
|
|
|
|
|
|
|
|
if (e != null) {
|
|
|
|
|
operLog.setStatus(BusinessStatus.FAIL.ordinal());
|
|
|
|
@ -113,7 +111,7 @@ public class LogAspect {
|
|
|
|
|
// 是否需要保存request,参数和值
|
|
|
|
|
if (log.isSaveRequestData()) {
|
|
|
|
|
// 获取参数的信息,传入到数据库中。
|
|
|
|
|
setRequestValue(joinPoint, operLog);
|
|
|
|
|
setRequestValue(joinPoint, operLog, log.excludeParamNames());
|
|
|
|
|
}
|
|
|
|
|
// 是否需要保存response,参数和值
|
|
|
|
|
if (log.isSaveResponseData() && ObjectUtil.isNotNull(jsonResult)) {
|
|
|
|
@ -127,14 +125,16 @@ public class LogAspect {
|
|
|
|
|
* @param operLog 操作日志
|
|
|
|
|
* @throws Exception 异常
|
|
|
|
|
*/
|
|
|
|
|
private void setRequestValue(JoinPoint joinPoint, OperLogEvent operLog) throws Exception {
|
|
|
|
|
private void setRequestValue(JoinPoint joinPoint, OperLogEvent operLog, String[] excludeParamNames) throws Exception {
|
|
|
|
|
Map<String, String> paramsMap = ServletUtils.getParamMap(ServletUtils.getRequest());
|
|
|
|
|
String requestMethod = operLog.getRequestMethod();
|
|
|
|
|
if (HttpMethod.PUT.name().equals(requestMethod) || HttpMethod.POST.name().equals(requestMethod)) {
|
|
|
|
|
String params = argsArrayToString(joinPoint.getArgs());
|
|
|
|
|
if (MapUtil.isEmpty(paramsMap)
|
|
|
|
|
&& HttpMethod.PUT.name().equals(requestMethod) || HttpMethod.POST.name().equals(requestMethod)) {
|
|
|
|
|
String params = argsArrayToString(joinPoint.getArgs(), excludeParamNames);
|
|
|
|
|
operLog.setOperParam(StringUtils.substring(params, 0, 2000));
|
|
|
|
|
} else {
|
|
|
|
|
Map<String, String> paramsMap = ServletUtils.getParamMap(ServletUtils.getRequest());
|
|
|
|
|
MapUtil.removeAny(paramsMap, EXCLUDE_PROPERTIES);
|
|
|
|
|
MapUtil.removeAny(paramsMap, excludeParamNames);
|
|
|
|
|
operLog.setOperParam(StringUtils.substring(JsonUtils.toJsonString(paramsMap), 0, 2000));
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
@ -142,7 +142,7 @@ public class LogAspect {
|
|
|
|
|
/**
|
|
|
|
|
* 参数拼装
|
|
|
|
|
*/
|
|
|
|
|
private String argsArrayToString(Object[] paramsArray) {
|
|
|
|
|
private String argsArrayToString(Object[] paramsArray, String[] excludeParamNames) {
|
|
|
|
|
StringBuilder params = new StringBuilder();
|
|
|
|
|
if (paramsArray != null && paramsArray.length > 0) {
|
|
|
|
|
for (Object o : paramsArray) {
|
|
|
|
@ -152,6 +152,7 @@ public class LogAspect {
|
|
|
|
|
Dict dict = JsonUtils.parseMap(str);
|
|
|
|
|
if (MapUtil.isNotEmpty(dict)) {
|
|
|
|
|
MapUtil.removeAny(dict, EXCLUDE_PROPERTIES);
|
|
|
|
|
MapUtil.removeAny(dict, excludeParamNames);
|
|
|
|
|
str = JsonUtils.toJsonString(dict);
|
|
|
|
|
}
|
|
|
|
|
params.append(str).append(" ");
|
|
|
|
|