<?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.zc.business.mapper.DcDispatchMapper">
    
    <resultMap type="com.zc.business.domain.DcDispatch" id="DcDispatchResult">
        <result property="id"    column="id"    />
        <result property="organizationId"    column="organization_id"    />
        <result property="eventId"    column="event_id"    />
        <result property="dispatchName"    column="dispatch_name"    />
        <result property="dispatchStatus"    column="dispatch_status"    />
        <result property="startTime"    column="start_time"    />
        <result property="endTime"    column="end_time"    />
        <result property="remark"    column="remark"    />
        <result property="organizationName"    column="organization_name"    />
    </resultMap>

    <sql id="selectDcDispatchVo">
        select dc_dispatch.id, organization_id, event_id, dispatch_name, dispatch_status, start_time, end_time, remark,dc_organization.organization_name AS organization_name from dc_dispatch
    </sql>

    <select id="selectDcDispatchList" parameterType="com.zc.business.domain.DcDispatch" resultMap="DcDispatchResult">
        <include refid="selectDcDispatchVo"/>
        <where>  
            <if test="organizationId != null "> and organization_id = #{organizationId}</if>
            <if test="eventId != null  and eventId != ''"> and event_id = #{eventId}</if>
            <if test="dispatchName != null  and dispatchName != ''"> and dispatch_name like concat('%', #{dispatchName}, '%')</if>
            <if test="dispatchStatus != null "> and dispatch_status = #{dispatchStatus}</if>
            <if test="startTime != null "> and start_time = #{startTime}</if>
            <if test="endTime != null "> and end_time = #{endTime}</if>
            <if test="endTime != null and startTime != null">  and start_time BETWEEN #{startTime} and #{endTime}  </if>
        </where>
    </select>
    
    <select id="selectDcDispatchById" parameterType="Long" resultMap="DcDispatchResult">
        <include refid="selectDcDispatchVo"/>
        where id = #{id}
    </select>
    <!--根据事件id获取调度信息记录详细信息-->
    <select id="selectDcDispatchByEventId" parameterType="string" resultMap="DcDispatchResult">
        <include refid="selectDcDispatchVo"/>
        where event_id = #{id}
    </select>
        
    <insert id="insertDcDispatch" parameterType="com.zc.business.domain.DcDispatch">
        insert into dc_dispatch
        <trim prefix="(" suffix=")" suffixOverrides=",">
            <if test="id != null">id,</if>
            <if test="organizationId != null">organization_id,</if>
            <if test="eventId != null and eventId != ''">event_id,</if>
            <if test="dispatchName != null">dispatch_name,</if>
            <if test="dispatchStatus != null">dispatch_status,</if>
            <if test="startTime != null">start_time,</if>
            <if test="endTime != null">end_time,</if>
            <if test="remark != null">remark,</if>
         </trim>
        <trim prefix="values (" suffix=")" suffixOverrides=",">
            <if test="id != null">#{id},</if>
            <if test="organizationId != null">#{organizationId},</if>
            <if test="eventId != null and eventId != ''">#{eventId},</if>
            <if test="dispatchName != null">#{dispatchName},</if>
            <if test="dispatchStatus != null">#{dispatchStatus},</if>
            <if test="startTime != null">#{startTime},</if>
            <if test="endTime != null">#{endTime},</if>
            <if test="remark != null">#{remark},</if>
         </trim>
    </insert>

    <update id="updateDcDispatch" parameterType="com.zc.business.domain.DcDispatch">
        update dc_dispatch
        <trim prefix="SET" suffixOverrides=",">
            <if test="organizationId != null">organization_id = #{organizationId},</if>
            <if test="eventId != null and eventId != ''">event_id = #{eventId},</if>
            <if test="dispatchName != null">dispatch_name = #{dispatchName},</if>
            <if test="dispatchStatus != null">dispatch_status = #{dispatchStatus},</if>
            <if test="startTime != null">start_time = #{startTime},</if>
            <if test="endTime != null">end_time = #{endTime},</if>
            <if test="remark != null">remark = #{remark},</if>
        </trim>
        where id = #{id}
    </update>

    <delete id="deleteDcDispatchById" parameterType="Long">
        delete from dc_dispatch where id = #{id}
    </delete>

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