<?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.muyu.car.mapper.SysCarMapper">

    <!--    车辆列表    -->
    <select id="carList" resultType="com.muyu.car.domain.vo.CarVO">
        SELECT
        tc.*,
        tt.energy_type,
        tt.gear_type,
        tt.type_name
        FROM
        `t_car` tc
        LEFT JOIN `t_type` tt ON tc.type_id = tt.type_id
        <where>
            <if test="carVin != null and carVin != ''">
                and tc.car_vin = #{carVin}
            </if>
            <if test="typeName != null and typeName != ''">
                and tt.type_name like concat('%',#{typeName},'%')
            </if>
            <if test="energyType != null and energyType > 0 ">
                and tt.energy_type = #{energyType}
            </if>
            <if test="gearType != null and gearType > 0 ">
                and tt.gear_type = #{gearType}
            </if>
        </where>
    </select>

    <select id="CarListShow" resultType="com.muyu.car.domain.vo.CarVO">
        SELECT
        tc.*,
        tt.energy_type,
        tt.gear_type,
        tt.type_name
        FROM
        `t_car` tc
        LEFT JOIN `t_type` tt ON tc.type_id = tt.type_id
        <where>
            <if test="carVin != null and carVin != ''">
                and tc.car_vin = #{carVin}
            </if>
            <if test="carLastJoinTime != null and carLastJoinTime != ''">
                and tc.car_last_join_time = #{carLastJoinTime}
            </if>
            <if test="carLastOfflineTime != null and carLastOfflineTime != ''">
                and tc.car_last_offline_time = #{carVin}
            </if>
            <if test="typeName != null and typeName != ''">
                and tt.type_name like concat('%',#{typeName},'%')
            </if>
            <if test="energyType != null and energyType > 0 ">
                and tt.energy_type = #{energyType}
            </if>
            <if test="gearType != null and gearType > 0 ">
                and tt.gear_type = #{gearType}
            </if>

        </where>
    </select>

    <!--    通过id查询    -->
    <select id="CarListShowByCarId" resultType="com.muyu.car.domain.vo.CarVO">
        SELECT
            tc.*,
            tt.energy_type,
            tt.gear_type,
            tt.type_name
        FROM
            `t_car` tc
                LEFT JOIN `t_type` tt ON tc.type_id = tt.type_id
            where tc.car_id = #{carId}
    </select>

</mapper>
