2026-08-19 16:24:02 +08:00
|
|
|
package com.baiyue.lastleg.mapper;
|
|
|
|
|
|
|
|
|
|
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
|
|
|
|
|
import com.baiyue.lastleg.entity.LastlegOrder;
|
2026-08-27 17:16:33 +08:00
|
|
|
import com.baiyue.lastleg.dto.LastlegOrderRequests;
|
|
|
|
|
import com.baiyue.lastleg.dto.PendingContainerSummary;
|
2026-08-19 16:24:02 +08:00
|
|
|
import org.apache.ibatis.annotations.Mapper;
|
|
|
|
|
import org.apache.ibatis.annotations.Param;
|
|
|
|
|
import org.apache.ibatis.annotations.Select;
|
|
|
|
|
import org.apache.ibatis.annotations.Update;
|
|
|
|
|
|
2026-08-27 17:16:33 +08:00
|
|
|
import java.util.List;
|
|
|
|
|
|
2026-08-19 16:24:02 +08:00
|
|
|
@Mapper
|
|
|
|
|
public interface LastlegOrderMapper extends BaseMapper<LastlegOrder> {
|
2026-08-27 17:16:33 +08:00
|
|
|
String PENDING_CONTAINER_FILTER = " FROM ll_order o " +
|
|
|
|
|
"WHERE o.source_container_booking_id IS NOT NULL AND o.source_container_booking_id<>'' " +
|
|
|
|
|
"<if test='q.containerNo != null and q.containerNo != \"\"'>AND o.container_no LIKE CONCAT('%',#{q.containerNo},'%') </if>" +
|
|
|
|
|
"<if test='q.createdFrom != null'>AND o.created_at >=#{q.createdFrom} </if>" +
|
|
|
|
|
"<if test='q.createdTo != null'>AND o.created_at <=#{q.createdTo} </if>" +
|
|
|
|
|
"GROUP BY o.source_container_booking_id " +
|
|
|
|
|
"HAVING SUM(CASE WHEN o.current_status IN ('PENDING_ASSIGNMENT','DESTINATION_ASSIGNED') THEN 1 ELSE 0 END)>0 ";
|
|
|
|
|
|
|
|
|
|
@Select("<script>SELECT o.source_container_booking_id AS sourceContainerBookingId," +
|
|
|
|
|
"CASE WHEN COUNT(DISTINCT NULLIF(o.container_no,''))=1 THEN MAX(NULLIF(o.container_no,'')) ELSE NULL END AS containerNo," +
|
|
|
|
|
"COUNT(*) AS orderCount,COUNT(DISTINCT o.inbound_code) AS inboundCodeCount," +
|
|
|
|
|
"COUNT(DISTINCT o.customer_id) AS customerCount,COALESCE(SUM(o.package_count),0) AS totalPackageCount," +
|
|
|
|
|
"COALESCE(SUM(o.pallet_count),0) AS totalPalletCount,COALESCE(SUM(o.volume_cbm),0) AS totalVolumeCbm," +
|
|
|
|
|
"CASE WHEN SUM(CASE WHEN o.current_status IN ('PENDING_ASSIGNMENT','DESTINATION_ASSIGNED') THEN 0 ELSE 1 END)=0 " +
|
|
|
|
|
"AND COUNT(NULLIF(o.container_no,''))=COUNT(*) AND COUNT(DISTINCT NULLIF(o.container_no,''))=1 " +
|
|
|
|
|
"THEN TRUE ELSE FALSE END AS eligible," +
|
|
|
|
|
"CASE WHEN COUNT(NULLIF(o.container_no,''))<>COUNT(*) " +
|
|
|
|
|
"OR COUNT(DISTINCT NULLIF(o.container_no,''))<>1 THEN '柜号缺失或不一致' " +
|
|
|
|
|
"WHEN SUM(CASE WHEN o.current_status IN ('PENDING_ASSIGNMENT','DESTINATION_ASSIGNED') THEN 0 ELSE 1 END)>0 " +
|
|
|
|
|
"THEN '柜内存在已生成计划或非待分配订单' ELSE NULL END AS ineligibleReason" +
|
|
|
|
|
PENDING_CONTAINER_FILTER +
|
|
|
|
|
"ORDER BY MAX(o.created_at) DESC,o.source_container_booking_id DESC LIMIT #{limit} OFFSET #{offset}</script>")
|
|
|
|
|
List<PendingContainerSummary> pagePendingContainers(@Param("q") LastlegOrderRequests.PendingContainerQuery query,
|
|
|
|
|
@Param("offset") long offset,
|
|
|
|
|
@Param("limit") long limit);
|
|
|
|
|
|
|
|
|
|
@Select("<script>SELECT COUNT(*) FROM (SELECT o.source_container_booking_id" +
|
|
|
|
|
PENDING_CONTAINER_FILTER + ") pending_containers</script>")
|
|
|
|
|
long countPendingContainers(@Param("q") LastlegOrderRequests.PendingContainerQuery query);
|
|
|
|
|
|
2026-08-19 16:24:02 +08:00
|
|
|
@Select("SELECT * FROM ll_order WHERE customer_id=#{customerId} AND source_region=#{sourceRegion} " +
|
|
|
|
|
"AND source_inbound_id=#{sourceInboundId} LIMIT 1")
|
|
|
|
|
LastlegOrder findSource(@Param("customerId") String customerId,
|
|
|
|
|
@Param("sourceRegion") String sourceRegion,
|
|
|
|
|
@Param("sourceInboundId") String sourceInboundId);
|
|
|
|
|
|
|
|
|
|
@Select("SELECT COUNT(*) FROM ll_order WHERE customer_id=#{customerId} AND container_no=#{containerNo}")
|
|
|
|
|
long countContainer(@Param("customerId") String customerId, @Param("containerNo") String containerNo);
|
|
|
|
|
|
|
|
|
|
@Select("SELECT * FROM ll_order WHERE customer_id=#{customerId} AND id=#{id} FOR UPDATE")
|
|
|
|
|
LastlegOrder lockById(@Param("customerId") String customerId, @Param("id") Long id);
|
|
|
|
|
|
|
|
|
|
@Update("UPDATE ll_order SET picked_package_count=picked_package_count+#{packages},updated_at=NOW() " +
|
|
|
|
|
"WHERE customer_id=#{customerId} AND id=#{id} " +
|
|
|
|
|
"AND package_count-shipped_package_count-picked_package_count >= #{packages}")
|
|
|
|
|
int increasePicked(@Param("customerId") String customerId, @Param("id") Long id,
|
|
|
|
|
@Param("packages") long packages);
|
|
|
|
|
|
|
|
|
|
@Update("UPDATE ll_order SET current_status=CASE WHEN shipped_package_count+#{packages}=package_count " +
|
|
|
|
|
"THEN 'COMPLETED' ELSE 'PARTIALLY_SHIPPED' END," +
|
|
|
|
|
"picked_package_count=picked_package_count-#{packages}," +
|
|
|
|
|
"shipped_package_count=shipped_package_count+#{packages},outbound_order_no=#{outboundNo},updated_at=NOW() " +
|
|
|
|
|
"WHERE customer_id=#{customerId} AND id=#{id} AND picked_package_count >= #{packages} " +
|
|
|
|
|
"AND shipped_package_count+#{packages} <= package_count")
|
|
|
|
|
int transferPickedToShipped(@Param("customerId") String customerId, @Param("id") Long id,
|
|
|
|
|
@Param("packages") long packages, @Param("outboundNo") String outboundNo);
|
2026-08-24 21:46:19 +08:00
|
|
|
|
|
|
|
|
@Update("UPDATE ll_order SET overseas_warehouse_id=#{warehouseId},overseas_warehouse_name=#{warehouseName}," +
|
|
|
|
|
"updated_at=NOW(3) WHERE id=#{orderId} AND customer_id=#{customerId} " +
|
|
|
|
|
"AND (overseas_warehouse_id IS NULL OR overseas_warehouse_id=#{warehouseId})")
|
|
|
|
|
int claimReceivingWarehouse(@Param("customerId") String customerId, @Param("orderId") long orderId,
|
|
|
|
|
@Param("warehouseId") String warehouseId,
|
|
|
|
|
@Param("warehouseName") String warehouseName);
|
2026-08-19 16:24:02 +08:00
|
|
|
}
|