package com.ruoyi.task.locationLog;

import java.util.List;

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

import com.ruoyi.bst.locationLog.domain.LocationLog;
import com.ruoyi.bst.locationLog.service.LocationLogService;
import com.ruoyi.common.constant.CacheConstants;
import com.ruoyi.common.core.redis.RedisCache;

import lombok.extern.slf4j.Slf4j;

@Component
@Slf4j
public class LocationLogTask {
    
    @Autowired
    private RedisCache redisCache;

    @Autowired
    private LocationLogService locationLogService;

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

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