<?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.ChinaAreaMapper">
    
    <resultMap type="com.ruoyi.system.domain.ChinaArea" id="ChinaAreaResult">
        <result property="areaId"    column="area_id"    />
        <result property="name"    column="name"    />
        <result property="pid"    column="pid"    />
        <result property="sort"    column="sort"    />
    </resultMap>

    <sql id="selectChinaAreaVo">
        select area_id, name, pid, sort from china_area
    </sql>

    <select id="selectChinaAreaList" parameterType="com.ruoyi.system.domain.ChinaArea" resultMap="ChinaAreaResult">
        <include refid="selectChinaAreaVo"/>
        <where>  
            <if test="name != null  and name != ''"> and name like concat('%', #{name}, '%')</if>
            <if test="pid != null  and pid != ''"> and pid = #{pid}</if>
            <if test="sort != null "> and sort = #{sort}</if>
        </where>
    </select>
    
    <select id="selectChinaAreaByAreaId" parameterType="String" resultMap="ChinaAreaResult">
        <include refid="selectChinaAreaVo"/>
        where area_id = #{areaId}
    </select>
    <select id="selectChinaAreaByPId" resultType="com.ruoyi.system.domain.ChinaArea" resultMap="ChinaAreaResult">
        <include refid="selectChinaAreaVo"/>
        where pid = #{areaId}
    </select>

    <insert id="insertChinaArea" parameterType="com.ruoyi.system.domain.ChinaArea">
        insert into china_area
        <trim prefix="(" suffix=")" suffixOverrides=",">
            <if test="areaId != null">area_id,</if>
            <if test="name != null">name,</if>
            <if test="pid != null">pid,</if>
            <if test="sort != null">sort,</if>
         </trim>
        <trim prefix="values (" suffix=")" suffixOverrides=",">
            <if test="areaId != null">#{areaId},</if>
            <if test="name != null">#{name},</if>
            <if test="pid != null">#{pid},</if>
            <if test="sort != null">#{sort},</if>
         </trim>
    </insert>

    <update id="updateChinaArea" parameterType="com.ruoyi.system.domain.ChinaArea">
        update china_area
        <trim prefix="SET" suffixOverrides=",">
            <if test="name != null">name = #{name},</if>
            <if test="pid != null">pid = #{pid},</if>
            <if test="sort != null">sort = #{sort},</if>
        </trim>
        where area_id = #{areaId}
    </update>

    <delete id="deleteChinaAreaByAreaId" parameterType="String">
        delete from china_area where area_id = #{areaId}
    </delete>

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