|
@@ -0,0 +1,61 @@
|
|
|
|
+package com.fire.admin.aop;
|
|
|
|
+
|
|
|
|
+import com.fire.admin.annotation.FireOperationLog;
|
|
|
|
+import io.swagger.annotations.ApiOperation;
|
|
|
|
+import lombok.extern.slf4j.Slf4j;
|
|
|
|
+import org.apache.commons.lang3.StringUtils;
|
|
|
|
+import org.aspectj.lang.ProceedingJoinPoint;
|
|
|
|
+import org.aspectj.lang.annotation.Around;
|
|
|
|
+import org.aspectj.lang.annotation.Aspect;
|
|
|
|
+import org.aspectj.lang.annotation.Pointcut;
|
|
|
|
+import org.aspectj.lang.reflect.MethodSignature;
|
|
|
|
+import org.springframework.stereotype.Component;
|
|
|
|
+
|
|
|
|
+import java.lang.reflect.Method;
|
|
|
|
+import java.util.Arrays;
|
|
|
|
+
|
|
|
|
+/**
|
|
|
|
+ * @author admin
|
|
|
|
+ * 操作日志记录切面
|
|
|
|
+ */
|
|
|
|
+@Aspect
|
|
|
|
+@Component
|
|
|
|
+@Slf4j
|
|
|
|
+public class FireOperationLogAop {
|
|
|
|
+
|
|
|
|
+ @Pointcut("@annotation(com.fire.admin.annotation.FireOperationLog)")
|
|
|
|
+ public void operationLog() {
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ @Around("operationLog()")
|
|
|
|
+ public Object getReturning(ProceedingJoinPoint joinPoint) throws Throwable {
|
|
|
|
+ //获取swagger接口说明注解
|
|
|
|
+ MethodSignature methodSign = (MethodSignature) joinPoint.getSignature();
|
|
|
|
+ Method method = methodSign.getMethod();
|
|
|
|
+ StringBuilder desc = new StringBuilder();
|
|
|
|
+
|
|
|
|
+ FireOperationLog zAnnotation = method.getAnnotation(FireOperationLog.class);
|
|
|
|
+ if (StringUtils.isNotEmpty(zAnnotation.description())) {
|
|
|
|
+ desc = new StringBuilder(zAnnotation.description());
|
|
|
|
+ } else {
|
|
|
|
+ // 判断是否有ApiOperation注解
|
|
|
|
+ boolean flag = method.isAnnotationPresent(ApiOperation.class);
|
|
|
|
+ if (flag) {
|
|
|
|
+ ApiOperation annotation = method.getAnnotation(ApiOperation.class);
|
|
|
|
+ desc = new StringBuilder(annotation.value());
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ //将参数拼接进说明中
|
|
|
|
+ desc.append(Arrays.toString(joinPoint.getArgs()));
|
|
|
|
+ //获取操作结果
|
|
|
|
+ Object obj = null;
|
|
|
|
+ try {
|
|
|
|
+ obj = joinPoint.proceed();
|
|
|
|
+ desc.append(" SUCCESS");
|
|
|
|
+ } catch (Throwable throwable) {
|
|
|
|
+ desc.append(" FAILURE");
|
|
|
|
+ throw throwable;
|
|
|
|
+ }
|
|
|
|
+ return obj;
|
|
|
|
+ }
|
|
|
|
+}
|