package com.sinata.appointment.audit; import cn.dev33.satoken.stp.StpUtil; import com.sinata.appointment.service.OpLogApplicationService; import lombok.RequiredArgsConstructor; import lombok.extern.slf4j.Slf4j; import org.aspectj.lang.JoinPoint; import org.aspectj.lang.annotation.AfterReturning; import org.aspectj.lang.annotation.Aspect; import org.springframework.stereotype.Component; /** * 配置类写操作审计(示例):复杂场景可在 ApplicationService 内显式记录。 */ @Slf4j @Aspect @Component @RequiredArgsConstructor public class OpLogAuditAspect { private final OpLogApplicationService opLogApplicationService; @AfterReturning( pointcut = "execution(* com.sinata.appointment.service.ConfigApplicationService.save*(..))", returning = "ret") public void afterConfigSave(JoinPoint jp, Object ret) { try { Long op = StpUtil.isLogin() ? StpUtil.getLoginIdAsLong() : null; opLogApplicationService.recordAsync( op, "CONFIG", jp.getSignature().getName(), jp.getArgs().length > 0 ? jp.getArgs()[0].getClass().getSimpleName() : "UNKNOWN", "", "{}"); } catch (Exception e) { log.debug("audit skip: {}", e.getMessage()); } } }