| | |
| | | package com.zy.asrs.service.impl; |
| | | |
| | | 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 com.core.common.SnowflakeIdWorker; |
| | | import com.zy.asrs.entity.ApiLog; |
| | | import com.zy.asrs.mapper.ApiLogMapper; |
| | | import com.zy.asrs.service.ApiLogService; |
| | | 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, // 添加时间 |
| | | null, // 修改时间 |
| | | null // 备注 |
| | | ); |
| | | if (!this.insert(apiLog)) { |
| | | log.error("接口调用日志保存失败!"); |
| | | } |
| | | } |
| | | |
| | | @Override |
| | | public boolean clearWeekBefore() { |
| | | return this.baseMapper.clearWeekBefore() > 0; |
| | | } |
| | | } |