<?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.yc.ship.module.resource.dal.mysql.driver.DriverMapper">

    <!--
        一般情况下，尽可能使用 Mapper 进行 CRUD 增删改查即可。
        无法满足的场景，例如说多表关联查询，才使用 XML 编写 SQL。
        代码生成器暂时只生成 Mapper XML 文件本身，更多推荐 MybatisX 快速开发插件来生成查询。
        文档可见：https://www.iocoder.cn/MyBatis/x-plugins/
     -->

    <select id="getDriverDefaultCarList"
            resultType="com.yc.ship.module.resource.controller.admin.driver.vo.DriverRespVO">
        SELECT
            a.id,
            a.NAME,
            a.phone,
            a.sex,
            a.driver_tag,
            a.supplier_type
        FROM
            dispatch_driver a
        where
            a.deleted = 0
          and a.use_status = 1
          and a.tenant_id = #{param.tenantId}
          and not EXISTS(select 1 from dispatch_car b where b.deleted=0 and b.driver_id = a.id and b.tenant_id = #{param.tenantId})
          <if test="param.name != null">
              and a.name like concat('%',#{param.name},'%')
          </if>
        order by
            a.NAME
    </select>
    <select id="getSimpleDriverListByCarType" resultType="com.yc.ship.module.resource.dal.dataobject.driver.DriverDO">
        SELECT DISTINCT
            a.id,
            a.driver_code,
            a.NAME,
            a.phone
        FROM
            dispatch_driver a
                INNER JOIN dispatch_car c ON c.driver_id = a.id
                INNER JOIN dispatch_car_type ct ON ct.id = c.car_type_id
        WHERE
            a.deleted = 0
          AND a.use_status = 1
          AND ct.id = #{carType}
        ORDER BY
            a.id
    </select>
</mapper>