<?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.product.terminal.device.mapper.PqLineMapper">
  <resultMap id="BaseResultMap" type="com.njcn.product.terminal.oracleDevice.pojo.po.PqLine">
    <!--@mbg.generated-->
    <!--@Table PQ_LINE-->
    <id column="LINE_INDEX" jdbcType="DECIMAL" property="lineIndex" />
    <result column="GD_INDEX" jdbcType="DECIMAL" property="gdIndex" />
    <result column="SUB_INDEX" jdbcType="DECIMAL" property="subIndex" />
    <result column="SUBV_INDEX" jdbcType="DECIMAL" property="subvIndex" />
    <result column="DEV_INDEX" jdbcType="DECIMAL" property="devIndex" />
    <result column="NAME" jdbcType="VARCHAR" property="name" />
    <result column="PT1" jdbcType="FLOAT" property="pt1" />
    <result column="PT2" jdbcType="FLOAT" property="pt2" />
    <result column="CT1" jdbcType="FLOAT" property="ct1" />
    <result column="CT2" jdbcType="FLOAT" property="ct2" />
    <result column="DEVCMP" jdbcType="FLOAT" property="devcmp" />
    <result column="DLCMP" jdbcType="FLOAT" property="dlcmp" />
    <result column="JZCMP" jdbcType="FLOAT" property="jzcmp" />
    <result column="XYCMP" jdbcType="FLOAT" property="xycmp" />
    <result column="SUBV_NO" jdbcType="DECIMAL" property="subvNo" />
    <result column="SCALE" jdbcType="VARCHAR" property="scale" />
    <result column="SUBV_NAME" jdbcType="VARCHAR" property="subvName" />
  </resultMap>
  <sql id="Base_Column_List">
    <!--@mbg.generated-->
    LINE_INDEX, GD_INDEX, SUB_INDEX, SUBV_INDEX, DEV_INDEX, "NAME", PT1, PT2, CT1, CT2,
    DEVCMP, DLCMP, JZCMP, XYCMP, SUBV_NO, "SCALE", SUBV_NAME
  </sql>


  <select id="getBaseLineInfo" resultType="com.njcn.product.terminal.oracleDevice.pojo.dto.LedgerBaseInfoDTO">

      WITH temp AS(
      select PQ_USER_LINE_ASS.LINE_INDEX LINE_INDEX,listagg(PQ_USER_LEDGER.CUSTOMER_NAME,';')  within GROUP (order by PQ_USER_LEDGER.CUSTOMER_NAME) objName from PQ_USER_LINE_ASS  ,PQ_USER_LEDGER where PQ_USER_LINE_ASS.USER_INDEX=PQ_USER_LEDGER.ID group by PQ_USER_LINE_ASS.LINE_INDEX
      )
      select
      PQ_GDINFORMATION.name gdName,
      pq_line.GD_INDEX gdIndex,
      pq_line.line_index lineId,
      pq_line.name lineName,
      PQ_SUBVOLTAGE.SUBV_INDEX busBarId,
      PQ_SUBVOLTAGE.name busBarName,
      pq_device.dev_index devId,
      pq_device.name devName,
      pq_device.Status runFlag,
      PQ_SUBSTATION.sub_index stationId,
      PQ_SUBSTATION.name stationName,
      temp.objName  objName
      from
      pq_line LEFT JOIN PQ_SUBVOLTAGE on pq_line.SUBV_INDEX = PQ_SUBVOLTAGE.SUBV_INDEX
      LEFT JOIN
      pq_device on PQ_SUBVOLTAGE.DEV_INDEX = pq_device.DEV_INDEX
      LEFT JOIN PQ_SUBSTATION on pq_device.SUB_INDEX = PQ_SUBSTATION.SUB_INDEX
      LEFT JOIN PQ_GDINFORMATION on pq_line.GD_INDEX =PQ_GDINFORMATION.GD_INDEX
      LEFT JOIN temp on temp.LINE_INDEX = pq_line.LINE_INDEX
where 1=1
      and pq_line.line_index in
    <foreach collection="ids" item="item" open="(" close=")" separator=",">
        #{item}
    </foreach>
  </select>


    <select id="getBaseLedger" resultType="com.njcn.product.terminal.oracleDevice.pojo.dto.LedgerBaseInfoDTO">
        select
        PQ_GDINFORMATION.name gdName,
        pq_line.GD_INDEX gdIndex,
        pq_line.line_index lineId,
        pq_line.name lineName,
        PQ_SUBVOLTAGE.SUBV_INDEX busBarId,
        PQ_SUBVOLTAGE.name busBarName,
        pq_device.dev_index devId,
        pq_device.name devName,
        pq_device.Status runFlag,
        PQ_SUBSTATION.sub_index stationId,
        PQ_SUBSTATION.name stationName
        from
        pq_line inner JOIN PQ_SUBVOLTAGE on pq_line.SUBV_INDEX = PQ_SUBVOLTAGE.SUBV_INDEX
        inner JOIN pq_device on PQ_SUBVOLTAGE.DEV_INDEX = pq_device.DEV_INDEX
        inner JOIN PQ_SUBSTATION on pq_device.SUB_INDEX = PQ_SUBSTATION.SUB_INDEX
        inner JOIN PQ_GDINFORMATION on pq_line.GD_INDEX =PQ_GDINFORMATION.GD_INDEX
        <where>
        and pq_line.line_index in
        <foreach collection="ids" item="item" open="(" close=")" separator=",">
            #{item}
        </foreach>
            <if test="searchValue!=null and searchValue!=''">
                and (
                PQ_GDINFORMATION.name  LIKE '%' || #{searchValue} || '%'
                or PQ_SUBSTATION.name  LIKE '%' || #{searchValue} || '%'
                or pq_line.name  LIKE '%' || #{searchValue} || '%'
                )
            </if>
        </where>
    </select>

    <select id="getRunMonitorIds" resultType="integer">
        select DISTINCT pq_line.line_index from pq_line inner join pq_device on pq_line.DEV_INDEX = pq_device.DEV_INDEX
        where pq_line.line_index in
        <foreach collection="ids" item="item" open="(" close=")" separator=",">
            #{item}
        </foreach>
        and pq_device.DEVFLAG = 0
    </select>


</mapper>
