package com.huatek.busi.task.generator.part;

import com.huatek.busi.common.SiteConstants;
import com.huatek.busi.common.SiteConstants.SiteTreeEnum;
import com.huatek.busi.service.*;
import com.huatek.busi.service.generatro.GeneratorAmplStatisticsService;
import com.huatek.busi.service.generatro.GeneratorPressureStatisticsService;
import com.huatek.busi.task.base.AbstractBusiTaskExecutor;
import com.huatek.busi.vo.BusiSensorVo;
import com.huatek.busi.vo.GeneratorAmplStatisticsVo;
import com.huatek.busi.vo.GeneratorPressureStatisticsVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import org.springframework.util.CollectionUtils;

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

/**
 * 发电机压力统计
 * 
 * @author anker_cheng
 * @date 2019/10/28
 */
@Component("generatorPressureTask")
public class GeneratorPressureTask extends AbstractBusiTaskExecutor {
    @Autowired
    private BusiGeneratorAmplService busiGeneratorAmplService;

    @Autowired
    private BusiGeneratorPressureService busiGeneratorPressureService;

    @Autowired
    private SiteUploadCycleService siteUploadCycleService;
    @Autowired
    private FailureRateService failureRateService;
    @Autowired
    private GeneratorAmplStatisticsService generatorAmplStatisticsService;
    @Autowired
    private GeneratorPressureStatisticsService generatorPressureStatisticsService;

    @Autowired
    private BusiSensorService busiSensorService;

    @Override
    public void execute(LocalDate day) {
        List<BusiSensorVo> sensorList = this.findSensorList(SiteConstants.GeneratorTreeEnum.YL_EQM.getValue());
        if (CollectionUtils.isEmpty(sensorList)) {
            return;
        }
        for (BusiSensorVo sensor : sensorList) {
            // 上传周期
//            BigDecimal cycle = siteUploadCycleService.getCycle(sensor.getSiteId(), ConfigField.fdjzz);
            // 数据统计
//            GeneratorAmplStatisticsVo item = busiGeneratorAmplService.getListEquInfo(day, sensor.getSensorCode());

            GeneratorPressureStatisticsVo item = busiGeneratorPressureService.getListEquInfo(day, sensor.getSensorCode());
            // 保存缺失率
//            failureRateService.saveSensorFailureRate(sensor, day, cycle, item == null ? 0 : item.getDataCount());
            // 保存统计信息
            if(item != null) {
                generatorPressureStatisticsService.saveStatistics(day, item);

            }
        }
    }

    private List<BusiSensorVo> findSensorList(String equipmentType) {
        return busiSensorService.findSensorList(SiteTreeEnum.GEN, new String[] {equipmentType});
    }
}
