From 73df1a92d6fd2696d4f359efa19e4b684317d732 Mon Sep 17 00:00:00 2001 From: LSH Date: 星期日, 17 九月 2023 18:46:13 +0800 Subject: [PATCH] # --- src/main/java/com/zy/asrs/service/impl/ApiLogServiceImpl.java | 45 ++++++++++++++++++++++++++++++++++++++++++--- 1 files changed, 42 insertions(+), 3 deletions(-) diff --git a/src/main/java/com/zy/asrs/service/impl/ApiLogServiceImpl.java b/src/main/java/com/zy/asrs/service/impl/ApiLogServiceImpl.java index e428fee..30a725f 100644 --- a/src/main/java/com/zy/asrs/service/impl/ApiLogServiceImpl.java +++ b/src/main/java/com/zy/asrs/service/impl/ApiLogServiceImpl.java @@ -1,12 +1,51 @@ 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, // 瀹㈡埛绔疘P + 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; + } } -- Gitblit v1.9.1