<?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.ximai.mes.md.mapper.MdVehicleDispatchMapper">

    <resultMap type="MdVehicleDispatch" id="MdVehicleDispatchResult">
        <result property="dispatchId"    column="dispatch_id"    />
        <result property="dispatchCode"    column="dispatch_code"    />
        <result property="dispatchTitle"    column="dispatch_title"    />
        <result property="vehicleId"    column="vehicle_id"    />
        <result property="dispatchBy"    column="dispatch_by"    />
        <result property="driverBy"    column="driver_by"    />
        <result property="dispatchDate"    column="dispatch_date"    />
        <result property="backDate"    column="back_date"    />
        <result property="travelMileage"    column="travel_mileage"    />
        <result property="startMileage"    column="start_mileage"    />
        <result property="endMileage"    column="end_mileage"    />
        <result property="oilConsumption"    column="oil_consumption"    />
        <result property="remark"    column="remark"    />
        <result property="status"    column="status"    />
        <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="selectMdVehicleDispatchVo">
        select dispatch_id, dispatch_code, dispatch_title, vehicle_id, dispatch_by, driver_by, dispatch_date, back_date, travel_mileage, start_mileage, end_mileage, oil_consumption, remark, status, create_by, create_time, update_by, update_time from md_vehicle_dispatch
    </sql>

    <select id="selectMdVehicleDispatchList" parameterType="MdVehicleDispatch" resultMap="MdVehicleDispatchResult">
        <include refid="selectMdVehicleDispatchVo"/>
        <where>
            <if test="dispatchCode != null  and dispatchCode != ''"> and dispatch_code = #{dispatchCode}</if>
            <if test="dispatchTitle != null  and dispatchTitle != ''"> and dispatch_title = #{dispatchTitle}</if>
            <if test="vehicleId != null "> and vehicle_id = #{vehicleId}</if>
            <if test="dispatchBy != null  and dispatchBy != ''"> and dispatch_by = #{dispatchBy}</if>
            <if test="driverBy != null  and driverBy != ''"> and driver_by = #{driverBy}</if>
            <if test="params.beginDispatchDate != null and params.beginDispatchDate != '' and params.endDispatchDate != null and params.endDispatchDate != ''"> and dispatch_date between #{params.beginDispatchDate} and #{params.endDispatchDate}</if>
            <if test="params.beginBackDate != null and params.beginBackDate != '' and params.endBackDate != null and params.endBackDate != ''"> and back_date between #{params.beginBackDate} and #{params.endBackDate}</if>
            <if test="travelMileage != null "> and travel_mileage = #{travelMileage}</if>
            <if test="startMileage != null "> and start_mileage = #{startMileage}</if>
            <if test="endMileage != null "> and end_mileage = #{endMileage}</if>
            <if test="oilConsumption != null "> and oil_consumption = #{oilConsumption}</if>
            <if test="status != null "> and status = #{status}</if>
        </where>
    </select>

    <select id="selectMdVehicleDispatchByDispatchId" parameterType="Long" resultMap="MdVehicleDispatchResult">
        <include refid="selectMdVehicleDispatchVo"/>
        where dispatch_id = #{dispatchId}
    </select>

    <insert id="insertMdVehicleDispatch" parameterType="MdVehicleDispatch" useGeneratedKeys="true" keyProperty="dispatchId">
        insert into md_vehicle_dispatch
        <trim prefix="(" suffix=")" suffixOverrides=",">
            <if test="dispatchCode != null">dispatch_code,</if>
            <if test="dispatchTitle != null">dispatch_title,</if>
            <if test="vehicleId != null">vehicle_id,</if>
            <if test="dispatchBy != null">dispatch_by,</if>
            <if test="driverBy != null">driver_by,</if>
            <if test="dispatchDate != null">dispatch_date,</if>
            <if test="backDate != null">back_date,</if>
            <if test="travelMileage != null">travel_mileage,</if>
            <if test="startMileage != null">start_mileage,</if>
            <if test="endMileage != null">end_mileage,</if>
            <if test="oilConsumption != null">oil_consumption,</if>
            <if test="remark != null">remark,</if>
            <if test="status != null">status,</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="dispatchCode != null">#{dispatchCode},</if>
            <if test="dispatchTitle != null">#{dispatchTitle},</if>
            <if test="vehicleId != null">#{vehicleId},</if>
            <if test="dispatchBy != null">#{dispatchBy},</if>
            <if test="driverBy != null">#{driverBy},</if>
            <if test="dispatchDate != null">#{dispatchDate},</if>
            <if test="backDate != null">#{backDate},</if>
            <if test="travelMileage != null">#{travelMileage},</if>
            <if test="startMileage != null">#{startMileage},</if>
            <if test="endMileage != null">#{endMileage},</if>
            <if test="oilConsumption != null">#{oilConsumption},</if>
            <if test="remark != null">#{remark},</if>
            <if test="status != null">#{status},</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="updateMdVehicleDispatch" parameterType="MdVehicleDispatch">
        update md_vehicle_dispatch
        <trim prefix="SET" suffixOverrides=",">
            <if test="dispatchCode != null">dispatch_code = #{dispatchCode},</if>
            <if test="dispatchTitle != null">dispatch_title = #{dispatchTitle},</if>
            <if test="vehicleId != null">vehicle_id = #{vehicleId},</if>
            <if test="dispatchBy != null">dispatch_by = #{dispatchBy},</if>
            <if test="driverBy != null">driver_by = #{driverBy},</if>
            <if test="dispatchDate != null">dispatch_date = #{dispatchDate},</if>
            <if test="backDate != null">back_date = #{backDate},</if>
            <if test="travelMileage != null">travel_mileage = #{travelMileage},</if>
            <if test="startMileage != null">start_mileage = #{startMileage},</if>
            <if test="endMileage != null">end_mileage = #{endMileage},</if>
            <if test="oilConsumption != null">oil_consumption = #{oilConsumption},</if>
            <if test="remark != null">remark = #{remark},</if>
            <if test="status != null">status = #{status},</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 dispatch_id = #{dispatchId}
    </update>

    <delete id="deleteMdVehicleDispatchByDispatchId" parameterType="Long">
        delete from md_vehicle_dispatch where dispatch_id = #{dispatchId}
    </delete>

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