<?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.DmsDormitoryBuildingInfoMapper">

    <!-- 通用查询映射结果 -->
    <resultMap id="BaseResultMap" type="com.srs.dormitory.domain.DmsDormitoryBuildingInfo">
        <id column="id" property="id" />
        <result column="building_id" property="buildingId" />
        <result column="unit_number" property="unitNumber" />
        <result column="floor_number" property="floorNumber" />
        <result column="bed_count" property="bedCount" />
        <result column="gender" property="gender" />
        <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>
    <update id="updateBedCountByDormitoryId" parameterType="Long">
        UPDATE dms_dormitory_building_info info SET info.bed_count = info.bed_count+#{bedCount}
        WHERE info.building_id = (
            SELECT ddb.id FROM dms_dormitory dd
                                   JOIN dms_dormitory_floor ddf ON ddf.id = dd.floor_id
                                   JOIN dms_dormitory_building ddb ON ddf.building_id = ddb.id
            WHERE dd.id = #{dormitoryId}
        )
    </update>
</mapper>
