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

    <resultMap id="BaseResultMap" type="com.hdkj.lt.core.bizms.modle.po.voltageLimitViolation.FhzgLimitTransferSchemeSwitchingFinalSegCurrentDetail">
            <id property="id" column="id" jdbcType="BIGINT"/>
            <result property="switchingId" column="switching_id" jdbcType="BIGINT"/>
            <result property="segmentId" column="segment_id" jdbcType="VARCHAR"/>
            <result property="segmentName" column="segment_name" jdbcType="VARCHAR"/>
            <result property="lineId" column="line_id" jdbcType="VARCHAR"/>
            <result property="lineName" column="line_name" jdbcType="VARCHAR"/>
            <result property="segmentRatedAmpacity" column="segment_rated_ampacity" jdbcType="VARCHAR"/>
            <result property="preLoopCloseCurrent" column="pre_loop_close_current" jdbcType="VARCHAR"/>
            <result property="loopOpenCurrent" column="loop_open_current" jdbcType="VARCHAR"/>
            <result property="currentThreshold" column="current_threshold" jdbcType="VARCHAR"/>
            <result property="segmentCurrentCheck" column="segment_current_check" jdbcType="VARCHAR"/>
            <result property="creator" column="creator" jdbcType="BIGINT"/>
            <result property="createTime" column="create_time" jdbcType="TIMESTAMP"/>
            <result property="lastEditor" column="last_editor" jdbcType="BIGINT"/>
            <result property="lastTime" column="last_time" jdbcType="TIMESTAMP"/>
            <result property="ratedI" column="rated_i" jdbcType="VARCHAR"/>
            <result property="maxAfter24hI" column="max_after24h_i" jdbcType="VARCHAR"/>
            <result property="marginValue" column="margin_value" jdbcType="VARCHAR"/>
    </resultMap>

    <select id="getTransferSchemeFinalSegmentCurrentDetailByIdPage" resultType="com.hdkj.lt.bf.entity.dto.FhzgLimitTransferSchemeFinalSegmentCurrentDetailDTO">
        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_limit_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="getLimitInfoBySwitchingId"
            resultType="com.hdkj.lt.core.bizms.modle.po.voltageLimitViolation.FhzgVoltageLimitViolationPowerCut">
        select a.limit_no, a.line_name
        from fhzg_voltage_limit_violation_power_cut a
                 join fhzg_info_limit_transfer_scheme b on a.id = b.limit_id
                 join fhzg_info_limit_transfer_scheme_switching_sequence c on b.id = c.scheme_id
        where c.id = #{switchingId} LIMIT 1
    </select>
    <select id="getPlanInfoBySwitchingId" 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_limit_transfer_scheme_switching_final_seg_current_detail fscd
        WHERE
            fscd.switching_id = #{switchingId}
        ORDER BY
            fscd.create_time DESC, fscd.id DESC
    </select>


</mapper>
