package com.huatek.busi.task.dataoutput;

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

import com.alibaba.dubbo.config.annotation.Reference;
import com.huatek.busi.service.ISimulateResultService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import org.springframework.util.CollectionUtils;

import com.huatek.busi.common.SiteConstants.SiteTreeEnum;
import com.huatek.busi.service.dataoutput.DataOutputEntityService;
import com.huatek.busi.task.base.AbstractBusiTaskExecutor;
import com.huatek.busi.vo.dataoutput.OutputEquipmentVo;

import lombok.extern.slf4j.Slf4j;

/**
 * 数据输出定时任务
 * 
 * @author anker_cheng
 * @date 2019/10/12
 */
@Slf4j
@Component("dataOutputTask")
public class DataOutputTask extends AbstractBusiTaskExecutor {
    @Autowired
    private DataOutputEntityService dataOutputEntityService;

    @Autowired
    ISimulateResultService simulateResultService;
    
    @Override
    public void execute() throws Exception {
        super.execute();
    }

    @Override
    public void execute(LocalDate day) {
        // 删除
        dataOutputEntityService.deleteByDay(day);
        // 生成
        execute(dataOutputEntityService.findOutputEquips(SiteTreeEnum.BYQ_EQM.getValue()), day);
        execute(dataOutputEntityService.findOutputEquips(SiteTreeEnum.GIS_HL_EQM.getValue()), day);
        execute(dataOutputEntityService.findOutputEquips(SiteTreeEnum.BLQ_HL_EQM.getValue()), day);
        execute(dataOutputEntityService.findOutputEquips(SiteTreeEnum.OTHER_EQM.getValue()), day);
        execute(dataOutputEntityService.findOutputEquips(SiteTreeEnum.CW_HL_EQM.getValue()), day);
        execute(dataOutputEntityService.findOutputEquips(SiteTreeEnum.DL_EQM.getValue()), day);
        // 变压器运行工况
        /*execute(dataOutputEntityService.findOutputMainEquips(SiteTreeEnum.BYQ_EQM.getValue()), day);*/
        execute(dataOutputEntityService.findOutputEquips(SiteTreeEnum.GEN_EQM.getValue()), day);
    }

    private void execute(List<OutputEquipmentVo> list, LocalDate day) {
        if (CollectionUtils.isEmpty(list)) {
            return;
        }
        for (OutputEquipmentVo vo : list) {
            try {
                // 查数据、写文件、保存记录
                dataOutputEntityService.doOutput(vo, day);
            } catch (Exception e) {
                log.error(e.getMessage(), e);
            }
        }
    }


}
























