<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
<mapper namespace="com.hdkj.lt.bf.mapper.FhzgLimitProcessStateCheckMapper">

    <select id="selectProcessStateCheckList" resultType="com.hdkj.lt.bf.entity.vo.ProcessStateVO"
    parameterType="com.hdkj.lt.core.bizms.modle.dto.SchemeQueryDTO">
        select
            a.id,
            a.scheme_id,
            a.switch_id,
            a.line_id,
            a.line_name,
            a.opposite_line_id,
            a.opposite_line_name,
            a.phase_angle_diff,
            a.phase_angle_diff_check,
            a.busbar_volt_diff,
            a.busbar_volt_diff_check,
            a.switch_rated_current,
            a.loop_close_current,
            a.loop_close_current_check,
            a.op_loop_close_current,
            a.op_loop_close_current_check,
            a.switch_current_check,
            a.segment_current_check,
            a.loop_close_check,
            b.switch_name,
            b.switch_type,
            b.is_auto_switch,
            b.operation_content,
            b.switching_seq
        from fhzg_plan_transfer_scheme_loop_close_check a
                 left join fhzg_info_limit_transfer_scheme_switching_sequence b
                           on a.scheme_id = b.scheme_id and a.switch_id = b.switch_id
        where a.scheme_id = #{schemeId}
          limit #{pageSize} offset #{offset}
    </select>

    <select id="selectProcessStateCheckCount" resultType="java.lang.Integer"
            parameterType="com.hdkj.lt.core.bizms.modle.dto.SchemeQueryDTO">
        select count(*) from
            fhzg_plan_transfer_scheme_loop_close_check a
                 left join fhzg_info_limit_transfer_scheme_switching_sequence b
                           on a.scheme_id = b.scheme_id and a.switch_id = b.switch_id
        where a.scheme_id = #{schemeId}
    </select>

    <select id="getSwitchingSequenceList" resultType="com.hdkj.lt.bf.entity.vo.SwitchingSequenceVO"
            parameterType="com.hdkj.lt.core.bizms.modle.dto.SchemeQueryDTO">
        select
            id ,
            scheme_id ,
            switch_id ,
            switch_name ,
            switch_type ,
            is_auto_switch ,
            operation_content ,
            switching_seq ,
            loop_close_check ,
            final_state_check
        from fhzg_info_limit_transfer_scheme_switching_sequence
        where scheme_id = #{schemeId}
            limit #{pageSize} offset #{offset}
    </select>

    <select id="getSwitchingSequenceCount" resultType="java.lang.Integer"
            parameterType="com.hdkj.lt.core.bizms.modle.dto.SchemeQueryDTO">
        select count(*)
        from fhzg_info_limit_transfer_scheme_switching_sequence
        where scheme_id = #{schemeId}
    </select>


    <select id="getSwitchCurrentDetailList" resultType="com.hdkj.lt.bf.entity.vo.SwitchingLoopCheckVO"
            parameterType="com.hdkj.lt.core.bizms.modle.dto.SchemeQueryDTO">
        select
            id ,
            switching_id ,
            line_id ,
            line_name ,
            opposite_line_id ,
            opposite_line_name ,
            phase_angle_diff ,
            phase_angle_diff_threshold ,
            phase_angle_diff_check ,
            line_voltage ,
            opposite_line_voltage ,
            line_voltage_diff ,
            line_voltage_diff_threshold ,
            line_voltage_diff_check,
            loop_current ,
            loop_current_threshold ,
            loop_current_check ,
            switch_current_check ,
            segment_current_check,
            afdrate_current,
            afd_cur_loop,
            rate_current,
            bfd_cur_loop
        from fhzg_limit_transfer_scheme_switching_loop_check
        where switching_id = #{switchingId}
    </select>


    <select id="getSwitchingLoopSwCurrentList" resultType="com.hdkj.lt.bf.entity.vo.SwitchingLoopSwVO"
            parameterType="com.hdkj.lt.core.bizms.modle.dto.SchemeQueryDTO">
        select
            id,
            switching_id,
            switch_id,
            switch_name,
            line_id,
            line_name,
            pre_loop_close_current,
            loop_close_current,
            loop_open_current,
            current_threshold,
            oc2_value,
            switch_current_check,
            line_rate_current,
            switch_rate_current
        from fhzg_limit_transfer_scheme_switching_loop_sw_current_detail
        where switching_id = #{switchingId}
            limit #{pageSize} offset #{offset}
    </select>

    <select id="getSwitchingLoopSwCurrentCount" resultType="java.lang.Integer"
            parameterType="com.hdkj.lt.core.bizms.modle.dto.SchemeQueryDTO">
        select count(*)
        from fhzg_limit_transfer_scheme_switching_loop_sw_current_detail
        where switching_id = #{switchingId}
    </select>

    <select id="getSwitchingLoopSegCurrentList" resultType="com.hdkj.lt.bf.entity.vo.SwitchingLoopSegVO"
            parameterType="com.hdkj.lt.core.bizms.modle.dto.SchemeQueryDTO">
        select
            id,
            switching_id,
            segment_id,
            segment_name,
            line_id,
            line_name,
            segment_rated_ampacity,
            pre_loop_close_current,
            loop_close_current,
            loop_open_current,
            current_threshold,
            margin_value,
            segment_current_check
        from fhzg_limit_transfer_scheme_switching_loop_seg_current_detail
        where switching_id = #{switchingId}
            limit #{pageSize} offset #{offset}
    </select>

    <select id="getSwitchingLoopSegCurrentCount" resultType="java.lang.Integer"
            parameterType="com.hdkj.lt.core.bizms.modle.dto.SchemeQueryDTO">
        select count(*)
        from fhzg_limit_transfer_scheme_switching_loop_seg_current_detail
        where switching_id = #{switchingId}
    </select>

    <select id="getFinalStateCheckDetail" resultType="com.hdkj.lt.bf.entity.vo.FinalStateCheckVO"
            parameterType="com.hdkj.lt.core.bizms.modle.dto.SchemeQueryDTO">
        select
            id,
            switching_id,
            line_id,
            line_name,
            opposite_line_id,
            opposite_line_name,
            allow_max_current,
            estimate_max_current,
            estimate_max_load_factor,
            load_factor_threshold,
            load_factor_check,
            switch_current_check,
            segment_current_check
        from fhzg_limit_transfer_scheme_switching_final_check a
        where a.switching_id = #{switchingId}
    </select>

    <select id="getSwitchingAutoSequenceCount" resultType="java.lang.Integer"
            parameterType="com.hdkj.lt.core.bizms.modle.dto.SchemeQueryDTO">
        select count(*) from
            fhzg_limit_transfer_scheme_loop_close_check a
                left join fhzg_info_limit_transfer_scheme_switching_sequence b
                          on a.scheme_id = b.scheme_id and a.switch_id = b.switch_id
        where a.scheme_id = #{schemeId}
        and is_auto_switch = '1'
    </select>

    <select id="getMaxLoadFactorBySchemeId" resultType="java.lang.String">
        select max(fc.estimate_max_load_factor) from fhzg_limit_transfer_scheme_switching_final_check fc
            left join fhzg_info_limit_transfer_scheme_switching_sequence ss
                on fc.switching_id = ss.switch_id
        where ss.scheme_id = #{schemeId}
    </select>

    <select id="getLoopSegCurrentListBySwitchingId" resultType="java.util.Map">
        select
            ROW_NUMBER() over() rowNum,
            id id,
            switching_id switchingId,
            segment_id segmentId,
            segment_name segmentName,
            line_id lineId,
            line_name lineName,
            segment_rated_ampacity segmentRatedAmpacity,
            pre_loop_close_current preLoopCloseCurrent,
            loop_close_current loopCloseCurrent,
            loop_open_current loopOpenCurrent,
            CASE
              segment_current_check
                WHEN '0' THEN
                '不通过'
                WHEN '1' THEN
                '通过' ELSE '未知状态'
            END AS segmentCurrentCheck,
            margin_value marginValue
        from fhzg_limit_transfer_scheme_switching_loop_seg_current_detail
        where switching_id =#{switchingId}
				order by create_time desc, id desc
    </select>

</mapper>
