<?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.ruoyi.business.mapper.VehicleMapper">
    
    <resultMap type="Vehicle" id="VehicleResult">
        <result property="vehicleId"    column="vehicle_id"    />
        <result property="orderId"    column="order_id"    />
        <result property="finishNum"    column="finish_num"    />
        <result property="vehicleInTime"    column="vehicle_in_time"    />
        <result property="vehicleOutTime"    column="vehicle_out_time"    />
        <result property="status"    column="status"    />
        <result property="standCode"    column="stand_code"    />
        <result property="standId"    column="stand_id"    />
    </resultMap>

    <sql id="selectVehicleVo">
        select vehicle_id, order_id, finish_num, vehicle_in_time, vehicle_out_time, status, stand_code, stand_id from vehicle
    </sql>

    <select id="selectVehicleList" parameterType="Vehicle" resultMap="VehicleResult">
        <include refid="selectVehicleVo"/>
        <where>  
            <if test="vehicleId != null  and vehicleId != ''"> and vehicle_id = #{vehicleId}</if>
            <if test="orderId != null  and orderId != ''"> and order_id = #{orderId}</if>
            <if test="finishNum != null "> and finish_num = #{finishNum}</if>
            <if test="vehicleInTime != null "> and vehicle_in_time = #{vehicleInTime}</if>
            <if test="vehicleOutTime != null "> and vehicle_out_time = #{vehicleOutTime}</if>
            <if test="status != null  and status != ''"> and status = #{status}</if>
            <if test="standId != null  and standId != ''"> and stand_id = #{standId}</if>
        </where>
        order by status
    </select>
    
    <select id="selectVehicleByVehicleId" parameterType="String" resultMap="VehicleResult">
        <include refid="selectVehicleVo"/>
        where vehicle_id = #{vehicleId}
    </select>
        
    <insert id="insertVehicle" parameterType="Vehicle">
        insert into vehicle
        <trim prefix="(" suffix=")" suffixOverrides=",">
            <if test="vehicleId != null">vehicle_id,</if>
            <if test="orderId != null">order_id,</if>
            <if test="finishNum != null">finish_num,</if>
            <if test="vehicleInTime != null">vehicle_in_time,</if>
            <if test="vehicleOutTime != null">vehicle_out_time,</if>
            <if test="status != null">status,</if>
            <if test="standCode != null">stand_code,</if>
            <if test="standId != null">stand_id,</if>
         </trim>
        <trim prefix="values (" suffix=")" suffixOverrides=",">
            <if test="vehicleId != null">#{vehicleId},</if>
            <if test="orderId != null">#{orderId},</if>
            <if test="finishNum != null">#{finishNum},</if>
            <if test="vehicleInTime != null">#{vehicleInTime},</if>
            <if test="vehicleOutTime != null">#{vehicleOutTime},</if>
            <if test="status != null">#{status},</if>
            <if test="standCode != null">#{standCode},</if>
            <if test="standId != null">#{standId},</if>
         </trim>
    </insert>

    <update id="updateVehicle" parameterType="Vehicle">
        update vehicle
        <trim prefix="SET" suffixOverrides=",">
            <if test="orderId != null">order_id = #{orderId},</if>
            <if test="finishNum != null">finish_num = #{finishNum},</if>
            <if test="vehicleInTime != null">vehicle_in_time = #{vehicleInTime},</if>
            <if test="vehicleOutTime != null">vehicle_out_time = #{vehicleOutTime},</if>
            <if test="status != null">status = #{status},</if>
            <if test="standCode != null">stand_code = #{standCode},</if>
            <if test="standId != null">stand_id = #{standId},</if>
        </trim>
        where vehicle_id = #{vehicleId}
    </update>

    <update id="updateVehicleStsByVehicleIds" parameterType="String">
        update vehicle set status = "1", vehicle_out_time=current_time
        where vehicle_id in
        <foreach item="vehicleId" collection="array" open="(" separator="," close=")">
            #{vehicleId}
        </foreach>
    </update>

    <delete id="deleteVehicleByVehicleId" parameterType="String">
        delete from vehicle where vehicle_id = #{vehicleId}
    </delete>

    <delete id="deleteVehicleByVehicleIds" parameterType="String">
        delete from vehicle where vehicle_id in 
        <foreach item="vehicleId" collection="array" open="(" separator="," close=")">
            #{vehicleId}
        </foreach>
    </delete>

</mapper>