保誠-保戶業務員媒合平台
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
package com.pollex.pam.aop.logging.audit;
 
import com.pollex.pam.aop.logging.audit.strategy.AuditLoggingFactory;
import org.aspectj.lang.ProceedingJoinPoint;
import org.aspectj.lang.annotation.Around;
import org.aspectj.lang.annotation.Aspect;
import org.aspectj.lang.reflect.MethodSignature;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
 
import java.lang.reflect.Method;
 
@Component
@Aspect
public class AuditLoggingAspect {
 
    private static final Logger log = LoggerFactory.getLogger(AuditLoggingAspect.class);
 
    @Autowired
    AuditLoggingFactory auditLoggingFactory;
 
    @Around("@annotation(com.pollex.pam.aop.logging.audit.AuditLoggingInject)")
    public Object around(ProceedingJoinPoint joinPoint) throws Throwable {
        MethodSignature signature = (MethodSignature) joinPoint.getSignature();
        Method method = signature.getMethod();
        AuditLoggingInject auditLoggingInject = method.getAnnotation(AuditLoggingInject.class);
 
        log.info("run audit logging strategy = {}", auditLoggingInject.type());
        auditLoggingFactory.getAuditLoggingStrategy(auditLoggingInject.type()).auditLogging(joinPoint);
 
        return joinPoint.proceed();
    }
}