<?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.AreaAttrMapper">
    
    <resultMap type="com.ruoyi.ems.domain.AreaAttr" id="areaAttrResult">
        <result property="id"    column="id"    />
        <result property="areaCode"    column="area_code"    />
        <result property="attrOrg"    column="attr_org"    />
        <result property="mgrOrg"    column="mgr_org"    />
        <result property="leader"    column="leader"    />
        <result property="phone"    column="phone"    />
        <result property="openDate"    column="open_date"    />
        <result property="floorArea"    column="floor_area"    />
        <result property="usableArea"    column="usable_area"    />
        <result property="floor"    column="floor"    />
        <result property="longitude"    column="longitude"    />
        <result property="latitude"    column="latitude"    />
    </resultMap>

    <sql id="selectAreaAttrVo">
        select
            id,
            area_code,
            attr_org,
            mgr_org,
            leader,
            phone,
            open_date,
            floor_area,
            usable_area,
            floor,
            longitude,
            latitude
        from adm_area_attr
    </sql>

    <select id="selectAreaAttrList" resultMap="areaAttrResult">
        <include refid="selectAreaAttrVo"/>
        <where>
            area_code in
            (
              <foreach collection="set" item="item" index="index" separator=",">
                #{item}
              </foreach>
            )
        </where>
    </select>
    
    <select id="selectAreaAttrByCode" parameterType="String" resultMap="areaAttrResult">
        <include refid="selectAreaAttrVo"/>
        where area_code = #{areaCode}
    </select>

    <insert id="insertAreaAttr" parameterType="com.ruoyi.ems.domain.AreaAttr" useGeneratedKeys="true" keyProperty="id">
        insert into adm_area_attr
        <trim prefix="(" suffix=")" suffixOverrides=",">
            area_code,

            <if test="attrOrg != null">attr_org,</if>
            <if test="mgrOrg != null">mgr_org,</if>
            <if test="leader != null">leader,</if>
            <if test="phone != null">phone,</if>
            <if test="openDate != null">open_date,</if>
            <if test="floorArea != null">floor_area,</if>
            <if test="usableArea != null">usable_area,</if>
            <if test="floor != null">floor,</if>
            <if test="longitude != null">longitude,</if>
            <if test="latitude != null">latitude,</if>
        </trim>
        <trim prefix="values (" suffix=")" suffixOverrides=",">
            #{areaCode},

            <if test="attrOrg != null">#{attrOrg},</if>
            <if test="mgrOrg != null">#{mgrOrg},</if>
            <if test="leader != null">#{leader},</if>
            <if test="phone != null">#{phone},</if>
            <if test="openDate != null">#{openDate},</if>
            <if test="floorArea != null">#{floorArea},</if>
            <if test="usableArea != null">#{usableArea},</if>
            <if test="floor != null">#{floor},</if>
            <if test="longitude != null">#{longitude},</if>
            <if test="latitude != null">#{latitude},</if>
        </trim>
    </insert>

    <update id="updateAreaAttr" parameterType="com.ruoyi.ems.domain.AreaAttr">
        update adm_area_attr
        <trim prefix="SET" suffixOverrides=",">
            <if test="attrOrg != null">attr_org = #{attrOrg},</if>
            <if test="mgrOrg != null">mgr_org = #{mgrOrg},</if>
            <if test="leader != null">leader = #{leader},</if>
            <if test="phone != null">phone = #{phone},</if>
            <if test="openDate != null">open_date = #{openDate},</if>
            <if test="floorArea != null">floor_area = #{floorArea},</if>
            <if test="usableArea != null">usable_area = #{usableArea},</if>
            <if test="floor != null">floor = #{floor},</if>
            <if test="longitude != null">longitude = #{longitude},</if>
            <if test="latitude != null">latitude = #{latitude},</if>
        </trim>
        where area_code = #{areaCode}
    </update>

    <delete id="deleteAreaAttrByCode" parameterType="String">
        delete from adm_area_attr where area_code = #{areaCode}
    </delete>
</mapper>