
package com.jeelowcode.core.framework.config.job;

import cn.hutool.core.date.DateUtil;
import com.jeelowcode.tool.framework.quartz.core.handler.JobHandler;
import com.jeelowcode.core.framework.service.IJeeLowCodeConfigService;
import com.jeelowcode.core.framework.service.IJeeLowCodeService;
import com.jeelowcode.framework.tenant.annotation.JeeLowCodeTenantIgnore;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import java.util.Date;

/**
 * 删除excel临时表数据
 */
@Component
@Slf4j
public class ClearExcelDataJob implements JobHandler {

    @Autowired
    private IJeeLowCodeService jeeLowCodeService;

    @Autowired
    private IJeeLowCodeConfigService jeeLowCodeConfigService;


    @Override
    @JeeLowCodeTenantIgnore
    public String execute(String param) {
        log.info("*********** 开始清理Excel Data日志 ************");
        Date now = DateUtil.date();
        Integer day = jeeLowCodeConfigService.getExcelFileDataDay();

        //x天之前
        Date clearDate = DateUtil.offsetDay(now, -day);

        Integer clearCou = jeeLowCodeService.clearExcelData(clearDate);

        String resultStr="*********** Excel Data日志清理完成，共清理了"+clearCou+"条 ************";
        log.info(resultStr);
        return resultStr;
    }

}
