<?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.sckw.car.mapper.KwCarWaybillOrderMapper">

    <resultMap type="com.sckw.car.entity.res.KwOrderWaybillDetailRes" id="selectWaybillDetail">
        <id property="id" column="id" />
        <result property="tyCompany" column="tyCompany" />
        <result property="cyCompany" column="cyCompany" />
        <!-- 一对多级联查询，ofType表示集合中的元素类型，将id传递给selectOrderById -->
        <collection property="pathList" column="id" select="selectPathList" />
    </resultMap>
    <insert id="insertBatch">
        insert into kw_waybill_order
        <trim prefix="(" suffix=")" suffixOverrides=",">
            id,
            ent_id,
            order_id,
            t_order_no,
            type,
            truck_id,
            truck_no,
            driver_id,
            driver_name,
            driver_phone,
            driver_idcard,
            remark,
            `status`,
            entrust_amount,
            unload_amount,
            load_amount,
            deficit_amount,
            start_time,
            end_time,
            t_type,
            tenant_id,
            create_by
        </trim>
        values
        <foreach collection="list" item="item" separator=",">
            <trim prefix="(" suffix=")" suffixOverrides=",">
                ${item.id},
                #{item.entId,jdbcType=BIGINT},
                #{item.orderId,jdbcType=BIGINT},
                #{item.tOrderNo,jdbcType=BIGINT},
                #{item.type,jdbcType=BIGINT},
                #{item.truckId,jdbcType=BIGINT},
                #{item.truckNo,jdbcType=VARCHAR},
                #{item.driverId,jdbcType=BIGINT},
                #{item.driverName,jdbcType=VARCHAR},
                #{item.driverPhone,jdbcType=VARCHAR},
                #{item.driverIdcard,jdbcType=VARCHAR},
                #{item.remark,jdbcType=VARCHAR},
                #{item.status,jdbcType=INTEGER},
                #{item.entrustAmount,jdbcType=DECIMAL},
                #{item.unloadAmount,jdbcType=DECIMAL},
                #{item.loadAmount,jdbcType=DECIMAL},
                #{item.deficitAmount,jdbcType=DECIMAL},
                #{item.startTime,jdbcType=VARCHAR},
                #{item.endTime,jdbcType=VARCHAR},
                #{item.tType,jdbcType=INTEGER},
                #{item.tenantId,jdbcType=VARCHAR},
                #{item.createBy,jdbcType=VARCHAR}
            </trim>
        </foreach>

    </insert>

    <select id="selectWaybillDetailById" resultMap="selectWaybillDetail" resultType="com.sckw.car.entity.res.KwOrderWaybillDetailRes">
        select
            id,
            ty_company,
            cy_company
        from kw_order as o
        where
            o.id = #{id} and o.del_flag = 0
    </select>

    <select id="selectPathList" resultType="com.sckw.car.entity.res.KwOrderDetailPath">
        select id,name, order_id,list_id from kw_order_car_land_transport_path where del_flag = 0 and order_id = #{id}
    </select>

</mapper>