<?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.pj.project.tb_business_car.TbBusinessCarMapper">
	<!-- ================================== 查询相关 ================================== -->
	<!-- select id, business_id, car_no, pre_in_time, pre_out_time, real_in_time, real_out_time, money, driver_phone from tb_business_car  -->
	
	<!-- 通用映射：手动模式 -->
	<resultMap id="model" type="com.pj.project.tb_business_car.TbBusinessCar">
		<result property="id" column="id" />
		<result property="businessId" column="business_id" />
		<result property="carNo" column="car_no" />
		<result property="preInTime" column="pre_in_time" />
		<result property="preOutTime" column="pre_out_time" />
		<result property="realInTime" column="real_in_time" />
		<result property="realOutTime" column="real_out_time" />
		<result property="money" column="money" />
		<result property="driverPhone" column="driver_phone" />
	</resultMap>
	
	<!-- 公共查询sql片段 -->
	<sql id="select_sql">
		select * 
		from tb_business_car 
	</sql>

	<!-- 查集合 - 根据条件（参数为空时代表忽略指定条件） [G] -->
	<select id="getList" resultMap="model">
		<include refid="select_sql"></include>
		<where>
			<if test=' this.has("id") '> and id = #{id} </if>
			<if test=' this.has("businessId") '> and business_id = #{businessId} </if>
            <if test=' this.has("customerId") '> and customer_id = #{customerId} </if>
			<if test=' this.has("carNo") '> and car_no like concat('%',#{carNo},'%') </if>
			<if test=' this.has("preInTime") '> and pre_in_time = #{preInTime} </if>
			<if test=' this.has("preOutTime") '> and pre_out_time = #{preOutTime} </if>
			<if test=' this.has("realInTime") '> and real_in_time = #{realInTime} </if>
			<if test=' this.has("realOutTime") '> and real_out_time = #{realOutTime} </if>
			<if test=' this.has("money") '> and money = #{money} </if>
			<if test=' this.has("driverPhone") '> and driver_phone = #{driverPhone} </if>
		</where>
		order by
		<choose>
			<when test='sortType == 1'> id desc </when>
			<when test='sortType == 2'> business_id desc </when>
			<when test='sortType == 3'> car_no desc </when>
			<when test='sortType == 4'> pre_in_time desc </when>
			<when test='sortType == 5'> pre_out_time desc </when>
			<when test='sortType == 6'> real_in_time desc </when>
			<when test='sortType == 7'> real_out_time desc </when>
			<when test='sortType == 8'> money desc </when>
			<when test='sortType == 9'> driver_phone desc </when>
			<otherwise> id desc </otherwise>
		</choose>
	</select>
	
	
	
	
	
	
	
	
	

</mapper>
