use of com.diboot.iam.annotation.Log 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