<?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.fuzamei.mapperInterface.CargoDeliverMapper">
	
	<select id="queryOrdersByCarrier" parameterType="Params" resultType="DeliverOrder">
		select 
			o.order_id,
			o.box_no,
			o.box_qty,
			o.car_no,
			o.transport_time,
			o.update_time,
			s.status_name
		from 
			(select * from orders where status_id not in (1,2)) o
		left join 
			status s
		on 
			o.status_id=s.status_id
		<where>
			o.carrier_id=#{userId}
			<if test="orderId!=null">
				and o.order_id=#{orderId}
			</if>
			<if test="carNo!=null and carNo!=''">
				and o.car_no=#{carNo}
			</if>
			<if test="statusId!=null">
				and o.status_id=#{statusId}
			</if>
			<if test="startTime!=null and endTime!=null">
				and o.require_time between #{startTime} and #{endTime}
			</if>
		</where>
		order by o.status_id asc,o.require_time desc
		limit #{startPage},#{rowNum}
	</select>
	
	
	<select id="findQueryCountByCarrier" parameterType="Params" resultType="int">
		select 
			count(*)
		from 
			(select * from orders where status_id not in (1,2)) o
		<where>
			o.carrier_id=#{userId}
			<if test="orderId!=null">
				and o.order_id=#{orderId}
			</if>
			<if test="carNo!=null and carNo!=''">
				and o.car_no=#{carNo}
			</if>
			<if test="statusId!=null">
				and o.status_id=#{statusId}
			</if>
			<if test="startTime!=null and endTime!=null">
				and o.require_time between #{startTime} and #{endTime}
			</if>
		</where>
	</select>
</mapper>