package cn.cecep.talroad.task;

import cn.cecep.talroad.common.core.web.domain.AjaxResults;
import cn.cecep.talroad.data.analyse.task.limestone.BaseAnomalyLimestoneService;
import cn.cecep.talroad.data.analyse.task.limestone.LimestoneAnomalyAbstractFactory;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;


/**
 * 石灰石消耗量  脱硫剂 使用量
 */
@Slf4j
@Api(tags = "石灰石消耗量，对应脱硫剂使用量")
@RestController
@RequestMapping("/data/limestone")
public class LimestoneController {

    @Autowired
    private LimestoneAnomalyAbstractFactory limestoneAnomalyAbstractFactory;

    @ApiOperation(value = "干，半干，脱硫剂使用量", notes = "干，半干，脱硫剂使用量")
    @GetMapping("/dryData")
    public AjaxResults<Void> realData() {
        List<BaseAnomalyLimestoneService> dryAnomalyAbstract = limestoneAnomalyAbstractFactory.getDryAnomalyAbstract();
        return execute(dryAnomalyAbstract);
    }

    @ApiOperation(value = "湿，脱硫剂使用量", notes = "湿，脱硫剂使用量")
    @GetMapping("/wetData")
    public AjaxResults<Void> wetData() {
        List<BaseAnomalyLimestoneService> dryAnomalyAbstract = limestoneAnomalyAbstractFactory.getWetAnomalyAbstract();
        return execute(dryAnomalyAbstract);
    }

    public AjaxResults<Void> execute(List<BaseAnomalyLimestoneService> dryAnomalyAbstract){
        for (BaseAnomalyLimestoneService baseAnomalyLimestoneService : dryAnomalyAbstract) {
            log.info("执行任务 start：className：{}",baseAnomalyLimestoneService.getClass().getName());
            boolean result = baseAnomalyLimestoneService.mainProcess();
            if (!result){
                log.error("执行数据逻辑分析任务失败！className:{}",baseAnomalyLimestoneService.getClass().getName());
                return AjaxResults.error();
            }
            log.info("执行任务 end：className：{}",baseAnomalyLimestoneService.getClass().getName());
        }
        return AjaxResults.success();
    }

}
