<?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.hotwj.platform.resourceManagement.vehicleInfo.mapper.VehicleInfoMapper">

    <select id="selectVehicleInfoPage"
            resultType="com.hotwj.platform.resourceManagement.vehicleInfo.domain.vo.VehicleInfoVo">
        SELECT v.id           AS id,
               c.company_name AS companyName,
               v.plate_number          AS plateNumber,
               v.brand_model           AS brandModel,
               v.vehicle_type          AS vehicleType,
               v.vehicle_model         AS vehicleModel,
               v.plate_color           AS plateColor,
               v.vehicle_register_date AS vehicleRegisterDate,
               v.rated_load_kg         AS ratedLoadKg,
               v.drive_motor_model         AS driveMotorModel,
               v.frame_number          AS frameNumber,
               v.transport_license_no  AS transportLicenseNo,
               v.fuel_type             AS fuelType,
               (SELECT CASE ar.evaluation_level WHEN 1 THEN '一级' WHEN 2 THEN '二级' ELSE CAST(ar.evaluation_level AS CHAR) END
                FROM hot_vehicle_annual_review ar
                WHERE ar.vehicle_id = v.id AND ar.is_deleted = 0
                ORDER BY ar.review_date DESC LIMIT 1) AS technicalLevel,
               v.transport_valid_month AS transportValidMonth,
               (SELECT ar.review_date
                FROM hot_vehicle_annual_review ar
                WHERE ar.vehicle_id = v.id AND ar.is_deleted = 0
                ORDER BY ar.review_date DESC LIMIT 1) AS inspectionDate,
               v.operation_status      AS operationStatus
        FROM hot_vehicle v
                 JOIN sys_company c ON v.company_id = c.id
        WHERE c.region_code = #{districtCode}
          AND COALESCE(v.is_deleted, 0) = 0
          AND COALESCE(c.is_deleted, 0) = 0
        <if test="bo.companyName != null and bo.companyName != ''">
            AND c.company_name LIKE CONCAT('%', #{bo.companyName}, '%')
        </if>
        <if test="bo.plateNumber != null and bo.plateNumber != ''">
            AND v.plate_number LIKE CONCAT('%', #{bo.plateNumber}, '%')
        </if>
        <if test="bo.fuelType != null and bo.fuelType != ''">
            AND v.fuel_type = #{bo.fuelType}
        </if>
        <if test="bo.operationStatus != null">
            AND v.operation_status = #{bo.operationStatus}
        </if>
    </select>

</mapper>
