longz
2026-04-21 c4db0a4526f61758272c92396aa788d84f098102
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
36
37
38
39
40
41
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());
        }
    }
}