<?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.ScheduleMapper">
    
    <resultMap type="Schedule" id="ScheduleResult">
        <result property="scheduleId"    column="schedule_id"    />
        <result property="number"    column="number"    />
        <result property="type"    column="type"    />
        <result property="cycle"    column="cycle"    />
        <result property="station"    column="station"    />
        <result property="status"    column="status"    />
        <result property="isTimeout"    column="is_timeout"    />
        <result property="name"    column="name"    />
        <result property="source"    column="source"    />
        <result property="content"    column="content"    />
        <result property="startTime"    column="start_time"    />
        <result property="endTime"    column="end_time"    />
        <result property="firstReminder"    column="first_reminder"    />
        <result property="secondReminder"    column="second_reminder"    />
        <result property="operator"    column="operator"    />
        <result property="commencementTime"    column="commencement_time"    />
        <result property="terminator"    column="terminator"    />
        <result property="resolutionTime"    column="resolution_time"    />
        <result property="resolutionContent"    column="resolution_content"    />
        <result property="preparedBy"    column="prepared_by"    />
        <result property="head"    column="head"    />
        <result property="remark"    column="remark"    />
        <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="selectScheduleVo">
        select schedule_id, number, type, cycle, station, status, is_timeout, name, source, content, start_time, end_time, first_reminder, second_reminder, operator, commencement_time, terminator, resolution_time, resolution_content, prepared_by, head, remark, create_by, create_time, update_by, update_time from schedule
    </sql>

    <select id="selectScheduleList" parameterType="Schedule" resultMap="ScheduleResult">
        <include refid="selectScheduleVo"/>
        <where>  
            <if test="number != null  and number != ''"> and number = #{number}</if>
            <if test="type != null  and type != ''"> and type = #{type}</if>
            <if test="cycle != null  and cycle != ''"> and cycle = #{cycle}</if>
            <if test="station != null  and station != ''"> and station = #{station}</if>
            <if test="status != null  and status != ''"> and status = #{status}</if>
            <if test="isTimeout != null  and isTimeout != ''"> and is_timeout = #{isTimeout}</if>
            <if test="name != null  and name != ''"> and name like concat('%', #{name}, '%')</if>
            <if test="source != null  and source != ''"> and source = #{source}</if>
            <if test="content != null  and content != ''"> and content = #{content}</if>
            <if test="startTime != null "> and start_time = #{startTime}</if>
            <if test="endTime != null "> and end_time = #{endTime}</if>
            <if test="firstReminder != null "> and first_reminder = #{firstReminder}</if>
            <if test="secondReminder != null "> and second_reminder = #{secondReminder}</if>
            <if test="operator != null  and operator != ''"> and operator = #{operator}</if>
            <if test="commencementTime != null "> and commencement_time = #{commencementTime}</if>
            <if test="terminator != null  and terminator != ''"> and terminator = #{terminator}</if>
            <if test="resolutionTime != null "> and resolution_time = #{resolutionTime}</if>
            <if test="resolutionContent != null  and resolutionContent != ''"> and resolution_content = #{resolutionContent}</if>
            <if test="preparedBy != null  and preparedBy != ''"> and prepared_by = #{preparedBy}</if>
            <if test="head != null  and head != ''"> and head = #{head}</if>
        </where>
    </select>
    
    <select id="selectScheduleByScheduleId" parameterType="Long" resultMap="ScheduleResult">
        <include refid="selectScheduleVo"/>
        where schedule_id = #{scheduleId}
    </select>
        
    <insert id="insertSchedule" parameterType="Schedule">
        insert into schedule
        <trim prefix="(" suffix=")" suffixOverrides=",">
            <if test="scheduleId != null">schedule_id,</if>
            <if test="number != null">number,</if>
            <if test="type != null">type,</if>
            <if test="cycle != null">cycle,</if>
            <if test="station != null">station,</if>
            <if test="status != null">status,</if>
            <if test="isTimeout != null">is_timeout,</if>
            <if test="name != null">name,</if>
            <if test="source != null">source,</if>
            <if test="content != null">content,</if>
            <if test="startTime != null">start_time,</if>
            <if test="endTime != null">end_time,</if>
            <if test="firstReminder != null">first_reminder,</if>
            <if test="secondReminder != null">second_reminder,</if>
            <if test="operator != null">operator,</if>
            <if test="commencementTime != null">commencement_time,</if>
            <if test="terminator != null">terminator,</if>
            <if test="resolutionTime != null">resolution_time,</if>
            <if test="resolutionContent != null">resolution_content,</if>
            <if test="preparedBy != null">prepared_by,</if>
            <if test="head != null">head,</if>
            <if test="remark != null">remark,</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="scheduleId != null">#{scheduleId},</if>
            <if test="number != null">#{number},</if>
            <if test="type != null">#{type},</if>
            <if test="cycle != null">#{cycle},</if>
            <if test="station != null">#{station},</if>
            <if test="status != null">#{status},</if>
            <if test="isTimeout != null">#{isTimeout},</if>
            <if test="name != null">#{name},</if>
            <if test="source != null">#{source},</if>
            <if test="content != null">#{content},</if>
            <if test="startTime != null">#{startTime},</if>
            <if test="endTime != null">#{endTime},</if>
            <if test="firstReminder != null">#{firstReminder},</if>
            <if test="secondReminder != null">#{secondReminder},</if>
            <if test="operator != null">#{operator},</if>
            <if test="commencementTime != null">#{commencementTime},</if>
            <if test="terminator != null">#{terminator},</if>
            <if test="resolutionTime != null">#{resolutionTime},</if>
            <if test="resolutionContent != null">#{resolutionContent},</if>
            <if test="preparedBy != null">#{preparedBy},</if>
            <if test="head != null">#{head},</if>
            <if test="remark != null">#{remark},</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="updateSchedule" parameterType="Schedule">
        update schedule
        <trim prefix="SET" suffixOverrides=",">
            <if test="number != null">number = #{number},</if>
            <if test="type != null">type = #{type},</if>
            <if test="cycle != null">cycle = #{cycle},</if>
            <if test="station != null">station = #{station},</if>
            <if test="status != null">status = #{status},</if>
            <if test="isTimeout != null">is_timeout = #{isTimeout},</if>
            <if test="name != null">name = #{name},</if>
            <if test="source != null">source = #{source},</if>
            <if test="content != null">content = #{content},</if>
            <if test="startTime != null">start_time = #{startTime},</if>
            <if test="endTime != null">end_time = #{endTime},</if>
            <if test="firstReminder != null">first_reminder = #{firstReminder},</if>
            <if test="secondReminder != null">second_reminder = #{secondReminder},</if>
            <if test="operator != null">operator = #{operator},</if>
            <if test="commencementTime != null">commencement_time = #{commencementTime},</if>
            <if test="terminator != null">terminator = #{terminator},</if>
            <if test="resolutionTime != null">resolution_time = #{resolutionTime},</if>
            <if test="resolutionContent != null">resolution_content = #{resolutionContent},</if>
            <if test="preparedBy != null">prepared_by = #{preparedBy},</if>
            <if test="head != null">head = #{head},</if>
            <if test="remark != null">remark = #{remark},</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 schedule_id = #{scheduleId}
    </update>

    <delete id="deleteScheduleByScheduleId" parameterType="Long">
        delete from schedule where schedule_id = #{scheduleId}
    </delete>

    <delete id="deleteScheduleByScheduleIds" parameterType="String">
        delete from schedule where schedule_id in 
        <foreach item="scheduleId" collection="array" open="(" separator="," close=")">
            #{scheduleId}
        </foreach>
    </delete>
</mapper>