package com.huatek.busi.task.dataoutput;

import com.huatek.busi.dto.SimulateResultDto;
import com.huatek.busi.service.ISimulateResultService;
import com.huatek.busi.service.WarningResultService;
import com.huatek.busi.service.dataoutput.DataOutputEntityService;
import com.huatek.busi.task.base.AbstractBusiTaskExecutor;
import com.huatek.busi.vo.warning.BusiEqmWarningTaskVo;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import org.springframework.util.CollectionUtils;
import org.springframework.util.ObjectUtils;

import java.text.ParseException;
import java.time.LocalDate;
import java.util.List;

/**
 * 数据输出定时任务
 * 
 * @author anker_cheng
 * @date 2019/10/12
 */
@Slf4j
@Component("dataOutputWarningTask")
public class DataOutputWarningTask extends AbstractBusiTaskExecutor {


    @Autowired
    WarningResultService warningResultService;
    @Autowired
    private DataOutputEntityService dataOutputEntityService;
    @Override
    public void execute() throws Exception {
        super.execute();
    }

    @Override
    public void execute(LocalDate day) throws ParseException {
        List<BusiEqmWarningTaskVo> listWarn = dataOutputEntityService.findWarnList();
        for (BusiEqmWarningTaskVo busiEqmWarningTaskVo : listWarn){
            String id = busiEqmWarningTaskVo.getId();
            execute(warningResultService.warningInfo(id),day);
        }
    }
    private void execute(BusiEqmWarningTaskVo vo, LocalDate day) {
        if (ObjectUtils.isEmpty(vo)) {
            return;
        }
            try {
//                 查数据、写文件、保存记录
                dataOutputEntityService.doOutputWarning(vo,day);
            } catch (Exception e) {
                log.error(e.getMessage(), e);
        }
    }
}
























