package com.njcn.prepare.executor;

import com.njcn.device.biz.pojo.dto.DeptGetBusBarDTO;
import com.njcn.prepare.harmonic.pojo.bo.CalculatedParam;
import com.njcn.prepare.harmonic.service.mysql.IRStatOrgBusbarVoltageDService;
import com.njcn.prepare.harmonic.service.mysql.IRStatOrgBusbarVoltageMService;
import com.njcn.prepare.harmonic.service.mysql.IRStatOrgBusbarVoltageQService;
import com.njcn.prepare.harmonic.service.mysql.IRStatOrgBusbarVoltageYService;
import com.njcn.prepare.harmonic.service.mysql.busbar.IStationBusBarReportService;
import com.njcn.prepare.harmonic.service.mysql.dim.IRDimVoltageDService;
import com.njcn.prepare.harmonic.service.mysql.dim.IRDimVoltageMService;
import com.njcn.prepare.harmonic.service.mysql.dim.IRDimVoltageYService;
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;

/**
 * pqs
 *
 * @author xuyang
 * @date 2023/11/27
 */
@LiteflowComponent
@RequiredArgsConstructor
public class BusBarExecutor extends BaseExecutor{
    private final IRDimVoltageDService irDimVoltageDService;
    private final IRDimVoltageMService irDimVoltageMService;
    private final IRDimVoltageYService irDimVoltageYService;

    private final IRStatOrgBusbarVoltageDService rStatOrgBusbarVoltageDService;
    private final IRStatOrgBusbarVoltageMService rStatOrgBusbarVoltageMService;
    private final IRStatOrgBusbarVoltageQService rStatOrgBusbarVoltageQService;
    private final IRStatOrgBusbarVoltageYService rStatOrgBusbarVoltageYService;

    private final IStationBusBarReportService iStationBusBarReportService;

    @LiteflowMethod(value = LiteFlowMethodEnum.IS_ACCESS, nodeId = "rBusbarVoltage", nodeType = NodeTypeEnum.COMMON)
    public boolean rBusbarVoltageAccess(NodeComponent bindCmp) {
        return isAccess(bindCmp);
    }
    @LiteflowMethod(value = LiteFlowMethodEnum.PROCESS, nodeId = "rBusbarVoltage", nodeType = NodeTypeEnum.COMMON)
    public void rBusbarVoltageProcess(NodeComponent bindCmp) {
        String tag = bindCmp.getTag();
        CalculatedParam<DeptGetBusBarDTO> calculatedParam = bindCmp.getRequestData();
        if (tag.equalsIgnoreCase("r_dim_voltage_d")) {
            //日表
            irDimVoltageDService.busbarVoltageD(calculatedParam);
        } else if (tag.equalsIgnoreCase("r_dim_voltage_m")) {
            //数据补招不执行非日表算法
            if (!calculatedParam.isRepair()) {
                //月表
                irDimVoltageMService.busbarVoltageM(calculatedParam);
            }
        }else if (tag.equalsIgnoreCase("r_dim_voltage_y")) {
            //数据补招不执行非日表算法
            if (!calculatedParam.isRepair()) {
                //年表
                irDimVoltageYService.busbarVoltageY(calculatedParam);
            }
        }
    }

    /**
     * 区域电站母线电压类指标超标统计
     * @param bindCmp
     * @return
     */
    @LiteflowMethod(value = LiteFlowMethodEnum.IS_ACCESS, nodeId = "rStatOrgBusBarVoltage", nodeType = NodeTypeEnum.COMMON)
    public boolean rStatOrgBusBarVoltageAccess(NodeComponent bindCmp) {
        return isAccess(bindCmp);
    }
    @LiteflowMethod(value = LiteFlowMethodEnum.PROCESS, nodeId = "rStatOrgBusBarVoltage", nodeType = NodeTypeEnum.COMMON)
    public void rStatOrgBusBarVoltageProcess(NodeComponent bindCmp) {
        String tag = bindCmp.getTag();
        CalculatedParam<DeptGetBusBarDTO> calculatedParam = bindCmp.getRequestData();
        if (tag.equalsIgnoreCase("r_stat_org_busbar_voltage_d")) {
            //日表
            rStatOrgBusbarVoltageDService.busBarHarmonicD(calculatedParam);
        } else if (tag.equalsIgnoreCase("r_stat_org_busbar_voltage_m")) {
            //数据补招不执行非日表算法
            if (!calculatedParam.isRepair()) {
                //月表
                rStatOrgBusbarVoltageMService.busBarHarmonicM(calculatedParam);
            }
        } else if (tag.equalsIgnoreCase("r_stat_org_busbar_voltage_q")) {
            //数据补招不执行非日表算法
            if (!calculatedParam.isRepair()) {
                //季表
                rStatOrgBusbarVoltageQService.busBarHarmonicQ(calculatedParam);
            }
        }  else if (tag.equalsIgnoreCase("r_stat_org_busbar_voltage_y")) {
            //数据补招不执行非日表算法
            if (!calculatedParam.isRepair()) {
                //年表
                rStatOrgBusbarVoltageYService.busBarHarmonicY(calculatedParam);
            }
        }
    }

    @LiteflowMethod(value = LiteFlowMethodEnum.IS_ACCESS, nodeId = "rStatBusbarHarmonicY", nodeType = NodeTypeEnum.COMMON)
    public boolean rStatBusbarHarmonicYAccess(NodeComponent bindCmp) {
        return isAccess(bindCmp);
    }
    @LiteflowMethod(value = LiteFlowMethodEnum.PROCESS, nodeId = "rStatBusbarHarmonicY", nodeType = NodeTypeEnum.COMMON)
    public void rStatBusbarHarmonicYProcess(NodeComponent bindCmp) {
        CalculatedParam<DeptGetBusBarDTO> calculatedParam = bindCmp.getRequestData();

        //年表
        iStationBusBarReportService.handleEveryDayAllYear(calculatedParam);


    }

}
