| | |
| | | @Resource |
| | | private AsyncLogService asyncLogService; |
| | | |
| | | @Around("@annotation(com.xiaopeng.common.log.annotation.AdminOperationLog) || execution(public * com.xiaopeng..controller..*(..))") |
| | | @Around("@annotation(com.xiaopeng.common.log.annotation.AdminOperationLog)") |
| | | public Object around(ProceedingJoinPoint joinPoint) throws Throwable { |
| | | Method method = getMethod(joinPoint); |
| | | AdminOperationLog annotation = method.getAnnotation(AdminOperationLog.class); |
| | | ApiOperationMeta apiMeta = getApiOperationMeta(method, joinPoint.getTarget().getClass()); |
| | | AdminOperationType operationType = resolveOperationType(annotation, apiMeta, method, joinPoint.getArgs()); |
| | | boolean shouldRecord = shouldRecord(annotation, apiMeta, operationType); |
| | | if (!shouldRecord) { |
| | | return joinPoint.proceed(); |
| | | } |
| | | |
| | | Object result = null; |
| | | Throwable error = null; |
| | |
| | | } |
| | | } |
| | | |
| | | private boolean shouldRecord(AdminOperationLog annotation, ApiOperationMeta apiMeta, AdminOperationType operationType) { |
| | | if (annotation != null) { |
| | | return true; |
| | | } |
| | | return apiMeta.hasAdminTag() && operationType != AdminOperationType.OTHER; |
| | | } |
| | | |
| | | private void saveLog(ProceedingJoinPoint joinPoint, Method method, AdminOperationLog annotation, |
| | | ApiOperationMeta apiMeta, AdminOperationType operationType, Object result, Throwable error) { |
| | | try { |
| | | XpAdminOperationLog operationLog = new XpAdminOperationLog(); |
| | | AdminBusinessType businessType = resolveBusinessType(annotation, apiMeta); |
| | | if (businessType == AdminBusinessType.OTHER || operationType == AdminOperationType.OTHER) { |
| | | return; |
| | | } |
| | | operationLog.setBusinessType(businessType.getCode()); |
| | | operationLog.setBusinessTypeName(businessType.getDesc()); |
| | | operationLog.setOperationType(operationType.getCode()); |