<?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.PqDeviceMapper">
  <resultMap id="BaseResultMap" type="com.njcn.product.terminal.oracleDevice.pojo.po.PqDevice">
    <!--@mbg.generated-->
    <!--@Table PQ_DEVICE-->
    <id column="DEV_INDEX" jdbcType="DECIMAL" property="devIndex" />
    <result column="GD_INDEX" jdbcType="DECIMAL" property="gdIndex" />
    <result column="SUB_INDEX" jdbcType="DECIMAL" property="subIndex" />
    <result column="NAME" jdbcType="VARCHAR" property="name" />
    <result column="STATUS" jdbcType="DECIMAL" property="status" />
    <result column="DEVTYPE" jdbcType="VARCHAR" property="devtype" />
    <result column="LOGONTIME" jdbcType="TIMESTAMP" property="logontime" />
    <result column="UPDATETIME" jdbcType="TIMESTAMP" property="updatetime" />
    <result column="NODE_INDEX" jdbcType="DECIMAL" property="nodeIndex" />
    <result column="PORTID" jdbcType="DECIMAL" property="portid" />
    <result column="DEVFLAG" jdbcType="DECIMAL" property="devflag" />
    <result column="DEV_SERIES" jdbcType="VARCHAR" property="devSeries" />
    <result column="DEV_KEY" jdbcType="VARCHAR" property="devKey" />
    <result column="IP" jdbcType="VARCHAR" property="ip" />
    <result column="DEVMODEL" jdbcType="DECIMAL" property="devmodel" />
    <result column="CALLFLAG" jdbcType="DECIMAL" property="callflag" />
    <result column="DATATYPE" jdbcType="DECIMAL" property="datatype" />
  </resultMap>
  <sql id="Base_Column_List">
    <!--@mbg.generated-->
    DEV_INDEX, GD_INDEX, SUB_INDEX, "NAME", "STATUS", DEVTYPE, LOGONTIME, UPDATETIME,
    NODE_INDEX, PORTID, DEVFLAG, DEV_SERIES, DEV_KEY, IP, DEVMODEL, CALLFLAG, DATATYPE
  </sql>

  <select id="queryListByIds" resultType="com.njcn.product.terminal.oracleDevice.pojo.dto.DeviceDTO">
    select
    pq_device.dev_index devId,
    pq_device.name devName,
    pq_device.UpdateTime updateTime,
    pq_device.DevFlag devFlag,
    pq_device.IP ip,
    pq_device.status status,
    PQ_SUBSTATION.sub_index stationId,
    PQ_SUBSTATION.name stationName,
    PQ_GDINFORMATION.Name gdName
    from
    pq_device,
    PQ_SUBSTATION,
    PQ_GDINFORMATION
    where
     pq_device.SUB_INDEX = PQ_SUBSTATION.SUB_INDEX
    and pq_device.GD_INDEX =PQ_GDINFORMATION.GD_INDEX
    and pq_device.DEV_INDEX in
    <foreach collection="ids" item="item" open="(" close=")" separator=",">
      #{item}
    </foreach>
  </select>

  <select id="selectDeviceDTOPage" resultType="com.njcn.product.terminal.oracleDevice.pojo.dto.DeviceDTO">

    SELECT  DISTINCT
    pq_device.dev_index devId,
    pq_device.name devName,
    pq_device.UpdateTime updateTime,
    pq_device.DevFlag devFlag,
    pq_device.IP ip,
    pq_device.status status,
    PQ_DEVICEDETAIL.ThisTimeCheck thisTimeCheck,
    PQ_DEVICEDETAIL.NextTimeCheck nextTimeCheck,
    pq_device.LogonTime logonTime,
    PQ_DEVICEDETAIL.MANUFACTURER
    FROM
    pq_device
    inner JOIN PQ_DEVICEDETAIL ON PQ_DEVICEDETAIL.dev_index = pq_device.dev_index
    <where>
    pq_device.DEV_INDEX in
    <foreach collection="devIndexs" item="item" open="(" close=")" separator=",">
      #{item}
    </foreach>
    order by pq_device.updatetime
    </where>
  </select>

<!--  <select id="selectDeviceDTOPage" resultType="com.njcn.product.event.devcie.pojo.dto.DeviceDTO">-->
<!--    WITH temp AS(-->
<!--    SELECT DISTINCT-->
<!--    PQ_LINE.DEV_INDEX,-->
<!--    PQS_DEPTS.DEPTSNAME-->
<!--    FROM-->
<!--    PQ_LINE,-->
<!--    PQS_DEPTSLINE,-->
<!--    PQS_DEPTS-->
<!--    WHERE-->
<!--    PQ_LINE.LINE_INDEX = PQS_DEPTSLINE.LINE_INDEX-->
<!--    AND PQS_DEPTS.DEPTS_INDEX = PQS_DEPTSLINE.DEPTS_INDEX-->
<!--    )-->
<!--    SELECT  DISTINCT-->
<!--    pq_device.dev_index devId,-->
<!--    pq_device.name devName,-->
<!--    pq_device.UpdateTime updateTime,-->
<!--    pq_device.DevFlag devFlag,-->
<!--    pq_device.IP ip,-->
<!--    pq_device.status status,-->
<!--    PQ_SUBSTATION.sub_index stationId,-->
<!--    PQ_SUBSTATION.name stationName,-->
<!--    PQ_GDINFORMATION.Name gdName,-->
<!--    PQS_DICDATA.DIC_Name MANUFACTURER_Name,-->
<!--    PQ_DEVICEDETAIL.ThisTimeCheck thisTimeCheck,-->
<!--    PQ_DEVICEDETAIL.NextTimeCheck nextTimeCheck,-->
<!--    pq_device.LogonTime logonTime,-->
<!--    temp.DEPTSNAME deptName-->
<!--    FROM-->
<!--    pq_device-->
<!--    LEFT JOIN PQ_SUBSTATION ON pq_device.SUB_INDEX = PQ_SUBSTATION.SUB_INDEX-->
<!--    LEFT JOIN PQ_GDINFORMATION ON pq_device.GD_INDEX = PQ_GDINFORMATION.GD_INDEX-->
<!--    LEFT JOIN PQ_DEVICEDETAIL ON PQ_DEVICEDETAIL.dev_index = pq_device.dev_index-->
<!--    LEFT JOIN PQS_DICDATA on  PQ_DEVICEDETAIL.MANUFACTURER = PQS_DICDATA.DIC_INDEX-->
<!--    LEFT JOIN temp on temp.DEV_INDEX = pq_device.dev_index-->
<!--    where 1=1-->
<!--    <if test="searchValue!= null and searchValue!= ''">-->
<!--      AND (-->
<!--      pq_device.name LIKE '%' || #{searchValue} || '%'-->
<!--      OR PQ_SUBSTATION.name LIKE '%' || #{searchValue} || '%'-->
<!--      OR PQ_GDINFORMATION.Name LIKE '%' || #{searchValue} || '%'-->
<!--      )-->
<!--    </if>-->
<!--    <if test="state!= null and state!= ''">-->
<!--      and pq_device.status = #{state}-->
<!--    </if>-->
<!--    and pq_device.DEV_INDEX in-->
<!--    <foreach collection="devIndexs" item="item" open="(" close=")" separator=",">-->
<!--      #{item}-->
<!--    </foreach>-->
<!--    order by pq_device.updatetime-->
<!--  </select>-->



</mapper>
