<?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.CdDeviceStatusDao">

  <select id="findOfflineDevice" resultMap="BaseResultMap">
    SELECT
    <include refid="Base_Column_List"/>
    FROM
    <include refid="Table_Name"/>
    WHERE TIMESTAMPDIFF(SECOND,last_heartbeat_time, #{date,jdbcType=TIMESTAMP}) > 120
    and device_status = '1'
  </select>

  <update id="updateDeviceStatus">
    UPDATE cd_device_status SET device_status = '2',usage_status = '3'
    WHERE id IN
    <foreach collection="ids" item="idItem" open="(" separator="," close=")">
      #{idItem, jdbcType=VARCHAR}
    </foreach>
  </update>

  <update id="updateHeartbeatTime">
    update cd_device_status SET last_heartbeat_time = now(),device_status = '1'
    WHERE id IN
    <foreach collection="ids" item="idItem" open="(" separator="," close=")">
      #{idItem, jdbcType=VARCHAR}
    </foreach>
  </update>

</mapper>