<?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.xxfc.platform.vehicle.mapper.VehicleCommonPriceInfoMapper">

    <select id="selectList" resultType="com.xxfc.platform.vehicle.pojo.vo.VehicleCommonPriceVo">
        SELECT
        vci.*, v.`code`,
        v.id as vehicleId,
        v.number_plate,
        FLOOR(
        YEAR (NOW()) - YEAR (v.vehicle_register_date)
        ) as vehicleAge,
        v.vehicle_status,
        v.vehicle_body_status,
        vm.name as modelName,
        v.mileage_last_update AS mileage
        FROM
        vehicle v
        LEFT JOIN vehicle_common_price_info vci ON v.id = vci.vehicle_id
        LEFT JOIN branch_company bc2 ON v.subordinate_branch = bc2.id
        LEFT JOIN company_info ci on ci.id = bc2.company_id
        LEFT JOIN vehicle_model vm ON  v.model_id = vm.id
        <where>
            <if test="modelId != null and modelId > 0">
                and vci.model_id = #{modelId}
            </if>
            <if test="subordinateBranch !=null ">
                and ( bc2.id = #{subordinateBranch})
            </if>
            <if test="parkBranchCompanyId !=null ">
                and ( bc.id = #{parkBranchCompanyId})
            </if>
            <if test="companyId !=null ">
                and ( ci.id = #{companyId})
            </if>
            <if test="dataCorporationIds != null and dataCorporationIds.size > 0">
                and ci.id in (
                <foreach collection="dataCorporationIds" item="id" open="(" separator="," close=")">
                    #{id}
                </foreach>
                )
            </if>
            <if test="dataCompanyIds != null and dataCompanyIds.size > 0">
                and (bc.id in (
                <foreach collection="dataCompanyIds" item="id" open="(" separator="," close=")">
                    #{id}
                </foreach>
                ) or
                bc2.id in (
                <foreach collection="dataCompanyIds" item="id" open="(" separator="," close=")">
                    #{id}
                </foreach>
                ))
            </if>
            <if test="numberPlate !=null and numberPlate != ''">
                and v.number_plate like concat('%',#{numberPlate},'%')
            </if>
            and v.is_del = 0
        </where>
        order by vci.upd_time DESC
    </select>

</mapper>