package cn.cecep.talroad.task;

import cn.cecep.talroad.common.core.web.domain.AjaxResults;
import cn.cecep.talroad.data.analyse.task.factory.label.change.FactoryLabelChangeServiceContext;
import cn.cecep.talroad.domain.dto.FactoryLabelChangeDTO;
import cn.cecep.talroad.enums.LabelFactoryEnum;
import io.swagger.annotations.Api;
import lombok.AllArgsConstructor;
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;

/**
 * @Author: Frank
 * @createTime: 2023年06月28日 17:11:33
 * @version:
 * @Description:
 */
@Api(tags = "企业标签变更定时任务")
@RestController
@RequestMapping("/factory/lacbel/change")
@Slf4j
@AllArgsConstructor
public class FactoryLabelChangeController {

    private final FactoryLabelChangeServiceContext factoryLabelChangeServiceContext;

    /**
     * 定时更新 企业的用电量标签关系
     */
    @GetMapping("/activePowerQuantityLabel")
    public AjaxResults<Void> updateFactoryActivePowerQuantityLabel(FactoryLabelChangeDTO factoryLabelChangeDTO) {
        try {
            factoryLabelChangeDTO.setEnumId(LabelFactoryEnum.PF016.getEnumId());
            factoryLabelChangeServiceContext.execute(factoryLabelChangeDTO);
            return AjaxResults.success();
        } catch (Exception e) {
            log.error("定时更新企业的用电量标签关系失败. 原因:{}", e.getMessage(), e);
            return AjaxResults.error();
        }
    }

    /**
     * 定时更新 企业的SO2排放标签关系
     */
    @GetMapping("/airPollutantS02Label")
    public AjaxResults<Void> updateFactoryAirPollutantS02Label(FactoryLabelChangeDTO factoryLabelChangeDTO) {
        try {
            factoryLabelChangeDTO.setEnumId(LabelFactoryEnum.PF008.getEnumId());
            factoryLabelChangeServiceContext.execute(factoryLabelChangeDTO);
            return AjaxResults.success();
        } catch (Exception e) {
            log.error("定时更新企业的SO2排放标签关系失败. 原因:{}", e.getMessage(), e);
            return AjaxResults.error();
        }
    }

    /**
     * 定时更新 企业的NOx排放标签关系
     */
    @GetMapping("/airPollutantNOXLabel")
    public AjaxResults<Void> updateFactoryAirPollutantNOXLabel(FactoryLabelChangeDTO factoryLabelChangeDTO) {
        try {
            factoryLabelChangeDTO.setEnumId(LabelFactoryEnum.PF009.getEnumId());
            factoryLabelChangeServiceContext.execute(factoryLabelChangeDTO);
            return AjaxResults.success();
        } catch (Exception e) {
            log.error("定时更新企业的NOx排放标签关系失败. 原因:{}", e.getMessage(), e);
            return AjaxResults.error();
        }
    }
    /**
     * 定时更新 企业的颗粒物排放标签关系
     */
    @GetMapping("/airPollutantParticulateLabel")
    public AjaxResults<Void> updateFactoryAirPollutantParticulateLabel(FactoryLabelChangeDTO factoryLabelChangeDTO) {
        try {
            factoryLabelChangeDTO.setEnumId(LabelFactoryEnum.PF010.getEnumId());
            factoryLabelChangeServiceContext.execute(factoryLabelChangeDTO);
            return AjaxResults.success();
        } catch (Exception e) {
            log.error("定时更新企业的颗粒物排放标签关系失败. 原因:{}", e.getMessage(), e);
            return AjaxResults.error();
        }
    }



    /**
     * 定时更新 企业的挥发性有机物排放标签关系
     */
    @GetMapping("/airPollutantVOCSLabel")
    public AjaxResults<Void> updateFactoryAirPollutantVOCSLabel(FactoryLabelChangeDTO factoryLabelChangeDTO) {
        try {
            factoryLabelChangeDTO.setEnumId(LabelFactoryEnum.PF011.getEnumId());
            factoryLabelChangeServiceContext.execute(factoryLabelChangeDTO);
            return AjaxResults.success();
        } catch (Exception e) {
            log.error("定时更新企业的企业的挥发性有机物排放标签关系失败. 原因:{}", e.getMessage(), e);
            return AjaxResults.error();
        }
    }
    /**
     * 定时更新 企业的COD排放标签关系
     */
    @GetMapping("/waterPollutantCODLabel")
    public AjaxResults<Void> updateFactoryWaterPollutantCODLabel(FactoryLabelChangeDTO factoryLabelChangeDTO) {
        try {
            factoryLabelChangeDTO.setEnumId(LabelFactoryEnum.PF012.getEnumId());
            factoryLabelChangeServiceContext.execute(factoryLabelChangeDTO);
            return AjaxResults.success();
        } catch (Exception e) {
            log.error("定时更新企业的COD排放标签关系失败. 原因:{}", e.getMessage(), e);
            return AjaxResults.error();
        }
    }
    /**
     * 定时更新 企业的氨氮排放标签关系
     */
    @GetMapping("/waterPollutantAmmoniaNitrogenLabel")
    public AjaxResults<Void> updateFactoryWaterPollutantAmmoniaNitrogenLabel(FactoryLabelChangeDTO factoryLabelChangeDTO) {
        try {
            factoryLabelChangeDTO.setEnumId(LabelFactoryEnum.PF013.getEnumId());
            factoryLabelChangeServiceContext.execute(factoryLabelChangeDTO);
            return AjaxResults.success();
        } catch (Exception e) {
            log.error("定时更新企业的氨氮排放标签关系失败. 原因:{}", e.getMessage(), e);
            return AjaxResults.error();
        }
    }
    /**
     * 定时更新 企业的总氮排放标签关系
     */
    @GetMapping("/waterPollutantTotalNitrogenLabel")
    public AjaxResults<Void> updateFactoryWaterPollutantTotalNitrogenLabel(FactoryLabelChangeDTO factoryLabelChangeDTO) {
        try {
            factoryLabelChangeDTO.setEnumId(LabelFactoryEnum.PF014.getEnumId());
            factoryLabelChangeServiceContext.execute(factoryLabelChangeDTO);
            return AjaxResults.success();
        } catch (Exception e) {
            log.error("定时更新企业的总氮排放标签关系失败. 原因:{}", e.getMessage(), e);
            return AjaxResults.error();
        }
    }
    /**
     * 定时更新 企业的总磷排放标签关系
     */
    @GetMapping("/waterPollutantPhosphorusLabel")
    public AjaxResults<Void> updateFactoryWaterPollutantPhosphorusDLabel(FactoryLabelChangeDTO factoryLabelChangeDTO) {
        try {
            factoryLabelChangeDTO.setEnumId(LabelFactoryEnum.PF015.getEnumId());
            factoryLabelChangeServiceContext.execute(factoryLabelChangeDTO);
            return AjaxResults.success();
        } catch (Exception e) {
            log.error("定时更新企业的总磷排放标签关系失败. 原因:{}", e.getMessage(), e);
            return AjaxResults.error();
        }
    }
}
