<?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.mapper.SysCarMapper">
    <select id="selectSysCarVoList" resultType="com.muyu.domain.resp.SysCarVo">
        SELECT * ,car_type.type_name,tb_fence.fence_name
        FROM `sys_car`
        LEFT JOIN car_type ON sys_car.car_type_id=car_type.id
        LEFT JOIN tb_fence ON sys_car.fence_id=tb_fence.fence_id
        <where>
            <if test="carVin!=null and carVin!=''">
                sys_car.car_vin=#{carVin}
            </if>
            <if test="state!=null and state!=''">
              and  sys_car.state=#{state}
            </if>
            <if test="carMotorManufacturer!=null and carMotorManufacturer!=''">
             and  sys_car.car_motor_manufacturer=#{carMotorManufacturer}
            </if>
            <if test="carBatteryManufacturer!=null and carBatteryManufacturer!=''">
                and  sys_car.car_battery_manufacturer=#{carBatteryManufacturer}
            </if>
            <if test="carMotorModel!=null and carMotorModel!=''">
                and  sys_car.car_motor_model=#{carMotorModel}
            </if>
            <if test="carBatteryModel!=null and carBatteryModel!=''">
                and  sys_car.car_battery_model=#{carBatteryModel}
            </if>
        </where>
    </select>


    <select id="selectSysCarVoById" resultType="com.muyu.domain.resp.SysCarVo">
        SELECT * ,car_type.type_name,tb_fence.fence_name
        FROM `sys_car`
                 LEFT JOIN car_type ON sys_car.car_type_id=car_type.id
                 LEFT JOIN tb_fence ON sys_car.fence_id=tb_fence.fence_id
        where sys_car.id=#{id}
    </select>
    <select id="findFenceByCarVin" resultType="com.muyu.domain.SysCarFaultLog">
        SELECT
            *
        FROM
            sys_car_fault_log
        WHERE
            vin = #{carVin};
    </select>

</mapper>
