package com.zy.asrs.service.impl; import com.baomidou.mybatisplus.service.impl.ServiceImpl; 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.text.SimpleDateFormat; import java.util.Date; @Slf4j @Service("apiLogService") public class ApiLogServiceImpl extends ServiceImpl implements ApiLogService { @Async @Override public void save(String namespace, String url, String appkey, String ip, String request, String response, boolean success) { Date now = new Date(); SimpleDateFormat dateFormat = new SimpleDateFormat("yyyyMMddHHmmss"); ApiLog apiLog = new ApiLog( dateFormat.format(now), // 日志编号 namespace, // 名称空间 url, // 接口地址 "110", // 平台密钥 String.valueOf(now.getTime()), // 时间戳 ip, // 客户端IP request, // 请求内容 response, "0", // 异常内容 success?1:0 , // 结果 1, // 状态 now, // 添加时间 now, // 修改时间 "null" // 备注 ); if (this.baseMapper.insert(apiLog) < 0) { log.error("接口调用日志保存失败!"); } } @Override public boolean clearWeekBefore() { return this.baseMapper.clearWeekBefore() > 0; } }