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

import com.huatek.busi.common.CacMonitorTypeCode;
import com.huatek.busi.common.SiteConstants;
import com.huatek.busi.common.SiteConstants.SiteTreeEnum;
import com.huatek.busi.common.SiteConstants.TransfromerTreeEnum;
import com.huatek.busi.common.UploadCycle.ConfigField;
import com.huatek.busi.service.BusiGeneratorAmplService;
import com.huatek.busi.service.BusiSensorService;
import com.huatek.busi.service.FailureRateService;
import com.huatek.busi.service.SiteUploadCycleService;
import com.huatek.busi.service.generatro.GeneratorAmplStatisticsService;
import com.huatek.busi.service.transformer.CwzzMonitoringStatisticsService;
import com.huatek.busi.service.transformer.CwzzTemperatureService;
import com.huatek.busi.task.base.AbstractBusiTaskExecutor;
import com.huatek.busi.vo.BusiSensorVo;
import com.huatek.busi.vo.CwzzTemperatureStatisticsVo;
import com.huatek.busi.vo.GeneratorAmplStatisticsVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import org.springframework.util.CollectionUtils;

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

/**
 * 发电机振动统计
 * 
 * @author anker_cheng
 * @date 2019/10/28
 */
@Component("generatorAmplTask")
public class GeneratorAmplTask extends AbstractBusiTaskExecutor {
    @Autowired
    private BusiGeneratorAmplService busiGeneratorAmplService;
    @Autowired
    private SiteUploadCycleService siteUploadCycleService;
    @Autowired
    private FailureRateService failureRateService;
    @Autowired
    private GeneratorAmplStatisticsService generatorAmplStatisticsService;
    @Autowired
    private BusiSensorService busiSensorService;

    @Override
    public void execute(LocalDate day) {
        List<BusiSensorVo> sensorList = this.findSensorList(SiteConstants.GeneratorTreeEnum.ZD_EQM.getValue());
        if (CollectionUtils.isEmpty(sensorList)) {
            return;
        }
        for (BusiSensorVo sensor : sensorList) {
            GeneratorAmplStatisticsVo item = busiGeneratorAmplService.getListEquInfo(day, sensor.getSensorCode());
            if(item != null) {
                generatorAmplStatisticsService.saveStatistics(day, item);
            }
        }
    }

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