package com.jiayue.ipfcst.calculate.job;

import com.jiayue.ipfcst.calculate.service.IAccuracyPassRateCalculate;
import com.jiayue.ipfcst.common.data.entity.ElectricField;
import com.jiayue.ipfcst.common.data.repository.ElectricFieldRepository;
import lombok.extern.slf4j.Slf4j;
import org.quartz.Job;
import org.quartz.JobExecutionContext;
import org.quartz.JobExecutionException;
import org.springframework.beans.factory.annotation.Autowired;

import java.util.Map;


/**
 * 准确率定时控制类
 *
 * @author yh
 * @version 1.0
 * @since 2020/10/22 11:29
 */
@Slf4j
public class AccuracyPassRateCalculateJob implements Job {
  @Autowired
  private ElectricFieldRepository electricFieldRepository;
  @Autowired
  private Map<String,IAccuracyPassRateCalculate> IAccuracyPassRateCalculateMap;

  public AccuracyPassRateCalculateJob() {
  }

  @Override
  public void execute(JobExecutionContext context) throws JobExecutionException {
    ElectricField electricField = this.electricFieldRepository.findByStationCodeIsNotNull();


    if (electricField != null) {
      String className = "accuarcyPassRateCalculateService";
      IAccuracyPassRateCalculate iAccuracyPassRateCalculate = IAccuracyPassRateCalculateMap.get(className + electricField.getProvinceEnum().name());
      if(iAccuracyPassRateCalculate !=null){
        iAccuracyPassRateCalculate.generateData(electricField);
      }else{
        log.warn("该场站无计算准确率合格率类");
      }
    } else {
      log.warn("场站信息未维护，无法计算准确率合格率");
    }

  }
}
