<?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.xinda.itsm.mapper.PrePlanMapper">
    
    <resultMap type="PrePlan" id="PrePlanResult">
        <result property="prePlanId"    column="pre_plan_id"    />
        <result property="number"    column="number"    />
        <result property="type"    column="type"    />
        <result property="station"    column="station"    />
        <result property="device"    column="device"    />
        <result property="content"    column="content"    />
        <result property="preparedBy"    column="prepared_by"    />
        <result property="keywords"    column="keywords"    />
        <result property="createBy"    column="create_by"    />
        <result property="createTime"    column="create_time"    />
        <result property="updateBy"    column="update_by"    />
        <result property="updateTime"    column="update_time"    />
    </resultMap>

    <sql id="selectPrePlanVo">
        select pre_plan_id, number, type, station, device, content, prepared_by, keywords, create_by, create_time, update_by, update_time from pre_plan
    </sql>

    <select id="selectPrePlanList" parameterType="PrePlan" resultMap="PrePlanResult">
        <include refid="selectPrePlanVo"/>
        <where>  
            <if test="number != null  and number != ''"> and number = #{number}</if>
            <if test="type != null  and type != ''"> and type = #{type}</if>
            <if test="station != null  and station != ''"> and station = #{station}</if>
            <if test="device != null  and device != ''"> and device = #{device}</if>
            <if test="content != null  and content != ''"> and content = #{content}</if>
            <if test="preparedBy != null  and preparedBy != ''"> and prepared_by = #{preparedBy}</if>
            <if test="keywords != null  and keywords != ''"> and keywords = #{keywords}</if>
        </where>
    </select>
    
    <select id="selectPrePlanByPrePlanId" parameterType="Long" resultMap="PrePlanResult">
        <include refid="selectPrePlanVo"/>
        where pre_plan_id = #{prePlanId}
    </select>
        
    <insert id="insertPrePlan" parameterType="PrePlan">
        insert into pre_plan
        <trim prefix="(" suffix=")" suffixOverrides=",">
            <if test="prePlanId != null">pre_plan_id,</if>
            <if test="number != null">number,</if>
            <if test="type != null">type,</if>
            <if test="station != null">station,</if>
            <if test="device != null">device,</if>
            <if test="content != null">content,</if>
            <if test="preparedBy != null">prepared_by,</if>
            <if test="keywords != null">keywords,</if>
            <if test="createBy != null">create_by,</if>
            <if test="createTime != null">create_time,</if>
            <if test="updateBy != null">update_by,</if>
            <if test="updateTime != null">update_time,</if>
         </trim>
        <trim prefix="values (" suffix=")" suffixOverrides=",">
            <if test="prePlanId != null">#{prePlanId},</if>
            <if test="number != null">#{number},</if>
            <if test="type != null">#{type},</if>
            <if test="station != null">#{station},</if>
            <if test="device != null">#{device},</if>
            <if test="content != null">#{content},</if>
            <if test="preparedBy != null">#{preparedBy},</if>
            <if test="keywords != null">#{keywords},</if>
            <if test="createBy != null">#{createBy},</if>
            <if test="createTime != null">#{createTime},</if>
            <if test="updateBy != null">#{updateBy},</if>
            <if test="updateTime != null">#{updateTime},</if>
         </trim>
    </insert>

    <update id="updatePrePlan" parameterType="PrePlan">
        update pre_plan
        <trim prefix="SET" suffixOverrides=",">
            <if test="number != null">number = #{number},</if>
            <if test="type != null">type = #{type},</if>
            <if test="station != null">station = #{station},</if>
            <if test="device != null">device = #{device},</if>
            <if test="content != null">content = #{content},</if>
            <if test="preparedBy != null">prepared_by = #{preparedBy},</if>
            <if test="keywords != null">keywords = #{keywords},</if>
            <if test="createBy != null">create_by = #{createBy},</if>
            <if test="createTime != null">create_time = #{createTime},</if>
            <if test="updateBy != null">update_by = #{updateBy},</if>
            <if test="updateTime != null">update_time = #{updateTime},</if>
        </trim>
        where pre_plan_id = #{prePlanId}
    </update>

    <delete id="deletePrePlanByPrePlanId" parameterType="Long">
        delete from pre_plan where pre_plan_id = #{prePlanId}
    </delete>

    <delete id="deletePrePlanByPrePlanIds" parameterType="String">
        delete from pre_plan where pre_plan_id in 
        <foreach item="prePlanId" collection="array" open="(" separator="," close=")">
            #{prePlanId}
        </foreach>
    </delete>
</mapper>