<?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.ruoyi.ems.mapper.AreaBuildingZoningMapper">
    
    <resultMap type="com.ruoyi.ems.domain.AreaBuildingZoning" id="AreaBuildingZoningResult">
        <result property="id"    column="id"    />
        <result property="bldgCode"    column="bldg_code"    />
        <result property="bldgName"    column="bldg_name"    />
        <result property="zoningCode"    column="zoning_code"    />
        <result property="zoningName"    column="zoning_name"    />
        <result property="floor"    column="floor"    />
        <result property="bldgLdArea"    column="bldg_ld_area"    />
        <result property="usageDetail"    column="usage_detail"    />
        <result property="tagCode"    column="tag_code"    />
        <result property="tagName"    column="tag_name"    />
    </resultMap>

    <sql id="selectAreaBuildingZoningVo">
        select z.`id`, z.`bldg_code`, b.`bldg_name`, z.`zoning_code`, z.`zoning_name`, z.`floor`, z.`bldg_ld_area`, z.`usage_detail`, z.`tag_code`, t.tag_name from adm_area_building_zoning z
            LEFT JOIN adm_area_building b ON z.bldg_code = b.bldg_code
            LEFT JOIN dim_ems_tag t ON z.tag_code = t.tag_code
    </sql>

    <select id="selectAreaBuildingZoningList" parameterType="com.ruoyi.ems.domain.AreaBuildingZoning" resultMap="AreaBuildingZoningResult">
        <include refid="selectAreaBuildingZoningVo"/>
        <where>  
            <if test="bldgCode != null  and bldgCode != ''"> and z.`bldg_code` = #{bldgCode}</if>
            <if test="zoningCode != null  and zoningCode != ''"> and z.`zoning_code` = #{zoningCode}</if>
            <if test="zoningName != null  and zoningName != ''"> and z.`zoning_name` like concat('%', #{zoningName}, '%')</if>
            <if test="floor != null "> and z.`floor` = #{floor}</if>
            <if test="bldgLdArea != null "> and z.`bldg_ld_area` = #{bldgLdArea}</if>
            <if test="usageDetail != null  and usageDetail != ''"> and z.`usage_detail` = #{usageDetail}</if>
            <if test="tagCode != null  and tagCode != ''"> and z.`tag_code` = #{tagCode}</if>
        </where>
    </select>
    
    <select id="selectAreaBuildingZoningById" parameterType="Long" resultMap="AreaBuildingZoningResult">
        <include refid="selectAreaBuildingZoningVo"/>
        where z.`id` = #{id}
    </select>

    <select id="selectAreaBuildingZoningByCode" parameterType="String" resultMap="AreaBuildingZoningResult">
        <include refid="selectAreaBuildingZoningVo"/>
        where z.`zoning_code` = #{code}
    </select>
        
    <insert id="insertAreaBuildingZoning" parameterType="com.ruoyi.ems.domain.AreaBuildingZoning" useGeneratedKeys="true" keyProperty="id">
        insert into adm_area_building_zoning
        <trim prefix="(" suffix=")" suffixOverrides=",">
            <if test="bldgCode != null and bldgCode != ''">bldg_code,</if>
            <if test="zoningCode != null and zoningCode != ''">zoning_code,</if>
            <if test="zoningName != null and zoningName != ''">zoning_name,</if>
            <if test="floor != null">floor,</if>
            <if test="bldgLdArea != null">bldg_ld_area,</if>
            <if test="usageDetail != null">usage_detail,</if>
            <if test="tagCode != null">tag_code,</if>
         </trim>
        <trim prefix="values (" suffix=")" suffixOverrides=",">
            <if test="bldgCode != null and bldgCode != ''">#{bldgCode},</if>
            <if test="zoningCode != null and zoningCode != ''">#{zoningCode},</if>
            <if test="zoningName != null and zoningName != ''">#{zoningName},</if>
            <if test="floor != null">#{floor},</if>
            <if test="bldgLdArea != null">#{bldgLdArea},</if>
            <if test="usageDetail != null">#{usageDetail},</if>
            <if test="tagCode != null">#{tagCode}</if>
         </trim>
    </insert>

    <update id="updateAreaBuildingZoning" parameterType="com.ruoyi.ems.domain.AreaBuildingZoning">
        update adm_area_building_zoning
        <trim prefix="SET" suffixOverrides=",">
            <if test="bldgCode != null and bldgCode != ''">bldg_code = #{bldgCode},</if>
            <if test="zoningCode != null and zoningCode != ''">zoning_code = #{zoningCode},</if>
            <if test="zoningName != null and zoningName != ''">zoning_name = #{zoningName},</if>
            <if test="floor != null">floor = #{floor},</if>
            <if test="bldgLdArea != null">bldg_ld_area = #{bldgLdArea},</if>
            <if test="usageDetail != null">usage_detail = #{usageDetail},</if>
            <if test="tagCode != null">tag_code = #{tagCode},</if>
        </trim>
        where id = #{id}
    </update>

    <delete id="deleteAreaBuildingZoningById" parameterType="Long">
        delete from adm_area_building_zoning where id = #{id}
    </delete>

    <delete id="deleteAreaBuildingZoningByIds" parameterType="String">
        delete from adm_area_building_zoning where id in
        <foreach item="id" collection="array" open="(" separator="," close=")">
            #{id}
        </foreach>
    </delete>
</mapper>