<?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.FhzgPlanTransferSchemeFinalSegmentCurrentDetailMapper">


    <select id="getTransferSchemeFinalSegmentCurrentDetailByIdPage"
            resultType="com.hdkj.lt.bf.entity.dto.FhzgPlanTransferSchemeFinalSegmentCurrentDetailDTO">
        SELECT distinct
            fscd.id id,
            fscd.switching_id switchingId,
            fscd.segment_id segmentId,
            fscd.segment_name segmentName,
            fscd.line_id lineId,
            fscd.line_name lineName,
            fscd.segment_rated_ampacity segmentRatedAmpacity,
            fscd.pre_loop_close_current preLoopCloseCurrent,
            fscd.loop_open_current loopOpenCurrent,
            fscd.current_threshold currentThreshold,
            fscd.segment_current_check segmentCurrentCheck,
            fscd.rated_i ratedI,
            fscd.max_after24h_i maxAfter24hI,
            fscd.margin_value marginValue,
            tft.rdf_id rdfId,
            fscd.create_time
        FROM
            fhzg_plan_transfer_scheme_switching_final_seg_current_detail fscd
        LEFT JOIN t_feeder_topo tft on fscd.segment_id = tft.psr_id
        WHERE
            fscd.switching_id = #{switchingId}
        order by fscd.create_time desc

    </select>

    <select id="getListBySwitchingId" resultType="java.util.Map">
        SELECT ROW_NUMBER() over() rowNum,
	fscd.id id,
	fscd.switching_id switchingId,
	fscd.segment_id segmentId,
	fscd.segment_name segmentName,
	fscd.line_id lineId,
	fscd.line_name lineName,
	fscd.segment_rated_ampacity segmentRatedAmpacity,
	fscd.pre_loop_close_current preLoopCloseCurrent,
	fscd.loop_open_current loopOpenCurrent,
	fscd.current_threshold currentThreshold,
    CASE
		fscd.segment_current_check
		WHEN '0' THEN
		'不通过'
		WHEN '1' THEN
		'通过' ELSE '未知状态'
        END
        AS segmentCurrentCheck,fscd.rated_i ratedI,
	fscd.max_after24h_i maxAfter24hI,
    fscd.margin_value marginValue
    FROM
	fhzg_plan_transfer_scheme_switching_final_seg_current_detail fscd
    WHERE
        fscd.switching_id = #{switchingId}
    ORDER BY
        fscd.create_time DESC, fscd.id DESC
    </select>

    <select id="getPlanInfoBySwitchingId" resultType="com.hdkj.lt.bf.entity.FhzgPlanPowerCut">
        select a.plan_no, a.line_name
        from fhzg_plan_power_cut a
                 join fhzg_plan_transfer_scheme b on a.id = b.plan_id
                 join fhzg_plan_transfer_scheme_switching_sequence c on b.id = c.scheme_id
        where c.id = #{switchingId} LIMIT 1
    </select>

</mapper>
