<?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.device.pq.mapper.PqsDeviceUnitMapper">

    <select id="deviceUnitList" resultType="com.njcn.device.pq.pojo.vo.PqsDeviceUnitVo$DeviceUnit">
        SELECT
            dev.id as  id,
            dev.pid as pid,
            dev.NAME as `name`,
            pd.Run_Flag as devFlag,
            b.*
        FROM
            pq_line dev
        INNER JOIN pq_device pd ON dev.id = pd.id and dev.State = 1
        LEFT JOIN pqs_device_unit b ON dev.id = b.dev_index
        <where>
            <if test="devFlag!=null and devFlag!='' ">
                pd.Run_Flag = #{devFlag}
            </if>
        </where>
    </select>
    <select id="deviceUnitByID" resultType="com.njcn.device.biz.pojo.po.PqsDeviceUnit">
        SELECT
            unit.*
        FROM
            pq_line line
        INNER JOIN pq_line vo ON vo.id = line.pid
        INNER JOIN pq_line dev ON dev.id = vo.pid
        INNER JOIN pq_device pd ON pd.id = dev.id
        LEFT JOIN pqs_device_unit unit ON unit.DEV_INDEX = dev.id
        <where>
            line.State = 1
            <if test="ids!=null and ids!='' ">
              and  line.id = #{ids}
            </if>
        </where>
    </select>

</mapper>
