(select su.nickname from system_user su where su.deleted = 0 and su.id = o.salesman_id) as salesman_name,
(select min(wi.`in_time`) from ecw_order_warehouse_in wi where wi.deleted = 0 and wi.order_id = o.order_id ) as in_time
FROM ecw_order o
LEFT JOIN (
SELECT
ewl.id AS line_id,
ew_start.id AS start_warehouse_id,
ew_dest.id AS dst_warehouse_id,
ew_start.title_zh AS start_title_zh,
IF( #{query.lang} = 0, ew_dest.title_zh, ew_dest.title_en ) AS dst_warehouse_name,
IF( #{query.lang} = 0, ew_start.title_zh, ew_start.title_en ) AS start_warehouse_name
FROM
ecw_warehouse_line ewl
LEFT JOIN ecw_warehouse ew_start ON ewl.start_warehouse_id = ew_start.id
LEFT JOIN ecw_warehouse ew_dest ON ewl.dest_warehouse_id = ew_dest.id
) w ON w.line_id = o.line_id
LEFT JOIN ecw_order_consignor nor on nor.order_id = o.order_id and nor.deleted = 0
LEFT JOIN ecw_order_consignee nee on nee.order_id = o.order_id and nee.deleted = 0
LEFT JOIN ecw_make_bill_of_lading bl on bl.order_id = o.order_id and bl.deleted = 0
LEFT JOIN ecw_customer norc on norc.id = nor.customer_id
LEFT JOIN ecw_customer neeo on neeo.id = nee.customer_id
WHERE o.`container_number` = #{query.containerNumber}
</select>
<sqlid="containerOrderSummaryQuery">
<iftest="query.orderNo != null and query.orderNo != '' ">
AND o.`order_no` like concat("%",concat(#{query.orderNo},"%"))
</if>
<iftest="query.tidanNo != null and query.tidanNo != '' ">
AND o.`tidan_no` like concat("%",concat(#{query.tidanNo},"%"))
</if>
<iftest="query.marks != null and query.marks != '' ">
AND o.`marks` like concat("%",concat(#{query.marks},"%"))
</if>
<iftest="query.consignorKey != null and query.consignorKey != '' ">
AND (concat(IFNULL(nor.`name`,''),IFNULL(nor.`name_en`,''),IFNULL(nor.`phone`,'')) like
concat("%",concat(#{query.consignorKey},"%"))
OR nor.customer_id in (select c.id from ecw_customer c where c.number like
concat("%",concat(#{query.consignorKey},"%"))))
</if>
<iftest="query.consigneeKey != null and query.consigneeKey != '' ">
AND (concat(IFNULL(nee.`name`,''),IFNULL(nee.`name_en`,''),IFNULL(nee.`phone`,'')) like
concat("%",concat(#{query.consigneeKey},"%"))
OR nee.customer_id in (select c.id from ecw_customer c where c.number like
concat("%",concat(#{query.consigneeKey},"%"))))
</if>
<iftest="query.startWarehouseIds !=null and query.startWarehouseIds.size() > 0 and query.destWarehouseIds !=null and query.destWarehouseIds.size() > 0 ">
<iftest="query.startWarehouseIds !=null and query.startWarehouseIds.size() > 0 and (query.destWarehouseIds==null or query.destWarehouseIds.size() == 0) ">
<iftest="(query.startWarehouseIds ==null or query.startWarehouseIds.size() == 0) and query.destWarehouseIds !=null and query.destWarehouseIds.size() > 0 ">