<?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.api.manage.dao.basicArchives.CpmBuildingUnitDao">
    <select id="list" parameterType="com.api.vo.basicArchives.VoCpmBuildingUnit" resultType="com.api.vo.basicArchives.VoCpmBuildingUnit">
        select cbu.id,cbu.building_id,cbu.no,cbu.total_floor,cbu.is_elevator,cb.name as buildingName
        from cpm_building cb,cpm_building_unit cbu
        <where>
            cb.id = cbu.building_id
            <if test="buildingName != null and buildingName != ''">
                and cb.name like concat('%',#{buildingName},'%')
            </if>
            <if test="no != null">
                and cbu.no = #{no}
            </if>
        </where>
        order by cbu.create_date desc
    </select>

    <insert id="insert" parameterType="com.api.model.basicArchives.CpmBuildingUnit">
        insert into
        cpm_building_unit(building_id,no,total_floor,is_elevator,create_id,create_date)
        values
        (#{buildingId},#{no},#{totalFloor},#{isElevator},#{createId},#{createDate})
    </insert>

    <select id="findById" parameterType="java.lang.Integer" resultType="com.api.model.basicArchives.CpmBuildingUnit">
        select id,building_id,no,total_floor,is_elevator
        from cpm_building_unit
        where id = #{id}
    </select>

    <update id="update" parameterType="com.api.model.basicArchives.CpmBuildingUnit">
        update cpm_building_unit
        <set>
            <if test="buildingId != null">
                building_id = #{buildingId},
            </if>
            <if test="no != null">
                no = #{no},
            </if>
            <if test="totalFloor != null">
                total_floor = #{totalFloor},
            </if>
            <if test="isElevator != null">
                is_elevator = #{isElevator},
            </if>
        </set>
        where id = #{id}
    </update>

    <delete id="delete" parameterType="java.lang.Integer">
        delete from cpm_building_unit where id = #{id}
    </delete>

    <select id="findAll" resultType="com.api.vo.basicArchives.VoFindAll">
        select id as value,no as label from cpm_building_unit
    </select>

    <select id="findByBuildingId" parameterType="java.lang.Integer" resultType="com.api.vo.basicArchives.VoFindAll">
        select id as value,no as label from cpm_building_unit
        where building_id = #{id}
    </select>

    <select id="findByNo" parameterType="java.lang.Integer" resultType="com.api.model.basicArchives.CpmBuildingUnit">
        select id,building_id,no,total_floor,is_elevator
        from cpm_building_unit
        where no = #{no}
    </select>
    <select id="countByBuildingId" parameterType="java.lang.Integer" resultType="java.lang.Integer">
        select count(*) from cpm_building_unit where building_id = #{id}
    </select>
</mapper>