<?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.da.dangan.mapper.AreaSortMapper">
    
    <resultMap type="AreaSort" id="AreaSortResult">
        <result property="id"    column="id"    />
        <result property="muName"    column="mu_name"    />
        <result property="areaType"    column="area_type"    />
        <result property="pid"    column="pid"    />
        <result property="createBy"    column="create_by"    />
        <result property="createTime"    column="create_time"    />
        <result property="updateBy"    column="update_by"    />
        <result property="updateTime"    column="update_time"    />
    </resultMap>

    <sql id="selectAreaSortVo">
        select id, mu_name, area_type, pid, create_by, create_time, update_by, update_time from area_sort
    </sql>

    <select id="selectAreaSortList" parameterType="AreaSort" resultMap="AreaSortResult">
        <include refid="selectAreaSortVo"/>
        <where>  
            <if test="muName != null  and muName != ''"> and mu_name like concat('%', #{muName}, '%')</if>
            <if test="areaType != null  and areaType != ''"> and area_type = #{areaType}</if>
            <if test="pid != null "> and pid = #{pid}</if>
        </where>
        order by pid
    </select>
    
    <select id="selectAreaSortById" parameterType="Long" resultMap="AreaSortResult">
        <include refid="selectAreaSortVo"/>
        where id = #{id}
    </select>
        
    <insert id="insertAreaSort" parameterType="AreaSort" useGeneratedKeys="true" keyProperty="id">
        insert into area_sort
        <trim prefix="(" suffix=")" suffixOverrides=",">
            <if test="muName != null and muName != ''">mu_name,</if>
            <if test="areaType != null and areaType != ''">area_type,</if>
            <if test="pid != null">pid,</if>
            <if test="createBy != null">create_by,</if>
            <if test="createTime != null">create_time,</if>
            <if test="updateBy != null">update_by,</if>
            <if test="updateTime != null">update_time,</if>
         </trim>
        <trim prefix="values (" suffix=")" suffixOverrides=",">
            <if test="muName != null and muName != ''">#{muName},</if>
            <if test="areaType != null and areaType != ''">#{areaType},</if>
            <if test="pid != null">#{pid},</if>
            <if test="createBy != null">#{createBy},</if>
            <if test="createTime != null">#{createTime},</if>
            <if test="updateBy != null">#{updateBy},</if>
            <if test="updateTime != null">#{updateTime},</if>
         </trim>
    </insert>

    <update id="updateAreaSort" parameterType="AreaSort">
        update area_sort
        <trim prefix="SET" suffixOverrides=",">
            <if test="muName != null and muName != ''">mu_name = #{muName},</if>
            <if test="areaType != null and areaType != ''">area_type = #{areaType},</if>
            <if test="pid != null">pid = #{pid},</if>
            <if test="createBy != null">create_by = #{createBy},</if>
            <if test="createTime != null">create_time = #{createTime},</if>
            <if test="updateBy != null">update_by = #{updateBy},</if>
            <if test="updateTime != null">update_time = #{updateTime},</if>
        </trim>
        where id = #{id}
    </update>

    <delete id="deleteAreaSortById" parameterType="Long">
        delete from area_sort where id = #{id}
    </delete>

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