<?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="net.northking.cctp.device.db.dao.CdDeviceCtrlDao">
  <resultMap id="DetailMap" type="net.northking.cctp.device.dto.ctrl.CdDeviceCtrlDetailDto">
    <!-- 主键id -->
    <id column="id" jdbcType="VARCHAR" property="id"/>
    <!-- 上位机名称 -->
    <result column="ctrl_name" jdbcType="VARCHAR" property="ctrlName"/>
    <!-- 上位机ip -->
    <result column="ctrl_ip" jdbcType="VARCHAR" property="ctrlIp"/>
    <!-- 上位机位置 -->
    <result column="ctrl_addr" jdbcType="VARCHAR" property="ctrlAddr"/>
    <!-- 上位机端口 -->
    <result column="ctrl_port" jdbcType="INTEGER" property="ctrlPort"/>
    <!-- appium端口 -->
    <result column="appium_port" jdbcType="INTEGER" property="appiumPort"/>
    <!-- 上位机状态 -->
    <result column="ctrl_status" jdbcType="VARCHAR" property="ctrlStatus"/>
    <!-- 接入设备上限 -->
    <result column="ctrl_up_limit" jdbcType="INTEGER" property="ctrlUpLimit"/>
    <!-- 备注 -->
    <result column="remark" jdbcType="VARCHAR" property="remark"/>
    <!-- 注册时间 -->
    <result column="created_time" jdbcType="TIMESTAMP" property="createdTime"/>
    <!-- 更新人 -->
    <result column="updated_by" jdbcType="VARCHAR" property="updatedBy"/>
    <!-- 更新时间 -->
    <result column="updated_time" jdbcType="TIMESTAMP" property="updatedTime"/>
  </resultMap>

  <select id="pagingQuery" resultMap="DetailMap" parameterType="net.northking.cctp.device.db.entity.CdDeviceCtrl">
    select
    cdc.id
    ,cdc.ctrl_name
    ,cdc.ctrl_ip
    ,cdc.ctrl_addr
    ,cdc.ctrl_port
    ,cdc.appium_port
    ,cdc.ctrl_status
    ,cdc.ctrl_up_limit
    ,cdc.remark
    ,cdc.created_time
    ,cdc.updated_by
    ,cdc.updated_time
    ,cdm.onlineNum
    from
    <include refid="Table_Name"/>
    cdc
    LEFT JOIN (
    SELECT ctrl_id,COUNT(ctrl_id) AS onlineNum
    FROM cd_mobile_device
    GROUP BY ctrl_id) cdm ON cdc.id  = cdm.ctrl_id
    <trim prefix="WHERE" prefixOverrides="AND" >
      <if test="id != null">
        AND cdc.id = #{id,jdbcType=VARCHAR}
      </if>
      <if test="ctrlName != null">
        AND cdc.ctrl_name = #{ctrlName,jdbcType=VARCHAR}
      </if>
      <if test="ctrlIp != null">
        AND cdc.ctrl_ip = #{ctrlIp,jdbcType=VARCHAR}
      </if>
      <if test="ctrlAddr != null">
        AND cdc.ctrl_addr = #{ctrlAddr,jdbcType=VARCHAR}
      </if>
      <if test="ctrlStatus != null">
        AND cdc.ctrl_status = #{ctrlStatus,jdbcType=VARCHAR}
      </if>
      <if test="ctrlUpLimit != null">
        AND cdc.ctrl_up_limit = #{ctrlUpLimit,jdbcType=INTEGER}
      </if>
      <if test="remark != null">
        AND cdc.remark = #{remark,jdbcType=VARCHAR}
      </if>
      <if test="createdTime != null">
        AND cdc.created_time = #{createdTime,jdbcType=TIMESTAMP}
      </if>
      <if test="updatedBy != null">
        AND cdc.updated_by = #{updatedBy,jdbcType=VARCHAR}
      </if>
      <if test="updatedTime != null">
        AND cdc.updated_time = #{updatedTime,jdbcType=TIMESTAMP}
      </if>
    </trim>
    order by cdc.created_time desc
  </select>


  <select id="queryCtrlOffLive" resultType="string">
    select id
    from
    <include refid="Table_Name"/>
    where ctrl_status in ('1','2');
  </select>

  <!-- 请在本文件内添加自定义SQL语句 -->
</mapper>