<?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.dataprocess.mapper.HwFenceAreaMapper">
    
    <resultMap type="HwFenceArea" id="HwFenceAreaResult">
        <result property="fenceAreaId"    column="fence_area_id"    />
        <result property="electronicFenceId"    column="electronic_fence_id"    />
        <result property="areaShapeFlag"    column="area_shape_flag"    />
        <result property="areaRange"    column="area_range"    />
    </resultMap>

    <sql id="selectHwFenceAreaVo">
        select fence_area_id, electronic_fence_id, area_shape_flag, area_range from hw_fence_area
    </sql>

    <select id="selectHwFenceAreaList" parameterType="HwFenceArea" resultMap="HwFenceAreaResult">
        <include refid="selectHwFenceAreaVo"/>
        <where>  
            <if test="electronicFenceId != null "> and electronic_fence_id = #{electronicFenceId}</if>
            <if test="areaShapeFlag != null  and areaShapeFlag != ''"> and area_shape_flag = #{areaShapeFlag}</if>
            <if test="areaRange != null  and areaRange != ''"> and area_range = #{areaRange}</if>
        </where>
    </select>
    
    <select id="selectHwFenceAreaByFenceAreaId" parameterType="Long" resultMap="HwFenceAreaResult">
        <include refid="selectHwFenceAreaVo"/>
        where fence_area_id = #{fenceAreaId}
    </select>
        
    <insert id="insertHwFenceArea" parameterType="HwFenceArea" useGeneratedKeys="true" keyProperty="fenceAreaId">
        insert into hw_fence_area
        <trim prefix="(" suffix=")" suffixOverrides=",">
            <if test="electronicFenceId != null">electronic_fence_id,</if>
            <if test="areaShapeFlag != null and areaShapeFlag != ''">area_shape_flag,</if>
            <if test="areaRange != null">area_range,</if>
         </trim>
        <trim prefix="values (" suffix=")" suffixOverrides=",">
            <if test="electronicFenceId != null">#{electronicFenceId},</if>
            <if test="areaShapeFlag != null and areaShapeFlag != ''">#{areaShapeFlag},</if>
            <if test="areaRange != null">#{areaRange},</if>
         </trim>
    </insert>

    <update id="updateHwFenceArea" parameterType="HwFenceArea">
        update hw_fence_area
        <trim prefix="SET" suffixOverrides=",">
            <if test="electronicFenceId != null">electronic_fence_id = #{electronicFenceId},</if>
            <if test="areaShapeFlag != null and areaShapeFlag != ''">area_shape_flag = #{areaShapeFlag},</if>
            <if test="areaRange != null">area_range = #{areaRange},</if>
        </trim>
        where fence_area_id = #{fenceAreaId}
    </update>

    <delete id="deleteHwFenceAreaByFenceAreaId" parameterType="Long">
        delete from hw_fence_area where fence_area_id = #{fenceAreaId}
    </delete>

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