<?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.business.mapper.HwFenceTargetMapper">
    
    <resultMap type="HwFenceTarget" id="HwFenceTargetResult">
        <result property="electronicFenceId"    column="electronic_fence_id"    />
        <result property="targetType"    column="target_type"    />
        <result property="targetId"    column="target_id"    />
    </resultMap>

    <sql id="selectHwFenceTargetVo">
        select electronic_fence_id, target_type, target_id from hw_fence_target
    </sql>

    <select id="selectHwFenceTargetList" parameterType="HwFenceTarget" resultMap="HwFenceTargetResult">
        <include refid="selectHwFenceTargetVo"/>
        <where>  
            <if test="electronicFenceId != null "> and electronic_fence_id = #{electronicFenceId}</if>
            <if test="targetType != null  and targetType != ''"> and target_type = #{targetType}</if>
        </where>
    </select>
    
    <select id="selectHwFenceTargetByTargetId" parameterType="Long" resultMap="HwFenceTargetResult">
        <include refid="selectHwFenceTargetVo"/>
        where target_id = #{targetId}
    </select>
        
    <insert id="insertHwFenceTarget" parameterType="HwFenceTarget">
        insert into hw_fence_target
        <trim prefix="(" suffix=")" suffixOverrides=",">
            <if test="electronicFenceId != null">electronic_fence_id,</if>
            <if test="targetType != null and targetType != ''">target_type,</if>
            <if test="targetId != null">target_id,</if>
         </trim>
        <trim prefix="values (" suffix=")" suffixOverrides=",">
            <if test="electronicFenceId != null">#{electronicFenceId},</if>
            <if test="targetType != null and targetType != ''">#{targetType},</if>
            <if test="targetId != null">#{targetId},</if>
         </trim>
    </insert>

    <update id="updateHwFenceTarget" parameterType="HwFenceTarget">
        update hw_fence_target
        <trim prefix="SET" suffixOverrides=",">
            <if test="electronicFenceId != null">electronic_fence_id = #{electronicFenceId},</if>
            <if test="targetType != null and targetType != ''">target_type = #{targetType},</if>
        </trim>
        where target_id = #{targetId}
    </update>

    <delete id="deleteHwFenceTargetByTargetId" parameterType="Long">
        delete from hw_fence_target where target_id = #{targetId}
    </delete>

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