<?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.si.dao.FhzgDeviceTypeMapper">

    <select id="getPsrType" resultType="java.lang.String">
        SELECT CASE
                   WHEN
                       a.is_start_kg = 0 OR a.is_start_kg IS NULL THEN
                       b.lc_yc_type
                   WHEN a.is_start_kg = 1 THEN
                       b.lc_yc_zw_type
                   ELSE NULL
                   END AS type
        FROM `t_feeder_topo` a
                 LEFT JOIN fhzg_device_type_mapping b ON a.psr_type = b.topo_psr_type
        WHERE a.psr_id = #{psrId}
        ORDER BY a.id DESC LIMIT 1
    </select>
    <select id="getPsrTypeByFeeder" resultType="java.lang.String">
        SELECT DISTINCT(b.lc_yc_zw_type)
        FROM t_feeder_topo a
                 Right JOIN fhzg_device_type_mapping b ON a.psr_type = b.topo_psr_type
        WHERE a.feeder = #{psrId}
          AND a.is_start_kg = '1'
    </select>
    <select id="getPsrIdByFeeder" resultType="java.lang.String">
        SELECT a.psr_id
        FROM t_feeder_topo a
        WHERE a.feeder = #{psrId}
          AND a.is_start_kg = '1'
    </select>
    <select id="getPsrIdByFeederSe" resultType="java.lang.String">
        SELECT a.psr_id
        FROM t_feeder_topo a
        WHERE a.feeder = #{psrId}
          AND a.psr_type = 'PD_31100000'
          and a.sszf_type = 'PD_30000000'
    </select>
    <select id="getPsrTypeByFeederSe" resultType="java.lang.String">
        SELECT DISTINCT(b.lc_yc_zw_type)
        FROM t_feeder_topo a
                 Right JOIN fhzg_device_type_mapping b ON a.psr_type = b.topo_psr_type
        WHERE a.psr_id in( SELECT distinct a.psr_id
                           FROM t_feeder_topo a
                           WHERE a.feeder = #{psrId}
                             AND a.psr_type = 'PD_31100000'
                             and a.sszf_type = 'PD_30000000')
    </select>
</mapper>
