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

    <resultMap type="KeyProject" id="KeyProjectResult">
        <result property="id"    column="id"    />
        <result property="parentId"    column="parent_id"    />
        <result property="projectName"    column="project_name"    />
        <result property="cameraName"    column="camera_name"    />
        <result property="cameraCode"    column="camera_code"    />
        <result property="presetPoints"    column="preset_points"    />
    </resultMap>

    <sql id="selectKeyProjectVo">
        select id, parent_id, project_name, camera_name, camera_code, preset_points from key_project
    </sql>

    <select id="selectKeyProjectList" parameterType="KeyProject" resultMap="KeyProjectResult">
        <include refid="selectKeyProjectVo"/>
        <where>
            and parent_id != 0
            <if test="projectName != null  and projectName != ''"> and project_name like concat('%', #{projectName}, '%')</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="selectKeyProjectById" parameterType="Long" resultMap="KeyProjectResult">
        <include refid="selectKeyProjectVo"/>
        where id = #{id}
    </select>

    <insert id="insertKeyProject" parameterType="KeyProject">
        insert into key_project
        <trim prefix="(" suffix=")" suffixOverrides=",">
            <if test="id != null">id,</if>
            <if test="parentId != null">parent_id,</if>
            <if test="projectName != null">project_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="projectName != null">#{projectName},</if>
            <if test="cameraName != null">#{cameraName},</if>
            <if test="cameraCode != null">#{cameraCode},</if>
            <if test="presetPoints != null">#{presetPoints},</if>
         </trim>
    </insert>

    <update id="updateKeyProject" parameterType="KeyProject">
        update key_project
        <trim prefix="SET" suffixOverrides=",">
            <if test="parentId != null">parent_id = #{parentId},</if>
            <if test="projectName != null">project_name = #{projectName},</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="deleteKeyProjectById" parameterType="Long">
        delete from key_project where id = #{id}
    </delete>

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

</mapper>
