49 lines
4.1 KiB
Java
49 lines
4.1 KiB
Java
package com.baiyue.lastleg.appointmentplanning;
|
|
|
|
import org.apache.ibatis.annotations.Mapper;
|
|
import org.apache.ibatis.annotations.Param;
|
|
import org.apache.ibatis.annotations.Select;
|
|
import java.time.LocalDateTime;
|
|
import java.util.List;
|
|
|
|
@Mapper
|
|
public interface AppointmentCoverageMapper {
|
|
String DESTINATION_TYPE="CASE WHEN o.order_type='WAREHOUSE_TRANSFER' THEN wt.destination_type ELSE o.destination_type END";
|
|
String DESTINATION_CODE="CASE WHEN o.order_type='WAREHOUSE_TRANSFER' THEN wt.destination_warehouse_code ELSE o.fba_warehouse_code END";
|
|
String SHIPMENT_MISSING="CASE WHEN o.order_type='WAREHOUSE_TRANSFER' THEN (wt.id IS NULL OR ((wt.fba_shipment_no IS NULL OR TRIM(wt.fba_shipment_no)='') AND (wt.tracking_no IS NULL OR TRIM(wt.tracking_no)=''))) ELSE " +
|
|
"(NOT EXISTS(SELECT 1 FROM ll_order_detail d WHERE d.order_id=o.id AND d.customer_id=o.customer_id) OR EXISTS(SELECT 1 FROM ll_order_detail d WHERE d.order_id=o.id AND d.customer_id=o.customer_id AND (d.shipment_no IS NULL OR TRIM(d.shipment_no)='') AND (d.fba_tracking_no IS NULL OR TRIM(d.fba_tracking_no)=''))) END";
|
|
String TRANSFER_JOIN=" LEFT JOIN ll_warehouse_transfer_order wt ON o.order_type='WAREHOUSE_TRANSFER' AND wt.lastleg_order_id=o.id AND wt.customer_id=o.customer_id ";
|
|
record OrderRef(String customerId, Long orderId) { }
|
|
record Source(Long orderId, String customerId, String destinationType, String fbaWarehouseCode,
|
|
Integer packages, Integer version, LocalDateTime updatedAt, boolean shipmentReferencesMissing) { }
|
|
record Fact(Long orderId, String customerId, String appointmentNo, String status,
|
|
LocalDateTime appointmentAt, LocalDateTime appointmentEndAt, LocalDateTime updatedAt,
|
|
Long itemId, Integer packages, String warehouseCode,String sourceKey,String sourceVersion,
|
|
String confirmationNo,String timezone,Integer cargoVerificationVersion) { }
|
|
|
|
@Select({"<script>SELECT o.id AS orderId,o.customer_id AS customerId,"+DESTINATION_TYPE+" AS destinationType,",
|
|
DESTINATION_CODE+" AS fbaWarehouseCode,o.package_count AS packages,o.version,o.updated_at AS updatedAt, ",
|
|
SHIPMENT_MISSING+" AS shipmentReferencesMissing ",
|
|
"FROM ll_order o "+TRANSFER_JOIN+" WHERE <foreach collection='sources' item='s' open='(' separator=' OR ' close=')'>",
|
|
"(o.id=#{s.orderId} AND o.customer_id=#{s.customerId})</foreach></script>"})
|
|
List<Source> sources(@Param("sources") List<OrderRef> sources);
|
|
|
|
@Select({"<script>SELECT i.order_id AS orderId,i.customer_id AS customerId,a.appointment_no AS appointmentNo,",
|
|
"a.appointment_status AS status,a.appointment_at AS appointmentAt,a.appointment_end_at AS appointmentEndAt,",
|
|
"a.updated_at AS updatedAt,i.id AS itemId,i.package_count AS packages,i.fba_warehouse_code AS warehouseCode, ",
|
|
"i.source_key AS sourceKey,i.source_version AS sourceVersion,a.confirmation_no AS confirmationNo,a.timezone,i.cargo_verification_version AS cargoVerificationVersion ",
|
|
"FROM ll_inbound_fba_appointment_item i JOIN ll_inbound_fba_appointment a ON a.id=i.appointment_id ",
|
|
"WHERE i.active=1 AND a.appointment_status NOT IN ('FAILED','CANCELLED') AND ",
|
|
"<foreach collection='sources' item='s' open='(' separator=' OR ' close=')'>",
|
|
"(i.source_key=#{s.sourceKey} AND i.customer_id=#{s.customerId})</foreach>",
|
|
" ORDER BY a.appointment_at,a.id,i.id</script>"})
|
|
List<Fact> appointments(@Param("sources") List<AppointmentCoverageService.SourceRef> sources);
|
|
|
|
@Select({"<script>SELECT v.* FROM ll_appointment_cargo_verification v WHERE ",
|
|
"<foreach collection='sources' item='s' open='(' separator=' OR ' close=')'>",
|
|
"(v.source_key=#{s.sourceKey} AND v.customer_id=#{s.customerId})</foreach>",
|
|
" AND v.version=(SELECT MAX(latest.version) FROM ll_appointment_cargo_verification latest",
|
|
" WHERE latest.source_key=v.source_key AND latest.customer_id=v.customer_id)</script>"})
|
|
List<AppointmentCargoVerification> verifications(@Param("sources") List<AppointmentCoverageService.SourceRef> sources);
|
|
}
|