<?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.ozs.mapper.VehiclePositionMapper">
    <resultMap id="VehiclePositionResult" type="com.ozs.entity.VehiclePosition">
        <id column="id" property="id"/>
        <result column="vehicle_code" property="vehicleCode"/>
        <result column="terminal_code" property="terminalCode"/>
        <result column="travel_mile" property="travelMile"/>
        <result column="line_dir" property="lineDir"/>
        <result column="railway_code" property="railwayCode"/>
        <result column="current_time" property="currentTime"/>
        <result column="create_time" property="createTime"/>
        <result column="remark" property="remark"/>
        <result column="vehicle_name" property="vehicleName"/>
        <result column="railway_name" property="railwayName"/>
        <result column="status" property="status"/>
    </resultMap>
    <select id="list" resultMap="VehiclePositionResult" >
        SELECT
        a.id,
        a.vehicle_code,
        a.terminal_code,
        a.travel_mile,
        a.line_dir,
        a.railway_code,
        a.current_time,
        a.create_time,
        a.remark,
        b.vehicle_name,
        d.railway_name,
        c.status
        FROM vehicle_position AS a INNER JOIN
        base_vehicle AS b ON a.vehicle_code = b.vehicle_code INNER JOIN
        base_vehicle_terminal c ON a.terminal_code = c.terminal_code INNER JOIN
        base_railway_management d ON a.railway_code = d.railway_code

        <where>
            <if test="vehicleCode != null and vehicleCode != ''">
                and a.vehicle_code = #{vehicleCode}
            </if>
            <if test="railwayCode != null and railwayCode != ''">
                and a.railway_code = #{railwayCode}
            </if>
            <if test="lineDir != null and lineDir != 0">
                and a.line_dir = #{lineDir}
            </if>
            <if test="status != null and status != 0">
                and c.status = #{status}
            </if>
        </where>
        order by create_time desc
    </select>


</mapper>
