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

    <!-- 统计状态数量 -->
    <select id="statusCount" resultType="com.xy.mapper.entity.DeviceStatusCount">
        select
        (select count(*) device_count from device_info) deviceCount,
        (select count(*) busy_state from device_info where busy_state = 1) busyState,
        (select count(*) net_state from device_status where net_state = 2) netState,
        (select count(*) device_state from device_status where device_state_l = 2 and device_state_r = 2) deviceState,
        (select count(*) active_state from device_info where active_state = 1) activeState,

        (select count(*) temp_state from device_status where temp_state = 2) tempState
        from dual
    </select>

    <!-- 离线的支付宝设备 -->
    <select id="aliPayNotNetWorkDevice" resultType="com.xy.entity.DeviceStatus">
        select ds.*
        from device_info di
        join device_status ds on(di.device_id = ds.device_id)
        where
        di.device_type = 5 and ds.net_state = 2
    </select>
</mapper>
