package com.jiayue.ipp.idp.job;

import com.jiayue.ipp.common.data.entity.ElectricField;
import com.jiayue.ipp.idp.service.AccuracyCalculationService;
import com.jiayue.ipp.idp.service.ElectricFieldService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.scheduling.annotation.EnableScheduling;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Service;

import java.util.List;


/**
 * 准确率定时计算
 *
 * @author whc
 * @date 2022-10-18 13:52:00
 */
@Slf4j
@Service
@EnableScheduling
public class AccuracyCalculationJob {

    private final AccuracyCalculationService accuracyCalculationService;

    private final ElectricFieldService electricFieldService;

    public AccuracyCalculationJob(AccuracyCalculationService accuracyCalculationService, ElectricFieldService electricFieldService) {
        this.accuracyCalculationService = accuracyCalculationService;
        this.electricFieldService = electricFieldService;
    }

    @Scheduled(cron = "0 0/15 * * * *")
    public void accuracyCalculation() {
        log.info("准确率定时计算任务开始执行");
        List<ElectricField> electricFieldList = electricFieldService.list();
        for (ElectricField e : electricFieldList) {
            accuracyCalculationService.calculate(e);
        }
        log.info("准确率定时计算任务执行完毕");

    }

}
