<?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.sckw.truck.mapper.KwBusinessTruckMapper">

    <resultMap id="truckPageListMap" type="com.sckw.truck.entity.res.BusinessTruckPageListRes" >
        <result column="id" property="id" />
        <result column="truck_no" property="truckNo" />
        <result column="truck_type_id" property="truckTypeId" />
        <result column="driver_str" property="driverStr" />
        <result column="energy_id" property="energyId" />
        <result column="outline_dimension" property="outlineDimension" />
        <result column="nuclear_load" property="nuclearLoad" />
        <result column="tare_weight" property="tareWeight" />
        <result column="status" property="status" />
        <result column="create_by" property="createBy" />
        <result column="update_by" property="updateBy" />
        <result column="create_time" property="createTime" />
        <result column="update_time" property="updateTime" />
        <result column="energy_type" property="energyIdStr" />
        <result column="truck_type" property="truckTypeIdStr" />
    </resultMap>

    <select id="truckPageList" resultMap="truckPageListMap">
        select
            kbt.id,
            kbt.truck_no,
            kbt.truck_type_id,
            kbt.driver_id,
            kbt.driver_str,
            kbt.use_nature,
            kbt.truck_own,
            kbt.truck_vin,
            kbt.trailer_no,
            kbt.total_weight,
            kbt.curb_weight,
            kbt.energy_id,
            kbt.outline_dimension,
            kbt.nuclear_load,
            kbt.tare_weight,
            kbt.truck_company,
            kbt.status,
            kbt.register_date,
            kbt.issue_date,
            kbt.inspection_authority,
            kbt.driving_license_face_url,
            kbt.driving_license_back_url,
            kbt.create_by,
            kbt.update_by,
            kbt.create_time,
            kbt.update_time,
            tt.truck_type,
            te.energy_type
        from kw_business_truck kbt
        join kw_business_truck_type tt ON tt.id = kbt.truck_type_id
        join kw_business_truck_energy te ON te.id = kbt.energy_id
        <where>
            kbt.del_flag = 0
            <if test="listReq.truckTypeId != null">
                and kbt.truck_type_id = #{listReq.truckTypeId}
            </if>
            <if test="listReq.energyId != null">
                and kbt.energy_id = #{listReq.energyId}
            </if>
            <if test="listReq.status != null">
                and kbt.status = #{listReq.status}
            </if>
            <if test="listReq.truckNo != null and listReq.truckNo != ''">
                AND kbt.truck_no LIKE concat('%' , #{listReq.truckNo} , '%')
            </if>
            <if test="listReq.keywords != null and listReq.keywords != ''">
                AND kbt.truck_no LIKE concat('%' , #{listReq.keywords} , '%')
            </if>
        </where>
    </select>
</mapper>