审计日志相关代码提交
This commit is contained in:
@@ -1,9 +1,5 @@
|
||||
package com.njcn.web.service.impl;
|
||||
|
||||
import cn.hutool.core.text.StrFormatter;
|
||||
import cn.hutool.core.util.StrUtil;
|
||||
import com.fasterxml.jackson.databind.DeserializationFeature;
|
||||
import com.fasterxml.jackson.databind.ObjectMapper;
|
||||
import com.github.tocrhz.mqtt.publisher.MqttPublisher;
|
||||
import com.njcn.common.config.GeneralInfo;
|
||||
import com.njcn.common.pojo.constant.LogInfo;
|
||||
@@ -19,14 +15,11 @@ import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.core.MethodParameter;
|
||||
import org.springframework.http.server.ServerHttpRequest;
|
||||
import org.springframework.scheduling.annotation.Async;
|
||||
import org.springframework.stereotype.Component;
|
||||
import org.springframework.stereotype.Service;
|
||||
import org.springframework.web.bind.MethodArgumentNotValidException;
|
||||
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
import java.lang.reflect.Method;
|
||||
import java.time.LocalDateTime;
|
||||
import java.time.ZoneOffset;
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
import java.util.Objects;
|
||||
@@ -65,20 +58,21 @@ public class LogServiceImpl implements ILogService {
|
||||
public void recodeAdviceLog(ServerHttpRequest request, MethodParameter returnType, HttpResult httpResult, String methodDescribe) {
|
||||
//处理审计日志
|
||||
String userName;
|
||||
int isLogin = 0;
|
||||
String userIndex ;
|
||||
HttpServletRequest httpServletRequest = RequestUtil.getRequest(request);
|
||||
if (UN_LOGIN_METHOD.contains(methodDescribe)) {
|
||||
userName = RequestUtil.getLoginName(httpServletRequest);
|
||||
userIndex = userName;
|
||||
} else {
|
||||
userName = RequestUtil.getUserNickname(request);
|
||||
isLogin = 1;
|
||||
userIndex = RequestUtil.getUserIndex(request);
|
||||
}
|
||||
String result = httpResult.getCode().equalsIgnoreCase(CommonResponseEnum.FAIL.getCode()) ? CommonResponseEnum.FAIL.getMessage() : CommonResponseEnum.SUCCESS.getMessage();
|
||||
String ip = RequestUtil.getRealIp(request);
|
||||
String type = ReflectCommonUtil.getOperateInfoByMethod(returnType.getMethod()).getOperateType();
|
||||
String level = ReflectCommonUtil.getOperateInfoByMethod(returnType.getMethod()).getOperateLevel();
|
||||
String operateType = ReflectCommonUtil.getOperateTypeByMethod(returnType.getMethod());
|
||||
LogInfoDTO logInfoDTO = new LogInfoDTO(userName, ip, methodDescribe, operateType, result.equalsIgnoreCase("失败") ? 0 : 1, levelStringToNumber(level), type.equalsIgnoreCase("业务事件") ? 0 : 1, generalInfo.getMicroServiceName(), isLogin);
|
||||
LogInfoDTO logInfoDTO = new LogInfoDTO(userName, ip, methodDescribe, operateType, result.equalsIgnoreCase("失败") ? 0 : 1, "",levelStringToNumber(level), type.equalsIgnoreCase("业务事件") ? 0 : 1, generalInfo.getMicroServiceName(), userIndex);
|
||||
publisher.send("/userLog", PubUtils.obj2json(logInfoDTO), 2, false);
|
||||
}
|
||||
|
||||
@@ -95,10 +89,12 @@ public class LogServiceImpl implements ILogService {
|
||||
public void recodeBusinessExceptionLog(Exception exception, HttpServletRequest request, String message) {
|
||||
LogInfoDTO tempLogInfo = RequestUtil.initLogInfo(request);
|
||||
//认证前,获取用户信息
|
||||
int isLogin = 1;
|
||||
String userIndex;
|
||||
if (Objects.equals(tempLogInfo.getUserName(), LogInfo.UNKNOWN_USER)) {
|
||||
tempLogInfo.setUserName(RequestUtil.getLoginName(request));
|
||||
isLogin = 0;
|
||||
userIndex = tempLogInfo.getUserName();
|
||||
}else{
|
||||
userIndex = RequestUtil.getUserIndex(request);
|
||||
}
|
||||
//根据异常获取method方法
|
||||
Method method = ReflectCommonUtil.getMethod(exception);
|
||||
@@ -106,12 +102,11 @@ public class LogServiceImpl implements ILogService {
|
||||
MethodArgumentNotValidException methodArgumentNotValidException = (MethodArgumentNotValidException) exception;
|
||||
method = methodArgumentNotValidException.getParameter().getMethod();
|
||||
}
|
||||
String methodDescribe = StrFormatter.format("{}{}{}", ReflectCommonUtil.getMethodDescribeByMethod(method), StrUtil.C_COMMA, message);
|
||||
String result = CommonResponseEnum.FAIL.getMessage();
|
||||
String type = ReflectCommonUtil.getOperateInfoByMethod(method).getOperateType();
|
||||
String level = ReflectCommonUtil.getOperateInfoByMethod(method).getOperateLevel();
|
||||
String operateType = ReflectCommonUtil.getOperateTypeByMethod(method);
|
||||
LogInfoDTO logInfoDTO = new LogInfoDTO(tempLogInfo.getUserName(), tempLogInfo.getIp(), methodDescribe, operateType, result.equalsIgnoreCase("失败") ? 0 : 1, levelStringToNumber(level), type.equalsIgnoreCase("业务事件") ? 0 : 1, generalInfo.getMicroServiceName(), isLogin);
|
||||
LogInfoDTO logInfoDTO = new LogInfoDTO(tempLogInfo.getUserName(), tempLogInfo.getIp(), ReflectCommonUtil.getMethodDescribeByMethod(method), operateType, result.equalsIgnoreCase("失败") ? 0 : 1,message, levelStringToNumber(level), type.equalsIgnoreCase("业务事件") ? 0 : 1, generalInfo.getMicroServiceName(), userIndex);
|
||||
publisher.send("/userLog", PubUtils.obj2json(logInfoDTO), 1, false);
|
||||
}
|
||||
|
||||
@@ -132,13 +127,12 @@ public class LogServiceImpl implements ILogService {
|
||||
MethodArgumentNotValidException methodArgumentNotValidException = (MethodArgumentNotValidException) exception;
|
||||
method = methodArgumentNotValidException.getParameter().getMethod();
|
||||
}
|
||||
String methodDescribe = StrFormatter.format("{}{}{}", ReflectCommonUtil.getMethodDescribeByMethod(method), StrUtil.C_COMMA, message);
|
||||
String result = CommonResponseEnum.FAIL.getMessage();
|
||||
String ip = RequestUtil.getRealIp(request);
|
||||
String type = ReflectCommonUtil.getOperateInfoByMethod(method).getOperateType();
|
||||
String level = ReflectCommonUtil.getOperateInfoByMethod(method).getOperateLevel();
|
||||
String operateType = ReflectCommonUtil.getOperateTypeByMethod(method);
|
||||
LogInfoDTO logInfoDTO = new LogInfoDTO(userName, ip, methodDescribe, operateType, result.equalsIgnoreCase("失败") ? 0 : 1, levelStringToNumber(level), type.equalsIgnoreCase("业务事件") ? 0 : 1, generalInfo.getMicroServiceName(), 0);
|
||||
LogInfoDTO logInfoDTO = new LogInfoDTO(userName, ip, ReflectCommonUtil.getMethodDescribeByMethod(method), operateType, result.equalsIgnoreCase("失败") ? 0 : 1,message, levelStringToNumber(level), type.equalsIgnoreCase("业务事件") ? 0 : 1, generalInfo.getMicroServiceName(), userName);
|
||||
publisher.send("/userLog", PubUtils.obj2json(logInfoDTO), 1, false);
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user