<?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.inspect.guideline.mapper.PatrolGuidelineMapper">

    <resultMap type="PatrolGuideline" id="PatrolGuidelineResult">
        <result property="guidelineId" column="guideline_id"/>
        <result property="classId" column="class_id"/>
        <result property="name" column="name"/>
        <result property="isEnable" column="is_enable"/>
        <result property="createTime" column="create_time"/>
    </resultMap>

    <sql id="selectPatrolGuidelineVo">
        select guideline_id, class_id, name, is_enable, create_time
        from patrol_guideline
    </sql>

    <select id="selectPatrolGuidelineList" parameterType="PatrolGuideline" resultMap="PatrolGuidelineResult">
        <include refid="selectPatrolGuidelineVo"/>
        <where>
            <if test="classId != null  and classId != ''">and class_id = #{classId}</if>
            <if test="name != null  and name != ''">and name like concat('%', #{name}, '%')</if>
            <if test="isEnable != null  and isEnable != ''">and is_enable = #{isEnable}</if>
        </where>
        order by guideline_id
    </select>

    <select id="selectPatrolGuidelineByGuidelineId" parameterType="Long" resultMap="PatrolGuidelineResult">
        <include refid="selectPatrolGuidelineVo"/>
        where guideline_id = #{guidelineId}
    </select>

    <insert id="insertPatrolGuideline" parameterType="PatrolGuideline" useGeneratedKeys="true"
            keyProperty="guidelineId">
        insert into patrol_guideline
        <trim prefix="(" suffix=")" suffixOverrides=",">
            <if test="classId != null">class_id,</if>
            <if test="name != null">name,</if>
            <if test="isEnable != null">is_enable,</if>
            <if test="createTime != null">create_time,</if>
        </trim>
        <trim prefix="values (" suffix=")" suffixOverrides=",">
            <if test="classId != null">#{classId},</if>
            <if test="name != null">#{name},</if>
            <if test="isEnable != null">#{isEnable},</if>
            <if test="createTime != null">#{createTime},</if>
        </trim>
    </insert>

    <update id="updatePatrolGuideline" parameterType="PatrolGuideline">
        update patrol_guideline
        <trim prefix="SET" suffixOverrides=",">
            <if test="classId != null">class_id = #{classId},</if>
            <if test="name != null">name = #{name},</if>
            <if test="isEnable != null">is_enable = #{isEnable},</if>
            <if test="createTime != null">create_time = #{createTime},</if>
        </trim>
        where guideline_id = #{guidelineId}
    </update>

    <delete id="deletePatrolGuidelineByGuidelineId" parameterType="Long">
        delete
        from patrol_guideline
        where guideline_id = #{guidelineId}
    </delete>

    <delete id="deletePatrolGuidelineByGuidelineIds" parameterType="String">
        delete from patrol_guideline where guideline_id in
        <foreach item="guidelineId" collection="array" open="(" separator="," close=")">
            #{guidelineId}
        </foreach>
    </delete>
</mapper>