<iftest="query.type != null and query.type != '' and query.type == 0 ">
AND (o.type is null or o.type = '' or o.type = '0')
</if>
<iftest="query.type == 1 ">
AND FIND_IN_SET(1, o.type)
</if>
<iftest="query.type == 2 ">
AND FIND_IN_SET(2, o.type)
</if>
<iftest="query.pdaStartWareIds != null and query.pdaStartWareIds != '' ">
AND FIND_IN_SET(ew_start.`id`, #{query.pdaStartWareIds})
</if>
<iftest="query.pdaDestWareIds != null and query.pdaDestWareIds != '' ">
AND FIND_IN_SET(ew_dest.`id`, #{query.pdaDestWareIds})
</if>
<iftest="query.isExternalWarehouse != null">
AND o.`is_external_warehouse` = #{query.isExternalWarehouse}
</if>
<iftest="query.status != null">
AND o.`status` = #{query.status}
</if>
<iftest="query.abnormalState != null">
<choose>
<whentest="query.abnormalState != 0">
<choose>
<whentest="query.abnormalState != -1">
AND o.`abnormal_state` = #{query.abnormalState}
</when>
<otherwise>
AND o.`abnormal_state` != 0
</otherwise>
</choose>
</when>
<otherwise>
AND o.`abnormal_state` = 0
</otherwise>
</choose>
</if>
<iftest="query.inWarehouseState != null">
AND o.`in_warehouse_state` = #{query.inWarehouseState}
</if>
<iftest="query.shipmentState != null">
AND o.`shipment_State` = #{query.shipmentState}
</if>
<iftest="query.auditType != null">
<choose>
<whentest="query.auditType != 0">
<choose>
<whentest="query.auditType != -1">
AND o.`audit_type` = #{query.auditType}
</when>
<otherwise>
AND o.`audit_type` != 0
</otherwise>
</choose>
</when>
<otherwise>
AND o.`audit_type` = 0
</otherwise>
</choose>
</if>
<iftest="query.salesmanId != null ">
AND (o.`salesman_id` = #{query.salesmanId} or o.`customer_id` in(select cus.id from ecw_customer cus where cus.is_customer_service_confirmed = 1 and cus.customer_service = #{query.salesmanId} ))
</if>
<iftest="query.customsType != null">
AND o.`customs_type` = #{query.customsType}
</if>
<iftest="query.productRecord != null">
AND o.`product_record` = #{query.productRecord}
</if>
<iftest="query.transportId != null">
AND o.`transport_id` = #{query.transportId}
</if>
<iftest="query.channelId != null">
AND o.`channel_id` = #{query.channelId}
</if>
<iftest="query.warehouseType != null">
AND o.`warehouse_type` = #{query.warehouseType}
</if>
<iftest="query.number != null and query.number != '' ">
AND (o.`number` like concat("%",concat(#{query.number},"%")) or o.order_id in( select distinct oi.order_id
from ecw_order_item oi
where oi.deleted = 0 and
((oi.warehouse_in_info is null and oi.express_no like concat('%',concat(#{query.number},'%')))
or (oi.warehouse_in_info is not null and oi.warehouse_in_info ->> '$.expressNo' like concat("%",concat(#{query.number},"%"))))))
</if>
<iftest="query.notNumber != null and query.notNumber != '' ">
AND o.`number` not like concat("%",concat(#{query.notNumber},"%"))
and
o.order_id not in
(select distinct oi.order_id from ecw_order_item oi
where oi.deleted = 0 and
((oi.warehouse_in_info is null and oi.express_no like concat("%",concat(#{query.notNumber},"%")))
or
(oi.warehouse_in_info is not null and oi.warehouse_in_info ->> '$.expressNo' like
concat("%",concat(#{query.notNumber},"%")))))
</if>
<iftest="query.marks != null and query.marks != '' ">
AND o.`marks` like concat("%",concat(#{query.marks},"%"))
</if>
<iftest="query.departureId != null ">
AND de.`departure_id` = #{query.departureId}
</if>
<iftest="query.objectiveId != null ">
AND ob.`objective_id` = #{query.objectiveId}
</if>
<iftest="query.destCountryId != null ">
AND ob.`objective_country_id` = #{query.destCountryId}
</if>
<iftest="query.consignorId != null ">
AND nor.`customer_id` = #{query.consignorId}
</if>
<iftest="query.consignorPhone != null and query.consignorPhone != '' ">
AND nor.`phone` = #{query.consignorPhone}
</if>
<iftest="query.packageType != null and query.packageType != '' ">
AND CONCAT(',',o.package_type,',') REGEXP CONCAT(',',REPLACE(#{query.packageType},',',',|,'), ',')
</if>
<iftest="query.consigneeId != null ">
AND nee.`customer_id` = #{query.consigneeId}
</if>
<iftest="query.consigneePhone != null and query.consigneePhone != '' ">
AND nee.`phone` = #{query.consigneePhone}
</if>
<iftest="query.isCargoControl != null ">
AND o.`is_cargo_control` = #{query.isCargoControl}
</if>
<iftest="query.orderNo != null and query.orderNo != '' ">
AND o.`order_no` like concat("%",concat(#{query.orderNo},"%"))
</if>
<iftest="query.orderIdList != null and query.orderIdList.size() != 0">