<?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.njzscloud.dispose.cst.order.mapper.OrderTransMapper">
    <resultMap id="BaseResultMap" autoMapping="true" type="com.njzscloud.dispose.cst.order.pojo.result.OrderTransResult">
        <id column="id" property="id"/>
        <result column="train_num" property="trainNum"/>
        <result column="order_id" property="orderId"/>
        <result column="trans_status" property="transStatus"/>
        <result column="lane" property="lane"/>
        <result column="assignment_driver_time" property="assignmentDriverTime"/>
        <result column="driver_confirm_time" property="driverConfirmTime"/>
        <result column="trans_time" property="transTime"/>
        <result column="finish_time" property="finishTime"/>
        <result column="checker_id" property="checkerId"/>
        <result column="check_status" property="checkStatus"/>
        <result column="check_time" property="checkTime"/>
        <result column="check_photo" property="checkPhoto" typeHandler="com.njzscloud.common.mp.support.handler.j.JsonTypeHandler"/>
        <result column="checker_memo" property="checkerMemo"/>
        <result column="driver_id" property="driverId"/>
        <result column="driver_customer_id" property="driverCustomerId"/>
        <result column="driver_user_id" property="driverUserId"/>
        <result column="truck_customer_id" property="truckCustomerId"/>
        <result column="truck_org_id" property="truckOrgId"/>
        <result column="truck_id" property="truckId"/>
        <result column="truck_license_plate" property="truckLicensePlate"/>
        <result column="history_tare_weight" property="historyTareWeight"/>
        <result column="rough_weight" property="roughWeight"/>
        <result column="tare_weight" property="tareWeight"/>
        <result column="settle_weight" property="settleWeight"/>
        <result column="trans_distance" property="transDistance"/>
        <result column="in_front_photo" property="inFrontPhoto"/>
        <result column="in_body_photo" property="inBodyPhoto"/>
        <result column="out_front_photo" property="outFrontPhoto"/>
        <result column="out_body_photo" property="outBodyPhoto"/>
        <result column="in_time" property="inTime"/>
        <result column="out_time" property="outTime"/>
        <result column="sn" property="sn"/>
        <result column="trans_org_id" property="transOrgId"/>
        <result column="trans_customer_id" property="transCustomerId"/>
        <result column="assignment_trans_time" property="assignmentTransTime"/>
        <result column="order_category" property="orderCategory"/>
        <result column="order_status" property="orderStatus"/>
        <result column="customer_id" property="customerId"/>
        <result column="order_time" property="orderTime"/>
        <result column="goods_id" property="goodsId"/>
        <result column="goods_category_id" property="goodsCategoryId"/>
        <result column="category_name" property="goodsCategoryId"/>
        <result column="goods_sn" property="goodsSn"/>
        <result column="estimated_quantity" property="estimatedQuantity"/>
        <result column="unit" property="unit"/>
        <result column="picture" property="picture"/>
    </resultMap>

    <sql id="Base_Column_List">
        cot.id AS id,
        cot.train_num AS train_num,
        cot.order_id AS order_id,
        cot.trans_status AS trans_status,
        cot.lane AS lane,
        cot.assignment_driver_time AS assignment_driver_time,
        cot.driver_confirm_time AS driver_confirm_time,
        cot.trans_time AS trans_time,
        cot.finish_time AS finish_time,
        cot.checker_id AS checker_id,
        cot.check_status AS check_status,
        cot.check_time AS check_time,
        cot.check_photo AS check_photo,
        cot.checker_memo AS checker_memo,
        cot.driver_id AS driver_id,
        cot.driver_customer_id AS driver_customer_id,
        cot.driver_user_id AS driver_user_id,
        cot.truck_customer_id AS truck_customer_id,
        cot.truck_org_id AS truck_org_id,
        cot.truck_id AS truck_id,
        cot.truck_license_plate AS truck_license_plate,
        cot.history_tare_weight AS history_tare_weight,
        cot.rough_weight AS rough_weight,
        cot.tare_weight AS tare_weight,
        cot.settle_weight AS settle_weight,
        cot.trans_distance AS trans_distance,
        cot.in_front_photo AS in_front_photo,
        cot.in_body_photo AS in_body_photo,
        cot.out_front_photo AS out_front_photo,
        cot.out_body_photo AS out_body_photo,
        cot.in_time AS in_time,
        cot.out_time AS out_time,
        co.sn,
        co.trans_org_id AS trans_org_id,
        co.trans_customer_id AS trans_customer_id,
        co.assignment_trans_time AS assignment_trans_time,
        co.order_category,
        co.order_status,
        co.customer_id,
        co.order_time,
        co.goods_id,
        co.goods_name,
        co.estimated_quantity,
        co.unit,
        gg.goods_category_id,
        gg.sn AS goods_sn,
        gg.picture,
        ggc.category_name AS goods_category_name
    </sql>

    <select id="getById" resultMap="BaseResultMap">
        SELECT
        <include refid="Base_Column_List"/>
        FROM cst_order_trans cot
        LEFT JOIN cst_order co on co.id = cot.order_id
        LEFT JOIN gds_goods gg on gg.id = co.goods_id
        LEFT JOIN gds_goods_category ggc on ggc.id = gg.goods_category_id
        WHERE cot.id = #{id}
    </select>

    <select id="paging" resultMap="BaseResultMap">
        SELECT
        <include refid="Base_Column_List"/>
        FROM cst_order_trans cot
        LEFT JOIN cst_order co on co.id = cot.order_id
        LEFT JOIN gds_goods gg on gg.id = co.goods_id
        LEFT JOIN gds_goods_category ggc on ggc.id = gg.goods_category_id
        <if test="ew.customSqlSegment != null and ew.customSqlSegment != ''">
            ${ew.customSqlSegment}
        </if>
    </select>

    <select id="getByLicensePlate" resultMap="BaseResultMap">
        SELECT
        <include refid="Base_Column_List"/>
        FROM cst_order_trans cot
        LEFT JOIN cst_order co on co.id = cot.order_id
        LEFT JOIN gds_goods gg on gg.id = co.goods_id
        LEFT JOIN gds_goods_category ggc on ggc.id = gg.goods_category_id
        WHERE cot.truck_license_plate = #{licensePlate}
        AND cot.trans_status IN ('YunShuZhong', 'YiJinChang')
        ORDER BY cot.create_time DESC
        LIMIT 1
    </select>

    <select id="getTransResultByOrderId" resultType="com.njzscloud.dispose.cst.order.pojo.result.TransResult">
        SELECT
            cot.truck_license_plate,
            cd.driver_name,
            cd.phone,
            cot.trans_time,
            cot.in_time,
            cot.out_time,
            cot.rough_weight,
            cot.tare_weight,
            cot.settle_weight
        FROM
            cst_order_trans cot
            LEFT JOIN cst_driver cd ON cd.id = cot.driver_id
        WHERE cot.order_id = #{orderId}
    </select>
    <select id="listTransRecode"
            resultType="com.njzscloud.dispose.cst.order.pojo.result.SearchOrderTransResult">
        SELECT
        a.id,
        a.train_num,
        a.order_id,
        a.trans_status,
        a.lane,
        a.assignment_driver_time,
        a.driver_confirm_time,
        a.trans_time,
        a.finish_time,
        a.checker_id,
        a.check_status,
        a.check_time,
        a.check_photo,
        a.checker_memo,
        a.driver_id,
        a.driver_customer_id,
        a.driver_user_id,
        a.truck_customer_id,
        a.truck_org_id,
        a.truck_id,
        a.truck_license_plate,
        a.history_tare_weight,
        a.rough_weight,
        a.tare_weight,
        a.settle_weight,
        a.trans_distance,
        a.in_front_photo,
        a.in_body_photo,
        a.out_front_photo,
        a.out_body_photo,
        a.in_time,
        a.out_time,
        b.driver_name,
        b.phone driver_phone
        FROM cst_order_trans a
        LEFT JOIN cst_driver b ON b.id = a.driver_id
        <if test="ew.customSqlSegment != null and ew.customSqlSegment != ''">
            ${ew.customSqlSegment}
        </if>
    </select>

</mapper>
