<?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.basic.mapper.HwAreaMapper">
    
    <resultMap type="HwArea" id="HwAreaResult">
        <result property="areaId"    column="area_id"    />
        <result property="areaName"    column="area_name"    />
        <result property="ancestors"    column="ancestors"    />
        <result property="parentId"    column="parent_id"    />
        <result property="areaStatus"    column="area_status"    />
        <result property="orderNum"    column="order_num"    />
        <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="selectHwAreaVo">
        select area_id, area_name, ancestors, parent_id, area_status, order_num, create_by, create_time, update_by, update_time from hw_area
    </sql>

    <select id="selectHwAreaList" parameterType="HwArea" resultMap="HwAreaResult">
        <include refid="selectHwAreaVo"/>
        <where>  
            <if test="areaName != null  and areaName != ''"> and area_name like concat('%', #{areaName}, '%')</if>
            <if test="ancestors != null  and ancestors != ''"> and ancestors = #{ancestors}</if>
            <if test="parentId != null "> and parent_id = #{parentId}</if>
            <if test="areaStatus != null "> and area_status = #{areaStatus}</if>
            <if test="orderNum != null "> and order_num = #{orderNum}</if>
        </where>
    </select>
    
    <select id="selectHwAreaByAreaId" parameterType="Long" resultMap="HwAreaResult">
        <include refid="selectHwAreaVo"/>
        where area_id = #{areaId}
    </select>
        
    <insert id="insertHwArea" parameterType="HwArea" useGeneratedKeys="true" keyProperty="areaId">
        insert into hw_area
        <trim prefix="(" suffix=")" suffixOverrides=",">
            <if test="areaName != null and areaName != ''">area_name,</if>
            <if test="ancestors != null">ancestors,</if>
            <if test="parentId != null">parent_id,</if>
            <if test="areaStatus != null">area_status,</if>
            <if test="orderNum != null">order_num,</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="areaName != null and areaName != ''">#{areaName},</if>
            <if test="ancestors != null">#{ancestors},</if>
            <if test="parentId != null">#{parentId},</if>
            <if test="areaStatus != null">#{areaStatus},</if>
            <if test="orderNum != null">#{orderNum},</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="updateHwArea" parameterType="HwArea">
        update hw_area
        <trim prefix="SET" suffixOverrides=",">
            <if test="areaName != null and areaName != ''">area_name = #{areaName},</if>
            <if test="ancestors != null">ancestors = #{ancestors},</if>
            <if test="parentId != null">parent_id = #{parentId},</if>
            <if test="areaStatus != null">area_status = #{areaStatus},</if>
            <if test="orderNum != null">order_num = #{orderNum},</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 area_id = #{areaId}
    </update>

    <delete id="deleteHwAreaByAreaId" parameterType="Long">
        delete from hw_area where area_id = #{areaId}
    </delete>

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