package cn.iocoder.yudao.module.order.dal.mysql.order;

import cn.iocoder.yudao.framework.common.pojo.PageResult;
import cn.iocoder.yudao.framework.mybatis.core.mapper.AbstractMapper;
import cn.iocoder.yudao.framework.mybatis.core.query.LambdaQuery;
import cn.iocoder.yudao.framework.mybatis.core.vo.PageVO;
import cn.iocoder.yudao.module.order.dal.dataobject.order.OrderDO;
import cn.iocoder.yudao.module.order.dal.dataobject.orderItem.OrderItemDO;
import cn.iocoder.yudao.module.order.dto.OrderExportBackDTO;
import cn.iocoder.yudao.module.order.dto.OrderBackInfoDto;
import cn.iocoder.yudao.module.order.dto.SearchBackDto;
import cn.iocoder.yudao.module.order.vo.order.*;
import cn.iocoder.yudao.module.order.vo.orderException.OrderExceptionStatisticsExcelVo;
import com.baomidou.mybatisplus.core.metadata.IPage;
import org.apache.ibatis.annotations.*;

import java.math.BigDecimal;
import java.util.Date;
import java.util.List;

/**
 * 订单 Mapper
 *
 * @author 系统管理员
 */
@Mapper
public interface OrderMapper extends AbstractMapper<OrderDO> {
    @Override
    default PageResult<OrderDO> selectPage(PageVO page, Object object) {
        if (object instanceof OrderQueryVO) {
            OrderQueryVO vo = (OrderQueryVO) object;
            return selectPage(page, new LambdaQuery<OrderDO>()
                    .eqIfPresent(OrderDO::getOrderNo, vo.getOrderNo())
                    .eqIfPresent(OrderDO::getTidanNo, vo.getTidanNo())
                    .eqIfPresent(OrderDO::getParentNumber, vo.getParentNumber())
                    .eqIfPresent(OrderDO::getParentOrderId, vo.getParentOrderId())
                    .eqIfPresent(OrderDO::getInitialParentOrderId, vo.getInitialParentOrderId())
                    .eqIfPresent(OrderDO::getOldNumbers, vo.getOldNumbers())
                    .eqIfPresent(OrderDO::getTransportId, vo.getTransportId())
                    .eqIfPresent(OrderDO::getLineId, vo.getLineId())
                    .eqIfPresent(OrderDO::getChannelId, vo.getChannelId())
                    .eqIfPresent(OrderDO::getType, vo.getType())
                    .eqIfPresent(OrderDO::getOrderType, vo.getOrderType())
                    .eqIfPresent(OrderDO::getUserId, vo.getUserId())
                    .eqIfPresent(OrderDO::getSalesmanId, vo.getSalesmanId())
                    .eqIfPresent(OrderDO::getMarks, vo.getMarks())
                    .eqIfPresent(OrderDO::getProductRecord, vo.getProductRecord())
                    .eqIfPresent(OrderDO::getIsCargoControl, vo.getIsCargoControl())
                    .eqIfPresent(OrderDO::getCargoControlStatus, vo.getCargoControlStatus())
                    .eqIfPresent(OrderDO::getCustomsType, vo.getCustomsType())
                    .eqIfPresent(OrderDO::getUpFile, vo.getUpFile())
                    .eqIfPresent(OrderDO::getPayType, vo.getPayType())
                    .eqIfPresent(OrderDO::getStatus, vo.getStatus())
                    .eqIfPresent(OrderDO::getOldStatus, vo.getOldStatus())
                    .eqIfPresent(OrderDO::getAbnormalState, vo.getAbnormalState())
                    .eqIfPresent(OrderDO::getInWarehouseState, vo.getInWarehouseState())
                    .eqIfPresent(OrderDO::getOldInWarehouseState, vo.getOldInWarehouseState())
                    .eqIfPresent(OrderDO::getShipmentState, vo.getShipmentState())
                    .eqIfPresent(OrderDO::getOldShipmentState, vo.getOldShipmentState())
                    .eqIfPresent(OrderDO::getAuditType, vo.getAuditType())
                    .eqIfPresent(OrderDO::getAuditResult, vo.getAuditResult())
                    .eqIfPresent(OrderDO::getIsDel, vo.getIsDel())
                    .eqIfPresent(OrderDO::getCollectionProxy, vo.getCollectionProxy())
                    .eqIfPresent(OrderDO::getCollectionProxyCurrency, vo.getCollectionProxyCurrency())
                    .eqIfPresent(OrderDO::getIsCollection, vo.getIsCollection())
                    .eqIfPresent(OrderDO::getWVolume, vo.getWVolume())
                    .eqIfPresent(OrderDO::getVWeight, vo.getVWeight())
                    .eqIfPresent(OrderDO::getWeightUnit, vo.getWeightUnit())
                    .eqIfPresent(OrderDO::getVolumeUnit, vo.getVolumeUnit())
                    .eqIfPresent(OrderDO::getOrgWeightUnit, vo.getOrgWeightUnit())
                    .eqIfPresent(OrderDO::getOrgVolumeUnit, vo.getOrgVolumeUnit())
                    .eqIfPresent(OrderDO::getWarehouseType, vo.getWarehouseType())
                    .eqIfPresent(OrderDO::getSendsms, vo.getSendsms())
                    .eqIfPresent(OrderDO::getDocumentsFile, vo.getDocumentsFile())
                    .eqIfPresent(OrderDO::getRemarks, vo.getRemarks())
                    .eqIfPresent(OrderDO::getAdjustToStartWarehouseId, vo.getAdjustToStartWarehouseId())
                    .eqIfPresent(OrderDO::getAdjustToDestWarehouseId, vo.getAdjustToDestWarehouseId())
                    .eqIfPresent(OrderDO::getSumNum, vo.getSumNum())
                    .eqIfPresent(OrderDO::getSumVolume, vo.getSumVolume())
                    .eqIfPresent(OrderDO::getSumWeight, vo.getSumWeight())
                    .eqIfPresent(OrderDO::getWeightRatio, vo.getWeightRatio())
                    .eqIfPresent(OrderDO::getCustomerId, vo.getCustomerId())
                    .eqIfPresent(OrderDO::getDrawee, vo.getDrawee())
                    .eqIfPresent(OrderDO::getCustomDrawee, vo.getCustomDrawee())
                    .likeIfPresent(OrderDO::getPackingListUrl, vo.getPackingListUrl())
                    .eqIfPresent(OrderDO::getAirShipment, vo.getAirShipment())
                    .eqIfPresent(OrderDO::getDeliveryWay, vo.getDeliveryWay())
                    .eqIfPresent(OrderDO::getPortDestCustomsClear, vo.getPortDestCustomsClear())
//                .eqIfPresent(OrderDO::getSumValue, vo.getSumValue())
//                .eqIfPresent(OrderDO::getValuationFee, vo.getValuationFee())
                    .betweenIfPresent(OrderDO::getRucangTime, vo.getBeginRucangTime(), vo.getEndRucangTime())
                    .betweenIfPresent(OrderDO::getDaogangTime, vo.getBeginDaogangTime(), vo.getEndDaogangTime())
                    .betweenIfPresent(OrderDO::getQingguanTime, vo.getBeginQingguanTime(), vo.getEndQingguanTime())
                    .betweenIfPresent(OrderDO::getPreLoadTime, vo.getBeginPreLoadTime(), vo.getEndPreLoadTime())
                    .betweenIfPresent(OrderDO::getLoadTime, vo.getBeginLoadTime(), vo.getEndLoadTime())
                    .betweenIfPresent(OrderDO::getUnloadTime, vo.getBeginUnloadTime(), vo.getEndUnloadTime())
                    .betweenIfPresent(OrderDO::getTakeTime, vo.getBeginTakeTime(), vo.getEndTakeTime())
                    .betweenIfPresent(OrderDO::getSplitTime, vo.getBeginSplitTime(), vo.getEndSplitTime())
                    .betweenIfPresent(OrderDO::getCreateTime, vo.getBeginCreateTime(), vo.getEndCreateTime())
                    .ne(OrderDO::getInWarehouseState, 211)
                    .orderByDesc(OrderDO::getOrderId));
        }

        return null;
    }

    @Override
    default List<OrderDO> selectList(Object object) {
        if (object instanceof OrderQueryVO) {
            OrderQueryVO vo = (OrderQueryVO) object;
            return selectList(new LambdaQuery<OrderDO>()
                    .eqIfPresent(OrderDO::getOrderNo, vo.getOrderNo())
                    .eqIfPresent(OrderDO::getTidanNo, vo.getTidanNo())
                    .eqIfPresent(OrderDO::getParentNumber, vo.getParentNumber())
                    .eqIfPresent(OrderDO::getParentOrderId, vo.getParentOrderId())
                    .eqIfPresent(OrderDO::getInitialParentOrderId, vo.getInitialParentOrderId())
                    .eqIfPresent(OrderDO::getOldNumbers, vo.getOldNumbers())
                    .eqIfPresent(OrderDO::getTransportId, vo.getTransportId())
                    .eqIfPresent(OrderDO::getLineId, vo.getLineId())
                    .eqIfPresent(OrderDO::getChannelId, vo.getChannelId())
                    .eqIfPresent(OrderDO::getType, vo.getType())
                    .eqIfPresent(OrderDO::getOrderType, vo.getOrderType())
                    .eqIfPresent(OrderDO::getUserId, vo.getUserId())
                    .eqIfPresent(OrderDO::getSalesmanId, vo.getSalesmanId())
                    .eqIfPresent(OrderDO::getMarks, vo.getMarks())
                    .eqIfPresent(OrderDO::getProductRecord, vo.getProductRecord())
                    .eqIfPresent(OrderDO::getIsCargoControl, vo.getIsCargoControl())
                    .eqIfPresent(OrderDO::getCargoControlStatus, vo.getCargoControlStatus())
                    .eqIfPresent(OrderDO::getCustomsType, vo.getCustomsType())
                    .eqIfPresent(OrderDO::getUpFile, vo.getUpFile())
                    .eqIfPresent(OrderDO::getPayType, vo.getPayType())
                    .eqIfPresent(OrderDO::getStatus, vo.getStatus())
                    .eqIfPresent(OrderDO::getOldStatus, vo.getOldStatus())
                    .eqIfPresent(OrderDO::getAbnormalState, vo.getAbnormalState())
                    .eqIfPresent(OrderDO::getInWarehouseState, vo.getInWarehouseState())
                    .eqIfPresent(OrderDO::getOldInWarehouseState, vo.getOldInWarehouseState())
                    .eqIfPresent(OrderDO::getShipmentState, vo.getShipmentState())
                    .eqIfPresent(OrderDO::getOldShipmentState, vo.getOldShipmentState())
                    .eqIfPresent(OrderDO::getAuditType, vo.getAuditType())
                    .eqIfPresent(OrderDO::getAuditResult, vo.getAuditResult())
                    .eqIfPresent(OrderDO::getIsDel, vo.getIsDel())
                    .eqIfPresent(OrderDO::getCollectionProxy, vo.getCollectionProxy())
                    .eqIfPresent(OrderDO::getCollectionProxyCurrency, vo.getCollectionProxyCurrency())
                    .eqIfPresent(OrderDO::getIsCollection, vo.getIsCollection())
                    .eqIfPresent(OrderDO::getWVolume, vo.getWVolume())
                    .eqIfPresent(OrderDO::getVWeight, vo.getVWeight())
                    .eqIfPresent(OrderDO::getWeightUnit, vo.getWeightUnit())
                    .eqIfPresent(OrderDO::getVolumeUnit, vo.getVolumeUnit())
                    .eqIfPresent(OrderDO::getOrgWeightUnit, vo.getOrgWeightUnit())
                    .eqIfPresent(OrderDO::getOrgVolumeUnit, vo.getOrgVolumeUnit())
                    .eqIfPresent(OrderDO::getWarehouseType, vo.getWarehouseType())
                    .eqIfPresent(OrderDO::getSendsms, vo.getSendsms())
                    .eqIfPresent(OrderDO::getDocumentsFile, vo.getDocumentsFile())
                    .eqIfPresent(OrderDO::getRemarks, vo.getRemarks())
                    .eqIfPresent(OrderDO::getAdjustToStartWarehouseId, vo.getAdjustToStartWarehouseId())
                    .eqIfPresent(OrderDO::getAdjustToDestWarehouseId, vo.getAdjustToDestWarehouseId())
                    .eqIfPresent(OrderDO::getSumNum, vo.getSumNum())
                    .eqIfPresent(OrderDO::getSumVolume, vo.getSumVolume())
                    .eqIfPresent(OrderDO::getSumWeight, vo.getSumWeight())
                    .eqIfPresent(OrderDO::getWeightRatio, vo.getWeightRatio())
                    .eqIfPresent(OrderDO::getCustomerId, vo.getCustomerId())
                    .eqIfPresent(OrderDO::getDrawee, vo.getDrawee())
                    .eqIfPresent(OrderDO::getCustomDrawee, vo.getCustomDrawee())
                    .eqIfPresent(OrderDO::getAirShipment, vo.getAirShipment())
                    .eqIfPresent(OrderDO::getDeliveryWay, vo.getDeliveryWay())
                    .eqIfPresent(OrderDO::getPortDestCustomsClear, vo.getPortDestCustomsClear())
                    .likeIfPresent(OrderDO::getPackingListUrl, vo.getPackingListUrl())
//                .eqIfPresent(OrderDO::getSumValue, vo.getSumValue())
//                .eqIfPresent(OrderDO::getValuationFee, vo.getValuationFee())
                    .betweenIfPresent(OrderDO::getRucangTime, vo.getBeginRucangTime(), vo.getEndRucangTime())
                    .betweenIfPresent(OrderDO::getDaogangTime, vo.getBeginDaogangTime(), vo.getEndDaogangTime())
                    .betweenIfPresent(OrderDO::getQingguanTime, vo.getBeginQingguanTime(), vo.getEndQingguanTime())
                    .betweenIfPresent(OrderDO::getPreLoadTime, vo.getBeginPreLoadTime(), vo.getEndPreLoadTime())
                    .betweenIfPresent(OrderDO::getLoadTime, vo.getBeginLoadTime(), vo.getEndLoadTime())
                    .betweenIfPresent(OrderDO::getUnloadTime, vo.getBeginUnloadTime(), vo.getEndUnloadTime())
                    .betweenIfPresent(OrderDO::getTakeTime, vo.getBeginTakeTime(), vo.getEndTakeTime())
                    .betweenIfPresent(OrderDO::getSplitTime, vo.getBeginSplitTime(), vo.getEndSplitTime())
                    .betweenIfPresent(OrderDO::getCreateTime, vo.getBeginCreateTime(), vo.getEndCreateTime())
                    .ne(OrderDO::getInWarehouseState, 211)
                    .orderByDesc(OrderDO::getOrderId));
        }

        return null;
    }

    @ResultType(OrderBackPageVO.class)
    @Select({
            "<script>",
            "select o.order_id, ",
            "o.package_type as advance_type, ",
            "o.package_remarks, ",
            "o.number, ",
            "o.order_no, ",
            "o.tidan_no, ",
            "o.type, ",
            "o.order_type, ",
            "o.air_shipment, ",
//            "IF(o.order_type != 2 and (SELECT COUNT(1) FROM ecw_order_exception hoe WHERE hoe.order_id = o.order_id AND hoe.deleted = 0 AND hoe.order_exception_status = 0 AND hoe.order_exception_type ='order_heavy_cargo_exception') = 0, o.sum_volume, o.w_volume ) as w_volume, ",
            "IFNULL((select SUM(IF(it.charge_volume > it.min_metering_volume, it.charge_volume, it.min_metering_volume)) FROM ecw_order_item it WHERE it.order_id = o.order_id and it.deleted = 0 and it.warehouse_in_info IS NOT NULL), 0) as w_volume, ",
//            "IF(o.order_type != 3 and (SELECT COUNT(1) FROM ecw_order_exception boe WHERE boe.order_id = o.order_id AND boe.deleted = 0 AND boe.order_exception_status = 0 AND boe.order_exception_type ='order_bulky_cargo_exception') = 0, o.sum_weight, o.v_weight ) as v_weight, ",
            "IFNULL((select SUM(IF( it.charge_weight > it.min_metering_weight, it.charge_weight, it.min_metering_weight)) FROM ecw_order_item it WHERE it.order_id = o.order_id and it.deleted = 0 and it.warehouse_in_info IS NOT NULL), 0) as v_weight, ",
            "o.customs_type, ",
            "if(#{query.customerDetailId} is not null and #{query.customerDetailId} > 0, (select min(owi.`in_time`) from ecw_order_warehouse_in owi where owi.deleted = 0 and owi.order_id = o.order_id ), o.rucang_time ) as rucang_time,",
            "o.cost, ",
            "o.parent_number, ",
            "o.parent_order_id, ",
            "o.initial_parent_order_id, ",
            "if(#{query.lang} = 0, de.departure ->> '$.titleZh', de.departure ->> '$.titleEn') as departure_name, ",
            "if(#{query.lang} = 0, ob.objective ->> '$.titleZh', ob.objective ->> '$.titleEn') as objective_name, ",
            "de.departure_id, ",
            "ob.objective_id, ",
            "o.adjust_to_start_warehouse_id, ",
            "(SELECT IF(0 = 0, ew_start_adjust.title_zh, ew_start_adjust.title_en) FROM ecw_warehouse ew_start_adjust WHERE ew_start_adjust.id = o.adjust_to_start_warehouse_id) AS adjust_to_start_warehouse_name,",
            "o.adjust_to_dest_warehouse_id, ",
            "(SELECT IF(0 = 0, ew_dest_adjust.title_zh, ew_dest_adjust.title_en) FROM ecw_warehouse ew_dest_adjust WHERE ew_dest_adjust.id = o.adjust_to_dest_warehouse_id) AS adjust_to_dest_warehouse_name,",
            "w.start_warehouse_name,",
            "w.dst_warehouse_name,",
            "w.start_warehouse_id,",
            "w.dst_warehouse_id,",
            "o.marks, ",
            "o.salesman_id, ",
            "o.status, ",
            "o.abnormal_state, ",
            "o.in_warehouse_state, ",
            "o.shipment_state, ",
            "o.pick_state, ",
            "o.audit_type, ",
            "o.audit_result, ",
            "o.guan_lian_order_status, ",
            "o.transport_id, ",
            "(select ifnull(sum(ccp.pick_num),0) from ecw_order_cargo_control_pick ccp where ccp.order_id = o.order_id and ccp.status in(1,2,3,4) ) as release_num, ",
            "o.is_cargo_control, ",
            "o.cargo_control_status, ",
            "o.cost ->> '$.totalNum' as total_num, ",
            "o.sum_num, ",
            "o.sum_volume, ",
            "o.sum_weight, ",
            "o.sum_volume_finished_warehouse_in, ",
            "o.sum_weight_finished_warehouse_in, ",
            "o.packing_list_url, ",
            "o.is_external_warehouse, ",
            "o.exception_reason, ",
            "o.is_exception, ",
            "o.create_time, ",
            "o.load_time, ",
            "(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, ",
            "IF(o.user_id is not null AND o.user_id > 0 AND o.`status` = 0, 1 , 0)  as st, ",
            "if(#{query.userType} = 1, 1, 2) as user_type, ",
            "nor.name as consignor_name, ",
            "nor.name_en as consignor_name_en, ",
            "nor.phone as consignor_phone, ",
            "nor.country_code as consignor_country_code,",
            "nee.name as consignee_name, ",
            "nee.name_en as consignee_name_en, ",
            "nee.phone as consignee_phone, ",
            "nee.country_code as consignee_country_code, ",
            "if(#{query.lang} = 0, channel.name_zh, channel.name_en) as channel_name, ",
            "o.update_time, ",
            "#{query.lang} as lang ",
            "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_departure de on de.order_id = o.order_id ",
            "left join ecw_order_objective ob on ob.order_id = o.order_id ",
            "left join ecw_order_consignor nor on nor.order_id = o.order_id ",
            "left join ecw_order_consignee nee on nee.order_id = o.order_id ",
            "left join ecw_channel channel on channel.channel_id = o.channel_id  ",
            "where o.deleted = 0 and o.in_warehouse_state != 211 and o.in_warehouse_state != 208 and o.status != 10",
            "<when test = 'query.deptId != null '>",
            "AND o.dept_id = #{query.deptId} ",
            "</when>",
            "<when test= 'query.deptIdList != null and query.deptIdList.size() > 0'>",
            "AND (o.dept_id IN",
            "<foreach item='deptId' collection='query.deptIdList' open='(' close=')' separator=','> #{deptId} </foreach>",
            " or ",
            "(SELECT u.dept_id FROM system_user u WHERE u.id = o.creator) IN",
            "<foreach item='deptId' collection='query.deptIdList' open='(' close=')' separator=','> #{deptId} </foreach>)",
            "</when>",
            "<when test = 'query.type != null and query.type != \"\" and query.type == 0 '>",
            "AND (o.type is null or o.type = '' or o.type = '0')",
            "</when>",
            "<when test = 'query.type == 1 '>",
            "AND FIND_IN_SET(1, o.type)",
            "</when>",
            "<when test = 'query.type == 2 '>",
            "AND FIND_IN_SET(2, o.type)",
            "</when>",
            "<when test = 'query.pdaStartWareIds != null and query.pdaStartWareIds != \"\" '>",
            "AND FIND_IN_SET(ew_start.`id`, #{query.pdaStartWareIds})",
            "</when>",
            "<when test = 'query.pdaDestWareIds != null and query.pdaDestWareIds != \"\" '>",
            "AND FIND_IN_SET(ew_dest.`id`, #{query.pdaDestWareIds})",
            "</when>",
            "<when test = 'query.packageType != null and query.packageType != \"\" '>",
            "AND CONCAT(',',o.package_type,',') REGEXP CONCAT(',',REPLACE(#{query.packageType},',',',|,'), ',')",
            "</when>",
            "<when test = 'query.isExternalWarehouse != null'>",
            "AND o.`is_external_warehouse` = #{query.isExternalWarehouse}",
            "</when>",
            "<when test = 'query.status != null'>",
            "AND o.`status` = #{query.status}",
            "</when>",
            "<when test = 'query.abnormalState != null'>",
            "<choose>",
            "<when test = 'query.abnormalState != 0'>",
            "<choose>",
            "<when test = '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>",
            "</when>",
            "<when test = 'query.inWarehouseState != null'>",
            "AND o.`in_warehouse_state` = #{query.inWarehouseState}",
            "</when>",
            "<when test = 'query.shipmentState != null'>",
            "AND o.`shipment_State` = #{query.shipmentState}",
            "</when>",
            "<when test = 'query.auditType != null'>",
            "<choose>",
            "<when test = 'query.auditType != 0'>",
            "<choose>",
            "<when test = '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>",
            "</when>",
            "<when test = '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} ))",
            "</when>",
            "<when test = 'query.customsType != null'>",
            "AND o.`customs_type` = #{query.customsType}",
            "</when>",
            "<when test = 'query.productRecord != null'>",
            "AND o.`product_record` = #{query.productRecord}",
            "</when>",
            "<when test = 'query.transportId != null'>",
            "AND o.`transport_id` = #{query.transportId}",
            "</when>",
            "<when test = 'query.channelId != null'>",
            "AND o.`channel_id` = #{query.channelId}",
            "</when>",
            "<when test = 'query.warehouseType != null'>",
            "AND o.`warehouse_type` = #{query.warehouseType}",
            "</when>",
            "<when test = '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},'%'))))))",
            "</when>",
            "<when test = '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},'%')))))",
            "</when>",
            "<when test = 'query.marks != null and query.marks != \"\" '>",
            "AND o.`marks` like concat('%',concat(#{query.marks},'%'))",
            "</when>",
            "<when test = 'query.departureId != null '>",
            "AND de.`departure_id` = #{query.departureId}",
            "</when>",
            "<when test = 'query.objectiveId != null '>",
            "AND ob.`objective_id` = #{query.objectiveId}",
            "</when>",
            "<when test = 'query.consignorId != null '>",
            "AND nor.`customer_id` = #{query.consignorId} ",
            "</when>",
            "<when test = 'query.consignorPhone != null and query.consignorPhone != \"\"  '>",
            "AND nor.`phone` = #{query.consignorPhone} ",
            "</when>",
            "<when test = 'query.consigneeId != null '>",
            "AND nee.`customer_id` = #{query.consigneeId}",
            "</when>",
            "<when test = 'query.consigneePhone != null and query.consigneePhone != \"\"  '>",
            "AND nee.`phone` = #{query.consigneePhone} ",
            "</when>",
            "<when test = 'query.isCargoControl != null '>",
            "AND o.`is_cargo_control` = #{query.isCargoControl}",
            "</when>",
            "<when test = 'query.orderNo != null and query.orderNo != \"\" '>",
            "AND o.`order_no` like concat('%',concat(#{query.orderNo},'%'))",
            "</when>",
            "<when test = 'query.orderIdList != null and query.orderIdList.size() != 0'>",
            "AND o.`order_id` in ",
            "<foreach item='orderId' index='index' collection='query.orderIdList' open='(' separator=',' close=')'>#{orderId}</foreach> ",
            "</when>",
            "<when test = 'query.tidanNo != null and query.tidanNo != \"\" '>",
            "AND o.`tidan_no` like concat('%',concat(#{query.tidanNo},'%'))",
            "</when>",
            "<when test = 'query.containerNumber != null and query.containerNumber != \"\" '>",
            "AND o.`container_number` = #{query.containerNumber}",
            "</when>",
//            "<when test = 'query.userId != null'>",
//            "AND o.`user_id` = #{query.userId}",
//            "</when>",
            "<when test = 'query.customerId != null'>",
            "AND o.`customer_id` = #{query.customerId}",
            "</when>",
            "<when test = 'query.beginRucangTime != null and query.endRucangTime != null '>",
//            "AND o.`rucang_time` between #{query.beginRucangTime} and #{query.endRucangTime}",
            "AND o.order_id in(select distinct wi.order_id from ecw_order_warehouse_in wi where wi.deleted = 0 and wi.`in_time` between #{query.beginRucangTime} and #{query.endRucangTime})",
            "</when>",
            "<when test = 'query.beginQingguanTime != null and query.endQingguanTime != null '>",
            "AND o.`qingguan_time` between #{query.beginQingguanTime} and #{query.endQingguanTime}",
            "</when>",
            "<when test = 'query.beginDaogangTime != null and query.endDaogangTime != null '>",
            "AND o.`daogang_time` between #{query.beginDaogangTime} and #{query.endDaogangTime}",
            "</when>",
            "<when test = 'query.beginPreLoadTime != null and query.endPreLoadTime != null '>",
            "AND o.`status` > 5 AND o.`pre_load_time` between #{query.beginPreLoadTime} and #{query.endPreLoadTime}",
            "</when>",
            "<when test = 'query.beginOutboundTime != null and query.endOutboundTime != null '>",
            "AND o.`status` > 5 AND o.container_number in(select distinct b.self_no from ecw_box_air_checkout bc join ecw_box b ON bc.shipment_id = b.id",
            "where b.deleted = 0 and bc.deleted = 0 and bc.`checkout_time` between #{query.beginOutboundTime} and #{query.endOutboundTime})",
            "</when>",
            "<when test = 'query.beginLoadTime != null and query.endLoadTime != null '>",
            "AND o.`load_time` between #{query.beginLoadTime} and #{query.endLoadTime}",
            "</when>",
            "<when test = 'query.beginUnloadTime != null and query.endUnloadTime != null '>",
            "AND o.`unload_time` between #{query.beginUnloadTime} and #{query.endUnloadTime}",
            "</when>",
            "<when test = 'query.beginTakeTime != null and query.endTakeTime != null '>",
            "AND o.`status` > 19 AND o.`take_time` between #{query.beginTakeTime} and #{query.endTakeTime}",
            "</when>",
            "<when test = 'query.beginSplitTime != null and query.endSplitTime != null '>",
            "AND o.`split_time` between #{query.beginSplitTime} and #{query.endSplitTime}",
            "</when>",
            "<when test = 'query.beginCreateTime != null and query.endCreateTime != null '>",
            "AND o.`create_time` between #{query.beginCreateTime} and #{query.endCreateTime}",
            "</when>",
            "<when test = 'query.beginPickTime != null and query.endPickTime != null '>",
            "AND o.order_id in(select distinct op.order_id from ecw_order_cargo_control_pick op where op.deleted = 0 and op.status in(1,3) and op.`create_time` between #{query.beginPickTime} and #{query.endPickTime})",
            "</when>",
            "<when test = 'query.beginPickUpTime != null and query.endPickUpTime != null '>",
            "AND o.order_no in(select distinct op.order_id from ecw_order_pickup op where op.deleted = 0 and op.`create_time` between #{query.beginPickUpTime} and #{query.endPickUpTime})",
            "</when>",
            "<when test = 'query.beginWarehouseInTime != null and query.endWarehouseInTime != null '>",
            "AND o.order_id in(select distinct wi.order_id from ecw_order_warehouse_in wi where wi.deleted = 0 and wi.`update_time` between #{query.beginWarehouseInTime} and #{query.endWarehouseInTime})",
            "</when>",
            "<when test = 'query.creator != null and query.creator != \"\" '>",
            "AND o.`creator` = #{query.creator} and (o.user_id is null or o.user_id = 0)",
            "</when>",
            "<when test = 'query.searchKey != null and query.searchKey != \"\" '>",
            "AND concat(IFNULL(o.`order_no`,''), IFNULL(o.`old_numbers`,'') ,IFNULL(o.`marks`,''),IFNULL(o.`tidan_no`,''),IFNULL(o.`container_number`,''),IFNULL(nee.`name`,''),IFNULL(nee.`phone`,'')) like concat('%',concat(#{query.searchKey},'%'))",
            "</when>",
            "<when test = '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},'%'))))",
            "</when>",
            "<when test = 'query.notConsignorKey != null and query.notConsignorKey != \"\" '>",
            "AND (concat(IFNULL(nor.`name`,''),IFNULL(nor.`name_en`,''),IFNULL(nor.`phone`,'')) not like concat('%',concat(#{query.notConsignorKey},'%'))",
            "AND nor.customer_id not in (select c.id from ecw_customer c where c.number like concat('%',concat(#{query.notConsignorKey},'%'))))",
            "</when>",
            "<when test = '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},'%'))))",
            "</when>",
            "<when test = 'query.notConsigneeKey != null and query.notConsigneeKey != \"\" '>",
            "AND (concat(IFNULL(nee.`name`,''),IFNULL(nee.`name_en`,''),IFNULL(nee.`phone`,'')) not like concat('%',concat(#{query.notConsigneeKey},'%'))",
            "AND nee.customer_id not in (select c.id from ecw_customer c where c.number like concat('%',concat(#{query.notConsigneeKey},'%'))))",
            "</when>",
            "<when test = 'query.numberKey != null and query.numberKey != \"\" '>",
            "AND concat(IFNULL(o.`order_no`,''), IFNULL(o.`old_numbers`,'') , IFNULL(o.`parent_number`,'') ,IFNULL(o.`initial_parent_order_no`,'') ,IFNULL(o.`marks`,''),IFNULL(o.`tidan_no`,''),IFNULL(o.`container_number`,''),IFNULL(o.`no_charge_record`,'')) like concat('%',concat(#{query.numberKey},'%'))",
            "</when>",
            "<when test = 'query.notNumberKey != null and query.notNumberKey != \"\" '>",
            "AND concat(IFNULL(o.`order_no`,''), IFNULL(o.`old_numbers`,'') , IFNULL(o.`parent_number`,'') ,IFNULL(o.`initial_parent_order_no`,'') ,IFNULL(o.`marks`,''),IFNULL(o.`tidan_no`,''),IFNULL(o.`container_number`,''),IFNULL(o.`no_charge_record`,'')) not like concat('%',concat(#{query.notNumberKey},'%'))",
            "</when>",
            "<when test = 'query.eqNumberKey != null and query.eqNumberKey != \"\" '>",
            "AND (o.`order_no` = #{query.eqNumberKey}",
            "or (o.`old_numbers` is not null and o.`old_numbers` != '' and o.`old_numbers` = #{query.eqNumberKey}) ",
            "or (o.`parent_number` is not null and o.`parent_number` != '' and o.`parent_number` = #{query.eqNumberKey}) ",
            "or (o.`marks` is not null and o.`marks` != '' and o.`marks` = #{query.eqNumberKey}) ",
            "or (o.`tidan_no` is not null and o.`tidan_no` != '' and o.`tidan_no` = #{query.eqNumberKey}) ",
            "or (o.`container_number` is not null and o.`container_number` != '' and o.`container_number` = #{query.eqNumberKey}) ",
            "or (o.`no_charge_record` is not null and o.`no_charge_record` != '' and o.`no_charge_record` = #{query.eqNumberKey})",
            "or (o.`initial_parent_order_no` is not null and o.`initial_parent_order_no` != '' and o.`initial_parent_order_no` = #{query.eqNumberKey}))",
            "</when>",
            "<when test = 'query.notEqNumberKey != null and query.notEqNumberKey != \"\" '>",
            "AND o.`order_no` != #{query.notEqNumberKey}",
            "AND (o.`old_numbers` is null or o.`old_numbers` = '' or o.`old_numbers` != #{query.notEqNumberKey})",
            "AND (o.`parent_number` is null or o.`parent_number` = '' or o.`parent_number` != #{query.notEqNumberKey})",
            "AND (o.`marks` is null or o.`marks` = '' or o.`marks` != #{query.notEqNumberKey})",
            "AND (o.`tidan_no` is null or o.`tidan_no` = '' or o.`tidan_no` != #{query.notEqNumberKey})",
            "AND (o.`container_number` is null or o.`container_number` = '' or o.`container_number` != #{query.notEqNumberKey})",
            "AND (o.`no_charge_record` is null or o.`no_charge_record` = '' or o.`no_charge_record` != #{query.notEqNumberKey})",
            "AND (o.`initial_parent_order_no` is null or o.`initial_parent_order_no` = '' or o.`initial_parent_order_no` != #{query.notEqNumberKey})",
            "</when>",
            "<when test = 'query.prodKey != null and query.prodKey != \"\" '>",
            "and (o.order_id in(",
            "select oi.order_id ",
            "from ecw_order_item oi ",
            "left join ecw_product p ",
            "on oi.prod_id = p.id ",
            "left join ecw_product_type pt ",
            "on pt.id = oi.prod_type ",
            "left join ecw_product_brank pb",
            "on pb.id = oi.brand",
            "where oi.deleted = 0 ",
            "and concat(IFNULL(oi.`prod_title_zh`,''),IFNULL(oi.`prod_title_en`,''),IFNULL(pt.`title_zh`,''),IFNULL(pt.`title_en`,''),IFNULL(pb.`title_zh`,''),IFNULL(pb.`title_en`,''))",
            "like concat('%',concat(#{query.prodKey},'%'))",
            "))",
            "</when>",
            "<when test = 'query.notProdKey != null and query.notProdKey != \"\" '>",
            "and (o.order_id not in(",
            "select oi.order_id ",
            "from ecw_order_item oi ",
            "left join ecw_product p ",
            "on oi.prod_id = p.id ",
            "left join ecw_product_type pt ",
            "on pt.id = oi.prod_type ",
            "left join ecw_product_brank pb",
            "on pb.id = oi.brand",
            "where oi.deleted = 0 and concat(IFNULL(oi.`prod_title_zh`,''),IFNULL(oi.`prod_title_en`,''),IFNULL(pt.`title_zh`,''),IFNULL(pt.`title_en`,''),IFNULL(pb.`title_zh`,''),IFNULL(pb.`title_en`,'')) " ,
            "like concat('%',concat(#{query.notProdKey},'%'))",
            "))",
            "</when>",
            "<when test = 'query.eqProdKey != null and query.eqProdKey != \"\" '>",
            "and (o.order_id in(",
            "select oi.order_id ",
            "from ecw_order_item oi ",
            "left join ecw_product p ",
            "on oi.prod_id = p.id ",
            "left join ecw_product_type pt ",
            "on pt.id = oi.prod_type ",
            "left join ecw_product_brank pb",
            "on pb.id = oi.brand",
            "where oi.deleted = 0 " ,
            "and (oi.`prod_title_zh` = #{query.eqProdKey} or oi.`prod_title_en` = #{query.eqProdKey} " ,
            "or pt.`title_zh` = #{query.eqProdKey} or pt.`title_en` = #{query.eqProdKey}",
            "or pb.`title_zh` = #{query.eqProdKey} or pb.`title_en` = #{query.eqProdKey})",
            "))",
            "</when>",
            "<when test = 'query.notEqProdKey != null and query.notEqProdKey != \"\" '>",
            "and (o.order_id not in(",
            "select oi.order_id ",
            "from ecw_order_item oi ",
            "left join ecw_product p ",
            "on oi.prod_id = p.id ",
            "left join ecw_product_type pt ",
            "on pt.id = oi.prod_type ",
            "left join ecw_product_brank pb",
            "on pb.id = oi.brand",
            "where oi.deleted = 0" ,
            "and (oi.`prod_title_zh` = #{query.notEqProdKey} or oi.`prod_title_en` = #{query.notEqProdKey} " ,
            "or pt.`title_zh` = #{query.notEqProdKey} or pt.`title_en` = #{query.notEqProdKey}",
            "or pb.`title_zh` = #{query.notEqProdKey} or pb.`title_en` = #{query.notEqProdKey})",
            "))",
            "</when>",
            "<when test = 'query.startWarehouseId != null and query.destWarehouseId != null '>",
            "and (o.line_id in(",
            "select whl.id ",
            "from ecw_warehouse_line whl ",
            "where whl.start_warehouse_id = #{query.startWarehouseId} and whl.dest_warehouse_id = #{query.destWarehouseId} ",
            "))",
            "</when>",
            "<when test = 'query.startWarehouseId != null and query.destWarehouseId == null '>",
            "and (o.line_id in(",
            "select whl.id ",
            "from ecw_warehouse_line whl ",
            "where whl.start_warehouse_id = #{query.startWarehouseId}  ",
            "))",
            "</when>",
            "<when test = 'query.startWarehouseId == null and query.destWarehouseId != null '>",
            "and (o.line_id in(",
            "select whl.id ",
            "from ecw_warehouse_line whl ",
            "where whl.dest_warehouse_id = #{query.destWarehouseId} ",
            "))",
            "</when>",
            "<when test = 'query.isNeat == false  '>",
            " AND o.sum_num  <![CDATA[ < ]]> o.cost->>'$.totalNum' ",
            "</when>",
            "<when test = 'query.airShipment != null and query.airShipment == 1'>",
            "AND o.`status` = 5 AND o.air_shipment = 1 and abnormal_state = 0 and audit_type = 0 ",
            "</when>",
            "<when test = 'query.airShipment != null and query.airShipment == 2'>",
            "AND o.`status` = 5  AND o.air_shipment = 2",
            "</when>",
            "<when test = 'query.airShipment != null and query.airShipment == 3'>",
            "AND o.`status` = 5  AND o.air_shipment = 3",
            "</when>",
            "<when test = 'query.airShipment != null and query.airShipment == 4'>",
            "AND o.`status` = 5  AND o.air_shipment = 4",
            "</when>",
            "<when test = 'query.airShipment != null and query.airShipment == 10'>",
            "AND o.`status` = 5 AND o.air_shipment in(2,3,4)",
            "</when>",
            "<when test = 'query.airShipment != null and query.airShipment == 11'>",
            "AND o.`status` = 5  AND o.air_shipment in(1,2,3,4) and abnormal_state = 0 and audit_type = 0 ",
            "</when>",
            "<when test = 'query.airShipment != null and query.airShipment == 12'>",
            "AND o.`status` = 5  AND o.air_shipment in(2,3) and abnormal_state = 0 and audit_type = 0 ",
            "</when>",
            "<when test = 'query.airShipment != null and query.airShipment == 20'>",
            "AND o.`status` = 5  AND o.air_shipment in(0,2,3,4) and abnormal_state = 0 and audit_type = 0 ",
            "</when>",
            "<when test = 'query.isNeat == true  '>",
            " AND o.sum_num  = o.cost->>'$.totalNum' ",
            "</when>",
            "<when test = 'query.customerDetailId != null'>",
            "AND (o.`customer_id` = #{query.customerDetailId} or nor.`customer_id` = #{query.customerDetailId}  or nee.`customer_id` = #{query.customerDetailId})",
            "</when>",
            "<when test = 'query.userType == 2 '>",
            "HAVING st = 0 ",
            "</when>",
            "</script>"
    })
    IPage<OrderBackPageVO> orderPage(IPage<OrderBackPageVO> mpPage, @Param("query") OrderQueryVO query);

    List<OrderBackPageVO> orderList(@Param("start") int start, @Param("size") int size, @Param("query") OrderQueryVO query);

    List<OrderBackPageVO> myOrderPageList(@Param("start") int start, @Param("size") int size, @Param("query") OrderQueryVO query);


    long orderCount(@Param("query") OrderQueryVO query);

    long myOrderCount(@Param("query") OrderQueryVO query);

    List<OrderExcelVO> exportOrderExcelList(@Param("start")int start, @Param("size") int size,@Param("query") OrderQueryVO query);

    /**
     * execl 导出
     * @param start
     * @param size
     * @param query
     * @return
     */
    List<OrderExcelVO> exportMyOrderExcelList(@Param("start")int start, @Param("size") int size,@Param("query") OrderQueryVO query);

    long exportOrderExcelCount(@Param("query") OrderQueryVO query);

    long exportMyOrderExcelCount(@Param("query") OrderQueryVO query);

    @ResultType(OrderBackPageVO.class)
    @Select({
            "<script>",
            "select o.order_id, ",
            "o.package_type as advance_type, ",
            "o.package_remarks, ",
            "o.number, ",
            "o.order_no, ",
            "o.tidan_no, ",
            "o.type, ",
            "o.order_type, ",
            "o.air_shipment, ",
//            "IF(o.order_type != 2 and (SELECT COUNT(1) FROM ecw_order_exception hoe WHERE hoe.order_id = o.order_id AND hoe.deleted = 0 AND hoe.order_exception_status = 0 AND hoe.order_exception_type ='order_heavy_cargo_exception') = 0, o.sum_volume, o.w_volume ) as w_volume, ",
            "IFNULL((select SUM(IF(it.charge_volume > it.min_metering_volume, it.charge_volume, it.min_metering_volume)) FROM ecw_order_item it WHERE it.order_id = o.order_id and it.deleted = 0 and it.warehouse_in_info IS NOT NULL), 0) as w_volume, ",
//            "IF(o.order_type != 3 and (SELECT COUNT(1) FROM ecw_order_exception boe WHERE boe.order_id = o.order_id AND boe.deleted = 0 AND boe.order_exception_status = 0 AND boe.order_exception_type ='order_bulky_cargo_exception') = 0, o.sum_weight, o.v_weight ) as v_weight, ",
            "IFNULL((select SUM(IF( it.charge_weight > it.min_metering_weight, it.charge_weight, it.min_metering_weight)) FROM ecw_order_item it WHERE it.order_id = o.order_id and it.deleted = 0 and it.warehouse_in_info IS NOT NULL), 0) as v_weight, ",
            "o.customs_type, ",
            "o.rucang_time, ",
            "o.cost, ",
            "o.parent_number, ",
            "o.parent_order_id, ",
            "o.initial_parent_order_id, ",
            "if(#{query.lang} = 0, de.departure ->> '$.titleZh', de.departure ->> '$.titleEn') as departure_name, ",
            "if(#{query.lang} = 0, ob.objective ->> '$.titleZh', ob.objective ->> '$.titleEn') as objective_name, ",
            "de.departure_id, ",
            "ob.objective_id, ",
            "o.adjust_to_start_warehouse_id, ",
            "(SELECT IF(0 = 0, ew_start_adjust.title_zh, ew_start_adjust.title_en) FROM ecw_warehouse ew_start_adjust WHERE ew_start_adjust.id = o.adjust_to_start_warehouse_id) AS adjust_to_start_warehouse_name,",
            "o.adjust_to_dest_warehouse_id, ",
            "(SELECT IF(0 = 0, ew_dest_adjust.title_zh, ew_dest_adjust.title_en) FROM ecw_warehouse ew_dest_adjust WHERE ew_dest_adjust.id = o.adjust_to_dest_warehouse_id) AS adjust_to_dest_warehouse_name,",
            "w.start_warehouse_name,",
            "w.dst_warehouse_name,",
            "w.start_warehouse_id,",
            "w.dst_warehouse_id,",
            "o.marks, ",
            "o.salesman_id, ",
            "o.status, ",
            "o.abnormal_state, ",
            "o.in_warehouse_state, ",
            "o.shipment_state, ",
            "o.pick_state, ",
            "o.audit_type, ",
            "o.audit_result, ",
            "o.guan_lian_order_status, ",
            "o.transport_id, ",
            "(select ifnull(sum(ccp.pick_num),0) from ecw_order_cargo_control_pick ccp where ccp.order_id = o.order_id and ccp.status in(1,2,3,4) ) as release_num, ",
            "o.is_cargo_control, ",
            "o.cargo_control_status, ",
            "o.cost ->> '$.totalNum' as total_num, ",
            "o.sum_num, ",
            "o.sum_volume, ",
            "o.sum_weight, ",
            "o.sum_volume_finished_warehouse_in, ",
            "o.sum_weight_finished_warehouse_in, ",
            "o.packing_list_url, ",
            "o.is_external_warehouse, ",
            "o.exception_reason, ",
            "o.is_exception, ",
            "o.create_time, ",
            "IF(o.user_id is not null AND o.user_id > 0 AND o.`status` = 0, 1 , 0)  as st, ",
            "if(#{query.userType} = 1, 1, 2) as user_type, ",
            "nor.name as consignor_name, ",
            "nor.name_en as consignor_name_en, ",
            "nor.phone as consignor_phone, ",
            "nor.country_code as consignor_country_code, ",
            "nee.name as consignee_name, ",
            "nee.name_en as consignee_name_en, ",
            "nee.phone as consignee_phone, ",
            "nee.country_code as consignee_country_code, ",
            "if(#{query.lang} = 0, channel.name_zh, channel.name_en) as channel_name, ",
            "o.update_time, ",
            "#{query.lang} as lang ",
            "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_departure de on de.order_id = o.order_id ",
            "left join ecw_order_objective ob on ob.order_id = o.order_id ",
            "left join ecw_order_consignor nor on nor.order_id = o.order_id ",
            "left join ecw_order_consignee nee on nee.order_id = o.order_id ",
            "left join ecw_channel channel on channel.channel_id = o.channel_id  ",
            "where o.deleted = 0 and o.in_warehouse_state != 211 and o.in_warehouse_state != 208 and o.status != 10 ",
            "AND o.dept_id = #{query.deptId} ",
            "<when test = 'query.pdaStartWareIds != null and query.pdaStartWareIds != \"\" '>",
            "AND FIND_IN_SET(ew_start.`id`, #{query.pdaStartWareIds})",
            "</when>",
            "<when test = 'query.pdaDestWareIds != null and query.pdaDestWareIds != \"\" '>",
            "AND FIND_IN_SET(ew_dest.`id`, #{query.pdaDestWareIds})",
            "</when>",
            "<when test = 'query.packageType != null and query.packageType != \"\" '>",
            "AND CONCAT(',',o.package_type,',') REGEXP CONCAT(',',REPLACE(#{query.packageType},',',',|,'), ',')",
            "</when>",
            "<when test = 'query.isExternalWarehouse != null'>",
            "AND o.`is_external_warehouse` = #{query.isExternalWarehouse}",
            "</when>",
            "<when test = 'query.status != null'>",
            "AND o.`status` = #{query.status}",
            "</when>",
            "<when test = 'query.abnormalState != null'>",
            "<choose>",
            "<when test = 'query.abnormalState != 0'>",
            "<choose>",
            "<when test = '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>",
            "</when>",
            "<when test = 'query.inWarehouseState != null'>",
            "AND o.`in_warehouse_state` = #{query.inWarehouseState}",
            "</when>",
            "<when test = 'query.shipmentState != null'>",
            "AND o.`shipment_State` = #{query.shipmentState}",
            "</when>",
            "<when test = 'query.auditType != null'>",
            "<choose>",
            "<when test = 'query.auditType != 0'>",
            "<choose>",
            "<when test = '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>",
            "</when>",
            "<when test = '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} ))",
            "</when>",
            "<when test = 'query.customsType != null'>",
            "AND o.`customs_type` = #{query.customsType}",
            "</when>",
            "<when test = 'query.productRecord != null'>",
            "AND o.`product_record` = #{query.productRecord}",
            "</when>",
            "<when test = 'query.transportId != null'>",
            "AND o.`transport_id` = #{query.transportId}",
            "</when>",
            "<when test = 'query.channelId != null'>",
            "AND o.`channel_id` = #{query.channelId}",
            "</when>",
            "<when test = 'query.warehouseType != null'>",
            "AND o.`warehouse_type` = #{query.warehouseType}",
            "</when>",
            "<when test = '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},'%'))))))",
            "</when>",
            "<when test = '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},'%')))))",
            "</when>",
            "<when test = 'query.marks != null and query.marks != \"\" '>",
            "AND o.`marks` like concat('%',concat(#{query.marks},'%'))",
            "</when>",
            "<when test = 'query.departureId != null '>",
            "AND de.`departure_id` = #{query.departureId}",
            "</when>",
            "<when test = 'query.objectiveId != null '>",
            "AND ob.`objective_id` = #{query.objectiveId}",
            "</when>",
            "<when test = 'query.consignorId != null '>",
            "AND nor.`customer_id` = #{query.consignorId} ",
            "</when>",
            "<when test = 'query.consignorPhone != null and query.consignorPhone != \"\"  '>",
            "AND nor.`phone` = #{query.consignorPhone} ",
            "</when>",
            "<when test = 'query.consigneeId != null '>",
            "AND nee.`customer_id` = #{query.consigneeId}",
            "</when>",
            "<when test = 'query.consigneePhone != null and query.consigneePhone != \"\"  '>",
            "AND nee.`phone` = #{query.consigneePhone} ",
            "</when>",
            "<when test = 'query.isCargoControl != null '>",
            "AND o.`is_cargo_control` = #{query.isCargoControl}",
            "</when>",
            "<when test = 'query.orderNo != null and query.orderNo != \"\" '>",
            "AND o.`order_no` like concat('%',concat(#{query.orderNo},'%'))",
            "</when>",
            "<when test = 'query.orderIdList != null and query.orderIdList.size() != 0'>",
            "AND o.`order_id` in ",
            "<foreach item='orderId' index='index' collection='query.orderIdList' open='(' separator=',' close=')'>#{orderId}</foreach> ",
            "</when>",
            "<when test = 'query.tidanNo != null and query.tidanNo != \"\" '>",
            "AND o.`tidan_no` like concat('%',concat(#{query.tidanNo},'%'))",
            "</when>",
            "<when test = 'query.containerNumber != null and query.containerNumber != \"\" '>",
            "AND o.`container_number` = #{query.containerNumber}",
            "</when>",
            "<when test = 'query.customerId != null'>",
            "AND o.`customer_id` = #{query.customerId}",
            "</when>",
            "<when test = 'query.beginRucangTime != null and query.endRucangTime != null '>",
//            "AND o.`rucang_time` between #{query.beginRucangTime} and #{query.endRucangTime}",
            "AND o.order_id in(select distinct wi.order_id from ecw_order_warehouse_in wi where wi.deleted = 0 and wi.`in_time` between #{query.beginRucangTime} and #{query.endRucangTime})",
            "</when>",
            "<when test = 'query.beginQingguanTime != null and query.endQingguanTime != null '>",
            "AND o.`qingguan_time` between #{query.beginQingguanTime} and #{query.endQingguanTime}",
            "</when>",
            "<when test = 'query.beginDaogangTime != null and query.endDaogangTime != null '>",
            "AND o.`daogang_time` between #{query.beginDaogangTime} and #{query.endDaogangTime}",
            "</when>",
            "<when test = 'query.beginPreLoadTime != null and query.endPreLoadTime != null '>",
            "AND o.`status` > 5 AND o.`pre_load_time` between #{query.beginPreLoadTime} and #{query.endPreLoadTime}",
            "</when>",
            "<when test = 'query.beginOutboundTime != null and query.endOutboundTime != null '>",
            "AND o.`status` > 5 AND o.container_number in(select distinct b.self_no from ecw_box_air_checkout bc join ecw_box b ON bc.shipment_id = b.id",
            "where b.deleted = 0 and bc.deleted = 0 and bc.`checkout_time` between #{query.beginOutboundTime} and #{query.endOutboundTime})",
            "</when>",
            "<when test = 'query.beginLoadTime != null and query.endLoadTime != null '>",
            "AND o.`load_time` between #{query.beginLoadTime} and #{query.endLoadTime}",
            "</when>",
            "<when test = 'query.beginUnloadTime != null and query.endUnloadTime != null '>",
            "AND o.`unload_time` between #{query.beginUnloadTime} and #{query.endUnloadTime}",
            "</when>",
            "<when test = 'query.beginTakeTime != null and query.endTakeTime != null '>",
            "AND o.`status` > 19 AND o.`take_time` between #{query.beginTakeTime} and #{query.endTakeTime}",
            "</when>",
            "<when test = 'query.beginSplitTime != null and query.endSplitTime != null '>",
            "AND o.`split_time` between #{query.beginSplitTime} and #{query.endSplitTime}",
            "</when>",
            "<when test = 'query.beginCreateTime != null and query.endCreateTime != null '>",
            "AND o.`create_time` between #{query.beginCreateTime} and #{query.endCreateTime}",
            "</when>",
            "<when test = 'query.beginPickTime != null and query.endPickTime != null '>",
            "AND o.order_id in(select distinct op.order_id from ecw_order_cargo_control_pick op where op.deleted = 0 and op.status in(1,3) and op.`create_time` between #{query.beginPickTime} and #{query.endPickTime})",
            "</when>",
            "<when test = 'query.beginPickUpTime != null and query.endPickUpTime != null '>",
            "AND o.order_no in(select distinct op.order_id from ecw_order_pickup op where op.deleted = 0 and op.`create_time` between #{query.beginPickUpTime} and #{query.endPickUpTime})",
            "</when>",
            "<when test = 'query.beginWarehouseInTime != null and query.endWarehouseInTime != null '>",
            "AND o.order_id in(select distinct wi.order_id from ecw_order_warehouse_in wi where wi.deleted = 0 and wi.`update_time` between #{query.beginWarehouseInTime} and #{query.endWarehouseInTime})",
            "</when>",
            "<when test = 'query.creator != null and query.creator != \"\" '>",
            "AND o.`creator` = #{query.creator}",
            "</when>",
            "<when test = 'query.searchKey != null and query.searchKey != \"\" '>",
            "AND concat(IFNULL(o.`order_no`,''), IFNULL(o.`old_numbers`,'') ,IFNULL(o.`marks`,''),IFNULL(o.`tidan_no`,''),IFNULL(o.`container_number`,''),IFNULL(nee.`name`,''),IFNULL(nee.`phone`,'')) like concat('%',concat(#{query.searchKey},'%'))",
            "</when>",
            "<when test = '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},'%'))))",
            "</when>",
            "<when test = 'query.notConsignorKey != null and query.notConsignorKey != \"\" '>",
            "AND (concat(IFNULL(nor.`name`,''),IFNULL(nor.`name_en`,''),IFNULL(nor.`phone`,'')) not like concat('%',concat(#{query.notConsignorKey},'%'))",
            "AND nor.customer_id not in (select c.id from ecw_customer c where c.number like concat('%',concat(#{query.notConsignorKey},'%'))))",
            "</when>",
            "<when test = '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},'%'))))",
            "</when>",
            "<when test = 'query.notConsigneeKey != null and query.notConsigneeKey != \"\" '>",
            "AND (concat(IFNULL(nee.`name`,''),IFNULL(nee.`name_en`,''),IFNULL(nee.`phone`,'')) not like concat('%',concat(#{query.notConsigneeKey},'%'))",
            "AND nee.customer_id not in (select c.id from ecw_customer c where c.number like concat('%',concat(#{query.notConsigneeKey},'%'))))",
            "</when>",
            "<when test = 'query.numberKey != null and query.numberKey != \"\" '>",
            "AND concat(IFNULL(o.`order_no`,''), IFNULL(o.`old_numbers`,''), IFNULL(o.`parent_number`,'') ,IFNULL(o.`initial_parent_order_no`,'') ,IFNULL(o.`marks`,''),IFNULL(o.`tidan_no`,''),IFNULL(o.`container_number`,''),IFNULL(o.`no_charge_record`,'')) like concat('%',concat(#{query.numberKey},'%'))",
            "</when>",
            "<when test = 'query.notNumberKey != null and query.notNumberKey != \"\" '>",
            "AND concat(IFNULL(o.`order_no`,''), IFNULL(o.`old_numbers`,'') , IFNULL(o.`parent_number`,'') ,IFNULL(o.`initial_parent_order_no`,'') ,IFNULL(o.`marks`,''),IFNULL(o.`tidan_no`,''),IFNULL(o.`container_number`,''),IFNULL(o.`no_charge_record`,'')) not like concat('%',concat(#{query.notNumberKey},'%'))",
            "</when>",
            "<when test = 'query.eqNumberKey != null and query.eqNumberKey != \"\" '>",
            "AND (o.`order_no` = #{query.eqNumberKey}",
            "or (o.`old_numbers` is not null and o.`old_numbers` != '' and o.`old_numbers` = #{query.eqNumberKey}) ",
            "or (o.`parent_number` is not null and o.`parent_number` != '' and o.`parent_number` = #{query.eqNumberKey}) ",
            "or (o.`marks` is not null and o.`marks` != '' and o.`marks` = #{query.eqNumberKey}) ",
            "or (o.`tidan_no` is not null and o.`tidan_no` != '' and o.`tidan_no` = #{query.eqNumberKey}) ",
            "or (o.`container_number` is not null and o.`container_number` != '' and o.`container_number` = #{query.eqNumberKey}) ",
            "or (o.`no_charge_record` is not null and o.`no_charge_record` != '' and o.`no_charge_record` = #{query.eqNumberKey})",
            "or (o.`initial_parent_order_no` is not null and o.`initial_parent_order_no` != '' and o.`initial_parent_order_no` = #{query.eqNumberKey}))",
            "</when>",
            "<when test = 'query.notEqNumberKey != null and query.notEqNumberKey != \"\" '>",
            "AND o.`order_no` != #{query.notEqNumberKey}",
            "AND (o.`old_numbers` is null or o.`old_numbers` = '' or o.`old_numbers` != #{query.notEqNumberKey})",
            "AND (o.`parent_number` is null or o.`parent_number` = '' or o.`parent_number` != #{query.notEqNumberKey})",
            "AND (o.`marks` is null or o.`marks` = '' or o.`marks` != #{query.notEqNumberKey})",
            "AND (o.`tidan_no` is null or o.`tidan_no` = '' or o.`tidan_no` != #{query.notEqNumberKey})",
            "AND (o.`container_number` is null or o.`container_number` = '' or o.`container_number` != #{query.notEqNumberKey})",
            "AND (o.`no_charge_record` is null or o.`no_charge_record` = '' or o.`no_charge_record` != #{query.notEqNumberKey})",
            "AND (o.`initial_parent_order_no` is null or o.`initial_parent_order_no` = '' or o.`initial_parent_order_no` != #{query.notEqNumberKey})",
            "</when>",
            "<when test = 'query.prodKey != null and query.prodKey != \"\" '>",
            "and (o.order_id in(",
            "select oi.order_id ",
            "from ecw_order_item oi ",
            "left join ecw_product p ",
            "on oi.prod_id = p.id ",
            "left join ecw_product_type pt ",
            "on pt.id = oi.prod_type ",
            "left join ecw_product_brank pb",
            "on pb.id = oi.brand",
            "where oi.deleted = 0 ",
            "and concat(IFNULL(oi.`prod_title_zh`,''),IFNULL(oi.`prod_title_en`,''),IFNULL(pt.`title_zh`,''),IFNULL(pt.`title_en`,''),IFNULL(pb.`title_zh`,''),IFNULL(pb.`title_en`,''))",
            "like concat('%',concat(#{query.prodKey},'%'))",
            "))",
            "</when>",
            "<when test = 'query.notProdKey != null and query.notProdKey != \"\" '>",
            "and (o.order_id not in(",
            "select oi.order_id ",
            "from ecw_order_item oi ",
            "left join ecw_product p ",
            "on oi.prod_id = p.id ",
            "left join ecw_product_type pt ",
            "on pt.id = oi.prod_type ",
            "left join ecw_product_brank pb",
            "on pb.id = oi.brand",
            "where oi.deleted = 0 and concat(IFNULL(oi.`prod_title_zh`,''),IFNULL(oi.`prod_title_en`,''),IFNULL(pt.`title_zh`,''),IFNULL(pt.`title_en`,''),IFNULL(pb.`title_zh`,''),IFNULL(pb.`title_en`,'')) " ,
            "like concat('%',concat(#{query.notProdKey},'%'))",
            "))",
            "</when>",
            "<when test = 'query.eqProdKey != null and query.eqProdKey != \"\" '>",
            "and (o.order_id in(",
            "select oi.order_id ",
            "from ecw_order_item oi ",
            "left join ecw_product p ",
            "on oi.prod_id = p.id ",
            "left join ecw_product_type pt ",
            "on pt.id = oi.prod_type ",
            "left join ecw_product_brank pb",
            "on pb.id = oi.brand",
            "where oi.deleted = 0 " ,
            "and (oi.`prod_title_zh` = #{query.eqProdKey} or oi.`prod_title_en` = #{query.eqProdKey} " ,
            "or pt.`title_zh` = #{query.eqProdKey} or pt.`title_en` = #{query.eqProdKey}",
            "or pb.`title_zh` = #{query.eqProdKey} or pb.`title_en` = #{query.eqProdKey})",
            "))",
            "</when>",
            "<when test = 'query.notEqProdKey != null and query.notEqProdKey != \"\" '>",
            "and (o.order_id not in(",
            "select oi.order_id ",
            "from ecw_order_item oi ",
            "left join ecw_product p ",
            "on oi.prod_id = p.id ",
            "left join ecw_product_type pt ",
            "on pt.id = oi.prod_type ",
            "left join ecw_product_brank pb",
            "on pb.id = oi.brand",
            "where oi.deleted = 0" ,
            "and (oi.`prod_title_zh` = #{query.notEqProdKey} or oi.`prod_title_en` = #{query.notEqProdKey} " ,
            "or pt.`title_zh` = #{query.notEqProdKey} or pt.`title_en` = #{query.notEqProdKey}",
            "or pb.`title_zh` = #{query.notEqProdKey} or pb.`title_en` = #{query.notEqProdKey})",
            "))",
            "</when>",
            "<when test = 'query.startWarehouseId != null and query.destWarehouseId != null '>",
            "and (o.line_id in(",
            "select whl.id ",
            "from ecw_warehouse_line whl ",
            "where whl.start_warehouse_id = #{query.startWarehouseId} and whl.dest_warehouse_id = #{query.destWarehouseId} ",
            "))",
            "</when>",
            "<when test = 'query.startWarehouseId != null and query.destWarehouseId == null '>",
            "and (o.line_id in(",
            "select whl.id ",
            "from ecw_warehouse_line whl ",
            "where whl.start_warehouse_id = #{query.startWarehouseId}  ",
            "))",
            "</when>",
            "<when test = 'query.startWarehouseId == null and query.destWarehouseId != null '>",
            "and (o.line_id in(",
            "select whl.id ",
            "from ecw_warehouse_line whl ",
            "where whl.dest_warehouse_id = #{query.destWarehouseId} ",
            "))",
            "</when>",
            "<when test = 'query.isNeat == false  '>",
            " AND o.sum_num  <![CDATA[ < ]]> o.cost->>'$.totalNum' ",
            "</when>",
            "<when test = 'query.isNeat == true  '>",
            " AND o.sum_num  = o.cost->>'$.totalNum' ",
            "</when>",
            "<when test = 'query.customerDetailId != null'>",
            "AND (o.`customer_id` = #{query.customerDetailId} or nor.`customer_id` = #{query.customerDetailId}  or nee.`customer_id` = #{query.customerDetailId})",
            "</when>",
            "<when test = 'query.type != null and query.type != \"\" and query.type == 0 '>",
            "AND (o.type is null or o.type = '' or o.type = '0')",
            "</when>",
            "<when test = 'query.type == 1 '>",
            "AND FIND_IN_SET(1, o.type)",
            "</when>",
            "<when test = 'query.type == 2 '>",
            "AND FIND_IN_SET(2, o.type)",
            "</when>",
            "<when test = 'query.userType == 2 '>",
            "HAVING st = 0 ",
            "</when>",
            "</script>"
    })
    IPage<OrderBackPageVO> deptOrderPage(IPage<OrderBackPageVO> mpPage, @Param("query") OrderQueryVO query);

    List<OrderBackPageVO> deptOrderList(@Param("start") int start, @Param("size") int size, @Param("query") OrderQueryVO query);

    List<OrderBackPageVO> deptOrderList1(@Param("start") int start, @Param("size") int size, @Param("query") OrderQueryVO query);

    long deptOrderCount(@Param("query") OrderQueryVO query);

    long deptOrderCount1(@Param("query") OrderQueryVO query);

    @ResultType(OrderBackPageVO.class)
    @Select({
            "<script>",
            "select o.order_id, ",
            "o.package_type as advance_type, ",
            "o.package_remarks, ",
            "o.number, ",
            "o.order_no, ",
            "o.tidan_no, ",
            "o.type, ",
            "o.order_type, ",
            "o.air_shipment, ",
//            "IF(o.order_type != 2 and (SELECT COUNT(1) FROM ecw_order_exception hoe WHERE hoe.order_id = o.order_id AND hoe.deleted = 0 AND hoe.order_exception_status = 0 AND hoe.order_exception_type ='order_heavy_cargo_exception') = 0, o.sum_volume, o.w_volume ) as w_volume, ",
            "IFNULL((select SUM(IF(it.charge_volume > it.min_metering_volume, it.charge_volume, it.min_metering_volume)) FROM ecw_order_item it WHERE it.order_id = o.order_id and it.deleted = 0 and it.warehouse_in_info IS NOT NULL), 0) as w_volume, ",
//            "IF(o.order_type != 3 and (SELECT COUNT(1) FROM ecw_order_exception boe WHERE boe.order_id = o.order_id AND boe.deleted = 0 AND boe.order_exception_status = 0 AND boe.order_exception_type ='order_bulky_cargo_exception') = 0, o.sum_weight, o.v_weight ) as v_weight, ",
            "IFNULL((select SUM(IF( it.charge_weight > it.min_metering_weight, it.charge_weight, it.min_metering_weight)) FROM ecw_order_item it WHERE it.order_id = o.order_id and it.deleted = 0 and it.warehouse_in_info IS NOT NULL), 0) as v_weight, ",
            "o.customs_type, ",
            "o.rucang_time, ",
            "o.cost, ",
            "o.parent_number, ",
            "o.parent_order_id, ",
            "o.initial_parent_order_id, ",
            "if(#{query.lang} = 0, de.departure ->> '$.titleZh', de.departure ->> '$.titleEn') as departure_name, ",
            "if(#{query.lang} = 0, ob.objective ->> '$.titleZh', ob.objective ->> '$.titleEn') as objective_name, ",
            "de.departure_id, ",
            "ob.objective_id, ",
            "o.adjust_to_start_warehouse_id, ",
            "(SELECT IF(0 = 0, ew_start_adjust.title_zh, ew_start_adjust.title_en) FROM ecw_warehouse ew_start_adjust WHERE ew_start_adjust.id = o.adjust_to_start_warehouse_id) AS adjust_to_start_warehouse_name,",
            "o.adjust_to_dest_warehouse_id, ",
            "(SELECT IF(0 = 0, ew_dest_adjust.title_zh, ew_dest_adjust.title_en) FROM ecw_warehouse ew_dest_adjust WHERE ew_dest_adjust.id = o.adjust_to_dest_warehouse_id) AS adjust_to_dest_warehouse_name,",
            "w.start_warehouse_name,",
            "w.dst_warehouse_name,",
            "w.start_warehouse_id,",
            "w.dst_warehouse_id,",
            "o.marks, ",
            "o.status, ",
            "o.abnormal_state, ",
            "o.in_warehouse_state, ",
            "o.shipment_state, ",
            "o.pick_state, ",
            "o.audit_type, ",
            "o.audit_result, ",
            "o.transport_id, ",
            "(select ifnull(sum(ccp.pick_num),0) from ecw_order_cargo_control_pick ccp where ccp.order_id = o.order_id and ccp.status in(1,2,3,4) ) as release_num, ",
            "o.is_cargo_control, ",
            "o.cargo_control_status, ",
            "o.cost ->> '$.totalNum' as total_num, ",
            "o.sum_num, ",
            "o.sum_volume, ",
            "o.sum_weight, ",
            "o.sum_volume_finished_warehouse_in, ",
            "o.sum_weight_finished_warehouse_in, ",
            "o.packing_list_url, ",
            "o.is_external_warehouse, ",
            "o.exception_reason, ",
            "o.is_exception, ",
            "o.create_time, ",
            "IF(o.user_id is not null AND o.user_id > 0 AND o.`status` = 0, 1 , 0)  as st, ",
            "if(#{query.userType} = 1, 1, 2) as user_type, ",
            "nor.name as consignor_name, ",
            "nor.name_en as consignor_name_en, ",
            "nor.phone as consignor_phone, ",
            "nor.country_code as consignor_country_code, ",
            "nee.name as consignee_name, ",
            "nee.name_en as consignee_name_en, ",
            "nee.phone as consignee_phone, ",
            "nee.country_code as consignee_country_code, ",
            "if(#{query.lang} = 0, channel.name_zh, channel.name_en) as channel_name, ",
            "o.update_time, ",
            "#{query.lang} as lang ",
            "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_departure de on de.order_id = o.order_id ",
            "left join ecw_order_objective ob on ob.order_id = o.order_id ",
            "left join ecw_order_consignor nor on nor.order_id = o.order_id ",
            "left join ecw_order_consignee nee on nee.order_id = o.order_id ",
            "left join ecw_channel channel on channel.channel_id = o.channel_id  ",
            "where o.deleted = 0 and o.in_warehouse_state != 211 and o.in_warehouse_state != 208 and o.status != 10 ",
            "<when test = 'query.deptId != null '>",
            "AND o.dept_id = #{query.deptId} ",
            "</when>",
            "<when test= 'query.deptIdList != null and query.deptIdList.size() > 0'>",
            "AND (o.dept_id IN",
            "<foreach item='deptId' collection='query.deptIdList' open='(' close=')' separator=','> #{deptId} </foreach>",
            " or ",
            "(SELECT u.dept_id FROM system_user u WHERE u.id = o.creator) IN",
            "<foreach item='deptId' collection='query.deptIdList' open='(' close=')' separator=','> #{deptId} </foreach>)",
            "</when>",
            "AND (o.user_id = #{query.userId} or nor.`phone` = #{query.consignorPhone} or nor.customer_contacts_id = #{query.consignorContactsId})",
            "<when test = 'query.pdaStartWareIds != null and query.pdaStartWareIds != \"\" '>",
            "AND FIND_IN_SET(ew_start.`id`, #{query.pdaStartWareIds})",
            "</when>",
            "<when test = 'query.pdaDestWareIds != null and query.pdaDestWareIds != \"\" '>",
            "AND FIND_IN_SET(ew_dest.`id`, #{query.pdaDestWareIds})",
            "</when>",
            "<when test = 'query.packageType != null and query.packageType != \"\" '>",
            "AND CONCAT(',',o.package_type,',') REGEXP CONCAT(',',REPLACE(#{query.packageType},',',',|,'), ',')",
            "</when>",
            "<when test = 'query.isExternalWarehouse != null'>",
            "AND o.`is_external_warehouse` = #{query.isExternalWarehouse}",
            "</when>",
            "<when test = 'query.status != null'>",
            "AND o.`status` = #{query.status}",
            "</when>",
            "<when test = '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} ))",
            "</when>",
            "<when test = 'query.customsType != null'>",
            "AND o.`customs_type` = #{query.customsType}",
            "</when>",
            "<when test = 'query.productRecord != null'>",
            "AND o.`product_record` = #{query.productRecord}",
            "</when>",
            "<when test = 'query.transportId != null'>",
            "AND o.`transport_id` = #{query.transportId}",
            "</when>",
            "<when test = 'query.channelId != null'>",
            "AND o.`channel_id` = #{query.channelId}",
            "</when>",
            "<when test = 'query.warehouseType != null'>",
            "AND o.`warehouse_type` = #{query.warehouseType}",
            "</when>",
            "<when test = '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},'%'))))))",
            "</when>",
            "<when test = '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},'%')))))",
            "</when>",
            "<when test = 'query.marks != null and query.marks != \"\" '>",
            "AND o.`marks` like concat('%',concat(#{query.marks},'%'))",
            "</when>",
            "<when test = 'query.departureId != null '>",
            "AND de.`departure_id` = #{query.departureId}",
            "</when>",
            "<when test = 'query.objectiveId != null '>",
            "AND ob.`objective_id` = #{query.objectiveId}",
            "</when>",
            "<when test = 'query.consigneePhone != null and query.consigneePhone != \"\"  '>",
            "AND nee.`phone` = #{query.consigneePhone} ",
            "</when>",
            "<when test = 'query.isCargoControl != null '>",
            "AND o.`is_cargo_control` = #{query.isCargoControl}",
            "</when>",
            "<when test = 'query.orderNo != null and query.orderNo != \"\" '>",
            "AND o.`order_no` like concat('%',concat(#{query.orderNo},'%'))",
            "</when>",
            "<when test = 'query.orderIdList != null and query.orderIdList.size() != 0'>",
            "AND o.`order_id` in ",
            "<foreach item='orderId' index='index' collection='query.orderIdList' open='(' separator=',' close=')'>#{orderId}</foreach> ",
            "</when>",
            "<when test = 'query.tidanNo != null and query.tidanNo != \"\" '>",
            "AND o.`tidan_no` like concat('%',concat(#{query.tidanNo},'%'))",
            "</when>",
            "<when test = 'query.containerNumber != null and query.containerNumber != \"\" '>",
            "AND o.`container_number` = #{query.containerNumber}",
            "</when>",
            "<when test = 'query.customerId != null'>",
            "AND o.`customer_id` = #{query.customerId}",
            "</when>",
            "<when test = 'query.beginRucangTime != null and query.endRucangTime != null '>",
//            "AND o.`rucang_time` between #{query.beginRucangTime} and #{query.endRucangTime}",
            "AND o.order_id in(select distinct wi.order_id from ecw_order_warehouse_in wi where wi.deleted = 0 and wi.`in_time` between #{query.beginRucangTime} and #{query.endRucangTime})",
            "</when>",
            "<when test = 'query.beginQingguanTime != null and query.endQingguanTime != null '>",
            "AND o.`qingguan_time` between #{query.beginQingguanTime} and #{query.endQingguanTime}",
            "</when>",
            "<when test = 'query.beginDaogangTime != null and query.endDaogangTime != null '>",
            "AND o.`daogang_time` between #{query.beginDaogangTime} and #{query.endDaogangTime}",
            "</when>",
            "<when test = 'query.beginPreLoadTime != null and query.endPreLoadTime != null '>",
            "AND o.`status` > 5 AND o.`pre_load_time` between #{query.beginPreLoadTime} and #{query.endPreLoadTime}",
            "</when>",
            "<when test = 'query.beginOutboundTime != null and query.endOutboundTime != null '>",
            "AND o.`status` > 5 AND o.container_number in(select distinct b.self_no from ecw_box_air_checkout bc join ecw_box b ON bc.shipment_id = b.id",
            "where b.deleted = 0 and bc.deleted = 0 and bc.`checkout_time` between #{query.beginOutboundTime} and #{query.endOutboundTime})",
            "</when>",
            "<when test = 'query.beginLoadTime != null and query.endLoadTime != null '>",
            "AND o.`load_time` between #{query.beginLoadTime} and #{query.endLoadTime}",
            "</when>",
            "<when test = 'query.beginUnloadTime != null and query.endUnloadTime != null '>",
            "AND o.`unload_time` between #{query.beginUnloadTime} and #{query.endUnloadTime}",
            "</when>",
            "<when test = 'query.beginTakeTime != null and query.endTakeTime != null '>",
            "AND o.`status` > 19 AND o.`take_time` between #{query.beginTakeTime} and #{query.endTakeTime}",
            "</when>",
            "<when test = 'query.beginSplitTime != null and query.endSplitTime != null '>",
            "AND o.`split_time` between #{query.beginSplitTime} and #{query.endSplitTime}",
            "</when>",
            "<when test = 'query.beginCreateTime != null and query.endCreateTime != null '>",
            "AND o.`create_time` between #{query.beginCreateTime} and #{query.endCreateTime}",
            "</when>",
            "<when test = 'query.beginPickTime != null and query.endPickTime != null '>",
            "AND o.order_id in(select distinct op.order_id from ecw_order_cargo_control_pick op where op.deleted = 0 and op.status in(1,3) and op.`create_time` between #{query.beginPickTime} and #{query.endPickTime})",
            "</when>",
            "<when test = 'query.beginPickUpTime != null and query.endPickUpTime != null '>",
            "AND o.order_no in(select distinct op.order_id from ecw_order_pickup op where op.deleted = 0 and op.`create_time` between #{query.beginPickUpTime} and #{query.endPickUpTime})",
            "</when>",
            "<when test = 'query.beginWarehouseInTime != null and query.endWarehouseInTime != null '>",
            "AND o.order_id in(select distinct wi.order_id from ecw_order_warehouse_in wi where wi.deleted = 0 and wi.`update_time` between #{query.beginWarehouseInTime} and #{query.endWarehouseInTime})",
            "</when>",
            "<when test = 'query.creator != null and query.creator != \"\" '>",
            "AND o.`creator` = #{query.creator} ",
            "</when>",
            "<when test = 'query.searchKey != null and query.searchKey != \"\" '>",
            "AND concat(IFNULL(o.`order_no`,''), IFNULL(o.`old_numbers`,'') ,IFNULL(o.`marks`,''),IFNULL(o.`tidan_no`,''),IFNULL(o.`container_number`,''),IFNULL(nee.`name`,''),IFNULL(nee.`phone`,'')) like concat('%',concat(#{query.searchKey},'%'))",
            "</when>",
            "<when test = '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},'%'))))",
            "</when>",
            "<when test = 'query.notConsignorKey != null and query.notConsignorKey != \"\" '>",
            "AND (concat(IFNULL(nor.`name`,''),IFNULL(nor.`name_en`,''),IFNULL(nor.`phone`,'')) not like concat('%',concat(#{query.notConsignorKey},'%'))",
            "AND nor.customer_id not in (select c.id from ecw_customer c where c.number like concat('%',concat(#{query.notConsignorKey},'%'))))",
            "</when>",
            "<when test = '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},'%'))))",
            "</when>",
            "<when test = 'query.notConsigneeKey != null and query.notConsigneeKey != \"\" '>",
            "AND (concat(IFNULL(nee.`name`,''),IFNULL(nee.`name_en`,''),IFNULL(nee.`phone`,'')) not like concat('%',concat(#{query.notConsigneeKey},'%'))",
            "AND nee.customer_id not in (select c.id from ecw_customer c where c.number like concat('%',concat(#{query.notConsigneeKey},'%'))))",
            "</when>",
            "<when test = 'query.numberKey != null and query.numberKey != \"\" '>",
            "AND concat(IFNULL(o.`order_no`,''), IFNULL(o.`old_numbers`,''), IFNULL(o.`parent_number`,'') ,IFNULL(o.`initial_parent_order_no`,'') ,IFNULL(o.`marks`,''),IFNULL(o.`tidan_no`,''),IFNULL(o.`container_number`,''),IFNULL(o.`no_charge_record`,'')) like concat('%',concat(#{query.numberKey},'%'))",
            "</when>",
            "<when test = 'query.notNumberKey != null and query.notNumberKey != \"\" '>",
            "AND concat(IFNULL(o.`order_no`,''), IFNULL(o.`old_numbers`,''), IFNULL(o.`parent_number`,'') ,IFNULL(o.`initial_parent_order_no`,'') ,IFNULL(o.`marks`,''),IFNULL(o.`tidan_no`,''),IFNULL(o.`container_number`,''),IFNULL(o.`no_charge_record`,'')) not like concat('%',concat(#{query.notNumberKey},'%'))",
            "</when>",
            "<when test = 'query.eqNumberKey != null and query.eqNumberKey != \"\" '>",
            "AND (o.`order_no` = #{query.eqNumberKey}",
            "or (o.`old_numbers` is not null and o.`old_numbers` != '' and o.`old_numbers` = #{query.eqNumberKey}) ",
            "or (o.`parent_number` is not null and o.`parent_number` != '' and o.`parent_number` = #{query.eqNumberKey}) ",
            "or (o.`marks` is not null and o.`marks` != '' and o.`marks` = #{query.eqNumberKey}) ",
            "or (o.`tidan_no` is not null and o.`tidan_no` != '' and o.`tidan_no` = #{query.eqNumberKey}) ",
            "or (o.`container_number` is not null and o.`container_number` != '' and o.`container_number` = #{query.eqNumberKey}) ",
            "or (o.`no_charge_record` is not null and o.`no_charge_record` != '' and o.`no_charge_record` = #{query.eqNumberKey})",
            "or (o.`initial_parent_order_no` is not null and o.`initial_parent_order_no` != '' and o.`initial_parent_order_no` = #{query.eqNumberKey}))",
            "</when>",
            "<when test = 'query.notEqNumberKey != null and query.notEqNumberKey != \"\" '>",
            "AND o.`order_no` != #{query.notEqNumberKey}",
            "AND (o.`old_numbers` is null or o.`old_numbers` = '' or o.`old_numbers` != #{query.notEqNumberKey})",
            "AND (o.`marks` is null or o.`marks` = '' or o.`marks` != #{query.notEqNumberKey})",
            "AND (o.`tidan_no` is null or o.`tidan_no` = '' or o.`tidan_no` != #{query.notEqNumberKey})",
            "AND (o.`container_number` is null or o.`container_number` = '' or o.`container_number` != #{query.notEqNumberKey})",
            "AND (o.`no_charge_record` is null or o.`no_charge_record` = '' or o.`no_charge_record` != #{query.notEqNumberKey})",
            "AND (o.`initial_parent_order_no` is null or o.`initial_parent_order_no` = '' or o.`initial_parent_order_no` != #{query.notEqNumberKey})",
            "</when>",
            "<when test = 'query.prodKey != null and query.prodKey != \"\" '>",
            "and (o.order_id in(",
            "select oi.order_id ",
            "from ecw_order_item oi ",
            "left join ecw_product p ",
            "on oi.prod_id = p.id ",
            "left join ecw_product_type pt ",
            "on pt.id = oi.prod_type ",
            "left join ecw_product_brank pb",
            "on pb.id = oi.brand",
            "where oi.deleted = 0 ",
            "and concat(IFNULL(oi.`prod_title_zh`,''),IFNULL(oi.`prod_title_en`,''),IFNULL(pt.`title_zh`,''),IFNULL(pt.`title_en`,''),IFNULL(pb.`title_zh`,''),IFNULL(pb.`title_en`,''))",
            "like concat('%',concat(#{query.prodKey},'%'))",
            "))",
            "</when>",
            "<when test = 'query.notProdKey != null and query.notProdKey != \"\" '>",
            "and (o.order_id not in(",
            "select oi.order_id ",
            "from ecw_order_item oi ",
            "left join ecw_product p ",
            "on oi.prod_id = p.id ",
            "left join ecw_product_type pt ",
            "on pt.id = oi.prod_type ",
            "left join ecw_product_brank pb",
            "on pb.id = oi.brand",
            "where oi.deleted = 0 and concat(IFNULL(oi.`prod_title_zh`,''),IFNULL(oi.`prod_title_en`,''),IFNULL(pt.`title_zh`,''),IFNULL(pt.`title_en`,''),IFNULL(pb.`title_zh`,''),IFNULL(pb.`title_en`,'')) " ,
            "like concat('%',concat(#{query.notProdKey},'%'))",
            "))",
            "</when>",
            "<when test = 'query.eqProdKey != null and query.eqProdKey != \"\" '>",
            "and (o.order_id in(",
            "select oi.order_id ",
            "from ecw_order_item oi ",
            "left join ecw_product p ",
            "on oi.prod_id = p.id ",
            "left join ecw_product_type pt ",
            "on pt.id = oi.prod_type ",
            "left join ecw_product_brank pb",
            "on pb.id = oi.brand",
            "where oi.deleted = 0 " ,
            "and (oi.`prod_title_zh` = #{query.eqProdKey} or oi.`prod_title_en` = #{query.eqProdKey} " ,
            "or pt.`title_zh` = #{query.eqProdKey} or pt.`title_en` = #{query.eqProdKey}",
            "or pb.`title_zh` = #{query.eqProdKey} or pb.`title_en` = #{query.eqProdKey})",
            "))",
            "</when>",
            "<when test = 'query.notEqProdKey != null and query.notEqProdKey != \"\" '>",
            "and (o.order_id not in(",
            "select oi.order_id ",
            "from ecw_order_item oi ",
            "left join ecw_product p ",
            "on oi.prod_id = p.id ",
            "left join ecw_product_type pt ",
            "on pt.id = oi.prod_type ",
            "left join ecw_product_brank pb",
            "on pb.id = oi.brand",
            "where oi.deleted = 0" ,
            "and (oi.`prod_title_zh` = #{query.notEqProdKey} or oi.`prod_title_en` = #{query.notEqProdKey} " ,
            "or pt.`title_zh` = #{query.notEqProdKey} or pt.`title_en` = #{query.notEqProdKey}",
            "or pb.`title_zh` = #{query.notEqProdKey} or pb.`title_en` = #{query.notEqProdKey})",
            "))",
            "</when>",
            "<when test = 'query.startWarehouseId != null and query.destWarehouseId != null '>",
            "and (o.line_id in(",
            "select whl.id ",
            "from ecw_warehouse_line whl ",
            "where whl.start_warehouse_id = #{query.startWarehouseId} and whl.dest_warehouse_id = #{query.destWarehouseId} ",
            "))",
            "</when>",
            "<when test = 'query.startWarehouseId != null and query.destWarehouseId == null '>",
            "and (o.line_id in(",
            "select whl.id ",
            "from ecw_warehouse_line whl ",
            "where whl.start_warehouse_id = #{query.startWarehouseId}  ",
            "))",
            "</when>",
            "<when test = 'query.startWarehouseId == null and query.destWarehouseId != null '>",
            "and (o.line_id in(",
            "select whl.id ",
            "from ecw_warehouse_line whl ",
            "where whl.dest_warehouse_id = #{query.destWarehouseId} ",
            "))",
            "</when>",
            "<when test = 'query.isNeat == false  '>",
            " AND o.sum_num  <![CDATA[ < ]]> o.cost->>'$.totalNum' ",
            "</when>",
            "<when test = 'query.isNeat == true  '>",
            " AND o.sum_num  = o.cost->>'$.totalNum' ",
            "</when>",
            "<when test = 'query.customerDetailId != null'>",
            "AND (o.`customer_id` = #{query.customerDetailId} or nor.`customer_id` = #{query.customerDetailId}  or nee.`customer_id` = #{query.customerDetailId})",
            "</when>",
            "<when test = 'query.type != null and query.type != \"\" and query.type == 0 '>",
            "AND (o.type is null or o.type = '' or o.type = '0')",
            "</when>",
            "<when test = 'query.type == 1 '>",
            "AND FIND_IN_SET(1, o.type)",
            "</when>",
            "<when test = 'query.type == 2 '>",
            "AND FIND_IN_SET(2, o.type)",
            "</when>",
            "<when test = 'query.userType == 2 '>",
            "HAVING st = 0 ",
            "</when>",
            "</script>"
    })
    IPage<OrderBackPageVO> appMyIssuedOrderPage(IPage<OrderBackPageVO> mpPage, @Param("query") OrderQueryVO query);

    List<OrderBackPageVO> appMyIssuedOrderList(@Param("start") int start, @Param("size") int size, @Param("query") OrderQueryVO query);

    long appMyIssuedOrderCount(@Param("query") OrderQueryVO query);

    @ResultType(OrderBackPageVO.class)
    @Select({
            "<script>",
            "select o.order_id, ",
            "o.package_type as advance_type, ",
            "o.package_remarks, ",
            "o.number, ",
            "o.order_no, ",
            "o.tidan_no, ",
            "o.type, ",
            "o.order_type, ",
            "o.air_shipment, ",
//            "IF(o.order_type != 2 and (SELECT COUNT(1) FROM ecw_order_exception hoe WHERE hoe.order_id = o.order_id AND hoe.deleted = 0 AND hoe.order_exception_status = 0 AND hoe.order_exception_type ='order_heavy_cargo_exception') = 0, o.sum_volume, o.w_volume ) as w_volume, ",
            "IFNULL((select SUM(IF(it.charge_volume > it.min_metering_volume, it.charge_volume, it.min_metering_volume)) FROM ecw_order_item it WHERE it.order_id = o.order_id and it.deleted = 0 and it.warehouse_in_info IS NOT NULL), 0) as w_volume, ",
//            "IF(o.order_type != 3 and (SELECT COUNT(1) FROM ecw_order_exception boe WHERE boe.order_id = o.order_id AND boe.deleted = 0 AND boe.order_exception_status = 0 AND boe.order_exception_type ='order_bulky_cargo_exception') = 0, o.sum_weight, o.v_weight ) as v_weight, ",
            "IFNULL((select SUM(IF( it.charge_weight > it.min_metering_weight, it.charge_weight, it.min_metering_weight)) FROM ecw_order_item it WHERE it.order_id = o.order_id and it.deleted = 0 and it.warehouse_in_info IS NOT NULL), 0) as v_weight, ",
            "o.customs_type, ",
            "o.parent_number, ",
            "o.parent_order_id, ",
            "o.initial_parent_order_id, ",
            "if(#{query.lang} = 0, de.departure ->> '$.titleZh', de.departure ->> '$.titleEn') as departure_name, ",
            "if(#{query.lang} = 0, ob.objective ->> '$.titleZh', ob.objective ->> '$.titleEn') as objective_name, ",
            "o.marks, ",
            "o.`status`, ",
            "o.abnormal_state, ",
            "o.in_warehouse_state, ",
            "o.shipment_state, ",
            "o.pick_state, ",
            "o.audit_type, ",
            "o.audit_result, ",
            "o.transport_id, ",
            "(select ifnull(sum(ccp.pick_num),0) from ecw_order_cargo_control_pick ccp where ccp.order_id = o.order_id and ccp.status in(1,2,3,4) ) as release_num, ",
            "o.is_cargo_control, ",
            "o.cargo_control_status, ",
            "o.cost ->> '$.totalNum' as total_num, ",
            "if(#{query.userType} = 1, 1, 2) as user_type, ",
            "o.sum_num, ",
            "o.sum_volume, ",
            "o.sum_weight, ",
            "o.sum_volume_finished_warehouse_in, ",
            "o.sum_weight_finished_warehouse_in, ",
            "o.packing_list_url, ",
            "o.is_external_warehouse, ",
            "o.exception_reason, ",
            "o.is_exception, ",
            "o.create_time, ",
            "nor.name as consignor_name, ",
            "nor.name_en as consignor_name_en, ",
            "nor.phone as consignor_phone, ",
            "nor.country_code as consignor_country_code, ",
            "nee.name as consignee_name, ",
            "nee.name_en as consignee_name_en, ",
            "nee.phone as consignee_phone, ",
            "nee.country_code as consignee_country_code, ",
            "o.update_time, ",
            "#{query.lang} as lang ",
            "from ecw_order o ",
            "left join ecw_order_departure de on de.order_id = o.order_id ",
            "left join ecw_order_objective ob on ob.order_id = o.order_id ",
            "left join ecw_order_consignor nor on nor.order_id = o.order_id ",
            "left join ecw_order_consignee nee on nee.order_id = o.order_id ",
            "where o.deleted = 0 and o.in_warehouse_state != 211 and o.in_warehouse_state != 208 and o.status != 10 ",
            "AND o.`status` not in(13,88) ",
            "AND (o.user_id = #{query.userId} or nor.`phone` = #{query.consignorPhone} or nor.customer_contacts_id = #{query.consignorContactsId})",
            "<when test = 'query.status != null'>",
            "AND o.`status` = #{query.status}",
            "</when>",
            "<when test = 'query.packageType != null and query.packageType != \"\" '>",
            "AND CONCAT(',',o.package_type,',') REGEXP CONCAT(',',REPLACE(#{query.packageType},',',',|,'), ',')",
            "</when>",
            "<when test = 'query.beginRucangTime != null and query.endRucangTime != null '>",
//            "AND o.`rucang_time` between #{query.beginRucangTime} and #{query.endRucangTime}",
            "AND o.order_id in(select distinct wi.order_id from ecw_order_warehouse_in wi where wi.deleted = 0 and wi.`in_time` between #{query.beginRucangTime} and #{query.endRucangTime})",
            "</when>",
            "<when test = 'query.beginQingguanTime != null and query.endQingguanTime != null '>",
            "AND o.`qingguan_time` between #{query.beginQingguanTime} and #{query.endQingguanTime}",
            "</when>",
            "<when test = 'query.beginDaogangTime != null and query.endDaogangTime != null '>",
            "AND o.`daogang_time` between #{query.beginDaogangTime} and #{query.endDaogangTime}",
            "</when>",
            "<when test = 'query.beginPreLoadTime != null and query.endPreLoadTime != null '>",
            "AND o.`status` > 5 AND o.`pre_load_time` between #{query.beginPreLoadTime} and #{query.endPreLoadTime}",
            "</when>",
            "<when test = 'query.beginOutboundTime != null and query.endOutboundTime != null '>",
            "AND o.`status` > 5 AND o.container_number in(select distinct b.self_no from ecw_box_air_checkout bc join ecw_box b ON bc.shipment_id = b.id",
            "where b.deleted = 0 and bc.deleted = 0 and bc.`checkout_time` between #{query.beginOutboundTime} and #{query.endOutboundTime})",
            "</when>",
            "<when test = 'query.beginLoadTime != null and query.endLoadTime != null '>",
            "AND o.`load_time` between #{query.beginLoadTime} and #{query.endLoadTime}",
            "</when>",
            "<when test = 'query.beginUnloadTime != null and query.endUnloadTime != null '>",
            "AND o.`unload_time` between #{query.beginUnloadTime} and #{query.endUnloadTime}",
            "</when>",
            "<when test = 'query.beginTakeTime != null and query.endTakeTime != null '>",
            "AND o.`status` > 19 AND o.`take_time` between #{query.beginTakeTime} and #{query.endTakeTime}",
            "</when>",
            "<when test = 'query.beginSplitTime != null and query.endSplitTime != null '>",
            "AND o.`split_time` between #{query.beginSplitTime} and #{query.endSplitTime}",
            "</when>",
            "<when test = 'query.beginCreateTime != null and query.endCreateTime != null '>",
            "AND o.`create_time` between #{query.beginCreateTime} and #{query.endCreateTime}",
            "</when>",
            "<when test = 'query.beginPickTime != null and query.endPickTime != null '>",
            "AND o.order_id in(select distinct op.order_id from ecw_order_cargo_control_pick op where op.deleted = 0 and op.status in(1,3) and op.`create_time` between #{query.beginPickTime} and #{query.endPickTime})",
            "</when>",
            "<when test = 'query.beginPickUpTime != null and query.endPickUpTime != null '>",
            "AND o.order_no in(select distinct op.order_id from ecw_order_pickup op where op.deleted = 0 and op.`create_time` between #{query.beginPickUpTime} and #{query.endPickUpTime})",
            "</when>",
            "<when test = 'query.beginWarehouseInTime != null and query.endWarehouseInTime != null '>",
            "AND o.order_id in(select distinct wi.order_id from ecw_order_warehouse_in wi where wi.deleted = 0 and wi.`update_time` between #{query.beginWarehouseInTime} and #{query.endWarehouseInTime})",
            "</when>",
            "<when test = 'query.isExternalWarehouse != null'>",
            "AND o.`is_external_warehouse` = #{query.isExternalWarehouse}",
            "</when>",
            "<when test = '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} )) ",
            "</when>",
            "<when test = 'query.customsType != null'>",
            "AND o.`customs_type` = #{query.customsType}",
            "</when>",
            "<when test = 'query.productRecord != null'>",
            "AND o.`product_record` = #{query.productRecord}",
            "</when>",
            "<when test = 'query.transportId != null'>",
            "AND o.`transport_id` = #{query.transportId}",
            "</when>",
            "<when test = 'query.channelId != null'>",
            "AND o.`channel_id` = #{query.channelId}",
            "</when>",
            "<when test = 'query.warehouseType != null'>",
            "AND o.`warehouse_type` = #{query.warehouseType}",
            "</when>",
            "<when test = '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},'%'))))))",
            "</when>",
            "<when test = '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},'%')))))",
            "</when>",
            "<when test = 'query.startWarehouseId != null and query.destWarehouseId != null '>",
            "and (o.line_id in(",
            "select whl.id ",
            "from ecw_warehouse_line whl ",
            "where whl.start_warehouse_id = #{query.startWarehouseId} and whl.dest_warehouse_id = #{query.destWarehouseId} ",
            "))",
            "</when>",
            "<when test = 'query.startWarehouseId != null and query.destWarehouseId == null '>",
            "and (o.line_id in(",
            "select whl.id ",
            "from ecw_warehouse_line whl ",
            "where whl.start_warehouse_id = #{query.startWarehouseId}  ",
            "))",
            "</when>",
            "<when test = 'query.startWarehouseId == null and query.destWarehouseId != null '>",
            "and (o.line_id in(",
            "select whl.id ",
            "from ecw_warehouse_line whl ",
            "where whl.dest_warehouse_id = #{query.destWarehouseId} ",
            "))",
            "</when>",
            "<when test = 'query.searchKey != null and query.searchKey != \"\" '>",
            "AND concat(IFNULL(o.`order_no`,''), IFNULL(o.`old_numbers`,'') ,IFNULL(o.`marks`,''),IFNULL(o.`tidan_no`,''),IFNULL(o.`container_number`,''),IFNULL(nee.`name`,''),IFNULL(nee.`phone`,'')) like concat('%',concat(#{query.searchKey},'%'))",
            "</when>",
            "<when test = 'query.marks != null and query.marks != \"\" '>",
            "AND o.`marks` like concat('%',concat(#{query.marks},'%'))",
            "</when>",
            "<when test = 'query.departureId != null '>",
            "AND de.`departure_id` = #{query.departureId}",
            "</when>",
            "<when test = 'query.objectiveId != null '>",
            "AND ob.`objective_id` = #{query.objectiveId}",
            "</when>",
            "<when test = 'query.consigneeId != null '>",
            "AND nee.`customer_id` = #{query.consigneeId}",
            "</when>",
            "<when test = '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},'%'))))",
            "</when>",
            "<when test = 'query.notConsignorKey != null and query.notConsignorKey != \"\" '>",
            "AND (concat(IFNULL(nor.`name`,''),IFNULL(nor.`name_en`,''),IFNULL(nor.`phone`,'')) not like concat('%',concat(#{query.notConsignorKey},'%'))",
            "AND nor.customer_id not in (select c.id from ecw_customer c where c.number like concat('%',concat(#{query.notConsignorKey},'%'))))",
            "</when>",
            "<when test = '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},'%'))))",
            "</when>",
            "<when test = 'query.notConsigneeKey != null and query.notConsigneeKey != \"\" '>",
            "AND (concat(IFNULL(nee.`name`,''),IFNULL(nee.`name_en`,''),IFNULL(nee.`phone`,'')) not like concat('%',concat(#{query.notConsigneeKey},'%'))",
            "AND nee.customer_id not in (select c.id from ecw_customer c where c.number like concat('%',concat(#{query.notConsigneeKey},'%'))))",
            "</when>",
            "<when test = 'query.orderNo != null and query.orderNo != \"\" '>",
            "AND o.`order_no` like concat('%',concat(#{query.orderNo},'%'))",
            "</when>",
            "<when test = 'query.tidanNo != null and query.tidanNo != \"\" '>",
            "AND o.`tidan_no` like concat('%',concat(#{query.tidanNo},'%'))",
            "</when>",
            "<when test = 'query.containerNumber != null and query.containerNumber != \"\" '>",
            "AND o.`container_number` = #{query.containerNumber}",
            "</when>",
            "<when test = 'query.type != null and query.type != \"\" and query.type == 0 '>",
            "AND (o.type is null or o.type = '' or o.type = '0')",
            "</when>",
            "<when test = 'query.type == 1 '>",
            "AND FIND_IN_SET(1, o.type)",
            "</when>",
            "<when test = 'query.type == 2 '>",
            "AND FIND_IN_SET(2, o.type)",
            "</when>",
            "<when test = 'query.customerId != null'>",
            "AND o.`customer_id` = #{query.customerId}",
            "</when>",
            "</script>"
    })
    IPage<OrderBackPageVO> dynamicOrderPage(@Param("mpPage") IPage<OrderBackPageVO> mpPage, @Param("query") OrderQueryVO query);


    @ResultType(OrderBackPageVO.class)
    @Select({
            "<script>",
            "select o.order_id, ",
            "(select ifnull(sum(ccp.pick_num),0) from ecw_order_cargo_control_pick ccp where ccp.order_id = o.order_id and ccp.status in(1,2,3,4,5,6) ) as release_num, ",
            "if((select count(1) from ecw_order_cargo_control_pick ccp2 where ccp2.order_id = o.order_id and ccp2.status = 1) > 0, true, false ) as is_to_review, ",
            "if((select count(1) from ecw_order_cargo_control_pick ccp3 where ccp3.order_id = o.order_id and ccp3.status = 3) > 0, true, false ) as is_release_after_goods, ",
            "o.number, ",
            "o.order_no, ",
            "o.tidan_no, ",
            "o.type, ",
            "o.order_type, ",
            "o.air_shipment, ",
//            "IF(o.order_type != 2 and (SELECT COUNT(1) FROM ecw_order_exception hoe WHERE hoe.order_id = o.order_id AND hoe.deleted = 0 AND hoe.order_exception_status = 0 AND hoe.order_exception_type ='order_heavy_cargo_exception') = 0, o.sum_volume, o.w_volume ) as w_volume, ",
            "IFNULL((select SUM(IF(it.charge_volume > it.min_metering_volume, it.charge_volume, it.min_metering_volume)) FROM ecw_order_item it WHERE it.order_id = o.order_id and it.deleted = 0 and it.warehouse_in_info IS NOT NULL), 0) as w_volume, ",
//            "IF(o.order_type != 3 and (SELECT COUNT(1) FROM ecw_order_exception boe WHERE boe.order_id = o.order_id AND boe.deleted = 0 AND boe.order_exception_status = 0 AND boe.order_exception_type ='order_bulky_cargo_exception') = 0, o.sum_weight, o.v_weight ) as v_weight, ",
            "IFNULL((select SUM(IF( it.charge_weight > it.min_metering_weight, it.charge_weight, it.min_metering_weight)) FROM ecw_order_item it WHERE it.order_id = o.order_id and it.deleted = 0 and it.warehouse_in_info IS NOT NULL), 0) as v_weight, ",
            "o.customs_type, ",
            "o.parent_number, ",
            "o.parent_order_id, ",
            "o.initial_parent_order_id, ",
            "if(#{query.lang} = 0, de.departure ->> '$.titleZh', de.departure ->> '$.titleEn') as departure_name, ",
            "if(#{query.lang} = 0, ob.objective ->> '$.titleZh', ob.objective ->> '$.titleEn') as objective_name, ",
            "if(#{query.userType} = 1, 1, 2) as user_type, ",
            "o.marks, ",
            "o.status, ",
            "o.abnormal_state, ",
            "o.in_warehouse_state, ",
            "o.shipment_state, ",
            "o.pick_state, ",
            "o.audit_type, ",
            "o.audit_result, ",
            "o.transport_id, ",
            "o.is_cargo_control, ",
            "o.cargo_control_status, ",
            "o.cost ->> '$.totalNum' as total_num, ",
            "o.sum_num, ",
            "o.sum_volume, ",
            "o.sum_weight, ",
            "o.sum_volume_finished_warehouse_in, ",
            "o.sum_weight_finished_warehouse_in, ",
            "o.packing_list_url, ",
            "o.is_external_warehouse, ",
            "o.exception_reason, ",
            "o.is_exception, ",
            "o.create_time, ",
//            "IF(o.user_id is not null AND o.user_id > 0 AND o.`status` = 0, 1 , 0)  as st, ",
            "nor.name as consignor_name, ",
            "nor.name_en as consignor_name_en, ",
            "nor.phone as consignor_phone, ",
            "nor.country_code as consignor_country_code, ",
            "nee.name as consignee_name, ",
            "nee.name_en as consignee_name_en, ",
            "nee.phone as consignee_phone, ",
            "nee.country_code as consignee_country_code, ",
            "occ.name as cargo_control_name, ",
            "occ.name_en as cargo_control_name_en, ",
            "occ.phone as cargo_control_phone, ",
            "occ.dial_code as cargo_control_country_code, ",
            "o.update_time, ",
            "#{query.lang} as lang ",
            "from ecw_order o ",
            "left join ecw_order_departure de on de.order_id = o.order_id ",
            "left join ecw_order_objective ob on ob.order_id = o.order_id ",
            "left join ecw_order_consignor nor on nor.order_id = o.order_id ",
            "left join ecw_order_consignee nee on nee.order_id = o.order_id ",
            "left join ecw_order_cargo_control occ ",
            "on occ.order_id = o.order_id and occ.is_actual = 1 and occ.deleted = 0",
            "where o.deleted = 0 and o.in_warehouse_state != 211 and o.in_warehouse_state != 208 and o.status != 10 ",
            "and o.is_cargo_control = 1 ",
            "<when test = 'query.status != null'>",
            " AND o.`status` = #{query.status}",
            "</when>",
            "<when test = 'query.transportId != null'>",
            "AND o.`transport_id` = #{query.transportId}",
            "</when>",
            "<when test = 'query.channelId != null'>",
            "AND o.`channel_id` = #{query.channelId}",
            "</when>",
            "<when test = 'query.packageType != null and query.packageType != \"\" '>",
            "AND CONCAT(',',o.package_type,',') REGEXP CONCAT(',',REPLACE(#{query.packageType},',',',|,'), ',')",
            "</when>",
            "<when test = 'query.isExternalWarehouse != null'>",
            "AND o.`is_external_warehouse` = #{query.isExternalWarehouse}",
            "</when>",
            "<when test = 'query.orderNo != null'>",
            " AND o.`order_no` like CONCAT('%',#{query.orderNo},'%')",
            "</when>",
            "<when test = 'query.tidanNo != null'>",
            " AND o.`tidan_no` like CONCAT('%',#{query.tidanNo},'%')",
            "</when>",
            "<when test = 'query.containerNumber != null and query.containerNumber != \"\" '>",
            "AND o.`container_number` = #{query.containerNumber}",
            "</when>",
            "<when test = 'query.marks != null'>",
            " AND o.`marks` like CONCAT('%',#{query.marks},'%')",
            "</when>",
            "<when test = 'query.cargoControlStatus != null and query.cargoControlStatus != 3'>",
            " AND o.`cargo_control_status` = #{query.cargoControlStatus}",
            "</when>",
            "<when test = 'query.cargoControlStatus != null and query.cargoControlStatus == 3'>",
            " AND o.`cargo_control_status` = 1 AND (select count(1) from ecw_order_cargo_control_pick ccp2 where ccp2.order_id = o.order_id and ccp2.status = 1) > 0",
            "</when>",
            "<when test = 'query.beginRucangTime != null and query.endRucangTime != null '>",
//            "AND o.`rucang_time` between #{query.beginRucangTime} and #{query.endRucangTime}",
            "AND o.order_id in(select distinct wi.order_id from ecw_order_warehouse_in wi where wi.deleted = 0 and wi.`in_time` between #{query.beginRucangTime} and #{query.endRucangTime})",
            "</when>",
            "<when test = 'query.beginQingguanTime != null and query.endQingguanTime != null '>",
            "AND o.`qingguan_time` between #{query.beginQingguanTime} and #{query.endQingguanTime}",
            "</when>",
            "<when test = 'query.beginDaogangTime != null and query.endDaogangTime != null '>",
            "AND o.`daogang_time` between #{query.beginDaogangTime} and #{query.endDaogangTime}",
            "</when>",
            "<when test = 'query.beginPreLoadTime != null and query.endPreLoadTime != null '>",
            "AND o.`status` > 5 AND o.`pre_load_time` between #{query.beginPreLoadTime} and #{query.endPreLoadTime}",
            "</when>",
            "<when test = 'query.beginOutboundTime != null and query.endOutboundTime != null '>",
            "AND o.`status` > 5 AND o.container_number in(select distinct b.self_no from ecw_box_air_checkout bc join ecw_box b ON bc.shipment_id = b.id",
            "where b.deleted = 0 and bc.deleted = 0 and bc.`checkout_time` between #{query.beginOutboundTime} and #{query.endOutboundTime})",
            "</when>",
            "<when test = 'query.beginLoadTime != null and query.endLoadTime != null '>",
            "AND o.`load_time` between #{query.beginLoadTime} and #{query.endLoadTime}",
            "</when>",
            "<when test = 'query.beginUnloadTime != null and query.endUnloadTime != null '>",
            "AND o.`unload_time` between #{query.beginUnloadTime} and #{query.endUnloadTime}",
            "</when>",
            "<when test = 'query.beginTakeTime != null and query.endTakeTime != null '>",
            "AND o.`status` > 19 AND o.`take_time` between #{query.beginTakeTime} and #{query.endTakeTime}",
            "</when>",
            "<when test = 'query.beginSplitTime != null and query.endSplitTime != null '>",
            "AND o.`split_time` between #{query.beginSplitTime} and #{query.endSplitTime}",
            "</when>",
            "<when test = 'query.beginCreateTime != null and query.endCreateTime != null '>",
            "AND o.`create_time` between #{query.beginCreateTime} and #{query.endCreateTime}",
            "</when>",
            "<when test = 'query.beginPickTime != null and query.endPickTime != null '>",
            "AND o.order_id in(select distinct op.order_id from ecw_order_cargo_control_pick op where op.deleted = 0 and op.status in(1,3) and op.`create_time` between #{query.beginPickTime} and #{query.endPickTime})",
            "</when>",
            "<when test = 'query.beginPickUpTime != null and query.endPickUpTime != null '>",
            "AND o.order_no in(select distinct op.order_id from ecw_order_pickup op where op.deleted = 0 and op.`create_time` between #{query.beginPickUpTime} and #{query.endPickUpTime})",
            "</when>",
            "<when test = 'query.beginWarehouseInTime != null and query.endWarehouseInTime != null '>",
            "AND o.order_id in(select distinct wi.order_id from ecw_order_warehouse_in wi where wi.deleted = 0 and wi.`update_time` between #{query.beginWarehouseInTime} and #{query.endWarehouseInTime})",
            "</when>",
            "AND (1= 1 ",
            "<when test = 'query.consignorId != null '>",
            " or nor.`customer_id` = #{query.consignorId} ",
            "</when>",
            "<when test = 'query.consignorPhone != null and query.consignorPhone != \"\" '>",
            " or nor.`phone` = #{query.consignorPhone} ",
            "</when>",
            " ) ",
            "<when test = '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},'%'))))",
            "</when>",
            "<when test = 'query.notConsignorKey != null and query.notConsignorKey != \"\" '>",
            "AND (concat(IFNULL(nor.`name`,''),IFNULL(nor.`name_en`,''),IFNULL(nor.`phone`,'')) not like concat('%',concat(#{query.notConsignorKey},'%'))",
            "AND nor.customer_id not in (select c.id from ecw_customer c where c.number like concat('%',concat(#{query.notConsignorKey},'%'))))",
            "</when>",
            "<when test = '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},'%'))))",
            "</when>",
            "<when test = 'query.notConsigneeKey != null and query.notConsigneeKey != \"\" '>",
            "AND (concat(IFNULL(nee.`name`,''),IFNULL(nee.`name_en`,''),IFNULL(nee.`phone`,'')) not like concat('%',concat(#{query.notConsigneeKey},'%'))",
            "AND nee.customer_id not in (select c.id from ecw_customer c where c.number like concat('%',concat(#{query.notConsigneeKey},'%'))))",
            "</when>",
            "<when test = 'query.startWarehouseId != null and query.destWarehouseId != null '>",
            "and (o.line_id in(",
            "select whl.id ",
            "from ecw_warehouse_line whl ",
            "where whl.start_warehouse_id = #{query.startWarehouseId} and whl.dest_warehouse_id = #{query.destWarehouseId} ",
            "))",
            "</when>",
            "<when test = 'query.startWarehouseId != null and query.destWarehouseId == null '>",
            "and (o.line_id in(",
            "select whl.id ",
            "from ecw_warehouse_line whl ",
            "where whl.start_warehouse_id = #{query.startWarehouseId}  ",
            "))",
            "</when>",
            "<when test = 'query.startWarehouseId == null and query.destWarehouseId != null '>",
            "and (o.line_id in(",
            "select whl.id ",
            "from ecw_warehouse_line whl ",
            "where whl.dest_warehouse_id = #{query.destWarehouseId} ",
            "))",
            "</when>",
            "<when test = 'query.searchKey != null and query.searchKey != \"\" '>",
            "AND concat(IFNULL(o.`order_no`,''), IFNULL(o.`old_numbers`,'') ,IFNULL(o.`marks`,''),IFNULL(o.`tidan_no`,''),IFNULL(o.`container_number`,''),IFNULL(nee.`name`,''),IFNULL(nee.`phone`,'')) like concat('%',concat(#{query.searchKey},'%'))",
            "</when>",
            "<when test = 'query.orderNo != null and query.orderNo != \"\" '>",
            "AND o.`order_no` like concat('%',concat(#{query.orderNo},'%'))",
            "</when>",
            "<when test = 'query.type != null and query.type != \"\" and query.type == 0 '>",
            "AND (o.type is null or o.type = '' or o.type = '0')",
            "</when>",
            "<when test = 'query.type == 1 '>",
            "AND FIND_IN_SET(1, o.type)",
            "</when>",
            "<when test = 'query.type == 2 '>",
            "AND FIND_IN_SET(2, o.type)",
            "</when>",
            "<when test = 'query.marks != null and query.marks != \"\" '>",
            "AND o.`marks` like concat('%',concat(#{query.marks},'%'))",
            "</when>",
//            "HAVING st = 0",
            "</script>"
    })
    IPage<OrderBackPageVO> adminCargoControlOrderPage(@Param("mpPage") IPage<OrderBackPageVO> mpPage, @Param("query") OrderQueryVO query);

    List<OrderBackPageVO> adminCargoControlOrderList(@Param("start") int start, @Param("size") int size, @Param("query") OrderQueryVO query);

    List<OrderBackPageVO> adminCargoControlMyOrderList(@Param("start") int start, @Param("size") int size, @Param("query") OrderQueryVO query);

    long adminCargoControlOrderCount(@Param("query") OrderQueryVO query);

    long adminCargoControlMyOrderCount(@Param("query") OrderQueryVO query);
    @ResultType(OrderBackPageVO.class)
    @Select({
            "<script>",
            "select o.order_id, ",
            "(select ifnull(sum(ccp1.pick_num),0) from ecw_order_cargo_control_pick ccp1 where ccp1.order_id = o.order_id and ccp1.status in(1,2,3,4,5,6) ) as release_num, ",
            "o.number, ",
            "o.order_no, ",
            "o.tidan_no, ",
            "o.parent_number, ",
            "o.parent_order_id, ",
            "o.initial_parent_order_id, ",
            "o.type, ",
            "o.order_type, ",
            "o.air_shipment, ",
//            "IF(o.order_type != 2 and (SELECT COUNT(1) FROM ecw_order_exception hoe WHERE hoe.order_id = o.order_id AND hoe.deleted = 0 AND hoe.order_exception_status = 0 AND hoe.order_exception_type ='order_heavy_cargo_exception') = 0, o.sum_volume, o.w_volume ) as w_volume, ",
            "IFNULL((select SUM(IF(it.charge_volume > it.min_metering_volume, it.charge_volume, it.min_metering_volume)) FROM ecw_order_item it WHERE it.order_id = o.order_id and it.deleted = 0 and it.warehouse_in_info IS NOT NULL), 0) as w_volume, ",
//            "IF(o.order_type != 3 and (SELECT COUNT(1) FROM ecw_order_exception boe WHERE boe.order_id = o.order_id AND boe.deleted = 0 AND boe.order_exception_status = 0 AND boe.order_exception_type ='order_bulky_cargo_exception') = 0, o.sum_weight, o.v_weight ) as v_weight, ",
            "IFNULL((select SUM(IF( it.charge_weight > it.min_metering_weight, it.charge_weight, it.min_metering_weight)) FROM ecw_order_item it WHERE it.order_id = o.order_id and it.deleted = 0 and it.warehouse_in_info IS NOT NULL), 0) as v_weight, ",
            "o.customs_type, ",
            "if(#{query.lang} = 0, de.departure ->> '$.titleZh', de.departure ->> '$.titleEn') as departure_name, ",
            "if(#{query.lang} = 0, ob.objective ->> '$.titleZh', ob.objective ->> '$.titleEn') as objective_name, ",
            "if(#{query.userType} = 1, 1, 2) as user_type, ",
            "o.marks, ",
            "o.status, ",
            "o.abnormal_state, ",
            "o.in_warehouse_state, ",
            "o.shipment_state, ",
            "o.pick_state, ",
            "o.audit_type, ",
            "o.audit_result, ",
            "o.transport_id, ",
            "o.is_cargo_control, ",
            "o.cargo_control_status, ",
            "o.cost ->> '$.totalNum' as total_num, ",
            "o.sum_num, ",
            "o.sum_volume, ",
            "o.sum_weight, ",
            "o.sum_volume_finished_warehouse_in, ",
            "o.sum_weight_finished_warehouse_in, ",
            "o.packing_list_url, ",
            "o.is_external_warehouse, ",
            "o.exception_reason, ",
            "o.is_exception, ",
            "o.create_time, ",
            "nor.name as consignor_name, ",
            "nor.name_en as consignor_name_en, ",
            "nor.phone as consignor_phone, ",
            "nor.country_code as consignor_country_code, ",
            "nee.name as consignee_name, ",
            "nee.name_en as consignee_name_en, ",
            "nee.phone as consignee_phone, ",
            "nee.country_code as consignee_country_code, ",
            "occ.name as cargo_control_name, ",
            "occ.name_en as cargo_control_name_en, ",
            "occ.phone as cargo_control_phone, ",
            "occ.dial_code as cargo_control_country_code, ",
            "o.update_time, ",
            "#{query.lang} as lang ",
            "from ecw_order o ",
            "left join ecw_order_departure de on de.order_id = o.order_id ",
            "left join ecw_order_objective ob on ob.order_id = o.order_id ",
            "left join ecw_order_consignor nor on nor.order_id = o.order_id ",
            "left join ecw_order_consignee nee on nee.order_id = o.order_id ",
            "left join ecw_order_cargo_control occ ",
            "on occ.order_id = o.order_id and occ.is_actual = 1 and occ.deleted = 0",
            "where o.deleted = 0 and o.in_warehouse_state != 211 and o.in_warehouse_state != 208 and o.status != 10 ",
            "and o.is_cargo_control = 1 ",
            "<when test = 'query.status != null'>",
            "AND o.`status` = #{query.status}",
            "</when>",
            "<when test = 'query.packageType != null and query.packageType != \"\" '>",
            "AND CONCAT(',',o.package_type,',') REGEXP CONCAT(',',REPLACE(#{query.packageType},',',',|,'), ',')",
            "</when>",
            "<when test = 'query.isExternalWarehouse != null'>",
            "AND o.`is_external_warehouse` = #{query.isExternalWarehouse}",
            "</when>",
            "<when test = 'query.transportId != null'>",
            "AND o.`transport_id` = #{query.transportId}",
            "</when>",
            "<when test = 'query.channelId != null'>",
            "AND o.`channel_id` = #{query.channelId}",
            "</when>",
            "<when test = 'query.beginRucangTime != null and query.endRucangTime != null '>",
//            "AND o.`rucang_time` between #{query.beginRucangTime} and #{query.endRucangTime}",
            "AND o.order_id in(select distinct wi.order_id from ecw_order_warehouse_in wi where wi.deleted = 0 and wi.`in_time` between #{query.beginRucangTime} and #{query.endRucangTime})",
            "</when>",
            "<when test = 'query.beginQingguanTime != null and query.endQingguanTime != null '>",
            "AND o.`qingguan_time` between #{query.beginQingguanTime} and #{query.endQingguanTime}",
            "</when>",
            "<when test = 'query.beginDaogangTime != null and query.endDaogangTime != null '>",
            "AND o.`daogang_time` between #{query.beginDaogangTime} and #{query.endDaogangTime}",
            "</when>",
            "<when test = 'query.beginPreLoadTime != null and query.endPreLoadTime != null '>",
            "AND o.`status` > 5 AND o.`pre_load_time` between #{query.beginPreLoadTime} and #{query.endPreLoadTime}",
            "</when>",
            "<when test = 'query.beginOutboundTime != null and query.endOutboundTime != null '>",
            "AND o.`status` > 5 AND o.container_number in(select distinct b.self_no from ecw_box_air_checkout bc join ecw_box b ON bc.shipment_id = b.id",
            "where b.deleted = 0 and bc.deleted = 0 and bc.`checkout_time` between #{query.beginOutboundTime} and #{query.endOutboundTime})",
            "</when>",
            "<when test = 'query.beginLoadTime != null and query.endLoadTime != null '>",
            "AND o.`load_time` between #{query.beginLoadTime} and #{query.endLoadTime}",
            "</when>",
            "<when test = 'query.beginUnloadTime != null and query.endUnloadTime != null '>",
            "AND o.`unload_time` between #{query.beginUnloadTime} and #{query.endUnloadTime}",
            "</when>",
            "<when test = 'query.beginTakeTime != null and query.endTakeTime != null '>",
            "AND o.`status` > 19 AND o.`take_time` between #{query.beginTakeTime} and #{query.endTakeTime}",
            "</when>",
            "<when test = 'query.beginSplitTime != null and query.endSplitTime != null '>",
            "AND o.`split_time` between #{query.beginSplitTime} and #{query.endSplitTime}",
            "</when>",
            "<when test = 'query.beginCreateTime != null and query.endCreateTime != null '>",
            "AND o.`create_time` between #{query.beginCreateTime} and #{query.endCreateTime}",
            "</when>",
            "<when test = 'query.beginPickTime != null and query.endPickTime != null '>",
            "AND o.order_id in(select distinct op.order_id from ecw_order_cargo_control_pick op where op.deleted = 0 and op.status in(1,3) and op.`create_time` between #{query.beginPickTime} and #{query.endPickTime})",
            "</when>",
            "<when test = 'query.beginPickUpTime != null and query.endPickUpTime != null '>",
            "AND o.order_no in(select distinct op.order_id from ecw_order_pickup op where op.deleted = 0 and op.`create_time` between #{query.beginPickUpTime} and #{query.endPickUpTime})",
            "</when>",
            "<when test = 'query.beginWarehouseInTime != null and query.endWarehouseInTime != null '>",
            "AND o.order_id in(select distinct wi.order_id from ecw_order_warehouse_in wi where wi.deleted = 0 and wi.`update_time` between #{query.beginWarehouseInTime} and #{query.endWarehouseInTime})",
            "</when>",
            "<when test = 'query.cargoControlStatus != null and query.cargoControlStatus != 3'>",
            " AND o.`cargo_control_status` = #{query.cargoControlStatus}",
            "</when>",
            "<when test = 'query.cargoControlStatus != null and query.cargoControlStatus == 3'>",
            " AND o.`cargo_control_status` = 1 AND (select count(1) from ecw_order_cargo_control_pick ccp2 where ccp2.order_id = o.order_id and ccp2.status = 1) > 0",
            "</when>",
            "AND (1= 1 ",
            "<when test = 'query.consignorId != null '>",
            "or nor.`customer_id` = #{query.consignorId} ",
            "</when>",
            "<when test = 'query.consignorPhone != null and query.consignorPhone != \"\" '>",
            "or nor.`phone` = #{query.consignorPhone} ",
            "</when>",
            " ) ",
            "<when test = '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},'%'))))",
            "</when>",
            "<when test = 'query.notConsignorKey != null and query.notConsignorKey != \"\" '>",
            "AND (concat(IFNULL(nor.`name`,''),IFNULL(nor.`name_en`,''),IFNULL(nor.`phone`,'')) not like concat('%',concat(#{query.notConsignorKey},'%'))",
            "AND nor.customer_id not in (select c.id from ecw_customer c where c.number like concat('%',concat(#{query.notConsignorKey},'%'))))",
            "</when>",
            "<when test = '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},'%'))))",
            "</when>",
            "<when test = 'query.notConsigneeKey != null and query.notConsigneeKey != \"\" '>",
            "AND (concat(IFNULL(nee.`name`,''),IFNULL(nee.`name_en`,''),IFNULL(nee.`phone`,'')) not like concat('%',concat(#{query.notConsigneeKey},'%'))",
            "AND nee.customer_id not in (select c.id from ecw_customer c where c.number like concat('%',concat(#{query.notConsigneeKey},'%'))))",
            "</when>",
            "<when test = 'query.startWarehouseId != null and query.destWarehouseId != null '>",
            "and (o.line_id in(",
            "select whl.id ",
            "from ecw_warehouse_line whl ",
            "where whl.start_warehouse_id = #{query.startWarehouseId} and whl.dest_warehouse_id = #{query.destWarehouseId} ",
            "))",
            "</when>",
            "<when test = 'query.startWarehouseId != null and query.destWarehouseId == null '>",
            "and (o.line_id in(",
            "select whl.id ",
            "from ecw_warehouse_line whl ",
            "where whl.start_warehouse_id = #{query.startWarehouseId}  ",
            "))",
            "</when>",
            "<when test = 'query.startWarehouseId == null and query.destWarehouseId != null '>",
            "and (o.line_id in(",
            "select whl.id ",
            "from ecw_warehouse_line whl ",
            "where whl.dest_warehouse_id = #{query.destWarehouseId} ",
            "))",
            "</when>",
            "<when test = 'query.searchKey != null and query.searchKey != \"\" '>",
            "AND concat(IFNULL(o.`order_no`,''), IFNULL(o.`old_numbers`,'') ,IFNULL(o.`marks`,''),IFNULL(o.`tidan_no`,''),IFNULL(o.`container_number`,''),IFNULL(nee.`name`,''),IFNULL(nee.`phone`,'')) like concat('%',concat(#{query.searchKey},'%'))",
            "</when>",
            "<when test = 'query.orderNo != null and query.orderNo != \"\" '>",
            "AND o.`order_no` like concat('%',concat(#{query.orderNo},'%'))",
            "</when>",
            "<when test = 'query.type != null and query.type != \"\" and query.type == 0 '>",
            "AND (o.type is null or o.type = '' or o.type = '0')",
            "</when>",
            "<when test = 'query.type == 1 '>",
            "AND FIND_IN_SET(1, o.type)",
            "</when>",
            "<when test = 'query.type == 2 '>",
            "AND FIND_IN_SET(2, o.type)",
            "</when>",
            "<when test = 'query.marks != null and query.marks != \"\" '>",
            "AND o.`marks` like concat('%',concat(#{query.marks},'%'))",
            "</when>",
            "<when test = 'query.containerNumber != null and query.containerNumber != \"\" '>",
            "AND o.`container_number` = #{query.containerNumber}",
            "</when>",
            "and occ.`phone` = #{query.cargoControlPhone} ",
            "and occ.is_actual = 1 and occ.deleted = 0 ",
            "</script>"
    })
    IPage<OrderBackPageVO> appCargoControlOrderPage(@Param("mpPage") IPage<OrderBackPageVO> mpPage, @Param("query") OrderQueryVO query);

    List<OrderBackPageVO> appCargoControlOrderList(@Param("start") int start, @Param("size") int size, @Param("query") OrderQueryVO query);

    long appCargoControlOrderCount(@Param("query") OrderQueryVO query);

    @ResultType(OrderBackPageVO.class)
    @Select({
            "<script>",
            "select o.order_id, ",
            "(select ifnull(sum(ccp.pick_num),0) from ecw_order_cargo_control_pick ccp where ccp.order_id = o.order_id and ccp.status in(1,2,3,4,5,6) ) as release_num, ",
            "(select ifnull(sum(ccp.pick_quantity),0) from ecw_order_cargo_control_pick ccp where ccp.order_id = o.order_id and ccp.status in(1,2,3,4,5,6) ) as release_quantity, ",
            "(select ifnull(sum(ccp.pick_volume),0) from ecw_order_cargo_control_pick ccp where ccp.order_id = o.order_id and ccp.status in(1,2,3,4,5,6) ) as release_volume, ",
            "(select ifnull(sum(ccp.pick_weight),0) from ecw_order_cargo_control_pick ccp where ccp.order_id = o.order_id and ccp.status in(1,2,3,4,5,6) ) as release_weight, ",
            "o.number, ",
            "o.order_no, ",
            "o.tidan_no, ",
            "o.parent_number, ",
            "o.parent_order_id, ",
            "o.initial_parent_order_id, ",
            "o.type, ",
            "o.order_type, ",
            "o.air_shipment, ",
//            "IF(o.order_type != 2 and (SELECT COUNT(1) FROM ecw_order_exception hoe WHERE hoe.order_id = o.order_id AND hoe.deleted = 0 AND hoe.order_exception_status = 0 AND hoe.order_exception_type ='order_heavy_cargo_exception') = 0, o.sum_volume, o.w_volume ) as w_volume, ",
            "IFNULL((select SUM(IF(it.charge_volume > it.min_metering_volume, it.charge_volume, it.min_metering_volume)) FROM ecw_order_item it WHERE it.order_id = o.order_id and it.deleted = 0 and it.warehouse_in_info IS NOT NULL), 0) as w_volume, ",
//            "IF(o.order_type != 3 and (SELECT COUNT(1) FROM ecw_order_exception boe WHERE boe.order_id = o.order_id AND boe.deleted = 0 AND boe.order_exception_status = 0 AND boe.order_exception_type ='order_bulky_cargo_exception') = 0, o.sum_weight, o.v_weight ) as v_weight, ",
            "IFNULL((select SUM(IF( it.charge_weight > it.min_metering_weight, it.charge_weight, it.min_metering_weight)) FROM ecw_order_item it WHERE it.order_id = o.order_id and it.deleted = 0 and it.warehouse_in_info IS NOT NULL), 0) as v_weight, ",
            "o.customs_type, ",
            "if(#{lang} = 0, de.departure ->> '$.titleZh', de.departure ->> '$.titleEn') as departure_name, ",
            "if(#{lang} = 0, ob.objective ->> '$.titleZh', ob.objective ->> '$.titleEn') as objective_name, ",
            "if(#{userType} = 1, 1, 2) as user_type, ",
            "o.marks, ",
            "o.`status`, ",
            "o.abnormal_state, ",
            "o.in_warehouse_state, ",
            "o.shipment_state, ",
            "o.pick_state, ",
            "o.audit_type, ",
            "o.audit_result, ",
            "o.transport_id, ",
            "o.is_cargo_control, ",
            "o.cargo_control_status, ",
            "o.cost ->> '$.totalNum' as total_num, ",
            "o.sum_num, ",
            "o.sum_volume, ",
            "o.sum_weight, ",
            "o.sum_volume_finished_warehouse_in, ",
            "o.sum_weight_finished_warehouse_in, ",
            "o.sum_quantity, ",
            "o.packing_list_url, ",
            "o.is_external_warehouse, ",
            "o.exception_reason, ",
            "o.is_exception, ",
            "o.create_time, ",
            "IF(o.user_id is not null AND o.user_id > 0 AND o.`status` = 0, 1 , 0)  as st, ",
            "nor.name as consignor_name, ",
            "nor.name_en as consignor_name_en, ",
            "nor.phone as consignor_phone, ",
            "nor.country_code as consignor_country_code, ",
            "nee.name as consignee_name, ",
            "nee.name_en as consignee_name_en, ",
            "nee.phone as consignee_phone, ",
            "nee.country_code as consignee_country_code, ",
            "occ.name as cargo_control_name, ",
            "occ.name_en as cargo_control_name_en, ",
            "occ.phone as cargo_control_phone, ",
            "occ.dial_code as cargo_control_country_code, ",
            "o.update_time, ",
            "#{lang} as lang ",
            "from ecw_order o ",
            "left join ecw_order_departure de on de.order_id = o.order_id ",
            "left join ecw_order_objective ob on ob.order_id = o.order_id ",
            "left join ecw_order_consignor nor on nor.order_id = o.order_id ",
            "left join ecw_order_consignee nee on nee.order_id = o.order_id ",
            "left join ecw_order_cargo_control occ ",
            "on occ.order_id = o.order_id and occ.is_actual = 1 and occ.deleted = 0 ",
            "where o.deleted = 0 and o.in_warehouse_state != 211 and o.in_warehouse_state != 208 and o.status != 10 ",
            "and o.order_id not in(#{orderId}) ",
            "and o.is_cargo_control = 1 ",
            "AND o.`cargo_control_status` in(0,2) ",
            "and occ.`phone` = #{cargoControlPhone} ",
            "<when test = 'userType == 2 '>",
            "HAVING st = 0 ",
            "</when>",
            "</script>"
    })
    List<OrderBackPageVO> cargoControlOrderSelect(@Param("orderId") Long orderId,
                                                  @Param("cargoControlPhone") String cargoControlPhone,
                                                  @Param("userType") Integer userType,
                                                  @Param("lang") Integer lang);

    @ResultType(OrderBackPageVO.class)
    @Select({
            "<script>",
            "select o.order_id, ",
            "o.number, ",
            "o.order_no, ",
            "o.tidan_no, ",
            "o.type, ",
            "o.order_type, ",
            "o.air_shipment, ",
//            "IF(o.order_type != 2 and (SELECT COUNT(1) FROM ecw_order_exception hoe WHERE hoe.order_id = o.order_id AND hoe.deleted = 0 AND hoe.order_exception_status = 0 AND hoe.order_exception_type ='order_heavy_cargo_exception') = 0, o.sum_volume, o.w_volume ) as w_volume, ",
            "IFNULL((select SUM(IF(it.charge_volume > it.min_metering_volume, it.charge_volume, it.min_metering_volume)) FROM ecw_order_item it WHERE it.order_id = o.order_id and it.deleted = 0 and it.warehouse_in_info IS NOT NULL), 0) as w_volume, ",
//            "IF(o.order_type != 3 and (SELECT COUNT(1) FROM ecw_order_exception boe WHERE boe.order_id = o.order_id AND boe.deleted = 0 AND boe.order_exception_status = 0 AND boe.order_exception_type ='order_bulky_cargo_exception') = 0, o.sum_weight, o.v_weight ) as v_weight, ",
            "IFNULL((select SUM(IF( it.charge_weight > it.min_metering_weight, it.charge_weight, it.min_metering_weight)) FROM ecw_order_item it WHERE it.order_id = o.order_id and it.deleted = 0 and it.warehouse_in_info IS NOT NULL), 0) as v_weight, ",
            "o.customs_type, ",
            "o.parent_number, ",
            "o.parent_order_id, ",
            "o.initial_parent_order_id, ",
            "if(#{query.lang} = 0, de.departure ->> '$.titleZh', de.departure ->> '$.titleEn') as departure_name, ",
            "if(#{query.lang} = 0, ob.objective ->> '$.titleZh', ob.objective ->> '$.titleEn') as objective_name, ",
            "if(#{query.userType} = 1, 1, 2) as user_type, ",
            "o.marks, ",
            "o.`status`, ",
            "o.abnormal_state, ",
            "o.in_warehouse_state, ",
            "o.shipment_state, ",
            "o.pick_state, ",
            "o.audit_type, ",
            "o.audit_result, ",
            "o.transport_id, ",
            "(select ifnull(sum(ccp.pick_num),0) from ecw_order_cargo_control_pick ccp where ccp.order_id = o.order_id and ccp.status in(1,2,3,4) ) as release_num, ",
            "o.is_cargo_control, ",
            "o.cargo_control_status, ",
            "o.cost ->> '$.totalNum' as total_num, ",
            "o.sum_num, ",
            "o.sum_volume, ",
            "o.sum_weight, ",
            "o.sum_volume_finished_warehouse_in, ",
            "o.sum_weight_finished_warehouse_in, ",
            "o.packing_list_url, ",
            "o.is_external_warehouse, ",
            "o.exception_reason, ",
            "o.is_exception, ",
            "o.create_time, ",
            "nor.name as consignor_name, ",
            "nor.name_en as consignor_name_en, ",
            "nor.phone as consignor_phone, ",
            "nor.country_code as consignor_country_code, ",
            "nee.name as consignee_name, ",
            "nee.name_en as consignee_name_en, ",
            "nee.phone as consignee_phone, ",
            "nee.country_code as consignee_country_code, ",
            "o.update_time, ",
            "#{query.lang} as lang ",
            "from ecw_order o ",
            "left join ecw_order_departure de on de.order_id = o.order_id ",
            "left join ecw_order_objective ob on ob.order_id = o.order_id ",
            "left join ecw_order_consignor nor on nor.order_id = o.order_id ",
            "left join ecw_order_consignee nee on nee.order_id = o.order_id ",
            "where o.deleted = 0 and o.in_warehouse_state != 211 and o.in_warehouse_state != 208 and o.status != 10 ",
            "<when test = 'query.status != null'>",
            "AND o.`status` = #{query.status}",
            "</when>",
            "<when test = 'query.packageType != null and query.packageType != \"\" '>",
            "AND CONCAT(',',o.package_type,',') REGEXP CONCAT(',',REPLACE(#{query.packageType},',',',|,'), ',')",
            "</when>",
            "<when test = 'query.beginRucangTime != null and query.endRucangTime != null '>",
//            "AND o.`rucang_time` between #{query.beginRucangTime} and #{query.endRucangTime}",
            "AND o.order_id in(select distinct wi.order_id from ecw_order_warehouse_in wi where wi.deleted = 0 and wi.`in_time` between #{query.beginRucangTime} and #{query.endRucangTime})",
            "</when>",
            "<when test = 'query.beginQingguanTime != null and query.endQingguanTime != null '>",
            "AND o.`qingguan_time` between #{query.beginQingguanTime} and #{query.endQingguanTime}",
            "</when>",
            "<when test = 'query.beginDaogangTime != null and query.endDaogangTime != null '>",
            "AND o.`daogang_time` between #{query.beginDaogangTime} and #{query.endDaogangTime}",
            "</when>",
            "<when test = 'query.beginPreLoadTime != null and query.endPreLoadTime != null '>",
            "AND o.`status` > 5 AND o.`pre_load_time` between #{query.beginPreLoadTime} and #{query.endPreLoadTime}",
            "</when>",
            "<when test = 'query.beginOutboundTime != null and query.endOutboundTime != null '>",
            "AND o.`status` > 5 AND o.container_number in(select distinct b.self_no from ecw_box_air_checkout bc join ecw_box b ON bc.shipment_id = b.id",
            "where b.deleted = 0 and bc.deleted = 0 and bc.`checkout_time` between #{query.beginOutboundTime} and #{query.endOutboundTime})",
            "</when>",
            "<when test = 'query.beginLoadTime != null and query.endLoadTime != null '>",
            "AND o.`load_time` between #{query.beginLoadTime} and #{query.endLoadTime}",
            "</when>",
            "<when test = 'query.beginUnloadTime != null and query.endUnloadTime != null '>",
            "AND o.`unload_time` between #{query.beginUnloadTime} and #{query.endUnloadTime}",
            "</when>",
            "<when test = 'query.beginTakeTime != null and query.endTakeTime != null '>",
            "AND o.`status` > 19 AND o.`take_time` between #{query.beginTakeTime} and #{query.endTakeTime}",
            "</when>",
            "<when test = 'query.beginSplitTime != null and query.endSplitTime != null '>",
            "AND o.`split_time` between #{query.beginSplitTime} and #{query.endSplitTime}",
            "</when>",
            "<when test = 'query.beginCreateTime != null and query.endCreateTime != null '>",
            "AND o.`create_time` between #{query.beginCreateTime} and #{query.endCreateTime}",
            "</when>",
            "<when test = 'query.beginPickTime != null and query.endPickTime != null '>",
            "AND o.order_id in(select distinct op.order_id from ecw_order_cargo_control_pick op where op.deleted = 0 and op.status in(1,3) and op.`create_time` between #{query.beginPickTime} and #{query.endPickTime})",
            "</when>",
            "<when test = 'query.beginPickUpTime != null and query.endPickUpTime != null '>",
            "AND o.order_no in(select distinct op.order_id from ecw_order_pickup op where op.deleted = 0 and op.`create_time` between #{query.beginPickUpTime} and #{query.endPickUpTime})",
            "</when>",
            "<when test = 'query.beginWarehouseInTime != null and query.endWarehouseInTime != null '>",
            "AND o.order_id in(select distinct wi.order_id from ecw_order_warehouse_in wi where wi.deleted = 0 and wi.`update_time` between #{query.beginWarehouseInTime} and #{query.endWarehouseInTime})",
            "</when>",
            "<when test = 'query.isExternalWarehouse != null'>",
            "AND o.`is_external_warehouse` = #{query.isExternalWarehouse}",
            "</when>",
            "<when test = '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} ))",
            "</when>",
            "<when test = 'query.customsType != null'>",
            "AND o.`customs_type` = #{query.customsType}",
            "</when>",
            "<when test = 'query.productRecord != null'>",
            "AND o.`product_record` = #{query.productRecord}",
            "</when>",
            "<when test = 'query.transportId != null'>",
            "AND o.`transport_id` = #{query.transportId}",
            "</when>",
            "<when test = 'query.channelId != null'>",
            "AND o.`channel_id` = #{query.channelId}",
            "</when>",
            "<when test = 'query.warehouseType != null'>",
            "AND o.`warehouse_type` = #{query.warehouseType}",
            "</when>",
            "<when test = '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},'%'))))))",
            "</when>",
            "<when test = '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},'%')))))",
            "</when>",
            "<when test = 'query.marks != null and query.marks != \"\" '>",
            "AND o.`marks` like concat('%',concat(#{query.marks},'%'))",
            "</when>",
            "<when test = 'query.departureId != null '>",
            "AND de.`departure_id` = #{query.departureId}",
            "</when>",
            "<when test = 'query.objectiveId != null '>",
            "AND ob.`objective_id` = #{query.objectiveId}",
            "</when>",
            "<when test = 'query.startWarehouseId != null and query.destWarehouseId != null '>",
            "and (o.line_id in(",
            "select whl.id ",
            "from ecw_warehouse_line whl ",
            "where whl.start_warehouse_id = #{query.startWarehouseId} and whl.dest_warehouse_id = #{query.destWarehouseId} ",
            "))",
            "</when>",
            "<when test = 'query.startWarehouseId != null and query.destWarehouseId == null '>",
            "and (o.line_id in(",
            "select whl.id ",
            "from ecw_warehouse_line whl ",
            "where whl.start_warehouse_id = #{query.startWarehouseId}  ",
            "))",
            "</when>",
            "<when test = 'query.startWarehouseId == null and query.destWarehouseId != null '>",
            "and (o.line_id in(",
            "select whl.id ",
            "from ecw_warehouse_line whl ",
            "where whl.dest_warehouse_id = #{query.destWarehouseId} ",
            "))",
            "</when>",
            "AND (nee.`phone` = #{query.consigneePhone} ",
            "<if test='query.consigneeContactsIds != null and query.consigneeContactsIds.size() != 0'>",
            "or nee.customer_contacts_id in ",
            "<foreach item='customerContactsId' index='index' collection='query.consigneeContactsIds' open='(' separator=',' close=')'>#{customerContactsId}</foreach>",
            "</if>)",
            "<when test = 'query.searchKey != null and query.searchKey != \"\" '>",
            "AND concat(IFNULL(o.`order_no`,''), IFNULL(o.`old_numbers`,'') ,IFNULL(o.`marks`,''),IFNULL(o.`tidan_no`,''),IFNULL(o.`container_number`,''),IFNULL(nee.`name`,''),IFNULL(nee.`phone`,'')) like concat('%',concat(#{query.searchKey},'%'))",
            "</when>",
            "<when test = 'query.orderNo != null and query.orderNo != \"\" '>",
            "AND o.`order_no` like concat('%',concat(#{query.orderNo},'%'))",
            "</when>",
            "<when test = 'query.type != null and query.type != \"\" and query.type == 0 '>",
            "AND (o.type is null or o.type = '' or o.type = '0')",
            "</when>",
            "<when test = 'query.type == 1 '>",
            "AND FIND_IN_SET(1, o.type)",
            "</when>",
            "<when test = 'query.type == 2 '>",
            "AND FIND_IN_SET(2, o.type)",
            "</when>",
            "<when test = 'query.marks != null and query.marks != \"\" '>",
            "AND o.`marks` like concat('%',concat(#{query.marks},'%'))",
            "</when>",
            "<when test = 'query.containerNumber != null and query.containerNumber != \"\" '>",
            "AND o.`container_number` = #{query.containerNumber}",
            "</when>",
            "</script>"
    })
    IPage<OrderBackPageVO> receivedOrderPage(@Param("mpPage") IPage<OrderBackPageVO> mpPage, @Param("query") OrderQueryVO query);

    @ResultType(OrderBackPageVO.class)
    @Select({
            "<script>",
            "select rs.order_id, ",
            "rs.number, ",
            "rs.order_no, ",
            "rs.tidan_no, ",
            "rs.type, ",
            "rs.order_type, ",
            "rs.air_shipment, ",
            "IF(rs.order_type != 2 and (SELECT COUNT(1) FROM ecw_order_exception hoe WHERE hoe.order_id = rs.order_id AND hoe.deleted = 0 AND hoe.order_exception_status = 0 AND hoe.order_exception_type ='order_heavy_cargo_exception') = 0, rs.sum_volume, rs.w_volume ) as w_volume, ",
            "IF(rs.order_type != 3 and (SELECT COUNT(1) FROM ecw_order_exception boe WHERE boe.order_id = rs.order_id AND boe.deleted = 0 AND boe.order_exception_status = 0 AND boe.order_exception_type ='order_bulky_cargo_exception') = 0, rs.sum_weight, rs.v_weight ) as v_weight, ",
            "rs.customs_type, ",
            "rs.parent_number, ",
            "rs.parent_order_id, ",
            "rs.user_id, ",
            "if(#{query.lang} = 0, de.departure ->> '$.titleZh', de.departure ->> '$.titleEn') as departure_name, ",
            "if(#{query.lang} = 0, ob.objective ->> '$.titleZh', ob.objective ->> '$.titleEn') as objective_name, ",
            "if(#{query.userType} = 1, 1, 2) as user_type, ",
            "rs.marks, ",
            "rs.`status`, ",
            "rs.abnormal_state, ",
            "rs.in_warehouse_state, ",
            "rs.shipment_state, ",
            "rs.pick_state, ",
            "rs.audit_type, ",
            "rs.audit_result, ",
            "rs.exception_reason, ",
            "rs.is_exception, ",
            "rs.transport_id, ",
            "rs.is_cargo_control, ",
            "rs.cargo_control_status, ",
            "rs.cost ->> '$.totalNum' as total_num, ",
            "rs.sum_num, ",
            "rs.sum_volume, ",
            "rs.sum_weight, ",
            "rs.sum_volume_finished_warehouse_in, ",
            "rs.sum_weight_finished_warehouse_in, ",
            "rs.packing_list_url, ",
            "rs.create_time, ",
            "rs.consignor_name, ",
            "rs.consignor_country_code, ",
            "rs.consignor_phone, ",
            "rs.consignee_name, ",
            "rs.consignee_country_code, ",
            "rs.consignee_phone, ",
            "rs.cargo_control_name, ",
            "rs.cargo_control_country_code, ",
            "rs.cargo_control_phone, ",
            "rs.release_num, ",
            "rs.update_time ",
            "from (",
            "select ",
            "o.*, ",
            "(select ifnull(sum(ccp.pick_num),0) from ecw_order_cargo_control_pick ccp where ccp.order_id = o.order_id and ccp.status in(1,2,3,4) ) as release_num, ",
            "occ.`name` as cargo_control_name, ",
            "occ.dial_code as cargo_control_country_code, ",
            "occ.phone as cargo_control_phone, ",
            "nor.`name` as consignor_name, ",
            "nor.country_code as consignor_country_code, ",
            "nor.phone as consignor_phone, ",
            "nee.`name` as consignee_name, ",
            "nee.country_code as consignee_country_code, ",
            "nee.phone as consignee_phone,",
            "#{query.lang} as lang",
            "from ecw_order o ",
            "left join ecw_order_consignor nor ",
            "on nor.order_id = o.order_id",
            "left join ecw_order_consignee nee ",
            "on nee.order_id = nor.order_id",
            "left join ecw_order_cargo_control occ ",
            "on occ.order_id = nor.order_id and occ.is_actual = 1 and occ.deleted = 0 ",
            "where o.deleted = 0 and o.in_warehouse_state != 211 and o.in_warehouse_state != 208 and o.status != 10 ",
            "<when test = 'query.status != null'>",
            "AND o.`status` = #{query.status}",
            "</when>",
            "<when test = 'query.beginRucangTime != null and query.endRucangTime != null '>",
//            "AND o.`rucang_time` between #{query.beginRucangTime} and #{query.endRucangTime}",
            "AND o.order_id in(select distinct wi.order_id from ecw_order_warehouse_in wi where wi.deleted = 0 and wi.`in_time` between #{query.beginRucangTime} and #{query.endRucangTime})",
            "</when>",
            "<when test = 'query.beginQingguanTime != null and query.endQingguanTime != null '>",
            "AND o.`qingguan_time` between #{query.beginQingguanTime} and #{query.endQingguanTime}",
            "</when>",
            "<when test = 'query.beginDaogangTime != null and query.endDaogangTime != null '>",
            "AND o.`daogang_time` between #{query.beginDaogangTime} and #{query.endDaogangTime}",
            "</when>",
            "<when test = 'query.beginPreLoadTime != null and query.endPreLoadTime != null '>",
            "AND o.`status` > 5 AND o.`pre_load_time` between #{query.beginPreLoadTime} and #{query.endPreLoadTime}",
            "</when>",
            "<when test = 'query.beginOutboundTime != null and query.endOutboundTime != null '>",
            "AND o.`status` > 5 AND o.container_number in(select distinct b.self_no from ecw_box_air_checkout bc join ecw_box b ON bc.shipment_id = b.id",
            "where b.deleted = 0 and bc.deleted = 0 and bc.`checkout_time` between #{query.beginOutboundTime} and #{query.endOutboundTime})",
            "</when>",
            "<when test = 'query.beginLoadTime != null and query.endLoadTime != null '>",
            "AND o.`load_time` between #{query.beginLoadTime} and #{query.endLoadTime}",
            "</when>",
            "<when test = 'query.beginUnloadTime != null and query.endUnloadTime != null '>",
            "AND o.`unload_time` between #{query.beginUnloadTime} and #{query.endUnloadTime}",
            "</when>",
            "<when test = 'query.beginTakeTime != null and query.endTakeTime != null '>",
            "AND o.`status` > 19 AND o.`take_time` between #{query.beginTakeTime} and #{query.endTakeTime}",
            "</when>",
            "<when test = 'query.beginSplitTime != null and query.endSplitTime != null '>",
            "AND o.`split_time` between #{query.beginSplitTime} and #{query.endSplitTime}",
            "</when>",
            "<when test = 'query.beginCreateTime != null and query.endCreateTime != null '>",
            "AND o.`create_time` between #{query.beginCreateTime} and #{query.endCreateTime}",
            "</when>",
            "<when test = 'query.packageType != null and query.packageType != \"\" '>",
            "AND CONCAT(',',o.package_type,',') REGEXP CONCAT(',',REPLACE(#{query.packageType},',',',|,'), ',')",
            "</when>",
            "<when test = 'query.beginPickTime != null and query.endPickTime != null '>",
            "AND o.order_id in(select distinct op.order_id from ecw_order_cargo_control_pick op where op.deleted = 0 and op.status in(1,3) and op.`create_time` between #{query.beginPickTime} and #{query.endPickTime})",
            "</when>",
            "<when test = 'query.beginPickUpTime != null and query.endPickUpTime != null '>",
            "AND o.order_no in(select distinct op.order_id from ecw_order_pickup op where op.deleted = 0 and op.`create_time` between #{query.beginPickUpTime} and #{query.endPickUpTime})",
            "</when>",
            "<when test = 'query.beginWarehouseInTime != null and query.endWarehouseInTime != null '>",
            "AND o.order_id in(select distinct wi.order_id from ecw_order_warehouse_in wi where wi.deleted = 0 and wi.`update_time` between #{query.beginWarehouseInTime} and #{query.endWarehouseInTime})",
            "</when>",
            "<when test = '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} ))",
            "</when>",
            "<when test = 'query.customsType != null'>",
            "AND o.`customs_type` = #{query.customsType}",
            "</when>",
            "<when test = 'query.productRecord != null'>",
            "AND o.`product_record` = #{query.productRecord}",
            "</when>",
            "<when test = 'query.transportId != null'>",
            "AND o.`transport_id` = #{query.transportId}",
            "</when>",
            "<when test = 'query.channelId != null'>",
            "AND o.`channel_id` = #{query.channelId}",
            "</when>",
            "<when test = 'query.warehouseType != null'>",
            "AND o.`warehouse_type` = #{query.warehouseType}",
            "</when>",
            "<when test = '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},'%'))))))",
            "</when>",
            "<when test = '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},'%')))))",
            "</when>",
            "<when test = 'query.marks != null and query.marks != \"\" '>",
            "AND o.`marks` like concat('%',concat(#{query.marks},'%'))",
            "</when>",
            "<when test = 'query.searchKey != null and query.searchKey != \"\" '>",
            "AND concat(IFNULL(o.`order_no`,''), IFNULL(o.`old_numbers`,'') ,IFNULL(o.`marks`,''),IFNULL(o.`tidan_no`,''),IFNULL(o.`container_number`,''),IFNULL(nee.`name`,''),IFNULL(nee.`phone`,'')) like concat('%',concat(#{query.searchKey},'%'))",
            "</when>",
            "<when test = 'query.type != null and query.type != \"\" and query.type == 0 '>",
            "AND (o.type is null or o.type = '' or o.type = '0')",
            "</when>",
            "<when test = 'query.type == 1 '>",
            "AND FIND_IN_SET(1, o.type)",
            "</when>",
            "<when test = 'query.type == 2 '>",
            "AND FIND_IN_SET(2, o.type)",
            "</when>",
            "<when test = 'query.orderNo != null and query.orderNo != \"\" '>",
            "AND o.`order_no` like concat('%',concat(#{query.orderNo},'%'))",
            "</when>",
            "and (o.`user_id` = #{query.userId} ",
            "or occ.`phone` = #{query.cargoControlPhone} ",
            "or nee.customer_contacts_id = #{query.consigneeContactsId} ",
            "or nee.`phone` = #{query.consigneePhone} ",
            "or nor.customer_contacts_id = #{query.consignorContactsId} ",
            "or nor.`phone` = #{query.consignorPhone} )",
            ") rs ",
            "left join ecw_order_departure de on de.order_id = rs.order_id ",
            "left join ecw_order_objective ob on ob.order_id = rs.order_id ",
            "where rs.deleted = 0",
            "<when test = 'query.departureId != null '>",
            "AND de.`departure_id` = #{query.departureId}",
            "</when>",
            "<when test = 'query.objectiveId != null '>",
            "AND ob.`objective_id` = #{query.objectiveId}",
            "</when>",
            "<when test = 'query.startWarehouseId != null and query.destWarehouseId != null '>",
            "and (o.line_id in(",
            "select whl.id ",
            "from ecw_warehouse_line whl ",
            "where whl.start_warehouse_id = #{query.startWarehouseId} and whl.dest_warehouse_id = #{query.destWarehouseId} ",
            "))",
            "</when>",
            "<when test = 'query.startWarehouseId != null and query.destWarehouseId == null '>",
            "and (rs.line_id in(",
            "select whl.id ",
            "from ecw_warehouse_line whl ",
            "where whl.start_warehouse_id = #{query.startWarehouseId}  ",
            "))",
            "</when>",
            "<when test = 'query.startWarehouseId == null and query.destWarehouseId != null '>",
            "and (rs.line_id in(",
            "select whl.id ",
            "from ecw_warehouse_line whl ",
            "where whl.dest_warehouse_id = #{query.destWarehouseId} ",
            "))",
            "</when>",
            "</script>"
    })
    IPage<OrderBackPageVO> myAllOrderPage(@Param("mpPage") IPage<OrderBackPageVO> mpPage, @Param("query") OrderQueryVO query);

    List<OrderBackPageVO> myAllOrderList(@Param("start") int start, @Param("size") int size, @Param("query") OrderQueryVO query);

    long myAllOrderCount(@Param("query") OrderQueryVO query);

    @ResultType(OrderPreloadVO.class)
    @Select({
            "<script>",
            "SELECT eo.order_id, ",
            "eo.order_no, ",
            "eo.transport_id, ",
            "eo.line_id, ",
            "eo.channel_id, ",
            "eo.STATUS, ",
            "eo.abnormal_state, ",
            "eo.in_warehouse_state, ",
            "eo.warehouse_type, ",
            "eo.weight_ratio, ",
            "eo.product_record, ",
            "eo.customs_type, ",
            "if(#{query.lang} = 0, eod.departure ->> '$.titleZh', eod.departure ->> '$.titleEn') as start_warehouse_name, ",
            "if(#{query.lang} = 0, eoo.objective ->> '$.titleZh', eoo.objective ->> '$.titleEn') as dest_warehouse_name, ",
            "eo.rucang_time, ",
            "#{query.lang} as lang ",
            "FROM ecw_order eo, ",
            "ecw_order_item eoi, ",
            "ecw_order_departure eod,",
            "ecw_order_objective eoo",
            "WHERE eo.order_id = eoi.order_id ",
            "and eo.order_id = eod.order_id ",
            "and eo.order_id = eoo.order_id ",
            "and eo.deleted=0 and eo.in_warehouse_state != 211 and eo.in_warehouse_state != 208 and eo.status != 10 ",
            "<when test = 'query.rucangTimeStart != null'>",
            "AND eo.`rucang_time` &gt;= #{query.rucangTimeStart}",
            "</when>",
            "<when test = 'query.rucangTimeEnd != null'>",
            "AND eo.`rucang_time &lt;= #{query.rucangTimeEnd}",
            "</when>",
            "<when test = 'query.productRecord != null'>",
            "AND eo.`product_record` = #{query.productRecord}",
            "</when>",
            "<when test = 'query.orderNo != null and query.orderNo != \"\" '>",
            "AND eo.`order_no` like concat('%',concat(#{query.orderNo},'%'))",
            "</when>",
            "<when test = 'query.type != null and query.type != \"\" and query.type == 0 '>",
            "AND (eo.type is null or eo.type = '' or eo.type = '0')",
            "</when>",
            "<when test = 'query.type != null and query.type == 1 '>",
            "AND FIND_IN_SET(1, eo.type)",
            "</when>",
            "<when test = 'query.type != null and query.type == 2 '>",
            "AND FIND_IN_SET(2, eo.type)",
            "</when>",
            "<when test = 'query.customsType != null '>",
            "AND eo.`customs_type` = #{query.customsType}",
            "</when>",
            "<when test = 'query.weightRatioMin != null '>",
            "AND eo.`weight_ratio` &gt;= #{query.weightRatioMin}",
            "</when>",
            "<when test = 'query.weightRatioMax != null '>",
            "AND eo.`weight_ratio` &lt;= #{query.weightRatioMax} ",
            "</when>",
            "<when test = 'query.startWarehouseId != null'>",
            "AND eod.`departure_id` = #{query.startWarehouseId}",
            "</when>",
            "<when test = 'query.destWarehouseIdList != null'>",
            "AND eoo.`objective_id` in ",
            "<foreach item='id' index='index' collection='destWarehouseIdList' open='(' separator=',' close=')'>#{id}</foreach>",
            "</when>",
            "<when test = 'query.itemName != null and query.itemName != \"\" '>",
            "AND (eoi.`prod_title_zh` like concat('%',concat(#{query.itemName},'%')) or eoi.`prod_title_en` like concat('%',concat(#{query.itemName},'%')) )",
            "</when>",
            "</script>"
    })
    IPage<OrderPreloadVO> orderPreloadPage(IPage<OrderPreloadVO> mPage, @Param("query") OrderPreloadReq query);

    @ResultType(OrderPreloadVO.class)
    @Select({
            "<script>",
            "SELECT eo.order_id, ",
            "eo.order_no, ",
            "eo.adjust_to_dest_warehouse_id, ",
            "eo.transport_id, ",
            "eo.line_id, ",
            "ewl.start_warehouse_id, ",
            "ewl.dest_warehouse_id, ",
            "eo.channel_id, ",
            "eo.STATUS, ",
            "eo.abnormal_state, ",
            "eo.in_warehouse_state, ",
            "eo.warehouse_type, ",
            "eo.port_dest_customs_clear, ",
            "eo.weight_ratio, ",
            "eo.product_record, ",
            "eo.is_external_warehouse, ",
            "eo.marks, ",
            "eo.customs_type, ",
            "if(#{query.lang} = 0, ew_start.title_zh, ew_start.title_en) as start_warehouse_name, ",
            "if(#{query.lang} = 0, ew_dest.title_zh, ew_dest.title_en) as dest_warehouse_name, ",
            "(select min(owi.`in_time`) from ecw_order_warehouse_in owi where owi.deleted = 0 and owi.order_id = eo.order_id ) as rucang_time,",  //eo.rucang_time,
            "eo.parent_order_id, ",
            "eo.guan_lian_order_status, ",
            "#{query.lang} as lang, ",
            "count(eo.order_id) match_item_count",
            "FROM ecw_order eo, ",
            "ecw_order_item eoi, ",
            "ecw_warehouse_line ewl, ",
            "ecw_warehouse ew_start, ",
            "ecw_warehouse ew_dest ",
            "WHERE eo.order_id = eoi.order_id and eo.in_warehouse_state not in (203,204,207,208,209,211,212) ",
            "and eo.line_id = ewl.id ",
            "and ewl.start_warehouse_id = ew_start.id ",
            "and ewl.dest_warehouse_id = ew_dest.id ",
            "and eo.deleted=0 ",
            "and eo.status in (5,8,9) ",
            "and eo.transport_id in (1,2,4)",
            "and eo.abnormal_state=0 ",
            "and eo.audit_type not in(6,11,13,14,22,23) ",
            "<when test = 'query.rucangTimeStart != null'>",
            "AND eo.`rucang_time` &gt;= #{query.rucangTimeStart}",
            "</when>",
            "<when test = 'query.rucangTimeEnd != null'>",
            "AND eo.`rucang_time` &lt;= #{query.rucangTimeEnd}",
            "</when>",
            "<when test = 'query.productRecord != null'>",
            "AND eoi.`fee_type` = #{query.productRecord}",
            "</when>",
            "<when test = 'query.destCountryId != null'>",
            "AND ew_dest.`guojia` = #{query.destCountryId}",
            "</when>",
            "<when test = 'query.orderNo != null and query.orderNo != \"\" '>",
            "AND eo.`order_no` like concat('%',concat(#{query.orderNo},'%'))",
            "</when>",
            "<when test = 'query.customsType != null '>",
            "AND eo.`customs_type` = #{query.customsType}",
            "</when>",
            "<when test = 'query.weightRatioMin != null '>",
            "AND eo.`weight_ratio` &gt;= #{query.weightRatioMin}",
            "</when>",
            "<when test = 'query.weightRatioMax != null '>",
            "AND eo.`weight_ratio` &lt;= #{query.weightRatioMax} ",
            "</when>",
            "<when test = 'query.transportType != null'>",
            "AND eo.`transport_id` = #{query.transportType}",
            "</when>",
//            "<when test = 'query.startWarehouseId != null'>",
//            "AND ewl.`start_warehouse_id` = #{query.startWarehouseId}",
//            "</when>",
            "<when test = 'query.destWarehouseIdList != null and query.destWarehouseIdList.size()!=0'>",
            "AND ewl.`dest_warehouse_id` in ",
            "<foreach item='id' index='index' collection='query.destWarehouseIdList' open='(' separator=',' close=')'>#{id}</foreach>",
            "</when>",
            "<when test = 'query.itemName != null and query.itemName != \"\" '>",
            "AND (eoi.`prod_title_zh` like concat('%',concat(#{query.itemName},'%')) or eoi.`prod_title_en` like concat('%',concat(#{query.itemName},'%')) )",
            "</when>",
            "GROUP BY eo.order_id",
            "</script>"
    })
    List<OrderPreloadVO> orderPreloadList(@Param("query") OrderPreloadReq query);


    IPage<OrderBackPageVO> getOrderListByIds(@Param("ids") List<Long> orderIds, @Param("orderQueryVO") OrderQueryVO orderQueryVO, @Param("mpPage") IPage<OrderBackPageVO> mpPage);


    @ResultType(OrderBackPageVO.class)
    @Select({
            "<script>",
            "select o.order_id, ",
            "o.package_type as advance_type, ",
            "o.package_remarks, ",
            "o.number, ",
            "o.order_no, ",
            "o.tidan_no, ",
            "o.type, ",
            "o.air_shipment, ",
            "o.rucang_time, ",
            "o.cost, ",
            "o.parent_number, ",
            "o.parent_order_id, ",
            "o.initial_parent_order_id, ",
            "if(#{query.lang} = 0, de.departure ->> '$.titleZh', de.departure ->> '$.titleEn') as departure_name, ",
            "if(#{query.lang} = 0, ob.objective ->> '$.titleZh', ob.objective ->> '$.titleEn') as objective_name, ",
            "de.departure_id, ",
            "ob.objective_id, ",
            "if(#{query.lang} = 0, ew_start.title_zh, ew_start.title_en) as start_warehouse_name, ",
            "if(#{query.lang} = 0, ew_dest.title_zh, ew_dest.title_en) as dst_warehouse_name, ",
            "ew_start.id as start_warehouse_id, ",
            "ew_dest.id as dst_warehouse_id, ",
            "o.marks, ",
            "o.status, ",
            "o.abnormal_state, ",
            "o.in_warehouse_state, ",
            "o.shipment_state, ",
            "o.pick_state, ",
            "o.audit_type, ",
            "o.audit_result, ",
            "o.transport_id, ",
            "o.is_cargo_control, ",
            "o.cargo_control_status, ",
            "o.cost ->> '$.totalNum' as total_num, ",
            "o.sum_num, ",
            "o.sum_volume, ",
            "o.sum_weight, ",
            "o.sum_volume_finished_warehouse_in, ",
            "o.sum_weight_finished_warehouse_in, ",
            "o.packing_list_url, ",
            "o.is_external_warehouse, ",
            "o.exception_reason, ",
            "o.is_exception, ",
            "o.create_time, ",
            "nor.name as consignor_name, ",
            "nor.name_en as consignor_name_en, ",
            "nor.phone as consignor_phone, ",
            "nor.country_code as consignor_country_code, ",
            "nee.name as consignee_name, ",
            "nee.name_en as consignee_name_en, ",
            "nee.phone as consignee_phone, ",
            "nee.country_code as consignee_country_code, ",
            "if(#{query.lang} = 0, channel.name_zh, channel.name_en) as channel_name, ",
            "o.update_time, ",
            "o.salesman_id, ",
            "su.nickname as salesman_name, ",
            "#{query.lang} as lang ",
            "from ecw_order o ",
            "inner join ecw_warehouse_line ewl ON ewl.id = o.line_id ",
            "inner join ecw_warehouse ew_start ON ewl.start_warehouse_id = ew_start.id",
            "inner join ecw_warehouse ew_dest ON ewl.dest_warehouse_id = ew_dest.id ",
            "left join ecw_order_departure de on de.order_id = o.order_id ",
            "left join ecw_order_objective ob on ob.order_id = o.order_id ",
            "left join ecw_order_consignor nor on nor.order_id = o.order_id ",
            "left join ecw_order_consignee nee on nee.order_id = o.order_id ",
            "left join ecw_channel channel on channel.channel_id = o.channel_id  ",
            "left join system_user su on su.id = o.salesman_id  ",
            "where o.deleted = 0 and o.in_warehouse_state != 211 and o.in_warehouse_state != 208 and o.status != 10 ",
            "<when test = 'query.pdaStartWareIds != null and query.pdaStartWareIds != \"\" '>",
            "AND FIND_IN_SET(ew_start.`id`, #{query.pdaStartWareIds})",
            "</when>",
            "<when test = 'query.pdaDestWareIds != null and query.pdaDestWareIds != \"\" '>",
            "AND FIND_IN_SET(ew_dest.`id`, #{query.pdaDestWareIds})",
            "</when>",
            "<when test = 'query.packageType != null and query.packageType != \"\" '>",
            "AND CONCAT(',',o.package_type,',') REGEXP CONCAT(',',REPLACE(#{query.packageType},',',',|,'), ',')",
            "</when>",
            "<when test = 'query.pdaAdjustStartWareIds != null and query.pdaAdjustStartWareIds != \"\" '>",
            "AND FIND_IN_SET(o.`adjust_to_start_warehouse_id`, #{query.pdaAdjustStartWareIds})",
            "</when>",
            "<when test = 'query.pdaAdjustDestWareIds != null and query.pdaAdjustDestWareIds != \"\" '>",
            "AND FIND_IN_SET(o.`adjust_to_dest_warehouse_id`, #{query.pdaAdjustDestWareIds})",
            "</when>",
            "<when test = 'query.orderNo != null and query.orderNo != \"\" '>",
            "AND o.`order_no` like concat('%',concat(#{query.orderNo},'%'))",
            "</when>",

            "<when test = 'query.statusList != null'> ",
            "AND o.`status` in ",
            "<foreach item='statusItem' index='index' collection='query.statusList' open='(' separator=',' close=')'>#{statusItem}</foreach> ",
            "</when> ",
            "<when test = 'query.excludeStatusList != null'> ",
            "AND o.`status` not in ",
            "<foreach item='statusItem' index='index' collection='query.excludeStatusList' open='(' separator=',' close=')'>#{statusItem}</foreach> ",
            "</when> ",
            "<when test = 'query.status != null '>",
            "AND o.`status` = #{query.status}",
            "</when>",
            "<when test = 'query.warehouseInStatus != null '>",
            "AND o.`in_warehouse_state` = #{query.warehouseInStatus}",
            "</when>",

            "<when test = 'query.transportIdList != null and query.transportIdList.size() > 0'> ",
            "AND o.`transport_id` in ",
            "<foreach item='transportId' index='index' collection='query.transportIdList' open='(' separator=',' close=')'>#{transportId}</foreach> ",
            "</when> ",


            "</script>"
    })
    IPage<OrderBackPageVO> pdaOrderPage(IPage<OrderBackPageVO> mpPage, @Param("query") PdaOrderQueryVo query);


    @ResultType(SearchBackDto.class)
    @Select({
            "<script>",
            "SELECT",
            "s.order_no as value",
            "FROM",
            "        ( SELECT t.order_no FROM ecw_order t where deleted =0  GROUP BY t.order_no ) s",
            "WHERE",
            "s.order_no LIKE concat('%',#{keyValue},'%')",
            "</script>"
    })
    IPage<SearchBackDto> orderNoSearch(IPage<SearchBackDto> mpPage, @Param("keyValue") String key);

    @ResultType(SearchBackDto.class)
    @Select({
            "<script>",
            "SELECT",
            "s.tidan_no  as value",
            "FROM",
            "        ( SELECT t.tidan_no  FROM ecw_order t WHERE deleted =0  GROUP BY t.`tidan_no`  ) s",
            "WHERE",
            "s.tidan_no LIKE concat('%',#{keyValue},'%')",
            "</script>"
    })
    IPage<SearchBackDto> billNoSearch(IPage<SearchBackDto> mpPage, @Param("keyValue") String key);

    IPage<OrderBackVO> getUnGuanlianOrderPage(@Param("mpPage") IPage<OrderBackVO> mpPage, @Param("query") OrderQueryVO orderQueryVo);

    IPage<OrderDO> getUnMutualOrderPage(@Param("mpPage") IPage<OrderDO> mpPage, @Param("query") OrderQueryVO orderQueryVo);

    List<OrderExportBackDTO> getExportOrderList(@Param("query") OrderQueryVO query);

    @ResultType(OrderBackInfoDto.class)
    @Select({
            "<script>",
            "SELECT",
            "o.*,",
            "IF((SELECT count(1) FROM ecw_make_bill_of_lading mbl WHERE mbl.order_id = o.order_id and mbl.deleted=0 and mbl.status = 2) > 0, true, false) as lading_state, ",
            "IF(o.order_type != 2 and (SELECT COUNT(1) FROM ecw_order_exception hoe WHERE hoe.order_id = o.order_id AND hoe.deleted = 0 AND hoe.order_exception_status = 0 AND hoe.order_exception_type ='order_heavy_cargo_exception') = 0, o.sum_volume, o.w_volume ) as we_volume, ",
            "IF(o.order_type != 3 and (SELECT COUNT(1) FROM ecw_order_exception boe WHERE boe.order_id = o.order_id AND boe.deleted = 0 AND boe.order_exception_status = 0 AND boe.order_exception_type ='order_bulky_cargo_exception') = 0, o.sum_weight, o.v_weight ) as vo_weight, ",
            "d.name as dept_name,",
            "u.nickname as salesman_name,",
            "if(#{lang} = 0, c.name_zh, c.name_en) as channel_name, ",
            "c.attr_id as channel_attr_id ",
            "FROM",
            "ecw_order o ",
            "LEFT JOIN ecw_channel c on o.channel_id = c.channel_id",
            "LEFT JOIN system_dept d on o.dept_id = d.id",
            "LEFT JOIN system_user u on o.salesman_id = u.id",
            "WHERE",
            "o.order_id = #{orderId}",
            "</script>"
    })
    OrderBackInfoDto info(@Param("orderId") Long orderId, @Param("lang") Integer lang);

    @ResultType(BigDecimal.class)
    @Select({
            "<script>",
            "SELECT",
            "IFNULL(sum(oi.volume),0)",
            "FROM",
            "ecw_order_item oi ",
            "LEFT JOIN ecw_order o ",
            "on o.order_id = oi.order_id ",
            "WHERE",
            "o.delivery_date = #{deliveryDate}",
            "AND oi.prod_id = #{prodId}",
            "<when test = 'orderItemId != null '>",
            "AND oi.order_item_id != #{orderItemId}",
            "</when>",
            "</script>"
    })
    BigDecimal getOrderTotalVolumeByDeliveryDate(@Param("deliveryDate") Date deliveryDate, @Param("prodId") Long prodId, @Param("orderItemId") Long orderItemId);

    @ResultType(BigDecimal.class)
    @Select({
            "<script>",
            "SELECT",
            "IFNULL(sum(oi.weight),0)",
            "FROM",
            "ecw_order_item oi ",
            "LEFT JOIN ecw_order o ",
            "on o.order_id = oi.order_id ",
            "WHERE",
            "o.delivery_date = #{deliveryDate}",
            "AND oi.prod_id = #{prodId}",
            "<when test = 'orderItemId != null '>",
            "AND oi.order_item_id != #{orderItemId}",
            "</when>",
            "</script>"
    })
    BigDecimal getOrderTotalWeightByDeliveryDate(@Param("deliveryDate") Date deliveryDate, @Param("prodId") Long prodId, @Param("orderItemId") Long orderItemId);

    @ResultType(OrderDO.class)
    @Select({
            "<script>",
            "SELECT",
            "o.*,",
            "d.id as departure_id,",
            "if(#{lang} =0, d.departure ->> '$.titleZh', d.departure ->> '$.titleEn') as departure_name,",
            "oo.id as objective_id,",
            "if(#{lang} =0, oo.objective ->> '$.titleZh', oo.objective ->> '$.titleEn') as objective_name",
            "FROM",
            "ecw_order o ",
            "LEFT JOIN ecw_order_departure d on o.order_id = d.order_id",
            "LEFT JOIN ecw_order_objective oo on o.order_id = oo.order_id",
            "WHERE",
            "o.order_id = #{orderId}",
            "</script>"
    })
    OrderDO headBaseInfo(@Param("orderId") Long orderId, @Param("lang") Integer lang);


    @Update("update ecw_order set  adjust_to_start_warehouse_id = #{adjustToStartWarehouseId}, adjust_to_dest_warehouse_id = #{adjustToDestWarehouseId} where order_id = #{orderId}")
    void updateAdjustWarehouseId(@Param("orderId") Long orderId, @Param("adjustToStartWarehouseId") Long adjustToStartWarehouseId, @Param("adjustToDestWarehouseId") Long adjustToDestWarehouseId);

    @Update("update ecw_order set  dest_adjust_to_start_warehouse_id = #{destAdjustToStartWarehouseId}, dest_adjust_to_dest_warehouse_id = #{destAdjustToDestWarehouseId} where order_id = #{orderId}")
    void updateDestAdjustWarehouseId(@Param("orderId") Long orderId, @Param("destAdjustToStartWarehouseId") Long destAdjustToStartWarehouseId, @Param("destAdjustToDestWarehouseId") Long destAdjustToDestWarehouseId);

    @ResultType(OrderItemDO.class)
    @Select({
            "<script>",
            "SELECT",
            "eoi.*",
            "FROM",
            "ecw_order_item eoi, ",
            "ecw_order eo ",
            "WHERE",
            "eoi.order_id=eo.order_id and eo.deleted=0 ",
            "and eoi.prod_id = #{productId}",
//            "and item_status = -1",
            "and eoi.line_id = #{lineId}",
            "<when test = 'channelId != null '>",
            "and eoi.channel_id = #{channelId}",
            "</when>",
            "</script>"
    })
    List<OrderItemDO> getOrderItemByLineIdAndProductId(@Param("lineId") Long lineId, @Param("productId") Long productId, @Param("channelId") Long channelId);


    @Select({
            "<script>",
            "select sum(ct) as ctsum from (",
            "select count(0) as ct from ecw_order_approval where `status` = 1 and order_id = #{orderId}",
            "union all",
            "select count(0) as ct from ecw_box_approval where `approval_status` = 1 and order_id = #{orderId}",
            "union all",
            "select count(0) as ct from ecw_order_fee_application where `status`=1 and deleted=0 and order_id=#{orderId}",
            "union all",
            "SELECT count(0) as ct FROM ecw_merge a LEFT JOIN ecw_order b ON a.apply_order_no = b.order_no left join ecw_order c on a.order_nos=c.order_no where a.`status`=1 and a.deleted=0 and (b.order_id=#{orderId} or c.order_id=#{orderId})",
            "union all",
            "select count(0) as ct from ecw_order_warehouse_approval where type !=  2 and `status` = 1 and order_ids = #{orderId}",
            "union all",
            "select count(0) as ct from ecw_order_warehouse_approval a inner join ecw_order_warehouse_adjust b on a.order_ids = b.id where a.type = 2 and a.`status` = 1 and b.`status` = 1 and b.order_id = #{orderId}",
            ") as total",
            "</script>"
    })
    Integer getWaitApprovalCount(@Param("orderId") Long orderId);

    @Select({
            "<script>",
            "select t2.ld_box_time from ecw_order t ",
            "LEFT JOIN ecw_box_preload_goods t1 on t.order_id=t1.order_id",
            "LEFT JOIN ecw_box_cabinet t2 on t1.shipment_id=t2.shipment_id",
            "where t.customer_id=#{customerId} and t2.ld_box_time is not null order by t2.ld_box_time asc limit 1",
            "</script>"
    })
    String getEarliestBoxTime(Long customerId);

    @Select({
            "<script>",
            "select cc.userId from ecw_order_consignee nee ",
            "LEFT JOIN ecw_customer_contacts cc on cc.id = nee.customer_contacts_id",
            "where nee.deleted = 0 and cc.deleted = 0 and nee.order_id = #{orderId}",
            "</script>"
    })
    Long getOrderConsigneeMemberInfo(@Param("orderId") Long orderId);

//    @ResultType(StatisticsOrderVO.class)
//    @Select({
//            "<script>",
//            "select ",
//            "SUM(IFNULL(IF(it.warehouse_in_info is null, 0, it.warehouse_in_info->>'$.cartonsNum'), 0)) as total_num, ",
//            "SUM(IFNULL(IF(it.warehouse_in_info is null, 0, it.warehouse_in_info->>'$.volume'), 0)) as total_volume, ",
//            "SUM(IFNULL(IF(it.warehouse_in_info is null, 0, it.warehouse_in_info->>'$.weight'), 0)) as total_weight, ",
//            "SUM(IFNULL(IF(it.warehouse_in_info is null, 0, it.warehouse_in_info->>'$.quantityAll'), 0)) as order_quantity, ",
//            "SUM(IFNULL(it.w_volume,0)) as total_w_volume, ",
//            "SUM(IFNULL(it.v_weight,0)) as total_v_weight, ",
//            "SUM(IFNULL(IF(it.warehouse_in_info is null, 0, IF(it.charge_weight > it.min_metering_weight ,it.charge_weight,it.min_metering_weight)), 0)) as total_charge_weight, ",
//            "SUM(IFNULL(IF(it.warehouse_in_info is null, 0, IF(it.charge_volume > it.min_metering_volume,it.charge_volume,it.min_metering_volume)), 0)) as total_charge_volume,",
//            "SUM(IFNULL(IF(it.warehouse_in_info is null, 0, IF(it.charge_quantity > it.min_metering_quantity,it.charge_quantity,it.min_metering_quantity)), 0)) as total_charge_quantity",
//            "from ecw_order_item it ",
//            "left join ecw_order o ",
//            "ON it.order_id = o.order_id and it.deleted = 0",
//            "left join ecw_order_departure de on de.order_id = o.order_id ",
//            "left join ecw_order_objective ob on ob.order_id = o.order_id ",
//            "left join ecw_order_consignor nor on nor.order_id = o.order_id ",
//            "left join ecw_order_consignee nee on nee.order_id = o.order_id ",
//            "left join ecw_channel channel on channel.channel_id = o.channel_id  ",
//            "where o.deleted = 0 and o.in_warehouse_state != 211 and o.in_warehouse_state != 208 and o.status != 10 ",
//            "<when test = 'query.deptId != null '>",
//            "AND o.dept_id = #{query.deptId} ",
//            "</when>",
//            "<when test= 'query.deptIdList != null and query.deptIdList.size() > 0'>",
//            "AND (o.dept_id IN",
//            "<foreach item='deptId' collection='query.deptIdList' open='(' close=')' separator=','> #{deptId} </foreach>",
//            " or ",
//            "(SELECT u.dept_id FROM system_user u WHERE u.id = o.creator) IN",
//            "<foreach item='deptId' collection='query.deptIdList' open='(' close=')' separator=','> #{deptId} </foreach>)",
//            "</when>",
//            "<when test = 'query.pdaStartWareIds != null and query.pdaStartWareIds != \"\" '>",
//            "AND FIND_IN_SET(ew_start.`id`, #{query.pdaStartWareIds})",
//            "</when>",
//            "<when test = 'query.pdaDestWareIds != null and query.pdaDestWareIds != \"\" '>",
//            "AND FIND_IN_SET(ew_dest.`id`, #{query.pdaDestWareIds})",
//            "</when>",
//            "<when test = 'query.packageType != null and query.packageType != \"\" '>",
//            "AND CONCAT(',',o.package_type,',') REGEXP CONCAT(',',REPLACE(#{query.packageType},',',',|,'), ',')",
//            "</when>",
//            "<when test = 'query.isExternalWarehouse != null'>",
//            "AND o.`is_external_warehouse` = #{query.isExternalWarehouse}",
//            "</when>",
//            "<when test = 'query.status != null'>",
//            "AND o.`status` = #{query.status}",
//            "</when>",
//            "<when test = 'query.abnormalState != null'>",
//            "<choose>",
//            "<when test = 'query.abnormalState != 0'>",
//            "<choose>",
//            "<when test = '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>",
//            "</when>",
//            "<when test = 'query.inWarehouseState != null'>",
//            "AND o.`in_warehouse_state` = #{query.inWarehouseState}",
//            "</when>",
//            "<when test = 'query.shipmentState != null'>",
//            "AND o.`shipment_State` = #{query.shipmentState}",
//            "</when>",
//            "<when test = 'query.auditType != null'>",
//            "<choose>",
//            "<when test = 'query.auditType != 0'>",
//            "<choose>",
//            "<when test = '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>",
//            "</when>",
//            "<when test = '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} ))",
//            "</when>",
//            "<when test = 'query.customsType != null'>",
//            "AND o.`customs_type` = #{query.customsType}",
//            "</when>",
//            "<when test = 'query.productRecord != null'>",
//            "AND o.`product_record` = #{query.productRecord}",
//            "</when>",
//            "<when test = 'query.transportId != null'>",
//            "AND o.`transport_id` = #{query.transportId}",
//            "</when>",
//            "<when test = 'query.channelId != null'>",
//            "AND o.`channel_id` = #{query.channelId}",
//            "</when>",
//            "<when test = 'query.warehouseType != null'>",
//            "AND o.`warehouse_type` = #{query.warehouseType}",
//            "</when>",
//            "<when test = '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},'%'))))))",
//            "</when>",
//            "<when test = '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},'%')))))",
//            "</when>",
//            "<when test = 'query.marks != null and query.marks != \"\" '>",
//            "AND o.`marks` like concat('%',concat(#{query.marks},'%'))",
//            "</when>",
//            "<when test = 'query.departureId != null '>",
//            "AND de.`departure_id` = #{query.departureId}",
//            "</when>",
//            "<when test = 'query.objectiveId != null '>",
//            "AND ob.`objective_id` = #{query.objectiveId}",
//            "</when>",
//            "<when test = 'query.consignorId != null '>",
//            "AND nor.`customer_id` = #{query.consignorId} ",
//            "</when>",
//            "<when test = 'query.consignorPhone != null and query.consignorPhone != \"\"  '>",
//            "AND nor.`phone` = #{query.consignorPhone} ",
//            "</when>",
//            "<when test = 'query.consigneeId != null '>",
//            "AND nee.`customer_id` = #{query.consigneeId}",
//            "</when>",
//            "<when test = 'query.consigneePhone != null and query.consigneePhone != \"\"  '>",
//            "AND nee.`phone` = #{query.consigneePhone} ",
//            "</when>",
//            "<when test = 'query.isCargoControl != null '>",
//            "AND o.`is_cargo_control` = #{query.isCargoControl}",
//            "</when>",
//            "<when test = 'query.orderNo != null and query.orderNo != \"\" '>",
//            "AND o.`order_no` like concat('%',concat(#{query.orderNo},'%'))",
//            "</when>",
//            "<when test = 'query.orderIdList != null and query.orderIdList.size() != 0'>",
//            "AND o.`order_id` in ",
//            "<foreach item='orderId' index='index' collection='query.orderIdList' open='(' separator=',' close=')'>#{orderId}</foreach> ",
//            "</when>",
//            "<when test = 'query.tidanNo != null and query.tidanNo != \"\" '>",
//            "AND o.`tidan_no` like concat('%',concat(#{query.tidanNo},'%'))",
//            "</when>",
//            "<when test = 'query.customerId != null'>",
//            "AND o.`customer_id` = #{query.customerId}",
//            "</when>",
//            "<when test = 'query.beginRucangTime != null and query.endRucangTime != null '>",
////            "AND o.`rucang_time` between #{query.beginRucangTime} and #{query.endRucangTime}",
//            "AND o.order_id in(select distinct wi.order_id from ecw_order_warehouse_in wi where wi.deleted = 0 and wi.`in_time` between #{query.beginRucangTime} and #{query.endRucangTime})",
//            "</when>",
//            "<when test = 'query.beginQingguanTime != null and query.endQingguanTime != null '>",
//            "AND o.`qingguan_time` between #{query.beginQingguanTime} and #{query.endQingguanTime}",
//            "</when>",
//            "<when test = 'query.beginDaogangTime != null and query.endDaogangTime != null '>",
//            "AND o.`daogang_time` between #{query.beginDaogangTime} and #{query.endDaogangTime}",
//            "</when>",
//            "<when test = 'query.beginPreLoadTime != null and query.endPreLoadTime != null '>",
//            "AND o.`status` > 5 AND o.`pre_load_time` between #{query.beginPreLoadTime} and #{query.endPreLoadTime}",
//            "</when>",
//            "<when test = 'query.beginOutboundTime != null and query.endOutboundTime != null '>",
//            "AND o.`status` > 5 AND o.container_number in(select distinct b.self_no from ecw_box_air_checkout bc join ecw_box b ON bc.shipment_id = b.id",
//            "where b.deleted = 0 and bc.deleted = 0 and bc.`checkout_time` between #{query.beginOutboundTime} and #{query.endOutboundTime})",
//            "</when>",
//            "<when test = 'query.beginLoadTime != null and query.endLoadTime != null '>",
//            "AND o.`load_time` between #{query.beginLoadTime} and #{query.endLoadTime}",
//            "</when>",
//            "<when test = 'query.beginUnloadTime != null and query.endUnloadTime != null '>",
//            "AND o.`unload_time` between #{query.beginUnloadTime} and #{query.endUnloadTime}",
//            "</when>",
//            "<when test = 'query.beginTakeTime != null and query.endTakeTime != null '>",
//            "AND o.`status` > 19 AND o.`take_time` between #{query.beginTakeTime} and #{query.endTakeTime}",
//            "</when>",
//            "<when test = 'query.beginSplitTime != null and query.endSplitTime != null '>",
//            "AND o.`split_time` between #{query.beginSplitTime} and #{query.endSplitTime}",
//            "</when>",
//            "<when test = 'query.beginCreateTime != null and query.endCreateTime != null '>",
//            "AND o.`create_time` between #{query.beginCreateTime} and #{query.endCreateTime}",
//            "</when>",
//            "<when test = 'query.beginPickTime != null and query.endPickTime != null '>",
//            "AND o.order_id in(select distinct op.order_id from ecw_order_cargo_control_pick op where op.deleted = 0 and op.status in(1,3) and op.`create_time` between #{query.beginPickTime} and #{query.endPickTime})",
//            "</when>",
//            "<when test = 'query.beginPickUpTime != null and query.endPickUpTime != null '>",
//            "AND o.order_no in(select distinct op.order_id from ecw_order_pickup op where op.deleted = 0 and op.`create_time` between #{query.beginPickUpTime} and #{query.endPickUpTime})",
//            "</when>",
//            "<when test = 'query.beginWarehouseInTime != null and query.endWarehouseInTime != null '>",
//            "AND o.order_id in(select distinct wi.order_id from ecw_order_warehouse_in wi where wi.deleted = 0 and wi.`update_time` between #{query.beginWarehouseInTime} and #{query.endWarehouseInTime})",
//            "</when>",
//            "<when test = 'query.creator != null and query.creator != \"\" '>",
//            "AND o.`creator` = #{query.creator} and (o.user_id is null or o.user_id = 0)",
//            "</when>",
//            "<when test = 'query.searchKey != null and query.searchKey != \"\" '>",
//            "AND concat(IFNULL(o.`order_no`,''), IFNULL(o.`old_numbers`,'') ,IFNULL(o.`marks`,''),IFNULL(o.`tidan_no`,''),IFNULL(o.`container_number`,''),IFNULL(nee.`name`,''),IFNULL(nee.`phone`,'')) like concat('%',concat(#{query.searchKey},'%'))",
//            "</when>",
//            "<when test = '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},'%'))))",
//            "</when>",
//            "<when test = 'query.notConsignorKey != null and query.notConsignorKey != \"\" '>",
//            "AND (concat(IFNULL(nor.`name`,''),IFNULL(nor.`name_en`,''),IFNULL(nor.`phone`,'')) not like concat('%',concat(#{query.notConsignorKey},'%'))",
//            "AND nor.customer_id not in (select c.id from ecw_customer c where c.number like concat('%',concat(#{query.notConsignorKey},'%'))))",
//            "</when>",
//            "<when test = '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},'%'))))",
//            "</when>",
//            "<when test = 'query.notConsigneeKey != null and query.notConsigneeKey != \"\" '>",
//            "AND (concat(IFNULL(nee.`name`,''),IFNULL(nee.`name_en`,''),IFNULL(nee.`phone`,'')) not like concat('%',concat(#{query.notConsigneeKey},'%'))",
//            "AND nee.customer_id not in (select c.id from ecw_customer c where c.number like concat('%',concat(#{query.notConsigneeKey},'%'))))",
//            "</when>",
//            "<when test = 'query.numberKey != null and query.numberKey != \"\" '>",
//            "AND concat(IFNULL(o.`order_no`,''), IFNULL(o.`old_numbers`,''), IFNULL(o.`parent_number`,''), IFNULL(o.`initial_parent_order_no`,'') ,IFNULL(o.`marks`,''),IFNULL(o.`tidan_no`,''),IFNULL(o.`container_number`,''),IFNULL(o.`no_charge_record`,'')) like concat('%',concat(#{query.numberKey},'%'))",
//            "</when>",
//            "<when test = 'query.notNumberKey != null and query.notNumberKey != \"\" '>",
//            "AND concat(IFNULL(o.`order_no`,''), IFNULL(o.`old_numbers`,''), IFNULL(o.`parent_number`,''), IFNULL(o.`initial_parent_order_no`,'') ,IFNULL(o.`marks`,''),IFNULL(o.`tidan_no`,''),IFNULL(o.`container_number`,''),IFNULL(o.`no_charge_record`,'')) not like concat('%',concat(#{query.notNumberKey},'%'))",
//            "</when>",
//            "<when test = 'query.eqNumberKey != null and query.eqNumberKey != \"\" '>",
//            "AND (o.`order_no` = #{query.eqNumberKey}",
//            "or (o.`old_numbers` is not null and o.`old_numbers` != '' and o.`old_numbers` = #{query.eqNumberKey}) ",
//            "or (o.`parent_number` is not null and o.`parent_number` != '' and o.`parent_number` = #{query.eqNumberKey}) ",
//            "or (o.`marks` is not null and o.`marks` != '' and o.`marks` = #{query.eqNumberKey}) ",
//            "or (o.`tidan_no` is not null and o.`tidan_no` != '' and o.`tidan_no` = #{query.eqNumberKey}) ",
//            "or (o.`container_number` is not null and o.`container_number` != '' and o.`container_number` = #{query.eqNumberKey}) ",
//            "or (o.`no_charge_record` is not null and o.`no_charge_record` != '' and o.`no_charge_record` = #{query.eqNumberKey})",
//            "or (o.`initial_parent_order_no` is not null and o.`initial_parent_order_no` != '' and o.`initial_parent_order_no` = #{query.eqNumberKey}))",
//            "</when>",
//            "<when test = 'query.notEqNumberKey != null and query.notEqNumberKey != \"\" '>",
//            "AND o.`order_no` != #{query.notEqNumberKey}",
//            "AND (o.`old_numbers` is null or o.`old_numbers` = '' or o.`old_numbers` != #{query.notEqNumberKey})",
//            "AND (o.`parent_number` is null or o.`parent_number` = '' or o.`parent_number` != #{query.notEqNumberKey})",
//            "AND (o.`marks` is null or o.`marks` = '' or o.`marks` != #{query.notEqNumberKey})",
//            "AND (o.`tidan_no` is null or o.`tidan_no` = '' or o.`tidan_no` != #{query.notEqNumberKey})",
//            "AND (o.`container_number` is null or o.`container_number` = '' or o.`container_number` != #{query.notEqNumberKey})",
//            "AND (o.`no_charge_record` is null or o.`no_charge_record` = '' or o.`no_charge_record` != #{query.notEqNumberKey})",
//            "AND (o.`initial_parent_order_no` is null or o.`initial_parent_order_no` = '' or o.`initial_parent_order_no` != #{query.notEqNumberKey})",
//            "</when>",
//            "<when test = 'query.prodKey != null and query.prodKey != \"\" '>",
//            "and (o.order_id in(",
//            "select oi.order_id ",
//            "from ecw_order_item oi ",
//            "left join ecw_product p ",
//            "on oi.prod_id = p.id ",
//            "left join ecw_product_type pt ",
//            "on pt.id = oi.prod_type ",
//            "left join ecw_product_brank pb",
//            "on pb.id = oi.brand",
//            "where oi.deleted = 0 ",
//            "and concat(IFNULL(oi.`prod_title_zh`,''),IFNULL(oi.`prod_title_en`,''),IFNULL(pt.`title_zh`,''),IFNULL(pt.`title_en`,''),IFNULL(pb.`title_zh`,''),IFNULL(pb.`title_en`,''))",
//            "like concat('%',concat(#{query.prodKey},'%'))",
//            "))",
//            "</when>",
//            "<when test = 'query.notProdKey != null and query.notProdKey != \"\" '>",
//            "and (o.order_id not in(",
//            "select oi.order_id ",
//            "from ecw_order_item oi ",
//            "left join ecw_product p ",
//            "on oi.prod_id = p.id ",
//            "left join ecw_product_type pt ",
//            "on pt.id = oi.prod_type ",
//            "left join ecw_product_brank pb",
//            "on pb.id = oi.brand",
//            "where oi.deleted = 0 and concat(IFNULL(oi.`prod_title_zh`,''),IFNULL(oi.`prod_title_en`,''),IFNULL(pt.`title_zh`,''),IFNULL(pt.`title_en`,''),IFNULL(pb.`title_zh`,''),IFNULL(pb.`title_en`,'')) " ,
//            "like concat('%',concat(#{query.notProdKey},'%'))",
//            "))",
//            "</when>",
//            "<when test = 'query.eqProdKey != null and query.eqProdKey != \"\" '>",
//            "and (o.order_id in(",
//            "select oi.order_id ",
//            "from ecw_order_item oi ",
//            "left join ecw_product p ",
//            "on oi.prod_id = p.id ",
//            "left join ecw_product_type pt ",
//            "on pt.id = oi.prod_type ",
//            "left join ecw_product_brank pb",
//            "on pb.id = oi.brand",
//            "where oi.deleted = 0 " ,
//            "and (oi.`prod_title_zh` = #{query.eqProdKey} or oi.`prod_title_en` = #{query.eqProdKey} " ,
//            "or pt.`title_zh` = #{query.eqProdKey} or pt.`title_en` = #{query.eqProdKey}",
//            "or pb.`title_zh` = #{query.eqProdKey} or pb.`title_en` = #{query.eqProdKey})",
//            "))",
//            "</when>",
//            "<when test = 'query.notEqProdKey != null and query.notEqProdKey != \"\" '>",
//            "and (o.order_id not in(",
//            "select oi.order_id ",
//            "from ecw_order_item oi ",
//            "left join ecw_product p ",
//            "on oi.prod_id = p.id ",
//            "left join ecw_product_type pt ",
//            "on pt.id = oi.prod_type ",
//            "left join ecw_product_brank pb",
//            "on pb.id = oi.brand",
//            "where oi.deleted = 0" ,
//            "and (oi.`prod_title_zh` = #{query.notEqProdKey} or oi.`prod_title_en` = #{query.notEqProdKey} " ,
//            "or pt.`title_zh` = #{query.notEqProdKey} or pt.`title_en` = #{query.notEqProdKey}",
//            "or pb.`title_zh` = #{query.notEqProdKey} or pb.`title_en` = #{query.notEqProdKey})",
//            "))",
//            "</when>",
//            "<when test = 'query.startWarehouseId != null and query.destWarehouseId != null '>",
//            "and (o.line_id in(",
//            "select whl.id ",
//            "from ecw_warehouse_line whl ",
//            "where whl.start_warehouse_id = #{query.startWarehouseId} and whl.dest_warehouse_id = #{query.destWarehouseId} ",
//            "))",
//            "</when>",
//            "<when test = 'query.startWarehouseId != null and query.destWarehouseId == null '>",
//            "and (o.line_id in(",
//            "select whl.id ",
//            "from ecw_warehouse_line whl ",
//            "where whl.start_warehouse_id = #{query.startWarehouseId}  ",
//            "))",
//            "</when>",
//            "<when test = 'query.startWarehouseId == null and query.destWarehouseId != null '>",
//            "and (o.line_id in(",
//            "select whl.id ",
//            "from ecw_warehouse_line whl ",
//            "where whl.dest_warehouse_id = #{query.destWarehouseId} ",
//            "))",
//            "</when>",
//            "<when test = 'query.airShipment != null and query.airShipment == 1'>",
//            "AND o.`status` = 5 AND o.air_shipment = 1 and abnormal_state = 0 and audit_type = 0 ",
//            "</when>",
//            "<when test = 'query.airShipment != null and query.airShipment == 2'>",
//            "AND o.`status` = 5  AND o.air_shipment = 2",
//            "</when>",
//            "<when test = 'query.airShipment != null and query.airShipment == 3'>",
//            "AND o.`status` = 5  AND o.air_shipment = 3",
//            "</when>",
//            "<when test = 'query.airShipment != null and query.airShipment == 4'>",
//            "AND o.`status` = 5  AND o.air_shipment = 4",
//            "</when>",
//            "<when test = 'query.airShipment != null and query.airShipment == 10'>",
//            "AND o.`status` = 5 AND o.air_shipment in(2,3,4)",
//            "</when>",
//            "<when test = 'query.airShipment != null and query.airShipment == 11'>",
//            "AND o.`status` = 5  AND o.air_shipment in(1,2,3,4) and abnormal_state = 0 and audit_type = 0 ",
//            "</when>",
//            "<when test = 'query.airShipment != null and query.airShipment == 12'>",
//            "AND o.`status` = 5  AND o.air_shipment in(2,3) and abnormal_state = 0 and audit_type = 0 ",
//            "</when>",
//            "<when test = 'query.airShipment != null and query.airShipment == 20'>",
//            "AND o.`status` = 5  AND o.air_shipment in(0,2,3,4) and abnormal_state = 0 and audit_type = 0 ",
//            "</when>",
//            "<when test = 'query.isNeat == false  '>",
//            " AND o.sum_num  <![CDATA[ < ]]> o.cost->>'$.totalNum' ",
//            "</when>",
//            "<when test = 'query.isNeat == true  '>",
//            " AND o.sum_num  = o.cost->>'$.totalNum' ",
//            "</when>",
//            "<when test = 'query.type != null and query.type != \"\" and query.type == 0 '>",
//            "AND (o.type is null or o.type = '' or o.type = '0')",
//            "</when>",
//            "<when test = 'query.type == 1 '>",
//            "AND FIND_IN_SET(1, o.type)",
//            "</when>",
//            "<when test = 'query.type == 2 '>",
//            "AND FIND_IN_SET(2, o.type)",
//            "</when>",
//            "<when test = 'query.customerDetailId != null'>",
//            "AND (o.`customer_id` = #{query.customerDetailId} or nor.`customer_id` = #{query.customerDetailId}  or nee.`customer_id` = #{query.customerDetailId})",
//            "</when>",
//            "<when test = 'query.userType == 2 '>",
//            "</when>",
//            "</script>"
//    })
    StatisticsOrderVO statisticsOrder(@Param("query") OrderQueryVO query);
//    @ResultType(StatisticsOrderVO.class)
//    @Select({
//            "<script>",
//            "select ",
//            "SUM(IFNULL(IF(it.warehouse_in_info is null, 0, it.warehouse_in_info->>'$.cartonsNum'), 0)) as total_num, ",
//            "SUM(IFNULL(IF(it.warehouse_in_info is null, 0, it.warehouse_in_info->>'$.volume'), 0)) as total_volume, ",
//            "SUM(IFNULL(IF(it.warehouse_in_info is null, 0, it.warehouse_in_info->>'$.weight'), 0)) as total_weight, ",
//            "SUM(IFNULL(IF(it.warehouse_in_info is null, 0, it.warehouse_in_info->>'$.quantityAll'), 0)) as order_quantity, ",
//            "SUM(IFNULL(it.w_volume,0)) as total_w_volume, ",
//            "SUM(IFNULL(it.v_weight,0)) as total_v_weight, ",
//            "SUM(IFNULL(IF(it.warehouse_in_info is null, 0, IF(it.charge_weight > it.min_metering_weight ,it.charge_weight,it.min_metering_weight)), 0)) as total_charge_weight, ",
//            "SUM(IFNULL(IF(it.warehouse_in_info is null, 0, IF(it.charge_volume > it.min_metering_volume,it.charge_volume,it.min_metering_volume)), 0)) as total_charge_volume,",
//            "SUM(IFNULL(IF(it.warehouse_in_info is null, 0, IF(it.charge_quantity > it.min_metering_quantity,it.charge_quantity,it.min_metering_quantity)), 0)) as total_charge_quantity",
//            "from ecw_order_item it ",
//            "left join ecw_order o ",
//            "ON it.order_id = o.order_id and it.deleted = 0",
//            "left join ecw_order_departure de on de.order_id = o.order_id ",
//            "left join ecw_order_objective ob on ob.order_id = o.order_id ",
//            "left join ecw_order_consignor nor on nor.order_id = o.order_id ",
//            "left join ecw_order_consignee nee on nee.order_id = o.order_id ",
//            "left join ecw_channel channel on channel.channel_id = o.channel_id  ",
//            "where o.deleted = 0 and o.in_warehouse_state != 211 and o.in_warehouse_state != 208 and o.status != 10 ",
//            "<when test = 'query.deptId != null '>",
//            "AND o.dept_id = #{query.deptId} ",
//            "</when>",
//            "<when test= 'query.deptIdList != null and query.deptIdList.size() > 0'>",
//            "AND (o.dept_id IN",
//            "<foreach item='deptId' collection='query.deptIdList' open='(' close=')' separator=','> #{deptId} </foreach>",
//            " or ",
//            "(SELECT u.dept_id FROM system_user u WHERE u.id = o.creator) IN",
//            "<foreach item='deptId' collection='query.deptIdList' open='(' close=')' separator=','> #{deptId} </foreach>)",
//            "</when>",
//            "<when test = 'query.pdaStartWareIds != null and query.pdaStartWareIds != \"\" '>",
//            "AND FIND_IN_SET(ew_start.`id`, #{query.pdaStartWareIds})",
//            "</when>",
//            "<when test = 'query.pdaDestWareIds != null and query.pdaDestWareIds != \"\" '>",
//            "AND FIND_IN_SET(ew_dest.`id`, #{query.pdaDestWareIds})",
//            "</when>",
//            "<when test = 'query.packageType != null and query.packageType != \"\" '>",
//            "AND CONCAT(',',o.package_type,',') REGEXP CONCAT(',',REPLACE(#{query.packageType},',',',|,'), ',')",
//            "</when>",
//            "<when test = 'query.isExternalWarehouse != null'>",
//            "AND o.`is_external_warehouse` = #{query.isExternalWarehouse}",
//            "</when>",
//            "<when test = 'query.status != null'>",
//            "AND o.`status` = #{query.status}",
//            "</when>",
//            "<when test = 'query.abnormalState != null'>",
//            "<choose>",
//            "<when test = 'query.abnormalState != 0'>",
//            "<choose>",
//            "<when test = '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>",
//            "</when>",
//            "<when test = 'query.inWarehouseState != null'>",
//            "AND o.`in_warehouse_state` = #{query.inWarehouseState}",
//            "</when>",
//            "<when test = 'query.shipmentState != null'>",
//            "AND o.`shipment_State` = #{query.shipmentState}",
//            "</when>",
//            "<when test = 'query.auditType != null'>",
//            "<choose>",
//            "<when test = 'query.auditType != 0'>",
//            "<choose>",
//            "<when test = '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>",
//            "</when>",
//            "<when test = '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} ))",
//            "</when>",
//            "<when test = 'query.customsType != null'>",
//            "AND o.`customs_type` = #{query.customsType}",
//            "</when>",
//            "<when test = 'query.productRecord != null'>",
//            "AND o.`product_record` = #{query.productRecord}",
//            "</when>",
//            "<when test = 'query.transportId != null'>",
//            "AND o.`transport_id` = #{query.transportId}",
//            "</when>",
//            "<when test = 'query.channelId != null'>",
//            "AND o.`channel_id` = #{query.channelId}",
//            "</when>",
//            "<when test = 'query.warehouseType != null'>",
//            "AND o.`warehouse_type` = #{query.warehouseType}",
//            "</when>",
//            "<when test = '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},'%'))))))",
//            "</when>",
//            "<when test = '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},'%')))))",
//            "</when>",
//            "<when test = 'query.marks != null and query.marks != \"\" '>",
//            "AND o.`marks` like concat('%',concat(#{query.marks},'%'))",
//            "</when>",
//            "<when test = 'query.departureId != null '>",
//            "AND de.`departure_id` = #{query.departureId}",
//            "</when>",
//            "<when test = 'query.objectiveId != null '>",
//            "AND ob.`objective_id` = #{query.objectiveId}",
//            "</when>",
//            "<when test = 'query.consignorId != null '>",
//            "AND nor.`customer_id` = #{query.consignorId} ",
//            "</when>",
//            "<when test = 'query.consignorPhone != null and query.consignorPhone != \"\"  '>",
//            "AND nor.`phone` = #{query.consignorPhone} ",
//            "</when>",
//            "<when test = 'query.consigneeId != null '>",
//            "AND nee.`customer_id` = #{query.consigneeId}",
//            "</when>",
//            "<when test = 'query.consigneePhone != null and query.consigneePhone != \"\"  '>",
//            "AND nee.`phone` = #{query.consigneePhone} ",
//            "</when>",
//            "<when test = 'query.isCargoControl != null '>",
//            "AND o.`is_cargo_control` = #{query.isCargoControl}",
//            "</when>",
//            "<when test = 'query.orderNo != null and query.orderNo != \"\" '>",
//            "AND o.`order_no` like concat('%',concat(#{query.orderNo},'%'))",
//            "</when>",
//            "<when test = 'query.orderIdList != null and query.orderIdList.size() != 0'>",
//            "AND o.`order_id` in ",
//            "<foreach item='orderId' index='index' collection='query.orderIdList' open='(' separator=',' close=')'>#{orderId}</foreach> ",
//            "</when>",
//            "<when test = 'query.tidanNo != null and query.tidanNo != \"\" '>",
//            "AND o.`tidan_no` like concat('%',concat(#{query.tidanNo},'%'))",
//            "</when>",
//            "<when test = 'query.customerId != null'>",
//            "AND o.`customer_id` = #{query.customerId}",
//            "</when>",
//            "<when test = 'query.beginRucangTime != null and query.endRucangTime != null '>",
//            "AND o.order_id in(select distinct wi.order_id from ecw_order_warehouse_in wi where wi.deleted = 0 and wi.`in_time` between #{query.beginRucangTime} and #{query.endRucangTime})",
//            "</when>",
//            "<when test = 'query.beginQingguanTime != null and query.endQingguanTime != null '>",
//            "AND o.`qingguan_time` between #{query.beginQingguanTime} and #{query.endQingguanTime}",
//            "</when>",
//            "<when test = 'query.beginDaogangTime != null and query.endDaogangTime != null '>",
//            "AND o.`daogang_time` between #{query.beginDaogangTime} and #{query.endDaogangTime}",
//            "</when>",
//            "<when test = 'query.beginPreLoadTime != null and query.endPreLoadTime != null '>",
//            "AND o.`status` > 5 AND o.`pre_load_time` between #{query.beginPreLoadTime} and #{query.endPreLoadTime}",
//            "</when>",
//            "<when test = 'query.beginOutboundTime != null and query.endOutboundTime != null '>",
//            "AND o.`status` > 5 AND o.container_number in(select distinct b.self_no from ecw_box_air_checkout bc join ecw_box b ON bc.shipment_id = b.id",
//            "where b.deleted = 0 and bc.deleted = 0 and bc.`checkout_time` between #{query.beginOutboundTime} and #{query.endOutboundTime})",
//            "</when>",
//            "<when test = 'query.beginLoadTime != null and query.endLoadTime != null '>",
//            "AND o.`load_time` between #{query.beginLoadTime} and #{query.endLoadTime}",
//            "</when>",
//            "<when test = 'query.beginUnloadTime != null and query.endUnloadTime != null '>",
//            "AND o.`unload_time` between #{query.beginUnloadTime} and #{query.endUnloadTime}",
//            "</when>",
//            "<when test = 'query.beginTakeTime != null and query.endTakeTime != null '>",
//            "AND o.`status` > 19 AND o.`take_time` between #{query.beginTakeTime} and #{query.endTakeTime}",
//            "</when>",
//            "<when test = 'query.beginSplitTime != null and query.endSplitTime != null '>",
//            "AND o.`split_time` between #{query.beginSplitTime} and #{query.endSplitTime}",
//            "</when>",
//            "<when test = 'query.beginCreateTime != null and query.endCreateTime != null '>",
//            "AND o.`create_time` between #{query.beginCreateTime} and #{query.endCreateTime}",
//            "</when>",
//            "<when test = 'query.beginPickTime != null and query.endPickTime != null '>",
//            "AND o.order_id in(select distinct op.order_id from ecw_order_cargo_control_pick op where op.deleted = 0 and op.status in(1,3) and op.`create_time` between #{query.beginPickTime} and #{query.endPickTime})",
//            "</when>",
//            "<when test = 'query.beginPickUpTime != null and query.endPickUpTime != null '>",
//            "AND o.order_no in(select distinct op.order_id from ecw_order_pickup op where op.deleted = 0 and op.`create_time` between #{query.beginPickUpTime} and #{query.endPickUpTime})",
//            "</when>",
//            "<when test = 'query.beginWarehouseInTime != null and query.endWarehouseInTime != null '>",
//            "AND o.order_id in(select distinct wi.order_id from ecw_order_warehouse_in wi where wi.deleted = 0 and wi.`update_time` between #{query.beginWarehouseInTime} and #{query.endWarehouseInTime})",
//            "</when>",
//            "<when test = 'query.creator != null and query.creator != \"\" '>",
//            "AND o.`creator` = #{query.creator} and (o.user_id is null or o.user_id = 0)",
//            "</when>",
//            "<when test = 'query.searchKey != null and query.searchKey != \"\" '>",
//            "AND concat(IFNULL(o.`order_no`,''), IFNULL(o.`old_numbers`,'') ,IFNULL(o.`marks`,''),IFNULL(o.`tidan_no`,''),IFNULL(o.`container_number`,''),IFNULL(nee.`name`,''),IFNULL(nee.`phone`,'')) like concat('%',concat(#{query.searchKey},'%'))",
//            "</when>",
//            "<when test = '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},'%'))))",
//            "</when>",
//            "<when test = 'query.notConsignorKey != null and query.notConsignorKey != \"\" '>",
//            "AND (concat(IFNULL(nor.`name`,''),IFNULL(nor.`name_en`,''),IFNULL(nor.`phone`,'')) not like concat('%',concat(#{query.notConsignorKey},'%'))",
//            "AND nor.customer_id not in (select c.id from ecw_customer c where c.number like concat('%',concat(#{query.notConsignorKey},'%'))))",
//            "</when>",
//            "<when test = '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},'%'))))",
//            "</when>",
//            "<when test = 'query.notConsigneeKey != null and query.notConsigneeKey != \"\" '>",
//            "AND (concat(IFNULL(nee.`name`,''),IFNULL(nee.`name_en`,''),IFNULL(nee.`phone`,'')) not like concat('%',concat(#{query.notConsigneeKey},'%'))",
//            "AND nee.customer_id not in (select c.id from ecw_customer c where c.number like concat('%',concat(#{query.notConsigneeKey},'%'))))",
//            "</when>",
//            "<when test = 'query.numberKey != null and query.numberKey != \"\" '>",
//            "AND concat(IFNULL(o.`order_no`,''), IFNULL(o.`old_numbers`,''), IFNULL(o.`parent_number`,''), IFNULL(o.`initial_parent_order_no`,'') ,IFNULL(o.`marks`,''),IFNULL(o.`tidan_no`,''),IFNULL(o.`container_number`,''),IFNULL(o.`no_charge_record`,'')) like concat('%',concat(#{query.numberKey},'%'))",
//            "</when>",
//            "<when test = 'query.notNumberKey != null and query.notNumberKey != \"\" '>",
//            "AND concat(IFNULL(o.`order_no`,''), IFNULL(o.`old_numbers`,''), IFNULL(o.`parent_number`,''), IFNULL(o.`initial_parent_order_no`,'') ,IFNULL(o.`marks`,''),IFNULL(o.`tidan_no`,''),IFNULL(o.`container_number`,''),IFNULL(o.`no_charge_record`,'')) not like concat('%',concat(#{query.notNumberKey},'%'))",
//            "</when>",
//            "<when test = 'query.eqNumberKey != null and query.eqNumberKey != \"\" '>",
//            "AND (o.`order_no` = #{query.eqNumberKey}",
//            "or (o.`old_numbers` is not null and o.`old_numbers` != '' and o.`old_numbers` = #{query.eqNumberKey}) ",
//            "or (o.`parent_number` is not null and o.`parent_number` != '' and o.`parent_number` = #{query.eqNumberKey}) ",
//            "or (o.`marks` is not null and o.`marks` != '' and o.`marks` = #{query.eqNumberKey}) ",
//            "or (o.`tidan_no` is not null and o.`tidan_no` != '' and o.`tidan_no` = #{query.eqNumberKey}) ",
//            "or (o.`container_number` is not null and o.`container_number` != '' and o.`container_number` = #{query.eqNumberKey}) ",
//            "or (o.`no_charge_record` is not null and o.`no_charge_record` != '' and o.`no_charge_record` = #{query.eqNumberKey})",
//            "or (o.`initial_parent_order_no` is not null and o.`initial_parent_order_no` != '' and o.`initial_parent_order_no` = #{query.eqNumberKey}))",
//            "</when>",
//            "<when test = 'query.notEqNumberKey != null and query.notEqNumberKey != \"\" '>",
//            "AND o.`order_no` != #{query.notEqNumberKey}",
//            "AND (o.`old_numbers` is null or o.`old_numbers` = '' or o.`old_numbers` != #{query.notEqNumberKey})",
//            "AND (o.`parent_number` is null or o.`parent_number` = '' or o.`parent_number` != #{query.notEqNumberKey})",
//            "AND (o.`marks` is null or o.`marks` = '' or o.`marks` != #{query.notEqNumberKey})",
//            "AND (o.`tidan_no` is null or o.`tidan_no` = '' or o.`tidan_no` != #{query.notEqNumberKey})",
//            "AND (o.`container_number` is null or o.`container_number` = '' or o.`container_number` != #{query.notEqNumberKey})",
//            "AND (o.`no_charge_record` is null or o.`no_charge_record` = '' or o.`no_charge_record` != #{query.notEqNumberKey})",
//            "AND (o.`initial_parent_order_no` is null or o.`initial_parent_order_no` = '' or o.`initial_parent_order_no` != #{query.notEqNumberKey})",
//            "</when>",
//            "<when test = 'query.prodKey != null and query.prodKey != \"\" '>",
//            "and (o.order_id in(",
//            "select oi.order_id ",
//            "from ecw_order_item oi ",
//            "left join ecw_product p ",
//            "on oi.prod_id = p.id ",
//            "left join ecw_product_type pt ",
//            "on pt.id = oi.prod_type ",
//            "left join ecw_product_brank pb",
//            "on pb.id = oi.brand",
//            "where oi.deleted = 0 ",
//            "and concat(IFNULL(oi.`prod_title_zh`,''),IFNULL(oi.`prod_title_en`,''),IFNULL(pt.`title_zh`,''),IFNULL(pt.`title_en`,''),IFNULL(pb.`title_zh`,''),IFNULL(pb.`title_en`,''))",
//            "like concat('%',concat(#{query.prodKey},'%'))",
//            "))",
//            "</when>",
//            "<when test = 'query.notProdKey != null and query.notProdKey != \"\" '>",
//            "and (o.order_id not in(",
//            "select oi.order_id ",
//            "from ecw_order_item oi ",
//            "left join ecw_product p ",
//            "on oi.prod_id = p.id ",
//            "left join ecw_product_type pt ",
//            "on pt.id = oi.prod_type ",
//            "left join ecw_product_brank pb",
//            "on pb.id = oi.brand",
//            "where oi.deleted = 0 and concat(IFNULL(oi.`prod_title_zh`,''),IFNULL(oi.`prod_title_en`,''),IFNULL(pt.`title_zh`,''),IFNULL(pt.`title_en`,''),IFNULL(pb.`title_zh`,''),IFNULL(pb.`title_en`,'')) " ,
//            "like concat('%',concat(#{query.notProdKey},'%'))",
//            "))",
//            "</when>",
//            "<when test = 'query.eqProdKey != null and query.eqProdKey != \"\" '>",
//            "and (o.order_id in(",
//            "select oi.order_id ",
//            "from ecw_order_item oi ",
//            "left join ecw_product p ",
//            "on oi.prod_id = p.id ",
//            "left join ecw_product_type pt ",
//            "on pt.id = oi.prod_type ",
//            "left join ecw_product_brank pb",
//            "on pb.id = oi.brand",
//            "where oi.deleted = 0 " ,
//            "and (oi.`prod_title_zh` = #{query.eqProdKey} or oi.`prod_title_en` = #{query.eqProdKey} " ,
//            "or pt.`title_zh` = #{query.eqProdKey} or pt.`title_en` = #{query.eqProdKey}",
//            "or pb.`title_zh` = #{query.eqProdKey} or pb.`title_en` = #{query.eqProdKey})",
//            "))",
//            "</when>",
//            "<when test = 'query.notEqProdKey != null and query.notEqProdKey != \"\" '>",
//            "and (o.order_id not in(",
//            "select oi.order_id ",
//            "from ecw_order_item oi ",
//            "left join ecw_product p ",
//            "on oi.prod_id = p.id ",
//            "left join ecw_product_type pt ",
//            "on pt.id = oi.prod_type ",
//            "left join ecw_product_brank pb",
//            "on pb.id = oi.brand",
//            "where oi.deleted = 0" ,
//            "and (oi.`prod_title_zh` = #{query.notEqProdKey} or oi.`prod_title_en` = #{query.notEqProdKey} " ,
//            "or pt.`title_zh` = #{query.notEqProdKey} or pt.`title_en` = #{query.notEqProdKey}",
//            "or pb.`title_zh` = #{query.notEqProdKey} or pb.`title_en` = #{query.notEqProdKey})",
//            "))",
//            "</when>",
//            "<when test = 'query.startWarehouseId != null and query.destWarehouseId != null '>",
//            "and (o.line_id in(",
//            "select whl.id ",
//            "from ecw_warehouse_line whl ",
//            "where whl.start_warehouse_id = #{query.startWarehouseId} and whl.dest_warehouse_id = #{query.destWarehouseId} ",
//            "))",
//            "</when>",
//            "<when test = 'query.startWarehouseId != null and query.destWarehouseId == null '>",
//            "and (o.line_id in(",
//            "select whl.id ",
//            "from ecw_warehouse_line whl ",
//            "where whl.start_warehouse_id = #{query.startWarehouseId}  ",
//            "))",
//            "</when>",
//            "<when test = 'query.startWarehouseId == null and query.destWarehouseId != null '>",
//            "and (o.line_id in(",
//            "select whl.id ",
//            "from ecw_warehouse_line whl ",
//            "where whl.dest_warehouse_id = #{query.destWarehouseId} ",
//            "))",
//            "</when>",
//            "<when test = 'query.airShipment != null and query.airShipment == 1'>",
//            "AND o.`status` = 5 AND o.air_shipment = 1 and abnormal_state = 0 and audit_type = 0 ",
//            "</when>",
//            "<when test = 'query.airShipment != null and query.airShipment == 2'>",
//            "AND o.`status` = 5  AND o.air_shipment = 2",
//            "</when>",
//            "<when test = 'query.airShipment != null and query.airShipment == 3'>",
//            "AND o.`status` = 5  AND o.air_shipment = 3",
//            "</when>",
//            "<when test = 'query.airShipment != null and query.airShipment == 4'>",
//            "AND o.`status` = 5  AND o.air_shipment = 4",
//            "</when>",
//            "<when test = 'query.airShipment != null and query.airShipment == 10'>",
//            "AND o.`status` = 5 AND o.air_shipment in(2,3,4)",
//            "</when>",
//            "<when test = 'query.airShipment != null and query.airShipment == 11'>",
//            "AND o.`status` = 5  AND o.air_shipment in(1,2,3,4) and abnormal_state = 0 and audit_type = 0 ",
//            "</when>",
//            "<when test = 'query.airShipment != null and query.airShipment == 12'>",
//            "AND o.`status` = 5  AND o.air_shipment in(2,3) and abnormal_state = 0 and audit_type = 0 ",
//            "</when>",
//            "<when test = 'query.airShipment != null and query.airShipment == 20'>",
//            "AND o.`status` = 5  AND o.air_shipment in(0,2,3,4) and abnormal_state = 0 and audit_type = 0 ",
//            "</when>",
//            "<when test = 'query.isNeat == false  '>",
//            " AND o.sum_num  <![CDATA[ < ]]> o.cost->>'$.totalNum' ",
//            "</when>",
//            "<when test = 'query.isNeat == true  '>",
//            " AND o.sum_num  = o.cost->>'$.totalNum' ",
//            "</when>",
//            "<when test = 'query.type != null and query.type != \"\" and query.type == 0 '>",
//            "AND (o.type is null or o.type = '' or o.type = '0')",
//            "</when>",
//
//            "<when test = 'query.type == 1 '>",
//            "AND FIND_IN_SET(1, o.type)",
//            "</when>",
//            "<when test = 'query.type == 2 '>",
//            "AND FIND_IN_SET(2, o.type)",
//            "</when>",
//            "<when test = 'query.customerDetailId != null'>",
//            "AND (o.`customer_id` = #{query.customerDetailId} or nor.`customer_id` = #{query.customerDetailId}  or nee.`customer_id` = #{query.customerDetailId})",
//            "</when>",
//            "<when test = 'query.userType == 2 '>",
//            "</when>",
//            "</script>"
//    })
    StatisticsOrderVO  statisticsMyOrder(@Param("query") OrderQueryVO query);


    /**
     * 获取异常单统计
     *
     * @param query
     * @return
     */
    List<OrderExceptionStatisticsExcelVo> getOrderExceptionStatisticsList(@Param("query") OrderQueryVO query);

    /**
     * 重货统计
     *
     * @param query
     * @return
     */
    List<OrderHeavyExcelVo> getHeavyOrderExcelList(@Param("query") OrderQueryVO query);

    /**
     * 退仓统计
     *
     * @param query
     * @return
     */
    List<OrderReturnOrderExcelVo> getReturnOrderExcelList(@Param("query") OrderQueryVO query);

    /**
     * 售后赔付
     *
     * @param query
     * @return
     */
    List<OrderSaleRepayExcelVo> getSaleRepayExcelList(@Param("query") OrderQueryVO query);

    /**
     * 报关数据
     *
     * @param query
     * @return
     */
    List<OrderCustomsDatasExcelVo> getCustomsDatasExcelList(@Param("query") OrderQueryVO query);

    /**
     * 出货量
     *
     * @param query
     * @return
     */
    List<OrderShipDataExcelVo> getShipDatasExcelList(@Param("query") OrderQueryVO query);

    /**
     * 预付运费
     *
     * @param query
     * @return
     */
    List<OrderShipFeeExcelVo> getShipFeeExcelList(@Param("query") OrderQueryVO query);

    @ResultType(OrderDO.class)
    @Select({
            "<script>",
            "SELECT",
            "o.*",
            "FROM",
            "ecw_order o ",
            "WHERE",
            "o.`status` = 20",
            "and o.`deleted` = 0",
            "and o.`commission_payable` = 0",
            "and o.order_id in(select distinct oi.order_id from ecw_order_item oi where oi.deleted = 0 and oi.`warehouse_in_info` is not null and oi.`warehouse_in_info`->>'$.cartonsNum' > 0 and oi.commission_type > 0)",
            "</script>"
    })
    List<OrderDO> commissionOrderList();

//    @ResultType(StatisticsOrderVO.class)
//    @Select({
//            "<script>",
//            "select ",
//            "SUM(IFNULL(wi.cartons_num, 0)) as total_num, ",
//            "SUM(IFNULL(wi.volume, 0)) as total_volume, ",
//            "SUM(IFNULL(wi.weight, 0)) as total_weight, ",
//            "SUM(IFNULL(wi.quantity_all, 0)) as order_quantity ",
//            "from ecw_order_warehouse_in wi ",
//            "left join ecw_order o ",
//            "ON wi.order_id = o.order_id ",
//            "left join ecw_order_departure de on de.order_id = o.order_id ",
//            "left join ecw_order_objective ob on ob.order_id = o.order_id ",
//            "left join ecw_order_consignor nor on nor.order_id = o.order_id ",
//            "left join ecw_order_consignee nee on nee.order_id = o.order_id ",
//            "left join ecw_channel channel on channel.channel_id = o.channel_id  ",
//            "where o.deleted = 0 and o.in_warehouse_state != 211 and o.in_warehouse_state != 208 and o.status != 10 and wi.deleted = 0",
//            "<when test = 'query.deptId != null '>",
//            "AND o.dept_id = #{query.deptId} ",
//            "</when>",
//            "<when test= 'query.deptIdList != null and query.deptIdList.size() > 0'>",
//            "AND (o.dept_id IN",
//            "<foreach item='deptId' collection='query.deptIdList' open='(' close=')' separator=','> #{deptId} </foreach>",
//            " or ",
//            "(SELECT u.dept_id FROM system_user u WHERE u.id = o.creator) IN",
//            "<foreach item='deptId' collection='query.deptIdList' open='(' close=')' separator=','> #{deptId} </foreach>)",
//            "</when>",
//            "<when test = 'query.pdaStartWareIds != null and query.pdaStartWareIds != \"\" '>",
//            "AND FIND_IN_SET(ew_start.`id`, #{query.pdaStartWareIds})",
//            "</when>",
//            "<when test = 'query.pdaDestWareIds != null and query.pdaDestWareIds != \"\" '>",
//            "AND FIND_IN_SET(ew_dest.`id`, #{query.pdaDestWareIds})",
//            "</when>",
//            "<when test = 'query.packageType != null and query.packageType != \"\" '>",
//            "AND CONCAT(',',o.package_type,',') REGEXP CONCAT(',',REPLACE(#{query.packageType},',',',|,'), ',')",
//            "</when>",
//            "<when test = 'query.isExternalWarehouse != null'>",
//            "AND o.`is_external_warehouse` = #{query.isExternalWarehouse}",
//            "</when>",
//            "<when test = 'query.status != null'>",
//            "AND o.`status` = #{query.status}",
//            "</when>",
//            "<when test = 'query.abnormalState != null'>",
//            "<choose>",
//            "<when test = 'query.abnormalState != 0'>",
//            "<choose>",
//            "<when test = '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>",
//            "</when>",
//            "<when test = 'query.inWarehouseState != null'>",
//            "AND o.`in_warehouse_state` = #{query.inWarehouseState}",
//            "</when>",
//            "<when test = 'query.shipmentState != null'>",
//            "AND o.`shipment_State` = #{query.shipmentState}",
//            "</when>",
//            "<when test = 'query.auditType != null'>",
//            "<choose>",
//            "<when test = 'query.auditType != 0'>",
//            "<choose>",
//            "<when test = '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>",
//            "</when>",
//            "<when test = '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} ))",
//            "</when>",
//            "<when test = 'query.customsType != null'>",
//            "AND o.`customs_type` = #{query.customsType}",
//            "</when>",
//            "<when test = 'query.productRecord != null'>",
//            "AND o.`product_record` = #{query.productRecord}",
//            "</when>",
//            "<when test = 'query.transportId != null'>",
//            "AND o.`transport_id` = #{query.transportId}",
//            "</when>",
//            "<when test = 'query.channelId != null'>",
//            "AND o.`channel_id` = #{query.channelId}",
//            "</when>",
//            "<when test = 'query.warehouseType != null'>",
//            "AND o.`warehouse_type` = #{query.warehouseType}",
//            "</when>",
//            "<when test = '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},'%'))))))",
//            "</when>",
//            "<when test = '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},'%')))))",
//            "</when>",
//            "<when test = 'query.marks != null and query.marks != \"\" '>",
//            "AND o.`marks` like concat('%',concat(#{query.marks},'%'))",
//            "</when>",
//            "<when test = 'query.departureId != null '>",
//            "AND de.`departure_id` = #{query.departureId}",
//            "</when>",
//            "<when test = 'query.type != null and query.type != \"\" and query.type == 0 '>",
//            "AND (o.type is null or o.type = '' or o.type = '0')",
//            "</when>",
//            "<when test = 'query.type == 1 '>",
//            "AND FIND_IN_SET(1, o.type)",
//            "</when>",
//            "<when test = 'query.type == 2 '>",
//            "AND FIND_IN_SET(2, o.type)",
//            "</when>",
//            "<when test = 'query.objectiveId != null '>",
//            "AND ob.`objective_id` = #{query.objectiveId}",
//            "</when>",
//            "<when test = 'query.consignorId != null '>",
//            "AND nor.`customer_id` = #{query.consignorId} ",
//            "</when>",
//            "<when test = 'query.consignorPhone != null and query.consignorPhone != \"\"  '>",
//            "AND nor.`phone` = #{query.consignorPhone} ",
//            "</when>",
//            "<when test = 'query.consigneeId != null '>",
//            "AND nee.`customer_id` = #{query.consigneeId}",
//            "</when>",
//            "<when test = 'query.consigneePhone != null and query.consigneePhone != \"\"  '>",
//            "AND nee.`phone` = #{query.consigneePhone} ",
//            "</when>",
//            "<when test = 'query.isCargoControl != null '>",
//            "AND o.`is_cargo_control` = #{query.isCargoControl}",
//            "</when>",
//            "<when test = 'query.orderNo != null and query.orderNo != \"\" '>",
//            "AND o.`order_no` like concat('%',concat(#{query.orderNo},'%'))",
//            "</when>",
//            "<when test = 'query.orderIdList != null and query.orderIdList.size() != 0'>",
//            "AND o.`order_id` in ",
//            "<foreach item='orderId' index='index' collection='query.orderIdList' open='(' separator=',' close=')'>#{orderId}</foreach> ",
//            "</when>",
//            "<when test = 'query.tidanNo != null and query.tidanNo != \"\" '>",
//            "AND o.`tidan_no` like concat('%',concat(#{query.tidanNo},'%'))",
//            "</when>",
//            "<when test = 'query.customerId != null'>",
//            "AND o.`customer_id` = #{query.customerId}",
//            "</when>",
//            "<when test = 'query.beginRucangTime != null and query.endRucangTime != null '>",
////            "AND o.`rucang_time` between #{query.beginRucangTime} and #{query.endRucangTime}",
//            "AND wi.`in_time` between #{query.beginRucangTime} and #{query.endRucangTime}",
//            "</when>",
//            "<when test = 'query.beginQingguanTime != null and query.endQingguanTime != null '>",
//            "AND o.`qingguan_time` between #{query.beginQingguanTime} and #{query.endQingguanTime}",
//            "</when>",
//            "<when test = 'query.beginDaogangTime != null and query.endDaogangTime != null '>",
//            "AND o.`daogang_time` between #{query.beginDaogangTime} and #{query.endDaogangTime}",
//            "</when>",
//            "<when test = 'query.beginPreLoadTime != null and query.endPreLoadTime != null '>",
//            "AND o.`status` > 5 AND o.`pre_load_time` between #{query.beginPreLoadTime} and #{query.endPreLoadTime}",
//            "</when>",
//            "<when test = 'query.beginOutboundTime != null and query.endOutboundTime != null '>",
//            "AND o.`status` > 5 AND o.container_number in(select distinct b.self_no from ecw_box_air_checkout bc join ecw_box b ON bc.shipment_id = b.id",
//            "where b.deleted = 0 and bc.deleted = 0 and bc.`checkout_time` between #{query.beginOutboundTime} and #{query.endOutboundTime})",
//            "</when>",
//            "<when test = 'query.beginLoadTime != null and query.endLoadTime != null '>",
//            "AND o.`load_time` between #{query.beginLoadTime} and #{query.endLoadTime}",
//            "</when>",
//            "<when test = 'query.beginUnloadTime != null and query.endUnloadTime != null '>",
//            "AND o.`unload_time` between #{query.beginUnloadTime} and #{query.endUnloadTime}",
//            "</when>",
//            "<when test = 'query.beginTakeTime != null and query.endTakeTime != null '>",
//            "AND o.`status` > 19 AND o.`take_time` between #{query.beginTakeTime} and #{query.endTakeTime}",
//            "</when>",
//            "<when test = 'query.beginSplitTime != null and query.endSplitTime != null '>",
//            "AND o.`split_time` between #{query.beginSplitTime} and #{query.endSplitTime}",
//            "</when>",
//            "<when test = 'query.beginCreateTime != null and query.endCreateTime != null '>",
//            "AND o.`create_time` between #{query.beginCreateTime} and #{query.endCreateTime}",
//            "</when>",
//            "<when test = 'query.beginPickTime != null and query.endPickTime != null '>",
//            "AND o.order_id in(select distinct op.order_id from ecw_order_cargo_control_pick op where op.deleted = 0 and op.status in(1,3) and op.`create_time` between #{query.beginPickTime} and #{query.endPickTime})",
//            "</when>",
//            "<when test = 'query.beginPickUpTime != null and query.endPickUpTime != null '>",
//            "AND o.order_no in(select distinct op.order_id from ecw_order_pickup op where op.deleted = 0 and op.`create_time` between #{query.beginPickUpTime} and #{query.endPickUpTime})",
//            "</when>",
//            "<when test = 'query.beginWarehouseInTime != null and query.endWarehouseInTime != null '>",
//            "AND wi.`update_time` between #{query.beginWarehouseInTime} and #{query.endWarehouseInTime}",
//            "</when>",
//            "<when test = 'query.creator != null and query.creator != \"\" '>",
//            "AND o.`creator` = #{query.creator}",
//            "</when>",
//            "<when test = 'query.searchKey != null and query.searchKey != \"\" '>",
//            "AND concat(IFNULL(o.`order_no`,''), IFNULL(o.`old_numbers`,'') ,IFNULL(o.`marks`,''),IFNULL(o.`tidan_no`,''),IFNULL(o.`container_number`,''),IFNULL(nee.`name`,''),IFNULL(nee.`phone`,'')) like concat('%',concat(#{query.searchKey},'%'))",
//            "</when>",
//            "<when test = '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},'%'))))",
//            "</when>",
//            "<when test = 'query.notConsignorKey != null and query.notConsignorKey != \"\" '>",
//            "AND (concat(IFNULL(nor.`name`,''),IFNULL(nor.`name_en`,''),IFNULL(nor.`phone`,'')) not like concat('%',concat(#{query.notConsignorKey},'%'))",
//            "AND nor.customer_id not in (select c.id from ecw_customer c where c.number like concat('%',concat(#{query.notConsignorKey},'%'))))",
//            "</when>",
//            "<when test = '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},'%'))))",
//            "</when>",
//            "<when test = 'query.notConsigneeKey != null and query.notConsigneeKey != \"\" '>",
//            "AND (concat(IFNULL(nee.`name`,''),IFNULL(nee.`name_en`,''),IFNULL(nee.`phone`,'')) not like concat('%',concat(#{query.notConsigneeKey},'%'))",
//            "AND nee.customer_id not in (select c.id from ecw_customer c where c.number like concat('%',concat(#{query.notConsigneeKey},'%'))))",
//            "</when>",
//            "<when test = 'query.numberKey != null and query.numberKey != \"\" '>",
//            "AND concat(IFNULL(o.`order_no`,''), IFNULL(o.`old_numbers`,'') , IFNULL(o.`parent_number`,'') , IFNULL(o.`initial_parent_order_no`,'') ,IFNULL(o.`marks`,''),IFNULL(o.`tidan_no`,''),IFNULL(o.`container_number`,''),IFNULL(o.`no_charge_record`,'')) like concat('%',concat(#{query.numberKey},'%'))",
//            "</when>",
//            "<when test = 'query.notNumberKey != null and query.notNumberKey != \"\" '>",
//            "AND concat(IFNULL(o.`order_no`,''), IFNULL(o.`old_numbers`,'') , IFNULL(o.`parent_number`,'') , IFNULL(o.`initial_parent_order_no`,'') ,IFNULL(o.`marks`,''),IFNULL(o.`tidan_no`,''),IFNULL(o.`container_number`,''),IFNULL(o.`no_charge_record`,'')) not like concat('%',concat(#{query.notNumberKey},'%'))",
//            "</when>",
//            "<when test = 'query.eqNumberKey != null and query.eqNumberKey != \"\" '>",
//            "AND (o.`order_no` = #{query.eqNumberKey}",
//            "or (o.`old_numbers` is not null and o.`old_numbers` != '' and o.`old_numbers` = #{query.eqNumberKey}) ",
//            "or (o.`parent_number` is not null and o.`parent_number` != '' and o.`parent_number` = #{query.eqNumberKey}) ",
//            "or (o.`marks` is not null and o.`marks` != '' and o.`marks` = #{query.eqNumberKey}) ",
//            "or (o.`tidan_no` is not null and o.`tidan_no` != '' and o.`tidan_no` = #{query.eqNumberKey}) ",
//            "or (o.`container_number` is not null and o.`container_number` != '' and o.`container_number` = #{query.eqNumberKey}) ",
//            "or (o.`no_charge_record` is not null and o.`no_charge_record` != '' and o.`no_charge_record` = #{query.eqNumberKey})",
//            "or (o.`initial_parent_order_no` is not null and o.`initial_parent_order_no` != '' and o.`initial_parent_order_no` = #{query.eqNumberKey}))",
//            "</when>",
//            "<when test = 'query.notEqNumberKey != null and query.notEqNumberKey != \"\" '>",
//            "AND o.`order_no` != #{query.notEqNumberKey}",
//            "AND (o.`old_numbers` is null or o.`old_numbers` = '' or o.`old_numbers` != #{query.notEqNumberKey})",
//            "AND (o.`marks` is null or o.`marks` = '' or o.`marks` != #{query.notEqNumberKey})",
//            "AND (o.`tidan_no` is null or o.`tidan_no` = '' or o.`tidan_no` != #{query.notEqNumberKey})",
//            "AND (o.`container_number` is null or o.`container_number` = '' or o.`container_number` != #{query.notEqNumberKey})",
//            "AND (o.`no_charge_record` is null or o.`no_charge_record` = '' or o.`no_charge_record` != #{query.notEqNumberKey})",
//            "AND (o.`initial_parent_order_no` is null or o.`initial_parent_order_no` = '' or o.`initial_parent_order_no` != #{query.notEqNumberKey})",
//            "</when>",
//            "<when test = 'query.prodKey != null and query.prodKey != \"\" '>",
//            "and (o.order_id in(",
//            "select oi.order_id ",
//            "from ecw_order_item oi ",
//            "left join ecw_product p ",
//            "on oi.prod_id = p.id ",
//            "left join ecw_product_type pt ",
//            "on pt.id = oi.prod_type ",
//            "left join ecw_product_brank pb",
//            "on pb.id = oi.brand",
//            "where oi.deleted = 0 ",
//            "and concat(IFNULL(oi.`prod_title_zh`,''),IFNULL(oi.`prod_title_en`,''),IFNULL(pt.`title_zh`,''),IFNULL(pt.`title_en`,''),IFNULL(pb.`title_zh`,''),IFNULL(pb.`title_en`,''))",
//            "like concat('%',concat(#{query.prodKey},'%'))",
//            "))",
//            "</when>",
//            "<when test = 'query.notProdKey != null and query.notProdKey != \"\" '>",
//            "and (o.order_id not in(",
//            "select oi.order_id ",
//            "from ecw_order_item oi ",
//            "left join ecw_product p ",
//            "on oi.prod_id = p.id ",
//            "left join ecw_product_type pt ",
//            "on pt.id = oi.prod_type ",
//            "left join ecw_product_brank pb",
//            "on pb.id = oi.brand",
//            "where oi.deleted = 0 and concat(IFNULL(oi.`prod_title_zh`,''),IFNULL(oi.`prod_title_en`,''),IFNULL(pt.`title_zh`,''),IFNULL(pt.`title_en`,''),IFNULL(pb.`title_zh`,''),IFNULL(pb.`title_en`,'')) " ,
//            "like concat('%',concat(#{query.notProdKey},'%'))",
//            "))",
//            "</when>",
//            "<when test = 'query.eqProdKey != null and query.eqProdKey != \"\" '>",
//            "and (o.order_id in(",
//            "select oi.order_id ",
//            "from ecw_order_item oi ",
//            "left join ecw_product p ",
//            "on oi.prod_id = p.id ",
//            "left join ecw_product_type pt ",
//            "on pt.id = oi.prod_type ",
//            "left join ecw_product_brank pb",
//            "on pb.id = oi.brand",
//            "where oi.deleted = 0 " ,
//            "and (oi.`prod_title_zh` = #{query.eqProdKey} or oi.`prod_title_en` = #{query.eqProdKey} " ,
//            "or pt.`title_zh` = #{query.eqProdKey} or pt.`title_en` = #{query.eqProdKey}",
//            "or pb.`title_zh` = #{query.eqProdKey} or pb.`title_en` = #{query.eqProdKey})",
//            "))",
//            "</when>",
//            "<when test = 'query.notEqProdKey != null and query.notEqProdKey != \"\" '>",
//            "and (o.order_id not in(",
//            "select oi.order_id ",
//            "from ecw_order_item oi ",
//            "left join ecw_product p ",
//            "on oi.prod_id = p.id ",
//            "left join ecw_product_type pt ",
//            "on pt.id = oi.prod_type ",
//            "left join ecw_product_brank pb",
//            "on pb.id = oi.brand",
//            "where oi.deleted = 0" ,
//            "and (oi.`prod_title_zh` = #{query.notEqProdKey} or oi.`prod_title_en` = #{query.notEqProdKey} " ,
//            "or pt.`title_zh` = #{query.notEqProdKey} or pt.`title_en` = #{query.notEqProdKey}",
//            "or pb.`title_zh` = #{query.notEqProdKey} or pb.`title_en` = #{query.notEqProdKey})",
//            "))",
//            "</when>",
//            "<when test = 'query.startWarehouseId != null and query.destWarehouseId != null '>",
//            "and (o.line_id in(",
//            "select whl.id ",
//            "from ecw_warehouse_line whl ",
//            "where whl.start_warehouse_id = #{query.startWarehouseId} and whl.dest_warehouse_id = #{query.destWarehouseId} ",
//            "))",
//            "</when>",
//            "<when test = 'query.startWarehouseId != null and query.destWarehouseId == null '>",
//            "and (o.line_id in(",
//            "select whl.id ",
//            "from ecw_warehouse_line whl ",
//            "where whl.start_warehouse_id = #{query.startWarehouseId}  ",
//            "))",
//            "</when>",
//            "<when test = 'query.startWarehouseId == null and query.destWarehouseId != null '>",
//            "and (o.line_id in(",
//            "select whl.id ",
//            "from ecw_warehouse_line whl ",
//            "where whl.dest_warehouse_id = #{query.destWarehouseId} ",
//            "))",
//            "</when>",
//            "<when test = 'query.airShipment != null and query.airShipment == 1'>",
//            "AND o.`status` = 5 AND o.air_shipment = 1 and abnormal_state = 0 and audit_type = 0 ",
//            "</when>",
//            "<when test = 'query.airShipment != null and query.airShipment == 2'>",
//            "AND o.`status` = 5  AND o.air_shipment = 2",
//            "</when>",
//            "<when test = 'query.airShipment != null and query.airShipment == 3'>",
//            "AND o.`status` = 5  AND o.air_shipment = 3",
//            "</when>",
//            "<when test = 'query.airShipment != null and query.airShipment == 4'>",
//            "AND o.`status` = 5  AND o.air_shipment = 4",
//            "</when>",
//            "<when test = 'query.airShipment != null and query.airShipment == 10'>",
//            "AND o.`status` = 5 AND o.air_shipment in(2,3,4)",
//            "</when>",
//            "<when test = 'query.airShipment != null and query.airShipment == 11'>",
//            "AND o.`status` = 5  AND o.air_shipment in(1,2,3,4) and abnormal_state = 0 and audit_type = 0 ",
//            "</when>",
//            "<when test = 'query.airShipment != null and query.airShipment == 12'>",
//            "AND o.`status` = 5  AND o.air_shipment in(2,3) and abnormal_state = 0 and audit_type = 0 ",
//            "</when>",
//            "<when test = 'query.airShipment != null and query.airShipment == 20'>",
//            "AND o.`status` = 5  AND o.air_shipment in(0,2,3,4) and abnormal_state = 0 and audit_type = 0 ",
//            "</when>",
//            "<when test = 'query.isNeat == false  '>",
//            " AND o.sum_num  <![CDATA[ < ]]> o.cost->>'$.totalNum' ",
//            "</when>",
//            "<when test = 'query.isNeat == true  '>",
//            " AND o.sum_num  = o.cost->>'$.totalNum' ",
//            "</when>",
//            "<when test = 'query.customerDetailId != null'>",
//            "AND (o.`customer_id` = #{query.customerDetailId} or nor.`customer_id` = #{query.customerDetailId}  or nee.`customer_id` = #{query.customerDetailId})",
//            "</when>",
//            "<when test = 'query.userType == 2 '>",
//            "</when>",
//            "</script>"
//    })
    StatisticsOrderVO statisticsWarehouseIn(@Param("query") OrderQueryVO query);
    @ResultType(StatisticsOrderVO.class)
    @Select({
            "<script>",
            "select ",
            "SUM(IFNULL(wi.cartons_num, 0)) as total_num, ",
            "SUM(IFNULL(wi.volume, 0)) as total_volume, ",
            "SUM(IFNULL(wi.weight, 0)) as total_weight, ",
            "SUM(IFNULL(wi.quantity_all, 0)) as order_quantity ",
            "from ecw_order_warehouse_in wi ",
            "left join ecw_order o ",
            "ON wi.order_id = o.order_id ",
            "left join ecw_order_departure de on de.order_id = o.order_id ",
            "left join ecw_order_objective ob on ob.order_id = o.order_id ",
            "left join ecw_order_consignor nor on nor.order_id = o.order_id ",
            "left join ecw_order_consignee nee on nee.order_id = o.order_id ",
            "left join ecw_channel channel on channel.channel_id = o.channel_id  ",
            "where o.deleted = 0 and o.in_warehouse_state != 211 and o.in_warehouse_state != 208 and o.status != 10 and wi.deleted = 0",
            "<when test = 'query.deptId != null '>",
            "AND o.dept_id = #{query.deptId} ",
            "</when>",
            "<when test= 'query.deptIdList != null and query.deptIdList.size() > 0'>",
            "AND (o.dept_id IN",
            "<foreach item='deptId' collection='query.deptIdList' open='(' close=')' separator=','> #{deptId} </foreach>",
            " or ",
            "(SELECT u.dept_id FROM system_user u WHERE u.id = o.creator) IN",
            "<foreach item='deptId' collection='query.deptIdList' open='(' close=')' separator=','> #{deptId} </foreach>)",
            "</when>",
            "<when test = 'query.pdaStartWareIds != null and query.pdaStartWareIds != \"\" '>",
            "AND FIND_IN_SET(ew_start.`id`, #{query.pdaStartWareIds})",
            "</when>",
            "<when test = 'query.pdaDestWareIds != null and query.pdaDestWareIds != \"\" '>",
            "AND FIND_IN_SET(ew_dest.`id`, #{query.pdaDestWareIds})",
            "</when>",
            "<when test = 'query.packageType != null and query.packageType != \"\" '>",
            "AND CONCAT(',',o.package_type,',') REGEXP CONCAT(',',REPLACE(#{query.packageType},',',',|,'), ',')",
            "</when>",
            "<if test=\"query.isExternalWarehouse != null and query.isExternalWarehouse.size()>0\">\n" +
                    "\n" +
                    "            <if test=\"query.isExternalWarehouse != null and query.isExternalWarehouse != '' and query.isExternalWarehouse.size()==1 \">\n" +
                    "                AND o.`is_external_warehouse` =\n" +
                    "                <foreach item='isExternalWarehouse' index=\"index\" collection='query.isExternalWarehouse' >\n" +
                    "                    #{isExternalWarehouse}\n" +
                    "                </foreach>\n" +
                    "            </if>\n" +
                    "\n" +
                    "            <if test=\"query.isExternalWarehouse != null and query.isExternalWarehouse != '' and query.isExternalWarehouse.size()>1 \">\n" +
                    "                AND o.`is_external_warehouse` in\n" +
                    "                <foreach item='isExternalWarehouse' index=\"index\" collection='query.isExternalWarehouse' open='(' separator=',' close=')'>\n" +
                    "                    #{isExternalWarehouse}\n" +
                    "                </foreach>\n" +
                    "            </if>\n" +
                    "\n" +
                    "        </if>",
//            "<when test = 'query.isExternalWarehouse != null'>",
//            "AND o.`is_external_warehouse` = #{query.isExternalWarehouse}",
//            "</when>",
            "  <if test=\"query.statusList != null and query.statusList.size()>0\">\n" +
                    "\n" +
                    "            <if test=\"query.statusList != null and query.statusList != '' and query.statusList.size()==1 \">\n" +
                    "                AND o.`status` =\n" +
                    "                <foreach item='status' index=\"index\" collection='query.statusList' >\n" +
                    "                    #{status}\n" +
                    "                </foreach>\n" +
                    "            </if>\n" +
                    "\n" +
                    "            <if test=\"query.statusList != null and query.statusList != '' and query.statusList.size()>1 \">\n" +
                    "                AND o.`status` in\n" +
                    "                <foreach item='status' index=\"index\" collection='query.statusList' open='(' separator=',' close=')'>\n" +
                    "                    #{status}\n" +
                    "                </foreach>\n" +
                    "            </if>\n" +
                    "\n" +
                    "        </if>",
//            "<when test = 'query.status != null'>",
//            "AND o.`status` = #{query.status}",
//            "</when>",
            "  <if test=\"query.abnormalState != null and query.abnormalState.size()>0\">\n" +
                    "\n" +
                    "            <if test=\"query.abnormalState != null and query.abnormalState != '' and query.abnormalState.size()==1 \">\n" +
                    "\n" +
                    "                <foreach item='abnormalState' index=\"index\" collection='query.abnormalState' >\n" +
                    "\n" +
                    "                                <choose>\n" +
                    "                                    <when test=\"abnormalState != '0'\">\n" +
                    "                                        <choose>\n" +
                    "                                            <when test=\"abnormalState != '-1'\">\n" +
                    "                                                AND o.`abnormal_state` = #{abnormalState}\n" +
                    "                                            </when>\n" +
                    "                                            <otherwise>\n" +
                    "                                                AND o.`abnormal_state` != 0\n" +
                    "                                            </otherwise>\n" +
                    "                                        </choose>\n" +
                    "                                    </when>\n" +
                    "                                    <otherwise>\n" +
                    "                                        AND o.`abnormal_state` = 0\n" +
                    "                                    </otherwise>\n" +
                    "                                </choose>\n" +
                    "                </foreach>\n" +
                    "            </if>\n" +
                    "\n" +
                    "            <if test=\"query.abnormalState != null and query.abnormalState != '' and query.abnormalState.size()>1 \">\n" +
                    "                  AND (1!=1\n" +
                    "                <foreach item='abnormalState' index=\"index\" collection='query.abnormalState'>\n" +
                    "\n" +
                    "                    <choose>\n" +
                    "                        <when test=\"abnormalState != '0'\">\n" +
                    "                            <choose>\n" +
                    "                                <when test=\"abnormalState != '-1'\">\n" +
                    "                                    OR o.`abnormal_state` = #{abnormalState}\n" +
                    "                                </when>\n" +
                    "                                <otherwise>\n" +
                    "                                    OR o.`abnormal_state` != 0\n" +
                    "                                </otherwise>\n" +
                    "                            </choose>\n" +
                    "                        </when>\n" +
                    "                        <otherwise>\n" +
                    "                            OR o.`abnormal_state` = 0\n" +
                    "                        </otherwise>\n" +
                    "                    </choose>\n" +
                    "                </foreach>\n" +
                    "\n" +
                    "                )\n" +
                    "            </if>\n" +
                    "\n" +
                    "        </if>",
//            "<when test = 'query.abnormalState != null'>",
//            "<choose>",
//            "<when test = 'query.abnormalState != 0'>",
//            "<choose>",
//            "<when test = '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>",
//            "</when>",
            "<when test = 'query.inWarehouseState != null'>",
            "AND o.`in_warehouse_state` = #{query.inWarehouseState}",
            "</when>",
            "<when test = 'query.shipmentState != null'>",
            "AND o.`shipment_State` = #{query.shipmentState}",
            "</when>",
            " <if test=\"query.auditType != null and query.auditType.size()>0\">\n" +
                    "\n" +
                    "            <if test=\"query.auditType != null and query.auditType != '' and query.auditType.size()==1 \">\n" +
                    "\n" +
                    "                <foreach item='auditType' index=\"index\" collection='query.auditType' >\n" +
                    "\n" +
                    "                    <choose>\n" +
                    "                        <when test=\"auditType != 0\">\n" +
                    "                            <choose>\n" +
                    "                                <when test=\"auditType != -1\">\n" +
                    "                                    AND o.`audit_type` = #{auditType}\n" +
                    "                                </when>\n" +
                    "                                <otherwise>\n" +
                    "                                    AND o.`audit_type` != 0\n" +
                    "                                </otherwise>\n" +
                    "                            </choose>\n" +
                    "                        </when>\n" +
                    "                        <otherwise>\n" +
                    "                            AND o.`audit_type` = 0\n" +
                    "                        </otherwise>\n" +
                    "                    </choose>\n" +
                    "                </foreach>\n" +
                    "            </if>\n" +
                    "        </if>",
//            "<when test = 'query.auditType != null'>",
//            "<choose>",
//            "<when test = 'query.auditType != 0'>",
//            "<choose>",
//            "<when test = '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>",
//            "</when>",
            "<when test = '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} ))",
            "</when>",
//            "<when test = 'query.customsType != null'>",
//            "AND o.`customs_type` = #{query.customsType}",
//            "</when>",
//            "<when test = 'query.productRecord != null'>",
//            "AND o.`product_record` = #{query.productRecord}",
//            "</when>",
            " <if test=\"query.customsType != null and query.customsType.size()>0\">\n" +
                    "\n" +
                    "            <if test=\"query.customsType != null and query.customsType != '' and query.customsType.size()==1 \">\n" +
                    "                AND o.`customs_type` =\n" +
                    "                <foreach item='customsType' index=\"index\" collection='query.customsType' >\n" +
                    "                    #{customsType}\n" +
                    "                </foreach>\n" +
                    "            </if>\n" +
                    "\n" +
                    "            <if test=\"query.customsType != null and query.customsType != '' and query.customsType.size()>1 \">\n" +
                    "                AND o.`customs_type` in\n" +
                    "                <foreach item='customsType' index=\"index\" collection='query.customsType' open='(' separator=',' close=')'>\n" +
                    "                    #{customsType}\n" +
                    "                </foreach>\n" +
                    "            </if>\n" +
                    "\n" +
                    "        </if>\n" +
                    "\n" +
                    "\n" +
                    "        <if test=\"query.productRecord != null and query.productRecord.size()>0\">\n" +
                    "\n" +
                    "            <if test=\"query.productRecord != null and query.productRecord != '' and query.productRecord.size()==1 \">\n" +
                    "                AND o.`product_record` =\n" +
                    "                <foreach item='productRecord' index=\"index\" collection='query.productRecord' >\n" +
                    "                    #{productRecord}\n" +
                    "                </foreach>\n" +
                    "            </if>\n" +
                    "\n" +
                    "            <if test=\"query.productRecord != null and query.productRecord != '' and query.productRecord.size()>1 \">\n" +
                    "                AND o.`product_record` in\n" +
                    "                <foreach item='productRecord' index=\"index\" collection='query.productRecord' open='(' separator=',' close=')'>\n" +
                    "                    #{productRecord}\n" +
                    "                </foreach>\n" +
                    "            </if>\n" +
                    "\n" +
                    "        </if>",
            "<when test = 'query.transportId != null'>",
            "AND o.`transport_id` = #{query.transportId}",
            "</when>",
            "<when test = 'query.channelId != null'>",
            "AND o.`channel_id` = #{query.channelId}",
            "</when>",
//            "<when test = 'query.warehouseType != null'>",
//            "AND o.`warehouse_type` = #{query.warehouseType}",
//            "</when>",
            " <if test=\"query.warehouseType != null and query.warehouseType.size()>0\">\n" +
                    "\n" +
                    "            <if test=\"query.warehouseType != null and query.warehouseType != '' and query.warehouseType.size()==1 \">\n" +
                    "                AND o.`warehouse_type` =\n" +
                    "                <foreach item='warehouseType' index=\"index\" collection='query.warehouseType' >\n" +
                    "                     #{warehouseType}\n" +
                    "                </foreach>\n" +
                    "            </if>\n" +
                    "\n" +
                    "            <if test=\"query.warehouseType != null and query.warehouseType != '' and query.warehouseType.size()>1 \">\n" +
                    "                AND o.`warehouse_type` in\n" +
                    "                <foreach item='warehouseType' index=\"index\" collection='query.warehouseType' open='(' separator=',' close=')'>\n" +
                    "                    #{warehouseType}\n" +
                    "                </foreach>\n" +
                    "            </if>\n" +
                    "\n" +
                    "        </if>",
            "<when test = '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},'%'))))))",
            "</when>",
            "<when test = '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},'%')))))",
            "</when>",
            "<when test = 'query.marks != null and query.marks != \"\" '>",
            "AND o.`marks` like concat('%',concat(#{query.marks},'%'))",
            "</when>",
            "<when test = 'query.departureId != null '>",
            "AND de.`departure_id` = #{query.departureId}",
            "</when>",
//            "<when test = 'query.type != null and query.type != \"\" and query.type == 0 '>",
//            "AND (o.type is null or o.type = '' or o.type = '0')",
//            "</when>",
//            "<when test = 'query.type == 1 '>",
//            "AND FIND_IN_SET(1, o.type)",
//            "</when>",
//            "<when test = 'query.type == 2 '>",
//            "AND FIND_IN_SET(2, o.type)",
//            "</when>",
            "<if test=\"query.type != null and query.type != '' and query.type.size()>0 \">\n" +
                    "            <if test=\"query.type != null and query.type != '' and query.type.size()>1 \">\n" +
                    "\n" +
                    "                 AND (1 !=1\n" +
                    "                <foreach item='type' index=\"index\" collection='query.type' >\n" +
                    "                    <if test=\"type == 0 \">\n" +
                    "                        OR (o.type is null or o.type = '' or o.type = '0')\n" +
                    "\n" +
                    "                    </if>\n" +
                    "                    <if test=\"type == 1 \">\n" +
                    "                        OR FIND_IN_SET(1, o.type)\n" +
                    "                    </if>\n" +
                    "                    <if test=\"type == 2 \">\n" +
                    "                        OR FIND_IN_SET(2, o.type)\n" +
                    "                    </if>\n" +
                    "                </foreach>\n" +
                    "                  )\n" +
                    "            </if>\n" +
                    "            <if test=\"query.type != null and query.type != '' and query.type.size()==1 \">\n" +
                    "                <foreach item='type' index=\"index\" collection='query.type' >\n" +
                    "                    <if test=\"type == 0 \">\n" +
                    "                        AND (o.type is null or o.type = '' or o.type = '0')\n" +
                    "\n" +
                    "                    </if>\n" +
                    "                    <if test=\"type == 1 \">\n" +
                    "                        AND FIND_IN_SET(1, o.type)\n" +
                    "                    </if>\n" +
                    "                    <if test=\"type == 2 \">\n" +
                    "                        AND FIND_IN_SET(2, o.type)\n" +
                    "                    </if>\n" +
                    "                </foreach>\n" +
                    "            </if>\n" +
                    "\n" +
                    "        </if>",
//                "<when test='query.type != null and query.type != '' and query.type.size()>0 '>" ,
//                "<if test='query.type != null and query.type != '' and query.type.size()>1 '>" ,
//                "AND o.type in" ,
//                "<foreach item='type'  collection='query.type' open='(' separator=',' close=')'>" ,
//                "${type}" ,
//                "</foreach>" ,
//                "</if>" ,
//                "<if test='query.type != null and query.type != '' and query.type.size()==1 '>" ,
//                "<if test='query.type != null and query.type != '' and query.type == 0 '>" ,
//                "AND (o.type is null or o.type = '' or o.type = '0')" ,
//                "</if>" ,
//                "<if test='query.type == 1 '>" ,
//                "AND FIND_IN_SET(1, o.type)" ,
//                "</if>" ,
//                "<if test='query.type == 2 '>" ,
//                "AND FIND_IN_SET(2, o.type)" ,
//                "</if>" ,
//                "</if>" ,
//                "</when>",
//            "<when test = 'query.objectiveId != null '>",
//            "AND ob.`objective_id` = #{query.objectiveId}",
//            "</when>",
            "<if test=\"query.objectiveId != null and query.objectiveId.size() != 0\">\n" +
                    "            AND   ob.`objective_id`   in\n" +
                    "            <foreach item='orderId' index='index' collection='query.objectiveId' open='(' separator=',' close=')'>\n" +
                    "                #{orderId}\n" +
                    "            </foreach>\n" +
                    "\n" +
                    "        </if>\n" +
                    "        <if test=\"query.destCountryId != null \">\n" +
                    "            AND ob.`objective_country_id` in\n" +
                    "            <foreach item='destCountryId' index='index' collection='query.destCountryId' open='(' separator=',' close=')'>\n" +
                    "                #{destCountryId}\n" +
                    "            </foreach>\n" +
                    "        </if>",
            "<when test = 'query.consignorId != null '>",
            "AND nor.`customer_id` = #{query.consignorId} ",
            "</when>",
            "<when test = 'query.consignorPhone != null and query.consignorPhone != \"\"  '>",
            "AND nor.`phone` = #{query.consignorPhone} ",
            "</when>",
            "<when test = 'query.consigneeId != null '>",
            "AND nee.`customer_id` = #{query.consigneeId}",
            "</when>",
            "<when test = 'query.consigneePhone != null and query.consigneePhone != \"\"  '>",
            "AND nee.`phone` = #{query.consigneePhone} ",
            "</when>",
            "<when test = 'query.isCargoControl != null '>",
            "AND o.`is_cargo_control` = #{query.isCargoControl}",
            "</when>",
            "<when test = 'query.orderNo != null and query.orderNo != \"\" '>",
            "AND o.`order_no` like concat('%',concat(#{query.orderNo},'%'))",
            "</when>",
            "<when test = 'query.orderIdList != null and query.orderIdList.size() != 0'>",
            "AND o.`order_id` in ",
            "<foreach item='orderId' index='index' collection='query.orderIdList' open='(' separator=',' close=')'>#{orderId}</foreach> ",
            "</when>",
            "<when test = 'query.tidanNo != null and query.tidanNo != \"\" '>",
            "AND o.`tidan_no` like concat('%',concat(#{query.tidanNo},'%'))",
            "</when>",
            "<when test = 'query.customerId != null'>",
            "AND o.`customer_id` = #{query.customerId}",
            "</when>",
            "<when test = 'query.beginRucangTime != null and query.endRucangTime != null '>",
//            "AND o.`rucang_time` between #{query.beginRucangTime} and #{query.endRucangTime}",
            "AND wi.`in_time` between #{query.beginRucangTime} and #{query.endRucangTime}",
            "</when>",
            "<when test = 'query.beginQingguanTime != null and query.endQingguanTime != null '>",
            "AND o.`qingguan_time` between #{query.beginQingguanTime} and #{query.endQingguanTime}",
            "</when>",
            "<when test = 'query.beginDaogangTime != null and query.endDaogangTime != null '>",
            "AND o.`daogang_time` between #{query.beginDaogangTime} and #{query.endDaogangTime}",
            "</when>",
            "<when test = 'query.beginPreLoadTime != null and query.endPreLoadTime != null '>",
            "AND o.`status` > 5 AND o.`pre_load_time` between #{query.beginPreLoadTime} and #{query.endPreLoadTime}",
            "</when>",
            "<when test = 'query.beginOutboundTime != null and query.endOutboundTime != null '>",
            "AND o.`status` > 5 AND o.container_number in(select distinct b.self_no from ecw_box_air_checkout bc join ecw_box b ON bc.shipment_id = b.id",
            "where b.deleted = 0 and bc.deleted = 0 and bc.`checkout_time` between #{query.beginOutboundTime} and #{query.endOutboundTime})",
            "</when>",
            "<when test = 'query.beginLoadTime != null and query.endLoadTime != null '>",
            "AND o.`load_time` between #{query.beginLoadTime} and #{query.endLoadTime}",
            "</when>",
            "<when test = 'query.beginUnloadTime != null and query.endUnloadTime != null '>",
            "AND o.`unload_time` between #{query.beginUnloadTime} and #{query.endUnloadTime}",
            "</when>",
            "<when test = 'query.beginTakeTime != null and query.endTakeTime != null '>",
            "AND o.`status` > 19 AND o.`take_time` between #{query.beginTakeTime} and #{query.endTakeTime}",
            "</when>",
            "<when test = 'query.beginSplitTime != null and query.endSplitTime != null '>",
            "AND o.`split_time` between #{query.beginSplitTime} and #{query.endSplitTime}",
            "</when>",
            "<when test = 'query.beginCreateTime != null and query.endCreateTime != null '>",
            "AND o.`create_time` between #{query.beginCreateTime} and #{query.endCreateTime}",
            "</when>",
            "<when test = 'query.beginPickTime != null and query.endPickTime != null '>",
            "AND o.order_id in(select distinct op.order_id from ecw_order_cargo_control_pick op where op.deleted = 0 and op.status in(1,3) and op.`create_time` between #{query.beginPickTime} and #{query.endPickTime})",
            "</when>",
            "<when test = 'query.beginPickUpTime != null and query.endPickUpTime != null '>",
            "AND o.order_no in(select distinct op.order_id from ecw_order_pickup op where op.deleted = 0 and op.`create_time` between #{query.beginPickUpTime} and #{query.endPickUpTime})",
            "</when>",
            "<when test = 'query.beginWarehouseInTime != null and query.endWarehouseInTime != null '>",
            "AND wi.`update_time` between #{query.beginWarehouseInTime} and #{query.endWarehouseInTime}",
            "</when>",
            "<when test = 'query.creator != null and query.creator != \"\" '>",
            "AND o.`creator` = #{query.creator}",
            "</when>",
            "<when test = 'query.searchKey != null and query.searchKey != \"\" '>",
            "AND concat(IFNULL(o.`order_no`,''), IFNULL(o.`old_numbers`,'') ,IFNULL(o.`marks`,''),IFNULL(o.`tidan_no`,''),IFNULL(o.`container_number`,''),IFNULL(nee.`name`,''),IFNULL(nee.`phone`,'')) like concat('%',concat(#{query.searchKey},'%'))",
            "</when>",
            "<when test = '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},'%'))))",
            "</when>",
            "<when test = 'query.notConsignorKey != null and query.notConsignorKey != \"\" '>",
            "AND (concat(IFNULL(nor.`name`,''),IFNULL(nor.`name_en`,''),IFNULL(nor.`phone`,'')) not like concat('%',concat(#{query.notConsignorKey},'%'))",
            "AND nor.customer_id not in (select c.id from ecw_customer c where c.number like concat('%',concat(#{query.notConsignorKey},'%'))))",
            "</when>",
            "<when test = '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},'%'))))",
            "</when>",
            "<when test = 'query.notConsigneeKey != null and query.notConsigneeKey != \"\" '>",
            "AND (concat(IFNULL(nee.`name`,''),IFNULL(nee.`name_en`,''),IFNULL(nee.`phone`,'')) not like concat('%',concat(#{query.notConsigneeKey},'%'))",
            "AND nee.customer_id not in (select c.id from ecw_customer c where c.number like concat('%',concat(#{query.notConsigneeKey},'%'))))",
            "</when>",
            "<when test = 'query.numberKey != null and query.numberKey != \"\" '>",
            "AND concat(IFNULL(o.`order_no`,''), IFNULL(o.`old_numbers`,'') , IFNULL(o.`parent_number`,'') , IFNULL(o.`initial_parent_order_no`,'') ,IFNULL(o.`marks`,''),IFNULL(o.`tidan_no`,''),IFNULL(o.`container_number`,''),IFNULL(o.`no_charge_record`,'')) like concat('%',concat(#{query.numberKey},'%'))",
            "</when>",
            "<when test = 'query.notNumberKey != null and query.notNumberKey != \"\" '>",
            "AND concat(IFNULL(o.`order_no`,''), IFNULL(o.`old_numbers`,'') , IFNULL(o.`parent_number`,'') , IFNULL(o.`initial_parent_order_no`,'') ,IFNULL(o.`marks`,''),IFNULL(o.`tidan_no`,''),IFNULL(o.`container_number`,''),IFNULL(o.`no_charge_record`,'')) not like concat('%',concat(#{query.notNumberKey},'%'))",
            "</when>",
            "<when test = 'query.eqNumberKey != null and query.eqNumberKey != \"\" '>",
            "AND (o.`order_no` = #{query.eqNumberKey}",
            "or (o.`old_numbers` is not null and o.`old_numbers` != '' and o.`old_numbers` = #{query.eqNumberKey}) ",
            "or (o.`parent_number` is not null and o.`parent_number` != '' and o.`parent_number` = #{query.eqNumberKey}) ",
            "or (o.`marks` is not null and o.`marks` != '' and o.`marks` = #{query.eqNumberKey}) ",
            "or (o.`tidan_no` is not null and o.`tidan_no` != '' and o.`tidan_no` = #{query.eqNumberKey}) ",
            "or (o.`container_number` is not null and o.`container_number` != '' and o.`container_number` = #{query.eqNumberKey}) ",
            "or (o.`no_charge_record` is not null and o.`no_charge_record` != '' and o.`no_charge_record` = #{query.eqNumberKey})",
            "or (o.`initial_parent_order_no` is not null and o.`initial_parent_order_no` != '' and o.`initial_parent_order_no` = #{query.eqNumberKey}))",
            "</when>",
            "<when test = 'query.notEqNumberKey != null and query.notEqNumberKey != \"\" '>",
            "AND o.`order_no` != #{query.notEqNumberKey}",
            "AND (o.`old_numbers` is null or o.`old_numbers` = '' or o.`old_numbers` != #{query.notEqNumberKey})",
            "AND (o.`marks` is null or o.`marks` = '' or o.`marks` != #{query.notEqNumberKey})",
            "AND (o.`tidan_no` is null or o.`tidan_no` = '' or o.`tidan_no` != #{query.notEqNumberKey})",
            "AND (o.`container_number` is null or o.`container_number` = '' or o.`container_number` != #{query.notEqNumberKey})",
            "AND (o.`no_charge_record` is null or o.`no_charge_record` = '' or o.`no_charge_record` != #{query.notEqNumberKey})",
            "AND (o.`initial_parent_order_no` is null or o.`initial_parent_order_no` = '' or o.`initial_parent_order_no` != #{query.notEqNumberKey})",
            "</when>",
            "<when test = 'query.prodKey != null and query.prodKey != \"\" '>",
            "and (o.order_id in(",
            "select oi.order_id ",
            "from ecw_order_item oi ",
            "left join ecw_product p ",
            "on oi.prod_id = p.id ",
            "left join ecw_product_type pt ",
            "on pt.id = oi.prod_type ",
            "left join ecw_product_brank pb",
            "on pb.id = oi.brand",
            "where oi.deleted = 0 ",
            "and concat(IFNULL(oi.`prod_title_zh`,''),IFNULL(oi.`prod_title_en`,''),IFNULL(pt.`title_zh`,''),IFNULL(pt.`title_en`,''),IFNULL(pb.`title_zh`,''),IFNULL(pb.`title_en`,''))",
            "like concat('%',concat(#{query.prodKey},'%'))",
            "))",
            "</when>",
            "<when test = 'query.notProdKey != null and query.notProdKey != \"\" '>",
            "and (o.order_id not in(",
            "select oi.order_id ",
            "from ecw_order_item oi ",
            "left join ecw_product p ",
            "on oi.prod_id = p.id ",
            "left join ecw_product_type pt ",
            "on pt.id = oi.prod_type ",
            "left join ecw_product_brank pb",
            "on pb.id = oi.brand",
            "where oi.deleted = 0 and concat(IFNULL(oi.`prod_title_zh`,''),IFNULL(oi.`prod_title_en`,''),IFNULL(pt.`title_zh`,''),IFNULL(pt.`title_en`,''),IFNULL(pb.`title_zh`,''),IFNULL(pb.`title_en`,'')) " ,
            "like concat('%',concat(#{query.notProdKey},'%'))",
            "))",
            "</when>",
            "<when test = 'query.eqProdKey != null and query.eqProdKey != \"\" '>",
            "and (o.order_id in(",
            "select oi.order_id ",
            "from ecw_order_item oi ",
            "left join ecw_product p ",
            "on oi.prod_id = p.id ",
            "left join ecw_product_type pt ",
            "on pt.id = oi.prod_type ",
            "left join ecw_product_brank pb",
            "on pb.id = oi.brand",
            "where oi.deleted = 0 " ,
            "and (oi.`prod_title_zh` = #{query.eqProdKey} or oi.`prod_title_en` = #{query.eqProdKey} " ,
            "or pt.`title_zh` = #{query.eqProdKey} or pt.`title_en` = #{query.eqProdKey}",
            "or pb.`title_zh` = #{query.eqProdKey} or pb.`title_en` = #{query.eqProdKey})",
            "))",
            "</when>",
            "<when test = 'query.notEqProdKey != null and query.notEqProdKey != \"\" '>",
            "and (o.order_id not in(",
            "select oi.order_id ",
            "from ecw_order_item oi ",
            "left join ecw_product p ",
            "on oi.prod_id = p.id ",
            "left join ecw_product_type pt ",
            "on pt.id = oi.prod_type ",
            "left join ecw_product_brank pb",
            "on pb.id = oi.brand",
            "where oi.deleted = 0" ,
            "and (oi.`prod_title_zh` = #{query.notEqProdKey} or oi.`prod_title_en` = #{query.notEqProdKey} " ,
            "or pt.`title_zh` = #{query.notEqProdKey} or pt.`title_en` = #{query.notEqProdKey}",
            "or pb.`title_zh` = #{query.notEqProdKey} or pb.`title_en` = #{query.notEqProdKey})",
            "))",
            "</when>",
//            "<when test = 'query.startWarehouseId != null and query.destWarehouseId != null '>",
//            "and (o.line_id in(",
//            "select whl.id ",
//            "from ecw_warehouse_line whl ",
//            "where whl.start_warehouse_id = #{query.startWarehouseId} and whl.dest_warehouse_id = #{query.destWarehouseId} ",
//            "))",
//            "</when>",
//            "<when test = 'query.startWarehouseId != null and query.destWarehouseId == null '>",
//            "and (o.line_id in(",
//            "select whl.id ",
//            "from ecw_warehouse_line whl ",
//            "where whl.start_warehouse_id = #{query.startWarehouseId}  ",
//            "))",
//            "</when>",
//            "<when test = 'query.startWarehouseId == null and query.destWarehouseId != null '>",
//            "and (o.line_id in(",
//            "select whl.id ",
//            "from ecw_warehouse_line whl ",
//            "where whl.dest_warehouse_id = #{query.destWarehouseId} ",
//            "))",
//            "</when>",
            " <if test=\"query.startWarehouseIds !=null and query.destWarehouseIds !=null  \">\n" +
                    "            and (o.line_id in(\n" +
                    "            select whl.id\n" +
                    "            from ecw_warehouse_line whl\n" +
                    "            where whl.start_warehouse_id in\n" +
                    "            <foreach item='warehouseId'  collection='query.startWarehouseIds' open='(' separator=',' close=')'>\n" +
                    "                #{warehouseId}\n" +
                    "            </foreach>\n" +
                    "\n" +
                    "            and whl.dest_warehouse_id in\n" +
                    "            <foreach item='destWarehouseId'  collection='query.destWarehouseIds' open='(' separator=',' close=')'>\n" +
                    "                #{destWarehouseId}\n" +
                    "            </foreach>\n" +
                    "\n" +
                    "            ))\n" +
                    "        </if>\n" +
                    "        <if test=\"query.startWarehouseIds !=null and query.destWarehouseIds==null\">\n" +
                    "            and (o.line_id in(\n" +
                    "            select whl.id\n" +
                    "            from ecw_warehouse_line whl\n" +
                    "            where whl.start_warehouse_id in\n" +
                    "            <foreach item='warehouseId'  collection='query.startWarehouseIds' open='(' separator=',' close=')'>\n" +
                    "                #{warehouseId}\n" +
                    "            </foreach>\n" +
                    "            ))\n" +
                    "        </if>\n" +
                    "        <if test=\"query.startWarehouseIds ==null and query.destWarehouseIds !=null  \">\n" +
                    "            and (o.line_id in(\n" +
                    "            select whl.id\n" +
                    "            from ecw_warehouse_line whl\n" +
                    "            where  whl.dest_warehouse_id  in\n" +
                    "            <foreach item='destWarehouseId'  collection='query.destWarehouseIds' open='(' separator=',' close=')'>\n" +
                    "                #{destWarehouseId}\n" +
                    "            </foreach>\n" +
                    "\n" +
                    "\n" +
                    "            ))\n" +
                    "        </if>",
            "<when test = 'query.airShipment != null and query.airShipment == 1'>",
            "AND o.`status` = 5 AND o.air_shipment = 1 and abnormal_state = 0 and audit_type = 0 ",
            "</when>",
            "<when test = 'query.airShipment != null and query.airShipment == 2'>",
            "AND o.`status` = 5  AND o.air_shipment = 2",
            "</when>",
            "<when test = 'query.airShipment != null and query.airShipment == 3'>",
            "AND o.`status` = 5  AND o.air_shipment = 3",
            "</when>",
            "<when test = 'query.airShipment != null and query.airShipment == 4'>",
            "AND o.`status` = 5  AND o.air_shipment = 4",
            "</when>",
            "<when test = 'query.airShipment != null and query.airShipment == 10'>",
            "AND o.`status` = 5 AND o.air_shipment in(2,3,4)",
            "</when>",
            "<when test = 'query.airShipment != null and query.airShipment == 11'>",
            "AND o.`status` = 5  AND o.air_shipment in(1,2,3,4) and abnormal_state = 0 and audit_type = 0 ",
            "</when>",
            "<when test = 'query.airShipment != null and query.airShipment == 12'>",
            "AND o.`status` = 5  AND o.air_shipment in(2,3) and abnormal_state = 0 and audit_type = 0 ",
            "</when>",
            "<when test = 'query.airShipment != null and query.airShipment == 20'>",
            "AND o.`status` = 5  AND o.air_shipment in(0,2,3,4) and abnormal_state = 0 and audit_type = 0 ",
            "</when>",
            "<when test = 'query.isNeat == false  '>",
            " AND o.sum_num  <![CDATA[ < ]]> o.cost->>'$.totalNum' ",
            "</when>",
            "<when test = 'query.isNeat == true  '>",
            " AND o.sum_num  = o.cost->>'$.totalNum' ",
            "</when>",
            "<when test = 'query.customerDetailId != null'>",
            "AND (o.`customer_id` = #{query.customerDetailId} or nor.`customer_id` = #{query.customerDetailId}  or nee.`customer_id` = #{query.customerDetailId})",
            "</when>",
            "<when test = 'query.userType == 2 '>",
            "</when>",
            "</script>"
    })
    StatisticsOrderVO statisticsMyWarehouseIn(@Param("query") OrderQueryVO query);

    @ResultType(StatisticsOrderVO.class)
    @Select({
            "<script>",
            "select ",
            "SUM(IFNULL(op.pick_num, 0)) as total_num",
            "from ecw_order_pickup op",
            "left join ecw_order o ",
            "ON op.order_id = o.order_no ",
            "left join ecw_order_departure de on de.order_id = o.order_id ",
            "left join ecw_order_objective ob on ob.order_id = o.order_id ",
            "left join ecw_order_consignor nor on nor.order_id = o.order_id ",
            "left join ecw_order_consignee nee on nee.order_id = o.order_id ",
            "left join ecw_channel channel on channel.channel_id = o.channel_id  ",
            "where o.deleted = 0 and o.in_warehouse_state != 211 and o.in_warehouse_state != 208 and o.status != 10 and op.deleted = 0",
            "<when test = 'query.deptId != null '>",
            "AND o.dept_id = #{query.deptId} ",
            "</when>",
            "<when test= 'query.deptIdList != null and query.deptIdList.size() > 0'>",
            "AND (o.dept_id IN",
            "<foreach item='deptId' collection='query.deptIdList' open='(' close=')' separator=','> #{deptId} </foreach>",
            " or ",
            "(SELECT u.dept_id FROM system_user u WHERE u.id = o.creator) IN",
            "<foreach item='deptId' collection='query.deptIdList' open='(' close=')' separator=','> #{deptId} </foreach>)",
            "</when>",
            "<when test = 'query.pdaStartWareIds != null and query.pdaStartWareIds != \"\" '>",
            "AND FIND_IN_SET(ew_start.`id`, #{query.pdaStartWareIds})",
            "</when>",
            "<when test = 'query.pdaDestWareIds != null and query.pdaDestWareIds != \"\" '>",
            "AND FIND_IN_SET(ew_dest.`id`, #{query.pdaDestWareIds})",
            "</when>",
            "<when test = 'query.packageType != null and query.packageType != \"\" '>",
            "AND CONCAT(',',o.package_type,',') REGEXP CONCAT(',',REPLACE(#{query.packageType},',',',|,'), ',')",
            "</when>",
            "<when test = 'query.isExternalWarehouse != null'>",
            "AND o.`is_external_warehouse` = #{query.isExternalWarehouse}",
            "</when>",
            "<when test = 'query.status != null'>",
            "AND o.`status` = #{query.status}",
            "</when>",
            "<when test = 'query.abnormalState != null'>",
            "<choose>",
            "<when test = 'query.abnormalState != 0'>",
            "<choose>",
            "<when test = '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>",
            "</when>",
            "<when test = 'query.inWarehouseState != null'>",
            "AND o.`in_warehouse_state` = #{query.inWarehouseState}",
            "</when>",
            "<when test = 'query.shipmentState != null'>",
            "AND o.`shipment_State` = #{query.shipmentState}",
            "</when>",
            "<when test = 'query.auditType != null'>",
            "<choose>",
            "<when test = 'query.auditType != 0'>",
            "<choose>",
            "<when test = '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>",
            "</when>",
            "<when test = '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} ))",
            "</when>",
            "<when test = 'query.customsType != null'>",
            "AND o.`customs_type` = #{query.customsType}",
            "</when>",
            "<when test = 'query.productRecord != null'>",
            "AND o.`product_record` = #{query.productRecord}",
            "</when>",
            "<when test = 'query.transportId != null'>",
            "AND o.`transport_id` = #{query.transportId}",
            "</when>",
            "<when test = 'query.channelId != null'>",
            "AND o.`channel_id` = #{query.channelId}",
            "</when>",
            "<when test = 'query.warehouseType != null'>",
            "AND o.`warehouse_type` = #{query.warehouseType}",
            "</when>",
            "<when test = '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},'%'))))))",
            "</when>",
            "<when test = '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},'%')))))",
            "</when>",
            "<when test = 'query.marks != null and query.marks != \"\" '>",
            "AND o.`marks` like concat('%',concat(#{query.marks},'%'))",
            "</when>",
            "<when test = 'query.departureId != null '>",
            "AND de.`departure_id` = #{query.departureId}",
            "</when>",
            "<when test = 'query.objectiveId != null '>",
            "AND ob.`objective_id` = #{query.objectiveId}",
            "</when>",
            "<when test = 'query.consignorId != null '>",
            "AND nor.`customer_id` = #{query.consignorId} ",
            "</when>",
            "<when test = 'query.consignorPhone != null and query.consignorPhone != \"\"  '>",
            "AND nor.`phone` = #{query.consignorPhone} ",
            "</when>",
            "<when test = 'query.consigneeId != null '>",
            "AND nee.`customer_id` = #{query.consigneeId}",
            "</when>",
            "<when test = 'query.consigneePhone != null and query.consigneePhone != \"\"  '>",
            "AND nee.`phone` = #{query.consigneePhone} ",
            "</when>",
            "<when test = 'query.isCargoControl != null '>",
            "AND o.`is_cargo_control` = #{query.isCargoControl}",
            "</when>",
            "<when test = 'query.orderNo != null and query.orderNo != \"\" '>",
            "AND o.`order_no` like concat('%',concat(#{query.orderNo},'%'))",
            "</when>",
            "<when test = 'query.orderIdList != null and query.orderIdList.size() != 0'>",
            "AND o.`order_id` in ",
            "<foreach item='orderId' index='index' collection='query.orderIdList' open='(' separator=',' close=')'>#{orderId}</foreach> ",
            "</when>",
            "<when test = 'query.tidanNo != null and query.tidanNo != \"\" '>",
            "AND o.`tidan_no` like concat('%',concat(#{query.tidanNo},'%'))",
            "</when>",
            "<when test = 'query.customerId != null'>",
            "AND o.`customer_id` = #{query.customerId}",
            "</when>",
            "<when test = 'query.beginRucangTime != null and query.endRucangTime != null '>",
//            "AND o.`rucang_time` between #{query.beginRucangTime} and #{query.endRucangTime}",
            "AND o.order_id in(select distinct wi.order_id from ecw_order_warehouse_in wi where wi.deleted = 0 and wi.`in_time` between #{query.beginRucangTime} and #{query.endRucangTime})",
            "</when>",
            "<when test = 'query.beginQingguanTime != null and query.endQingguanTime != null '>",
            "AND o.`qingguan_time` between #{query.beginQingguanTime} and #{query.endQingguanTime}",
            "</when>",
            "<when test = 'query.beginDaogangTime != null and query.endDaogangTime != null '>",
            "AND o.`daogang_time` between #{query.beginDaogangTime} and #{query.endDaogangTime}",
            "</when>",
            "<when test = 'query.beginPreLoadTime != null and query.endPreLoadTime != null '>",
            "AND o.`status` > 5 AND o.`pre_load_time` between #{query.beginPreLoadTime} and #{query.endPreLoadTime}",
            "</when>",
            "<when test = 'query.beginOutboundTime != null and query.endOutboundTime != null '>",
            "AND o.`status` > 5 AND o.container_number in(select distinct b.self_no from ecw_box_air_checkout bc join ecw_box b ON bc.shipment_id = b.id",
            "where b.deleted = 0 and bc.deleted = 0 and bc.`checkout_time` between #{query.beginOutboundTime} and #{query.endOutboundTime})",
            "</when>",
            "<when test = 'query.beginLoadTime != null and query.endLoadTime != null '>",
            "AND o.`load_time` between #{query.beginLoadTime} and #{query.endLoadTime}",
            "</when>",
            "<when test = 'query.beginUnloadTime != null and query.endUnloadTime != null '>",
            "AND o.`unload_time` between #{query.beginUnloadTime} and #{query.endUnloadTime}",
            "</when>",
            "<when test = 'query.beginTakeTime != null and query.endTakeTime != null '>",
            "AND o.`status` > 19 AND o.`take_time` between #{query.beginTakeTime} and #{query.endTakeTime}",
            "</when>",
            "<when test = 'query.beginSplitTime != null and query.endSplitTime != null '>",
            "AND o.`split_time` between #{query.beginSplitTime} and #{query.endSplitTime}",
            "</when>",
            "<when test = 'query.beginCreateTime != null and query.endCreateTime != null '>",
            "AND o.`create_time` between #{query.beginCreateTime} and #{query.endCreateTime}",
            "</when>",
            "<when test = 'query.beginPickTime != null and query.endPickTime != null '>",
            "AND o.order_id in(select distinct op.order_id from ecw_order_cargo_control_pick op where op.deleted = 0 and op.status in(1,3) and op.`create_time` between #{query.beginPickTime} and #{query.endPickTime})",
            "</when>",
            "and op.`create_time` between #{query.beginPickUpTime} and #{query.endPickUpTime}",
            "<when test = 'query.creator != null and query.creator != \"\" '>",
            "AND o.`creator` = #{query.creator}",
            "</when>",
            "<when test = 'query.searchKey != null and query.searchKey != \"\" '>",
            "AND concat(IFNULL(o.`order_no`,''), IFNULL(o.`old_numbers`,'') ,IFNULL(o.`marks`,''),IFNULL(o.`tidan_no`,''),IFNULL(o.`container_number`,''),IFNULL(nee.`name`,''),IFNULL(nee.`phone`,'')) like concat('%',concat(#{query.searchKey},'%'))",
            "</when>",
            "<when test = '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},'%'))))",
            "</when>",
            "<when test = 'query.notConsignorKey != null and query.notConsignorKey != \"\" '>",
            "AND (concat(IFNULL(nor.`name`,''),IFNULL(nor.`name_en`,''),IFNULL(nor.`phone`,'')) not like concat('%',concat(#{query.notConsignorKey},'%'))",
            "AND nor.customer_id not in (select c.id from ecw_customer c where c.number like concat('%',concat(#{query.notConsignorKey},'%'))))",
            "</when>",
            "<when test = '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},'%'))))",
            "</when>",
            "<when test = 'query.notConsigneeKey != null and query.notConsigneeKey != \"\" '>",
            "AND (concat(IFNULL(nee.`name`,''),IFNULL(nee.`name_en`,''),IFNULL(nee.`phone`,'')) not like concat('%',concat(#{query.notConsigneeKey},'%'))",
            "AND nee.customer_id not in (select c.id from ecw_customer c where c.number like concat('%',concat(#{query.notConsigneeKey},'%'))))",
            "</when>",
            "<when test = 'query.numberKey != null and query.numberKey != \"\" '>",
            "AND concat(IFNULL(o.`order_no`,''), IFNULL(o.`old_numbers`,''), IFNULL(o.`parent_number`,''), IFNULL(o.`initial_parent_order_no`,'') ,IFNULL(o.`marks`,''),IFNULL(o.`tidan_no`,''),IFNULL(o.`container_number`,''),IFNULL(o.`no_charge_record`,'')) like concat('%',concat(#{query.numberKey},'%'))",
            "</when>",
            "<when test = 'query.notNumberKey != null and query.notNumberKey != \"\" '>",
            "AND concat(IFNULL(o.`order_no`,''), IFNULL(o.`old_numbers`,''), IFNULL(o.`parent_number`,''), IFNULL(o.`initial_parent_order_no`,'') ,IFNULL(o.`marks`,''),IFNULL(o.`tidan_no`,''),IFNULL(o.`container_number`,''),IFNULL(o.`no_charge_record`,'')) not like concat('%',concat(#{query.notNumberKey},'%'))",
            "</when>",
            "<when test = 'query.eqNumberKey != null and query.eqNumberKey != \"\" '>",
            "AND (o.`order_no` = #{query.eqNumberKey}",
            "or (o.`old_numbers` is not null and o.`old_numbers` != '' and o.`old_numbers` = #{query.eqNumberKey}) ",
            "or (o.`parent_number` is not null and o.`parent_number` != '' and o.`parent_number` = #{query.eqNumberKey}) ",
            "or (o.`marks` is not null and o.`marks` != '' and o.`marks` = #{query.eqNumberKey}) ",
            "or (o.`tidan_no` is not null and o.`tidan_no` != '' and o.`tidan_no` = #{query.eqNumberKey}) ",
            "or (o.`container_number` is not null and o.`container_number` != '' and o.`container_number` = #{query.eqNumberKey}) ",
            "or (o.`no_charge_record` is not null and o.`no_charge_record` != '' and o.`no_charge_record` = #{query.eqNumberKey}))",
            "</when>",
            "<when test = 'query.notEqNumberKey != null and query.notEqNumberKey != \"\" '>",
            "AND o.`order_no` != #{query.notEqNumberKey}",
            "AND (o.`old_numbers` is null or o.`old_numbers` = '' or o.`old_numbers` != #{query.notEqNumberKey})",
            "AND (o.`parent_number` is null or o.`parent_number` = '' or o.`parent_number` != #{query.notEqNumberKey})",
            "AND (o.`marks` is null or o.`marks` = '' or o.`marks` != #{query.notEqNumberKey})",
            "AND (o.`tidan_no` is null or o.`tidan_no` = '' or o.`tidan_no` != #{query.notEqNumberKey})",
            "AND (o.`container_number` is null or o.`container_number` = '' or o.`container_number` != #{query.notEqNumberKey})",
            "AND (o.`no_charge_record` is null or o.`no_charge_record` = '' or o.`no_charge_record` != #{query.notEqNumberKey})",
            "</when>",
            "<when test = 'query.prodKey != null and query.prodKey != \"\" '>",
            "and (o.order_id in(",
            "select oi.order_id ",
            "from ecw_order_item oi ",
            "left join ecw_product p ",
            "on oi.prod_id = p.id ",
            "left join ecw_product_type pt ",
            "on pt.id = oi.prod_type ",
            "left join ecw_product_brank pb",
            "on pb.id = oi.brand",
            "where oi.deleted = 0 ",
            "and concat(IFNULL(oi.`prod_title_zh`,''),IFNULL(oi.`prod_title_en`,''),IFNULL(pt.`title_zh`,''),IFNULL(pt.`title_en`,''),IFNULL(pb.`title_zh`,''),IFNULL(pb.`title_en`,''))",
            "like concat('%',concat(#{query.prodKey},'%'))",
            "))",
            "</when>",
            "<when test = 'query.notProdKey != null and query.notProdKey != \"\" '>",
            "and (o.order_id not in(",
            "select oi.order_id ",
            "from ecw_order_item oi ",
            "left join ecw_product p ",
            "on oi.prod_id = p.id ",
            "left join ecw_product_type pt ",
            "on pt.id = oi.prod_type ",
            "left join ecw_product_brank pb",
            "on pb.id = oi.brand",
            "where oi.deleted = 0 and concat(IFNULL(oi.`prod_title_zh`,''),IFNULL(oi.`prod_title_en`,''),IFNULL(pt.`title_zh`,''),IFNULL(pt.`title_en`,''),IFNULL(pb.`title_zh`,''),IFNULL(pb.`title_en`,'')) " ,
            "like concat('%',concat(#{query.notProdKey},'%'))",
            "))",
            "</when>",
            "<when test = 'query.eqProdKey != null and query.eqProdKey != \"\" '>",
            "and (o.order_id in(",
            "select oi.order_id ",
            "from ecw_order_item oi ",
            "left join ecw_product p ",
            "on oi.prod_id = p.id ",
            "left join ecw_product_type pt ",
            "on pt.id = oi.prod_type ",
            "left join ecw_product_brank pb",
            "on pb.id = oi.brand",
            "where oi.deleted = 0 " ,
            "and (oi.`prod_title_zh` = #{query.eqProdKey} or oi.`prod_title_en` = #{query.eqProdKey} " ,
            "or pt.`title_zh` = #{query.eqProdKey} or pt.`title_en` = #{query.eqProdKey}",
            "or pb.`title_zh` = #{query.eqProdKey} or pb.`title_en` = #{query.eqProdKey})",
            "))",
            "</when>",
            "<when test = 'query.notEqProdKey != null and query.notEqProdKey != \"\" '>",
            "and (o.order_id not in(",
            "select oi.order_id ",
            "from ecw_order_item oi ",
            "left join ecw_product p ",
            "on oi.prod_id = p.id ",
            "left join ecw_product_type pt ",
            "on pt.id = oi.prod_type ",
            "left join ecw_product_brank pb",
            "on pb.id = oi.brand",
            "where oi.deleted = 0" ,
            "and (oi.`prod_title_zh` = #{query.notEqProdKey} or oi.`prod_title_en` = #{query.notEqProdKey} " ,
            "or pt.`title_zh` = #{query.notEqProdKey} or pt.`title_en` = #{query.notEqProdKey}",
            "or pb.`title_zh` = #{query.notEqProdKey} or pb.`title_en` = #{query.notEqProdKey})",
            "))",
            "</when>",
            "<when test = 'query.startWarehouseId != null and query.destWarehouseId != null '>",
            "and (o.line_id in(",
            "select whl.id ",
            "from ecw_warehouse_line whl ",
            "where whl.start_warehouse_id = #{query.startWarehouseId} and whl.dest_warehouse_id = #{query.destWarehouseId} ",
            "))",
            "</when>",
            "<when test = 'query.startWarehouseId != null and query.destWarehouseId == null '>",
            "and (o.line_id in(",
            "select whl.id ",
            "from ecw_warehouse_line whl ",
            "where whl.start_warehouse_id = #{query.startWarehouseId}  ",
            "))",
            "</when>",
            "<when test = 'query.startWarehouseId == null and query.destWarehouseId != null '>",
            "and (o.line_id in(",
            "select whl.id ",
            "from ecw_warehouse_line whl ",
            "where whl.dest_warehouse_id = #{query.destWarehouseId} ",
            "))",
            "</when>",
            "<when test = 'query.airShipment != null and query.airShipment == 1'>",
            "AND o.`status` = 5 AND o.air_shipment = 1 and abnormal_state = 0 and audit_type = 0 ",
            "</when>",
            "<when test = 'query.airShipment != null and query.airShipment == 2'>",
            "AND o.`status` = 5  AND o.air_shipment = 2",
            "</when>",
            "<when test = 'query.airShipment != null and query.airShipment == 3'>",
            "AND o.`status` = 5  AND o.air_shipment = 3",
            "</when>",
            "<when test = 'query.airShipment != null and query.airShipment == 4'>",
            "AND o.`status` = 5  AND o.air_shipment = 4",
            "</when>",
            "<when test = 'query.airShipment != null and query.airShipment == 10'>",
            "AND o.`status` = 5 AND o.air_shipment in(2,3,4)",
            "</when>",
            "<when test = 'query.airShipment != null and query.airShipment == 11'>",
            "AND o.`status` = 5  AND o.air_shipment in(1,2,3,4) and abnormal_state = 0 and audit_type = 0 ",
            "</when>",
            "<when test = 'query.airShipment != null and query.airShipment == 12'>",
            "AND o.`status` = 5  AND o.air_shipment in(2,3) and abnormal_state = 0 and audit_type = 0 ",
            "</when>",
            "<when test = 'query.airShipment != null and query.airShipment == 20'>",
            "AND o.`status` = 5  AND o.air_shipment in(0,2,3,4) and abnormal_state = 0 and audit_type = 0 ",
            "</when>",
            "<when test = 'query.isNeat == false  '>",
            " AND o.sum_num  <![CDATA[ < ]]> o.cost->>'$.totalNum' ",
            "</when>",
            "<when test = 'query.isNeat == true  '>",
            " AND o.sum_num  = o.cost->>'$.totalNum' ",
            "</when>",
            "<when test = 'query.customerDetailId != null'>",
            "AND (o.`customer_id` = #{query.customerDetailId} or nor.`customer_id` = #{query.customerDetailId}  or nee.`customer_id` = #{query.customerDetailId})",
            "</when>",
            "<when test = 'query.userType == 2 '>",
            "</when>",
            "</script>"
    })
    StatisticsOrderVO statisticsPickUp(@Param("query") OrderQueryVO query);

    @ResultType(StatisticsOrderVO.class)
    @Select({
            "<script>",
            "select ",
            "SUM(IFNULL(op.pick_num, 0)) as total_num",
            "from ecw_order_pickup op",
            "left join ecw_order o ",
            "ON op.order_id = o.order_no ",
            "left join ecw_order_departure de on de.order_id = o.order_id ",
            "left join ecw_order_objective ob on ob.order_id = o.order_id ",
            "left join ecw_order_consignor nor on nor.order_id = o.order_id ",
            "left join ecw_order_consignee nee on nee.order_id = o.order_id ",
            "left join ecw_channel channel on channel.channel_id = o.channel_id  ",
            "where o.deleted = 0 and o.in_warehouse_state != 211 and o.in_warehouse_state != 208 and o.status != 10 and op.deleted = 0",
            "<when test = 'query.deptId != null '>",
            "AND o.dept_id = #{query.deptId} ",
            "</when>",
            "<when test= 'query.deptIdList != null and query.deptIdList.size() > 0'>",
            "AND (o.dept_id IN",
            "<foreach item='deptId' collection='query.deptIdList' open='(' close=')' separator=','> #{deptId} </foreach>",
            " or ",
            "(SELECT u.dept_id FROM system_user u WHERE u.id = o.creator) IN",
            "<foreach item='deptId' collection='query.deptIdList' open='(' close=')' separator=','> #{deptId} </foreach>)",
            "</when>",
            "<when test = 'query.pdaStartWareIds != null and query.pdaStartWareIds != \"\" '>",
            "AND FIND_IN_SET(ew_start.`id`, #{query.pdaStartWareIds})",
            "</when>",
            "<when test = 'query.pdaDestWareIds != null and query.pdaDestWareIds != \"\" '>",
            "AND FIND_IN_SET(ew_dest.`id`, #{query.pdaDestWareIds})",
            "</when>",
            "<when test = 'query.packageType != null and query.packageType != \"\" '>",
            "AND CONCAT(',',o.package_type,',') REGEXP CONCAT(',',REPLACE(#{query.packageType},',',',|,'), ',')",
            "</when>",
            "  <if test=\"query.isExternalWarehouse != null and query.isExternalWarehouse.size()>0\">\n" +
                    "\n" +
                    "            <if test=\"query.isExternalWarehouse != null and query.isExternalWarehouse != '' and query.isExternalWarehouse.size()==1 \">\n" +
                    "                AND o.`is_external_warehouse` =\n" +
                    "                <foreach item='isExternalWarehouse' index=\"index\" collection='query.isExternalWarehouse' >\n" +
                    "                    #{isExternalWarehouse}\n" +
                    "                </foreach>\n" +
                    "            </if>\n" +
                    "\n" +
                    "            <if test=\"query.isExternalWarehouse != null and query.isExternalWarehouse != '' and query.isExternalWarehouse.size()>1 \">\n" +
                    "                AND o.`is_external_warehouse` in\n" +
                    "                <foreach item='isExternalWarehouse' index=\"index\" collection='query.isExternalWarehouse' open='(' separator=',' close=')'>\n" +
                    "                    #{isExternalWarehouse}\n" +
                    "                </foreach>\n" +
                    "            </if>\n" +
                    "\n" +
                    "        </if>",
//            "<when test = 'query.isExternalWarehouse != null'>",
//            "AND o.`is_external_warehouse` = #{query.isExternalWarehouse}",
//            "</when>",
            " <if test=\"query.statusList != null and query.statusList.size()>0\">\n" +
                    "\n" +
                    "            <if test=\"query.statusList != null and query.statusList != '' and query.statusList.size()==1 \">\n" +
                    "                AND o.`status` =\n" +
                    "                <foreach item='status' index=\"index\" collection='query.statusList' >\n" +
                    "                    #{status}\n" +
                    "                </foreach>\n" +
                    "            </if>\n" +
                    "\n" +
                    "            <if test=\"query.statusList != null and query.statusList != '' and query.statusList.size()>1 \">\n" +
                    "                AND o.`status` in\n" +
                    "                <foreach item='status' index=\"index\" collection='query.statusList' open='(' separator=',' close=')'>\n" +
                    "                    #{status}\n" +
                    "                </foreach>\n" +
                    "            </if>\n" +
                    "\n" +
                    "        </if>",
//            "<when test = 'query.status != null'>",
//            "AND o.`status` = #{query.status}",
//            "</when>",
            " <if test=\"query.abnormalState != null and query.abnormalState.size()>0\">\n" +
                    "\n" +
                    "            <if test=\"query.abnormalState != null and query.abnormalState != '' and query.abnormalState.size()==1 \">\n" +
                    "\n" +
                    "                <foreach item='abnormalState' index=\"index\" collection='query.abnormalState' >\n" +
                    "\n" +
                    "                                <choose>\n" +
                    "                                    <when test=\"abnormalState != '0'\">\n" +
                    "                                        <choose>\n" +
                    "                                            <when test=\"abnormalState != '-1'\">\n" +
                    "                                                AND o.`abnormal_state` = #{abnormalState}\n" +
                    "                                            </when>\n" +
                    "                                            <otherwise>\n" +
                    "                                                AND o.`abnormal_state` != 0\n" +
                    "                                            </otherwise>\n" +
                    "                                        </choose>\n" +
                    "                                    </when>\n" +
                    "                                    <otherwise>\n" +
                    "                                        AND o.`abnormal_state` = 0\n" +
                    "                                    </otherwise>\n" +
                    "                                </choose>\n" +
                    "                </foreach>\n" +
                    "            </if>\n" +
                    "\n" +
                    "            <if test=\"query.abnormalState != null and query.abnormalState != '' and query.abnormalState.size()>1 \">\n" +
                    "                  AND (1!=1\n" +
                    "                <foreach item='abnormalState' index=\"index\" collection='query.abnormalState'>\n" +
                    "\n" +
                    "                    <choose>\n" +
                    "                        <when test=\"abnormalState != '0'\">\n" +
                    "                            <choose>\n" +
                    "                                <when test=\"abnormalState != '-1'\">\n" +
                    "                                    OR o.`abnormal_state` = #{abnormalState}\n" +
                    "                                </when>\n" +
                    "                                <otherwise>\n" +
                    "                                    OR o.`abnormal_state` != 0\n" +
                    "                                </otherwise>\n" +
                    "                            </choose>\n" +
                    "                        </when>\n" +
                    "                        <otherwise>\n" +
                    "                            OR o.`abnormal_state` = 0\n" +
                    "                        </otherwise>\n" +
                    "                    </choose>\n" +
                    "                </foreach>\n" +
                    "\n" +
                    "                )\n" +
                    "            </if>\n" +
                    "\n" +
                    "        </if>",
//            "<when test = 'query.abnormalState != null'>",
//            "<choose>",
//            "<when test = 'query.abnormalState != 0'>",
//            "<choose>",
//            "<when test = '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>",
//            "</when>",
            "<when test = 'query.inWarehouseState != null'>",
            "AND o.`in_warehouse_state` = #{query.inWarehouseState}",
            "</when>",
            "<when test = 'query.shipmentState != null'>",
            "AND o.`shipment_State` = #{query.shipmentState}",
            "</when>",
            " <if test=\"query.auditType != null and query.auditType.size()>0\">\n" +
                    "\n" +
                    "            <if test=\"query.auditType != null and query.auditType != '' and query.auditType.size()==1 \">\n" +
                    "\n" +
                    "                <foreach item='auditType' index=\"index\" collection='query.auditType' >\n" +
                    "\n" +
                    "                    <choose>\n" +
                    "                        <when test=\"auditType != 0\">\n" +
                    "                            <choose>\n" +
                    "                                <when test=\"auditType != -1\">\n" +
                    "                                    AND o.`audit_type` = #{auditType}\n" +
                    "                                </when>\n" +
                    "                                <otherwise>\n" +
                    "                                    AND o.`audit_type` != 0\n" +
                    "                                </otherwise>\n" +
                    "                            </choose>\n" +
                    "                        </when>\n" +
                    "                        <otherwise>\n" +
                    "                            AND o.`audit_type` = 0\n" +
                    "                        </otherwise>\n" +
                    "                    </choose>\n" +
                    "                </foreach>\n" +
                    "            </if>\n" +
                    "        </if>",
//            "<when test = 'query.auditType != null'>",
//            "<choose>",
//            "<when test = 'query.auditType != 0'>",
//            "<choose>",
//            "<when test = '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>",
//            "</when>",
            "<when test = '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} ))",
            "</when>",
//            "<when test = 'query.customsType != null'>",
//            "AND o.`customs_type` = #{query.customsType}",
//            "</when>",
//            "<when test = 'query.productRecord != null'>",
//            "AND o.`product_record` = #{query.productRecord}",
//            "</when>",
            " <if test=\"query.customsType != null and query.customsType.size()>0\">\n" +
                    "\n" +
                    "            <if test=\"query.customsType != null and query.customsType != '' and query.customsType.size()==1 \">\n" +
                    "                AND o.`customs_type` =\n" +
                    "                <foreach item='customsType' index=\"index\" collection='query.customsType' >\n" +
                    "                    #{customsType}\n" +
                    "                </foreach>\n" +
                    "            </if>\n" +
                    "\n" +
                    "            <if test=\"query.customsType != null and query.customsType != '' and query.customsType.size()>1 \">\n" +
                    "                AND o.`customs_type` in\n" +
                    "                <foreach item='customsType' index=\"index\" collection='query.customsType' open='(' separator=',' close=')'>\n" +
                    "                    #{customsType}\n" +
                    "                </foreach>\n" +
                    "            </if>\n" +
                    "\n" +
                    "        </if>\n" +
                    "\n" +
                    "\n" +
                    "        <if test=\"query.productRecord != null and query.productRecord.size()>0\">\n" +
                    "\n" +
                    "            <if test=\"query.productRecord != null and query.productRecord != '' and query.productRecord.size()==1 \">\n" +
                    "                AND o.`product_record` =\n" +
                    "                <foreach item='productRecord' index=\"index\" collection='query.productRecord' >\n" +
                    "                    #{productRecord}\n" +
                    "                </foreach>\n" +
                    "            </if>\n" +
                    "\n" +
                    "            <if test=\"query.productRecord != null and query.productRecord != '' and query.productRecord.size()>1 \">\n" +
                    "                AND o.`product_record` in\n" +
                    "                <foreach item='productRecord' index=\"index\" collection='query.productRecord' open='(' separator=',' close=')'>\n" +
                    "                    #{productRecord}\n" +
                    "                </foreach>\n" +
                    "            </if>\n" +
                    "\n" +
                    "        </if>",
            "<when test = 'query.transportId != null'>",
            "AND o.`transport_id` = #{query.transportId}",
            "</when>",
            "<when test = 'query.channelId != null'>",
            "AND o.`channel_id` = #{query.channelId}",
            "</when>",
//            "<when test = 'query.warehouseType != null'>",
//            "AND o.`warehouse_type` = #{query.warehouseType}",
//            "</when>",
            " <if test=\"query.warehouseType != null and query.warehouseType.size()>0\">\n" +
                    "\n" +
                    "            <if test=\"query.warehouseType != null and query.warehouseType != '' and query.warehouseType.size()==1 \">\n" +
                    "                AND o.`warehouse_type` =\n" +
                    "                <foreach item='warehouseType' index=\"index\" collection='query.warehouseType' >\n" +
                    "                     #{warehouseType}\n" +
                    "                </foreach>\n" +
                    "            </if>\n" +
                    "\n" +
                    "            <if test=\"query.warehouseType != null and query.warehouseType != '' and query.warehouseType.size()>1 \">\n" +
                    "                AND o.`warehouse_type` in\n" +
                    "                <foreach item='warehouseType' index=\"index\" collection='query.warehouseType' open='(' separator=',' close=')'>\n" +
                    "                    #{warehouseType}\n" +
                    "                </foreach>\n" +
                    "            </if>\n" +
                    "\n" +
                    "        </if>",
            "<when test = '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},'%'))))))",
            "</when>",
            "<when test = '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},'%')))))",
            "</when>",
            "<when test = 'query.marks != null and query.marks != \"\" '>",
            "AND o.`marks` like concat('%',concat(#{query.marks},'%'))",
            "</when>",
            "<when test = 'query.departureId != null '>",
            "AND de.`departure_id` = #{query.departureId}",
            "</when>",
//            "<when test = 'query.objectiveId != null '>",
//            "AND ob.`objective_id` = #{query.objectiveId}",
//            "</when>",
            "<when test= 'query.objectiveId != null and query.objectiveId.size() > 0'>",
            "AND ob.`objective_id` IN",
            "<foreach item='objectiveId' collection='query.objectiveId' open='(' close=')' separator=','> #{objectiveId} </foreach>",
            "</when>",
            "<if test=\"query.destCountryId != null \">\n" +
                    "            AND ob.`objective_country_id` in\n" +
                    "            <foreach item='destCountryId' index='index' collection='query.destCountryId' open='(' separator=',' close=')'>\n" +
                    "                #{destCountryId}\n" +
                    "            </foreach>\n" +
                    "        </if>",
            "<when test = 'query.consignorId != null '>",
            "AND nor.`customer_id` = #{query.consignorId} ",
            "</when>",
            "<when test = 'query.consignorPhone != null and query.consignorPhone != \"\"  '>",
            "AND nor.`phone` = #{query.consignorPhone} ",
            "</when>",
            "<when test = 'query.consigneeId != null '>",
            "AND nee.`customer_id` = #{query.consigneeId}",
            "</when>",
            "<when test = 'query.consigneePhone != null and query.consigneePhone != \"\"  '>",
            "AND nee.`phone` = #{query.consigneePhone} ",
            "</when>",
            "<when test = 'query.isCargoControl != null '>",
            "AND o.`is_cargo_control` = #{query.isCargoControl}",
            "</when>",
            "<when test = 'query.orderNo != null and query.orderNo != \"\" '>",
            "AND o.`order_no` like concat('%',concat(#{query.orderNo},'%'))",
            "</when>",
            "<when test = 'query.orderIdList != null and query.orderIdList.size() != 0'>",
            "AND o.`order_id` in ",
            "<foreach item='orderId' index='index' collection='query.orderIdList' open='(' separator=',' close=')'>#{orderId}</foreach> ",
            "</when>",
            "<when test = 'query.tidanNo != null and query.tidanNo != \"\" '>",
            "AND o.`tidan_no` like concat('%',concat(#{query.tidanNo},'%'))",
            "</when>",
            "<when test = 'query.customerId != null'>",
            "AND o.`customer_id` = #{query.customerId}",
            "</when>",
            "<when test = 'query.beginRucangTime != null and query.endRucangTime != null '>",
//            "AND o.`rucang_time` between #{query.beginRucangTime} and #{query.endRucangTime}",
            "AND o.order_id in(select distinct wi.order_id from ecw_order_warehouse_in wi where wi.deleted = 0 and wi.`in_time` between #{query.beginRucangTime} and #{query.endRucangTime})",
            "</when>",
            "<when test = 'query.beginQingguanTime != null and query.endQingguanTime != null '>",
            "AND o.`qingguan_time` between #{query.beginQingguanTime} and #{query.endQingguanTime}",
            "</when>",
            "<when test = 'query.beginDaogangTime != null and query.endDaogangTime != null '>",
            "AND o.`daogang_time` between #{query.beginDaogangTime} and #{query.endDaogangTime}",
            "</when>",
            "<when test = 'query.beginPreLoadTime != null and query.endPreLoadTime != null '>",
            "AND o.`status` > 5 AND o.`pre_load_time` between #{query.beginPreLoadTime} and #{query.endPreLoadTime}",
            "</when>",
            "<when test = 'query.beginOutboundTime != null and query.endOutboundTime != null '>",
            "AND o.`status` > 5 AND o.container_number in(select distinct b.self_no from ecw_box_air_checkout bc join ecw_box b ON bc.shipment_id = b.id",
            "where b.deleted = 0 and bc.deleted = 0 and bc.`checkout_time` between #{query.beginOutboundTime} and #{query.endOutboundTime})",
            "</when>",
            "<when test = 'query.beginLoadTime != null and query.endLoadTime != null '>",
            "AND o.`load_time` between #{query.beginLoadTime} and #{query.endLoadTime}",
            "</when>",
            "<when test = 'query.beginUnloadTime != null and query.endUnloadTime != null '>",
            "AND o.`unload_time` between #{query.beginUnloadTime} and #{query.endUnloadTime}",
            "</when>",
            "<when test = 'query.beginTakeTime != null and query.endTakeTime != null '>",
            "AND o.`status` > 19 AND o.`take_time` between #{query.beginTakeTime} and #{query.endTakeTime}",
            "</when>",
            "<when test = 'query.beginSplitTime != null and query.endSplitTime != null '>",
            "AND o.`split_time` between #{query.beginSplitTime} and #{query.endSplitTime}",
            "</when>",
            "<when test = 'query.beginCreateTime != null and query.endCreateTime != null '>",
            "AND o.`create_time` between #{query.beginCreateTime} and #{query.endCreateTime}",
            "</when>",
            "<when test = 'query.beginPickTime != null and query.endPickTime != null '>",
            "AND o.order_id in(select distinct op.order_id from ecw_order_cargo_control_pick op where op.deleted = 0 and op.status in(1,3) and op.`create_time` between #{query.beginPickTime} and #{query.endPickTime})",
            "</when>",
            "and op.`create_time` between #{query.beginPickUpTime} and #{query.endPickUpTime}",
            "<when test = 'query.creator != null and query.creator != \"\" '>",
            "AND o.`creator` = #{query.creator}",
            "</when>",
            "<when test = 'query.searchKey != null and query.searchKey != \"\" '>",
            "AND concat(IFNULL(o.`order_no`,''), IFNULL(o.`old_numbers`,'') ,IFNULL(o.`marks`,''),IFNULL(o.`tidan_no`,''),IFNULL(o.`container_number`,''),IFNULL(nee.`name`,''),IFNULL(nee.`phone`,'')) like concat('%',concat(#{query.searchKey},'%'))",
            "</when>",
            "<when test = '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},'%'))))",
            "</when>",
            "<when test = 'query.notConsignorKey != null and query.notConsignorKey != \"\" '>",
            "AND (concat(IFNULL(nor.`name`,''),IFNULL(nor.`name_en`,''),IFNULL(nor.`phone`,'')) not like concat('%',concat(#{query.notConsignorKey},'%'))",
            "AND nor.customer_id not in (select c.id from ecw_customer c where c.number like concat('%',concat(#{query.notConsignorKey},'%'))))",
            "</when>",
            "<when test = '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},'%'))))",
            "</when>",
            "<when test = 'query.notConsigneeKey != null and query.notConsigneeKey != \"\" '>",
            "AND (concat(IFNULL(nee.`name`,''),IFNULL(nee.`name_en`,''),IFNULL(nee.`phone`,'')) not like concat('%',concat(#{query.notConsigneeKey},'%'))",
            "AND nee.customer_id not in (select c.id from ecw_customer c where c.number like concat('%',concat(#{query.notConsigneeKey},'%'))))",
            "</when>",
            "<when test = 'query.numberKey != null and query.numberKey != \"\" '>",
            "AND concat(IFNULL(o.`order_no`,''), IFNULL(o.`old_numbers`,''), IFNULL(o.`parent_number`,''), IFNULL(o.`initial_parent_order_no`,'') ,IFNULL(o.`marks`,''),IFNULL(o.`tidan_no`,''),IFNULL(o.`container_number`,''),IFNULL(o.`no_charge_record`,'')) like concat('%',concat(#{query.numberKey},'%'))",
            "</when>",
            "<when test = 'query.notNumberKey != null and query.notNumberKey != \"\" '>",
            "AND concat(IFNULL(o.`order_no`,''), IFNULL(o.`old_numbers`,''), IFNULL(o.`parent_number`,''), IFNULL(o.`initial_parent_order_no`,'') ,IFNULL(o.`marks`,''),IFNULL(o.`tidan_no`,''),IFNULL(o.`container_number`,''),IFNULL(o.`no_charge_record`,'')) not like concat('%',concat(#{query.notNumberKey},'%'))",
            "</when>",
            "<when test = 'query.eqNumberKey != null and query.eqNumberKey != \"\" '>",
            "AND (o.`order_no` = #{query.eqNumberKey}",
            "or (o.`old_numbers` is not null and o.`old_numbers` != '' and o.`old_numbers` = #{query.eqNumberKey}) ",
            "or (o.`parent_number` is not null and o.`parent_number` != '' and o.`parent_number` = #{query.eqNumberKey}) ",
            "or (o.`marks` is not null and o.`marks` != '' and o.`marks` = #{query.eqNumberKey}) ",
            "or (o.`tidan_no` is not null and o.`tidan_no` != '' and o.`tidan_no` = #{query.eqNumberKey}) ",
            "or (o.`container_number` is not null and o.`container_number` != '' and o.`container_number` = #{query.eqNumberKey}) ",
            "or (o.`no_charge_record` is not null and o.`no_charge_record` != '' and o.`no_charge_record` = #{query.eqNumberKey}))",
            "</when>",
            "<when test = 'query.notEqNumberKey != null and query.notEqNumberKey != \"\" '>",
            "AND o.`order_no` != #{query.notEqNumberKey}",
            "AND (o.`old_numbers` is null or o.`old_numbers` = '' or o.`old_numbers` != #{query.notEqNumberKey})",
            "AND (o.`parent_number` is null or o.`parent_number` = '' or o.`parent_number` != #{query.notEqNumberKey})",
            "AND (o.`marks` is null or o.`marks` = '' or o.`marks` != #{query.notEqNumberKey})",
            "AND (o.`tidan_no` is null or o.`tidan_no` = '' or o.`tidan_no` != #{query.notEqNumberKey})",
            "AND (o.`container_number` is null or o.`container_number` = '' or o.`container_number` != #{query.notEqNumberKey})",
            "AND (o.`no_charge_record` is null or o.`no_charge_record` = '' or o.`no_charge_record` != #{query.notEqNumberKey})",
            "</when>",
            "<when test = 'query.prodKey != null and query.prodKey != \"\" '>",
            "and (o.order_id in(",
            "select oi.order_id ",
            "from ecw_order_item oi ",
            "left join ecw_product p ",
            "on oi.prod_id = p.id ",
            "left join ecw_product_type pt ",
            "on pt.id = oi.prod_type ",
            "left join ecw_product_brank pb",
            "on pb.id = oi.brand",
            "where oi.deleted = 0 ",
            "and concat(IFNULL(oi.`prod_title_zh`,''),IFNULL(oi.`prod_title_en`,''),IFNULL(pt.`title_zh`,''),IFNULL(pt.`title_en`,''),IFNULL(pb.`title_zh`,''),IFNULL(pb.`title_en`,''))",
            "like concat('%',concat(#{query.prodKey},'%'))",
            "))",
            "</when>",
            "<when test = 'query.notProdKey != null and query.notProdKey != \"\" '>",
            "and (o.order_id not in(",
            "select oi.order_id ",
            "from ecw_order_item oi ",
            "left join ecw_product p ",
            "on oi.prod_id = p.id ",
            "left join ecw_product_type pt ",
            "on pt.id = oi.prod_type ",
            "left join ecw_product_brank pb",
            "on pb.id = oi.brand",
            "where oi.deleted = 0 and concat(IFNULL(oi.`prod_title_zh`,''),IFNULL(oi.`prod_title_en`,''),IFNULL(pt.`title_zh`,''),IFNULL(pt.`title_en`,''),IFNULL(pb.`title_zh`,''),IFNULL(pb.`title_en`,'')) " ,
            "like concat('%',concat(#{query.notProdKey},'%'))",
            "))",
            "</when>",
            "<when test = 'query.eqProdKey != null and query.eqProdKey != \"\" '>",
            "and (o.order_id in(",
            "select oi.order_id ",
            "from ecw_order_item oi ",
            "left join ecw_product p ",
            "on oi.prod_id = p.id ",
            "left join ecw_product_type pt ",
            "on pt.id = oi.prod_type ",
            "left join ecw_product_brank pb",
            "on pb.id = oi.brand",
            "where oi.deleted = 0 " ,
            "and (oi.`prod_title_zh` = #{query.eqProdKey} or oi.`prod_title_en` = #{query.eqProdKey} " ,
            "or pt.`title_zh` = #{query.eqProdKey} or pt.`title_en` = #{query.eqProdKey}",
            "or pb.`title_zh` = #{query.eqProdKey} or pb.`title_en` = #{query.eqProdKey})",
            "))",
            "</when>",
            "<when test = 'query.notEqProdKey != null and query.notEqProdKey != \"\" '>",
            "and (o.order_id not in(",
            "select oi.order_id ",
            "from ecw_order_item oi ",
            "left join ecw_product p ",
            "on oi.prod_id = p.id ",
            "left join ecw_product_type pt ",
            "on pt.id = oi.prod_type ",
            "left join ecw_product_brank pb",
            "on pb.id = oi.brand",
            "where oi.deleted = 0" ,
            "and (oi.`prod_title_zh` = #{query.notEqProdKey} or oi.`prod_title_en` = #{query.notEqProdKey} " ,
            "or pt.`title_zh` = #{query.notEqProdKey} or pt.`title_en` = #{query.notEqProdKey}",
            "or pb.`title_zh` = #{query.notEqProdKey} or pb.`title_en` = #{query.notEqProdKey})",
            "))",
            "</when>",
//            "<when test = 'query.startWarehouseId != null and query.destWarehouseId != null '>",
//            "and (o.line_id in(",
//            "select whl.id ",
//            "from ecw_warehouse_line whl ",
//            "where whl.start_warehouse_id = #{query.startWarehouseId} and whl.dest_warehouse_id = #{query.destWarehouseId} ",
//            "))",
//            "</when>",
//            "<when test = 'query.startWarehouseId != null and query.destWarehouseId == null '>",
//            "and (o.line_id in(",
//            "select whl.id ",
//            "from ecw_warehouse_line whl ",
//            "where whl.start_warehouse_id = #{query.startWarehouseId}  ",
//            "))",
//            "</when>",
//            "<when test = 'query.startWarehouseId == null and query.destWarehouseId != null '>",
//            "and (o.line_id in(",
//            "select whl.id ",
//            "from ecw_warehouse_line whl ",
//            "where whl.dest_warehouse_id = #{query.destWarehouseId} ",
//            "))",
//            "</when>",
            " <if test=\"query.startWarehouseIds !=null and query.destWarehouseIds !=null  \">\n" +
                    "            and (o.line_id in(\n" +
                    "            select whl.id\n" +
                    "            from ecw_warehouse_line whl\n" +
                    "            where whl.start_warehouse_id in\n" +
                    "            <foreach item='warehouseId'  collection='query.startWarehouseIds' open='(' separator=',' close=')'>\n" +
                    "                #{warehouseId}\n" +
                    "            </foreach>\n" +
                    "\n" +
                    "            and whl.dest_warehouse_id in\n" +
                    "            <foreach item='destWarehouseId'  collection='query.destWarehouseIds' open='(' separator=',' close=')'>\n" +
                    "                #{destWarehouseId}\n" +
                    "            </foreach>\n" +
                    "\n" +
                    "            ))\n" +
                    "        </if>\n" +
                    "        <if test=\"query.startWarehouseIds !=null and query.destWarehouseIds==null\">\n" +
                    "            and (o.line_id in(\n" +
                    "            select whl.id\n" +
                    "            from ecw_warehouse_line whl\n" +
                    "            where whl.start_warehouse_id in\n" +
                    "            <foreach item='warehouseId'  collection='query.startWarehouseIds' open='(' separator=',' close=')'>\n" +
                    "                #{warehouseId}\n" +
                    "            </foreach>\n" +
                    "            ))\n" +
                    "        </if>\n" +
                    "        <if test=\"query.startWarehouseIds ==null and query.destWarehouseIds !=null  \">\n" +
                    "            and (o.line_id in(\n" +
                    "            select whl.id\n" +
                    "            from ecw_warehouse_line whl\n" +
                    "            where  whl.dest_warehouse_id  in\n" +
                    "            <foreach item='destWarehouseId'  collection='query.destWarehouseIds' open='(' separator=',' close=')'>\n" +
                    "                #{destWarehouseId}\n" +
                    "            </foreach>\n" +
                    "\n" +
                    "\n" +
                    "            ))\n" +
                    "        </if>",
            "<when test = 'query.airShipment != null and query.airShipment == 1'>",
            "AND o.`status` = 5 AND o.air_shipment = 1 and abnormal_state = 0 and audit_type = 0 ",
            "</when>",
            "<when test = 'query.airShipment != null and query.airShipment == 2'>",
            "AND o.`status` = 5  AND o.air_shipment = 2",
            "</when>",
            "<when test = 'query.airShipment != null and query.airShipment == 3'>",
            "AND o.`status` = 5  AND o.air_shipment = 3",
            "</when>",
            "<when test = 'query.airShipment != null and query.airShipment == 4'>",
            "AND o.`status` = 5  AND o.air_shipment = 4",
            "</when>",
            "<when test = 'query.airShipment != null and query.airShipment == 10'>",
            "AND o.`status` = 5 AND o.air_shipment in(2,3,4)",
            "</when>",
            "<when test = 'query.airShipment != null and query.airShipment == 11'>",
            "AND o.`status` = 5  AND o.air_shipment in(1,2,3,4) and abnormal_state = 0 and audit_type = 0 ",
            "</when>",
            "<when test = 'query.airShipment != null and query.airShipment == 12'>",
            "AND o.`status` = 5  AND o.air_shipment in(2,3) and abnormal_state = 0 and audit_type = 0 ",
            "</when>",
            "<when test = 'query.airShipment != null and query.airShipment == 20'>",
            "AND o.`status` = 5  AND o.air_shipment in(0,2,3,4) and abnormal_state = 0 and audit_type = 0 ",
            "</when>",
            "<when test = 'query.isNeat == false  '>",
            " AND o.sum_num  <![CDATA[ < ]]> o.cost->>'$.totalNum' ",
            "</when>",
            "<when test = 'query.isNeat == true  '>",
            " AND o.sum_num  = o.cost->>'$.totalNum' ",
            "</when>",
            "<when test = 'query.customerDetailId != null'>",
            "AND (o.`customer_id` = #{query.customerDetailId} or nor.`customer_id` = #{query.customerDetailId}  or nee.`customer_id` = #{query.customerDetailId})",
            "</when>",
            "<when test = 'query.userType == 2 '>",
            "</when>",
            "</script>"
    })
    StatisticsOrderVO statisticsMyPickUp(@Param("query") OrderQueryVO query);

    @ResultType(OrderDO.class)
    @Select({
            "select * from ecw_order where parent_order_id = #{parentOrderId}"
    })
    List<OrderDO> orderChildren(@Param("parentOrderId") Long parentOrderId);

    @ResultType(OrderDO.class)
    @Select({
            "select * from ecw_order where order_id = #{orderId}"
    })
    OrderDO getOrderById(@Param("orderId") Long orderId);

    @ResultType(Long.class)
    @Select({
            "select distinct salesman_id from ecw_order where customer_id = #{customerId} and salesman_id is not null and salesman_id > 0"
    })
    List<Long> getOrderCustomerServiceByCustomerId(Long customerId);

    void remove(@Param("orderIds") List<Long> orderIds);


    @ResultType(OrderDO.class)
    @Select({
            "select o.* from ecw_order o ",
            "inner join ecw_order_consignee nee on o.order_id = nee.order_id ",
            "inner join ecw_order_consignor nor on o.order_id = nor.order_id",
            "inner join ecw_customer c on nor.customer_id = c.id ",
            "where o.deleted = 0 and nee.deleted = 0 and nor.deleted = 0 and c.deleted = 0  ",
            "and o.status = 2 and o.user_id is not null ",
            "and DATEDIFF(now(), o.create_time) > #{day} and (nee.customer_id is null or nee.customer_id = 0 or nee.customer_contacts_id is null or nee.customer_contacts_id = 0)",
            "and !FIND_IN_SET('2', c.type) and !FIND_IN_SET('3', c.type) ",
            "and not exists(",
            "	select 1 from ecw_customer_contacts cc where cc.deleted = 0 and cc.area_code = nee.country_code and cc.phone_new = nee.phone",
            ")"
    })
    List<OrderDO> getNoConsigeeCustomerOrderList(@Param("day") Integer day);

    @ResultType(OrderDO.class)
    @Select({
            "select * from ecw_order where order_no like concat(#{orderNoLike},'%')"
    })
    List<OrderDO> getOrderChildrenLikeByOrderNo(@Param("orderNoLike") String orderNoLike);

    @ResultType(OrderPreloadVO.class)
    @Select({
            "<script>",
            "SELECT eo.order_id, ",
            "eo.order_no, ",
            "eo.adjust_to_dest_warehouse_id, ",
            "eo.transport_id, ",
            "eo.line_id, ",
            "ewl.start_warehouse_id, ",
            "ewl.dest_warehouse_id, ",
            "eo.channel_id, ",
            "eo.STATUS, ",
            "eo.abnormal_state, ",
            "eo.in_warehouse_state, ",
            "eo.warehouse_type, ",
            "eo.weight_ratio, ",
            "eo.product_record, ",
            "eo.port_dest_customs_clear, ",
            "eo.is_external_warehouse, ",
            "eo.marks, ",
            "eo.air_shipment, ",
            "eo.customs_type, ",
            "if(#{query.lang} = 0, ew_start.title_zh, ew_start.title_en) as start_warehouse_name, ",
            "if(#{query.lang} = 0, ew_dest.title_zh, ew_dest.title_en) as dest_warehouse_name, ",
            "(select min(owi.`in_time`) from ecw_order_warehouse_in owi where owi.deleted = 0 and owi.order_id = eo.order_id ) as rucang_time,",  //eo.rucang_time,
            "eo.parent_order_id, ",
            "eo.guan_lian_order_status, ",
            "#{query.lang} as lang, ",
            "count(eo.order_id) match_item_count",
            "FROM ecw_order eo, ",
            "ecw_order_item eoi, ",
            "ecw_warehouse_line ewl, ",
            "ecw_warehouse ew_start, ",
            "<when test = 'query.relationId != null'>",
            "ecw_order_consignee consignee, ",
            "</when>",
            "ecw_warehouse ew_dest ",
            "WHERE eo.order_id = eoi.order_id ",
            "and eo.line_id = ewl.id ",
            "and ewl.start_warehouse_id = ew_start.id ",
            "and ewl.dest_warehouse_id = ew_dest.id ",
            "and eo.deleted=0 ",
            "and eo.air_shipment in (2,3,4) ",
            "and eo.status in (5,8,9) ",
            "and eo.transport_id = 3",
            "and eo.in_warehouse_state not in (203,204,207,208,209,211,212) ",
            "and eo.abnormal_state=0 ",
            "and eo.audit_type=0 ",
            "<when test = 'query.rucangTimeStart != null'>",
            "AND eo.`rucang_time` &gt;= #{query.rucangTimeStart}",
            "</when>",
            "<when test = 'query.rucangTimeEnd != null'>",
            "AND eo.`rucang_time` &lt;= #{query.rucangTimeEnd}",
            "</when>",
            "<when test = 'query.productRecord != null'>",
            "AND eoi.`fee_type` = #{query.productRecord}",
            "</when>",
            "<when test = 'query.orderNo != null and query.orderNo != \"\" '>",
            "AND eo.`order_no` like concat('%',concat(#{query.orderNo},'%'))",
            "</when>",
            "<when test = 'query.customsType != null '>",
            "AND eo.`customs_type` = #{query.customsType}",
            "</when>",
            "<when test = 'query.weightRatioMin != null '>",
            "AND eo.`weight_ratio` &gt;= #{query.weightRatioMin}",
            "</when>",
            "<when test = 'query.weightRatioMax != null '>",
            "AND eo.`weight_ratio` &lt;= #{query.weightRatioMax} ",
            "</when>",
            "<when test = 'query.transportType != null'>",
            "AND eo.`transport_id` = #{query.transportType}",
            "</when>",
            "<when test = 'query.channelId != null and query.channelId != \"\" '>",
            "AND eo.`channel_id` = #{query.channelId}",
            "</when>",
            "<when test = 'query.airShipment != null'>",
            "AND eo.`status` = 5 AND eo.`air_shipment` = #{query.airShipment}",
            "</when>",
            "<when test = 'query.relationId != null'>",
            "AND consignee.`order_id` = eo.order_id AND consignee.`relation_id` = #{query.relationId}",
            "</when>",
//            "<when test = 'query.startWarehouseId != null'>",
//            "AND ewl.`start_warehouse_id` = #{query.startWarehouseId}",
//            "</when>",
            "<when test = 'query.destWarehouseIdList != null and query.destWarehouseIdList.size()!=0'>",
            "AND ewl.`dest_warehouse_id` in ",
            "<foreach item='id' index='index' collection='query.destWarehouseIdList' open='(' separator=',' close=')'>#{id}</foreach>",
            "</when>",
            "<when test = 'query.itemName != null and query.itemName != \"\" '>",
            "AND (eoi.`prod_title_zh` like concat('%',concat(#{query.itemName},'%')) or eoi.`prod_title_en` like concat('%',concat(#{query.itemName},'%')) )",
            "</when>",
            "GROUP BY eo.order_id",
            "</script>"
    })
    List<OrderPreloadVO> orderPreloadListAir(@Param("query") OrderPreloadReq query);

    @ResultType(String.class)
    @Select({
            "select t.guojia from ecw_warehouse t where id =(select s.id from ecw_warehouse_line s where s.id=(select o.line_id from ecw_order o where o.order_id=#{orderId}))"
    })
    String getDestCountryByOrderId(@Param("orderId") Long orderId);

    List<OrderDO> getAirRefreshOrderPrice(@Param("transportIdList") List<Integer> transportIdList);

    @ResultType(String.class)
    @Select({"SELECT order_id FROM ecw_order WHERE deleted = 0 AND order_no = #{orderNo} "})
    Long getOrderIdByOrderNo(@Param("orderNo") String  orderNo);

    @Update("update ecw_order set sum_cartons_num_prev_packed = sum_num, sum_quantity_all_prev_packed = sum_quantity, sum_weight_prev_packed = sum_weight, sum_volume_prev_packed = sum_volume  where order_id = #{orderId}")
    void updateSumDataPrevPacked(@Param("orderId") Long orderId);


    /*
     更新订单业绩类型 yeji_type,yeji_create_date,cal_v_value
     */
    @Update("update ecw_order set yeji_type=#{yejiType} where order_id = #{orderId}")
    void UpdateOrderYeJiType(@Param("orderId") Long orderId,
                             @Param("yejiType") int yejiType);


    /*
     更新订单V值
     yeji_create_date 业绩产生时间
     简单的SQL语句用SQL注解来写比较方便
     */
    @Update("update ecw_order set cal_v_value=#{calVvalue},yeji_create_date=#{yejiCreateDate} where order_id = #{orderId}")
    void UpdateOrderVValue(@Param("orderId") Long orderId,
                           @Param("calVvalue") BigDecimal calVvalue,
                           @Param("yejiCreateDate") Date yejiCreateDate);

    @Update("update ecw_order set salesman_id=#{salesman_id} where order_id = #{orderId}")
    void updateOrderSalesmanId(@Param("orderId") Long orderId,
                               @Param("salesman_id") Long salesman_id);

    /**
     * 报价结果赢单时，同步业绩归属
     * @param customerId
     * @param salesmanId
     * @param orderId
     */
    @Update("update ecw_order set customer_id=#{customerId},salesman_id=#{salesmanId} where order_id = #{orderId}")
    void updateOrderCustomerAndSalesmanId(@Param("customerId")Long customerId,@Param("salesmanId") Long salesmanId,@Param("orderId") Long orderId);
}
