<?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.order.mapper.OrderRentVehicleDetailMapper">

    <select id="listByOrderId" parameterType="Integer" resultType="com.xxfc.platform.order.entity.OrderRentVehicleDetail">
        select *
        from order_rent_vehicle_detail
        where order_id = #{orderId}
    </select>

    <select id="oneByOrderId" parameterType="Integer" resultType="map">
        select *
        from order_rent_vehicle_detail
        where order_id = #{orderId} limit 1 offset 0;
    </select>

    <select id="getPScore" resultType="Integer" >
        SELECT round(IFNULL (AVG(score),0)) score  FROM  order_rent_vehicle_detail  WHERE model_id=#{modelId}
     </select>

    <select id="pageByParm" parameterType="Map" resultType="com.xxfc.platform.order.entity.OrderRentVehicleDetail">
        select *
        from order_rent_vehicle_detail
        <where>
            <if test="id != null">
                and id = #{id}
            </if>
            <if test="startCompanyId != null">
                and start_company_id = #{startCompanyId}
            </if>
            <if test="endCompanyId != null">
                and end_company_id = #{endCompanyId}
            </if>
        </where>
        order by crt_time desc
    </select>

    <select id="selectListFull" parameterType="com.xxfc.platform.order.pojo.order.OrderFullDTO" resultType="com.xxfc.platform.order.pojo.order.OrderFullVO">
        select bo.*
        from order_rent_vehicle_detail orvd
        left join base_order bo on
        orvd.order_id = bo.id
        <where>
            <if test="crtTime != null">
                and bo.crt_time &gt;= #{crtTime}
            </if>
            <if test="startTimeGte != null">
                and orvd.start_time &gt;= #{startTimeGte}
            </if>
            <if test="startTimeLte != null">
                and orvd.start_time &lt;= #{startTimeLte}
            </if>
            <if test="endTimeGte != null">
                and orvd.end_time &gt;= #{endTimeGte}
            </if>
            <if test="endTimeLte != null">
                and orvd.end_time &lt;= #{endTimeLte}
            </if>
            <if test="hasPay != null">
                and bo.has_pay = #{hasPay}
            </if>
            <if test="vehicleIds != null">
                and orvd.vehicle_id in
                <foreach collection="vehicleIds"  item="id" open="(" separator="," close=")">
                    #{id}
                </foreach>
            </if>
            <if test="multiNotStatus != null">
                and bo.status not in
                <foreach collection="multiNotStatus.split(',')"  item="notStatus" open="(" separator="," close=")">
                    #{notStatus}
                </foreach>
            </if>
            <if test="multiStatus != null">
                and bo.status not in
                <foreach collection="multiStatus.split(',')"  item="status" open="(" separator="," close=")">
                    #{status}
                </foreach>
            </if>
        </where>
        order by crt_time desc
    </select>

</mapper>