yangys
2024-10-30 25db770e621f1259b8d5b7fd514207f7481c2d0f
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
package com.qianwen.smartman.common.event;
 
import java.util.Map;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import com.qianwen.core.launch.props.BladeProperties;
import com.qianwen.core.launch.server.ServerInfo;
import com.qianwen.core.log.event.ApiLogEvent;
import com.qianwen.core.log.model.LogApi;
import com.qianwen.core.log.utils.LogAbstractUtil;
import com.qianwen.smartman.modules.system.service.ILogService;
import org.springframework.context.event.EventListener;
import org.springframework.core.annotation.Order;
import org.springframework.scheduling.annotation.Async;
 
public class ApiLogListener {
    private static final Logger log = LoggerFactory.getLogger(ApiLogListener.class);
    private final ILogService logService;
    private final ServerInfo serverInfo;
    private final BladeProperties bladeProperties;
 
    public ApiLogListener(final ILogService logService, final ServerInfo serverInfo, final BladeProperties bladeProperties) {
        this.logService = logService;
        this.serverInfo = serverInfo;
        this.bladeProperties = bladeProperties;
    }
 
    @Async
    @EventListener({ApiLogEvent.class})
    @Order
    public void saveApiLog(ApiLogEvent event) {
        Map<String, Object> source = (Map) event.getSource();
        LogApi logApi = (LogApi) source.get("log");
        LogAbstractUtil.addOtherInfoToLog(logApi, this.bladeProperties, this.serverInfo);
        this.logService.saveApiLog(logApi);
    }
}