<?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.TElectronicFenceMapper">

    <resultMap type="TElectronicFence" id="TElectronicFenceResult">
        <result property="id" column="id"/>
        <result property="name" column="name"/>
        <result property="startTime" column="start_time"/>
        <result property="endTime" column="end_time"/>
        <result property="updateTime" column="update_time"/>
        <result property="createTime" column="create_time"/>
        <result property="eState" column="e_state"/>
        <result property="eType" column="e_type"/>
        <result property="eDesc" column="e_desc"/>
        <result property="gfid" column="gfid"/>
        <result property="delState" column="del_state"/>
        <result property="userId" column="user_id"/>
        <result property="deviceId" column="device_id"/>
        <result property="serviceId" column="service_id"/>
    </resultMap>

    <sql id="selectTElectronicFenceVo">
        select id,
               name,
               start_time,
               end_time,
               update_time,
               create_time,
               e_state,
               e_type,
               e_desc,
               gfid,
               del_state,
               user_id,
               device_id,
               service_id
        from t_electronic_fence
    </sql>

    <select id="selectTElectronicFenceList" parameterType="TElectronicFence" resultMap="TElectronicFenceResult">
        <include refid="selectTElectronicFenceVo"/>
        <where>
            <if test="name != null  and name != ''">and name like concat('%', #{name}, '%')</if>
            <if test="startTime != null ">and start_time = #{startTime}</if>
            <if test="endTime != null ">and end_time = #{endTime}</if>
            <if test="eState != null ">and e_state = #{eState}</if>
            <if test="eType != null ">and e_type = #{eType}</if>
            <if test="eDesc != null  and eDesc != ''">and e_desc = #{eDesc}</if>
            <if test="gfid != null ">and gfid = #{gfid}</if>
            <if test="delState != null ">and del_state = #{delState}</if>
            <if test="userId != null ">and user_id = #{userId}</if>
            <if test="deviceId != null ">and device_id = #{deviceId}</if>
            <if test="serviceId != null ">and service_id = #{serviceId}</if>
        </where>
    </select>

    <select id="selectTElectronicFenceById" parameterType="Long" resultMap="TElectronicFenceResult">
        <include refid="selectTElectronicFenceVo"/>
        where id = #{id}
    </select>

    <select id="selectTElectronicFenceListByDeviceId" parameterType="Long" resultMap="TElectronicFenceResult">
        <include refid="selectTElectronicFenceVo"/>
        WHERE device_id = #{deviceId} AND del_state = 0
    </select>

    <select id="selectTElectronicFenceByDelState" parameterType="integer"
            resultMap="TElectronicFenceResult">
        <include refid="selectTElectronicFenceVo"/>
        WHERE del_state= #{delState}
    </select>

    <insert id="insertTElectronicFence" parameterType="TElectronicFence" useGeneratedKeys="true" keyProperty="id">
        insert into t_electronic_fence
        <trim prefix="(" suffix=")" suffixOverrides=",">
            <if test="name != null and name != ''">name,</if>
            <if test="startTime != null">start_time,</if>
            <if test="endTime != null">end_time,</if>
            <if test="updateTime != null">update_time,</if>
            <if test="createTime != null">create_time,</if>
            <if test="eState != null">e_state,</if>
            <if test="eType != null">e_type,</if>
            <if test="eDesc != null">e_desc,</if>
            <if test="gfid != null">gfid,</if>
            <if test="delState != null">del_state,</if>
            <if test="userId != null">user_id,</if>
            <if test="deviceId != null">device_id,</if>
            <if test="serviceId != null">service_id,</if>
        </trim>
        <trim prefix="values (" suffix=")" suffixOverrides=",">
            <if test="name != null and name != ''">#{name},</if>
            <if test="startTime != null">#{startTime},</if>
            <if test="endTime != null">#{endTime},</if>
            <if test="updateTime != null">#{updateTime},</if>
            <if test="createTime != null">#{createTime},</if>
            <if test="eState != null">#{eState},</if>
            <if test="eType != null">#{eType},</if>
            <if test="eDesc != null">#{eDesc},</if>
            <if test="gfid != null">#{gfid},</if>
            <if test="delState != null">#{delState},</if>
            <if test="userId != null">#{userId},</if>
            <if test="deviceId != null">#{deviceId},</if>
            <if test="serviceId != null">#{serviceId},</if>
        </trim>
    </insert>

    <update id="updateTElectronicFence" parameterType="TElectronicFence">
        update t_electronic_fence
        <trim prefix="SET" suffixOverrides=",">
            <if test="name != null and name != ''">name = #{name},</if>
            <if test="startTime != null">start_time = #{startTime},</if>
            <if test="endTime != null">end_time = #{endTime},</if>
            <if test="updateTime != null">update_time = #{updateTime},</if>
            <if test="createTime != null">create_time = #{createTime},</if>
            <if test="eState != null">e_state = #{eState},</if>
            <if test="eType != null">e_type = #{eType},</if>
            <if test="eDesc != null">desc = #{eDesc},</if>
            <if test="gfid != null">gfid = #{gfid},</if>
            <if test="delState != null">del_state = #{delState},</if>
            <if test="userId != null">user_id = #{userId},</if>
            <if test="deviceId != null">device_id = #{deviceId},</if>
            <if test="serviceId != null">service_id = #{serviceId},</if>
        </trim>
        where id = #{id}
    </update>

    <delete id="deleteTElectronicFenceById" parameterType="Long">
        delete
        from t_electronic_fence
        where id = #{id}
    </delete>

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

    <delete id="deleteTElectronicFenceStateByIds" parameterType="String">
        UPDATE t_electronic_fence SET del_state = 1 WHERE id IN
        <foreach item="id" collection="array" open="(" separator="," close=")">
            #{id}
        </foreach>
    </delete>

    <delete id="deleteTElectronicFenceByGfids">
        delete from t_electronic_fence where gfid in
        <foreach item="gfid" collection="array" open="(" separator="," close=")">
            #{gfid}
        </foreach>
    </delete>
</mapper>