package com.lantone.daqe.task;

import com.lantone.common.util.DateUtil;
import com.lantone.daqe.facade.ColumnResultManagementFacade;
import com.lantone.daqe.vo.DataCheckVO;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Configuration;
import org.springframework.scheduling.Trigger;
import org.springframework.scheduling.TriggerContext;
import org.springframework.scheduling.annotation.EnableScheduling;
import org.springframework.scheduling.annotation.SchedulingConfigurer;
import org.springframework.scheduling.config.ScheduledTaskRegistrar;
import org.springframework.scheduling.support.CronTrigger;

import java.util.Date;

@Configuration      //1.主要用于标记配置类，兼备Component的效果。
@EnableScheduling   // 2.开启定时任务
@Slf4j
public class UpColumnResultDataCompareTask implements SchedulingConfigurer {

    @Autowired
    private ColumnResultManagementFacade columnResultManagementFacade;
    @Value("${upColumnResult.compare.cron}")
    private String cron = "0 0 0 * * ?";
    @Value("${upColumnResult.compare.use}")
    private String isUsed = "false";
    @Value("${upColumnResult.compare.hospitalId}")
    private String hospitalId = "0";
    /**
     * 执行定时任务.
     */
    @Override
    public void configureTasks(ScheduledTaskRegistrar taskRegistrar) {
        taskRegistrar.addTriggerTask(new Runnable() {
            @Override
            public void run() {
                if(Boolean.parseBoolean(isUsed)){

                    columnResultManagementFacade.taskCheckTableColumnVal(Long.valueOf(hospitalId));
                }
            }
        }, new Trigger() {
            @Override
            public Date nextExecutionTime(TriggerContext triggerContext) {
                CronTrigger trigger = new CronTrigger(cron);
                return trigger.nextExecutionTime(triggerContext);
            }
        });
    }
}
