package com.ruoyi.task.operLog;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import com.ruoyi.common.constant.CacheConstants;
import com.ruoyi.common.core.redis.RedisCache;
import com.ruoyi.system.operLog.domain.OperLog;
import com.ruoyi.system.operLog.service.OperLogService;

import lombok.extern.slf4j.Slf4j;

@Component
@Slf4j
public class OperLogTask {


    @Autowired
    private RedisCache redisCache;

    @Autowired
    private OperLogService operLogService;

    // 将缓存中的定位日志保存到数据库
    public void freshToDb() {
        List<OperLog> logList = redisCache.getAndClearCacheList(CacheConstants.OPER_LOG_QUEUE);

        // 保存到数据库
        int rows = operLogService.batchInsert(logList);
        log.info("保存到数据库{}条操作日志", rows);
    }
}
