<?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.srs.dormitory.mapper.DmsDormitoryParkMapper">

    <!-- 通用查询映射结果 -->
    <resultMap id="BaseResultMap" type="com.srs.dormitory.domain.DmsDormitoryPark">
        <id column="id" property="id" />
        <result column="name" property="name" />
        <result column="campus_id" property="campusId" />
        <result column="remark" property="remark" />
        <result column="create_by" property="createBy" />
        <result column="create_time" property="createTime" />
        <result column="update_by" property="updateBy" />
        <result column="update_time" property="updateTime" />
        <result column="del_flag" property="delFlag" />
    </resultMap>
    <select id="selectParkTotalOccupancy" resultType="Integer">
        SELECT
            COALESCE(SUM(d.occupancy), 0) AS totalOccupancy
        FROM
            dms_dormitory_park p
                LEFT JOIN dms_dormitory_building b ON p.id = b.park_id
                LEFT JOIN dms_dormitory_floor f ON b.id = f.building_id
                LEFT JOIN dms_dormitory d ON f.id = d.floor_id
        WHERE p.id = #{id}
    </select>
    <select id="getDormitoryParkList" resultType="java.util.Map">
        SELECT p.id,p.`name` parkName,p.remark,p.create_by createBy,
               p.create_time createTime,p.update_by updateBy,p.update_time updateTime,
               c.`name` campusName
        FROM dms_dormitory_park p
        LEFT JOIN dms_campus c ON p.campus_id = c.id
        <where>
            <if test="id != null">and p.id = #{id}</if>
            <if test="name != null">and p.name = #{name}</if>
            <if test="campusId != null">and c.id = #{campusId}</if>
        </where>
    </select>
    <select id="getParkListByCampusId" resultType="com.srs.dormitory.domain.Vo.ParkVo">
        SELECT id,name
        FROM dms_dormitory_park
        where campus_id = #{campusId}
    </select>

</mapper>
