<?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">
<!--  Copyright (c) 京北方信息技术股份有限公司 Corporation 2022 . All rights reserved. -->
<!--  文件内容由代码生成器产生，请不要手动修改！ -->
<!--  version: 1.0  -->
<!--  author:  maven-cctp-plugin    -->
<!--  date:  2022-09-21 14:45:06  -->
<mapper namespace="net.northking.cctp.device.db.dao.CdDeviceStatusDao">
  <resultMap id="BaseResultMap" type="net.northking.cctp.device.db.entity.CdDeviceStatus">
      <!-- 主键id(设备id) -->
    <id column="id" jdbcType="VARCHAR" property="id"/>
                    <!-- 设备类型(1-移动 2-PC) -->
    <result column="device_type" jdbcType="VARCHAR" property="deviceType"/>
        <!-- 使用状态(1-空闲 2-使用中) -->
    <result column="usage_status" jdbcType="VARCHAR" property="usageStatus"/>
        <!-- 设备状态(1-在线 2-离线 3-移除) -->
    <result column="device_status" jdbcType="VARCHAR" property="deviceStatus"/>
        <!-- 最近心跳时间 -->
    <result column="last_heartbeat_time" jdbcType="TIMESTAMP" property="lastHeartbeatTime"/>
    </resultMap>

  <sql id="Base_Column_List">
    id
    ,device_type
    ,usage_status
    ,device_status
    ,last_heartbeat_time
  </sql>

  <sql id="Table_Name">
    ${defaultSchema}.cd_device_status
  </sql>

  <select id="findByPrimaryKey" parameterType="String" resultMap="BaseResultMap">
    select
    <include refid="Base_Column_List"/>
    from
    <include refid="Table_Name"/>
    where id = #{id,jdbcType=VARCHAR}
  </select>

  <select id="findByPrimaryKeys" parameterType="java.util.List" resultMap="BaseResultMap">
    select
    <include refid="Base_Column_List"/>
    from
    <include refid="Table_Name"/>
    where id in
    <foreach collection="list" item="idItem" open="(" separator="," close=")">
      #{idItem, jdbcType=VARCHAR}
    </foreach>
  </select>

  <delete id="deleteByPrimaryKey" parameterType="String">
    delete from
    <include refid="Table_Name"/>
    where id = #{id,jdbcType=VARCHAR}
  </delete>

  <delete id="deleteByPrimaryKeys" parameterType="String">
    delete from
    <include refid="Table_Name"/>
    where id in
    <foreach collection="list" item="idItem" open="(" separator="," close=")">
      #{idItem, jdbcType=VARCHAR}
    </foreach>
  </delete>

  <delete id="deleteByExample" parameterType="net.northking.cctp.device.db.entity.CdDeviceStatus">
    delete from
    <include refid="Table_Name"/>
    <trim prefix="WHERE" prefixOverrides="AND" >
      <choose>
        <when test="id != null">
          id = #{id,jdbcType=VARCHAR}
        </when>
      </choose>
              <if test="id != null">
          AND id=#{id,jdbcType=VARCHAR}
        </if>
              <if test="deviceType != null">
          AND device_type=#{deviceType,jdbcType=VARCHAR}
        </if>
              <if test="usageStatus != null">
          AND usage_status=#{usageStatus,jdbcType=VARCHAR}
        </if>
              <if test="deviceStatus != null">
          AND device_status=#{deviceStatus,jdbcType=VARCHAR}
        </if>
              <if test="lastHeartbeatTime != null">
          AND last_heartbeat_time=#{lastHeartbeatTime,jdbcType=TIMESTAMP}
        </if>
          </trim>
  </delete>

  <insert id="insert" parameterType="net.northking.cctp.device.db.entity.CdDeviceStatus">
    insert into
    <include refid="Table_Name"/>
    <trim prefix="(" suffix=")" suffixOverrides=",">
      <if test="id != null">
        id,
      </if>
      <if test="deviceType != null">
        device_type,
      </if>
      <if test="usageStatus != null">
        usage_status,
      </if>
      <if test="deviceStatus != null">
        device_status,
      </if>
      <if test="lastHeartbeatTime != null">
        last_heartbeat_time,
      </if>
    </trim>
    <trim prefix="values (" suffix=")" suffixOverrides=",">
      <if test="id != null">
          #{id, jdbcType=VARCHAR},
      </if>
      <if test="deviceType != null">
          #{deviceType, jdbcType=VARCHAR},
      </if>
      <if test="usageStatus != null">
          #{usageStatus, jdbcType=VARCHAR},
      </if>
      <if test="deviceStatus != null">
          #{deviceStatus, jdbcType=VARCHAR},
      </if>
      <if test="lastHeartbeatTime != null">
          #{lastHeartbeatTime, jdbcType=TIMESTAMP},
      </if>
    </trim>
  </insert>

  <insert id="insertByBatch" parameterType="java.util.List">
    insert into
    <include refid="Table_Name"/>
    <trim prefix="(" suffix=")" suffixOverrides=",">
    id,
    device_type,
    usage_status,
    device_status,
    last_heartbeat_time,
    </trim>
    values
    <foreach collection="list" item="item" index="index" separator=",">
      <trim prefix="(" suffix=")" suffixOverrides=",">
    #{item.id, jdbcType=VARCHAR},
    #{item.deviceType, jdbcType=VARCHAR},
    #{item.usageStatus, jdbcType=VARCHAR},
    #{item.deviceStatus, jdbcType=VARCHAR},
    #{item.lastHeartbeatTime, jdbcType=TIMESTAMP},
      </trim>
    </foreach>
  </insert>

  <update id="updateByPrimaryKey" parameterType="net.northking.cctp.device.db.entity.CdDeviceStatus">
    update
    <include refid="Table_Name"/>
    <set>
      <if test="deviceType != null">
        device_type = #{deviceType, jdbcType=VARCHAR},
      </if>
      <if test="usageStatus != null">
        usage_status = #{usageStatus, jdbcType=VARCHAR},
      </if>
      <if test="deviceStatus != null">
        device_status = #{deviceStatus, jdbcType=VARCHAR},
      </if>
      <if test="lastHeartbeatTime != null">
        last_heartbeat_time = #{lastHeartbeatTime, jdbcType=TIMESTAMP},
      </if>
    </set>
    where id = #{id,jdbcType=VARCHAR}
  </update>

  <select id="query" resultMap="BaseResultMap" parameterType="net.northking.cctp.device.db.entity.CdDeviceStatus">
    select
    <include refid="Base_Column_List" />
    from
    <include refid="Table_Name"/>
    <trim prefix="WHERE" prefixOverrides="AND" >
      <if test="id != null">
        AND id = #{id,jdbcType=VARCHAR}
      </if>
      <if test="deviceType != null">
        AND device_type = #{deviceType,jdbcType=VARCHAR}
      </if>
      <if test="usageStatus != null">
        AND usage_status = #{usageStatus,jdbcType=VARCHAR}
      </if>
      <if test="deviceStatus != null">
        AND device_status = #{deviceStatus,jdbcType=VARCHAR}
      </if>
      <if test="lastHeartbeatTime != null">
        AND last_heartbeat_time = #{lastHeartbeatTime,jdbcType=TIMESTAMP}
      </if>
    </trim>
  </select>

  <select id="queryCount" resultType="java.lang.Long" parameterType="net.northking.cctp.device.db.entity.CdDeviceStatus">
    select count(*) from
    <include refid="Table_Name"/>
    <trim prefix="WHERE" prefixOverrides="AND" >
      <if test="id != null">
        AND id=#{id,jdbcType=VARCHAR}
      </if>
      <if test="deviceType != null">
        AND device_type=#{deviceType,jdbcType=VARCHAR}
      </if>
      <if test="usageStatus != null">
        AND usage_status=#{usageStatus,jdbcType=VARCHAR}
      </if>
      <if test="deviceStatus != null">
        AND device_status=#{deviceStatus,jdbcType=VARCHAR}
      </if>
      <if test="lastHeartbeatTime != null">
        AND last_heartbeat_time=#{lastHeartbeatTime,jdbcType=TIMESTAMP}
      </if>
    </trim>
  </select>

</mapper>