use of com.diboot.iam.entity.IamOperationLog in project diboot by dibo-software.
the class LogAspect method afterReturningHandler.
/**
* 操作日志处理
* @param proceedingJoinPoint
*/
@AfterReturning(value = "pointCut()", returning = "returnObj")
public void afterReturningHandler(JoinPoint proceedingJoinPoint, Object returnObj) {
IamOperationLog operationLog = buildOperationLog(proceedingJoinPoint);
BaseLoginUser currentUser = IamSecurityUtils.getCurrentUser();
if (currentUser == null) {
currentUser = threadLocal.get();
}
// 处理返回结果
int statusCode = 0;
String errorMsg = null;
if (returnObj instanceof JsonResult) {
JsonResult jsonResult = (JsonResult) returnObj;
statusCode = jsonResult.getCode();
if (statusCode > 0) {
errorMsg = jsonResult.getMsg();
}
}
operationLog.setStatusCode(statusCode).setErrorMsg(errorMsg);
// 异步保存操作日志
iamAsyncWorker.saveOperationLog(operationLog, currentUser);
}
use of com.diboot.iam.entity.IamOperationLog in project diboot by dibo-software.
the class LogAspect method afterThrowingHandler.
/**
* 操作日志处理
* @param joinPoint
*/
@AfterThrowing(value = "pointCut()", throwing = "throwable")
public void afterThrowingHandler(JoinPoint joinPoint, Throwable throwable) {
IamOperationLog operationLog = buildOperationLog(joinPoint);
// 处理返回结果
int statusCode = Status.FAIL_EXCEPTION.code();
String errorMsg = null;
if (throwable != null) {
errorMsg = throwable.toString();
StackTraceElement[] stackTraceElements = throwable.getStackTrace();
if (V.notEmpty(stackTraceElements)) {
errorMsg += " : " + stackTraceElements[0].toString();
}
errorMsg = S.cut(errorMsg, maxLength);
}
operationLog.setStatusCode(statusCode).setErrorMsg(errorMsg);
// 异步保存操作日志
iamAsyncWorker.saveOperationLog(operationLog, IamSecurityUtils.getCurrentUser());
}
use of com.diboot.iam.entity.IamOperationLog in project diboot by dibo-software.
the class LogAspect method buildOperationLog.
/**
* 构建操作日志对象
* @param joinPoint
* @return
*/
private IamOperationLog buildOperationLog(JoinPoint joinPoint) {
IamOperationLog operationLog = new IamOperationLog();
// 当前请求信息
RequestAttributes ra = RequestContextHolder.getRequestAttributes();
HttpServletRequest request = ((ServletRequestAttributes) ra).getRequest();
operationLog.setRequestMethod(request.getMethod()).setRequestUri(request.getRequestURI()).setRequestIp(HttpHelper.getRequestIp(request));
// 记录url请求参数 及 body参数
Map<String, Object> paramsMap = new HashMap<>();
if (V.notEmpty(request.getQueryString())) {
paramsMap.put("query", request.getQueryString());
}
// 补充注解信息
MethodSignature signature = (MethodSignature) joinPoint.getSignature();
Method method = signature.getMethod();
Log logAnno = AnnotationUtils.getAnnotation(method, Log.class);
// 保存requestBody数据
if (logAnno.saveRequestData()) {
Object[] bodyParams = joinPoint.getArgs();
if (V.notEmpty(bodyParams)) {
for (Object arg : bodyParams) {
if (arg != null && isSimpleDataType(arg)) {
paramsMap.put(arg.getClass().getSimpleName(), arg);
}
}
}
}
String paramsJson = null;
if (V.notEmpty(paramsMap)) {
paramsJson = JSON.stringify(paramsMap);
}
operationLog.setRequestParams(paramsJson);
String businessObj = logAnno.businessObj();
if (V.isEmpty(businessObj)) {
Class clazz = method.getDeclaringClass();
Class entityClazz = BeanUtils.getGenericityClass(clazz, 0);
if (entityClazz != null) {
businessObj = entityClazz.getSimpleName();
} else {
log.warn("@Log(operation='{}') 注解未识别到class泛型参数,请指定 businessObj", logAnno.operation());
}
}
String appModule = null;
// 自动识别appModule
operationLog.setAppModule(appModule).setBusinessObj(businessObj).setOperation(logAnno.operation());
return operationLog;
}
Aggregations