<?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.KwOrderCarLandTransportInventoryMapper">

    <resultMap type="com.sckw.car.entity.res.ListDetailRes" id="listDetail">
        <id property="id" column="id" />
        <result property="name" column="name" />
        <!-- 一对多级联查询，ofType表示集合中的元素类型，将id传递给selectOrderById -->
        <collection property="list" column="id" select="selectListDetail" />
    </resultMap>

    <select id="selectList" resultMap="listDetail" resultType="com.sckw.car.entity.res.ListDetailRes">
        select id,`name` from kw_order_car_land_transport_list
        <where>
            del_flag = 0
            <if test="name != null and name != ''">
                and `name` like concat('%', #{name}, '%')
            </if>
        </where>
    </select>

    <select id="selectListDetail" resultType="com.sckw.car.entity.res.ListAndDetailDto">
        select id,`name`,list_order_num from kw_order_car_land_transport_list_detail where del_flag = 0 and car_list_id = #{id}
    </select>
    <select id="selectByOrderId" resultType="com.sckw.car.entity.res.CarDetailRes">
        select
        <!--            header-->
        o.id,
        o.order_source orderSource,
        o.order_no orderNo,
        o.create_time createTime,
        o.create_by createBy,
        o.status,
        o.pid,
        o.type_handling typeHandling,
        <!--            企业信息-->
        o.ty_company_id tyCompanId,
        o.ty_company tyCompany,
        o.ty_phone tyPhone,
        o.cy_company_id cyCompanyId,
        o.cy_company cyCompany,
        o.cy_phone cyPhone,
        o.fh_company_id fhCompanyId,
        o.fh_company fhCompany,
        o.fh_phone fhPhone,
        o.sh_company_id shCompanyId,
        o.sh_company shCompany,
        o.sh_phone shPhone,
        o.remain_allocation remainAllocation,
        o.remain_num remainNum,
        o.tenant_id tenantId,
        <!--            货物信息-->
#         tg.goods_id goodsId,
#         tg.goods_name goodsName,
#         tg.goods_type goodsType,
#         tg.goods_unit goodsUnit,
#         tg.goods_num  goodsNum,
#         tg.goods_volume goodsVolume,
#         tg.goods_weight goodsWeight,
        <!--            履约信息-->
        tp.per_start_time perStartTime,
        tp.per_end_time perEndTime,
        tp.billing_cycle settlementCycle,
        tp.pay_method payment,
        tp.pay_company payCompany,
        tp.billing_mode billingMode,
        tp.gathering_company gatheringCompany,
        tp.price,
        <!--            履约记录-->
        o.total_load_amount,
        o.total_unload_amount,
        o.remain_num,
        <!--            扣亏货-->
        tdg.rational_loss rationalLoss,
        tdg.ded_price dedPrice,
        <!--            更多信息-->
        tm.truck_type truckType,
        tm.truck_type_str truckTypeStr,
        tm.estimate_freight estimateFreight
        from kw_order o
        left join kw_order_car_land_transport_per tp on o.id = tp.order_id
        left join kw_order_car_land_transport_more tm on o.id = tm.order_id
        left join kw_order_car_land_transport_def_goods tdg on o.id = tdg.order_id
        <where>
            o.del_flag = 0
            <if test="orderId != null">
                and o.id = #{orderId}
            </if>
        </where>
    </select>

</mapper>