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
package com.sinata.appointment.service;
 
import com.sinata.appointment.entity.BizOpLog;
import com.sinata.appointment.mapper.BizOpLogMapper;
import java.time.LocalDateTime;
import lombok.RequiredArgsConstructor;
import org.slf4j.MDC;
import org.springframework.scheduling.annotation.Async;
import org.springframework.stereotype.Service;
 
@Service
@RequiredArgsConstructor
public class OpLogApplicationService {
 
    public static final String MDC_TRACE = "traceId";
 
    private final BizOpLogMapper bizOpLogMapper;
 
    @Async
    public void recordAsync(
            Long operatorUserId,
            String module,
            String action,
            String resourceType,
            String resourceId,
            String detailJson) {
        BizOpLog log = new BizOpLog();
        log.setOperatorUserId(operatorUserId);
        log.setModule(module);
        log.setAction(action);
        log.setResourceType(resourceType);
        log.setResourceId(resourceId);
        log.setDetailJson(detailJson);
        log.setOpTime(LocalDateTime.now());
        log.setTraceId(MDC.get(MDC_TRACE));
        bizOpLogMapper.insert(log);
    }
}