@Entity
@Data
public class SysOperateLog implements Serializable {
private String id;
private String module;
private String type;
private String ip;
private String content;
private String description;
private LocalDateTime createTime;
private String createId;
private String createName;
private String orgId;
}
@Aspect
@Component
public class SysOperateLogAspect {
@Autowired
private SysOperateLogService sysOperateLogService;
@Pointcut("@annotation(OperateLog)")
public void logPointCut(){
}
@AfterReturning(pointcut = "logPointCut()")
public void doAfter(JoinPoint joinPoint){
String methodName = joinPoint.getSignature().getName();
Method method = currentMethod(joinPoint,methodName);
OperateLog log = method.getAnnotation(OperateLog.class);
sysOperateLogService.put(joinPoint,methodName,log.module(),log.type(),log.description());
}
private Method currentMethod(JoinPoint joinPoint, String methodName) {
Method[] methods = joinPoint.getTarget().getClass().getMethods();
Method resultMethod = null;
for (Method method : methods) {
if (method.getName().equals(methodName)) {
resultMethod = method;
break;
}
}
return resultMethod;
}
}
public interface SysOperateLogService {
void put(JoinPoint joinPoint, String methodName, String module, String type,