package com.njcn.prepare.executor;

import com.njcn.device.biz.pojo.dto.DeptGetChildrenMoreDTO;
import com.njcn.prepare.harmonic.pojo.bo.CalculatedParam;
import com.njcn.prepare.harmonic.service.mysql.line.PollutionService;
import com.njcn.prepare.harmonic.service.mysql.newalgorithm.RStatSubstationService;
import com.njcn.prepare.harmonic.service.mysql.upload.IRUploadSubstationStatisticalDataDService;
import com.njcn.prepare.harmonic.service.mysql.send.ConverterDetailStatisticsPOService;
import com.yomahub.liteflow.annotation.LiteflowComponent;
import com.yomahub.liteflow.annotation.LiteflowMethod;
import com.yomahub.liteflow.core.NodeComponent;
import com.yomahub.liteflow.enums.LiteFlowMethodEnum;
import com.yomahub.liteflow.enums.NodeTypeEnum;
import lombok.RequiredArgsConstructor;

import java.util.Objects;

/**
 * Description:
 * Date: 2023/11/10  10:39【需求编号】
 *
 * @author clam
 * @version V1.0.0
 */
@LiteflowComponent
@RequiredArgsConstructor
public class SubStationExecutor extends BaseExecutor{

    private final PollutionService pollutionService;
    private final RStatSubstationService rStatSubstationService;
    private final ConverterDetailStatisticsPOService converterDetailStatisticsPOService;
    private final IRUploadSubstationStatisticalDataDService rUploadSubstationStatisticalDataDService;


    /**
     * 3.4.15.	变电站污区图统计（新增）
     *
     */
    @LiteflowMethod(value = LiteFlowMethodEnum.IS_ACCESS, nodeId = "rStatPollutionSubstation", nodeType = NodeTypeEnum.COMMON)
    public boolean processRStatPollutionSubstationAccess(NodeComponent bindCmp) {
        return isAccess(bindCmp);
    }
    @LiteflowMethod(value = LiteFlowMethodEnum.PROCESS, nodeId = "rStatPollutionSubstation", nodeType = NodeTypeEnum.COMMON)
    public void processRStatPollutionSubstationProcess(NodeComponent bindCmp) {
        String tag = bindCmp.getTag();
        CalculatedParam<String> calculatedParam = bindCmp.getRequestData();
        if (tag.equalsIgnoreCase("r_stat_pollution_substation_d")) {
            //日表
            pollutionService.handleSubstationDay(calculatedParam);
        } else if (tag.equalsIgnoreCase("r_stat_pollution_substation_m")) {
            //数据补招不执行非日表算法
            if (!calculatedParam.isRepair()) {
                //月表
                pollutionService.handleSubstationMonth(calculatedParam);
            }
        }else if (tag.equalsIgnoreCase("r_stat_pollution_substation_q")) {
            //数据补招不执行非日表算法
            if (!calculatedParam.isRepair()) {
                //季表
                pollutionService.handleSubstationQtr(calculatedParam);
            }
        }else if (tag.equalsIgnoreCase("r_stat_pollution_substation_y")) {
            //数据补招不执行非日表算法
            if (!calculatedParam.isRepair()) {
                //年表
                pollutionService.handleSubstationYear(calculatedParam);
            }
        }
    }
    /**需求：
     * FWJK-PMS3.0-TC0013-电能质量管理两级贯通接口V1.10
     * 2.4.1.19	接收电能质量换流站指标统计明细数据接口
     *
     */
    @LiteflowMethod(value = LiteFlowMethodEnum.IS_ACCESS, nodeId = "converterDetailStatistics", nodeType = NodeTypeEnum.COMMON)
    public boolean processConverterDetailStatisticsStatistics(NodeComponent bindCmp) {
        return isAccess(bindCmp);
    }
    @LiteflowMethod(value = LiteFlowMethodEnum.PROCESS, nodeId = "converterDetailStatistics", nodeType = NodeTypeEnum.COMMON)
    public void processConverterDetailStatisticsStatisticss(NodeComponent bindCmp) {
        String tag = bindCmp.getTag();
        CalculatedParam<String> calculatedParam = bindCmp.getRequestData();

        converterDetailStatisticsPOService.handleDay(calculatedParam);


    }




    /********************************************算法负责人:xy***********************************************************/
    /**
     * 算法名: 3.4.10-----变电站指标统计(r_stat_substation_*)
     *
     * @author xuyang
     * @date 2023年11月15日 10:06
     */
    @LiteflowMethod(value = LiteFlowMethodEnum.IS_ACCESS, nodeId = "rStatSubstation", nodeType = NodeTypeEnum.COMMON)
    public boolean rStatSubstationAccess(NodeComponent bindCmp) {
        return isAccess(bindCmp);
    }
    @LiteflowMethod(value = LiteFlowMethodEnum.PROCESS, nodeId = "rStatSubstation", nodeType = NodeTypeEnum.COMMON)
    public void rStatSubstationProcess(NodeComponent bindCmp) {
        String tag = bindCmp.getTag();
        CalculatedParam calculatedParam = bindCmp.getRequestData();
        if (Objects.equals(tag,"r_stat_substation_d")){
            //日表
            rStatSubstationService.handlerD(calculatedParam);
        } else if (Objects.equals(tag,"r_stat_substation_m")) {
            //数据补招不执行非日表算法
            if (!calculatedParam.isRepair()) {
                //月表
                rStatSubstationService.handlerM(calculatedParam);
            }
        } else if (Objects.equals(tag,"r_stat_substation_q")) {
            //数据补招不执行非日表算法
            if (!calculatedParam.isRepair()) {
                //季表
                rStatSubstationService.handlerQ(calculatedParam);
            }
        } else if (Objects.equals(tag,"r_stat_substation_y")) {
            //数据补招不执行非日表算法
            if (!calculatedParam.isRepair()) {
                //年表
                rStatSubstationService.handlerY(calculatedParam);
            }
        }
    }

    /**
     * 河北国网上送接口
     * 2.4.1.20接收电能质量变电站监测统计数据接口
     * xuyang
     */
    @LiteflowMethod(value = LiteFlowMethodEnum.IS_ACCESS, nodeId = "rUploadSubStatisticalData", nodeType = NodeTypeEnum.COMMON)
    public boolean rUploadSubStatisticalDataAccess(NodeComponent bindCmp) {
        return isAccess(bindCmp);
    }
    @LiteflowMethod(value = LiteFlowMethodEnum.PROCESS, nodeId = "rUploadSubStatisticalData", nodeType = NodeTypeEnum.COMMON)
    public void rUploadSubStatisticalDataProcess(NodeComponent bindCmp) {
        String tag = bindCmp.getTag();
        CalculatedParam<DeptGetChildrenMoreDTO> calculatedParam = bindCmp.getRequestData();
        if (tag.equalsIgnoreCase("r_upload_substation_statistical_data_m")) {
            //月表
            rUploadSubstationStatisticalDataDService.insertSubStatisticalDataMonth(bindCmp.getRequestData());
        } else if (tag.equalsIgnoreCase("r_upload_substation_statistical_data_y")) {
            //数据补招不执行非日表算法
            if (!calculatedParam.isRepair()) {
                //年算法
                rUploadSubstationStatisticalDataDService.insertSubStatisticalDataYear(bindCmp.getRequestData());
            }
        }
    }
    /********************************************算法负责人:xy结束***********************************************************/

}
