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
42
43
44
45
| package com.zy.asrs.service.impl;
|
| import com.core.common.SnowflakeIdWorker;
| import com.zy.asrs.mapper.ApiLogMapper;
| import com.zy.asrs.entity.ApiLog;
| import com.zy.asrs.service.ApiLogService;
| import com.baomidou.mybatisplus.service.impl.ServiceImpl;
| import lombok.extern.slf4j.Slf4j;
| import org.springframework.beans.factory.annotation.Autowired;
| import org.springframework.scheduling.annotation.Async;
| import org.springframework.stereotype.Service;
|
| import java.util.Date;
| @Slf4j
| @Service("apiLogService")
| public class ApiLogServiceImpl extends ServiceImpl<ApiLogMapper, ApiLog> implements ApiLogService {
|
| @Autowired
| private SnowflakeIdWorker snowflakeIdWorker;
|
| @Async
| @Override
| public void save(String namespace, String url, String appkey, String ip, String request, String response, boolean success) {
| Date now = new Date();
| ApiLog apiLog = new ApiLog(
| String.valueOf(snowflakeIdWorker.nextId()), // 日志编号
| namespace, // 名称空间
| url, // 接口地址
| appkey, // 平台密钥
| String.valueOf(now.getTime()), // 时间戳
| ip, // 客户端IP
| request, // 请求内容
| response,
| null, // 异常内容
| success?1:0 , // 结果
| 1, // 状态
| now, // 添加时间
| now, // 修改时间
| null // 备注
| );
| if (!this.insert(apiLog)) {
| log.error("接口调用日志保存失败!");
| }
| }
| }
|
|