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


    <select id="getTerminalVersionInfo" resultType="TerminalVersionVO">
        SELECT
        a.id,
        a.pid,
        a.NAME,
        a.LEVEL,
        b.run_flag,
        b.com_flag,
        c.NAME devType,
        ifnull(e.NAME,'/') versionName,
        ifnull(e.protocol,'/') protocol,
        ifnull(e.date,'/') versionDate,
        ifnull(e.update_time,'/') updateTime,
        ifnull(e.update_by,'/') updateBy
        FROM
        pq_line a
        INNER JOIN pq_device b ON a.id = b.id
        LEFT JOIN sys_dict_data c ON b.dev_type = c.id
        LEFT JOIN cld_dev_version d ON b.id = d.Line_Id and d.flag = 1 and d.Result = 1
        LEFT JOIN cld_version e ON d.Version_Id = e.id
        LEFT JOIN sys_user f on d.update_by = f.id
        WHERE
        b.dev_model = 1
        <if test="queryParam.runFlag!=null">
            and b.run_flag = #{queryParam.runFlag}
        </if>
        <if test="queryParam.comFlag!=null">
            and b.com_flag = #{queryParam.comFlag}
        </if>
        <if test="queryParam.devType!=null and queryParam.devType!=''">
            and b.dev_type = #{queryParam.devType}
        </if>

    </select>

    <select id="getGdAndSubList" resultType="TerminalVersionVO">
        select id,name,level,pid from pq_line where level = #{level} and state = 1 order by sort
    </select>

    <select id="getProvList" resultType="TerminalVersionVO">
        select a.id,b.name,a.level,a.pid from pq_line a
        inner join sys_area b on a.name = b.id
        where a.level = 1
        and a.state = 1
        order by a.sort
    </select>

    <select id="getPqLineProvList" resultType="TerminalVersionVO">
        select a.id,b.name,a.level,a.pid from pq_line a
        inner join sys_area b on a.name = b.id
        where a.level = 1
        and a.id in
        <foreach collection="ids" item="item" open="(" close=")" separator=",">
            #{item}
        </foreach>
        order by a.sort
    </select>

    <select id="getPqLineGdAndSubList" resultType="TerminalVersionVO">
        select a.id,a.name,a.level,a.pid from pq_line a
        where a.id in
        <foreach collection="ids" item="item" open="(" close=")" separator=",">
            #{item}
        </foreach>
        order by a.sort
    </select>

</mapper>
