<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
<mapper namespace="com.tofly.xrtygis.custom.mapper.TableCountMapper">

    <select id="getPartition" resultType="map">
        select id, dma_name, partition_level, sum(in_num) in_num, sum(out_num) out_num
        from (select a.id,
                     a.dma_name,
                     partition_level,
                     decode(isout, 0, count(0), 0) in_num,
                     decode(isout, 1, count(0), 0) out_num
              from tf_ywpn_dmaregion_w a,
                   tf_ywpn_dmaandobser_w b
              where a.id = b.dma_id
              group by a.id, dma_name, isout, partition_level
             ) t
        group by id, dma_name, partition_level
        order by partition_level
    </select>

    <select id="getPartitionInfo" resultType="map">
        select c.DMA_NAME,
               decode(b.ISOUT, '0', '入口', '1', '出口') ISOUT,
               d.CODE,
               d.NAME,
               d.MANUFACTURER,
               d.MODEL_SPECIFICATION,
               a.BORE
        from TF_YWPN_DMATABLE_W a
        LEFT JOIN tf_ywpn_dmaandobser_w b ON a.ID = b.TABLE_ID
        LEFT JOIN tf_ywpn_dmaregion_w c ON b.DMA_ID = c.ID
        LEFT JOIN TF_DEVICE_ARCHIVE_MANAGE d ON a.DEVICE_ID = d.ID
        where
            1=1
        <if test="dmaId != null">
            and b.dma_id = #{dmaId}
        </if>
        order by isout
    </select>

    <select id="viewPartitionInfo" resultType="map">
        select c.DMA_NAME,
               decode(b.ISOUT, '0', '入口', '1', '出口') ISOUT,
               d.CODE,
               d.NAME,
               d.MANUFACTURER,
               d.MODEL_SPECIFICATION,
               a.BORE
        from TF_YWPN_DMATABLE_W a
        LEFT JOIN tf_ywpn_dmaandobser_w b ON a.ID = b.TABLE_ID
        LEFT JOIN tf_ywpn_dmaregion_w c ON b.DMA_ID = c.ID
        LEFT JOIN TF_DEVICE_ARCHIVE_MANAGE d ON a.DEVICE_ID = d.ID
        where
            1=1
        <if test="dmaId != null">
            and b.dma_id = #{dmaId}
        </if>
        order by isout
    </select>

</mapper>