<?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="org.king.modules.ad.mapper.ThirdMapper">

    <select id="queryDeviceInfo" resultType="org.king.modules.ad.entity.AdDeviceForThird">
        select id,
               sys_office_id,
               berth_id,
               type,
               voltage,
               rated_current,
               maximum_current,
               frequency,
               capy,
               number,
               free_num,
               company_id,
               service_name,
               firm_name,
               position,
               is_free,
               status,
               price,
               province,
               city,
               area,
               longitude,
               latitude,
               company_name,
               area_name,
               current_consumption,
               ifnull(t2.count, 0) count
        from ad_device t1
            left join (
            select ad_device_id, count(1) as count
            from ad_charging_record
            where real_start_time is not null
            group by ad_device_id) t2 on t1.id = t2.ad_device_id
        where t1.is_del = 0
    </select>
</mapper>