<?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.xxfc.platform.vehicle.mapper.VehicleDispatchInfoMapper" >

    <!-- 获取调度申请列表-->
  <select id="getInfoList" parameterType="com.xxfc.platform.vehicle.pojo.dto.VehicleDispatchInfoDto"
        resultType="com.xxfc.platform.vehicle.pojo.vo.VehicleDispatchInfoVo">
        SELECT
        DISTINCT
        i.id,
        i.account_id as accountId,
        i.account_name as accountName,
        i.company_id as companyId,
        c.`name` as companyName,
        i.mode_id as modeId,
        i.`user`,
        i.user_tel as userTel,
        i.start_time as startTime,
        i.end_time as endTime,
        i.wish_ret_company as wishRetCompany,
        c1.`name` as wishRetCompanyName,
        i.book_type as bookType,
        i.book_remark as bookRemark,
        i.reason,
        i.`status`,
        i.record_ids as recordIds,
        i.status_time as statusTime,
        i.crt_time as crtTime,
        i.upd_time as updTime
        FROM vehicle_dispatch_info i
        LEFT JOIN branch_company  c ON i.company_id=c.id
        LEFT JOIN branch_company  c1 ON i.company_id=c1.id
        <where>
          i.is_del=0
          <if test="companyList != null">
          and  i.company_id in (
          <trim suffixOverrides=",">
            <foreach collection="companyList" item="companyId">
              #{companyId},
            </foreach>
          </trim>
          )
          </if>
          <if test="status !=null">
            and i.status = #{status}
          </if>
        </where>
        order by i.crt_time desc
    </select>
    <!-- 获取调度申请用车详情列表-->
    <select id="getRecordList" resultType="com.xxfc.platform.vehicle.pojo.vo.VehiclDispatchRecordVo">
        SELECT
        DISTINCT
        r.id,
        r.lift_company as liftCompany,
        c.`name` as liftCompanyName,
        c.leader  as liftCompanyLeader,
        c.leader_contact_info as liftCompanyLeaderTel,
        r.actual_start_date as actualStartDate,
        r.ret_company as retCompany,
        c1.`name` as retCompanyName,
        c1.leader  as retCompanyLeader,
        c1.leader_contact_info as retCompanyLeaderTel,
        r.actual_end_date as actualEndDate
        FROM vehicle_book_record r
        LEFT JOIN branch_company  c ON r.lift_company=c.id
        LEFT JOIN branch_company  c1 ON r.ret_company=c1.id
        <where>
          r.id in (
            <trim suffixOverrides=",">
                <foreach collection="recordIds" item="id">
                    #{id},
                </foreach>
            </trim>
            )
        </where>
        order  by  r.actual_start_date
    </select>
</mapper>