<?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.system.mapper.AreaMapper">
    
    <resultMap type="Area" id="AreaResult">
        <result property="id"    column="id"    />
        <result property="pid"    column="pid"    />
        <result property="title"    column="title"    />
    </resultMap>

    <sql id="selectAreaVo">
        select id, pid, title from area
    </sql>

    <select id="selectAreaList" parameterType="Area" resultMap="AreaResult">
        <include refid="selectAreaVo"/>
        <where>  
            <if test="pid != null "> and pid = #{pid}</if>
            <if test="title != null  and title != ''"> and title = #{title}</if>
        </where>
    </select>
    
    <select id="selectAreaById" parameterType="Long" resultMap="AreaResult">
        <include refid="selectAreaVo"/>
        where id = #{id}
    </select>

    <insert id="insertArea" parameterType="Area" useGeneratedKeys="true" keyProperty="id">
        insert into area
        <trim prefix="(" suffix=")" suffixOverrides=",">
            <if test="pid != null">pid,</if>
            <if test="title != null and title != ''">title,</if>
         </trim>
        <trim prefix="values (" suffix=")" suffixOverrides=",">
            <if test="pid != null">#{pid},</if>
            <if test="title != null and title != ''">#{title},</if>
         </trim>
    </insert>

    <update id="updateArea" parameterType="Area">
        update area
        <trim prefix="SET" suffixOverrides=",">
            <if test="pid != null">pid = #{pid},</if>
            <if test="title != null and title != ''">title = #{title},</if>
        </trim>
        where id = #{id}
    </update>

    <delete id="deleteAreaById" parameterType="Long">
        delete from area where id = #{id}
    </delete>

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