<?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.zcloud.zcGbsServicer.persistence.mapper.FireResourceMapper">

    <select id="selectStaPage" resultType="com.zcloud.zcGbsServicer.persistence.dataobject.FireResourceStaDO">
        SELECT
        ci.id AS corpId,
        ci.corp_name AS corpName,
        (SELECT COUNT(*) FROM rescue_team WHERE tenant_id = ci.id AND delete_enum = 'false') AS rescueTeamCount,
        (SELECT COUNT(*) FROM control_room WHERE tenant_id = ci.id AND delete_enum = 'false') AS controlRoomCount,
        (SELECT COUNT(*) FROM pump_room WHERE tenant_id = ci.id AND delete_enum = 'false') AS pumpRoomCount,
        (SELECT COUNT(*) FROM water_source WHERE tenant_id = ci.id AND delete_enum = 'false') AS waterSourceCount
        FROM
        corp_info ci
        <where>
            ci.delete_enum = 'FALSE'
            AND
            ci.type IN(0, 1, 6)
            <if test="corpName != null and corpName != ''">
                AND ci.corp_name LIKE CONCAT('%', #{corpName}, '%')
            </if>
        </where>
        ORDER BY ci.corp_order ASC,
        ci.create_time Desc
    </select>

</mapper>

