<?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="cn.iocoder.yudao.module.custom.mapper.CustomerCarMapper">

    <sql id="baseCarMainColumn">
        tbcarm.id,
        tbcarm.engine_number,
        tbcarm.vin,
        tbcarm.license_number,
        tbcarm.car_model,
        tbcarm.maintenance_date,
        tbcarm.maintenance_mileage,
        tbcarm.inspection_date,
        tbcarm.insurance_date,
        tbcarm.check_date,
        tbcarm.next_maintenance_date,
        tbcarm.next_maintenance_mileage,
        tbcarm.next_inspection_date,
        tbcarm.insurance_expiry_date,
        tbcarm.next_check_date,
        tbcarm.car_brand,
        tbcarm.car_nature,
        tbcarm.car_category,
        tbcarm.car_register_date,
        tbcarm.car_license_img,
        tbcarm.recently_handled_business,
        tbcarm.recently_handle_business_time,
        tbcarm.deleted,
        tbcarm.creator,
        tbcarm.create_time,
        tbcarm.updater,
        tbcarm.update_time
    </sql>

    <sql id="baseCustomerMainColumn">
        tbcusm.id,
        tbcusm.user_id,
        tbcusm.type_code,
        tbcusm.dept_code,
        tbcusm.cus_name,
        tbcusm.phone_number,
        tbcusm.birthday,
        tbcusm.address,
        tbcusm.sex,
        tbcusm.id_card,
        tbcusm.id_card_image,
        tbcusm.data_from,
        tbcusm.near_do_time,
        tbcusm.near_do_content,
        tbcusm.inviter,
        tbcusm.inviter_type,
        tbcusm.status,
        tbcusm.tenant_id,
        tbcusm.deleted,
        tbcusm.creator,
        tbcusm.create_time,
        tbcusm.updater,
        tbcusm.update_time

    </sql>

    <select id="selectCarListByCusId" resultType="cn.iocoder.yudao.module.custom.vo.CarMainRespVO">
        SELECT
        <include refid="baseCarMainColumn"></include>,
        main.is_owner AS isOwner,bcb.brand_name AS brandStr,bcm.model_name AS modelStr
        FROM
            base_customer_car main
        LEFT JOIN
            base_car_main tbcarm ON main.car_id = tbcarm.id AND tbcarm.deleted = 0
        LEFT JOIN base_car_brand bcb ON bcb.deleted = 0 AND tbcarm.car_brand = bcb.id
        LEFT JOIN base_car_model bcm ON bcm.deleted = 0 AND tbcarm.car_model = bcm.id
        WHERE
            main.deleted = 0
        AND
              main.cus_id = #{cusId}
        ORDER BY
            main.create_time DESC
    </select>

    <select id="selectCusListByCarId" resultType="cn.iocoder.yudao.module.custom.vo.CustomerMainRespVO">
        SELECT
        <include refid="baseCustomerMainColumn"></include>,
        main.is_owner AS isOwner
        FROM
            base_customer_car main
        LEFT JOIN
            base_customer_main tbcusm ON main.cus_id = tbcusm.id AND tbcusm.deleted = 0
        WHERE
            main.deleted = 0
        AND
            main.car_id = #{carId}
        ORDER BY
            main.create_time DESC
    </select>
</mapper>