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

    <resultMap type="KeyAreas" id="KeyAreasResult">
        <result property="id"    column="id"    />
        <result property="parentId"    column="parent_id"    />
        <result property="areasName"    column="areas_name"    />
        <result property="cameraName"    column="camera_name"    />
        <result property="cameraCode"    column="camera_code"    />
        <result property="presetPoints"    column="preset_points"    />
    </resultMap>

    <sql id="selectKeyAreasVo">
        select id, parent_id, areas_name, camera_name, camera_code, preset_points from key_areas
    </sql>

    <select id="selectKeyAreasList" parameterType="KeyAreas" resultMap="KeyAreasResult">
        <include refid="selectKeyAreasVo"/>
        <where>
            and parent_id != 0
            <if test="areasName != null  and areasName != ''"> and areas_name like concat('%', #{areasName}, '%')</if>
            <if test="cameraName != null  and cameraName != ''"> and camera_name like concat('%', #{cameraName}, '%')</if>
            <if test="cameraCode != null  and cameraCode != ''"> and camera_code like concat('%', #{cameraCode}, '%')</if>
            <if test="presetPoints != null "> and preset_points like concat('%', #{presetPoints}, '%')</if>
        </where>
    </select>

    <select id="selectKeyAreasById" parameterType="Long" resultMap="KeyAreasResult">
        <include refid="selectKeyAreasVo"/>
        where id = #{id}
    </select>

    <insert id="insertKeyAreas" parameterType="KeyAreas">
        insert into key_areas
        <trim prefix="(" suffix=")" suffixOverrides=",">
            <if test="id != null">id,</if>
            <if test="parentId != null">parent_id,</if>
            <if test="areasName != null">areas_name,</if>
            <if test="cameraName != null">camera_name,</if>
            <if test="cameraCode != null">camera_code,</if>
            <if test="presetPoints != null">preset_points,</if>
         </trim>
        <trim prefix="values (" suffix=")" suffixOverrides=",">
            <if test="id != null">#{id},</if>
            <if test="parentId != null">#{parentId},</if>
            <if test="areasName != null">#{areasName},</if>
            <if test="cameraName != null">#{cameraName},</if>
            <if test="cameraCode != null">#{cameraCode},</if>
            <if test="presetPoints != null">#{presetPoints},</if>
         </trim>
    </insert>

    <update id="updateKeyAreas" parameterType="KeyAreas">
        update key_areas
        <trim prefix="SET" suffixOverrides=",">
            <if test="parentId != null">parent_id = #{parentId},</if>
            <if test="areasName != null">areas_name = #{areasName},</if>
            <if test="cameraName != null">camera_name = #{cameraName},</if>
            <if test="cameraCode != null">camera_code = #{cameraCode},</if>
            <if test="presetPoints != null">preset_points = #{presetPoints},</if>
        </trim>
        where id = #{id}
    </update>

    <delete id="deleteKeyAreasById" parameterType="Long">
        delete from key_areas where id = #{id}
    </delete>

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

</mapper>
