<?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="vip.xiaonuo.biz.modular.bizappointmentrecord.mapper.BizAppointmentRecordMapper">

    <select id="getPage" resultType="vip.xiaonuo.biz.modular.bizappointmentrecord.entity.BizAppointmentRecord">
        select
            bar.id,
            bar.order_id,
            bar.license_number,
            bo.order_number,
            bo.order_name,
            bo.order_type,
            bc.name customerName,
            bc.contact customerContactName,
            bg.GOODS_NAME goodsName,
            bg.GOODS_MODEL goodsModel,
            bar.time_id,
            bgc.CONF_START_TIME begin_time,
            bgc.CONF_END_TIME end_time,
            bar.driver_name,
            bar.driver_mobile,
            bar.status,
            bar.appointment_reason,
            bar.over_id,
            bec.vehicle_axle_number axleNumber,
            br.id recordId,
            bar.queue_number,
            br.driver_sign,
            br.unload_weight/1000 unload_weight,
            br.unload_img,
            br.unload_name,
            br.audit_sign
        from biz_appointment_record bar
         left join biz_order bo on bar.order_id = bo.id
         left join biz_goods bg on bg.id = bo.good_id
         left join biz_goods_conf bgc on bgc.id = bar.time_id
         left join biz_customer bc on bc.id = bo.customer_id
         left join biz_excess_config bec on bec.id = bar.over_id
         left join biz_record br on bar.id = br.appointment_id
        ${ew.customSqlSegment}
    </select>
    <select id="getRecord"
            resultType="vip.xiaonuo.biz.modular.bizappointmentrecord.entity.BizAppointmentRecord">
        SELECT
            bar.id,
            bar.order_id,
            bar.license_number,
            bar.time_id,
            bgc.CONF_START_TIME begin_time,
            bgc.CONF_END_TIME end_time,
            bar.driver_name,
            bar.driver_mobile,
            bar.STATUS,
            bar.appointment_reason,
            bar.create_user,
            bar.queue_number
        FROM
            biz_appointment_record bar
        LEFT JOIN biz_goods_conf bgc ON bgc.id = bar.time_id
            ${ew.customSqlSegment}
    </select>

    <select id="gerVehicleTotal" resultType="java.util.Map">
        SELECT
            case
                when a.DICT_VALUE ='1' then '待审核'
                when a.DICT_VALUE ='2' then '审核不通过'
                when a.DICT_VALUE ='3' then '排队中'
                when a.DICT_VALUE ='4' then '可入场'
                when a.DICT_VALUE ='5' then '已入场'
                when a.DICT_VALUE ='6' then '一次过磅'
                when a.DICT_VALUE ='7' then '完成装货'
                when a.DICT_VALUE ='8' then '二次过磅'
                when a.DICT_VALUE ='9' then '待出场'
                when a.DICT_VALUE ='10' then '已出场'
                when a.DICT_VALUE ='11' then '已签收'
                when a.DICT_VALUE ='12' then '销售待审核'
                when a.DICT_VALUE ='13' then '销售已审核'
                when a.DICT_VALUE ='14' then '已取消'
                else '超期作废'
            end as status,
            ifnull( b.count, 0 ) count
        FROM
            ( SELECT DICT_VALUE FROM dev_dict WHERE PARENT_ID = ( SELECT id FROM dev_dict WHERE DICT_VALUE = 'appointment_status' ) ) a
            LEFT JOIN (
                SELECT STATUS, count( * ) count
                FROM biz_appointment_record bar
                where delete_flag = 'NOT_DELETE'
                <if test="beginTime!=null and endTime!=null">
                    and create_time between #{beginTime} and #{endTime}
                </if>
                GROUP BY bar.STATUS
            ) b ON a.DICT_VALUE = b.STATUS
    </select>
</mapper>
