<?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.mysqlTerminal.mapper.LedgerScaleMapper">


    <select id="getBaseInfo" resultType="com.njcn.product.terminal.mysqlTerminal.pojo.dto.LedgerBaseInfo">
        select
        point.id lineId,
        point.name lineName,
        detail.obj_name
        from pq_line point
        inner join pq_line_detail detail on point.id = detail.id
        where point.id in
        <foreach collection="lineIds" item="item" open="(" close=")" separator=",">
            #{item}
        </foreach>
    </select>

    <select id="getLedgerBaseInfo" resultType="com.njcn.product.terminal.mysqlTerminal.pojo.dto.LedgerBaseInfo">
        select
        point.id lineId,
        point.name lineName,
        voltage.id busBarId,
        voltage.name busBarName,
        dev.id devId,
        dev.name devName,
        device.com_flag,
        device.run_flag,
        device.ip,
        station.id stationId,
        station.name stationName,
        gd.id gdId,
        gd.name gdName,
        detail.num,
        detail.ct1,
        detail.ct2,
        detail.pt1,
        detail.pt2,
        detail.PT_Type ptType,
        detail.Time_Interval,
        users.project_name objName,
        busBar.scale voltageLevel
        from pq_line point
        inner join pq_line_detail detail on point.id = detail.id
        inner join pq_line voltage on point.pid = voltage.id
        inner join pq_voltage busBar on voltage.id = busBar.id
        inner join pq_line dev on voltage.pid = dev.id
        inner join pq_device device on dev.id = device.id
        inner join pq_line station on dev.pid = station.id
        inner join pq_line gd on station.pid = gd.id
        LEFT JOIN supervision_user_report users ON users.id = detail.obj_id
        where point.id in
        <foreach collection="lineIds" item="item" open="(" close=")" separator=",">
            #{item}
        </foreach>
        order by station.name,dev.name,point.name
    </select>


    <select id="getQueryLedger" resultType="string">
        select
        distinct point.id lineId
        from pq_line point
        inner join pq_line_detail detail on point.id = detail.id
        inner join pq_line voltage on point.pid = voltage.id
        inner join pq_voltage busBar on voltage.id = busBar.id
        inner join pq_line dev on voltage.pid = dev.id
        inner join pq_device device on dev.id = device.id
        inner join pq_line station on dev.pid = station.id
        inner join pq_line gd on station.pid = gd.id
        LEFT JOIN supervision_user_report users ON users.id = detail.obj_id
        where point.id in
        <foreach collection="lineIds" item="item" open="(" close=")" separator=",">
            #{item}
        </foreach>
        <if test="searchValue!=null and searchValue!=''">
            and (point.name like CONCAT('%', #{searchValue}, '%')
            or station.name like CONCAT('%', #{searchValue}, '%')
            or gd.name like CONCAT('%', #{searchValue}, '%')
            or users.project_name like CONCAT('%', #{searchValue}, '%'))
        </if>
    </select>

</mapper>

