<?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.njcn.mapper.point.PointBaseInfoMapper">
    <select id="getPointInfo" resultType="PointInfo">
        SELECT
            a.pt1      pt1,
            a.pt2      pt2,
            a.ct1      ct1,
            a.ct2      ct2,
            a.devcmp   devcmp,
            a.dlcmp    dlcmp,
            a.jzcmp    jzcmp,
            a.xycmp    xycmp,
            b.dic_name voltageClasses,
			d.dic_name devType
        FROM pq_line a
				inner join pqs_dicdata b on b.dic_index = a.scale
				inner join pq_device c on a.dev_index = c.dev_index
				inner join pqs_dicdata d on c.devtype=d.dic_index
        WHERE a.line_index = #{pointIndex}
    </select>

    <select id="getInfo" resultType="PointInfo">
        select a.name, b.name pName, c.name bdName
          from pq_line a, pq_subvoltage b, pq_substation c
         where a.line_index = #{lineId}
           and a.subv_index = b.subv_index
           and a.sub_index = c.sub_index
    </select>

    <select id="getFlowInfo" resultType="PointInfo">
		SELECT nvl(fm.fm_number,
		nvl((select FM_NUMBER
		from PQS_FLOWMEAL
		where type = 0
		and SECOND_TYPE = 0),
		0)) as baseFlow,
		nvl(fm2.fm_number, 0) as extendFlow,
		nvl((SELECT af.actualflow
		FROM PQS_MONTHFLOW af
		WHERE af.DEV_INDEX = pq.DEV_INDEX
		and to_char(af.timeid, 'yyyy-MM') =
		to_char(sysdate, 'yyyy-MM')),
		0) / nullif(((nvl(fm.fm_number,
		nvl((select FM_NUMBER
		from PQS_FLOWMEAL
		where type = 0
		and SECOND_TYPE = 0),
		0))) + (nvl(fm2.fm_number, 0))) * 1024 * 1024,
		0) as useFlow
		FROM PQ_DEVICE pq
		left join PQS_DEVEDASS ded
		on pq.DEV_INDEX = ded.DEV_INDEX
		and ded.STATE = 1
		and ded.UPDATERESULT = 1
		left join PQS_EDDATA ed
		on ded.ED_INDEX = ed.ED_INDEX
		left join PQS_DEVFMASS dm
		on pq.DEV_INDEX = dm.DEV_INDEX
		left join PQS_FLOWMEAL fm
		on dm.FM_BASE_INDEX = fm.FM_INDEX
		left join PQS_FLOWMEAL fm2
		on dm.FM_REAM_INDEX = fm2.FM_INDEX
		WHERE pq.DEVMODEL = 1
		and pq.dev_index =
		(select dev_index from pq_line where line_index = #{pointIndex})
	</select>
</mapper>