package cn.cecep.talroad.task;

import cn.cecep.talroad.common.core.web.domain.AjaxResults;
import cn.cecep.talroad.data.analyse.task.anomaly.analysis.DataAnomalyAbstractFactory;
import cn.cecep.talroad.data.analyse.task.anomaly.analysis.DataAnomalyAbstractService;
import cn.cecep.talroad.data.analyse.task.enums.DataAnomalyFactoryServiceEnum;
import cn.cecep.talroad.enums.DataTypeEnum;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
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;

/**
 * @author hehongyu
 * @description: 数据逻辑异常分析任务
 * @date 2023/6/11 15:11
 */
@Slf4j
@Api(tags = "数据丢失异常分析任务")
@RestController
@RequestMapping("/data/logic")
public class DataLogicExceptionController {

    @ApiOperation(value = "钢铁,焚烧,焦化,玻璃，电力，水泥 数据丢失异常分析", notes = "钢铁,焚烧,焦化,玻璃，电力，水泥 数据丢失异常分析")
    @GetMapping("/realData")
    public AjaxResults<Void> realData() {
        List<DataAnomalyFactoryServiceEnum> logicCodes = DataAnomalyFactoryServiceEnum.getLogicCodes();
        for (DataAnomalyFactoryServiceEnum logicCode : logicCodes) {
            DataAnomalyAbstractService service = DataAnomalyAbstractFactory.getService(logicCode);
            log.info("执行任务 start：className：{}",service.getClass().getName());
            boolean result = false;
            try {
                result = service.mainProcess();
            } catch (Exception e) {
                log.error("执行数据逻辑分析任务失败！className:{}",service.getClass().getName());
            }
            if (!result){
                log.error("执行数据逻辑分析任务失败！className:{}",service.getClass().getName());
                return AjaxResults.error();
            }
            log.info("执行任务 end：className：{}",service.getClass().getName());
        }
        return AjaxResults.success();
    }

}
