<?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.usky.fire.mapper.BscEnterpriseAutonomyMapper">

    <!-- 通用查询映射结果 -->
    <resultMap id="BaseResultMap" type="com.usky.fire.domain.BscEnterpriseAutonomy">
        <id column="id" property="id"/>
        <result column="enterprise_autonomy" property="enterpriseAutonomy"/>
        <result column="iot_device" property="iotDevice"/>
        <result column="patrol_inspection" property="patrolInspection"/>
        <result column="street_company" property="streetCompany"/>
        <result column="create_time" property="createTime"/>
        <result column="rpn" property="rpn"/>
    </resultMap>

    <select id="deviceStatusCount" resultType="com.usky.fire.service.vo.DataCountVo">
        SELECT
        a.street_town as listName,
        c.device_status as listType,
        COUNT(*) as listCount
        FROM
        base_company AS a
        JOIN base_device AS b ON a.company_id = b.company_id
        JOIN base_device_status AS c ON b.device_code = c.device_code
        <where>
            a.`enable` = 0
            and b.`enable` = 1
            <if test="streetTownList != null and streetTownList.size() > 0">
                AND a.street_town in
                <foreach item="item" collection="streetTownList" open="(" separator="," close=")">
                    #{item}
                </foreach>
            </if>
        </where>
        GROUP BY
        a.street_town,
        device_status
    </select>

</mapper>
