package cn.hanghui.outapi.platform.tenant.job;

import cn.hanghui.outapi.platform.tenant.service.AppLogService;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang3.time.DateUtils;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Configuration;
import org.springframework.scheduling.annotation.EnableAsync;
import org.springframework.scheduling.annotation.EnableScheduling;
import org.springframework.scheduling.annotation.Scheduled;

import javax.annotation.Resource;
import java.util.Date;
import java.util.List;
import java.util.stream.Collectors;

/**
 * @author shisl
 * @package cn.hanghui.outapi.platform.tenant.job
 * @class AppLogJob
 * @date 2023/12/19 下午1:53
 * @description
 */
@Configuration
@EnableScheduling
@EnableAsync
@Slf4j
public class AppLogJob {

    @Value("${job.enable}")
    private Boolean jobEnable;

    @Resource
    private AppLogService appLogService;

    /**
     * 每一分钟执行一次
     */
//    @Scheduled(cron = "0 */1 * * * ?", zone = "Asia/Shanghai")
    /**
     * 每日凌晨0点执行
     */
//    @Scheduled(cron = "0 0 0 * * ?", zone = "Asia/Shanghai")
    public void delExpireLog() {
        if (!jobEnable) {
            return;
        }
        log.info("--->开始执行删除过期日志操作");
        Date currentTime = new Date();
        Date endTime = DateUtils.addDays(currentTime, -7);
        appLogService.delExpireLog(endTime);

    }
}
