<?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.jkcredit.invoice.hub.mapper.CarFreeCarrierBillStartMapper">
    <resultMap id="baseResultMap"
               type="com.jkcredit.invoice.hub.model.po.carFreeCarrierBillStart.CarFreeCarrierBillStartPo">
        <id column="id" property="id"/>
        <result column="plate_color" property="plateColor"/>
        <result column="plate_number" property="plateNumber"/>
        <result column="num" property="num"/>
        <result column="start_time" property="startTime"/>
        <result column="source_addr" property="sourceAddr"/>
        <result column="dest_addr" property="destAddr"/>
        <result column="predict_end_time" property="predictEndTime"/>
        <result column="fee" property="fee"/>
        <result column="title_type" property="titleType"/>
        <result column="tax_player_code" property="taxPlayerCode"/>
        <result column="user_id" property="userId"/>
        <result column="create_time" property="createTime"/>
        <result column="status" property="status"/>
        <result column="is_history" property="isHistory"/>
        <result column="update_time" property="updateTime"/>
        <result column="activated" property="activated"/>
        <result column="is_search" property="isSearch"/>
    </resultMap>

    <select id="getBillStartByNum" resultMap="baseResultMap">
        select * from h_car_free_carrier_bill_start where activated = 1 and num = #{num}
    </select>

    <select id="getRealTimeBills" resultMap="baseResultMap">
        select * from h_car_free_carrier_bill_start where activated = 1 and is_history = 1 and (status = 2 or status = 4)
    </select>

    <select id="getHistoryBills" resultMap="baseResultMap">
        select * from h_car_free_carrier_bill_start where activated = 1 and is_history = 2 and (status = 2 or status = 4)
    </select>

    <select id="getNoSearchNums" resultType="java.lang.String">
        select num from h_car_free_carrier_bill_start where activated = 1 and is_search = 1 and user_id = #{userId}
    </select>

    <select id="getBillRecord" resultType="com.jkcredit.invoice.hub.model.po.carFreeCarrierBillStart.BillRecordPo">
        select
        start.num,
        start.plate_number as plateNumber,
        start.start_time as startBillStartTime,
        start.status,
        start.is_history as isHistory,
        start.create_time as startBillCreateTime,
        end.real_dest_addr as realDestAddr,
        end.create_time as endBillCreateTime,
        user.app_key as appKey,
        user.company
        from h_car_free_carrier_bill_start start
        left join h_car_free_carrier_bill_end end on start.num = end.num
        left join h_user user on start.user_id = user.id
        <where>
            start.activated = 1 and user.activated = 1
            <if test="query.appKey != null and query.appKey != ''">
                and user.app_key = #{query.appKey}
            </if>
            <if test="query.num != null and query.num != ''">
                and start.num = #{query.num}
            </if>
            <if test="query.status != null and query.status != ''">
                and start.status = #{query.status}
            </if>
            <if test="query.isHistory != null and query.isHistory != ''">
                and start.is_history = #{query.isHistory}
            </if>
            <if test="query.plateNumber != null and query.plateNumber != ''">
                and start.plate_number = #{query.plateNumber}
            </if>
        </where>
    </select>
</mapper>
