eden-basic/target/classes/mapper/room/BuildingMapper.xml
zhongchangyuyu fde29b7072 资源管理
2025-04-23 15:58:01 +08:00

272 lines
14 KiB
XML

<?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.eden.room.mapper.BuildingMapper">
<resultMap type="Building" id="BuildingResult">
<result property="id" column="id"/>
<result property="tenantId" column="tenant_id"/>
<result property="projectId" column="project_id"/>
<result property="buildingCode" column="building_code"/>
<result property="buildingName" column="building_name"/>
<result property="region" column="region"/>
<result property="address" column="address"/>
<result property="propertyNature" column="property_nature"/>
<result property="propertyCertNo" column="property_cert_no"/>
<result property="propertyNo" column="property_no"/>
<result property="landNo" column="land_no"/>
<result property="sortOrder" column="sort_order"/>
<result property="buildingArea" column="building_area"/>
<result property="propertyArea" column="property_area"/>
<result property="rentableArea" column="rentable_area"/>
<result property="selfUseArea" column="self_use_area"/>
<result property="supportingArea" column="supporting_area"/>
<result property="parkingArea" column="parking_area"/>
<result property="accountId" column="account_id"/>
<result property="buildingTags" column="building_tags"/>
<result property="isHot" column="is_hot"/>
<result property="totalFloors" column="total_floors"/>
<result property="facilities" column="facilities"/>
<result property="imageUrl" column="image_url"/>
<result property="createTime" column="create_time"/>
<result property="lastModTime" column="last_mod_time"/>
<result property="createUserId" column="create_user_id"/>
<result property="lastModUserId" column="last_mod_user_id"/>
<result property="delFlag" column="del_flag"/>
<result property="remark" column="remark"/>
<result property="reserve1" column="reserve1"/>
<result property="reserve2" column="reserve2"/>
<result property="reserve3" column="reserve3"/>
<result property="projectName" column="project_name"/>
</resultMap>
<sql id="selectBuildingVo">
select b.id, b.tenant_id, b.project_id, b.building_code, b.building_name, b.region,
b.address, b.property_nature, b.property_cert_no, b.property_no, b.land_no,
b.sort_order, b.building_area, b.property_area, b.rentable_area, b.self_use_area,
b.supporting_area, b.parking_area, b.account_id, b.building_tags, b.is_hot, b.total_floors, b.facilities, b.image_url, b.create_time,
b.last_mod_time, b.create_user_id, b.last_mod_user_id,
b.del_flag, b.remark, b.reserve1, b.reserve2, b.reserve3,
p.project_name
from TB_BUILDING b
left join TB_PROJECT p on b.project_id = p.id and p.del_flag = '0'
</sql>
<select id="selectBuildingList" parameterType="Building" resultMap="BuildingResult">
<include refid="selectBuildingVo"/>
<where>
<if test="projectId != null and projectId != ''">
AND project_id = #{projectId}
</if>
<if test="buildingCode != null and buildingCode != ''">
AND building_code = #{buildingCode}
</if>
<if test="buildingName != null and buildingName != ''">
AND building_name like concat('%', #{buildingName}, '%')
</if>
<if test="region != null and region != ''">
AND region = #{region}
</if>
<if test="propertyNature != null and propertyNature != ''">
AND property_nature = #{propertyNature}
</if>
<if test="buildingTags != null and buildingTags != ''">
AND building_tags = #{buildingTags}
</if>
<if test="isHot != null and isHot != ''">
AND is_hot = #{isHot}
</if>
AND b.del_flag = '0'
</where>
order by sort_order desc, create_time desc
</select>
<select id="selectBuildingById" parameterType="String" resultMap="BuildingResult">
<include refid="selectBuildingVo"/>
where b.id = #{id} and b.del_flag = '0'
</select>
<insert id="insertBuilding" parameterType="Building" useGeneratedKeys="true" keyProperty="id">
insert into TB_BUILDING
<trim prefix="(" suffix=")" suffixOverrides=",">
<if test="tenantId != null">tenant_id,</if>
<if test="projectId != null">project_id,</if>
<if test="buildingCode != null">building_code,</if>
<if test="buildingName != null">building_name,</if>
<if test="region != null">region,</if>
<if test="address != null">address,</if>
<if test="propertyNature != null">property_nature,</if>
<if test="propertyCertNo != null">property_cert_no,</if>
<if test="propertyNo != null">property_no,</if>
<if test="landNo != null">land_no,</if>
<if test="sortOrder != null">sort_order,</if>
<if test="buildingArea != null">building_area,</if>
<if test="propertyArea != null">property_area,</if>
<if test="rentableArea != null">rentable_area,</if>
<if test="selfUseArea != null">self_use_area,</if>
<if test="supportingArea != null">supporting_area,</if>
<if test="parkingArea != null">parking_area,</if>
<if test="accountId != null">account_id,</if>
<if test="buildingTags != null">building_tags,</if>
<if test="isHot != null">is_hot,</if>
<if test="totalFloors != null">total_floors,</if>
<if test="facilities != null">facilities,</if>
<if test="imageUrl != null">image_url,</if>
<if test="createUserId != null">create_user_id,</if>
<if test="lastModUserId != null">last_mod_user_id,</if>
<if test="delFlag != null">del_flag,</if>
<if test="remark != null">remark,</if>
<if test="reserve1 != null">reserve1,</if>
<if test="reserve2 != null">reserve2,</if>
<if test="reserve3 != null">reserve3,</if>
create_time,
last_mod_time
</trim>
<trim prefix="values (" suffix=")" suffixOverrides=",">
<if test="tenantId != null">#{tenantId},</if>
<if test="projectId != null">#{projectId},</if>
<if test="buildingCode != null">#{buildingCode},</if>
<if test="buildingName != null">#{buildingName},</if>
<if test="region != null">#{region},</if>
<if test="address != null">#{address},</if>
<if test="propertyNature != null">#{propertyNature},</if>
<if test="propertyCertNo != null">#{propertyCertNo},</if>
<if test="propertyNo != null">#{propertyNo},</if>
<if test="landNo != null">#{landNo},</if>
<if test="sortOrder != null">#{sortOrder},</if>
<if test="buildingArea != null">#{buildingArea},</if>
<if test="propertyArea != null">#{propertyArea},</if>
<if test="rentableArea != null">#{rentableArea},</if>
<if test="selfUseArea != null">#{selfUseArea},</if>
<if test="supportingArea != null">#{supportingArea},</if>
<if test="parkingArea != null">#{parkingArea},</if>
<if test="accountId != null">#{accountId},</if>
<if test="buildingTags != null">#{buildingTags},</if>
<if test="isHot != null">#{isHot},</if>
<if test="totalFloors != null">#{totalFloors},</if>
<if test="facilities != null">#{facilities},</if>
<if test="imageUrl != null">#{imageUrl},</if>
<if test="createUserId != null">#{createUserId},</if>
<if test="lastModUserId != null">#{lastModUserId},</if>
<if test="delFlag != null">#{delFlag},</if>
<if test="remark != null">#{remark},</if>
<if test="reserve1 != null">#{reserve1},</if>
<if test="reserve2 != null">#{reserve2},</if>
<if test="reserve3 != null">#{reserve3},</if>
CURRENT_TIMESTAMP,
CURRENT_TIMESTAMP
</trim>
</insert>
<update id="updateBuilding" parameterType="Building">
update TB_BUILDING
<trim prefix="SET" suffixOverrides=",">
<if test="buildingCode != null">building_code = #{buildingCode},</if>
<if test="buildingName != null">building_name = #{buildingName},</if>
<if test="region != null">region = #{region},</if>
<if test="address != null">address = #{address},</if>
<if test="propertyNature != null">property_nature = #{propertyNature},</if>
<if test="propertyCertNo != null">property_cert_no = #{propertyCertNo},</if>
<if test="propertyNo != null">property_no = #{propertyNo},</if>
<if test="landNo != null">land_no = #{landNo},</if>
<if test="sortOrder != null">sort_order = #{sortOrder},</if>
<if test="buildingArea != null">building_area = #{buildingArea},</if>
<if test="propertyArea != null">property_area = #{propertyArea},</if>
<if test="rentableArea != null">rentable_area = #{rentableArea},</if>
<if test="selfUseArea != null">self_use_area = #{selfUseArea},</if>
<if test="supportingArea != null">supporting_area = #{supportingArea},</if>
<if test="parkingArea != null">parking_area = #{parkingArea},</if>
<if test="accountId != null">account_id = #{accountId},</if>
<if test="buildingTags != null">building_tags = #{buildingTags},</if>
<if test="isHot != null">is_hot = #{isHot},</if>
<if test="totalFloors != null">total_floors = #{totalFloors},</if>
<if test="facilities != null">facilities = #{facilities},</if>
<if test="imageUrl != null">image_url = #{imageUrl},</if>
<if test="lastModUserId != null">last_mod_user_id = #{lastModUserId},</if>
<if test="remark != null">remark = #{remark},</if>
<if test="reserve1 != null">reserve1 = #{reserve1},</if>
<if test="reserve2 != null">reserve2 = #{reserve2},</if>
<if test="reserve3 != null">reserve3 = #{reserve3},</if>
last_mod_time = CURRENT_TIMESTAMP
</trim>
where id = #{id} and del_flag = '0'
</update>
<delete id="deleteBuildingById" parameterType="String">
update TB_BUILDING set del_flag = '1' where id = #{id}
</delete>
<delete id="deleteBuildingByIds" parameterType="String">
update TB_BUILDING set del_flag = '1' where id in
<foreach item="id" collection="array" open="(" separator="," close=")">
#{id}
</foreach>
</delete>
<select id="checkBuildingNameExists" parameterType="Building" resultType="Integer">
select count(*) from TB_BUILDING
where building_name = #{buildingName}
and project_id = #{projectId}
and tenant_id = #{tenantId}
and del_flag = '0'
<if test="id != null and id != ''">
and id != #{id}
</if>
</select>
<select id="checkBuildingCodeExists" parameterType="Building" resultType="Integer">
select count(*) from TB_BUILDING
where building_code = #{buildingCode}
and project_id = #{projectId}
and tenant_id = #{tenantId}
and del_flag = '0'
<if test="id != null and id != ''">
and id != #{id}
</if>
</select>
<select id="selectBuildingStatistics" parameterType="String" resultMap="BuildingResult">
select b.*,
(select count(*) from TB_ROOM_BASE where building_id = b.id and del_flag = '0') as total_rooms,
(select count(*) from TB_ROOM_BASE rb
inner join TB_ROOM_BUSINESS rbs on rb.id = rbs.room_id
where rb.building_id = b.id and rb.del_flag = '0' and rbs.rental_status = '已租') as rented_rooms,
(select count(*) from TB_ROOM_BASE rb
inner join TB_ROOM_BUSINESS rbs on rb.id = rbs.room_id
where rb.building_id = b.id and rb.del_flag = '0' and rbs.rental_status = '待租') as waiting_rooms,
(select COALESCE(sum(rb.building_area), 0) from TB_ROOM_BASE rb
inner join TB_ROOM_BUSINESS rbs on rb.id = rbs.room_id
where rb.building_id = b.id and rb.del_flag = '0' and rbs.rental_status = '已租') as rented_area,
(select COALESCE(sum(rb.building_area), 0) from TB_ROOM_BASE rb
inner join TB_ROOM_BUSINESS rbs on rb.id = rbs.room_id
where rb.building_id = b.id and rb.del_flag = '0' and rbs.rental_status = '待租') as waiting_area,
(select count(*) from TB_ROOM_BASE rb
inner join TB_ROOM_BUSINESS rbs on rb.id = rbs.room_id
where rb.building_id = b.id and rb.del_flag = '0' and rbs.business_status = '招商') as available_rooms,
(select COALESCE(sum(rb.building_area), 0) from TB_ROOM_BASE rb
inner join TB_ROOM_BUSINESS rbs on rb.id = rbs.room_id
where rb.building_id = b.id and rb.del_flag = '0' and rbs.business_status = '招商') as available_area
from TB_BUILDING b
where b.id = #{id} and b.del_flag = '0'
</select>
<select id="selectBuildingIdByNameAndProjectId" resultType="String">
select id from TB_BUILDING
where building_name = #{buildingName}
and project_id = #{projectId}
and del_flag = '0'
limit 1
</select>
<select id="checkBuildingHasFloors" parameterType="String" resultType="Boolean">
select count(1) > 0 from tb_floor where building_id = #{id}
</select>
<select id="getBuildByIds" parameterType="java.util.List" resultMap="BuildingResult">
<include refid="selectBuildingVo"/>
where b.id IN
<foreach item="id" collection="ids" open="(" separator="," close=")">
#{id}
</foreach>
</select>
</mapper>