<?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.sqx.modules.driver.dao.DriverRouteDao">


    <select id="selectDriverRouteList" resultType="com.sqx.modules.driver.entity.DriverRoute">
        select dr.*,d.driver_name as driverName,u.nick_name as userName,u.phone,d.driver_plate as driverPlate,u.avatar,
               (select count(*) from orders o where o.driver_id=d.driver_id and status=5) as ordersCount,
               (select count(*) from message_info m where m.platform=#{ordersId} and m.state=6 and m.user_id=dr.user_id ) as messageCount
        from driver_route dr
        left join tb_user u on u.user_id=dr.user_id
        left join driver d on d.driver_id=dr.driver_id
        where 1=1
        <if test="shipProvince!=null and shipProvince!=''">
            and dr.ship_province like concat('%',#{shipProvince},'%')
        </if>
        <if test="shipCity!=null and shipCity!=''">
            and dr.ship_city like concat('%',#{shipCity},'%')
        </if>
        <if test="shipDistrict!=null and shipDistrict!=''">
            and dr.ship_district like concat('%',#{shipDistrict},'%')
        </if>
        <if test="shipAddress!=null and shipAddress!=''">
            and dr.ship_address like concat('%',#{shipAddress},'%')
        </if>
        <if test="deliveryProvince!=null and deliveryProvince!=''">
            and dr.delivery_province like concat('%',#{deliveryProvince},'%')
        </if>
        <if test="deliveryCity!=null and deliveryCity!=''">
            and dr.delivery_city like concat('%',#{deliveryCity},'%')
        </if>
        <if test="deliveryDistrict!=null and deliveryDistrict!=''">
            and dr.delivery_district like concat('%',#{deliveryDistrict},'%')
        </if>
        <if test="deliveryAddress!=null and deliveryAddress!=''">
            and dr.delivery_address like concat('%',#{deliveryAddress},'%')
        </if>
        <if test="driverName!=null and driverName!=''">
            and d.driver_name like concat('%',#{driverName},'%')
        </if>
        <if test="userName!=null and userName!=''">
            and u.nick_name like concat('%',#{userName},'%')
        </if>
        <if test="phone!=null and phone!=''">
            and u.phone like concat('%',#{phone},'%')
        </if>
        <if test="status!=null">
            and dr.status=#{status}
        </if>
        <if test="isHighSpeedPrice!=null">
            and dr.is_high_speed_price=#{isHighSpeedPrice}
        </if>
        order by dr.create_time desc
    </select>


</mapper>