<?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.basetyre.mapper.BaseCarMapper">
    
    <resultMap type="BaseCar" id="BaseCarResult">
        <result property="id"    column="id"    />
        <result property="companyCode"    column="company_code"    />
        <result property="carQueueId"    column="car_queue_id"    />
        <result property="carTypeId"    column="car_type_id"    />
        <result property="carLicense"    column="car_license"    />
        <result property="carLicenseIn"    column="car_license_in"    />
        <result property="carLicenseParent"    column="car_license_parent"    />
        <result property="carIdParent"    column="car_id_parent"    />
        <result property="userId"    column="user_id"    />
        <result property="userName"    column="user_name"    />
        <result property="deviceId"    column="device_id"    />
        <result property="deviceBindTime"    column="device_bind_time"    />
        <result property="firstChangeDate"    column="first_change_date"    />
        <result property="trailerNum"    column="trailer_num"    />
        <result property="isHandDevice"    column="is_hand_device"    />
        <result property="isHasDevice"    column="is_has_device"    />
        <result property="longitude"    column="longitude"    />
        <result property="latitude"    column="latitude"    />
        <result property="tiresTotal"    column="tires_total"    />
        <result property="isDelete"    column="is_delete"    />
        <result property="createTime"    column="create_time"    />
        <result property="createId"    column="create_id"    />
        <result property="createBy"    column="create_by"    />
        <result property="createName"    column="create_name"    />
        <result property="modifyTime"    column="modify_time"    />
        <result property="modifyId"    column="modify_id"    />
        <result property="modifyBy"    column="modify_by"    />
    </resultMap>

    <sql id="selectBaseCarVo">
        select id, company_code, car_queue_id, car_type_id, car_license, car_license_in, car_license_parent, car_id_parent, user_id, user_name, device_id, device_bind_time, first_change_date, trailer_num, is_hand_device, is_has_device, longitude, latitude, tires_total, is_delete, create_time, create_id, create_by, create_name, modify_time, modify_id, modify_by from base_car
    </sql>
    
    <select id="queryList" parameterType="BaseCar" resultMap="BaseCarResult">
        SELECT
            bc.id,
            bcq.title car_queue_id,
            bct.title car_type_id,
            bc.car_license,
            bc.device_id,
            bc.device_bind_time,
            bc.create_time,
            bc.create_by,
            bc.create_name
        FROM
            base_car bc
            LEFT JOIN base_car_queue bcq ON bc.car_queue_id = bcq.id
            LEFT JOIN base_car_type bct ON bct.id = bc.car_type_id
            <where>
                <if test="carLicense != null  and carLicense != ''"> and  bc.car_license = #{carLicense}</if>
            </where>
    </select>

    <select id="selectBaseCarList" parameterType="BaseCar" resultMap="BaseCarResult">
        <include refid="selectBaseCarVo"/>
        <where>
            <if test="companyCode != null  and companyCode != ''"> and company_code = #{companyCode}</if>
            <if test="carQueueId != null  and carQueueId != ''"> and car_queue_id = #{carQueueId}</if>
            <if test="carTypeId != null  and carTypeId != ''"> and car_type_id = #{carTypeId}</if>
            <if test="carLicense != null  and carLicense != ''"> and car_license = #{carLicense}</if>
            <if test="carLicenseIn != null  and carLicenseIn != ''"> and car_license_in = #{carLicenseIn}</if>
            <if test="carLicenseParent != null  and carLicenseParent != ''"> and car_license_parent = #{carLicenseParent}</if>
            <if test="carIdParent != null  and carIdParent != ''"> and car_id_parent = #{carIdParent}</if>
            <if test="userId != null  and userId != ''"> and user_id = #{userId}</if>
            <if test="userName != null  and userName != ''"> and user_name like concat('%', #{userName}, '%')</if>
            <if test="deviceId != null  and deviceId != ''"> and device_id = #{deviceId}</if>
            <if test="deviceBindTime != null "> and device_bind_time = #{deviceBindTime}</if>
            <if test="firstChangeDate != null "> and first_change_date = #{firstChangeDate}</if>
            <if test="trailerNum != null "> and trailer_num = #{trailerNum}</if>
            <if test="isHandDevice != null "> and is_hand_device = #{isHandDevice}</if>
            <if test="isHasDevice != null "> and is_has_device = #{isHasDevice}</if>
            <if test="longitude != null "> and longitude = #{longitude}</if>
            <if test="latitude != null "> and latitude = #{latitude}</if>
            <if test="tiresTotal != null "> and tires_total = #{tiresTotal}</if>
            <if test="isDelete != null "> and is_delete = #{isDelete}</if>
            <if test="createId != null  and createId != ''"> and create_id = #{createId}</if>
            <if test="createName != null  and createName != ''"> and create_name like concat('%', #{createName}, '%')</if>
            <if test="modifyTime != null "> and modify_time = #{modifyTime}</if>
            <if test="modifyId != null  and modifyId != ''"> and modify_id = #{modifyId}</if>
            <if test="modifyBy != null  and modifyBy != ''"> and modify_by = #{modifyBy}</if>
        </where>
    </select>
    
    <select id="selectBaseCarById" parameterType="String" resultMap="BaseCarResult">
        <include refid="selectBaseCarVo"/>
        where id = #{id}
    </select>
        
    <insert id="insertBaseCar" parameterType="BaseCar">
        insert into base_car
        <trim prefix="(" suffix=")" suffixOverrides=",">
            <if test="id != null">id,</if>
            <if test="companyCode != null">company_code,</if>
            <if test="carQueueId != null">car_queue_id,</if>
            <if test="carTypeId != null">car_type_id,</if>
            <if test="carLicense != null">car_license,</if>
            <if test="carLicenseIn != null">car_license_in,</if>
            <if test="carLicenseParent != null">car_license_parent,</if>
            <if test="carIdParent != null">car_id_parent,</if>
            <if test="userId != null">user_id,</if>
            <if test="userName != null">user_name,</if>
            <if test="deviceId != null">device_id,</if>
            <if test="deviceBindTime != null">device_bind_time,</if>
            <if test="firstChangeDate != null">first_change_date,</if>
            <if test="trailerNum != null">trailer_num,</if>
            <if test="isHandDevice != null">is_hand_device,</if>
            <if test="isHasDevice != null">is_has_device,</if>
            <if test="longitude != null">longitude,</if>
            <if test="latitude != null">latitude,</if>
            <if test="tiresTotal != null">tires_total,</if>
            <if test="isDelete != null">is_delete,</if>
            <if test="createTime != null">create_time,</if>
            <if test="createId != null">create_id,</if>
            <if test="createBy != null">create_by,</if>
            <if test="createName != null">create_name,</if>
            <if test="modifyTime != null">modify_time,</if>
            <if test="modifyId != null">modify_id,</if>
            <if test="modifyBy != null">modify_by,</if>
         </trim>
        <trim prefix="values (" suffix=")" suffixOverrides=",">
            <if test="id != null">#{id},</if>
            <if test="companyCode != null">#{companyCode},</if>
            <if test="carQueueId != null">#{carQueueId},</if>
            <if test="carTypeId != null">#{carTypeId},</if>
            <if test="carLicense != null">#{carLicense},</if>
            <if test="carLicenseIn != null">#{carLicenseIn},</if>
            <if test="carLicenseParent != null">#{carLicenseParent},</if>
            <if test="carIdParent != null">#{carIdParent},</if>
            <if test="userId != null">#{userId},</if>
            <if test="userName != null">#{userName},</if>
            <if test="deviceId != null">#{deviceId},</if>
            <if test="deviceBindTime != null">#{deviceBindTime},</if>
            <if test="firstChangeDate != null">#{firstChangeDate},</if>
            <if test="trailerNum != null">#{trailerNum},</if>
            <if test="isHandDevice != null">#{isHandDevice},</if>
            <if test="isHasDevice != null">#{isHasDevice},</if>
            <if test="longitude != null">#{longitude},</if>
            <if test="latitude != null">#{latitude},</if>
            <if test="tiresTotal != null">#{tiresTotal},</if>
            <if test="isDelete != null">#{isDelete},</if>
            <if test="createTime != null">#{createTime},</if>
            <if test="createId != null">#{createId},</if>
            <if test="createBy != null">#{createBy},</if>
            <if test="createName != null">#{createName},</if>
            <if test="modifyTime != null">#{modifyTime},</if>
            <if test="modifyId != null">#{modifyId},</if>
            <if test="modifyBy != null">#{modifyBy},</if>
         </trim>
    </insert>

    <update id="updateBaseCar" parameterType="BaseCar">
        update base_car
        <trim prefix="SET" suffixOverrides=",">
            <if test="companyCode != null">company_code = #{companyCode},</if>
            <if test="carQueueId != null">car_queue_id = #{carQueueId},</if>
            <if test="carTypeId != null">car_type_id = #{carTypeId},</if>
            <if test="carLicense != null">car_license = #{carLicense},</if>
            <if test="carLicenseIn != null">car_license_in = #{carLicenseIn},</if>
            <if test="carLicenseParent != null">car_license_parent = #{carLicenseParent},</if>
            <if test="carIdParent != null">car_id_parent = #{carIdParent},</if>
            <if test="userId != null">user_id = #{userId},</if>
            <if test="userName != null">user_name = #{userName},</if>
            <if test="deviceId != null">device_id = #{deviceId},</if>
            <if test="deviceBindTime != null">device_bind_time = #{deviceBindTime},</if>
            <if test="firstChangeDate != null">first_change_date = #{firstChangeDate},</if>
            <if test="trailerNum != null">trailer_num = #{trailerNum},</if>
            <if test="isHandDevice != null">is_hand_device = #{isHandDevice},</if>
            <if test="isHasDevice != null">is_has_device = #{isHasDevice},</if>
            <if test="longitude != null">longitude = #{longitude},</if>
            <if test="latitude != null">latitude = #{latitude},</if>
            <if test="tiresTotal != null">tires_total = #{tiresTotal},</if>
            <if test="isDelete != null">is_delete = #{isDelete},</if>
            <if test="createTime != null">create_time = #{createTime},</if>
            <if test="createId != null">create_id = #{createId},</if>
            <if test="createBy != null">create_by = #{createBy},</if>
            <if test="createName != null">create_name = #{createName},</if>
            <if test="modifyTime != null">modify_time = #{modifyTime},</if>
            <if test="modifyId != null">modify_id = #{modifyId},</if>
            <if test="modifyBy != null">modify_by = #{modifyBy},</if>
        </trim>
        where id = #{id}
    </update>

    <delete id="deleteBaseCarById" parameterType="String">
        delete from base_car where id = #{id}
    </delete>

<!--    <delete id="deleteBaseCarByIds" parameterType="String">-->
<!--        delete from base_car where id in -->
<!--        <foreach item="id" collection="array" open="(" separator="," close=")">-->
<!--            #{id}-->
<!--        </foreach>-->
<!--    </delete>-->
    <update id="deleteBaseCarByIds" parameterType="String">

    </update>
</mapper>